remove replay_network_sender
It didnt really make the code easier
This commit is contained in:
parent
d3f52a0fc2
commit
8ff6128f0f
4 changed files with 24 additions and 70 deletions
|
@ -53,7 +53,6 @@ playmp_controller::playmp_controller(const config& level, saved_game& state_of_g
|
|||
, network_processing_stopped_(false)
|
||||
, next_scenario_notified_(false)
|
||||
, blindfold_(*gui_, mp_info && mp_info->skip_replay_blindfolded)
|
||||
, replay_sender_(*resources::recorder)
|
||||
, network_reader_([this](config& cfg) { return receive_from_wesnothd(cfg); })
|
||||
, mp_info_(mp_info)
|
||||
{
|
||||
|
@ -337,9 +336,9 @@ void playmp_controller::play_slice(bool is_delay_enabled)
|
|||
// receive chat during animations and delay
|
||||
// But don't execute turn data during animations etc.
|
||||
process_network_data(true);
|
||||
// cannot use send_actions() here.
|
||||
// todo: why? The checks in send_actions() should be safe enouth.
|
||||
replay_sender_.sync_non_undoable();
|
||||
// send_actions() makes sure that no actions that can
|
||||
// still be undone is sent.
|
||||
send_actions();
|
||||
}
|
||||
|
||||
playsingle_controller::play_slice(is_delay_enabled);
|
||||
|
@ -662,11 +661,18 @@ void playmp_controller::process_network_change_controller_impl(const config& cha
|
|||
|
||||
void playmp_controller::send_actions()
|
||||
{
|
||||
if(!is_networked_mp()) {
|
||||
return;
|
||||
}
|
||||
|
||||
resources::whiteboard->send_network_data();
|
||||
|
||||
const bool send_everything = synced_context::is_unsynced() ? !resources::undo_stack->can_undo() : synced_context::undo_blocked();
|
||||
if ( !send_everything ) {
|
||||
replay_sender_.sync_non_undoable();
|
||||
} else {
|
||||
replay_sender_.commit_and_sync();
|
||||
const replay::DATA_TYPE data_type = send_everything ? replay::ALL_DATA : replay::NON_UNDO_DATA;
|
||||
|
||||
config data = resources::recorder->get_unsent_commands(data_type);
|
||||
if (!data.empty()) {
|
||||
send_to_wesnothd(config{ "turn", data});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,10 +91,7 @@ private:
|
|||
void send_change_side_controller(int side, const std::string& player);
|
||||
static PROCESS_DATA_RESULT replay_to_process_data_result(REPLAY_RETURN replayreturn);
|
||||
|
||||
/// Helper to send our actions to the server
|
||||
/// Used by turn_data_
|
||||
replay_network_sender replay_sender_;
|
||||
/// Used by turn_data_
|
||||
/// Helper to preprocess infoming network data.
|
||||
playturn_network_adapter network_reader_;
|
||||
mp_game_metadata* mp_info_;
|
||||
};
|
||||
|
|
|
@ -181,6 +181,7 @@ chat_msg::~chat_msg()
|
|||
|
||||
replay::replay(replay_recorder_base& base)
|
||||
: base_(&base)
|
||||
, sent_upto_(base.size())
|
||||
, message_locations()
|
||||
{}
|
||||
|
||||
|
@ -393,11 +394,10 @@ const std::vector<chat_msg>& replay::build_chat_log() const
|
|||
return message_log;
|
||||
}
|
||||
|
||||
config replay::get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type) const
|
||||
config replay::get_unsent_commands(DATA_TYPE data_type)
|
||||
{
|
||||
config res;
|
||||
|
||||
for (int cmd = cmd_start; cmd < cmd_end; ++cmd)
|
||||
for (int cmd = sent_upto_; cmd < ncommands(); ++cmd)
|
||||
{
|
||||
config &c = command(cmd);
|
||||
//prevent creating 'blank' attribute values during checks
|
||||
|
@ -405,10 +405,12 @@ config replay::get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type) c
|
|||
if ((data_type == ALL_DATA || !cc["undo"].to_bool(true)) && !cc["sent"].to_bool(false))
|
||||
{
|
||||
res.add_child("command", c);
|
||||
if (data_type == NON_UNDO_DATA) c["sent"] = true;
|
||||
c["sent"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(data_type == ALL_DATA) {
|
||||
sent_upto_ = ncommands();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -914,42 +916,3 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
replay_network_sender::replay_network_sender(replay& obj) : obj_(obj), upto_(obj_.ncommands())
|
||||
{
|
||||
}
|
||||
|
||||
replay_network_sender::~replay_network_sender()
|
||||
{
|
||||
try {
|
||||
} catch (...) {}
|
||||
}
|
||||
|
||||
void replay_network_sender::sync_non_undoable()
|
||||
{
|
||||
if(resources::controller->is_networked_mp()) {
|
||||
resources::whiteboard->send_network_data();
|
||||
|
||||
config cfg;
|
||||
const config& data = cfg.add_child("turn",obj_.get_data_range(upto_,obj_.ncommands(),replay::NON_UNDO_DATA));
|
||||
if(data.empty() == false) {
|
||||
resources::controller->send_to_wesnothd(cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void replay_network_sender::commit_and_sync()
|
||||
{
|
||||
if(resources::controller->is_networked_mp()) {
|
||||
resources::whiteboard->send_network_data();
|
||||
|
||||
config cfg;
|
||||
const config& data = cfg.add_child("turn",obj_.get_data_range(upto_,obj_.ncommands()));
|
||||
|
||||
if(data.empty() == false) {
|
||||
resources::controller->send_to_wesnothd(cfg);
|
||||
}
|
||||
|
||||
upto_ = obj_.ncommands();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
//undoable data includes moves such as placing a label or speaking, which is
|
||||
//ignored by the undo system.
|
||||
enum DATA_TYPE { ALL_DATA, NON_UNDO_DATA };
|
||||
config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA) const;
|
||||
config get_unsent_commands(DATA_TYPE data_type);
|
||||
|
||||
void undo();
|
||||
/*
|
||||
|
@ -158,6 +158,7 @@ private:
|
|||
*/
|
||||
config& add_nonundoable_command();
|
||||
replay_recorder_base* base_;
|
||||
int sent_upto_;
|
||||
std::vector<int> message_locations;
|
||||
};
|
||||
|
||||
|
@ -178,16 +179,3 @@ REPLAY_ACTION_TYPE get_replay_action_type(const config& command);
|
|||
REPLAY_RETURN do_replay(bool one_move = false);
|
||||
|
||||
REPLAY_RETURN do_replay_handle(bool one_move = false);
|
||||
|
||||
class replay_network_sender
|
||||
{
|
||||
public:
|
||||
replay_network_sender(replay& obj);
|
||||
~replay_network_sender();
|
||||
|
||||
void sync_non_undoable();
|
||||
void commit_and_sync();
|
||||
private:
|
||||
replay& obj_;
|
||||
int upto_;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue