Archived

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

Timers / Timing

This topic is 5302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I''ve found a couple of decent timers / timing code, but its always so damn complex for me to learn from. Like I''ll get some nice code, but then it''ll be for some complex 3D Polygon Vector Intersection Math simulation or something =P Could anyone post some timer code for just a simple DOS Window (or CLI or whatever WinXP calls it), that just prints something every 2 seconds or something. Just something nice and easy to understand, so I can follow it. Its really hard to get something like Tetris or Pong going without any timing, and I''m too stupid to learn from my aforementioned 3D Polygon Vector Intersection Math simulation =P Thanks.

Share this post


Link to post
Share on other sites
DOS timers use the DOS IDLE interrupt (int 28H), and it is a pretty complex thing, actually. I am not sure that newer Windows OSes like you messing with those interrupts, and it gets complicated. I wrote some code for Win95 a couple of years ago, I can dredge it up if you really want me to, but right now I am not at home. Let me know.

Share this post


Link to post
Share on other sites

Something like this ... Just off the top of my head

long lastTime = GetTickCount();
while(1)
{
long now = GetTickCount();
if (lastTime < (now - 1000) )
{
// one second has passed .. Do something
lastTime = now;
}
else
Sleep(1);
}

Sleep(1) will allow other processes to run, it essentially just gives up the time slice to others ...

I can''t remember what GetTickCount returns (DWORD I think?) and what library it''s in. You could also use timeGetTime(), but I can''t remember specifics on that one either ...

I don''t consider this the best method for game programming, because it makes no determination if 2 - 3 seconds have passed, hopefully not, but there is a better algo:

Everytime thru the loop, check the time and move your objects based on how much time HAS passed, this implies that instead of your moving each object a fixed step everytime thru the loop, each object has a velocity that you multiply by the timePassed to find out how far to move it ...

Cheers .. goodluck
J.







Share this post


Link to post
Share on other sites