I'm trying to figure out a way to release the memory from the Entities (as I call anything that moves in my game) that I won't use anymore.
-warning: bad design coming! some tips?-
As an example, my Player class has Bullets. When there is a Fire() event, I check if the ship is allowed to fire; if it is, a new bullet is put to the entities list and the game flux goes on merry on its gammy way.
The problem is that I'm not releasing the resources used by bullets that are already dead, i.e. out of screen or collided. Sometime soon it will bite me back.
So I tried to release it by popping the dead bullets out of the entities list using this code:
for ( std::vector<Entities*> iter = entities.begin(); iter != entities.size(); ++iter) { if( (**iter).checkIfDead() ) { (*iter).pop_front; } }
I will call it a Pseudo code. After the "if" part I dunno what to do. I want to call each entities "checkIfDead()" function and them remove it from the container. I think it would be simple if it was a vector<Stuff> (not a vector of pointers), but I really need to use a vector of pointers.
hear from you!
Fabio