From 9f80a278a6f188c8e9131df0684bad14a07491ee Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 21 Mar 2025 18:16:40 +0500 Subject: Toggles system rework, added flight pmove mode - Reworked toggles to use a constant-styled enumerations - Added TOGGLE_PM_FLIGHT and an according movement mode. Now server-side just doesn't simulate gravity altogether for players, instead relying on whatever the client provides which works fine for now. Closes #12 --- game/client/gamepad.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'game/client/gamepad.cc') diff --git a/game/client/gamepad.cc b/game/client/gamepad.cc index 73c60b6..b26dbb8 100644 --- a/game/client/gamepad.cc +++ b/game/client/gamepad.cc @@ -8,6 +8,7 @@ #include "client/glfw.hh" #include "client/globals.hh" #include "client/settings.hh" +#include "client/toggles.hh" constexpr static int INVALID_GAMEPAD_ID = INT_MAX; constexpr static std::size_t NUM_AXES = static_cast(GLFW_GAMEPAD_AXIS_LAST + 1); @@ -22,6 +23,24 @@ ConfigBoolean gamepad::active(false); GLFWgamepadstate gamepad::state; GLFWgamepadstate gamepad::last_state; +static void on_toggle_enable(const ToggleEnabledEvent &event) +{ + if(event.type == TOGGLE_USE_GAMEPAD) { + spdlog::info("KHUETA ENABLED"); + gamepad::active.set_value(true); + return; + } +} + +static void on_toggle_disable(const ToggleDisabledEvent &event) +{ + if(event.type == TOGGLE_USE_GAMEPAD) { + spdlog::info("KHUETA DISABLED"); + gamepad::active.set_value(false); + return; + } +} + static void on_glfw_joystick_event(const GlfwJoystickEvent &event) { if((event.event_type == GLFW_CONNECTED) && glfwJoystickIsGamepad(event.joystick_id) && (active_gamepad_id == INVALID_GAMEPAD_ID)) { @@ -92,6 +111,8 @@ void gamepad::init(void) for(int i = 0; i < NUM_AXES; gamepad::state.axes[i++] = 0.0f); for(int i = 0; i < NUM_BUTTONS; gamepad::state.buttons[i++] = GLFW_RELEASE); + globals::dispatcher.sink().connect<&on_toggle_enable>(); + globals::dispatcher.sink().connect<&on_toggle_disable>(); globals::dispatcher.sink().connect<&on_glfw_joystick_event>(); } -- cgit