diff --git a/ScStwLibraries/headers/scstwrace.h b/ScStwLibraries/headers/scstwrace.h index 87599d0..3df605b 100644 --- a/ScStwLibraries/headers/scstwrace.h +++ b/ScStwLibraries/headers/scstwrace.h @@ -131,7 +131,7 @@ public slots: protected slots: private slots: - void refreshTimerStates(); + void handleTimersStateChange(); void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled); int handleFalseStart(); bool playSoundsAndStartTimers(); diff --git a/ScStwLibraries/sources/scstwrace.cpp b/ScStwLibraries/sources/scstwrace.cpp index e51e29f..2b13f53 100644 --- a/ScStwLibraries/sources/scstwrace.cpp +++ b/ScStwLibraries/sources/scstwrace.cpp @@ -197,7 +197,7 @@ void ScStwRace::technicalIncident() { bool raceIsRunning = this->state == RUNNING; - qDebug() << "[ERROR][RACE] Got a technical incident"; + qDebug() << "[ERROR][RACE] Got a technical incident, state is: " << this->state; foreach(ScStwTimer *timer, this->timers){ if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine) @@ -210,7 +210,12 @@ void ScStwRace::technicalIncident() { if(!raceIsRunning) { this->startWaitLoop->exit(LoopCancelExit); - this->soundPlayer->cancel(); + + if(this->state == STARTING) { + this->soundPlayer->cancel(); + this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume()); + } + this->setState(INCIDENT); } } @@ -220,8 +225,10 @@ void ScStwRace::handleTimerReadyStateChange(ScStwTimer::ReadyState readyState) { if(!this->competitionMode || this->state == IDLE || this->state == STOPPED || this->state == INCIDENT ) return; + qDebug() << "Some ready state changed: " << readyState; + // cancel as a technical incident if extensions are disconnected or run low on battery - if(readyState == ScStwTimer::ExtensionBatteryNotFine || readyState == ScStwTimer::ExtensionBatteryNotFine) { + if(readyState == ScStwTimer::ExtensionIsNotConnected || readyState == ScStwTimer::ExtensionBatteryNotFine) { this->technicalIncident(); return; } @@ -234,13 +241,16 @@ void ScStwRace::handleTimerReadyStateChange(ScStwTimer::ReadyState readyState) { } int ScStwRace::handleFalseStart() { - if(this->getState() != STARTING && this->getState() != RUNNING) + if(this->state != STARTING && this->state != RUNNING) return ScStw::CurrentStateNotVaildForOperationError; + qDebug() << "[INFO][RACE] Got a FALSE START"; + int returnCode = ScStw::Success; + // cancel all running timers foreach(ScStwTimer *timer, this->timers) { - if(!timer->cancel() && timer->getState() != ScStwTimer::DISABLED && timer->getState() != ScStwTimer::FAILED) + if(timer->getState() != ScStwTimer::FAILED && !timer->cancel() && timer->getState() != ScStwTimer::DISABLED) returnCode = ScStw::InternalErrorTimerOperationFailed; } @@ -456,8 +466,8 @@ void ScStwRace::setState(RaceState newState) { } } -void ScStwRace::refreshTimerStates() { - qDebug() << "[INFO][MAIN] refreshing timer states"; +void ScStwRace::handleTimersStateChange() { + qDebug() << "[INFO][MAIN] handling timer state change"; // check if the race is over bool raceIsOver = true; @@ -466,14 +476,13 @@ void ScStwRace::refreshTimerStates() { if(timer->getState() < ScStwTimer::WON && timer->getState() != ScStwTimer::WAITING){ // if the timer is not in stoped state raceIsOver = false; - break; } - else if(timer->getState() == ScStwTimer::WAITING) { + else if(timer->getState() == ScStwTimer::WAITING) this->handleTimerStop(); - } - else if (timer->getState() == ScStwTimer::FAILED) { + else if (timer->getState() == ScStwTimer::FAILED) this->handleFalseStart(); - } + else if (timer->getState() == ScStwTimer::INCIDENT) + return; } if(raceIsOver) @@ -621,7 +630,7 @@ bool ScStwRace::addTimer(ScStwTimer *timer) { this->timers.append(timer); - connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::refreshTimerStates); + connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::handleTimersStateChange); connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged); connect(timer, &ScStwTimer::wantsToBeDisabledChanged, this, &ScStwRace::handleTimerWantsToBeDisabledChange); connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged); diff --git a/ScStwLibraries/sources/scstwsoundplayer.cpp b/ScStwLibraries/sources/scstwsoundplayer.cpp index 463d716..180bc53 100644 --- a/ScStwLibraries/sources/scstwsoundplayer.cpp +++ b/ScStwLibraries/sources/scstwsoundplayer.cpp @@ -62,6 +62,8 @@ ScStwSoundPlayer::PlayResult ScStwSoundPlayer::play(ScStwSoundPlayer::StartSound loop.exec(); } + qDebug() << "[DEBUG][Sound] Playing sound now: " << sound; + // start this->soundEffect->play();