Changes in preparation for the integration of the network server. GUI does not directly know Game and Hand any more, only Session. WARNING: This version crashes due to initialization order problems.

This commit is contained in:
lotodore
2007-05-11 12:01:13 +00:00
parent a37fe9969e
commit 7c6337d810
20 changed files with 441 additions and 323 deletions
+24 -8
View File
@@ -30,7 +30,7 @@
using namespace std;
Session::Session(GuiInterface *g)
: currentGameID(0), myNetClient(0), myNetServer(0), actualGame(0), myGui(g)
: currentGameID(0), myNetClient(0), myNetServer(0), currentGame(0), myGui(g)
{
myConfig = new ConfigFile;
@@ -49,9 +49,8 @@ Session::~Session()
void Session::startGame(const GameData &gameData) {
myGui->setGame(0);
myGui->initGui(gameData.guiSpeed);
deleteGame();
myGui->initGui(gameData.guiSpeed);
currentGameID++;
@@ -75,18 +74,21 @@ void Session::startGame(const GameData &gameData) {
playerDataList.push_back(playerData);
}
actualGame = new Game(myGui, playerDataList, gameData, currentGameID);
myGui->setGame(actualGame);
currentGame = new Game(myGui, playerDataList, gameData, currentGameID);
}
void Session::deleteGame() {
delete actualGame;
actualGame = 0;
delete currentGame;
currentGame = 0;
}
Game *Session::getCurrentGame()
{
return currentGame;
}
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd)
{
if (myNetClient || !myGui)
@@ -149,6 +151,13 @@ void Session::initiateNetworkServerGame()
myNetServer->StartGame();
}
void Session::waitForNetworkServerAction(GameState state, unsigned uniquePlayerId)
{
if (!myNetServer)
return; // TODO: throw exception
myNetServer->WaitForClientAction(state, uniquePlayerId);
}
void Session::terminateNetworkServer()
{
if (!myNetServer)
@@ -163,3 +172,10 @@ void Session::terminateNetworkServer()
myNetServer = 0;
}
bool Session::isNetworkServerRunning() const
{
// TODO: Hack
// TODO: Every function which calls this function is also hacked.
return myNetServer != 0;
}