Palette loading done.

This commit is contained in:
2025-08-27 19:59:55 -05:00
parent 7a90d2d38f
commit 6c11096fd2
11 changed files with 110 additions and 27 deletions

View File

@@ -11,6 +11,7 @@
#include "assettileset.h"
#include "error/error.h"
#include <zip.h>
#include "display/texture/texture.h"
#define ASSET_COUNT_MAX 128
#define ASSET_FILENAME_MAX 128
@@ -21,6 +22,7 @@
#error "Unsupported ASSET_TYPE"
#endif
#pragma pack(push, 1)
typedef struct {
char_t header[ASSET_HEADER_LENGTH];
union {
@@ -28,6 +30,14 @@ typedef struct {
assettileset_t tileset;
};
} assetdata_t;
#pragma pack(pop)
typedef struct {
union {
texture_t palette;
assettileset_t *tileset;
};
} assetloaded_t;
typedef enum {
ASSET_STATE_NONE,
@@ -46,11 +56,16 @@ typedef struct {
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] = {
@@ -63,9 +78,9 @@ static const char_t ASSET_SEARCH_PATHS[][FILENAME_MAX] = {
};
static const assetmap_t ASSET_MAP[] = {
{ "DPF", "test.palette.dpf" },
{ "DPT", "test.tileset.dpt" },
{ NULL, NULL }
{ "DPF", ".dpf", assetParsePalette },
{ "DPT", ".dpt", assetParseTileset },
{ NULL, NULL, NULL }
};
#define ASSET_SEARCH_PATHS_COUNT (\
@@ -83,9 +98,15 @@ errorret_t assetInit(void);
* Gets an asset by filename, does not load it.
*
* @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 assetLoad(
const char_t *filename,
void (*callback)(void* data),
void *data
);
/**
* Disposes/cleans up the asset system.