timing

Associate
Joined
10 Nov 2007
Posts
809
Location
Southampton
hi guys me again

im currently writing an algorithm to control timing and frame rate

i have a method which initializes the time which works fine then i have a method which gets the current time i i have an uninitialized __int64 called tune then i call queryperformancecounter() from win.h then in my return statement i cast time as a double and divide that by a global variable time frequency which is set to 600 (not sure about this variables value) which is then subtracted from another gloabal variable called time begin which is set to 0 to start with then in another method which loops all the time the program is running i first of set a double to = the result of CurrentTime() then say if that is greater than a variable call another method this loop should always be true but it isn't

any ideas?
 
Can you post some more information, preferably the relevant code? I don't think even a clairvoyant could work out what is going on from that description.

I gather there are various variables being manipulated and methods called then we get to the problem part.

then in another method which loops all the time the program is running i first of set a double to = the result of CurrentTime() then say if that is greater than a variable call another method this loop should always be true but it isn't

Code:
void someMethod() {
    Double tmp = CurrentTime();

    loop forever {
        if (tmp > anotherMethod()) {
            //the should always be true branch
            //do stuff
        } else {
            //should not happen
        }
    }
}

You need to check whether
anotherMethod() is returning too high a value
tmp is too low
logic / syntax is wrong in your method

Print out the variables and check their values are what you expected. Then work back through the code and you should be able to determine at what point things went wrong.

Is your app multithreaded? Could be a concurrency issue with one thread overwriting global variables before the other can access them.
 
re

global variables
Code:
double TimeFrequency = 600;
double TimeBegin = 0;


Code:
	double getCurTime()
{
	__int64 time;
	QueryPerformanceCounter((LARGE_INTEGER*)&time);//returns -1 if it succeeds
	
	return ((double)time / TimeFrequency) - TimeBegin;
	
}

then in loopforever

Code:
curTime = getCurTime();

double framerate = 0.33333333//hardcoded 

if(curTime-lastDisplayUpdate>framerate)
{
method()
}

any ideas why it never hits the loop ive worked out the maths on a calc and providing that is correct i dont see why it does not work
 
You need to use QueryPerformanceFrequency to get the frequency of the counter, then do something like

Code:
//in initialisation
LARGE_INTEGER freq;
QueryPerformanceFrequency (&freq);

//returns elapsed time in seconds since start
double elapsed (LARGE_INTEGER start) {

    LARGE_INTEGER now;
    QueryPerformanceCounter (&now);
    return double(now - start) / double(freq);
}
 
Back
Top Bottom