From a0fad441d03cdc9b7dd0b40233c3c37ab65d20a6 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 20 Apr 2026 12:59:25 -0500 Subject: [PATCH] Updated bind command --- src/dusk/console/cmd/cmdbind.h | 27 +++++++++++++++++++++------ src/dusk/console/console.c | 5 ++--- src/dusk/input/input.c | 12 ++++-------- src/dusk/input/inputaction.c | 18 +++++++++--------- src/dusk/input/inputaction.h | 2 +- src/dusk/input/inputbutton.c | 13 +++++++++++++ src/dusk/input/inputbutton.h | 10 +++++++++- 7 files changed, 59 insertions(+), 28 deletions(-) diff --git a/src/dusk/console/cmd/cmdbind.h b/src/dusk/console/cmd/cmdbind.h index 5eafd5ce..6e300bfc 100644 --- a/src/dusk/console/cmd/cmdbind.h +++ b/src/dusk/console/cmd/cmdbind.h @@ -15,16 +15,31 @@ void cmdBind(const consolecmdexec_t *exec) { return; } - if(exec->argc == 1) { - consolePrint("TODO: Show binds"); - return; - } - inputbutton_t button = inputButtonGetByName(exec->argv[0]); if(button.type == INPUT_BUTTON_TYPE_NONE) { consolePrint("Unknown button \"%s\"", exec->argv[0]); return; } - inputBind(button, exec->argv[1]); + if(exec->argc == 1) { + // Get the button data for this button. + inputbuttondata_t *data = inputButtonGetData(button); + assertNotNull(data, "Input button not found"); + + inputaction_t act = data->action; + if(act == INPUT_ACTION_NULL || act >= INPUT_ACTION_COUNT) { + consolePrint("%s is not bound.", data->name); + } else { + consolePrint("%s is bound to %s.", data->name, INPUT_ACTION_IDS[act]); + } + return; + } + + inputaction_t action = inputActionGetByName(exec->argv[1]); + if(action == INPUT_ACTION_COUNT) { + consolePrint("Unknown action \"%s\"", exec->argv[1]); + return; + } + + inputBind(button, action); } \ No newline at end of file diff --git a/src/dusk/console/console.c b/src/dusk/console/console.c index 02da80c1..de8b1d87 100644 --- a/src/dusk/console/console.c +++ b/src/dusk/console/console.c @@ -17,9 +17,7 @@ #include "console/cmd/cmdset.h" #include "console/cmd/cmdget.h" #include "console/cmd/cmdquit.h" -// #include "console/cmd/cmdbind.h" -// #include "console/cmd/cmdtoggleconsole.h" - +#include "console/cmd/cmdbind.h" #include "display/shader/shaderunlit.h" #include "display/text/text.h" #include "display/spritebatch/spritebatch.h" @@ -40,6 +38,7 @@ void consoleInit() { REG("echo", cmdEcho); REG("quit", cmdQuit); REG("exit", cmdQuit); + REG("bind", cmdBind); #undef REG #ifdef DUSK_CONSOLE_POSIX diff --git a/src/dusk/input/input.c b/src/dusk/input/input.c index 1dd13517..beb83e8b 100644 --- a/src/dusk/input/input.c +++ b/src/dusk/input/input.c @@ -179,19 +179,15 @@ void inputBind(const inputbutton_t button, const inputaction_t act) { assertTrue(act != INPUT_ACTION_NULL, "Cannot bind to NULL action"); // Get the button data for this button. - inputbuttondata_t *data = INPUT_BUTTON_DATA; - do { - if(memoryCompare(&data->button, &button, sizeof(inputbutton_t)) == 0) { - break; - } - data++; - } while(data->name != NULL); - assertNotNull(data->name, "Input button not found"); + inputbuttondata_t *data = inputButtonGetData(button); + assertNotNull(data, "Input button not found"); // Bind the action. data->action = act; } + + float_t inputDeadzone(const float_t rawValue, const float_t deadzone) { if(rawValue < deadzone) return 0.0f; return (rawValue - deadzone) / (1.0f - deadzone); diff --git a/src/dusk/input/inputaction.c b/src/dusk/input/inputaction.c index daae645e..cf556af2 100644 --- a/src/dusk/input/inputaction.c +++ b/src/dusk/input/inputaction.c @@ -9,14 +9,14 @@ #include "assert/assert.h" #include "util/string.h" -// 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(INPUT_ACTION_IDS[i] == NULL) continue; -// if(stringCompareInsensitive(INPUT_ACTION_IDS[i], name) != 0) continue; -// return i; -// } + for(inputaction_t i = 0; i < INPUT_ACTION_COUNT; i++) { + if(INPUT_ACTION_IDS[i] == NULL) continue; + if(stringCompareInsensitive(INPUT_ACTION_IDS[i], name) != 0) continue; + return i; + } -// return INPUT_ACTION_COUNT; -// } \ No newline at end of file + return INPUT_ACTION_COUNT; +} \ No newline at end of file diff --git a/src/dusk/input/inputaction.h b/src/dusk/input/inputaction.h index b829c0eb..77a5f913 100644 --- a/src/dusk/input/inputaction.h +++ b/src/dusk/input/inputaction.h @@ -26,4 +26,4 @@ typedef struct { * @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); \ No newline at end of file +inputaction_t inputActionGetByName(const char_t *name); \ No newline at end of file diff --git a/src/dusk/input/inputbutton.c b/src/dusk/input/inputbutton.c index 5a7f8af5..9cdb4054 100644 --- a/src/dusk/input/inputbutton.c +++ b/src/dusk/input/inputbutton.c @@ -9,6 +9,7 @@ #include "input.h" #include "assert/assert.h" #include "util/string.h" +#include "util/memory.h" inputbutton_t inputButtonGetByName(const char_t *name) { assertNotNull(name, "name must not be NULL"); @@ -26,4 +27,16 @@ inputbutton_t inputButtonGetByName(const char_t *name) { float_t inputButtonGetValue(const inputbutton_t button) { return inputButtonGetValuePlatform(button); +} +inputbuttondata_t * inputButtonGetData(const inputbutton_t button) { + inputbuttondata_t *data = INPUT_BUTTON_DATA; + + do { + if(memoryCompare(&data->button, &button, sizeof(inputbutton_t)) == 0) { + return data; + } + data++; + } while(data->name != NULL); + + return NULL; } \ No newline at end of file diff --git a/src/dusk/input/inputbutton.h b/src/dusk/input/inputbutton.h index 470fdfe9..953cad82 100644 --- a/src/dusk/input/inputbutton.h +++ b/src/dusk/input/inputbutton.h @@ -96,4 +96,12 @@ inputbutton_t inputButtonGetByName(const char_t *name); * @param button The input button. * @return The current value of the input button (0.0f to 1.0f). */ -float_t inputButtonGetValue(const inputbutton_t button); \ No newline at end of file +float_t inputButtonGetValue(const inputbutton_t button); + +/** + * Gets the button data for a specific input button. + * + * @param button The input button to get the data for. + * @return The button data, or NULL if not found. + */ +inputbuttondata_t * inputButtonGetData(const inputbutton_t button); \ No newline at end of file