Skip to content

Commit

Permalink
Merge branch 'refactor_reports'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 13, 2014
2 parents 62eb55a + 89c22a8 commit 2c312a1
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 319 deletions.
19 changes: 15 additions & 4 deletions src/display.cpp
Expand Up @@ -28,6 +28,7 @@
#include "map.hpp"
#include "map_label.hpp"
#include "minimap.hpp"
#include "play_controller.hpp" //note: this can probably be refactored out
#include "reports.hpp"
#include "terrain_builder.hpp"
#include "text.hpp"
Expand Down Expand Up @@ -136,8 +137,9 @@ void display::remove_single_overlay(const map_location& loc, const std::string&



display::display(const display_context * dc, CVideo& video, const config& theme_cfg, const config& level) :
display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb, const config& theme_cfg, const config& level) :
dc_(dc),
wb_(wb),
exclusive_unit_draw_requests_(),
screen_(video),
currentTeam_(0),
Expand Down Expand Up @@ -364,8 +366,8 @@ void display::set_team(size_t teamindex, bool show_everything)
viewpoint_ = NULL;
}
labels().recalculate_labels();
if(resources::whiteboard)
resources::whiteboard->on_viewer_change(teamindex);
if(boost::shared_ptr<wb::manager> w = wb_.lock())
w->on_viewer_change(teamindex);
}

void display::set_playing_team(size_t teamindex)
Expand Down Expand Up @@ -2733,7 +2735,16 @@ void display::refresh_report(std::string const &report_name, const config * new_
}

// Now we will need the config. Generate one if needed.
const config generated_cfg = new_cfg ? config() : reports::generate_report(report_name);

boost::optional <events::mouse_handler &> mhb = boost::none;

if (resources::controller) {
mhb = resources::controller->get_mouse_handler_base();
}

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 )
new_cfg = &generated_cfg;

Expand Down
13 changes: 12 additions & 1 deletion src/display.hpp
Expand Up @@ -39,6 +39,10 @@ struct time_of_day;
class map_labels;
class arrow;

namespace wb {
class manager;
}

#include "display_context.hpp"
#include "font.hpp"
#include "key.hpp"
Expand All @@ -55,6 +59,7 @@ class arrow;
#include <list>

#include <boost/function.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <map>

Expand All @@ -63,7 +68,7 @@ class gamemap;
class display
{
public:
display(const display_context * dc, CVideo& video,
display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::manager> wb,
const config& theme_cfg, const config& level);
virtual ~display();
static display* get_singleton() { return singleton_ ;}
Expand Down Expand Up @@ -191,6 +196,11 @@ class display
virtual bool in_game() const { return false; }
virtual bool in_editor() const { return false; }

/** Virtual functions shadowed in game_display. These are needed to generate reports easily, without dynamic casting. Hope to factor out eventually. */
virtual const map_location & displayed_unit_hex() const { return map_location::null_location(); }
virtual int playing_side() const { return -100; } //In this case give an obviously wrong answer to fail fast, since this could actually cause a big bug. */
virtual const std::set<std::string>& observers() const { static const std::set<std::string> fake_obs = std::set<std::string> (); return fake_obs; }

/**
* the dimensions of the display. x and y are width/height.
* mapx is the width of the portion of the display which shows the game area.
Expand Down Expand Up @@ -627,6 +637,7 @@ class display
protected:
//TODO sort
const display_context * dc_;
boost::weak_ptr<wb::manager> wb_;

typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;
/// map of hexes where only one unit should be drawn, the one identified by the associated id string
Expand Down
8 changes: 7 additions & 1 deletion src/editor/editor_display.cpp
Expand Up @@ -17,6 +17,12 @@
#include "reports.hpp"
#include "terrain_builder.hpp"

#include <boost/shared_ptr.hpp>

namespace wb {
class manager;
}

namespace editor {

// Define dummy display context;
Expand Down Expand Up @@ -47,7 +53,7 @@ const display_context * get_dummy_display_context() {

editor_display::editor_display(const display_context * dc, CVideo& video,
const config& theme_cfg, const config& level)
: display(dc, video, theme_cfg, level)
: display(dc, video, boost::shared_ptr<wb::manager>(), theme_cfg, level)
, brush_locations_()
, palette_report_()
{
Expand Down
42 changes: 23 additions & 19 deletions src/game_display.cpp
Expand Up @@ -61,10 +61,10 @@ static lg::log_domain log_engine("engine");

std::map<map_location,fixed_t> game_display::debugHighlights_;

game_display::game_display(game_board& board, CVideo& video,
game_display::game_display(game_board& board, CVideo& video, boost::weak_ptr<wb::manager> wb,
const tod_manager& tod,
const config& theme_cfg, const config& level) :
display(&board, video, theme_cfg, level),
display(&board, video, wb, theme_cfg, level),
overlay_map_(),
fake_units_(),
attack_indicator_src_(),
Expand All @@ -90,7 +90,7 @@ game_display* game_display::create_dummy_display(CVideo& video)
static config dummy_cfg2;
static game_board dummy_board(dummy_cfg, dummy_cfg2);
static tod_manager dummy_tod(dummy_cfg);
return new game_display(dummy_board, video, dummy_tod,
return new game_display(dummy_board, video, boost::shared_ptr<wb::manager>(), dummy_tod,
dummy_cfg, dummy_cfg);
}

Expand Down Expand Up @@ -222,8 +222,8 @@ void game_display::scroll_to_leader(int side, SCROLL_TYPE scroll_type,bool force
}

void game_display::pre_draw() {
if (resources::whiteboard) {
resources::whiteboard->pre_draw();
if (boost::shared_ptr<wb::manager> w = wb_.lock()) {
w->pre_draw();
}
process_reachmap_changes();
/**
Expand All @@ -235,8 +235,8 @@ void game_display::pre_draw() {


void game_display::post_draw() {
if (resources::whiteboard) {
resources::whiteboard->post_draw();
if (boost::shared_ptr<wb::manager> w = wb_.lock()) {
w->post_draw();
}
}

Expand Down Expand Up @@ -318,14 +318,16 @@ void game_display::draw_hex(const map_location& loc)
image::get_image(unreachable,image::SCALED_TO_HEX));
}

resources::whiteboard->draw_hex(loc);
if (boost::shared_ptr<wb::manager> w = wb_.lock()) {
w->draw_hex(loc);

if (!(resources::whiteboard->is_active() && resources::whiteboard->has_temp_move()))
{
// Footsteps indicating a movement path
const std::vector<surface>& footstepImages = footsteps_images(loc);
if (!footstepImages.empty()) {
drawing_buffer_add(LAYER_FOOTSTEPS, loc, xpos, ypos, footstepImages);
if (!(w->is_active() && w->has_temp_move()))
{
// Footsteps indicating a movement path
const std::vector<surface>& footstepImages = footsteps_images(loc);
if (!footstepImages.empty()) {
drawing_buffer_add(LAYER_FOOTSTEPS, loc, xpos, ypos, footstepImages);
}
}
}
// Draw the attack direction indicator
Expand Down Expand Up @@ -411,12 +413,14 @@ void game_display::draw_movement_info(const map_location& loc)
// Search if there is a mark here
pathfind::marked_route::mark_map::iterator w = route_.marks.find(loc);

boost::shared_ptr<wb::manager> wb = wb_.lock();

// Don't use empty route or the first step (the unit will be there)
if(w != route_.marks.end()
&& !route_.steps.empty() && route_.steps.front() != loc) {
const unit_map::const_iterator un =
resources::whiteboard->get_temp_move_unit().valid() ?
resources::whiteboard->get_temp_move_unit() : dc_->units().find(route_.steps.front());
(wb && wb->get_temp_move_unit().valid()) ?
wb->get_temp_move_unit() : dc_->units().find(route_.steps.front());
if(un != dc_->units().end()) {
// Display the def% of this terrain
int def = 100 - un->defense_modifier(get_map().get_terrain(loc));
Expand All @@ -432,7 +436,7 @@ void game_display::draw_movement_info(const map_location& loc)
int xpos = get_location_x(loc);
int ypos = get_location_y(loc);

if (w->second.invisible) {
if (w->second.invisible) {
drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
image::get_image("misc/hidden.png", image::SCALED_TO_HEX));
}
Expand Down Expand Up @@ -1002,8 +1006,8 @@ void game_display::set_team(size_t teamindex, bool show_everything)
viewpoint_ = NULL;
}
labels().recalculate_labels();
if(resources::whiteboard)
resources::whiteboard->on_viewer_change(teamindex);
if(boost::shared_ptr<wb::manager> w = wb_.lock())
w->on_viewer_change(teamindex);
}

void game_display::set_playing_team(size_t teamindex)
Expand Down
1 change: 1 addition & 0 deletions src/game_display.hpp
Expand Up @@ -38,6 +38,7 @@ class game_display : public display
{
public:
game_display(game_board& board, CVideo& video,
boost::weak_ptr<wb::manager> wb,
const tod_manager& tod_manager,
const config& theme_cfg,
const config& level);
Expand Down
14 changes: 8 additions & 6 deletions src/play_controller.cpp
Expand Up @@ -84,7 +84,7 @@ static void clear_resources()
resources::tunnels = NULL;
resources::undo_stack = NULL;
resources::units = NULL;
resources::whiteboard = NULL;
resources::whiteboard.reset();


resources::classification = NULL;
Expand Down Expand Up @@ -255,9 +255,15 @@ void play_controller::init(CVideo& video){
loadscreen::start_stage("init theme");
const config &theme_cfg = get_theme(game_config_, level_["theme"]);

LOG_NG << "initializing pathfinding and whiteboard..." << (SDL_GetTicks() - ticks_) << std::endl;
pathfind_manager_.reset(new pathfind::manager(level_));
whiteboard_manager_.reset(new wb::manager());
resources::tunnels = pathfind_manager_.get();
resources::whiteboard = whiteboard_manager_;

LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks_) << std::endl;
loadscreen::start_stage("build terrain");
gui_.reset(new game_display(gameboard_, video, tod_manager_, theme_cfg, level_));
gui_.reset(new game_display(gameboard_, video, whiteboard_manager_, tod_manager_, theme_cfg, level_));
if (!gui_->video().faked()) {
if (gamestate_.mp_settings().mp_countdown)
gui_->get_theme().modify_label("time-icon", _ ("time left for current turn"));
Expand Down Expand Up @@ -316,12 +322,8 @@ void play_controller::init_managers(){
prefs_disp_manager_.reset(new preferences::display_manager(gui_.get()));
tooltips_manager_.reset(new tooltips::manager(gui_->video()));
soundsources_manager_.reset(new soundsource::manager(*gui_));
pathfind_manager_.reset(new pathfind::manager(level_));
whiteboard_manager_.reset(new wb::manager());

resources::soundsources = soundsources_manager_.get();
resources::tunnels = pathfind_manager_.get();
resources::whiteboard = whiteboard_manager_.get();

halo_manager_.reset(new halo::manager(*gui_));
LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks_) << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/play_controller.hpp
Expand Up @@ -247,7 +247,7 @@ class play_controller : public controller_base, public events::observer, public
boost::scoped_ptr<actions::undo_list> undo_stack_;

//whiteboard manager
boost::scoped_ptr<wb::manager> whiteboard_manager_;
boost::shared_ptr<wb::manager> whiteboard_manager_;

const unit_type::experience_accelerator xp_mod_;
//if a team is specified whose turn it is, it means we're loading a game
Expand Down

0 comments on commit 2c312a1

Please sign in to comment.