move reset_gamestate function (reset_replay) to play_controller
This commit is contained in:
parent
941f00e491
commit
ec8bf1e1f7
9 changed files with 78 additions and 20 deletions
|
@ -176,7 +176,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
|
|||
turbo_(false),
|
||||
invalidateGameStatus_(true),
|
||||
map_labels_(new map_labels(*this, 0)),
|
||||
reports_object_(reports_object),
|
||||
reports_object_(&reports_object),
|
||||
scroll_event_("scrolled"),
|
||||
complete_redraw_event_("completely_redrawn"),
|
||||
nextDraw_(0),
|
||||
|
@ -3111,7 +3111,7 @@ void display::refresh_report(std::string const &report_name, const config * new_
|
|||
|
||||
reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb);
|
||||
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_.generate_report(report_name, temp_context);
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_->generate_report(report_name, temp_context);
|
||||
if ( new_cfg == NULL )
|
||||
new_cfg = &generated_cfg;
|
||||
|
||||
|
@ -3322,7 +3322,7 @@ void display::refresh_report(std::string const &report_name, const config * new_
|
|||
|
||||
reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb);
|
||||
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_.generate_report(report_name, temp_context);
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_->generate_report(report_name, temp_context);
|
||||
if ( new_cfg == NULL )
|
||||
new_cfg = &generated_cfg;
|
||||
|
||||
|
|
|
@ -645,7 +645,10 @@ public:
|
|||
|
||||
/** Rebuild the flag list (not team colors) for a single side. */
|
||||
void reinit_flags_for_side(size_t side);
|
||||
|
||||
void reset_reports(reports& reports_object)
|
||||
{
|
||||
reports_object_ = &reports_object;
|
||||
}
|
||||
private:
|
||||
void init_flags_for_side_internal(size_t side, const std::string& side_color);
|
||||
|
||||
|
@ -781,7 +784,7 @@ protected:
|
|||
bool turbo_;
|
||||
bool invalidateGameStatus_;
|
||||
boost::scoped_ptr<map_labels> map_labels_;
|
||||
reports & reports_object_;
|
||||
reports * reports_object_;
|
||||
|
||||
/** Event raised when the map is being scrolled */
|
||||
mutable events::generic_event scroll_event_;
|
||||
|
|
|
@ -78,7 +78,7 @@ game_display::game_display(game_board& board, CVideo& video, boost::weak_ptr<wb:
|
|||
attack_indicator_src_(),
|
||||
attack_indicator_dst_(),
|
||||
route_(),
|
||||
tod_manager_(tod),
|
||||
tod_manager_(&tod),
|
||||
displayedUnitHex_(),
|
||||
sidebarScaling_(1.0),
|
||||
first_turn_(true),
|
||||
|
@ -113,10 +113,10 @@ game_display::~game_display()
|
|||
//TODO: proper SDL_gpu implementation
|
||||
void game_display::new_turn()
|
||||
{
|
||||
const time_of_day& tod = tod_manager_.get_time_of_day();
|
||||
const time_of_day& tod = tod_manager_->get_time_of_day();
|
||||
|
||||
if( !first_turn_) {
|
||||
const time_of_day& old_tod = tod_manager_.get_previous_time_of_day();
|
||||
const time_of_day& old_tod = tod_manager_->get_previous_time_of_day();
|
||||
|
||||
if(old_tod.image_mask != tod.image_mask) {
|
||||
const surface old_mask(image::get_image(old_tod.image_mask,image::SCALED_TO_HEX));
|
||||
|
@ -453,12 +453,12 @@ void game_display::draw_hex(const map_location& loc)
|
|||
|
||||
const time_of_day& game_display::get_time_of_day(const map_location& loc) const
|
||||
{
|
||||
return tod_manager_.get_time_of_day(loc);
|
||||
return tod_manager_->get_time_of_day(loc);
|
||||
}
|
||||
|
||||
bool game_display::has_time_area() const
|
||||
{
|
||||
return tod_manager_.has_time_area();
|
||||
return tod_manager_->has_time_area();
|
||||
}
|
||||
|
||||
void game_display::draw_sidebar()
|
||||
|
@ -475,7 +475,7 @@ void game_display::draw_sidebar()
|
|||
|
||||
// We display the unit the mouse is over if it is over a unit,
|
||||
// otherwise we display the unit that is selected.
|
||||
BOOST_FOREACH(const std::string &name, reports_object_.report_list()) {
|
||||
BOOST_FOREACH(const std::string &name, reports_object_->report_list()) {
|
||||
refresh_report(name);
|
||||
}
|
||||
invalidateGameStatus_ = false;
|
||||
|
|
|
@ -132,7 +132,7 @@ public:
|
|||
|
||||
bool has_time_area() const;
|
||||
|
||||
const tod_manager & get_tod_man() const { return tod_manager_; } /**< Allows this class to properly implement filter context, used for animations */
|
||||
const tod_manager & get_tod_man() const { return *tod_manager_; } /**< Allows this class to properly implement filter context, used for animations */
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -224,7 +224,10 @@ public:
|
|||
|
||||
/// Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
|
||||
bool maybe_rebuild();
|
||||
|
||||
void reset_tod_manager(const tod_manager& tod_manager)
|
||||
{
|
||||
tod_manager_ = &tod_manager;
|
||||
}
|
||||
private:
|
||||
game_display(const game_display&);
|
||||
void operator=(const game_display&);
|
||||
|
@ -241,7 +244,7 @@ private:
|
|||
|
||||
pathfind::marked_route route_;
|
||||
|
||||
const tod_manager& tod_manager_;
|
||||
const tod_manager* tod_manager_;
|
||||
|
||||
void invalidate_route();
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ static lg::log_domain log_engine("engine");
|
|||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||
|
||||
static void no_op() {}
|
||||
|
||||
game_state::game_state(const config & level, play_controller & pc, const tdata_cache & tdata) :
|
||||
gamedata_(level),
|
||||
board_(tdata, level),
|
||||
|
@ -58,6 +60,26 @@ game_state::game_state(const config & level, play_controller & pc, const tdata_c
|
|||
{
|
||||
init(pc.ticks(), pc, level);
|
||||
}
|
||||
game_state::game_state(const config & level, play_controller & pc, const tdata_cache & tdata, game_board& board) :
|
||||
gamedata_(level),
|
||||
board_(board),
|
||||
tod_manager_(level),
|
||||
pathfind_manager_(new pathfind::manager(level)),
|
||||
reports_(new reports()),
|
||||
lua_kernel_(new game_lua_kernel(NULL, *this, pc, *reports_)),
|
||||
events_manager_(),
|
||||
player_number_(level["playing_team"].to_int() + 1),
|
||||
init_side_done_(level["init_side_done"].to_bool(false)),
|
||||
first_human_team_(-1)
|
||||
{
|
||||
init(pc.ticks(), pc, level);
|
||||
|
||||
game_events_resources_ = boost::make_shared<game_events::t_context>(lua_kernel_.get(), this, static_cast<game_display*>(NULL), &gamedata_, &board_.units_, &no_op, boost::bind(&play_controller::current_side, &pc));
|
||||
|
||||
events_manager_.reset(new game_events::manager(level, game_events_resources_));
|
||||
|
||||
}
|
||||
|
||||
|
||||
game_state::~game_state() {}
|
||||
|
||||
|
@ -132,8 +154,6 @@ void game_state::place_sides_in_preferred_locations(const config& level)
|
|||
}
|
||||
}
|
||||
|
||||
static void no_op() {}
|
||||
|
||||
void game_state::init(const int ticks, play_controller & pc, const config& level)
|
||||
{
|
||||
int ticks1 = SDL_GetTicks();
|
||||
|
@ -148,7 +168,7 @@ void game_state::init(const int ticks, play_controller & pc, const config& level
|
|||
}
|
||||
|
||||
LOG_NG << "initialized teams... " << (SDL_GetTicks() - ticks) << std::endl;
|
||||
loadscreen::start_stage("init teams");
|
||||
//loadscreen::start_stage("init teams");
|
||||
|
||||
board_.teams_.resize(level.child_count("side"));
|
||||
|
||||
|
|
|
@ -63,6 +63,8 @@ public:
|
|||
int first_human_team_; //needed to initialize the viewpoint during setup
|
||||
|
||||
game_state(const config & level, play_controller &, const tdata_cache & tdata);
|
||||
/// The third parameter is an optimisation.
|
||||
game_state(const config & level, play_controller &, const tdata_cache & tdata, game_board& board);
|
||||
|
||||
~game_state();
|
||||
|
||||
|
|
|
@ -302,6 +302,33 @@ void play_controller::init(CVideo& video, const config& level)
|
|||
plugins_context_->set_callback("quit", throw_end_level(), false);
|
||||
}
|
||||
|
||||
void play_controller::reset_gamestate(const config& level)
|
||||
{
|
||||
resources::gameboard = NULL;
|
||||
resources::gamedata = NULL;
|
||||
resources::teams = NULL;
|
||||
resources::tod_manager = NULL;
|
||||
resources::units = NULL;
|
||||
resources::filter_con = NULL;
|
||||
resources::lua_kernel = NULL;
|
||||
resources::game_events = NULL;
|
||||
resources::tunnels = NULL;
|
||||
gamestate_.reset(new game_state(level, *this, tdata_));
|
||||
gamestate().bind(whiteboard_manager_.get(), gui_.get());
|
||||
resources::gameboard = &gamestate().board_;
|
||||
resources::gamedata = &gamestate().gamedata_;
|
||||
resources::teams = &gamestate().board_.teams_;
|
||||
resources::tod_manager = &gamestate().tod_manager_;
|
||||
resources::units = &gamestate().board_.units_;
|
||||
resources::filter_con = &gamestate();
|
||||
resources::lua_kernel = gamestate().lua_kernel_.get();
|
||||
resources::game_events = gamestate().events_manager_.get();
|
||||
resources::tunnels = gamestate().pathfind_manager_.get();
|
||||
gui_->reset_tod_manager(gamestate().tod_manager_);
|
||||
gui_->reset_reports(*gamestate().reports_);
|
||||
gui_->change_display_context(&gamestate().board_);
|
||||
}
|
||||
|
||||
void play_controller::init_managers()
|
||||
{
|
||||
LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
|
|
|
@ -307,6 +307,7 @@ protected:
|
|||
*/
|
||||
void update_gui_to_player(const int team_index, const bool observe = false);
|
||||
|
||||
void reset_gamestate(const config& level);
|
||||
private:
|
||||
|
||||
void init(CVideo &video, const config& level);
|
||||
|
|
|
@ -359,11 +359,13 @@ void replay_controller::reset_replay_impl()
|
|||
DBG_REPLAY << "replay_controller::reset_replay\n";
|
||||
|
||||
gui_->get_chat_manager().clear_chat_messages();
|
||||
reset_gamestate(level_);
|
||||
resources::recorder->start_replay();
|
||||
#if 0
|
||||
gamestate_->player_number_ = level_["playing_team"].to_int() + 1;
|
||||
gamestate_->init_side_done() = level_["init_side_done"].to_bool(false);
|
||||
skip_replay_ = false;
|
||||
gamestate().tod_manager_= tod_manager_start_;
|
||||
resources::recorder->start_replay();
|
||||
gamestate().board_ = gameboard_start_;
|
||||
gui_->change_display_context(&gamestate().board_); //this doesn't change the pointer value, but it triggers the gui to update the internal terrain builder object,
|
||||
//idk what the consequences of not doing that are, but its probably a good idea to do it, esp. if layout
|
||||
|
@ -389,10 +391,10 @@ void replay_controller::reset_replay_impl()
|
|||
gamestate().game_events_resources_->lua_kernel = resources::lua_kernel;
|
||||
gamestate().events_manager_.reset(new game_events::manager(level_, gamestate().game_events_resources_));
|
||||
resources::game_events = gamestate().events_manager_.get();
|
||||
|
||||
*resources::gamedata = game_data(level_);
|
||||
#endif
|
||||
gui_->labels().read(level_);
|
||||
|
||||
*resources::gamedata = game_data(level_);
|
||||
statistics::fresh_stats();
|
||||
|
||||
gui_->needs_rebuild(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue