refactor(input): elimina InputState vestigial
This commit is contained in:
1 parent
fd3da8cb99
commit
80140434e7
6 files changed
+14
-119
No files matched your search
@@ -14,9 +14,8 @@
|
||||
//
|
||||
// El polling real de botons i eixos NO es fa a través d'aquesta classe:
|
||||
// els consumidors obtenen el `SDL_Gamepad*` primari (o l'enèsim per a
|
||||
// multi-jugador futur) i el passen a `InputState::getGamepadButton/Axis`,
|
||||
// que ho filtra pel flag de bloqueig de la UI (mateixa estratègia que
|
||||
// amb el teclat).
|
||||
// multi-jugador futur) i el passen directament a
|
||||
// `SDL_GetGamepadButton`/`SDL_GetGamepadAxis`.
|
||||
class GamepadManager {
|
||||
public:
|
||||
static auto get() -> GamepadManager&;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "core/input/input_state.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
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<bool, SDL_SCANCODE_COUNT> 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<Sint16>(0) : SDL_GetGamepadAxis(gp, ax);
|
||||
}
|
||||
|
||||
} // namespace InputState
|
||||
@@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Wrapper de l'estat d'input (polling) amb gating de bloqueig.
|
||||
//
|
||||
// El service menu (i qualsevol UI modal futura) ha de poder "amagar" l'estat
|
||||
// d'entrada als consumidors de polling — el jugador, entitats controlades
|
||||
// per l'usuari, etc. — mentre la UI captura l'atenció, sense interrompre la
|
||||
// resta del joc. Per això tots els consumidors de polling han de llegir a
|
||||
// través d'aquest mòdul i no cridar `SDL_GetKeyboardState` directament. Si
|
||||
// `setBlocked(true)` està actiu, el wrapper retorna un buffer tot-a-zero;
|
||||
// altrament, la crida és transparent (mateix pointer que SDL).
|
||||
//
|
||||
// El menú NO passa per aquí: consumeix events (`SDL_EVENT_KEY_DOWN`) abans
|
||||
// que l'escena els vegi, així que la seva navegació segueix funcionant per
|
||||
// molt que el flag estigui posat.
|
||||
//
|
||||
// El mateix patró aplica al gamepad: `getGamepadButton`/`getGamepadAxis`
|
||||
// retornen zero/false quan el bloqueig és actiu. Els mandos concrets els
|
||||
// obtén el caller via `GamepadManager::get().getPrimary()` o similars.
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace InputState {
|
||||
|
||||
// Activa/desactiva el bloqueig global de polling. El ServiceMenu el
|
||||
// crida a `toggle()`/`close()`. No es toca des de cap altre lloc.
|
||||
void setBlocked(bool value);
|
||||
|
||||
[[nodiscard]] auto isBlocked() -> bool;
|
||||
|
||||
// Equivalent a `SDL_GetKeyboardState(nullptr)`: retorna un buffer de
|
||||
// `SDL_SCANCODE_COUNT` bools. Si l'input està bloquejat, tots zero —
|
||||
// el consumidor veu com si cap tecla estigués premuda, sense branques
|
||||
// explícites. El buffer és estable mentre dura la sessió; no cal
|
||||
// guardar-lo frame a frame.
|
||||
[[nodiscard]] auto getKeyboardState() -> const bool*;
|
||||
|
||||
// Versió filtrada de `SDL_GetGamepadButton`. Retorna false si el bloqueig
|
||||
// és actiu o si `gp` és nullptr (cas habitual: no hi ha cap mand).
|
||||
[[nodiscard]] auto getGamepadButton(SDL_Gamepad* gp, SDL_GamepadButton b) -> bool;
|
||||
|
||||
// Versió filtrada de `SDL_GetGamepadAxis`. Retorna 0 si el bloqueig
|
||||
// és actiu o si `gp` és nullptr.
|
||||
[[nodiscard]] auto getGamepadAxis(SDL_Gamepad* gp, SDL_GamepadAxis ax) -> Sint16;
|
||||
|
||||
} // namespace InputState
|
||||
Reference in new issue
Block a user