Asset loading

This commit is contained in:
2026-02-04 21:52:14 -06:00
parent d955fb6430
commit 56e1696cd4
10 changed files with 130 additions and 57 deletions

View File

@@ -119,12 +119,9 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
configure_file(opengl.pc.in opengl.pc @ONLY)
find_package(PkgConfig REQUIRED)
pkg_check_modules(zip IMPORTED_TARGET libzip)
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DOLPHIN
)
@@ -159,6 +156,7 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wi
cglm
liblua
m
fat
PkgConfig::zip
)
endif()

View File

@@ -12,14 +12,62 @@
#include "asset/assettype.h"
#include "engine/engine.h"
#include "debug/debug.h"
#include "util/string.h"
errorret_t assetInit(void) {
memoryZero(&ASSET, sizeof(asset_t));
#if DOLPHIN
// Init FAT driver.
if(!fatInitDefault()) errorThrow("Failed to initialize FAT filesystem.");
char_t **dolphinSearchPath = (char_t **)ASSET_DOLPHIN_PATHS;
char_t foundPath[FILENAME_MAX];
foundPath[0] = '\0';
do {
// Try open dir
DIR *pdir = opendir(*dolphinSearchPath);
if(pdir == NULL) continue;
// Scan if file is present
while(true) {
struct dirent* pent = readdir(pdir);
if(pent == NULL) break;
if(stringCompareInsensitive(pent->d_name, ASSET_FILE) != 0) {
continue;
}
// Copy out filename
snprintf(
foundPath,
FILENAME_MAX,
"%s%s",
*dolphinSearchPath,
ASSET_FILE
);
break;
}
// Close dir.
closedir(pdir);
// Did we find the file here?
if(foundPath[0] != '\0') break;
} while(*(++dolphinSearchPath) != NULL);
// Did we find the asset file?
if(foundPath[0] == '\0') {
errorThrow("Failed to find asset file on FAT filesystem.");
}
ASSET.zip = zip_open(foundPath, ZIP_RDONLY, NULL);
if(ASSET.zip == NULL) {
errorThrow("Failed to open asset file on FAT filesystem.");
}
errorOk();
#endif
// Engine may have been provided the launch path
if(ENGINE.argc > 0) {
// Get the directory of the executable

View File

@@ -9,27 +9,46 @@
#include "error/error.h"
#include "assettype.h"
#if ASSET_TYPE == wad
#if PSP
#define ASSET_PBP_READ_PBP_FROM_HOST 0
#define ASSET_PBP_SIGNATURE_SIZE 4
#define ASSET_PBP_SIGNATURE "\0PBP"
#if PSP
#define ASSET_PBP_READ_PBP_FROM_HOST 0
#define ASSET_PBP_SIGNATURE_SIZE 4
#define ASSET_PBP_SIGNATURE "\0PBP"
typedef struct {
char_t signature[ASSET_PBP_SIGNATURE_SIZE];
uint32_t version;
uint32_t sfoOffset;
uint32_t icon0Offset;
uint32_t icon1Offset;
uint32_t pic0Offset;
uint32_t pic1Offset;
uint32_t snd0Offset;
uint32_t pspOffset;
uint32_t psarOffset;
} assetpbp_t;
#elif DOLPHIN
#include <fat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static const char_t *ASSET_DOLPHIN_PATHS[] = {
"/",
"/Dusk",
"%s/dusk",
"%s/DUSK",
"%s/apps",
"%s/apps/Dusk",
"%s/apps/dusk",
"%s/apps/DUSK",
NULL
};
typedef struct {
char_t signature[ASSET_PBP_SIGNATURE_SIZE];
uint32_t version;
uint32_t sfoOffset;
uint32_t icon0Offset;
uint32_t icon1Offset;
uint32_t pic0Offset;
uint32_t pic1Offset;
uint32_t snd0Offset;
uint32_t pspOffset;
uint32_t psarOffset;
} assetpbp_t;
#endif
#else
#error "Unsupported ASSET_TYPE"
#endif
#define ASSET_FILE "dusk.dsk"

View File

@@ -27,7 +27,13 @@ void debugPrint(const char_t *message, ...) {
}
#elif DOLPHIN
if(!DISPLAY.frameBuffer) return;
if(!DISPLAY.frameBuffer) {
errorret_t ret = displayInit();
if(ret.code != ERROR_OK) {
abort();
}
}
console_init(
DISPLAY.frameBuffer,
20,

View File

@@ -86,26 +86,6 @@ errorret_t displayInit(void) {
VIDEO_WaitVSync();
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
// DISPLAY.fifoBuffer = MEM_K0_TO_K1(memalign(32,FIFO_SIZE));
// memset(DISPLAY.fifoBuffer, 0, FIFO_SIZE);
// GX_Init(DISPLAY.fifoBuffer, FIFO_SIZE);
// GXColor backgroundColor = {0, 0, 0, 255};
// GX_SetCopyClear(backgroundColor, 0x00ffffff);
// GX_SetViewport(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight,0,1);
// GX_SetDispCopyYScale((f32)DISPLAY.screenMode->xfbHeight/(f32)DISPLAY.screenMode->efbHeight);
// GX_SetScissor(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight);
// GX_SetDispCopySrc(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight);
// GX_SetDispCopyDst(DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->xfbHeight);
// GX_SetCopyFilter(DISPLAY.screenMode->aa,DISPLAY.screenMode->sample_pattern,
// GX_TRUE,DISPLAY.screenMode->vfilter);
// GX_SetFieldMode(DISPLAY.screenMode->field_rendering,
// ((DISPLAY.screenMode->viHeight==2*DISPLAY.screenMode->xfbHeight)?GX_ENABLE:GX_DISABLE));
// GX_SetCullMode(GX_CULL_NONE);
// GX_CopyDisp(DISPLAY.frameBuffer,GX_TRUE);
// GX_SetDispCopyGamma(GX_GM_1_0);
#endif
quadInit();
@@ -147,6 +127,7 @@ errorret_t displayUpdate(void) {
}
SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext);
#elif DOLPHIN

View File

@@ -68,6 +68,13 @@ int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
}
return framebuffer->texture.width;
#elif DOLPHIN
return DISPLAY.screenMode->fbWidth;
#else
#error "Unsupported DISPLAY_TYPE."
#endif
}
@@ -84,6 +91,13 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
}
return framebuffer->texture.height;
#elif DOLPHIN
return DISPLAY.screenMode->efbHeight;
#else
#error "Unsupported DISPLAY_TYPE."
#endif
}

