From f185b2cee7bd03d5218ae99afed7d8bc783684ca Mon Sep 17 00:00:00 2001 From: Matthew Territo Date: Fri, 14 Sep 2018 15:54:57 -0600 Subject: [PATCH] Add lua script payload to flight controller. Access websocket sensitivity in orbitalnavigator --- .../include/topics/flightcontrollertopic.h | 1 + .../src/topics/flightcontrollertopic.cpp | 43 +++++++++++++------ src/interaction/orbitalnavigator.cpp | 5 +++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/modules/server/include/topics/flightcontrollertopic.h b/modules/server/include/topics/flightcontrollertopic.h index 56d0ac0bd0..bfaac7bbe1 100644 --- a/modules/server/include/topics/flightcontrollertopic.h +++ b/modules/server/include/topics/flightcontrollertopic.h @@ -64,6 +64,7 @@ private: void processInputState(const nlohmann::json& json); void setFocusNodes(); void changeFocus(const nlohmann::json& json); + void processLua(const nlohmann::json& json); void setFriction(const bool &on) const; }; diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index d85ba00547..ca44f17840 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -50,12 +51,13 @@ namespace { constexpr const char* BasePathToken = "${BASE}"; enum class Command { - Connect = 0, - Disconnect, - InputState, - ChangeFocus, - Autopilot, - Friction + Connect = 0 + , Disconnect + , InputState + , ChangeFocus + , Autopilot + , Friction + , Lua }; using AxisType = openspace::interaction::WebsocketCameraStates::AxisType; @@ -82,13 +84,15 @@ namespace { // Friction JSON Keys constexpr const char* FrictionEngagedKey = "engaged"; - constexpr const char* FrictionPropertyUri = "NavigationHandler.OrbitalNavigator.Friction"; - constexpr const char* RotationalFriction = "Friction.RotationalFriction"; constexpr const char* ZoomFriction = "Friction.ZoomFriction"; constexpr const char* RollFriction = "Friction.RollFriction"; + // Friction Lua Keys + constexpr const char* LuaKey = "lua"; + constexpr const char* LuaScript = "script"; + const std::string OrbitX = "orbitX"; const std::string OrbitY = "orbitY"; const std::string ZoomIn = "zoomIn"; @@ -106,6 +110,7 @@ namespace { const std::string ChangeFocus = "changeFocus"; const std::string Autopilot = "autopilot"; const std::string Friction = "friction"; + const std::string Lua = "lua"; const static std::unordered_map AxisIndexMap ({ {OrbitX, AxisType::OrbitX}, @@ -121,12 +126,13 @@ namespace { }); const static std::unordered_map CommandMap ({ - {Connect, Command::Connect}, - {Disconnect, Command::Disconnect}, - {InputState, Command::InputState}, - {ChangeFocus, Command::ChangeFocus}, - {Autopilot, Command::Autopilot}, - {Friction, Command::Friction} + {Connect, Command::Connect} + , {Disconnect, Command::Disconnect} + , {InputState, Command::InputState} + , {ChangeFocus, Command::ChangeFocus} + , {Autopilot, Command::Autopilot} + , {Friction, Command::Friction} + , {Lua, Command::Lua} }); const int Axes = 10; @@ -189,6 +195,9 @@ void FlightControllerTopic::handleJson(const nlohmann::json& json) { case Command::Friction: setFriction(json[Friction][FrictionEngagedKey]); break; + case Command::Lua: + processLua(json[Lua]); + break; default: LWARNING(fmt::format("Unrecognized action: {}", it->first)); break; @@ -343,4 +352,10 @@ void FlightControllerTopic::processInputState(const nlohmann::json& json) { _inputState.axes[std::distance(AxisIndexMap.begin(), mapIt)] = float(it.value()); } } + +void FlightControllerTopic::processLua(const nlohmann::json &json) { + const std::string script = json[LuaScript]; + global::scriptEngine.queueScript(script, openspace::scripting::ScriptEngine::RemoteScripting::Yes); +} + } // namespace openspace diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index 7e9a3158a1..ed23332540 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -225,6 +225,10 @@ OrbitalNavigator::OrbitalNavigator() _joystickSensitivity.onChange([&]() { _joystickStates.setSensitivity(_joystickSensitivity * pow(10.0, -4)); }); + _websocketSensitivity.onChange([&]() { + _websocketStates.setSensitivity(_websocketSensitivity); + }); + addPropertySubOwner(_friction); @@ -239,6 +243,7 @@ OrbitalNavigator::OrbitalNavigator() addProperty(_stereoInterpolationTime); addProperty(_mouseSensitivity); addProperty(_joystickSensitivity); + addProperty(_websocketSensitivity); } void OrbitalNavigator::updateStatesFromInput(const InputState& inputState,