Fixed init gui in networking (is now thread safe). Fixed displaying of game/hand number for network games.

This commit is contained in:
lotodore
2007-06-03 13:36:24 +00:00
parent baad95427f
commit 1fcb0c80fd
13 changed files with 58 additions and 34 deletions
+7 -7
View File
@@ -25,7 +25,10 @@
using namespace std; using namespace std;
LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC)
: HandInterface(), myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(0), bettingRoundsPlayed(0) : myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0),
myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0),
smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0),
bettingRoundsPlayed(0)
{ {
int i, j, k; int i, j, k;
@@ -39,6 +42,8 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardI
if(playerArray[i]->getMyActiveStatus() != 0) { if(playerArray[i]->getMyActiveStatus() != 0) {
playerArray[i]->setHand(this); playerArray[i]->setHand(this);
} }
// myFlipCards auf 0 setzen
playerArray[i]->setMyCardsFlip(0, 0);
} }
@@ -89,11 +94,6 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardI
} }
delete[] cardsArray; delete[] cardsArray;
// myFlipCards auf 0 setzen
for(i=0; i<startQuantityPlayers; i++) {
playerArray[i]->setMyCardsFlip(0, 0);
}
// // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
// // int *temp5Array; // // int *temp5Array;
@@ -353,7 +353,7 @@ void LocalHand::switchRounds() {
//unhighlight actual players groupbox //unhighlight actual players groupbox
if(playerArray[lastPlayersTurn]->getMyActiveStatus() == 1) myGui->refreshGroupbox(lastPlayersTurn,1); if(playerArray[lastPlayersTurn]->getMyActiveStatus() == 1) myGui->refreshGroupbox(lastPlayersTurn,1);
myGui->refreshGameLabels(actualRound); myGui->refreshGameLabels();
// /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl; // /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl;
// //
// cout << "NextPlayerSpeed2 start" << endl; // cout << "NextPlayerSpeed2 start" << endl;
+10 -1
View File
@@ -22,7 +22,10 @@
using namespace std; using namespace std;
ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC)
: myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), allInCondition(0), bettingRoundsPlayed(0) : myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0),
myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0),
smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0),
bettingRoundsPlayed(0)
{ {
int i; int i;
lastPlayersTurn = 0; lastPlayersTurn = 0;
@@ -34,6 +37,7 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, Boar
if(playerArray[i]->getMyActiveStatus() != 0) { if(playerArray[i]->getMyActiveStatus() != 0) {
playerArray[i]->setHand(this); playerArray[i]->setHand(this);
} }
// myFlipCards auf 0 setzen
playerArray[i]->setMyCardsFlip(0, 0); playerArray[i]->setMyCardsFlip(0, 0);
} }
@@ -72,6 +76,11 @@ ClientHand::start()
void void
ClientHand::switchRounds() ClientHand::switchRounds()
{ {
// update active players counter.
activePlayersCounter = 0;
for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) {
if (playerArray[i]->getMyAction() != 1 && playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++;
}
} }
+1 -3
View File
@@ -60,15 +60,13 @@ void ServerGuiWrapper::refreshPot() const {}
void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {} void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {}
void ServerGuiWrapper::refreshPlayerName() const {} void ServerGuiWrapper::refreshPlayerName() const {}
void ServerGuiWrapper::refreshButton() const {} void ServerGuiWrapper::refreshButton() const {}
void ServerGuiWrapper::refreshGameLabels() const {}
void ServerGuiWrapper::dealHoleCards() {} void ServerGuiWrapper::dealHoleCards() {}
void ServerGuiWrapper::dealFlopCards() {} void ServerGuiWrapper::dealFlopCards() {}
void ServerGuiWrapper::dealTurnCard() {} void ServerGuiWrapper::dealTurnCard() {}
void ServerGuiWrapper::dealRiverCard() {} void ServerGuiWrapper::dealRiverCard() {}
void ServerGuiWrapper::refreshGameLabels(int round) const {}
void ServerGuiWrapper::nextPlayerAnimation() {} void ServerGuiWrapper::nextPlayerAnimation() {}
void ServerGuiWrapper::preflopAnimation1() {} void ServerGuiWrapper::preflopAnimation1() {}
+1 -1
View File
@@ -44,7 +44,7 @@ public:
void refreshAll() const; void refreshAll() const;
void refreshPlayerName() const; void refreshPlayerName() const;
void refreshButton() const; void refreshButton() const;
void refreshGameLabels(int round) const; void refreshGameLabels() const;
void dealHoleCards(); void dealHoleCards();
void dealFlopCards(); void dealFlopCards();
+1 -2
View File
@@ -49,6 +49,7 @@ public:
virtual void refreshAll() const=0; virtual void refreshAll() const=0;
virtual void refreshPlayerName() const=0; virtual void refreshPlayerName() const=0;
virtual void refreshButton() const =0; virtual void refreshButton() const =0;
virtual void refreshGameLabels() const=0;
// // Karten-Funktionen // // Karten-Funktionen
virtual void dealHoleCards()=0; virtual void dealHoleCards()=0;
@@ -56,8 +57,6 @@ public:
virtual void dealTurnCard()=0; virtual void dealTurnCard()=0;
virtual void dealRiverCard()=0; virtual void dealRiverCard()=0;
virtual void refreshGameLabels(int) const=0;
virtual void nextPlayerAnimation()=0; virtual void nextPlayerAnimation()=0;
virtual void preflopAnimation1()=0; virtual void preflopAnimation1()=0;
+2 -2
View File
@@ -44,7 +44,7 @@ GuiWrapper::~GuiWrapper()
{ {
} }
void GuiWrapper::initGui(int speed) { myW->initGui(speed); } void GuiWrapper::initGui(int speed) { myW->signalInitGui(speed); }
Session &GuiWrapper::getSession() { return myW->getSession(); } Session &GuiWrapper::getSession() { return myW->getSession(); }
void GuiWrapper::setSession(boost::shared_ptr<Session> session) { myW->setSession(session); } void GuiWrapper::setSession(boost::shared_ptr<Session> session) { myW->setSession(session); }
@@ -58,7 +58,7 @@ void GuiWrapper::refreshPot() const { myW->signalRefreshPot(); }
void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); } void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); }
void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); } void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); }
void GuiWrapper::refreshButton() const { myW->signalRefreshButton(); } void GuiWrapper::refreshButton() const { myW->signalRefreshButton(); }
void GuiWrapper::refreshGameLabels(int round) const { myW->signalRefreshGameLabels(round); } void GuiWrapper::refreshGameLabels() const { myW->signalRefreshGameLabels(); }
void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); } void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); }
void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); } void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); }
+1 -2
View File
@@ -52,14 +52,13 @@ public:
void refreshAll() const; void refreshAll() const;
void refreshPlayerName() const; void refreshPlayerName() const;
void refreshButton() const; void refreshButton() const;
void refreshGameLabels() const;
void dealHoleCards(); void dealHoleCards();
void dealFlopCards(); void dealFlopCards();
void dealTurnCard(); void dealTurnCard();
void dealRiverCard(); void dealRiverCard();
void refreshGameLabels(int round) const;
void nextPlayerAnimation(); void nextPlayerAnimation();
void preflopAnimation1(); void preflopAnimation1();
+10 -3
View File
@@ -572,6 +572,8 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) ); connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) );
//Nachrichten Thread-Save //Nachrichten Thread-Save
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet())); connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash())); connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
connect(this, SIGNAL(signalRefreshAction(int, int)), this, SLOT(refreshAction(int, int))); connect(this, SIGNAL(signalRefreshAction(int, int)), this, SLOT(refreshAction(int, int)));
@@ -581,6 +583,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
connect(this, SIGNAL(signalRefreshAll()), this, SLOT(refreshAll())); connect(this, SIGNAL(signalRefreshAll()), this, SLOT(refreshAll()));
connect(this, SIGNAL(signalRefreshPlayerName()), this, SLOT(refreshPlayerName())); connect(this, SIGNAL(signalRefreshPlayerName()), this, SLOT(refreshPlayerName()));
connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton())); connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton()));
connect(this, SIGNAL(signalRefreshGameLabels()), this, SLOT(refreshGameLabels()));
connect(this, SIGNAL(signalMeInAction()), this, SLOT(meInAction())); connect(this, SIGNAL(signalMeInAction()), this, SLOT(meInAction()));
@@ -589,7 +592,6 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
connect(this, SIGNAL(signalDealTurnCards0()), this, SLOT(dealTurnCards0())); connect(this, SIGNAL(signalDealTurnCards0()), this, SLOT(dealTurnCards0()));
connect(this, SIGNAL(signalDealRiverCards0()), this, SLOT(dealRiverCards0())); connect(this, SIGNAL(signalDealRiverCards0()), this, SLOT(dealRiverCards0()));
connect(this, SIGNAL(signalRefreshGameLabels(int)), this, SLOT(refreshGameLabels(int)));
connect(this, SIGNAL(signalNextPlayerAnimation()), this, SLOT(nextPlayerAnimation())); connect(this, SIGNAL(signalNextPlayerAnimation()), this, SLOT(nextPlayerAnimation()));
connect(this, SIGNAL(signalPreflopAnimation1()), this, SLOT(preflopAnimation1())); connect(this, SIGNAL(signalPreflopAnimation1()), this, SLOT(preflopAnimation1()));
@@ -1181,9 +1183,9 @@ void mainWindowImpl::refreshGroupbox(int playerID, int status) {
} }
} }
void mainWindowImpl::refreshGameLabels(int round) { void mainWindowImpl::refreshGameLabels() {
switch(round) { switch(mySession->getCurrentGame()->getCurrentHand()->getActualRound()) {
case 0: { case 0: {
textLabel_handLabel->setText("Preflop"); textLabel_handLabel->setText("Preflop");
} break; } break;
@@ -2472,6 +2474,11 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
{ myChangeHumanPlayerNameDialog->label_Message->setText(tr("The player name is either too short or too long. Please choose another one.")); { myChangeHumanPlayerNameDialog->label_Message->setText(tr("The player name is either too short or too long. Please choose another one."));
myChangeHumanPlayerNameDialog->exec(); } myChangeHumanPlayerNameDialog->exec(); }
break; break;
case ERR_NET_UNKNOWN_PLAYER_ID:
{ QMessageBox::warning(this, tr("Network Error"),
tr("The server referred to an unknown player. Aborting."),
QMessageBox::Close); }
break;
default: { QMessageBox::warning(this, tr("Network Error"), default: { QMessageBox::warning(this, tr("Network Error"),
tr("An internal error occured."), tr("An internal error occured."),
QMessageBox::Close); } QMessageBox::Close); }
+6 -4
View File
@@ -64,8 +64,6 @@ public:
~mainWindowImpl(); ~mainWindowImpl();
void initGui(int speed);
Session &getSession(); Session &getSession();
void setSession(boost::shared_ptr<Session> session); void setSession(boost::shared_ptr<Session> session);
@@ -75,6 +73,8 @@ public:
void setSpeeds(); void setSpeeds();
signals: signals:
void signalInitGui(int speed);
void signalRefreshSet(); void signalRefreshSet();
void signalRefreshCash(); void signalRefreshCash();
void signalRefreshAction(int =-1, int=-1); void signalRefreshAction(int =-1, int=-1);
@@ -92,7 +92,7 @@ signals:
void signalDealTurnCards0(); void signalDealTurnCards0();
void signalDealRiverCards0(); void signalDealRiverCards0();
void signalRefreshGameLabels(int); void signalRefreshGameLabels();
void signalNextPlayerAnimation(); void signalNextPlayerAnimation();
void signalPreflopAnimation1(); void signalPreflopAnimation1();
@@ -122,6 +122,8 @@ signals:
public slots: public slots:
void initGui(int speed);
//refresh-Funktionen //refresh-Funktionen
void refreshSet(); void refreshSet();
void refreshCash(); void refreshCash();
@@ -131,7 +133,7 @@ public slots:
void refreshGroupbox(int =-1, int =-1); void refreshGroupbox(int =-1, int =-1);
void refreshAll(); void refreshAll();
void refreshPlayerName(); void refreshPlayerName();
void refreshGameLabels(int); void refreshGameLabels();
void refreshButton(); void refreshButton();
void refreshPlayerAvatar(); void refreshPlayerAvatar();
+1 -1
View File
@@ -257,7 +257,7 @@ protected:
static void SetPlayersTurn(Game &curGame, int playersTurn); static void SetPlayersTurn(Game &curGame, int playersTurn);
}; };
// State: Final (TODO). // State: Final (just for testing, should not be used).
class ClientStateFinal : public ClientState class ClientStateFinal : public ClientState
{ {
public: public:
+12 -6
View File
@@ -538,6 +538,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<Net
client.GetGame()->initHand(); client.GetGame()->initHand();
client.GetGame()->startHand(); client.GetGame()->startHand();
client.GetGui().dealHoleCards(); client.GetGui().dealHoleCards();
client.GetGui().refreshGameLabels();
client.SetState(ClientStateRunHand::Instance()); client.SetState(ClientStateRunHand::Instance());
retVal = MSG_NET_GAME_CLIENT_HAND_START; retVal = MSG_NET_GAME_CLIENT_HAND_START;
@@ -577,7 +578,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
NetPacketPlayersActionDone::Data actionDoneData; NetPacketPlayersActionDone::Data actionDoneData;
packet->ToNetPacketPlayersActionDone()->GetData(actionDoneData); packet->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId);
assert(tmpPlayer); // TODO: throw exception if (!tmpPlayer)
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND) if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND)
tmpPlayer->setMyButton(BUTTON_SMALL_BLIND); tmpPlayer->setMyButton(BUTTON_SMALL_BLIND);
@@ -609,7 +611,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
NetPacketPlayersTurn::Data turnData; NetPacketPlayersTurn::Data turnData;
packet->ToNetPacketPlayersTurn()->GetData(turnData); packet->ToNetPacketPlayersTurn()->GetData(turnData);
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId);
assert(tmpPlayer); // TODO: throw exception if (!tmpPlayer)
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
// Set round. // Set round.
if (curGame->getCurrentHand()->getActualRound() != turnData.gameState) if (curGame->getCurrentHand()->getActualRound() != turnData.gameState)
@@ -623,12 +626,13 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
curGame->getPlayerArray()[i]->setMySetNull(); curGame->getPlayerArray()[i]->setMySetNull();
} }
curGame->getCurrentHand()->setActualRound(turnData.gameState);
client.GetGui().refreshPot(); client.GetGui().refreshPot();
client.GetGui().refreshSet(); client.GetGui().refreshSet();
client.GetGui().refreshAction(); client.GetGui().refreshAction();
client.GetGui().refreshCash(); client.GetGui().refreshCash();
client.GetGui().refreshGameLabels();
curGame->getCurrentHand()->setActualRound(turnData.gameState);
} }
// Next player's turn. // Next player's turn.
@@ -683,7 +687,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
packet->ToNetPacketEndOfHandHideCards()->GetData(endHandData); packet->ToNetPacketEndOfHandHideCards()->GetData(endHandData);
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(endHandData.playerId); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(endHandData.playerId);
assert(tmpPlayer); // TODO: throw exception if (!tmpPlayer)
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
tmpPlayer->setMyCash(endHandData.playerMoney); tmpPlayer->setMyCash(endHandData.playerMoney);
// TODO use moneyWon // TODO use moneyWon
@@ -711,7 +716,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
while (i != end) while (i != end)
{ {
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId);
assert(tmpPlayer); // TODO: throw exception if (!tmpPlayer)
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
int tmpCards[2]; int tmpCards[2];
tmpCards[0] = static_cast<int>((*i).cards[0]); tmpCards[0] = static_cast<int>((*i).cards[0]);
+5 -2
View File
@@ -53,7 +53,7 @@ private:
ClientThread::ClientThread(GuiInterface &gui) ClientThread::ClientThread(GuiInterface &gui)
: m_curState(NULL), m_gui(gui), m_curGameId(0), m_guiPlayerNum(0) : m_curState(NULL), m_gui(gui), m_curGameId(1), m_guiPlayerNum(0)
{ {
m_context.reset(new ClientContext); m_context.reset(new ClientContext);
m_senderCallback.reset(new ClientSenderCallback(*this)); m_senderCallback.reset(new ClientSenderCallback(*this));
@@ -70,7 +70,10 @@ ClientThread::Init(
const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd, const string &playerName) const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd, const string &playerName)
{ {
if (IsRunning()) if (IsRunning())
return; // TODO: throw exception {
assert(false);
return;
}
ClientContext &context = GetContext(); ClientContext &context = GetContext();
+1
View File
@@ -50,6 +50,7 @@
#define ERR_NET_INVALID_PLAYER_NAME 107 #define ERR_NET_INVALID_PLAYER_NAME 107
#define ERR_NET_INVALID_PLAYER_RESULTS 108 #define ERR_NET_INVALID_PLAYER_RESULTS 108
#define ERR_NET_INVALID_CHAT_TEXT 109 #define ERR_NET_INVALID_CHAT_TEXT 109
#define ERR_NET_UNKNOWN_PLAYER_ID 110
// This is an internal message which is not reported. // This is an internal message which is not reported.
#define MSG_SOCK_INTERNAL_PENDING 0 #define MSG_SOCK_INTERNAL_PENDING 0