Refactor asset loading
This commit is contained in:
22
src/ui/ui.c
22
src/ui/ui.c
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
// */
|
||||
|
||||
#include "uitext.h"
|
||||
#include "asset/assetmanager.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/spritebatch.h"
|
||||
|
||||
@@ -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 '!'
|
||||
|
||||
Reference in New Issue
Block a user