Final docs
This commit is contained in:
+70
-13
@@ -17,6 +17,26 @@ The platform layer implements two hooks:
|
||||
- `inputButtonGetValuePlatform()` -- return the analog value [0.0, 1.0]
|
||||
for a given button
|
||||
|
||||
## Defined actions
|
||||
|
||||
Actions are defined in `src/dusk/input/input.csv` and code-generated
|
||||
into the `inputaction_t` enum. Current values:
|
||||
|
||||
| Constant | Meaning |
|
||||
|----------|---------|
|
||||
| `INPUT_ACTION_NULL` | Invalid / sentinel (0) |
|
||||
| `INPUT_ACTION_UP` | Up direction |
|
||||
| `INPUT_ACTION_DOWN` | Down direction |
|
||||
| `INPUT_ACTION_LEFT` | Left direction |
|
||||
| `INPUT_ACTION_RIGHT` | Right direction |
|
||||
| `INPUT_ACTION_ACCEPT` | Confirm / primary action |
|
||||
| `INPUT_ACTION_CANCEL` | Back / secondary action |
|
||||
| `INPUT_ACTION_RAGEQUIT` | Quit the application |
|
||||
| `INPUT_ACTION_CONSOLE` | Toggle debug console |
|
||||
| `INPUT_ACTION_POINTERX` | Mouse / pointer X axis |
|
||||
| `INPUT_ACTION_POINTERY` | Mouse / pointer Y axis |
|
||||
| `INPUT_ACTION_COUNT` | Total count (not a valid action) |
|
||||
|
||||
## Global state
|
||||
|
||||
```c
|
||||
@@ -40,14 +60,22 @@ bool_t inputWasDown(inputaction_t action);
|
||||
bool_t inputPressed(inputaction_t action); // was up, now down
|
||||
bool_t inputReleased(inputaction_t action); // was down, now up
|
||||
|
||||
// 2D axis helpers
|
||||
// Single axis from a neg + pos pair of actions (returns [-1, 1]):
|
||||
float_t inputAxis(inputaction_t neg, inputaction_t pos);
|
||||
|
||||
// 2D axis from four actions (negX/posX/negY/posY):
|
||||
void inputAxis2D(
|
||||
inputaction_t horiz,
|
||||
inputaction_t vert,
|
||||
vec2 out
|
||||
inputaction_t negX, inputaction_t posX,
|
||||
inputaction_t negY, inputaction_t posY,
|
||||
vec2 result
|
||||
);
|
||||
|
||||
// Same four-action axis, normalized to a unit vector via atan2:
|
||||
void inputAngle2D(
|
||||
inputaction_t negX, inputaction_t posX,
|
||||
inputaction_t negY, inputaction_t posY,
|
||||
vec2 result
|
||||
);
|
||||
float_t inputAngle2D(inputaction_t horiz, inputaction_t vert);
|
||||
void inputAxis(inputaction_t action, float_t *out);
|
||||
|
||||
// Deadzone filter (applied to raw axis values)
|
||||
float_t inputDeadzone(float_t value, float_t deadzone);
|
||||
@@ -119,12 +147,41 @@ constants to PSP button names, then calls `inputBind` to wire them:
|
||||
| L / R | `SDL_CONTROLLER_BUTTON_LEFTSHOULDER` / `RIGHTSHOULDER` |
|
||||
| L-Stick | `SDL_CONTROLLER_AXIS_LEFTX/Y` |
|
||||
|
||||
### Vita (`src/duskvita/input/`)
|
||||
|
||||
Layered on top of SDL2 (via vitaSDL2). Behaviour is similar to PSP --
|
||||
no keyboard, no pointer, gamepad only.
|
||||
|
||||
## JS module (`Input`)
|
||||
|
||||
The input system is exposed to JS as the global `Input` object with
|
||||
static methods. Action constants are pre-defined as numeric properties
|
||||
on the `Input` object (e.g. `Input.ACCEPT`, `Input.UP`):
|
||||
|
||||
```js
|
||||
// Check if the accept button is held this frame:
|
||||
if(Input.isDown(Input.ACCEPT)) { ... }
|
||||
|
||||
// Was the cancel button just pressed?
|
||||
if(Input.pressed(Input.CANCEL)) { ... }
|
||||
|
||||
// Analog value for the right trigger:
|
||||
var val = Input.getValue(Input.RIGHT);
|
||||
|
||||
// Single axis (-1 to 1) from a neg/pos pair:
|
||||
var h = Input.axis(Input.LEFT, Input.RIGHT);
|
||||
```
|
||||
|
||||
All `Input.*` action constants match the `INPUT_ACTION_*` enum values
|
||||
from the C layer (UP, DOWN, LEFT, RIGHT, ACCEPT, CANCEL, RAGEQUIT,
|
||||
CONSOLE, POINTERX, POINTERY).
|
||||
|
||||
## Platform capability notes
|
||||
|
||||
| Feature | Linux/Knulli | PSP | GameCube/Wii |
|
||||
|---------|-------------|-----|--------------|
|
||||
| Keyboard | Yes (SDL2) | No | No |
|
||||
| Pointer/Mouse | Yes (SDL2) | No | No |
|
||||
| Gamepad | Yes (SDL2) | Yes (SDL2) | Yes (PAD) |
|
||||
| Analog axes | Yes | L-Stick only | L-Stick, C-Stick, Triggers |
|
||||
| Touch | Defined, not implemented | -- | -- |
|
||||
| Feature | Linux/Knulli | PSP | Vita | GameCube/Wii |
|
||||
|---------|-------------|-----|------|--------------|
|
||||
| Keyboard | Yes (SDL2) | No | No | No |
|
||||
| Pointer/Mouse | Yes (SDL2) | No | No | No |
|
||||
| Gamepad | Yes (SDL2) | Yes (SDL2) | Yes (SDL2) | Yes (PAD) |
|
||||
| Analog axes | Yes | L-Stick only | L-Stick, R-Stick | L-Stick, C-Stick, Triggers |
|
||||
| Touch | Defined, not implemented | -- | -- | -- |
|
||||
|
||||
Reference in New Issue
Block a user