Game updates

This commit is contained in:
2025-10-01 17:07:29 -05:00
parent 22e2f703db
commit a734ecaa10
21 changed files with 77 additions and 235 deletions

View File

@@ -40,4 +40,5 @@ add_subdirectory(physics)
# add_subdirectory(rpg) # add_subdirectory(rpg)
add_subdirectory(thread) add_subdirectory(thread)
add_subdirectory(time) add_subdirectory(time)
add_subdirectory(ui)
add_subdirectory(util) add_subdirectory(util)

View File

@@ -9,7 +9,6 @@ target_sources(${DUSK_TARGET_NAME}
display.c display.c
camera.c camera.c
tileset.c tileset.c
screen.c
) )
# Subdirectories # Subdirectories
@@ -19,7 +18,6 @@ add_subdirectory(palette)
add_subdirectory(texture) add_subdirectory(texture)
add_subdirectory(scene) add_subdirectory(scene)
add_subdirectory(spritebatch) add_subdirectory(spritebatch)
add_subdirectory(ui)
if(DUSK_TARGET_SYSTEM STREQUAL "linux") if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}

View File

@@ -10,9 +10,8 @@
#include "display/framebuffer/framebuffer.h" #include "display/framebuffer/framebuffer.h"
#include "display/scene/scenemanager.h" #include "display/scene/scenemanager.h"
#include "display/spritebatch/spritebatch.h" #include "display/spritebatch/spritebatch.h"
#include "display/ui/ui.h"
#include "display/mesh/quad.h" #include "display/mesh/quad.h"
#include "display/screen.h" #include "game/game.h"
display_t DISPLAY; display_t DISPLAY;
@@ -67,9 +66,7 @@ errorret_t displayInit(void) {
quadInit(); quadInit();
frameBufferInitBackbuffer(); frameBufferInitBackbuffer();
spriteBatchInit(); spriteBatchInit();
errorChain(uiInit());
errorChain(sceneManagerInit()); errorChain(sceneManagerInit());
screenInit();
errorOk(); errorOk();
} }
@@ -107,15 +104,14 @@ errorret_t displayUpdate(void) {
#endif #endif
spriteBatchClear(); spriteBatchClear();
screenBind(); frameBufferBind(NULL);
frameBufferClear(
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
COLOR_CORNFLOWER_BLUE
);
sceneManagerUpdate(); gameRender();
uiUpdate(); spriteBatchFlush();
sceneManagerRender();
uiRender();
screenUnbindAndRender();
#if DISPLAY_SDL2 #if DISPLAY_SDL2
SDL_GL_SwapWindow(DISPLAY.window); SDL_GL_SwapWindow(DISPLAY.window);
@@ -131,9 +127,7 @@ errorret_t displayUpdate(void) {
} }
errorret_t displayDispose(void) { errorret_t displayDispose(void) {
screenDispose();
sceneManagerDispose(); sceneManagerDispose();
uiDispose();
spriteBatchDispose(); spriteBatchDispose();
#if DISPLAY_SDL2 #if DISPLAY_SDL2

View File

@@ -1,75 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "ui.h"
#include "uitext.h"
#include "display/framebuffer/framebuffer.h"
#include "display/spritebatch/spritebatch.h"
#include "uiconsole.h"
#include "uifps.h"
#include "util/memory.h"
#include "display/tileset/tileset_minogram.h"
ui_t UI;
errorret_t uiInit(void) {
memoryZero(&UI, sizeof(ui_t));
// Load debug font.
UI.debugFontTileset = &TILESET_MINOGRAM;
errorChain(assetManagerLoadAsset(
UI.debugFontTileset->image,
&UI.debugFontAsset,
&UI.debugFontRef
));
// Setup UI Camera.
cameraInit(&UI.camera);
UI.camera.projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC;
UI.camera.orthographic.left = 0.0f;
UI.camera.orthographic.top = 0.0f;
UI.camera.orthographic.right = frameBufferGetWidth(&FRAMEBUFFER_BACKBUFFER);
UI.camera.orthographic.bottom = frameBufferGetHeight(&FRAMEBUFFER_BACKBUFFER);
UI.camera.nearClip = -1.0f;
UI.camera.farClip = 1.0f;
UI.camera.viewType = CAMERA_VIEW_TYPE_MATRIX;
glm_mat4_identity(UI.camera.view);
UI.scale = 1.0f;
// Setup FPS element.
uiFPSInit();
errorOk();
}
void uiUpdate(void) {
}
void uiRender(void) {
UI.camera.orthographic.right = (
frameBufferGetWidth(FRAMEBUFFER_BOUND) / UI.scale
);
UI.camera.orthographic.bottom = (
frameBufferGetHeight(FRAMEBUFFER_BOUND) / UI.scale
);
cameraPushMatrix(&UI.camera);
uiConsoleRender();
uiFPSRender();
spriteBatchFlush();
cameraPopMatrix();
}
void uiDispose(void) {
}

View File

@@ -1,46 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
#include "display/camera.h"
#include "display/texture/texture.h"
#include "display/tileset.h"
#include "asset/asset.h"
typedef struct {
camera_t camera;
float_t scale;
const tileset_t *debugFontTileset;
asset_t *debugFontAsset;
ref_t debugFontRef;
} ui_t;
extern ui_t UI;
/**
* Initializes the UI system.
*
* @return An errorret_t indicating success or failure.
*/
errorret_t uiInit(void);
/**
* Updates the UI system. Will not render anything.
*/
void uiUpdate(void);
/**
* Renders the UI system.
*/
void uiRender(void);
/**
* Disposes of the UI system.
*/
void uiDispose(void);

View File

@@ -1,11 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
void uiConsoleRender(void);

View File

@@ -1,12 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
void uiFPSInit(void);
void uiFPSRender(void);

View File

@@ -6,11 +6,26 @@
*/ */
#pragma once #pragma once
#include "error/error.h"
#if DUSK_GAME_RPG == 1 /**
#include "rpg/game.h" * Initialize the game.
#elif DUSK_GAME_MINESWEEPER == 1 *
#include "minesweeper/game.h" * @return Error code.
#else */
#error "Unknown game specified" errorret_t gameInit(void);
#endif
/**
* Render the game.
*/
void gameRender(void);
/**
* Update the game state.
*/
void gameUpdate(void);
/**
* Dispose of the game.
*/
void gameDispose(void);

View File

@@ -1,16 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#if DUSK_GAME_RPG == 1
#include "rpg/scene.h"
#elif DUSK_GAME_MINESWEEPER == 1
#include "minesweeper/scene.h"
#else
#error "Unknown game specified"
#endif

View File

@@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "game.h" #include "game/game.h"
errorret_t gameInit(void) { errorret_t gameInit(void) {
errorOk(); errorOk();
@@ -15,6 +15,10 @@ void gameUpdate(void) {
} }
void gameRender(void) {
}
void gameDispose(void) { void gameDispose(void) {
} }

View File

@@ -1,24 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
/**
* Initializes the game.
*/
errorret_t gameInit(void);
/**
* Updates the game.
*/
void gameUpdate(void);
/**
* Disposes of the game.
*/
void gameDispose(void);

View File

@@ -1,11 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#error TEST

View File

@@ -7,7 +7,6 @@
target_sources(${DUSK_TARGET_NAME} target_sources(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
uitext.c uitext.c
ui.c
uifps.c uifps.c
uiconsole.c uiconsole.c
) )

View File

@@ -8,9 +8,8 @@
#include "uiconsole.h" #include "uiconsole.h"
#include "uitext.h" #include "uitext.h"
#include "console/console.h" #include "console/console.h"
#include "ui.h"
void uiConsoleRender(void) { void uiConsoleRender(const tileset_t *tileset, texture_t *texture) {
if(!CONSOLE.visible) return; if(!CONSOLE.visible) return;
consolePrint("Test\n"); consolePrint("Test\n");
@@ -25,7 +24,7 @@ void uiConsoleRender(void) {
uiTextDraw( uiTextDraw(
0, i * TILESET_MINOGRAM.tileHeight, 0, i * TILESET_MINOGRAM.tileHeight,
line, COLOR_WHITE, line, COLOR_WHITE,
UI.debugFontTileset, &UI.debugFontAsset->alphaImage.texture tileset, texture
); );
i--; i--;
} while(i > 0); } while(i > 0);

18
src/ui/uiconsole.h Normal file
View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "display/tileset.h"
#include "display/texture/texture.h"
/**
* Renders the console UI.
*
* @param tileset The tileset to use for rendering text.
* @param texture The texture associated with the tileset.
*/
void uiConsoleRender(const tileset_t *tileset, texture_t *texture);

View File

@@ -6,17 +6,12 @@
*/ */
#include "uifps.h" #include "uifps.h"
#include "display/ui/uitext.h"
#include "time/time.h" #include "time/time.h"
#include "console/console.h" #include "console/console.h"
#include "util/string.h" #include "util/string.h"
#include "ui.h" #include "ui/uitext.h"
void uiFPSInit(void) { void uiFPSRender(const tileset_t *tileset, texture_t *texture) {
consoleRegVar("fps", "0", NULL);
}
void uiFPSRender(void) {
if(stringCompare(consoleVarGet("fps")->value, "0") == 0) { if(stringCompare(consoleVarGet("fps")->value, "0") == 0) {
return; return;
} }
@@ -37,9 +32,5 @@ void uiFPSRender(void) {
COLOR_RED COLOR_RED
); );
uiTextDraw( uiTextDraw(0, 0, buffer, color, tileset, texture);
0, 0,
buffer, color,
UI.debugFontTileset, &UI.debugFontAsset->alphaImage.texture
);
} }

18
src/ui/uifps.h Normal file
View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "display/tileset.h"
#include "display/texture/texture.h"
/**
* Renders the FPS counter UI.
*
* @param tileset The tileset to use for rendering text.
* @param texture The texture associated with the tileset.
*/
void uiFPSRender(const tileset_t *tileset, texture_t *texture);