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.
This commit is contained in:
Chris Beck 2014-06-12 20:09:05 -04:00
parent 816be79aa2
commit dd8e0159f9
4 changed files with 20 additions and 17 deletions

View file

@ -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 )

View file

@ -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<time_of_day>& schedule = resources::tod_manager->times(hex);
const std::vector<time_of_day>& 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 << "<b>";
@ -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());
}

View file

@ -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 <vector>
#include <boost/optional.hpp>
@ -44,7 +46,7 @@ namespace reports {
class context
{
public:
context(const display_context & dc, display & disp, boost::shared_ptr<wb::manager> wb, boost::optional<events::mouse_handler &> mhb) : dc_(dc), disp_(disp), wb_(wb), mhb_(mhb) {}
context(const display_context & dc, display & disp, const tod_manager & tod, boost::shared_ptr<wb::manager> wb, boost::optional<events::mouse_handler &> mhb) : dc_(dc), disp_(disp), tod_(tod), wb_(wb), mhb_(mhb) {}
const std::vector<team> & 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::manager> wb() { return wb_; }
boost::optional<events::mouse_handler&> mhb() { return mhb_; }
private:
const display_context & dc_;
display & disp_;
const tod_manager & tod_;
boost::shared_ptr<wb::manager> wb_;
boost::optional<events::mouse_handler&> mhb_;
};

View file

@ -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;
}