From 594985bf9e87a9a2e92c41fcd14f025604978f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Fri, 26 Sep 2025 08:37:07 +0200 Subject: [PATCH] Fix timer starting twice, not stopping and not resetting correctly. Took 39 minutes --- cockatrice/src/game/game_state.cpp | 12 +++++++++--- cockatrice/src/game/game_state.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/game/game_state.cpp b/cockatrice/src/game/game_state.cpp index 04248819f..718bee747 100644 --- a/cockatrice/src/game/game_state.cpp +++ b/cockatrice/src/game/game_state.cpp @@ -15,6 +15,9 @@ 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); } void GameState::incrementGameTime() @@ -24,6 +27,7 @@ void GameState::incrementGameTime() void GameState::setGameTime(int _secondsElapsed) { + secondsElapsed = _secondsElapsed; int seconds = _secondsElapsed; int minutes = seconds / 60; seconds -= minutes * 60; @@ -37,8 +41,10 @@ void GameState::setGameTime(int _secondsElapsed) void GameState::startGameTimer() { - gameTimer = new QTimer(this); - gameTimer->setInterval(1000); - connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime); gameTimer->start(); +} + +void GameState::stopGameTimer() +{ + gameTimer->stop(); } \ No newline at end of file diff --git a/cockatrice/src/game/game_state.h b/cockatrice/src/game/game_state.h index 63d38ebb7..3305596f0 100644 --- a/cockatrice/src/game/game_state.h +++ b/cockatrice/src/game/game_state.h @@ -94,11 +94,13 @@ public: startGameTimer(); emit gameStarted(_started); } else { + stopGameTimer(); emit gameStopped(); } } void startGameTimer(); + void stopGameTimer(); void setGameStateKnown(bool known) {