How do you separate game logic from display?

后端 未结 8 1989
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 07:33

How can you make the display frames per second be independent from the game logic? That is so the game logic runs the same speed no matter how fast the video card can render

相关标签:
8条回答
  • 2020-12-24 08:29

    Koen Witters has a very detailed article about different game loop setups.

    He covers:

    • FPS dependent on Constant Game Speed
    • Game Speed dependent on Variable FPS
    • Constant Game Speed with Maximum FPS
    • Constant Game Speed independent of Variable FPS

    (These are the headings pulled from the article, in order of desirability.)

    0 讨论(0)
  • 2020-12-24 08:31

    This doesn' cover the higher program abstraction stuff, i.e. state machines etc.

    It's fine to control movement and acceleration by adjusting those with your frame time lapse. But how about stuff like triggering a sound 2.55 seconds after this or that, or changing game level 18.25 secs later, etc.

    That can be tied up to an elapsed frame time accumulator (counter), BUT these timings can get screwed up if your frame rate falls below your state script resolution i.e if your higher logic needs 0.05 sec granularity and you fall below 20fps.

    Determinism can be kept if the game logic is run on a separate "thread" (at the software level, which I would prefer for this, or OS level) with a fixed time-slice, independent of fps.

    The penalty might be that you might waste cpu time in-between frames if not much is happening, but I think it's probably worth it.

    0 讨论(0)
提交回复
热议问题