From c6b358488bb4706d7aa7993b5cff6c269d0f5d81 Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Fri, 13 Feb 2015 11:02:35 +0100 Subject: [PATCH] changed sync variables for camera and time classes. added a boolean _timeJumped which is synced and set to true whenever setTime is called. (Note this is never set to false afterwards unless a call is made to setTimeJumped( bool ) with value false) --- include/openspace/util/camera.h | 5 ----- include/openspace/util/time.h | 11 +++++++---- src/util/camera.cpp | 19 ++++++------------- src/util/time.cpp | 28 +++++++++++++++++++++------- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/include/openspace/util/camera.h b/include/openspace/util/camera.h index 3566212e90..79e96090e2 100644 --- a/include/openspace/util/camera.h +++ b/include/openspace/util/camera.h @@ -169,11 +169,6 @@ private: glm::vec2 _sharedScaling; psc _sharedPosition; glm::mat4 _sharedViewRotationMatrix; - - //cluster synced variables - glm::vec2 _syncedScaling; - psc _syncedPosition; - glm::mat4 _syncedViewRotationMatrix; }; diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 34d6f3612c..708cd660bc 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -158,6 +158,10 @@ public: void preSynchronization(); + bool timeJumped(); + + void setTimeJumped(bool jumped); + /** * Returns the Lua library that contains all Lua functions available to change the * current time, retrieve the current time etc. The functions contained are @@ -187,15 +191,14 @@ private: //local copies double _time; ///< The time stored as the number of seconds past the J2000 epoch double _dt; + bool _timeJumped; //shared copies double _sharedTime; double _sharedDt; + bool _sharedTimeJumped; + - //synched copies - double _syncedTime; - double _syncedDt; - std::mutex _syncMutex; }; diff --git a/src/util/camera.cpp b/src/util/camera.cpp index 248a6d1198..8b11f2e459 100644 --- a/src/util/camera.cpp +++ b/src/util/camera.cpp @@ -51,9 +51,6 @@ Camera::Camera() , _sharedPosition() , _sharedScaling(1.f, 0.f) , _sharedViewRotationMatrix(1.f) - , _syncedPosition() - , _syncedScaling(1.f, 0.f) - , _syncedViewRotationMatrix(1.f) , _focusPosition() { } @@ -65,15 +62,11 @@ Camera::~Camera() void Camera::setPosition(psc pos) { _localPosition = std::move(pos); - _syncedPosition = _localPosition; } const psc& Camera::position() const { - return _syncedPosition; - ///* FIXA HÄR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (litet compileringsfel på slutet också så jag inte ska glömma!)*/ hej här är ett kompileringsfel! - - //return _localPosition; + return _localPosition; } void Camera::setModelMatrix(glm::mat4 modelMatrix){ @@ -126,7 +119,7 @@ void Camera::setViewRotationMatrix(glm::mat4 m) { const glm::mat4& Camera::viewRotationMatrix() const { - return _syncedViewRotationMatrix; + return _localViewRotationMatrix; } void Camera::compileViewRotationMatrix() @@ -201,7 +194,7 @@ void Camera::setScaling(glm::vec2 scaling) const glm::vec2& Camera::scaling() const { - return _syncedScaling; + return _localScaling; } void Camera::setLookUpVector(glm::vec3 lookUp) @@ -237,9 +230,9 @@ void Camera::deserialize(SyncBuffer* syncBuffer){ void Camera::postSynchronizationPreDraw(){ _syncMutex.lock(); - _syncedViewRotationMatrix = _sharedViewRotationMatrix; - _syncedPosition = _sharedPosition; - _syncedScaling = _sharedScaling; + _localViewRotationMatrix = _sharedViewRotationMatrix; + _localPosition = _sharedPosition; + _localScaling = _sharedScaling; _syncMutex.unlock(); } diff --git a/src/util/time.cpp b/src/util/time.cpp index 2a7162ae04..a90dec7091 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -150,9 +150,9 @@ Time::Time() , _dt(1.0) , _sharedTime(-1.0) , _sharedDt(1.0) - , _syncedTime(-1.0) - , _syncedDt(1.0) , _deltaTimePerSecond(1.0) + , _timeJumped(false) + , _sharedTimeJumped(false) { } @@ -179,11 +179,12 @@ bool Time::isInitialized() { void Time::setTime(double value) { _time = std::move(value); + _timeJumped = true; } double Time::currentTime() const { assert(_instance); - return _syncedTime; + return _time; } double Time::advanceTime(double tickTime) { @@ -199,18 +200,19 @@ void Time::setDeltaTime(double deltaT) { } double Time::deltaTime() const { - return _syncedDt; + return _dt; } void Time::setTime(std::string time) { SpiceManager::ref().getETfromDate(std::move(time), _time); + _timeJumped = true; // Add callback to OpenSpaceEngine that signals that the next update phase // needs total invalidation ---abock } std::string Time::currentTimeUTC() const { std::string date; - SpiceManager::ref().getDateFromET(_syncedTime, date); + SpiceManager::ref().getDateFromET(_time, date); return date; } @@ -219,6 +221,7 @@ void Time::serialize(SyncBuffer* syncBuffer){ syncBuffer->encode(_sharedTime); syncBuffer->encode(_sharedDt); + syncBuffer->encode(_sharedTimeJumped); _syncMutex.unlock(); } @@ -228,6 +231,7 @@ void Time::deserialize(SyncBuffer* syncBuffer){ syncBuffer->decode(_sharedTime); syncBuffer->decode(_sharedDt); + syncBuffer->decode(_sharedTimeJumped); _syncMutex.unlock(); } @@ -235,8 +239,9 @@ void Time::deserialize(SyncBuffer* syncBuffer){ void Time::postSynchronizationPreDraw(){ _syncMutex.lock(); - _syncedTime = _sharedTime; - _syncedDt = _sharedDt; + _time = _sharedTime; + _dt = _sharedDt; + _timeJumped = _sharedTimeJumped; _syncMutex.unlock(); } @@ -246,10 +251,19 @@ void Time::preSynchronization(){ _sharedTime = _time; _sharedDt = _dt; + _sharedTimeJumped = _timeJumped; _syncMutex.unlock(); } +bool Time::timeJumped(){ + return _timeJumped; +} + +void Time::setTimeJumped(bool jumped){ + _timeJumped = jumped; +} + scripting::ScriptEngine::LuaLibrary Time::luaLibrary() { scripting::ScriptEngine::LuaLibrary timeLibrary = { "time",