Add inventory.
This commit is contained in:
84
src/scene/scene.c
Normal file
84
src/scene/scene.c
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "scene.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/string.h"
|
||||
|
||||
const scene_t SCENES[] = {
|
||||
};
|
||||
|
||||
uint_fast8_t SCENE_CURRENT = 0xFF;
|
||||
|
||||
errorret_t sceneInit(void) {
|
||||
// Initialize the scene subsystem here
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void sceneUpdate(void) {
|
||||
const scene_t *current = sceneGetCurrent();
|
||||
if(current && current->update) {
|
||||
current->update();
|
||||
}
|
||||
}
|
||||
|
||||
void sceneRender(void) {
|
||||
const scene_t *current = sceneGetCurrent();
|
||||
|
||||
if(current && current->render) {
|
||||
current->render();
|
||||
}
|
||||
}
|
||||
|
||||
void sceneDispose(void) {
|
||||
const scene_t *current = sceneGetCurrent();
|
||||
|
||||
if(current && current->dispose) {
|
||||
current->dispose();
|
||||
}
|
||||
}
|
||||
|
||||
errorret_t sceneSet(const scene_t *scene) {
|
||||
sceneDispose();
|
||||
|
||||
if(scene) {
|
||||
SCENE_CURRENT = (uint_fast8_t)(scene - SCENES);
|
||||
|
||||
assertTrue(
|
||||
SCENE_CURRENT < sizeof(SCENES) / sizeof(scene_t),
|
||||
"Invalid scene index."
|
||||
);
|
||||
|
||||
if(scene->init) {
|
||||
errorret_t err = scene->init();
|
||||
if(err.code != ERROR_OK) SCENE_CURRENT = 0xFF;
|
||||
errorChain(err);
|
||||
}
|
||||
} else {
|
||||
SCENE_CURRENT = 0xFF;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
const scene_t* sceneGetCurrent(void) {
|
||||
if(SCENE_CURRENT == 0xFF) return NULL;
|
||||
|
||||
assertTrue(
|
||||
SCENE_CURRENT < sizeof(SCENES) / sizeof(scene_t),
|
||||
"Invalid current scene index."
|
||||
);
|
||||
|
||||
return &SCENES[SCENE_CURRENT];
|
||||
}
|
||||
|
||||
const scene_t* sceneGetByName(const char_t *name) {
|
||||
for(uint_fast8_t i = 0; i < sizeof(SCENES) / sizeof(scene_t); i++) {
|
||||
if(stringCompare(SCENES[i].name, name) == 0) {
|
||||
return &SCENES[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user