Reg console.

This commit is contained in:
2026-04-20 14:31:22 -05:00
parent a0fad441d0
commit b89ae2391b
7 changed files with 160 additions and 86 deletions
+4 -1
View File
@@ -16,6 +16,7 @@ if PSP then
inputBind("lstick_down", INPUT_ACTION_DOWN) inputBind("lstick_down", INPUT_ACTION_DOWN)
inputBind("lstick_left", INPUT_ACTION_LEFT) inputBind("lstick_left", INPUT_ACTION_LEFT)
inputBind("lstick_right", INPUT_ACTION_RIGHT) inputBind("lstick_right", INPUT_ACTION_RIGHT)
inputBind("triangle", INPUT_ACTION_CONSOLE)
elseif DOLPHIN then elseif DOLPHIN then
inputBind("up", INPUT_ACTION_UP) inputBind("up", INPUT_ACTION_UP)
@@ -24,7 +25,8 @@ elseif DOLPHIN then
inputBind("right", INPUT_ACTION_RIGHT) inputBind("right", INPUT_ACTION_RIGHT)
inputBind("b", INPUT_ACTION_CANCEL) inputBind("b", INPUT_ACTION_CANCEL)
inputBind("a", INPUT_ACTION_ACCEPT) inputBind("a", INPUT_ACTION_ACCEPT)
inputBind("z", INPUT_ACTION_RAGEQUIT) -- inputBind("z", INPUT_ACTION_RAGEQUIT)
inputBind("z", INPUT_ACTION_CONSOLE)
inputBind("lstick_up", INPUT_ACTION_UP) inputBind("lstick_up", INPUT_ACTION_UP)
inputBind("lstick_down", INPUT_ACTION_DOWN) inputBind("lstick_down", INPUT_ACTION_DOWN)
inputBind("lstick_left", INPUT_ACTION_LEFT) inputBind("lstick_left", INPUT_ACTION_LEFT)
@@ -48,6 +50,7 @@ elseif LINUX then
inputBind("q", INPUT_ACTION_CANCEL) inputBind("q", INPUT_ACTION_CANCEL)
inputBind("escape", INPUT_ACTION_RAGEQUIT) inputBind("escape", INPUT_ACTION_RAGEQUIT)
inputBind("`", INPUT_ACTION_CONSOLE)
end end
if INPUT_GAMEPAD then if INPUT_GAMEPAD then
@@ -7,7 +7,8 @@
#pragma once #pragma once
#include "console/console.h" #include "console/console.h"
#include "time/time.h"
void cmdToggleConsole(const consolecmdexec_t *exec) { void cmdTime(const consolecmdexec_t *exec) {
CONSOLE.visible = !CONSOLE.visible; consolePrint("Time: %.2f", TIME.time);
} }
+44 -12
View File
@@ -18,6 +18,8 @@
#include "console/cmd/cmdget.h" #include "console/cmd/cmdget.h"
#include "console/cmd/cmdquit.h" #include "console/cmd/cmdquit.h"
#include "console/cmd/cmdbind.h" #include "console/cmd/cmdbind.h"
#include "console/cmd/cmdtime.h"
#include "display/shader/shaderunlit.h" #include "display/shader/shaderunlit.h"
#include "display/text/text.h" #include "display/text/text.h"
#include "display/spritebatch/spritebatch.h" #include "display/spritebatch/spritebatch.h"
@@ -28,9 +30,11 @@ void consoleInit() {
memoryZero(&CONSOLE, sizeof(console_t)); memoryZero(&CONSOLE, sizeof(console_t));
// Register vars // Register vars
consoleRegVar("fps", "0", NULL); #define REG(name, value) consoleRegVar(name, value, NULL)
REG("console", "0");
#undef REG
// Register cmds // Register cmdss
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet); CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet); CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
@@ -39,6 +43,7 @@ void consoleInit() {
REG("quit", cmdQuit); REG("quit", cmdQuit);
REG("exit", cmdQuit); REG("exit", cmdQuit);
REG("bind", cmdBind); REG("bind", cmdBind);
REG("time", cmdTime);
#undef REG #undef REG
#ifdef DUSK_CONSOLE_POSIX #ifdef DUSK_CONSOLE_POSIX
@@ -86,6 +91,31 @@ consolevar_t * consoleVarGet(const char_t *name) {
return NULL; return NULL;
} }
int32_t consoleVarGetInt(const char_t *name, const int32_t initial) {
consolevar_t *var = consoleVarGet(name);
if(var == NULL) return initial;
char *end;
int32_t value = (int32_t)strtol(var->value, &end, 10);
if(*end != '\0') return initial;
return value;
}
bool_t consoleVarGetBool(const char_t *name, const bool_t initial) {
return consoleVarGetInt(name, initial ? 1 : 0) != 0;
}
void consoleVarSetInt(const char_t *name, const int32_t value) {
consolevar_t *existing = consoleVarGet(name);
assertNotNull(existing, "Variable not found");
char_t buffer[CONSOLE_VAR_VALUE_MAX];
stringFormat(buffer, CONSOLE_VAR_VALUE_MAX, "%d", value);
consoleVarSetValue(existing, buffer);
}
void consoleVarSetBool(const char_t *name, const bool_t value) {
consoleVarSetInt(name, value ? 1 : 0);
}
void consolePrint(const char_t *message, ...) { void consolePrint(const char_t *message, ...) {
char_t buffer[CONSOLE_LINE_MAX]; char_t buffer[CONSOLE_LINE_MAX];
@@ -337,14 +367,18 @@ void consoleExec(const char_t *line) {
} }
void consoleUpdate() { void consoleUpdate() {
#ifdef DUSK_TIME_DYNAMIC
if(TIME.dynamicUpdate) return;
#endif
#ifdef DUSK_CONSOLE_POSIX #ifdef DUSK_CONSOLE_POSIX
threadMutexLock(&CONSOLE.execMutex); threadMutexLock(&CONSOLE.execMutex);
#endif #endif
// Toggle console // Toggle console
// if(inputPressed(INPUT_ACTION_CONSOLE)) { if(inputPressed(INPUT_ACTION_CONSOLE)) {
// CONSOLE.visible = !CONSOLE.visible; consoleVarSetBool("console", !consoleVarGetBool("console", false));
// } }
// Anything to exec? // Anything to exec?
if(CONSOLE.execBufferCount == 0) { if(CONSOLE.execBufferCount == 0) {
@@ -379,21 +413,19 @@ void consoleUpdate() {
} }
errorret_t consoleDraw() { errorret_t consoleDraw() {
if(!CONSOLE.visible) { if(!consoleVarGetBool("console", false)) {
errorOk(); errorOk();
} }
errorChain(shaderSetTexture( for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &DEFAULT_FONT_TEXTURE
));
errorChain(shaderSetColor(&SHADER_UNLIT, SHADER_UNLIT_COLOR, COLOR_WHITE));
errorChain(textDraw( errorChain(textDraw(
32, 32, 0, DEFAULT_FONT_TILESET.tileHeight * i,
"Hello World", CONSOLE.line[i],
COLOR_WHITE, COLOR_WHITE,
&DEFAULT_FONT_TILESET, &DEFAULT_FONT_TILESET,
&DEFAULT_FONT_TEXTURE &DEFAULT_FONT_TEXTURE
)); ));
}
errorChain(spriteBatchFlush()); errorChain(spriteBatchFlush());
errorOk(); errorOk();
} }
+36 -2
View File
@@ -46,8 +46,6 @@ typedef struct {
consolecmd_t *cmdGet; consolecmd_t *cmdGet;
consolecmd_t *cmdSet; consolecmd_t *cmdSet;
bool_t visible;
#ifdef DUSK_CONSOLE_POSIX #ifdef DUSK_CONSOLE_POSIX
char_t inputBuffer[CONSOLE_LINE_MAX]; char_t inputBuffer[CONSOLE_LINE_MAX];
thread_t thread; thread_t thread;
@@ -94,6 +92,42 @@ consolevar_t * consoleRegVar(
*/ */
consolevar_t * consoleVarGet(const char_t *name); consolevar_t * consoleVarGet(const char_t *name);
/**
* Gets the value of a console variable as an int32_t.
*
* @param name The name of the variable.
* @param initial The default value to return if the variable is not found or
* invalid.
* @return The value of the variable, or default if not found or invalid.
*/
int32_t consoleVarGetInt(const char_t *name, const int32_t initial);
/**
* Gets the value of a console variable as a bool_t.
*
* @param name The name of the variable.
* @param initial The default value to return if the variable is not found or
* invalid.
* @return The value of the variable, or default if not found or invalid.
*/
bool_t consoleVarGetBool(const char_t *name, const bool_t initial);
/**
* Sets the value of a console variable as an int32_t.
*
* @param name The name of the variable.
* @param value The new value of the variable.
*/
void consoleVarSetInt(const char_t *name, const int32_t value);
/**
* Sets the value of a console variable as a bool_t.
*
* @param name The name of the variable.
* @param value The new value of the variable.
*/
void consoleVarSetBool(const char_t *name, const bool_t value);
/** /**
* Prints a message to the console. * Prints a message to the console.
* *
+1 -1
View File
@@ -18,5 +18,5 @@
#define CONSOLE_ALIAS_MAX 32 #define CONSOLE_ALIAS_MAX 32
#define CONSOLE_VAR_NAME_MAX 32 #define CONSOLE_VAR_NAME_MAX 32
#define CONSOLE_VAR_VALUE_MAX 128 #define CONSOLE_VAR_VALUE_MAX 32
#define CONSOLE_VAR_EVENTS_MAX 8 #define CONSOLE_VAR_EVENTS_MAX 8
+2 -1
View File
@@ -5,6 +5,7 @@ LEFT,
RIGHT, RIGHT,
ACCEPT, ACCEPT,
CANCEL, CANCEL,
RAGEQUIT RAGEQUIT,
CONSOLE,
POINTERX, POINTERX,
POINTERY, POINTERY,
1 id, id
5 RIGHT, RIGHT
6 ACCEPT, ACCEPT
7 CANCEL, CANCEL
8 RAGEQUIT RAGEQUIT
9 CONSOLE
10 POINTERX, POINTERX
11 POINTERY, POINTERY
+8 -5
View File
@@ -41,18 +41,20 @@ errorret_t sceneRender(void) {
entityid_t camCount = componentGetEntitiesWithComponent( entityid_t camCount = componentGetEntitiesWithComponent(
COMPONENT_TYPE_CAMERA, camEnts, camComps COMPONENT_TYPE_CAMERA, camEnts, camComps
); );
if(camCount == 0) errorOk();
// Prep Matricies
mat4 view, proj, model;
if(camCount > 0) {
// Get meshes // Get meshes
entityid_t meshEnts[ENTITY_COUNT_MAX]; entityid_t meshEnts[ENTITY_COUNT_MAX];
componentid_t meshComps[ENTITY_COUNT_MAX]; componentid_t meshComps[ENTITY_COUNT_MAX];
entityid_t meshCount = componentGetEntitiesWithComponent( entityid_t meshCount = componentGetEntitiesWithComponent(
COMPONENT_TYPE_MESH, meshEnts, meshComps COMPONENT_TYPE_MESH, meshEnts, meshComps
); );
if(meshCount == 0) errorOk();
// Prep Matricies if(meshCount > 0) {
mat4 view, proj, model;
errorChain(shaderBind(&SHADER_UNLIT)); errorChain(shaderBind(&SHADER_UNLIT));
// For each camera. // For each camera.
@@ -113,6 +115,8 @@ errorret_t sceneRender(void) {
errorChain(meshDraw(mesh, 0, -1)); errorChain(meshDraw(mesh, 0, -1));
} }
} }
}
}
// Here is where UI will go // Here is where UI will go
glm_ortho( glm_ortho(
@@ -133,7 +137,6 @@ errorret_t sceneRender(void) {
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)); errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view)); errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model)); errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
errorChain(consoleDraw()); errorChain(consoleDraw());
errorOk(); errorOk();