Asset prog
This commit is contained in:
@@ -10,6 +10,7 @@ target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PUBLIC
|
||||
m
|
||||
cglm
|
||||
zip
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
@@ -8,4 +8,10 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
asset.c
|
||||
assetsystem.c
|
||||
)
|
||||
|
||||
# Compile definitions
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
ASSET_TYPE=wad
|
||||
)
|
@@ -7,11 +7,19 @@
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include <zip.h>
|
||||
|
||||
#define ASSET_FILENAME_MAX 256
|
||||
|
||||
typedef struct asset_s {
|
||||
int32_t nothing;
|
||||
|
||||
const char_t *filename;
|
||||
zip_file_t *fileHandle;
|
||||
} asset_t;
|
||||
|
||||
void assetInit(void);
|
||||
void assetInit(
|
||||
const char_t *filename,
|
||||
);
|
||||
|
||||
void assetDispose(void);
|
@@ -7,8 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "display/color.h"
|
||||
|
||||
#define ASSET_PALETTE_COLOR_COUNT_MAX 256
|
||||
|
||||
typedef struct {
|
||||
const int32_t width;
|
||||
const int32_t height;
|
||||
} assetimage_t;
|
||||
char_t header[3];
|
||||
int32_t colorCount;
|
||||
color4b_t colors[ASSET_PALETTE_COLOR_COUNT_MAX];
|
||||
} assetpalette_t;
|
@@ -7,14 +7,68 @@
|
||||
|
||||
#include "assetsystem.h"
|
||||
#include "util/memory.h"
|
||||
#include "console/console.h"
|
||||
|
||||
#define ASSET_SYSTEM_ASSET_FILE "dusk.dsk"
|
||||
|
||||
const char_t ASSET_SYSTEM_SEARCH_PATHS[][FILENAME_MAX] = {
|
||||
"%s/%s",
|
||||
"./%s",
|
||||
"../%s",
|
||||
"../../%s",
|
||||
"data/%s",
|
||||
"../data/%s",
|
||||
};
|
||||
#define ASSET_SYSTEM_SEARCH_PATHS_COUNT (\
|
||||
sizeof(ASSET_SYSTEM_SEARCH_PATHS) / FILENAME_MAX\
|
||||
)
|
||||
|
||||
assetsystem_t ASSET_SYSTEM;
|
||||
|
||||
void assetSystemInit(void) {
|
||||
errorret_t assetSystemInit(void) {
|
||||
memoryZero(&ASSET_SYSTEM, sizeof(assetsystem_t));
|
||||
// threadInit(&ASSET_SYSTEM.thread, NULL);
|
||||
|
||||
// Open zip file
|
||||
char_t searchPath[FILENAME_MAX];
|
||||
consolevar_t *var = consoleVarGet("sys_path");
|
||||
const char_t *sysPath = var ? var->value : ".";
|
||||
for(int32_t i = 0; i < ASSET_SYSTEM_SEARCH_PATHS_COUNT; i++) {
|
||||
sprintf(
|
||||
searchPath,
|
||||
ASSET_SYSTEM_SEARCH_PATHS[i],
|
||||
sysPath,
|
||||
ASSET_SYSTEM_ASSET_FILE
|
||||
);
|
||||
|
||||
// Try open
|
||||
ASSET_SYSTEM.zip = zip_open(searchPath, ZIP_RDONLY, NULL);
|
||||
if(ASSET_SYSTEM.zip == NULL) continue;
|
||||
consolePrint("Opened asset file: %s", searchPath);
|
||||
break;
|
||||
}
|
||||
|
||||
// Did we open the asset?
|
||||
if(ASSET_SYSTEM.zip == NULL) errorThrow("Failed to open asset file.");
|
||||
|
||||
// Get "test.palette.dpf" file.
|
||||
zip_file_t *file = zip_fopen(ASSET_SYSTEM.zip, "test.palette.dpf", 0);
|
||||
if(file == NULL) errorThrow("Failed to open test.palette.dpf in asset file.");
|
||||
|
||||
// Read it
|
||||
char_t buffer[256];
|
||||
zip_int64_t n = zip_fread(file, buffer, 256);
|
||||
if(n < 0) {
|
||||
zip_fclose(file);
|
||||
errorThrow("Failed to read test.palette.dpf in asset file.");
|
||||
}
|
||||
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void assetSystemDispose(void) {
|
||||
// threadDispose(&ASSET_SYSTEM.thread);
|
||||
if(ASSET_SYSTEM.zip != NULL) {
|
||||
zip_close(ASSET_SYSTEM.zip);
|
||||
ASSET_SYSTEM.zip = NULL;
|
||||
}
|
||||
}
|
@@ -7,9 +7,16 @@
|
||||
|
||||
#pragma once
|
||||
#include "asset.h"
|
||||
#include "error/error.h"
|
||||
|
||||
#if ASSET_TYPE == wad
|
||||
#else
|
||||
#error "Unsupported ASSET_TYPE"
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int32_t nothing;
|
||||
zip_t *zip;
|
||||
} assetsystem_t;
|
||||
|
||||
extern assetsystem_t ASSET_SYSTEM;
|
||||
@@ -17,7 +24,7 @@ extern assetsystem_t ASSET_SYSTEM;
|
||||
/**
|
||||
* Initializes the asset system.
|
||||
*/
|
||||
void assetSystemInit(void);
|
||||
errorret_t assetSystemInit(void);
|
||||
|
||||
/**
|
||||
* Disposes/cleans up the asset system.
|
||||
|
@@ -11,9 +11,10 @@
|
||||
typedef struct assetimage_s assetimage_t;
|
||||
|
||||
typedef struct {
|
||||
const int32_t tileWidth;
|
||||
const int32_t tileHeight;
|
||||
const int32_t tileCount;
|
||||
const int32_t columns;
|
||||
const assetimage_t *image;
|
||||
char_t header[3];
|
||||
int32_t tileWidth;
|
||||
int32_t tileHeight;
|
||||
int32_t tileCount;
|
||||
int32_t columns;
|
||||
char_t tilesetName[256];
|
||||
} assettileset_t;
|
@@ -18,6 +18,6 @@ add_subdirectory(cmd)
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
DUSK_CONSOLE_POSIX=1
|
||||
CONSOLE_POSIX=1
|
||||
)
|
||||
endif()
|
@@ -45,11 +45,32 @@ consolevar_t * consoleRegVar(
|
||||
const char_t *value,
|
||||
consolevarchanged_t event
|
||||
) {
|
||||
consolevar_t *var = &CONSOLE.variables[CONSOLE.variableCount++];
|
||||
consolevar_t *var;
|
||||
|
||||
// Existing?
|
||||
var = consoleVarGet(name);
|
||||
if(var != NULL) return var;
|
||||
|
||||
assertTrue(
|
||||
CONSOLE.variableCount < CONSOLE_VARIABLES_MAX,
|
||||
"Too many console variables registered."
|
||||
);
|
||||
|
||||
// Create
|
||||
var = &CONSOLE.variables[CONSOLE.variableCount++];
|
||||
consoleVarInitListener(var, name, value, event);
|
||||
return var;
|
||||
}
|
||||
|
||||
consolevar_t * consoleVarGet(const char_t *name) {
|
||||
assertNotNull(name, "name must not be NULL");
|
||||
for(uint32_t i = 0; i < CONSOLE.variableCount; i++) {
|
||||
consolevar_t *var = &CONSOLE.variables[i];
|
||||
if(stringCompare(var->name, name) == 0) return var;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void consolePrint(const char_t *message, ...) {
|
||||
char_t buffer[CONSOLE_LINE_MAX];
|
||||
|
||||
|
@@ -85,6 +85,14 @@ consolevar_t * consoleRegVar(
|
||||
consolevarchanged_t event
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets a console variable by name.
|
||||
*
|
||||
* @param name The name of the variable.
|
||||
* @return The variable, or NULL if not found.
|
||||
*/
|
||||
consolevar_t * consoleVarGet(const char_t *name);
|
||||
|
||||
/**
|
||||
* Sets the value of a console variable.
|
||||
*
|
||||
|
@@ -26,7 +26,7 @@ errorret_t engineInit(void) {
|
||||
timeInit();
|
||||
consoleInit();
|
||||
ecsSystemInit();
|
||||
assetSystemInit();
|
||||
errorChain(assetSystemInit());
|
||||
errorChain(displayInit());
|
||||
|
||||
sceneTestAdd();
|
||||
|
@@ -115,7 +115,7 @@ errorret_t errorPrint(const errorret_t retval);
|
||||
#define errorThrow(message, ...) \
|
||||
return errorThrowImpl(\
|
||||
&ERROR_STATE, ERROR_NOT_OK, __FILE__, __func__, __LINE__, (message), \
|
||||
__VA_ARGS__ \
|
||||
##__VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
|
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "engine/engine.h"
|
||||
#include "console/console.h"
|
||||
|
||||
// PSP_MODULE_INFO("Dusk", 0, 1, 0);
|
||||
// PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | THREAD_ATTR_VFPU);
|
||||
@@ -14,6 +15,9 @@ int main(int argc, char **argv) {
|
||||
errorret_t ret;
|
||||
ret = engineInit();
|
||||
|
||||
// Set console variable
|
||||
if(argc > 0) consoleRegVar("sys_path", argv[0], NULL);
|
||||
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return ret.code;
|
||||
|
Reference in New Issue
Block a user