From eba94b3e22022ebb3f455723a60ef6b6518284fa Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 28 Nov 2017 04:57:34 +1100 Subject: [PATCH] Cleaned up unnecessary drawing calls After testing, it seems these calls to raise_draw_event and display/game_display::draw() were unnecessary - or at least, became unnecessary at some point. One or two are definitely still needed, but removing these doesn't seem to cause anything to to glitch out. Likely explanation is anything that needs updating just gets updated either immediately or on the next play_slice loop. --- src/actions/advancement.cpp | 2 -- src/actions/attack.cpp | 2 -- src/actions/move.cpp | 14 -------------- src/actions/undo.cpp | 4 ---- src/actions/unit_creator.cpp | 2 -- src/editor/controller/editor_controller.cpp | 3 --- src/editor/map/context_manager.cpp | 1 - src/game_display.cpp | 2 -- src/menu_events.cpp | 2 -- src/mouse_events.cpp | 2 -- src/mouse_handler_base.cpp | 2 -- src/play_controller.cpp | 4 ---- src/playmp_controller.cpp | 4 ---- src/playsingle_controller.cpp | 6 ------ src/replay_controller.cpp | 2 -- src/units/udisplay.cpp | 14 -------------- 16 files changed, 66 deletions(-) diff --git a/src/actions/advancement.cpp b/src/actions/advancement.cpp index 1a1558cb2d7..cde00c382cb 100644 --- a/src/actions/advancement.cpp +++ b/src/actions/advancement.cpp @@ -143,12 +143,10 @@ namespace animator.wait_for_end(); animator.set_all_standing(); resources::screen->invalidate(loc); - resources::screen->draw(); events::pump(); } resources::screen->invalidate_all(); - resources::screen->draw(); return true; } diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index 16fe7104879..c95834a2bc0 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -964,7 +964,6 @@ void attack::fire_event(const std::string& n) if(update_display_) { resources::screen->redraw_minimap(); - resources::screen->draw(true, true); } fire_event("attack_end"); @@ -1473,7 +1472,6 @@ void attack::perform() resources::screen->invalidate_unit(); resources::screen->invalidate(a_.loc_); resources::screen->invalidate(d_.loc_); - resources::screen->draw(true, true); } if(OOS_error_) { diff --git a/src/actions/move.cpp b/src/actions/move.cpp index 5b5c5aceeb3..8ec103d0d47 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -620,8 +620,6 @@ namespace { // Private helpers for move_unit() if (ambush_string_.empty()) { ambush_string_ = _("Ambushed!"); } - // Update the display. - resources::screen->draw(); } @@ -1108,7 +1106,6 @@ namespace { // Private helpers for move_unit() // Update the screen. resources::screen->redraw_minimap(); - resources::screen->draw(); } @@ -1120,8 +1117,6 @@ namespace { // Private helpers for move_unit() // Alias some resources. game_display &disp = *resources::screen; - bool redraw = false; - // Multiple messages may be displayed simultaneously // this variable is used to keep them from overlapping std::string message_prefix = ""; @@ -1130,7 +1125,6 @@ namespace { // Private helpers for move_unit() if ( ambushed_ && show_ambush_alert_ ) { disp.announce(message_prefix + ambush_string_, font::BAD_COLOR); message_prefix += " \n"; - redraw = true; } display::announce_options announce_options; @@ -1141,7 +1135,6 @@ namespace { // Private helpers for move_unit() std::string teleport_string = _("Failed teleport! Exit not empty"); disp.announce(message_prefix + teleport_string, font::BAD_COLOR, announce_options); message_prefix += " \n"; - redraw = true; } // Sighted units feedback? @@ -1171,7 +1164,6 @@ namespace { // Private helpers for move_unit() disp.announce(message_prefix + message, msg_color, announce_options); message_prefix += " \n"; - redraw = true; } // Suggest "continue move"? @@ -1184,14 +1176,8 @@ namespace { // Private helpers for move_unit() std::string message = vgettext("(press $hotkey to keep moving)", symbols); disp.announce(message_prefix + message, font::NORMAL_COLOR, announce_options); message_prefix += " \n"; - redraw = true; } } - - // Update the screen. - if (redraw) { - disp.draw(); - } } }//end anonymous namespace diff --git a/src/actions/undo.cpp b/src/actions/undo.cpp index 554e624dfd0..c3272282042 100644 --- a/src/actions/undo.cpp +++ b/src/actions/undo.cpp @@ -376,7 +376,6 @@ void undo_list::undo() gui.invalidate_unit(); gui.invalidate_game_status(); gui.redraw_minimap(); - gui.draw(); } else { @@ -425,7 +424,6 @@ void undo_list::redo() gui.invalidate_unit(); gui.invalidate_game_status(); gui.redraw_minimap(); - gui.draw(); } @@ -484,14 +482,12 @@ bool undo_list::apply_shroud_changes() const // Update the display before pumping events. clearer.invalidate_after_clear(); - disp.draw(); // Fire sighted events if ( std::get<0>(clearer.fire_events() )) { // Fix up the display in case WML changed stuff. clear_shroud(side_); disp.invalidate_unit(); - disp.draw(); } return true; diff --git a/src/actions/unit_creator.cpp b/src/actions/unit_creator.cpp index 226707d00eb..3167e417c7a 100644 --- a/src/actions/unit_creator.cpp +++ b/src/actions/unit_creator.cpp @@ -244,8 +244,6 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo if (animate) { unit_display::unit_recruited(loc); - } else if (show) { - resources::screen->draw(); } } } diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index f411daa2505..17bbd9c71ac 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -87,7 +87,6 @@ editor_controller::editor_controller(const config &game_config) gui().create_buttons(); gui().redraw_everything(); - events::raise_draw_event(); } void editor_controller::init_gui() @@ -710,11 +709,9 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i return true; case HOTKEY_EDITOR_PALETTE_UPSCROLL: toolkit_->get_palette_manager()->scroll_up(); - gui_->draw(true,false); return true; case HOTKEY_EDITOR_PALETTE_DOWNSCROLL: toolkit_->get_palette_manager()->scroll_down(); - gui_->draw(true,false); return true; case HOTKEY_QUIT_GAME: diff --git a/src/editor/map/context_manager.cpp b/src/editor/map/context_manager.cpp index 2e9261126d1..461ad50aa58 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -141,7 +141,6 @@ void context_manager::refresh_all() get_map_context().set_needs_terrain_rebuild(false); gui_.create_buttons(); gui_.invalidate_all(); - gui_.draw(false); get_map_context().clear_changed_locations(); gui_.recalculate_minimap(); } diff --git a/src/game_display.cpp b/src/game_display.cpp index 89f041861bb..1152c895055 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -123,7 +123,6 @@ void game_display::new_turn() } invalidate_all(); - draw(); const int cur_ticks = SDL_GetTicks(); const int wanted_ticks = starting_ticks + i*frame_time; @@ -142,7 +141,6 @@ void game_display::new_turn() display::update_tod(); invalidate_all(); - draw(); } void game_display::select_hex(map_location hex) diff --git a/src/menu_events.cpp b/src/menu_events.cpp index ba0f1c8bfab..3f69252c817 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -963,7 +963,6 @@ void menu_handler::unit_hold_position(mouse_handler& mousehandler, int side_num) gui_->invalidate(mousehandler.get_selected_hex()); mousehandler.set_current_paths(pathfind::paths()); - gui_->draw(); if(un->hold_position()) { mousehandler.cycle_units(false); @@ -979,7 +978,6 @@ void menu_handler::end_unit_turn(mouse_handler& mousehandler, int side_num) gui_->invalidate(mousehandler.get_selected_hex()); mousehandler.set_current_paths(pathfind::paths()); - gui_->draw(); if(un->user_end_turn()) { mousehandler.cycle_units(false); diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 88281b3fa68..06b3f526a6d 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -936,7 +936,6 @@ void mouse_handler::save_whiteboard_attack( // gui().highlight_hex(map_location()); - gui().draw(); gui().unhighlight_reach(); gui().clear_attack_indicator(); @@ -1064,7 +1063,6 @@ void mouse_handler::attack_enemy_(const map_location& att_loc, const map_locatio gui().highlight_hex(map_location()); gui().clear_attack_indicator(); gui().unhighlight_reach(); - gui().draw(); current_team().set_action_bonus_count(1 + current_team().action_bonus_count()); ///@todo change ToD to be location specific for the defender diff --git a/src/mouse_handler_base.cpp b/src/mouse_handler_base.cpp index 2d9a35332ae..4c8c0665076 100644 --- a/src/mouse_handler_base.cpp +++ b/src/mouse_handler_base.cpp @@ -282,8 +282,6 @@ void mouse_handler_base::right_mouse_up(int x, int y, const bool browse) return; } - gui().draw(); // redraw highlight (and maybe some more) - const theme::menu* const m = gui().get_theme().context_menu(); if(m != nullptr) { show_menu_ = true; diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 9e817efa734..5aacf560f26 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -993,7 +993,6 @@ void play_controller::update_gui_to_player(const int team_index, const bool obse gui_->set_team(team_index, observe); gui_->recalculate_minimap(); gui_->invalidate_all(); - gui_->draw(true,true); } void play_controller::do_autosave() @@ -1090,7 +1089,6 @@ void play_controller::start_game() init_gui(); LOG_NG << "first_time..." << (is_skipping_replay() ? "skipping" : "no skip") << "\n"; - events::raise_draw_event(); fire_start(); if (is_regular_game_end()) { return; @@ -1108,7 +1106,6 @@ void play_controller::start_game() else { init_gui(); - events::raise_draw_event(); gamestate().gamedata_.set_phase(game_data::PLAY); gui_->recalculate_minimap(); } @@ -1167,7 +1164,6 @@ void play_controller::play_turn() whiteboard_manager_->on_gamestate_change(); gui_->new_turn(); gui_->invalidate_game_status(); - events::raise_draw_event(); LOG_NG << "turn: " << turn() << "\n"; diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index 1e395f3fce9..4f3d6bea4c3 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -112,7 +112,6 @@ void playmp_controller::play_linger_turn() } } play_slice(); - gui_->draw(); } } @@ -200,7 +199,6 @@ void playmp_controller::play_idle_loop() process_network_data(); play_slice_catch(); SDL_Delay(1); - gui_->draw(); } catch(...) { @@ -347,8 +345,6 @@ void playmp_controller::play_network_turn(){ if (!network_processing_stopped_){ turn_data_.send_data(); } - - gui_->draw(); } LOG_NG << "finished networked...\n"; diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index a71d254d5d2..e7f5e8ea6fa 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -147,9 +147,7 @@ void playsingle_controller::init_gui() } update_locker lock_display(gui_->video(), is_skipping_replay()); - gui_->draw(); get_hotkey_command_executor()->set_button_state(); - events::raise_draw_event(); } @@ -363,7 +361,6 @@ void playsingle_controller::play_idle_loop() { while(!should_return_to_play_side()) { play_slice_catch(); - gui_->draw(); SDL_Delay(10); } } @@ -474,7 +471,6 @@ void playsingle_controller::play_human_turn() { while(!should_return_to_play_side()) { check_objectives(); play_slice_catch(); - gui_->draw(); } } @@ -502,7 +498,6 @@ void playsingle_controller::linger() end_turn_ = END_TURN_NONE; while(end_turn_ == END_TURN_NONE) { play_slice(); - gui_->draw(); } } catch(const savegame::load_game_exception &) { // Loading a new game is effectively a quit. @@ -580,7 +575,6 @@ void playsingle_controller::play_ai_turn() gui_->invalidate_unit(); gui_->invalidate_game_status(); gui_->invalidate_all(); - gui_->draw(); } diff --git a/src/replay_controller.cpp b/src/replay_controller.cpp index ece7beafbf3..3961455cb99 100644 --- a/src/replay_controller.cpp +++ b/src/replay_controller.cpp @@ -266,8 +266,6 @@ void replay_controller::update_gui() controller_.get_display().recalculate_minimap(); controller_.get_display().redraw_minimap(); controller_.get_display().invalidate_all(); - events::raise_draw_event(); - controller_.get_display().draw(); } void replay_controller::handle_generic_event(const std::string& name) diff --git a/src/units/udisplay.cpp b/src/units/udisplay.cpp index 39565008688..5b720df9f1f 100644 --- a/src/units/udisplay.cpp +++ b/src/units/udisplay.cpp @@ -268,20 +268,6 @@ void unit_mover::start(unit_ptr u) // If it does not fit we might be able to do a better scroll later. disp_->scroll_to_tiles(path_, game_display::ONSCREEN, true, true, 0.0, false); } - // We need to clear big invalidation before the move and have a smooth animation - // (mainly black stripes and invalidation after canceling attack dialog). - // Two draw calls are needed to also redraw the previously invalidated hexes. - // We use update=false because we don't need delay here (no time wasted) - // and no screen refresh (will be done by last 3rd draw() and it optimizes - // the double blitting done by these invalidations). - disp_->draw(false); - disp_->draw(false); - - // The last draw() was still slow, and its initial new_animation_frame() call - // is now old, so we do another draw() to get a fresh one - // TODO: replace that by a new_animation_frame() before starting anims - // don't forget to change the previous draw(false) to true - disp_->draw(true); // extra immobile movement animation for take-off animator_.add_animation(temp_unit_ptr_.get(), "pre_movement", path_[0], path_[1]);