/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "dusk.h" #include "assetpalette.h" #include "assettileset.h" #include "assetpalleteimage.h" #include "error/error.h" #include #include "display/texture/texture.h" #define ASSET_COUNT_MAX 128 #define ASSET_FILENAME_MAX 128 #define ASSET_HEADER_LENGTH 3 #if ASSET_TYPE == wad #else #error "Unsupported ASSET_TYPE" #endif #pragma pack(push, 1) typedef struct { char_t header[ASSET_HEADER_LENGTH]; union { assetpalette_t palette; assettileset_t tileset; assetpaletteimage_t paletteImage; }; } assetdata_t; #pragma pack(pop) typedef struct { union { texture_t palette; assettileset_t *tileset; texture_t paletteImage; }; } assetloaded_t; typedef enum { ASSET_STATE_NONE, ASSET_STATE_LOADING, ASSET_STATE_LOADED, ASSET_STATE_ERROR } assetstate_t; typedef struct { int32_t nothing; zip_t *zip; // thread_t thread; errorstate_t errorState; errorret_t error; assetstate_t state; char_t filename[ASSET_FILENAME_MAX]; assetdata_t data; assetloaded_t loaded; void (*callback)(void* data); void *callbackData; } asset_t; typedef struct { const char_t *header; const char_t *extension; void (*parser)(); } assetmap_t; static const char_t ASSET_SEARCH_PATHS[][FILENAME_MAX] = { "%s/%s", "./%s", "../%s", "../../%s", "data/%s", "../data/%s", }; static const assetmap_t ASSET_MAP[] = { { "DPF", ".dpf", assetParsePalette }, { "DPT", ".dpt", assetParseTileset }, { "DPI", ".dpi", assetParsePaletteImage }, { NULL, NULL, NULL } }; #define ASSET_SEARCH_PATHS_COUNT (\ sizeof(ASSET_SEARCH_PATHS) / FILENAME_MAX\ ) extern asset_t ASSET; /** * Initializes the asset system. */ errorret_t assetInit(void); /** * Loads an asset by filename, blocking. * * @param filename The filename of the asset to get. * @param callback The callback to call when the asset is loaded. * @param data The data for the callback function. * @return The asset. */ void assetLoad( const char_t *filename, void (*callback)(void* data), void *data ); /** * Disposes/cleans up the asset system. */ void assetDispose(void);