Skip to content
Snippets Groups Projects
Commit 4f71382d authored by Vanessa Karolek's avatar Vanessa Karolek
Browse files

[#60] handle reconnecting gamepad

Currently, only the first window is referenced.... If we use more windows, we need to know how to handle this. Maybe we have to bind a gamepadIndex to a specific window.
parent b7880a77
No related branches found
No related tags found
1 merge request!65Resolve "Kamera - Steuerung mittels Controller"
Pipeline #25889 passed
...@@ -74,6 +74,13 @@ namespace vkcv { ...@@ -74,6 +74,13 @@ namespace vkcv {
*/ */
static void onCharEvent(GLFWwindow *callbackWindow, unsigned int c); static void onCharEvent(GLFWwindow *callbackWindow, unsigned int c);
/**
* @brief A callback function for handling gamepad re-connection.
* @param gamepadIndex The gamepad index.
* @param gamepadEvent The gamepad connection event.
*/
static void onGamepadConnection(int gamepadIndex, int gamepadEvent);
/** /**
* @brief A callback function for gamepad input events. * @brief A callback function for gamepad input events.
* @param gamepadIndex The gamepad index. * @param gamepadIndex The gamepad index.
......
...@@ -23,7 +23,7 @@ namespace vkcv { ...@@ -23,7 +23,7 @@ namespace vkcv {
glfwSetScrollCallback(m_window, Window::onMouseScrollEvent); glfwSetScrollCallback(m_window, Window::onMouseScrollEvent);
glfwSetCharCallback(m_window, Window::onCharEvent); glfwSetCharCallback(m_window, Window::onCharEvent);
glfwSetJoystickCallback(nullptr); glfwSetJoystickCallback(Window::onGamepadConnection);
glfwSetJoystickUserPointer(GLFW_JOYSTICK_1, this); glfwSetJoystickUserPointer(GLFW_JOYSTICK_1, this);
} }
...@@ -127,6 +127,16 @@ namespace vkcv { ...@@ -127,6 +127,16 @@ namespace vkcv {
} }
} }
void Window::onGamepadConnection(int gamepadIndex, int gamepadEvent) {
if (gamepadEvent == GLFW_CONNECTED) {
auto window = static_cast<Window *>(glfwGetWindowUserPointer(s_Windows[0])); // todo check for correct window
if (window != nullptr) {
glfwSetJoystickUserPointer(gamepadIndex, window);
}
}
}
void Window::onGamepadEvent(int gamepadIndex) { void Window::onGamepadEvent(int gamepadIndex) {
auto window = static_cast<Window *>(glfwGetJoystickUserPointer(gamepadIndex)); auto window = static_cast<Window *>(glfwGetJoystickUserPointer(gamepadIndex));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment