mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-25 06:19:02 -06:00
Merge branch 'develop' of github.com:OpenSpace/OpenSpace into feature/parallelconnection
Conflicts: include/openspace/engine/openspaceengine.h src/engine/openspaceengine.cpp src/interaction/interactionhandler.cpp src/network/parallelconnection.cpp src/scripting/scriptengine.cpp
This commit is contained in:
@@ -29,9 +29,10 @@
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <openspace/util/syncdata.h>
|
||||
|
||||
// glm includes
|
||||
#include <ghoul/glm.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
@@ -118,12 +119,8 @@ namespace openspace {
|
||||
// of the old calls to the function wrong..
|
||||
const Mat4& combinedViewMatrix() const;
|
||||
|
||||
// Synchronization
|
||||
void postSynchronizationPreDraw();
|
||||
void preSynchronization();
|
||||
void serialize(SyncBuffer* syncBuffer);
|
||||
void deserialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void invalidateCache();
|
||||
|
||||
void serialize(std::ostream& os) const;
|
||||
void deserialize(std::istream& is);
|
||||
|
||||
@@ -177,32 +174,17 @@ namespace openspace {
|
||||
[[deprecated("Replaced by Camera::SgctInternal::viewProjectionMatrix()")]]
|
||||
const glm::mat4& viewProjectionMatrix() const;
|
||||
|
||||
|
||||
std::vector<Syncable*> getSyncables();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
Class encapsulating data that needs to be synched between SGCT nodes.
|
||||
Are all three variables (i.e. local, shared, synced) really neccessary? /EB
|
||||
*/
|
||||
template <typename T>
|
||||
struct SyncData {
|
||||
SyncData() {}
|
||||
SyncData(const SyncData& d)
|
||||
: local(d.local), shared(d.shared), synced(d.synced) {}
|
||||
|
||||
void serialize(SyncBuffer* syncBuffer) { syncBuffer->encode(shared); }
|
||||
void deserialize(SyncBuffer* syncBuffer) { syncBuffer->decode(shared); }
|
||||
void postSynchronizationPreDraw() { synced = shared; }
|
||||
void preSynchronization() { shared = local; }
|
||||
|
||||
T local;
|
||||
T shared;
|
||||
T synced;
|
||||
};
|
||||
|
||||
// State of the camera
|
||||
SyncData<Vec3> _position;
|
||||
SyncData<Quat> _rotation;
|
||||
SyncData<glm::vec2> _scaling;
|
||||
|
||||
|
||||
// _focusPosition to be removed
|
||||
Vec3 _focusPosition;
|
||||
float _maxFov;
|
||||
|
||||
@@ -86,9 +86,11 @@ public:
|
||||
/**
|
||||
* Adds the passed \p factory to the FactoryManager. Factories may only be added once.
|
||||
* \param factory The ghoul::TemplateFactory to add to this FactoryManager
|
||||
* \param name A user-readable name for the registered factory.
|
||||
* \pre \p factory must not be nullptr
|
||||
*/
|
||||
void addFactory(std::unique_ptr<ghoul::TemplateFactoryBase> factory);
|
||||
void addFactory(std::unique_ptr<ghoul::TemplateFactoryBase> factory,
|
||||
std::string name = "");
|
||||
|
||||
/**
|
||||
* This method provides access to all registered ghoul::TemplateFactory%s through
|
||||
@@ -102,11 +104,25 @@ public:
|
||||
template <class T>
|
||||
ghoul::TemplateFactory<T>* factory() const;
|
||||
|
||||
/**
|
||||
* Writes a documentation for the FactoryMananger that contains all of the registered
|
||||
* factories and for each factory all registered class names.
|
||||
* \param file The file to which the documentation will be written
|
||||
* \param type The type of documentation that will be written
|
||||
* \pre \p file must not be empty
|
||||
* \pre \p type must not be empty
|
||||
*/
|
||||
void writeDocumentation(const std::string& file, const std::string& type);
|
||||
|
||||
private:
|
||||
/// Singleton member for the Factory Manager
|
||||
static FactoryManager* _manager;
|
||||
|
||||
std::vector<std::unique_ptr<ghoul::TemplateFactoryBase>> _factories;
|
||||
struct FactoryInfo {
|
||||
std::unique_ptr<ghoul::TemplateFactoryBase> factory;
|
||||
std::string name;
|
||||
};
|
||||
std::vector<FactoryInfo> _factories;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace openspace {
|
||||
template <class T>
|
||||
ghoul::TemplateFactory<T>* FactoryManager::factory() const {
|
||||
for (auto& factory : _factories) {
|
||||
if (factory->baseClassType() == typeid(T))
|
||||
return dynamic_cast<ghoul::TemplateFactory<T>*>(factory.get());
|
||||
if (factory.factory->baseClassType() == typeid(T))
|
||||
return dynamic_cast<ghoul::TemplateFactory<T>*>(factory.factory.get());
|
||||
}
|
||||
|
||||
throw FactoryNotFoundError(typeid(T).name());
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -64,6 +66,8 @@ public:
|
||||
*/
|
||||
void deinitialize();
|
||||
|
||||
virtual std::vector<Documentation> documentations() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Customization point for each derived class. The internalInitialize method is called
|
||||
|
||||
134
include/openspace/util/syncdata.h
Normal file
134
include/openspace/util/syncdata.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __SYNC_DATA_H__
|
||||
#define __SYNC_DATA_H__
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
/**
|
||||
* Interface for synchronizable data
|
||||
*
|
||||
* Used by <code>SyncEngine</code>
|
||||
*/
|
||||
class Syncable {
|
||||
public:
|
||||
virtual ~Syncable() {};
|
||||
|
||||
protected:
|
||||
// Allowing SyncEngine synchronization methods and at the same time hiding them
|
||||
// from the used of implementations of the interface
|
||||
friend class SyncEngine;
|
||||
virtual void presync(bool isMaster) {};
|
||||
virtual void encode(SyncBuffer* syncBuffer) = 0;
|
||||
virtual void decode(SyncBuffer* syncBuffer) = 0;
|
||||
virtual void postsync(bool isMaster) {};
|
||||
};
|
||||
|
||||
/**
|
||||
* A double buffered implementation of the Syncable interface.
|
||||
* Users are encouraged to used this class as a default way to synchronize different
|
||||
* C++ data types using the <code>SyncEngine</code>
|
||||
*
|
||||
* This class aims to handle the synchronization parts and yet act like a regular
|
||||
* instance of T. Implicit casts are supported, however, when accessing member functions or
|
||||
* or variables, user may have to do explicit casts.
|
||||
*
|
||||
* ((T&) t).method();
|
||||
*
|
||||
*/
|
||||
template<class T>
|
||||
class SyncData : public Syncable {
|
||||
public:
|
||||
|
||||
SyncData() {};
|
||||
SyncData(const T& val) : data(val) {};
|
||||
SyncData(const SyncData<T>& o) : data(o.data) {
|
||||
// Should not have to be copied!
|
||||
};
|
||||
|
||||
/**
|
||||
* Allowing assignment of data as if
|
||||
*/
|
||||
SyncData& operator=(const T& rhs) {
|
||||
data = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow implicit cast to referenced T
|
||||
*/
|
||||
operator T&() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow implicit cast to const referenced T
|
||||
*/
|
||||
operator const T&() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void encode(SyncBuffer* syncBuffer) {
|
||||
_mutex.lock();
|
||||
syncBuffer->encode(data);
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
virtual void decode(SyncBuffer* syncBuffer) {
|
||||
_mutex.lock();
|
||||
syncBuffer->decode(doubleBufferedData);
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
virtual void postsync(bool isMaster) {
|
||||
// apply synced update
|
||||
if (!isMaster) {
|
||||
_mutex.lock();
|
||||
data = doubleBufferedData;
|
||||
_mutex.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
T data;
|
||||
T doubleBufferedData;
|
||||
std::mutex _mutex;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif //#ifndef __SYNC_DATA_H__
|
||||
@@ -26,6 +26,7 @@
|
||||
#define __TIME_H__
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/syncdata.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@@ -40,7 +41,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 +103,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 +121,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
|
||||
@@ -182,14 +181,6 @@ public:
|
||||
*/
|
||||
double advanceTime(double tickTime);
|
||||
|
||||
void serialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void deserialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void postSynchronizationPreDraw();
|
||||
|
||||
void preSynchronization();
|
||||
|
||||
bool timeJumped() const;
|
||||
|
||||
void setTimeJumped(bool jumped);
|
||||
@@ -209,28 +200,16 @@ public:
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
std::vector<Syncable*> getSyncables();
|
||||
|
||||
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;
|
||||
SyncData<double> _time;
|
||||
SyncData<double> _dt;
|
||||
SyncData<bool> _timeJumped;
|
||||
|
||||
//synced copies
|
||||
double _syncedTime = -1.0;
|
||||
double _syncedDt = 1.0;
|
||||
bool _syncedTimeJumped = false;
|
||||
|
||||
std::mutex _syncMutex;
|
||||
bool _timePaused = false;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -50,12 +50,14 @@ struct UpdateData {
|
||||
bool doPerformanceMeasurement;
|
||||
};
|
||||
|
||||
|
||||
struct RenderData {
|
||||
const Camera& camera;
|
||||
// psc position to be removed in favor of the double precision position defined in
|
||||
// the translation in transform.
|
||||
psc position;
|
||||
bool doPerformanceMeasurement;
|
||||
int renderBinMask;
|
||||
TransformData modelTransform;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user