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{
|
class GameObserver{
|
||||||
protected:
|
protected:
|
||||||
|
unsigned int mSeed;
|
||||||
GameType mGameType;
|
GameType mGameType;
|
||||||
MTGCardInstance * cardWaitingForTargets;
|
MTGCardInstance * cardWaitingForTargets;
|
||||||
queue<WEvent *> eventsQueue;
|
queue<WEvent *> eventsQueue;
|
||||||
@@ -40,7 +40,6 @@ class GameObserver{
|
|||||||
list<string> loadingList;
|
list<string> loadingList;
|
||||||
list<string>::iterator loadingite;
|
list<string>::iterator loadingite;
|
||||||
RandomGenerator randomGenerator;
|
RandomGenerator randomGenerator;
|
||||||
unsigned int mSeed;
|
|
||||||
WResourceManager* mResourceManager;
|
WResourceManager* mResourceManager;
|
||||||
JGE* mJGE;
|
JGE* mJGE;
|
||||||
DeckManager* mDeckManager;
|
DeckManager* mDeckManager;
|
||||||
@@ -54,7 +53,7 @@ class GameObserver{
|
|||||||
bool parseLine(const string& s);
|
bool parseLine(const string& s);
|
||||||
virtual void logAction(const string& s);
|
virtual void logAction(const string& s);
|
||||||
bool processAction(const string& s, bool swapPlayer = false);
|
bool processAction(const string& s, bool swapPlayer = false);
|
||||||
bool processActions(bool undo
|
bool processActions(bool undo, bool swapPlayer
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
, TestSuiteGame* testgame
|
, TestSuiteGame* testgame
|
||||||
#endif
|
#endif
|
||||||
@@ -201,6 +200,7 @@ public:
|
|||||||
static void loadPlayer(void*pThis, stringstream& in, stringstream& out);
|
static void loadPlayer(void*pThis, stringstream& in, stringstream& out);
|
||||||
static void sendAction(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 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){};
|
static void ignoreResponse(void*pThis, stringstream& in, stringstream& out){};
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1646,7 +1646,7 @@ bool GameObserver::load(const string& ss, bool undo, bool swapPlayers
|
|||||||
// take a snapshot before processing the actions
|
// take a snapshot before processing the actions
|
||||||
resetStartupGame();
|
resetStartupGame();
|
||||||
|
|
||||||
mRules->initGame(this, currentPlayerSet);
|
if(mRules) mRules->initGame(this, currentPlayerSet);
|
||||||
phaseRing->goToPhase(0, currentPlayer, false);
|
phaseRing->goToPhase(0, currentPlayer, false);
|
||||||
phaseRing->goToPhase(mCurrentGamePhase, currentPlayer);
|
phaseRing->goToPhase(mCurrentGamePhase, currentPlayer);
|
||||||
|
|
||||||
@@ -1655,7 +1655,7 @@ bool GameObserver::load(const string& ss, bool undo, bool swapPlayers
|
|||||||
testgame->initGame();
|
testgame->initGame();
|
||||||
#endif //TESTSUITE
|
#endif //TESTSUITE
|
||||||
|
|
||||||
processActions(undo
|
processActions(undo, swapPlayers
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
, testgame
|
, testgame
|
||||||
#endif //TESTSUITE
|
#endif //TESTSUITE
|
||||||
@@ -1729,7 +1729,7 @@ bool GameObserver::processAction(const string& s, bool swapPlayer)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameObserver::processActions(bool undo
|
bool GameObserver::processActions(bool undo, bool swapPlayer
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
, TestSuiteGame* testgame
|
, TestSuiteGame* testgame
|
||||||
#endif
|
#endif
|
||||||
@@ -1767,7 +1767,7 @@ bool GameObserver::processActions(bool undo
|
|||||||
|
|
||||||
for(loadingite = loadingList.begin(); loadingite != loadingList.end(); loadingite++, cmdIndex++)
|
for(loadingite = loadingList.begin(); loadingite != loadingList.end(); loadingite++, cmdIndex++)
|
||||||
{
|
{
|
||||||
processAction(*loadingite);
|
processAction(*loadingite, swapPlayer);
|
||||||
|
|
||||||
size_t nb = actionsList.size();
|
size_t nb = actionsList.size();
|
||||||
|
|
||||||
@@ -1954,8 +1954,8 @@ NetworkGameObserver::NetworkGameObserver(JNetwork* pNetwork, WResourceManager* o
|
|||||||
: GameObserver(output, input), mpNetworkSession(pNetwork), mSynchronized(false)
|
: GameObserver(output, input), mpNetworkSession(pNetwork), mSynchronized(false)
|
||||||
{
|
{
|
||||||
mpNetworkSession->registerCommand("loadPlayer", this, loadPlayer, ignoreResponse);
|
mpNetworkSession->registerCommand("loadPlayer", this, loadPlayer, ignoreResponse);
|
||||||
mpNetworkSession->registerCommand("synchronize", this, synchronize, ignoreResponse);
|
mpNetworkSession->registerCommand("synchronize", this, synchronize, checkSynchro);
|
||||||
mpNetworkSession->registerCommand("sendAction", this, sendAction, ignoreResponse);
|
mpNetworkSession->registerCommand("sendAction", this, sendAction, checkSynchro);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkGameObserver::~NetworkGameObserver()
|
NetworkGameObserver::~NetworkGameObserver()
|
||||||
@@ -2017,6 +2017,19 @@ void NetworkGameObserver::synchronize(void*pxThis, stringstream& in, stringstrea
|
|||||||
NetworkGameObserver* pThis = (NetworkGameObserver*)pxThis;
|
NetworkGameObserver* pThis = (NetworkGameObserver*)pxThis;
|
||||||
// now, we need to swap players as player1 for host is player 2 for guest
|
// now, we need to swap players as player1 for host is player 2 for guest
|
||||||
pThis->load(in.str(), false, true);
|
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)
|
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->mForwardAction = false;
|
||||||
pThis->processAction(in.str(), true);
|
pThis->processAction(in.str(), true);
|
||||||
pThis->mForwardAction = true;
|
pThis->mForwardAction = true;
|
||||||
|
out << *pThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkGameObserver::logAction(const string& s)
|
void NetworkGameObserver::logAction(const string& s)
|
||||||
|
|||||||
Reference in New Issue
Block a user