Frame
This commit is contained in:
@@ -8,47 +8,103 @@
|
||||
#include "scenemanager.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "console/console.h"
|
||||
#include "util/string.h"
|
||||
|
||||
scenemanager_t SCENE_MANAGER;
|
||||
|
||||
errorret_t sceneManagerInit(void) {
|
||||
memoryZero(&SCENE_MANAGER, sizeof(scenemanager_t));
|
||||
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
scene_t * sceneManagerGetSceneByName(const char_t *name) {
|
||||
assertNotNull(name, "Name is null");
|
||||
|
||||
for(uint8_t i = 0; i < SCENE_MANAGER.sceneCount; i++) {
|
||||
if(strcmp(SCENE_MANAGER.scenes[i]->name, name) != 0) continue;
|
||||
return SCENE_MANAGER.scenes[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sceneManagerRegisterScene(scene_t *scene) {
|
||||
assertNotNull(scene, "Scene is null");
|
||||
assertTrue(
|
||||
SCENE_MANAGER.sceneCount < SCENE_MANAGER_SCENE_COUNT_MAX,
|
||||
"Scene count exceeded max"
|
||||
);
|
||||
assertNotNull(scene->name, "Scene name is null");
|
||||
assertNull(
|
||||
sceneManagerGetSceneByName(scene->name), "Scene name already registered"
|
||||
);
|
||||
|
||||
SCENE_MANAGER.scenes[SCENE_MANAGER.sceneCount++] = scene;
|
||||
}
|
||||
|
||||
void sceneManagerSetScene(scene_t *scene) {
|
||||
if(SCENE_MANAGER.current) {
|
||||
SCENE_MANAGER.current->sleep();
|
||||
SCENE_MANAGER.current->flags &= ~SCENE_FLAG_ACTIVE;
|
||||
if(SCENE_MANAGER.current->sleep) SCENE_MANAGER.current->sleep();
|
||||
|
||||
// TODO: Should dispose?
|
||||
SCENE_MANAGER.current->flags &= ~(
|
||||
SCENE_FLAG_INITIALIZED | SCENE_FLAG_ACTIVE
|
||||
);
|
||||
if(SCENE_MANAGER.current->dispose) SCENE_MANAGER.current->dispose();
|
||||
}
|
||||
|
||||
SCENE_MANAGER.current = scene;
|
||||
|
||||
if(SCENE_MANAGER.current) {
|
||||
SCENE_MANAGER.current->active();
|
||||
SCENE_MANAGER.current->flags |= SCENE_FLAG_ACTIVE;
|
||||
if(scene) {
|
||||
assertTrue(
|
||||
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"
|
||||
);
|
||||
SCENE_MANAGER.current->update();
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
|
||||
"Current scene not initialized"
|
||||
);
|
||||
|
||||
if(SCENE_MANAGER.current->update) SCENE_MANAGER.current->update();
|
||||
}
|
||||
|
||||
void sceneManagerRender(void) {
|
||||
if(!SCENE_MANAGER.current) return;
|
||||
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE,
|
||||
"Current scene not active"
|
||||
);
|
||||
SCENE_MANAGER.current->render();
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
|
||||
"Current scene not initialized"
|
||||
);
|
||||
|
||||
if(SCENE_MANAGER.current->render) SCENE_MANAGER.current->render();
|
||||
}
|
||||
|
||||
void sceneManagerDispose(void) {
|
||||
assertNull(SCENE_MANAGER.current, "Current scene not null");
|
||||
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_MANAGER.sceneCount = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user