Display: cleaned up overlay map getter interface
Instead of a pointer to a member of a derived class, used a virtual function implemented in both derived classes (game_display and editor_display) that return an reference to the appropriate object. Also removed the overlay.hpp include from display.hpp. We can forward-declare the overlay struct.
This commit is contained in:
parent
f0f664b636
commit
e583c470be
7 changed files with 26 additions and 19 deletions
|
@ -131,7 +131,6 @@ display::display(const display_context* dc,
|
|||
, activeTeam_(0)
|
||||
, map_screenshot_(false)
|
||||
, reach_map_()
|
||||
, overlays_(nullptr)
|
||||
, fps_handle_(0)
|
||||
, drawn_hexes_(0)
|
||||
, idle_anim_(preferences::idle_anim())
|
||||
|
@ -295,25 +294,25 @@ void display::add_overlay(const map_location& loc,
|
|||
get_location_y(loc) + hex_size() / 2, halo, loc
|
||||
);
|
||||
|
||||
overlays_->emplace(loc, overlay(img, halo, halo_handle, team_name, item_id, visible_under_fog));
|
||||
get_overlays().emplace(loc, overlay(img, halo, halo_handle, team_name, item_id, visible_under_fog));
|
||||
}
|
||||
}
|
||||
|
||||
void display::remove_overlay(const map_location& loc)
|
||||
{
|
||||
overlays_->erase(loc);
|
||||
get_overlays().erase(loc);
|
||||
}
|
||||
|
||||
void display::remove_single_overlay(const map_location& loc, const std::string& toDelete)
|
||||
{
|
||||
// Iterate through the values with key of loc
|
||||
auto itors = overlays_->equal_range(loc);
|
||||
auto itors = get_overlays().equal_range(loc);
|
||||
|
||||
while(itors.first != itors.second) {
|
||||
const overlay& o = itors.first->second;
|
||||
|
||||
if(o.image == toDelete || o.halo == toDelete || o.id == toDelete) {
|
||||
overlays_->erase(itors.first++);
|
||||
get_overlays().erase(itors.first++);
|
||||
} else {
|
||||
++itors.first;
|
||||
}
|
||||
|
@ -1695,7 +1694,7 @@ void display::draw_gamemap()
|
|||
//
|
||||
// On-map overlays, such as [item]s.
|
||||
//
|
||||
for(const auto& overlay_record : *overlays_) {
|
||||
for(const auto& overlay_record : get_overlays()) {
|
||||
const map_location& o_loc = overlay_record.first;
|
||||
|
||||
if(shrouded(o_loc)) {
|
||||
|
|
|
@ -39,6 +39,7 @@ class map_labels;
|
|||
class arrow;
|
||||
class reports;
|
||||
class team;
|
||||
struct overlay;
|
||||
|
||||
namespace halo
|
||||
{
|
||||
|
@ -59,7 +60,6 @@ class manager;
|
|||
#include "image.hpp" //only needed for enums (!)
|
||||
#include "key.hpp"
|
||||
#include "map/hex_rect.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
#include "sdl/surface.hpp"
|
||||
#include "sdl/texture.hpp"
|
||||
|
@ -935,9 +935,9 @@ protected:
|
|||
|
||||
typedef std::multimap<map_location, overlay> overlay_map;
|
||||
|
||||
private:
|
||||
overlay_map* overlays_;
|
||||
virtual overlay_map& get_overlays() = 0;
|
||||
|
||||
private:
|
||||
/** Handle for the label which displays frames per second. */
|
||||
int fps_handle_;
|
||||
/** Count work done for the debug info displayed under fps */
|
||||
|
@ -962,12 +962,6 @@ private:
|
|||
|
||||
tod_color color_adjust_;
|
||||
|
||||
public:
|
||||
void replace_overlay_map(overlay_map* overlays)
|
||||
{
|
||||
overlays_ = overlays;
|
||||
}
|
||||
|
||||
protected:
|
||||
static display* singleton_;
|
||||
};
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "editor/editor_display.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "sdl/texture.hpp"
|
||||
#include "team.hpp"
|
||||
|
@ -134,4 +135,9 @@ const time_of_day& editor_display::get_time_of_day(const map_location& /*loc*/)
|
|||
return controller_.get_current_map_context().get_time_manager()->get_time_of_day();
|
||||
}
|
||||
|
||||
display::overlay_map& editor_display::get_overlays()
|
||||
{
|
||||
return controller_.get_current_map_context().get_overlays();
|
||||
}
|
||||
|
||||
} //end namespace editor
|
||||
|
|
|
@ -51,6 +51,9 @@ protected:
|
|||
virtual void draw_hex_cursor(const map_location& loc) override;
|
||||
virtual void draw_hex_overlays() override;
|
||||
|
||||
/** Inherited from display. */
|
||||
virtual overlay_map& get_overlays() override;
|
||||
|
||||
const SDL_Rect get_clip_rect() override;
|
||||
|
||||
std::set<map_location> brush_locations_;
|
||||
|
|
|
@ -99,9 +99,6 @@ void context_manager::refresh_on_context_change()
|
|||
|
||||
// TODO register the tod_manager with the gui?
|
||||
resources::tod_manager = get_map_context().get_time_manager();
|
||||
|
||||
gui().replace_overlay_map(&get_map_context().get_overlays());
|
||||
|
||||
resources::classification = &get_map_context().get_classification();
|
||||
|
||||
gui().init_flags();
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "map/label.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "resources.hpp"
|
||||
|
@ -70,7 +71,6 @@ game_display::game_display(game_board& board, std::weak_ptr<wb::manager> wb,
|
|||
, mode_(RUNNING)
|
||||
, needs_rebuild_(false)
|
||||
{
|
||||
replace_overlay_map(&overlay_map_);
|
||||
#ifdef USE_GL_RENDERING
|
||||
gl::clear_screen();
|
||||
#else
|
||||
|
@ -692,3 +692,8 @@ bool game_display::maybe_rebuild()
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
display::overlay_map& game_display::get_overlays()
|
||||
{
|
||||
return overlay_map_;
|
||||
}
|
||||
|
|
|
@ -142,6 +142,9 @@ protected:
|
|||
|
||||
virtual void draw_hex_overlays() override;
|
||||
|
||||
/** Inherited from display. */
|
||||
virtual overlay_map& get_overlays() override;
|
||||
|
||||
public:
|
||||
/** Set the attack direction indicator. */
|
||||
void set_attack_indicator(const map_location& src, const map_location& dst);
|
||||
|
|
Loading…
Add table
Reference in a new issue