diff options
| author | Drew DeVault <sir@cmpwn.com> | 2021-12-09 16:46:37 +0100 |
|---|---|---|
| committer | Drew DeVault <sir@cmpwn.com> | 2021-12-09 16:46:37 +0100 |
| commit | 81bac10cd7c26cf1ca1c0fcb9ee3dcccd7710f22 (patch) | |
| tree | 649b0c5e3977041def1245d61ada75036410f809 /sdl2 | |
| parent | timer: correct naming convention (diff) | |
| download | hare-chip8-81bac10cd7c26cf1ca1c0fcb9ee3dcccd7710f22.tar.gz | |
Initial gamecontroller support
Diffstat (limited to '')
| -rw-r--r-- | sdl2/events.ha | 2 | ||||
| -rw-r--r-- | sdl2/gamecontroller.ha | 43 | ||||
| -rw-r--r-- | sdl2/joystick.ha | 13 |
3 files changed, 57 insertions, 1 deletions
diff --git a/sdl2/events.ha b/sdl2/events.ha index 60ac771..e26333a 100644 --- a/sdl2/events.ha +++ b/sdl2/events.ha @@ -220,7 +220,7 @@ export type joy_device_event = struct { export type controller_axis_event = struct { common_event, which: i32, // TODO - axis: u8, + axis: controller_axis, padding1: u8, padding2: u8, padding3: u8, diff --git a/sdl2/gamecontroller.ha b/sdl2/gamecontroller.ha new file mode 100644 index 0000000..3b752e1 --- /dev/null +++ b/sdl2/gamecontroller.ha @@ -0,0 +1,43 @@ +// TODO: Flesh me out + +// The gamecontroller structure used to identify an SDL game controller. +// (Opaque) +export type gamecontroller = void; + +// The list of axes available from a controller +// +// Thumbstick axis values range from [[JOYSTICK_AXIS_MIN]] to +// [[JOYSTICK_AXIS_MAX]], and are centered within ~8000 of zero, though advanced +// UI will allow users to set or autodetect the dead zone, which varies between +// controllers. +// +// Trigger axis values range from 0 to [[JOYSTICK_AXIS_MAX]]. +export type controller_axis = enum u8 { + LEFTX, + LEFTY, + RIGHTX, + RIGHTY, + TRIGGERLEFT, + TRIGGERRIGHT, + INVALID = 255, +}; + +// Check if the given joystick is supported by the game controller interface. +// +// 'joystick_index' is the same as the 'device_index' passed to +// [[joystick_open]]. +// +// Returns SDL_TRUE if the given joystick is supported by the game controller +// interface, SDL_FALSE if it isn't or it's an invalid index. +export @symbol("SDL_IsGameController") fn is_game_controller( + joystick_index: int) bool; + +// Get the SDL_GameController associated with an instance id. +// +// Returns a [[controller]] on success or NULL on failure. +export @symbol("SDL_GameControllerOpen") fn game_controller_open( + joystick_index: int) *gamecontroller; + +// Close a game controller previously opened with [[game_controller_open]]. +export @symbol("SDL_GameControllerClose") fn game_controller_close( + gamecontroller: *gamecontroller) void; diff --git a/sdl2/joystick.ha b/sdl2/joystick.ha new file mode 100644 index 0000000..c4f4c96 --- /dev/null +++ b/sdl2/joystick.ha @@ -0,0 +1,13 @@ +// TODO: Flesh me out + +// Minimum value for a joystick axis. +export def JOYSTICK_AXIS_MIN: i16 = -32768; + +// Minimum value for a joystick axis. +export def JOYSTICK_AXIS_MAX: i16 = 32767; + +// Count the number of joysticks attached to the system. +// +// Returns the number of attached joysticks on success or a negative error code +// on failure. +export @symbol("SDL_NumJoysticks") fn numjoysticks() int; |
