Some include file optimizations. Fixes for the server.

This commit is contained in:
lotodore
2007-05-15 20:37:37 +00:00
parent c3fd4dded6
commit c160a09811
19 changed files with 144 additions and 123 deletions
+3 -6
View File
@@ -20,9 +20,7 @@
#ifndef LOCALBOARD_H #ifndef LOCALBOARD_H
#define LOCALBOARD_H #define LOCALBOARD_H
#include "boardinterface.h" #include <boardinterface.h>
#include <iostream>
class PlayerInterface; class PlayerInterface;
class HandInterface; class HandInterface;
@@ -30,9 +28,8 @@ class HandInterface;
class LocalBoard : public BoardInterface{ class LocalBoard : public BoardInterface{
public: public:
LocalBoard(); LocalBoard();
~LocalBoard();
~LocalBoard();
void setPlayer(PlayerInterface**); void setPlayer(PlayerInterface**);
void setHand(HandInterface*); void setHand(HandInterface*);
+11 -1
View File
@@ -19,9 +19,19 @@
***************************************************************************/ ***************************************************************************/
#include "localenginefactory.h" #include "localenginefactory.h"
#include "localhand.h"
#include "localboard.h"
#include "localplayer.h"
#include "localpreflop.h"
#include "localflop.h"
#include "localturn.h"
#include "localriver.h"
#include <configfile.h>
LocalEngineFactory::LocalEngineFactory(ConfigFile *c) LocalEngineFactory::LocalEngineFactory(ConfigFile *c)
: EngineFactory(), myConfig(c) : myConfig(c)
{ {
} }
+11 -12
View File
@@ -22,22 +22,21 @@
#include <enginefactory.h> #include <enginefactory.h>
#include "localhand.h" #include <handinterface.h>
#include "localboard.h" #include <boardinterface.h>
#include "localplayer.h" #include <playerinterface.h>
#include "localpreflop.h" #include <preflopinterface.h>
#include "localflop.h" #include <flopinterface.h>
#include "localturn.h" #include <turninterface.h>
#include "localriver.h" #include <riverinterface.h>
#include "configfile.h" class ConfigFile;
class LocalEngineFactory : public EngineFactory class LocalEngineFactory : public EngineFactory
{ {
public: public:
LocalEngineFactory(ConfigFile*); LocalEngineFactory(ConfigFile*);
~LocalEngineFactory();
~LocalEngineFactory();
HandInterface* createHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC); HandInterface* createHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC);
BoardInterface* createBoard(); BoardInterface* createBoard();
@@ -46,8 +45,8 @@ public:
FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB); FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB);
TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB); TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB);
RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB); RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB);
private:
private:
ConfigFile *myConfig; ConfigFile *myConfig;
}; };
+2 -2
View File
@@ -19,8 +19,9 @@
***************************************************************************/ ***************************************************************************/
#include "localflop.h" #include "localflop.h"
#include <game_defs.h> #include <game_defs.h>
#include <handinterface.h>
using namespace std; //using namespace std;
LocalFlop::LocalFlop(HandInterface* bR, int id, int qP, int dP, int sB) : FlopInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstFlopRun(1), firstFlopRound(1), playersTurn(dP) LocalFlop::LocalFlop(HandInterface* bR, int id, int qP, int dP, int sB) : FlopInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstFlopRun(1), firstFlopRound(1), playersTurn(dP)
@@ -83,7 +84,6 @@ void LocalFlop::flopRun() {
myHand->getGuiInterface()->refreshAction(); myHand->getGuiInterface()->refreshAction();
myHand->switchRounds(); myHand->switchRounds();
} }
else { else {
// Flop ist wirklich dran // Flop ist wirklich dran
+4 -6
View File
@@ -20,17 +20,15 @@
#ifndef LOCALFLOP_H #ifndef LOCALFLOP_H
#define LOCALFLOP_H #define LOCALFLOP_H
#include "flopinterface.h" #include <flopinterface.h>
#include "handinterface.h"
#include <iostream> class HandInterface;
class LocalFlop : public FlopInterface{ class LocalFlop : public FlopInterface{
public: public:
LocalFlop(HandInterface*, int, int, int, int); LocalFlop(HandInterface*, int, int, int, int);
~LocalFlop();
~LocalFlop();
void setPlayersTurn(const int& theValue) { playersTurn = theValue; } void setPlayersTurn(const int& theValue) { playersTurn = theValue; }
+2
View File
@@ -18,6 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "localhand.h" #include "localhand.h"
#include "tools.h"
#include "cardsvalue.h"
#include <game_defs.h> #include <game_defs.h>
using namespace std; using namespace std;
+11 -23
View File
@@ -17,28 +17,23 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef HandInterface_H #ifndef LOCALHAND_H
#define HandInterface_H #define LOCALHAND_H
#include "enginefactory.h"
#include "handinterface.h"
#include "guiinterface.h"
#include "tools.h"
#include "cardsvalue.h"
#include "localpreflop.h"
#include "localflop.h"
#include "localturn.h"
#include "localriver.h"
#include <enginefactory.h>
#include <guiinterface.h>
#include <boardinterface.h>
#include <playerinterface.h>
#include <handinterface.h>
#include <preflopinterface.h>
#include <flopinterface.h>
#include <turninterface.h>
#include <riverinterface.h>
class LocalHand : public HandInterface{ class LocalHand : public HandInterface{
public: public:
LocalHand(EngineFactory*, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int); LocalHand(EngineFactory*, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int);
~LocalHand(); ~LocalHand();
void start(); void start();
@@ -91,13 +86,6 @@ public:
void switchRounds(); void switchRounds();
private: private:
EngineFactory *myFactory; EngineFactory *myFactory;
+5 -1
View File
@@ -18,8 +18,12 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "localplayer.h" #include "localplayer.h"
#include "localhand.h" #include "localhand.h"
#include "tools.h"
#include "cardsvalue.h"
#include <configfile.h>
#include <fstream>
using namespace std; using namespace std;
+3 -6
View File
@@ -20,17 +20,14 @@
#ifndef LOCALPLAYER_H #ifndef LOCALPLAYER_H
#define LOCALPLAYER_H #define LOCALPLAYER_H
#include "playerinterface.h" #include <playerinterface.h>
#include "cardsvalue.h"
#include "configfile.h"
#include <boost/shared_ptr.hpp>
#include <string> #include <string>
#include <fstream>
class CardsValue; class CardsValue;
class ConfigFile;
class HandInterface; class HandInterface;
class BoardInterface; class BoardInterface;
+2 -3
View File
@@ -19,10 +19,10 @@
***************************************************************************/ ***************************************************************************/
#include "localpreflop.h" #include "localpreflop.h"
#include "handinterface.h" #include <handinterface.h>
#include <game_defs.h> #include <game_defs.h>
using namespace std; //using namespace std;
LocalPreflop::LocalPreflop(HandInterface* bR, int id, int qP, int dP, int sB) : PreflopInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), bigBlindPosition(0), smallBlind(sB), highestSet(2*sB), preflopFirstRound(1), playersTurn(0) LocalPreflop::LocalPreflop(HandInterface* bR, int id, int qP, int dP, int sB) : PreflopInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), bigBlindPosition(0), smallBlind(sB), highestSet(2*sB), preflopFirstRound(1), playersTurn(0)
@@ -86,7 +86,6 @@ void LocalPreflop::preflopRun() {
myHand->getGuiInterface()->refreshAction(); myHand->getGuiInterface()->refreshAction();
myHand->switchRounds(); myHand->switchRounds();
} }
else { else {
// Preflop ist wirklich dran // Preflop ist wirklich dran
+3 -6
View File
@@ -20,18 +20,15 @@
#ifndef LOCALPREFLOP_H #ifndef LOCALPREFLOP_H
#define LOCALPREFLOP_H #define LOCALPREFLOP_H
#include "preflopinterface.h" #include <preflopinterface.h>
#include <iostream>
class HandInterface; class HandInterface;
class LocalPreflop : public PreflopInterface{ class LocalPreflop : public PreflopInterface{
public: public:
LocalPreflop(HandInterface*, int, int, int, int); LocalPreflop(HandInterface*, int, int, int, int);
~LocalPreflop();
~LocalPreflop();
void setPlayersTurn(const int& theValue) { playersTurn = theValue; } void setPlayersTurn(const int& theValue) { playersTurn = theValue; }
+2 -1
View File
@@ -18,8 +18,10 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "localriver.h" #include "localriver.h"
#include <handinterface.h>
#include <game_defs.h> #include <game_defs.h>
#include <iostream>
using namespace std; using namespace std;
@@ -84,7 +86,6 @@ void LocalRiver::riverRun() {
myHand->getGuiInterface()->refreshAction(); myHand->getGuiInterface()->refreshAction();
myHand->switchRounds(); myHand->switchRounds();
} }
else { else {
// River ist wirklich dran // River ist wirklich dran
+4 -7
View File
@@ -20,18 +20,15 @@
#ifndef LOCALRIVER_H #ifndef LOCALRIVER_H
#define LOCALRIVER_H #define LOCALRIVER_H
#include "riverinterface.h" #include <riverinterface.h>
#include <iostream> class HandInterface;
#include "handinterface.h"
class LocalRiver : public RiverInterface{ class LocalRiver : public RiverInterface{
public: public:
LocalRiver(HandInterface*, int, int, int, int); LocalRiver(HandInterface*, int, int, int, int);
~LocalRiver();
~LocalRiver();
void setPlayersTurn(const int& theValue) { playersTurn = theValue; } void setPlayersTurn(const int& theValue) { playersTurn = theValue; }
int getPlayersTurn() const { return playersTurn; } int getPlayersTurn() const { return playersTurn; }
+2 -2
View File
@@ -18,10 +18,11 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "localturn.h" #include "localturn.h"
#include <handinterface.h>
#include <game_defs.h> #include <game_defs.h>
using namespace std; //using namespace std;
LocalTurn::LocalTurn(HandInterface* bR, int id, int qP, int dP, int sB) : TurnInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstTurnRun(1), firstTurnRound(1), playersTurn(dP) LocalTurn::LocalTurn(HandInterface* bR, int id, int qP, int dP, int sB) : TurnInterface(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstTurnRun(1), firstTurnRound(1), playersTurn(dP)
@@ -85,7 +86,6 @@ void LocalTurn::turnRun() {
myHand->getGuiInterface()->refreshAction(); myHand->getGuiInterface()->refreshAction();
myHand->switchRounds(); myHand->switchRounds();
} }
else { else {
// Turn ist wirklich dran // Turn ist wirklich dran
+4 -8
View File
@@ -20,18 +20,14 @@
#ifndef LOCALTURN_H #ifndef LOCALTURN_H
#define LOCALTURN_H #define LOCALTURN_H
#include "turninterface.h" #include <turninterface.h>
#include "handinterface.h" class HandInterface;
#include <iostream>
class LocalTurn : public TurnInterface{ class LocalTurn : public TurnInterface{
public: public:
LocalTurn(HandInterface*, int, int, int, int); LocalTurn(HandInterface*, int, int, int, int);
~LocalTurn();
~LocalTurn();
void setPlayersTurn(const int& theValue) { playersTurn = theValue; } void setPlayersTurn(const int& theValue) { playersTurn = theValue; }
int getPlayersTurn() const { return playersTurn; } int getPlayersTurn() const { return playersTurn; }
+3 -7
View File
@@ -20,13 +20,9 @@
#include "game.h" #include "game.h"
#include "gamedata.h" #include "gamedata.h"
#include "enginefactory.h" #include <localenginefactory.h>
#include "localenginefactory.h" #include <guiinterface.h>
#include <tools.h>
#include "guiinterface.h"
#include "boardinterface.h"
#include "playerinterface.h"
#include "handinterface.h"
using namespace std; using namespace std;
-2
View File
@@ -81,8 +81,6 @@ public:
// virtual void postRiverAnimation2()=0; // virtual void postRiverAnimation2()=0;
virtual void flipHolecardsAllIn()=0; virtual void flipHolecardsAllIn()=0;
// virtual void handSwitchRounds() const=0;
//
// virtual void startNewHand() const=0; // virtual void startNewHand() const=0;
virtual void nextRoundCleanGui()=0; virtual void nextRoundCleanGui()=0;
// //
+66 -29
View File
@@ -318,41 +318,24 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
Game &curGame = server.GetGame(); Game &curGame = server.GetGame();
curGame.getCurrentHand()->switchRounds(); curGame.getCurrentHand()->switchRounds();
int playersTurn = 0;
// TODO: no switch needed here if game states are polymorphic // Call main loop - if state changes, call again.
switch(curGame.getCurrentHand()->getActualRound()) { int newRound = curGame.getCurrentHand()->getActualRound();
case 0: { int curRound;
// Preflop starten do
curGame.getCurrentHand()->getPreflop()->preflopRun(); {
playersTurn = curGame.getCurrentHand()->getPreflop()->getPlayersTurn(); curRound = newRound;
} break; GameRun(curGame, curRound);
case 1: { newRound = curGame.getCurrentHand()->getActualRound();
// Flop starten } while (newRound != curRound);
curGame.getCurrentHand()->getFlop()->flopRun();
playersTurn = curGame.getCurrentHand()->getFlop()->getPlayersTurn();
} break;
case 2: {
// Turn starten
curGame.getCurrentHand()->getTurn()->turnRun();
playersTurn = curGame.getCurrentHand()->getTurn()->getPlayersTurn();
} break;
case 3: {
// River starten
curGame.getCurrentHand()->getRiver()->riverRun();
playersTurn = curGame.getCurrentHand()->getRiver()->getPlayersTurn();
} break;
default: {
// TODO
}
}
assert(playersTurn < curGame.getActualQuantityPlayers()); // Retrieve current player.
PlayerInterface *curPlayer = GetCurrentPlayer(curGame);
boost::shared_ptr<NetPacket> notification(new NetPacketPlayersTurn); boost::shared_ptr<NetPacket> notification(new NetPacketPlayersTurn);
NetPacketPlayersTurn::Data playersTurnData; NetPacketPlayersTurn::Data playersTurnData;
playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound(); playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound();
playersTurnData.playerId = curGame.getPlayerArray()[playersTurn]->getMyUniqueID(); playersTurnData.playerId = curPlayer->getMyUniqueID();
static_cast<NetPacketPlayersTurn *>(notification.get())->SetData(playersTurnData); static_cast<NetPacketPlayersTurn *>(notification.get())->SetData(playersTurnData);
server.SendToAllPlayers(notification); server.SendToAllPlayers(notification);
@@ -362,6 +345,60 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
return MSG_NET_GAME_SERVER_ROUND; return MSG_NET_GAME_SERVER_ROUND;
} }
void
ServerRecvStateStartRound::GameRun(Game &curGame, int state)
{
// TODO: no switch needed here if game states are polymorphic
switch(state) {
case 0: {
// Preflop starten
curGame.getCurrentHand()->getPreflop()->preflopRun();
} break;
case 1: {
// Flop starten
curGame.getCurrentHand()->getFlop()->flopRun();
} break;
case 2: {
// Turn starten
curGame.getCurrentHand()->getTurn()->turnRun();
} break;
case 3: {
// River starten
curGame.getCurrentHand()->getRiver()->riverRun();
} break;
default: {
// TODO
}
}
}
PlayerInterface *
ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame)
{
int curPlayerNum = 0;
// TODO: no switch needed here if game states are polymorphic
switch(curGame.getCurrentHand()->getActualRound()) {
case 0: {
curPlayerNum = curGame.getCurrentHand()->getPreflop()->getPlayersTurn();
} break;
case 1: {
curPlayerNum = curGame.getCurrentHand()->getFlop()->getPlayersTurn();
} break;
case 2: {
curPlayerNum = curGame.getCurrentHand()->getTurn()->getPlayersTurn();
} break;
case 3: {
curPlayerNum = curGame.getCurrentHand()->getRiver()->getPlayersTurn();
} break;
default: {
// TODO
}
}
assert(curPlayerNum < curGame.getActualQuantityPlayers());
return curGame.getPlayerArray()[curPlayerNum];
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
ServerRecvStateFinal & ServerRecvStateFinal &
+5
View File
@@ -27,6 +27,8 @@
#define SERVER_INITIAL_STATE ServerRecvStateInit #define SERVER_INITIAL_STATE ServerRecvStateInit
#define SERVER_START_GAME_STATE ServerRecvStateStartGame #define SERVER_START_GAME_STATE ServerRecvStateStartGame
class Game;
class PlayerInterface;
class ServerRecvThread; class ServerRecvThread;
class ServerCallback; class ServerCallback;
@@ -128,6 +130,9 @@ protected:
// Protected constructor - this is a singleton. // Protected constructor - this is a singleton.
ServerRecvStateStartRound(); ServerRecvStateStartRound();
void GameRun(Game &curGame, int state);
PlayerInterface *GetCurrentPlayer(Game &curGame);
}; };
// State: Final. // State: Final.