Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dorian Zedler 2020-10-05 20:42:22 +02:00
commit c9bf812615
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
2 changed files with 44 additions and 40 deletions

View file

@ -153,33 +153,6 @@ ScStw::StatusCode ScStwRace::cancel() {
return returnCode; return returnCode;
} }
void ScStwRace::technicalIncident() {
bool raceIsRunning = this->state == RUNNING;
qDebug() << "[ERROR][RACE] Got a technical incident, state is: " << this->state;
foreach(ScStwTimer *timer, this->timers){
if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine)
continue;
else if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine)
timer->technicalIncident();
else if(!raceIsRunning)
timer->setState(ScStwTimer::CANCELLED);
}
if(!raceIsRunning) {
this->startWaitLoop->exit(LoopCancelExit);
if(this->state == STARTING) {
this->soundPlayer->cancel();
this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume());
}
this->setState(INCIDENT);
}
}
void ScStwRace::handleTimerReadyStateChange(ScStwTimer::ReadyState readyState) { 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 )
@ -410,7 +383,8 @@ void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
newState == ScStwTimer::WON || newState == ScStwTimer::WON ||
newState == ScStwTimer::LOST || newState == ScStwTimer::LOST ||
newState == ScStwTimer::WILDCARD || newState == ScStwTimer::WILDCARD ||
newState == ScStwTimer::FAILED newState == ScStwTimer::FAILED ||
this->state == INCIDENT
) )
return; return;
@ -418,6 +392,7 @@ void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
// check if the race is over // check if the race is over
bool raceIsOver = true; bool raceIsOver = true;
int incidentCount = 0;
foreach(ScStwTimer * timer, this->timers){ foreach(ScStwTimer * timer, this->timers){
if(timer->getState() < ScStwTimer::WAITING){ if(timer->getState() < ScStwTimer::WAITING){
@ -429,10 +404,14 @@ void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
else if (timer->getState() == ScStwTimer::FAILING) else if (timer->getState() == ScStwTimer::FAILING)
this->handleFalseStart(); this->handleFalseStart();
else if (timer->getState() == ScStwTimer::INCIDENT) else if (timer->getState() == ScStwTimer::INCIDENT)
return; incidentCount ++;
} }
if(raceIsOver) if(incidentCount == this->timers.length()) {
this->setState(INCIDENT);
this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume());
}
else if(raceIsOver)
this->setState(STOPPED); this->setState(STOPPED);
} }
@ -495,11 +474,11 @@ void ScStwRace::handleFalseStart() {
// find out which timer(s) have lost and which get a wildcard // find out which timer(s) have lost and which get a wildcard
foreach(ScStwTimer * timer, this->timers) { foreach(ScStwTimer * timer, this->timers) {
qDebug() << "THIS TIMERS reaction time is: " << lowestReactionTime; qDebug() << "THIS TIMERS reaction time is: " << timer->getReactionTime();
if( if(
timer->getState() >= ScStwTimer::FAILING && timer->getState() >= ScStwTimer::FAILING &&
timer->getState() <= ScStwTimer::FAILED && timer->getState() <= ScStwTimer::FAILED &&
timer->getReactionTime() == lowestReactionTime timer->getReactionTime() <= lowestReactionTime
) { ) {
// this is the timer with the lowest stopped time // this is the timer with the lowest stopped time
timer->setResult(ScStwTimer::FAILED); timer->setResult(ScStwTimer::FAILED);
@ -510,9 +489,38 @@ void ScStwRace::handleFalseStart() {
} }
} }
this->setState(STOPPED); if(this->state != STOPPED) {
this->soundPlayer->cancel(); this->setState(STOPPED);
this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume()); this->soundPlayer->cancel();
this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume());
}
}
void ScStwRace::technicalIncident() {
bool raceIsRunning = this->state == RUNNING;
qDebug() << "[ERROR][RACE] Got a technical incident, state is: " << this->state;
if(!raceIsRunning) {
this->startWaitLoop->exit(LoopCancelExit);
if(this->state == STARTING) {
this->soundPlayer->cancel();
this->soundPlayer->play(ScStwSoundPlayer::FalseStart, this->getSoundVolume());
}
this->setState(INCIDENT);
}
foreach(ScStwTimer *timer, this->timers){
if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine)
continue;
else if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryNotFine)
timer->technicalIncident();
else if(!raceIsRunning)
timer->setState(ScStwTimer::CANCELLED);
}
} }
// ------------------------ // ------------------------

View file

@ -155,11 +155,7 @@ bool ScStwTimer::setResult(TimerState result) {
break; break;
case WILDCARD: case WILDCARD:
case FAILED: case FAILED:
if(this->state == STARTING || this->state == RUNNING || this->state == FAILED) { if(this->state == STARTING || this->state == RUNNING || this->state == FAILED || this->state == FAILING) {
this->setState(WILDCARD);
return true;
}
if(this->state == FAILING) {
this->setState(result); this->setState(result);
return true; return true;
} }