From b00ca3d48c8912756a97b14af21f61a2bf397d9a Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 6 Oct 2025 23:16:19 -0500 Subject: [PATCH] scene crap --- assets/config/init-base.dcf | 4 +++- src/console/cmd/cmdscene.h | 2 +- src/console/console.c | 5 ++++- src/display/display.c | 7 ++----- src/rpg/rpg.h | 13 +++++++++++++ src/scene/scene.h | 15 ++++++--------- src/scene/scene/scenetest.h | 38 +++++++++++++++++++++++++++++++++++++ src/scene/scenedata.h | 15 +++++++++++++++ src/scene/scenemanager.c | 38 ++++++++++++++++++------------------- src/ui/CMakeLists.txt | 1 + src/ui/ui.c | 26 +++++++++++++++++++++++++ src/ui/ui.h | 35 ++++++++++++++++++++++++++++++++++ 12 files changed, 163 insertions(+), 36 deletions(-) create mode 100644 src/rpg/rpg.h create mode 100644 src/scene/scene/scenetest.h create mode 100644 src/scene/scenedata.h create mode 100644 src/ui/ui.c create mode 100644 src/ui/ui.h diff --git a/assets/config/init-base.dcf b/assets/config/init-base.dcf index cffccea..b42fc9e 100644 --- a/assets/config/init-base.dcf +++ b/assets/config/init-base.dcf @@ -1,2 +1,4 @@ echo " = Dawn Init = "; -fps 1; \ No newline at end of file + +fps 1; +scene test; \ No newline at end of file diff --git a/src/console/cmd/cmdscene.h b/src/console/cmd/cmdscene.h index ea8fb3d..ca8fa13 100644 --- a/src/console/cmd/cmdscene.h +++ b/src/console/cmd/cmdscene.h @@ -24,7 +24,7 @@ void cmdScene(const consolecmdexec_t *exec) { if((scene->flags & SCENE_FLAG_INITIALIZED) == 0) { if(scene->init) { - errorret_t ret = errorPrint(scene->init()); + errorret_t ret = errorPrint(scene->init(scene->data)); if(ret.code != ERROR_OK) { errorCatch(ret); consolePrint("Error: Failed to initialize scene '%s'.", exec->argv[0]); diff --git a/src/console/console.c b/src/console/console.c index 9c75030..a2fd50f 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -27,7 +27,10 @@ console_t CONSOLE; void consoleInit() { memoryZero(&CONSOLE, sizeof(console_t)); - // Register the get and set command. + // Register vars + consoleRegVar("fps", "0", NULL); + + // Register cmds CONSOLE.cmdGet = consoleRegCmd("get", cmdGet); CONSOLE.cmdSet = consoleRegCmd("set", cmdSet); consoleRegCmd("quit", cmdQuit); diff --git a/src/display/display.c b/src/display/display.c index bb7dd2f..4d4afe4 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -63,11 +63,6 @@ errorret_t displayInit(void) { glEnableClientState(GL_VERTEX_ARRAY); #endif - // Commands - - // Variables - consoleRegVar("fps", "0", NULL); - quadInit(); frameBufferInitBackbuffer(); spriteBatchInit(); @@ -115,6 +110,8 @@ errorret_t displayUpdate(void) { // Bind screen and render scene screenBind(); sceneManagerRender(); + + // UI will probs go here // Finish up spriteBatchFlush(); diff --git a/src/rpg/rpg.h b/src/rpg/rpg.h new file mode 100644 index 0000000..5d7ba8f --- /dev/null +++ b/src/rpg/rpg.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +typedef struct { + map_t map; +} rpg_t; \ No newline at end of file diff --git a/src/scene/scene.h b/src/scene/scene.h index fdb589d..67bd5a4 100644 --- a/src/scene/scene.h +++ b/src/scene/scene.h @@ -10,19 +10,16 @@ #include "error/error.h" #include "display/color.h" -#define SCENE_FLAG_ACTIVE (1 << 0) -#define SCENE_FLAG_INITIALIZED (1 << 1) +#define SCENE_FLAG_INITIALIZED (1 << 0) typedef struct { const char_t *name; + void *data; - errorret_t (*init)(void); - void (*update)(void); - void (*render)(void); - void (*dispose)(void); - - void (*active)(void); - void (*sleep)(void); + errorret_t (*init)(void *data); + void (*update)(void *data); + void (*render)(void *data); + void (*dispose)(void *data); uint8_t flags; color_t background; diff --git a/src/scene/scene/scenetest.h b/src/scene/scene/scenetest.h new file mode 100644 index 0000000..3a9a15a --- /dev/null +++ b/src/scene/scene/scenetest.h @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "scene/scene.h" + +typedef struct { + int32_t nothing; +} scenetest_t; + +static errorret_t sceneTestInit(scenetest_t *test) { + printf("Scene Test Init\n"); + errorOk(); +} + +static void sceneTestUpdate(scenetest_t *test) { + +} + +static void sceneTestRender(scenetest_t *test) { + +} + +static void sceneTestDispose(scenetest_t *test) { + +} + +static scene_t SCENE_TEST = { + .name = "test", + .init = sceneTestInit, + .update = sceneTestUpdate, + .render = sceneTestRender, + .dispose = sceneTestDispose +}; \ No newline at end of file diff --git a/src/scene/scenedata.h b/src/scene/scenedata.h new file mode 100644 index 0000000..aa97d84 --- /dev/null +++ b/src/scene/scenedata.h @@ -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 "scene/scene.h" + +#include "scene/scene/scenetest.h" + +typedef union { + scenetest_t sceneTest; +} scenedata_t; \ No newline at end of file diff --git a/src/scene/scenemanager.c b/src/scene/scenemanager.c index b13deb1..85d3dc8 100644 --- a/src/scene/scenemanager.c +++ b/src/scene/scenemanager.c @@ -12,10 +12,14 @@ #include "display/framebuffer.h" #include "util/string.h" +#include "scene/scene/scenetest.h" + scenemanager_t SCENE_MANAGER; errorret_t sceneManagerInit(void) { memoryZero(&SCENE_MANAGER, sizeof(scenemanager_t)); + + // sceneManagerRegisterScene(&SCENE_TEST); errorOk(); } @@ -47,13 +51,16 @@ void sceneManagerRegisterScene(scene_t *scene) { void sceneManagerSetScene(scene_t *scene) { if(SCENE_MANAGER.current) { - if(SCENE_MANAGER.current->sleep) SCENE_MANAGER.current->sleep(); - // TODO: Should dispose? - SCENE_MANAGER.current->flags &= ~( - SCENE_FLAG_INITIALIZED | SCENE_FLAG_ACTIVE + assertTrue( + SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED, + "Current scene not initialized" ); - if(SCENE_MANAGER.current->dispose) SCENE_MANAGER.current->dispose(); + + SCENE_MANAGER.current->flags &= ~SCENE_FLAG_INITIALIZED; + if(SCENE_MANAGER.current->dispose) { + SCENE_MANAGER.current->dispose(SCENE_MANAGER.current->data); + } } SCENE_MANAGER.current = scene; @@ -63,34 +70,25 @@ void sceneManagerSetScene(scene_t *scene) { scene->flags & SCENE_FLAG_INITIALIZED, "Scene not initialized" ); - - if(scene->active) scene->active(); - scene->flags |= SCENE_FLAG_ACTIVE; } } void sceneManagerUpdate(void) { if(!SCENE_MANAGER.current) return; - assertTrue( - SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE, - "Current scene not active" - ); assertTrue( SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED, "Current scene not initialized" ); - if(SCENE_MANAGER.current->update) SCENE_MANAGER.current->update(); + if(SCENE_MANAGER.current->update) { + SCENE_MANAGER.current->update(SCENE_MANAGER.current->data); + } } void sceneManagerRender(void) { if(!SCENE_MANAGER.current) return; - assertTrue( - SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE, - "Current scene not active" - ); assertTrue( SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED, "Current scene not initialized" @@ -101,14 +99,16 @@ void sceneManagerRender(void) { SCENE_MANAGER.current->background ); - if(SCENE_MANAGER.current->render) SCENE_MANAGER.current->render(); + if(SCENE_MANAGER.current->render) { + SCENE_MANAGER.current->render(SCENE_MANAGER.current->data); + } } void sceneManagerDispose(void) { for(uint8_t i = 0; i < SCENE_MANAGER.sceneCount; i++) { scene_t *scene = SCENE_MANAGER.scenes[i]; if(scene->flags & SCENE_FLAG_INITIALIZED) { - scene->dispose(); + scene->dispose(scene->data); } } diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 14dadcf..575297b 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -6,6 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE + ui.c uitext.c uifps.c uiframe.c diff --git a/src/ui/ui.c b/src/ui/ui.c new file mode 100644 index 0000000..91adaff --- /dev/null +++ b/src/ui/ui.c @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "ui.h" + +ui_t UI; + +void uiInit(void) { + // Initialize UI components here +} + +void uiUpdate(void) { + // Update UI state here +} + +void uiRender(void) { + // Render UI elements here +} + +void uiDispose(void) { + // Clean up UI resources here +} \ No newline at end of file diff --git a/src/ui/ui.h b/src/ui/ui.h new file mode 100644 index 0000000..b374c59 --- /dev/null +++ b/src/ui/ui.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +typedef struct { + int32_t nothing; +} ui_t; + +extern ui_t UI; + +/** + * Initializes the UI system, loading necessary resources. + */ +void uiInit(void); + +/** + * Updates the UI state, handling user interactions and animations. + */ +void uiUpdate(void); + +/** + * Renders the UI elements to the screen. + */ +void uiRender(void); + +/** + * Cleans up and frees all UI resources. + */ +void uiDispose(void); \ No newline at end of file