Finished asset manager
This commit is contained in:
@ -10,23 +10,28 @@
|
||||
assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[] = {
|
||||
{
|
||||
&_assetManagerLoaderTextureAsync,
|
||||
&_assetManagerLoaderTextureSync
|
||||
&_assetManagerLoaderTextureSync,
|
||||
&_assetManagerLoaderTextureDispose
|
||||
},
|
||||
{
|
||||
&_assetManagerLoaderFontAsync,
|
||||
&_assetManagerLoaderFontSync
|
||||
&_assetManagerLoaderFontSync,
|
||||
&_assetManagerLoaderFontDispose
|
||||
},
|
||||
{
|
||||
&_assetManagerLoaderShaderAsync,
|
||||
&_assetManagerLoaderShaderSync
|
||||
&_assetManagerLoaderShaderSync,
|
||||
&_assetManagerLoaderShaderDispose
|
||||
},
|
||||
{
|
||||
&_assetManagerLoaderScaledTextureAsync,
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
&_assetManagerLoaderTextureScaleAsync,
|
||||
&_assetManagerLoaderTextureScaleSync
|
||||
&_assetManagerLoaderTextureScaleSync,
|
||||
&_assetManagerLoaderTextureScaleDispose
|
||||
}
|
||||
};
|
||||
|
||||
@ -60,9 +65,7 @@ assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man) {
|
||||
for(i = 0; i < 0xFF; i++) {
|
||||
if(arrayFind(
|
||||
sizeof(assetmanagerowner_t), man->holders, man->holderCount, &i
|
||||
) == -1) {
|
||||
break;
|
||||
}
|
||||
) == -1) break;
|
||||
}
|
||||
|
||||
man->holders[man->holderCount++] = i;
|
||||
@ -70,12 +73,40 @@ assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man) {
|
||||
}
|
||||
|
||||
void assetManagerHolderRelease(assetmanager_t *man, assetmanagerowner_t hold) {
|
||||
int32_t i = arrayFind(
|
||||
sizeof(assetmanagerowner_t), man->holders, man->holderCount, &hold
|
||||
);
|
||||
int32_t i;
|
||||
uint8_t j;
|
||||
assetmanageritem_t *item;
|
||||
size_t s;
|
||||
|
||||
s = sizeof(assetmanagerowner_t);
|
||||
i = arrayFind(s, man->holders,man->holderCount,&hold);
|
||||
if(i == -1) return;
|
||||
|
||||
arraySplice(sizeof(uint8_t), man->holders, i, 1, man->holderCount);
|
||||
man->holderCount--;
|
||||
|
||||
for(j = 0; j < man->itemCount; j++) {
|
||||
item = man->items + j;
|
||||
i = arrayFind(s, item->holders, item->holderCount, &hold);
|
||||
if(i == -1) continue;
|
||||
arraySplice(s, item->holders, i, 1, item->holderCount);
|
||||
item->holderCount--;
|
||||
}
|
||||
}
|
||||
|
||||
void assetManagerDisposeReleased(assetmanager_t *man) {
|
||||
uint8_t i;
|
||||
assetmanagerloader_t *disp;
|
||||
assetmanageritem_t *item;
|
||||
|
||||
for(i = 0; i < man->itemCount; i++) {
|
||||
item = man->items + i;
|
||||
disp = ASSET_MANAGER_LOADERS[item->type].dispose;
|
||||
if(item->holderCount > 0) continue;
|
||||
if(disp != NULL) disp(item);
|
||||
arraySplice(sizeof(assetmanageritem_t), man->items, i, 1, man->itemCount);
|
||||
man->itemCount--;
|
||||
}
|
||||
}
|
||||
|
||||
// Thread Management
|
||||
@ -233,6 +264,10 @@ bool _assetManagerLoaderFontSync(assetmanageritem_t *item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item) {
|
||||
fontDispose(item->data.font.font);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Texture
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
@ -293,6 +328,11 @@ bool _assetManagerLoaderTextureSync(assetmanageritem_t *item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item) {
|
||||
textureDispose(item->data.texture.texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Scaled Texture
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
@ -423,6 +463,11 @@ bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureScaleDispose(assetmanageritem_t *item) {
|
||||
textureDispose(item->data.scaleTexture.texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shader
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
@ -466,3 +511,8 @@ bool _assetManagerLoaderShaderSync(assetmanageritem_t *item) {
|
||||
free(item->data.shader.dataVert);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item) {
|
||||
shaderDispose(item->data.shader.shader);
|
||||
return true;
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
#include "xml.h"
|
||||
|
||||
#define ASSET_MANAGER_ITEMS_MAX 64
|
||||
#define ASSET_MANAGER_ITEM_NAME_MAX 32
|
||||
#define ASSET_MANAGER_ITEM_NAME_MAX 96
|
||||
|
||||
#define ASSET_MANAGER_HOLDERS_MAX 8
|
||||
|
||||
@ -94,6 +94,7 @@ typedef bool assetmanagerloader_t(assetmanageritem_t *item);
|
||||
typedef struct {
|
||||
assetmanagerloader_t *loadAsync;
|
||||
assetmanagerloader_t *loadSync;
|
||||
assetmanagerloader_t *dispose;
|
||||
} assetmanagerloaderdefinition_t;
|
||||
|
||||
// Manager
|
||||
@ -127,6 +128,7 @@ float assetManagerProgressGet(assetmanager_t *manager);
|
||||
|
||||
uint8_t assetManagerHolderCreate(assetmanager_t *man);
|
||||
void assetManagerHolderRelease(assetmanager_t *man, uint8_t hold);
|
||||
void assetManagerDisposeReleased(assetmanager_t *man);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -206,6 +208,7 @@ assetmanageritem_t * assetManagerLoadFont(
|
||||
|
||||
bool _assetManagerLoaderFontAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderFontSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Queue a texture load onto the asset manager buffer.
|
||||
@ -223,6 +226,7 @@ assetmanageritem_t * assetManagerLoadTexture(
|
||||
|
||||
bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Queue a scaled texture load asset to the asset manager buffer. This will not
|
||||
@ -259,6 +263,7 @@ assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
|
||||
bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureScaleDispose(assetmanageritem_t *item);
|
||||
|
||||
/**
|
||||
* Queues a shader load onto the asset manager buffer.
|
||||
@ -277,4 +282,4 @@ assetmanageritem_t * assetManagerLoadShader(
|
||||
|
||||
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item);
|
||||
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item);
|
@ -10,30 +10,37 @@
|
||||
bool sandboxGameInit(sandboxgame_t *game) {
|
||||
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
|
||||
|
||||
assetManagerInit(&game->manager);
|
||||
assetManagerLoadFont(&game->manager, &game->font,
|
||||
"fonts/opensans/OpenSans-Regular.ttf"
|
||||
assetManagerInit(&game->assetManager);
|
||||
game->assetOwner = assetManagerHolderCreate(&game->assetManager);
|
||||
assetManagerLoadFont(
|
||||
&game->assetManager, game->assetOwner,
|
||||
&game->font, "fonts/opensans/OpenSans-Regular.ttf"
|
||||
);
|
||||
assetManagerLoadShader(&game->manager, &game->shader,
|
||||
"shaders/textured.vert",
|
||||
"shaders/textured.frag"
|
||||
assetManagerLoadShader(
|
||||
&game->assetManager, game->assetOwner,
|
||||
&game->shader, "shaders/textured.vert", "shaders/textured.frag"
|
||||
);
|
||||
assetManagerLoadScaledTexture(&game->manager, &game->st,
|
||||
"poker/characters/sammy", "sprite"
|
||||
assetManagerLoadScaledTexture(
|
||||
&game->assetManager, game->assetOwner,
|
||||
&game->st, "poker/characters/sammy", "sprite"
|
||||
);
|
||||
assetManagerLoadTextureScale(&game->manager, &game->st, &game->texture, 0);
|
||||
assetManagerLoadTextureScale(
|
||||
&game->assetManager, game->assetOwner,
|
||||
&game->st, &game->texture, 0
|
||||
);
|
||||
|
||||
assetManagerStart(&game->assetManager);
|
||||
|
||||
assetManagerStart(&game->manager);
|
||||
return true;
|
||||
}
|
||||
|
||||
void sandboxGameUpdate(sandboxgame_t *game) {
|
||||
camera_t camera;
|
||||
float n = assetManagerProgressGet(&game->manager);
|
||||
|
||||
float n;
|
||||
|
||||
n = assetManagerProgressGet(&game->assetManager);
|
||||
if(n < 1.0f) {
|
||||
assetManagerUpdate(&game->manager);
|
||||
printf("Loading %.2f\n", n);
|
||||
assetManagerUpdate(&game->assetManager);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,5 +59,6 @@ void sandboxGameUpdate(sandboxgame_t *game) {
|
||||
}
|
||||
|
||||
void sandboxGameDispose(sandboxgame_t *game) {
|
||||
// shaderDispose(&game->shader);
|
||||
assetManagerHolderRelease(&game->assetManager, game->assetOwner);
|
||||
primitiveDispose(&game->quad);
|
||||
}
|
@ -22,11 +22,14 @@
|
||||
|
||||
typedef struct {
|
||||
engine_t engine;
|
||||
|
||||
assetmanager_t assetManager;
|
||||
uint8_t assetOwner;
|
||||
|
||||
shader_t shader;
|
||||
font_t font;
|
||||
texture_t texture;
|
||||
primitive_t quad;
|
||||
assetmanager_t manager;
|
||||
|
||||
scaledtexture_t st;
|
||||
} sandboxgame_t;
|
||||
|
Reference in New Issue
Block a user