Averaging frame times.

This commit is contained in:
Anish Bhobe 2025-06-18 17:18:58 +02:00
parent 0e55949309
commit babbe93479
4 changed files with 21 additions and 3 deletions

View File

@ -4,6 +4,7 @@ AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: AlignConsecutiveAssignments:
Enabled: true Enabled: true
AcrossEmptyLines: true AcrossEmptyLines: true
AlignCompound: true
AlignFunctionPointers: true AlignFunctionPointers: true
AlignConsecutiveDeclarations: AlignConsecutiveDeclarations:
Enabled: true Enabled: true

View File

@ -117,9 +117,15 @@ SDL_AppResult SDL_AppIterate( void* appstate )
misc.previousCounter = currentCounter; misc.previousCounter = currentCounter;
{ {
double deltaTimeMs = deltaTime * 1000.0; misc.frameTimeSum -= misc.frameTime[misc.frameTimeWriteHead];
double fps = 1.0 / deltaTime; misc.frameTime[misc.frameTimeWriteHead] = deltaTime;
( void )sprintf_s<256>( appState.sprintfBuffer, "%.2f fps %.2f ms", fps, deltaTimeMs ); 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 ); SDL_SetWindowTitle( appState.window, appState.sprintfBuffer );
} }

View File

@ -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; return true;
} }

View File

@ -40,6 +40,11 @@ struct MiscData
VkImageMemoryBarrier2 renderToPresentBarrier; VkImageMemoryBarrier2 renderToPresentBarrier;
VkDependencyInfo renderToPresentDependency; VkDependencyInfo renderToPresentDependency;
double frameTime[16];
double frameTimeSum;
uint8_t frameTimeWriteHead;
uint8_t frameTimeEntryCount;
bool init( RenderDevice const& renderDevice ); bool init( RenderDevice const& renderDevice );
void destroy( RenderDevice const& renderDevice ); void destroy( RenderDevice const& renderDevice );
}; };