- fixed some issues with post- and during- start checks

- fixed issues with timers states
This commit is contained in:
Dorian Zedler 2020-10-04 15:11:07 +02:00
parent ade9949377
commit ec6723af75
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
3 changed files with 25 additions and 14 deletions

View file

@ -131,7 +131,7 @@ public slots:
protected slots: protected slots:
private slots: private slots:
void refreshTimerStates(); void handleTimersStateChange();
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled); void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
int handleFalseStart(); int handleFalseStart();
bool playSoundsAndStartTimers(); bool playSoundsAndStartTimers();

View file

@ -197,7 +197,7 @@ void ScStwRace::technicalIncident() {
bool raceIsRunning = this->state == RUNNING; 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){ foreach(ScStwTimer *timer, this->timers){
if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine) if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine)
@ -210,7 +210,12 @@ void ScStwRace::technicalIncident() {
if(!raceIsRunning) { if(!raceIsRunning) {
this->startWaitLoop->exit(LoopCancelExit); this->startWaitLoop->exit(LoopCancelExit);
if(this->state == STARTING) {
this->soundPlayer->cancel(); this->soundPlayer->cancel();
this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume());
}
this->setState(INCIDENT); 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 ) if(!this->competitionMode || this->state == IDLE || this->state == STOPPED || this->state == INCIDENT )
return; return;
qDebug() << "Some ready state changed: " << readyState;
// cancel as a technical incident if extensions are disconnected or run low on battery // 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(); this->technicalIncident();
return; return;
} }
@ -234,13 +241,16 @@ void ScStwRace::handleTimerReadyStateChange(ScStwTimer::ReadyState readyState) {
} }
int ScStwRace::handleFalseStart() { int ScStwRace::handleFalseStart() {
if(this->getState() != STARTING && this->getState() != RUNNING) if(this->state != STARTING && this->state != RUNNING)
return ScStw::CurrentStateNotVaildForOperationError; return ScStw::CurrentStateNotVaildForOperationError;
qDebug() << "[INFO][RACE] Got a FALSE START";
int returnCode = ScStw::Success; int returnCode = ScStw::Success;
// cancel all running timers // cancel all running timers
foreach(ScStwTimer *timer, this->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; returnCode = ScStw::InternalErrorTimerOperationFailed;
} }
@ -456,8 +466,8 @@ void ScStwRace::setState(RaceState newState) {
} }
} }
void ScStwRace::refreshTimerStates() { void ScStwRace::handleTimersStateChange() {
qDebug() << "[INFO][MAIN] refreshing timer states"; qDebug() << "[INFO][MAIN] handling timer state change";
// check if the race is over // check if the race is over
bool raceIsOver = true; bool raceIsOver = true;
@ -466,14 +476,13 @@ void ScStwRace::refreshTimerStates() {
if(timer->getState() < ScStwTimer::WON && timer->getState() != ScStwTimer::WAITING){ if(timer->getState() < ScStwTimer::WON && timer->getState() != ScStwTimer::WAITING){
// if the timer is not in stoped state // if the timer is not in stoped state
raceIsOver = false; raceIsOver = false;
break;
} }
else if(timer->getState() == ScStwTimer::WAITING) { else if(timer->getState() == ScStwTimer::WAITING)
this->handleTimerStop(); this->handleTimerStop();
} else if (timer->getState() == ScStwTimer::FAILED)
else if (timer->getState() == ScStwTimer::FAILED) {
this->handleFalseStart(); this->handleFalseStart();
} else if (timer->getState() == ScStwTimer::INCIDENT)
return;
} }
if(raceIsOver) if(raceIsOver)
@ -621,7 +630,7 @@ bool ScStwRace::addTimer(ScStwTimer *timer) {
this->timers.append(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::stateChanged, this, &ScStwRace::timersChanged);
connect(timer, &ScStwTimer::wantsToBeDisabledChanged, this, &ScStwRace::handleTimerWantsToBeDisabledChange); connect(timer, &ScStwTimer::wantsToBeDisabledChanged, this, &ScStwRace::handleTimerWantsToBeDisabledChange);
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged); connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);

View file

@ -62,6 +62,8 @@ ScStwSoundPlayer::PlayResult ScStwSoundPlayer::play(ScStwSoundPlayer::StartSound
loop.exec(); loop.exec();
} }
qDebug() << "[DEBUG][Sound] Playing sound now: " << sound;
// start // start
this->soundEffect->play(); this->soundEffect->play();