add quit command
This commit is contained in:
@@ -10,3 +10,6 @@ target_sources(${DUSK_TARGET_NAME}
|
|||||||
consolecmd.c
|
consolecmd.c
|
||||||
consolevar.c
|
consolevar.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Subdirectories
|
||||||
|
add_subdirectory(cmd)
|
9
src/dusk/console/cmd/CMakeLists.txt
Normal file
9
src/dusk/console/cmd/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Copyright (c) 2025 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DUSK_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
)
|
18
src/dusk/console/cmd/cmdecho.h
Normal file
18
src/dusk/console/cmd/cmdecho.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "console/console.h"
|
||||||
|
|
||||||
|
void cmdEcho(const consolecmdexec_t *exec) {
|
||||||
|
assertTrue(
|
||||||
|
exec->argc >= 1,
|
||||||
|
"echo command requires 1 argument."
|
||||||
|
);
|
||||||
|
|
||||||
|
consolePrint("%s", exec->argv[0]);
|
||||||
|
}
|
25
src/dusk/console/cmd/cmdget.h
Normal file
25
src/dusk/console/cmd/cmdget.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "console/console.h"
|
||||||
|
|
||||||
|
void cmdGet(const consolecmdexec_t *exec) {
|
||||||
|
assertTrue(
|
||||||
|
exec->argc >= 1,
|
||||||
|
"Get command requires 1 argument."
|
||||||
|
);
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
||||||
|
consolevar_t *var = &CONSOLE.variables[i];
|
||||||
|
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
|
||||||
|
consolePrint("%s", var->value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
consolePrint("Error: Variable '%s' not found.", exec->argv[0]);
|
||||||
|
}
|
15
src/dusk/console/cmd/cmdquit.h
Normal file
15
src/dusk/console/cmd/cmdquit.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "console/console.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
void cmdQuit(const consolecmdexec_t *exec) {
|
||||||
|
consolePrint("Quitting application...");
|
||||||
|
GAME.running = false;
|
||||||
|
}
|
27
src/dusk/console/cmd/cmdset.h
Normal file
27
src/dusk/console/cmd/cmdset.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "console/console.h"
|
||||||
|
|
||||||
|
void cmdSet(const consolecmdexec_t *exec) {
|
||||||
|
assertTrue(exec->argc >= 2, "set command requires 2 arguments.");
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
||||||
|
consolevar_t *var = &CONSOLE.variables[i];
|
||||||
|
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
|
||||||
|
consoleVarSetValue(var, exec->argv[1]);
|
||||||
|
consolePrint("%s %s", var->name, var->value);
|
||||||
|
for(i = 0; i < var->eventCount; i++) {
|
||||||
|
assertNotNull(var->events[i], "Event is NULL");
|
||||||
|
var->events[i](var);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
consolePrint("Error: Variable '%s' not found.", exec->argv[0]);
|
||||||
|
}
|
@@ -9,6 +9,11 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
#include "console/cmd/cmdquit.h"
|
||||||
|
#include "console/cmd/cmdecho.h"
|
||||||
|
#include "console/cmd/cmdset.h"
|
||||||
|
#include "console/cmd/cmdget.h"
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
console_t CONSOLE;
|
console_t CONSOLE;
|
||||||
@@ -19,6 +24,7 @@ void consoleInit() {
|
|||||||
// Register the get and set command.
|
// Register the get and set command.
|
||||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
||||||
|
consoleRegCmd("quit", cmdQuit);
|
||||||
consoleRegCmd("echo", cmdEcho);
|
consoleRegCmd("echo", cmdEcho);
|
||||||
|
|
||||||
consolePrint(" = Dawn Console = ");
|
consolePrint(" = Dawn Console = ");
|
||||||
@@ -266,49 +272,6 @@ void consoleExec(const char_t *line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdGet(const consolecmdexec_t *exec) {
|
|
||||||
assertTrue(
|
|
||||||
exec->argc >= 1,
|
|
||||||
"Get command requires 1 argument."
|
|
||||||
);
|
|
||||||
|
|
||||||
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
|
||||||
consolevar_t *var = &CONSOLE.variables[i];
|
|
||||||
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
|
|
||||||
consolePrint("%s", var->value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
consolePrint("Error: Variable '%s' not found.", exec->argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmdSet(const consolecmdexec_t *exec) {
|
|
||||||
assertTrue(exec->argc >= 2, "set command requires 2 arguments.");
|
|
||||||
|
|
||||||
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
|
||||||
consolevar_t *var = &CONSOLE.variables[i];
|
|
||||||
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
|
|
||||||
consoleVarSetValue(var, exec->argv[1]);
|
|
||||||
consolePrint("%s %s", var->name, var->value);
|
|
||||||
for(i = 0; i < var->eventCount; i++) {
|
|
||||||
assertNotNull(var->events[i], "Event is NULL");
|
|
||||||
var->events[i](var);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
consolePrint("Error: Variable '%s' not found.", exec->argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmdEcho(const consolecmdexec_t *exec) {
|
|
||||||
assertTrue(
|
|
||||||
exec->argc >= 1,
|
|
||||||
"echo command requires 1 argument."
|
|
||||||
);
|
|
||||||
|
|
||||||
consolePrint("%s", exec->argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// May move these later
|
// May move these later
|
||||||
void consoleUpdate() {
|
void consoleUpdate() {
|
||||||
if(inputPressed(INPUT_BIND_CONSOLE)) {
|
if(inputPressed(INPUT_BIND_CONSOLE)) {
|
||||||
@@ -364,27 +327,3 @@ void consoleUpdate() {
|
|||||||
// Clear the exec buffer
|
// Clear the exec buffer
|
||||||
CONSOLE.execBufferCount = 0;
|
CONSOLE.execBufferCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void consoleDraw() {
|
|
||||||
// if(!CONSOLE.open) return;
|
|
||||||
|
|
||||||
// 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, YELLOW);
|
|
||||||
// i++;
|
|
||||||
// } while(i < CONSOLE_HISTORY_MAX);
|
|
||||||
|
|
||||||
// DrawText(
|
|
||||||
// CONSOLE.inputBuffer, 0,
|
|
||||||
// (CONSOLE_HISTORY_MAX + 1) * fontSize,
|
|
||||||
// fontSize,
|
|
||||||
// PINK
|
|
||||||
// );
|
|
||||||
// }
|
|
@@ -103,3 +103,4 @@ void consoleUpdate();
|
|||||||
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);
|
||||||
|
void cmdQuit(const consolecmdexec_t *exec);
|
@@ -15,7 +15,11 @@
|
|||||||
#include "ui/uitextbox.h"
|
#include "ui/uitextbox.h"
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
|
|
||||||
|
game_t GAME;
|
||||||
|
|
||||||
void gameInit(void) {
|
void gameInit(void) {
|
||||||
|
GAME.running = true;
|
||||||
|
|
||||||
consoleInit();
|
consoleInit();
|
||||||
inputInit();
|
inputInit();
|
||||||
eventInit();
|
eventInit();
|
||||||
|
@@ -8,6 +8,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool_t running;
|
||||||
|
} game_t;
|
||||||
|
|
||||||
|
extern game_t GAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the game, this should be called before any other game functions.
|
* Initializes the game, this should be called before any other game functions.
|
||||||
* This should be called by the parent platform at a time that it deems
|
* This should be called by the parent platform at a time that it deems
|
||||||
|
@@ -18,8 +18,9 @@ typedef inputbind_t inputstate_t;
|
|||||||
#define INPUT_BIND_ACTION (1 << 4)
|
#define INPUT_BIND_ACTION (1 << 4)
|
||||||
#define INPUT_BIND_CANCEL (1 << 5)
|
#define INPUT_BIND_CANCEL (1 << 5)
|
||||||
#define INPUT_BIND_CONSOLE (1 << 6)
|
#define INPUT_BIND_CONSOLE (1 << 6)
|
||||||
|
#define INPUT_BIND_QUIT (1 << 7)
|
||||||
|
|
||||||
#define INPUT_BIND_COUNT (INPUT_BIND_CONSOLE + 1)
|
#define INPUT_BIND_COUNT (INPUT_BIND_QUIT + 1)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t current;
|
uint8_t current;
|
||||||
|
@@ -16,6 +16,7 @@ target_sources(${DUSK_TARGET_NAME}
|
|||||||
add_subdirectory(camera)
|
add_subdirectory(camera)
|
||||||
add_subdirectory(framebuffer)
|
add_subdirectory(framebuffer)
|
||||||
add_subdirectory(mesh)
|
add_subdirectory(mesh)
|
||||||
|
add_subdirectory(overworld)
|
||||||
add_subdirectory(texture)
|
add_subdirectory(texture)
|
||||||
add_subdirectory(spritebatch)
|
add_subdirectory(spritebatch)
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
10
src/dusksdl2/display/overworld/CMakeLists.txt
Normal file
10
src/dusksdl2/display/overworld/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Copyright (c) 2025 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DUSK_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
renderoverworld.c
|
||||||
|
)
|
16
src/dusksdl2/display/overworld/renderoverworld.c
Normal file
16
src/dusksdl2/display/overworld/renderoverworld.c
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "renderoverworld.h"
|
||||||
|
|
||||||
|
void renderOverworldInit(void) {
|
||||||
|
// Initialize overworld rendering resources here
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderOverworldDispose(void) {
|
||||||
|
// Clean up overworld rendering resources here
|
||||||
|
}
|
34
src/dusksdl2/display/overworld/renderoverworld.h
Normal file
34
src/dusksdl2/display/overworld/renderoverworld.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "world/chunk.h"
|
||||||
|
#include "display/mesh/mesh.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mesh_t meshBase;
|
||||||
|
meshvertex_t verticesBase[CHUNK_TILE_COUNT];
|
||||||
|
|
||||||
|
mesh_t meshBaseOverlay;
|
||||||
|
meshvertex_t verticesBaseOverlay[CHUNK_TILE_COUNT];
|
||||||
|
} renderchunk_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
renderchunk_t chunks[CHUNK_MAP_COUNT];
|
||||||
|
} renderoverworld_t;
|
||||||
|
|
||||||
|
extern renderoverworld_t RENDER_OVERWORLD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the render overworld.
|
||||||
|
*/
|
||||||
|
void renderOverworldInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of the render overworld.
|
||||||
|
*/
|
||||||
|
void renderOverworldDispose(void);
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "renderscene.h"
|
#include "renderscene.h"
|
||||||
|
#include "display/overworld/renderoverworld.h"
|
||||||
|
|
||||||
renderscenecallback_t RENDER_SCENE_CALLBACKS[SCENE_COUNT] = {
|
renderscenecallback_t RENDER_SCENE_CALLBACKS[SCENE_COUNT] = {
|
||||||
[SCENE_INITIAL] = {
|
[SCENE_INITIAL] = {
|
||||||
@@ -15,9 +16,9 @@ renderscenecallback_t RENDER_SCENE_CALLBACKS[SCENE_COUNT] = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[SCENE_OVERWORLD] = {
|
[SCENE_OVERWORLD] = {
|
||||||
.init = NULL,
|
.init = renderOverworldInit,
|
||||||
.draw = NULL,
|
.draw = NULL,
|
||||||
.dispose = NULL
|
.dispose = renderOverworldDispose
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -49,6 +49,7 @@
|
|||||||
{ SDL_SCANCODE_SPACE, INPUT_BIND_ACTION },
|
{ SDL_SCANCODE_SPACE, INPUT_BIND_ACTION },
|
||||||
{ SDL_SCANCODE_ESCAPE, INPUT_BIND_CANCEL },
|
{ SDL_SCANCODE_ESCAPE, INPUT_BIND_CANCEL },
|
||||||
{ SDL_SCANCODE_GRAVE, INPUT_BIND_CONSOLE },
|
{ SDL_SCANCODE_GRAVE, INPUT_BIND_CONSOLE },
|
||||||
|
{ SDL_SCANCODE_Q, INPUT_BIND_QUIT },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@@ -26,12 +26,8 @@ int main(int argc, char *argv[]) {
|
|||||||
gameUpdate();
|
gameUpdate();
|
||||||
mainError(renderDraw());
|
mainError(renderDraw());
|
||||||
|
|
||||||
if(inputPressed(INPUT_BIND_UP)) consolePrint("Up pressed");
|
if(inputPressed(INPUT_BIND_QUIT)) consoleExec("quit");
|
||||||
if(inputPressed(INPUT_BIND_DOWN)) consolePrint("Down pressed");
|
if(!GAME.running) break;
|
||||||
if(inputPressed(INPUT_BIND_LEFT)) consolePrint("Left pressed");
|
|
||||||
if(inputPressed(INPUT_BIND_RIGHT)) consolePrint("Right pressed");
|
|
||||||
if(inputPressed(INPUT_BIND_ACTION)) consolePrint("Action pressed");
|
|
||||||
if(inputPressed(INPUT_BIND_CANCEL)) consolePrint("Cancel pressed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gameDispose();
|
gameDispose();
|
||||||
|
Reference in New Issue
Block a user