Refactor/simplify *::after_human_turn(), with the goal of reducing
the number of calls to clear_undo_stack() to one.
This commit is contained in:
parent
00b2954a36
commit
b04ed2e3b0
4 changed files with 22 additions and 28 deletions
|
@ -249,7 +249,6 @@ void playmp_controller::play_human_turn(){
|
|||
|
||||
turn_data_->send_data();
|
||||
}
|
||||
menu_handler_.clear_undo_stack(player_number_);
|
||||
}
|
||||
|
||||
void playmp_controller::set_end_scenario_button()
|
||||
|
@ -389,20 +388,19 @@ void playmp_controller::after_human_turn(){
|
|||
recorder.add_countdown_update(current_team().countdown_time(),player_number_);
|
||||
}
|
||||
LOG_NG << "playmp::after_human_turn...\n";
|
||||
end_turn_record();
|
||||
|
||||
//ensure that turn_data_ is constructed before it is used.
|
||||
if (turn_data_ == NULL) init_turn_data();
|
||||
|
||||
// Normal post-processing for human turns (clear undos, end the turn, etc.)
|
||||
playsingle_controller::after_human_turn();
|
||||
//send one more time to make sure network is up-to-date.
|
||||
turn_data_->send_data();
|
||||
playsingle_controller::after_human_turn();
|
||||
if (turn_data_ != NULL){
|
||||
turn_data_->host_transfer().detach_handler(this);
|
||||
delete turn_data_;
|
||||
turn_data_ = NULL;
|
||||
}
|
||||
|
||||
// Release turn_data_.
|
||||
turn_data_->host_transfer().detach_handler(this);
|
||||
delete turn_data_;
|
||||
turn_data_ = NULL;
|
||||
}
|
||||
|
||||
void playmp_controller::finish_side_turn(){
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "playsingle_controller.hpp"
|
||||
|
||||
#include "actions/undo.hpp"
|
||||
#include "ai/manager.hpp"
|
||||
#include "ai/game_info.hpp"
|
||||
#include "ai/testing.hpp"
|
||||
|
@ -699,6 +700,13 @@ void playsingle_controller::before_human_turn(bool save)
|
|||
if(preferences::turn_bell() && level_result_ == NONE) {
|
||||
sound::play_bell(game_config::sounds::turn_bell);
|
||||
}
|
||||
|
||||
// Error check.
|
||||
if ( !resources::undo_stack->empty() ) {
|
||||
ERR_NG << "Undo stack not empty before_human_turn().\n";
|
||||
// At worst, someone missed some sighted events, so try to recover.
|
||||
resources::undo_stack->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void playsingle_controller::show_turn_dialog(){
|
||||
|
@ -800,19 +808,6 @@ void playsingle_controller::linger()
|
|||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
void playsingle_controller::end_turn_record()
|
||||
{
|
||||
if (!turn_over_)
|
||||
{
|
||||
turn_over_ = true;
|
||||
recorder.end_turn();
|
||||
}
|
||||
}
|
||||
void playsingle_controller::end_turn_record_unlock()
|
||||
{
|
||||
turn_over_ = false;
|
||||
}
|
||||
|
||||
hotkey::ACTION_STATE playsingle_controller::get_action_state(hotkey::HOTKEY_COMMAND command, int index) const
|
||||
{
|
||||
switch(command) {
|
||||
|
@ -824,12 +819,16 @@ hotkey::ACTION_STATE playsingle_controller::get_action_state(hotkey::HOTKEY_COMM
|
|||
}
|
||||
|
||||
|
||||
void playsingle_controller::after_human_turn(){
|
||||
browse_ = true;
|
||||
end_turn_record();
|
||||
end_turn_record_unlock();
|
||||
void playsingle_controller::after_human_turn()
|
||||
{
|
||||
// Ending the turn commits all moves.
|
||||
menu_handler_.clear_undo_stack(player_number_);
|
||||
|
||||
// Mark the turn as done.
|
||||
browse_ = true;
|
||||
recorder.end_turn();
|
||||
|
||||
// Clear moves from the GUI.
|
||||
gui_->set_route(NULL);
|
||||
gui_->unhighlight_reach();
|
||||
}
|
||||
|
|
|
@ -77,8 +77,6 @@ protected:
|
|||
void execute_gotos();
|
||||
virtual void play_human_turn();
|
||||
virtual void after_human_turn();
|
||||
void end_turn_record();
|
||||
void end_turn_record_unlock();
|
||||
virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const;
|
||||
void play_ai_turn();
|
||||
virtual void play_network_turn();
|
||||
|
|
|
@ -52,7 +52,6 @@ turn_info::turn_info(unsigned team_num, replay_network_sender &replay_sender) :
|
|||
}
|
||||
|
||||
turn_info::~turn_info(){
|
||||
resources::undo_stack->clear();
|
||||
}
|
||||
|
||||
void turn_info::sync_network()
|
||||
|
|
Loading…
Add table
Reference in a new issue