scene crap
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
echo " = Dawn Init = ";
|
||||
fps 1;
|
||||
|
||||
fps 1;
|
||||
scene test;
|
@@ -24,7 +24,7 @@ void cmdScene(const consolecmdexec_t *exec) {
|
||||
|
||||
if((scene->flags & SCENE_FLAG_INITIALIZED) == 0) {
|
||||
if(scene->init) {
|
||||
errorret_t ret = errorPrint(scene->init());
|
||||
errorret_t ret = errorPrint(scene->init(scene->data));
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(ret);
|
||||
consolePrint("Error: Failed to initialize scene '%s'.", exec->argv[0]);
|
||||
|
@@ -27,7 +27,10 @@ console_t CONSOLE;
|
||||
void consoleInit() {
|
||||
memoryZero(&CONSOLE, sizeof(console_t));
|
||||
|
||||
// Register the get and set command.
|
||||
// Register vars
|
||||
consoleRegVar("fps", "0", NULL);
|
||||
|
||||
// Register cmds
|
||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
||||
consoleRegCmd("quit", cmdQuit);
|
||||
|
@@ -63,11 +63,6 @@ errorret_t displayInit(void) {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
|
||||
// Commands
|
||||
|
||||
// Variables
|
||||
consoleRegVar("fps", "0", NULL);
|
||||
|
||||
quadInit();
|
||||
frameBufferInitBackbuffer();
|
||||
spriteBatchInit();
|
||||
@@ -115,6 +110,8 @@ errorret_t displayUpdate(void) {
|
||||
// Bind screen and render scene
|
||||
screenBind();
|
||||
sceneManagerRender();
|
||||
|
||||
// UI will probs go here
|
||||
|
||||
// Finish up
|
||||
spriteBatchFlush();
|
||||
|
13
src/rpg/rpg.h
Normal file
13
src/rpg/rpg.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
map_t map;
|
||||
} rpg_t;
|
@@ -10,19 +10,16 @@
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
|
||||
#define SCENE_FLAG_ACTIVE (1 << 0)
|
||||
#define SCENE_FLAG_INITIALIZED (1 << 1)
|
||||
#define SCENE_FLAG_INITIALIZED (1 << 0)
|
||||
|
||||
typedef struct {
|
||||
const char_t *name;
|
||||
void *data;
|
||||
|
||||
errorret_t (*init)(void);
|
||||
void (*update)(void);
|
||||
void (*render)(void);
|
||||
void (*dispose)(void);
|
||||
|
||||
void (*active)(void);
|
||||
void (*sleep)(void);
|
||||
errorret_t (*init)(void *data);
|
||||
void (*update)(void *data);
|
||||
void (*render)(void *data);
|
||||
void (*dispose)(void *data);
|
||||
|
||||
uint8_t flags;
|
||||
color_t background;
|
||||
|
38
src/scene/scene/scenetest.h
Normal file
38
src/scene/scene/scenetest.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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 {
|
||||
int32_t nothing;
|
||||
} scenetest_t;
|
||||
|
||||
static errorret_t sceneTestInit(scenetest_t *test) {
|
||||
printf("Scene Test Init\n");
|
||||
errorOk();
|
||||
}
|
||||
|
||||
static void sceneTestUpdate(scenetest_t *test) {
|
||||
|
||||
}
|
||||
|
||||
static void sceneTestRender(scenetest_t *test) {
|
||||
|
||||
}
|
||||
|
||||
static void sceneTestDispose(scenetest_t *test) {
|
||||
|
||||
}
|
||||
|
||||
static scene_t SCENE_TEST = {
|
||||
.name = "test",
|
||||
.init = sceneTestInit,
|
||||
.update = sceneTestUpdate,
|
||||
.render = sceneTestRender,
|
||||
.dispose = sceneTestDispose
|
||||
};
|
15
src/scene/scenedata.h
Normal file
15
src/scene/scenedata.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "scene/scene.h"
|
||||
|
||||
#include "scene/scene/scenetest.h"
|
||||
|
||||
typedef union {
|
||||
scenetest_t sceneTest;
|
||||
} scenedata_t;
|
@@ -12,10 +12,14 @@
|
||||
#include "display/framebuffer.h"
|
||||
#include "util/string.h"
|
||||
|
||||
#include "scene/scene/scenetest.h"
|
||||
|
||||
scenemanager_t SCENE_MANAGER;
|
||||
|
||||
errorret_t sceneManagerInit(void) {
|
||||
memoryZero(&SCENE_MANAGER, sizeof(scenemanager_t));
|
||||
|
||||
// sceneManagerRegisterScene(&SCENE_TEST);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -47,13 +51,16 @@ void sceneManagerRegisterScene(scene_t *scene) {
|
||||
|
||||
void sceneManagerSetScene(scene_t *scene) {
|
||||
if(SCENE_MANAGER.current) {
|
||||
if(SCENE_MANAGER.current->sleep) SCENE_MANAGER.current->sleep();
|
||||
|
||||
// TODO: Should dispose?
|
||||
SCENE_MANAGER.current->flags &= ~(
|
||||
SCENE_FLAG_INITIALIZED | SCENE_FLAG_ACTIVE
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
|
||||
"Current scene not initialized"
|
||||
);
|
||||
if(SCENE_MANAGER.current->dispose) SCENE_MANAGER.current->dispose();
|
||||
|
||||
SCENE_MANAGER.current->flags &= ~SCENE_FLAG_INITIALIZED;
|
||||
if(SCENE_MANAGER.current->dispose) {
|
||||
SCENE_MANAGER.current->dispose(SCENE_MANAGER.current->data);
|
||||
}
|
||||
}
|
||||
|
||||
SCENE_MANAGER.current = scene;
|
||||
@@ -63,34 +70,25 @@ void sceneManagerSetScene(scene_t *scene) {
|
||||
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"
|
||||
);
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
|
||||
"Current scene not initialized"
|
||||
);
|
||||
|
||||
if(SCENE_MANAGER.current->update) SCENE_MANAGER.current->update();
|
||||
if(SCENE_MANAGER.current->update) {
|
||||
SCENE_MANAGER.current->update(SCENE_MANAGER.current->data);
|
||||
}
|
||||
}
|
||||
|
||||
void sceneManagerRender(void) {
|
||||
if(!SCENE_MANAGER.current) return;
|
||||
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_ACTIVE,
|
||||
"Current scene not active"
|
||||
);
|
||||
assertTrue(
|
||||
SCENE_MANAGER.current->flags & SCENE_FLAG_INITIALIZED,
|
||||
"Current scene not initialized"
|
||||
@@ -101,14 +99,16 @@ void sceneManagerRender(void) {
|
||||
SCENE_MANAGER.current->background
|
||||
);
|
||||
|
||||
if(SCENE_MANAGER.current->render) SCENE_MANAGER.current->render();
|
||||
if(SCENE_MANAGER.current->render) {
|
||||
SCENE_MANAGER.current->render(SCENE_MANAGER.current->data);
|
||||
}
|
||||
}
|
||||
|
||||
void sceneManagerDispose(void) {
|
||||
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->dispose(scene->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
ui.c
|
||||
uitext.c
|
||||
uifps.c
|
||||
uiframe.c
|
||||
|
26
src/ui/ui.c
Normal file
26
src/ui/ui.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "ui.h"
|
||||
|
||||
ui_t UI;
|
||||
|
||||
void uiInit(void) {
|
||||
// Initialize UI components here
|
||||
}
|
||||
|
||||
void uiUpdate(void) {
|
||||
// Update UI state here
|
||||
}
|
||||
|
||||
void uiRender(void) {
|
||||
// Render UI elements here
|
||||
}
|
||||
|
||||
void uiDispose(void) {
|
||||
// Clean up UI resources here
|
||||
}
|
35
src/ui/ui.h
Normal file
35
src/ui/ui.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t nothing;
|
||||
} ui_t;
|
||||
|
||||
extern ui_t UI;
|
||||
|
||||
/**
|
||||
* Initializes the UI system, loading necessary resources.
|
||||
*/
|
||||
void uiInit(void);
|
||||
|
||||
/**
|
||||
* Updates the UI state, handling user interactions and animations.
|
||||
*/
|
||||
void uiUpdate(void);
|
||||
|
||||
/**
|
||||
* Renders the UI elements to the screen.
|
||||
*/
|
||||
void uiRender(void);
|
||||
|
||||
/**
|
||||
* Cleans up and frees all UI resources.
|
||||
*/
|
||||
void uiDispose(void);
|
Reference in New Issue
Block a user