Made input work on fixed timesteps primarily.

This commit is contained in:
2025-11-04 08:41:18 -06:00
parent 6ea4132ff9
commit c9608ad7a7
11 changed files with 136 additions and 53 deletions

View File

@@ -10,6 +10,7 @@
#include "util/memory.h"
#include "util/string.h"
#include "util/math.h"
#include "time/time.h"
input_t INPUT;
@@ -81,6 +82,11 @@ void inputUpdate(void) {
do {
action->lastValue = action->currentValue;
action->currentValue = 0.0f;
if(TIME.fixedUpdate) {
action->lastFixedValue = action->currentFixedValue;
action->currentFixedValue = 0.0f;
}
action++;
} while(action < &INPUT.actions[INPUT_ACTION_COUNT]);
@@ -95,20 +101,36 @@ void inputUpdate(void) {
continue;
}
// Update current val.
INPUT.actions[cur->action].currentValue = mathMax(
cur->curVal, INPUT.actions[cur->action].currentValue
);
if(TIME.fixedUpdate) {
INPUT.actions[cur->action].currentFixedValue = mathMax(
cur->curVal, INPUT.actions[cur->action].currentFixedValue
);
}
cur++;
} while(cur->name);
}
float_t inputGetCurrentValue(const inputaction_t action) {
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].currentFixedValue;
}
float_t inputGetCurrentValueNonFixed(const inputaction_t action) {
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].currentValue;
}
float_t inputGetLast(const inputaction_t action) {
float_t inputGetLastValue(const inputaction_t action) {
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].lastFixedValue;
}
float_t inputGetLastValueNonFixed(const inputaction_t action) {
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].lastValue;
}
@@ -118,7 +140,7 @@ bool_t inputIsDown(const inputaction_t action) {
}
bool_t inputWasDown(const inputaction_t action) {
return inputGetLast(action) > 0.0f;
return inputGetLastValue(action) > 0.0f;
}
bool_t inputPressed(const inputaction_t action) {

View File

@@ -47,13 +47,29 @@ void inputUpdate(void);
*/
float_t inputGetCurrentValue(const inputaction_t action);
/**
* Gets the current value of a specific input action (non-fixed 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 inputGetCurrentValueNonFixed(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 inputGetLast(const inputaction_t action);
float_t inputGetLastValue(const inputaction_t action);
/**
* Gets the last value of a specific input action (non-fixed 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 inputGetLastValueNonFixed(const inputaction_t action);
/**
* Checks if a specific input action is currently pressed.

View File

@@ -25,6 +25,8 @@ typedef struct {
inputaction_t action;
float_t lastValue;
float_t currentValue;
float_t lastFixedValue;
float_t currentFixedValue;
} inputactiondata_t;
extern const char_t* INPUT_ACTION_NAMES[INPUT_ACTION_COUNT];