Game Development Community

Framerate issues over time (PC and XBOX) [objects not deleting properly?]

by William McDonald · in Torque X 2D · 09/10/2009 (10:05 pm) · 4 replies

As my game progresses in complexity, I am starting to encounter a lot of framerate issues on both the PC and the XBOX. The issues manifest after playing the game for a period of time. At the start of the level, with lots of sprites, it runs smoothly and at a decent speed. Once I get to the later stages of the level, the game has slowed to the point that it is virtually a slideshow.

This has become much more severe now that I have added gibs. I spawn two scene objects per gib (a T2DStaticSprite for the shadow and a T2DAnimatedSprite for the gib), and I typically spawn around 5 gibs per destroyed object.

I assume that TorqueX isn't properly cleaning up something since it works fine in the beginning. I have tried with pooled objects and without pooled objects. One thing I noticed is that with pooled objects, the ProcessList._TickObjects() loop would continue to grow and wasn't being reduced as objects were deleted. I thought that maybe that was the issue, but after removing object pooling (which caused the _TickObjects() loop to reduce as objects were being deleted), it doesn't seem to be.

Here is a dump of my profiler information:
http://dungeons.pastebin.com/f33f43357

I currently am using this for deleting sprites. I used to just use MarkForDelete, but tried this in an attempt to get it working:
// _sprite is the T2DAnimatedSprite, which is the gib from a sprite sheet.
// SceneObject is the T2DStaticSprite, which is the shadow.
_sprite.IsOwnedByMount = true;
_sprite.MarkForDelete = true;
SceneObject.MarkForDelete = true;
ProcessList.Instance.SetEnabled(_sprite, false);
ProcessList.Instance.RemoveObject(_sprite);
ProcessList.Instance.SetEnabled(SceneObject, false);
ProcessList.Instance.RemoveObject(SceneObject);

----------

Actually, as I was playing the game just now to get a profiler dump, I just noticed something. As I kill enemies and flood the screen with gibs, I fade them out and delete them, and the game gets slower and slower. However, once I progress further along in the level and leave the previous battle area, the game suddenly becomes smooth again, until the next battle starts. It is almost like the engine isn't deleting the objects and attempts to draw hundreds of invisible gibs and deleted enemies all over the place, slowing the game down. Maybe the game isn't removing the polygons from the scene when you delete the object? Does anyone know where this code would be within Torque?

About the author

I am the grand bureaucrat of SuckerFree Games. I now have one game in distribution, "Kobold's Quest" and another is soon to be published, "Dungeons the Eye of Draconus". My day job is as a Videographer.


#1
09/10/2009 (11:02 pm)
are you actually deleting the gibs? I have over 50 attackers a level, each having a sprite, and an attached sprite, plus shooting stuff, projectiles, particles.

I just MarkForDelete and they go away. I would really check your code and make certain they are deleting. Step through in the debugger.
#2
09/10/2009 (11:05 pm)
Yes. I am calling MarkForDelete. For the gibs, I call it for both the shadow and the gib. For the enemies, I call it for both the shadow and the enemy. Placing breakpoints on the code confirms this.

EDIT: The objects do disappear. They always have. My problem is that when they disappear, the performance doesn't improve. It just keeps getting worse, like the engine is still trying to draw them. It gets better when the area where they died gets moved outside of the camera view.
#3
09/10/2009 (11:40 pm)
Since the bottleneck could possibly be anywhere, I think the best possible solution is to hook up a profiler so you can drill down to the exact call(s) that are causing the issue.

If you don't have any I'd recomment JetBrain's dotTrace for performance issues and SciTech's memory profiler for memory leaks. Both are excellent programs and can be used unlocked with full features for at least 15 days (I believe dotTrace is actually 30 days). I use them practically on a daily basis at work (and sometimes with Torque).

Either that or you could stick to some trial and error and start sticking Torque's profiler in areas of interest to see what you come up with.
#4
09/15/2009 (3:37 am)
I'm not 100% sure, but I dont think MarkForDelete deletes them instantly... I always thought it told the engine it could do it whenever it had time. BTW, I'm wrong a lot, so I won't be surprised if I'm wrong now.

I've gotten used to using:
TorqueObjectDatabase.Instance.Unregister(object);
Which deletes instantly.