Time is better.

This commit is contained in:
2025-11-09 18:32:33 -06:00
parent b9ec6523d6
commit 943e775364
17 changed files with 293 additions and 146 deletions

View File

@@ -80,12 +80,17 @@ void inputUpdate(void) {
// Reset all actions
inputactiondata_t *action = &INPUT.actions[0];
do {
action->lastValue = action->currentValue;
action->currentValue = 0.0f;
if(TIME.fixedUpdate) {
action->lastFixedValue = action->currentFixedValue;
action->currentFixedValue = 0.0f;
}
#if TIME_FIXED == 0
action->lastDynamicValue = action->currentDynamicValue;
action->currentDynamicValue = 0.0f;
if(!TIME.dynamicUpdate) {
action->lastValue = action->currentValue;
action->currentValue = 0.0f;
}
#else
action->lastValue = action->currentValue;
action->currentValue = 0.0f;
#endif
action++;
} while(action < &INPUT.actions[INPUT_ACTION_COUNT]);
@@ -102,50 +107,55 @@ void inputUpdate(void) {
}
// 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
#if TIME_FIXED == 0
INPUT.actions[cur->action].currentDynamicValue = mathMax(
cur->curVal, INPUT.actions[cur->action].currentDynamicValue
);
}
if(!TIME.dynamicUpdate) {
INPUT.actions[cur->action].currentValue = mathMax(
cur->curVal, INPUT.actions[cur->action].currentValue
);
}
#else
INPUT.actions[cur->action].currentValue = mathMax(
cur->curVal, INPUT.actions[cur->action].currentValue
);
#endif
cur++;
} while(cur->name);
}
float_t inputGetCurrentValue(const inputaction_t action) {
// This may be cursed, not sure yet!
if(TIME.fixedUpdate) return inputGetCurrentValueFixed(action);
return inputGetCurrentValueNonFixed(action);
}
#if TIME_FIXED == 0
if(TIME.dynamicUpdate) return inputGetCurrentValueDynamic(action);
#endif
float_t inputGetCurrentValueFixed(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 inputGetLastValue(const inputaction_t action) {
if(TIME.fixedUpdate) return inputGetLastValueFixed(action);
return inputGetLastValueNonFixed(action);
}
float_t inputGetLastValueFixed(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) {
#if TIME_FIXED == 0
if(TIME.dynamicUpdate) return inputGetLastValueDynamic(action);
#endif
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].lastValue;
}
#if TIME_FIXED == 0
float_t inputGetCurrentValueDynamic(const inputaction_t action) {
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].currentDynamicValue;
}
float_t inputGetLastValueDynamic(const inputaction_t action) {
assertTrue(action < INPUT_ACTION_COUNT, "Input action out of bounds");
return INPUT.actions[action].lastDynamicValue;
}
#endif
bool_t inputIsDown(const inputaction_t action) {
return inputGetCurrentValue(action) > 0.0f;
}

View File

@@ -47,22 +47,6 @@ void inputUpdate(void);
*/
float_t inputGetCurrentValue(const inputaction_t action);
/**
* Gets the current value of a specific input action (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 inputGetCurrentValueFixed(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.
*
@@ -71,21 +55,23 @@ float_t inputGetCurrentValueNonFixed(const inputaction_t action);
*/
float_t inputGetLastValue(const inputaction_t action);
/**
* Gets the last value of a specific input action (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 inputGetLastValueFixed(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 (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);
/**
* 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.

View File

@@ -9,22 +9,13 @@
#include "assert/assert.h"
#include "util/string.h"
const char_t* INPUT_ACTION_NAMES[INPUT_ACTION_COUNT] = {
[INPUT_ACTION_UP] = "UP",
[INPUT_ACTION_DOWN] = "DOWN",
[INPUT_ACTION_LEFT] = "LEFT",
[INPUT_ACTION_RIGHT] = "RIGHT",
[INPUT_ACTION_ACCEPT] = "ACCEPT",
[INPUT_ACTION_CANCEL] = "CANCEL",
};
inputaction_t inputActionGetByName(const char_t *name) {
assertNotNull(name, "name must not be NULL");
// inputaction_t inputActionGetByName(const char_t *name) {
// assertNotNull(name, "name must not be NULL");
for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) {
if(stringCompareInsensitive(INPUT_ACTION_NAMES[i], name) != 0) continue;
return i;
}
// for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) {
// if(stringCompareInsensitive(INPUT_ACTION_NAMES[i], name) != 0) continue;
// return i;
// }
return INPUT_ACTION_COUNT;
}
// return INPUT_ACTION_COUNT;
// }

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "dusk.h"
#include "time/time.h"
typedef enum {
INPUT_ACTION_NULL,
@@ -25,11 +25,22 @@ typedef struct {
inputaction_t action;
float_t lastValue;
float_t currentValue;
float_t lastFixedValue;
float_t currentFixedValue;
#if TIME_FIXED == 0
float_t lastDynamicValue;
float_t currentDynamicValue;
#endif
} inputactiondata_t;
extern const char_t* INPUT_ACTION_NAMES[INPUT_ACTION_COUNT];
// static const char_t* INPUT_ACTION_NAMES[INPUT_ACTION_COUNT] = {
// [INPUT_ACTION_UP] = "UP",
// [INPUT_ACTION_DOWN] = "DOWN",
// [INPUT_ACTION_LEFT] = "LEFT",
// [INPUT_ACTION_RIGHT] = "RIGHT",
// [INPUT_ACTION_ACCEPT] = "ACCEPT",
// [INPUT_ACTION_CANCEL] = "CANCEL",
// [INPUT_ACTION_RAGEQUIT] = "RAGEQUIT",
// };
/**
* Gets an input action by its name.
@@ -37,4 +48,4 @@ extern const char_t* INPUT_ACTION_NAMES[INPUT_ACTION_COUNT];
* @param name The name of the input action.
* @return The input action, or INPUT_ACTION_COUNT if not found.
*/
inputaction_t inputActionGetByName(const char_t *name);
// inputaction_t inputActionGetByName(const char_t *name);