summaryrefslogtreecommitdiff
path: root/platformer/src/controls.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--platformer/src/controls.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/platformer/src/controls.h b/platformer/src/controls.h
new file mode 100644
index 0000000..972ce9e
--- /dev/null
+++ b/platformer/src/controls.h
@@ -0,0 +1,66 @@
+/*
+ * ============================================================
+ * FILE: controls.h
+ *
+ * PURPOSE: Defines `Input`, the one abstract snapshot of what the player
+ * is asking for this tick. Gameplay code reads Input and never
+ * reads a raw device, so the player and camera don't care whether
+ * a gamepad or the keyboard produced it.
+ *
+ * FITS IN: main.c calls controls_poll() once per fixed tick and passes the
+ * Input to player_update() and camera_update().
+ *
+ * INTERFACE: Use these exact names:
+ *
+ * typedef struct Input {
+ * Vec2 move; left stick after the deadzone. Length is 0..1.
+ * +x = right, +y = FORWARD (stick pushed up).
+ * Vec2 look; right stick after the deadzone. Length is 0..1.
+ * +x = orbit camera right, +y = tilt camera up.
+ * bool jump_held; A is down this tick
+ * bool jump_pressed; A went down THIS tick (true for one tick only)
+ * bool reset_pressed; Back/Select went down this tick (one tick only)
+ * bool recenter_pressed; right stick click went down this tick (one tick
+ * only): swing the camera behind the player, centered
+ * bool quit_pressed; Start (or Esc) went down this tick (one tick only)
+ * bool using_gamepad; true if a gamepad produced this Input (debug info)
+ * } Input;
+ *
+ * void controls_init(void); call after window_init()
+ * void controls_poll(Input *out); call once per FIXED TICK (not once per
+ * frame). The "pressed" edges are
+ * worked out tick-to-tick, so a press
+ * is never lost or counted twice.
+ *
+ * Include <stdbool.h> and "math3d.h" (for Vec2).
+ *
+ * CONVENTIONS: Include guard: CONTROLS_H.
+ *
+ * NOT IN SCOPE: Rebinding, multiple players, mouse look, rumble.
+ *
+ * DONE WHEN: player.c and camera.c can be written against Input alone,
+ * without including GLFW.
+ * ============================================================
+ */
+#ifndef CONTROLS_H
+#define CONTROLS_H
+
+#include <stdbool.h>
+
+#include "math3d.h"
+
+typedef struct Input {
+ Vec2 move; /* left stick after deadzone, length 0..1. +x = right, +y = forward */
+ Vec2 look; /* right stick after deadzone, length 0..1. +x = orbit right, +y = tilt up */
+ bool jump_held; /* A is down this tick */
+ bool jump_pressed; /* A went down THIS tick (one tick only) */
+ bool reset_pressed; /* Back/Select went down this tick (one tick only) */
+ bool recenter_pressed; /* right stick click went down this tick (one tick only) */
+ bool quit_pressed; /* Start (or Esc) went down this tick (one tick only) */
+ bool using_gamepad; /* true if a gamepad produced this Input (debug info) */
+} Input;
+
+void controls_init(void);
+void controls_poll(Input *out);
+
+#endif /* CONTROLS_H */