mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 08:42:35 +00:00
Merge branch 'refactor_reports'
This commit is contained in:
commit
2c312a11ef
@ -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"
|
||||
@ -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),
|
||||
@ -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)
|
||||
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
@ -55,6 +59,7 @@ class arrow;
|
||||
#include <list>
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <map>
|
||||
|
||||
@ -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_ ;}
|
||||
@ -191,6 +196,11 @@ public:
|
||||
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.
|
||||
@ -627,6 +637,7 @@ private:
|
||||
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
|
||||
|
@ -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;
|
||||
@ -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_()
|
||||
{
|
||||
|
@ -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_(),
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
/**
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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));
|
||||
@ -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));
|
||||
}
|
||||
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
@ -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"));
|
||||
@ -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;
|
||||
|
@ -247,7 +247,7 @@ protected:
|
||||
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
|
||||
|
553
src/reports.cpp
553
src/reports.cpp
File diff suppressed because it is too large
Load Diff
@ -15,22 +15,67 @@
|
||||
#ifndef REPORTS_HPP_INCLUDED
|
||||
#define REPORTS_HPP_INCLUDED
|
||||
|
||||
#include "display_context.hpp"
|
||||
#include "map_location.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
//this module is responsible for outputting textual reports of
|
||||
//various game and unit statistics
|
||||
|
||||
class gamemap;
|
||||
class team;
|
||||
class unit_map;
|
||||
|
||||
class display;
|
||||
|
||||
namespace wb {
|
||||
class manager;
|
||||
}
|
||||
|
||||
namespace events {
|
||||
class mouse_handler;
|
||||
}
|
||||
|
||||
namespace reports {
|
||||
|
||||
class context
|
||||
{
|
||||
public:
|
||||
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(); }
|
||||
const gamemap & map() { return dc_.map(); }
|
||||
|
||||
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_;
|
||||
};
|
||||
|
||||
struct generator
|
||||
{
|
||||
virtual config generate() = 0;
|
||||
virtual config generate(context & ct) = 0;
|
||||
virtual ~generator() {}
|
||||
};
|
||||
|
||||
void reset_generators();
|
||||
void register_generator(const std::string &name, generator *);
|
||||
|
||||
config generate_report(const std::string &name, bool only_static = false);
|
||||
config generate_report(const std::string &name, context & ct, bool only_static = false);
|
||||
|
||||
const std::set<std::string> &report_list();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace resources
|
||||
pathfind::manager *tunnels = NULL;
|
||||
actions::undo_list *undo_stack = NULL;
|
||||
unit_map *units = NULL;
|
||||
wb::manager *whiteboard = NULL;
|
||||
boost::shared_ptr<wb::manager> whiteboard = boost::shared_ptr<wb::manager>();
|
||||
game_classification *classification = NULL;
|
||||
const mp_game_settings *mp_settings = NULL;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define RESOURCES_H_
|
||||
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class game_board;
|
||||
class game_config_manager;
|
||||
@ -57,7 +58,7 @@ namespace resources
|
||||
extern pathfind::manager *tunnels;
|
||||
extern actions::undo_list *undo_stack;
|
||||
extern unit_map *units;
|
||||
extern wb::manager *whiteboard;
|
||||
extern boost::shared_ptr<wb::manager> whiteboard;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -3575,10 +3575,10 @@ namespace {
|
||||
std::string name;
|
||||
lua_report_generator(lua_State *L, const std::string &n)
|
||||
: mState(L), name(n) {}
|
||||
virtual config generate();
|
||||
virtual config generate(reports::context & rc);
|
||||
};
|
||||
|
||||
config lua_report_generator::generate()
|
||||
config lua_report_generator::generate(reports::context & /*rc*/)
|
||||
{
|
||||
lua_State *L = mState;
|
||||
config cfg;
|
||||
@ -3597,7 +3597,8 @@ namespace {
|
||||
static int cfun_theme_item(lua_State *L)
|
||||
{
|
||||
const char *m = lua_tostring(L, lua_upvalueindex(1));
|
||||
luaW_pushconfig(L, reports::generate_report(m, true));
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,10 @@
|
||||
#include "game_display.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
|
||||
namespace wb {
|
||||
class manager;
|
||||
}
|
||||
|
||||
namespace test_utils {
|
||||
|
||||
class fake_display_manager {
|
||||
@ -61,7 +65,7 @@ namespace test_utils {
|
||||
dummy_board_(dummy_cfg_, dummy_cfg2_),
|
||||
dummy_tod_(dummy_cfg_),
|
||||
main_event_context_(),
|
||||
disp_(dummy_board_, video_, dummy_tod_,
|
||||
disp_(dummy_board_, video_, boost::shared_ptr<wb::manager> (), dummy_tod_,
|
||||
dummy_cfg_, dummy_cfg_)
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user