The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Types | Static Public Member Functions | Static Private Attributes | List of all members
synced_context Class Reference

#include <synced_context.hpp>

Classes

class  server_choice
 

Public Types

enum  synced_state { UNSYNCED, SYNCED, LOCAL_CHOICE }
 
typedef std::deque< std::pair
< config,
game_events::queued_event > > 
event_list
 

Static Public Member Functions

static bool run (const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
 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, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
 
static bool run_and_throw (const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
 
static bool run_in_synced_context_if_not_already (const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
 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 void set_synced_state (synced_state newstate)
 
static std::string generate_random_seed ()
 
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 void default_error_function (const std::string &message, bool heavy)
 a function to be passed to run_in_synced_context to assert false on error (the default). More...
 
static void just_log_error_function (const std::string &message, bool heavy)
 a function to be passed to run_in_synced_context to log the error. More...
 
static void ignore_error_function (const std::string &message, bool heavy)
 a function to be passed to run_in_synced_context to ignore the error. More...
 
static boost::shared_ptr
< random_new::rng
get_rng_for_action ()
 
static bool is_simultaneously ()
 
static void reset_is_simultaneously ()
 
static void set_is_simultaneously ()
 
static bool can_undo ()
 
static void set_last_unit_id (int id)
 
static int get_unit_id_diff ()
 
static config ask_server_choice (const server_choice &)
 
static event_listget_undo_commands ()
 
static event_listget_redo_commands ()
 
static void add_undo_commands (const config &commands, const game_events::queued_event &ctx)
 
static void add_redo_commands (const config &commands, const game_events::queued_event &ctx)
 
static void reset_undo_commands ()
 
static void reset_redo_commands ()
 

Static Private Attributes

static synced_state state_ = synced_context::UNSYNCED
 
static bool is_simultaneously_ = false
 
static int last_unit_id_ = 0
 Used to restore the unit id manager when undoing. More...
 
static event_list undo_commands_
 Actions wml to be executed when the current actio is undone. More...
 
static event_list redo_commands_
 Actions wml to be executed when the current actio is redone. More...
 

Detailed Description

Definition at line 33 of file synced_context.hpp.

Member Typedef Documentation

Definition at line 151 of file synced_context.hpp.

Member Enumeration Documentation

Enumerator
UNSYNCED 
SYNCED 
LOCAL_CHOICE 

Definition at line 36 of file synced_context.hpp.

Member Function Documentation

void synced_context::add_redo_commands ( const config commands,
const game_events::queued_event ctx 
)
static

Definition at line 373 of file synced_context.cpp.

References redo_commands_.

Referenced by game_events::WML_HANDLER_FUNCTION().

void synced_context::add_undo_commands ( const config commands,
const game_events::queued_event ctx 
)
static

Definition at line 368 of file synced_context.cpp.

References undo_commands_.

Referenced by game_events::WML_HANDLER_FUNCTION().

config synced_context::ask_server_choice ( const server_choice sch)
static
bool synced_context::can_undo ( )
static
Returns
whether there were recently no methods called that prevent undoing.

Definition at line 228 of file synced_context.cpp.

References random_new::generator, random_new::rng::get_random_calls(), is_simultaneously_, and is_synced().

Referenced by actions::recall_unit(), actions::recruit_unit(), and run().

void synced_context::default_error_function ( const std::string message,
bool  heavy 
)
static

a function to be passed to run_in_synced_context to assert false on error (the default).

Definition at line 152 of file synced_context.cpp.

References ERR_REPLAY.

std::string synced_context::generate_random_seed ( )
static

Definition at line 204 of file synced_context.cpp.

References ask_server_choice(), and config::attribute_value::str().

Referenced by get_rng_for_action().

static event_list& synced_context::get_redo_commands ( )
inlinestatic

Definition at line 153 of file synced_context.hpp.

References redo_commands_.

Referenced by actions::undo_action::undo_action().

boost::shared_ptr< random_new::rng > synced_context::get_rng_for_action ( )
static
Returns
a rng_deterministic if in determinsic mode otherwise a rng_synced.

Definition at line 259 of file synced_context.cpp.

References resources::classification, resources::gamedata, generate_random_seed(), and game_classification::random_mode.

synced_context::synced_state synced_context::get_synced_state ( )
static
Returns
whether we are currently executing a synced action like recruit, start, recall, disband, movement, attack, init_side, end_turn, fire_event, lua_ai, auto_shroud or similar.

Definition at line 168 of file synced_context.cpp.

References state_.

Referenced by events::console_handler::is_enabled(), is_synced(), leave_synced_context::leave_synced_context(), actions::move_unit_and_record(), run_in_synced_context_if_not_already(), set_scontext_synced_base::set_scontext_synced_base(), game_lua_kernel::synced_state(), leave_synced_context::~leave_synced_context(), and set_scontext_synced_base::~set_scontext_synced_base().

static event_list& synced_context::get_undo_commands ( )
inlinestatic

Definition at line 152 of file synced_context.hpp.

References undo_commands_.

Referenced by actions::undo_action::undo_action().

int synced_context::get_unit_id_diff ( )
static
void synced_context::ignore_error_function ( const std::string message,
bool  heavy 
)
static

a function to be passed to run_in_synced_context to ignore the error.

Definition at line 163 of file synced_context.cpp.

References DBG_REPLAY.

Referenced by ai::recall_result::do_execute(), wb::recall::execute(), and events::menu_handler::recall().

bool synced_context::is_simultaneously ( )
static
Returns
whether we already sended data about the current action to other clients. which means we cannot undo it. returns is_simultaneously_

Definition at line 212 of file synced_context.cpp.

References is_simultaneously_.

Referenced by user_choice_manager::ask_local_choice().

bool synced_context::is_synced ( )
static
Returns
whether we are currently executing a synced action like recruit, start, recall, disband, movement, attack, init_side, end_turn, fire_event, lua_ai, auto_shroud or similar.

Definition at line 173 of file synced_context.cpp.

References get_synced_state(), and SYNCED.

Referenced by actions::undo_list::apply_shroud_changes(), ask_server_choice(), can_undo(), unit::clone(), game_display::display_unit_hex(), ai::attack_result::do_execute(), do_replay_handle(), get_unit_id_diff(), mp_sync::get_user_choice(), mp_sync::get_user_choice_multiple_sides(), game_display::highlight_hex(), side_filter::match_internal(), and unit::set_underlying_id().

void synced_context::just_log_error_function ( const std::string message,
bool  heavy 
)
static

a function to be passed to run_in_synced_context to log the error.

Definition at line 158 of file synced_context.cpp.

References ERR_REPLAY.

void synced_context::pull_remote_user_input ( )
static

called from get_user_choice while waiting for a remove user choice.

Definition at line 248 of file synced_context.cpp.

References syncmp_registry::pull_remote_choice().

Referenced by ask_server_choice(), and user_choice_manager::pull().

void synced_context::reset_is_simultaneously ( )
static
void synced_context::reset_redo_commands ( )
static

Definition at line 383 of file synced_context.cpp.

References redo_commands_.

Referenced by set_scontext_synced_base::set_scontext_synced_base().

void synced_context::reset_undo_commands ( )
static

Definition at line 378 of file synced_context.cpp.

References undo_commands_.

Referenced by set_scontext_synced_base::set_scontext_synced_base().

bool synced_context::run ( const std::string commandname,
const config data,
bool  use_undo = true,
bool  show = true,
synced_command::error_handler_function  error_handler = default_error_function 
)
static

Sets the context to 'synced', initialises random context, and calls the given function.

The plan is that in replay 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).

movement commands are currently treated specially, thats because actions::move_unit returns a value and some function use that value. maybe i should add a way here to return a value.

ai's attacks are also treated special because the ai wants to pass advancement_aspects.

redoing does normaly not take place in a synced context, because we saved the dependent=true replaycommands in the replaystack data. also there are no events of similar fired when redoing an action (in most cases).

Parameters
use_undothis parameter is used to ignore undos during an ai move to optimize.
error_handleran error handler for the case that data contains invalid data.
Returns
true if the action was successful.

Definition at line 59 of file synced_context.cpp.

References can_undo(), play_controller::check_victory(), resources::controller, DBG_REPLAY, set_scontext_synced::do_final_checkup(), synced_command::registry(), and resources::undo_stack.

Referenced by do_replay_handle(), and run_and_store().

bool synced_context::run_and_store ( const std::string commandname,
const config data,
bool  use_undo = true,
bool  show = true,
synced_command::error_handler_function  error_handler = default_error_function 
)
static
bool synced_context::run_and_throw ( const std::string commandname,
const config data,
bool  use_undo = true,
bool  show = true,
synced_command::error_handler_function  error_handler = default_error_function 
)
static
bool synced_context::run_in_synced_context_if_not_already ( const std::string commandname,
const config data,
bool  use_undo = true,
bool  show = true,
synced_command::error_handler_function  error_handler = default_error_function 
)
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 119 of file synced_context.cpp.

References ERR_REPLAY, get_synced_state(), LOCAL_CHOICE, synced_command::registry(), run_and_throw(), SYNCED, and UNSYNCED.

Referenced by ai::recall_result::do_execute(), ai::recruit_result::do_execute(), ai::synced_command_result::do_execute(), game_events::wml_menu_item::fire_event(), and game_events::WML_HANDLER_FUNCTION().

void synced_context::send_user_choice ( )
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 253 of file synced_context.cpp.

References is_simultaneously_, and syncmp_registry::send_user_choice().

Referenced by user_choice_manager::ask_local_choice().

void synced_context::set_is_simultaneously ( )
static
void synced_context::set_last_unit_id ( int  id)
static

Definition at line 236 of file synced_context.cpp.

References last_unit_id_.

Referenced by set_scontext_synced_base::set_scontext_synced_base().

void synced_context::set_synced_state ( synced_state  newstate)
static

Member Data Documentation

bool synced_context::is_simultaneously_ = false
staticprivate
int synced_context::last_unit_id_ = 0
staticprivate

Used to restore the unit id manager when undoing.

Definition at line 175 of file synced_context.hpp.

Referenced by get_unit_id_diff(), and set_last_unit_id().

synced_context::event_list synced_context::redo_commands_
staticprivate

Actions wml to be executed when the current actio is redone.

Definition at line 183 of file synced_context.hpp.

Referenced by add_redo_commands(), get_redo_commands(), and reset_redo_commands().

synced_context::synced_state synced_context::state_ = synced_context::UNSYNCED
staticprivate

Definition at line 162 of file synced_context.hpp.

Referenced by get_synced_state(), and set_synced_state().

synced_context::event_list synced_context::undo_commands_
staticprivate

Actions wml to be executed when the current actio is undone.

Definition at line 179 of file synced_context.hpp.

Referenced by add_undo_commands(), get_undo_commands(), and reset_undo_commands().


The documentation for this class was generated from the following files: