Skip to content

Commit

Permalink
Play_controller: register as AI observer in reset_gamestate()
Browse files Browse the repository at this point in the history
Now when play controller can outlive AI manager, it needs to register
itself as an observer when the AI manager is recreated.

While I was working with this code, I also moved the existing
registration from playsingle_controller to play_controller (for
consistency) and stopped using the singleton pointer to access the
manager.

Thanks to @gfgtdf for spotting the problem.
  • Loading branch information
jyrkive committed Feb 23, 2018
1 parent 8728933 commit d256a7b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/play_controller.cpp
Expand Up @@ -216,6 +216,7 @@ void play_controller::init(const config& level)
resources::game_events = gamestate().events_manager_.get();
resources::lua_kernel = gamestate().lua_kernel_.get();

gamestate_->ai_manager_.add_observer(this);
gamestate_->init(level, *this);
resources::tunnels = gamestate().pathfind_manager_.get();

Expand Down Expand Up @@ -314,6 +315,7 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
resources::game_events = gamestate().events_manager_.get();
resources::lua_kernel = gamestate().lua_kernel_.get();

gamestate_->ai_manager_.add_observer(this);
gamestate_->init(level, *this);
gamestate().set_game_display(gui_.get());
resources::tunnels = gamestate().pathfind_manager_.get();
Expand Down
2 changes: 0 additions & 2 deletions src/playsingle_controller.cpp
Expand Up @@ -84,8 +84,6 @@ playsingle_controller::playsingle_controller(const config& level,
// game may need to start in linger mode
linger_ = this->is_regular_game_end();

ai::manager::get_singleton().add_observer(this);

plugins_context_->set_accessor_string("level_result", std::bind(&playsingle_controller::describe_result, this));
plugins_context_->set_accessor_int("turn", std::bind(&play_controller::turn, this));
}
Expand Down

0 comments on commit d256a7b

Please sign in to comment.