Skip to content

Commit

Permalink
fix get_user_choice for other sides
Browse files Browse the repository at this point in the history
as the comment in replay.cpp says we want "send data to others" so
calling "pull_remote_user_input" is not really correct. Since
plamp_controller::handle_generaic_command("ai_user_input")
also invokes send_data we just don't call it with "sync_network" in this
case. This solution is still not optmial but it has the smallest chance
to break things since epecialy because this should go to 1.12 too.

Conflicts:
	src/ai/manager.cpp
  • Loading branch information
gfgtdf committed Jun 15, 2014
1 parent 799e09d commit 0e79ef9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ai/manager.cpp
Expand Up @@ -398,10 +398,10 @@ void manager::remove_turn_started_observer( events::observer* event_observer )
turn_started_.detach_handler(event_observer);
}

void manager::raise_user_interact() {
void manager::raise_user_interact(bool force_now) {
const int interact_time = 30;
const int time_since_interact = SDL_GetTicks() - last_interact_;
if(time_since_interact < interact_time) {
if(time_since_interact < interact_time && !force_now) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ai/manager.hpp
Expand Up @@ -184,8 +184,10 @@ class manager
* with the interface. This function will make sure that interaction
* doesn't occur too often, so there is no problem with calling it very
* regularly.
* @param force ignore if we already called this function recenlty,
* this is part of a hack related to mp_sync
*/
static void raise_user_interact();
static void raise_user_interact(bool force= false);

/**
* Notifies all observers of 'ai_sync_network' event.
Expand Down
2 changes: 1 addition & 1 deletion src/replay.cpp
Expand Up @@ -1023,7 +1023,7 @@ static std::map<int, config> get_user_choice_internal(const std::string &name, c
//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();
synced_context::pull_remote_user_input(true);
}
continue;

Expand Down
6 changes: 4 additions & 2 deletions src/synced_context.cpp
Expand Up @@ -161,7 +161,7 @@ namespace
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(lua_network_error)
};
}
void synced_context::pull_remote_user_input()
void synced_context::pull_remote_user_input(bool send_only)
{
//we sended data over the network.
is_simultaneously_ = true;
Expand All @@ -174,13 +174,15 @@ void synced_context::pull_remote_user_input()
//because that might result in crashs if someone clicks anywhere during screenlock.
try
{
ai::manager::raise_user_interact();
ai::manager::raise_user_interact(send_only);
}
catch(end_turn_exception&)
{
//ignore, since it will be thwown throw again.
}
}
if(send_only)
return;
try
{
ai::manager::raise_sync_network();
Expand Down
2 changes: 1 addition & 1 deletion src/synced_context.hpp
Expand Up @@ -76,7 +76,7 @@ class synced_context
/*
called from get_user_choice;
*/
static void pull_remote_user_input();
static void pull_remote_user_input(bool send_only = false);
/*
a function to be passed to run_in_synced_context to assert false on error (the default).
*/
Expand Down

0 comments on commit 0e79ef9

Please sign in to comment.