mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-10 20:52:18 +00:00
partly revert 'simplify game_state construction'
It turned out that it isn't really possible to create the gamestate without access to te gamestate from everywhere (resourcces::) the main problem were the [effect] filters when creating units.
This commit is contained in:
parent
7fc9a974a0
commit
4fa11dd3e4
@ -47,7 +47,7 @@ static lg::log_domain log_engine("engine");
|
|||||||
|
|
||||||
static void no_op() {}
|
static void no_op() {}
|
||||||
|
|
||||||
game_state::game_state(const config & level, play_controller & pc, const tdata_cache & tdata) :
|
game_state::game_state(const config & level, play_controller &, const tdata_cache & tdata) :
|
||||||
gamedata_(level),
|
gamedata_(level),
|
||||||
board_(tdata, level),
|
board_(tdata, level),
|
||||||
tod_manager_(level),
|
tod_manager_(level),
|
||||||
@ -62,7 +62,7 @@ game_state::game_state(const config & level, play_controller & pc, const tdata_c
|
|||||||
server_request_number_(level["server_request_number"].to_int()),
|
server_request_number_(level["server_request_number"].to_int()),
|
||||||
first_human_team_(-1)
|
first_human_team_(-1)
|
||||||
{
|
{
|
||||||
init(pc.ticks(), pc, level);
|
//init(pc.ticks(), pc, level);
|
||||||
}
|
}
|
||||||
game_state::game_state(const config & level, play_controller & pc, game_board& board) :
|
game_state::game_state(const config & level, play_controller & pc, game_board& board) :
|
||||||
gamedata_(level),
|
gamedata_(level),
|
||||||
@ -84,11 +84,11 @@ game_state::game_state(const config & level, play_controller & pc, game_board& b
|
|||||||
end_level_data_ = el_data;
|
end_level_data_ = el_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(pc.ticks(), pc, level);
|
//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));
|
//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_));
|
//events_manager_.reset(new game_events::manager(level, game_events_resources_));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,20 +166,19 @@ void game_state::place_sides_in_preferred_locations(const config& level)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_state::init(const int ticks, play_controller & pc, const config& level)
|
void game_state::init(const config& level, play_controller & pc)
|
||||||
{
|
{
|
||||||
const int ticks1 = SDL_GetTicks();
|
|
||||||
if (level["modify_placing"].to_bool()) {
|
if (level["modify_placing"].to_bool()) {
|
||||||
LOG_NG << "modifying placing..." << std::endl;
|
LOG_NG << "modifying placing..." << std::endl;
|
||||||
place_sides_in_preferred_locations(level);
|
place_sides_in_preferred_locations(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_NG << "initialized time of day regions... " << (SDL_GetTicks() - ticks) << std::endl;
|
LOG_NG << "initialized time of day regions... " << (SDL_GetTicks() - pc.ticks()) << std::endl;
|
||||||
BOOST_FOREACH(const config &t, level.child_range("time_area")) {
|
BOOST_FOREACH(const config &t, level.child_range("time_area")) {
|
||||||
tod_manager_.add_time_area(board_.map(),t);
|
tod_manager_.add_time_area(board_.map(),t);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_NG << "initialized teams... " << (SDL_GetTicks() - ticks) << std::endl;
|
LOG_NG << "initialized teams... " << (SDL_GetTicks() - pc.ticks()) << std::endl;
|
||||||
//loadscreen::start_stage("init teams");
|
//loadscreen::start_stage("init teams");
|
||||||
|
|
||||||
board_.teams_.resize(level.child_count("side"));
|
board_.teams_.resize(level.child_count("side"));
|
||||||
@ -220,8 +219,6 @@ void game_state::init(const int ticks, play_controller & pc, const config& level
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_NG << "Initializing teams took " << SDL_GetTicks() - ticks1 << " ticks.\n";
|
|
||||||
|
|
||||||
pathfind_manager_.reset(new pathfind::manager(level));
|
pathfind_manager_.reset(new pathfind::manager(level));
|
||||||
|
|
||||||
lua_kernel_.reset(new game_lua_kernel(NULL, *this, pc, *reports_));
|
lua_kernel_.reset(new game_lua_kernel(NULL, *this, pc, *reports_));
|
||||||
@ -230,8 +227,6 @@ void game_state::init(const int ticks, play_controller & pc, const config& level
|
|||||||
|
|
||||||
events_manager_.reset(new game_events::manager(level, game_events_resources_));
|
events_manager_.reset(new game_events::manager(level, game_events_resources_));
|
||||||
|
|
||||||
LOG_NG << "Initializing total took " << SDL_GetTicks() - ticks1 << " ticks.\n";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
void place_sides_in_preferred_locations(const config& level);
|
void place_sides_in_preferred_locations(const config& level);
|
||||||
|
|
||||||
void init(int ticks, play_controller &, const config& level);
|
void init(const config& level, play_controller &);
|
||||||
|
|
||||||
void bind(wb::manager *, game_display *);
|
void bind(wb::manager *, game_display *);
|
||||||
|
|
||||||
|
@ -243,6 +243,8 @@ void play_controller::init(CVideo& video, const config& level)
|
|||||||
resources::units = &gamestate().board_.units_;
|
resources::units = &gamestate().board_.units_;
|
||||||
resources::filter_con = &gamestate();
|
resources::filter_con = &gamestate();
|
||||||
resources::undo_stack = &undo_stack();
|
resources::undo_stack = &undo_stack();
|
||||||
|
|
||||||
|
gamestate_->init(level, *this);
|
||||||
resources::tunnels = gamestate().pathfind_manager_.get();
|
resources::tunnels = gamestate().pathfind_manager_.get();
|
||||||
|
|
||||||
LOG_NG << "initializing whiteboard..." << (SDL_GetTicks() - ticks()) << std::endl;
|
LOG_NG << "initializing whiteboard..." << (SDL_GetTicks() - ticks()) << std::endl;
|
||||||
@ -322,18 +324,22 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
|
|||||||
resources::game_events = NULL;
|
resources::game_events = NULL;
|
||||||
resources::tunnels = NULL;
|
resources::tunnels = NULL;
|
||||||
resources::undo_stack = NULL;
|
resources::undo_stack = NULL;
|
||||||
|
|
||||||
gamestate_.reset(new game_state(level, *this, tdata_));
|
gamestate_.reset(new game_state(level, *this, tdata_));
|
||||||
gamestate().bind(whiteboard_manager_.get(), gui_.get());
|
|
||||||
resources::gameboard = &gamestate().board_;
|
resources::gameboard = &gamestate().board_;
|
||||||
resources::gamedata = &gamestate().gamedata_;
|
resources::gamedata = &gamestate().gamedata_;
|
||||||
resources::teams = &gamestate().board_.teams_;
|
resources::teams = &gamestate().board_.teams_;
|
||||||
resources::tod_manager = &gamestate().tod_manager_;
|
resources::tod_manager = &gamestate().tod_manager_;
|
||||||
resources::units = &gamestate().board_.units_;
|
resources::units = &gamestate().board_.units_;
|
||||||
resources::filter_con = &gamestate();
|
resources::filter_con = &gamestate();
|
||||||
|
resources::undo_stack = &undo_stack();
|
||||||
|
|
||||||
|
gamestate_->init(level, *this);
|
||||||
|
gamestate().bind(whiteboard_manager_.get(), gui_.get());
|
||||||
resources::lua_kernel = gamestate().lua_kernel_.get();
|
resources::lua_kernel = gamestate().lua_kernel_.get();
|
||||||
resources::game_events = gamestate().events_manager_.get();
|
resources::game_events = gamestate().events_manager_.get();
|
||||||
resources::tunnels = gamestate().pathfind_manager_.get();
|
resources::tunnels = gamestate().pathfind_manager_.get();
|
||||||
resources::undo_stack = &undo_stack();
|
|
||||||
gui_->reset_tod_manager(gamestate().tod_manager_);
|
gui_->reset_tod_manager(gamestate().tod_manager_);
|
||||||
gui_->reset_reports(*gamestate().reports_);
|
gui_->reset_reports(*gamestate().reports_);
|
||||||
gui_->change_display_context(&gamestate().board_);
|
gui_->change_display_context(&gamestate().board_);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user