diff --git a/cockatrice/src/abstractclient.cpp b/cockatrice/src/abstractclient.cpp index b359b1e2..45c67864 100644 --- a/cockatrice/src/abstractclient.cpp +++ b/cockatrice/src/abstractclient.cpp @@ -44,7 +44,7 @@ AbstractClient::AbstractClient(QObject *parent) qRegisterMetaType >("QList"); qRegisterMetaType("Event_ReplayAdded"); - connect(this, SIGNAL(sigSendCommandContainer(CommandContainer)), this, SLOT(sendCommandContainer(CommandContainer))); + connect(this, SIGNAL(sigQueuePendingCommand(PendingCommand *)), this, SLOT(queuePendingCommand(PendingCommand *))); } AbstractClient::~AbstractClient() @@ -58,12 +58,10 @@ void AbstractClient::processProtocolItem(const ServerMessage &item) const Response &response = item.response(); const int cmdId = response.cmd_id(); - QMutexLocker locker(&clientMutex); PendingCommand *pend = pendingCommands.value(cmdId, 0); if (!pend) return; pendingCommands.remove(cmdId); - locker.unlock(); pend->processResponse(response); pend->deleteLater(); @@ -100,6 +98,7 @@ void AbstractClient::processProtocolItem(const ServerMessage &item) void AbstractClient::setStatus(const ClientStatus _status) { + QMutexLocker locker(&clientMutex); if (_status != status) { status = _status; emit statusChanged(_status); @@ -113,15 +112,19 @@ void AbstractClient::sendCommand(const CommandContainer &cont) void AbstractClient::sendCommand(PendingCommand *pend) { + pend->moveToThread(thread()); + emit sigQueuePendingCommand(pend); +} + +void AbstractClient::queuePendingCommand(PendingCommand *pend) +{ + // This function is always called from the client thread via signal/slot. const int cmdId = nextCmdId++; pend->getCommandContainer().set_cmd_id(cmdId); - pend->moveToThread(thread()); - clientMutex.lock(); pendingCommands.insert(cmdId, pend); - clientMutex.unlock(); - emit sigSendCommandContainer(pend->getCommandContainer()); + sendCommandContainer(pend->getCommandContainer()); } PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf::Message &cmd) diff --git a/cockatrice/src/abstractclient.h b/cockatrice/src/abstractclient.h index 124f7a2f..7853deb3 100644 --- a/cockatrice/src/abstractclient.h +++ b/cockatrice/src/abstractclient.h @@ -60,23 +60,25 @@ signals: void ignoreListReceived(const QList &ignoreList); void replayAddedEventReceived(const Event_ReplayAdded &event); - void sigSendCommandContainer(const CommandContainer &commandContainer); + void sigQueuePendingCommand(PendingCommand *pend); private: int nextCmdId; - QMutex clientMutex; + mutable QMutex clientMutex; + ClientStatus status; +private slots: + void queuePendingCommand(PendingCommand *pend); protected slots: void processProtocolItem(const ServerMessage &item); - virtual void sendCommandContainer(const CommandContainer &cont) = 0; protected: QMap pendingCommands; - ClientStatus status; QString userName, password; void setStatus(ClientStatus _status); + virtual void sendCommandContainer(const CommandContainer &cont) = 0; public: AbstractClient(QObject *parent = 0); ~AbstractClient(); - ClientStatus getStatus() const { return status; } + ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; } void sendCommand(const CommandContainer &cont); void sendCommand(PendingCommand *pend); diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index 1307eb50..ce083c76 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -13,11 +13,13 @@ #include GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent) - : QGraphicsScene(parent), phasesToolbar(_phasesToolbar) + : QGraphicsScene(parent), phasesToolbar(_phasesToolbar), viewSize(QSize()) { animationTimer = new QBasicTimer; addItem(phasesToolbar); connect(settingsCache, SIGNAL(minPlayersForMultiColumnLayoutChanged()), this, SLOT(rearrange())); + + rearrange(); } GameScene::~GameScene() diff --git a/cockatrice/src/gameview.cpp b/cockatrice/src/gameview.cpp index d8de4893..75a4024b 100644 --- a/cockatrice/src/gameview.cpp +++ b/cockatrice/src/gameview.cpp @@ -8,7 +8,7 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent), rubberBand(0) { setBackgroundBrush(QBrush(QColor(0, 0, 0))); - setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/); + setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing); setFocusPolicy(Qt::NoFocus); setViewportUpdateMode(BoundingRectViewportUpdate); @@ -31,9 +31,9 @@ void GameView::resizeEvent(QResizeEvent *event) QGraphicsView::resizeEvent(event); GameScene *s = dynamic_cast(scene()); - if (s) { + if (s) s->processViewSizeChange(event->size()); - } + updateSceneRect(scene()->sceneRect()); } diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index 9ae607ca..acf63082 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -125,7 +125,7 @@ void RemoteClient::readData() processProtocolItem(newServerMessage); } while (!inputBuffer.isEmpty()); - if (status == StatusDisconnecting) + if (getStatus() == StatusDisconnecting) // use thread-safe getter doDisconnectFromServer(); } diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 9f1fa4bf..f0ee0848 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -271,7 +271,6 @@ TabGame::TabGame(GameReplay *_replay) } phasesToolbar = new PhasesToolbar; - phasesToolbar->hide(); scene = new GameScene(phasesToolbar, this); gameView = new GameView(scene); @@ -399,7 +398,6 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client gameTimer->start(); phasesToolbar = new PhasesToolbar; - phasesToolbar->hide(); connect(phasesToolbar, SIGNAL(sendGameCommand(const ::google::protobuf::Message &, int)), this, SLOT(sendGameCommand(const ::google::protobuf::Message &, int))); scene = new GameScene(phasesToolbar, this); @@ -869,7 +867,6 @@ void TabGame::startGame(bool resuming) gameInfo.set_started(true); static_cast(gameView->scene())->rearrange(); gameView->show(); - phasesToolbar->show(); } void TabGame::stopGame() @@ -888,7 +885,6 @@ void TabGame::stopGame() playerListWidget->setGameStarted(false, false); gameInfo.set_started(false); gameView->hide(); - phasesToolbar->hide(); } void TabGame::closeGame()