diff --git a/src/display.cpp b/src/display.cpp index 05ab4df35a2..fcbd80b535f 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -398,19 +398,17 @@ void display::set_team(std::size_t teamindex, bool show_everything) { assert(teamindex < dc_->teams().size()); currentTeam_ = teamindex; - if (!show_everything) - { + if(!show_everything) { labels().set_team(&dc_->teams()[teamindex]); dont_show_all_ = true; - } - else - { + } else { labels().set_team(nullptr); dont_show_all_ = false; } labels().recalculate_labels(); - if(std::shared_ptr w = wb_.lock()) + if(std::shared_ptr w = wb_.lock()) { w->on_viewer_change(teamindex); + } } void display::set_playing_team(std::size_t teamindex) @@ -422,13 +420,10 @@ void display::set_playing_team(std::size_t teamindex) bool display::add_exclusive_draw(const map_location& loc, unit& unit) { - if (loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end()) - { + if(loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end()) { exclusive_unit_draw_requests_[loc] = unit.id(); return true; - } - else - { + } else { return false; } } @@ -536,10 +531,9 @@ bool display::is_blindfolded() const return blindfold_ctr_ > 0; } - const SDL_Rect& display::max_map_area() const { - static SDL_Rect max_area {0, 0, 0, 0}; + static SDL_Rect max_area{0, 0, 0, 0}; // hex_size() is always a multiple of 4 // and hex_width() a multiple of 3, @@ -548,7 +542,7 @@ const SDL_Rect& display::max_map_area() const // To display a hex fully on screen, // a little bit extra space is needed. // Also added the border two times. - max_area.w = static_cast((get_map().w() + 2 * theme_.border().size + 1.0/3.0) * hex_width()); + max_area.w = static_cast((get_map().w() + 2 * theme_.border().size + 1.0 / 3.0) * hex_width()); max_area.h = static_cast((get_map().h() + 2 * theme_.border().size + 0.5) * hex_size()); return max_area; @@ -560,7 +554,7 @@ const SDL_Rect& display::map_area() const max_area = max_map_area(); // if it's for map_screenshot, maximize and don't recenter - if (map_screenshot_) { + if(map_screenshot_) { return max_area; } @@ -569,13 +563,13 @@ const SDL_Rect& display::map_area() const if(max_area.w < res.w) { // map is smaller, center - res.x += (res.w - max_area.w)/2; + res.x += (res.w - max_area.w) / 2; res.w = max_area.w; } if(max_area.h < res.h) { // map is smaller, center - res.y += (res.h - max_area.h)/2; + res.y += (res.h - max_area.h) / 2; res.h = max_area.h; } @@ -586,8 +580,7 @@ bool display::outside_area(const SDL_Rect& area, const int x, const int y) { const int x_thresh = hex_size(); const int y_thresh = hex_size(); - return (x < area.x || x > area.x + area.w - x_thresh || - y < area.y || y > area.y + area.h - y_thresh); + return (x < area.x || x > area.x + area.w - x_thresh || y < area.y || y > area.y + area.h - y_thresh); } // This function uses the screen as reference @@ -604,7 +597,6 @@ const map_location display::hex_clicked_on(int xclick, int yclick) const return pixel_position_to_hex(xpos_ + xclick, ypos_ + yclick); } - // This function uses the rect of map_area as reference const map_location display::pixel_position_to_hex(int x, int y) const { @@ -684,7 +676,7 @@ const display::rect_of_hexes display::hexes_under_rect(const SDL_Rect& r) const { rect_of_hexes res; - if (r.w<=0 || r.h<=0) { + if(r.w <= 0 || r.h <= 0) { // empty rect, return dummy values giving begin=end res.left = 0; res.right = -1; // end is right+1 @@ -711,14 +703,14 @@ const display::rect_of_hexes display::hexes_under_rect(const SDL_Rect& r) const res.left = static_cast(std::floor(-border + x / tile_width - 0.3333333)); // we remove 1 pixel of the rectangle dimensions // (the rounded division take one pixel more than needed) - res.right = static_cast(std::floor(-border + (x + r.w-1) / tile_width)); + res.right = static_cast(std::floor(-border + (x + r.w - 1) / tile_width)); // for odd x, we must shift up one half-hex. Since x will vary along the edge, // we store here the y values for even and odd x, respectively res.top[0] = static_cast(std::floor(-border + y / tile_size)); res.top[1] = static_cast(std::floor(-border + y / tile_size - 0.5)); - res.bottom[0] = static_cast(std::floor(-border + (y + r.h-1) / tile_size)); - res.bottom[1] = static_cast(std::floor(-border + (y + r.h-1) / tile_size - 0.5)); + res.bottom[0] = static_cast(std::floor(-border + (y + r.h - 1) / tile_size)); + res.bottom[1] = static_cast(std::floor(-border + (y + r.h - 1) / tile_size - 0.5)); // TODO: in some rare cases (1/16), a corner of the big rect is on a tile // (the 72x72 rectangle containing the hex) but not on the hex itself @@ -754,10 +746,10 @@ int display::get_location_y(const map_location& loc) const map_location display::minimap_location_on(int x, int y) { - //TODO: don't return location for this, - // instead directly scroll to the clicked pixel position + // TODO: don't return location for this, + // instead directly scroll to the clicked pixel position - if (!sdl::point_in_rect(x, y, minimap_area())) { + if(!sdl::point_in_rect(x, y, minimap_area())) { return map_location(); } @@ -765,19 +757,21 @@ map_location display::minimap_location_on(int x, int y) // probably more adjustments to do (border, minimap shift...) // but the mouse and human capacity to evaluate the rectangle center // is not pixel precise. - int px = (x - minimap_location_.x) * get_map().w()*hex_width() / std::max (minimap_location_.w, 1); - int py = (y - minimap_location_.y) * get_map().h()*hex_size() / std::max(minimap_location_.h, 1); + int px = (x - minimap_location_.x) * get_map().w() * hex_width() / std::max(minimap_location_.w, 1); + int py = (y - minimap_location_.y) * get_map().h() * hex_size() / std::max(minimap_location_.h, 1); map_location loc = pixel_position_to_hex(px, py); - if (loc.x < 0) + if(loc.x < 0) { loc.x = 0; - else if (loc.x >= get_map().w()) + } else if(loc.x >= get_map().w()) { loc.x = get_map().w() - 1; + } - if (loc.y < 0) + if(loc.y < 0) { loc.y = 0; - else if (loc.y >= get_map().h()) + } else if(loc.y >= get_map().h()) { loc.y = get_map().h() - 1; + } return loc; } @@ -826,9 +820,9 @@ surface display::screenshot(bool map_screenshot) std::shared_ptr display::find_action_button(const std::string& id) { - for (std::size_t i = 0; i < action_buttons_.size(); ++i) { - if(action_buttons_[i]->id() == id) { - return action_buttons_[i]; + for(auto& b : action_buttons_) { + if(b->id() == id) { + return b; } } return nullptr; @@ -836,9 +830,9 @@ std::shared_ptr display::find_action_button(const std::string& id) std::shared_ptr display::find_menu_button(const std::string& id) { - for (std::size_t i = 0; i < menu_buttons_.size(); ++i) { - if(menu_buttons_[i]->id() == id) { - return menu_buttons_[i]; + for(auto& b : menu_buttons_) { + if(b->id() == id) { + return b; } } return nullptr; @@ -848,8 +842,7 @@ void display::layout_buttons() { DBG_DP << "positioning menu buttons...\n"; for(const auto& menu : theme_.menus()) { - std::shared_ptr b = find_menu_button(menu.get_id()); - if(b) { + if(auto b = find_menu_button(menu.get_id())) { const SDL_Rect& loc = menu.location(screen_.screen_area()); b->set_location(loc); b->set_measurements(0,0); @@ -860,8 +853,7 @@ void display::layout_buttons() DBG_DP << "positioning action buttons...\n"; for(const auto& action : theme_.actions()) { - std::shared_ptr b = find_action_button(action.get_id()); - if(b) { + if(auto b = find_action_button(action.get_id())) { const SDL_Rect& loc = action.location(screen_.screen_area()); b->set_location(loc); b->set_measurements(0,0); @@ -898,71 +890,66 @@ const std::string& get_direction(std::size_t n) void display::create_buttons() { - std::vector> menu_work; - std::vector> action_work; + menu_buttons_.clear(); + action_buttons_.clear(); DBG_DP << "creating menu buttons...\n"; for(const auto& menu : theme_.menus()) { - if (!menu.is_button()) continue; + if(!menu.is_button()) { + continue; + } + + auto b = std::make_shared(screen_, menu.title(), gui::button::TYPE_PRESS, menu.image(), + gui::button::DEFAULT_SPACE, false, menu.overlay(), font::SIZE_BUTTON_SMALL); - std::shared_ptr b(new gui::button(screen_, menu.title(), gui::button::TYPE_PRESS, menu.image(), - gui::button::DEFAULT_SPACE, false, menu.overlay(), font::SIZE_BUTTON_SMALL)); DBG_DP << "drawing button " << menu.get_id() << "\n"; b->join_same(this); b->set_id(menu.get_id()); - if (!menu.tooltip().empty()){ + if(!menu.tooltip().empty()) { b->set_tooltip_string(menu.tooltip()); } - std::shared_ptr b_prev = find_menu_button(b->id()); - if(b_prev) { + if(auto b_prev = find_menu_button(b->id())) { b->enable(b_prev->enabled()); } - menu_work.push_back(b); + menu_buttons_.push_back(std::move(b)); } DBG_DP << "creating action buttons...\n"; for(const auto& action : theme_.actions()) { - std::shared_ptr b(new gui::button(screen_, action.title(), string_to_button_type(action.type()), action.image(), - gui::button::DEFAULT_SPACE, false, action.overlay(), font::SIZE_BUTTON_SMALL)); + auto b = std::make_shared(screen_, action.title(), string_to_button_type(action.type()), + action.image(), gui::button::DEFAULT_SPACE, false, action.overlay(), font::SIZE_BUTTON_SMALL); DBG_DP << "drawing button " << action.get_id() << "\n"; b->set_id(action.get_id()); b->join_same(this); - if (!action.tooltip(0).empty()){ + if(!action.tooltip(0).empty()) { b->set_tooltip_string(action.tooltip(0)); } - std::shared_ptr b_prev = find_action_button(b->id()); - if(b_prev) { + if(auto b_prev = find_action_button(b->id())) { b->enable(b_prev->enabled()); - if (b_prev->get_type() == gui::button::TYPE_CHECK) { + if(b_prev->get_type() == gui::button::TYPE_CHECK) { b->set_check(b_prev->checked()); } } - action_work.push_back(b); + action_buttons_.push_back(std::move(b)); } - - menu_buttons_.clear(); - menu_buttons_.assign(menu_work.begin(), menu_work.end()); - action_buttons_.clear(); - action_buttons_.assign(action_work.begin(), action_work.end()); - layout_buttons(); DBG_DP << "buttons created\n"; } void display::render_buttons() { - for (std::shared_ptr btn : menu_buttons_) { + for(auto& btn : menu_buttons_) { btn->set_dirty(true); btn->draw(); } - for (std::shared_ptr btn : action_buttons_) { + for(auto& btn : action_buttons_) { btn->set_dirty(true); btn->draw(); } @@ -973,11 +960,10 @@ std::vector display::get_fog_shroud_images(const map_location& loc, ima std::vector names; const auto adjacent = get_adjacent_tiles(loc); - enum visibility {FOG=0, SHROUD=1, CLEAR=2}; - visibility tiles[6]; + enum visibility { FOG = 0, SHROUD = 1, CLEAR = 2 }; + std::array tiles; - const std::string* image_prefix[] = - { &game_config::fog_prefix, &game_config::shroud_prefix}; + const std::array image_prefix{&game_config::fog_prefix, &game_config::shroud_prefix}; for(int i = 0; i < 6; ++i) { if(shrouded(adjacent[i])) { @@ -1002,7 +988,7 @@ std::vector display::get_fog_shroud_images(const map_location& loc, ima // Completely surrounded by fog or shroud. This might have // a special graphic. const std::string name = *image_prefix[v] + "-all.png"; - if ( image::exists(name) ) { + if(image::exists(name)) { names.push_back(name); // Proceed to the next visibility (fog -> shroud -> clear). continue; @@ -1013,20 +999,20 @@ std::vector display::get_fog_shroud_images(const map_location& loc, ima } // Find all the directions overlap occurs from - for (int i = (start+1)%6, cap1 = 0; i != start && cap1 != 6; ++cap1) { + for(int i = (start + 1) % 6, cap1 = 0; i != start && cap1 != 6; ++cap1) { if(tiles[i] == v) { std::ostringstream stream; std::string name; stream << *image_prefix[v]; - for (int cap2 = 0; v == tiles[i] && cap2 != 6; i = (i+1)%6, ++cap2) { + for(int cap2 = 0; v == tiles[i] && cap2 != 6; i = (i + 1) % 6, ++cap2) { stream << get_direction(i); if(!image::exists(stream.str() + ".png")) { // If we don't have any surface at all, // then move onto the next overlapped area if(name.empty()) { - i = (i+1)%6; + i = (i + 1) % 6; } break; } else { @@ -1038,7 +1024,7 @@ std::vector display::get_fog_shroud_images(const map_location& loc, ima names.push_back(name + ".png"); } } else { - i = (i+1)%6; + i = (i + 1) % 6; } } } @@ -1046,40 +1032,31 @@ std::vector display::get_fog_shroud_images(const map_location& loc, ima // now get the surfaces std::vector res; - for (std::string& name : names) { - surface surf(image::get_image(name, image_type)); - if (surf) + for(const std::string& name : names) { + if(surface surf = image::get_image(name, image_type)) { res.push_back(std::move(surf)); + } } return res; } -void display::get_terrain_images(const map_location &loc, - const std::string& timeid, - TERRAIN_TYPE terrain_type) +void display::get_terrain_images(const map_location& loc, const std::string& timeid, TERRAIN_TYPE terrain_type) { terrain_image_vector_.clear(); - terrain_builder::TERRAIN_TYPE builder_terrain_type = - (terrain_type == FOREGROUND ? - terrain_builder::FOREGROUND : terrain_builder::BACKGROUND); - - const terrain_builder::imagelist* const terrains = builder_->get_terrain_at(loc, - timeid, builder_terrain_type); - image::light_string lt; - const time_of_day& tod = get_time_of_day(loc); - //get all the light transitions + // get all the light transitions const auto adjs = get_adjacent_tiles(loc); - std::array atods; - for(size_t d = 0; d < adjs.size(); ++d){ + std::array atods; + + for(std::size_t d = 0; d < adjs.size(); ++d) { atods[d] = &get_time_of_day(adjs[d]); } - for(int d=0; d<6; ++d){ + for(int d = 0; d < 6; ++d) { /* concave _____ @@ -1096,11 +1073,12 @@ void display::get_terrain_images(const map_location &loc, const time_of_day& atod1 = *atods[d]; const time_of_day& atod2 = *atods[(d + 1) % 6]; - if(atod1.color == tod.color || atod2.color == tod.color || atod1.color != atod2.color) + if(atod1.color == tod.color || atod2.color == tod.color || atod1.color != atod2.color) { continue; + } if(lt.empty()) { - //color the full hex before adding transitions + // color the full hex before adding transitions tod_color col = tod.color + color_adjust_; lt = image::get_light_string(0, col.r, col.g, col.b); } @@ -1109,7 +1087,8 @@ void display::get_terrain_images(const map_location &loc, tod_color acol = atod1.color + color_adjust_; lt += image::get_light_string(d + 1, acol.r, acol.g, acol.b); } - for(int d=0; d<6; ++d){ + + for(int d = 0; d < 6; ++d) { /* convex 1 _____ @@ -1126,11 +1105,12 @@ void display::get_terrain_images(const map_location &loc, const time_of_day& atod1 = *atods[d]; const time_of_day& atod2 = *atods[(d + 1) % 6]; - if(atod1.color == tod.color || atod1.color == atod2.color) + if(atod1.color == tod.color || atod1.color == atod2.color) { continue; + } if(lt.empty()) { - //color the full hex before adding transitions + // color the full hex before adding transitions tod_color col = tod.color + color_adjust_; lt = image::get_light_string(0, col.r, col.g, col.b); } @@ -1139,7 +1119,8 @@ void display::get_terrain_images(const map_location &loc, tod_color acol = atod1.color + color_adjust_; lt += image::get_light_string(d + 7, acol.r, acol.g, acol.b); } - for(int d=0; d<6; ++d){ + + for(int d = 0; d < 6; ++d) { /* convex 2 _____ @@ -1156,11 +1137,12 @@ void display::get_terrain_images(const map_location &loc, const time_of_day& atod1 = *atods[d]; const time_of_day& atod2 = *atods[(d + 1) % 6]; - if(atod2.color == tod.color || atod1.color == atod2.color) + if(atod2.color == tod.color || atod1.color == atod2.color) { continue; + } if(lt.empty()) { - //color the full hex before adding transitions + // color the full hex before adding transitions tod_color col = tod.color + color_adjust_; lt = image::get_light_string(0, col.r, col.g, col.b); } @@ -1178,21 +1160,23 @@ void display::get_terrain_images(const map_location &loc, } } - if(terrains != nullptr) { - // Cache the offmap name. - // Since it is themeable it can change, - // so don't make it static. + const terrain_builder::TERRAIN_TYPE builder_terrain_type = terrain_type == FOREGROUND + ? terrain_builder::FOREGROUND + : terrain_builder::BACKGROUND; + + if(const terrain_builder::imagelist* const terrains = builder_->get_terrain_at(loc, timeid, builder_terrain_type)) { + // Cache the offmap name. Since it is themeable it can change, so don't make it static. const std::string off_map_name = "terrain/" + theme_.border().tile_image; for(const auto& terrain : *terrains) { - const image::locator &image = animate_map_ ? - terrain.get_current_frame() : terrain.get_first_frame(); + const image::locator& image = animate_map_ ? terrain.get_current_frame() : terrain.get_first_frame(); // We prevent ToD coloring and brightening of off-map tiles, // We need to test for the tile to be rendered and // not the location, since the transitions are rendered // over the offmap-terrain and these need a ToD coloring. surface surf; - const bool off_map = (image.get_filename() == off_map_name || image.get_modifications().find("NO_TOD_SHIFT()") != std::string::npos); + const bool off_map = (image.get_filename() == off_map_name + || image.get_modifications().find("NO_TOD_SHIFT()") != std::string::npos); if(off_map) { surf = image::get_image(image, image::SCALED_TO_HEX); @@ -1202,7 +1186,7 @@ void display::get_terrain_images(const map_location &loc, surf = image::get_lighted_image(image, lt, image::SCALED_TO_HEX); } - if (surf) { + if(surf) { terrain_image_vector_.push_back(std::move(surf)); } } @@ -1298,17 +1282,16 @@ void display::drawing_buffer_commit() * layergroup > location > layer > 'blit_helper' > surface */ - for (const blit_helper &blit : drawing_buffer_) { - for (const surface& surf : blit.surf()) { + for(const blit_helper& blit : drawing_buffer_) { + for(const surface& surf : blit.surf()) { // Note that dstrect can be changed by sdl_blit // and so a new instance should be initialized // to pass to each call to sdl_blit. - SDL_Rect dstrect {blit.x(), blit.y(), 0, 0}; + SDL_Rect dstrect{blit.x(), blit.y(), 0, 0}; SDL_Rect srcrect = blit.clip(); - SDL_Rect *srcrectArg = (srcrect.x | srcrect.y | srcrect.w | srcrect.h) - ? &srcrect : nullptr; + SDL_Rect* srcrectArg = (srcrect.x | srcrect.y | srcrect.w | srcrect.h) ? &srcrect : nullptr; sdl_blit(surf, srcrectArg, screen, &dstrect); - //NOTE: the screen part should already be marked as 'to update' + // NOTE: the screen part should already be marked as 'to update' } } drawing_buffer_clear(); @@ -1756,8 +1739,8 @@ void display::announce(const std::string& message, const color_t& color, const a font::floating_label flabel(message); flabel.set_font_size(font::SIZE_FLOAT_LABEL); flabel.set_color(color); - flabel.set_position(map_outside_area().x + map_outside_area().w/2, - map_outside_area().y + map_outside_area().h/3); + flabel.set_position( + map_outside_area().x + map_outside_area().w / 2, map_outside_area().y + map_outside_area().h / 3); flabel.set_lifetime(options.lifetime); flabel.set_clip_rect(map_outside_area()); @@ -1806,8 +1789,8 @@ void display::draw_minimap() SDL_Rect map_rect = map_area(); SDL_Rect map_out_rect = map_outside_area(); double border = theme_.border().size; - double shift_x = - border*hex_width() - (map_out_rect.w - map_rect.w) / 2; - double shift_y = - (border+0.25)*hex_size() - (map_out_rect.h - map_rect.h) / 2; + double shift_x = -border * hex_width() - (map_out_rect.w - map_rect.w) / 2; + double shift_y = -(border + 0.25) * hex_size() - (map_out_rect.h - map_rect.h) / 2; int view_x = static_cast((xpos_ + shift_x) * xscaling); int view_y = static_cast((ypos_ + shift_y) * yscaling); @@ -2376,7 +2359,7 @@ double display::turbo_speed() const } res |= screen_.faked(); - if (res) + if(res) return preferences::turbo_speed(); else return 1.0; @@ -2441,23 +2424,25 @@ void display::clear_redraw_observers() redraw_observers_.clear(); } -void display::draw() { +void display::draw() +{ draw(true, false); } -void display::draw(bool update) { +void display::draw(bool update) +{ draw(update, false); } +void display::draw(bool update, bool force) +{ + // log_scope("display::draw"); -void display::draw(bool update,bool force) { -// log_scope("display::draw"); - - if (screen_.update_locked()) { + if(screen_.update_locked()) { return; } - if (dirty_) { + if(dirty_) { flip_locker flip_lock(screen_); dirty_ = false; redraw_everything(); @@ -2465,7 +2450,7 @@ void display::draw(bool update,bool force) { } // Trigger cache rebuild when preference gets changed - if (animate_water_ != preferences::animate_water()) { + if(animate_water_ != preferences::animate_water()) { animate_water_ = preferences::animate_water(); builder_->rebuild_cache_all(); } @@ -2478,8 +2463,6 @@ void display::draw(bool update,bool force) { invalidate_animations(); if(!get_map().empty()) { - //int simulate_delay = 0; - /* * draw_invalidated() also invalidates the halos, so also needs to be * ran if invalidated_.empty() == true. @@ -2491,9 +2474,6 @@ void display::draw(bool update,bool force) { drawing_buffer_commit(); post_commit(); draw_sidebar(); - - // Simulate slow PC: - //SDL_Delay(2*simulate_delay + rand() % 20); } draw_wrap(update, force); post_draw(); @@ -2533,25 +2513,25 @@ void display::draw_invalidated() { } invalidated_hexes_ += invalidated_.size(); - if (dc_->teams().empty()) - { - // The unit drawer can't function without teams + // The unit drawer can't function without teams + if(dc_->teams().empty()) { return; } unit_drawer drawer = unit_drawer(*this); - for (const map_location& loc : invalidated_) { + for(const map_location& loc : invalidated_) { unit_map::const_iterator u_it = dc_->units().find(loc); exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc); - if (u_it != dc_->units().end() - && (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id())) + if(u_it != dc_->units().end() + && (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id())) { drawer.redraw_unit(*u_it); + } } - } -void display::draw_hex(const map_location& loc) { +void display::draw_hex(const map_location& loc) +{ int xpos = get_location_x(loc); int ypos = get_location_y(loc); image::TYPE image_type = get_image_type(loc); @@ -3039,7 +3019,7 @@ bool display::propagate_invalidation(const std::set& locs) bool display::invalidate_visible_locations_in_rect(const SDL_Rect& rect) { - return invalidate_locations_in_rect(sdl::intersect_rects(map_area(),rect)); + return invalidate_locations_in_rect(sdl::intersect_rects(map_area(), rect)); } bool display::invalidate_locations_in_rect(const SDL_Rect& rect) @@ -3048,17 +3028,18 @@ bool display::invalidate_locations_in_rect(const SDL_Rect& rect) return false; bool result = false; - for (const map_location &loc : hexes_under_rect(rect)) { + for(const map_location& loc : hexes_under_rect(rect)) { result |= invalidate(loc); } return result; } -void display::invalidate_animations_location(const map_location& loc) { - if (get_map().is_village(loc)) { +void display::invalidate_animations_location(const map_location& loc) +{ + if(get_map().is_village(loc)) { const int owner = dc_->village_owner(loc) - 1; - if (owner >= 0 && flags_[owner].need_update() - && (!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(owner+1))) { + if(owner >= 0 && flags_[owner].need_update() + && (!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(owner + 1))) { invalidate(loc); } } @@ -3068,11 +3049,11 @@ void display::invalidate_animations() { new_animation_frame(); animate_map_ = preferences::animate_map(); - if (animate_map_) { - for (const map_location &loc : get_visible_hexes()) - { - if (shrouded(loc)) continue; - if (builder_->update_animation(loc)) { + if(animate_map_) { + for(const map_location& loc : get_visible_hexes()) { + if(shrouded(loc)) + continue; + if(builder_->update_animation(loc)) { invalidate(loc); } else { invalidate_animations_location(loc); @@ -3083,21 +3064,20 @@ void display::invalidate_animations() for(const unit& u : dc_->units()) { u.anim_comp().refresh(); } - for (const unit* u : *fake_unit_man_) { + for(const unit* u : *fake_unit_man_) { u->anim_comp().refresh(); } - bool new_inval; do { new_inval = false; - for (const unit & u : dc_->units()) { - new_inval |= u.anim_comp().invalidate(*this); + for(const unit& u : dc_->units()) { + new_inval |= u.anim_comp().invalidate(*this); } - for (const unit* u : *fake_unit_man_) { - new_inval |= u->anim_comp().invalidate(*this); + for(const unit* u : *fake_unit_man_) { + new_inval |= u->anim_comp().invalidate(*this); } - } while (new_inval); + } while(new_inval); } void display::reset_standing_animations() @@ -3109,32 +3089,25 @@ void display::reset_standing_animations() void display::add_arrow(arrow& arrow) { - const arrow_path_t & arrow_path = arrow.get_path(); - for (const map_location& loc : arrow_path) - { + for(const map_location& loc : arrow.get_path()) { arrows_map_[loc].push_back(&arrow); } } void display::remove_arrow(arrow& arrow) { - const arrow_path_t & arrow_path = arrow.get_path(); - for (const map_location& loc : arrow_path) - { + for(const map_location& loc : arrow.get_path()) { arrows_map_[loc].remove(&arrow); } } void display::update_arrow(arrow & arrow) { - const arrow_path_t & previous_path = arrow.get_previous_path(); - for (const map_location& loc : previous_path) - { + for(const map_location& loc : arrow.get_previous_path()) { arrows_map_[loc].remove(&arrow); } - const arrow_path_t & arrow_path = arrow.get_path(); - for (const map_location& loc : arrow_path) - { + + for(const map_location& loc : arrow.get_path()) { arrows_map_[loc].push_back(&arrow); } } @@ -3201,26 +3174,26 @@ void display::process_reachmap_changes() reach_map_changed_ = false; } -void display::handle_window_event(const SDL_Event& event) { - if (event.type == SDL_WINDOWEVENT) { - switch (event.window.event) { - case SDL_WINDOWEVENT_RESIZED: - case SDL_WINDOWEVENT_RESTORED: - case SDL_WINDOWEVENT_EXPOSED: - dirty_ = true; +void display::handle_window_event(const SDL_Event& event) +{ + if(event.type == SDL_WINDOWEVENT) { + switch(event.window.event) { + case SDL_WINDOWEVENT_RESIZED: + case SDL_WINDOWEVENT_RESTORED: + case SDL_WINDOWEVENT_EXPOSED: + dirty_ = true; - break; - } + break; + } } - - } -void display::handle_event(const SDL_Event& event) { - if (gui2::dialogs::loading_screen::displaying()) { +void display::handle_event(const SDL_Event& event) +{ + if(gui2::dialogs::loading_screen::displaying()) { return; } - if (event.type == DRAW_ALL_EVENT) { + if(event.type == DRAW_ALL_EVENT) { draw(); } }