prog
This commit is contained in:
@@ -65,14 +65,20 @@ void assetLoad(const char_t *filename) {
|
|||||||
"Asset system is already loading an asset."
|
"Asset system is already loading an asset."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Determine the asset map type we are expecting based on the extension.
|
||||||
|
const assetmap_t *expected = &ASSET_MAP[0];
|
||||||
|
do {
|
||||||
|
if(stringEndsWith(filename, expected->extension)) break;
|
||||||
|
expected++;
|
||||||
|
} while(expected->extension);
|
||||||
|
assertNotNull(expected->extension, "Unknown asset type.");
|
||||||
|
|
||||||
// Pass off to the thread to begin loading.
|
// Pass off to the thread to begin loading.
|
||||||
ASSET.errorState = ERROR_STATE_INIT;
|
ASSET.errorState = ERROR_STATE_INIT;
|
||||||
ASSET.state = ASSET_STATE_LOADING;
|
ASSET.state = ASSET_STATE_LOADING;
|
||||||
stringCopy(ASSET.filename, filename, ASSET_FILENAME_MAX);
|
stringCopy(ASSET.filename, filename, ASSET_FILENAME_MAX);
|
||||||
memoryZero(&ASSET.data, sizeof(ASSET.data));
|
memoryZero(&ASSET.data, sizeof(ASSET.data));
|
||||||
|
|
||||||
consolePrint("Loading asset: %s", filename);
|
|
||||||
|
|
||||||
// For the sake of testing I'm going to do blocking load, fun stuff.
|
// For the sake of testing I'm going to do blocking load, fun stuff.
|
||||||
zip_file_t *file = zip_fopen(ASSET.zip, filename, 0);
|
zip_file_t *file = zip_fopen(ASSET.zip, filename, 0);
|
||||||
if(file == NULL) {
|
if(file == NULL) {
|
||||||
@@ -85,8 +91,6 @@ void assetLoad(const char_t *filename) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
consolePrint("Opened asset: %s", filename);
|
|
||||||
|
|
||||||
// Determine length of the file (uncompressed)
|
// Determine length of the file (uncompressed)
|
||||||
struct zip_stat st;
|
struct zip_stat st;
|
||||||
if(zip_stat(ASSET.zip, filename, 0, &st) != 0) {
|
if(zip_stat(ASSET.zip, filename, 0, &st) != 0) {
|
||||||
@@ -100,7 +104,6 @@ void assetLoad(const char_t *filename) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Asset size: %d\n", (int)st.size);
|
|
||||||
if(st.size > sizeof(ASSET.data.palette)) {
|
if(st.size > sizeof(ASSET.data.palette)) {
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
ASSET.error = errorCreate(
|
ASSET.error = errorCreate(
|
||||||
@@ -117,11 +120,26 @@ void assetLoad(const char_t *filename) {
|
|||||||
zip_fread(file, &ASSET.data, st.size);
|
zip_fread(file, &ASSET.data, st.size);
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
ASSET.state = ASSET_STATE_LOADED;
|
ASSET.state = ASSET_STATE_LOADED;
|
||||||
consolePrint("First 3 bytes: %c%c%c\n",
|
|
||||||
ASSET.data.header[0],
|
if(memoryCompare(
|
||||||
ASSET.data.header[1],
|
ASSET.data.header, expected->header, ASSET_HEADER_LENGTH
|
||||||
ASSET.data.header[2]
|
) != 0) {
|
||||||
);
|
ASSET.state = ASSET_STATE_ERROR;
|
||||||
|
ASSET.error = errorCreate(
|
||||||
|
&ASSET.errorState,
|
||||||
|
"Asset header mismatch: %s (got %c%c%c, expected %c%c%c)",
|
||||||
|
filename,
|
||||||
|
ASSET.data.header[0],
|
||||||
|
ASSET.data.header[1],
|
||||||
|
ASSET.data.header[2],
|
||||||
|
expected->header[0],
|
||||||
|
expected->header[1],
|
||||||
|
expected->header[2]
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Loaded asset: %s\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void assetDispose(void) {
|
void assetDispose(void) {
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#define ASSET_COUNT_MAX 128
|
#define ASSET_COUNT_MAX 128
|
||||||
#define ASSET_FILENAME_MAX 128
|
#define ASSET_FILENAME_MAX 128
|
||||||
|
#define ASSET_HEADER_LENGTH 3
|
||||||
|
|
||||||
#if ASSET_TYPE == wad
|
#if ASSET_TYPE == wad
|
||||||
#else
|
#else
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char_t header[3];
|
char_t header[ASSET_HEADER_LENGTH];
|
||||||
union {
|
union {
|
||||||
assetpalette_t palette;
|
assetpalette_t palette;
|
||||||
assettileset_t tileset;
|
assettileset_t tileset;
|
||||||
@@ -47,6 +48,11 @@ typedef struct {
|
|||||||
assetdata_t data;
|
assetdata_t data;
|
||||||
} asset_t;
|
} asset_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char_t *header;
|
||||||
|
const char_t *extension;
|
||||||
|
} assetmap_t;
|
||||||
|
|
||||||
static const char_t ASSET_SEARCH_PATHS[][FILENAME_MAX] = {
|
static const char_t ASSET_SEARCH_PATHS[][FILENAME_MAX] = {
|
||||||
"%s/%s",
|
"%s/%s",
|
||||||
"./%s",
|
"./%s",
|
||||||
@@ -56,6 +62,12 @@ static const char_t ASSET_SEARCH_PATHS[][FILENAME_MAX] = {
|
|||||||
"../data/%s",
|
"../data/%s",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const assetmap_t ASSET_MAP[] = {
|
||||||
|
{ "DPF", "test.palette.dpf" },
|
||||||
|
{ "DPT", "test.tileset.dpt" },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
#define ASSET_SEARCH_PATHS_COUNT (\
|
#define ASSET_SEARCH_PATHS_COUNT (\
|
||||||
sizeof(ASSET_SEARCH_PATHS) / FILENAME_MAX\
|
sizeof(ASSET_SEARCH_PATHS) / FILENAME_MAX\
|
||||||
)
|
)
|
||||||
|
@@ -29,8 +29,8 @@ errorret_t engineInit(void) {
|
|||||||
errorChain(assetInit());
|
errorChain(assetInit());
|
||||||
errorChain(displayInit());
|
errorChain(displayInit());
|
||||||
|
|
||||||
assetLoad("test.palette.dp123123");
|
// assetLoad("test.palette.dp123123");
|
||||||
// assetLoad("test.palette.dpf");
|
assetLoad("test.palette.dpf");
|
||||||
if(ASSET.state == ASSET_STATE_ERROR) errorChain(ASSET.error);
|
if(ASSET.state == ASSET_STATE_ERROR) errorChain(ASSET.error);
|
||||||
|
|
||||||
sceneTestAdd();
|
sceneTestAdd();
|
||||||
|
Reference in New Issue
Block a user