Asset prog

This commit is contained in:
2025-08-25 10:16:55 -05:00
parent 947f21cac7
commit 8af2f044ed
23 changed files with 290 additions and 31 deletions

View File

@@ -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
)

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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.

View File

@@ -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;