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

Author Topic: Having one calculation loop and one graphic loop in SFML 2.0  (Read 3540 times)

0 Members and 1 Guest are viewing this topic.

natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
Having one calculation loop and one graphic loop in SFML 2.0
« 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?

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: Having one calculation loop and one graphic loop in SFML 2.0
« Reply #1 on: October 10, 2012, 03:48:07 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/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11047
    • View Profile
    • development blog
    • Email
Re: Having one calculation loop and one graphic loop in SFML 2.0
« Reply #2 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 interesting too.
You also might want to look at GatorQue Engine (GQE) which goes the approach of having different rates for update and drawing. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
Re: Having one calculation loop and one graphic loop in SFML 2.0
« Reply #3 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/

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)

Zephilinox

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Having one calculation loop and one graphic loop in SFML 2.0
« Reply #4 on: October 19, 2012, 09:20:16 pm »
actually it means about 350 FPS, milli = 1000 not 100 :]

 

anything