prog
This commit is contained in:
@@ -64,6 +64,14 @@ void assetLoad(const char_t *filename) {
|
||||
ASSET.state != ASSET_STATE_LOADING,
|
||||
"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.
|
||||
ASSET.errorState = ERROR_STATE_INIT;
|
||||
@@ -71,8 +79,6 @@ void assetLoad(const char_t *filename) {
|
||||
stringCopy(ASSET.filename, filename, ASSET_FILENAME_MAX);
|
||||
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.
|
||||
zip_file_t *file = zip_fopen(ASSET.zip, filename, 0);
|
||||
if(file == NULL) {
|
||||
@@ -85,8 +91,6 @@ void assetLoad(const char_t *filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
consolePrint("Opened asset: %s", filename);
|
||||
|
||||
// Determine length of the file (uncompressed)
|
||||
struct zip_stat st;
|
||||
if(zip_stat(ASSET.zip, filename, 0, &st) != 0) {
|
||||
@@ -100,7 +104,6 @@ void assetLoad(const char_t *filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Asset size: %d\n", (int)st.size);
|
||||
if(st.size > sizeof(ASSET.data.palette)) {
|
||||
zip_fclose(file);
|
||||
ASSET.error = errorCreate(
|
||||
@@ -117,11 +120,26 @@ void assetLoad(const char_t *filename) {
|
||||
zip_fread(file, &ASSET.data, st.size);
|
||||
zip_fclose(file);
|
||||
ASSET.state = ASSET_STATE_LOADED;
|
||||
consolePrint("First 3 bytes: %c%c%c\n",
|
||||
ASSET.data.header[0],
|
||||
ASSET.data.header[1],
|
||||
ASSET.data.header[2]
|
||||
);
|
||||
|
||||
if(memoryCompare(
|
||||
ASSET.data.header, expected->header, ASSET_HEADER_LENGTH
|
||||
) != 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) {
|
||||
|
||||
Reference in New Issue
Block a user