fix quit furing start

by using differnt codepath for 'normal' game ends (victory/defeat) and
QUIT.
QUIT now throws an exception that is not handled by playcontroller,
similar to load_game_exception.
This commit is contained in:
gfgtdf 2015-03-03 15:52:42 +01:00
parent f4cf1c6ea6
commit 62cea304b3
4 changed files with 31 additions and 34 deletions

View file

@ -81,8 +81,8 @@ private:
/**
* Struct used to transmit info caught from an end_turn_exception.
*/
struct end_level_struct {
bool is_quit;
struct end_level_struct
{
};
/**
@ -94,18 +94,14 @@ class end_level_exception
{
public:
end_level_exception(bool isquit = false)
end_level_exception()
: tlua_jailbreak_exception()
, std::exception()
, is_quit(isquit)
{
}
bool is_quit;
end_level_struct to_struct() {
end_level_struct els = {is_quit};
return els;
return end_level_struct();
}
const char * what() const throw() { return "end_level_exception"; }
@ -114,6 +110,21 @@ private:
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(end_level_exception)
};
class quit_game_exception
: public tlua_jailbreak_exception
, public std::exception
{
public:
quit_game_exception()
: tlua_jailbreak_exception()
, std::exception()
{
}
const char * what() const throw() { return "quit_game_exception"; }
private:
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(quit_game_exception)
};
/**
* The two end_*_exceptions are caught and transformed to this signaling object
*/
@ -199,6 +210,6 @@ inline void throw_quit_game_exception()
// Distinguish 'Quit' from 'Regular' end_level_exceptions to solve the following problem:
// If a player quits the game during an event after an [endlevel] occurs, the game won't
// Quit but continue with the [endlevel] instead.
throw end_level_exception(true);
throw quit_game_exception();
}
#endif /* ! GAME_END_EXCEPTIONS_HPP_INCLUDED */

View file

@ -152,6 +152,10 @@ LEVEL_RESULT play_replay(display& disp, saved_game& gamestate, const config& gam
} else {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
}
} catch(quit_game_exception& e) {
LOG_NG << "The replay was aborted\n";
return QUIT;
} catch(game::game_error& e) {
ERR_NG << std::string(_("Error while playing the game: ")) + " (game::game_error) " + e.message << std::endl;
if (is_unit_test) {
@ -293,10 +297,12 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
{
res = playmp_scenario(game_config, tdata, disp, gamestate, story, skip_replay, blindfold_replay, io_type, end_level);
}
} catch(game::load_game_failed& e) {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
return QUIT;
} catch(quit_game_exception& e) {
LOG_NG << "The game was aborted\n";
return QUIT;
} catch(game::game_error& e) {
gui2::show_error_message(disp.video(), _("Error while playing the game: ") + e.message);
return QUIT;

View file

@ -207,10 +207,7 @@ void playsingle_controller::play_scenario_init() {
try {
fire_preload();
} catch (end_level_exception &e) {
if(e.is_quit) {
this->reset_end_level_data();
}
} catch (end_level_exception) {
return;
}
@ -226,10 +223,7 @@ void playsingle_controller::play_scenario_init() {
try {
fire_prestart();
} catch (end_level_exception &e) {
if(e.is_quit) {
this->reset_end_level_data();
}
} catch (end_level_exception) {
return;
}
@ -240,10 +234,7 @@ void playsingle_controller::play_scenario_init() {
events::raise_draw_event();
try {
fire_start();
} catch (end_level_exception &e) {
if(e.is_quit) {
this->reset_end_level_data();
}
} catch (end_level_exception) {
return;
}
sync.do_final_checkup();
@ -291,9 +282,6 @@ void playsingle_controller::play_scenario_main_loop() {
possible_end_play_signal signal = play_turn();
if (signal) {
if(signal->is_quit) {
reset_end_level_data();
}
return;
}
@ -336,16 +324,12 @@ LEVEL_RESULT playsingle_controller::play_scenario(
LOG_NG << "entering try... " << (SDL_GetTicks() - ticks_) << "\n";
try {
play_scenario_init();
//FIXME: This ignores QUITs during play_scenario_init()
if (!is_regular_game_end() && !linger_) {
play_scenario_main_loop();
}
if (game_config::exit_at_end) {
exit(0);
}
if (!is_regular_game_end()) {
return QUIT;
}
const bool is_victory = get_end_level_data_const().is_victory;
if(this->gamestate_.gamedata_.phase() <= game_data::PRESTART) {
@ -795,8 +779,7 @@ possible_end_play_signal playsingle_controller::check_time_over(){
e.proceed_to_next_level = false;
e.is_victory = false;
set_end_level_data(e);
end_level_struct els = { false };
return possible_end_play_signal (els);
return possible_end_play_signal (end_level_struct());
}
return boost::none;
}

View file

@ -482,9 +482,6 @@ possible_end_play_signal replay_controller::play_replay(){
possible_end_play_signal signal = play_replay_main_loop();
if(signal) {
if(signal->is_quit) {
return signal;
}
}
if (!is_playing_) {