🔒 Locked
Loading Time
Advertisement
Original Post
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?
No, thats not normal, some more information about your timing system would be nice though. From the sounds of it, your timer isn''t getting initialized correctly from the get-go, but I would need to know more about your system to get a correct answer.
Trent Polack
Burnt Fur Entertainment
trent@codershq.com
Author of Focus on 3D Terrain Programming
Trent Polack
Burnt Fur Entertainment
trent@codershq.com
Author of Focus on 3D Terrain Programming
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!
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!
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.
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.
You could get a better frame-rate reading by doing this:
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
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
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement