Remove last part of turn_info class

(The files were not deleted because i dont know how to remove them from the various projectfiles)
This commit is contained in:
gfgtdf 2024-03-05 02:15:46 +01:00
parent 8d8643915e
commit f2bf2dd465
6 changed files with 33 additions and 128 deletions

View file

@ -30,7 +30,6 @@
#include "log.hpp"
#include "map/label.hpp"
#include "mp_ui_alerts.hpp"
#include "playturn.hpp"
#include "preferences/game.hpp"
#include "preferences/general.hpp"
#include "replay_helper.hpp"
@ -401,7 +400,7 @@ void playmp_controller::process_network_data(bool unsync_only)
//Do nothing, Otherwise we might risk getting data that belongs to the next scenario.
} else if(network_reader_.read(cfg)) {
auto res = process_network_data_impl(cfg, unsync_only);
if(res == turn_info::PROCESS_CANNOT_HANDLE) {
if(res == PROCESS_DATA_RESULT::CANNOT_HANDLE) {
network_reader_.push_front(std::move(cfg));
}
if(next_scenario_notified_) {
@ -410,7 +409,7 @@ void playmp_controller::process_network_data(bool unsync_only)
}
}
turn_info::PROCESS_DATA_RESULT playmp_controller::process_network_data_impl(const config& cfg, bool chat_only)
playmp_controller::PROCESS_DATA_RESULT playmp_controller::process_network_data_impl(const config& cfg, bool chat_only)
{
// the simple wesnothserver implementation in wesnoth was removed years ago.
assert(cfg.all_children_count() == 1);
@ -480,10 +479,10 @@ turn_info::PROCESS_DATA_RESULT playmp_controller::process_network_data_impl(cons
ERR_NW << "found unknown command:\n" << cfg.debug();
}
return turn_info::PROCESS_CONTINUE;
return PROCESS_DATA_RESULT::CONTINUE;
}
turn_info::PROCESS_DATA_RESULT playmp_controller::process_network_turn_impl(const config& t, bool chat_only)
playmp_controller::PROCESS_DATA_RESULT playmp_controller::process_network_turn_impl(const config& t, bool chat_only)
{
//t can contain a [command] or a [upload_log]
assert(t.all_children_count() == 1);
@ -491,7 +490,7 @@ turn_info::PROCESS_DATA_RESULT playmp_controller::process_network_turn_impl(cons
if(auto command = t.optional_child("command")) {
auto commandtype = get_replay_action_type(*command);
if(chat_only && (commandtype == REPLAY_ACTION_TYPE::SYNCED || commandtype == REPLAY_ACTION_TYPE::INVALID) ) {
return turn_info::PROCESS_CANNOT_HANDLE;
return PROCESS_DATA_RESULT::CANNOT_HANDLE;
}
if (commandtype == REPLAY_ACTION_TYPE::SYNCED && current_team().is_local()) {
// Executing those is better than OOS, also the server checks that other players don't send actions while it's not their turn.
@ -500,7 +499,7 @@ turn_info::PROCESS_DATA_RESULT playmp_controller::process_network_turn_impl(cons
}
//note, that this function might call itself recursively: do_replay -> ... -> get_user_choice -> ... -> playmp_controller::pull_remote_choice -> sync_network -> handle_turn
resources::recorder->add_config(t, replay::MARK_AS_SENT);
turn_info::PROCESS_DATA_RESULT retv = replay_to_process_data_result(do_replay());
PROCESS_DATA_RESULT retv = replay_to_process_data_result(do_replay());
return retv;
}
@ -713,19 +712,19 @@ void playmp_controller::send_actions()
}
}
turn_info::PROCESS_DATA_RESULT playmp_controller::process_network_data_from_reader()
playmp_controller::PROCESS_DATA_RESULT playmp_controller::process_network_data_from_reader()
{
config cfg;
while(this->network_reader_.read(cfg))
{
turn_info::PROCESS_DATA_RESULT res = process_network_data_impl(cfg);
if(res != turn_info::PROCESS_CONTINUE)
PROCESS_DATA_RESULT res = process_network_data_impl(cfg);
if(res != PROCESS_DATA_RESULT::CONTINUE)
{
return res;
}
cfg.clear();
}
return turn_info::PROCESS_CONTINUE;
return PROCESS_DATA_RESULT::CONTINUE;
}
@ -739,18 +738,18 @@ void playmp_controller::send_change_side_controller(int side, const std::string&
send_to_wesnothd(cfg);
}
turn_info::PROCESS_DATA_RESULT playmp_controller::replay_to_process_data_result(REPLAY_RETURN replayreturn)
playmp_controller::PROCESS_DATA_RESULT playmp_controller::replay_to_process_data_result(REPLAY_RETURN replayreturn)
{
switch(replayreturn)
{
case REPLAY_RETURN_AT_END:
return turn_info::PROCESS_CONTINUE;
return PROCESS_DATA_RESULT::CONTINUE;
case REPLAY_FOUND_DEPENDENT:
return turn_info::PROCESS_FOUND_DEPENDENT;
return PROCESS_DATA_RESULT::FOUND_DEPENDENT;
case REPLAY_FOUND_END_TURN:
return turn_info::PROCESS_END_TURN;
return PROCESS_DATA_RESULT::END_TURN;
case REPLAY_FOUND_END_LEVEL:
return turn_info::PROCESS_END_LEVEL;
return PROCESS_DATA_RESULT::END_LEVEL;
default:
assert(false);
throw "found invalid REPLAY_RETURN";

View file

@ -64,18 +64,32 @@ protected:
blindfold blindfold_;
private:
enum class PROCESS_DATA_RESULT
{
CONTINUE,
RESTART_TURN,
END_TURN,
/** When the host uploaded the next scenario this is returned. */
END_LINGER,
/** When we couldn't process the network data because we found a dependent command, this should only happen if we were called playmp_controller::from handle_generic_event -> sync_network*/
FOUND_DEPENDENT,
/** when we couldn't handle the given action currently. */
CANNOT_HANDLE,
/** We found a player action in the replay that caused the game to end*/
END_LEVEL
};
/**
* @param unsync_only if false (default) this can exceute synced (gamestate changing) turn commands (recall, move, etc.)
*/
void process_network_data(bool unsync_only = false);
turn_info::PROCESS_DATA_RESULT process_network_data_impl(const config& cfg, bool chat_only = false);
turn_info::PROCESS_DATA_RESULT process_network_turn_impl(const config& t, bool chat_only = false);
PROCESS_DATA_RESULT process_network_data_impl(const config& cfg, bool chat_only = false);
PROCESS_DATA_RESULT process_network_turn_impl(const config& t, bool chat_only = false);
void process_network_side_drop_impl(const config& t);
void process_network_change_controller_impl(const config& );
turn_info::PROCESS_DATA_RESULT process_network_data_from_reader();
PROCESS_DATA_RESULT process_network_data_from_reader();
void send_change_side_controller(int side, const std::string& player);
static turn_info::PROCESS_DATA_RESULT replay_to_process_data_result(REPLAY_RETURN replayreturn);
static PROCESS_DATA_RESULT replay_to_process_data_result(REPLAY_RETURN replayreturn);
/// Helper to send our actions to the server
/// Used by turn_data_

View file

@ -36,7 +36,6 @@
#include "log.hpp"
#include "map/label.hpp"
#include "map/map.hpp"
#include "playturn.hpp"
#include "preferences/game.hpp"
#include "replay_controller.hpp"
#include "replay_helper.hpp"

View file

@ -21,7 +21,6 @@
#include "cursor.hpp"
#include "lua_jailbreak_exception.hpp"
#include "playturn_network_adapter.hpp"
#include "playturn.hpp"
#include "replay.hpp"
#include <exception>

View file

@ -12,47 +12,3 @@
See the COPYING file for more details.
*/
#include "playturn.hpp"
#include "actions/undo.hpp" // for undo_list
#include "chat_events.hpp" // for chat_handler, etc
#include "config.hpp" // for config, etc
#include "display_chat_manager.hpp" // for add_chat_message, add_observer, etc
#include "formula/string_utils.hpp" // for VGETTEXT
#include "game_board.hpp" // for game_board
#include "game_display.hpp" // for game_display
#include "game_end_exceptions.hpp" // for end_level_exception, etc
#include "gettext.hpp" // for _
#include "gui/dialogs/simple_item_selector.hpp"
#include "log.hpp" // for LOG_STREAM, logger, etc
#include "map/label.hpp"
#include "play_controller.hpp" // for play_controller
#include "playturn_network_adapter.hpp" // for playturn_network_adapter
#include "preferences/general.hpp" // for message_bell
#include "replay.hpp" // for replay, recorder, do_replay, etc
#include "resources.hpp" // for gameboard, screen, etc
#include "serialization/string_utils.hpp" // for string_map
#include "synced_context.hpp"
#include "team.hpp" // for team, team::CONTROLLER::AI, etc
#include "wesnothd_connection_error.hpp"
#include "whiteboard/manager.hpp" // for manager
#include <cassert> // for assert
#include <ctime> // for time
#include <vector> // for vector
static lg::log_domain log_network("network");
#define ERR_NW LOG_STREAM(err, log_network)
turn_info::turn_info(replay_network_sender &replay_sender,playturn_network_adapter &network_reader) :
replay_sender_(replay_sender),
host_transfer_("host_transfer"),
network_reader_(network_reader)
{
}
turn_info::~turn_info()
{
}

View file

@ -12,65 +12,3 @@
See the COPYING file for more details.
*/
#pragma once
#include <string> // for string
#include "generic_event.hpp" // for generic_event
#include "replay.hpp"
class config; // lines 18-18
class playturn_network_adapter;
/**
TODO: rename this class since it isn't that much related to turns.
*/
class turn_info
{
public:
turn_info(replay_network_sender &network_sender, playturn_network_adapter &network_reader);
~turn_info();
enum PROCESS_DATA_RESULT
{
PROCESS_CONTINUE,
PROCESS_RESTART_TURN,
PROCESS_END_TURN,
/** When the host uploaded the next scenario this is returned. */
PROCESS_END_LINGER,
/** When we couldn't process the network data because we found a dependent command, this should only happen if we were called playmp_controller::from handle_generic_event -> sync_network*/
PROCESS_FOUND_DEPENDENT,
/** when we couldn't handle the given action currently. */
PROCESS_CANNOT_HANDLE,
/** We found a player action in the replay that caused the game to end*/
PROCESS_END_LEVEL
};
PROCESS_DATA_RESULT sync_network();
void send_data();
//function which will process incoming network data received with playturn_network_adapter, and act on it.
PROCESS_DATA_RESULT process_network_data(const config& cfg, bool chat_only = false);
//reads as much data from network_reader_ as possible and processed it.
PROCESS_DATA_RESULT process_network_data_from_reader();
events::generic_event& host_transfer() { return host_transfer_; }
static PROCESS_DATA_RESULT replay_to_process_data_result(REPLAY_RETURN replayreturn);
private:
static void change_side_controller(int side, const std::string& player);
PROCESS_DATA_RESULT handle_turn(const config& t, bool chat_only = false);
void do_save();
replay_network_sender& replay_sender_;
events::generic_event host_transfer_;
playturn_network_adapter& network_reader_;
};