Nuked console
This commit is contained in:
@@ -59,31 +59,10 @@ void inputUpdate(void) {
|
||||
cur++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(cur->actionType) {
|
||||
case INPUT_BUTTON_ACTION_TYPE_NULL: {
|
||||
break;
|
||||
}
|
||||
|
||||
case INPUT_BUTTON_ACTION_TYPE_COMMAND: {
|
||||
if(cur->lastVal == 0.0f && cur->command[0] != '\0') {
|
||||
consoleExec(cur->command);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case INPUT_BUTTON_ACTION_TYPE_ACTION: {
|
||||
INPUT.actions[cur->action].currentValue = mathMax(
|
||||
cur->curVal, INPUT.actions[cur->action].currentValue
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
assertUnreachable("Unknown input button action type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
INPUT.actions[cur->action].currentValue = mathMax(
|
||||
cur->curVal, INPUT.actions[cur->action].currentValue
|
||||
);
|
||||
|
||||
cur++;
|
||||
} while(cur->name);
|
||||
@@ -122,10 +101,11 @@ float_t inputAxis(const inputaction_t neg, const inputaction_t pos) {
|
||||
return inputGetCurrentValue(pos) - inputGetCurrentValue(neg);
|
||||
}
|
||||
|
||||
void inputBind(const inputbutton_t button, const char_t *action) {
|
||||
assertNotNull(action, "Input action is null");
|
||||
assertStrLenMin(action, 1, "Input action is empty");
|
||||
assertStrLenMax(action, CONSOLE_LINE_MAX - 1, "Input action is too long");
|
||||
void inputBind(const inputbutton_t button, const inputaction_t act) {
|
||||
assertTrue(
|
||||
act < INPUT_ACTION_COUNT,
|
||||
"Invalid input action"
|
||||
);
|
||||
|
||||
// Get the button data for this button.
|
||||
inputbuttondata_t *data = INPUT_BUTTON_DATA;
|
||||
@@ -137,19 +117,6 @@ void inputBind(const inputbutton_t button, const char_t *action) {
|
||||
} while(data->name != NULL);
|
||||
assertNotNull(data->name, "Input button not found");
|
||||
|
||||
// Try find input action first.
|
||||
for(inputaction_t act = 0; act < INPUT_ACTION_COUNT; act++) {
|
||||
if(stringCompareInsensitive(INPUT_ACTION_NAMES[act], action) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Action found.
|
||||
data->actionType = INPUT_BUTTON_ACTION_TYPE_ACTION;
|
||||
data->action = act;
|
||||
return;
|
||||
}
|
||||
|
||||
// No action found, treat as command.
|
||||
data->actionType = INPUT_BUTTON_ACTION_TYPE_COMMAND;
|
||||
stringCopy(data->command, action, CONSOLE_LINE_MAX);
|
||||
// Bind the action.
|
||||
data->action = act;
|
||||
}
|
||||
@@ -99,10 +99,9 @@ bool_t inputReleased(const inputaction_t action);
|
||||
float_t inputAxis(const inputaction_t neg, const inputaction_t pos);
|
||||
|
||||
/**
|
||||
* Binds an input button to an action. Will first check if a matching action
|
||||
* exists, otherwise it will be treated as a command.
|
||||
* Binds an input button to an action.
|
||||
*
|
||||
* @param button The input button to bind.
|
||||
* @param action The name of the input action or command to bind the button to.
|
||||
* @param action The input action to bind the button to.
|
||||
*/
|
||||
void inputBind(const inputbutton_t data, const char_t *action);
|
||||
void inputBind(const inputbutton_t button, const inputaction_t act);
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
INPUT_ACTION_NULL,
|
||||
INPUT_ACTION_UP,
|
||||
INPUT_ACTION_DOWN,
|
||||
INPUT_ACTION_LEFT,
|
||||
|
||||
@@ -111,6 +111,19 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||
{ .name = "f10", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F10 } },
|
||||
{ .name = "f11", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F11 } },
|
||||
{ .name = "f12", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F12 } },
|
||||
{ .name = "f13", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F13 } },
|
||||
{ .name = "f14", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F14 } },
|
||||
{ .name = "f15", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F15 } },
|
||||
{ .name = "f16", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F16 } },
|
||||
{ .name = "f17", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F17 } },
|
||||
{ .name = "f18", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F18 } },
|
||||
{ .name = "f19", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F19 } },
|
||||
{ .name = "f20", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F20 } },
|
||||
{ .name = "f21", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F21 } },
|
||||
{ .name = "f22", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F22 } },
|
||||
{ .name = "f23", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F23 } },
|
||||
{ .name = "f24", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_F24 } },
|
||||
|
||||
|
||||
{ .name = "minus", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_MINUS } },
|
||||
{ .name = "equals", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_EQUALS } },
|
||||
@@ -124,6 +137,11 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||
{ .name = "period", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_PERIOD } },
|
||||
{ .name = "slash", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SLASH } },
|
||||
|
||||
{ .name = "caps", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_CAPSLOCK } },
|
||||
{ .name = "capslock", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_CAPSLOCK } },
|
||||
{ .name = "numlock", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_NUMLOCKCLEAR } },
|
||||
{ .name = "scrollock", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_SCROLLLOCK } },
|
||||
|
||||
{ .name = "-", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_MINUS } },
|
||||
{ .name = "=", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_EQUALS } },
|
||||
{ .name = "[", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_LEFTBRACKET } },
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
#include "inputaction.h"
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
@@ -62,23 +61,12 @@ typedef struct {
|
||||
};
|
||||
} inputbutton_t;
|
||||
|
||||
typedef enum {
|
||||
INPUT_BUTTON_ACTION_TYPE_NULL,
|
||||
INPUT_BUTTON_ACTION_TYPE_COMMAND,
|
||||
INPUT_BUTTON_ACTION_TYPE_ACTION,
|
||||
} inputbuttonactiontype_t;
|
||||
|
||||
typedef struct {
|
||||
const char_t *name;
|
||||
inputbutton_t button;
|
||||
float_t curVal;
|
||||
float_t lastVal;
|
||||
inputbuttonactiontype_t actionType;
|
||||
|
||||
union {
|
||||
char_t command[CONSOLE_LINE_MAX];
|
||||
inputaction_t action;
|
||||
};
|
||||
inputaction_t action;
|
||||
} inputbuttondata_t;
|
||||
|
||||
extern inputbuttondata_t INPUT_BUTTON_DATA[];
|
||||
|
||||
Reference in New Issue
Block a user