# Speed & Timing issues

Anyone know of a good resource I could check out to get better at timing my applications?

That is: I want to do basic things, like keep the “speed” of the world constant, no matter what the framerate might be (wether it was 10 fps or 1000 fps). I know this is simple stuff, I’ve just never been exposed, and… well, I’m trying to be, now.

So far, my (ameteur) methods seem far too unreliable. Though my questions are far too general to ask for specific help, here… I’m looking for a good nudge in the right direction.

I don’t know of any good internet source for that…but I could explain how its done:
Basically within your main game loop…you poll the timer and find out how much time elapsed and use that for scaling all your movement. If you don’t know how to poll or use the timer I can explain that also… Good Luck!

I understand the theory a’right, but my implementation leaves a bit to be… desired, I think. ;>

## This is how I’m (currently) getting the time:

double rcvutils_getTimeDouble()
{
struct _timeb time_struct;
_ftime( &time_struct);

``````	return (time_struct.time + ((double)time_struct.millitm/1000));
``````

## }

So, yeah, in the main game loop, I just use that func to grab, compare, and save the current time.

Seems to work just fine if I’m testing for the passage of time (as in: “Has half of a second passed, yet?”), but things get really wierd if I start using that func (and it’s product) for calculations (ex: “go this_far forward since only this_much time has elapsed”). Is the precision on doubles just too much?

Heh… if you hadn’t guessed, this is my first time even touching timing… am I anywhere close to where I need to be, or have I created a monster?

-Rayme

[This message has been edited by rcvinson (edited 07-26-2000).]

Lets see…I guess you need to get the time elapsed value as a decimal(so like make sure its small somehow) then that is your scaler…multiple all object movements by that. It should be a very small number anyways because most systems run over 1fps! so that way say .0001 ticks(arbitrary) has passed…all object movement amounts are multiplied by this…but say .1 ticks have gone by then u multiple by this…here is how it would work:

gettime(currtime)
elapsed = currtime - lasttime
lasttime = currtime

so now elapsed would be the scalar which u multiply by…btw…gettime() is just my way of saying fill currtime with the current time.

Go check flipcode’s COTD ( Code of the day ).
They have a good timing class, use it =).

-Marcus “Cruxis” Lenngren - nop

A simple way to do timing is to get the time since last frame (as blide stated) and use this time as a scalar. The you store all movements as vectors (or whatever) with length of the distance it moves in one second. Then muliply this “vector” with your scalar.

If your movementvector mv=(1, 1, 0) (means it will move 1 unit in x and y in one second), and if elapsed time is 0.5 seconds, your movementvector will be 0.5*mv=(0.5, 0.5, 0). Then move your object 0.5 units along the x- and y-axis.