scene crap
This commit is contained in:
@@ -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;
|
||||
|
||||
38
src/scene/scene/scenetest.h
Normal file
38
src/scene/scene/scenetest.h
Normal 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
15
src/scene/scenedata.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 "scene/scene.h"
|
||||
|
||||
#include "scene/scene/scenetest.h"
|
||||
|
||||
typedef union {
|
||||
scenetest_t sceneTest;
|
||||
} scenedata_t;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user