More shared_ptr in engine to prevent race conditions when accessing client engine from gui. Still incomplete.

This commit is contained in:
lotodore
2011-01-09 14:16:20 +00:00
parent 54bc7aaa8d
commit 3974e7cac5
17 changed files with 95 additions and 94 deletions
+3 -3
View File
@@ -31,10 +31,10 @@ public:
virtual ~EngineFactory();
virtual HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0;
virtual BoardInterface* createBoard(unsigned dp) =0;
virtual boost::shared_ptr<HandInterface> createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0;
virtual boost::shared_ptr<BoardInterface> createBoard(unsigned dp) =0;
virtual boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) =0;
virtual std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB) =0;
virtual std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface *hi, int id, unsigned dP, int sB) =0;
};
#endif
+3 -3
View File
@@ -40,7 +40,7 @@ public:
virtual PlayerListIterator getActivePlayerIt(unsigned) const =0;
virtual PlayerListIterator getRunningPlayerIt(unsigned) const =0;
virtual BoardInterface* getBoard() const =0;
virtual boost::shared_ptr<BoardInterface> getBoard() const =0;
virtual boost::shared_ptr<BeRoInterface> getPreflop() const =0;
virtual boost::shared_ptr<BeRoInterface> getFlop() const =0;
virtual boost::shared_ptr<BeRoInterface> getTurn() const =0;
@@ -75,8 +75,8 @@ public:
virtual void setLastPlayersTurn(int theValue) =0;
virtual int getLastPlayersTurn() const =0;
virtual void setLastActionPlayer( unsigned theValue ) =0;
virtual unsigned getLastActionPlayer() const =0;
virtual void setLastActionPlayer( unsigned theValue ) =0;
virtual unsigned getLastActionPlayer() const =0;
virtual void setCardsShown(bool theValue) =0;
virtual bool getCardsShown() const =0;
+16 -7
View File
@@ -42,18 +42,27 @@ LocalEngineFactory::~LocalEngineFactory()
}
HandInterface*
LocalEngineFactory::createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC)
boost::shared_ptr<HandInterface>
LocalEngineFactory::createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC)
{
return new LocalHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC);
return boost::shared_ptr<HandInterface>(new LocalHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC));
}
BoardInterface* LocalEngineFactory::createBoard(unsigned dp) { return new LocalBoard(dp); }
boost::shared_ptr<BoardInterface>
LocalEngineFactory::createBoard(unsigned dp)
{
return boost::shared_ptr<BoardInterface>(new LocalBoard(dp));
}
boost::shared_ptr<PlayerInterface> LocalEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) { return boost::shared_ptr<PlayerInterface> (new LocalPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB)); }
std::vector<boost::shared_ptr<BeRoInterface> > LocalEngineFactory::createBeRo(HandInterface* hi, int id, unsigned dP, int sB) {
boost::shared_ptr<PlayerInterface>
LocalEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
{
return boost::shared_ptr<PlayerInterface> (new LocalPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB));
}
std::vector<boost::shared_ptr<BeRoInterface> >
LocalEngineFactory::createBeRo(HandInterface *hi, int id, unsigned dP, int sB)
{
std::vector<boost::shared_ptr<BeRoInterface> > myBeRo;
myBeRo.push_back(boost::shared_ptr<BeRoInterface>(new LocalBeRoPreflop(hi, id, dP, sB)));
+4 -4
View File
@@ -37,10 +37,10 @@ public:
LocalEngineFactory(ConfigFile*);
~LocalEngineFactory();
HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC);
BoardInterface* createBoard(unsigned dp);
boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB);
virtual boost::shared_ptr<HandInterface> createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC);
virtual boost::shared_ptr<BoardInterface> createBoard(unsigned dp);
virtual boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
virtual std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface *hi, int id, unsigned dP, int sB);
private:
ConfigFile *myConfig;
+1 -1
View File
@@ -30,7 +30,7 @@
using namespace std;
LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC)
LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC)
: myFactory(f), myGui(g), myBoard(b), myLog(l), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), smallBlindPosition(dP), bigBlindPosition(dP), currentRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(-1), lastActionPlayer(0), allInCondition(false),
cardsShown(false), bettingRoundsPlayed(0)
{
+5 -5
View File
@@ -33,7 +33,7 @@ class Log;
class LocalHand : public HandInterface{
public:
LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface*, BoardInterface*, Log*, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int);
LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface*, boost::shared_ptr<BoardInterface>, Log*, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int);
~LocalHand();
void start();
@@ -46,7 +46,7 @@ public:
PlayerListIterator getActivePlayerIt(unsigned) const;
PlayerListIterator getRunningPlayerIt(unsigned) const;
BoardInterface* getBoard() const { return myBoard; }
boost::shared_ptr<BoardInterface> getBoard() const { return myBoard; }
boost::shared_ptr<BeRoInterface> getPreflop() const { return myBeRo[GAME_STATE_PREFLOP]; }
boost::shared_ptr<BeRoInterface> getFlop() const { return myBeRo[GAME_STATE_FLOP]; }
boost::shared_ptr<BeRoInterface> getTurn() const { return myBeRo[GAME_STATE_TURN]; }
@@ -81,8 +81,8 @@ public:
void setLastPlayersTurn(int theValue) { lastPlayersTurn = theValue; }
int getLastPlayersTurn() const { return lastPlayersTurn; }
void setLastActionPlayer ( unsigned theValue );
unsigned getLastActionPlayer() const { return lastActionPlayer; }
void setLastActionPlayer ( unsigned theValue );
unsigned getLastActionPlayer() const { return lastActionPlayer; }
void setCardsShown(bool theValue) { cardsShown = theValue; }
bool getCardsShown() const { return cardsShown; }
@@ -96,7 +96,7 @@ private:
boost::shared_ptr<EngineFactory> myFactory;
GuiInterface *myGui;
BoardInterface *myBoard;
boost::shared_ptr<BoardInterface> myBoard;
Log *myLog;
PlayerList seatsList; // all player
+3 -3
View File
@@ -37,7 +37,7 @@ public:
~LocalPlayer();
void setHand(HandInterface*);
void setHand(HandInterface *);
int getMyID() const { return myID; }
unsigned getMyUniqueID() const { return myUniqueID; }
@@ -77,8 +77,8 @@ public:
void setMyActiveStatus(bool theValue) { myActiveStatus = theValue; }
bool getMyActiveStatus() const { return myActiveStatus; }
void setMyStayOnTableStatus(bool theValue) { myStayOnTableStatus = theValue; }
bool getMyStayOnTableStatus() const { return myStayOnTableStatus; }
void setMyStayOnTableStatus(bool theValue) { myStayOnTableStatus = theValue; }
bool getMyStayOnTableStatus() const { return myStayOnTableStatus; }
void setMyCards(int* theValue) { int i; for(i=0; i<2; i++) myCards[i] = theValue[i]; }
void getMyCards(int* theValue) const { int i; for(i=0; i<2; i++) theValue[i] = myCards[i]; }
@@ -35,23 +35,27 @@ ClientEngineFactory::~ClientEngineFactory()
}
HandInterface* ClientEngineFactory::createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC)
boost::shared_ptr<HandInterface>
ClientEngineFactory::createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC)
{
return new ClientHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC);
return boost::shared_ptr<HandInterface>(new ClientHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC));
}
BoardInterface* ClientEngineFactory::createBoard(unsigned dp)
boost::shared_ptr<BoardInterface>
ClientEngineFactory::createBoard(unsigned dp)
{
return new ClientBoard(dp);
return boost::shared_ptr<BoardInterface>(new ClientBoard(dp));
}
boost::shared_ptr<PlayerInterface> ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
boost::shared_ptr<PlayerInterface>
ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
{
return boost::shared_ptr<PlayerInterface> (new ClientPlayer(NULL, b, id, uniqueId, type, name, avatar, sC, aS, mB));
return boost::shared_ptr<PlayerInterface>(new ClientPlayer(NULL, b, id, uniqueId, type, name, avatar, sC, aS, mB));
}
std::vector<boost::shared_ptr<BeRoInterface> > ClientEngineFactory::createBeRo(HandInterface* hi, int id, unsigned dP, int sB) {
std::vector<boost::shared_ptr<BeRoInterface> >
ClientEngineFactory::createBeRo(HandInterface *hi, int id, unsigned dP, int sB)
{
std::vector<boost::shared_ptr<BeRoInterface> > myBeRo;
myBeRo.push_back(boost::shared_ptr<BeRoInterface>(new ClientBeRo(hi, id, dP, sB, GAME_STATE_PREFLOP)));
@@ -38,11 +38,10 @@ public:
ClientEngineFactory();
~ClientEngineFactory();
HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC);
BoardInterface* createBoard(unsigned dp);
boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB);
virtual boost::shared_ptr<HandInterface> createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC);
virtual boost::shared_ptr<BoardInterface> createBoard(unsigned dp);
virtual boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
virtual std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface *hi, int id, unsigned dP, int sB);
};
#endif
+2 -2
View File
@@ -21,7 +21,7 @@
using namespace std;
ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC)
ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost::shared_ptr<BoardInterface> b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC)
: myFactory(f), myGui(g), myBoard(b), myLog(l), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), currentRound(0),
smallBlind(sB), startCash(sC), lastPlayersTurn(-1), allInCondition(0),
cardsShown(false), bettingRoundsPlayed(0)
@@ -125,7 +125,7 @@ ClientHand::getRunningPlayerIt(unsigned uniqueId) const
return it;
}
BoardInterface*
boost::shared_ptr<BoardInterface>
ClientHand::getBoard() const
{
return myBoard;
+3 -3
View File
@@ -33,7 +33,7 @@
class ClientHand : public HandInterface
{
public:
ClientHand ( boost::shared_ptr<EngineFactory> f, GuiInterface*, BoardInterface*, Log*, PlayerList, PlayerList, PlayerList , int, int, int, int, int );
ClientHand ( boost::shared_ptr<EngineFactory> f, GuiInterface*, boost::shared_ptr<BoardInterface>, Log*, PlayerList, PlayerList, PlayerList , int, int, int, int, int );
~ClientHand();
void start();
@@ -46,7 +46,7 @@ class ClientHand : public HandInterface
PlayerListIterator getActivePlayerIt(unsigned) const;
PlayerListIterator getRunningPlayerIt(unsigned) const;
BoardInterface* getBoard() const;
boost::shared_ptr<BoardInterface> getBoard() const;
boost::shared_ptr<BeRoInterface> getPreflop() const;
boost::shared_ptr<BeRoInterface> getFlop() const;
boost::shared_ptr<BeRoInterface> getTurn() const;
@@ -98,7 +98,7 @@ class ClientHand : public HandInterface
boost::shared_ptr<EngineFactory> myFactory;
GuiInterface *myGui;
BoardInterface *myBoard;
boost::shared_ptr<BoardInterface> myBoard;
Log *myLog;
PlayerList seatsList;
+1 -1
View File
@@ -35,7 +35,7 @@ public:
ClientPlayer(ConfigFile*, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
~ClientPlayer();
void setHand(HandInterface*);
void setHand(HandInterface *);
int getMyID() const;
unsigned getMyUniqueID() const;
+1 -1
View File
@@ -30,7 +30,7 @@ public:
virtual ~PlayerInterface() =0;
virtual void setHand(HandInterface*) =0;
virtual void setHand(HandInterface *) =0;
virtual int getMyID() const =0;
virtual unsigned getMyUniqueID() const =0;