Fixed another dumb warning reported in the forum and added a nice assert for synchronization issues during network game. So, don't try it if you're not ready to get crashes in the face.
This commit is contained in:
@@ -30,7 +30,7 @@ using namespace std;
|
||||
|
||||
class GameObserver{
|
||||
protected:
|
||||
|
||||
unsigned int mSeed;
|
||||
GameType mGameType;
|
||||
MTGCardInstance * cardWaitingForTargets;
|
||||
queue<WEvent *> eventsQueue;
|
||||
@@ -40,7 +40,6 @@ class GameObserver{
|
||||
list<string> loadingList;
|
||||
list<string>::iterator loadingite;
|
||||
RandomGenerator randomGenerator;
|
||||
unsigned int mSeed;
|
||||
WResourceManager* mResourceManager;
|
||||
JGE* mJGE;
|
||||
DeckManager* mDeckManager;
|
||||
@@ -54,7 +53,7 @@ class GameObserver{
|
||||
bool parseLine(const string& s);
|
||||
virtual void logAction(const string& s);
|
||||
bool processAction(const string& s, bool swapPlayer = false);
|
||||
bool processActions(bool undo
|
||||
bool processActions(bool undo, bool swapPlayer
|
||||
#ifdef TESTSUITE
|
||||
, TestSuiteGame* testgame
|
||||
#endif
|
||||
@@ -201,6 +200,7 @@ public:
|
||||
static void loadPlayer(void*pThis, stringstream& in, stringstream& out);
|
||||
static void sendAction(void*pThis, stringstream& in, stringstream& out);
|
||||
static void synchronize(void*pThis, stringstream& in, stringstream& out);
|
||||
static void checkSynchro(void*pxThis, stringstream& in, stringstream& out);
|
||||
static void ignoreResponse(void*pThis, stringstream& in, stringstream& out){};
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1646,7 +1646,7 @@ bool GameObserver::load(const string& ss, bool undo, bool swapPlayers
|
||||
// take a snapshot before processing the actions
|
||||
resetStartupGame();
|
||||
|
||||
mRules->initGame(this, currentPlayerSet);
|
||||
if(mRules) mRules->initGame(this, currentPlayerSet);
|
||||
phaseRing->goToPhase(0, currentPlayer, false);
|
||||
phaseRing->goToPhase(mCurrentGamePhase, currentPlayer);
|
||||
|
||||
@@ -1655,7 +1655,7 @@ bool GameObserver::load(const string& ss, bool undo, bool swapPlayers
|
||||
testgame->initGame();
|
||||
#endif //TESTSUITE
|
||||
|
||||
processActions(undo
|
||||
processActions(undo, swapPlayers
|
||||
#ifdef TESTSUITE
|
||||
, testgame
|
||||
#endif //TESTSUITE
|
||||
@@ -1729,7 +1729,7 @@ bool GameObserver::processAction(const string& s, bool swapPlayer)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GameObserver::processActions(bool undo
|
||||
bool GameObserver::processActions(bool undo, bool swapPlayer
|
||||
#ifdef TESTSUITE
|
||||
, TestSuiteGame* testgame
|
||||
#endif
|
||||
@@ -1767,7 +1767,7 @@ bool GameObserver::processActions(bool undo
|
||||
|
||||
for(loadingite = loadingList.begin(); loadingite != loadingList.end(); loadingite++, cmdIndex++)
|
||||
{
|
||||
processAction(*loadingite);
|
||||
processAction(*loadingite, swapPlayer);
|
||||
|
||||
size_t nb = actionsList.size();
|
||||
|
||||
@@ -1954,8 +1954,8 @@ NetworkGameObserver::NetworkGameObserver(JNetwork* pNetwork, WResourceManager* o
|
||||
: GameObserver(output, input), mpNetworkSession(pNetwork), mSynchronized(false)
|
||||
{
|
||||
mpNetworkSession->registerCommand("loadPlayer", this, loadPlayer, ignoreResponse);
|
||||
mpNetworkSession->registerCommand("synchronize", this, synchronize, ignoreResponse);
|
||||
mpNetworkSession->registerCommand("sendAction", this, sendAction, ignoreResponse);
|
||||
mpNetworkSession->registerCommand("synchronize", this, synchronize, checkSynchro);
|
||||
mpNetworkSession->registerCommand("sendAction", this, sendAction, checkSynchro);
|
||||
}
|
||||
|
||||
NetworkGameObserver::~NetworkGameObserver()
|
||||
@@ -2017,6 +2017,19 @@ void NetworkGameObserver::synchronize(void*pxThis, stringstream& in, stringstrea
|
||||
NetworkGameObserver* pThis = (NetworkGameObserver*)pxThis;
|
||||
// now, we need to swap players as player1 for host is player 2 for guest
|
||||
pThis->load(in.str(), false, true);
|
||||
out << *pThis;
|
||||
}
|
||||
|
||||
|
||||
void NetworkGameObserver::checkSynchro(void*pxThis, stringstream& in, stringstream& out)
|
||||
{
|
||||
NetworkGameObserver* pThis = (NetworkGameObserver*)pxThis;
|
||||
|
||||
GameObserver aGame;
|
||||
aGame.mRules = pThis->mRules;
|
||||
aGame.load(in.str(), false, true);
|
||||
|
||||
assert(aGame == *pThis);
|
||||
}
|
||||
|
||||
void NetworkGameObserver::sendAction(void*pxThis, stringstream& in, stringstream& out)
|
||||
@@ -2026,6 +2039,7 @@ void NetworkGameObserver::sendAction(void*pxThis, stringstream& in, stringstream
|
||||
pThis->mForwardAction = false;
|
||||
pThis->processAction(in.str(), true);
|
||||
pThis->mForwardAction = true;
|
||||
out << *pThis;
|
||||
}
|
||||
|
||||
void NetworkGameObserver::logAction(const string& s)
|
||||
|
||||
Reference in New Issue
Block a user