archivemuh
This commit is contained in:
80
src/input/input.h
Normal file
80
src/input/input.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef uint8_t inputbind_t;
|
||||
typedef inputbind_t inputstate_t;
|
||||
|
||||
#define INPUT_BIND_UP (1 << 0)
|
||||
#define INPUT_BIND_DOWN (1 << 1)
|
||||
#define INPUT_BIND_LEFT (1 << 2)
|
||||
#define INPUT_BIND_RIGHT (1 << 3)
|
||||
#define INPUT_BIND_ACTION (1 << 4)
|
||||
#define INPUT_BIND_CANCEL (1 << 5)
|
||||
#define INPUT_BIND_CONSOLE (1 << 6)
|
||||
#define INPUT_BIND_QUIT (1 << 7)
|
||||
|
||||
#define INPUT_BIND_COUNT (INPUT_BIND_QUIT + 1)
|
||||
|
||||
typedef struct {
|
||||
uint8_t current;
|
||||
uint8_t previous;
|
||||
} input_t;
|
||||
|
||||
extern input_t INPUT;
|
||||
|
||||
/**
|
||||
* Initialize the input system.
|
||||
*/
|
||||
void inputInit(void);
|
||||
|
||||
/**
|
||||
* Updates the input state.
|
||||
*/
|
||||
void inputUpdate(void);
|
||||
|
||||
/**
|
||||
* Gets the current input state as a bitmask.
|
||||
*
|
||||
* @return The current input state as a bitmask.
|
||||
*/
|
||||
inputstate_t inputStateGet(void);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind is currently pressed.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind is currently pressed, false otherwise.
|
||||
*/
|
||||
bool_t inputIsDown(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind was pressed in the last update.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind was pressed in the last update, false otherwise.
|
||||
*/
|
||||
bool_t inputWasDown(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind was down this frame but not in the the
|
||||
* previous frame.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind is currently pressed, false otherwise.
|
||||
*/
|
||||
bool_t inputPressed(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Checks if a specific input bind was released this frame.
|
||||
*
|
||||
* @param bind The input bind to check.
|
||||
* @return true if the bind was released this frame, false otherwise.
|
||||
*/
|
||||
bool_t inputReleased(const inputbind_t bind);
|
Reference in New Issue
Block a user