Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XNA Platformer (2D) - Framerate/FPS fluctuations

Tags:

c#

xna

xbox360

I'm new to C Sharp, and writing a game w/ the XNA Framework. I've created a project that's a heavily modified version of the "Platformer" XNA starter kit.

I'm seeing (seemingly) random fluctuations with the framerate. Sometimes it'll run at 60 FPS the whole time, sometimes it'll start at 60 FPS then drop to 49-52, and othertimes it'll drop to 49-52 immediately. Using Fraps to display framerate (not recording video to disk).

The unique nature of this game requires that it run at 60 FPS consistently.

So it seems some race condition or random factor is causing a difference between individual runs of the exe. Numerous rebuilds make no difference.

This fluctuation occurs on both my desktop and laptop with exactly the same frequency, so it's not an issue w/ hardware, anti-virus, etc.

I've searched about how to lock framerates in XNA, and my code seems to be doing much of what it needs to do, including an attempt to clamp at 60 FPS (using IsFixedTimeStep, SynchronizeWithVerticalRetrace).

The game is absolutely capable of 60 FPS from beginning to end, I see it all the time. When it's running at 60 FPS it does not tax CPU, RAM or any other resource as far as I can tell.

Anyone else experienced this?

Thanks, - S

like image 544
Scott Avatar asked Oct 12 '22 15:10

Scott


1 Answers

The inconsistency you describe means that the problem is either caused by

  • An environmental factor such as another process; or
  • A code path in your game that isn't taken on every run

The most likely cause is another process that is running on both your computers.

Close down all non-essential processes like media players. Windows Media Player and iTunes can both reduce your framerate while they are playing. Fraps should be ok as long as it isn't recording but I would implement your own built in FPS display just to be sure.

Use the windows performance monitor to check if there is a process consuming cpu or memory. Especially look for instances of your game that have failed to shutdown properly and are still running in the background.

Other things you could try to narrow down an environmental cause include:

  • Determine if the game runs at 60fps after a clean reboot
  • Determine if the game always runs at 60fps on the first run
  • Launch your game from explorer instead of visual studio
  • Determine if running in Release or Debug mode has any impact
  • Run your game on a friend's computer

If the cause is from a code path inside your game that isn't executed on every run you could:

  • repeatedly play and try to determine what it is you do in the game that triggers the slow down.
  • implement an input recording and playback system so that the same run through the game is exactly repeatable
  • profile your garbage collection and general performance to look for any problems that stand out
like image 199
Empyrean Avatar answered Oct 21 '22 07:10

Empyrean