Skip to content

Commit

Permalink
don't send data if it's not needed
Browse files Browse the repository at this point in the history
thsi code used the variable is_simulaneously, is_simultaneously_ is true
when we have aready sended data over the network, this variable is used
in get_user_choice so that when we make a local choice we only send it
immediately over the network if did already send data over the network.
  • Loading branch information
gfgtdf committed Apr 16, 2014
1 parent 99c64f0 commit 9176d6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/replay.cpp
Expand Up @@ -985,8 +985,11 @@ static std::map<int, config> get_user_choice_internal(const std::string &name, c
retv[local_side]= cfg;

//send data to others.
//TODO: check wether we are still in a local context (= wether we haven't senden anything during this action yet).
synced_context::pull_remote_user_input();
//but if there wasn't any data sended during this turn, we don't want to bein wth that now.
if(synced_context::is_simultaneously() || current_side != local_side)
{
synced_context::pull_remote_user_input();
}
continue;

}
Expand Down
15 changes: 14 additions & 1 deletion src/synced_context.cpp
Expand Up @@ -101,8 +101,20 @@ int synced_context::generate_random_seed()
return retv_c["new_seed"];
}

bool synced_context::is_simultaneously()
{
return is_simultaneously_;
}

void synced_context::reset_is_simultaneously()
{
is_simultaneously_ = false;
}

void synced_context::pull_remote_user_input()
{
//we sended data over the network.
is_simultaneously_ = true;
//code copied form persist_var, feels strange to call ai::.. functions for something where the ai isn't involved....
//note that ai::manager::raise_sync_network isn't called by the ai at all anymore (one more reason to put it somehwere else)
try
Expand Down Expand Up @@ -295,7 +307,8 @@ void set_scontext_synced::init()
assert(synced_context::get_syced_state() == synced_context::UNSYNCED);

synced_context::set_syced_state(synced_context::SYNCED);

synced_context::reset_is_simultaneously();

old_checkup_ = checkup_instance;
checkup_instance = & new_checkup_;
old_rng_ = random_new::generator;
Expand Down
19 changes: 12 additions & 7 deletions src/synced_context.hpp
Expand Up @@ -100,6 +100,14 @@ 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);
/*
returns is_simultaneously_
*/
static bool is_simultaneously();
/*
sets is_simultaneously_ = false, called when entering the synced context.
*/
static void reset_is_simultaneously();
private:
/*
similar to get_user_choice but asks the server instead of a user.
Expand All @@ -110,14 +118,11 @@ class synced_context
*/
static syced_state state_;
/*
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
is impossible to undo that.
also during the execution of networked turns this should always be true.
false = we are on a local turn and havent sended anything yet.
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 sended over the network.
this variable is currently not used, the original plan was to use it to send data as soon as possible if is_simultaneously_= true.
*/
false = we are on a local turn and haven't sended anything yet.
*/
static bool is_simultaneously_;
/*
TODO: replace ai::manager::raise_sync_network with this event because ai::manager::raise_sync_network has nothing to do with ai anymore.
Expand Down

0 comments on commit 9176d6a

Please sign in to comment.