125 lines
3.5 KiB
C
125 lines
3.5 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "asset/loader/assetentry.h"
|
|
#include "asset/loader/assetloader.h"
|
|
#include "event/event.h"
|
|
|
|
#define ASSET_BATCH_COUNT_MAX 64
|
|
#define ASSET_BATCH_EVENT_MAX 4
|
|
|
|
typedef struct {
|
|
const char_t *path;
|
|
assetloadertype_t type;
|
|
assetloaderinput_t input;
|
|
} assetbatchdesc_t;
|
|
|
|
typedef struct {
|
|
assetentry_t *entries[ASSET_BATCH_COUNT_MAX];
|
|
assetloaderinput_t inputs[ASSET_BATCH_COUNT_MAX];
|
|
uint16_t count;
|
|
uint16_t loadedCount;
|
|
uint16_t errorCount;
|
|
|
|
/** Fires once when every entry loaded. params = assetbatch_t * */
|
|
event_t onLoaded;
|
|
eventcallback_t onLoadedCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
void *onLoadedUsers[ASSET_BATCH_EVENT_MAX];
|
|
|
|
/** Fires each time a single entry loads. params = assetentry_t * */
|
|
event_t onEntryLoaded;
|
|
eventcallback_t onEntryLoadedCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
void *onEntryLoadedUsers[ASSET_BATCH_EVENT_MAX];
|
|
|
|
/** Fires when all entries finish (any with errors). params: assetbatch_t * */
|
|
event_t onError;
|
|
eventcallback_t onErrorCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
void *onErrorUsers[ASSET_BATCH_EVENT_MAX];
|
|
|
|
/** Fires each time a single entry errors. params = assetentry_t * */
|
|
event_t onEntryError;
|
|
eventcallback_t onEntryErrorCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
void *onEntryErrorUsers[ASSET_BATCH_EVENT_MAX];
|
|
} assetbatch_t;
|
|
|
|
/**
|
|
* Initialises the batch from an array of descriptors. Each entry is locked
|
|
* and queued for loading immediately.
|
|
*
|
|
* @param batch Batch to initialise.
|
|
* @param descs Array of entry descriptors (need not outlive this call).
|
|
* @param count Number of descriptors (must be <= ASSET_BATCH_COUNT_MAX).
|
|
*/
|
|
void assetBatchInit(
|
|
assetbatch_t *batch,
|
|
uint16_t count,
|
|
const assetbatchdesc_t *descs
|
|
);
|
|
|
|
/**
|
|
* Acquires one additional lock on every entry in the batch.
|
|
*
|
|
* @param batch Batch to lock.
|
|
*/
|
|
void assetBatchLock(assetbatch_t *batch);
|
|
|
|
/**
|
|
* Releases one lock from every entry in the batch. When an entry's lock
|
|
* count reaches zero it will be reaped on the next assetUpdate.
|
|
*
|
|
* @param batch Batch to unlock.
|
|
*/
|
|
void assetBatchUnlock(assetbatch_t *batch);
|
|
|
|
/**
|
|
* Returns true if every entry in the batch has finished loading.
|
|
*
|
|
* @param batch Batch to query.
|
|
*/
|
|
bool_t assetBatchIsLoaded(const assetbatch_t *batch);
|
|
|
|
/**
|
|
* Returns true if any entry in the batch is in an error state.
|
|
*
|
|
* @param batch Batch to query.
|
|
*/
|
|
bool_t assetBatchHasError(const assetbatch_t *batch);
|
|
|
|
/**
|
|
* Blocks until every entry is loaded. Returns an error if any entry fails.
|
|
*
|
|
* @param batch Batch to wait on.
|
|
*/
|
|
errorret_t assetBatchRequireLoaded(assetbatch_t *batch);
|
|
|
|
/**
|
|
* Releases the batch's lock on every entry and clears the batch. After this
|
|
* call the batch struct may be reused with assetBatchInit.
|
|
*
|
|
* @param batch Batch to dispose.
|
|
*/
|
|
void assetBatchDispose(assetbatch_t *batch);
|
|
|
|
/**
|
|
* Event trampoline invoked when a batch entry finishes loading.
|
|
* Increments the loaded counter and fires batch-level events.
|
|
*
|
|
* @param params The loaded assetentry_t pointer.
|
|
* @param user The owning assetbatch_t pointer.
|
|
*/
|
|
void assetBatchEntryOnLoadedCb(void *params, void *user);
|
|
|
|
/**
|
|
* Event trampoline invoked when a batch entry fails to load.
|
|
* Increments the error counter and fires batch-level events.
|
|
*
|
|
* @param params The errored assetentry_t pointer.
|
|
* @param user The owning assetbatch_t pointer.
|
|
*/
|
|
void assetBatchEntryOnErrorCb(void *params, void *user);
|