Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

GameLoop source review...

Started by AquaMacker Jul 16, 2012 at 7:39 AM 2 replies 1.1k views
Original Post
AquaMacker
AquaMacker

[font=verdana, geneva, sans-serif]Hi~~~[/font]

[font=verdana, geneva, sans-serif]Today is hard day [/font]

[font=verdana, geneva, sans-serif]Sooooo hard :([/font]

[font=verdana, geneva, sans-serif]This is GameLoop the best post !!!!!
http://www.koonsolo.com/news/dewitters-gameloop/ [/font]

[font=verdana, geneva, sans-serif]In this post, "Constant Game Speed independent of Variable FPS"[/font]

[font=verdana, geneva, sans-serif]const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;[/font]

[font=verdana, geneva, sans-serif]while ( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP )
{
update_game();[/font]

[font=verdana, geneva, sans-serif]next_game_tick += SKIP_TICKS;
}[/font]

[font=verdana, geneva, sans-serif]Please Look bold...[/font]

[font=verdana, geneva, sans-serif]I don't understand...[/font]

[font=verdana, geneva, sans-serif]What does mean "GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP" ?[/font]

[font=verdana, geneva, sans-serif]How many "Update()" call ?[/font]

[font=verdana, geneva, sans-serif]Why ? next_game_tick += SKIP_TICKS;(==40 Tick)
Why add 40 tick ?[/font]

[font=verdana, geneva, sans-serif]I don't understanding really...[/font]

[font=verdana, geneva, sans-serif]I do not know how to be to find information.[/font]

[font=verdana, geneva, sans-serif]Please let me us.....
Please.....[/font]

[font=verdana, geneva, sans-serif]It's so hard......[/font]

eppo
eppo
The idea is to let the games logic/physics run at a fixed (say 40 ms) interval and the renderer at the best it can come up with (say it manages only 5 fps).

So whenever rendering is finished, logic-time needs 5 steps to overtake (you make the assumption the next frame will take 200 ms to render as well).

Perhaps you find this a bit more readable:
[source lang="java"]
renderTimePos = 0;
logicTimePos = 0;
logicTimeStep = 40;

loop{

render_game();

//rendering took 200 ms
renderTimePos += 200;

while(logicTimePos < renderTimePos) update_game(), logicTimePos += logicTimeStep;
}
[/source]
L. Spiro
L. Spiro
I have written an article that tries to explain this concept a little more clearly, with graphics to make it clear.
http://lspiroengine.com/?p=378

If you can read it you should be able to understand everything.
Because it is long, I will tell you to look mostly at the section called “But How Can That Work? Don’t I Need to Know its Next Position, Not its Last Position?” and the graphic in that section.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
AquaMacker
AquaMacker
[font=verdana, geneva, sans-serif]

@eppo, @L.Spiro[/font]

[font=verdana, geneva, sans-serif]

Really Thanks you so much.[/font]

[font=verdana, geneva, sans-serif]

I Will try very hard to read and try to solve the problem ^^a[/font]

[font=verdana, geneva, sans-serif]

Thanks more ~~~[/font]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.