mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Include delta time steps in time topic
In case anyone wants to create a GUI that contains the delta time steps
This commit is contained in:
@@ -43,14 +43,17 @@ private:
|
||||
|
||||
void sendCurrentTime();
|
||||
void sendFullTimeData();
|
||||
void sendDeltaTimeSteps();
|
||||
|
||||
int _timeCallbackHandle = UnsetOnChangeHandle;
|
||||
int _deltaTimeCallbackHandle = UnsetOnChangeHandle;
|
||||
int _deltaTimeStepsCallbackHandle = UnsetOnChangeHandle;
|
||||
bool _isDone = false;
|
||||
std::chrono::system_clock::time_point _lastUpdateTime;
|
||||
|
||||
bool _lastPauseState = false;
|
||||
double _lastTargetDeltaTime = 0.0;
|
||||
std::vector<double> _lastDeltaTimeSteps;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -54,6 +54,9 @@ TimeTopic::~TimeTopic() {
|
||||
if (_deltaTimeCallbackHandle != UnsetOnChangeHandle) {
|
||||
global::timeManager.removeDeltaTimeChangeCallback(_deltaTimeCallbackHandle);
|
||||
}
|
||||
if (_deltaTimeStepsCallbackHandle != UnsetOnChangeHandle) {
|
||||
global::timeManager.removeDeltaTimeStepsChangeCallback(_deltaTimeStepsCallbackHandle);
|
||||
}
|
||||
}
|
||||
|
||||
bool TimeTopic::isDone() const {
|
||||
@@ -68,6 +71,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
|
||||
sendFullTimeData();
|
||||
sendDeltaTimeSteps();
|
||||
|
||||
if (event != SubscribeEvent) {
|
||||
_isDone = true;
|
||||
@@ -95,6 +99,15 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
|
||||
sendFullTimeData();
|
||||
}
|
||||
});
|
||||
|
||||
_deltaTimeStepsCallbackHandle = global::timeManager.addDeltaTimeStepsChangeCallback(
|
||||
[this]() {
|
||||
const std::vector<double> steps = global::timeManager.deltaTimeSteps();
|
||||
if (steps != _lastDeltaTimeSteps) {
|
||||
sendDeltaTimeSteps();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void TimeTopic::sendCurrentTime() {
|
||||
@@ -140,4 +153,30 @@ void TimeTopic::sendFullTimeData() {
|
||||
_lastTargetDeltaTime = targetDeltaTime;
|
||||
}
|
||||
|
||||
void TimeTopic::sendDeltaTimeSteps() {
|
||||
const std::vector<double> steps = global::timeManager.deltaTimeSteps();
|
||||
const std::optional<double> nextStep = global::timeManager.nextDeltaTimeStep();
|
||||
const std::optional<double> prevStep = global::timeManager.previousDeltaTimeStep();
|
||||
|
||||
const bool hasNext = nextStep.has_value();
|
||||
const bool hasPrev = prevStep.has_value();
|
||||
|
||||
json deltaTimeStepsJson = {
|
||||
{ "deltaTimeSteps", steps },
|
||||
{ "hasNextStep", hasNext },
|
||||
{ "hasPrevStep", hasPrev }
|
||||
};
|
||||
|
||||
if (hasNext) {
|
||||
deltaTimeStepsJson["nextStep"] = nextStep.value();
|
||||
}
|
||||
|
||||
if (hasPrev) {
|
||||
deltaTimeStepsJson["prevStep"] = prevStep.value();
|
||||
}
|
||||
|
||||
_connection->sendJson(wrappedPayload(deltaTimeStepsJson));
|
||||
_lastDeltaTimeSteps = steps;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user