Skip to content

Commit

Permalink
push end_play_exceptions one down in call stack, at "play_turn()"
Browse files Browse the repository at this point in the history
Continues trend of previous commit. play_turn becomes no throw
with respect to these exceptions, and so we can switch calls to it
to use the "PROPOGATE_END_PLAY_SIGNAL" instead of "HANDLE_...".

It looks like by progressively doing this and unit testing at each
step, we will be able to successfully convert all of the functions
in play_controller to use PROPOGATE, which is a cheap if else and
not an exception handler, and increase the stability of the engine
by avoiding the use of exceptions for control flow. If we continue
this way, we could push all the throws into the event handler
and the replay module. Perhaps could continue from there, but
likely at some point the exceptions might be the simpler solution
esp. for breaking recursion in WML / lua or things like this.
  • Loading branch information
cbeck88 committed Jun 8, 2014
1 parent c11088c commit b7c18c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/playsingle_controller.cpp
Expand Up @@ -415,7 +415,7 @@ possible_end_play_signal playsingle_controller::play_scenario_main_loop(end_leve
do_autosaves_ = !loading_game_;
ai_testing::log_game_start();
for(; ; first_player_ = 1) {
HANDLE_END_PLAY_SIGNAL( play_turn() );
PROPOGATE_END_PLAY_SIGNAL( play_turn() );
do_autosaves_ = true;
} //end for loop
return boost::none;
Expand Down Expand Up @@ -621,12 +621,12 @@ LEVEL_RESULT playsingle_controller::play_scenario(
return QUIT;
}

void playsingle_controller::play_turn()
possible_end_play_signal playsingle_controller::play_turn()
{
resources::whiteboard->on_gamestate_change();
gui_->new_turn();
gui_->invalidate_game_status();
events::raise_draw_event();
HANDLE_END_PLAY_SIGNAL ( events::raise_draw_event() );

LOG_NG << "turn: " << turn() << "\n";

Expand All @@ -648,18 +648,20 @@ void playsingle_controller::play_turn()
turn_data_.sync_network();
}
continue;
} catch (end_level_exception & ele) {
return possible_end_play_signal(ele.to_struct());
}

if (replaying_) {
LOG_NG << "doing replay " << player_number_ << "\n";
replaying_ = ::do_replay() == REPLAY_FOUND_END_TURN;
HANDLE_END_PLAY_SIGNAL ( replaying_ = ::do_replay() == REPLAY_FOUND_END_TURN );
LOG_NG << "result of replay: " << (replaying_?"true":"false") << "\n";
} else {
ai_testing::log_turn_start(player_number_);
play_side();
HANDLE_END_PLAY_SIGNAL ( play_side() );
}

finish_side_turn();
HANDLE_END_PLAY_SIGNAL( finish_side_turn() );

if(non_interactive()) {
LOG_AIT << " Player " << player_number_ << ": " <<
Expand All @@ -668,7 +670,7 @@ void playsingle_controller::play_turn()
ai_testing::log_turn_end(player_number_);
}

check_victory();
HANDLE_END_PLAY_SIGNAL ( check_victory() );

//if loading a savegame, network turns might not have reset this yet
loading_game_ = false;
Expand All @@ -678,10 +680,11 @@ void playsingle_controller::play_turn()
if(player_number_ > static_cast<int>(gameboard_.teams_.size()))
player_number_ = gameboard_.teams_.size();

finish_turn();
HANDLE_END_PLAY_SIGNAL ( finish_turn() );

// Time has run out
check_time_over();
HANDLE_END_PLAY_SIGNAL ( check_time_over() );
return boost::none;
}

void playsingle_controller::play_idle_loop()
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.hpp
Expand Up @@ -91,7 +91,7 @@ class playsingle_controller : public play_controller
virtual void maybe_linger();

protected:
virtual void play_turn();
possible_end_play_signal play_turn();
virtual void play_side();
virtual void before_human_turn();
void show_turn_dialog();
Expand Down

0 comments on commit b7c18c8

Please sign in to comment.