Active Ghosts count incorrect
by Gary Preston · in Torque Game Engine · 11/07/2006 (1:59 pm) · 0 replies
This is really just a cosmetic bug.
If you run two clients and display their respective net graphs, over the course of several rounds/missions the active ghosts count accumulates. I ran our game for a few hours and had over 4000 active ghosts.
After looking into this and checking that ghosts are deleted due to the missionCleanup group been deleted, I noticed the cause of the problem in netGhost.cc.
mGhostsActive is incremented during receipt of a new ghost in the ghostReadPacket method. It is likewise decremented in the same method when a KillGhost flag is received. However, this does not account for all ghosts, a number are deleted during the "EndGhosting" case of handleConnectionMessage as well new ghosts created during the loadNextGhostAlwaysObject method, neither of which are accounted for.
In our case, what I beleive happened was the active ghost count was incremented in ghostReadPacket as we created over the course of the round several scope always objects (terrain deformers) these however were not been freed by a ghostPacketUpdate, instead they were freed in the "EndGhosting" section and thus the mGhostsActive count never decremented.
Adjust EndGhosting case
Add near end of loadNextGhostAlwaysObject
With the above, ghost active count now reads the correct value on both clients and returns to the correct value after cycling to the next mission.
There is one other place that may need adjusting. In ghostReadStartBlock new ghosts are registered due to demo loading
However I havn't tested this with demos, so I'm not sure whether that change is required or not.
If you run two clients and display their respective net graphs, over the course of several rounds/missions the active ghosts count accumulates. I ran our game for a few hours and had over 4000 active ghosts.
After looking into this and checking that ghosts are deleted due to the missionCleanup group been deleted, I noticed the cause of the problem in netGhost.cc.
mGhostsActive is incremented during receipt of a new ghost in the ghostReadPacket method. It is likewise decremented in the same method when a KillGhost flag is received. However, this does not account for all ghosts, a number are deleted during the "EndGhosting" case of handleConnectionMessage as well new ghosts created during the loadNextGhostAlwaysObject method, neither of which are accounted for.
In our case, what I beleive happened was the active ghost count was incremented in ghostReadPacket as we created over the course of the round several scope always objects (terrain deformers) these however were not been freed by a ghostPacketUpdate, instead they were freed in the "EndGhosting" section and thus the mGhostsActive count never decremented.
Adjust EndGhosting case
case EndGhosting:
// just delete all the local ghosts,
// and delete all the ghosts in the current save list
for(i = 0; i < MaxGhostCount; i++)
{
if(mLocalGhosts[i])
{
[b]mGhostsActive--;[/b]
mLocalGhosts[i]->deleteObject();
mLocalGhosts[i] = NULL;
}
}
while(mGhostAlwaysSaveList.size())
{
delete mGhostAlwaysSaveList[0].ghost;
mGhostAlwaysSaveList.pop_front();
[b]mGhostsActive--;[/b]
}Add near end of loadNextGhostAlwaysObject
AssertFatal(mLocalGhosts[index] == NULL, "Ghost already in table!");
mLocalGhosts[index] = object;
hadNewFiles = true;
[b]mGhostsActive++;[/b]With the above, ghost active count now reads the correct value on both clients and returns to the correct value after cycling to the next mission.
There is one other place that may need adjusting. In ghostReadStartBlock new ghosts are registered due to demo loading
obj->mNetFlags = NetObject::IsGhost;
obj->mNetIndex = index;
mLocalGhosts[index] = obj;
[b]mGhostsActive++;[/b]However I havn't tested this with demos, so I'm not sure whether that change is required or not.
About the author