Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading Time

Started by Dovyman Dec 16, 2002 at 7:23 PM 8 replies 500+ views
Original Post
Dovyman
Dovyman
When I first start my program, it reports the framerate as 1, even when things are already being rendered, then suddenly after about 5 seconds it jumps up to the real frame rate. I use the frame rate to calculate synchronization stuff so thats a problem. I can easily fix that with some type of loading screen, but I''m wondering if thats normal, has anybody elsed experienced similiar issues? is it most likely a bug or just some lag due to initialization?
Dovyman
Dovyman
I''m running a 850mhz Athlon with a 32mb GeForce2
Heres some of the code:

//-----------------------------------------------------------------
// GameLoop()
// Update variables, handle input, render
//-----------------------------------------------------------------
int GameLoop()
{
//sync frames
FrameCount();

//render all graphics
Render();

//dinput stuff
HandleInput();

return S_OK;
}

//-----------------------------------------------------------------------------
// FrameCount()
// Compute current framerate, and deviance from set optimum
//-----------------------------------------------------------------------------
void FrameCount()
{
INT64 NewCount = 0; // The current count
static INT64 LastCount = 0; // The last count
INT64 Difference = 0; // The differnce since the last count

// Get the current count
QueryPerformanceCounter( (LARGE_INTEGER*)&NewCount );

// If the count is 0 then this system does not have
// high performance timers
if( NewCount == 0 )
SetError( "The system does not support high resolution timing" );

// Increase the frame count
g_FrameCount++;

// Compute the difference since the last count
Difference = NewCount - LastCount;

// If more than a second has passed
if( Difference >= g_Frequency )
{
// Record the number of elapsed frames
g_FrameRate = g_FrameCount;
// Reset the counter
g_FrameCount = 0;

// Update the last count
LastCount = NewCount;
}

//used for synchronization
g_FrameDeviance = g_FrameRate / OptimumFrameRate;
}

Help!

AndyTX
AndyTX
One problem could be that the first time through your frame loop, "LastCount" is going to be 0, which produces an obscenely high difference between "NewCount" and "LastCount". This in turn will produce a misreported low frame rate.

I''d suggest a special case for the first time that you come through... perhaps just checking for if "LastCount == 0" then just ignore this frame and setup "LastCount" to the "NewCount"... that or initialize "LastCount" to the current count, but this could mess up a bit if you have lots of loading to do after the initialization of the counters, but before the first frame.
mdias
mdias
You could get a better frame-rate reading by doing this:


  
float g_FrameRate = 0.0f;

void RenderFrame()
{
LARGE_INTEGER Temp_FrameRate;
QueryPerformanceCounter( &Temp_FrameRate );

... // Render all your stuff


LARGE_INTEGER New_FrameRate;
QueryPerformanceCounter( &New_FrameRate );
g_FrameRate = 4000000.0f /(float)(New_FrameRate.QuadPart-Temp_FrameRate.QuadPart)
}


This way you can measure frame-rate every frame and the result
is pretty good... I use it in my 3D Engine in it works very well.

KaMiKaZe
krumms
krumms
Kamikaze, where on earth did you pull that number - 4000000.0f - from??????

Tom L
refrain_from_stupidity( &me );
billybob
billybob
it must be the QueryPerformanceFrequency() result on his computer. replace that with a number that gets initilazed to QueryPerformanceFrequency()
mdias
mdias
quote:

it must be the QueryPerformanceFrequency() result on his computer. replace that with a number that gets initilazed to QueryPerformanceFrequency()



Yeah, that's it, sorry I forgot to tell you about it
I had replaced it on my code for debuging purposes and I forgot
to put the QueryPerformanceFrequency() value on it again...
So the new code is:

    
float g_FrameRate = 0.0f;
LARGE_INTEGER g_Frequency;
QueryPerformanceFrequency(&g_Frequency)

void RenderFrame()
{
LARGE_INTEGER Temp_FrameRate;
QueryPerformanceCounter( &Temp_FrameRate );

... // Render all your stuff


LARGE_INTEGER New_FrameRate;
QueryPerformanceCounter( &New_FrameRate );
g_FrameRate = (float)g_Frequency.QuadPart/(float)(New_FrameRate.QuadPart-Temp_FrameRate.QuadPart)
}


KaMiKaZe

[edited by - Kamikaze15 on December 18, 2002 10:41:09 PM]

[edited by - Kamikaze15 on December 18, 2002 10:50:12 PM]
Dovyman
Dovyman
Thats it I''m burning my copy of Zen of D3D, that book hasn''t given me one useful piece of code yet. Thanks for helping me sort out my timing issues guys.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.