• ### Announcements

#### Archived

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

# LARGE_INTEGER troubles...

## Recommended Posts

im getting these errors in my FPS code, and I dont know what to do... C:\Windows\Profiles\Elijah\My Documents\C++\Shatterblox\Jester.cpp(320) : error C2676: binary '/' : 'union _LARGE_INTEGER' does not define this operator or a conversion to a type acceptable to the predefined operator

// Frames per second

void CJester::StartFPS()
{
LARGE_INTEGER iCount;
LARGE_INTEGER iFreq;

if(!QueryPerformanceFrequency(&iFreq) || !QueryPerformanceCounter(&iCount))
{
Log("QueryPerformanceFrequency() or QueryPerformanceCounter() Failed.");
PostQuitMessage(-1);
}

StartTime = iCount/iFreq;
}    
And in some other code... (but both are LARGE_INTEGERS) C:\Windows\Profiles\Elijah\My Documents\C++\Shatterblox\Jester.cpp(336) : error C2784: '_D __cdecl std::operator -(const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce t emplate argument for 'const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'union _LARGE_INTEGER' C:\Windows\Profiles\Elijah\My Documents\C++\Shatterblox\Jester.cpp(336) : error C2676: binary '-' : 'union _LARGE_INTEGER' does not define this operator or a conversion to a type acceptable to the predefined operator

FPS[9] = iEndTime - StartTime;

Edit: wrong errors [edited by - elis-cool on October 22, 2002 4:07:46 AM]

##### Share on other sites
LARGE_INTEGER is a union of a 64-bit integer and a pair of 32-bit integers. If you want to perform 64-bit arithmetic on one you need to select the 64-bit int from inside the union, e.g. :

##### Share on other sites
hmmn... ok so is this how everyone else calculates their frames per second?

##### Share on other sites
For calculating my FPS I am usually not too concerned about absolute accuracy, so I just use GetTickCount().

##### Share on other sites
You can cast to an __int64.

##### Share on other sites
quote:
Original post by elis-cool
hmmn... ok so is this how everyone else calculates their frames per second?

i have QPC/QPF overloads for __int64''s.

##### Share on other sites
I use rdtsc, time the CPU (use that as my divisor), use the FPU to perform the division, then apply a simple one-pole low-pass filter before converting it to acsii using a custom ftoa routine (to avoid the global MT CRT mutex, and to handle special cases; e.g. Inf, NaN) before sending it through my texture-caching font blitter and out into the world.

When I started, my goal was to update the frame-rate every frame - now that I'm done I can't recall why I ever wanted to do that. \$#%!'s fast... (as long as you have a multi-texture capable card).

The frame-rate bobbled around so much that you couldn't read it. I had to add the filter to stablize it - if I start to feel exceedingly frame-rate anal again I may go back and change it to a multi-pole filter (might be able to get another stable half-decimal-place).

It's nice to know that your frame-rate is 67.3 +/- 0.1 Hz

Btw, calling Queryxxxx takes ~50us (I think it's a kernel gate call or something - takes forever).
You might want to call QueryxxxFreq once and remember the result.
Also, QueryxxxFreqtakes can take a friggin' eternity on 2k if the machine supports 'power conervation modes' because it checks for to see if the clock-rate has been reduced. We stopped using it when we switched from NT4 to 2k, so I don't know how XP behaves.

[edited by - Magmai Kai Holmlor on October 22, 2002 7:27:43 PM]

##### Share on other sites
Thanks guys, so ok, ill call the query performance freq once and use that, then the counter and the start and end of each frame... and then just use the .QuadPart stuff... or would this be agood place to flex my asm skillz, eg with rdtsc etc?

##### Share on other sites
ok, so I changed the stuff, but its still not working, it seems to be outputing 0 or 10... hmmn...

  class CJester{//...        void StartFPS();	void EndFPS();	int GetFPS(){return (int)iAveragedFPS;}//...        float FPS[10];	LARGE_INTEGER StartTime;	LARGE_INTEGER iClockFreq; // calculated at startup	float iAveragedFPS;};// Frames per secondvoid CJester::StartFPS(){	LARGE_INTEGER iCount;	QueryPerformanceCounter(&iCount);	StartTime.QuadPart = iCount.QuadPart/iClockFreq.QuadPart;}void CJester::EndFPS(){	LARGE_INTEGER iCount;	LARGE_INTEGER iEndTime;	QueryPerformanceCounter(&iCount);	iEndTime.QuadPart = iCount.QuadPart/iClockFreq.QuadPart;		for(int i = 0; i < 9; i++){FPS[i] = FPS[i+1];}	FPS[9] = iEndTime.QuadPart - StartTime.QuadPart;	iAveragedFPS = 0;	for(int k = 0; k < 10; k++) iAveragedFPS += FPS[k];	iAveragedFPS /= 10.0f;	iAveragedFPS = 1.0f/iAveragedFPS; // Calculate and store the FPS for next frame}

##### Share on other sites
ok, nm, I seem to have it working now...

##### Share on other sites
Ok... for some reason my FPS has decreased now... before it was running at the monitors refresh rate (75Hz), but now its only running at ~68 FPS... could all the calls to QueryPerformanceCounter be slowing it down? but 50us isnt very long at all.. maybe its all the LARGE_INEGER math... anyone have any clues?

##### Share on other sites
Don''t forget that you are doing an integer division between the Quadparts. Cast it to double instead, or implement your own division algorithm.

##### Share on other sites
You may want to check these links out...

http://www.mvps.org/directx/articles/selecting_timer_functions.htm

• ### Forum Statistics

• Total Topics
627731
• Total Posts
2978831

• 10
• 9
• 21
• 14
• 12