SFML community forums

Help => General => Topic started by: natchos on October 10, 2012, 03:02:06 pm

Title: Having one calculation loop and one graphic loop in SFML 2.0
Post by: natchos on October 10, 2012, 03:02:06 pm
To explain my topic a bit better: Is there anyway to have a section of code which goes much faster than the rest of SFML?
I would like to change my project to have two loops: one drawing loop which is "only" called 40 times per second, so that the visual portion of the game has 40 fps, and a update/calculation loop which runs at a higher speed (say 70-80 times per second).

Is there any easy way to do this, is it impossible with sfml or is it possible but I just have to code it myself?
Title: Re: Having one calculation loop and one graphic loop in SFML 2.0
Post by: model76 on October 10, 2012, 03:48:07 pm
This can be achieved in two ways:

I found this article helpful, although it is focused around game loops, which may not be what you are looking for:
http://www.koonsolo.com/news/dewitters-gameloop/ (http://www.koonsolo.com/news/dewitters-gameloop/)
Title: Re: Having one calculation loop and one graphic loop in SFML 2.0
Post by: eXpl0it3r on October 10, 2012, 05:27:55 pm
SFML doesn't provide anything like this since SFML doesn't provide 'logic' parts but only functionalities that can help you, all the rest (structure, content, engine...) is stuff you have to do. ;)

You might find this article (http://gafferongames.com/game-physics/fix-your-timestep/) interesting too.
You also might want to look at GatorQue Engine (GQE) (https://code.google.com/p/gqe/) which goes the approach of having different rates for update and drawing. ;)
Title: Re: Having one calculation loop and one graphic loop in SFML 2.0
Post by: natchos on October 14, 2012, 10:36:13 pm
This can be achieved in two ways:
  • Spawn a thread that runs your logic. Be aware that it can be more difficult to work with than it looks.
  • Use one loop, but only perform tasks at the wanted intervals.

I found this article helpful, although it is focused around game loops, which may not be what you are looking for:
http://www.koonsolo.com/news/dewitters-gameloop/ (http://www.koonsolo.com/news/dewitters-gameloop/)

Sorry for not responding. Thank you.

In the end I went for this approach

if(DisplayClock.GetElapsedTime().asMilliseconds() >= 2.85714)
{
draw stuff...
}
 

(2.85714 millis means about 35 frames per second)
Title: Re: Having one calculation loop and one graphic loop in SFML 2.0
Post by: Zephilinox on October 19, 2012, 09:20:16 pm
actually it means about 350 FPS, milli = 1000 not 100 :]