Archived

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

LARGE_INTEGER troubles...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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. :

StartTime.QuadPart = iCount.QuadPart/iFreq.QuadPart;
FPS[9] = iEndTime.QuadPart - StartTime.QuadPart;

Share this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Or you could derive a class(without member variables) from LARGE_INTEGER, and add your own operator overloading.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 second

void 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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
You may want to check these links out...

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

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

Share this post


Link to post
Share on other sites