Moved some code around and cleaned things a bit.

This commit is contained in:
2021-02-22 08:08:12 +11:00
parent a456eb1008
commit 11ca3d96e3
14 changed files with 405 additions and 77 deletions

View File

@ -7,13 +7,13 @@
#include <stdbool.h>
#include <stdint.h>
#include <malloc.h>
#include "../platform/platform.h"
/////////////////////////////////// CONSTANTS //////////////////////////////////
#define INPUT_NULL (inputbind_t)0x00
#define INPUT_INPUTS_PER_BIND
/////////////////////////////// Type Definitions ///////////////////////////////
/**
* Input Source, can be a button or an axis. Currently a void type.
*/
typedef void inputsource_t;
/**
* Input Bind, a specific action bind reference for the game engine to use.
* e.g. "Jump" or "Walk Forward".
@ -21,7 +21,7 @@ typedef void inputsource_t;
typedef uint8_t inputbind_t;
/**
* Input Bind Map, contains the bound link between an inputsource_t and an
* Input Bind Map, contains the bound link between an input source and an
* inputbind_t. Bind Maps can be added and removed.
*/
typedef uint16_t inputbindmap_t;
@ -34,28 +34,21 @@ typedef struct {
uint32_t inputBindCount;
/** Float of the input between 0 and 1. For teh current frame */
float *inputsCurrent;
float *current;
/** Float of the input between 0 and 1. For the last frame */
float *inputsPrevious;
float *previous;
/** Float of the GameTime that the input was actuated last. */
float *inputTime;
/**
* Array of pointers to all of the input sources. This must be set up by the
* platform to register each known input to poll on. Essentially the engine is
* going to query the platform for the current state of each input based on the
* entries within this list.
*/
inputsource_t **bindingSources;
float *times;
/**
* Array of input bindings. This is the list of "possible actions" that the
* user can perform. This would contain "jump", "walk forward", "run"... etc.
*/
inputbind_t *INPUT_BINDING_BINDS;
inputbind_t *binds;
} input_t;
//////////////////////////////////// Methods ///////////////////////////////////
/**
@ -64,13 +57,13 @@ typedef struct {
* @param inputCount The input binding counts to allow for.
* @return The input manager
*/
input_t * inputInit(uint32_t inputBindCount);
input_t * inputInit(platform_t *platform, uint32_t inputBindCount);
/**
* Tick the input manager.
* @param input The input to update.
*/
void inputUpdate(input_t *input);
void inputUpdate(platform_t *platform, input_t *input);
/**
* Destroy the input manager and cleanup.
@ -88,19 +81,10 @@ void inputDispose(input_t *input);
* @return The map between the bind and the source, needed to unbind later.
*/
inputbindmap_t inputBind(input_t *input, inputbind_t bind,
inputsource_t *source
platforminputsource_t *source
);
/**
* Platform-centric method. Method will be polled for each known input source to
* request the current state from the device. Values returned will be defined
* within the 0 to 1 range.
*
* @param binding The binding that has been created.
* @param source The input source, this was created when the binding was defined
* @return Input state between 0 and 1.
*/
float inputGetState(inputbind_t binding, inputsource_t *source);
float inputGetState(inputbind_t binding, platforminputsource_t *source);
/**
* Is the current input "down", not being pressed, being moved, not in a state