Skip to content

Commit

Permalink
push end play exceptions out of replay_controller::play_replay
Browse files Browse the repository at this point in the history
Returns a "possible_end_play_signal" now instead. This also
required changes to the header in hotkey/command_executor. This
seems pretty minor, and could perhaps be refactored later.
  • Loading branch information
cbeck88 committed Jun 8, 2014
1 parent 22ee9bc commit 6eb71ad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/hotkey/command_executor.hpp
Expand Up @@ -17,7 +17,7 @@

#include "hotkey_command.hpp"
#include "display.hpp"

#include "game_end_exceptions.hpp"

namespace hotkey {

Expand Down Expand Up @@ -79,7 +79,7 @@ class command_executor
virtual void ai_formula() {}
virtual void clear_messages() {}
virtual void change_language() {}
virtual void play_replay() {}
virtual possible_end_play_signal play_replay() { return boost::none; }
virtual void reset_replay() {}
virtual void stop_replay() {}
virtual void replay_next_turn() {}
Expand Down
40 changes: 27 additions & 13 deletions src/replay_controller.cpp
Expand Up @@ -439,31 +439,45 @@ void replay_controller::replay_skip_animation(){
}

//move all sides till stop/end
void replay_controller::play_replay(){
possible_end_play_signal replay_controller::play_replay(){

if (recorder.at_end()){
//shouldn't actually happen
return;
return boost::none;
}

try{
is_playing_ = true;
replay_ui_playback_should_start();
is_playing_ = true;
replay_ui_playback_should_start();

DBG_REPLAY << "starting main loop\n" << (SDL_GetTicks() - ticks_) << "\n";
for(; !recorder.at_end() && is_playing_; first_player_ = 1) {
play_turn();
}
possible_end_play_signal signal = play_replay_main_loop();

if (!is_playing_) {
gui_->scroll_to_leader(gameboard_.units_, player_number_,game_display::ONSCREEN,false);
if(signal) {
switch ( boost::apply_visitor(get_signal_type(), *signal)) {
case END_TURN:
return signal;
case END_LEVEL:
if ( boost::apply_visitor(get_result(), *signal) == QUIT) {
return signal;
}
}

}
catch(end_level_exception& e){
if (e.result == QUIT) throw;

if (!is_playing_) {
gui_->scroll_to_leader(gameboard_.units_, player_number_,game_display::ONSCREEN,false);
}

replay_ui_playback_should_stop();

return boost::none;
}

possible_end_play_signal replay_controller::play_replay_main_loop() {
DBG_REPLAY << "starting main loop\n" << (SDL_GetTicks() - ticks_) << "\n";
for(; !recorder.at_end() && is_playing_; first_player_ = 1) {
HANDLE_END_PLAY_SIGNAL ( play_turn() );
}
return boost::none;
}

//make all sides move, then stop
Expand Down
4 changes: 3 additions & 1 deletion src/replay_controller.hpp
Expand Up @@ -36,7 +36,7 @@ class replay_controller : public play_controller
//event handlers
virtual void preferences();
virtual void show_statistics();
void play_replay();
possible_end_play_signal play_replay();
void reset_replay();
void stop_replay();
void replay_next_turn();
Expand Down Expand Up @@ -67,6 +67,8 @@ class replay_controller : public play_controller
void rebuild_replay_theme();
void handle_generic_event(const std::string& /*name*/);

possible_end_play_signal play_replay_main_loop();

void reset_replay_ui();
void update_replay_ui();

Expand Down

0 comments on commit 6eb71ad

Please sign in to comment.