scerne stuff

This commit is contained in:
2025-10-01 19:21:20 -05:00
parent 83243ba32f
commit 4b04fc65ad
19 changed files with 150 additions and 76 deletions

View File

@@ -0,0 +1,6 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
add_asset(PALETTE palette0.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -38,6 +38,7 @@ add_subdirectory(input)
# add_subdirectory(locale) # add_subdirectory(locale)
add_subdirectory(physics) add_subdirectory(physics)
# add_subdirectory(rpg) # add_subdirectory(rpg)
add_subdirectory(scene)
add_subdirectory(thread) add_subdirectory(thread)
add_subdirectory(time) add_subdirectory(time)
add_subdirectory(ui) add_subdirectory(ui)

View File

@@ -16,7 +16,6 @@ add_subdirectory(framebuffer)
add_subdirectory(mesh) add_subdirectory(mesh)
add_subdirectory(palette) add_subdirectory(palette)
add_subdirectory(texture) add_subdirectory(texture)
add_subdirectory(scene)
add_subdirectory(spritebatch) add_subdirectory(spritebatch)
if(DUSK_TARGET_SYSTEM STREQUAL "linux") if(DUSK_TARGET_SYSTEM STREQUAL "linux")

View File

@@ -8,7 +8,7 @@
#include "display/display.h" #include "display/display.h"
#include "console/console.h" #include "console/console.h"
#include "display/framebuffer/framebuffer.h" #include "display/framebuffer/framebuffer.h"
#include "display/scene/scenemanager.h" #include "scene/scenemanager.h"
#include "display/spritebatch/spritebatch.h" #include "display/spritebatch/spritebatch.h"
#include "display/mesh/quad.h" #include "display/mesh/quad.h"
#include "game/game.h" #include "game/game.h"
@@ -71,7 +71,6 @@ errorret_t displayInit(void) {
quadInit(); quadInit();
frameBufferInitBackbuffer(); frameBufferInitBackbuffer();
spriteBatchInit(); spriteBatchInit();
errorChain(sceneManagerInit());
errorOk(); errorOk();
} }
@@ -115,7 +114,7 @@ errorret_t displayUpdate(void) {
COLOR_CORNFLOWER_BLUE COLOR_CORNFLOWER_BLUE
); );
gameRender(); sceneManagerRender();
spriteBatchFlush(); spriteBatchFlush();
#if DISPLAY_SDL2 #if DISPLAY_SDL2
@@ -132,7 +131,6 @@ errorret_t displayUpdate(void) {
} }
errorret_t displayDispose(void) { errorret_t displayDispose(void) {
sceneManagerDispose();
spriteBatchDispose(); spriteBatchDispose();
#if DISPLAY_SDL2 #if DISPLAY_SDL2

View File

@@ -1,58 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "scenemanager.h"
scenemanager_t SCENE_MANAGER;
// scene_t SCENE_MANAGER_SCENES[SCENE_TYPE_COUNT] = {
// [SCENE_TYPE_LOGO] = { 0 },
// [SCENE_TYPE_TEST] = {
// .init = sceneTestInit,
// .update = sceneTestUpdate,
// .render = sceneTestRender,
// .dispose = sceneTestDispose
// },
// [SCENE_TYPE_OVERWORLD] = {
// .init = sceneOverworldInit,
// .update = sceneOverworldUpdate,
// .render = sceneOverworldRender,
// .dispose = sceneOverworldDispose
// }
// };
errorret_t sceneManagerInit(void) {
// scene_t *initial = &SCENE_MANAGER_SCENES[SCENE_TYPE_INITIAL];
// if(initial->init != NULL) errorChain(initial->init());
errorOk();
}
void sceneManagerUpdate(void) {
// For each scene.
// for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
// scene_t *scene = &SCENE_MANAGER_SCENES[i];
// if((scene->flags & SCENE_FLAG_ACTIVE) == 0) continue;
// if(scene->update != NULL) scene->update();
// }
}
void sceneManagerRender(void) {
// for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
// scene_t *scene = &SCENE_MANAGER_SCENES[i];
// if((scene->flags & SCENE_FLAG_VISIBLE) == 0) continue;
// if(scene->render != NULL) scene->render();
// }
}
void sceneManagerDispose(void) {
// for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
// scene_t *scene = &SCENE_MANAGER_SCENES[i];
// if(scene->dispose != NULL) scene->dispose();
// }
}

View File

@@ -11,6 +11,7 @@
#include "input/input.h" #include "input/input.h"
#include "console/console.h" #include "console/console.h"
#include "display/display.h" #include "display/display.h"
#include "scene/scenemanager.h"
#include "asset/assetmanager.h" #include "asset/assetmanager.h"
#include "game/game.h" #include "game/game.h"
@@ -29,6 +30,7 @@ errorret_t engineInit(void) {
inputInit(); inputInit();
errorChain(assetManagerInit()); errorChain(assetManagerInit());
errorChain(displayInit()); errorChain(displayInit());
errorChain(sceneManagerInit());
errorChain(gameInit()); errorChain(gameInit());
// Init scripts // Init scripts
@@ -48,6 +50,7 @@ errorret_t engineUpdate(void) {
assetManagerUpdate(); assetManagerUpdate();
gameUpdate(); gameUpdate();
sceneManagerUpdate();
errorChain(displayUpdate()); errorChain(displayUpdate());
errorOk(); errorOk();

View File

@@ -15,11 +15,6 @@
*/ */
errorret_t gameInit(void); errorret_t gameInit(void);
/**
* Render the game.
*/
void gameRender(void);
/** /**
* Update the game state. * Update the game state.
*/ */

View File

@@ -18,10 +18,6 @@ void gameUpdate(void) {
} }
void gameRender(void) {
uiRender();
}
void gameDispose(void) { void gameDispose(void) {
uiDispose(); uiDispose();
} }

View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "scenesweep.h"
scene_t SCENE_SWEEP = {
.init = sceneSweepInit,
.update = sceneSweepUpdate,
.render = sceneSweepRender,
.dispose = sceneSweepDispose,
.active = NULL,
.sleep = NULL,
.flags = 0
};
scenesweep_t SCENE_SWEEP_DATA;
errorret_t sceneSweepInit(void) {
// Initialize scene data here
errorOk();
}
void sceneSweepUpdate(void) {
// Update scene logic here
}
void sceneSweepRender(void) {
// Render scene here
}
void sceneSweepDispose(void) {
// Clean up scene resources here
}

View File

@@ -0,0 +1,36 @@
/**
* 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 {
} scenesweep_t;
extern scene_t SCENE_SWEEP;
extern scenesweep_t SCENE_SWEEP_DATA;
/**
* Initializes the scene.
*/
errorret_t sceneSweepInit(void);
/**
* Updates the state of the scene.
*/
void sceneSweepUpdate(void);
/**
* Renders the current state of the scene.
*/
void sceneSweepRender(void);
/**
* Cleans up resources used by the scene.
*/
void sceneSweepDispose(void);

View File

@@ -9,14 +9,14 @@
#include "dusk.h" #include "dusk.h"
#include "error/error.h" #include "error/error.h"
#define SCENE_FLAG_VISIBLE (1 << 0) #define SCENE_FLAG_ACTIVE (1 << 0)
#define SCENE_FLAG_ACTIVE (1 << 1)
typedef struct { typedef struct {
errorret_t (*init)(void); errorret_t (*init)(void);
void (*update)(void); void (*update)(void);
void (*render)(void); void (*render)(void);
void (*dispose)(void); void (*dispose)(void);
void (*active)(void); void (*active)(void);
void (*sleep)(void); void (*sleep)(void);

54
src/scene/scenemanager.c Normal file
View 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");
}

View File

@@ -9,17 +9,23 @@
#include "scene.h" #include "scene.h"
typedef struct { typedef struct {
int nothing; scene_t *current;
} scenemanager_t; } scenemanager_t;
extern scenemanager_t SCENE_MANAGER; extern scenemanager_t SCENE_MANAGER;
// extern scene_t SCENE_MANAGER_SCENES[SCENE_TYPE_COUNT];
/** /**
* Initializes the scene manager and the initial scene. * Initializes the scene manager and the initial scene.
*/ */
errorret_t sceneManagerInit(void); 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. * Updates all active scenes.
*/ */