reset texture path cache on reload

This commit is contained in:
veclav talica 2024-08-21 18:00:27 +03:00
parent 1a34f6416b
commit 9a3d7a9db3
3 changed files with 20 additions and 8 deletions

View File

@ -502,6 +502,7 @@ static void load_game(void) {
static void reset_state(void) { static void reset_state(void) {
input_reset_state(&ctx.input); input_reset_state(&ctx.input);
textures_reset_state();
} }

View File

@ -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 */ /* returns the number of atlases in the cache */
size_t textures_get_num_atlases(const struct texture_cache *cache); size_t textures_get_num_atlases(const struct texture_cache *cache);
void textures_reset_state(void);
#endif #endif

View File

@ -385,20 +385,20 @@ void textures_update_atlas(struct texture_cache *cache) {
/* EXPERIMANTAL: LIKELY TO BE REMOVED! */ /* EXPERIMANTAL: LIKELY TO BE REMOVED! */
#ifdef __linux__ /* use rodata elf section for fast lookups of repeating textures */ #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_start;
static const char *rodata_stop; 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 */ /* TODO: separate and reuse */
t_texture_key textures_get_key(struct texture_cache *cache, const char *path) { 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 (rodata_stop == NULL)
if (!infer_elf_section_bounds(".rodata", &rodata_start, &rodata_stop)) if (!infer_elf_section_bounds(".rodata", &rodata_start, &rodata_stop))
CRY("Section inference", ".rodata section lookup failed"); 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) { size_t textures_get_num_atlases(const struct texture_cache *cache) {
return cache->atlas_index + 1; 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
}