57 lines
1.5 KiB
C
57 lines
1.5 KiB
C
/**
|
|
* Copyright (c) 2021 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "item.h"
|
|
|
|
assetmanageritem_t * assetManagerItemGet(assetmanager_t *man, char *key) {
|
|
uint8_t i;
|
|
assetmanageritem_t *item;
|
|
|
|
for(i = 0; i < man->itemCount; i++) {
|
|
item = man->items + i;
|
|
if(strcmp(item->key, key) == 0) return item;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager, char *key) {
|
|
// Check if key already exists.
|
|
assetmanageritem_t *item = manager->items + manager->itemCount++;
|
|
item->state = ASSET_MANAGER_STATE_NOT_READY;
|
|
memcpy(item->key, key, strlen(key) + 1);
|
|
item->holderCount = 0x00;
|
|
return item;
|
|
}
|
|
|
|
uint8_t assetManagerItemGetOrAddHolder(
|
|
assetmanageritem_t *item, assetmanagerowner_t owner
|
|
) {
|
|
uint8_t i, firstEmpty;
|
|
firstEmpty = 0xFF;
|
|
|
|
for(i = 0; i < item->holderCount; i++) {
|
|
if(item->holders[i] == owner) return i;
|
|
if(firstEmpty == 0xFF && item->holders[i] == 0xFF) {
|
|
firstEmpty = i;
|
|
}
|
|
}
|
|
|
|
if(firstEmpty == 0xFF) firstEmpty = item->holderCount++;
|
|
item->holders[firstEmpty] = owner;
|
|
return firstEmpty;
|
|
}
|
|
|
|
bool assetManagerItemIsFinished(assetmanageritem_t *item, assetmanagerloaderdefinition_t *def) {
|
|
// Sync done is always done
|
|
if(item->state == ASSET_MANAGER_STATE_SYNC_DONE) return true;
|
|
// Only check if ASYNC is done.
|
|
if(item->state != ASSET_MANAGER_STATE_ASYNC_DONE) return false;
|
|
// Does it need to still sync load?
|
|
if(def->loadSync == NULL) return true;
|
|
return false;
|
|
} |