Skip to content

Commit

Permalink
Re-set demo controller on sector transition
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed May 2, 2018
1 parent c90f7a7 commit 035128f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/supertux/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ GameSession::update(float elapsed_time)
sector->play_music(LEVEL_MUSIC);
currentsector = sector;
currentsector->play_looping_sounds();
reset_demo_controller();
//Keep persistent across sectors
if(edit_mode)
currentsector->get_players()[0]->set_edit_mode(edit_mode);
Expand Down
16 changes: 13 additions & 3 deletions src/supertux/game_session_recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ GameSessionRecorder::play_demo(const std::string& filename)
throw std::runtime_error(msg.str());
}

Player& tux = *GameSession::current()->get_current_sector()->player;
demo_controller = new CodeController();
tux.set_controller(demo_controller);
reset_demo_controller();

// skip over random seed, if it exists in the file
char buf[30]; // ascii decimal seed
Expand All @@ -123,6 +121,18 @@ GameSessionRecorder::play_demo(const std::string& filename)
playback_demo_stream->seekg(0); // old style w/o seed, restart at beg
}

void
GameSessionRecorder::reset_demo_controller()
{
if(demo_controller == NULL)
{
demo_controller = new CodeController();
}
auto game_session = GameSession::current();
auto player = game_session->get_current_sector()->player;
player->set_controller(demo_controller);
}

void
GameSessionRecorder::process_events()
{
Expand Down
6 changes: 6 additions & 0 deletions src/supertux/game_session_recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class GameSessionRecorder
void play_demo(const std::string& filename);
void process_events();

/**
* Re-sets the demo controller in case the sector
* (and thus the Player instance) changes.
*/
void reset_demo_controller();

private:
void capture_demo_step();

Expand Down

0 comments on commit 035128f

Please sign in to comment.