Refactor asset loading

This commit is contained in:
2025-11-04 22:23:44 -06:00
parent 7c11a7e5bc
commit 1ce1fdff8d
26 changed files with 198 additions and 1010 deletions

View File

@@ -6,6 +6,7 @@
*/
#include "ui.h"
#include "assert/assert.h"
#include "ui/uifps.h"
#include "util/memory.h"
#include "display/tileset/tileset_minogram.h"
@@ -36,26 +37,29 @@ void uiRender(void) {
cameraPushMatrix(&UI.camera);
// Render UI elements here
if(UI.font) {
uiFPSRender(UI.fontTileset, &UI.font->alphaImage.texture);
if(UI.fontTexture.width > 0) {
uiFPSRender(UI.fontTileset, &UI.fontTexture);
}
cameraPopMatrix();
}
errorret_t uiSetFont(const tileset_t *fontTileset) {
if(UI.font) {
assetUnlock(UI.font, UI.fontRef);
UI.font = NULL;
if(UI.fontTexture.width > 0) {
textureDispose(&UI.fontTexture);
UI.fontTexture.width = -1;
}
assertNotNull(fontTileset, "Font tileset cannot be NULL.");
UI.fontTileset = fontTileset;
assetManagerLoadAsset(fontTileset->image, &UI.font, &UI.fontRef);
errorChain(assetLoad(UI.fontTileset->image, &UI.fontTexture));
errorOk();
}
void uiDispose(void) {
if(UI.font) {
assetUnlock(UI.font, UI.fontRef);
UI.font = NULL;
if(UI.fontTexture.width > 0) {
textureDispose(&UI.fontTexture);
UI.fontTexture.width = -1;
}
}

View File

@@ -6,16 +6,14 @@
*/
#pragma once
#include "dusk.h"
#include "asset/asset.h"
#include "display/texture.h"
#include "display/tileset/tileset.h"
#include "display/camera.h"
typedef struct {
camera_t camera;
ref_t fontRef;
asset_t *font;
texture_t fontTexture;
const tileset_t *fontTileset;
} ui_t;

View File

@@ -6,7 +6,6 @@
// */
#include "uitext.h"
#include "asset/assetmanager.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "display/spritebatch.h"

View File

@@ -7,6 +7,7 @@
#pragma once
#include "asset/asset.h"
#include "display/texture.h"
#include "display/tileset/tileset_minogram.h"
#define UI_TEXT_CHAR_START '!'