fix for rare condition when the game screen would remain white when the game starts
This commit is contained in:
parent
40fbbc5982
commit
a319ce3afb
6 changed files with 24 additions and 21 deletions
|
@ -44,7 +44,7 @@ AbstractClient::AbstractClient(QObject *parent)
|
|||
qRegisterMetaType<QList<ServerInfo_User> >("QList<ServerInfo_User>");
|
||||
qRegisterMetaType<Event_ReplayAdded>("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)
|
||||
|
|
|
@ -60,23 +60,25 @@ signals:
|
|||
void ignoreListReceived(const QList<ServerInfo_User> &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<int, PendingCommand *> 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);
|
||||
|
||||
|
|
|
@ -13,11 +13,13 @@
|
|||
#include <QGraphicsView>
|
||||
|
||||
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()
|
||||
|
|
|
@ -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<GameScene *>(scene());
|
||||
if (s) {
|
||||
if (s)
|
||||
s->processViewSizeChange(event->size());
|
||||
}
|
||||
|
||||
updateSceneRect(scene()->sceneRect());
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ void RemoteClient::readData()
|
|||
processProtocolItem(newServerMessage);
|
||||
} while (!inputBuffer.isEmpty());
|
||||
|
||||
if (status == StatusDisconnecting)
|
||||
if (getStatus() == StatusDisconnecting) // use thread-safe getter
|
||||
doDisconnectFromServer();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<AbstractClient *> &_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<GameScene *>(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()
|
||||
|
|
Loading…
Reference in a new issue