Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / What is the easiest way to get time difference

Author
Message
MxM111
15
Years of Service
User Offline
Joined: 3rd Oct 2009
Location:
Posted: 22nd Oct 2009 00:36
Hello,
Can anyone say what is the easiest way to get time difference between two execution points of the program? I am not talking about profiling but about actual in-game time, so that code was aware how much time past since last time it checked.

The thing is that I just want to get a single integer or float number, which is time passed in milliseconds (or any other units of time).
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 22nd Oct 2009 00:53
startTime = dbTimer( )
elapsedTimer = dbTimer( ) - startTime;

MxM111
15
Years of Service
User Offline
Joined: 3rd Oct 2009
Location:
Posted: 22nd Oct 2009 17:52
Does dbTimer reset itself from time to time? It can not go to infinity, right? In this case would elapsedTimer show wrong time?
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 22nd Oct 2009 18:12
it does (Assuming it works the same way as the DBPro timer) but you have to leave the pc on for something like 25 consecutive days before it goes back to zero; so its not really a problem.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 22nd Oct 2009 19:15
Using luke810's above code, the elapsedTimer value will always give you correct values no matter how long you leave your PC running for(assuming startTime is an integer), if you want to know why then read up on how two's complement works.

MxM111
15
Years of Service
User Offline
Joined: 3rd Oct 2009
Location:
Posted: 23rd Oct 2009 02:02
dark coder,

I am a bit new to vc++, but are you saying that adding two large integer numbers in vc++ does not generate overflow error, but instead gives negative number (complimentary negative number, whatever the right terminology)?
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 23rd Oct 2009 12:07
No, I'm saying this works as expected:



Login to post a reply

Server time is: 2024-11-20 11:29:59
Your offset time is: 2024-11-20 11:29:59