mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Remove local, shared, synced versions of Time. Keep one source of true
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<std::chrono::milliseconds>(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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
|
||||
std::future<DownloadManager::MemoryFile> fetchImageCygnet(int id, double timestamp);
|
||||
std::future<DownloadManager::MemoryFile> 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<IswaBaseGroup> iswaGroup(std::string name);
|
||||
|
||||
|
||||
@@ -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()){
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<char> tbuffer;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user