"progress"
This commit is contained in:
154
archive/src/input/input.h
Normal file
154
archive/src/input/input.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "inputbutton.h"
|
||||
#include "inputaction.h"
|
||||
#include "event/event.h"
|
||||
|
||||
#if DOLPHIN
|
||||
#define INPUT_PAD_COUNT PAD_CHANMAX
|
||||
#define INPUT_AXIS_FLOAT(value) ((float_t)(value) / 128.0f)
|
||||
#endif
|
||||
|
||||
#define INPUT_LISTENER_PRESSED_MAX 16
|
||||
#define INPUT_LISTENER_RELEASED_MAX INPUT_LISTENER_PRESSED_MAX
|
||||
|
||||
typedef struct {
|
||||
const inputaction_t action;
|
||||
} inputevent_t;
|
||||
|
||||
typedef struct {
|
||||
inputactiondata_t actions[INPUT_ACTION_COUNT];
|
||||
|
||||
eventlistener_t pressedListeners[INPUT_LISTENER_PRESSED_MAX];
|
||||
event_t eventPressed;
|
||||
eventlistener_t releasedListeners[INPUT_LISTENER_RELEASED_MAX];
|
||||
event_t eventReleased;
|
||||
|
||||
#if INPUT_GAMEPAD == 1
|
||||
float_t deadzone;
|
||||
#endif
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
#if INPUT_GAMEPAD == 1
|
||||
SDL_GameController *controller;
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
const uint8_t *keyboardState;
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
#if INPUT_SDL2 == 1
|
||||
float_t mouseX, mouseY;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif DOLPHIN
|
||||
int padState[INPUT_PAD_COUNT];
|
||||
float_t pads[INPUT_PAD_COUNT][INPUT_GAMEPAD_AXIS_COUNT];
|
||||
|
||||
#endif
|
||||
} input_t;
|
||||
|
||||
extern input_t INPUT;
|
||||
|
||||
/**
|
||||
* Initialize the input system.
|
||||
*/
|
||||
void inputInit(void);
|
||||
|
||||
/**
|
||||
* Updates the input state.
|
||||
*/
|
||||
void inputUpdate(void);
|
||||
|
||||
/**
|
||||
* Gets the current value of a specific input action.
|
||||
*
|
||||
* @param action The input action to get the value for.
|
||||
* @return The current value of the action (0.0f to 1.0f).
|
||||
*/
|
||||
float_t inputGetCurrentValue(const inputaction_t action);
|
||||
|
||||
/**
|
||||
* Gets the last value of a specific input action.
|
||||
*
|
||||
* @param action The input action to get the value for.
|
||||
* @return The last value of the action (0.0f to 1.0f).
|
||||
*/
|
||||
float_t inputGetLastValue(const inputaction_t action);
|
||||
|
||||
#if TIME_FIXED == 0
|
||||
/**
|
||||
* Gets the current value of a specific input action (dynamic timestep).
|
||||
*
|
||||
* @param action The input action to get the value for.
|
||||
* @return The current value of the action (0.0f to 1.0f).
|
||||
*/
|
||||
float_t inputGetCurrentValueDynamic(const inputaction_t action);
|
||||
|
||||
/**
|
||||
* Gets the last value of a specific input action (dynamic timestep).
|
||||
*
|
||||
* @param action The input action to get the value for.
|
||||
* @return The last value of the action (0.0f to 1.0f).
|
||||
*/
|
||||
float_t inputGetLastValueDynamic(const inputaction_t action);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Checks if a specific input action is currently pressed.
|
||||
*
|
||||
* @param action The input action to check.
|
||||
* @return true if the action is currently pressed, false otherwise.
|
||||
*/
|
||||
bool_t inputIsDown(const inputaction_t action);
|
||||
|
||||
/**
|
||||
* Checks if a specific input action was pressed in the last update.
|
||||
*
|
||||
* @param action The input action to check.
|
||||
* @return true if the action was pressed in the last update, false otherwise.
|
||||
*/
|
||||
bool_t inputWasDown(const inputaction_t action);
|
||||
|
||||
/**
|
||||
* Checks if a specific input action was down this frame but not in the the
|
||||
* previous frame.
|
||||
*
|
||||
* @param action The input action to check.
|
||||
* @return true if the action is currently pressed, false otherwise.
|
||||
*/
|
||||
bool_t inputPressed(const inputaction_t action);
|
||||
|
||||
/**
|
||||
* Checks if a specific input action was released this frame.
|
||||
*
|
||||
* @param action The input action to check.
|
||||
* @return true if the action was released this frame, false otherwise.
|
||||
*/
|
||||
bool_t inputReleased(const inputaction_t action);
|
||||
|
||||
/**
|
||||
* Gets the value of an input axis, defined by two actions (negative and
|
||||
* positive).
|
||||
*
|
||||
* @param neg The action representing the negative direction of the axis.
|
||||
* @param pos The action representing the positive direction of the axis.
|
||||
* @return The current value of the axis (-1.0f to 1.0f).
|
||||
*/
|
||||
float_t inputAxis(const inputaction_t neg, const inputaction_t pos);
|
||||
|
||||
/**
|
||||
* Binds an input button to an action.
|
||||
*
|
||||
* @param button The input button to bind.
|
||||
* @param action The input action to bind the button to.
|
||||
*/
|
||||
void inputBind(const inputbutton_t button, const inputaction_t act);
|
||||
Reference in New Issue
Block a user