From 540a0387c9fc107fcefd64e36cdbbec2930ed461 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Fri, 29 May 2020 18:08:00 +0300 Subject: [PATCH 1/3] fix build --- src/pc/controller/controller_entry_point.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pc/controller/controller_entry_point.c b/src/pc/controller/controller_entry_point.c index 2b264b29..65b88023 100644 --- a/src/pc/controller/controller_entry_point.c +++ b/src/pc/controller/controller_entry_point.c @@ -1,6 +1,8 @@ #include "lib/src/libultra_internal.h" #include "lib/src/osContInternal.h" +#include "../configfile.h" + #include "controller_recorded_tas.h" #include "controller_keyboard.h" From 93030b02a3451f95c97103bec3f114e448c6ed7f Mon Sep 17 00:00:00 2001 From: fgsfds Date: Fri, 29 May 2020 19:35:35 +0300 Subject: [PATCH 2/3] don't die after encountering a NULL texture --- src/game/ingame_menu.c | 2 ++ src/pc/gfx/gfx_pc.c | 44 +++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index 6f3d84b9..9711ec7e 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -245,6 +245,7 @@ static inline u8 *convert_ia8_char(u8 c, u16 *tex, s16 w, s16 h) { #ifdef EXTERNAL_TEXTURES return (u8 *)tex; // the data's just a name #else + if (!tex) return NULL; if (!charCache[c].used) { charCache[c].used = 1; alloc_ia8_text_from_i1(charCache[c].data, tex, w, h); @@ -305,6 +306,7 @@ static u8 *convert_ia4_char(u8 c, u8 *tex, s16 w, s16 h) { #ifdef EXTERNAL_TEXTURES return tex; // the data's just a name #else + if (!tex) return NULL; if (!charCache[c].used) { charCache[c].used = 1; alloc_ia4_tex_from_i1(charCache[c].data, tex, w, h); diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index c0900831..6bd2fca4 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -573,30 +574,47 @@ static bool preload_texture(const char *path) { return true; } +static inline void load_texture(const char *name) { + static char fpath[SYS_MAX_PATH]; + int w, h; + const char *texname = name; + + if (!texname[0]) { + fprintf(stderr, "empty texture name at %p\n", texname); + return; + } + + snprintf(fpath, sizeof(fpath), "%s/%s.png", sys_data_path(), texname); + u8 *data = stbi_load(fpath, &w, &h, NULL, 4); + if (!data) { + fprintf(stderr, "could not load texture: `%s`\n", fpath); + return; + } + + gfx_rapi->upload_texture(data, w, h); + stbi_image_free(data); // don't need this anymore +} + #endif // EXTERNAL_TEXTURES static void import_texture(int tile) { uint8_t fmt = rdp.texture_tile.fmt; uint8_t siz = rdp.texture_tile.siz; - + + if (!rdp.loaded_texture[tile].addr) { + fprintf(stderr, "NULL texture: tile %d, format %d/%d, size %d\n", + tile, (int)fmt, (int)siz, (int)rdp.loaded_texture[tile].size_bytes); + return; + } + if (gfx_texture_cache_lookup(tile, &rendering_state.textures[tile], rdp.loaded_texture[tile].addr, fmt, siz)) { return; } - + #ifdef EXTERNAL_TEXTURES // the "texture data" is actually a C string with the path to our texture in it // load it from an external image in our data path - static char fpath[SYS_MAX_PATH]; - int w, h; - const char *texname = (const char*)rdp.loaded_texture[tile].addr; - snprintf(fpath, sizeof(fpath), "%s/%s.png", sys_data_path(), texname); - u8 *data = stbi_load(fpath, &w, &h, NULL, 4); - if (!data) { - fprintf(stderr, "could not load texture: `%s`\n", fpath); - abort(); - } - gfx_rapi->upload_texture(data, w, h); - stbi_image_free(data); // don't need this anymore + load_texture((const char*)rdp.loaded_texture[tile].addr); #else // the texture data is actual texture data int t0 = get_time(); From f6c54e95b239e991253b730c62a068baf1c6a3b5 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Fri, 29 May 2020 20:10:38 +0300 Subject: [PATCH 3/3] read in all config line tokens (fixes the binds not saving) --- src/pc/configfile.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 25eb1146..9c9038a4 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -231,7 +231,7 @@ void configfile_load(const char *filename) { // Go through each line in the file while ((line = read_file_line(file)) != NULL) { char *p = line; - char *tokens[2]; + char *tokens[1 + MAX_BINDS]; int numTokens; while (isspace(*p)) @@ -240,7 +240,7 @@ void configfile_load(const char *filename) { if (!*p || *p == '#') // comment or empty line continue; - numTokens = tokenize_string(p, 2, tokens); + numTokens = tokenize_string(p, sizeof(tokens) / sizeof(tokens[0]), tokens); if (numTokens != 0) { if (numTokens >= 2) { const struct ConfigOption *option = NULL; @@ -274,7 +274,9 @@ void configfile_load(const char *filename) { default: assert(0); // bad type } - printf("option: '%s', value: '%s'\n", tokens[0], tokens[1]); + printf("option: '%s', value:", tokens[0]); + for (int i = 1; i < numTokens; ++i) printf(" '%s'", tokens[i]); + printf("\n"); } } else puts("error: expected value");