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;
}
}