Update console
This commit is contained in:
@@ -15,7 +15,6 @@ console_t CONSOLE;
|
|||||||
|
|
||||||
void consoleInit() {
|
void consoleInit() {
|
||||||
memoryZero(&CONSOLE, sizeof(console_t));
|
memoryZero(&CONSOLE, sizeof(console_t));
|
||||||
pthread_mutex_init(&CONSOLE.lock, NULL); // Initialize the mutex
|
|
||||||
|
|
||||||
// Register the get and set command.
|
// Register the get and set command.
|
||||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||||
@@ -26,10 +25,8 @@ void consoleInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function) {
|
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function) {
|
||||||
pthread_mutex_lock(&CONSOLE.lock); // Lock
|
|
||||||
consolecmd_t *cmd = &CONSOLE.commands[CONSOLE.commandCount++];
|
consolecmd_t *cmd = &CONSOLE.commands[CONSOLE.commandCount++];
|
||||||
consoleCmdInit(cmd, name, function);
|
consoleCmdInit(cmd, name, function);
|
||||||
pthread_mutex_unlock(&CONSOLE.lock); // Unlock
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +35,8 @@ consolevar_t * consoleRegVar(
|
|||||||
const char_t *value,
|
const char_t *value,
|
||||||
consolevarchanged_t event
|
consolevarchanged_t event
|
||||||
) {
|
) {
|
||||||
pthread_mutex_lock(&CONSOLE.lock); // Lock
|
|
||||||
consolevar_t *var = &CONSOLE.variables[CONSOLE.variableCount++];
|
consolevar_t *var = &CONSOLE.variables[CONSOLE.variableCount++];
|
||||||
consoleVarInitListener(var, name, value, event);
|
consoleVarInitListener(var, name, value, event);
|
||||||
pthread_mutex_unlock(&CONSOLE.lock); // Unlock
|
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +65,6 @@ void consolePrint(const char_t *message, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void consoleExec(const char_t *line) {
|
void consoleExec(const char_t *line) {
|
||||||
pthread_mutex_lock(&CONSOLE.lock); // Lock
|
|
||||||
assertNotNull(line, "line must not be NULL");
|
assertNotNull(line, "line must not be NULL");
|
||||||
assertTrue(
|
assertTrue(
|
||||||
CONSOLE.execBufferCount < CONSOLE_EXEC_BUFFER_MAX,
|
CONSOLE.execBufferCount < CONSOLE_EXEC_BUFFER_MAX,
|
||||||
@@ -270,23 +264,6 @@ void consoleExec(const char_t *line) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&CONSOLE.lock); // Unlock
|
|
||||||
}
|
|
||||||
|
|
||||||
void consoleProcess() {
|
|
||||||
pthread_mutex_lock(&CONSOLE.lock); // Lock
|
|
||||||
for(uint32_t i = 0; i < CONSOLE.execBufferCount; i++) {
|
|
||||||
consolecmdexec_t *exec = &CONSOLE.execBuffer[i];
|
|
||||||
|
|
||||||
assertNotNull(exec->cmd, "Command execution has no command.");
|
|
||||||
|
|
||||||
exec->cmd->function(exec);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear the exec buffer
|
|
||||||
CONSOLE.execBufferCount = 0;
|
|
||||||
pthread_mutex_unlock(&CONSOLE.lock); // Unlock
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdGet(const consolecmdexec_t *exec) {
|
void cmdGet(const consolecmdexec_t *exec) {
|
||||||
@@ -334,62 +311,71 @@ void cmdEcho(const consolecmdexec_t *exec) {
|
|||||||
|
|
||||||
// May move these later
|
// May move these later
|
||||||
void consoleUpdate() {
|
void consoleUpdate() {
|
||||||
if(inputIsPressed(INPUT_TOGGLE_CONSOLE)) {
|
for(uint32_t i = 0; i < CONSOLE.execBufferCount; i++) {
|
||||||
CONSOLE.open = !CONSOLE.open;
|
consolecmdexec_t *exec = &CONSOLE.execBuffer[i];
|
||||||
} else if(CONSOLE.open) {
|
assertNotNull(exec->cmd, "Command execution has no command.");
|
||||||
switch(INPUT.keyPressed) {
|
exec->cmd->function(exec);
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KEY_ENTER:
|
|
||||||
consoleExec(CONSOLE.inputBuffer);
|
|
||||||
CONSOLE.inputIndex = 0;
|
|
||||||
CONSOLE.inputBuffer[0] = '\0';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KEY_BACKSPACE:
|
|
||||||
if(CONSOLE.inputIndex > 0) {
|
|
||||||
CONSOLE.inputIndex--;
|
|
||||||
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if(
|
|
||||||
INPUT.keyPressed >= 32 &&
|
|
||||||
INPUT.keyPressed <= 126 &&
|
|
||||||
CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1
|
|
||||||
) {
|
|
||||||
CONSOLE.inputBuffer[CONSOLE.inputIndex++] = INPUT.charPressed;
|
|
||||||
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleProcess();
|
// #if DUSK_KEYBOARD_SUPPORT == 1
|
||||||
|
// uint8_t key;
|
||||||
|
// while((key = inputKeyboardPop()) != 0) {
|
||||||
|
// printf("Key pressed: %c\n", key);
|
||||||
|
// switch(key) {
|
||||||
|
// case 0:
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case INPUT_KEY_ENTER:
|
||||||
|
// consoleExec(CONSOLE.inputBuffer);
|
||||||
|
// CONSOLE.inputIndex = 0;
|
||||||
|
// CONSOLE.inputBuffer[0] = '\0';
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case INPUT_KEY_BACKSPACE:
|
||||||
|
// if(CONSOLE.inputIndex > 0) {
|
||||||
|
// CONSOLE.inputIndex--;
|
||||||
|
// CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// default:
|
||||||
|
// if(
|
||||||
|
// key >= INPUT_KEY_ASCII_START && key <= INPUT_KEY_ASCII_END &&
|
||||||
|
// CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1
|
||||||
|
// ) {
|
||||||
|
// CONSOLE.inputBuffer[CONSOLE.inputIndex++] = key;
|
||||||
|
// CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// Clear the exec buffer
|
||||||
|
CONSOLE.execBufferCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void consoleDraw() {
|
// void consoleDraw() {
|
||||||
if(!CONSOLE.open) return;
|
// if(!CONSOLE.open) return;
|
||||||
|
|
||||||
size_t i = 0;
|
// size_t i = 0;
|
||||||
char_t *line;
|
// char_t *line;
|
||||||
int32_t fontSize = 10;
|
// int32_t fontSize = 10;
|
||||||
do {
|
// do {
|
||||||
line = CONSOLE.line[i];
|
// line = CONSOLE.line[i];
|
||||||
if(line[0] == '\0') {
|
// if(line[0] == '\0') {
|
||||||
i++;
|
// i++;
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
DrawText(line, 0, i*fontSize, fontSize, YELLOW);
|
// DrawText(line, 0, i*fontSize, fontSize, YELLOW);
|
||||||
i++;
|
// i++;
|
||||||
} while(i < CONSOLE_HISTORY_MAX);
|
// } while(i < CONSOLE_HISTORY_MAX);
|
||||||
|
|
||||||
DrawText(
|
// DrawText(
|
||||||
CONSOLE.inputBuffer, 0,
|
// CONSOLE.inputBuffer, 0,
|
||||||
(CONSOLE_HISTORY_MAX + 1) * fontSize,
|
// (CONSOLE_HISTORY_MAX + 1) * fontSize,
|
||||||
fontSize,
|
// fontSize,
|
||||||
PINK
|
// PINK
|
||||||
);
|
// );
|
||||||
}
|
// }
|
@@ -37,13 +37,14 @@ typedef struct {
|
|||||||
|
|
||||||
consolecmd_t *cmdGet;
|
consolecmd_t *cmdGet;
|
||||||
consolecmd_t *cmdSet;
|
consolecmd_t *cmdSet;
|
||||||
pthread_mutex_t lock; // Mutex for thread safety
|
|
||||||
|
bool_t visible;
|
||||||
|
|
||||||
// May move these later
|
// May move these later
|
||||||
char_t inputBuffer[CONSOLE_LINE_MAX];
|
// #if DUSK_KEYBOARD_SUPPORT == 1
|
||||||
int32_t inputIndex;
|
// char_t inputBuffer[CONSOLE_LINE_MAX];
|
||||||
|
// int32_t inputIndex;
|
||||||
bool_t open;
|
// #endif
|
||||||
} console_t;
|
} console_t;
|
||||||
|
|
||||||
extern console_t CONSOLE;
|
extern console_t CONSOLE;
|
||||||
@@ -97,18 +98,8 @@ void consoleExec(const char_t *line);
|
|||||||
/**
|
/**
|
||||||
* Processes the console's pending commands.
|
* Processes the console's pending commands.
|
||||||
*/
|
*/
|
||||||
void consoleProcess();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the console's input buffer and handles user input.
|
|
||||||
*/
|
|
||||||
void consoleUpdate();
|
void consoleUpdate();
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws the console's output.
|
|
||||||
*/
|
|
||||||
void consoleDraw();
|
|
||||||
|
|
||||||
void cmdGet(const consolecmdexec_t *exec);
|
void cmdGet(const consolecmdexec_t *exec);
|
||||||
void cmdSet(const consolecmdexec_t *exec);
|
void cmdSet(const consolecmdexec_t *exec);
|
||||||
void cmdEcho(const consolecmdexec_t *exec);
|
void cmdEcho(const consolecmdexec_t *exec);
|
@@ -12,6 +12,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
typedef bool bool_t;
|
typedef bool bool_t;
|
||||||
typedef int int_t;
|
typedef int int_t;
|
||||||
|
@@ -13,8 +13,10 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "event/event.h"
|
#include "event/event.h"
|
||||||
#include "ui/uitextbox.h"
|
#include "ui/uitextbox.h"
|
||||||
|
#include "console/console.h"
|
||||||
|
|
||||||
void gameInit(void) {
|
void gameInit(void) {
|
||||||
|
consoleInit();
|
||||||
inputInit();
|
inputInit();
|
||||||
eventInit();
|
eventInit();
|
||||||
uiTextboxInit();
|
uiTextboxInit();
|
||||||
@@ -28,6 +30,7 @@ void gameUpdate(void) {
|
|||||||
uiTextboxUpdate();
|
uiTextboxUpdate();
|
||||||
eventUpdate();
|
eventUpdate();
|
||||||
|
|
||||||
|
consoleUpdate();
|
||||||
inputUpdate();
|
inputUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
* - If your system handles time dynamically, it should be ready to be used.
|
* - If your system handles time dynamically, it should be ready to be used.
|
||||||
*
|
*
|
||||||
* The systems called (in order) are;
|
* The systems called (in order) are;
|
||||||
|
* - Console.
|
||||||
* - Input system (Not the platforms input, but the game's input system).
|
* - Input system (Not the platforms input, but the game's input system).
|
||||||
* - Time system (if applicable).
|
* - Time system (if applicable).
|
||||||
* - Event System
|
* - Event System
|
||||||
|
@@ -18,6 +18,11 @@ void inputInit(void) {
|
|||||||
void inputUpdate(void) {
|
void inputUpdate(void) {
|
||||||
INPUT.previous = INPUT.current;
|
INPUT.previous = INPUT.current;
|
||||||
INPUT.current = inputStateGet();
|
INPUT.current = inputStateGet();
|
||||||
|
|
||||||
|
#if DUSK_KEYBOARD_SUPPORT == 1
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t inputIsDown(const uint8_t bind) {
|
bool_t inputIsDown(const uint8_t bind) {
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t current;
|
uint8_t current;
|
||||||
uint8_t previous;
|
uint8_t previous;
|
||||||
} input_t;
|
} input_t;
|
||||||
|
|
||||||
extern input_t INPUT;
|
extern input_t INPUT;
|
||||||
|
@@ -3,6 +3,12 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Compile defs
|
||||||
|
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
# DUSK_KEYBOARD_SUPPORT=1
|
||||||
|
)
|
||||||
|
|
||||||
# Libs
|
# Libs
|
||||||
find_package(raylib REQUIRED)
|
find_package(raylib REQUIRED)
|
||||||
|
|
||||||
@@ -11,6 +17,7 @@ target_link_libraries(${DUSK_TARGET_NAME}
|
|||||||
raylib
|
raylib
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Includes
|
# Includes
|
||||||
target_include_directories(${DUSK_TARGET_NAME}
|
target_include_directories(${DUSK_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
@@ -21,6 +28,7 @@ target_include_directories(${DUSK_TARGET_NAME}
|
|||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
input.c
|
input.c
|
||||||
|
main.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
|
@@ -9,4 +9,5 @@ target_sources(${DUSK_TARGET_NAME}
|
|||||||
drawscene.c
|
drawscene.c
|
||||||
drawoverworld.c
|
drawoverworld.c
|
||||||
drawui.c
|
drawui.c
|
||||||
|
drawconsole.c
|
||||||
)
|
)
|
33
src/duskraylib/display/draw/drawconsole.c
Normal file
33
src/duskraylib/display/draw/drawconsole.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "drawconsole.h"
|
||||||
|
#include "console/console.h"
|
||||||
|
|
||||||
|
void drawConsoleInit(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawConsoleDraw(void) {
|
||||||
|
CONSOLE.visible = true; // Set console to visible by default
|
||||||
|
if(!CONSOLE.visible) return;
|
||||||
|
|
||||||
|
BeginBlendMode(BLEND_ALPHA);
|
||||||
|
size_t i = 0;
|
||||||
|
char_t *line;
|
||||||
|
int32_t fontSize = 10;
|
||||||
|
do {
|
||||||
|
line = CONSOLE.line[i];
|
||||||
|
if(line[0] == '\0') {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DrawText(line, 0, i * fontSize, fontSize, ORANGE);
|
||||||
|
i++;
|
||||||
|
} while(i < CONSOLE_HISTORY_MAX);
|
||||||
|
|
||||||
|
EndBlendMode();
|
||||||
|
}
|
19
src/duskraylib/display/draw/drawconsole.h
Normal file
19
src/duskraylib/display/draw/drawconsole.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "duskraylib.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the console drawing system.
|
||||||
|
*/
|
||||||
|
void drawConsoleInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the console to the screen.
|
||||||
|
*/
|
||||||
|
void drawConsoleDraw(void);
|
@@ -9,6 +9,7 @@
|
|||||||
#include "display/draw/drawscene.h"
|
#include "display/draw/drawscene.h"
|
||||||
#include "display/draw/drawoverworld.h"
|
#include "display/draw/drawoverworld.h"
|
||||||
#include "display/draw/drawui.h"
|
#include "display/draw/drawui.h"
|
||||||
|
#include "display/draw/drawconsole.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
|
||||||
RenderTexture2D RENDER_SCREEN_TEXTURE;
|
RenderTexture2D RENDER_SCREEN_TEXTURE;
|
||||||
@@ -36,6 +37,7 @@ void renderInit(void) {
|
|||||||
|
|
||||||
drawOverworldInit();
|
drawOverworldInit();
|
||||||
drawUIInit();
|
drawUIInit();
|
||||||
|
drawConsoleInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderDraw(void) {
|
void renderDraw(void) {
|
||||||
@@ -75,10 +77,11 @@ void renderDraw(void) {
|
|||||||
0.0f,
|
0.0f,
|
||||||
WHITE
|
WHITE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
drawConsoleDraw();
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
EndBlendMode();
|
EndBlendMode();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderDispose(void) {
|
void renderDispose(void) {
|
||||||
|
@@ -18,6 +18,11 @@ typedef struct {
|
|||||||
uint8_t bind;
|
uint8_t bind;
|
||||||
} inputgpmap_t;
|
} inputgpmap_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t key;
|
||||||
|
uint32_t bind;
|
||||||
|
} inputkeyboardmap_t;
|
||||||
|
|
||||||
inputkbmap_t INPUT_KB_MAP[] = {
|
inputkbmap_t INPUT_KB_MAP[] = {
|
||||||
{ KEY_UP, INPUT_BIND_UP },
|
{ KEY_UP, INPUT_BIND_UP },
|
||||||
{ KEY_W, INPUT_BIND_UP },
|
{ KEY_W, INPUT_BIND_UP },
|
||||||
@@ -71,4 +76,14 @@ uint8_t inputStateGet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uint32_t inputKeyboardPop(void) {
|
||||||
|
// while(true) {
|
||||||
|
// int32_t key = GetKeyPressed();
|
||||||
|
// if(key == 0) return 0;
|
||||||
|
// printf("Got key: %d\n", key);
|
||||||
|
// return (uint32_t)key;
|
||||||
|
// }
|
||||||
|
// return 0;
|
||||||
|
// }
|
@@ -9,6 +9,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
renderInit();
|
||||||
gameInit();
|
gameInit();
|
||||||
|
|
||||||
while(!WindowShouldClose()) {
|
while(!WindowShouldClose()) {
|
||||||
|
Reference in New Issue
Block a user