Scene fixing

This commit is contained in:
2025-10-08 06:53:37 -05:00
parent b00ca3d48c
commit e36256abe3
12 changed files with 75 additions and 40 deletions

View File

@@ -19,5 +19,6 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
CONSOLE_POSIX=1 CONSOLE_POSIX=1
#CONSOLE_INTERACTIVE=1
) )
endif() endif()

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(scene->data)); errorret_t ret = errorPrint(scene->init(&SCENE_MANAGER.sceneData));
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

@@ -6,6 +6,7 @@
*/ */
#include "display/display.h" #include "display/display.h"
#include "engine/engine.h"
#include "console/console.h" #include "console/console.h"
#include "display/framebuffer.h" #include "display/framebuffer.h"
#include "scene/scenemanager.h" #include "scene/scenemanager.h"
@@ -77,14 +78,14 @@ errorret_t displayUpdate(void) {
while(SDL_PollEvent(&event)) { while(SDL_PollEvent(&event)) {
switch(event.type) { switch(event.type) {
case SDL_QUIT: { case SDL_QUIT: {
consoleExec("quit"); ENGINE.running = false;
break; break;
} }
case SDL_WINDOWEVENT: { case SDL_WINDOWEVENT: {
switch(event.window.event) { switch(event.window.event) {
case SDL_WINDOWEVENT_CLOSE: { case SDL_WINDOWEVENT_CLOSE: {
consoleExec("quit"); ENGINE.running = false;
break; break;
} }
@@ -122,9 +123,9 @@ errorret_t displayUpdate(void) {
SDL_GL_SwapWindow(DISPLAY.window); SDL_GL_SwapWindow(DISPLAY.window);
#endif #endif
GLenum err = glGetError(); GLenum err;
if (err != GL_NO_ERROR) { while((err = glGetError()) != GL_NO_ERROR) {
printf("GL Error: %d\n", err); consolePrint("GL Error: %d\n", err);
} }
// For now, we just return an OK error. // For now, we just return an OK error.

View File

@@ -53,6 +53,10 @@ errorret_t engineUpdate(void) {
errorOk(); errorOk();
} }
void engineExit(void) {
ENGINE.running = false;
}
errorret_t engineDispose(void) { errorret_t engineDispose(void) {
sceneManagerDispose(); sceneManagerDispose();
errorChain(displayDispose()); errorChain(displayDispose());

View File

@@ -9,4 +9,5 @@ target_sources(${DUSK_TARGET_NAME}
scenemanager.c scenemanager.c
) )
# Subdirs # Subdirs
add_subdirectory(scene)

View File

@@ -12,15 +12,14 @@
#define SCENE_FLAG_INITIALIZED (1 << 0) #define SCENE_FLAG_INITIALIZED (1 << 0)
typedef struct scenedata_s scenedata_t;
typedef struct { typedef struct {
const char_t *name; const char_t *name;
void *data; errorret_t (*init)(scenedata_t *data);
void (*update)(scenedata_t *data);
errorret_t (*init)(void *data); void (*render)(scenedata_t *data);
void (*update)(void *data); void (*dispose)(scenedata_t *data);
void (*render)(void *data);
void (*dispose)(void *data);
uint8_t flags; uint8_t flags;
color_t background; color_t background;
} scene_t; } scene_t;

View File

@@ -0,0 +1,12 @@
# 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
scenetest.c
)
# Subdirs

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "scenetest.h"
#include "scene/scenedata.h"
errorret_t sceneTestInit(scenedata_t *data) {
printf("Scene Test Init\n");
data->sceneTest.nothing = 0;
errorOk();
}
void sceneTestUpdate(scenedata_t *data) {
}
void sceneTestRender(scenedata_t *data) {
}
void sceneTestDispose(scenedata_t *data) {
}

View File

@@ -12,22 +12,10 @@ typedef struct {
int32_t nothing; int32_t nothing;
} scenetest_t; } scenetest_t;
static errorret_t sceneTestInit(scenetest_t *test) { errorret_t sceneTestInit(scenedata_t *data);
printf("Scene Test Init\n"); void sceneTestUpdate(scenedata_t *data);
errorOk(); void sceneTestRender(scenedata_t *data);
} void sceneTestDispose(scenedata_t *data);
static void sceneTestUpdate(scenetest_t *test) {
}
static void sceneTestRender(scenetest_t *test) {
}
static void sceneTestDispose(scenetest_t *test) {
}
static scene_t SCENE_TEST = { static scene_t SCENE_TEST = {
.name = "test", .name = "test",

View File

@@ -10,6 +10,8 @@
#include "scene/scene/scenetest.h" #include "scene/scene/scenetest.h"
typedef union { typedef struct scenedata_s {
scenetest_t sceneTest; union {
} scenedata_t; scenetest_t sceneTest;
};
} scenedata_t;

View File

@@ -12,14 +12,12 @@
#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); sceneManagerRegisterScene(&SCENE_TEST);
errorOk(); errorOk();
} }
@@ -59,7 +57,7 @@ void sceneManagerSetScene(scene_t *scene) {
SCENE_MANAGER.current->flags &= ~SCENE_FLAG_INITIALIZED; SCENE_MANAGER.current->flags &= ~SCENE_FLAG_INITIALIZED;
if(SCENE_MANAGER.current->dispose) { if(SCENE_MANAGER.current->dispose) {
SCENE_MANAGER.current->dispose(SCENE_MANAGER.current->data); SCENE_MANAGER.current->dispose(&SCENE_MANAGER.sceneData);
} }
} }
@@ -82,7 +80,7 @@ void sceneManagerUpdate(void) {
); );
if(SCENE_MANAGER.current->update) { if(SCENE_MANAGER.current->update) {
SCENE_MANAGER.current->update(SCENE_MANAGER.current->data); SCENE_MANAGER.current->update(&SCENE_MANAGER.sceneData);
} }
} }
@@ -100,7 +98,7 @@ void sceneManagerRender(void) {
); );
if(SCENE_MANAGER.current->render) { if(SCENE_MANAGER.current->render) {
SCENE_MANAGER.current->render(SCENE_MANAGER.current->data); SCENE_MANAGER.current->render(&SCENE_MANAGER.sceneData);
} }
} }
@@ -108,7 +106,7 @@ 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->data); scene->dispose(&SCENE_MANAGER.sceneData);
} }
} }

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "scene.h" #include "scene.h"
#include "scenedata.h"
#define SCENE_MANAGER_SCENE_COUNT_MAX 32 #define SCENE_MANAGER_SCENE_COUNT_MAX 32
@@ -14,6 +15,7 @@ typedef struct {
scene_t *current; scene_t *current;
scene_t *scenes[SCENE_MANAGER_SCENE_COUNT_MAX]; scene_t *scenes[SCENE_MANAGER_SCENE_COUNT_MAX];
uint8_t sceneCount; uint8_t sceneCount;
scenedata_t sceneData;
} scenemanager_t; } scenemanager_t;
extern scenemanager_t SCENE_MANAGER; extern scenemanager_t SCENE_MANAGER;