17#include <glm/geometric.hpp>
18#include <glm/trigonometric.hpp>
19#include <glm/vec2.hpp>
65 .x = swapSticks ? SDL_GAMEPAD_AXIS_LEFTX : SDL_GAMEPAD_AXIS_RIGHTX,
66 .y = swapSticks ? SDL_GAMEPAD_AXIS_LEFTY : SDL_GAMEPAD_AXIS_RIGHTY,
74 .x = swapSticks ? SDL_GAMEPAD_AXIS_RIGHTX : SDL_GAMEPAD_AXIS_LEFTX,
75 .y = swapSticks ? SDL_GAMEPAD_AXIS_RIGHTY : SDL_GAMEPAD_AXIS_LEFTY,
93 constexpr glm::vec2 directions[3] = {
100 std::uint8_t bestIndex = 0;
101 float bestDot = glm::dot(aim, directions[0]);
102 for (std::uint8_t i = 1; i < 3; ++i) {
103 const float d = glm::dot(aim, directions[i]);
137 SDL_GetRelativeMouseState(&mdx, &mdy);
151 if (gravityFlipped) {
161 snap.
yaw -= mdx * mouseSensitivity;
164 snap.
yaw = std::remainder(snap.
yaw, glm::radians(360.0f));
167 snap.
pitch = std::clamp(snap.
pitch + mdy * mouseSensitivity, -glm::radians(89.0f), glm::radians(89.0f));
183 const bool*
const kKeys = SDL_GetKeyboardState(
nullptr);
184 const SDL_MouseButtonFlags mouse = SDL_GetMouseState(
nullptr,
nullptr);
204 snap.
left = gravityFlipped ? right : left;
205 snap.
right = gravityFlipped ? left : right;
224 const bool*
const kKeys = SDL_GetKeyboardState(
nullptr);
225 const SDL_MouseButtonFlags mouse = SDL_GetMouseState(
nullptr,
nullptr);
244 const bool*
const kKeys = SDL_GetKeyboardState(
nullptr);
245 const SDL_MouseButtonFlags mouse = SDL_GetMouseState(
nullptr,
nullptr);
249 const bool selectLeftNow = abilityMenuHeld && shootDown;
250 const bool selectRightNow = abilityMenuHeld && scopeDown;
277 const std::uint8_t grenadeSelectIndex =
281 snap.
shooting = shootDown && !abilityMenuHeld;
282 snap.
scoped = scopeDown && !abilityMenuHeld;
344 const float v = std::clamp(
static_cast<float>(raw) / 32767.0f, -1.0f, 1.0f);
345 if (std::fabs(v) < deadzone)
348 const float sign = v < 0.0f ? -1.0f : 1.0f;
349 return sign * (std::fabs(v) - deadzone) / (1.0f - deadzone);
373 float pitchSensitivity,
374 float yawSensitivity,
377 bool gravityFlipped =
false,
378 bool swapSticks =
false)
388 if (rx == 0.0f && ry == 0.0f)
391 if (gravityFlipped) {
400 snap.
yaw -= rx * yawSensitivity * dt;
401 snap.
yaw = std::remainder(snap.
yaw, glm::radians(360.0f));
405 snap.
pitch = std::clamp(snap.
pitch + ry * pitchSensitivity * dt, -glm::radians(89.0f), glm::radians(89.0f));
430 bool gravityFlipped =
false,
431 bool swapSticks =
false)
444 constexpr float moveThresh = 0.3f;
445 const bool padForward = ly < -moveThresh;
446 const bool padBack = ly > moveThresh;
448 const bool padLeft = gravityFlipped ? (lx > moveThresh) : (lx < -moveThresh);
449 const bool padRight = gravityFlipped ? (lx < -moveThresh) : (lx > moveThresh);
458 snap.
back |= padBack;
459 snap.
left |= padLeft;
460 snap.
right |= padRight;
461 snap.
jump |= padJump;
491 const bool selectLeftNow = abilityMenuHeld && padShoot;
492 const bool selectRightNow = abilityMenuHeld && padScope;
499 snap.
shooting |= padShoot && !abilityMenuHeld;
500 snap.
scoped |= padScope && !abilityMenuHeld;
Client side Tag component — entity is eligible to receive player input.
Marker component identifying the locally controlled player entity.
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
Component for tracking player respawn times.
Definition InputSampleSystem.hpp:320
constexpr float k_stickDeadzone
Stick deadzone as a fraction of full deflection.
Definition InputSampleSystem.hpp:327
float normaliseAxis(Sint16 raw, float deadzone=k_stickDeadzone)
Convert SDL's int16 axis value to a deadzoned float in [-1, 1].
Definition InputSampleSystem.hpp:339
constexpr float k_triggerThreshold
Trigger threshold for treating an analog trigger as "pressed".
Definition InputSampleSystem.hpp:333
Client-only input sampling system — split into two halves so mouse look can run every iterate() (smoo...
Definition DebugUI.hpp:15
void runGamepadLook(Registry ®istry, SDL_Gamepad *gamepad, float pitchSensitivity, float yawSensitivity, float deadzone, float dt, bool gravityFlipped=false, bool swapSticks=false)
Sample the right stick into yaw / pitch.
Definition InputSampleSystem.hpp:371
float grenadeHeldSeconds
Seconds the grenade key has been continuously held.
Definition InputSampleSystem.hpp:32
bool prevGrenadeKey
Tracks previous-frame G key state for grenade quick-throw / radial behavior.
Definition InputSampleSystem.hpp:30
void runGamepadDeadInput(Registry ®istry, SDL_Gamepad *gamepad, const InputBindings &bindings)
Sample controller skip-respawn input while the local player is dead.
Definition InputSampleSystem.hpp:516
constexpr float k_grenadeRadialHoldSeconds
Hold duration before the grenade quick-throw becomes radial selection.
Definition InputSampleSystem.hpp:40
void runGamepadMovement(Registry ®istry, SDL_Gamepad *gamepad, const InputBindings &bindings, float deadzone, bool gravityFlipped=false, bool swapSticks=false)
Sample gamepad buttons / left stick into the movement flags.
Definition InputSampleSystem.hpp:426
bool consumePendingGrenadeThrow()
Consume and clear the queued grenade quick-throw request.
Definition InputSampleSystem.hpp:113
JoystickAxis getMoveJoystickAxes(bool swapSticks)
Return the SDL axes used for movement, honoring the stick-swap setting.
Definition InputSampleSystem.hpp:71
bool prevGamepadAbilitySelectRight
Tracks previous-frame gamepad right ability-select chord for edge detection.
Definition InputSampleSystem.hpp:52
void runMouseLook(Registry ®istry, float mouseSensitivity, bool gravityFlipped=false)
Sample mouse delta and accumulate into yaw / pitch.
Definition InputSampleSystem.hpp:133
void runMovementKeys(Registry ®istry, const InputBindings &bindings, bool gravityFlipped=false)
Sample keyboard state into the movement flags.
Definition InputSampleSystem.hpp:181
bool grenadeRadialActive
True while the grenade radial selector is open.
Definition InputSampleSystem.hpp:34
std::uint8_t grenadeRadialIndexFromAim()
Convert the current grenade radial aim vector into a grenade slot index.
Definition InputSampleSystem.hpp:87
void runInputSample(Registry ®istry, const InputBindings &bindings, float mouseSensitivity=0.001f)
Legacy combined sampler — calls both runMouseLook and runMovementKeys.
Definition InputSampleSystem.hpp:299
bool prevGamepadAbilitySelectLeft
Tracks previous-frame gamepad left ability-select chord for edge detection.
Definition InputSampleSystem.hpp:50
JoystickAxis getLookJoystickAxes(bool swapSticks)
Return the SDL axes used for camera look, honoring the stick-swap setting.
Definition InputSampleSystem.hpp:62
void runWeaponKeys(Registry ®istry, const InputBindings &bindings, float dt=0.0f)
Sample keyboard state into the weapon flags.
Definition InputSampleSystem.hpp:242
void runGamepadWeapon(Registry ®istry, SDL_Gamepad *gamepad, const InputBindings &bindings)
Sample gamepad buttons / right trigger into the weapon flags.
Definition InputSampleSystem.hpp:478
constexpr float k_grenadeRadialDeadzone
Minimum radial aim distance required to choose a grenade slot.
Definition InputSampleSystem.hpp:42
bool gamepadConnected(SDL_Gamepad *gamepad)
True when a gamepad handle is non-null and still connected.
Definition InputSampleSystem.hpp:80
bool pendingGrenadeThrow
Latched quick-throw request consumed by HUD/gameplay code.
Definition InputSampleSystem.hpp:38
bool prevAbilitySelectRight
Tracks previous-frame Alt+RMB state for ability choice edge detection.
Definition InputSampleSystem.hpp:48
glm::vec2 grenadeRadialAim
Current mouse-relative aim vector inside the grenade radial selector.
Definition InputSampleSystem.hpp:36
bool prevAbilitySelectLeft
Tracks previous-frame Alt+LMB state for ability choice edge detection.
Definition InputSampleSystem.hpp:46
constexpr float k_grenadeRadialMaxDistance
Maximum stored cursor distance from the grenade radial center.
Definition InputSampleSystem.hpp:44
bool prevKillSelfKey
Tracks previous-frame key state for edge detection.
Definition InputSampleSystem.hpp:28
void runDeadInput(Registry ®istry, const InputBindings &bindings)
Sample skip-respawn input while the local player is dead.
Definition InputSampleSystem.hpp:222
Client side Tag component — entity is eligible to receive player input.
Definition Controllable.hpp:9
Marker component that tags exactly one entity per client as the locally controlled player.
Definition LocalPlayer.hpp:12
ECS component: countdown until a dead player respawns.
Definition RespawnTimer.hpp:10
Gamepad axis mapping configuration for look and move axes, used to support stick swapping in user set...
Definition InputSampleSystem.hpp:56
SDL_GamepadAxis x
Definition InputSampleSystem.hpp:57
SDL_GamepadAxis y
Definition InputSampleSystem.hpp:58