Fixed rate logic question - Dewitters

BlitzMax Forums/BlitzMax Beginners Area/Fixed rate logic question - Dewitters

coffeedotbean(Posted 2015) [#1]
So I might be missing the obvious but I have been reading Dewitters game loops http://www.koonsolo.com/news/dewitters-gameloop/ and I'm thinking about using;

	
    const int TICKS_PER_SECOND = 50;
    const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
    const int MAX_FRAMESKIP = 10;
    DWORD next_game_tick = GetTickCount();
    int loops;

    bool game_is_running = true;
    while( game_is_running ) {

        loops = 0;
        while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
            update_game();

            next_game_tick += SKIP_TICKS;
            loops++;
        }

        display_game();
    }




Now implementing the above is easypeasy

    Const TICKS_PER_SECOND:Int = 50
    Const SKIP_TICKS:Int = 1000 / TICKS_PER_SECOND
    Const MAX_FRAMESKIP:Int = 10
    Global next_game_tick:Int = MilliSecs()
    Global loops:Int

	loops = 0
	While (MilliSecs() > next_game_tick And loops < MAX_FRAMESKIP)
		Game.Update
		next_game_tick:+SKIP_TICKS
		loops:+1
	Wend

        Game.Render


I fail to see what 'loops' is doing also the next_game_tick seems all wrong, should it not be millisecs() + SKIP_TICKS?


H&K(Posted 2015) [#2]
While (MilliSecs() > next_game_tick) And (loops < MAX_FRAMESKIP)

Although it happens like once every ridiculous number of cycles, it is very bad form not to deal with when MilliSecs resets to zero, so GetTickCount is doing that.

Loops is just a loop counter to see how many time the logic loop has run, its "loops < MAX_FRAMESKIP" just say "if we have done this less times than we should, then do it again"


Brucey(Posted 2015) [#3]
Actually, MilliSecs() will go negative if your PC has been on long enough - on account of BlitzMax Int being signed, and the real value Millisecs() being unsigned...


H&K(Posted 2015) [#4]
lol

I would in my defence point out that not both listings are BMax