summaryrefslogtreecommitdiff
path: root/kon/konassets.h
diff options
context:
space:
mode:
authorKonAki <konaki@anokonaki.org>2026-10-09 18:21:19 +0800
committerKonAki <konaki@anokonaki.org>2026-10-09 18:21:19 +0800
commit0d73e4712f8472bf8e004faadc79dab453684866 (patch)
treeeb1ddfc88a23eb96c9dfbff481ad9051b3b27c70 /kon/konassets.h
parent29ac0888951c423d6673fff10c93e60b0434f204 (diff)
Add asset groups and automatic model textures
Diffstat (limited to 'kon/konassets.h')
-rw-r--r--kon/konassets.h35
1 files changed, 33 insertions, 2 deletions
diff --git a/kon/konassets.h b/kon/konassets.h
index 6dd65eb..3b35629 100644
--- a/kon/konassets.h
+++ b/kon/konassets.h
@@ -65,6 +65,10 @@ typedef struct kon_assetLoader {
const char *extensions;
void *(*load)(const uint8_t *data, size_t size, size_t *bytes);
void (*unload)(void *object);
+ /* both can be NULL. bind is called right after load and is the place to get other assets the object needs, like the textures of a model.
+ unbind is called by kon_assetsCollect before the object is freed, and gives those assets back. assets that depend on each other in a circle never get freed */
+ void (*bind)(void *object, kon_assets_t *assets);
+ void (*unbind)(void *object, kon_assets_t *assets);
} kon_assetLoader_t;
typedef struct kon_assetInfo {
@@ -89,7 +93,7 @@ int kon_assetsRegister(kon_assets_t *assets, const kon_assetLoader_t *loader);
NULL if it is not found or fails to load, see kon_assetsError */
void *kon_assetGet(kon_assets_t *assets, const char *name);
-/* same but NULL if the file is not of that type, without counting a use */
+/* same, but NULL if the file is not of that type. counts a use the same way, and a file of the wrong type isn't loaded */
void *kon_assetGetAs(kon_assets_t *assets, const char *name, int type);
#define kon_assetBlob(assets, name) ((kon_blob_t *)kon_assetGetAs((assets), (name), KON_ASSET_BLOB))
@@ -99,9 +103,36 @@ void *kon_assetGetAs(kon_assets_t *assets, const char *name, int type);
/* gives back one use. nothing is freed until kon_assetsCollect */
void kon_assetRelease(kon_assets_t *assets, const char *name);
-/* frees everything nobody is using, returns how many it freed */
+/* frees everything nobody is using, and then what only that was using, returns how many it freed */
int kon_assetsCollect(kon_assets_t *assets);
+/*** groups ***/
+
+/* a group is a list of assets that live and die together, like everything one level needs.
+ loading the next level's group before freeing the old one keeps what both use */
+typedef struct kon_assetGroup kon_assetGroup_t;
+
+kon_assetGroup_t *kon_assetGroupCreate(kon_assets_t *assets);
+
+/* adds a name to the waiting list, nothing is loaded yet. returns 0 if there was no memory */
+int kon_assetGroupQueue(kon_assetGroup_t *group, const char *name);
+
+/* queues every name in a text asset, one per line. empty lines and lines starting with # are skipped.
+ returns how many it queued, or -1 if the list can't be read */
+int kon_assetGroupQueueList(kon_assetGroup_t *group, const char *listName);
+
+/* loads one waiting asset and returns how many are still waiting, so a loading bar can call it once per frame */
+int kon_assetGroupStep(kon_assetGroup_t *group);
+
+/* loads everything that is waiting and returns how many could not be loaded */
+int kon_assetGroupLoadAll(kon_assetGroup_t *group);
+
+/* loaded counts the assets that are in, total also counts the ones waiting and the ones that failed */
+void kon_assetGroupProgress(const kon_assetGroup_t *group, int *loaded, int *total);
+
+/* gives back every use the group holds and frees what nothing else uses. the group is gone after this */
+void kon_assetGroupFree(kon_assetGroup_t *group);
+
/* for the debug view */
int kon_assetsCount(const kon_assets_t *assets);
int kon_assetsInfo(const kon_assets_t *assets, int index, kon_assetInfo_t *info);