Skip to main content

GLFWGamepadLookup.ixx File

GLFW gamepad mapping helpers. More...

Included Headers

#include <GLFW/glfw3.h> #include <array> #include <bit> #include <helios.input.types.Gamepad>

Namespaces Index

namespacehelios
namespaceext

Platform-specific extensions and backend implementations. More...

namespaceglfw

GLFW-specific implementations. More...

namespaceinput

GLFW input handling. More...

namespaceGLFWGamepadLookup

Description

GLFW gamepad mapping helpers.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file GLFWGamepadLookup.ixx
3 * @brief GLFW gamepad mapping helpers.
4 */
5module;
6
7#include <GLFW/glfw3.h>
8#include <array>
9#include <bit>
10
11export module helios.ext.glfw.input.GLFWGamepadLookup;
12
13import helios.input.types.Gamepad;
14
16
17 /**
18 * @brief Internal method to safely compute an array index for the specified gamepadId,
19 * adhering to the logic arrayIndex = log_2(gamepadId)
20 *
21 * @param gamepadId The gamepadId for which the array index should be returned.
22 *
23 * @return the array index for the specified gamepadId.
24 */
25 constexpr unsigned int toArrayIndex(const helios::input::types::Gamepad gamepadId) noexcept {
26 return std::bit_width(static_cast<unsigned int>(gamepadId))-1;
27 }
28
29
30 /**
31 * @brief Provides a lookup for converting helios gamepad ids glfw-specific gamepad ids.
32 *
33 * @param gamepadId The helios gamepad id to map to the gamepad ids registered by GLFW
34 *
35 * @return A gamepad-id in glfw space.
36 */
37 inline int from(const helios::input::types::Gamepad gamepadId) noexcept {
38
39 static constexpr std::array<int, helios::input::types::Gamepad::size_> HELIOS_GAMEPAD_TO_GLFW=[] {
40 std::array<int, helios::input::types::Gamepad::size_> map{};
41
46
47 return map;
48 }();
49
50 return HELIOS_GAMEPAD_TO_GLFW[toArrayIndex(gamepadId)];
51 }
52
53}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.