Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Member Since 29 Jun 2004
Online Last Active Today, 03:51 AM

#4963072 FXAA, why not use Depth

Posted by Rattenhirn on 25 July 2012 - 03:37 PM

There are AA alorithms out there that use depth. But the big seller for FXAA is, that it only needs the backbuffer as input and does everything in one fairly simple pass. It's simple to integrate and fast to boot.

It can also smoothe edges with no depth information, for example reflections or refractions, as well as edges created by post processing.

In my experience, purely image based algorithms don't get signigicantly better than that.

#4953987 std::vector vs std::unique_ptr

Posted by Rattenhirn on 29 June 2012 - 09:50 AM

Please explain in what way it is misleading? std::vector is used to manage vectors. std::unique_ptr is used to manage pointers to objects or vectors. So it is rather obvious what I was asking for, isn't it?

The title of this thread is "std::vector vs std::unique_ptr". I'm pretty sure most people started to read it, because they were wondering how one could possibly meaningfully compare those two and not because they want to discuss vector vs. array, which has been discussed to death already.

I don't understand this. A vector is a one dimensional array. So for the one dimensional case, there are no differences by definition.

In your original post you asked "What are the general guidelines here?" for "std::vector vs std::unique_ptr" (to a T[]).
I gave you a general guideline, that is very simple and very effective.

If you look at vector vs. array from the perspective, that both of them store a sequence of values in a continuous chunk of memory, then yes, there is no difference. However, there are differences between "std::vector vs std::unique_ptr" (to a T[]), which is, if I understood you at all, what you asked for. And the answer is that vector is preferable in pretty much every case, because it offers more functionality and safer interface, at the cost of approximately 2 extra pointers.

If you're so starved on memory, that you can't afford those 2 extra pointers, you'll need to stay away from allocations on the free-store anyways, so unique_ptr to a T[] is no help either.

I hope that clarifies things!

#4953646 std::vector vs std::unique_ptr

Posted by Rattenhirn on 28 June 2012 - 06:51 AM

First of all, the title of this message is very misleading.

What you actually want to know is the difference between an array which life time is managed with unique_ptr vs. std::vector.

Fortunately there is a good general guideline:
Use std::vector!

If you need to know why, please search for some of the discussion about arrays vs. vector and remove all arguments against arrays that concern lifetime management of the array's memory.

#4953569 HTML5 Game Development?

Posted by Rattenhirn on 28 June 2012 - 12:53 AM

If you want client side interactivity with HTML, you're gonna need JavaScript. If you can do everything on the server side, you can use pretty much any programming language out there.

#4941892 Get Pitch, Yall and Roll from matRotation

Posted by Rattenhirn on 21 May 2012 - 05:59 AM

I see some issues stated about converting matrix to Euler, I want to guarantee that I will receive VALID values and EXACTLY the same rotation values from a D3DXMATRIX every time I convert D3DXMATRIX to Euler without any problem, is that possible?

Barring rounding errors, you'll get the exact same rotation in euler angles. However, euler angles do not represent orientations uniquely, meaning there's more than one set of euler angles for any given orientation.

Of course, as long you'll use the same algorithm for conversion, matrix M will always give the same angles X, Y and Z. But, for instance, if your rotate M by 45 degrees around the Y axis, you won't necessarily get X, Y+45 and Z. Just another set of angles that represent that orientation.

So, if you want to keep the exact euler values, e.g. as entered, you have to save them...

#4939334 Class Function Overloading Method Question

Posted by Rattenhirn on 11 May 2012 - 10:08 AM

Check out the LSP, which is generally regarded a very good practice in OOP:

Relying on the "smarts" of users is a very error prone approach.

Why make add an extra parameter to Draw, if all that does is modifying the state of the object anyways? It's more intuitive, if "Draw" would always draw the object, and if you want it at another place, call "SetModelPosition".

#4937760 pointer behaviour

Posted by Rattenhirn on 06 May 2012 - 07:19 AM

If you delete an object, not all pointers to it are automatically set to 0. This would be very convenient, but that's not how it works.

The simplest, but also pretty dangerous solution would be to manually set every reference to the deleted object to 0 manually.

Alternatively, you can add another layer of abstraction, i.e. a "shared_ptr". This would ensure, that as long as something is pointing to the object, it does not get deleted. This is probably not what you want, but there's also a standard solution for that. For references that should not keep the object alive, use "weak_ptr".

Here's a quick tutorial that google spat out after a quick search:

I hope that helps!

#4920357 Is it important to have Maths on your C.V?

Posted by Rattenhirn on 08 March 2012 - 02:21 AM

