From fad1280185cfb5148d847a6cbc317a04f5ee2df6 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Fri, 26 Sep 2025 19:28:07 +0200 Subject: [PATCH] [Game] Fix game timer starting twice, not stopping and not resetting correctly. (#6177) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix timer starting twice, not stopping and not resetting correctly. Took 39 minutes * Don't stop/start, just start. Took 29 minutes * Fix build. Took 2 minutes --------- Co-authored-by: Lukas BrĂ¼bach --- cockatrice/src/game/game_state.cpp | 13 +++++-------- cockatrice/src/game/game_state.h | 3 --- cockatrice/src/tabs/tab_game.cpp | 1 - 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/game/game_state.cpp b/cockatrice/src/game/game_state.cpp index 04248819f..854878b92 100644 --- a/cockatrice/src/game/game_state.cpp +++ b/cockatrice/src/game/game_state.cpp @@ -15,6 +15,10 @@ GameState::GameState(AbstractGame *parent, clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase), activePlayer(-1), gameClosed(_gameClosed) { + gameTimer = new QTimer(this); + gameTimer->setInterval(1000); + connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime); + gameTimer->start(); } void GameState::incrementGameTime() @@ -24,6 +28,7 @@ void GameState::incrementGameTime() void GameState::setGameTime(int _secondsElapsed) { + secondsElapsed = _secondsElapsed; int seconds = _secondsElapsed; int minutes = seconds / 60; seconds -= minutes * 60; @@ -33,12 +38,4 @@ void GameState::setGameTime(int _secondsElapsed) emit updateTimeElapsedLabel(QString::number(hours).rightJustified(2, '0') + ":" + QString::number(minutes).rightJustified(2, '0') + ":" + QString::number(seconds).rightJustified(2, '0')); -} - -void GameState::startGameTimer() -{ - gameTimer = new QTimer(this); - gameTimer->setInterval(1000); - connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime); - gameTimer->start(); } \ No newline at end of file diff --git a/cockatrice/src/game/game_state.h b/cockatrice/src/game/game_state.h index 63d38ebb7..6edf579b0 100644 --- a/cockatrice/src/game/game_state.h +++ b/cockatrice/src/game/game_state.h @@ -91,15 +91,12 @@ public: void onStartedChanged(bool _started) { if (_started) { - startGameTimer(); emit gameStarted(_started); } else { emit gameStopped(); } } - void startGameTimer(); - void setGameStateKnown(bool known) { gameStateKnown = known; diff --git a/cockatrice/src/tabs/tab_game.cpp b/cockatrice/src/tabs/tab_game.cpp index 7e345472d..3bd857428 100644 --- a/cockatrice/src/tabs/tab_game.cpp +++ b/cockatrice/src/tabs/tab_game.cpp @@ -1277,7 +1277,6 @@ void TabGame::createMessageDock(bool bReplay) timeElapsedLabel = new QLabel; timeElapsedLabel->setAlignment(Qt::AlignCenter); connect(game->getGameState(), &GameState::updateTimeElapsedLabel, this, &TabGame::updateTimeElapsedLabel); - game->getGameState()->startGameTimer(); messageLogLayout->addWidget(timeElapsedLabel); }