Prepping for overworld rendering.

This commit is contained in:
2025-02-24 22:40:10 -06:00
parent 7844eb5d51
commit af598552f4
8 changed files with 84 additions and 8 deletions

View File

@ -9,7 +9,7 @@
#include "assert/assert.h"
entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
{ NULL },
{ NULL, NULL },
{ playerInit, playerUpdate }
};
@ -26,6 +26,7 @@ void entityInit(
memset(ent, 0, sizeof(entity_t));
ent->type = type;
// Call init
assertNotNull(ENTITY_CALLBACKS[type].init, "Entity type init callback err.");
ENTITY_CALLBACKS[type].init(ent);
}

View File

@ -17,7 +17,28 @@ typedef struct {
extern overworld_t overworld;
/**
* Initializes the overworld.
*/
void overworldInit();
/**
* Called by the scene system when the overworld scene is made to be the
* active scene.
*/
void overworldSceneInit();
/**
* Called by the scene system when the overworld scene is made to be inactive.
*/
void overworldSceneDeinit();
void overworldUpdate();
/**
* Called by the scene system when the overworld scene is to perform a tick.
*/
void overworldUpdate();
/**
* Platform level render method. Refer to sceneRender for information.
*/
void overworldRender();

View File

@ -10,8 +10,17 @@
#include "overworld/overworld.h"
scenetypecallback_t SCENE_CALLBACKS[] = {
{ NULL, NULL, NULL, NULL },// SCENE_TYPE_INITIAL
{ overworldInit, overworldSceneInit, overworldSceneDeinit, overworldUpdate },
// SCENE_TYPE_INITIAL
{ NULL, NULL, NULL, NULL, NULL },
// SCENE_TYPE_OVERWORLD
{
overworldInit,
overworldSceneInit,
overworldSceneDeinit,
overworldUpdate,
overworldRender
},
};
scene_t SCENE;
@ -41,6 +50,14 @@ void sceneUpdate() {
}
}
void sceneRender() {
assertTrue(SCENE.current < SCENE_TYPE_COUNT, "Invalid Scene Type");
if(SCENE_CALLBACKS[SCENE.current].onRender) {
SCENE_CALLBACKS[SCENE.current].onRender();
}
}
void sceneSet(const scenetype_t scene) {
assertTrue(SCENE.next < SCENE_TYPE_COUNT, "Invalid Scene Type");
SCENE.next = scene;

View File

@ -25,6 +25,7 @@ typedef struct {
void (*onActive)();
void (*onInactive)();
void (*onUpdate)();
void (*onRender)();
} scenetypecallback_t;
extern scene_t SCENE;
@ -39,6 +40,16 @@ void sceneInit();
*/
void sceneUpdate();
/**
* Renders the scene system.
*
* Scene rendering is really just an abstraction meant to simplify things for
* the render host. It is not REQUIRED to be called at all and is not actually
* implemented in the dusk dir itself, it is overriden somewhere within the
* render host.
*/
void sceneRender();
/**
* Sets the current scene. This will happen at the start of the next tick.
*

View File

@ -26,4 +26,5 @@ target_sources(${DUSK_TARGET_NAME}
# Subdirs
add_subdirectory(assert)
add_subdirectory(display)
add_subdirectory(display)
add_subdirectory(overworld)

View File

@ -7,6 +7,7 @@
#include "assert/assertgl.h"
#include "render.h"
#include "render/scene.h"
render_t RENDER;
@ -15,10 +16,10 @@ void renderInit() {
}
void renderUpdate() {
}
void renderOverworld() {
// Hand off to the scene to do its rendering.
sceneRender();
}
void renderDispose() {
}

View 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
overworld.c
)
# Subdirs

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "overworld/overworld.h"
void overworldRender() {
}