Skip to main content
gamedev.net
🔒 Locked

Speed Control

Started by Oniera Oct 11, 2000 at 5:07 PM 2 replies 250+ views
Original Post
Oniera
Oniera
I''d be interested in people''s methods of controlling the speed of their 3D programs. By this I mean making sure that the game runs at the same speed regardless of the frame rate. Demetrios Georgeadis Director/Programmer Oniera Software Artists

www.oniera.com

Demetrios GeorgeadisDirector/ProgrammerOniera Software Artistswww.oniera.com
BrianH
BrianH
You should decouple your graphics rendering and your game logic. I will give you an example...

//coupled.. not good //////
GameMain()
{
DoLogic();
DoRendering();

WaitFor30FPS();

}
///////////////////////////

this is not a good way, since your DoLogic() function is called only 30 times per second. Instead, what I do it allow the GameMain() run as fast as possible - take out the WaitFor30FPS().

Then, the timing code should go into the various objects and functions used in your DoRendering() function.

What I do is allow the rendering to be done as fast as possible and have all my animated objects interpolate their values based on how much time has passed since the last cycle.

example

///////////////////
SPRITE::Draw()
{
//dt is the time passed since the lat cycle
float distx = velocityx*dt;
float disty = velocityy*dt;

posx += distx;
posy += disty;

//blit at new location
Blit((int)posx,(int)posy);
}

This method will provide the smoothest possible movement for whatever machine its running on.

Hope this helps,

BrianH
Oniera
Oniera
Hi Brian,

I do something similar, but I''ve been getting a jerk motion when my objects reach a fast speed.

What I do is, when an object is given the command to move (in distance per second), I store the clock time when the command is called, then after I draw my graphics I calculate how much time has passed since the command was called, and divide the speed/sec accordingly.

Works well, but objects jerk when they travel quickly...


Demetrios Georgeadis
Director/Programmer
Oniera Software Artists

www.oniera.com


Demetrios GeorgeadisDirector/ProgrammerOniera Software Artistswww.oniera.com
JOL
JOL
Always deal with deltaTime. thats the only way to do things, I mean why lock your framerate if the cpu is fast enough, or why let the player with a slow cpu play a slower game. compute movement and all kind of animation due to your deltatime.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work

Topic Locked

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

Sign in to reply to this topic.