RTSProjectile exploration
by Stephen Zepp · in RTS Starter Kit · 12/11/2004 (7:16 am) · 7 replies
Background: Due to the nature of our game, using MissionCleanup to handle memory management doesn't work (our mission never ends client side until the client actually stops playing for that session), so we've handled object memory cleanup manually for all client objects.
While debugging client console.log messages, I noted that RTSProjectiles when created (game.cs onDoClientAttackAnimation() ) are immediately set to the MissionCleanup group via MissionCleanup.add. Since we don't have a MissionCleanup group, this led me to believe I need to handle cleaning up those objects manually, so I started tracing through how they are handled in memory.
The first thing I did was to run through the code (RTSProjectile.cc) and try to track down the "life" of a projectile. It appears that:
--the explode() handles deletion of the projectile via a SimEvent, which I am assuming gets propagated across the net.
Wierdness part 1: the ObjectDeleteEvent.process() isn't called client side ( put in a debug line on the client side), leading me to believe that it's not a networked event. This would imply that the Projectile actually is never deleted.
Wierdness Part 2: I ran a test where I created a rifleman and had him unload on a bot, and then after he was done loaded up tree(); and searched through the client side objects. I found no RTSProjectile instances, which implies that the projectiles are deleted after all.
Ok, on to the two questions, for whomever:
1) If RTSProjectile objects are deleted somewhere, any idea of the execution sequence of where they get deleted?
2) If they are in fact deleted (which it appears they are), why add them to MissionCleanup with MissionCleanup.add()? Just a safety net and/or copied code from elsewhere?
While debugging client console.log messages, I noted that RTSProjectiles when created (game.cs onDoClientAttackAnimation() ) are immediately set to the MissionCleanup group via MissionCleanup.add. Since we don't have a MissionCleanup group, this led me to believe I need to handle cleaning up those objects manually, so I started tracing through how they are handled in memory.
The first thing I did was to run through the code (RTSProjectile.cc) and try to track down the "life" of a projectile. It appears that:
--the explode() handles deletion of the projectile via a SimEvent, which I am assuming gets propagated across the net.
Wierdness part 1: the ObjectDeleteEvent.process() isn't called client side ( put in a debug line on the client side), leading me to believe that it's not a networked event. This would imply that the Projectile actually is never deleted.
Wierdness Part 2: I ran a test where I created a rifleman and had him unload on a bot, and then after he was done loaded up tree(); and searched through the client side objects. I found no RTSProjectile instances, which implies that the projectiles are deleted after all.
Ok, on to the two questions, for whomever:
1) If RTSProjectile objects are deleted somewhere, any idea of the execution sequence of where they get deleted?
2) If they are in fact deleted (which it appears they are), why add them to MissionCleanup with MissionCleanup.add()? Just a safety net and/or copied code from elsewhere?
#2
As I said, it seems that they are handled normally--I'm not getting tons of loose RTSProjectile objects at the end of a session, but I can't quite place where they are being handled (and it's not MissionCleanup, eheh, at least not on my project).
12/11/2004 (10:55 am)
That's what I figured...the SimEvent posting confused me a bit, because I hadn't seen events used locally like that.As I said, it seems that they are handled normally--I'm not getting tons of loose RTSProjectile objects at the end of a session, but I can't quite place where they are being handled (and it's not MissionCleanup, eheh, at least not on my project).
#3
12/11/2004 (9:30 pm)
Do they... you know... delete themselves when they're done?
#4
Here are the possible candidates:
In void RTSProjectile::explode:
in RTSProjectile::processTick:
Don't ever see that log message either.
In RTSProjectile::onCollision:
That script isn't implemented anywhere either.
I can't find any other candidates that may be deleting them, and no scheduled deletes that I can find, so that's why I asked on the boards.
12/11/2004 (10:01 pm)
Heh..not sure if that is a sarcastic question or not, but I didn't see anything that suggested they did!Here are the possible candidates:
class ObjectDeleteEvent : public SimEvent
{
public:
void process(SimObject *object)
{
Con::printf("ObjectDeleteEvent--deleting object %i, class %s ", object->getId(), object->getClassName() );
object->deleteObject();
}
};That printf never occurs.In void RTSProjectile::explode:
Con::executef(mDataBlock, 4, "onClientExplode", scriptThis(), buffer, "1.0"); Sim::postEvent(this, new ObjectDeleteEvent, Sim::getCurrentTime() + DeleteWaitTime);OnClientExplode isn't implemented anywhere, and the postEvent may happen, but the event handler doesn't appear to get called (see above).
in RTSProjectile::processTick:
if (mCurrTick >= mDataBlock->lifetime)
{
Con::printf("RTSProjectile::processTick--deleting object %i, class %s ", this->getId(), this->getClassName() );
deleteObject();
return;
}Don't ever see that log message either.
In RTSProjectile::onCollision:
Con::executef(mDataBlock, 6, "onClientCollision",
scriptThis(),
Con::getIntArg(hitObject->getId()),
Con::getFloatArg(mFadeValue),
posArg,
normalArg);That script isn't implemented anywhere either.
I can't find any other candidates that may be deleting them, and no scheduled deletes that I can find, so that's why I asked on the boards.
#5
12/12/2004 (11:52 am)
Hmm... Interesting. I'll add this to my todo list.
#6
BTW, I may have been misleading--since we're post integration, I only searched our project's files. Let me search the stock RTS-SK and make sure we didn't just miss something on integration.
EDIT: I confirmed that onClientExplode and onClientCollision are not implemented as scripts in the stock RTS-SK.
12/12/2004 (1:05 pm)
Well the thing is, I can't find any proof that they aren't being deleted either. It certainly doesn't fill up the object inspector (tree();) with massive amounts of projectile objects after a decent sized fight.BTW, I may have been misleading--since we're post integration, I only searched our project's files. Let me search the stock RTS-SK and make sure we didn't just miss something on integration.
EDIT: I confirmed that onClientExplode and onClientCollision are not implemented as scripts in the stock RTS-SK.
#7
12/12/2004 (1:16 pm)
Thanks yet again Stephen. As you can tell, we'll be taking a gander. :)
Torque 3D Owner Pat Wilson