Archived

This topic is now archived and is closed to further replies.

rumblef

Dead enemy notification

Recommended Posts

rumblef    122
Hi, I have a class that creates and deletes enemy objects. When an enemy dies, it goes through its death animation etc. How can I notify the managing class that the enemy is completely dead and thus can be deleted? Right now I have a loop that checks that state of all enemies on each update, but that seems like a waste of cpu. Any nicer solutions?

Share this post


Link to post
Share on other sites
RuneLancer    253
Why not just remove the enemy as soon as the death animation ends instead of putting it in a queue? Just call the managing class''s "get rid of the enemy" function right away.

Share this post


Link to post
Share on other sites
rumblef    122
Hi,
The managing class doesn''t know when the enemies death animation is completed, so it keeps checking the state of each enemy to see which ones are completely dead. I''d rather the enemy told the managing class when it was completely dead but dont know how to go about doing this.

Share this post


Link to post
Share on other sites
GroZZleR    820
My advice? Don''t remove it.

Stop drawing it, if you want (I dunno, maybe you want the corpse to hang around). But if you go to create a new entity, have your manager loop through to check for currently ''dead'' enemies and just recycle them. Saves you new / delete calls.

If you''re interested in something like that, look into Factories. It sounds like you''ve got a similar system already going, which is good =)

Share this post


Link to post
Share on other sites
Palidine    1315
why not something like this?


class Enemy
{
public:
~Enemy();
};

Enemy::~Enemy()
{
//assuming availability of static class

EnemyManager::NotifyOfDestruction(this);

//

// or

//


//non-static version

GlobalObjects::GetEnemyManager()->NotifyOfDestruction(this);
}


-me

Share this post


Link to post
Share on other sites
markr    1692
If you are looping through all the objects anyway in order to call their logic functions, and drawing functions, it is not a problem to also loop through them to check for a "dead" flag.

I put a boolean member variable on my base class "dead" - here dead means "Completely dead, needs to be thrown away imminently". Anything flagged as dead will be removed from the active list by the manager routine, and ultimately delete[]d

It''s common to use this for bullets and animation objects (particles), these are typically very short lived, and hence need to be thrown away quickly otherwise there will be too many hanging around in memory.

Mark

Share this post


Link to post
Share on other sites