Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the comment in replay.cpp says we want "send data to others" so calling "pull_remote_user_input" is not really correct. I added a function synced_context::send_user_choice for this case. this fixes a bug where players can get an oos error in wesnoth.synconize_choice I backported a simpler version to 1.12: 0e79ef9 because i don't know whether this bug can happen in 1.12 too.
- Loading branch information
Showing
9 changed files
with
146 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "syncmp_handler.hpp" | ||
|
||
#include <cassert> | ||
#include <boost/foreach.hpp> | ||
|
||
syncmp_handler::syncmp_handler() | ||
{ | ||
syncmp_registry::add_handler(this); | ||
} | ||
|
||
syncmp_handler::~syncmp_handler() | ||
{ | ||
syncmp_registry::remove_handler(this); | ||
} | ||
|
||
std::vector<syncmp_handler*>& syncmp_registry::handlers() | ||
{ | ||
//using pointer in order to prevent destruction at programm end. Although in this simple case it shouldn't matter. | ||
static t_handlers* handlers_ = new t_handlers(); | ||
return *handlers_; | ||
} | ||
|
||
void syncmp_registry::remove_handler(syncmp_handler* handler) | ||
{ | ||
t_handlers::iterator elem = std::find(handlers().begin(), handlers().end(), handler); | ||
assert(elem != handlers().end()); | ||
handlers().erase(elem); | ||
} | ||
|
||
void syncmp_registry::add_handler(syncmp_handler* handler) | ||
{ | ||
t_handlers::iterator elem = std::find(handlers().begin(), handlers().end(), handler); | ||
assert(elem == handlers().end()); | ||
handlers().push_back(handler); | ||
} | ||
|
||
void syncmp_registry::pull_remote_choice() | ||
{ | ||
BOOST_FOREACH(syncmp_handler* phandler, handlers()) | ||
{ | ||
phandler->pull_remote_choice(); | ||
} | ||
} | ||
|
||
void syncmp_registry::send_user_choice() | ||
{ | ||
BOOST_FOREACH(syncmp_handler* phandler, handlers()) | ||
{ | ||
phandler->send_user_choice(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#include<vector> | ||
/* | ||
Automaticly registrates itself in the registry in the constructor. | ||
*/ | ||
class syncmp_handler | ||
{ | ||
public: | ||
syncmp_handler(); | ||
virtual void pull_remote_choice() = 0; | ||
virtual void send_user_choice() = 0; | ||
virtual ~syncmp_handler(); | ||
}; | ||
|
||
class syncmp_registry | ||
{ | ||
public: | ||
//called by get_user_choice while waiting for a remote user choice. | ||
static void pull_remote_choice(); | ||
//called when get_user_choice was called and the client wants to send the choice to the other clients immideately | ||
static void send_user_choice(); | ||
private: | ||
friend class syncmp_handler; | ||
typedef std::vector<syncmp_handler*> t_handlers; | ||
static void remove_handler(syncmp_handler* handler); | ||
static void add_handler(syncmp_handler* handler); | ||
static t_handlers& handlers(); | ||
}; |