I'm about to throw my computer out the window

Started by
21 comments, last by MaulingMonkey 18 years, 10 months ago
Visit this thread from VbForums. I just told someone else in a thread from yesterday about this. Its an old thread that I started almost a year ago and someone bumped it asking for a QueryPerformanceTimer class.

The download is near the bottom of the thread, feel free to download and use the class, credit me for your timer :) Actually a timer class is pretty standard, no sense in re-inventing the wheel, so enjoy.
http://vbforums.com/showthread.php?t=305885
Advertisement
If you are using a really old computer then it may not support QueryPerformanceCounter, and in that case I think you would get 0. The reason that you divide by the perfancefrequency is because the counter will be different on different CPU's. So divide by the frequency then multiply by 1000 to get milliseconds.
Go on an Intense Rampage
// first, a minor change (this is not your problem of course:

struct sFrameTime
{
LARGE_INTEGER LastValue;
LARGE_INTEGER CurrentValue;
static LARGE_INTEGER TicksPerSecond; // don't store this PER SAMPLE, it never changes
float ElapsedTime;
} FrameTime;

// now a real change:

struct sFrameTime
{
LARGE_INTEGER LastValue;
LARGE_INTEGER CurrentValue;
static LARGE_INTEGER TicksPerSecond; // don't store this PER SAMPLE, it never changes
LARGE_INTEGER ElapsedTicks;
} FrameTime;

/*====================== Calculate Frame Time ======================*/
QueryPerformanceCounter(&FrameTime.CurrentValue);
FrameTime.ElapsedTicks.QuadPart=FrameTime.CurrentValue.QuadPart-FrameTime.LastValue.QuadPart;
FrameTime.LastValue =FrameTime.CurrentValue;
/*==================================================================*/

then see if the value is still zero.

Also, the REAL way to solve this kind of problem is easily done with a debugger, just break into the debugger and look and see if Current and Last are exactly the same before your subtraction, if so, the problem is higher up (or non-existent), if not, the problem is with your subtraction, assignment, or display ...
thanks dude I appreciate it, but the frustrating part is that i can't get my code working, does anyone have any idea why ElapsedTime is always coming out 0 ?
Did you miss my post??
Download the class timer wrapper and compare it to your code to find your error. Simple as that.
xai - thanks a bunch, that fixed it
except for the static part, i now get:
game.obj : error LNK2001: unresolved external symbol "public: static union _LARGE_INTEGER sFrameTime::TicksPerSecond" (?TicksPerSecond@sFrameTime@@2T_LARGE_INTEGER@@A)


but it doesn't matter because there will only be one 'sample' as you put it, there is only one object of that struct


Halsafar - thanks for your time too, i appreciate it
Quote:Original post by PcChip
xai - thanks a bunch, that fixed it
except for the static part, i now get:
game.obj : error LNK2001: unresolved external symbol "public: static union _LARGE_INTEGER sFrameTime::TicksPerSecond" (?TicksPerSecond@sFrameTime@@2T_LARGE_INTEGER@@A)


To fix this, in your header, have the structure as per usual:

struct sFrameTime
{
LARGE_INTEGER LastValue;
LARGE_INTEGER CurrentValue;
static LARGE_INTEGER TicksPerSecond; // don't store this PER SAMPLE, it never changes
float ElapsedTime;
} FrameTime;

In a source file, have:

#include "......"
LARGE_INTEGER sFrameTime::TicksPerSecond;


HTH
actually that struct isn't in a header, it's in the main cpp file at the top
Quote:Original post by PcChip
actually that struct isn't in a header, it's in the main cpp file at the top


It should be in a header if you want to be able to use it in multiple cpp files.

In any case, in order to get the static variable to work, you simply need to also declare it seperately, like so:

struct A {
static B C;
};

B A::C;

You will get multiple definition errors if the "B A::C;" line is in a header included by multiple CPP files. Although I'd generally advise "struct A { ... };" to be in a header, not doing so shouldn't cause errors.

HTH
now I'm trying to find out the number of seconds that have elapsed:

FrameTime.Seconds = ((float)FrameTime.ElapsedTime.QuadPart /
(float)FrameTime.TicksPerSecond.QuadPart);

[FrameTime.Seconds is a float]

i keep getting all kinds of results, including some negatives :(
I've even looked at the code mentioned from that other thread and it's not helping me, what am I doing wrong ??

This topic is closed to new replies.

Advertisement