From dd8e0159f90a115654de4f0612a6917f0ed00c0f Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 12 Jun 2014 20:09:05 -0400 Subject: [PATCH] add tod manager to report::context This allows to remove all remaining resources:: links from the reports generator code, and to finish removing several expensive dependencies from that compilation unit. --- src/display.cpp | 2 +- src/reports.cpp | 25 ++++++++++++------------- src/reports.hpp | 8 ++++++-- src/scripting/lua.cpp | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index b500b37371b..c8f4660ca81 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -2742,7 +2742,7 @@ void display::refresh_report(std::string const &report_name, const config * new_ mhb = resources::controller->get_mouse_handler_base(); } - reports::context temp_context = reports::context(*dc_, *this, wb_.lock(), mhb); + reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb); const config generated_cfg = new_cfg ? config() : reports::generate_report(report_name, temp_context); if ( new_cfg == NULL ) diff --git a/src/reports.cpp b/src/reports.cpp index 7469f5dd385..94de5d4cccb 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -25,9 +25,8 @@ #include "language.hpp" #include "map.hpp" #include "marked-up_text.hpp" -#include "play_controller.hpp" +#include "mouse_events.hpp" #include "reports.hpp" -#include "resources.hpp" #include "strftime.hpp" #include "team.hpp" #include "text.hpp" @@ -1111,9 +1110,9 @@ REPORT_GENERATOR(tod_stats, rc) const map_location& hex = mouseover_hex.valid() ? mouseover_hex : selected_hex; - const std::vector& schedule = resources::tod_manager->times(hex); + const std::vector& schedule = rc.tod().times(hex); - int current = resources::tod_manager->get_current_time(hex); + int current = rc.tod().get_current_time(hex); int i = 0; BOOST_FOREACH(const time_of_day& tod, schedule) { if (i == current) tooltip << ""; @@ -1135,12 +1134,12 @@ static config time_of_day_at(reports::context & rc, const map_location& mouseove const team &viewing_team = rc.teams()[rc.screen().viewing_team()]; if (viewing_team.shrouded(mouseover_hex)) { // Don't show time on shrouded tiles. - tod = resources::tod_manager->get_time_of_day(); + tod = rc.tod().get_time_of_day(); } else if (viewing_team.fogged(mouseover_hex)) { // Don't show illuminated time on fogged tiles. - tod = resources::tod_manager->get_time_of_day(mouseover_hex); + tod = rc.tod().get_time_of_day(mouseover_hex); } else { - tod = resources::tod_manager->get_illuminated_time_of_day(mouseover_hex); + tod = rc.tod().get_illuminated_time_of_day(mouseover_hex); } int b = tod.lawful_bonus; @@ -1181,16 +1180,16 @@ static config unit_box_at(reports::context & rc, const map_location& mouseover_h { std::ostringstream tooltip; time_of_day local_tod; - time_of_day global_tod = resources::tod_manager->get_time_of_day(); + time_of_day global_tod = rc.tod().get_time_of_day(); const team &viewing_team = rc.teams()[rc.screen().viewing_team()]; if (viewing_team.shrouded(mouseover_hex)) { // Don't show time on shrouded tiles. local_tod = global_tod; } else if (viewing_team.fogged(mouseover_hex)) { // Don't show illuminated time on fogged tiles. - local_tod = resources::tod_manager->get_time_of_day(mouseover_hex); + local_tod = rc.tod().get_time_of_day(mouseover_hex); } else { - local_tod = resources::tod_manager->get_illuminated_time_of_day(mouseover_hex); + local_tod = rc.tod().get_illuminated_time_of_day(mouseover_hex); } int bonus = local_tod.lawful_bonus; @@ -1259,11 +1258,11 @@ REPORT_GENERATOR(unit_box, rc) } -REPORT_GENERATOR(turn, /*dc*/) +REPORT_GENERATOR(turn, rc) { std::ostringstream str; - str << resources::tod_manager->turn(); - int nb = resources::tod_manager->number_of_turns(); + str << rc.tod().turn(); + int nb = rc.tod().number_of_turns(); if (nb != -1) str << '/' << nb; return text_report(str.str()); } diff --git a/src/reports.hpp b/src/reports.hpp index c19575d4097..597dfb7a223 100644 --- a/src/reports.hpp +++ b/src/reports.hpp @@ -15,8 +15,10 @@ #ifndef REPORTS_HPP_INCLUDED #define REPORTS_HPP_INCLUDED -#include "map_location.hpp" #include "display_context.hpp" +#include "map_location.hpp" +#include "tod_manager.hpp" + #include #include @@ -44,7 +46,7 @@ namespace reports { class context { public: - context(const display_context & dc, display & disp, boost::shared_ptr wb, boost::optional mhb) : dc_(dc), disp_(disp), wb_(wb), mhb_(mhb) {} + context(const display_context & dc, display & disp, const tod_manager & tod, boost::shared_ptr wb, boost::optional mhb) : dc_(dc), disp_(disp), tod_(tod), wb_(wb), mhb_(mhb) {} const std::vector & teams() { return dc_.teams(); } const unit_map & units() { return dc_.units(); } @@ -52,12 +54,14 @@ public: const display_context & dc() { return dc_; } display & screen() { return disp_; } + const tod_manager & tod() { return tod_; } boost::shared_ptr wb() { return wb_; } boost::optional mhb() { return mhb_; } private: const display_context & dc_; display & disp_; + const tod_manager & tod_; boost::shared_ptr wb_; boost::optional mhb_; }; diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index fd3dc6a5109..c2499bdf557 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -3597,7 +3597,7 @@ namespace { static int cfun_theme_item(lua_State *L) { const char *m = lua_tostring(L, lua_upvalueindex(1)); - reports::context temp_context = reports::context(*resources::disp_context, *resources::screen, resources::whiteboard, resources::controller->get_mouse_handler_base()); + reports::context temp_context = reports::context(*resources::disp_context, *resources::screen, *resources::tod_manager, resources::whiteboard, resources::controller->get_mouse_handler_base()); luaW_pushconfig(L, reports::generate_report(m, temp_context , true)); return 1; }