Fixed init gui in networking (is now thread safe). Fixed displaying of game/hand number for network games.
This commit is contained in:
@@ -25,7 +25,10 @@
|
||||
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)
|
||||
: 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;
|
||||
@@ -39,6 +42,8 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardI
|
||||
if(playerArray[i]->getMyActiveStatus() != 0) {
|
||||
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;
|
||||
|
||||
// myFlipCards auf 0 setzen
|
||||
for(i=0; i<startQuantityPlayers; i++) {
|
||||
playerArray[i]->setMyCardsFlip(0, 0);
|
||||
}
|
||||
|
||||
// // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
|
||||
|
||||
// // int *temp5Array;
|
||||
@@ -353,7 +353,7 @@ void LocalHand::switchRounds() {
|
||||
//unhighlight actual players groupbox
|
||||
if(playerArray[lastPlayersTurn]->getMyActiveStatus() == 1) myGui->refreshGroupbox(lastPlayersTurn,1);
|
||||
|
||||
myGui->refreshGameLabels(actualRound);
|
||||
myGui->refreshGameLabels();
|
||||
// /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl;
|
||||
//
|
||||
// cout << "NextPlayerSpeed2 start" << endl;
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
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)
|
||||
: 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;
|
||||
lastPlayersTurn = 0;
|
||||
@@ -34,6 +37,7 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, Boar
|
||||
if(playerArray[i]->getMyActiveStatus() != 0) {
|
||||
playerArray[i]->setHand(this);
|
||||
}
|
||||
// myFlipCards auf 0 setzen
|
||||
playerArray[i]->setMyCardsFlip(0, 0);
|
||||
}
|
||||
|
||||
@@ -72,6 +76,11 @@ ClientHand::start()
|
||||
void
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,15 +60,13 @@ void ServerGuiWrapper::refreshPot() const {}
|
||||
void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {}
|
||||
void ServerGuiWrapper::refreshPlayerName() const {}
|
||||
void ServerGuiWrapper::refreshButton() const {}
|
||||
void ServerGuiWrapper::refreshGameLabels() const {}
|
||||
|
||||
void ServerGuiWrapper::dealHoleCards() {}
|
||||
void ServerGuiWrapper::dealFlopCards() {}
|
||||
void ServerGuiWrapper::dealTurnCard() {}
|
||||
void ServerGuiWrapper::dealRiverCard() {}
|
||||
|
||||
void ServerGuiWrapper::refreshGameLabels(int round) const {}
|
||||
|
||||
|
||||
void ServerGuiWrapper::nextPlayerAnimation() {}
|
||||
|
||||
void ServerGuiWrapper::preflopAnimation1() {}
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
void refreshAll() const;
|
||||
void refreshPlayerName() const;
|
||||
void refreshButton() const;
|
||||
void refreshGameLabels(int round) const;
|
||||
void refreshGameLabels() const;
|
||||
|
||||
void dealHoleCards();
|
||||
void dealFlopCards();
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
virtual void refreshAll() const=0;
|
||||
virtual void refreshPlayerName() const=0;
|
||||
virtual void refreshButton() const =0;
|
||||
virtual void refreshGameLabels() const=0;
|
||||
|
||||
// // Karten-Funktionen
|
||||
virtual void dealHoleCards()=0;
|
||||
@@ -56,8 +57,6 @@ public:
|
||||
virtual void dealTurnCard()=0;
|
||||
virtual void dealRiverCard()=0;
|
||||
|
||||
virtual void refreshGameLabels(int) const=0;
|
||||
|
||||
virtual void nextPlayerAnimation()=0;
|
||||
|
||||
virtual void preflopAnimation1()=0;
|
||||
|
||||
@@ -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(); }
|
||||
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::refreshPlayerName() const { myW->signalRefreshPlayerName(); }
|
||||
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::dealFlopCards() { myW->signalDealFlopCards0(); }
|
||||
|
||||
@@ -52,14 +52,13 @@ public:
|
||||
void refreshAll() const;
|
||||
void refreshPlayerName() const;
|
||||
void refreshButton() const;
|
||||
void refreshGameLabels() const;
|
||||
|
||||
void dealHoleCards();
|
||||
void dealFlopCards();
|
||||
void dealTurnCard();
|
||||
void dealRiverCard();
|
||||
|
||||
void refreshGameLabels(int round) const;
|
||||
|
||||
void nextPlayerAnimation();
|
||||
|
||||
void preflopAnimation1();
|
||||
|
||||
@@ -572,6 +572,8 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
||||
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) );
|
||||
|
||||
//Nachrichten Thread-Save
|
||||
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
|
||||
|
||||
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
|
||||
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
|
||||
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(signalRefreshPlayerName()), this, SLOT(refreshPlayerName()));
|
||||
connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton()));
|
||||
connect(this, SIGNAL(signalRefreshGameLabels()), this, SLOT(refreshGameLabels()));
|
||||
|
||||
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(signalDealRiverCards0()), this, SLOT(dealRiverCards0()));
|
||||
|
||||
connect(this, SIGNAL(signalRefreshGameLabels(int)), this, SLOT(refreshGameLabels(int)));
|
||||
connect(this, SIGNAL(signalNextPlayerAnimation()), this, SLOT(nextPlayerAnimation()));
|
||||
|
||||
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: {
|
||||
textLabel_handLabel->setText("Preflop");
|
||||
} 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->exec(); }
|
||||
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"),
|
||||
tr("An internal error occured."),
|
||||
QMessageBox::Close); }
|
||||
|
||||
@@ -64,8 +64,6 @@ public:
|
||||
|
||||
~mainWindowImpl();
|
||||
|
||||
void initGui(int speed);
|
||||
|
||||
Session &getSession();
|
||||
void setSession(boost::shared_ptr<Session> session);
|
||||
|
||||
@@ -75,6 +73,8 @@ public:
|
||||
void setSpeeds();
|
||||
|
||||
signals:
|
||||
void signalInitGui(int speed);
|
||||
|
||||
void signalRefreshSet();
|
||||
void signalRefreshCash();
|
||||
void signalRefreshAction(int =-1, int=-1);
|
||||
@@ -92,7 +92,7 @@ signals:
|
||||
void signalDealTurnCards0();
|
||||
void signalDealRiverCards0();
|
||||
|
||||
void signalRefreshGameLabels(int);
|
||||
void signalRefreshGameLabels();
|
||||
void signalNextPlayerAnimation();
|
||||
|
||||
void signalPreflopAnimation1();
|
||||
@@ -122,6 +122,8 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void initGui(int speed);
|
||||
|
||||
//refresh-Funktionen
|
||||
void refreshSet();
|
||||
void refreshCash();
|
||||
@@ -131,7 +133,7 @@ public slots:
|
||||
void refreshGroupbox(int =-1, int =-1);
|
||||
void refreshAll();
|
||||
void refreshPlayerName();
|
||||
void refreshGameLabels(int);
|
||||
void refreshGameLabels();
|
||||
void refreshButton();
|
||||
void refreshPlayerAvatar();
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ protected:
|
||||
static void SetPlayersTurn(Game &curGame, int playersTurn);
|
||||
};
|
||||
|
||||
// State: Final (TODO).
|
||||
// State: Final (just for testing, should not be used).
|
||||
class ClientStateFinal : public ClientState
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -538,6 +538,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
client.GetGame()->initHand();
|
||||
client.GetGame()->startHand();
|
||||
client.GetGui().dealHoleCards();
|
||||
client.GetGui().refreshGameLabels();
|
||||
client.SetState(ClientStateRunHand::Instance());
|
||||
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND_START;
|
||||
@@ -577,7 +578,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
packet->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
|
||||
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)
|
||||
tmpPlayer->setMyButton(BUTTON_SMALL_BLIND);
|
||||
@@ -609,7 +611,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
NetPacketPlayersTurn::Data turnData;
|
||||
packet->ToNetPacketPlayersTurn()->GetData(turnData);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
if (!tmpPlayer)
|
||||
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
||||
|
||||
// Set round.
|
||||
if (curGame->getCurrentHand()->getActualRound() != turnData.gameState)
|
||||
@@ -623,12 +626,13 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
curGame->getPlayerArray()[i]->setMySetNull();
|
||||
}
|
||||
|
||||
curGame->getCurrentHand()->setActualRound(turnData.gameState);
|
||||
|
||||
client.GetGui().refreshPot();
|
||||
client.GetGui().refreshSet();
|
||||
client.GetGui().refreshAction();
|
||||
client.GetGui().refreshCash();
|
||||
|
||||
curGame->getCurrentHand()->setActualRound(turnData.gameState);
|
||||
client.GetGui().refreshGameLabels();
|
||||
}
|
||||
|
||||
// Next player's turn.
|
||||
@@ -683,7 +687,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
packet->ToNetPacketEndOfHandHideCards()->GetData(endHandData);
|
||||
|
||||
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);
|
||||
// TODO use moneyWon
|
||||
@@ -711,7 +716,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
while (i != end)
|
||||
{
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
if (!tmpPlayer)
|
||||
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
|
||||
|
||||
int tmpCards[2];
|
||||
tmpCards[0] = static_cast<int>((*i).cards[0]);
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
|
||||
|
||||
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_senderCallback.reset(new ClientSenderCallback(*this));
|
||||
@@ -70,7 +70,10 @@ ClientThread::Init(
|
||||
const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd, const string &playerName)
|
||||
{
|
||||
if (IsRunning())
|
||||
return; // TODO: throw exception
|
||||
{
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ClientContext &context = GetContext();
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#define ERR_NET_INVALID_PLAYER_NAME 107
|
||||
#define ERR_NET_INVALID_PLAYER_RESULTS 108
|
||||
#define ERR_NET_INVALID_CHAT_TEXT 109
|
||||
#define ERR_NET_UNKNOWN_PLAYER_ID 110
|
||||
|
||||
// This is an internal message which is not reported.
|
||||
#define MSG_SOCK_INTERNAL_PENDING 0
|
||||
|
||||
Reference in New Issue
Block a user