From fe4821cb4e889a9e3409e7ec365cfc58c8790a2c Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 9 Aug 2024 12:47:39 -0500 Subject: [PATCH] fix CPU spike during intro splash screens --- src/game/boe.main.cpp | 6 +++--- src/game/boe.main.hpp | 5 +++-- src/game/boe.startup.cpp | 13 +++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/game/boe.main.cpp b/src/game/boe.main.cpp index d7f3bb6f..2b5ef68b 100644 --- a/src/game/boe.main.cpp +++ b/src/game/boe.main.cpp @@ -42,7 +42,6 @@ #include "tools/prefs.hpp" #include "dialogxml/widgets/button.hpp" #include "tools/enum_map.hpp" -#include "tools/framerate_limiter.hpp" #include "tools/event_listener.hpp" #include "tools/drawable_manager.hpp" bool All_Done = false; @@ -358,12 +357,13 @@ void init_boe(int argc, char* argv[]) { init_screen_locs(); init_startup(); flushingInput = true; + cFramerateLimiter fps_limiter; // Hidden preference to hide the startup logo - should be kept hidden if(get_bool_pref("ShowStartupLogo", true)) - show_logo(); + show_logo(fps_limiter); // The preference to hide the startup splash is exposed however. if(get_bool_pref("ShowStartupSplash", true)) - plop_fancy_startup(); + plop_fancy_startup(fps_limiter); cUniverse::print_result = iLiving::print_result = add_string_to_buf; cPlayer::give_help = give_help; diff --git a/src/game/boe.main.hpp b/src/game/boe.main.hpp index b522413a..a5299343 100644 --- a/src/game/boe.main.hpp +++ b/src/game/boe.main.hpp @@ -1,5 +1,6 @@ #include +#include "tools/framerate_limiter.hpp" #ifdef __APPLE__ extern eMenuChoice menuChoice; @@ -18,8 +19,8 @@ void incidental_noises(bool on_surface); void pause(short length); bool handle_startup_press(location the_point); void handle_splash_events(); -void show_logo(); -void plop_fancy_startup(); +void show_logo(cFramerateLimiter& framerate_limiter); +void plop_fancy_startup(cFramerateLimiter& framerate_limiter); void update_terrain_animation(); void update_startup_animation(); void handle_events(); diff --git a/src/game/boe.startup.cpp b/src/game/boe.startup.cpp index ab50707c..bb610e0a 100644 --- a/src/game/boe.startup.cpp +++ b/src/game/boe.startup.cpp @@ -128,12 +128,13 @@ bool handle_startup_press(location the_point) { return false; } -void handle_splash_events() { +void handle_splash_events(cFramerateLimiter& framerate_limiter) { sf::Event event; while(mainPtr.pollEvent(event)) { if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved) set_cursor(sword_curs); } + framerate_limiter.frame_finished(); } static rectangle view_rect() { @@ -141,7 +142,7 @@ static rectangle view_rect() { return rectangle(0, 0, size.y, size.x); } -void show_logo() { +void show_logo(cFramerateLimiter& framerate_limiter) { rectangle whole_window = view_rect(); if(get_int_pref("DisplayMode") != 5) @@ -156,17 +157,17 @@ void show_logo() { play_sound(-95); while(sound_going(95)) { draw_splash(pict_to_draw, mainPtr, logo_from); - handle_splash_events(); + handle_splash_events(framerate_limiter); } if(!get_int_pref("ShowStartupSplash", true)) { sf::Time delay = time_in_ticks(60); sf::Clock timer; while(timer.getElapsedTime() < delay) - handle_splash_events(); + handle_splash_events(framerate_limiter); } } -void plop_fancy_startup() { +void plop_fancy_startup(cFramerateLimiter& framerate_limiter) { rectangle whole_window = view_rect(); float ui_scale = get_float_pref("UIScale", 1.0); @@ -182,7 +183,7 @@ void plop_fancy_startup() { while(timer.getElapsedTime() < delay) { draw_splash(pict_to_draw, mainPtr, intro_from); - handle_splash_events(); + handle_splash_events(framerate_limiter); } }