From 9a3d7a9db3655d33e31bea554c98a2926d6f20cc Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Wed, 21 Aug 2024 18:00:27 +0300 Subject: [PATCH] reset texture path cache on reload --- townengine/main.c | 1 + townengine/textures/internal_api.h | 2 ++ townengine/textures/textures.c | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/townengine/main.c b/townengine/main.c index 476c207..fda32fc 100644 --- a/townengine/main.c +++ b/townengine/main.c @@ -502,6 +502,7 @@ static void load_game(void) { static void reset_state(void) { input_reset_state(&ctx.input); + textures_reset_state(); } diff --git a/townengine/textures/internal_api.h b/townengine/textures/internal_api.h index b651015..b2ad139 100644 --- a/townengine/textures/internal_api.h +++ b/townengine/textures/internal_api.h @@ -87,4 +87,6 @@ enum texture_mode textures_get_mode(const struct texture_cache *cache, t_texture /* returns the number of atlases in the cache */ size_t textures_get_num_atlases(const struct texture_cache *cache); +void textures_reset_state(void); + #endif diff --git a/townengine/textures/textures.c b/townengine/textures/textures.c index 145bd40..dd4d4ba 100644 --- a/townengine/textures/textures.c +++ b/townengine/textures/textures.c @@ -385,20 +385,20 @@ void textures_update_atlas(struct texture_cache *cache) { /* EXPERIMANTAL: LIKELY TO BE REMOVED! */ #ifdef __linux__ /* use rodata elf section for fast lookups of repeating textures */ -#include "../system/linux/elf.h" +#include "townengine/system/linux/elf.h" static const char *rodata_start; static const char *rodata_stop; +static const char *last_path = NULL; +static t_texture_key last_texture; +static struct ptr_to_texture { + const void *key; + t_texture_key value; +} *ptr_to_texture; + /* TODO: separate and reuse */ t_texture_key textures_get_key(struct texture_cache *cache, const char *path) { - static const char *last_path = NULL; - static t_texture_key last_texture; - static struct ptr_to_texture { - const void *key; - t_texture_key value; - } *ptr_to_texture; - if (rodata_stop == NULL) if (!infer_elf_section_bounds(".rodata", &rodata_start, &rodata_stop)) CRY("Section inference", ".rodata section lookup failed"); @@ -548,3 +548,12 @@ enum texture_mode textures_get_mode(const struct texture_cache *cache, t_texture size_t textures_get_num_atlases(const struct texture_cache *cache) { return cache->atlas_index + 1; } + +void textures_reset_state(void) { +#ifdef __linux__ + last_path = NULL; + last_texture = (t_texture_key){0}; + shfree(ptr_to_texture); + +#endif +}