Skip to content

Commit

Permalink
Display: removed old drawing code and external draw calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jul 5, 2017
1 parent 070e1ca commit 8372f97
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 117 deletions.
2 changes: 0 additions & 2 deletions src/actions/attack.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -1318,7 +1317,6 @@ namespace {

if (update_display_){
resources::screen->invalidate_unit();
resources::screen->draw(true, true);
}

if(OOS_error_) {
Expand Down
12 changes: 6 additions & 6 deletions src/actions/vision.cpp
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
81 changes: 6 additions & 75 deletions src/display.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 1 addition & 7 deletions src/display.hpp
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/editor/controller/editor_controller.cpp
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/editor/map/context_manager.cpp
Expand Up @@ -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();
}
Expand Down
3 changes: 0 additions & 3 deletions src/gui/dialogs/editor/custom_tod.cpp
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/play_controller.cpp
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/replay_controller.cpp
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -3290,8 +3289,6 @@ int game_lua_kernel::intf_redraw(lua_State *L)
}
screen.recalculate_minimap();
}

screen.draw(true,true);
}
return 0;
}
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 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 Expand Up @@ -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();
Expand Down

0 comments on commit 8372f97

Please sign in to comment.