Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: fps spikes  (Read 2008 times)

0 Members and 1 Guest are viewing this topic.

Ileev

  • Newbie
  • *
  • Posts: 3
    • View Profile
fps spikes
« on: May 08, 2014, 02:13:29 am »
hello guys, Im not sure if I post this thread in correct category but I hope I do.

basically, my movement isn't smooth. I believe this happens because of huge fps spikes



...and here comes the code(which is very simple)
http://pastebin.com/qCkbWj0t

some more informations:
- i5
- gt330m
- ssd ocz drive
- windows 8.1
- visual studio express 2013
- sfml 2.1 built by me using cmake
- no difference between static or dynamic libs or release/debug


F2CPP

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • StackOverflow
Re: fps spikes
« Reply #1 on: May 09, 2014, 08:30:44 pm »
try standardising the time passed per iteration so that when things are being delayed the excess elapsed time is 'lost' and not used to update the game.

e.g. check out this post:
http://gafferongames.com/game-physics/fix-your-timestep/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: fps spikes
« Reply #2 on: May 09, 2014, 08:36:31 pm »
Time between frames *will* vary (hugely). You must deal with that.

Varying frame times have many causes:
 - the code you write yourself may take variable time for different frames.
 - your drivers may have bugs (naah, they certainly do).
 - the OS may be busy running other applications or interacting with hardware.
 - memory pressure varies over time.
 - power saving may be changing CPU/GPU frequency dynamically.
and much more.
There is basically *no way* that you can expect a steady frame rate. Far from it - and this has nothing to do with SFML.

Enabling things like vsync ( http://www.sfml-dev.org/documentation/2.1/classsf_1_1Window.php#a59041c4556e0351048f8aff366034f61 ) will smooth things out a bit (and save some CPU cycles and power - use it), but it doesn't solve the problem. You still need to take a variable frame rate into account yourself.

Some good stuff to read:
 http://gafferongames.com/game-physics/fix-your-timestep/
 http://www.koonsolo.com/news/dewitters-gameloop/
 http://gameprogrammingpatterns.com/game-loop.html
 
« Last Edit: May 10, 2014, 08:27:30 pm by Jesper Juhl »

 

anything