View File

@@ -18,6 +18,7 @@
#include "script/scriptmanager.h"
#include "debug/debug.h"
#include "item/backpack.h"
#include "assert/assert.h"
engine_t ENGINE;

View File

@@ -11,6 +11,7 @@
#include "util/string.h"
#include "util/math.h"
#include "time/time.h"
#include "debug/debug.h"
input_t INPUT;
@@ -78,7 +79,7 @@ void inputUpdate(void) {
// For each button...
inputbuttondata_t *cur = &INPUT_BUTTON_DATA[0];
do {
while(cur->name) {
cur->lastVal = cur->curVal;
cur->curVal = inputButtonGetValue(cur->button);
@@ -104,7 +105,7 @@ void inputUpdate(void) {
#endif
cur++;
} while(cur->name);
}
// Do we need to fire off events?
#if TIME_FIXED == 0

View File

@@ -174,18 +174,18 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
#elif DOLPHIN
#if INPUT_GAMEPAD == 1
{ .name = "a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_A } },
{ .name = "b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_B } },
{ .name = "x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_X } },
{ .name = "y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_Y } },
{ .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_START } },
{ .name = "a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_A } },
{ .name = "b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_B } },
{ .name = "x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_X } },
{ .name = "y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_Y } },
{ .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_START } },
{ .name = "dpad_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_UP } },
{ .name = "dpad_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_DOWN } },
{ .name = "dpad_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_LEFT } },
{ .name = "dpad_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_RIGHT } },
{ .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_L } },
{ .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_R } },
{ .name = "z", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_Z } },
{ .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_L } },
{ .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_R } },
{ .name = "z", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_Z } },
{ .name = "lstick_positive_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = true } } },
{ .name = "lstick_negative_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = false } } },
{ .name = "lstick_positive_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = true } } },
@@ -220,9 +220,9 @@ float_t inputButtonGetValue(const inputbutton_t button) {
case INPUT_BUTTON_TYPE_KEYBOARD: {
#if INPUT_SDL2 == 1
return INPUT.keyboardState[button.scancode] ? 1.0f : 0.0f;
#else
return 0.0f;
#endif
return 0.0f;
}
#endif
@@ -233,6 +233,7 @@ float_t inputButtonGetValue(const inputbutton_t button) {
return 1.0f;
}
#endif
return 0.0f;
}
@@ -245,6 +246,8 @@ float_t inputButtonGetValue(const inputbutton_t button) {
if(value < INPUT.deadzone) return 0.0f;
return value;
#endif
return 0.0f;
}
#endif

View File

@@ -11,6 +11,8 @@
#include "display/spritebatch.h"
#include "display/screen.h"
#include "debug/debug.h"
ui_t UI;
errorret_t uiInit(void) {