- 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:
private slots:
void refreshTimerStates();
void handleTimersStateChange();
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
int handleFalseStart();
bool playSoundsAndStartTimers();

View file

@ -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);
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);

View file

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