Archived

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

ByteMe95

Queryperformancecounter? cant find a clean cut solution to bumpy animation

Recommended Posts

ByteMe95    122
I just read through a good 10 articles on gamedev about adjusting sprite velocities so they are the saem over different computers. I ahve always used timeGetTime() but I realize that my animations are very bumpy occasionally, looks like something jumps back at some points, probably low resolution of the tiemr from what I''ve read. I had used: g_LastTime = g_Time; g_Time - timeGetTime(); FrameRatio = (g_Time - g_LastTime)/(float)FRAMERATE; where FRAMERATE is say 60 and then i would uise frameration throughout all my code. Now I tried: QueryPerformanceCounter(&g_Time); FrameRatio = (g_Time.LowPart - g_LastTime.LowPart)/((float)FRAMERATE); That made my FrameRatio way too high, so I dvidied by another 1000, but this is all just guess work, so how should I do it properly? I just want smooth animations!! ByteMe95::~ByteMe95() My S(h)ite

Share this post


Link to post
Share on other sites
Jason Zelos    211
timeGetTime() is accurate to 10ms, so it should be adequate for most applications. Use a float for frameratio (DeltaTime) and you shouldn't have any problems.

QueryPerformanceFrequency(Freq as Ulong) returns the number of ticks per second( or ms ?), which differs from machine to machine. Don't forget that the Performance Counter is not guaranteed to be availible on all computers.

,Jay

Edit: Query not Get.

[edited by - Jason Zelos on March 18, 2002 5:50:45 PM]

Share this post


Link to post
Share on other sites
Jason Zelos    211
I looked at your code again. I use 1/FPS to get DeltaTime and call my Physics code each iteration using Speed*DeltaTime, where Speed is distance over 1 second, set individuly for each Pawn.

How you get FPS is up to you, I simply count Page Flips and reset DeltaTime each second or nearest using:

If (timeGetTime()>LastTime)
{
FPS = FrameCounter;
FrameCounter = 0;
DeltaTime = 1 / FPS;
}

,Jay

Share this post


Link to post
Share on other sites
ByteMe95    122
Alimonster, how do i use queryperformancefrequency together with counter to get rid of the guesswork?

Jason, isn''t ever ycomputer with windows gauranteed to have it?

I''m assuming the reason for the bumpy animations is the tiemr resolution, I may be wrong. All I know is that if I dont multiply my velocities by FrameRatio and put in a value that runs at a good rate on MY machine, the animation is smooth just the way I want it to be.

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
Jason Zelos    211
We crossed posts.

Freq is ticks per second (or milisecond, I forget), so:


  

void init()
{
QueryPerformanceFrequency(Frequency);
}

void Elapsed(ETime as unsigned long) as bool
{
unsigned long Ticks;
static unsigned long OldTime;

QueryPerfomanceCounter(Ticks);

If (OldTime-(Ticks/Frequency)>ETime)
{
OldTime=Ticks/Frequency;
Elapsed = true;
} else Elapsed = false;

}



I would write a timer class (in C++ or VB).

But the performance counter is a hardware device, I think all x386 PC''s have them but they are not required to do so.

,Jay

Share this post


Link to post
Share on other sites
a person    118
you should be using (1000/60) or 16.66666666666 instead of 60. since you must divide the number of milliseconds that past by the number of milliseconds in a frame. NOT by the number of milliseconds that past by the number of frames in a second. also FrameRatio better be a float, which it seems to be by the code.

QueryPerformenceCounter will NOT fix your animations problems. dont bother using it just yet, since you still dont understand completely how the timing code and interpolation should work.

btw you are sing it completely wrong, you must first call QueryFrequencyCounter() to get the the number to divide by to get the number of milliseconds past instead of number of ticks. it is a bit more complicated then using timeGetTime(). also you cant just subtract the lowparts, you MUST subtract the entire 64bit number otherwise you are subtracting meaningless numbers.

Share this post


Link to post
Share on other sites
Gorg    248
A little class for you, it works under unix and windows

You might have to change WIN32 by _WIN32 depending on your compiler

    

//------------------HEADER FILE-----------------------------

#ifndef TIMING_H
#define TIMING_H



class Timer
{
protected:

#ifdef WIN32
double one_overf; //1/freq

#endif

public:
Timer(void);

//give current time in seconds

double GetTime() const;
};


#endif

//-------------------SOURCEFILE------------------------

#ifdef WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <unistd.h>
#endif

#include "Timer.h"


#ifdef WIN32
Timer::Timer(void)
{

__int64 freq;


QueryPerformanceFrequency((LARGE_INTEGER*)&freq);

one_overf = 1.0/(double)freq;


}//Timer::Timer();




double Timer::GetTime() const
{
__int64 end;

QueryPerformanceCounter((LARGE_INTEGER*) &end);


return ((double)(end*one_overf));
}

#else //Unix


Timer::Timer(void)
{


}



double Timer::GetTime() const
{
const double val = 1.0/1000000.0;

struct timeval curtime;
gettimeofday(&curtime, NULL);

return static_cast<double>(curtime.tv_sec) +
static_cast<double>(curtime.tv_usec)*val;

}

#endif



Example :

  
Timer t;

double start = t.GetTime();
doSomeAction();
double end = t.Gettime();

std::cout << "time of some actions is : " << end - start << " secs";


The version under linux is as precise as Queryperformance counter.

[edited by - Gorg on March 19, 2002 1:57:51 AM]

Share this post


Link to post
Share on other sites
ByteMe95    122
Gorg, I just compiled and ran that, it returns the time in seconds which doesn''t help, I need time in 1/1000 of second at least, I would think

Share this post


Link to post
Share on other sites
Gorg    248
I know. That is what it says it does!

You can multiply by a 1000 the result you get from Gettime()!

Or you can change GetTime() to return in ms.


It is precise enough though. You get close to nano second precision which is WAY more than what you need for game timer..





[edited by - Gorg on March 19, 2002 1:29:13 PM]

Share this post


Link to post
Share on other sites