Files
goldeneye-pc-port/port/include/input.h
T
James Dansereau 8337a87fb2 D118: implement SDL input layer (kbd/mouse/gamepad -> N64 pad)
port/src/input.c was a stub; input only worked via libultra.c's minimal
contSnapshotFromKeyboard (no C-buttons, mouse, or gamepad).

- input.c: keyboard+mouse + SDL_GameController -> OSContPad. Analog stick
  = move, C-buttons = aim. Mouse-look bridged to digital C-buttons via a
  clamped per-axis accumulator (proportional press dwell). RMB/LT = aim
  mode, LMB/RT = fire. Config: ge007.ini [Input] MouseEnabled /
  MouseAimSpeed / MouseInvertY.
- input.h: add inputConnectedMask() + inputComputePad().
- libultra.c SI section: contSnapshotFromKeyboard() now delegates to the
  input module (single source of controller state); osContGetReadData()
  fills all MAXCONTROLLERS channels, not just controller 0.
- GE_INPUTLOG=1 gates a per-poll OSContPad trace (zero-cost when unset).

Build green (ntsc-final); boots -level_09 crash-free 35s. Live input
untested from headless agent - human playtest owed.
2026-08-29 11:11:08 -04:00

46 lines
1.4 KiB
C

#ifndef PORT_INPUT_H
#define PORT_INPUT_H
/*
* Input: SDL2 keyboard/mouse/gamepad -> N64 controller structs.
* Modelled on the PD port's port/include/input.h.
*
* The game reads controllers via osContInit / osContStartReadData (src/joy.c).
* This layer populates the N64 controller state (buttons, stick) from SDL
* events. Default bindings follow the 1964GEPD / Xbox schemes; see the PD
* port README for the reference table.
*/
#include <PR/ultratypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Initialize SDL input. Returns 0 on success. */
int inputInit(void);
void inputDestroy(void);
/* Poll once per frame; updates the connected-controller state that
* osContStartReadData / osContRead will return. */
void inputUpdate(void);
/* Number of controllers currently "connected" (1..4). */
int inputGetNumControllers(void);
/* Bitmask of connected controllers (bit N = controller N). Bit 0 is always
* set (keyboard/mouse). Consumed by libultra.c's osContInit. */
int inputConnectedMask(void);
/* Compute the N64 button mask + analog stick for controller `idx`.
* Returns the 16-bit CONT_* button mask; writes the stick (-80..80) through
* the out params. Reads current SDL keyboard/mouse/gamepad state plus the
* mouse-aim accumulator maintained by inputUpdate(). */
unsigned inputComputePad(int idx, signed char *stick_x, signed char *stick_y);
#ifdef __cplusplus
}
#endif
#endif /* PORT_INPUT_H */