Archived

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

How to get "the change in time"??

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

Recommended Posts

At the moment I''m workin'' on a cool mecha simulation game. I would like to get the change in time since my last animation frame, what is the best function to do this?? At them moment I''m using the function timeGetTime(), which retrieves number of clock cycles that have pasted since the last time the function was called. I''m not sure if this is the best way, is there a much more acturate method??

Share on other sites
Yes, timeGetTime() is a very good function to use for simulating time. It doesn''t return the time since it was last called, it returns the number of msec that have elapsed since Windows started.

Anyway, have a DWORD variable keep track of the last time you changed frames. Do soemthing like this:

DWORD time = timeGetTime();

if ( time - mechLastFrameChange() > 100 )
{
mechChangeFrame();
mechSetLastFrameChange( time );
}

You can fiddle with the number in the if statement (100) to whatever looks good.

That should do it...

Share on other sites
So timeGetTime() is the function most people use when they program games??? Are there any other functions that are more acturate???

Share on other sites
I think the method most games use is the QueryPerformanceCounter() functions, they''re much more accurate. This will only work however if your processor has a performance counter, so to support all computers you should have a fallback method.

Another thing to note is that apparently you sometimes get the performance counter skipping forward, I''ve never experienced this but I know that there is a workaround method by using to different timers, this is documented somewhere on the web by Microsoft by I can''t remember where.

Share on other sites
You could use QueryPerformanceFrequency and QueryPerformanceCounter for a high-resolution timer.

  class HighResolutionTimerException{public:   HighResolutionTimerException()    : mdwLastError(::GetLastError())   {   }   DWORD GetLastError() const { return mdwLastError; }private:   DWORD mdwLastError;};double GetHighResolutionFrequency(){   LARGE_INTEGER  liPerformanceFrequency;   if (!QueryPerformanceFrequency(&liPerformanceFrequency))   {      throw HighResolutionTimerException();   }   else   {      return (double) liPerformanceFrequency.QuadPart;   }}double GetHighResolutionTime(){   static double  dPerformancePeriod = 1 / GetHighResolutionFrequency();   LARGE_INTEGER  liPerformanceCount;   if (!QueryPerformanceCounter(&liPerformanceCount))   {      throw HighResolutionTimerException();   }   else   {      return (double) liPerformanceCount.QuadPart * dPerformancePeriod;   }}

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632997
• Total Posts
3009799
• Who's Online (See full list)

There are no registered users currently online

×