Averaging frame times.
This commit is contained in:
parent
0e55949309
commit
babbe93479
|
|
@ -4,6 +4,7 @@ AlignAfterOpenBracket: AlwaysBreak
|
|||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AlignCompound: true
|
||||
AlignFunctionPointers: true
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
|
|
|
|||
|
|
@ -117,9 +117,15 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
|||
misc.previousCounter = currentCounter;
|
||||
|
||||
{
|
||||
double deltaTimeMs = deltaTime * 1000.0;
|
||||
double fps = 1.0 / deltaTime;
|
||||
( void )sprintf_s<256>( appState.sprintfBuffer, "%.2f fps %.2f ms", fps, deltaTimeMs );
|
||||
misc.frameTimeSum -= misc.frameTime[misc.frameTimeWriteHead];
|
||||
misc.frameTime[misc.frameTimeWriteHead] = deltaTime;
|
||||
misc.frameTimeSum += deltaTime;
|
||||
misc.frameTimeWriteHead = ( misc.frameTimeWriteHead + 1 ) % misc.frameTimeEntryCount;
|
||||
|
||||
double avgDeltaTime = ( misc.frameTimeSum / misc.frameTimeEntryCount );
|
||||
double fps = 1.0 / avgDeltaTime;
|
||||
double avgDeltaTimeMs = 1000.0 * avgDeltaTime;
|
||||
( void )sprintf_s<256>( appState.sprintfBuffer, "%.2f fps %.2f ms", fps, avgDeltaTimeMs );
|
||||
SDL_SetWindowTitle( appState.window, appState.sprintfBuffer );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -445,6 +445,12 @@ bool MiscData::init( RenderDevice const& renderDevice )
|
|||
};
|
||||
}
|
||||
|
||||
// Frame Time
|
||||
frameTimeEntryCount = 16;
|
||||
memset( frameTime, 0, frameTimeEntryCount * sizeof( float ) );
|
||||
frameTimeSum = 0;
|
||||
frameTimeWriteHead = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ struct MiscData
|
|||
VkImageMemoryBarrier2 renderToPresentBarrier;
|
||||
VkDependencyInfo renderToPresentDependency;
|
||||
|
||||
double frameTime[16];
|
||||
double frameTimeSum;
|
||||
uint8_t frameTimeWriteHead;
|
||||
uint8_t frameTimeEntryCount;
|
||||
|
||||
bool init( RenderDevice const& renderDevice );
|
||||
void destroy( RenderDevice const& renderDevice );
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue