1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 */
|