Skip to content

Commit

Permalink
remove the 'only_attacks' random mode
Browse files Browse the repository at this point in the history
i came to the conclusion, that the lag for asking the server for a new
seed is neglectable. So we don't need this mode.
  • Loading branch information
gfgtdf committed Apr 13, 2014
1 parent fad4f6f commit 6e32189
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/ai/actions.cpp
Expand Up @@ -283,7 +283,7 @@ void attack_result::do_execute()
recorder.add_synced_command("attack", replay_helper::get_attack(attacker_loc_, defender_loc_, attacker_weapon, defender_weapon, a_->type_id(),
d_->type_id(), a_->level(), d_->level(), resources::tod_manager->turn(),
resources::tod_manager->get_time_of_day()));
set_scontext_synced sync("attack");
set_scontext_synced sync;
attack_unit_and_advance(attacker_loc_, defender_loc_, attacker_weapon, defender_weapon, true, advancements_);
}

Expand Down
29 changes: 4 additions & 25 deletions src/synced_context.cpp
Expand Up @@ -44,7 +44,7 @@ bool synced_context::run_in_synced_context(const std::string& commandname, const
use this after recorder.add_synced_command
because set_scontext_synced sets the checkup to the last added command
*/
set_scontext_synced sco(commandname);
set_scontext_synced sco;
synced_command::map::iterator it = synced_command::registry().find(commandname);
if(it == synced_command::registry().end())
{
Expand Down Expand Up @@ -156,7 +156,7 @@ void synced_context::pull_remote_user_input()
}


boost::shared_ptr<random_new::rng> synced_context::get_rng_for(const std::string& commandname)
boost::shared_ptr<random_new::rng> synced_context::get_rng_for_action()
{
/*
i copied the code for "deterministic_mode" from the code for "difficulty".
Expand All @@ -170,21 +170,6 @@ boost::shared_ptr<random_new::rng> synced_context::get_rng_for(const std::string
{
return boost::shared_ptr<random_new::rng>(new random_new::rng_deterministic(resources::gamedata->rng()));
}
else if (mode == "only_attacks")
{
/*
this is how is was before, it does make sense because random calculation in non attack actions
might be not important enough to pay the lag you get with asking the server for a new sed.
*/
if(commandname == "attack")
{
return boost::shared_ptr<random_new::rng>(new random_new::synced_rng(generate_random_seed));
}
else
{
return boost::shared_ptr<random_new::rng>(new random_new::rng_deterministic(resources::gamedata->rng()));
}
}
else
{
return boost::shared_ptr<random_new::rng>(new random_new::synced_rng(generate_random_seed));
Expand Down Expand Up @@ -294,20 +279,14 @@ config synced_context::ask_server(const std::string &name, const mp_sync::user_c
}
}

set_scontext_synced::set_scontext_synced(const std::string& commandname)
: new_rng_(synced_context::get_rng_for(commandname)), new_checkup_(recorder.get_last_real_command().child_or_add("checkup")), disabler_()
{
init();
}

set_scontext_synced::set_scontext_synced()
: new_rng_(synced_context::get_rng_for("")), new_checkup_(recorder.get_last_real_command().child_or_add("checkup")), disabler_()
: new_rng_(synced_context::get_rng_for_action()), new_checkup_(recorder.get_last_real_command().child_or_add("checkup")), disabler_()
{
init();
}

set_scontext_synced::set_scontext_synced(int number)
: new_rng_(synced_context::get_rng_for("")), new_checkup_(recorder.get_last_real_command().child_or_add("checkup" + boost::lexical_cast<std::string>(number))), disabler_()
: new_rng_(synced_context::get_rng_for_action()), new_checkup_(recorder.get_last_real_command().child_or_add("checkup" + boost::lexical_cast<std::string>(number))), disabler_()
{
init();
}
Expand Down
3 changes: 1 addition & 2 deletions src/synced_context.hpp
Expand Up @@ -87,7 +87,7 @@ class synced_context
/*
returns a rng_deterministic if in determinsic mode otherwise a rng_synced.
*/
static boost::shared_ptr<random_new::rng> get_rng_for(const std::string& commandname);
static boost::shared_ptr<random_new::rng> get_rng_for_action();
/*
returns is_simultaneously_
*/
Expand Down Expand Up @@ -128,7 +128,6 @@ class synced_context
class set_scontext_synced
{
public:
set_scontext_synced(const std::string& commanname);
set_scontext_synced();
/*
use this if you have multiple synced_context but only one replay entry.
Expand Down

0 comments on commit 6e32189

Please sign in to comment.