move halo::manager from play_controller to display

Also this removes the need to have it in the editor.
This commit is contained in:
Chris Beck 2014-06-27 10:29:54 -04:00
parent 1010fbee77
commit b0e407ac66
10 changed files with 34 additions and 33 deletions

View file

@ -100,8 +100,8 @@ void display::parse_team_overlays()
void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo,const std::string& team_name, bool visible_under_fog)
{
if (resources::halo) {
const halo::handle halo_handle = resources::halo->add(get_location_x(loc) + hex_size() / 2,
if (halo_man_) {
const halo::handle halo_handle = halo_man_->add(get_location_x(loc) + hex_size() / 2,
get_location_y(loc) + hex_size() / 2, halo, loc);
const overlay item(img, halo, halo_handle, team_name, visible_under_fog);
@ -112,11 +112,11 @@ void display::add_overlay(const map_location& loc, const std::string& img, const
void display::remove_overlay(const map_location& loc)
{
/* This code no longer needed because of RAII in halo::handles
if (resources::halo) {
if (halo_man_) {
typedef overlay_map::const_iterator Itor;
std::pair<Itor,Itor> itors = overlays_->equal_range(loc);
while(itors.first != itors.second) {
resources::halo->remove(itors.first->second.halo_handle);
halo_man_->remove(itors.first->second.halo_handle);
++itors.first;
}
}
@ -136,7 +136,7 @@ void display::remove_single_overlay(const map_location& loc, const std::string&
if(itors.first->second.image == toDelete || itors.first->second.halo == toDelete) {
iteratorCopy = itors.first;
++itors.first;
//Not needed because of RAII -->resources::halo->remove(iteratorCopy->second.halo_handle);
//Not needed because of RAII --> halo_man_->remove(iteratorCopy->second.halo_handle);
overlays_->erase(iteratorCopy);
}
else {
@ -150,6 +150,7 @@ void display::remove_single_overlay(const map_location& loc, const std::string&
display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb, const config& theme_cfg, const config& level) :
dc_(dc),
halo_man_(new halo::manager(*this)),
wb_(wb),
exclusive_unit_draw_requests_(),
screen_(video),
@ -584,6 +585,16 @@ void display::change_display_context(const display_context * dc)
builder_->change_map(&dc_->map()); //TODO: Should display_context own and initalize the builder object?
}
void display::reset_halo_manager()
{
halo_man_.reset(new halo::manager(*this));
}
void display::reset_halo_manager(halo::manager & halo_man)
{
halo_man_.reset(&halo_man);
}
void display::blindfold(bool value)
{
if(value == true)

View file

@ -39,6 +39,10 @@ class terrain_builder;
class map_labels;
class arrow;
namespace halo {
class manager;
}
namespace wb {
class manager;
}
@ -168,9 +172,12 @@ public:
void reload_map();
void change_display_context(const display_context * dc);
const display_context & get_disp_context() const { return *dc_; }
void reset_halo_manager();
void reset_halo_manager(halo::manager & hm);
halo::manager & get_halo_manager() { return *halo_man_; }
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
{ return 0xFF000000 | (red << 16) | (green << 8) | blue; }
static Uint8 red(Uint32 color)
@ -641,6 +648,7 @@ private:
protected:
//TODO sort
const display_context * dc_;
boost::scoped_ptr<halo::manager> halo_man_;
boost::weak_ptr<wb::manager> wb_;
typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;

View file

@ -70,7 +70,6 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
, prefs_disp_manager_(NULL)
, tooltip_manager_(video)
, floating_label_manager_(NULL)
, halo_manager_(NULL)
, help_manager_(NULL)
, do_quit_(false)
, quit_mode_(EXIT_ERROR)
@ -99,8 +98,12 @@ void editor_controller::init_gui()
floating_label_manager_.reset(new font::floating_label_context());
gui().set_draw_coordinates(preferences::editor::draw_hex_coordinates());
gui().set_draw_terrain_codes(preferences::editor::draw_terrain_codes());
halo_manager_.reset(new halo::manager(*gui_));
resources::halo = halo_manager_.get();
// halo_manager_.reset(new halo::manager(*gui_));
// resources::halo = halo_manager_.get();
// ^ These lines no longer necessary, the gui owns its halo manager.
// TODO: Should the editor map contexts actually own the halo manager and swap them in and out from the gui?
// Note that if that is what happens it might not actually be a good idea for the gui to own the halo manager, so that it can be swapped out
// without deleting it.
}
void editor_controller::init_tods(const config& game_config)

View file

@ -43,10 +43,6 @@ namespace preferences {
struct display_manager;
} // namespace preferences
namespace halo {
class manager;
} // namespace halo
namespace editor {
class editor_map;
@ -235,7 +231,6 @@ class editor_controller : public controller_base,
tooltips::manager tooltip_manager_;
boost::scoped_ptr<font::floating_label_context> floating_label_manager_;
boost::scoped_ptr<halo::manager> halo_manager_;
boost::scoped_ptr<help::help_manager> help_manager_;
/** Quit main loop flag */

View file

@ -252,9 +252,7 @@ void game_display::post_draw() {
void game_display::draw_invalidated()
{
if (resources::halo) {
resources::halo->unrender(invalidated_);
}
halo_man_->unrender(invalidated_);
display::draw_invalidated();
unit_drawer drawer = unit_drawer(*this);
@ -270,9 +268,7 @@ void game_display::draw_invalidated()
void game_display::post_commit()
{
if (resources::halo) {
resources::halo->render();
}
halo_man_->render();
}
void game_display::draw_hex(const map_location& loc)

View file

@ -104,7 +104,6 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
prefs_disp_manager_(),
tooltips_manager_(),
events_manager_(),
halo_manager_(),
labels_manager_(),
help_manager_(&game_config),
mouse_handler_(NULL, gamestate_.board_),
@ -271,9 +270,6 @@ void play_controller::init_managers(){
soundsources_manager_.reset(new soundsource::manager(*gui_));
resources::soundsources = soundsources_manager_.get();
halo_manager_.reset(new halo::manager(*gui_));
resources::halo = halo_manager_.get();
LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks_) << std::endl;
}

View file

@ -45,10 +45,6 @@ namespace game_events {
class wml_menu_item;
} // namespace game_events
namespace halo {
class manager;
} // namespace halo
namespace preferences {
struct display_manager;
}
@ -228,7 +224,6 @@ protected:
boost::scoped_ptr<preferences::display_manager> prefs_disp_manager_;
boost::scoped_ptr<tooltips::manager> tooltips_manager_;
boost::scoped_ptr<game_events::manager> events_manager_;
boost::scoped_ptr<halo::manager> halo_manager_;
font::floating_label_context labels_manager_;
help::help_manager help_manager_;

View file

@ -25,7 +25,6 @@ namespace resources
persist_manager *persist = NULL;
game_display *screen = NULL;
soundsource::manager *soundsources = NULL;
halo::manager *halo = NULL;
std::vector<team> *teams = NULL;
::tod_manager *tod_manager = NULL;
fake_unit_manager *fake_units = NULL;

View file

@ -54,7 +54,6 @@ namespace resources
extern game_display *screen;
extern const mp_game_settings *mp_settings;
extern soundsource::manager *soundsources;
extern halo::manager *halo;
extern std::vector<team> *teams;
extern fake_unit_manager *fake_units;
extern ::tod_manager *tod_manager;

View file

@ -20,7 +20,6 @@
#include "halo.hpp"
#include "map.hpp"
#include "map_location.hpp"
#include "resources.hpp" //only for halo::manager
#include "sdl/utils.hpp"
#include "team.hpp"
#include "unit.hpp"
@ -35,7 +34,7 @@ unit_drawer::unit_drawer(display & thedisp) :
dc(disp.get_disp_context()),
map(dc.map()),
teams(dc.teams()),
halo_man(*resources::halo),
halo_man(thedisp.get_halo_manager()),
viewing_team(disp.viewing_team()),
playing_team(disp.playing_team()),
viewing_team_ref(teams[viewing_team]),