mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-25 13:58:55 -05:00
begin refactor parallel connection
This commit is contained in:
@@ -47,107 +47,6 @@ class SceneGraphNode;
|
||||
namespace interaction {
|
||||
|
||||
|
||||
//#define USE_OLD_INTERACTIONHANDLER
|
||||
#ifdef USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
class InteractionHandler : public properties::PropertyOwner {
|
||||
public:
|
||||
InteractionHandler();
|
||||
~InteractionHandler();
|
||||
|
||||
// Mutators
|
||||
void setKeyboardController(KeyboardController* controller);
|
||||
void setMouseController(MouseController* controller);
|
||||
void setFocusNode(SceneGraphNode* node);
|
||||
void setCamera(Camera* camera);
|
||||
void setInteractionSensitivity(float sensitivity);
|
||||
void resetKeyBindings();
|
||||
void setInvertRoll(bool invert);
|
||||
void setInvertRotation(bool invert);
|
||||
|
||||
void addController(Controller* controller);
|
||||
void addKeyframe(const network::datamessagestructures::PositionKeyframe &kf);
|
||||
void clearKeyframes();
|
||||
|
||||
void bindKey(Key key, KeyModifier modifier, std::string lua);
|
||||
|
||||
void lockControls();
|
||||
void unlockControls();
|
||||
|
||||
void update(double deltaTime);
|
||||
|
||||
// Accessors
|
||||
const SceneGraphNode* const focusNode() const;
|
||||
const Camera* const camera() const;
|
||||
double deltaTime() const;
|
||||
float interactionSensitivity() const;
|
||||
bool invertRoll() const;
|
||||
bool invertRotation() const;
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
* interaction. The functions contained are
|
||||
* - openspace::luascriptfunctions::setOrigin
|
||||
* \return The Lua library that contains all Lua functions available to affect the
|
||||
* interaction
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
|
||||
// Callback functions
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
void mouseButtonCallback(MouseButton button, MouseAction action);
|
||||
void mousePositionCallback(double x, double y);
|
||||
void mouseScrollWheelCallback(double pos);
|
||||
|
||||
// Interaction functions
|
||||
void orbitDelta(const glm::quat& rotation);
|
||||
void orbit(const float &dx, const float &dy, const float &dz, const float &dist);
|
||||
void rotateDelta(const glm::quat& rotation);
|
||||
void distanceDelta(const PowerScaledScalar& distance, size_t iterations = 0);
|
||||
void lookAt(const glm::quat& rotation);
|
||||
void setRotation(const glm::quat& rotation);
|
||||
|
||||
|
||||
private:
|
||||
// Remove copy and move constructors
|
||||
InteractionHandler(const InteractionHandler&) = delete;
|
||||
InteractionHandler& operator=(const InteractionHandler&) = delete;
|
||||
InteractionHandler(InteractionHandler&&) = delete;
|
||||
InteractionHandler& operator=(InteractionHandler&&) = delete;
|
||||
|
||||
// Settings
|
||||
float _controllerSensitivity;
|
||||
bool _invertRoll;
|
||||
bool _invertRotation;
|
||||
|
||||
// Pointers to entities to affect
|
||||
Camera* _camera;
|
||||
SceneGraphNode* _focusNode;
|
||||
|
||||
// Cached data
|
||||
double _deltaTime;
|
||||
std::mutex _mutex;
|
||||
|
||||
//bool _validKeyLua;
|
||||
std::multimap<KeyWithModifier, std::string > _keyLua;
|
||||
|
||||
|
||||
KeyboardController* _keyboardController;
|
||||
MouseController* _mouseController;
|
||||
std::vector<Controller*> _controllers;
|
||||
|
||||
properties::StringProperty _origin;
|
||||
properties::StringProperty _coordinateSystem;
|
||||
|
||||
//remote controller
|
||||
std::vector<network::datamessagestructures::PositionKeyframe> _keyframes;
|
||||
double _currentKeyframeTime;
|
||||
std::mutex _keyframeMutex;
|
||||
};
|
||||
|
||||
#else // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
class InteractionHandler : public properties::PropertyOwner
|
||||
{
|
||||
public:
|
||||
@@ -165,7 +64,7 @@ public:
|
||||
|
||||
void resetKeyBindings();
|
||||
|
||||
void addKeyframe(const network::datamessagestructures::PositionKeyframe &kf);
|
||||
void addKeyframe(const network::datamessagestructures::CameraKeyframe &kf);
|
||||
void clearKeyframes();
|
||||
|
||||
void bindKey(Key key, KeyModifier modifier, std::string lua);
|
||||
@@ -232,8 +131,6 @@ private:
|
||||
properties::FloatProperty _rapidness;
|
||||
};
|
||||
|
||||
#endif // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace interaction {
|
||||
void mouseScrollWheelCallback(double mouseScrollDelta);
|
||||
|
||||
// Mutators
|
||||
void addKeyframe(const network::datamessagestructures::PositionKeyframe &kf);
|
||||
void addKeyframe(const network::datamessagestructures::CameraKeyframe &kf);
|
||||
void clearKeyframes();
|
||||
|
||||
// Accessors
|
||||
@@ -64,7 +64,7 @@ namespace interaction {
|
||||
const std::list<MouseButton>& getPressedMouseButtons() const;
|
||||
glm::dvec2 getMousePosition() const;
|
||||
double getMouseScrollDelta() const;
|
||||
std::vector<network::datamessagestructures::PositionKeyframe>& getKeyFrames() const;
|
||||
std::vector<network::datamessagestructures::CameraKeyframe>& getKeyFrames() const;
|
||||
|
||||
bool isKeyPressed(std::pair<Key, KeyModifier> keyModPair) const;
|
||||
bool isMouseButtonPressed(MouseButton mouseButton) const;
|
||||
@@ -76,8 +76,7 @@ namespace interaction {
|
||||
double _mouseScrollDelta;
|
||||
|
||||
// Remote input via keyframes
|
||||
std::vector<network::datamessagestructures::PositionKeyframe> _keyframes;
|
||||
std::mutex _keyframeMutex;
|
||||
std::vector<network::datamessagestructures::CameraKeyframe> _keyframes;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -33,33 +33,38 @@
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
//openspace includes
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/camera.h>
|
||||
|
||||
namespace openspace{
|
||||
|
||||
namespace network{
|
||||
|
||||
namespace datamessagestructures{
|
||||
enum type{
|
||||
PositionData = 0,
|
||||
namespace datamessagestructures {
|
||||
enum class Type : uint32_t {
|
||||
CameraData = 0,
|
||||
TimeData,
|
||||
ScriptData
|
||||
};
|
||||
|
||||
struct PositionKeyframe{
|
||||
glm::quat _viewRotationQuat;
|
||||
psc _position;
|
||||
double _timeStamp;
|
||||
|
||||
struct CameraKeyframe {
|
||||
CameraKeyframe() {}
|
||||
CameraKeyframe(const std::vector<char> &buffer) {
|
||||
deserialize(buffer);
|
||||
}
|
||||
|
||||
glm::dvec3 _position;
|
||||
glm::dquat _rotation;
|
||||
double _timestamp;
|
||||
|
||||
void serialize(std::vector<char> &buffer){
|
||||
//add position
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_position), reinterpret_cast<char*>(&_position) + sizeof(_position));
|
||||
|
||||
//add orientation
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_viewRotationQuat), reinterpret_cast<char*>(&_viewRotationQuat) + sizeof(_viewRotationQuat));
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_rotation), reinterpret_cast<char*>(&_rotation) + sizeof(_rotation));
|
||||
|
||||
//add timestamp
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_timeStamp), reinterpret_cast<char*>(&_timeStamp) + sizeof(_timeStamp));
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_timestamp), reinterpret_cast<char*>(&_timestamp) + sizeof(_timestamp));
|
||||
};
|
||||
|
||||
void deserialize(const std::vector<char> &buffer){
|
||||
@@ -72,17 +77,21 @@ namespace openspace{
|
||||
offset += size;
|
||||
|
||||
//orientation
|
||||
size = sizeof(_viewRotationQuat);
|
||||
memcpy(&_viewRotationQuat, buffer.data() + offset, size);
|
||||
size = sizeof(_rotation);
|
||||
memcpy(&_rotation, buffer.data() + offset, size);
|
||||
offset += size;
|
||||
|
||||
//timestamp
|
||||
size = sizeof(_timeStamp);
|
||||
memcpy(&_timeStamp, buffer.data() + offset, size);
|
||||
size = sizeof(_timestamp);
|
||||
memcpy(&_timestamp, buffer.data() + offset, size);
|
||||
};
|
||||
};
|
||||
|
||||
struct TimeKeyframe{
|
||||
struct TimeKeyframe {
|
||||
TimeKeyframe() {}
|
||||
TimeKeyframe(const std::vector<char> &buffer) {
|
||||
deserialize(buffer);
|
||||
}
|
||||
|
||||
double _time;
|
||||
double _dt;
|
||||
@@ -128,31 +137,20 @@ namespace openspace{
|
||||
};
|
||||
};
|
||||
|
||||
struct ScriptMessage{
|
||||
|
||||
uint16_t _scriptlen;
|
||||
struct ScriptMessage {
|
||||
ScriptMessage() {}
|
||||
ScriptMessage(const std::vector<char> &buffer) {
|
||||
deserialize(buffer);
|
||||
}
|
||||
|
||||
std::string _script;
|
||||
|
||||
void serialize(std::vector<char> &buffer){
|
||||
//add script length
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_scriptlen), reinterpret_cast<char*>(&_scriptlen) + sizeof(_scriptlen));
|
||||
|
||||
//add script
|
||||
buffer.insert(buffer.end(), _script.begin(), _script.end());
|
||||
|
||||
};
|
||||
|
||||
void deserialize(const std::vector<char> &buffer){
|
||||
int offset = 0;
|
||||
int size = 0;
|
||||
|
||||
//size of script
|
||||
size = sizeof(uint16_t);
|
||||
memcpy(&_scriptlen, buffer.data() + offset, size);
|
||||
offset += size;
|
||||
|
||||
//actual script
|
||||
_script.assign(buffer.begin() + offset, buffer.end());
|
||||
_script.assign(buffer.begin(), buffer.end());
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@
|
||||
//std includes
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <sstream>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <condition_variable>
|
||||
@@ -63,6 +63,35 @@ namespace openspace{
|
||||
|
||||
namespace network{
|
||||
|
||||
enum class MessageType : uint32_t {
|
||||
Authentication = 0,
|
||||
Data,
|
||||
HostInformation,
|
||||
HostshipRequest,
|
||||
HostshipResignation
|
||||
};
|
||||
|
||||
struct Message {
|
||||
Message() {};
|
||||
Message(MessageType t, const std::vector<char>& c)
|
||||
: type(t)
|
||||
, content(c)
|
||||
{};
|
||||
|
||||
MessageType type;
|
||||
std::vector<char> content;
|
||||
};
|
||||
|
||||
struct DataMessage {
|
||||
DataMessage() {};
|
||||
DataMessage(network::datamessagestructures::Type t, const std::vector<char>& c)
|
||||
: type(t)
|
||||
, content(c)
|
||||
{};
|
||||
network::datamessagestructures::Type type;
|
||||
std::vector<char> content;
|
||||
};
|
||||
|
||||
class ParallelConnection{
|
||||
public:
|
||||
|
||||
@@ -82,24 +111,19 @@ namespace openspace{
|
||||
|
||||
void requestHostship(const std::string &password);
|
||||
|
||||
void resignHostship();
|
||||
|
||||
void setPassword(const std::string &password);
|
||||
|
||||
void signalDisconnect();
|
||||
|
||||
void preSynchronization();
|
||||
|
||||
void sendScript(const std::string& script);
|
||||
|
||||
void scriptMessage(const std::string propIdentifier, const std::string propValue);
|
||||
//void scriptMessage(const std::string propIdentifier, const std::string propValue);
|
||||
|
||||
enum MessageTypes{
|
||||
Authentication=0,
|
||||
Initialization,
|
||||
Data,
|
||||
Script, //obsolete now
|
||||
HostInfo,
|
||||
InitializationRequest,
|
||||
HostshipRequest,
|
||||
InitializationCompleted
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
@@ -114,28 +138,15 @@ namespace openspace{
|
||||
|
||||
private:
|
||||
//@TODO change this into the ghoul hasher for client AND server
|
||||
uint32_t hash(const std::string &val){
|
||||
uint32_t hashVal = 0, i;
|
||||
size_t len = val.length();
|
||||
|
||||
for (hashVal = i = 0; i < len; ++i){
|
||||
hashVal += val.c_str()[i];
|
||||
hashVal += (hashVal << 10);
|
||||
hashVal ^= (hashVal >> 6);
|
||||
}
|
||||
|
||||
hashVal += (hashVal << 3);
|
||||
hashVal ^= (hashVal >> 11);
|
||||
hashVal += (hashVal << 15);
|
||||
|
||||
return hashVal;
|
||||
};
|
||||
|
||||
void queueMessage(std::vector<char> message);
|
||||
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 writeHeader(std::vector<char> &buffer, uint32_t messageType);
|
||||
|
||||
void closeSocket();
|
||||
|
||||
@@ -147,26 +158,18 @@ namespace openspace{
|
||||
|
||||
void listenCommunication();
|
||||
|
||||
void delegateDecoding(uint32_t type);
|
||||
void handleMessage(const Message&);
|
||||
|
||||
void initializationMessageReceived();
|
||||
void dataMessageReceived(const std::vector<char>& messageContent);
|
||||
|
||||
void dataMessageReceived();
|
||||
|
||||
void hostInfoMessageReceived();
|
||||
void hostInfoMessageReceived(const std::vector<char>& messageContent);
|
||||
|
||||
void initializationRequestMessageReceived();
|
||||
|
||||
void broadcast();
|
||||
|
||||
int headerSize();
|
||||
|
||||
int receiveData(_SOCKET & socket, std::vector<char> &buffer, int length, int flags);
|
||||
|
||||
void sendFunc();
|
||||
|
||||
bool parseHints(addrinfo &info);
|
||||
|
||||
void threadManagement();
|
||||
|
||||
std::string scriptFromPropertyAndValue(const std::string property, const std::string value);
|
||||
@@ -176,24 +179,27 @@ namespace openspace{
|
||||
std::string _address;
|
||||
std::string _name;
|
||||
_SOCKET _clientSocket;
|
||||
std::thread *_connectionThread;
|
||||
std::thread *_broadcastThread;
|
||||
std::thread *_sendThread;
|
||||
std::thread *_listenThread;
|
||||
std::thread *_handlerThread;
|
||||
std::unique_ptr<std::thread> _connectionThread;
|
||||
std::unique_ptr<std::thread> _broadcastThread;
|
||||
std::unique_ptr<std::thread> _sendThread;
|
||||
std::unique_ptr<std::thread> _listenThread;
|
||||
std::unique_ptr<std::thread> _handlerThread;
|
||||
std::atomic<bool> _isHost;
|
||||
std::atomic<bool> _isConnected;
|
||||
std::atomic<bool> _performDisconnect;
|
||||
std::atomic<bool> _isRunning;
|
||||
std::atomic<bool> _tryConnect;
|
||||
std::atomic<bool> _disconnect;
|
||||
std::atomic<bool> _initializationTimejumpRequired;
|
||||
|
||||
std::condition_variable _disconnectCondition;
|
||||
std::mutex _disconnectMutex;
|
||||
|
||||
std::vector<std::vector<char>> _sendBuffer;
|
||||
std::mutex _sendBufferMutex;
|
||||
std::condition_variable _sendCondition;
|
||||
std::deque<Message> _sendBuffer;
|
||||
std::mutex _sendBufferMutex;
|
||||
|
||||
std::deque<Message> _receiveBuffer;
|
||||
std::mutex _receiveBufferMutex;
|
||||
|
||||
network::datamessagestructures::TimeKeyframe _latestTimeKeyframe;
|
||||
std::mutex _timeKeyframeMutex;
|
||||
|
||||
Reference in New Issue
Block a user