@@ -25,7 +25,7 @@ Engine::~Engine() {
2525
2626bool Engine::Initialize (const std::string& appName, int width, int height, bool enableValidationLayers) {
2727 // Create platform
28- #if PLATFORM_ANDROID
28+ #if defined( PLATFORM_ANDROID)
2929 // For Android, the platform is created with the android_app
3030 // This will be handled in the android_main function
3131 return false ;
@@ -213,14 +213,17 @@ void Engine::Run() {
213213 frameCount++;
214214 fpsUpdateTimer += deltaTime;
215215
216- // Update window title with FPS and frame count every second
216+ // Update window title with FPS and frame time every second
217217 if (fpsUpdateTimer >= 1 .0f ) {
218218 uint64_t framesSinceLastUpdate = frameCount - lastFPSUpdateFrame;
219219 currentFPS = framesSinceLastUpdate / fpsUpdateTimer;
220+ // Average frame time in milliseconds over the last interval
221+ double avgMs = (fpsUpdateTimer / static_cast <double >(framesSinceLastUpdate)) * 1000.0 ;
220222
221- // Update window title with frame count and FPS
223+ // Update window title with frame count, FPS, and frame time
222224 std::string title = " Simple Engine - Frame: " + std::to_string (frameCount) +
223- " | FPS: " + std::to_string (static_cast <int >(currentFPS));
225+ " | FPS: " + std::to_string (static_cast <int >(currentFPS)) +
226+ " | ms: " + std::to_string (static_cast <int >(avgMs));
224227 platform->SetWindowTitle (title);
225228
226229 // Reset timer and frame counter for next update
@@ -415,29 +418,26 @@ void Engine::Render() {
415418}
416419
417420float Engine::CalculateDeltaTime () {
418- // Get current time
419- auto currentTime = static_cast <uint64_t >(std::chrono::duration_cast<std::chrono::milliseconds>(
420- std::chrono::high_resolution_clock::now ().time_since_epoch ()
421- ).count ());
421+ // Get current time using a steady clock to avoid system time jumps
422+ uint64_t currentTime = static_cast <uint64_t >(
423+ std::chrono::duration_cast<std::chrono::milliseconds>(
424+ std::chrono::steady_clock::now ().time_since_epoch ()
425+ ).count ()
426+ );
422427
423428 // Initialize lastFrameTime on first call
424429 if (lastFrameTime == 0 ) {
425430 lastFrameTime = currentTime;
426- return 0 .016f ; // Return ~16ms (60 FPS) for first frame
431+ return 0 .016f ; // ~16ms as a sane initial guess
427432 }
428433
429- // Calculate delta time
434+ // Calculate delta time in milliseconds
430435 uint64_t delta = currentTime - lastFrameTime;
431436
432437 // Update last frame time
433438 lastFrameTime = currentTime;
434439
435- // Clamp delta time to reasonable values (prevent huge jumps)
436- if (delta > 10 ) { // Cap at 100ms (10 FPS minimum)
437- delta = 16 ; // Use 16ms instead
438- }
439-
440- return delta / 1000 .0f ; // Convert to seconds
440+ return static_cast <float >(delta) / 1000 .0f ;
441441}
442442
443443void Engine::HandleResize (int width, int height) const {
@@ -754,7 +754,7 @@ void Engine::HandleMouseHover(float mouseX, float mouseY) {
754754}
755755
756756
757- #if PLATFORM_ANDROID
757+ #if defined( PLATFORM_ANDROID)
758758// Android-specific implementation
759759bool Engine::InitializeAndroid (android_app* app, const std::string& appName, bool enableValidationLayers) {
760760 // Create platform
0 commit comments