diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ebe534c..fd069dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,4 +40,5 @@ add_subdirectory(physics) # add_subdirectory(rpg) add_subdirectory(thread) add_subdirectory(time) +add_subdirectory(ui) add_subdirectory(util) \ No newline at end of file diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index eae96ab..8384af4 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -9,7 +9,6 @@ target_sources(${DUSK_TARGET_NAME} display.c camera.c tileset.c - screen.c ) # Subdirectories @@ -19,7 +18,6 @@ add_subdirectory(palette) add_subdirectory(texture) add_subdirectory(scene) add_subdirectory(spritebatch) -add_subdirectory(ui) if(DUSK_TARGET_SYSTEM STREQUAL "linux") target_compile_definitions(${DUSK_TARGET_NAME} diff --git a/src/display/display.c b/src/display/display.c index 96b0222..f6ab470 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -10,9 +10,8 @@ #include "display/framebuffer/framebuffer.h" #include "display/scene/scenemanager.h" #include "display/spritebatch/spritebatch.h" -#include "display/ui/ui.h" #include "display/mesh/quad.h" -#include "display/screen.h" +#include "game/game.h" display_t DISPLAY; @@ -67,9 +66,7 @@ errorret_t displayInit(void) { quadInit(); frameBufferInitBackbuffer(); spriteBatchInit(); - errorChain(uiInit()); errorChain(sceneManagerInit()); - screenInit(); errorOk(); } @@ -107,15 +104,14 @@ errorret_t displayUpdate(void) { #endif spriteBatchClear(); - screenBind(); + frameBufferBind(NULL); + frameBufferClear( + FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH, + COLOR_CORNFLOWER_BLUE + ); - sceneManagerUpdate(); - uiUpdate(); - - sceneManagerRender(); - uiRender(); - - screenUnbindAndRender(); + gameRender(); + spriteBatchFlush(); #if DISPLAY_SDL2 SDL_GL_SwapWindow(DISPLAY.window); @@ -131,9 +127,7 @@ errorret_t displayUpdate(void) { } errorret_t displayDispose(void) { - screenDispose(); sceneManagerDispose(); - uiDispose(); spriteBatchDispose(); #if DISPLAY_SDL2 diff --git a/src/display/ui/ui.c b/src/display/ui/ui.c deleted file mode 100644 index e9768ec..0000000 --- a/src/display/ui/ui.c +++ /dev/null @@ -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) { - -} \ No newline at end of file diff --git a/src/display/ui/ui.h b/src/display/ui/ui.h deleted file mode 100644 index d2f93e7..0000000 --- a/src/display/ui/ui.h +++ /dev/null @@ -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); \ No newline at end of file diff --git a/src/display/ui/uiconsole.h b/src/display/ui/uiconsole.h deleted file mode 100644 index 88bed96..0000000 --- a/src/display/ui/uiconsole.h +++ /dev/null @@ -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); \ No newline at end of file diff --git a/src/display/ui/uifps.h b/src/display/ui/uifps.h deleted file mode 100644 index 4c5cd75..0000000 --- a/src/display/ui/uifps.h +++ /dev/null @@ -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); \ No newline at end of file diff --git a/src/game/game.h b/src/game/game.h index 6ccd3e5..ba0f502 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -6,11 +6,26 @@ */ #pragma once +#include "error/error.h" -#if DUSK_GAME_RPG == 1 - #include "rpg/game.h" -#elif DUSK_GAME_MINESWEEPER == 1 - #include "minesweeper/game.h" -#else - #error "Unknown game specified" -#endif \ No newline at end of file +/** + * Initialize the game. + * + * @return Error code. + */ +errorret_t gameInit(void); + +/** + * Render the game. + */ +void gameRender(void); + +/** + * Update the game state. + */ +void gameUpdate(void); + +/** + * Dispose of the game. + */ +void gameDispose(void); \ No newline at end of file diff --git a/src/game/gamescene.h b/src/game/gamescene.h deleted file mode 100644 index 9d93a5d..0000000 --- a/src/game/gamescene.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/game/minesweeper/game.c b/src/game/minesweeper/game.c index 25b4377..10bacba 100644 --- a/src/game/minesweeper/game.c +++ b/src/game/minesweeper/game.c @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "game.h" +#include "game/game.h" errorret_t gameInit(void) { errorOk(); @@ -15,6 +15,10 @@ void gameUpdate(void) { } +void gameRender(void) { + +} + void gameDispose(void) { } \ No newline at end of file diff --git a/src/game/minesweeper/game.h b/src/game/minesweeper/game.h deleted file mode 100644 index 7312291..0000000 --- a/src/game/minesweeper/game.h +++ /dev/null @@ -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); \ No newline at end of file diff --git a/src/game/minesweeper/scene.h b/src/game/minesweeper/scene.h deleted file mode 100644 index 15ebdb9..0000000 --- a/src/game/minesweeper/scene.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/display/screen.c b/src/game/rpg/screen.c similarity index 100% rename from src/display/screen.c rename to src/game/rpg/screen.c diff --git a/src/display/screen.h b/src/game/rpg/screen.h similarity index 100% rename from src/display/screen.h rename to src/game/rpg/screen.h diff --git a/src/display/ui/CMakeLists.txt b/src/ui/CMakeLists.txt similarity index 96% rename from src/display/ui/CMakeLists.txt rename to src/ui/CMakeLists.txt index e7ce66f..b0d132a 100644 --- a/src/display/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -7,7 +7,6 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE uitext.c - ui.c uifps.c uiconsole.c ) \ No newline at end of file diff --git a/src/display/ui/uiconsole.c b/src/ui/uiconsole.c similarity index 82% rename from src/display/ui/uiconsole.c rename to src/ui/uiconsole.c index 023d778..5fc82c0 100644 --- a/src/display/ui/uiconsole.c +++ b/src/ui/uiconsole.c @@ -8,9 +8,8 @@ #include "uiconsole.h" #include "uitext.h" #include "console/console.h" -#include "ui.h" -void uiConsoleRender(void) { +void uiConsoleRender(const tileset_t *tileset, texture_t *texture) { if(!CONSOLE.visible) return; consolePrint("Test\n"); @@ -25,7 +24,7 @@ void uiConsoleRender(void) { uiTextDraw( 0, i * TILESET_MINOGRAM.tileHeight, line, COLOR_WHITE, - UI.debugFontTileset, &UI.debugFontAsset->alphaImage.texture + tileset, texture ); i--; } while(i > 0); diff --git a/src/ui/uiconsole.h b/src/ui/uiconsole.h new file mode 100644 index 0000000..6c4953b --- /dev/null +++ b/src/ui/uiconsole.h @@ -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); \ No newline at end of file diff --git a/src/display/ui/uifps.c b/src/ui/uifps.c similarity index 71% rename from src/display/ui/uifps.c rename to src/ui/uifps.c index c41cb1d..8853978 100644 --- a/src/display/ui/uifps.c +++ b/src/ui/uifps.c @@ -6,17 +6,12 @@ */ #include "uifps.h" -#include "display/ui/uitext.h" #include "time/time.h" #include "console/console.h" #include "util/string.h" -#include "ui.h" +#include "ui/uitext.h" -void uiFPSInit(void) { - consoleRegVar("fps", "0", NULL); -} - -void uiFPSRender(void) { +void uiFPSRender(const tileset_t *tileset, texture_t *texture) { if(stringCompare(consoleVarGet("fps")->value, "0") == 0) { return; } @@ -37,9 +32,5 @@ void uiFPSRender(void) { COLOR_RED ); - uiTextDraw( - 0, 0, - buffer, color, - UI.debugFontTileset, &UI.debugFontAsset->alphaImage.texture - ); + uiTextDraw(0, 0, buffer, color, tileset, texture); } \ No newline at end of file diff --git a/src/ui/uifps.h b/src/ui/uifps.h new file mode 100644 index 0000000..b2b4654 --- /dev/null +++ b/src/ui/uifps.h @@ -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); \ No newline at end of file diff --git a/src/display/ui/uitext.c b/src/ui/uitext.c similarity index 100% rename from src/display/ui/uitext.c rename to src/ui/uitext.c diff --git a/src/display/ui/uitext.h b/src/ui/uitext.h similarity index 100% rename from src/display/ui/uitext.h rename to src/ui/uitext.h