mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 18:51:17 -06:00
avoid oversampling in time sync
This commit is contained in:
@@ -35,7 +35,6 @@ public:
|
||||
void preSynchronization(double dt);
|
||||
void addKeyframe(const network::datamessagestructures::TimeKeyframe& kf);
|
||||
void removeKeyframesBefore(double timestamp);
|
||||
void removeKeyframesAfter(double timestamp);
|
||||
void clearKeyframes();
|
||||
private:
|
||||
void consumeKeyframes(double dt);
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
namespace {
|
||||
double SecondsOffTolerance = 0.1;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
using network::datamessagestructures::TimeKeyframe;
|
||||
@@ -73,10 +77,10 @@ void TimeManager::consumeKeyframes(double dt) {
|
||||
|
||||
time.setPause(latest._paused);
|
||||
time.setTimeJumped(consumingTimeJump);
|
||||
time.setDeltaTime(latest._dt);
|
||||
|
||||
if (consumingTimeJump || latest._paused) {
|
||||
time.setTime(latest._time, consumingTimeJump);
|
||||
time.setDeltaTime(latest._dt);
|
||||
}
|
||||
_latestConsumedTimestamp = latest._timestamp;
|
||||
}
|
||||
@@ -92,6 +96,14 @@ void TimeManager::consumeKeyframes(double dt) {
|
||||
return;
|
||||
}
|
||||
|
||||
double predictedTime = time.j2000Seconds() + time.deltaTime() * (next._timestamp - now);
|
||||
bool withinTolerance = std::abs(predictedTime - next._time) < std::abs(next._dt * SecondsOffTolerance);
|
||||
|
||||
if (next._dt == time.deltaTime() && withinTolerance) {
|
||||
Time::ref().advanceTime(dt);
|
||||
return;
|
||||
}
|
||||
|
||||
double t0 = now - dt;
|
||||
double t1 = now;
|
||||
double t2 = next._timestamp;
|
||||
@@ -123,17 +135,11 @@ void TimeManager::addKeyframe(const TimeKeyframe& kf) {
|
||||
_keyframes.insert(iter, kf);
|
||||
}
|
||||
|
||||
void TimeManager::removeKeyframesAfter(double timestamp) {
|
||||
network::datamessagestructures::TimeKeyframe kf;
|
||||
kf._timestamp = timestamp;
|
||||
auto iter = std::upper_bound(_keyframes.begin(), _keyframes.end(), kf, &TimeManager::compareKeyframeTimes);
|
||||
_keyframes.erase(iter, _keyframes.end());
|
||||
}
|
||||
|
||||
void TimeManager::removeKeyframesBefore(double timestamp) {
|
||||
network::datamessagestructures::TimeKeyframe kf;
|
||||
kf._timestamp = timestamp;
|
||||
auto iter = std::lower_bound(_keyframes.begin(), _keyframes.end(), kf, &TimeManager::compareKeyframeTimes);
|
||||
auto iter = std::upper_bound(_keyframes.begin(), _keyframes.end(), kf, &TimeManager::compareKeyframeTimes);
|
||||
_keyframes.erase(_keyframes.begin(), iter);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user