Huh, I was hoping someone would reply who knows what A-Level education grade B and 2.1 graduation of a course in Game Software Development actually means. Different countries have different education and grading systems, you know.

But since nobody did, I'll jump in and tell you what I look at on incoming CVs for programmers: How much programming education and how much programming experience, both especially in C++.

Most CVs don't even list the math grades explicitely, and if grades are included, I don't look at them, because in 99% of the cases I don't know the specific school, course or university they can from anyways, which makes it impossible to assign any meaning to those arbitrary numbers. This is especially true from grades that were achieved during the forming ("teenage") years.

During the interview I reality check the claimed programming skills with a C++ or general programming quiz and I also check some secondary skills. It's not so important that the answers are perfect, it's more insightful how the questions are answered. Even if someone doesn't know the answer, and that usually happens a couple of times because of the vastness of topics available for asking, I usually still can tell whether the interviewee will be able to understand the answer once she's heard it. Often by telling them the answer and observing the reaction.

As for math, I usually ask only one specific question: What is the dot product of 2 3D vectors and what can it be used for. You'd be surprised how many struggle with this question, often even people who claim to have done Shader programming and are interested in CG...

I hope that helps!

#4918105 [C++] Custom containers vs STL

Posted by Rattenhirn on 01 March 2012 - 01:25 AM

As Hodgman already explained, the capacity of vectors can indeed be controlled.

If you're looking to build a "custom" container that works for all possible use cases, you won't be able to do better than vector.

However, if you have a specific use case you need to optimize for, there might be a better way.

Now, to answer your actual question:

> a) Using new/delete every time we want to add/delete elements (To keep the size of the buffer exact: for an n-element-buffer, the size is n*sizeof(element_type) ).

This is most likely the worst possible solution. Keep in mind that new/delete are usually pretty expensive operations and that you need to copy the complete content of your container on every resize. If you're worried about memory wasting and do not need continuity in memory, you should consider making a vector of (smart) pointers to your element type. In this case, not much memory is wasted, because pointers are small and resizing is cheap, because the big / expensive to copy objects don't have to be moved.

> b) Increasing the capacity unnecessarily (To avoid calling ::operator new and ::operator delete every time).

That's exactly what vector is doing. Not only does it avoid new/delete, but also copying stuff around on resize.

I hope that helps!

#4827826 What is the best free, open source audio library for commercial production?

Posted by Rattenhirn on 26 June 2011 - 03:21 AM

Try also FMod.

FMod is not free for commercial use.

#4822800 Checking for collision between elements in two vectors

Posted by Rattenhirn on 13 June 2011 - 09:40 AM

Fixed that for you!

	for(std::vector<sf::Sprite>::iterator bulletIter = storeBullets.begin(); bulletIter != storeBullets.end();)
                bool hasCollided = false;
		for(std::vector<sf::Sprite>::iterator asterIter = roidStore.begin();asterIter != roidStore.end();)
			if(Collision::HasCollided(*asterIter, *bulletIter)==true)
				asterIter = roidStore.erase(asterIter); //same for asteroid
                                hasCollided = true;
                if (hasCollided)
       		    bulletIter = storeBullets.erase(bulletIter); //remove bullet from vector
		    ++bulletIter; // check next

#4814175 Bugs you expected to throw a compiler error ...

Posted by Rattenhirn on 22 May 2011 - 03:51 AM

The compiler can and should only check for lexical, syntactic or semantic errors that cannot be translated. Your example is perfectly valid source code.

I guess what you're looking for is a static code analyzer.
Here's a list of tools that do that, but I'm not sure any of these will the detect the mistake in your example...

#4814173 Relations of classes in C++

Posted by Rattenhirn on 22 May 2011 - 03:46 AM

Brother Bob is spot on.

As a general rule, never put an include statement into a header, unless absolutely necessary.

It's only necessary when the header file to include declares a type that's:
  • inheriting from
  • a value type member
  • passed or returned as value type (which in most cases is questionable in itself)

#4808672 Cant find variable error

Posted by Rattenhirn on 09 May 2011 - 01:08 PM

There's an extra semicolon (";") at the end of the first for in the case "2" block...

#4804750 [c++] Stop windows command line pausing process while moving/scrolling

Posted by Rattenhirn on 30 April 2011 - 07:57 AM

Your application appears to hang when the command window is being manipulated, because stdout/stderr are not read at that time. And once the stdout/stderr buffer is full, every attempt to write to stdout/stderr will block until the buffer is being cleared again.

So, one possible solution is to use async io to write to stdout. Another possibility is to do the time critical stuff (or just everything) in a second thread, write output to a buffer and have the main thread read that buffer and write it to stdout/stderr. Or do it the other way round and create a "logger" thread...

I hope that helps!