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
+18 -10
View File
@@ -110,17 +110,25 @@ void LocalFlop::flopRun() {
// cout << "playersTurn " << playersTurn << endl;
// wenn wir letzter aktiver Spieler vor SmallBlind sind, dann flopFirstRound zuende
if(myHand->getPlayerArray()[playersTurn]->getMyID() == activePlayerBeforeSmallBlind) { firstFlopRound = 0; }
if(playersTurn == 0) {
// Wir sind dran
// cout << "actualRound " << myHand->getActualRound() << endl;
// cout << "highestSet vor meInAction " << highestSet << endl;
myHand->getGuiInterface()->meInAction();
if(myHand->getGuiInterface()->isNetworkServer())
{
myHand->getGuiInterface()->waitForNetworkAction(
GAME_STATE_FLOP, myHand->getPlayerArray()[playersTurn]->getMyUniqueID());
}
else {
//Gegner sind dran
// cout << "NextPlayerSpeed3 start" << endl;
myHand->getGuiInterface()->flopAnimation2();
else
{
if(playersTurn == 0) {
// Wir sind dran
// cout << "actualRound " << myHand->getActualRound() << endl;
// cout << "highestSet vor meInAction " << highestSet << endl;
myHand->getGuiInterface()->meInAction();
}
else {
//Gegner sind dran
// cout << "NextPlayerSpeed3 start" << endl;
myHand->getGuiInterface()->flopAnimation2();
}
}
}
}
-1
View File
@@ -30,7 +30,6 @@ LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, Playe
CardsValue myCardsValue;
myGui->setHand(this);
myBoard->setHand(this);
+15 -7
View File
@@ -107,14 +107,22 @@ void LocalPreflop::preflopRun() {
myHand->getPlayerArray()[playersTurn]->setMyTurn(1);
myHand->getGuiInterface()->refreshGroupbox(playersTurn,2);
if(playersTurn == 0) {
// Wir sind dran
myHand->getGuiInterface()->meInAction();
if(myHand->getGuiInterface()->isNetworkServer())
{
myHand->getGuiInterface()->waitForNetworkAction(
GAME_STATE_PREFLOP, myHand->getPlayerArray()[playersTurn]->getMyUniqueID());
}
else {
//Gegner sind dran
// cout << "NextPlayerSpeed3 start" << endl;
myHand->getGuiInterface()->preflopAnimation2();
else
{
if(playersTurn == 0) {
// Wir sind dran
myHand->getGuiInterface()->meInAction();
}
else {
//Gegner sind dran
// cout << "NextPlayerSpeed3 start" << endl;
myHand->getGuiInterface()->preflopAnimation2();
}
}
}
}
+17 -9
View File
@@ -110,16 +110,24 @@ void LocalRiver::riverRun() {
// cout << "playersTurn " << playersTurn << endl;
// wenn wir letzter aktiver Spieler vor SmallBlind sind, dann flopFirstRound zuende
if(myHand->getPlayerArray()[playersTurn]->getMyID() == activePlayerBeforeSmallBlind) { firstRiverRound = 0; }
if(playersTurn == 0) {
// Wir sind dran
// cout << "actualRound " << myHand->getActualRound() << endl;
// cout << "highestSet vor meInAction " << highestSet << endl;
myHand->getGuiInterface()->meInAction();
if(myHand->getGuiInterface()->isNetworkServer())
{
myHand->getGuiInterface()->waitForNetworkAction(
GAME_STATE_RIVER, myHand->getPlayerArray()[playersTurn]->getMyUniqueID());
}
else {
//Gegner sind dran
myHand->getGuiInterface()->riverAnimation2();
else
{
if(playersTurn == 0) {
// Wir sind dran
// cout << "actualRound " << myHand->getActualRound() << endl;
// cout << "highestSet vor meInAction " << highestSet << endl;
myHand->getGuiInterface()->meInAction();
}
else {
//Gegner sind dran
myHand->getGuiInterface()->riverAnimation2();
}
}
}
}
+18 -10
View File
@@ -111,17 +111,25 @@ void LocalTurn::turnRun() {
// cout << "playersTurn " << playersTurn << endl;
// wenn wir letzter aktiver Spieler vor SmallBlind sind, dann flopFirstRound zuende
if(myHand->getPlayerArray()[playersTurn]->getMyID() == activePlayerBeforeSmallBlind) { firstTurnRound = 0; }
if(playersTurn == 0) {
// Wir sind dran
// cout << "actualRound " << myHand->getActualRound() << endl;
// cout << "highestSet vor meInAction " << highestSet << endl;
myHand->getGuiInterface()->meInAction();
if(myHand->getGuiInterface()->isNetworkServer())
{
myHand->getGuiInterface()->waitForNetworkAction(
GAME_STATE_TURN, myHand->getPlayerArray()[playersTurn]->getMyUniqueID());
}
else {
//Gegner sind dran
// cout << "NextPlayerSpeed3 start" << endl;
myHand->getGuiInterface()->turnAnimation2();
else
{
if(playersTurn == 0) {
// Wir sind dran
// cout << "actualRound " << myHand->getActualRound() << endl;
// cout << "highestSet vor meInAction " << highestSet << endl;
myHand->getGuiInterface()->meInAction();
}
else {
//Gegner sind dran
// cout << "NextPlayerSpeed3 start" << endl;
myHand->getGuiInterface()->turnAnimation2();
}
}
}
}
+5
View File
@@ -110,6 +110,11 @@ Game::~Game()
}
HandInterface * Game::getCurrentHand()
{
return actualHand;
}
void Game::startHand()
{
+4 -2
View File
@@ -37,9 +37,11 @@ struct GameData;
class Game {
public:
Game(GuiInterface *gui, const PlayerDataList &playerDataList, const GameData &gameData, int gameId);
Game(GuiInterface *gui, const PlayerDataList &playerDataList, const GameData &gameData, int gameId);
~Game();
~Game();
HandInterface *getCurrentHand();
//Zufgriff Startvariablen
void setStartQuantityPlayers(const int& theValue) { startQuantityPlayers = theValue; }
+9 -6
View File
@@ -22,11 +22,12 @@
#include <net/clientcallback.h>
#include <net/servercallback.h>
#include <game_defs.h>
#include <string>
#include <boost/shared_ptr.hpp>
class Game;
class Session;
class HandInterface;
class GuiInterface : public ClientCallback, public ServerCallback {
@@ -34,10 +35,12 @@ public:
virtual ~GuiInterface();
virtual void initGui(int speed) =0;
//set
virtual void setGame(Game*) =0;
virtual void setHand(HandInterface*) =0;
virtual void setSession(Session*) =0;
virtual Session &getSession() =0;
virtual void setSession(boost::shared_ptr<Session> session) =0;
virtual bool isNetworkServer() const =0;
virtual void waitForNetworkAction(GameState state, unsigned uniquePlayerId) =0;
//refresh-Funktionen
virtual void refreshSet() const=0;
+6 -3
View File
@@ -19,6 +19,7 @@
***************************************************************************/
#include "guiwrapper.h"
#include "session.h"
using namespace std;
@@ -43,9 +44,11 @@ GuiWrapper::~GuiWrapper()
void GuiWrapper::initGui(int speed) { myW->initGui(speed); }
void GuiWrapper::setGame(Game *g) { myW->setGame(g); }
void GuiWrapper::setHand(HandInterface *lh) { myW->setHand(lh); }
void GuiWrapper::setSession(Session *s) { myW->setSession(s); }
Session &GuiWrapper::getSession() { return myW->getSession(); }
void GuiWrapper::setSession(boost::shared_ptr<Session> session) { myW->setSession(session); }
bool GuiWrapper::isNetworkServer() const { /* TODO hack */ return false; }
void GuiWrapper::waitForNetworkAction(GameState state, unsigned uniquePlayerId) { /* TODO hack */ }
void GuiWrapper::refreshSet() const { myW->refreshSet(); }
void GuiWrapper::refreshCash() const { myW->refreshCash(); }
+8 -9
View File
@@ -30,23 +30,22 @@
#include <string>
#include <iostream>
#include "handinterface.h"
#include "session.h"
#include "game.h"
class Session;
class GuiWrapper : public GuiInterface
{
public:
GuiWrapper();
GuiWrapper();
~GuiWrapper();
~GuiWrapper();
void initGui(int speed);
void setGame(Game*);
void setHand(HandInterface*);
void setSession(Session*);
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
bool isNetworkServer() const;
void waitForNetworkAction(GameState state, unsigned uniquePlayerId);
void refreshSet() const;
void refreshCash() const;
+32 -27
View File
@@ -20,6 +20,9 @@
#include "log.h"
#include "mainwindowimpl.h"
#include <handinterface.h>
#include <session.h>
#include <game.h>
#include <game_defs.h>
using namespace std;
@@ -149,44 +152,45 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
//Aktive Spieler zählen
int activePlayersCounter = 0;
HandInterface *currentHand = myW->getSession().getCurrentGame()->getCurrentHand();
for (k=0; k<MAX_NUMBER_OF_PLAYERS; k++) {
if (myW->getActualHand()->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
if (currentHand->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
}
k = 0;
if(activePlayersCounter > 2) {
for(i=0; i<myW->getActualHand()->getStartQuantityPlayers(); i++) {
for(i=0; i<currentHand->getStartQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus()) {
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
//print cash only for active players
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 1) {
if(currentHand->getPlayerArray()[i]->getMyButton() == 1) {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash(),10)+"$";
}
else {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash()+myW->getActualHand()->getPlayerArray()[i]->getMySet(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
}
}
}
}
else {
for(i=0; i<myW->getActualHand()->getStartQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus()) {
for(i=0; i<currentHand->getStartQuantityPlayers(); i++) {
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
//print cash only for active players
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 3) {
if(currentHand->getPlayerArray()[i]->getMyButton() == 3) {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash()+myW->getActualHand()->getPlayerArray()[i]->getMySet(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
}
else {
if(k==1) { stream << ", "; }
k=1;
stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash()+myW->getActualHand()->getPlayerArray()[i]->getMySet(),10)+"$";
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
}
}
}
@@ -198,17 +202,17 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
//Aktive Spieler zählen
int activePlayersCounter = 0;
for (k=0; k<MAX_NUMBER_OF_PLAYERS; k++) {
if (myW->getActualHand()->getPlayerArray()[k]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
if (currentHand->getPlayerArray()[k]->getMyAction() != 1 && currentHand->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
}
if(activePlayersCounter < 3) { j=1; }
// cout << activePlayersCounter << endl;
// cout << (i+myW->getActualHand()->getDealerPosition()+j)%5 << endl;
// cout << (i+currentHand->getDealerPosition()+j)%5 << endl;
switch (myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyButton()) {
case 2 : stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$), ";
switch (currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyButton()) {
case 2 : stream << QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$), ";
break;
case 3 : stream << QString::fromUtf8(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$)";
case 3 : stream << QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$)";
break;
default :;
}
@@ -226,18 +230,19 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
void Log::logPlayerWinsMsg(int playerID, int pot) {
int i;
HandInterface *currentHand = myW->getSession().getCurrentGame()->getCurrentHand();
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
// if (cardsValueInt != -1) {
// myW->textBrowser_Log->append(QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$ with "+translateCardsValueCode(cardsValueInt).at(0)+"!!! ");
// stream << "</br><i>"+QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$ with "+translateCardsValueCode(cardsValueInt).at(0)+"!!! ");
// stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// }
// else {
myW->textBrowser_Log->append(QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!! ");
stream << "</br><i>"+QString::fromUtf8(myW->getActualHand()->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!! ");
stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// }
myLogFile->close();
@@ -340,20 +345,20 @@ void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int
// Kicker anzeigen?
// for(i=0; i<5; i++) {
// if(myW->getActualHand()->getPlayerArray()[i]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus() == 1 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// if(currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// sameHandCounter++;
// if(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt();
// if(currentHand->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = currentHand->getPlayerArray()[i]->getMyCardsValueInt();
// }
// }
// }
// Unterschied ermitteln
// for(i=0; i<5; i++) {
// if(myW->getActualHand()->getPlayerArray()[i]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus() == 1 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// if(currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) {
// sameHandCounter++;
// if(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt();
// if(currentHand->getPlayerArray()[i]->getMyCardsValueInt() > tempHighestCardsValueInt) {
// tempHighestCardsValueInt = currentHand->getPlayerArray()[i]->getMyCardsValueInt();
// }
// }
// }
@@ -364,7 +369,7 @@ void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int
/* } else {
if(cardsValueInt == tempHighestCardsValueInt) {
for(i=0; i<5; i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[i]->getMyActiveStatus() == 1 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(myW->getActualHand()->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) ;
if(currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000 == 3 && currentHand->getPlayerArray()[i]->getMyCardsValueInt()/1000000 - (int)(currentHand->getPlayerArray()[i]->getMyCardsValueInt()/100000000)*100 == secondPart) ;
}
}
}*/
File diff suppressed because it is too large Load Diff
+9 -16
View File
@@ -21,20 +21,19 @@
#define MAINWINDOWIMPL_H
#include "ui_mainwindow.h"
#include "game_defs.h"
#include <gamedata.h>
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <QtGui>
#include <QtCore>
#include "handinterface.h"
#include "game_defs.h"
#include <gamedata.h>
class Session;
class Game;
class Log;
class ConfigFile;
class Session;
class BoardInterface;
// class HandInterface;
@@ -60,15 +59,11 @@ public:
void initGui(int speed);
void setGame(Game*);
void setHand(HandInterface*);
void setSession(Session*);
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
void setLog(Log*);
void setActualHand(HandInterface* theValue) { actualHand = theValue;}
HandInterface* getActualHand() const { return actualHand;}
//refresh-Funktionen
void refreshSet();
void refreshButton();
@@ -203,9 +198,7 @@ public slots:
private:
Game *actualGame;
HandInterface *actualHand;
Session *mySession;
boost::shared_ptr<Session> mySession;
Log *myLog;
ConfigFile *myConfig;
+6 -4
View File
@@ -80,10 +80,10 @@ ServerRecvThread::AddConnection(boost::shared_ptr<ConnectData> data)
}
void
ServerRecvThread::AddNotification(unsigned notification)
ServerRecvThread::AddNotification(unsigned message, unsigned param1, unsigned param2)
{
boost::mutex::scoped_lock lock(m_notificationQueueMutex);
m_notificationQueue.push_back(notification);
m_notificationQueue.push_back(Notification(message, param1, param2));
}
void
@@ -135,14 +135,16 @@ ServerRecvThread::NotificationLoop()
// Process all notifications.
while (!m_notificationQueue.empty())
{
unsigned notification = m_notificationQueue.front();
Notification notification = m_notificationQueue.front();
m_notificationQueue.pop_front();
switch(notification)
switch(notification.message)
{
case NOTIFY_GAME_START:
SetState(SERVER_START_GAME_STATE::Instance());
break;
case NOTIFY_WAIT_FOR_CLIENT_ACTION:
break;
}
}
}
+11 -1
View File
@@ -62,7 +62,17 @@ ServerThread::StartGame()
return; // TODO: throw exception
// Thread-safe notification.
GetRecvThread().AddNotification(NOTIFY_GAME_START);
GetRecvThread().AddNotification(NOTIFY_GAME_START, 0, 0);
}
void
ServerThread::WaitForClientAction(GameState state, unsigned uniquePlayerId)
{
if (!IsRunning())
return; // TODO: throw exception
// Thread-safe notification.
GetRecvThread().AddNotification(NOTIFY_WAIT_FOR_CLIENT_ACTION, state, uniquePlayerId);
}
ServerCallback &
+13 -3
View File
@@ -36,7 +36,8 @@
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
// Notifications
#define NOTIFY_GAME_START 1
#define NOTIFY_GAME_START 1
#define NOTIFY_WAIT_FOR_CLIENT_ACTION 2
class ServerRecvState;
class SenderThread;
@@ -54,15 +55,24 @@ public:
void Init(const std::string &pwd, const GameData &gameData);
void AddConnection(boost::shared_ptr<ConnectData> data);
void AddNotification(unsigned notification);
void AddNotification(unsigned message, unsigned param1, unsigned param2);
ServerCallback &GetCallback();
protected:
struct Notification
{
Notification(unsigned m, unsigned p1, unsigned p2)
: message(m), param1(p1), param2(p2) {}
unsigned message;
unsigned param1;
unsigned param2;
};
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
typedef std::map<SOCKET, boost::shared_ptr<SessionData> > SocketSessionMap;
typedef std::deque<unsigned> NotificationQueue;
typedef std::deque<Notification> NotificationQueue;
typedef std::list<std::pair<boost::microsec_timer, boost::shared_ptr<SessionData> > > CloseSessionList;
// Main function of the thread.
+2
View File
@@ -21,6 +21,7 @@
#ifndef _SERVERTHREAD_H_
#define _SERVERTHREAD_H_
#include <game_defs.h>
#include <core/thread.h>
#include <string>
#include <memory>
@@ -42,6 +43,7 @@ public:
void Init(unsigned serverPort, bool ipv6, const std::string &pwd,
const GameData &gameData);
void StartGame();
void WaitForClientAction(GameState state, unsigned uniquePlayerId);
ServerCallback &GetCallback();
+4 -2
View File
@@ -87,8 +87,10 @@ int main( int argc, char **argv )
///////////////////////////////////////////////////
GuiInterface *myGuiInterface = new GuiWrapper();
Session theFirst(myGuiInterface);
myGuiInterface->setSession(&theFirst);
{
boost::shared_ptr<Session> session(new Session(myGuiInterface));
myGuiInterface->setSession(session);
}
int retVal = a.exec();
+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;
}
+7 -1
View File
@@ -20,6 +20,7 @@
#ifndef STDSESSION_H
#define STDSESSION_H
#include "gamedata.h"
#include "game_defs.h"
#include <string>
class GuiInterface;
@@ -38,14 +39,19 @@ public:
void startGame(const GameData &gameData);
void deleteGame();
Game *getCurrentGame();
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, const std::string &pwd);
void startNetworkClientForLocalServer();
void terminateNetworkClient();
void startNetworkServer(const GameData &gameData);
void initiateNetworkServerGame();
void waitForNetworkServerAction(GameState state, unsigned uniquePlayerId);
void terminateNetworkServer();
bool isNetworkServerRunning() const;
void setCurrentGameID(const int& theValue) { currentGameID = theValue; }
int getCurrentGameID() const { return currentGameID; }
@@ -56,7 +62,7 @@ private:
ClientThread *myNetClient;
ServerThread *myNetServer;
Game *actualGame;
Game *currentGame;
GuiInterface *myGui;
ConfigFile *myConfig;