From 9196ec2f50fe95e0b30d0fa9084264fe74d637bb Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Sat, 3 Sep 2016 19:45:58 -0400 Subject: [PATCH] Remove local, shared, synced versions of Time. Keep one source of true --- include/openspace/util/time.h | 24 ++----- modules/base/rendering/renderablemodel.cpp | 2 +- modules/base/rendering/renderablepath.cpp | 2 +- .../globebrowsing/chunk/chunkedlodglobe.cpp | 4 +- .../tileprovider/temporaltileprovider.cpp | 6 +- modules/iswa/rendering/iswacygnet.h | 2 +- modules/iswa/util/iswamanager.h | 2 +- .../rendering/renderableplanetprojection.cpp | 2 +- src/engine/openspaceengine.cpp | 2 +- src/network/networkengine.cpp | 4 +- src/network/parallelconnection.cpp | 2 +- src/rendering/renderengine.cpp | 6 +- src/scene/scene.cpp | 2 +- src/util/time.cpp | 70 ++++--------------- src/util/time_lua.inl | 8 +-- 15 files changed, 40 insertions(+), 98 deletions(-) diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 8820bcbcc0..f40dc75195 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -40,7 +40,7 @@ namespace openspace { * a valid date string in accordance to the Spice library * (http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html). The time can * be retrieved as the number of seconds since the J2000 epoch with currentTime() or as a - * UTC string following ISO 8601 with the method currentTimeUTC(). + * UTC string following ISO 8601 with the method UTC(). * * In addition to the time itself, it also stores a delta time value. This value denotes * the number of seconds that pass for each real-time second. This value is set with @@ -102,7 +102,7 @@ public: * time-jump; defaults to true as most calls to set time will require recomputation of * planetary paths etc. */ - void setTime(double value, bool requireJump = true); + void setTime(double j2000Seconds, bool requireJump = true); /** * Sets the current time to the specified value given as a Spice compliant string as @@ -120,16 +120,14 @@ public: * current time is a date before that epoch, the returned value will be negative. * \return The current time as the number of seconds past the J2000 epoch */ - double currentTime() const; - - double unsyncedJ2000Seconds() const; + double j2000Seconds() const; /** * Returns the current time as a formatted date string compliant with ISO 8601 and * thus also compliant with the Spice library. * \return The current time as a formatted date string */ - std::string currentTimeUTC() const; + std::string UTC() const; /** * Returns the current time as a ISO 8601 formatted, i.e YYYY-MM-DDThh:mm:ssZ @@ -211,24 +209,12 @@ public: private: static Time* _instance; ///< The singleton instance - - //local copies + /// The time stored as the number of seconds past the J2000 epoch double _time = -1.0; double _dt = 1.0; bool _timeJumped = false; bool _timePaused = false; - bool _jockeHasToFixThisLater; - - //shared copies - double _sharedTime = -1.0; - double _sharedDt = 1.0; - bool _sharedTimeJumped = false; - - //synced copies - double _syncedTime = -1.0; - double _syncedDt = 1.0; - bool _syncedTimeJumped = false; std::mutex _syncMutex; }; diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 376fe8cf81..5366b3a3bc 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -178,7 +178,7 @@ void RenderableModel::render(const RenderData& data) { double lt; // Fade away if it does not have spice coverage - double time = openspace::Time::ref().currentTime(); + double time = openspace::Time::ref().j2000Seconds(); bool targetPositionCoverage = openspace::SpiceManager::ref().hasSpkCoverage(_target, time); if (!targetPositionCoverage) { int frame = _frameCount % 180; diff --git a/modules/base/rendering/renderablepath.cpp b/modules/base/rendering/renderablepath.cpp index 29ced4620b..be5547aefd 100644 --- a/modules/base/rendering/renderablepath.cpp +++ b/modules/base/rendering/renderablepath.cpp @@ -141,7 +141,7 @@ bool RenderablePath::isReady() const { } void RenderablePath::render(const RenderData& data) { - double time = openspace::Time::ref().currentTime(); + double time = openspace::Time::ref().j2000Seconds(); if (_start > time || _stop < time) return; diff --git a/modules/globebrowsing/chunk/chunkedlodglobe.cpp b/modules/globebrowsing/chunk/chunkedlodglobe.cpp index 967bf6bac4..fd32fa4e77 100644 --- a/modules/globebrowsing/chunk/chunkedlodglobe.cpp +++ b/modules/globebrowsing/chunk/chunkedlodglobe.cpp @@ -156,7 +156,7 @@ namespace openspace { stats.startNewRecord(); - int j2000s = Time::now().unsyncedJ2000Seconds(); + int j2000s = Time::now().j2000Seconds(); auto duration = std::chrono::system_clock::now().time_since_epoch(); auto millis = std::chrono::duration_cast(duration).count(); @@ -180,7 +180,7 @@ namespace openspace { stats.i["chunks leafs"]++; if (chunk.isVisible()) { stats.i["rendered chunks"]++; - double t0 = Time::now().unsyncedJ2000Seconds(); + double t0 = Time::now().j2000Seconds(); _renderer->renderChunk(chunkNode.getChunk(), data); debugRenderChunk(chunk, mvp); } diff --git a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp index 4adaef4a26..d0f330d068 100644 --- a/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/temporaltileprovider.cpp @@ -250,8 +250,8 @@ namespace openspace { // Time Quantizer // ////////////////////////////////////////////////////////////////////////////////////// TimeQuantizer::TimeQuantizer(const Time& start, const Time& end, double resolution) - : _start(start.unsyncedJ2000Seconds()) - , _end(end.unsyncedJ2000Seconds()) + : _start(start.j2000Seconds()) + , _end(end.j2000Seconds()) , _resolution(resolution) { @@ -291,7 +291,7 @@ namespace openspace { } bool TimeQuantizer::quantize(Time& t) const { - double unquantized = t.unsyncedJ2000Seconds(); + double unquantized = t.j2000Seconds(); if (_start <= unquantized && unquantized <= _end) { double quantized = std::floor((unquantized - _start) / _resolution) * _resolution + _start; t.setTime(quantized); diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index c123aa5c22..5f140af97f 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -115,7 +115,7 @@ protected: * this should be the data file. * @return true if update was successfull */ - virtual bool downloadTextureResource(double timestamp = Time::ref().currentTime()) = 0; + virtual bool downloadTextureResource(double timestamp = Time::ref().j2000Seconds()) = 0; virtual bool readyToRender() const = 0; /** * should set all uniforms needed to render diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index 9b81fa4646..b96e69dc19 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -91,7 +91,7 @@ public: std::future fetchImageCygnet(int id, double timestamp); std::future fetchDataCygnet(int id, double timestamp); - std::string iswaUrl(int id, double timestamp = Time::ref().currentTime(), std::string type = "image"); + std::string iswaUrl(int id, double timestamp = Time::ref().j2000Seconds(), std::string type = "image"); std::shared_ptr iswaGroup(std::string name); diff --git a/modules/newhorizons/rendering/renderableplanetprojection.cpp b/modules/newhorizons/rendering/renderableplanetprojection.cpp index 8f625eb60d..e883877546 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.cpp +++ b/modules/newhorizons/rendering/renderableplanetprojection.cpp @@ -390,7 +390,7 @@ void RenderablePlanetProjection::update(const UpdateData& data) { _projectionComponent.update(); - _time = Time::ref().currentTime(); + _time = Time::ref().j2000Seconds(); _capture = false; if (openspace::ImageSequencer::ref().isReady()){ diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index af047bb2e4..a7217875cd 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -759,7 +759,7 @@ void OpenSpaceEngine::preSynchronization() { Time::ref().advanceTime(dt); Time::ref().preSynchronization(); - auto scheduledScripts = _scriptScheduler->scheduledScripts(Time::ref().currentTime()); + auto scheduledScripts = _scriptScheduler->scheduledScripts(Time::ref().j2000Seconds()); while(scheduledScripts.size()){ auto scheduledScript = scheduledScripts.front(); LINFO(scheduledScript); diff --git a/src/network/networkengine.cpp b/src/network/networkengine.cpp index 1ddfa24924..6b8b58b54f 100644 --- a/src/network/networkengine.cpp +++ b/src/network/networkengine.cpp @@ -95,8 +95,8 @@ void NetworkEngine::publishStatusMessage() { uint16_t messageSize = 0; - double time = Time::ref().currentTime(); - std::string timeString = Time::ref().currentTimeUTC(); + double time = Time::ref().j2000Seconds(); + std::string timeString = Time::ref().UTC(); double delta = Time::ref().deltaTime(); messageSize += sizeof(time); diff --git a/src/network/parallelconnection.cpp b/src/network/parallelconnection.cpp index 260d8d64fe..f8579a0f5e 100644 --- a/src/network/parallelconnection.cpp +++ b/src/network/parallelconnection.cpp @@ -912,7 +912,7 @@ void ParallelConnection::preSynchronization(){ tf._dt = Time::ref().deltaTime(); tf._paused = Time::ref().paused(); tf._requiresTimeJump = Time::ref().timeJumped(); - tf._time = Time::ref().currentTime(); + tf._time = Time::ref().j2000Seconds(); //create a buffer and serialize message std::vector tbuffer; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index cfafb02bbe..d27d5b8d8e 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -384,7 +384,7 @@ void RenderEngine::postSynchronizationPreDraw() { glm::dvec3(0), glm::dmat3(1), 1, - Time::ref().currentTime(), + Time::ref().j2000Seconds(), Time::ref().timeJumped(), Time::ref().deltaTime(), _performanceManager != nullptr @@ -1314,7 +1314,7 @@ void RenderEngine::renderInformation() { RenderFontCr(*_fontDate, penPosition, "Date: %s", - Time::ref().currentTimeUTC().c_str() + Time::ref().UTC().c_str() ); RenderFontCr(*_fontInfo, @@ -1356,7 +1356,7 @@ void RenderEngine::renderInformation() { #ifdef OPENSPACE_MODULE_NEWHORIZONS_ENABLED bool hasNewHorizons = scene()->sceneGraphNode("NewHorizons"); - double currentTime = Time::ref().currentTime(); + double currentTime = Time::ref().j2000Seconds(); if (MissionManager::ref().hasCurrentMission()) { diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 9cffc86a82..428ec1c9f9 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -213,7 +213,7 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) { glm::dvec3(0), glm::dmat3(1), 1, - Time::ref().currentTime() }); + Time::ref().j2000Seconds() }); } catch (const ghoul::RuntimeError& e) { LERRORC(e.component, e.message); diff --git a/src/util/time.cpp b/src/util/time.cpp index 2695202e2e..e706d25f31 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -44,18 +44,8 @@ Time* Time::_instance = nullptr; Time::Time(double secondsJ2000) : _time(secondsJ2000) , _dt(1.0) - //local copies , _timeJumped(false) , _timePaused(false) - , _jockeHasToFixThisLater(false) - //shared copies - , _sharedTime(-1.0) - , _sharedDt(1.0) - , _sharedTimeJumped(false) - //synced copies - , _syncedTime(-1.0) - , _syncedDt(1.0) - , _syncedTimeJumped(false) { } @@ -64,18 +54,8 @@ Time::Time(double secondsJ2000) Time::Time(const Time& other) : _time(other._time) , _dt(other._dt) - //local copies , _timeJumped(other._timeJumped) , _timePaused(other._timePaused) - , _jockeHasToFixThisLater(other._jockeHasToFixThisLater) - //shared copies - , _sharedTime(other._sharedTime) - , _sharedDt(other._sharedDt) - , _sharedTimeJumped(other._sharedTimeJumped) - //synced copies - , _syncedTime(other._syncedTime) - , _syncedDt(other._syncedDt) - , _syncedTimeJumped(other._syncedTimeJumped) { } @@ -116,11 +96,7 @@ void Time::setTime(double value, bool requireJump) { _timeJumped = requireJump; } -double Time::currentTime() const { - return _syncedTime; -} - -double Time::unsyncedJ2000Seconds() const { +double Time::j2000Seconds() const { return _time; } @@ -136,7 +112,7 @@ void Time::setDeltaTime(double deltaT) { } double Time::deltaTime() const { - return _syncedDt; + return _dt; } void Time::setPause(bool pause) { @@ -153,12 +129,12 @@ void Time::setTime(std::string time, bool requireJump) { _timeJumped = requireJump; } -std::string Time::currentTimeUTC() const { - return SpiceManager::ref().dateFromEphemerisTime(_syncedTime); +std::string Time::UTC() const { + return SpiceManager::ref().dateFromEphemerisTime(_time); } std::string Time::ISO8601() const { - std::string datetime = SpiceManager::ref().dateFromEphemerisTime(_syncedTime); + std::string datetime = SpiceManager::ref().dateFromEphemerisTime(_time); std::string month = datetime.substr(5, 3); std::string MM = ""; @@ -183,9 +159,9 @@ std::string Time::ISO8601() const { void Time::serialize(SyncBuffer* syncBuffer) { _syncMutex.lock(); - syncBuffer->encode(_sharedTime); - syncBuffer->encode(_sharedDt); - syncBuffer->encode(_sharedTimeJumped); + syncBuffer->encode(_time); + syncBuffer->encode(_dt); + syncBuffer->encode(_timeJumped); _syncMutex.unlock(); } @@ -193,43 +169,23 @@ void Time::serialize(SyncBuffer* syncBuffer) { void Time::deserialize(SyncBuffer* syncBuffer) { _syncMutex.lock(); - syncBuffer->decode(_sharedTime); - syncBuffer->decode(_sharedDt); - syncBuffer->decode(_sharedTimeJumped); - - if (_sharedTimeJumped) - _jockeHasToFixThisLater = true; + syncBuffer->decode(_time); + syncBuffer->decode(_dt); + syncBuffer->decode(_timeJumped); _syncMutex.unlock(); } void Time::postSynchronizationPreDraw() { - _syncMutex.lock(); - _syncedTime = _sharedTime; - _syncedDt = _sharedDt; - _syncedTimeJumped = _sharedTimeJumped; - - if (_jockeHasToFixThisLater) { - _syncedTimeJumped = true; - _jockeHasToFixThisLater = false; - } - - _syncMutex.unlock(); } void Time::preSynchronization() { - _syncMutex.lock(); - _sharedTime = _time; - _sharedDt = _dt; - _sharedTimeJumped = _timeJumped; - - _syncMutex.unlock(); } bool Time::timeJumped() const { - return _syncedTimeJumped; + return _timeJumped; } void Time::setTimeJumped(bool jumped) { @@ -292,7 +248,7 @@ scripting::LuaLibrary Time::luaLibrary() { "the J2000 epoch" }, { - "currentTimeUTC", + "UTC", &luascriptfunctions::time_currentTimeUTC, "", "Returns the current time as an ISO 8601 date string " diff --git a/src/util/time_lua.inl b/src/util/time_lua.inl index 89681cf9fc..3a5a935d69 100644 --- a/src/util/time_lua.inl +++ b/src/util/time_lua.inl @@ -139,18 +139,18 @@ int time_setTime(lua_State* L) { * It is returned by calling the Time::currentTime method. */ int time_currentTime(lua_State* L) { - lua_pushnumber(L, openspace::Time::ref().currentTime()); + lua_pushnumber(L, openspace::Time::ref().j2000Seconds()); return 1; } /** * \ingroup LuaScripts - * currentTimeUTC(): + * UTC(): * Returns the current simulation time as a structured ISO 8601 string using the UTC - * timezone by calling the Time::currentTimeUTC method + * timezone by calling the Time::UTC method */ int time_currentTimeUTC(lua_State* L) { - lua_pushstring(L, openspace::Time::ref().currentTimeUTC().c_str()); + lua_pushstring(L, openspace::Time::ref().UTC().c_str()); return 1; }