95 lines
2.7 KiB
C
95 lines
2.7 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/dmf/assetmeshloader.h"
|
|
#include "asset/loader/dmf/assetmodelloader.h"
|
|
#include "asset/loader/display/assettextureloader.h"
|
|
#include "asset/loader/display/assettilesetloader.h"
|
|
#include "asset/loader/locale/assetlocaleloader.h"
|
|
#include "asset/loader/json/assetjsonloader.h"
|
|
|
|
typedef enum {
|
|
ASSET_LOADER_TYPE_NULL,
|
|
|
|
ASSET_LOADER_TYPE_MESH,
|
|
ASSET_LOADER_TYPE_MODEL,
|
|
ASSET_LOADER_TYPE_TEXTURE,
|
|
ASSET_LOADER_TYPE_TILESET,
|
|
ASSET_LOADER_TYPE_LOCALE,
|
|
ASSET_LOADER_TYPE_JSON,
|
|
|
|
ASSET_LOADER_TYPE_COUNT
|
|
} assetloadertype_t;
|
|
|
|
typedef union {
|
|
assetmeshloaderloading_t mesh;
|
|
assetmodelloaderloading_t model;
|
|
assettextureloaderloading_t texture;
|
|
assettilesetloaderloading_t tileset;
|
|
assetlocaleloaderloading_t locale;
|
|
assetjsonloaderloading_t json;
|
|
} assetloaderloading_t;
|
|
|
|
typedef union {
|
|
assetmeshoutput_t mesh;
|
|
assetmodeloutput_t model;
|
|
assettextureoutput_t texture;
|
|
assettilesetoutput_t tileset;
|
|
assetlocaleoutput_t locale;
|
|
assetjsonoutput_t json;
|
|
} assetloaderoutput_t;
|
|
|
|
typedef union {
|
|
assettextureloaderinput_t texture;
|
|
assettilesetloaderinput_t tileset;
|
|
assetlocaleloaderinput_t locale;
|
|
assetjsonloaderinput_t json;
|
|
} assetloaderinput_t;
|
|
|
|
typedef struct assetloading_s assetloading_t;
|
|
typedef struct assetentry_s assetentry_t;
|
|
|
|
typedef errorret_t (assetloadersynccallback_t)(assetloading_t *loading);
|
|
typedef errorret_t (assetloaderasynccallback_t)(assetloading_t *loading);
|
|
typedef errorret_t (assetloaderdisposecallback_t)(assetentry_t *entry);
|
|
|
|
typedef struct {
|
|
assetloadersynccallback_t *loadSync;
|
|
assetloaderasynccallback_t *loadAsync;
|
|
assetloaderdisposecallback_t *dispose;
|
|
} assetloadercallbacks_t;
|
|
|
|
extern assetloadercallbacks_t ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_COUNT];
|
|
|
|
/**
|
|
* Shorthand method to both chain an error (against the loader state) and to
|
|
* set the asset entry state to error.
|
|
*
|
|
* @param loading The asset loading slot.
|
|
* @param ret The error return value to check and chain if it's an error.
|
|
*/
|
|
#define assetLoaderErrorChain(loading, _expr) {\
|
|
errorret_t _alec = (_expr); \
|
|
if(errorIsNotOk(_alec)) { \
|
|
(loading)->entry->state = ASSET_ENTRY_STATE_ERROR; \
|
|
errorChain(_alec); \
|
|
} \
|
|
}
|
|
|
|
/**
|
|
* Shorthand method to both throw an error (against the loader state) and to
|
|
* set the asset entry state to error.
|
|
*
|
|
* @param loading The asset loading slot.
|
|
* @param ... Format string and arguments for the error message.
|
|
*/
|
|
#define assetLoaderErrorThrow(loading, ...) {\
|
|
loading->entry->state = ASSET_ENTRY_STATE_ERROR; \
|
|
errorThrow(__VA_ARGS__); \
|
|
}
|