game: try to make Blades of Exile less CPU hungry...

This commit is contained in:
ALONSO Laurent
2021-10-08 11:26:35 +02:00
committed by Celtic Minstrel
parent 278c315df4
commit 4d0da8f6ac
2 changed files with 29 additions and 17 deletions

View File

@@ -267,10 +267,12 @@ void handle_events() {
cFramerateLimiter fps_limiter;
while(!All_Done) {
bool need_redraw=false;
#ifdef __APPLE__
if (menuChoiceId>=0) {
eMenuChoice aMenuChoice=menuChoice;
menuChoice=eMenuChoice::MENU_CHOICE_NONE;
need_redraw=true;
switch(aMenuChoice) {
case eMenuChoice::MENU_CHOICE_GENERIC:
handle_menu_choice(eMenu(menuChoiceId));
@@ -282,19 +284,27 @@ void handle_events() {
handle_monster_info_menu(menuChoiceId);
break;
case eMenuChoice::MENU_CHOICE_NONE:
need_redraw=false;
break;
}
menuChoiceId=-1;
}
#endif
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent);
while(mainPtr.pollEvent(currentEvent)) {
need_redraw=true;
handle_one_event(currentEvent);
}
// It would be nice to have minimap inside the main game window (we have lots of screen space in fullscreen mode).
// Alternatively, minimap could live on its own thread.
// But for now we just handle events from both windows on this thread.
while(map_visible && mini_map.pollEvent(currentEvent)) handle_one_minimap_event(currentEvent);
while(map_visible && mini_map.pollEvent(currentEvent)) {
need_redraw = true;
handle_one_minimap_event(currentEvent);
}
if(changed_display_mode) {
need_redraw = true;
changed_display_mode = false;
adjust_window_mode();
init_mini_map();
@@ -305,9 +315,11 @@ void handle_events() {
// Ideally this call should update all of the things that are happening in the world current tick.
// NOTE that update does not mean draw.
update_everything();
if (update_everything())
need_redraw=true;
// Ideally, this should be the only draw call that is done in a cycle.
if (need_redraw)
redraw_everything();
// Prevent the loop from executing too fast.
@@ -407,29 +419,31 @@ void handle_one_minimap_event(const sf::Event& event) {
}
}
void update_terrain_animation() {
static bool update_terrain_animation() {
static const long fortyTicks = time_in_ticks(40).asMilliseconds();
if(overall_mode == MODE_STARTUP) return;
if(!get_bool_pref("DrawTerrainAnimation", true)) return;
if(animTimer.getElapsedTime().asMilliseconds() < fortyTicks) return;
if(overall_mode == MODE_STARTUP) return false;
if(!get_bool_pref("DrawTerrainAnimation", true)) return false;
if(animTimer.getElapsedTime().asMilliseconds() < fortyTicks) return false;
anim_ticks++;
animTimer.restart();
return true;
}
void update_startup_animation() {
static bool update_startup_animation() {
static const long twentyTicks = time_in_ticks(20).asMilliseconds();
if(overall_mode != MODE_STARTUP) return;
if(animTimer.getElapsedTime().asMilliseconds() < twentyTicks) return;
if(overall_mode != MODE_STARTUP) return false;
if(animTimer.getElapsedTime().asMilliseconds() < twentyTicks) return false;
draw_startup_anim(true);
animTimer.restart();
return true;
}
void update_everything() {
update_terrain_animation();
bool update_everything() {
return update_terrain_animation() ||
update_startup_animation();
}

View File

@@ -6,7 +6,7 @@ extern eMenuChoice menuChoice;
extern short menuChoiceId;
#endif
int main(int argc, char* argv[]);
void update_everything();
bool update_everything();
void redraw_everything();
void Mouse_Pressed(const sf::Event&);
void close_program();
@@ -19,8 +19,6 @@ bool handle_startup_press(location the_point);
void handle_splash_events();
void show_logo();
void plop_fancy_startup();
void update_terrain_animation();
void update_startup_animation();
void handle_events();
void handle_one_event(const sf::Event&);
void handle_one_minimap_event(const sf::Event &);