Asset compartmentalized
This commit is contained in:
@@ -10,4 +10,5 @@ target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(debug)
|
||||
10
src/dusklinux/asset/CMakeLists.txt
Normal file
10
src/dusklinux/asset/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
assetlinux.c
|
||||
)
|
||||
81
src/dusklinux/asset/assetlinux.c
Normal file
81
src/dusklinux/asset/assetlinux.c
Normal 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();
|
||||
}
|
||||
37
src/dusklinux/asset/assetlinux.h
Normal file
37
src/dusklinux/asset/assetlinux.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
static const char_t *ASSET_LINUX_SEARCH_PATHS[] = {
|
||||
"%s/%s",
|
||||
"%s",
|
||||
"../%s",
|
||||
"../../%s",
|
||||
"data/%s",
|
||||
"../data/%s",
|
||||
NULL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char_t systemPath[FILENAME_MAX];
|
||||
} assetlinux_t;
|
||||
|
||||
/**
|
||||
* Initializes the asset system on Linux.
|
||||
*
|
||||
* @return Error state if failed, otherwise returns success.
|
||||
*/
|
||||
errorret_t assetInitLinux(void);
|
||||
|
||||
/**
|
||||
* Disposes the asset system on Linux.
|
||||
*
|
||||
* @return Error state if failed, otherwise returns success.
|
||||
*/
|
||||
errorret_t assetDisposeLinux(void);
|
||||
13
src/dusklinux/asset/assetplatform.h
Normal file
13
src/dusklinux/asset/assetplatform.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset/assetlinux.h"
|
||||
|
||||
typedef assetlinux_t assetplatform_t;
|
||||
#define assetInitPlatform assetInitLinux
|
||||
#define assetDisposePlatform assetDisposeLinux
|
||||
Reference in New Issue
Block a user