mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
Feature/thesis work merge (#566)
Web GUI from Klas Eskilson (three new modules: webgui, webbrowser and cefwebgui) Parallel connection refactorization Wormhole server added to the main repository Transfer function editor work from Cristoffer Särevall Update ghoul
This commit is contained in:
@@ -86,6 +86,9 @@ public:
|
||||
|
||||
/// The key that stores the factory documentation values
|
||||
static constexpr const char* KeyFactoryDocumentation = "FactoryDocumentation";
|
||||
/// The key that decides whether or not we should require incoming web socket connections
|
||||
/// to authorize or not
|
||||
static constexpr const char* KeyRequireSocketAuthentication = "RequireSocketAuthentication";
|
||||
|
||||
/// The key that stores the location of the asset file that is initially loaded
|
||||
static constexpr const char* KeyConfigAsset = "Asset";
|
||||
@@ -200,7 +203,13 @@ public:
|
||||
/// The part of the key storing whether the OpenGL state should be checked each call
|
||||
static constexpr const char* KeyCheckOpenGLState = "CheckOpenGLState";
|
||||
|
||||
/// The part of the key storing whether each OpenGL call should be logged
|
||||
/// The part of the key storing whether the OpenGL state should be checked each call
|
||||
static constexpr const char* KeyServerPasskey = "ServerPasskey";
|
||||
|
||||
/// Whitelist of client addresses that won't need autorization
|
||||
static constexpr const char* KeyServerClientAddressWhitelist =
|
||||
"ClientAddressWhitelist";
|
||||
|
||||
static constexpr const char* KeyLogEachOpenGLCall = "LogEachOpenGLCall";
|
||||
|
||||
/// This key determines whether the scene graph nodes should initialized multithreaded
|
||||
@@ -233,6 +242,8 @@ public:
|
||||
/// The key used to specify whether screenshots should contain the current date
|
||||
static constexpr const char* KeyScreenshotUseDate = "ScreenshotUseDate";
|
||||
|
||||
static constexpr const char* KeyWebHelperLocation = "WebHelperLocation";
|
||||
static constexpr const char* KeyCefWebGuiUrl = "CefWebGuiUrl";
|
||||
|
||||
/**
|
||||
* Iteratively walks the directory structure starting with \p filename to find the
|
||||
|
||||
@@ -51,7 +51,7 @@ class LoadingScreen;
|
||||
class LuaConsole;
|
||||
class ModuleEngine;
|
||||
class NetworkEngine;
|
||||
class ParallelConnection;
|
||||
class ParallelPeer;
|
||||
class RenderEngine;
|
||||
class Scene;
|
||||
class SyncEngine;
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
ModuleEngine& moduleEngine();
|
||||
LoadingScreen& loadingScreen();
|
||||
NetworkEngine& networkEngine();
|
||||
ParallelConnection& parallelConnection();
|
||||
ParallelPeer& parallelPeer();
|
||||
RenderEngine& renderEngine();
|
||||
TimeManager& timeManager();
|
||||
WindowWrapper& windowWrapper();
|
||||
@@ -212,7 +212,7 @@ private:
|
||||
std::unique_ptr<LuaConsole> _console;
|
||||
std::unique_ptr<ModuleEngine> _moduleEngine;
|
||||
std::unique_ptr<NetworkEngine> _networkEngine;
|
||||
std::unique_ptr<ParallelConnection> _parallelConnection;
|
||||
std::unique_ptr<ParallelPeer> _parallelPeer;
|
||||
std::unique_ptr<RenderEngine> _renderEngine;
|
||||
std::unique_ptr<SyncEngine> _syncEngine;
|
||||
std::unique_ptr<TimeManager> _timeManager;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define __OPENSPACE_CORE___KEYFRAMENAVIGATOR___H__
|
||||
|
||||
#include <openspace/util/timeline.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/network/parallelpeer.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#ifndef __OPENSPACE_CORE___LUACONSOLE___H__
|
||||
#define __OPENSPACE_CORE___LUACONSOLE___H__
|
||||
|
||||
#include <openspace/network/parallelpeer.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
|
||||
@@ -26,39 +26,18 @@
|
||||
#define __OPENSPACE_CORE___PARALLELCONNECTION___H__
|
||||
|
||||
#include <openspace/network/messagestructures.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/numericalproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <ghoul/io/socket/tcpsocket.h>
|
||||
|
||||
#include <ghoul/designpattern/event.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <condition_variable>
|
||||
|
||||
#if defined(WIN32) || defined(__MING32__) || defined(__MING64__)
|
||||
typedef size_t _SOCKET;
|
||||
#else
|
||||
typedef int _SOCKET;
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
struct addrinfo;
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ParallelConnection : public properties::PropertyOwner {
|
||||
public:
|
||||
class ParallelConnection {
|
||||
public:
|
||||
enum class Status : uint32_t {
|
||||
Disconnected = 0,
|
||||
Connecting,
|
||||
ClientWithoutHost,
|
||||
ClientWithHost,
|
||||
Host
|
||||
@@ -70,7 +49,8 @@ class ParallelConnection : public properties::PropertyOwner {
|
||||
ConnectionStatus,
|
||||
HostshipRequest,
|
||||
HostshipResignation,
|
||||
NConnections
|
||||
NConnections,
|
||||
Disconnection
|
||||
};
|
||||
|
||||
struct Message {
|
||||
@@ -94,115 +74,23 @@ class ParallelConnection : public properties::PropertyOwner {
|
||||
std::vector<char> content;
|
||||
};
|
||||
|
||||
ParallelConnection();
|
||||
~ParallelConnection();
|
||||
void clientConnect();
|
||||
void setPort(std::string port);
|
||||
void setAddress(std::string address);
|
||||
void setName(std::string name);
|
||||
bool isHost();
|
||||
const std::string& hostName();
|
||||
void requestHostship();
|
||||
void resignHostship();
|
||||
void setPassword(std::string password);
|
||||
void setHostPassword(std::string hostPassword);
|
||||
void signalDisconnect();
|
||||
void preSynchronization();
|
||||
void sendScript(std::string script);
|
||||
void resetTimeOffset();
|
||||
double latencyStandardDeviation() const;
|
||||
double timeTolerance() const;
|
||||
class ConnectionLostError : public ghoul::RuntimeError {
|
||||
public:
|
||||
explicit ConnectionLostError();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
* remote OS parallel connection. The functions contained are
|
||||
* -
|
||||
* \return The Lua library that contains all Lua functions available to affect the
|
||||
* interaction
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
Status status();
|
||||
int nConnections();
|
||||
std::shared_ptr<ghoul::Event<>> connectionEvent();
|
||||
ParallelConnection(std::unique_ptr<ghoul::io::TcpSocket> socket);
|
||||
|
||||
bool isConnectedOrConnecting();
|
||||
void sendDataMessage(const ParallelConnection::DataMessage& dataMessage);
|
||||
bool sendMessage(const ParallelConnection::Message& message);
|
||||
void disconnect();
|
||||
ghoul::io::TcpSocket* socket();
|
||||
|
||||
ParallelConnection::Message receiveMessage();
|
||||
|
||||
private:
|
||||
//@TODO change this into the ghoul hasher for client AND server
|
||||
uint32_t hash(const std::string &val);
|
||||
void queueOutMessage(const Message& message);
|
||||
void queueOutDataMessage(const DataMessage& dataMessage);
|
||||
void queueInMessage(const Message& message);
|
||||
|
||||
void disconnect();
|
||||
void closeSocket();
|
||||
bool initNetworkAPI();
|
||||
void establishConnection(addrinfo *info);
|
||||
void sendAuthentication();
|
||||
void listenCommunication();
|
||||
int receiveData(_SOCKET & socket, std::vector<char> &buffer, int length, int flags);
|
||||
|
||||
void handleMessage(const Message&);
|
||||
void dataMessageReceived(const std::vector<char>& messageContent);
|
||||
void connectionStatusMessageReceived(const std::vector<char>& messageContent);
|
||||
void nConnectionsMessageReceived(const std::vector<char>& messageContent);
|
||||
|
||||
void sendCameraKeyframe();
|
||||
void sendTimeKeyframe();
|
||||
|
||||
void sendFunc();
|
||||
void threadManagement();
|
||||
|
||||
void setStatus(Status status);
|
||||
void setHostName(const std::string& hostName);
|
||||
void setNConnections(size_t nConnections);
|
||||
|
||||
double calculateBufferedKeyframeTime(double originalTime);
|
||||
|
||||
properties::StringProperty _password;
|
||||
properties::StringProperty _hostPassword;
|
||||
properties::StringProperty _port;
|
||||
properties::StringProperty _address;
|
||||
properties::StringProperty _name;
|
||||
properties::FloatProperty _bufferTime;
|
||||
properties::FloatProperty _timeKeyframeInterval;
|
||||
properties::FloatProperty _cameraKeyframeInterval;
|
||||
properties::FloatProperty _timeTolerance;
|
||||
|
||||
double _lastTimeKeyframeTimestamp;
|
||||
double _lastCameraKeyframeTimestamp;
|
||||
|
||||
_SOCKET _clientSocket;
|
||||
|
||||
std::atomic<bool> _isConnected;
|
||||
std::atomic<bool> _isRunning;
|
||||
std::atomic<bool> _tryConnect;
|
||||
std::atomic<bool> _disconnect;
|
||||
std::atomic<bool> _initializationTimejumpRequired;
|
||||
|
||||
std::atomic<size_t> _nConnections;
|
||||
std::atomic<Status> _status;
|
||||
std::string _hostName;
|
||||
|
||||
std::condition_variable _disconnectCondition;
|
||||
std::mutex _disconnectMutex;
|
||||
|
||||
std::condition_variable _sendCondition;
|
||||
std::deque<Message> _sendBuffer;
|
||||
std::mutex _sendBufferMutex;
|
||||
|
||||
std::deque<Message> _receiveBuffer;
|
||||
std::mutex _receiveBufferMutex;
|
||||
|
||||
std::atomic<bool> _timeJumped;
|
||||
std::mutex _latencyMutex;
|
||||
std::deque<double> _latencyDiffs;
|
||||
double _initialTimeDiff;
|
||||
|
||||
std::unique_ptr<std::thread> _connectionThread;
|
||||
std::unique_ptr<std::thread> _sendThread;
|
||||
std::unique_ptr<std::thread> _listenThread;
|
||||
std::unique_ptr<std::thread> _handlerThread;
|
||||
std::shared_ptr<ghoul::Event<>> _connectionEvent;
|
||||
std::unique_ptr<ghoul::io::TcpSocket> _socket;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* 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 __OPENSPACE_CORE___PARALLELPEER___H__
|
||||
#define __OPENSPACE_CORE___PARALLELPEER___H__
|
||||
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/network/messagestructures.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/numericalproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <ghoul/designpattern/event.h>
|
||||
#include <ghoul/io/socket/tcpsocket.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ParallelPeer : public properties::PropertyOwner {
|
||||
public:
|
||||
ParallelPeer();
|
||||
~ParallelPeer();
|
||||
void connect();
|
||||
void setPort(std::string port);
|
||||
void setAddress(std::string address);
|
||||
void setName(std::string name);
|
||||
bool isHost();
|
||||
const std::string& hostName();
|
||||
void requestHostship();
|
||||
void resignHostship();
|
||||
void setPassword(std::string password);
|
||||
void setHostPassword(std::string hostPassword);
|
||||
void disconnect();
|
||||
void preSynchronization();
|
||||
void sendScript(std::string script);
|
||||
void resetTimeOffset();
|
||||
double latencyStandardDeviation() const;
|
||||
double timeTolerance() const;
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
* remote OS parallel connection.
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
ParallelConnection::Status status();
|
||||
int nConnections();
|
||||
std::shared_ptr<ghoul::Event<>> connectionEvent();
|
||||
|
||||
private:
|
||||
void queueInMessage(const ParallelConnection::Message& message);
|
||||
|
||||
void sendAuthentication();
|
||||
void handleCommunication();
|
||||
|
||||
void handleMessage(const ParallelConnection::Message&);
|
||||
void dataMessageReceived(const std::vector<char>& messageContent);
|
||||
void connectionStatusMessageReceived(const std::vector<char>& messageContent);
|
||||
void nConnectionsMessageReceived(const std::vector<char>& messageContent);
|
||||
|
||||
void sendCameraKeyframe();
|
||||
void sendTimeKeyframe();
|
||||
|
||||
void setStatus(ParallelConnection::Status status);
|
||||
void setHostName(const std::string& hostName);
|
||||
void setNConnections(size_t nConnections);
|
||||
|
||||
double calculateBufferedKeyframeTime(double originalTime);
|
||||
|
||||
properties::StringProperty _password;
|
||||
properties::StringProperty _hostPassword;
|
||||
properties::StringProperty _port;
|
||||
properties::StringProperty _address;
|
||||
properties::StringProperty _name;
|
||||
properties::FloatProperty _bufferTime;
|
||||
properties::FloatProperty _timeKeyframeInterval;
|
||||
properties::FloatProperty _cameraKeyframeInterval;
|
||||
properties::FloatProperty _timeTolerance;
|
||||
|
||||
double _lastTimeKeyframeTimestamp;
|
||||
double _lastCameraKeyframeTimestamp;
|
||||
|
||||
std::atomic<bool> _shouldDisconnect;
|
||||
|
||||
std::atomic<size_t> _nConnections;
|
||||
std::atomic<ParallelConnection::Status> _status;
|
||||
std::string _hostName;
|
||||
|
||||
std::deque<ParallelConnection::Message> _receiveBuffer;
|
||||
std::mutex _receiveBufferMutex;
|
||||
|
||||
std::atomic<bool> _timeJumped;
|
||||
std::mutex _latencyMutex;
|
||||
std::deque<double> _latencyDiffs;
|
||||
double _initialTimeDiff;
|
||||
|
||||
std::unique_ptr<std::thread> _receiveThread;
|
||||
std::shared_ptr<ghoul::Event<>> _connectionEvent;
|
||||
|
||||
ParallelConnection _connection;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___PARALLELPEER___H__
|
||||
@@ -0,0 +1,123 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* 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 __OPENSPACE_CORE___PARALLELSERVER___H__
|
||||
#define __OPENSPACE_CORE___PARALLELSERVER___H__
|
||||
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
|
||||
#include <openspace/util/concurrentqueue.h>
|
||||
|
||||
#include <ghoul/io/socket/tcpsocketserver.h>
|
||||
#include <ghoul/io/socket/tcpsocket.h>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <atomic>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ParallelServer {
|
||||
public:
|
||||
void start(int port,
|
||||
const std::string& password,
|
||||
const std::string& changeHostPassword);
|
||||
|
||||
void setDefaultHostAddress(std::string);
|
||||
|
||||
std::string defaultHostAddress() const;
|
||||
|
||||
void stop();
|
||||
|
||||
size_t nConnections() const;
|
||||
|
||||
private:
|
||||
struct Peer {
|
||||
size_t id;
|
||||
std::string name;
|
||||
ParallelConnection parallelConnection;
|
||||
ParallelConnection::Status status;
|
||||
std::thread thread;
|
||||
};
|
||||
|
||||
struct PeerMessage {
|
||||
size_t peerId;
|
||||
ParallelConnection::Message message;
|
||||
};
|
||||
|
||||
bool isConnected(std::shared_ptr<Peer> peer) const;
|
||||
|
||||
void sendMessage(std::shared_ptr<Peer> peer,
|
||||
ParallelConnection::MessageType messageType,
|
||||
const std::vector<char>& message);
|
||||
|
||||
void sendMessageToAll(ParallelConnection::MessageType messageType,
|
||||
const std::vector<char>& message);
|
||||
|
||||
void sendMessageToClients(ParallelConnection::MessageType messageType,
|
||||
const std::vector<char>& message);
|
||||
|
||||
void disconnect(std::shared_ptr<Peer> peer);
|
||||
void setName(std::shared_ptr<Peer> peer, std::string name);
|
||||
void assignHost(std::shared_ptr<Peer> peer);
|
||||
void setToClient(std::shared_ptr<Peer> peer);
|
||||
void setNConnections(size_t nConnections);
|
||||
void sendConnectionStatus(std::shared_ptr<Peer> peer);
|
||||
|
||||
void handleAuthentication(std::shared_ptr<Peer> peer, std::vector<char> data);
|
||||
void handleData(std::shared_ptr<Peer> peer, std::vector<char> data);
|
||||
void handleHostshipRequest(std::shared_ptr<Peer> peer, std::vector<char> data);
|
||||
void handleHostshipResignation(std::shared_ptr<Peer> peer, std::vector<char> data);
|
||||
void handleDisconnection(std::shared_ptr<Peer> peer);
|
||||
|
||||
void handleNewPeers();
|
||||
void eventLoop();
|
||||
std::shared_ptr<Peer> peer(size_t i);
|
||||
void handlePeer(size_t id);
|
||||
void handlePeerMessage(PeerMessage peerMessage);
|
||||
|
||||
std::unordered_map<size_t, std::shared_ptr<Peer>> _peers;
|
||||
mutable std::mutex _peerListMutex;
|
||||
|
||||
std::thread _serverThread;
|
||||
std::thread _eventLoopThread;
|
||||
ghoul::io::TcpSocketServer _socketServer;
|
||||
size_t _passwordHash;
|
||||
size_t _changeHostPasswordHash;
|
||||
size_t _nextConnectionId = 1;
|
||||
std::atomic_bool _shouldStop = false;
|
||||
|
||||
std::atomic_size_t _nConnections = 0;
|
||||
std::atomic_size_t _hostPeerId = 0;
|
||||
|
||||
mutable std::mutex _hostInfoMutex;
|
||||
std::string _hostName;
|
||||
std::string _defaultHostAddress;
|
||||
|
||||
ConcurrentQueue<PeerMessage> _incomingMessages;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___PARALLELSERVER___H__
|
||||
@@ -0,0 +1,37 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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 __OPENSPACE_CORE___BINARYPROPERTY___H__
|
||||
#define __OPENSPACE_CORE___BINARYPROPERTY___H__
|
||||
|
||||
#include <openspace/properties/templateproperty.h>
|
||||
#include <vector>
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_HEADER(BinaryProperty, std::vector<char>)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
#endif // __OPENSPACE_CORE___BINARYPROPERTY___H__
|
||||
@@ -62,6 +62,8 @@ public:
|
||||
|
||||
virtual std::string className() const override;
|
||||
|
||||
std::string jsonValue() const override;
|
||||
|
||||
using TemplateProperty<T>::operator=;
|
||||
|
||||
|
||||
@@ -79,7 +81,14 @@ protected:
|
||||
static const std::string SteppingValueKey;
|
||||
static const std::string ExponentValueKey;
|
||||
|
||||
std::string generateAdditionalDescription() const override;
|
||||
std::string generateAdditionalJsonDescription() const override;
|
||||
|
||||
/**
|
||||
* convert a lua formatted value to a JSON formatted value
|
||||
* @param luaValue
|
||||
* @return a json formatted string representation of the given lua value
|
||||
*/
|
||||
std::string luaToJson(std::string luaValue) const;
|
||||
|
||||
T _minimumValue;
|
||||
T _maximumValue;
|
||||
|
||||
@@ -386,15 +386,34 @@ void NumericalProperty<T>::setExponent(float exponent) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string NumericalProperty<T>::generateAdditionalDescription() const {
|
||||
std::string result;
|
||||
result += MinimumValueKey + " = " + std::to_string(_minimumValue) + ",";
|
||||
result += MaximumValueKey + " = " + std::to_string(_maximumValue) + ",";
|
||||
result += SteppingValueKey + " = " + std::to_string(_stepping) + ",";
|
||||
result += ExponentValueKey + " = " + std::to_string(_exponent);
|
||||
std::string NumericalProperty<T>::generateAdditionalJsonDescription() const {
|
||||
std::string result = "{ ";
|
||||
result += "\"" + MinimumValueKey + "\": " + luaToJson(std::to_string(_minimumValue)) + ",";
|
||||
result += "\"" + MaximumValueKey + "\": " + luaToJson(std::to_string(_maximumValue)) + ",";
|
||||
result += "\"" + SteppingValueKey + "\": " + luaToJson(std::to_string(_stepping)) + ",";
|
||||
result += "\"" + ExponentValueKey + "\": " + luaToJson(std::to_string(_exponent));
|
||||
result += " }";
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string NumericalProperty<T>::luaToJson(std::string luaValue) const {
|
||||
if(luaValue[0] == '{') {
|
||||
luaValue.replace(0, 1, "[");
|
||||
}
|
||||
if (luaValue[luaValue.size() - 1] == '}') {
|
||||
luaValue.replace(luaValue.size() - 1, 1, "]");
|
||||
}
|
||||
return luaValue;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string NumericalProperty<T>::jsonValue() const {
|
||||
std::string value;
|
||||
getStringValue(value);
|
||||
return luaToJson(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void NumericalProperty<T>::setInterpolationTarget(ghoul::any value) {
|
||||
try {
|
||||
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
|
||||
private:
|
||||
static const std::string OptionsKey;
|
||||
std::string generateAdditionalDescription() const override;
|
||||
std::string generateAdditionalJsonDescription() const override;
|
||||
|
||||
/// The list of options which have been registered with this OptionProperty
|
||||
std::vector<Option> _options;
|
||||
|
||||
@@ -93,6 +93,10 @@ public:
|
||||
/// onChange callback
|
||||
using OnChangeHandle = uint32_t;
|
||||
|
||||
/// An OnChangeHandle is returned by the onChange method to uniquely identify an
|
||||
/// onDelete callback
|
||||
using OnDeleteHandle = uint32_t;
|
||||
|
||||
/// This OnChangeHandle can be used to remove all onChange callbacks from this
|
||||
/// Property
|
||||
static OnChangeHandle OnChangeHandleAll;
|
||||
@@ -114,7 +118,7 @@ public:
|
||||
* The destructor taking care of deallocating all unused memory. This method will not
|
||||
* remove the Property from the PropertyOwner.
|
||||
*/
|
||||
virtual ~Property() = default;
|
||||
virtual ~Property();
|
||||
|
||||
/**
|
||||
* This method returns the class name of the Property. The method is used by the
|
||||
@@ -198,6 +202,14 @@ public:
|
||||
*/
|
||||
virtual bool getStringValue(std::string& value) const;
|
||||
|
||||
/**
|
||||
* This method encodes the encapsulated value of this Property as a
|
||||
* <code>std::string</code>.
|
||||
* \return the string value
|
||||
* \throws an exception if value couldn't be fetched
|
||||
*/
|
||||
std::string getStringValue() const;
|
||||
|
||||
/**
|
||||
* This method sets the value encapsulated by this Property by deserializing the
|
||||
* passed <code>std::string</code>. The specific details of the deserialization are up
|
||||
@@ -222,6 +234,14 @@ public:
|
||||
*/
|
||||
OnChangeHandle onChange(std::function<void()> callback);
|
||||
|
||||
/**
|
||||
* This method registers a <code>callback</code> function that will be called when
|
||||
* the property is destructed.
|
||||
* \pre The callback must not be empty
|
||||
* \return An OnDeleteHandle that can be used in subsequent calls to remove a callback
|
||||
*/
|
||||
OnDeleteHandle onDelete(std::function<void()> callback);
|
||||
|
||||
/**
|
||||
* This method deregisters a callback that was previously registered with the onChange
|
||||
* method. If OnChangeHandleAll is passed to this function, all registered callbacks
|
||||
@@ -233,6 +253,16 @@ public:
|
||||
*/
|
||||
void removeOnChange(OnChangeHandle handle);
|
||||
|
||||
/**
|
||||
* This method deregisters a callback that was previously registered with the onDelete
|
||||
* method.
|
||||
* \param handle An OnDeleteHandle that was returned from a previous call to onDelete
|
||||
* by this property.
|
||||
* \pre handle must refer to a callback that has been previously registred
|
||||
* \pre handle must refer to a callback that has not been removed previously
|
||||
*/
|
||||
void removeOnDelete(OnDeleteHandle handle);
|
||||
|
||||
/**
|
||||
* This method returns the unique identifier of this Property.
|
||||
* \return The unique identifier of this Property
|
||||
@@ -365,6 +395,18 @@ public:
|
||||
*/
|
||||
const ghoul::Dictionary& metaData() const;
|
||||
|
||||
/**
|
||||
* Convert the Property into a string containing a JSON representation of the Property.
|
||||
* Includes description of the object.
|
||||
* @return the JSON string
|
||||
*/
|
||||
virtual std::string toJson() const;
|
||||
|
||||
/**
|
||||
* Get a valid JSON formatted representation of the Property's value.
|
||||
* @return the value in a json compatible format
|
||||
*/
|
||||
virtual std::string jsonValue() const;
|
||||
|
||||
/// Interpolation methods
|
||||
virtual void setInterpolationTarget(ghoul::any value);
|
||||
@@ -374,12 +416,6 @@ public:
|
||||
virtual void interpolateValue(float t,
|
||||
ghoul::EasingFunc<float> easingFunction = nullptr);
|
||||
|
||||
protected:
|
||||
static const char* IdentifierKey;
|
||||
static const char* NameKey;
|
||||
static const char* TypeKey;
|
||||
static const char* MetaDataKey;
|
||||
|
||||
/**
|
||||
* Creates the information that is general to every Property and adds the
|
||||
* <code>Identifier</code>, <code>Name</code>, <code>Type</code>, and
|
||||
@@ -388,16 +424,16 @@ protected:
|
||||
* class wants to add meta data that is not curated by the Property class
|
||||
* \return The base description common to all Property classes
|
||||
*/
|
||||
std::string generateBaseDescription() const;
|
||||
std::string generateBaseJsonDescription() const;
|
||||
|
||||
/**
|
||||
* Creates the information for the <code>MetaData</code> key-part of the Lua
|
||||
* Creates the information for the <code>MetaData</code> key-part of the json
|
||||
* description for the Property. The result can be included as one key-value pair in
|
||||
* the description text generated by subclasses. Only the metadata curated by the
|
||||
* Property class is used in this method.
|
||||
* \return The metadata information text for the property
|
||||
*/
|
||||
virtual std::string generateMetaDataDescription() const;
|
||||
virtual std::string generateMetaDataJsonDescription() const;
|
||||
|
||||
/**
|
||||
* Creates the information that is specific to each subclass of Property%s. If a
|
||||
@@ -410,13 +446,23 @@ protected:
|
||||
* and this method being the override points to customize the behavior.
|
||||
* \return The information specific to each subclass of Property
|
||||
*/
|
||||
virtual std::string generateAdditionalDescription() const;
|
||||
virtual std::string generateAdditionalJsonDescription() const;
|
||||
|
||||
protected:
|
||||
|
||||
static const char* IdentifierKey;
|
||||
static const char* NameKey;
|
||||
static const char* TypeKey;
|
||||
static const char* DescriptionKey;
|
||||
static const char* JsonValueKey;
|
||||
static const char* MetaDataKey;
|
||||
static const char* AdditionalDataKey;
|
||||
|
||||
/**
|
||||
* This method must be called by all subclasses whenever the encapsulated value has
|
||||
* changed and a potential listener has to be informed.
|
||||
* changed and potential listeners need to be informed.
|
||||
*/
|
||||
void notifyListener();
|
||||
void notifyChangeListeners();
|
||||
|
||||
/// The PropetyOwner this Property belongs to, or <code>nullptr</code>
|
||||
PropertyOwner* _owner;
|
||||
@@ -436,7 +482,12 @@ protected:
|
||||
/// The callback function sthat will be invoked whenever the value changes
|
||||
std::vector<std::pair<OnChangeHandle, std::function<void()>>> _onChangeCallbacks;
|
||||
|
||||
/// The callback function sthat will be invoked whenever the value changes
|
||||
std::vector<std::pair<OnDeleteHandle, std::function<void()>>> _onDeleteCallbacks;
|
||||
|
||||
private:
|
||||
void notifyDeleteListeners();
|
||||
|
||||
OnChangeHandle _currentHandleValue;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
|
||||
private:
|
||||
static const std::string OptionsKey;
|
||||
std::string generateAdditionalDescription() const override;
|
||||
std::string generateAdditionalJsonDescription() const override;
|
||||
|
||||
/// The list of options which have been registered with this OptionProperty
|
||||
std::vector<Option> _options;
|
||||
|
||||
@@ -178,7 +178,7 @@ template <typename T>
|
||||
void openspace::properties::TemplateProperty<T>::setValue(T val) {
|
||||
if (val != _value) {
|
||||
_value = std::move(val);
|
||||
notifyListener();
|
||||
notifyChangeListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ void TemplateProperty<T>::set(ghoul::any value) {
|
||||
T v = ghoul::any_cast<T>(std::move(value));
|
||||
if (v != _value) {
|
||||
_value = std::move(v);
|
||||
notifyListener();
|
||||
notifyChangeListeners();
|
||||
}
|
||||
}
|
||||
catch (ghoul::bad_any_cast&) {
|
||||
|
||||
@@ -65,6 +65,10 @@ public:
|
||||
* \param value The ignored value
|
||||
*/
|
||||
void set(ghoul::any value) override;
|
||||
|
||||
std::string toJson() const override;
|
||||
|
||||
std::string jsonValue() const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -47,14 +47,17 @@ public:
|
||||
glm::vec4 sample(size_t t);
|
||||
size_t width();
|
||||
void setCallback(TfChangedCallback callback);
|
||||
void setTextureFromTxt(std::shared_ptr<ghoul::opengl::Texture> ptr);
|
||||
private:
|
||||
void setTextureFromTxt();
|
||||
void setTextureFromTxt() {
|
||||
setTextureFromTxt(_texture);
|
||||
}
|
||||
void setTextureFromImage();
|
||||
void uploadTexture();
|
||||
|
||||
std::string _filepath;
|
||||
std::unique_ptr<ghoul::filesystem::File> _file = nullptr;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture = nullptr;
|
||||
std::shared_ptr<ghoul::opengl::Texture> _texture = nullptr;
|
||||
bool _needsUpdate = false;
|
||||
TfChangedCallback _tfChangedCallback;
|
||||
};
|
||||
|
||||
@@ -70,6 +70,7 @@ public:
|
||||
Histogram equalize();
|
||||
float equalize (float);
|
||||
float entropy();
|
||||
std::vector<char> getBinaryData() const;
|
||||
|
||||
float highestBinValue(bool equalized, int overBins=0);
|
||||
float binWidth();
|
||||
|
||||
@@ -25,8 +25,10 @@
|
||||
#ifndef __OPENSPACE_CORE___TIMEMANAGER___H__
|
||||
#define __OPENSPACE_CORE___TIMEMANAGER___H__
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <openspace/util/timeline.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/syncdata.h>
|
||||
@@ -35,6 +37,9 @@ namespace openspace {
|
||||
|
||||
class TimeManager {
|
||||
public:
|
||||
using CallbackHandle = int;
|
||||
using TimeChangeCallback = std::function<void()>;
|
||||
|
||||
Time& time();
|
||||
std::vector<Syncable*> getSyncables();
|
||||
void preSynchronization(double dt);
|
||||
@@ -45,6 +50,10 @@ public:
|
||||
void setTimeNextFrame(Time t);
|
||||
size_t nKeyframes() const;
|
||||
|
||||
CallbackHandle addTimeChangeCallback(TimeChangeCallback cb);
|
||||
CallbackHandle addDeltaTimeChangeCallback(TimeChangeCallback cb);
|
||||
void removeTimeChangeCallback(CallbackHandle handle);
|
||||
void removeDeltaTimeChangeCallback(CallbackHandle handle);
|
||||
private:
|
||||
bool _shouldSetTime = false;
|
||||
Time _timeNextFrame;
|
||||
@@ -52,6 +61,12 @@ private:
|
||||
SyncData<Time> _currentTime;
|
||||
void consumeKeyframes(double dt);
|
||||
double _latestConsumedTimestamp;
|
||||
int _nextCallbackHandle = 0;
|
||||
|
||||
std::vector<std::pair<CallbackHandle, TimeChangeCallback>> _timeChangeCallbacks;
|
||||
std::vector<std::pair<CallbackHandle, TimeChangeCallback>> _deltaTimeChangeCallbacks;
|
||||
double _lastTime = 0;
|
||||
double _lastDeltaTime = 0;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user