Skip to content

Commit

Permalink
Cleaned up unnecessary drawing calls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vultraz authored and GregoryLundberg committed Nov 30, 2017
1 parent 2bc7c12 commit 6afee1f
Show file tree
Hide file tree
Showing 16 changed files with 0 additions and 66 deletions.
2 changes: 0 additions & 2 deletions src/actions/advancement.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/actions/attack.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -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_) {
Expand Down
14 changes: 0 additions & 14 deletions src/actions/move.cpp
Expand Up @@ -620,8 +620,6 @@ namespace { // Private helpers for move_unit()
if (ambush_string_.empty()) {
ambush_string_ = _("Ambushed!");
}
// Update the display.
resources::screen->draw();
}


Expand Down Expand Up @@ -1108,7 +1106,6 @@ namespace { // Private helpers for move_unit()

// Update the screen.
resources::screen->redraw_minimap();
resources::screen->draw();
}


Expand All @@ -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 = "";
Expand All @@ -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;
Expand All @@ -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?
Expand Down Expand Up @@ -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"?
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/actions/undo.cpp
Expand Up @@ -376,7 +376,6 @@ void undo_list::undo()
gui.invalidate_unit();
gui.invalidate_game_status();
gui.redraw_minimap();
gui.draw();
}
else
{
Expand Down Expand Up @@ -425,7 +424,6 @@ void undo_list::redo()
gui.invalidate_unit();
gui.invalidate_game_status();
gui.redraw_minimap();
gui.draw();
}


Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/actions/unit_creator.cpp
Expand Up @@ -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();
}
}
}
3 changes: 0 additions & 3 deletions src/editor/controller/editor_controller.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/editor/map/context_manager.cpp
Expand Up @@ -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();
}
Expand Down
2 changes: 0 additions & 2 deletions src/game_display.cpp
Expand Up @@ -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;
Expand All @@ -142,7 +141,6 @@ void game_display::new_turn()
display::update_tod();

invalidate_all();
draw();
}

void game_display::select_hex(map_location hex)
Expand Down
2 changes: 0 additions & 2 deletions src/menu_events.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/mouse_events.cpp
Expand Up @@ -936,7 +936,6 @@ void mouse_handler::save_whiteboard_attack(

// gui().highlight_hex(map_location());

gui().draw();
gui().unhighlight_reach();
gui().clear_attack_indicator();

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/mouse_handler_base.cpp
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/play_controller.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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";

Expand Down
4 changes: 0 additions & 4 deletions src/playmp_controller.cpp
Expand Up @@ -112,7 +112,6 @@ void playmp_controller::play_linger_turn()
}
}
play_slice();
gui_->draw();
}
}

Expand Down Expand Up @@ -200,7 +199,6 @@ void playmp_controller::play_idle_loop()
process_network_data();
play_slice_catch();
SDL_Delay(1);
gui_->draw();
}
catch(...)
{
Expand Down Expand Up @@ -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";
Expand Down
6 changes: 0 additions & 6 deletions src/playsingle_controller.cpp
Expand Up @@ -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();
}


Expand Down Expand Up @@ -363,7 +361,6 @@ void playsingle_controller::play_idle_loop()
{
while(!should_return_to_play_side()) {
play_slice_catch();
gui_->draw();
SDL_Delay(10);
}
}
Expand Down Expand Up @@ -474,7 +471,6 @@ void playsingle_controller::play_human_turn() {
while(!should_return_to_play_side()) {
check_objectives();
play_slice_catch();
gui_->draw();
}

}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -580,7 +575,6 @@ void playsingle_controller::play_ai_turn()
gui_->invalidate_unit();
gui_->invalidate_game_status();
gui_->invalidate_all();
gui_->draw();
}


Expand Down
2 changes: 0 additions & 2 deletions src/replay_controller.cpp
Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions src/units/udisplay.cpp
Expand Up @@ -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]);
Expand Down

0 comments on commit 6afee1f

Please sign in to comment.