scene crap

This commit is contained in:
2025-10-06 23:16:19 -05:00
parent cf2e6bf382
commit b00ca3d48c
12 changed files with 163 additions and 36 deletions

View File

@@ -1,2 +1,4 @@
echo " = Dawn Init = "; echo " = Dawn Init = ";
fps 1;
fps 1;
scene test;

View File

@@ -24,7 +24,7 @@ void cmdScene(const consolecmdexec_t *exec) {
if((scene->flags & SCENE_FLAG_INITIALIZED) == 0) { if((scene->flags & SCENE_FLAG_INITIALIZED) == 0) {
if(scene->init) { if(scene->init) {
errorret_t ret = errorPrint(scene->init()); errorret_t ret = errorPrint(scene->init(scene->data));
if(ret.code != ERROR_OK) { if(ret.code != ERROR_OK) {
errorCatch(ret); errorCatch(ret);
consolePrint("Error: Failed to initialize scene '%s'.", exec->argv[0]); consolePrint("Error: Failed to initialize scene '%s'.", exec->argv[0]);

View File

@@ -27,7 +27,10 @@ console_t CONSOLE;
void consoleInit() { void consoleInit() {
memoryZero(&CONSOLE, sizeof(console_t)); 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.cmdGet = consoleRegCmd("get", cmdGet);
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet); CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
consoleRegCmd("quit", cmdQuit); consoleRegCmd("quit", cmdQuit);

View File

@@ -63,11 +63,6 @@ errorret_t displayInit(void) {
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
#endif #endif
// Commands
// Variables
consoleRegVar("fps", "0", NULL);
quadInit(); quadInit();
frameBufferInitBackbuffer(); frameBufferInitBackbuffer();
spriteBatchInit(); spriteBatchInit();
@@ -115,6 +110,8 @@ errorret_t displayUpdate(void) {
// Bind screen and render scene // Bind screen and render scene
screenBind(); screenBind();
sceneManagerRender(); sceneManagerRender();
// UI will probs go here
// Finish up // Finish up
spriteBatchFlush(); spriteBatchFlush();

13
src/rpg/rpg.h Normal file
View File

@@ -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;

View File

@@ -10,19 +10,16 @@
#include "error/error.h" #include "error/error.h"
#include "display/color.h" #include "display/color.h"
#define SCENE_FLAG_ACTIVE (1 << 0) #define SCENE_FLAG_INITIALIZED (1 << 0)
#define SCENE_FLAG_INITIALIZED (1 << 1)
typedef struct { typedef struct {
const char_t *name; const char_t *name;
void *data;
errorret_t (*init)(void); errorret_t (*init)(void *data);
void (*update)(void); void (*update)(void *data);
void (*render)(void); void (*render)(void *data);
void (*dispose)(void); void (*dispose)(void *data);
void (*active)(void);
void (*sleep)(void);
uint8_t flags; uint8_t flags;
color_t background; color_t background;

View File

@@ -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
};

15
src/scene/scenedata.h Normal file
View 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 "scene/scene.h"
#include "scene/scene/scenetest.h"
typedef union {
scenetest_t sceneTest;
} scenedata_t;

View File

@@ -12,10 +12,14 @@
#include "display/framebuffer.h" #include "display/framebuffer.h"
#include "util/string.h" #include "util/string.h"
#include "scene/scene/scenetest.h"
scenemanager_t SCENE_MANAGER; scenemanager_t SCENE_MANAGER;
errorret_t sceneManagerInit(void) { errorret_t sceneManagerInit(void) {
memoryZero(&SCENE_MANAGER, sizeof(scenemanager_t)); memoryZero(&SCENE_MANAGER, sizeof(scenemanager_t));
// sceneManagerRegisterScene(&SCENE_TEST);
errorOk(); errorOk();
} }
@@ -47,13 +51,16 @@ void sceneManagerRegisterScene(scene_t *scene) {
void sceneManagerSetScene(scene_t *scene) { void sceneManagerSetScene(scene_t *scene) {
if(SCENE_MANAGER.current) { if(SCENE_MANAGER.current) {
if(SCENE_MANAGER.current->sleep) SCENE_MANAGER.current->sleep();
// TODO: Should dispose? // TODO: Should dispose?
SCENE_MANAGER.current->flags &= ~( assertTrue(
SCENE_FLAG_INITIALIZED | SCENE_FLAG_ACTIVE 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; SCENE_MANAGER.current = scene;
@@ -63,34 +70,25 @@ void sceneManagerSetScene(scene_t *scene) {
scene->flags & SCENE_FLAG_INITIALIZED, scene->flags & SCENE_FLAG_INITIALIZED,
"Scene not initialized" "Scene not initialized"
); );
if(scene->active) scene->active();
scene->flags |= SCENE_FLAG_ACTIVE;
} }
} }
void sceneManagerUpdate(void) { void sceneManagerUpdate(void) {
if(!SCENE_MANAGER.current) return; if(!SCENE_MANAGER.current) return;
assertTrue(
SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE,
"Current scene not active"
);
assertTrue( assertTrue(
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED, SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
"Current scene not 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) { void sceneManagerRender(void) {
if(!SCENE_MANAGER.current) return; if(!SCENE_MANAGER.current) return;
assertTrue(
SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE,
"Current scene not active"
);
assertTrue( assertTrue(
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED, SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
"Current scene not initialized" "Current scene not initialized"
@@ -101,14 +99,16 @@ void sceneManagerRender(void) {
SCENE_MANAGER.current->background 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) { void sceneManagerDispose(void) {
for(uint8_t i = 0; i < SCENE_MANAGER.sceneCount; i++) { for(uint8_t i = 0; i < SCENE_MANAGER.sceneCount; i++) {
scene_t *scene = SCENE_MANAGER.scenes[i]; scene_t *scene = SCENE_MANAGER.scenes[i];
if(scene->flags & SCENE_FLAG_INITIALIZED) { if(scene->flags & SCENE_FLAG_INITIALIZED) {
scene->dispose(); scene->dispose(scene->data);
} }
} }

View File

@@ -6,6 +6,7 @@
# Sources # Sources
target_sources(${DUSK_TARGET_NAME} target_sources(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
ui.c
uitext.c uitext.c
uifps.c uifps.c
uiframe.c uiframe.c

26
src/ui/ui.c Normal file
View File

@@ -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
}

35
src/ui/ui.h Normal file
View File

@@ -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);