Doing some thinking about asset manager
This commit is contained in:
@ -36,6 +36,7 @@ void assetManagerInit(assetmanager_t *manager) {
|
||||
manager->thread.user = manager;
|
||||
manager->itemCount = 0;
|
||||
manager->finished = false;
|
||||
manager->holderCount = 0;
|
||||
}
|
||||
|
||||
void assetManagerStart(assetmanager_t *manager) {
|
||||
@ -383,4 +384,26 @@ bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item) {
|
||||
|
||||
free(item->data.scaleTexture.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man) {
|
||||
uint8_t i;
|
||||
|
||||
// Find first available number.
|
||||
for(i = 0; i < 0xFF; i++) {
|
||||
if(arrayFind(sizeof(uint8_t), man->holders, man->holderCount, &i) == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
man->holders[man->holderCount++] = i;
|
||||
return i;// No slots left.
|
||||
}
|
||||
|
||||
void assetManagerHolderRelease(assetmanager_t *man, assetmanagerowner_t hold) {
|
||||
uint8_t i = arrayFind(sizeof(uint8_t), man->holders, man->holderCount, &hold);
|
||||
if(i == -1) return;
|
||||
arraySplice(sizeof(uint8_t), man->holders, i, 1, man->holderCount);
|
||||
man->holderCount--;
|
||||
}
|
@ -14,9 +14,11 @@
|
||||
#include "../display/scaledtexture.h"
|
||||
#include "../display/font.h"
|
||||
#include "../script/scripter.h"
|
||||
#include "../util/array.h"
|
||||
#include "xml.h"
|
||||
|
||||
#define ASSET_MANAGER_ITEMS_MAX 64
|
||||
#define ASSET_MANAGER_HOLDERS_MAX 8
|
||||
|
||||
#define ASSET_MANAGER_STATE_PENDING 0x00
|
||||
#define ASSET_MANAGER_STATE_ASYNC_LOADING 0x01
|
||||
@ -67,6 +69,8 @@ typedef struct {
|
||||
|
||||
|
||||
// Item
|
||||
typedef uint8_t assetmanagerowner_t;
|
||||
|
||||
typedef union {
|
||||
assetmanagertexture_t texture;
|
||||
assetmanagershader_t shader;
|
||||
@ -79,6 +83,7 @@ typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t state;
|
||||
assetmanagerassetdata_t data;
|
||||
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
|
||||
} assetmanageritem_t;
|
||||
|
||||
|
||||
@ -97,6 +102,9 @@ typedef struct {
|
||||
assetmanageritem_t items[ASSET_MANAGER_ITEMS_MAX];
|
||||
uint8_t itemCount;
|
||||
bool finished;
|
||||
|
||||
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
|
||||
uint8_t holderCount;
|
||||
} assetmanager_t;
|
||||
|
||||
extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[];
|
||||
@ -214,4 +222,10 @@ assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item);
|
||||
bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item);
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t assetManagerHolderCreate(assetmanager_t *man);
|
||||
void assetManagerHolderRelease(assetmanager_t *man, uint8_t hold);
|
@ -7,8 +7,6 @@
|
||||
|
||||
#include "game.h"
|
||||
|
||||
#define CHUNK 16384
|
||||
|
||||
bool sandboxGameInit(sandboxgame_t *game) {
|
||||
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
|
||||
|
||||
@ -21,14 +19,11 @@ bool sandboxGameInit(sandboxgame_t *game) {
|
||||
"shaders/textured.frag"
|
||||
);
|
||||
assetManagerLoadScaledTexture(&game->manager, &game->st,
|
||||
"poker/characters/penny", "sprite"
|
||||
"poker/characters/sammy", "sprite"
|
||||
);
|
||||
assetManagerLoadTextureScale(&game->manager, &game->st, &game->texture, 0);
|
||||
|
||||
assetManagerStart(&game->manager);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user