mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Move joystick input states to interactionhandler
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/settings.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/joystickinputstate.h>
|
||||
#include <openspace/util/progressbar.h>
|
||||
#include <openspace/util/task.h>
|
||||
@@ -240,7 +241,7 @@ void checkJoystickStatus() {
|
||||
for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; i++) {
|
||||
ZoneScopedN("Joystick state");
|
||||
|
||||
JoystickInputState& state = global::joystickInputStates->at(i);
|
||||
JoystickInputState& state = global::interactionHandler->joystickInputStates().at(i);
|
||||
|
||||
const int present = glfwJoystickPresent(i);
|
||||
if (present == GLFW_FALSE) {
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace ghoul::fontrendering { class FontManager; }
|
||||
namespace openspace {
|
||||
|
||||
namespace interaction {
|
||||
struct JoystickInputStates;
|
||||
class ActionManager;
|
||||
class InteractionHandler;
|
||||
class KeybindingManager;
|
||||
@@ -91,7 +90,6 @@ inline WindowDelegate* windowDelegate;
|
||||
inline Configuration* configuration;
|
||||
inline interaction::ActionManager* actionManager;
|
||||
inline interaction::InteractionHandler* interactionHandler;
|
||||
inline interaction::JoystickInputStates* joystickInputStates;
|
||||
inline interaction::KeybindingManager* keybindingManager;
|
||||
inline interaction::KeyframeRecordingHandler* keyframeRecording;
|
||||
inline interaction::NavigationHandler* navigationHandler;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/interaction/interactionmonitor.h>
|
||||
#include <openspace/interaction/joystickinputstate.h>
|
||||
#include <openspace/interaction/keyboardinputstate.h>
|
||||
#include <openspace/interaction/mouseinputstate.h>
|
||||
#include <openspace/interaction/websocketinputstate.h>
|
||||
@@ -56,6 +57,9 @@ public:
|
||||
WebsocketInputStates& websocketInputStates();
|
||||
const WebsocketInputStates& websocketInputStates() const;
|
||||
|
||||
JoystickInputStates& joystickInputStates();
|
||||
const JoystickInputStates& joystickInputStates() const;
|
||||
|
||||
bool disabledKeybindings() const;
|
||||
bool disabledMouse() const;
|
||||
bool disabledJoystick() const;
|
||||
@@ -74,12 +78,13 @@ public:
|
||||
*/
|
||||
void markInteraction();
|
||||
|
||||
void clearGlobalJoystickStates();
|
||||
void clearJoystickStates();
|
||||
|
||||
private:
|
||||
MouseInputState _mouseInputState;
|
||||
KeyboardInputState _keyboardInputState;
|
||||
WebsocketInputStates _websocketInputStates;
|
||||
JoystickInputStates _joystickInputStates;
|
||||
|
||||
// TODO: add joystick and websocket input state
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/imgui/include/imgui_include.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/joystickinputstate.h>
|
||||
|
||||
namespace {
|
||||
@@ -50,8 +51,12 @@ void GuiJoystickComponent::render() {
|
||||
_isEnabled = v;
|
||||
_isCollapsed = ImGui::IsWindowCollapsed();
|
||||
|
||||
for (size_t i = 0; i < global::joystickInputStates->size(); i++) {
|
||||
const JoystickInputState& state = global::joystickInputStates->at(i);
|
||||
JoystickInputStates joystickStates =
|
||||
global::interactionHandler->joystickInputStates();
|
||||
|
||||
for (size_t i = 0; i < joystickStates.size(); i++) {
|
||||
const JoystickInputState& state = joystickStates.at(i);
|
||||
|
||||
if (!state.isConnected) {
|
||||
continue;
|
||||
}
|
||||
@@ -86,8 +91,8 @@ void GuiJoystickComponent::render() {
|
||||
|
||||
ImGui::Text("%s", "Summed contributions");
|
||||
ImGui::Text("%s", "Axes");
|
||||
for (int i = 0; i < global::joystickInputStates->numAxes(); i++) {
|
||||
float f = global::joystickInputStates->axis("", i);
|
||||
for (int i = 0; i < joystickStates.numAxes(); i++) {
|
||||
float f = joystickStates.axis("", i);
|
||||
const std::string id = std::to_string(i) + "##" + "TotalAxis";
|
||||
ImGui::SliderFloat(
|
||||
id.c_str(),
|
||||
@@ -97,12 +102,12 @@ void GuiJoystickComponent::render() {
|
||||
);
|
||||
}
|
||||
ImGui::Text("%s", "Buttons");
|
||||
for (int i = 0; i < global::joystickInputStates->numButtons(); i++) {
|
||||
for (int i = 0; i < joystickStates.numButtons(); i++) {
|
||||
const std::string id = std::to_string(i) + "##" + "TotalButton";
|
||||
ImGui::RadioButton(
|
||||
id.c_str(),
|
||||
global::joystickInputStates->button("", i, JoystickAction::Press) ||
|
||||
global::joystickInputStates->button("", i, JoystickAction::Repeat)
|
||||
joystickStates.button("", i, JoystickAction::Press) ||
|
||||
joystickStates.button("", i, JoystickAction::Repeat)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/keybindingmanager.h>
|
||||
#include <openspace/interaction/keyframerecordinghandler.h>
|
||||
#include <openspace/interaction/joystickinputstate.h>
|
||||
#include <openspace/interaction/sessionrecordinghandler.h>
|
||||
#include <openspace/mission/missionmanager.h>
|
||||
#include <openspace/navigation/navigationhandler.h>
|
||||
@@ -94,7 +93,6 @@ namespace {
|
||||
sizeof(Configuration) +
|
||||
sizeof(interaction::ActionManager) +
|
||||
sizeof(interaction::InteractionHandler) +
|
||||
sizeof(interaction::JoystickInputStates) +
|
||||
sizeof(interaction::KeybindingManager) +
|
||||
sizeof(interaction::KeyframeRecordingHandler) +
|
||||
sizeof(interaction::NavigationHandler) +
|
||||
@@ -300,14 +298,6 @@ void create() {
|
||||
interactionHandler = new interaction::InteractionHandler;
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef WIN32
|
||||
joystickInputStates = new (currentPos) interaction::JoystickInputStates;
|
||||
ghoul_assert(joystickInputStates, "No joystickInputStates");
|
||||
currentPos += sizeof(interaction::JoystickInputStates);
|
||||
#else // ^^^ WIN32 / !WIN32 vvv
|
||||
joystickInputStates = new interaction::JoystickInputStates;
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef WIN32
|
||||
keybindingManager = new (currentPos) interaction::KeybindingManager;
|
||||
ghoul_assert(keybindingManager, "No keybindingManager");
|
||||
@@ -484,13 +474,6 @@ void destroy() {
|
||||
delete keybindingManager;
|
||||
#endif // WIN32
|
||||
|
||||
LDEBUGC("Globals", "Destroying 'JoystickInputStates'");
|
||||
#ifdef WIN32
|
||||
joystickInputStates->~JoystickInputStates();
|
||||
#else // ^^^ WIN32 / !WIN32 vvv
|
||||
delete joystickInputStates;
|
||||
#endif // WIN32
|
||||
|
||||
LDEBUGC("Globals", "Destroying 'InteractionHandler'");
|
||||
#ifdef WIN32
|
||||
interactionHandler->~InteractionHandler();
|
||||
|
||||
@@ -102,7 +102,7 @@ InteractionHandler::InteractionHandler()
|
||||
|
||||
_disableJoystickInputs.onChange([this]() {
|
||||
if (_disableJoystickInputs) {
|
||||
clearGlobalJoystickStates();
|
||||
clearJoystickStates();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -144,6 +144,14 @@ const WebsocketInputStates& InteractionHandler::websocketInputStates() const {
|
||||
return _websocketInputStates;
|
||||
}
|
||||
|
||||
JoystickInputStates& InteractionHandler::joystickInputStates() {
|
||||
return _joystickInputStates;
|
||||
}
|
||||
|
||||
const JoystickInputStates& InteractionHandler::joystickInputStates() const {
|
||||
return _joystickInputStates;
|
||||
}
|
||||
|
||||
bool InteractionHandler::disabledKeybindings() const {
|
||||
return _disableKeybindings;
|
||||
}
|
||||
@@ -230,10 +238,10 @@ void InteractionHandler::markInteraction() {
|
||||
_interactionMonitor.markInteraction();
|
||||
}
|
||||
|
||||
void InteractionHandler::clearGlobalJoystickStates() {
|
||||
void InteractionHandler::clearJoystickStates() {
|
||||
std::fill(
|
||||
global::joystickInputStates->begin(),
|
||||
global::joystickInputStates->end(),
|
||||
_joystickInputStates.begin(),
|
||||
_joystickInputStates.end(),
|
||||
JoystickInputState()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/joystickinputstate.h>
|
||||
#include <openspace/util/geodetic.h>
|
||||
#include <openspace/util/time.h>
|
||||
@@ -643,10 +644,13 @@ struct [[codegen::Dictionary(JoystickAxis)]] JoystickAxis {
|
||||
*/
|
||||
[[codegen::luawrap]] std::vector<std::string> listAllJoysticks() {
|
||||
using namespace openspace;
|
||||
std::vector<std::string> result;
|
||||
result.reserve(global::joystickInputStates->size());
|
||||
|
||||
for (const interaction::JoystickInputState& state : *global::joystickInputStates) {
|
||||
interaction::JoystickInputStates joysticks =
|
||||
global::interactionHandler->joystickInputStates();
|
||||
|
||||
std::vector<std::string> result;
|
||||
result.reserve(joysticks.size());
|
||||
for (const interaction::JoystickInputState& state : joysticks) {
|
||||
if (!state.name.empty()) {
|
||||
result.push_back(state.name);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <algorithm>
|
||||
@@ -182,7 +183,7 @@ void JoystickCameraStates::updateStateFromInput(
|
||||
for (int i = 0; i < nButtons; i++) {
|
||||
auto itRange = joystick->buttonMapping.equal_range(i);
|
||||
for (auto it = itRange.first; it != itRange.second; it++) {
|
||||
const bool active = global::joystickInputStates->button(
|
||||
const bool active = global::interactionHandler->joystickInputStates().button(
|
||||
joystickInputState.name,
|
||||
i,
|
||||
it->second.action
|
||||
@@ -267,7 +268,7 @@ void JoystickCameraStates::setAxisMapping(const std::string& joystickName,
|
||||
joystickMapping->axisMapping[axis].sensitivity = sensitivity;
|
||||
|
||||
joystickMapping->prevAxisValues[axis] =
|
||||
global::joystickInputStates->axis(joystickName, axis);
|
||||
global::interactionHandler->joystickInputStates().axis(joystickName, axis);
|
||||
}
|
||||
|
||||
void JoystickCameraStates::setAxisMappingProperty(const std::string& joystickName,
|
||||
@@ -296,7 +297,7 @@ void JoystickCameraStates::setAxisMappingProperty(const std::string& joystickNam
|
||||
joystickMapping->axisMapping[axis].isRemote = isRemote;
|
||||
|
||||
joystickMapping->prevAxisValues[axis] =
|
||||
global::joystickInputStates->axis(joystickName, axis);
|
||||
global::interactionHandler->joystickInputStates().axis(joystickName, axis);
|
||||
}
|
||||
|
||||
JoystickCameraStates::AxisInformation JoystickCameraStates::axisMapping(
|
||||
@@ -320,18 +321,18 @@ JoystickCameraStates::AxisInformation JoystickCameraStates::axisMapping(
|
||||
void JoystickCameraStates::setDeadzone(const std::string& joystickName, int axis,
|
||||
float deadzone)
|
||||
{
|
||||
Joystick* joystickMapping = findOrAddJoystickMapping(joystickName);
|
||||
if (!joystickMapping) {
|
||||
Joystick* joystick = findOrAddJoystickMapping(joystickName);
|
||||
if (!joystick) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the axis index is too big for the vector then resize it to have room
|
||||
if (axis >= static_cast<int>(joystickMapping->axisMapping.size())) {
|
||||
joystickMapping->axisMapping.resize(axis + 1);
|
||||
joystickMapping->prevAxisValues.resize(axis + 1);
|
||||
if (axis >= static_cast<int>(joystick->axisMapping.size())) {
|
||||
joystick->axisMapping.resize(axis + 1);
|
||||
joystick->prevAxisValues.resize(axis + 1);
|
||||
}
|
||||
|
||||
joystickMapping->axisMapping[axis].deadzone = deadzone;
|
||||
joystick->axisMapping[axis].deadzone = deadzone;
|
||||
}
|
||||
|
||||
float JoystickCameraStates::deadzone(const std::string& joystickName, int axis) const {
|
||||
|
||||
@@ -184,8 +184,17 @@ void OrbitalInputHandler::updateStatesFromInput(double deltaTime) {
|
||||
global::interactionHandler->keyboardInputState(),
|
||||
deltaTime
|
||||
);
|
||||
_joystickStates.updateStateFromInput(*global::joystickInputStates, deltaTime);
|
||||
_websocketStates.updateStateFromInput(global::interactionHandler->websocketInputStates(), deltaTime);
|
||||
|
||||
_joystickStates.updateStateFromInput(
|
||||
global::interactionHandler->joystickInputStates(),
|
||||
deltaTime
|
||||
);
|
||||
|
||||
_websocketStates.updateStateFromInput(
|
||||
global::interactionHandler->websocketInputStates(),
|
||||
deltaTime
|
||||
);
|
||||
|
||||
_scriptStates.updateStateFromInput(deltaTime);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user