Asset compartmentalized

This commit is contained in:
2026-03-08 13:29:40 -05:00
parent a3c2e37b17
commit e984b9f5d7
13 changed files with 375 additions and 282 deletions
+81
View File
@@ -0,0 +1,81 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "asset/asset.h"
#include "engine/engine.h"
#include "util/string.h"
#include "assert/assert.h"
errorret_t assetInitLinux(void) {
// Engine may have been provided the launch path
if(ENGINE.argc > 0) {
// Get the directory of the executable
char_t buffer[FILENAME_MAX];
stringCopy(buffer, ENGINE.argv[0], FILENAME_MAX);
size_t len = strlen(buffer);
// Normalize slashes
for(size_t i = 0; i < FILENAME_MAX; i++) {
if(buffer[i] == '\0') break;
if(buffer[i] == '\\') buffer[i] = '/';
}
// Now find the last slash
char_t *end = buffer + len - 1;
do {
end--;
if(*end == '/') {
*end = '\0';
break;
}
} while(end != buffer);
// Did we find a slash?
if(end != buffer) {
// We found the directory, set as system path
stringCopy(ASSET.platform.systemPath, buffer, FILENAME_MAX);
}
}
// Default system path, intended to be overridden by the platform
stringCopy(ASSET.platform.systemPath, ".", FILENAME_MAX);
// Open zip file
char_t searchPath[FILENAME_MAX];
const char_t **path = ASSET_LINUX_SEARCH_PATHS;
int32_t error;
do {
sprintf(
searchPath,
*path,
ASSET.platform.systemPath,
ASSET_FILE_NAME
);
// Try open
ASSET.zip = zip_open(searchPath, ZIP_RDONLY, &error);
if(ASSET.zip == NULL) continue;
if(error != 0) {
printf("Warning: Opened asset file with non-zero error code: %d\n", error);
ASSET.zip = NULL;
continue;
}
break;// Found!
} while(*(++path) != NULL);
// Did we open the asset?
if(ASSET.zip == NULL) {
errorThrow("Failed to open asset file.");
}
errorOk();
}
errorret_t assetDisposeLinux(void) {
errorOk();
}