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

View File

@@ -12,11 +12,59 @@
#include "asset/assettype.h" #include "asset/assettype.h"
#include "engine/engine.h" #include "engine/engine.h"
#include "debug/debug.h" #include "debug/debug.h"
#include "util/string.h"
errorret_t assetInit(void) { errorret_t assetInit(void) {
memoryZero(&ASSET, sizeof(asset_t)); memoryZero(&ASSET, sizeof(asset_t));
#if DOLPHIN #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(); errorOk();
#endif #endif

View File

@@ -9,8 +9,7 @@
#include "error/error.h" #include "error/error.h"
#include "assettype.h" #include "assettype.h"
#if ASSET_TYPE == wad #if PSP
#if PSP
#define ASSET_PBP_READ_PBP_FROM_HOST 0 #define ASSET_PBP_READ_PBP_FROM_HOST 0
#define ASSET_PBP_SIGNATURE_SIZE 4 #define ASSET_PBP_SIGNATURE_SIZE 4
#define ASSET_PBP_SIGNATURE "\0PBP" #define ASSET_PBP_SIGNATURE "\0PBP"
@@ -27,9 +26,29 @@
uint32_t pspOffset; uint32_t pspOffset;
uint32_t psarOffset; uint32_t psarOffset;
} assetpbp_t; } assetpbp_t;
#endif
#else #elif DOLPHIN
#error "Unsupported ASSET_TYPE" #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
};
#endif #endif
#define ASSET_FILE "dusk.dsk" #define ASSET_FILE "dusk.dsk"

View File

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

View File

@@ -86,26 +86,6 @@ errorret_t displayInit(void) {
VIDEO_WaitVSync(); VIDEO_WaitVSync();
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) 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 #endif
quadInit(); quadInit();
@@ -147,6 +127,7 @@ errorret_t displayUpdate(void) {
} }
SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext); SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext);
#elif DOLPHIN #elif DOLPHIN

View File

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

View File

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

View File

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

View File

@@ -220,9 +220,9 @@ float_t inputButtonGetValue(const inputbutton_t button) {
case INPUT_BUTTON_TYPE_KEYBOARD: { case INPUT_BUTTON_TYPE_KEYBOARD: {
#if INPUT_SDL2 == 1 #if INPUT_SDL2 == 1
return INPUT.keyboardState[button.scancode] ? 1.0f : 0.0f; return INPUT.keyboardState[button.scancode] ? 1.0f : 0.0f;
#else
return 0.0f;
#endif #endif
return 0.0f;
} }
#endif #endif
@@ -233,6 +233,7 @@ float_t inputButtonGetValue(const inputbutton_t button) {
return 1.0f; return 1.0f;
} }
#endif #endif
return 0.0f; return 0.0f;
} }
@@ -245,6 +246,8 @@ float_t inputButtonGetValue(const inputbutton_t button) {
if(value < INPUT.deadzone) return 0.0f; if(value < INPUT.deadzone) return 0.0f;
return value; return value;
#endif #endif
return 0.0f;
} }
#endif #endif

View File

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