Scene fixing
This commit is contained in:
@@ -19,5 +19,6 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
CONSOLE_POSIX=1
|
||||
#CONSOLE_INTERACTIVE=1
|
||||
)
|
||||
endif()
|
@@ -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(scene->data));
|
||||
errorret_t ret = errorPrint(scene->init(&SCENE_MANAGER.sceneData));
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(ret);
|
||||
consolePrint("Error: Failed to initialize scene '%s'.", exec->argv[0]);
|
||||
|
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "display/display.h"
|
||||
#include "engine/engine.h"
|
||||
#include "console/console.h"
|
||||
#include "display/framebuffer.h"
|
||||
#include "scene/scenemanager.h"
|
||||
@@ -77,14 +78,14 @@ errorret_t displayUpdate(void) {
|
||||
while(SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_QUIT: {
|
||||
consoleExec("quit");
|
||||
ENGINE.running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
switch(event.window.event) {
|
||||
case SDL_WINDOWEVENT_CLOSE: {
|
||||
consoleExec("quit");
|
||||
ENGINE.running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -122,9 +123,9 @@ errorret_t displayUpdate(void) {
|
||||
SDL_GL_SwapWindow(DISPLAY.window);
|
||||
#endif
|
||||
|
||||
GLenum err = glGetError();
|
||||
if (err != GL_NO_ERROR) {
|
||||
printf("GL Error: %d\n", err);
|
||||
GLenum err;
|
||||
while((err = glGetError()) != GL_NO_ERROR) {
|
||||
consolePrint("GL Error: %d\n", err);
|
||||
}
|
||||
|
||||
// For now, we just return an OK error.
|
||||
|
@@ -53,6 +53,10 @@ errorret_t engineUpdate(void) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void engineExit(void) {
|
||||
ENGINE.running = false;
|
||||
}
|
||||
|
||||
errorret_t engineDispose(void) {
|
||||
sceneManagerDispose();
|
||||
errorChain(displayDispose());
|
||||
|
@@ -9,4 +9,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
scenemanager.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
# Subdirs
|
||||
add_subdirectory(scene)
|
@@ -12,15 +12,14 @@
|
||||
|
||||
#define SCENE_FLAG_INITIALIZED (1 << 0)
|
||||
|
||||
typedef struct scenedata_s scenedata_t;
|
||||
|
||||
typedef struct {
|
||||
const char_t *name;
|
||||
void *data;
|
||||
|
||||
errorret_t (*init)(void *data);
|
||||
void (*update)(void *data);
|
||||
void (*render)(void *data);
|
||||
void (*dispose)(void *data);
|
||||
|
||||
errorret_t (*init)(scenedata_t *data);
|
||||
void (*update)(scenedata_t *data);
|
||||
void (*render)(scenedata_t *data);
|
||||
void (*dispose)(scenedata_t *data);
|
||||
uint8_t flags;
|
||||
color_t background;
|
||||
} scene_t;
|
12
src/scene/scene/CMakeLists.txt
Normal file
12
src/scene/scene/CMakeLists.txt
Normal 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
|
27
src/scene/scene/scenetest.c
Normal file
27
src/scene/scene/scenetest.c
Normal 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) {
|
||||
|
||||
}
|
@@ -12,22 +12,10 @@ 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) {
|
||||
|
||||
}
|
||||
errorret_t sceneTestInit(scenedata_t *data);
|
||||
void sceneTestUpdate(scenedata_t *data);
|
||||
void sceneTestRender(scenedata_t *data);
|
||||
void sceneTestDispose(scenedata_t *data);
|
||||
|
||||
static scene_t SCENE_TEST = {
|
||||
.name = "test",
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "scene/scene/scenetest.h"
|
||||
|
||||
typedef union {
|
||||
scenetest_t sceneTest;
|
||||
} scenedata_t;
|
||||
typedef struct scenedata_s {
|
||||
union {
|
||||
scenetest_t sceneTest;
|
||||
};
|
||||
} scenedata_t;
|
||||
|
@@ -12,14 +12,12 @@
|
||||
#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);
|
||||
sceneManagerRegisterScene(&SCENE_TEST);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -59,7 +57,7 @@ void sceneManagerSetScene(scene_t *scene) {
|
||||
|
||||
SCENE_MANAGER.current->flags &= ~SCENE_FLAG_INITIALIZED;
|
||||
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) {
|
||||
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) {
|
||||
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++) {
|
||||
scene_t *scene = SCENE_MANAGER.scenes[i];
|
||||
if(scene->flags & SCENE_FLAG_INITIALIZED) {
|
||||
scene->dispose(scene->data);
|
||||
scene->dispose(&SCENE_MANAGER.sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
#include "scenedata.h"
|
||||
|
||||
#define SCENE_MANAGER_SCENE_COUNT_MAX 32
|
||||
|
||||
@@ -14,6 +15,7 @@ typedef struct {
|
||||
scene_t *current;
|
||||
scene_t *scenes[SCENE_MANAGER_SCENE_COUNT_MAX];
|
||||
uint8_t sceneCount;
|
||||
scenedata_t sceneData;
|
||||
} scenemanager_t;
|
||||
|
||||
extern scenemanager_t SCENE_MANAGER;
|
||||
|
Reference in New Issue
Block a user