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)
This commit is contained in:
Joakim Kilby
2015-02-13 11:02:35 +01:00
parent e39f3adc18
commit c6b358488b
4 changed files with 34 additions and 29 deletions

View File

@@ -169,11 +169,6 @@ private:
glm::vec2 _sharedScaling;
psc _sharedPosition;
glm::mat4 _sharedViewRotationMatrix;
//cluster synced variables
glm::vec2 _syncedScaling;
psc _syncedPosition;
glm::mat4 _syncedViewRotationMatrix;
};

View File

@@ -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;
};

View File

@@ -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();
}

View File

@@ -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",