Archived

This topic is now archived and is closed to further replies.

chox

How can I determine number of loop counter between state?

Recommended Posts

How can I determine number of counter in game loop for take some actions from the different CPU speed ? example : Non players have their state, they have to loop until some values and then go to next state. But the same values of loop counte makes different time consumption for difference CPU speed. How can I fix it ? Thank you very much

Share this post


Link to post
Share on other sites
I think you''re approaching the whole "framerate issue" backwards.

You don''t want to try and time things when processing your frames. Instead, you want to let the game run as fast as it can, and then time how fast that particular frame took. Use this newly calculate value to process things next frame.

For example :

float Frametime; // in milliseconds
while(game_is_running){
process_game_stuff(Frametime);
render_frame();

Frametime = calculate_THIS_frametime();
}

You''ll probably want to add a framerate cap as well. So if your game is running too fast, just cap it at 60 fps (ie, if its faster, just physically _wait_ until 1/60th of a second has passed total for the frame). Also, if your framerate is really low, bash Frametime by hand to something reasonable like 1/4 of a second so that your game "chugs" its way along when it needs to.

Share this post


Link to post
Share on other sites