mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 20:39:08 -06:00
Started cleanup of Time class
This commit is contained in:
@@ -26,8 +26,9 @@
|
||||
#define __TIME_H__
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <string>
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -49,6 +50,8 @@ namespace openspace {
|
||||
* time that has passed since the last call to the method. For example, if the
|
||||
* advanceTime(double) method is called each frame, the <code>tickTime</code> has to be
|
||||
* equal to the frame time.
|
||||
*
|
||||
* The synchronization of the simulation time requires
|
||||
*/
|
||||
|
||||
class SyncBuffer;
|
||||
@@ -59,18 +62,21 @@ public:
|
||||
* Initializes the Time singleton.
|
||||
* \return <code>true</code> if the initialization succeeded, <code>false</code>
|
||||
* otherwise
|
||||
* \pre The Time singleton must not have been initialized
|
||||
*/
|
||||
static bool initialize();
|
||||
static void initialize();
|
||||
|
||||
/**
|
||||
* Deinitializes the Time singleton. This method will not unload the kernel that was
|
||||
* possibly loaded during the initialize method.
|
||||
* \pre The Time singleton must have been initialized
|
||||
*/
|
||||
static void deinitialize();
|
||||
|
||||
/**
|
||||
* Returns the reference to the Time singleton object.
|
||||
* \return The reference to the Time singleton object
|
||||
* \pre The Time singleton must have been initialized
|
||||
*/
|
||||
static Time& ref();
|
||||
|
||||
@@ -86,7 +92,9 @@ public:
|
||||
* Sets the current time to the specified value in seconds past the J2000 epoch. This
|
||||
* value can be negative to represent dates before the epoch.
|
||||
* \param value The number of seconds after the J2000 epoch
|
||||
* \param requireJump Wether or not the time change is big enough to require a time-jump, defaults to true as most calls to set time will require recomputation of planetary paths etc.
|
||||
* \param requireJump Whether or not the time change is big enough to require a
|
||||
* 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);
|
||||
|
||||
@@ -95,7 +103,9 @@ public:
|
||||
* described in the Spice documentation
|
||||
* (http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html)
|
||||
* \param time The time to be set as a date string
|
||||
* \param requireJump Wether or not the time change is big enough to require a time-jump, defaults to true as most calls to set time will require recomputation of planetary paths etc.
|
||||
* \param requireJump Whether or not the time change is big enough to require a
|
||||
* time-jump; defaults to true as most calls to set time will require recomputation of
|
||||
* planetary paths etc.
|
||||
*/
|
||||
void setTime(std::string time, bool requireJump = true);
|
||||
|
||||
@@ -186,32 +196,25 @@ public:
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
/// Creates the time object. Only used in the initialize() method
|
||||
Time();
|
||||
Time(const Time& src) = delete;
|
||||
Time& operator=(const Time& rhs) = delete;
|
||||
|
||||
static Time* _instance; ///< The singleton instance
|
||||
|
||||
//sync variables
|
||||
|
||||
//local copies
|
||||
double _time; ///< The time stored as the number of seconds past the J2000 epoch
|
||||
double _dt;
|
||||
bool _timeJumped;
|
||||
bool _timePaused;
|
||||
//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;
|
||||
double _sharedDt;
|
||||
bool _sharedTimeJumped;
|
||||
double _sharedTime = -1.0;
|
||||
double _sharedDt = 1.0;
|
||||
bool _sharedTimeJumped = false;
|
||||
|
||||
//synced copies
|
||||
double _syncedTime;
|
||||
double _syncedDt;
|
||||
bool _syncedTimeJumped;
|
||||
|
||||
double _syncedTime = -1.0;
|
||||
double _syncedDt = 1.0;
|
||||
bool _syncedTimeJumped = false;
|
||||
|
||||
std::mutex _syncMutex;
|
||||
};
|
||||
|
||||
@@ -42,15 +42,6 @@ struct UpdateData {
|
||||
};
|
||||
|
||||
struct RenderData {
|
||||
RenderData(const Camera& cam, psc pos, bool performance)
|
||||
: camera(cam)
|
||||
, position(std::move(pos))
|
||||
, doPerformanceMeasurement(std::move(performance))
|
||||
{}
|
||||
|
||||
//RenderData() = default;
|
||||
RenderData& operator=(const RenderData& rhs) = delete;
|
||||
|
||||
const Camera& camera;
|
||||
psc position;
|
||||
bool doPerformanceMeasurement;
|
||||
|
||||
@@ -24,54 +24,31 @@
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include "time_lua.inl"
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Time";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
Time* Time::_instance = nullptr;
|
||||
|
||||
Time::Time()
|
||||
: _time(-1.0)
|
||||
, _dt(1.0)
|
||||
, _timeJumped(false)
|
||||
, _timePaused(false)
|
||||
, _sharedTime(-1.0)
|
||||
, _sharedDt(1.0)
|
||||
, _sharedTimeJumped(false)
|
||||
, _syncedTime(-1.0)
|
||||
, _syncedDt(1.0)
|
||||
, _syncedTimeJumped(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool Time::initialize() {
|
||||
assert( _instance == nullptr);
|
||||
_instance = new Time();
|
||||
return true;
|
||||
void Time::initialize() {
|
||||
ghoul_assert(_instance == nullptr, "Static time must not have been ininitialized");
|
||||
_instance = new Time();
|
||||
}
|
||||
|
||||
void Time::deinitialize() {
|
||||
assert(_instance);
|
||||
delete _instance;
|
||||
_instance = nullptr;
|
||||
ghoul_assert(_instance, "Static time must have been ininitialized");
|
||||
delete _instance;
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
Time& Time::ref() {
|
||||
assert(_instance);
|
||||
ghoul_assert(_instance, "Static time must have been ininitialized");
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
@@ -80,13 +57,11 @@ bool Time::isInitialized() {
|
||||
}
|
||||
|
||||
void Time::setTime(double value, bool requireJump) {
|
||||
_time = std::move(value);
|
||||
_time = value;
|
||||
_timeJumped = requireJump;
|
||||
}
|
||||
|
||||
double Time::currentTime() const {
|
||||
assert(_instance);
|
||||
//return _time;
|
||||
return _syncedTime;
|
||||
}
|
||||
|
||||
@@ -98,11 +73,10 @@ double Time::advanceTime(double tickTime) {
|
||||
}
|
||||
|
||||
void Time::setDeltaTime(double deltaT) {
|
||||
_dt = std::move(deltaT);
|
||||
_dt = deltaT;
|
||||
}
|
||||
|
||||
double Time::deltaTime() const {
|
||||
//return _dt;
|
||||
return _syncedDt;
|
||||
}
|
||||
|
||||
@@ -124,7 +98,7 @@ std::string Time::currentTimeUTC() const {
|
||||
return SpiceManager::ref().dateFromEphemerisTime(_syncedTime);
|
||||
}
|
||||
|
||||
void Time::serialize(SyncBuffer* syncBuffer){
|
||||
void Time::serialize(SyncBuffer* syncBuffer) {
|
||||
_syncMutex.lock();
|
||||
|
||||
syncBuffer->encode(_sharedTime);
|
||||
@@ -134,7 +108,7 @@ void Time::serialize(SyncBuffer* syncBuffer){
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::deserialize(SyncBuffer* syncBuffer){
|
||||
void Time::deserialize(SyncBuffer* syncBuffer) {
|
||||
_syncMutex.lock();
|
||||
|
||||
syncBuffer->decode(_sharedTime);
|
||||
@@ -147,13 +121,12 @@ void Time::deserialize(SyncBuffer* syncBuffer){
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::postSynchronizationPreDraw(){
|
||||
void Time::postSynchronizationPreDraw() {
|
||||
_syncMutex.lock();
|
||||
|
||||
_syncedTime = _sharedTime;
|
||||
_syncedDt = _sharedDt;
|
||||
//if (_sharedTimeJumped)
|
||||
_syncedTimeJumped = _sharedTimeJumped;
|
||||
_syncedTimeJumped = _sharedTimeJumped;
|
||||
|
||||
if (_jockeHasToFixThisLater) {
|
||||
_syncedTimeJumped = true;
|
||||
@@ -163,7 +136,7 @@ void Time::postSynchronizationPreDraw(){
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::preSynchronization(){
|
||||
void Time::preSynchronization() {
|
||||
_syncMutex.lock();
|
||||
|
||||
_sharedTime = _time;
|
||||
@@ -174,15 +147,14 @@ void Time::preSynchronization(){
|
||||
}
|
||||
|
||||
bool Time::timeJumped() const {
|
||||
//return _timeJumped;
|
||||
return _syncedTimeJumped;
|
||||
}
|
||||
|
||||
void Time::setTimeJumped(bool jumped){
|
||||
void Time::setTimeJumped(bool jumped) {
|
||||
_timeJumped = jumped;
|
||||
}
|
||||
|
||||
bool Time::paused() const{
|
||||
bool Time::paused() const {
|
||||
return _timePaused;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user