scerne stuff
This commit is contained in:
12
src/scene/CMakeLists.txt
Normal file
12
src/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
|
||||
scenemanager.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
24
src/scene/scene.h
Normal file
24
src/scene/scene.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "error/error.h"
|
||||
|
||||
#define SCENE_FLAG_ACTIVE (1 << 0)
|
||||
|
||||
typedef struct {
|
||||
errorret_t (*init)(void);
|
||||
void (*update)(void);
|
||||
void (*render)(void);
|
||||
void (*dispose)(void);
|
||||
|
||||
void (*active)(void);
|
||||
void (*sleep)(void);
|
||||
|
||||
uint8_t flags;
|
||||
} scene_t;
|
||||
54
src/scene/scenemanager.c
Normal file
54
src/scene/scenemanager.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scenemanager.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
scenemanager_t SCENE_MANAGER;
|
||||
|
||||
errorret_t sceneManagerInit(void) {
|
||||
memoryZero(&SCENE_MANAGER, sizeof(scenemanager_t));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void sceneManagerSetScene(scene_t *scene) {
|
||||
if(SCENE_MANAGER.current) {
|
||||
SCENE_MANAGER.current->sleep();
|
||||
SCENE_MANAGER.current->flags &= ~SCENE_FLAG_ACTIVE;
|
||||
}
|
||||
|
||||
SCENE_MANAGER.current = scene;
|
||||
|
||||
if(SCENE_MANAGER.current) {
|
||||
SCENE_MANAGER.current->active();
|
||||
SCENE_MANAGER.current->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();
|
||||
}
|
||||
|
||||
void sceneManagerRender(void) {
|
||||
if(!SCENE_MANAGER.current) return;
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE,
|
||||
"Current scene not active"
|
||||
);
|
||||
SCENE_MANAGER.current->render();
|
||||
}
|
||||
|
||||
void sceneManagerDispose(void) {
|
||||
assertNull(SCENE_MANAGER.current, "Current scene not null");
|
||||
}
|
||||
42
src/scene/scenemanager.h
Normal file
42
src/scene/scenemanager.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
|
||||
typedef struct {
|
||||
scene_t *current;
|
||||
} scenemanager_t;
|
||||
|
||||
extern scenemanager_t SCENE_MANAGER;
|
||||
|
||||
/**
|
||||
* Initializes the scene manager and the initial scene.
|
||||
*/
|
||||
errorret_t sceneManagerInit(void);
|
||||
|
||||
/**
|
||||
* Sets the current active scene.
|
||||
*
|
||||
* @param scene The scene to set as current.
|
||||
*/
|
||||
void sceneManagerSetScene(scene_t *scene);
|
||||
|
||||
/**
|
||||
* Updates all active scenes.
|
||||
*/
|
||||
void sceneManagerUpdate(void);
|
||||
|
||||
/**
|
||||
* Renders all visible scenes.
|
||||
*/
|
||||
void sceneManagerRender(void);
|
||||
|
||||
/**
|
||||
* Disposes of all scenes.
|
||||
*/
|
||||
void sceneManagerDispose(void);
|
||||
Reference in New Issue
Block a user