finished implementing wildcard and failing state

This commit is contained in:
Dorian Zedler 2020-10-04 16:31:49 +02:00
parent 1138348a0e
commit fcd12b127e
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
4 changed files with 30 additions and 36 deletions

View file

@ -131,17 +131,19 @@ public slots:
protected slots: protected slots:
private slots: private slots:
void handleTimerStateChange(); void handleTimerStateChange(ScStwTimer::TimerState newState);
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
void handleFalseStart();
bool playSoundsAndStartTimers();
ScStwSoundPlayer::PlayResult doDelayAndSoundOfCurrentStartState(double *timeOfSoundPlaybackStart = nullptr);
void technicalIncident();
/** /**
* \brief Function to declare the winner and looser timers after a timer has been stopped * \brief Function to declare the winner and looser timers after a timer has been stopped
*/ */
void handleTimerStop(); void handleTimerStop();
void handleFalseStart();
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
bool playSoundsAndStartTimers();
ScStwSoundPlayer::PlayResult doDelayAndSoundOfCurrentStartState(double *timeOfSoundPlaybackStart = nullptr);
void technicalIncident();
virtual void refreshCompetitionMode(); virtual void refreshCompetitionMode();

View file

@ -348,7 +348,7 @@ signals:
/*! /*!
* \brief Emitted when the state of the timer changed * \brief Emitted when the state of the timer changed
*/ */
void stateChanged(); void stateChanged(TimerState state);
/*! /*!
* \brief Emitted when the reaction time changed * \brief Emitted when the reaction time changed

View file

@ -405,7 +405,15 @@ void ScStwRace::setState(RaceState newState) {
} }
} }
void ScStwRace::handleTimerStateChange() { void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
if(
newState == ScStwTimer::WON ||
newState == ScStwTimer::LOST ||
newState == ScStwTimer::WILDCARD ||
newState == ScStwTimer::FAILED
)
return;
qDebug() << "[INFO][MAIN] handling timer state change"; qDebug() << "[INFO][MAIN] handling timer state change";
// check if the race is over // check if the race is over
@ -438,7 +446,7 @@ void ScStwRace::handleTimerStop() {
// iterate through all timers and find the lowest time that was stopped // iterate through all timers and find the lowest time that was stopped
foreach(ScStwTimer * timer, this->timers) { foreach(ScStwTimer * timer, this->timers) {
if(timer->getCurrentTime() > 0 && (timer->getCurrentTime() <= lowestStoppedTime || lowestStoppedTime < 0)) { if(timer->getCurrentTime() <= lowestStoppedTime || lowestStoppedTime < 0) {
// this is the timer with the lowest stopped time // this is the timer with the lowest stopped time
lowestStoppedTime = timer->getCurrentTime(); lowestStoppedTime = timer->getCurrentTime();
} }
@ -446,27 +454,12 @@ void ScStwRace::handleTimerStop() {
// append the timer(s) with the lowest stopped time to the winner list // append the timer(s) with the lowest stopped time to the winner list
foreach(ScStwTimer * timer, this->timers) { foreach(ScStwTimer * timer, this->timers) {
if(timer->getCurrentTime() > 0 if(timer->getCurrentTime() <= lowestStoppedTime)
&& (timer->getCurrentTime() <= lowestStoppedTime || lowestStoppedTime < 0)
&& timer->getState() != ScStwTimer::RUNNING
) {
// this is the timer with the lowest stopped time // this is the timer with the lowest stopped time
timersWhichHaveWon.append(timer);
}
}
// update the states of all timers
foreach(ScStwTimer * timer, this->timers) {
if(timer->getState() == ScStwTimer::RUNNING)
continue;
if(timersWhichHaveWon.contains(timer)) {
timer->setResult(ScStwTimer::WON); timer->setResult(ScStwTimer::WON);
} else
else {
timer->setResult(ScStwTimer::LOST); timer->setResult(ScStwTimer::LOST);
} }
}
} }
void ScStwRace::handleFalseStart() { void ScStwRace::handleFalseStart() {
@ -476,7 +469,7 @@ void ScStwRace::handleFalseStart() {
qDebug() << "[INFO][RACE] Got a FALSE START"; qDebug() << "[INFO][RACE] Got a FALSE START";
// set lowest to a value that is impossible to reach (start tone is only 3100ms long) // set lowest to a value that is impossible to reach (start tone is only 3100ms long)
int lowestReactionTime = -4000; double lowestReactionTime = -4000;
// iterate through all timers and find the lowest reactiontime that was stopped // iterate through all timers and find the lowest reactiontime that was stopped
foreach(ScStwTimer *timer, this->timers) { foreach(ScStwTimer *timer, this->timers) {
@ -496,15 +489,19 @@ void ScStwRace::handleFalseStart() {
// no timer has failed // no timer has failed
return; return;
qDebug() << "LOWEST reaction time is: " << lowestReactionTime;
// 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;
if( if(
timer->getState() >= ScStwTimer::FAILING && timer->getState() >= ScStwTimer::FAILING &&
timer->getState() <= ScStwTimer::FAILED && timer->getState() <= ScStwTimer::FAILED &&
timer->getCurrentTime() <= 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);
qDebug() << "FOUND BAD TIMER";
} }
else { else {
timer->setResult(ScStwTimer::WILDCARD); timer->setResult(ScStwTimer::WILDCARD);

View file

@ -84,8 +84,8 @@ void ScStwTimer::handleClimberStart(double timeOfStart) {
qDebug() << "+ [INFO][TIMER] reaction time: " << this->reactionTime; qDebug() << "+ [INFO][TIMER] reaction time: " << this->reactionTime;
if(this->reactionTime <= 0 && this->reactionTime > -3100){ if(this->reactionTime <= 0 && this->reactionTime > -3100){
this->stop(FailStop); qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
return; this->setState(FAILING);
} }
emit this->reactionTimeChanged(); emit this->reactionTimeChanged();
@ -134,11 +134,6 @@ bool ScStwTimer::stop(StopReason reason, double timeOfStop) {
} }
break; break;
} }
case FailStop: {
qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
this->setState(FAILED);
break;
}
default: { default: {
return false; return false;
} }
@ -209,7 +204,7 @@ void ScStwTimer::setState(TimerState newState){
if(this->state != newState) { if(this->state != newState) {
this->state = newState; this->state = newState;
qDebug() << "[INFO][TIMER] timer state changed: " << newState; qDebug() << "[INFO][TIMER] timer state changed: " << newState;
emit this->stateChanged(); emit this->stateChanged(newState);
} }
} }