some fixes and cleanup (made some things more consistent)
This commit is contained in:
parent
c9e1f4f8ec
commit
da97e671a5
4 changed files with 86 additions and 57 deletions
|
@ -34,7 +34,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
double currentStartTotalDelay;
|
double currentStartTotalDelay;
|
||||||
double currentStartDelayStartedAt;
|
double currentStartDelayStartedAt;
|
||||||
bool currentlyWaitingForClimbers;
|
double latestStartDelayProgress;
|
||||||
bool isReadyForNextState;
|
bool isReadyForNextState;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -48,7 +48,7 @@ public slots:
|
||||||
ScStw::StatusCode stop();
|
ScStw::StatusCode stop();
|
||||||
ScStw::StatusCode reset();
|
ScStw::StatusCode reset();
|
||||||
bool addTimer(ScStwTimer *timer);
|
bool addTimer(ScStwTimer *timer);
|
||||||
QVariantList getCurrentStartDelay();
|
QVariantMap getCurrentStartDelay();
|
||||||
bool getIsReadyForNextState();
|
bool getIsReadyForNextState();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -53,8 +53,10 @@ class ScStwRace : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
|
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
|
||||||
Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged)
|
Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged)
|
||||||
Q_PROPERTY(QVariantList currentStartDelay READ getCurrentStartDelay NOTIFY currentStartDelayChanged)
|
Q_PROPERTY(QVariantMap currentStartDelay READ getCurrentStartDelay NOTIFY currentStartDelayChanged)
|
||||||
Q_PROPERTY(bool isReadyForNextState READ getIsReadyForNextState NOTIFY isReadyForNextStateChanged)
|
Q_PROPERTY(bool isReadyForNextState READ getIsReadyForNextState NOTIFY isReadyForNextStateChanged)
|
||||||
|
Q_PROPERTY(bool competitionMode READ getCompetitionMode NOTIFY competitionModeChanged)
|
||||||
|
Q_PROPERTY(bool readySoundEnabled READ getReadySoundEnabled NOTIFY readySoundEnabledChanged)
|
||||||
Q_PROPERTY(QVariantMap details READ getDetails NOTIFY detailsChanged)
|
Q_PROPERTY(QVariantMap details READ getDetails NOTIFY detailsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -65,12 +67,6 @@ public:
|
||||||
enum RaceState { IDLE, PREPAIRING, WAITING, STARTING, RUNNING, STOPPED, INCIDENT };
|
enum RaceState { IDLE, PREPAIRING, WAITING, STARTING, RUNNING, STOPPED, INCIDENT };
|
||||||
Q_ENUM(RaceState)
|
Q_ENUM(RaceState)
|
||||||
|
|
||||||
enum CurrentStartDetailAttributes {
|
|
||||||
CurrentStartStateTotalDelay = 0,
|
|
||||||
CurrentStartStateDelayProgress = 1
|
|
||||||
};
|
|
||||||
Q_ENUM(CurrentStartDetailAttributes);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QList<ScStwTimer *> timers;
|
QList<ScStwTimer *> timers;
|
||||||
void setState(RaceState newState);
|
void setState(RaceState newState);
|
||||||
|
@ -87,7 +83,7 @@ private:
|
||||||
// some settings
|
// some settings
|
||||||
double soundVolume;
|
double soundVolume;
|
||||||
bool competitionMode;
|
bool competitionMode;
|
||||||
bool competitionModeChanged;
|
bool competitionModeChangedRecently;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief stores the start action settings
|
* \brief stores the start action settings
|
||||||
|
@ -136,14 +132,15 @@ public slots:
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
RaceState getState();
|
RaceState getState();
|
||||||
virtual QVariantList getCurrentStartDelay();
|
virtual QVariantMap getCurrentStartDelay();
|
||||||
QList<ScStwTimer*> getTimers();
|
QList<ScStwTimer*> getTimers();
|
||||||
QVariantList getTimerDetailList();
|
QVariantList getTimerDetailList();
|
||||||
QVariantMap getDetails();
|
QVariantMap getDetails();
|
||||||
|
bool getCompetitionMode();
|
||||||
|
bool getReadySoundEnabled();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refreshTimerStates();
|
void refreshTimerStates();
|
||||||
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
|
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
|
||||||
|
@ -170,7 +167,8 @@ signals:
|
||||||
void timersChanged();
|
void timersChanged();
|
||||||
void isReadyForNextStateChanged();
|
void isReadyForNextStateChanged();
|
||||||
void detailsChanged();
|
void detailsChanged();
|
||||||
|
void competitionModeChanged();
|
||||||
|
void readySoundEnabledChanged();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -128,15 +128,21 @@ void ScStwRemoteRace::refreshDetails(QVariantMap details) {
|
||||||
this->setState(ScStwRace::RaceState(details["state"].toInt()));
|
this->setState(ScStwRace::RaceState(details["state"].toInt()));
|
||||||
|
|
||||||
// competition mode
|
// competition mode
|
||||||
|
if(this->competitionMode != details["competitionMode"].toBool()) {
|
||||||
this->competitionMode = details["competitionMode"].toBool();
|
this->competitionMode = details["competitionMode"].toBool();
|
||||||
|
emit this->competitionModeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// ready sound enabled
|
// ready sound enabled
|
||||||
|
if(this->getReadySoundEnabled() != details["readySoundEnabled"].toBool()) {
|
||||||
this->writeStartSoundSetting(ScStwSoundPlayer::Ready, details["readySoundEnabled"].toBool(), 0);
|
this->writeStartSoundSetting(ScStwSoundPlayer::Ready, details["readySoundEnabled"].toBool(), 0);
|
||||||
|
emit this->readySoundEnabledChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// current start delay
|
// current start delay
|
||||||
this->currentStartTotalDelay = details["currentStartDelay"].toList()[ScStwRace::CurrentStartStateTotalDelay].toInt();
|
this->currentStartTotalDelay = details["currentStartDelay"].toMap()["total"].toInt();
|
||||||
this->currentStartDelayStartedAt = QDateTime::currentMSecsSinceEpoch() - (this->currentStartTotalDelay * details["currentStartDelay"].toList()[ScStwRace::CurrentStartStateDelayProgress].toDouble());
|
this->latestStartDelayProgress = details["currentStartDelay"].toMap()["progress"].toDouble();
|
||||||
this->currentlyWaitingForClimbers = details["currentStartDelay"].toList()[ScStwRace::CurrentStartStateDelayProgress].toDouble() == 0 && this->currentStartTotalDelay == -1;
|
this->currentStartDelayStartedAt = QDateTime::currentMSecsSinceEpoch() - (this->currentStartTotalDelay * this->latestStartDelayProgress);
|
||||||
|
|
||||||
emit this->currentStartDelayChanged();
|
emit this->currentStartDelayChanged();
|
||||||
|
|
||||||
|
@ -204,27 +210,27 @@ bool ScStwRemoteRace::addTimer(ScStwTimer* timer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList ScStwRemoteRace::getCurrentStartDelay() {
|
QVariantMap ScStwRemoteRace::getCurrentStartDelay() {
|
||||||
int nextActionDelay = -1;
|
|
||||||
double nextActionDelayProg = -1;
|
|
||||||
|
|
||||||
if(this->getState() == WAITING && this->currentlyWaitingForClimbers) {
|
QVariantMap currentStartDelay = {
|
||||||
nextActionDelayProg = 0;
|
{"total", -1.0},
|
||||||
|
{"progress", -1.0}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(this->currentStartTotalDelay == -1) {
|
||||||
|
currentStartDelay["progress"] = this->latestStartDelayProgress;
|
||||||
}
|
}
|
||||||
else if(this->getState() == PREPAIRING || this->getState() == WAITING) {
|
else if(this->getState() == PREPAIRING || this->getState() == WAITING) {
|
||||||
// get the total delay and the delay progress of the next action timer
|
// get the total delay and the delay progress of the next action timer
|
||||||
double elapsed = QDateTime::currentMSecsSinceEpoch() - this->currentStartDelayStartedAt;
|
double elapsed = QDateTime::currentMSecsSinceEpoch() - this->currentStartDelayStartedAt;
|
||||||
nextActionDelay = this->currentStartTotalDelay;
|
currentStartDelay["total"] = this->currentStartTotalDelay;
|
||||||
if(elapsed < 0 || elapsed > nextActionDelay) {
|
if(elapsed < 0 || elapsed > currentStartDelay["total"].toDouble()) {
|
||||||
elapsed = nextActionDelay;
|
elapsed = currentStartDelay["total"].toDouble();
|
||||||
}
|
}
|
||||||
nextActionDelayProg = elapsed / nextActionDelay;
|
currentStartDelay["progress"] = elapsed / currentStartDelay["total"].toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return currentStartDelay;
|
||||||
nextActionDelay,
|
|
||||||
nextActionDelayProg
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScStwRemoteRace::getIsReadyForNextState() {
|
bool ScStwRemoteRace::getIsReadyForNextState() {
|
||||||
|
|
|
@ -406,9 +406,9 @@ void ScStwRace::setState(RaceState newState) {
|
||||||
|
|
||||||
if(this->state == IDLE) {
|
if(this->state == IDLE) {
|
||||||
// if we changed to IDLE -> handle timer enable / disable
|
// if we changed to IDLE -> handle timer enable / disable
|
||||||
if(this->competitionModeChanged && this->competitionMode) {
|
if(this->competitionModeChangedRecently && this->competitionMode) {
|
||||||
this->enableAllTimers();
|
this->enableAllTimers();
|
||||||
this->competitionModeChanged = false;
|
this->competitionModeChangedRecently = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this->competitionMode) {
|
if(!this->competitionMode) {
|
||||||
|
@ -523,7 +523,7 @@ void ScStwRace::setCompetitionMode(bool competitionMode) {
|
||||||
this->competitionMode = competitionMode;
|
this->competitionMode = competitionMode;
|
||||||
|
|
||||||
if(this->state != IDLE)
|
if(this->state != IDLE)
|
||||||
this->competitionModeChanged = true;
|
this->competitionModeChangedRecently = true;
|
||||||
else if(this->competitionMode)
|
else if(this->competitionMode)
|
||||||
this->enableAllTimers();
|
this->enableAllTimers();
|
||||||
}
|
}
|
||||||
|
@ -539,31 +539,48 @@ void ScStwRace::enableAllTimers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList ScStwRace::getCurrentStartDelay() {
|
QVariantMap ScStwRace::getCurrentStartDelay() {
|
||||||
int nextActionDelay = -1;
|
|
||||||
double nextActionDelayProg = -1;
|
|
||||||
|
|
||||||
if(this->state == WAITING && !this->getIsReadyForNextState()) {
|
QVariantMap currentStartDelay = {
|
||||||
|
{"total", -1.0},
|
||||||
|
{"progress", -1.0}
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (this->state) {
|
||||||
|
|
||||||
|
case WAITING:
|
||||||
|
if(!this->startSoundSettings[ScStwSoundPlayer::Ready]["Enabled"].toBool())
|
||||||
|
return currentStartDelay;
|
||||||
|
if(!this->getIsReadyForNextState())
|
||||||
// indicate that we are waiting for climbers and the progress shall be zero
|
// indicate that we are waiting for climbers and the progress shall be zero
|
||||||
nextActionDelayProg = 0;
|
currentStartDelay["progress"] = -1;
|
||||||
|
return currentStartDelay;
|
||||||
|
case PREPAIRING: {
|
||||||
|
if(!this->startSoundSettings[ScStwSoundPlayer::AtYourMarks]["Enabled"].toBool())
|
||||||
|
return currentStartDelay;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if(this->state == PREPAIRING || this->state == WAITING) {
|
|
||||||
|
default:
|
||||||
|
return currentStartDelay;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// get the total delay and the delay progress of the next action timer
|
// get the total delay and the delay progress of the next action timer
|
||||||
double remaining = this->startDelayTimer->remainingTime();
|
double remaining = this->startDelayTimer->remainingTime();
|
||||||
nextActionDelay = this->startDelayTimer->interval();
|
currentStartDelay["total"] = this->startDelayTimer->interval();
|
||||||
if(remaining < 0) {
|
if(remaining < 0) {
|
||||||
remaining = nextActionDelay;
|
remaining = currentStartDelay["total"].toDouble();
|
||||||
}
|
}
|
||||||
nextActionDelayProg = 1 - (remaining / nextActionDelay);
|
currentStartDelay["progress"] = 1 - (remaining / currentStartDelay["total"].toDouble());
|
||||||
|
|
||||||
if(nextActionDelayProg < 0)
|
if(currentStartDelay["progress"].toDouble() < 0)
|
||||||
nextActionDelayProg = 0;
|
currentStartDelay["progress"] = 0;
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
nextActionDelay,
|
return currentStartDelay;
|
||||||
nextActionDelayProg
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScStwRace::writeStartSoundSetting(ScStwSoundPlayer::StartSound sound, bool enabled, int delay) {
|
bool ScStwRace::writeStartSoundSetting(ScStwSoundPlayer::StartSound sound, bool enabled, int delay) {
|
||||||
|
@ -669,3 +686,11 @@ void ScStwRace::handleTimerReadyStateChange(ScStwTimer::ReadyState readyState) {
|
||||||
if(this->state == WAITING)
|
if(this->state == WAITING)
|
||||||
emit this->timersChanged();
|
emit this->timersChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScStwRace::getCompetitionMode() {
|
||||||
|
return this->competitionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScStwRace::getReadySoundEnabled() {
|
||||||
|
return this->startSoundSettings[ScStwSoundPlayer::Ready]["Enabled"].toBool();
|
||||||
|
}
|
||||||
|
|
Reference in a new issue