#include "core/input/input_state.hpp" #include namespace InputState { namespace { bool blocked = false; // Buffer retornat quan el bloqueig és actiu. `SDL_GetKeyboardState` // retorna un pointer d'una mida igual a `SDL_SCANCODE_COUNT`; el // nostre buffer ha de ser com a mínim igual de gran perquè els // consumidors puguin indexar-lo amb qualsevol scancode sense // llegir fora de rang. auto zeroKeyboard() -> const bool* { static const std::array ZEROS{}; return ZEROS.data(); } } // namespace void setBlocked(bool value) { blocked = value; } auto isBlocked() -> bool { return blocked; } auto getKeyboardState() -> const bool* { return blocked ? zeroKeyboard() : SDL_GetKeyboardState(nullptr); } auto getGamepadButton(SDL_Gamepad* gp, SDL_GamepadButton b) -> bool { return (blocked || gp == nullptr) ? false : SDL_GetGamepadButton(gp, b); } auto getGamepadAxis(SDL_Gamepad* gp, SDL_GamepadAxis ax) -> Sint16 { return (blocked || gp == nullptr) ? static_cast(0) : SDL_GetGamepadAxis(gp, ax); } } // namespace InputState