From 8372f97e502e50c9bf8b78bf254e2980577f0234 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Wed, 5 Jul 2017 22:43:09 +1100 Subject: [PATCH] Display: removed old drawing code and external draw calls --- src/actions/attack.cpp | 2 - src/actions/vision.cpp | 12 +-- src/display.cpp | 81 ++------------------- src/display.hpp | 8 +- src/editor/controller/editor_controller.cpp | 2 - src/editor/map/context_manager.cpp | 1 - src/gui/dialogs/editor/custom_tod.cpp | 3 - src/play_controller.cpp | 1 - src/replay_controller.cpp | 1 - src/scripting/game_lua_kernel.cpp | 4 - src/units/udisplay.cpp | 15 ---- 11 files changed, 13 insertions(+), 117 deletions(-) diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index 89229d3f1444c..ff9ae45c10933 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -856,7 +856,6 @@ namespace { actions::recalculate_fog(defender_side); if (update_display_){ resources::screen->redraw_minimap(); - resources::screen->draw(true, true); } fire_event("attack_end"); throw attack_end_exception(); @@ -1318,7 +1317,6 @@ namespace { if (update_display_){ resources::screen->invalidate_unit(); - resources::screen->draw(true, true); } if(OOS_error_) { diff --git a/src/actions/vision.cpp b/src/actions/vision.cpp index 0297243c6be0a..9825e8254ac0a 100644 --- a/src/actions/vision.cpp +++ b/src/actions/vision.cpp @@ -325,8 +325,8 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team, move_unit_spectator * spectator, bool instant) { // Give animations a chance to progress; see bug #20324. - if ( !instant && resources::screen ) - resources::screen->draw(true); + // TODO: ^ is this something we need to worry about now that external draw calls are removed? + // vultraz, 7/5/2017 bool cleared_something = false; // Dummy variables to make some logic simpler. @@ -340,15 +340,15 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team, if ( view_team_ != &view_team ) { calculate_jamming(&view_team); // Give animations a chance to progress; see bug #20324. - if ( !instant && resources::screen ) - resources::screen->draw(true); + // TODO: ^ is this something we need to worry about now that external draw calls are removed? + // vultraz, 7/5/2017 } // Determine the hexes to clear. pathfind::vision_path sight(costs, slowed, sight_range, view_loc, jamming_); // Give animations a chance to progress; see bug #20324. - if ( !instant && resources::screen ) - resources::screen->draw(true); + // TODO: ^ is this something we need to worry about now that external draw calls are removed? + // vultraz, 7/5/2017 // Clear the fog. for (const pathfind::paths::step &dest : sight.destinations) { diff --git a/src/display.cpp b/src/display.cpp index 5d8825fe56108..7cce7e6ef5360 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -789,7 +789,7 @@ bool display::screenshot(const std::string& filename, bool map_screenshot) // we reroute render output to the screenshot surface and invalidate all map_screenshot_= true ; DBG_DP << "draw() with map_screenshot\n"; - draw(true,true); + //draw(true,true); // finally save the image on disk res = image::save_image(map_screenshot_surf_,filename); @@ -1758,7 +1758,7 @@ bool display::set_zoom(unsigned int amount, const bool validate_value_and_set_in // Forces a redraw after zooming. // This prevents some graphic glitches from occurring. - draw(); + //draw(); return true; } @@ -1810,7 +1810,7 @@ void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_ty if(scroll_type == WARP || scroll_type == ONSCREEN_WARP || turbo_speed() > 2.0 || preferences::scroll_speed() > 99) { scroll(xmove,ymove,true); - draw(); + //draw(); return; } @@ -1867,7 +1867,7 @@ void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_ty scroll(dx,dy,true); x_old += dx; y_old += dy; - draw(); + //draw(); } } @@ -2463,75 +2463,6 @@ void display::read(const config& cfg) // #define SLOW_THINGS_DOWN -void display::draw() -{ - draw_new(); - //draw(true, false); -} - -void display::draw(bool update) -{ - draw(update, false); -} - -void display::draw(bool update, bool force) -{ - return; - - // log_scope("display::draw"); - - if(video_.update_locked()) { - return; - } - - if (dirty_) { - flip_locker flip_lock(video_); - dirty_ = false; - redraw_everything(); - return; - } - - // Trigger cache rebuild when preference gets changed - if (animate_water_ != preferences::animate_water()) { - animate_water_ = preferences::animate_water(); - builder_->rebuild_cache_all(); - } - - set_scontext_unsynced leave_synced_context; - - draw_init(); - - pre_draw(); - - // invalidate all that needs to be invalidated - invalidate_animations(); - // at this stage we have everything that needs to be invalidated for this redraw - // save it as the previous invalidated, and merge with the previous invalidated_ - // we merge with the previous redraw because if a hex had a unit last redraw but - // not this one, nobody will tell us to redraw (cleanup) - - // these new invalidations cannot cause any propagation because - // if a hex was invalidated last turn but not this turn, then - // * case of no unit in neighbor hex=> no propagation - // * case of unit in hex but was there last turn=>its hexes are invalidated too - // * case of unit in hex not there last turn => it moved, so was invalidated previously - if(!get_map().empty()) { -#ifdef SLOW_THINGS_DOWN - int simulate_delay = 0; -#endif - post_commit(); - draw_sidebar(); - -#ifdef SLOW_THINGS_DOWN - SDL_Delay(2 * simulate_delay + rand() % 20); -#endif - } - - draw_wrap(update, force); - - post_draw(); -} - void display::redraw_everything() { if(video_.update_locked()) { @@ -2577,7 +2508,7 @@ void display::redraw_everything() int ticks1 = SDL_GetTicks(); //invalidate_all(); int ticks2 = SDL_GetTicks(); - draw(true,true); + //draw(true,true); int ticks3 = SDL_GetTicks(); LOG_DP << "invalidate and draw: " << (ticks3 - ticks2) << " and " << (ticks2 - ticks1) << "\n"; @@ -2818,7 +2749,7 @@ void display::draw_hex(const map_location& loc) #endif } -void display::draw_new() +void display::draw() { // Execute any pre-draw actions from derived classes. pre_draw(); diff --git a/src/display.hpp b/src/display.hpp index 923dc8b0c48ef..4eb9cf0f62b60 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -544,13 +544,7 @@ class display : public filter_context, public video2::draw_layering * Not virtual, since it gathers common actions. Calls various protected * virtuals (further below) to allow specialized behavior in derived classes. */ - virtual void draw(); - - void draw(bool update); - - void draw(bool update, bool force); - - void draw_new(); + virtual void draw() override; map_labels& labels(); const map_labels& labels() const; diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index 3d22c962f8047..abdf1397a8eeb 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -712,11 +712,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 4baac87a8671b..806e7a5f5ca6a 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -140,7 +140,6 @@ void context_manager::refresh_all() gui_.rebuild_all(); get_map_context().set_needs_terrain_rebuild(false); gui_.create_buttons(); - gui_.draw(false); get_map_context().clear_changed_locations(); gui_.recalculate_minimap(); } diff --git a/src/gui/dialogs/editor/custom_tod.cpp b/src/gui/dialogs/editor/custom_tod.cpp index ad50b4c45c797..517afcbad11b3 100644 --- a/src/gui/dialogs/editor/custom_tod.cpp +++ b/src/gui/dialogs/editor/custom_tod.cpp @@ -290,9 +290,6 @@ void custom_tod::update_tod_display() // redraw_everything() instead. disp->update_tod(&get_selected_tod()); - - // redraw tiles - disp->draw(false); } void custom_tod::update_lawful_bonus(window& window) diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 606e3971d7e2f..09ae7c1c21295 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -926,7 +926,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_->draw(true,true); } void play_controller::do_autosave() diff --git a/src/replay_controller.cpp b/src/replay_controller.cpp index 3eaa222b5df56..08d12ab64881a 100644 --- a/src/replay_controller.cpp +++ b/src/replay_controller.cpp @@ -265,7 +265,6 @@ void replay_controller::update_gui() { controller_.get_display().recalculate_minimap(); controller_.get_display().redraw_minimap(); - controller_.get_display().draw(); } void replay_controller::handle_generic_event(const std::string& name) diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 1501e26cb3fc1..6d076e4da6b39 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -3232,7 +3232,6 @@ int game_lua_kernel::intf_color_adjust(lua_State *L) vconfig cfg(luaW_checkvconfig(L, 1)); game_display_->adjust_color_overlay(cfg["red"], cfg["green"], cfg["blue"]); - game_display_->draw(true,true); } return 0; } @@ -3290,8 +3289,6 @@ int game_lua_kernel::intf_redraw(lua_State *L) } screen.recalculate_minimap(); } - - screen.draw(true,true); } return 0; } @@ -3583,7 +3580,6 @@ int game_lua_kernel::intf_scroll(lua_State * L) if (game_display_) { game_display_->scroll(x, y, true); - game_display_->draw(true, true); } return 0; diff --git a/src/units/udisplay.cpp b/src/units/udisplay.cpp index e86cf9d2cd9d5..c930a06df3e7b 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]); @@ -710,7 +696,6 @@ void unit_recruited(const map_location& loc,const map_location& leader_loc) disp->scroll_to_tile(loc,game_display::ONSCREEN,true,false); } - disp->draw(); u->set_hidden(false); animator.add_animation(&*u, "recruited", loc, leader_loc); animator.start_animations();