remove level_ member of game_lua_kernel
the intention is to be able to remove the level cfg.
This commit is contained in:
parent
368a4ab284
commit
12e839b9b7
5 changed files with 20 additions and 20 deletions
|
@ -186,7 +186,7 @@ void game_state::init(const int ticks, play_controller & pc)
|
|||
|
||||
pathfind_manager_.reset(new pathfind::manager(level_));
|
||||
|
||||
lua_kernel_.reset(new game_lua_kernel(level_, NULL, *this, pc, *reports_));
|
||||
lua_kernel_.reset(new game_lua_kernel(NULL, *this, pc, *reports_));
|
||||
|
||||
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));
|
||||
|
||||
|
|
|
@ -278,7 +278,8 @@ void play_controller::init(CVideo& video){
|
|||
plugins_context_->set_callback("quit", throw_end_level(), false);
|
||||
}
|
||||
|
||||
void play_controller::init_managers(){
|
||||
void play_controller::init_managers()
|
||||
{
|
||||
LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
prefs_disp_manager_.reset(new preferences::display_manager(gui_.get()));
|
||||
tooltips_manager_.reset(new tooltips::manager(gui_->video()));
|
||||
|
@ -292,7 +293,7 @@ void play_controller::fire_preload()
|
|||
{
|
||||
// Run initialization scripts, even if loading from a snapshot.
|
||||
gamestate_.gamedata_.set_phase(game_data::PRELOAD);
|
||||
gamestate_.lua_kernel_->initialize();
|
||||
gamestate_.lua_kernel_->initialize(level_);
|
||||
gamestate_.gamedata_.get_variable("turn_number") = int(turn());
|
||||
pump().fire("preload");
|
||||
}
|
||||
|
|
|
@ -329,7 +329,7 @@ void replay_controller::reset_replay()
|
|||
resources::game_events=NULL;
|
||||
gamestate_.lua_kernel_.reset();
|
||||
resources::lua_kernel=NULL;
|
||||
gamestate_.lua_kernel_.reset(new game_lua_kernel(level_, &gui_->video(), gamestate_, *this, *gamestate_.reports_));
|
||||
gamestate_.lua_kernel_.reset(new game_lua_kernel(&gui_->video(), gamestate_, *this, *gamestate_.reports_));
|
||||
gamestate_.lua_kernel_->set_game_display(gui_.get());
|
||||
resources::lua_kernel=gamestate_.lua_kernel_.get();
|
||||
gamestate_.game_events_resources_->lua_kernel = resources::lua_kernel;
|
||||
|
|
|
@ -4037,13 +4037,13 @@ int dispatch2(lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state & gs, play_controller & pc, reports & reports_object)
|
||||
game_lua_kernel::game_lua_kernel(CVideo * video, game_state & gs, play_controller & pc, reports & reports_object)
|
||||
: lua_kernel_base(video)
|
||||
, game_display_(NULL)
|
||||
, game_state_(gs)
|
||||
, play_controller_(pc)
|
||||
, reports_(reports_object)
|
||||
, level_(cfg)
|
||||
, level_lua_()
|
||||
, queued_events_()
|
||||
{
|
||||
static game_events::queued_event default_queued_event("_from_lua", map_location(), map_location(), config());
|
||||
|
@ -4324,10 +4324,11 @@ game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state &
|
|||
lua_settop(L, 0);
|
||||
}
|
||||
|
||||
void game_lua_kernel::initialize()
|
||||
void game_lua_kernel::initialize(const config& level)
|
||||
{
|
||||
lua_State *L = mState;
|
||||
|
||||
assert(level_lua_.empty());
|
||||
level_lua_.append_children(level, "lua");
|
||||
// Create the sides table.
|
||||
// note:
|
||||
// This table is redundant to the return value of wesnoth.get_sides({}).
|
||||
|
@ -4374,11 +4375,11 @@ void game_lua_kernel::initialize()
|
|||
BOOST_FOREACH(const config &cfg, game_lua_kernel::preload_scripts) {
|
||||
run(cfg["code"].str().c_str());
|
||||
}
|
||||
BOOST_FOREACH(const config &cfg, level_.child_range("lua")) {
|
||||
BOOST_FOREACH(const config &cfg, level_lua_.child_range("lua")) {
|
||||
run(cfg["code"].str().c_str());
|
||||
}
|
||||
|
||||
load_game();
|
||||
load_game(level);
|
||||
}
|
||||
|
||||
void game_lua_kernel::set_game_display(game_display * gd) {
|
||||
|
@ -4411,7 +4412,7 @@ static bool is_handled_file_tag(const std::string &s)
|
|||
* Executes the game_events.on_load function and passes to it all the
|
||||
* scenario tags not yet handled.
|
||||
*/
|
||||
void game_lua_kernel::load_game()
|
||||
void game_lua_kernel::load_game(const config& level)
|
||||
{
|
||||
lua_State *L = mState;
|
||||
|
||||
|
@ -4420,7 +4421,7 @@ void game_lua_kernel::load_game()
|
|||
|
||||
lua_newtable(L);
|
||||
int k = 1;
|
||||
BOOST_FOREACH(const config::any_child &v, level_.all_children_range())
|
||||
BOOST_FOREACH(const config::any_child &v, level.all_children_range())
|
||||
{
|
||||
if (is_handled_file_tag(v.key)) continue;
|
||||
lua_createtable(L, 2, 0);
|
||||
|
@ -4440,9 +4441,7 @@ void game_lua_kernel::load_game()
|
|||
*/
|
||||
void game_lua_kernel::save_game(config &cfg)
|
||||
{
|
||||
BOOST_FOREACH(const config &v, level_.child_range("lua")) {
|
||||
cfg.add_child("lua", v);
|
||||
}
|
||||
cfg.append_children(cfg, "lua");
|
||||
|
||||
lua_State *L = mState;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class game_lua_kernel : public lua_kernel_base
|
|||
game_data & gamedata();
|
||||
tod_manager & tod_man();
|
||||
|
||||
const config &level_;
|
||||
config level_lua_;
|
||||
|
||||
std::stack<game_events::queued_event const * > queued_events_;
|
||||
|
||||
|
@ -162,15 +162,15 @@ class game_lua_kernel : public lua_kernel_base
|
|||
std::vector<int> get_sides_vector(const vconfig& cfg);
|
||||
|
||||
public:
|
||||
game_lua_kernel(const config &, CVideo *, game_state &, play_controller &, reports &);
|
||||
game_lua_kernel(CVideo *, game_state &, play_controller &, reports &);
|
||||
|
||||
void set_game_display(game_display * gd);
|
||||
|
||||
virtual std::string my_name() { return "Game Lua Kernel"; }
|
||||
|
||||
void initialize();
|
||||
void save_game(config &);
|
||||
void load_game();
|
||||
void initialize(const config& level);
|
||||
void save_game(config & level);
|
||||
void load_game(const config& level);
|
||||
bool run_event(game_events::queued_event const &);
|
||||
void set_wml_action(std::string const &, game_events::wml_action::handler);
|
||||
bool run_wml_action(std::string const &, vconfig const &,
|
||||
|
|
Loading…
Add table
Reference in a new issue