#include <synced_context.hpp>
Classes | |
struct | event_info |
class | server_choice |
Public Types | |
enum | synced_state { UNSYNCED , SYNCED , LOCAL_CHOICE } |
typedef std::deque< event_info > | event_list |
Static Public Member Functions | |
static bool | run (const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator()) |
Sets the context to 'synced', initialises random context, and calls the given function. More... | |
static bool | run_and_store (const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator()) |
static bool | run_and_throw (const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator()) |
static bool | run_in_synced_context_if_not_already (const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator()) |
Checks whether we are currently running in a synced context, and if not we enters it. More... | |
static synced_state | get_synced_state () |
static bool | is_synced () |
static bool | is_unsynced () |
static void | set_synced_state (synced_state newstate) |
Should only be called form set_scontext_synced, set_scontext_local_choice. More... | |
static std::string | generate_random_seed () |
Generates a new seed for a synced event, by asking the 'server'. More... | |
static void | pull_remote_user_input () |
called from get_user_choice while waiting for a remove user choice. More... | |
static void | send_user_choice () |
called from get_user_choice to send a recently made choice to the other clients. More... | |
static action_spectator & | get_default_spectator () |
An object to be passed to run_in_synced_context to assert false on error (the default). More... | |
static std::shared_ptr< randomness::rng > | get_rng_for_action () |
static void | block_undo (bool do_block=true, bool clear_undo=true) |
set this to false to prevent clearing the undo stack, this is important when we cannot change the gamestate becasue with dsu clearing the undo stack changes the gamestate, which we for example don't want during formula evaluation, when it used the dice operator. More... | |
static void | reset_block_undo () |
static bool | undo_blocked () |
static void | set_last_unit_id (int id) |
static int | get_unit_id_diff () |
static config | ask_server_choice (const server_choice &) |
If we are in a mp game, ask the server, otherwise generate the answer ourselves. More... | |
static event_list & | get_undo_commands () |
static void | add_undo_commands (const config &commands, const game_events::queued_event &ctx) |
static void | add_undo_commands (int fcn_idx, const game_events::queued_event &ctx) |
static void | add_undo_commands (int fcn_idx, const config &args, const game_events::queued_event &ctx) |
static void | reset_undo_commands () |
static bool | ignore_undo () |
Static Private Attributes | |
static synced_state | state_ = synced_context::UNSYNCED |
Weather we are in a synced move, in a user_choice, or none of them. More... | |
static bool | is_undo_blocked_ = false |
As soon as get_user_choice is used with side != current_side (for example in generate_random_seed) other sides execute the command simultaneously and is_simultaneously is set to true. More... | |
static int | last_unit_id_ = 0 |
Used to restore the unit id manager when undoing. More... | |
static event_list | undo_commands_ {} |
Actions to be executed when the current action is undone. More... | |
Definition at line 28 of file synced_context.hpp.
typedef std::deque<event_info> synced_context::event_list |
Definition at line 164 of file synced_context.hpp.
Enumerator | |
---|---|
UNSYNCED | |
SYNCED | |
LOCAL_CHOICE |
Definition at line 31 of file synced_context.hpp.
|
static |
Definition at line 347 of file synced_context.cpp.
References undo_commands_.
Referenced by game_lua_kernel::cfun_undoable_event(), and game_lua_kernel::intf_add_undo_actions().
|
static |
Definition at line 357 of file synced_context.cpp.
References undo_commands_.
|
static |
Definition at line 352 of file synced_context.cpp.
References undo_commands_.
|
static |
If we are in a mp game, ask the server, otherwise generate the answer ourselves.
Definition at line 262 of file synced_context.cpp.
References replay::at_end(), block_undo(), resources::controller, DBG_REPLAY, config::debug(), do_replay_handle(), ERR_REPLAY, replay::get_next_action(), config::has_child(), play_controller::increase_server_request_number(), play_controller::is_networked_mp(), is_synced(), synced_context::server_choice::local_choice(), config::mandatory_child(), synced_context::server_choice::name(), controller_base::play_slice(), replay::process_error(), pull_remote_user_input(), resources::recorder, synced_context::server_choice::request_id(), replay::revert_action(), synced_context::server_choice::send_request(), replay::user_input(), and WRN_REPLAY.
Referenced by game_state::add_side_wml(), team::change_controller_by_wml(), and generate_random_seed().
|
static |
set this to false to prevent clearing the undo stack, this is important when we cannot change the gamestate becasue with dsu clearing the undo stack changes the gamestate, which we for example don't want during formula evaluation, when it used the dice operator.
TODO: consider removing this parameter when dsu is removed.
Definition at line 184 of file synced_context.cpp.
References actions::undo_list::clear(), resources::controller, is_undo_blocked_, play_controller::send_actions(), and resources::undo_stack.
Referenced by ask_server_choice(), play_controller::do_init_side(), play_controller::finish_side_turn_events(), get_rng_for_action(), actions::recall_unit(), actions::recruit_unit(), play_controller::start_game(), SYNCED_COMMAND_HANDLER_FUNCTION(), and user_choice_manager::user_choice_manager().
|
static |
Generates a new seed for a synced event, by asking the 'server'.
Definition at line 176 of file synced_context.cpp.
References ask_server_choice(), and config_attribute_value::str().
Referenced by get_rng_for_action().
|
static |
An object to be passed to run_in_synced_context to assert false on error (the default).
Definition at line 137 of file synced_context.cpp.
References ERR_REPLAY.
|
static |
Definition at line 232 of file synced_context.cpp.
References block_undo(), resources::classification, resources::gamedata, generate_random_seed(), randomness::mt_rng::get_next_random(), game_classification::random_mode, and game_data::rng().
|
inlinestatic |
Definition at line 65 of file synced_context.hpp.
References state_.
Referenced by do_replay_handle(), events::console_handler::is_enabled(), is_synced(), is_unsynced(), leave_synced_context::leave_synced_context(), run_in_synced_context_if_not_already(), set_scontext_synced_base::set_scontext_synced_base(), game_lua_kernel::synced_state(), game_events::WML_HANDLER_FUNCTION(), leave_synced_context::~leave_synced_context(), and set_scontext_synced_base::~set_scontext_synced_base().
|
inlinestatic |
Definition at line 165 of file synced_context.hpp.
References undo_commands_.
Referenced by actions::undo_action::undo_action().
|
static |
Definition at line 213 of file synced_context.cpp.
References resources::gameboard, n_unit::id_manager::get_save_id(), is_synced(), last_unit_id_, and game_board::unit_id_manager().
|
static |
Definition at line 362 of file synced_context.cpp.
References resources::controller, play_controller::current_team(), and team::is_ai().
|
inlinestatic |
Definition at line 74 of file synced_context.hpp.
References get_synced_state(), and SYNCED.
Referenced by actions::undo_list::apply_shroud_changes(), ask_server_choice(), game_display::display_unit_hex(), do_replay_handle(), get_unit_id_diff(), mp_sync::get_user_choice(), mp_sync::get_user_choice_multiple_sides(), game_display::highlight_hex(), game_lua_kernel::intf_has_achievement(), game_lua_kernel::intf_has_sub_achievement(), unit::mark_clone(), side_filter::match_internal(), and unit::set_underlying_id().
|
inlinestatic |
Definition at line 83 of file synced_context.hpp.
References get_synced_state(), and UNSYNCED.
Referenced by wb::manager::can_modify_game_state(), playmp_controller::send_actions(), and undo_blocked().
|
static |
called from get_user_choice while waiting for a remove user choice.
Definition at line 220 of file synced_context.cpp.
References resources::controller, and play_controller::receive_actions().
Referenced by ask_server_choice(), and user_choice_manager::pull().
|
inlinestatic |
Definition at line 118 of file synced_context.hpp.
References is_undo_blocked_.
Referenced by set_scontext_synced_base::set_scontext_synced_base().
|
inlinestatic |
Definition at line 174 of file synced_context.hpp.
References undo_commands_.
Referenced by set_scontext_synced_base::set_scontext_synced_base().
|
static |
Sets the context to 'synced', initialises random context, and calls the given function.
The plan is that in replays and in real game the same function is called. However, if you cannot call this function you can also use set_scontext_synced directly (use it like it's used in this method).
commandname | The command to run. |
data | The data to use with the command. |
spectator | An error handler for the case that data contains invalid data. |
Definition at line 47 of file synced_context.cpp.
References play_controller::check_victory(), actions::undo_list::clear(), resources::controller, data, DBG_REPLAY, set_scontext_synced::do_final_checkup(), action_spectator::error(), synced_command::registry(), send_user_choice(), undo_blocked(), and resources::undo_stack.
Referenced by do_replay_handle(), actions::undo_list::redo(), and run_and_store().
|
static |
Definition at line 82 of file synced_context.cpp.
References replay::add_synced_command(), resources::controller, data, ERR_REPLAY, resources::recorder, run(), and replay::undo().
Referenced by playsingle_controller::play_ai_turn(), playmp_controller::play_human_turn(), and run_and_throw().
|
static |
Definition at line 99 of file synced_context.cpp.
References resources::controller, data, play_controller::maybe_throw_return_to_play_side(), and run_and_store().
Referenced by events::mouse_handler::attack_enemy_(), gui2::dialogs::unit_recall::dismiss_unit(), events::console_handler::do_choose_level(), events::console_handler::do_event(), events::console_handler::do_fog(), events::console_handler::do_gold(), events::console_handler::do_lua(), events::console_handler::do_next_level(), events::menu_handler::do_recruit(), events::console_handler::do_set_var(), events::console_handler::do_shroud(), events::console_handler::do_terrain(), events::console_handler::do_turn(), events::console_handler::do_turn_limit(), events::console_handler::do_unit(), wb::recall::execute(), game_events::wml_menu_item::fire_event(), events::menu_handler::kill_unit(), actions::move_unit_and_record(), events::menu_handler::recall(), run_in_synced_context_if_not_already(), wb::manager::set_active(), actions::teleport_unit_and_record(), events::menu_handler::toggle_shroud_updates(), and events::menu_handler::update_shroud_now().
|
static |
Checks whether we are currently running in a synced context, and if not we enters it.
This is never called from so_replay_handle.
Definition at line 109 of file synced_context.cpp.
References data, ERR_REPLAY, action_spectator::error(), get_synced_state(), LOCAL_CHOICE, synced_command::registry(), run_and_throw(), SYNCED, and UNSYNCED.
Referenced by ai::attack_result::do_execute(), ai::recall_result::do_execute(), ai::recruit_result::do_execute(), game_events::wml_menu_item::fire_event(), and game_events::WML_HANDLER_FUNCTION().
|
static |
called from get_user_choice to send a recently made choice to the other clients.
Does not receive any data from the network any sends data.
Definition at line 226 of file synced_context.cpp.
References resources::controller, play_controller::send_actions(), and undo_blocked().
Referenced by user_choice_manager::ask_local_choice(), and run().
|
inlinestatic |
Definition at line 126 of file synced_context.hpp.
References id, and last_unit_id_.
Referenced by set_scontext_synced_base::set_scontext_synced_base().
|
inlinestatic |
Should only be called form set_scontext_synced, set_scontext_local_choice.
Definition at line 89 of file synced_context.hpp.
References state_.
Referenced by leave_synced_context::leave_synced_context(), set_scontext_synced_base::set_scontext_synced_base(), leave_synced_context::~leave_synced_context(), and set_scontext_synced_base::~set_scontext_synced_base().
|
static |
Definition at line 198 of file synced_context.cpp.
References resources::controller, game_data::end_turn_forced(), resources::gamedata, play_controller::is_regular_game_end(), is_undo_blocked_, and is_unsynced().
Referenced by user_choice_manager::ask_local_choice(), run(), playmp_controller::send_actions(), send_user_choice(), and SYNCED_COMMAND_HANDLER_FUNCTION().
|
inlinestaticprivate |
As soon as get_user_choice is used with side != current_side (for example in generate_random_seed) other sides execute the command simultaneously and is_simultaneously is set to true.
It's impossible to undo data that has been sent over the network.
false = we are on a local turn and haven't sent anything yet.
Definition at line 191 of file synced_context.hpp.
Referenced by block_undo(), reset_block_undo(), and undo_blocked().
|
inlinestaticprivate |
Used to restore the unit id manager when undoing.
Definition at line 194 of file synced_context.hpp.
Referenced by get_unit_id_diff(), and set_last_unit_id().
|
inlinestaticprivate |
Weather we are in a synced move, in a user_choice, or none of them.
Definition at line 182 of file synced_context.hpp.
Referenced by get_synced_state(), and set_synced_state().
|
inlinestaticprivate |
Actions to be executed when the current action is undone.
Definition at line 197 of file synced_context.hpp.
Referenced by add_undo_commands(), get_undo_commands(), and reset_undo_commands().