From 78b0b883d55aae9c7efeb59aa2fef9eb5cfe0c7d Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Thu, 1 Oct 2020 01:54:39 +0200 Subject: [PATCH] - began to redo layout - fixed some issues in ScStwRace --- ScStwLibraries/headers/scstwrace.h | 2 + .../sources/client/scstwremotemonitorrace.cpp | 7 +--- ScStwLibraries/sources/scstwrace.cpp | 40 ++++++++++++------- ScStwLibraries/sources/scstwtimer.cpp | 12 +++--- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/ScStwLibraries/headers/scstwrace.h b/ScStwLibraries/headers/scstwrace.h index bf0e28d..7f1b061 100644 --- a/ScStwLibraries/headers/scstwrace.h +++ b/ScStwLibraries/headers/scstwrace.h @@ -150,6 +150,8 @@ private slots: */ void handleTimerStop(); + bool isStarting(); + signals: void startTimers(); void stopTimers(int type); diff --git a/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp b/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp index b286927..40767da 100644 --- a/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp +++ b/ScStwLibraries/sources/client/scstwremotemonitorrace.cpp @@ -71,11 +71,6 @@ int ScStwRemoteMonitorRace::stop() { return 904; } - // type can be: - // 0: stopp - // 1: cancel - // 2: fail (fase start) - qDebug() << "+ --- stopping race"; int returnCode = 900; @@ -95,7 +90,7 @@ int ScStwRemoteMonitorRace::stop() { int ScStwRemoteMonitorRace::reset() { - if(this->getState() != ScStwRace::STOPPED) { + if(this->getState() != ScStwRace::STOPPED && this->getState() != ScStwRace::INCIDENT) { return 904; } diff --git a/ScStwLibraries/sources/scstwrace.cpp b/ScStwLibraries/sources/scstwrace.cpp index e3af55c..22af64d 100644 --- a/ScStwLibraries/sources/scstwrace.cpp +++ b/ScStwLibraries/sources/scstwrace.cpp @@ -175,9 +175,8 @@ int ScStwRace::reset() { } } - if(returnCode == ScStw::Success){ + if(returnCode == ScStw::Success) this->setState(IDLE); - } return returnCode; } @@ -188,12 +187,6 @@ int ScStwRace::cancel() { qDebug() << "[INFO][RACE] cancelling race"; - this->soundPlayer->cancel(this->soundVolume); - this->nextActionTimer->stop(); - this->nextActionLoop->quit(); - this->climberReadyWaitLoop->quit(); - this->nextStartAction = None; - int returnCode = ScStw::Success; foreach(ScStwTimer *timer, this->timers){ @@ -201,6 +194,17 @@ int ScStwRace::cancel() { returnCode = ScStw::InternalErrorTimerOperationFailed; } + if(returnCode != ScStw::Success) + return returnCode; + + this->setState(STOPPED); + + this->soundPlayer->cancel(this->soundVolume); + this->nextActionTimer->stop(); + this->nextActionLoop->quit(); + this->climberReadyWaitLoop->quit(); + this->nextStartAction = None; + return returnCode; } @@ -227,15 +231,13 @@ bool ScStwRace::playSoundsAndStartTimers() { // The check if all timers are ready has already happened at this point if(!this->doDelayAndSoundOfStartAction(AtYourMarks)) { - qDebug() << "At marks sound returned false!"; return false; } // check if the start was cancelled - if(this->state != PREPAIRING) + if(!this->isStarting()) return false; - qDebug() << "NOW IN WAITING"; this->setState(WAITING); // do climber readiness tests @@ -265,7 +267,7 @@ bool ScStwRace::playSoundsAndStartTimers() { this->climberReadyWaitLoop->exec(); // check if the start was cancelled - if(this->state != WAITING) + if(!this->isStarting()) return false; } @@ -280,7 +282,7 @@ bool ScStwRace::playSoundsAndStartTimers() { this->climberReadyWaitLoop->exec(); // check if the start was cancelled - if(this->state != WAITING) + if(!this->isStarting()) return false; } while(this->nextActionTimer->remainingTime() > 0); @@ -319,7 +321,7 @@ bool ScStwRace::playSoundsAndStartTimers() { } // check if a false start occured - if(this->state != STARTING) + if(!this->isStarting()) return true; nextStartAction = None; @@ -333,6 +335,9 @@ bool ScStwRace::playSoundsAndStartTimers() { } bool ScStwRace::doDelayAndSoundOfStartAction(ScStwRace::StartAction action, double *timeOfSoundPlaybackStart) { + if(!this->isStarting()) + return false; + if(this->startActionSettings.contains(action) && this->startActionSettings[action]["Enabled"].toBool()) { this->nextStartAction = action; @@ -351,6 +356,9 @@ bool ScStwRace::doDelayAndSoundOfStartAction(ScStwRace::StartAction action, doub } } + if(!this->isStarting()) + return false; + if(!this->soundPlayer->play(action, this->soundVolume, timeOfSoundPlaybackStart)) return false; } @@ -547,3 +555,7 @@ QVariantList ScStwRace::getTimerDetailList() { return tmpTimers; } + +bool ScStwRace::isStarting() { + return this->state == PREPAIRING || this->state == WAITING || this->state == STARTING; +} diff --git a/ScStwLibraries/sources/scstwtimer.cpp b/ScStwLibraries/sources/scstwtimer.cpp index e2b6bff..0756f50 100644 --- a/ScStwLibraries/sources/scstwtimer.cpp +++ b/ScStwLibraries/sources/scstwtimer.cpp @@ -86,7 +86,9 @@ bool ScStwTimer::cancel() { if(!(this->state == IDLE || this->state == STARTING || this->state == RUNNING)) return false; - this->stop(CancelStop, -1); + qDebug() << "[INFO][TIMER] Timer was cancelled"; + + this->setState(CANCELLED); return true; } @@ -125,11 +127,6 @@ bool ScStwTimer::stop(StopReason reason, double timeOfStop) { this->setState(FAILED); break; } - case CancelStop: { - qDebug() << "[INFO][TIMER] Timer was cancelled"; - this->setState(CANCELLED); - break; - } default: { return false; } @@ -284,6 +281,9 @@ QString ScStwTimer::getText() { case ScStwTimer::CANCELLED: newText = "cancelled"; break; + case ScStwTimer::INCIDENT: + newText = "Technical incident!"; + break; case ScStwTimer::DISABLED: newText = "---"; break;