Game Slow and Weird Behavior
by Tony Pitman · in Torque X 2D · 07/07/2009 (6:16 am) · 15 replies
I am writing a 2D game using Torque X. This is my 3rd, so I think I am getting the hang of things. I am having 2 problems at this point. The first one is that my player objects seem to pause ever half second or so. It is not consistant so it is not like it is happening on a timer or something.
The second and more noticable problem happened for the first time last night. I have just a couple of layers with a main background, then a background on a closer layer and then several invisible objects for collision with my terrain. On top of that I have some spawners that only spawn once that are playing an animation (only 3 frames per second) that are blinking rectangles for landing pads.
My player objects are simple ships with an animation playing for the rocket blast. I make the blast grow and shrink based on thrust by simply changing its size. Nothing special.
After a couple of minutes of playing, suddenly the background disappeared and then came back several times. It was like it was blinking on and off irratically. Then the second closer background started in along with the main background. Then the player ships disappeared and didn't come back. Then the game just stopped. This was all on my xBox while debugging. Nothing came up in the debugger for a crash or anything like that.
What the heck happened?
I found this link about a memory leak: http://www.garagegames.com/community/forums/viewthread/92771
Could that have somehting to do with it? I don't have the source code. I only have the Torque X XNA Creators Club version license that doesn't come with the source code.
The second and more noticable problem happened for the first time last night. I have just a couple of layers with a main background, then a background on a closer layer and then several invisible objects for collision with my terrain. On top of that I have some spawners that only spawn once that are playing an animation (only 3 frames per second) that are blinking rectangles for landing pads.
My player objects are simple ships with an animation playing for the rocket blast. I make the blast grow and shrink based on thrust by simply changing its size. Nothing special.
After a couple of minutes of playing, suddenly the background disappeared and then came back several times. It was like it was blinking on and off irratically. Then the second closer background started in along with the main background. Then the player ships disappeared and didn't come back. Then the game just stopped. This was all on my xBox while debugging. Nothing came up in the debugger for a crash or anything like that.
What the heck happened?
I found this link about a memory leak: http://www.garagegames.com/community/forums/viewthread/92771
Could that have somehting to do with it? I don't have the source code. I only have the Torque X XNA Creators Club version license that doesn't come with the source code.
#2
How can the camera clip plan fix the second problem when it doesn't start out doing it? It only starts to happen after about 2 minutes of play. Since this is a 2D game, those backgrounds are not changing position in Z or anything like that. Everything starts out fine and then after a couple minutes first the background, then the second background then the players and none of them change in the Z (don't even think there is a Z in a 2D game).
On the 1st problem I will check out my loops. Does this include things like:
SceneObject.Physics.Velocity = new Vector2(......)?
Is that bad to do and should I use another way?
07/07/2009 (7:30 am)
Thanks for the quick reply.How can the camera clip plan fix the second problem when it doesn't start out doing it? It only starts to happen after about 2 minutes of play. Since this is a 2D game, those backgrounds are not changing position in Z or anything like that. Everything starts out fine and then after a couple minutes first the background, then the second background then the players and none of them change in the Z (don't even think there is a Z in a 2D game).
On the 1st problem I will check out my loops. Does this include things like:
SceneObject.Physics.Velocity = new Vector2(......)?
Is that bad to do and should I use another way?
#3
I found in my game after some objects started getting created, they would begin disappearing, beginning with the background. If you have objects onscreen getting created, then destroyed, right around the object limit, that would explain the background disappearing and reappearing as its depth goes from within the cam depth to beyond it and back. Increasing the cam depth will fix that.
07/07/2009 (9:41 am)
Are there more objects being created as the game goes on? The camera depth comes into play because each object is put on a different z-coordinate, (even though it is "2D", it is still actually rendered in 3D). Thus, there is a limit to how many objects can be on screen at a time. Increasing the depth will allow more objects:T2DSceneCamera cam = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>(); //if you are using the default cam from TXB cam.FarDistance = 5000; //FarDistance must be greater than the number of objects on screen //since their depth is assigned based on sort order. Default value is 100.And remember, that each individual particle of particle effects counts as an object, as well.
I found in my game after some objects started getting created, they would begin disappearing, beginning with the background. If you have objects onscreen getting created, then destroyed, right around the object limit, that would explain the background disappearing and reappearing as its depth goes from within the cam depth to beyond it and back. Increasing the cam depth will fix that.
#4
I have created another game and it has more objects coming and going and never does this even after 20 minutes of playing it. That one doesn't have any particle effects, however. Again my new one doesn't either, but used to....
07/07/2009 (9:47 am)
Thanks for the code. If I do have that many objects getting created then there is a bug somewhere because I don't. I did have a particle effect in the game, but don't anymore. Is it possible is it still being created behind the scenes even though I deleted it from the level data file?I have created another game and it has more objects coming and going and never does this even after 20 minutes of playing it. That one doesn't have any particle effects, however. Again my new one doesn't either, but used to....
#5
Do you have these same issues when you run it under Windows?
Also, I'd try hooking up some counters and using XNA Framework Remote Performance Monitor for Xbox 360. From there you can see if garbage collection is bottlenecking your CPU.
07/07/2009 (3:57 pm)
Hey Tony,Do you have these same issues when you run it under Windows?
Also, I'd try hooking up some counters and using XNA Framework Remote Performance Monitor for Xbox 360. From there you can see if garbage collection is bottlenecking your CPU.
#6
Thanks for the link, I will try that as well.
07/07/2009 (4:05 pm)
I do have the studder problem on Windows, but have not had it the background going away problem. I will try running it longer on Windows and see if I do.Thanks for the link, I will try that as well.
#7
It turns out I had my particle effect set to STOP instead of KILL. I thought I had to have it that way because I am using the same particle over and over (it is my explosion). I was wrong, though, because I am cloning a template, so the clone needed to be killed when it was done instead of just stopped. I should have realized that.
So now the objects are not blinking off. The glitchiness might just have been the symptom of something else. I changed several other things to get to the point I am now and it seems to run pretty smooth now.
Thanks to all, this one is solved....
07/07/2009 (6:14 pm)
I think, with all of your help, I figured it out. The key was indeed the number of objects getting created. Matt and Scott mentioned that even each particle is an object in the camera clipping plane.It turns out I had my particle effect set to STOP instead of KILL. I thought I had to have it that way because I am using the same particle over and over (it is my explosion). I was wrong, though, because I am cloning a template, so the clone needed to be killed when it was done instead of just stopped. I should have realized that.
So now the objects are not blinking off. The glitchiness might just have been the symptom of something else. I changed several other things to get to the point I am now and it seems to run pretty smooth now.
Thanks to all, this one is solved....
#8
07/07/2009 (8:11 pm)
Something else that might help in any case is to set up an object pool and re-use the most commonly created objects if you have many of them. There are all kinds of resources on the internet concerning objects pools and how to implement them, including what they can and can't do. It's basically a method for you to re-use many of your objects so that they don't have to be created/destroyed each time.
#9
07/07/2009 (8:25 pm)
Thank you. I agree. In my other game where there are projectiles I do use object pooling....
#11
I think the xBox jerkiness is pretty much gone since I found and fixed the particle issue I mentioned above.
07/08/2009 (4:20 pm)
Thanks. So is the SimulateFences on or off for an xBox build or is it even relevant? I was seeing performance issues on the xBox, just not as bad. I have a Dell M1730 with the dual NVidia 8700 cards with SLI. I wonder if that is the problem on Windows.I think the xBox jerkiness is pretty much gone since I found and fixed the particle issue I mentioned above.
#13
07/08/2009 (9:33 pm)
I can't seem to find anywhere in the TX2D documentation where you set this setting. Can someone point me to it? I have created a standard Torque X 2D game.
#14
It is in the TorqueSettings.xml file. Open it and insert the line under TorqueEngineSettings:
You can adjust a number of things there which get read by the exe when it runs. For instance, to run in full-screen mode, add a line under WindowsGraphicsManagerSettings like so:
07/09/2009 (9:31 am)
@Tony:It is in the TorqueSettings.xml file. Open it and insert the line under TorqueEngineSettings:
<TorqueEngineSettings> <SimulateFences>true</SimulateFences> . . .Assuming, of course it's not already there.
You can adjust a number of things there which get read by the exe when it runs. For instance, to run in full-screen mode, add a line under WindowsGraphicsManagerSettings like so:
<WindowsGraphicsManagerSettings> <IsFullScreen>true</IsFullScreen> . . .That way, it (and all other settings in this file) can be changed at will without having to rebuild the exe.
#15
07/09/2009 (10:47 am)
Well, in the end it appears to not have anything to do with the simulatefences because that setting is already true for this game.
Torque Owner Matthew Hoesterey
So it sounds like you have two problems. The second is easy to fix. You need to increase the camera clip plane. I don't have my code on hand but if you search the forums you should find the method. (I belive you can do it in your settings xml file)
The first problem sounds like Garbage Collection. If your creating deleting objects over and over ie... bullets make sure you have pool or pool with components set to true. (maybe your cloning a particle every frame or something then deleting it but it's not set to pool)
you may Also be allocating variables on a loop in code. look for places that you are initilizing variables in your proccess tick or other function that runs every frame and try to initilize those variables at the class level.
It's hard to say whats wrong without seeing the code but usually a slowdown that is happens consistently on a sort of heart beat is usually a garabage collection problem.
The Memory leak your seeing is only in the Menus and would cause perminent slowdowns. But probably wont' effect you once you are playing the game. Something GG needs to fix.