From 07dc39d10783eb6b052b72fb36176a7b8750ee06 Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 11 Jun 2007 17:48:22 +0000 Subject: [PATCH] Client engine should now be completely thread safe. const int& -> int. Player CardsValue is now returned as copy, not the array itself. --- src/engine/flopinterface.h | 8 +- src/engine/local_engine/localflop.h | 8 +- src/engine/local_engine/localhand.cpp | 9 +- src/engine/local_engine/localplayer.h | 13 +- src/engine/local_engine/localpreflop.h | 4 +- src/engine/local_engine/localriver.h | 10 +- src/engine/local_engine/localturn.h | 8 +- src/engine/network_engine/clientboard.cpp | 56 +++- src/engine/network_engine/clientboard.h | 18 +- src/engine/network_engine/clientflop.cpp | 78 ++++- src/engine/network_engine/clientflop.h | 29 +- src/engine/network_engine/clienthand.cpp | 213 +++++++++++- src/engine/network_engine/clienthand.h | 64 ++-- src/engine/network_engine/clientplayer.cpp | 354 +++++++++++++++++++- src/engine/network_engine/clientplayer.h | 131 +++----- src/engine/network_engine/clientpreflop.cpp | 43 +++ src/engine/network_engine/clientpreflop.h | 20 +- src/engine/network_engine/clientriver.cpp | 90 +++++ src/engine/network_engine/clientriver.h | 29 +- src/engine/network_engine/clientturn.cpp | 77 +++++ src/engine/network_engine/clientturn.h | 24 +- src/engine/playerinterface.h | 5 +- src/engine/preflopinterface.h | 4 +- src/engine/riverinterface.h | 10 +- src/engine/turninterface.h | 8 +- src/game.h | 12 +- src/gui/qt/mainwindow/mainwindowimpl.cpp | 18 +- src/net/common/clientstate.cpp | 4 +- src/net/common/serverrecvstate.cpp | 4 +- src/session.h | 2 +- 30 files changed, 1128 insertions(+), 225 deletions(-) diff --git a/src/engine/flopinterface.h b/src/engine/flopinterface.h index 0a22c87d..f9849d33 100644 --- a/src/engine/flopinterface.h +++ b/src/engine/flopinterface.h @@ -26,19 +26,19 @@ public: virtual ~FlopInterface(); - virtual void setPlayersTurn(const int& theValue) =0; + virtual void setPlayersTurn(int theValue) =0; virtual int getPlayersTurn() const =0; - virtual void setHighestSet(const int& theValue) =0; + virtual void setHighestSet(int theValue) =0; virtual int getHighestSet() const =0; virtual void setFirstFlopRound(bool theValue) =0; virtual bool getFirstFlopRound() const =0; - virtual void setSmallBlindPosition(const int& theValue) =0; + virtual void setSmallBlindPosition(int theValue) =0; virtual int getSmallBlindPosition() const =0; - virtual void setSmallBlind(const int& theValue) =0; + virtual void setSmallBlind(int theValue) =0; virtual int getSmallBlind() const =0; virtual void resetFirstRun() =0; diff --git a/src/engine/local_engine/localflop.h b/src/engine/local_engine/localflop.h index d123afde..cf3f5748 100755 --- a/src/engine/local_engine/localflop.h +++ b/src/engine/local_engine/localflop.h @@ -31,19 +31,19 @@ public: ~LocalFlop(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } + void setPlayersTurn(int theValue) { playersTurn = theValue; } int getPlayersTurn() const { return playersTurn; } - void setHighestSet(const int& theValue) { highestSet = theValue; } + void setHighestSet(int theValue) { highestSet = theValue; } int getHighestSet() const { return highestSet;} void setFirstFlopRound(bool theValue) { firstFlopRound = theValue;} bool getFirstFlopRound() const { return firstFlopRound;} - void setSmallBlindPosition(const int& theValue) { smallBlindPosition = theValue;} + void setSmallBlindPosition(int theValue) { smallBlindPosition = theValue;} int getSmallBlindPosition() const { return smallBlindPosition; } - void setSmallBlind(const int& theValue) { smallBlind = theValue; } + void setSmallBlind(int theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } void resetFirstRun() { firstFlopRun = false; } diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index e88e9d64..4d3ea59c 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -70,16 +70,21 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI myBoard->setMyCards(tempBoardArray); for(i=0; igetMyActiveStatus() != 0) { + + int bestHandPos[5]; + playerArray[i]->getMyBestHandPosition(bestHandPos); + for(j=0; j<2; j++) { tempPlayerArray[j] = cardsArray[2*k+j+5]; tempPlayerAndBoardArray[j] = cardsArray[2*k+j+5]; } playerArray[i]->setMyCards(tempPlayerArray); - playerArray[i]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray,playerArray[i]->getMyBestHandPosition())); + playerArray[i]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray, bestHandPos)); + playerArray[i]->setMyBestHandPosition(bestHandPos); // myBestHandPosition auf Fehler ueberpruefen for(j=0; j<5; j++) { - if((playerArray[i]->getMyBestHandPosition())[j] == -1) { + if (bestHandPos[j] == -1) { cout << "ERROR get myBestHandPosition in localhand.cpp" << endl; } } diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index c87cdf21..a469ae94 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -78,7 +78,7 @@ public: bool getMyActiveStatus() const { return myActiveStatus; } void setMyCards(int* theValue) { int i; for(i=0; i<2; i++) myCards[i] = theValue[i]; } - void getMyCards(int* theValue) { int i; for(i=0; i<2; i++) theValue[i] = myCards[i]; } + void getMyCards(int* theValue) const { int i; for(i=0; i<2; i++) theValue[i] = myCards[i]; } void setMyTurn(bool theValue){ myTurn = theValue;} bool getMyTurn() const{ return myTurn;} @@ -103,7 +103,16 @@ public: void setMyCardsValueInt(int theValue) { myCardsValueInt = theValue;} int getMyCardsValueInt() const { return myCardsValueInt; } - int* getMyBestHandPosition() { return myBestHandPosition; } + void setMyBestHandPosition(int* theValue) + { + for (int i = 0; i < 5; i++) + myBestHandPosition[i] = theValue[i]; + } + void getMyBestHandPosition(int* theValue) const + { + for (int i = 0; i < 5; i++) + theValue[i] = myBestHandPosition[i]; + } void setMyRoundStartCash(int theValue) { myRoundStartCash = theValue;} int getMyRoundStartCash() const { return myRoundStartCash; } diff --git a/src/engine/local_engine/localpreflop.h b/src/engine/local_engine/localpreflop.h index b4fcb618..0f6ae4a5 100755 --- a/src/engine/local_engine/localpreflop.h +++ b/src/engine/local_engine/localpreflop.h @@ -31,10 +31,10 @@ public: ~LocalPreflop(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } + void setPlayersTurn(int theValue) { playersTurn = theValue; } int getPlayersTurn() const { return playersTurn; } - void setHighestSet(const int& theValue) { highestSet = theValue; } + void setHighestSet(int theValue) { highestSet = theValue; } int getHighestSet() const { return highestSet;} void setPreflopFirstRound(bool theValue) { preflopFirstRound = theValue; } diff --git a/src/engine/local_engine/localriver.h b/src/engine/local_engine/localriver.h index 5156c8f0..904968a8 100755 --- a/src/engine/local_engine/localriver.h +++ b/src/engine/local_engine/localriver.h @@ -30,22 +30,22 @@ public: LocalRiver(HandInterface*, int, int, int, int); ~LocalRiver(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } + void setPlayersTurn(int theValue) { playersTurn = theValue; } int getPlayersTurn() const { return playersTurn; } - void setHighestSet(const int& theValue) { highestSet = theValue; } + void setHighestSet(int theValue) { highestSet = theValue; } int getHighestSet() const { return highestSet;} void setFirstRiverRound(bool theValue) { firstRiverRound = theValue;} bool getFirstRiverRound() const { return firstRiverRound;} - void setSmallBlindPosition(const int& theValue) { smallBlindPosition = theValue;} + void setSmallBlindPosition(int theValue) { smallBlindPosition = theValue;} int getSmallBlindPosition() const { return smallBlindPosition; } - void setSmallBlind(const int& theValue) { smallBlind = theValue; } + void setSmallBlind(int theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } - void setHighestCardsValue(const int& theValue) { highestCardsValue = theValue;} + void setHighestCardsValue(int theValue) { highestCardsValue = theValue;} int getHighestCardsValue() const { return highestCardsValue;} void resetFirstRun() { firstRiverRun = false; } diff --git a/src/engine/local_engine/localturn.h b/src/engine/local_engine/localturn.h index 75d6639f..40fe7053 100755 --- a/src/engine/local_engine/localturn.h +++ b/src/engine/local_engine/localturn.h @@ -29,19 +29,19 @@ public: LocalTurn(HandInterface*, int, int, int, int); ~LocalTurn(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } + void setPlayersTurn(int theValue) { playersTurn = theValue; } int getPlayersTurn() const { return playersTurn; } - void setHighestSet(const int& theValue) { highestSet = theValue; } + void setHighestSet(int theValue) { highestSet = theValue; } int getHighestSet() const { return highestSet;} void setFirstTurnRound(bool theValue) { firstTurnRound = theValue;} bool getFirstTurnRound() const { return firstTurnRound;} - void setSmallBlindPosition(const int& theValue) { smallBlindPosition = theValue;} + void setSmallBlindPosition(int theValue) { smallBlindPosition = theValue;} int getSmallBlindPosition() const { return smallBlindPosition; } - void setSmallBlind(const int& theValue) { smallBlind = theValue; } + void setSmallBlind(int theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } void resetFirstRun() { firstTurnRun = false; } diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index 7c9f5822..2fe18827 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -18,7 +18,7 @@ ***************************************************************************/ #include "clientboard.h" -#include "localhand.h" +#include #include using namespace std; @@ -36,26 +36,74 @@ ClientBoard::~ClientBoard() void ClientBoard::setPlayer(PlayerInterface** p) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); playerArray = p; } void ClientBoard::setHand(HandInterface* br) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); actualHand = br; } +void +ClientBoard::setMyCards(int* theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i = 0; i < 5; i++) + myCards[i] = theValue[i]; +} + +void +ClientBoard::getMyCards(int* theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i = 0; i < 5; i++) + theValue[i] = myCards[i]; +} + +int +ClientBoard::getPot() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return pot; +} + +void +ClientBoard::setPot(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + pot = theValue; +} + +int +ClientBoard::getSets() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return sets; +} + +void +ClientBoard::setSets(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + sets = theValue; +} + void ClientBoard::collectSets() { - sets = 0; - int i; - for(i=0; igetMySet(); + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + sets = 0; + for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) + sets += playerArray[i]->getMySet(); } void ClientBoard::collectPot() { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); pot += sets; sets = 0; } diff --git a/src/engine/network_engine/clientboard.h b/src/engine/network_engine/clientboard.h index 89e64d7b..4fd6c24c 100644 --- a/src/engine/network_engine/clientboard.h +++ b/src/engine/network_engine/clientboard.h @@ -20,12 +20,14 @@ #define CLIENTBOARD_H #include +#include class PlayerInterface; class HandInterface; -class ClientBoard : public BoardInterface{ +class ClientBoard : public BoardInterface +{ public: ClientBoard(); ~ClientBoard(); @@ -33,18 +35,20 @@ public: void setPlayer(PlayerInterface**); void setHand(HandInterface*); - void setMyCards(int* theValue) { int i; for(i=0; i<5; i++) myCards[i] = theValue[i]; } - void getMyCards(int* theValue) { int i; for(i=0; i<5; i++) theValue[i] = myCards[i]; } + void setMyCards(int* theValue); + void getMyCards(int* theValue); - int getPot() const { return pot;} - void setPot(int theValue) { pot = theValue;} - int getSets() const { return sets; } - void setSets(int theValue) { sets = theValue; } + int getPot() const; + void setPot(int theValue); + int getSets() const; + void setSets(int theValue); void collectSets(); void collectPot(); private: + mutable boost::recursive_mutex m_syncMutex; + PlayerInterface **playerArray; HandInterface *actualHand; diff --git a/src/engine/network_engine/clientflop.cpp b/src/engine/network_engine/clientflop.cpp index feda7ee5..46a3a16c 100644 --- a/src/engine/network_engine/clientflop.cpp +++ b/src/engine/network_engine/clientflop.cpp @@ -32,6 +32,83 @@ ClientFlop::~ClientFlop() { } +void +ClientFlop::setPlayersTurn(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + playersTurn = theValue; +} + +int +ClientFlop::getPlayersTurn() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return playersTurn; +} + +void +ClientFlop::setHighestSet(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + highestSet = theValue; +} + +int +ClientFlop::getHighestSet() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return highestSet; +} + +void +ClientFlop::setFirstFlopRound(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + firstFlopRound = theValue; +} + +bool +ClientFlop::getFirstFlopRound() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return firstFlopRound; +} + +void +ClientFlop::setSmallBlindPosition(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlindPosition = theValue; +} + +int +ClientFlop::getSmallBlindPosition() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlindPosition; +} + +void +ClientFlop::setSmallBlind(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlind = theValue; +} + +int +ClientFlop::getSmallBlind() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlind; +} + +void +ClientFlop::resetFirstRun() +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + firstFlopRun = false; +} + void ClientFlop::flopRun() { @@ -42,4 +119,3 @@ ClientFlop::nextPlayer2() { } - diff --git a/src/engine/network_engine/clientflop.h b/src/engine/network_engine/clientflop.h index 4de42096..21c7a482 100644 --- a/src/engine/network_engine/clientflop.h +++ b/src/engine/network_engine/clientflop.h @@ -20,36 +20,39 @@ #define CLIENTFLOP_H #include "flopinterface.h" +#include class HandInterface; -class ClientFlop : public FlopInterface{ +class ClientFlop : public FlopInterface +{ public: ClientFlop(HandInterface*, int, int, int, int); ~ClientFlop(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } - int getPlayersTurn() const { return playersTurn; } - - void setHighestSet(const int& theValue) { highestSet = theValue; } - int getHighestSet() const { return highestSet;} + void setPlayersTurn(int theValue); + int getPlayersTurn() const; - void setFirstFlopRound(bool theValue) { firstFlopRound = theValue;} - bool getFirstFlopRound() const { return firstFlopRound;} + void setHighestSet(int theValue); + int getHighestSet() const; - void setSmallBlindPosition(const int& theValue) { smallBlindPosition = theValue;} - int getSmallBlindPosition() const { return smallBlindPosition; } + void setFirstFlopRound(bool theValue); + bool getFirstFlopRound() const; - void setSmallBlind(const int& theValue) { smallBlind = theValue; } - int getSmallBlind() const { return smallBlind; } + void setSmallBlindPosition(int theValue); + int getSmallBlindPosition() const; - void resetFirstRun() { firstFlopRun = false; } + void setSmallBlind(int theValue); + int getSmallBlind() const; + + void resetFirstRun(); void flopRun(); void nextPlayer2(); private: + mutable boost::recursive_mutex m_syncMutex; HandInterface *myHand; diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index c34ac14e..421842fc 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -74,9 +74,220 @@ ClientHand::start() { } +PlayerInterface** +ClientHand::getPlayerArray() const +{ + return playerArray; +} + +BoardInterface* +ClientHand::getBoard() const +{ + return myBoard; +} + +PreflopInterface* +ClientHand::getPreflop() const +{ + return myPreflop; +} + +FlopInterface* +ClientHand::getFlop() const +{ + return myFlop; +} + +TurnInterface* +ClientHand::getTurn() const +{ + return myTurn; +} + +RiverInterface* +ClientHand::getRiver() const +{ + return myRiver; +} + +GuiInterface* +ClientHand::getGuiInterface() const +{ + return myGui; +} + +void +ClientHand::setMyID(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myID = theValue; +} + +int +ClientHand::getMyID() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myID; +} + +void +ClientHand::setActualQuantityPlayers(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + actualQuantityPlayers = theValue; +} + +int +ClientHand::getActualQuantityPlayers() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return actualQuantityPlayers; +} + +void +ClientHand::setStartQuantityPlayers(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + startQuantityPlayers = theValue; +} + +int +ClientHand::getStartQuantityPlayers() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return startQuantityPlayers; +} + +void +ClientHand::setActualRound(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + actualRound = theValue; +} + +int +ClientHand::getActualRound() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return actualRound; +} + +void +ClientHand::setDealerPosition(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + dealerPosition = theValue; +} + +int +ClientHand::getDealerPosition() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return dealerPosition; +} + +void +ClientHand::setSmallBlind(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlind = theValue; +} + +int +ClientHand::getSmallBlind() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlind; +} + +void +ClientHand::setAllInCondition(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + allInCondition = theValue; +} + +bool +ClientHand::getAllInCondition() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return allInCondition; +} + +void +ClientHand::setStartCash(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + startCash = theValue; +} + +int +ClientHand::getStartCash() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return startCash; +} + +void +ClientHand::setActivePlayersCounter(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + activePlayersCounter = theValue; +} + +int +ClientHand::getActivePlayersCounter() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return activePlayersCounter; +} + +void +ClientHand::setBettingRoundsPlayed(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + bettingRoundsPlayed = theValue; +} + +int +ClientHand::getBettingRoundsPlayed() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return bettingRoundsPlayed; +} + +void +ClientHand::setLastPlayersTurn(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + lastPlayersTurn = theValue; +} + +int +ClientHand::getLastPlayersTurn() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return lastPlayersTurn; +} + +void +ClientHand::setCardsShown(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + cardsShown = theValue; +} + +bool +ClientHand::getCardsShown() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return cardsShown; +} + void ClientHand::switchRounds() { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); // update active players counter. activePlayersCounter = 0; for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) { @@ -84,5 +295,3 @@ ClientHand::switchRounds() } } - - diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index 2edbbcbe..7e89acdd 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -29,6 +29,7 @@ #include #include +#include class ClientHand : public HandInterface { @@ -38,54 +39,55 @@ public: void start(); - PlayerInterface** getPlayerArray() const { return playerArray; } - BoardInterface* getBoard() const { return myBoard; } - PreflopInterface* getPreflop() const { return myPreflop; } - FlopInterface* getFlop() const { return myFlop; } - TurnInterface* getTurn() const { return myTurn; } - RiverInterface* getRiver() const { return myRiver; } - GuiInterface* getGuiInterface() const { return myGui; } + PlayerInterface** getPlayerArray() const; + BoardInterface* getBoard() const; + PreflopInterface* getPreflop() const; + FlopInterface* getFlop() const; + TurnInterface* getTurn() const; + RiverInterface* getRiver() const; + GuiInterface* getGuiInterface() const; - void setMyID(int theValue) { myID = theValue; } - int getMyID() const { return myID; } + void setMyID(int theValue); + int getMyID() const; - void setActualQuantityPlayers(int theValue) { actualQuantityPlayers = theValue; } - int getActualQuantityPlayers() const { return actualQuantityPlayers; } + void setActualQuantityPlayers(int theValue); + int getActualQuantityPlayers() const; - void setStartQuantityPlayers(int theValue) { startQuantityPlayers = theValue; } - int getStartQuantityPlayers() const { return startQuantityPlayers; } + void setStartQuantityPlayers(int theValue); + int getStartQuantityPlayers() const; - void setActualRound(int theValue) { actualRound = theValue; } - int getActualRound() const { return actualRound; } + void setActualRound(int theValue); + int getActualRound() const; - void setDealerPosition(int theValue) { dealerPosition = theValue; } - int getDealerPosition() const { return dealerPosition; } + void setDealerPosition(int theValue); + int getDealerPosition() const; - void setSmallBlind(int theValue) { smallBlind = theValue; } - int getSmallBlind() const { return smallBlind; } + void setSmallBlind(int theValue); + int getSmallBlind() const; - void setAllInCondition(bool theValue) { allInCondition = theValue; } - bool getAllInCondition() const { return allInCondition; } + void setAllInCondition(bool theValue); + bool getAllInCondition() const; - void setStartCash(int theValue) { startCash = theValue; } - int getStartCash() const { return startCash; } + void setStartCash(int theValue); + int getStartCash() const; - void setActivePlayersCounter(int theValue) { activePlayersCounter = theValue; } - int getActivePlayersCounter() const { return activePlayersCounter; } + void setActivePlayersCounter(int theValue); + int getActivePlayersCounter() const; - void setBettingRoundsPlayed(int theValue) { bettingRoundsPlayed = theValue; } - int getBettingRoundsPlayed() const { return bettingRoundsPlayed; } + void setBettingRoundsPlayed(int theValue); + int getBettingRoundsPlayed() const; - void setLastPlayersTurn(int theValue) { lastPlayersTurn = theValue; } - int getLastPlayersTurn() const { return lastPlayersTurn; } + void setLastPlayersTurn(int theValue); + int getLastPlayersTurn() const; - void setCardsShown(bool theValue) { cardsShown = theValue; } - bool getCardsShown() const { return cardsShown; } + void setCardsShown(bool theValue); + bool getCardsShown() const; void switchRounds(); private: + mutable boost::recursive_mutex m_syncMutex; boost::shared_ptr myFactory; GuiInterface *myGui; diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index e1400a70..572c4304 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -17,7 +17,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "clientplayer.h" -#include "handinterface.h" +#include using namespace std; @@ -36,9 +36,359 @@ ClientPlayer::~ClientPlayer() void ClientPlayer::setHand(HandInterface* br) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); actualHand = br; } +int +ClientPlayer::getMyID() const +{ + return myID; +} + +unsigned +ClientPlayer::getMyUniqueID() const +{ + return myUniqueID; +} + +PlayerType +ClientPlayer::getMyType() const +{ + return myType; +} + +void +ClientPlayer::setMyDude(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myDude = theValue; +} + +int +ClientPlayer::getMyDude() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myDude; +} + +void +ClientPlayer::setMyDude4(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myDude4 = theValue; +} + +int +ClientPlayer::getMyDude4() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myDude4; +} + +void +ClientPlayer::setMyName(const std::string& theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myName = theValue; +} + +std::string +ClientPlayer::getMyName() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myName; +} + +void +ClientPlayer::setMyAvatar(const std::string& theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myAvatar = theValue; +} + +std::string +ClientPlayer::getMyAvatar() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myAvatar; +} + +void +ClientPlayer::setMyCash(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myCash = theValue; +} + +int +ClientPlayer::getMyCash() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myCash; +} + +void +ClientPlayer::setMySet(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myLastRelativeSet = theValue; +} + +void +ClientPlayer::setMySetAbsolute(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + mySet = theValue; +} + +void +ClientPlayer::setMySetNull() +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + mySet = 0; + myLastRelativeSet = 0; +} + +int +ClientPlayer::getMySet() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return mySet; +} + +int +ClientPlayer::getMyLastRelativeSet() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myLastRelativeSet; +} + +void +ClientPlayer::setMyAction(int theValue, bool blind) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myAction = theValue; +} + +int +ClientPlayer::getMyAction() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myAction; +} + +void +ClientPlayer::setMyButton(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myButton = theValue; +} + +int +ClientPlayer::getMyButton() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myButton; +} + +void +ClientPlayer::setMyActiveStatus(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myActiveStatus = theValue; +} + +bool +ClientPlayer::getMyActiveStatus() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myActiveStatus; +} + +void +ClientPlayer::setMyCards(int* theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i = 0; i < 2; i++) + myCards[i] = theValue[i]; +} + +void +ClientPlayer::getMyCards(int* theValue) const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i = 0; i < 2; i++) + theValue[i] = myCards[i]; +} + +void +ClientPlayer::setMyTurn(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myTurn = theValue; +} + +bool +ClientPlayer::getMyTurn() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myTurn; +} + +void +ClientPlayer::setMyCardsFlip(bool theValue, int state) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myCardsFlip = theValue; + // log flipping cards + if (myCardsFlip) { + switch(state) { + case 1: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); + break; + case 2: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); + break; + case 3: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); + break; + default: ; + } + } +} + +bool +ClientPlayer::getMyCardsFlip() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myCardsFlip; +} + +void +ClientPlayer::setMyCardsValueInt(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myCardsValueInt = theValue; +} + +int +ClientPlayer::getMyCardsValueInt() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myCardsValueInt; +} + +void +ClientPlayer::setMyBestHandPosition(int* theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i = 0; i < 5; i++) + myBestHandPosition[i] = theValue[i]; +} + +void +ClientPlayer::getMyBestHandPosition(int* theValue) const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i = 0; i < 5; i++) + theValue[i] = myBestHandPosition[i]; +} + +void +ClientPlayer::setMyRoundStartCash(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myRoundStartCash = theValue; +} + +int +ClientPlayer::getMyRoundStartCash() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myRoundStartCash; +} + +void +ClientPlayer::setMyAverageSets(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myAverageSets[0] = myAverageSets[1]; + myAverageSets[1] = myAverageSets[2]; + myAverageSets[2] = myAverageSets[3]; + myAverageSets[3] = theValue; +} + +int +ClientPlayer::getMyAverageSets() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return (myAverageSets[0]+myAverageSets[1]+myAverageSets[2]+myAverageSets[3])/4; +} + +void +ClientPlayer::setMyAggressive(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + for (int i=0; i<6; i++) + { + myAggressive[i] = myAggressive[i+1]; + } + myAggressive[6] = theValue; +} + +int +ClientPlayer::getMyAggressive() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + int sum = 0; + for (int i=0; i<7; i++) + { + sum += myAggressive[i]; + } + return sum; +} + +void +ClientPlayer::setSBluff(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + sBluff = theValue; +} + +int +ClientPlayer::getSBluff() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return sBluff; +} + +void +ClientPlayer::setSBluffStatus(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + sBluffStatus = theValue; +} + +bool +ClientPlayer::getSBluffStatus() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return sBluffStatus; +} + +void +ClientPlayer::setMyWinnerState(bool theValue, int pot) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myWinnerState = theValue; + if(theValue) + actualHand->getGuiInterface()->logPlayerWinsMsg(myID, pot); +} + +bool +ClientPlayer::getMyWinnerState() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return myWinnerState; +} void ClientPlayer::action() @@ -123,11 +473,13 @@ ClientPlayer::riverEngine3() void ClientPlayer::setNetSessionData(boost::shared_ptr session) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); myNetSessionData = session; } boost::shared_ptr ClientPlayer::getNetSessionData() { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return myNetSessionData; } diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index 5150f784..71563767 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -22,9 +22,9 @@ #include #include +#include #include - class CardsValue; class ConfigFile; class HandInterface; @@ -37,100 +37,72 @@ public: void setHand(HandInterface*); - int getMyID() const { return myID; } - unsigned getMyUniqueID() const { return myUniqueID; } - PlayerType getMyType() const { return myType; } + int getMyID() const; + unsigned getMyUniqueID() const; + PlayerType getMyType() const; - void setMyDude(int theValue) { myDude = theValue; } - int getMyDude() const { return myDude; } + void setMyDude(int theValue); + int getMyDude() const; - void setMyDude4(int theValue) { myDude4 = theValue; } - int getMyDude4() const { return myDude4; } + void setMyDude4(int theValue); + int getMyDude4() const; - void setMyName(const std::string& theValue) { myName = theValue; } - std::string getMyName() const { return myName; } + void setMyName(const std::string& theValue); + std::string getMyName() const; - void setMyAvatar(const std::string& theValue) { myAvatar = theValue; } - std::string getMyAvatar() const { return myAvatar; } + void setMyAvatar(const std::string& theValue); + std::string getMyAvatar() const; - void setMyCash(int theValue) { myCash = theValue; } - int getMyCash() const { return myCash; } + void setMyCash(int theValue); + int getMyCash() const; - void setMySet(int theValue) { myLastRelativeSet = theValue; } - void setMySetAbsolute(int theValue) { mySet = theValue; } - void setMySetNull() { mySet = 0; myLastRelativeSet = 0; } - int getMySet() const { return mySet;} - int getMyLastRelativeSet() const { return myLastRelativeSet; } + void setMySet(int theValue); + void setMySetAbsolute(int theValue); + void setMySetNull(); + int getMySet() const; + int getMyLastRelativeSet() const; - void setMyAction(int theValue, bool blind) { myAction = theValue; } - int getMyAction() const { return myAction; } + void setMyAction(int theValue, bool blind); + int getMyAction() const; - void setMyButton(int theValue) { myButton = theValue; } - int getMyButton() const { return myButton; } + void setMyButton(int theValue); + int getMyButton() const; - void setMyActiveStatus(bool theValue) { myActiveStatus = theValue; } - bool getMyActiveStatus() const { return myActiveStatus; } + void setMyActiveStatus(bool theValue); + bool getMyActiveStatus() const; - void setMyCards(int* theValue) { int i; for(i=0; i<2; i++) myCards[i] = theValue[i]; } - void getMyCards(int* theValue) { int i; for(i=0; i<2; i++) theValue[i] = myCards[i]; } + void setMyCards(int* theValue); + void getMyCards(int* theValue) const; - void setMyTurn(bool theValue){ myTurn = theValue;} - bool getMyTurn() const{ return myTurn;} + void setMyTurn(bool theValue); + bool getMyTurn() const; - void setMyCardsFlip(bool theValue, int state){ - myCardsFlip = theValue; - // log flipping cards - if(myCardsFlip) { - switch(state) { - case 1: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); - break; - case 2: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); - break; - case 3: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); - break; - default: ; - } - } - } - bool getMyCardsFlip() const{ return myCardsFlip;} + void setMyCardsFlip(bool theValue, int state); + bool getMyCardsFlip() const; - void setMyCardsValueInt(int theValue) { myCardsValueInt = theValue;} - int getMyCardsValueInt() const { return myCardsValueInt; } + void setMyCardsValueInt(int theValue); + int getMyCardsValueInt() const; - int* getMyBestHandPosition() { return myBestHandPosition; } + void setMyBestHandPosition(int* theValue); + void getMyBestHandPosition(int* theValue) const; - void setMyRoundStartCash(int theValue) { myRoundStartCash = theValue;} - int getMyRoundStartCash() const { return myRoundStartCash; } + void setMyRoundStartCash(int theValue); + int getMyRoundStartCash() const; - void setMyAverageSets(int theValue) { myAverageSets[0] = myAverageSets[1]; myAverageSets[1] = myAverageSets[2]; myAverageSets[2] = myAverageSets[3]; myAverageSets[3] = theValue; } - int getMyAverageSets() const { return (myAverageSets[0]+myAverageSets[1]+myAverageSets[2]+myAverageSets[3])/4; } - - void setMyAggressive(bool theValue) { - int i; - for(i=0; i<6; i++) { - myAggressive[i] = myAggressive[i+1]; - } - myAggressive[6] = theValue; - } - int getMyAggressive() const { - int i, sum = 0; - for(i=0; i<7; i++) { - sum += myAggressive[i]; - } - return sum; - } + void setMyAverageSets(int theValue); + int getMyAverageSets() const; - void setSBluff ( int theValue ) { sBluff = theValue; } - int getSBluff() const { return sBluff; } + void setMyAggressive(bool theValue); + int getMyAggressive() const; - void setSBluffStatus ( bool theValue ) { sBluffStatus = theValue; } - bool getSBluffStatus() const { return sBluffStatus; } + void setSBluff (int theValue); + int getSBluff() const; - void setMyWinnerState ( bool theValue, int pot ) { - myWinnerState = theValue; - if(theValue) actualHand->getGuiInterface()->logPlayerWinsMsg(myID, pot); - } - bool getMyWinnerState() const { return myWinnerState;} + void setSBluffStatus (bool theValue); + bool getSBluffStatus() const; + + void setMyWinnerState (bool theValue, int pot); + bool getMyWinnerState() const; void action(); @@ -156,6 +128,7 @@ public: boost::shared_ptr getNetSessionData(); private: + mutable boost::recursive_mutex m_syncMutex; ConfigFile *myConfig; HandInterface *actualHand; @@ -164,9 +137,9 @@ private: CardsValue *myCardsValue; // Konstanten - int myID; - unsigned myUniqueID; - PlayerType myType; + const int myID; + const unsigned myUniqueID; + const PlayerType myType; std::string myName; std::string myAvatar; int myDude; diff --git a/src/engine/network_engine/clientpreflop.cpp b/src/engine/network_engine/clientpreflop.cpp index 737d9984..4b30524d 100644 --- a/src/engine/network_engine/clientpreflop.cpp +++ b/src/engine/network_engine/clientpreflop.cpp @@ -34,6 +34,48 @@ ClientPreflop::~ClientPreflop() { } +void +ClientPreflop::setPlayersTurn(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + playersTurn = theValue; +} + +int +ClientPreflop::getPlayersTurn() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return playersTurn; +} + +void +ClientPreflop::setHighestSet(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + highestSet = theValue; +} + +int +ClientPreflop::getHighestSet() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return highestSet; +} + +void +ClientPreflop::setPreflopFirstRound(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + preflopFirstRound = theValue; +} + +bool +ClientPreflop::setPreflopFirstRound() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return preflopFirstRound; +} + void ClientPreflop::preflopRun() { @@ -43,3 +85,4 @@ void ClientPreflop::nextPlayer2() { } + diff --git a/src/engine/network_engine/clientpreflop.h b/src/engine/network_engine/clientpreflop.h index 21c33326..6aab3372 100644 --- a/src/engine/network_engine/clientpreflop.h +++ b/src/engine/network_engine/clientpreflop.h @@ -20,6 +20,7 @@ #define CLIENTPREFLOP_H #include +#include class HandInterface; @@ -29,26 +30,25 @@ public: ClientPreflop(HandInterface*, int, int, int, int); ~ClientPreflop(); - - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } - int getPlayersTurn() const { return playersTurn; } + void setPlayersTurn(int theValue); + int getPlayersTurn() const; - void setHighestSet(const int& theValue) { highestSet = theValue; } - int getHighestSet() const { return highestSet;} + void setHighestSet(int theValue); + int getHighestSet() const; - void setPreflopFirstRound(bool theValue) { preflopFirstRound = theValue; } - bool setPreflopFirstRound() const { return preflopFirstRound; } + void setPreflopFirstRound(bool theValue); + bool setPreflopFirstRound() const; void preflopRun(); void nextPlayer2(); - - private: + mutable boost::recursive_mutex m_syncMutex; + HandInterface *myHand; int myID; - int actualQuantityPlayers; + int actualQuantityPlayers; int dealerPosition; int bigBlindPosition; diff --git a/src/engine/network_engine/clientriver.cpp b/src/engine/network_engine/clientriver.cpp index d7dae696..a910f906 100644 --- a/src/engine/network_engine/clientriver.cpp +++ b/src/engine/network_engine/clientriver.cpp @@ -31,6 +31,96 @@ ClientRiver::~ClientRiver() { } +void +ClientRiver::setPlayersTurn(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + playersTurn = theValue; +} + +int +ClientRiver::getPlayersTurn() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return playersTurn; +} + +void +ClientRiver::setHighestSet(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + highestSet = theValue; +} + +int +ClientRiver::getHighestSet() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return highestSet; +} + +void +ClientRiver::setFirstRiverRound(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + firstRiverRound = theValue; +} + +bool +ClientRiver::getFirstRiverRound() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return firstRiverRound; +} + +void +ClientRiver::setSmallBlindPosition(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlindPosition = theValue; +} + +int +ClientRiver::getSmallBlindPosition() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlindPosition; +} + +void +ClientRiver::setSmallBlind(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlind = theValue; +} + +int +ClientRiver::getSmallBlind() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlind; +} + +void +ClientRiver::setHighestCardsValue(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + highestCardsValue = theValue; +} + +int +ClientRiver::getHighestCardsValue() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return highestCardsValue; +} + +void +ClientRiver::resetFirstRun() +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + firstRiverRun = false; +} void ClientRiver::riverRun() diff --git a/src/engine/network_engine/clientriver.h b/src/engine/network_engine/clientriver.h index 7ea22d42..15c2001a 100644 --- a/src/engine/network_engine/clientriver.h +++ b/src/engine/network_engine/clientriver.h @@ -20,6 +20,7 @@ #define CLIENTRIVER_H #include +#include class HandInterface; @@ -29,25 +30,25 @@ public: ClientRiver(HandInterface*, int, int, int, int); ~ClientRiver(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } - int getPlayersTurn() const { return playersTurn; } + void setPlayersTurn(int theValue); + int getPlayersTurn() const; - void setHighestSet(const int& theValue) { highestSet = theValue; } - int getHighestSet() const { return highestSet;} + void setHighestSet(int theValue); + int getHighestSet() const; - void setFirstRiverRound(bool theValue) { firstRiverRound = theValue;} - bool getFirstRiverRound() const { return firstRiverRound;} + void setFirstRiverRound(bool theValue); + bool getFirstRiverRound() const; - void setSmallBlindPosition(const int& theValue) { smallBlindPosition = theValue;} - int getSmallBlindPosition() const { return smallBlindPosition; } + void setSmallBlindPosition(int theValue); + int getSmallBlindPosition() const; - void setSmallBlind(const int& theValue) { smallBlind = theValue; } - int getSmallBlind() const { return smallBlind; } + void setSmallBlind(int theValue); + int getSmallBlind() const; - void setHighestCardsValue(const int& theValue) { highestCardsValue = theValue;} - int getHighestCardsValue() const { return highestCardsValue;} + void setHighestCardsValue(int theValue); + int getHighestCardsValue() const; - void resetFirstRun() { firstRiverRun = false; } + void resetFirstRun(); void riverRun(); void postRiverRun(); @@ -55,6 +56,7 @@ public: void distributePot(); private: + mutable boost::recursive_mutex m_syncMutex; HandInterface *myHand; @@ -75,3 +77,4 @@ private: }; #endif + diff --git a/src/engine/network_engine/clientturn.cpp b/src/engine/network_engine/clientturn.cpp index ce03158d..353acaf4 100644 --- a/src/engine/network_engine/clientturn.cpp +++ b/src/engine/network_engine/clientturn.cpp @@ -31,6 +31,83 @@ ClientTurn::~ClientTurn() { } +void +ClientTurn::setPlayersTurn(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + playersTurn = theValue; +} + +int +ClientTurn::getPlayersTurn() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return playersTurn; +} + +void +ClientTurn::setHighestSet(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + highestSet = theValue; +} + +int +ClientTurn::getHighestSet() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return highestSet; +} + +void +ClientTurn::setFirstTurnRound(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + firstTurnRound = theValue; +} + +bool +ClientTurn::getFirstTurnRound() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return firstTurnRound; +} + +void +ClientTurn::setSmallBlindPosition(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlindPosition = theValue; +} + +int +ClientTurn::getSmallBlindPosition() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlindPosition; +} + +void +ClientTurn::setSmallBlind(int theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + smallBlind = theValue; +} + +int +ClientTurn::getSmallBlind() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return smallBlind; +} + +void +ClientTurn::resetFirstRun() +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + firstTurnRun = false; +} + void ClientTurn::turnRun() { diff --git a/src/engine/network_engine/clientturn.h b/src/engine/network_engine/clientturn.h index d8ae48cd..71815427 100644 --- a/src/engine/network_engine/clientturn.h +++ b/src/engine/network_engine/clientturn.h @@ -20,6 +20,7 @@ #define CLIENTTURN_H #include +#include class HandInterface; @@ -28,27 +29,28 @@ public: ClientTurn(HandInterface*, int, int, int, int); ~ClientTurn(); - void setPlayersTurn(const int& theValue) { playersTurn = theValue; } - int getPlayersTurn() const { return playersTurn; } + void setPlayersTurn(int theValue); + int getPlayersTurn() const; - void setHighestSet(const int& theValue) { highestSet = theValue; } - int getHighestSet() const { return highestSet;} + void setHighestSet(int theValue); + int getHighestSet() const; - void setFirstTurnRound(bool theValue) { firstTurnRound = theValue;} - bool getFirstTurnRound() const { return firstTurnRound;} + void setFirstTurnRound(bool theValue); + bool getFirstTurnRound() const; - void setSmallBlindPosition(const int& theValue) { smallBlindPosition = theValue;} - int getSmallBlindPosition() const { return smallBlindPosition; } + void setSmallBlindPosition(int theValue); + int getSmallBlindPosition() const; - void setSmallBlind(const int& theValue) { smallBlind = theValue; } - int getSmallBlind() const { return smallBlind; } + void setSmallBlind(int theValue); + int getSmallBlind() const; - void resetFirstRun() { firstTurnRun = false; } + void resetFirstRun(); void turnRun(); void nextPlayer2(); private: + mutable boost::recursive_mutex m_syncMutex; HandInterface *myHand; diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index c63fab94..c2a6e6da 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -69,7 +69,7 @@ public: virtual bool getMyActiveStatus() const =0; virtual void setMyCards(int* theValue) =0; - virtual void getMyCards(int* theValue) =0; + virtual void getMyCards(int* theValue) const =0; virtual void setMyTurn(bool theValue) =0; virtual bool getMyTurn() const =0; @@ -80,7 +80,8 @@ public: virtual void setMyCardsValueInt(int theValue) =0; virtual int getMyCardsValueInt() const =0; - virtual int* getMyBestHandPosition() =0; + virtual void setMyBestHandPosition(int* theValue) =0; + virtual void getMyBestHandPosition(int* theValue) const =0; virtual void setMyRoundStartCash(int theValue) =0; virtual int getMyRoundStartCash() const =0; diff --git a/src/engine/preflopinterface.h b/src/engine/preflopinterface.h index 809258f8..0b87553e 100644 --- a/src/engine/preflopinterface.h +++ b/src/engine/preflopinterface.h @@ -25,10 +25,10 @@ public: virtual ~PreflopInterface(); - virtual void setPlayersTurn(const int& theValue) =0; + virtual void setPlayersTurn(int theValue) =0; virtual int getPlayersTurn() const =0; - virtual void setHighestSet(const int& theValue) =0; + virtual void setHighestSet(int theValue) =0; virtual int getHighestSet() const =0; virtual void setPreflopFirstRound(bool theValue) =0; diff --git a/src/engine/riverinterface.h b/src/engine/riverinterface.h index bd033edc..7dc7342d 100644 --- a/src/engine/riverinterface.h +++ b/src/engine/riverinterface.h @@ -25,22 +25,22 @@ public: virtual ~RiverInterface(); - virtual void setPlayersTurn(const int& theValue) =0; + virtual void setPlayersTurn(int theValue) =0; virtual int getPlayersTurn() const =0; - virtual void setHighestSet(const int& theValue) =0; + virtual void setHighestSet(int theValue) =0; virtual int getHighestSet() const =0; virtual void setFirstRiverRound(bool theValue) =0; virtual bool getFirstRiverRound() const =0; - virtual void setSmallBlindPosition(const int& theValue) =0; + virtual void setSmallBlindPosition(int theValue) =0; virtual int getSmallBlindPosition() const =0; - virtual void setSmallBlind(const int& theValue) =0; + virtual void setSmallBlind(int theValue) =0; virtual int getSmallBlind() const =0; - virtual void setHighestCardsValue(const int& theValue) =0; + virtual void setHighestCardsValue(int theValue) =0; virtual int getHighestCardsValue() const =0; virtual void resetFirstRun() =0; diff --git a/src/engine/turninterface.h b/src/engine/turninterface.h index 52477f34..68538a6c 100644 --- a/src/engine/turninterface.h +++ b/src/engine/turninterface.h @@ -25,19 +25,19 @@ class TurnInterface{ public: virtual ~TurnInterface(); - virtual void setPlayersTurn(const int& theValue) =0; + virtual void setPlayersTurn(int theValue) =0; virtual int getPlayersTurn() const =0; - virtual void setHighestSet(const int& theValue) =0; + virtual void setHighestSet(int theValue) =0; virtual int getHighestSet() const=0; virtual void setFirstTurnRound(bool theValue) =0; virtual bool getFirstTurnRound() const =0; - virtual void setSmallBlindPosition(const int& theValue) =0; + virtual void setSmallBlindPosition(int theValue) =0; virtual int getSmallBlindPosition() const =0; - virtual void setSmallBlind(const int& theValue) =0; + virtual void setSmallBlind(int theValue) =0; virtual int getSmallBlind() const =0; virtual void resetFirstRun() =0; diff --git a/src/game.h b/src/game.h index 0274b7ef..9a21cbd4 100755 --- a/src/game.h +++ b/src/game.h @@ -52,25 +52,25 @@ public: PlayerInterface** getPlayerArray() {return playerArray;} //Zufgriff Startvariablen - void setStartQuantityPlayers(const int& theValue) { startQuantityPlayers = theValue; } + void setStartQuantityPlayers(int theValue) { startQuantityPlayers = theValue; } int getStartQuantityPlayers() const { return startQuantityPlayers; } - void setStartSmallBlind(const int& theValue) { startSmallBlind = theValue; } + void setStartSmallBlind(int theValue) { startSmallBlind = theValue; } int getStartSmallBlind() const { return startSmallBlind; } - void setStartCash(const int& theValue) { startCash = theValue; } + void setStartCash(int theValue) { startCash = theValue; } int getStartCash() const { return startCash; } int getMyGameID() const { return myGameID; } //Zufgriff Laufvariablen - void setActualQuantityPlayers(const int& theValue) { actualQuantityPlayers = theValue; } + void setActualQuantityPlayers(int theValue) { actualQuantityPlayers = theValue; } int getActualQuantityPlayers() const { return actualQuantityPlayers; } - void setActualSmallBlind(const int& theValue) { actualSmallBlind = theValue; } + void setActualSmallBlind(int theValue) { actualSmallBlind = theValue; } int getActualSmallBlind() const { return actualSmallBlind; } - void setActualHandID(const int& theValue) { actualHandID = theValue; } + void setActualHandID(int theValue) { actualHandID = theValue; } int getActualHandID() const { return actualHandID; } PlayerInterface * getPlayerByUniqueId(unsigned id); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index be85d822..c0006fe4 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -1957,48 +1957,50 @@ void mainWindowImpl::postRiverRunAnimation3() { if ( currentHand->getActivePlayersCounter() != 1 && myConfig->readConfigInt("ShowFadeOutCardsAnimation")) { int j; - + int bestHandPos[5]; + currentHand->getPlayerArray()[i]->getMyBestHandPosition(bestHandPos); + //index 0 testen --> Karte darf nicht im MyBestHand Position Array drin sein, es darf nicht nur ein Spieler Aktiv sein, die Config fordert die Animation bool index0 = TRUE; for(j=0; j<5; j++) { // cout << (currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] << endl; - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 0 ) { index0 = FALSE; } + if (bestHandPos[j] == 0 ) { index0 = FALSE; } } if (index0) { holeCardsArray[i][0]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index0" << endl;*/} //index 1 testen bool index1 = TRUE; for(j=0; j<5; j++) { - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 1 ) { index1 = FALSE; } + if (bestHandPos[j] == 1 ) { index1 = FALSE; } } if (index1) { holeCardsArray[i][1]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index1" << endl;*/} //index 2 testen bool index2 = TRUE; for(j=0; j<5; j++) { - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 2 ) { index2 = FALSE; } + if (bestHandPos[j] == 2 ) { index2 = FALSE; } } if (index2) { boardCardsArray[0]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index2" << endl;*/} //index 3 testen bool index3 = TRUE; for(j=0; j<5; j++) { - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 3 ) { index3 = FALSE; } + if (bestHandPos[j] == 3 ) { index3 = FALSE; } } if (index3) { boardCardsArray[1]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index3" << endl;*/} //index 4 testen bool index4 = TRUE; for(j=0; j<5; j++) { - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 4 ) { index4 = FALSE; } + if (bestHandPos[j] == 4 ) { index4 = FALSE; } } if (index4) { boardCardsArray[2]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index4" << endl;*/} //index 5 testen bool index5 = TRUE; for(j=0; j<5; j++) { - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 5 ) { index5 = FALSE; } + if (bestHandPos[j] == 5 ) { index5 = FALSE; } } if (index5) { boardCardsArray[3]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index5" << endl;*/} //index 6 testen bool index6 = TRUE; for(j=0; j<5; j++) { - if ((currentHand->getPlayerArray()[i]->getMyBestHandPosition())[j] == 6 ) { index6 = FALSE; } + if (bestHandPos[j] == 6 ) { index6 = FALSE; } } if (index6) { boardCardsArray[4]->startFadeOut(guiGameSpeed); /*cout << "Fade Out index6" << endl;*/} } diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 07e41b9f..f69d5de6 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -818,12 +818,14 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr((*i).cards[0]); tmpCards[1] = static_cast((*i).cards[1]); tmpPlayer->setMyCards(tmpCards); for (int num = 0; num < 5; num++) - tmpPlayer->getMyBestHandPosition()[num] = (*i).bestHandPos[num]; + bestHandPos[num] = (*i).bestHandPos[num]; tmpPlayer->setMyCardsValueInt((*i).valueOfCards); + tmpPlayer->setMyBestHandPosition(bestHandPos); if (tmpPlayer->getMyCardsValueInt() > highestValueOfCards) highestValueOfCards = tmpPlayer->getMyCardsValueInt(); tmpPlayer->setMyCash((*i).playerMoney); diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index ed384b64..db9fcfc4 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -618,12 +618,14 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server) tmpPlayerResult.playerId = (*i)->getMyUniqueID(); int tmpCards[2]; + int bestHandPos[5]; (*i)->getMyCards(tmpCards); tmpPlayerResult.cards[0] = static_cast(tmpCards[0]); tmpPlayerResult.cards[1] = static_cast(tmpCards[1]); + (*i)->getMyBestHandPosition(bestHandPos); for (int num = 0; num < 5; num++) - tmpPlayerResult.bestHandPos[num] = (*i)->getMyBestHandPosition()[num]; + tmpPlayerResult.bestHandPos[num] = bestHandPos[num]; tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt(); tmpPlayerResult.moneyWon = 0; // TODO diff --git a/src/session.h b/src/session.h index 173c6d84..e432c1c2 100755 --- a/src/session.h +++ b/src/session.h @@ -55,7 +55,7 @@ public: void sendClientPlayerAction(); - void setCurrentGameID(const int& theValue) { currentGameID = theValue; } + void setCurrentGameID(int theValue) { currentGameID = theValue; } int getCurrentGameID() const { return currentGameID; } void sendChatMessage(const std::string &message);