fixes issues with delayed triggers.

This commit is contained in:
Dorian Zedler 2020-10-04 17:25:30 +02:00
parent fcd12b127e
commit 80aae3b22a
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
3 changed files with 32 additions and 70 deletions

View file

@ -94,17 +94,6 @@ public:
}; };
Q_ENUM(TimerState); Q_ENUM(TimerState);
/*!
* \brief The StopReason enum contains all possible reasons for a stop
*/
enum StopReason {
ManualStop, /*!< Timer was stopped manually */
CancelStop, /*!< Timer was cancelled */
FailStop, /*!< A false start occured */
TopPadStop, /*!< Timer was stopped by a physical trigger (eg. a ScStwExtension) */
TechnicalIncidentStop /*!< The timer was stopped due to a technical incident */
};
/*! /*!
* \brief The ReadyStatus enum contains all possible reasons for a timer not to be ready (>0) and the case that it is ready (0) * \brief The ReadyStatus enum contains all possible reasons for a timer not to be ready (>0) and the case that it is ready (0)
*/ */
@ -283,33 +272,6 @@ protected slots:
*/ */
void handleClimberStart(double timeOfStart); void handleClimberStart(double timeOfStart);
/*!
* \brief Function to stop the timer at a given point in time (past or future)
*
* To do this, the timer has to be in ScStwTimer::RUNNING state!
*
* \param reason reason for the timer stop
* \param timeOfStop the point in time (msecs since epoch) when the timer is supposted to be stopped
*
* \return false if the timer was not in the required state and therefore not stopped, true otherwise
*
* \see ScStwTimer::StopReason
*/
virtual bool stop(StopReason reason, double timeOfStop);
/*!
* \brief Function to stop the timer
*
* To do this, the timer has to be in ScStwTimer::RUNNING state!
*
* \param reason reason for the timer stop
*
* \return false if the timer was not in the required state and therefore not stopped, true otherwise
*
* \see ScStwTimer::StopReason
*/
bool stop(StopReason reason);
/*! /*!
* \brief Function to change the state of the timer * \brief Function to change the state of the timer
* *

View file

@ -440,6 +440,8 @@ void ScStwRace::handleTimerStop() {
if(this->state != RUNNING) if(this->state != RUNNING)
return; return;
qDebug() << "[INFO][RACE] Got a TIMER STOP";
// find out which timer has won // find out which timer has won
double lowestStoppedTime = -1; double lowestStoppedTime = -1;
QList<ScStwTimer *> timersWhichHaveWon; QList<ScStwTimer *> timersWhichHaveWon;

View file

@ -83,7 +83,7 @@ void ScStwTimer::handleClimberStart(double timeOfStart) {
this->reactionTime = timeOfStart - this->startTime; this->reactionTime = timeOfStart - this->startTime;
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){
qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime; qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
this->setState(FAILING); this->setState(FAILING);
} }
@ -109,58 +109,56 @@ bool ScStwTimer::stop() {
} }
bool ScStwTimer::stop(double timeOfStop) { bool ScStwTimer::stop(double timeOfStop) {
return this->stop(ManualStop, timeOfStop); if(this->state != RUNNING)
}
bool ScStwTimer::stop(StopReason reason) {
return this->stop(reason, QDateTime::currentMSecsSinceEpoch());
}
bool ScStwTimer::stop(StopReason reason, double timeOfStop) {
if(this->state != STARTING && this->state != WILDCARD && this->state != RUNNING && this->state != WAITING){
return false; return false;
}
switch (reason) { this->stopTime = timeOfStop;
case ManualStop: {
if(this->state == STARTING){
this->setState(CANCELLED);
}
else {
this->stopTime = timeOfStop;
// trigger an external state refresh to set the state to either WON or LOST depending on the other timers values (see ScStwRace::refreshTimerStates()) // trigger an external state refresh to set the state to either WON or LOST depending on the other timers values (see ScStwRace::refreshTimerStates())
this->setState(WAITING); this->setState(WAITING);
}
break;
}
default: {
return false;
}
}
qDebug() << "[INFO][TIMER] Stopped: " << "start Time: " << startTime << " stopTime: " << stopTime << " stoppedTime: " << this->getCurrentTime() << " reactionTime: " << reactionTime; qDebug() << "[INFO][TIMER] Stopped: " << "start Time: " << startTime << " stopTime: " << stopTime << " stoppedTime: " << this->getCurrentTime() << " reactionTime: " << reactionTime;
return true; return true;
} }
bool ScStwTimer::setResult(TimerState result) { bool ScStwTimer::setResult(TimerState result) {
if(this->state != FAILING && this->state != WAITING && this->state != STARTING)
QList<ScStwTimer::TimerState> allowedStates = {
STARTING,
RUNNING,
WAITING,
WON,
FAILING,
FAILED
};
if(!allowedStates.contains(this->state))
return false; return false;
/* The reasons why it has to accept all these states:
*
* STARTING: To set a timer to WILDCARD when its opponent has done a false start
* RUNNING: To set a timer to WILDCARD when its opponent has done a false start that was received with a delay
* WAITING: To set a timer to either WON or LOST
* WON: To set a timer to LOST when its opponent has won the race but their trigger was delayed
* FAILING: To set a timer to either FAILED or WILDCARD
* FAILED: To set a timer to WILDCARD when its opponent did an earlier false start but their tirgger was delayed
*/
switch (result) { switch (result) {
case WON:
case LOST: case LOST:
if(this->state == WAITING) { case WON:
if(this->state == WAITING || this->state == WON) {
this->setState(result); this->setState(result);
return true; return true;
} }
break; break;
case WILDCARD: case WILDCARD:
if(this->state == STARTING) { case FAILED:
if(this->state == STARTING || this->state == RUNNING || this->state == FAILED) {
this->setState(WILDCARD); this->setState(WILDCARD);
return true; return true;
} }
case FAILED:
if(this->state == FAILING) { if(this->state == FAILING) {
this->setState(result); this->setState(result);
return true; return true;