Skip to content

Commit

Permalink
refactor game_lua_kernel not to use resources:: for gamestate
Browse files Browse the repository at this point in the history
This commit changes the majority of the wesnoth callback functions
for the game lua kernel to be private methods of the game lua
kernel. The game lua kernel is given direct access, via it's ctor,
to references of many of the things provided by resources. The
call back functions are modified to access these private reference
variables instead of resources, and they are added to the
scripting environment using the lua cpp function mechanism.

This greatly improves encapsulation and will eventually lead to
eliminating the resources pointers from the game lua kernel
entirely.
  • Loading branch information
cbeck88 committed Nov 24, 2014
1 parent abebbd8 commit 9eaba64
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 232 deletions.
1 change: 1 addition & 0 deletions src/game_board.hpp
Expand Up @@ -62,6 +62,7 @@ class game_board : public display_context {
friend class events::mouse_handler;
friend class events::menu_handler;
friend class game_state;
friend class game_lua_kernel;

/**
* Temporary unit move structs:
Expand Down
16 changes: 9 additions & 7 deletions src/play_controller.cpp
Expand Up @@ -191,13 +191,6 @@ void play_controller::init(CVideo& video){
loadscreen::start_stage("load level");
recorder.set_skip(false);

// This *needs* to be created before the show_intro and show_map_scene
// as that functions use the manager state_of_game
// Has to be done before registering any events!
lua_kernel_.reset(new game_lua_kernel(level_, &video));
resources::lua_kernel=lua_kernel_.get();
events_manager_.reset(new game_events::manager(level_));

LOG_NG << "initializing game_state..." << (SDL_GetTicks() - ticks_) << std::endl;
gamestate_.init(ticks_);
resources::tunnels = gamestate_.pathfind_manager_.get();
Expand Down Expand Up @@ -234,6 +227,15 @@ void play_controller::init(CVideo& video){

LOG_NG << "done initializing display... " << (SDL_GetTicks() - ticks_) << std::endl;

LOG_NG << "building lua kernel and game events manager... " << (SDL_GetTicks() - ticks_) << std::endl;
//loadscreen::start_stage("build events manager & lua");
// This *needs* to be created before the show_intro and show_map_scene
// as that functions use the manager state_of_game
// Has to be done before registering any events!
lua_kernel_.reset(new game_lua_kernel(level_, *gui_, gamestate_));
resources::lua_kernel=lua_kernel_.get();
events_manager_.reset(new game_events::manager(level_));

if(gamestate_.first_human_team_ != -1) {
gui_->set_team(gamestate_.first_human_team_);
}
Expand Down

0 comments on commit 9eaba64

Please sign in to comment.