From 1aab7ffa2dc0da8e1e25181094f59757e774a7b3 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Sat, 6 Jul 2024 00:49:39 -0300 Subject: [PATCH] Delete translations in G_InitialState --- src/d_main.c | 3 +++ src/g_game.c | 5 ++++ src/r_translation.c | 56 ++++++++++++++++++++++++++++++++++++++++++++- src/r_translation.h | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 4070ce037..3e517795d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1800,6 +1800,9 @@ void D_ReloadFiles(void) Patch_FreeTag(PU_PATCH_ROTATED); Patch_FreeTag(PU_SPRITE); + // Reinit the palette remaps + PaletteRemap_Init(); + // Load SOC and Lua. for (INT32 i = 0; i < numwadfiles; i++) { diff --git a/src/g_game.c b/src/g_game.c index 0f32ff1d9..bb7e55c60 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -27,6 +27,7 @@ #include "p_local.h" #include "r_draw.h" #include "r_main.h" +#include "r_translation.h" #include "s_sound.h" #include "g_game.h" #include "g_demo.h" @@ -4392,6 +4393,10 @@ void G_InitialState(void) // Delete all skins. R_DelSkins(); + // Delete all translations + R_DeleteCustomTranslations(); + PaletteRemap_DeleteAll(); + // Clear all added sound effects. for (INT32 i = sfx_freeslot0; i <= sfx_lastskinsoundslot; i++) { diff --git a/src/r_translation.c b/src/r_translation.c index a53b30e9f..5128ad0e3 100644 --- a/src/r_translation.c +++ b/src/r_translation.c @@ -139,6 +139,48 @@ unsigned PaletteRemap_Add(remaptable_t *tr) return numpaletteremaps - 1; } +static void DeleteSkincolorRemaps(colorcache_t **remaps) +{ + for (unsigned i = 0; i < MAXSKINCOLORS - 1; i++) + { + if (remaps[i]) + Z_Free(remaps[i]); + } +} + +static void PaletteRemap_Delete(remaptable_t *tr) +{ + if (tr->skincolor_remaps) + { + for (unsigned i = 0; i < TT_CACHE_SIZE; i++) + { + colorcache_t **remaps = tr->skincolor_remaps[i]; + if (remaps) + { + DeleteSkincolorRemaps(remaps); + Z_Free(remaps); + } + } + + Z_Free(tr->skincolor_remaps); + } + + Z_Free(tr->sources); + + Z_Free(tr); +} + +void PaletteRemap_DeleteAll(void) +{ + for (unsigned i = 0; i < numpaletteremaps; i++) + PaletteRemap_Delete(paletteremaps[i]); + + Z_Free(paletteremaps); + + paletteremaps = NULL; + numpaletteremaps = 0; +} + static void MakeGrayscaleRemap(void) { remaptable_t *grayscale = PaletteRemap_New(); @@ -1129,7 +1171,7 @@ UINT8 *R_GetTranslationRemap(int id, skincolornum_t skincolor, INT32 skinnum) INT32 index = R_SkinTranslationToCacheIndex(skinnum); if (!tr->skincolor_remaps[index]) - tr->skincolor_remaps[index] = Z_Calloc(NUM_PALETTE_ENTRIES * (MAXSKINCOLORS - 1), PU_LEVEL, NULL); + tr->skincolor_remaps[index] = Z_Calloc(sizeof(colorcache_t *) * (MAXSKINCOLORS - 1), PU_LEVEL, NULL); colorcache_t *cache = tr->skincolor_remaps[index][skincolor - 1]; if (!cache) @@ -1179,3 +1221,15 @@ remaptable_t *R_GetBuiltInTranslation(SINT8 tc) } return NULL; } + +void R_DeleteCustomTranslations(void) +{ + for (unsigned i = 0; i < numcustomtranslations; i++) + { + Z_Free(customtranslations[i].name); + } + + Z_Free(customtranslations); + customtranslations = NULL; + numcustomtranslations = 0; +} diff --git a/src/r_translation.h b/src/r_translation.h index 1eb40233d..d9f76d580 100644 --- a/src/r_translation.h +++ b/src/r_translation.h @@ -79,6 +79,7 @@ boolean PaletteRemap_Equal(remaptable_t *a, remaptable_t *b); void PaletteRemap_SetIdentity(remaptable_t *tr); boolean PaletteRemap_IsIdentity(remaptable_t *tr); unsigned PaletteRemap_Add(remaptable_t *tr); +void PaletteRemap_DeleteAll(void); int R_FindCustomTranslation(const char *name); int R_FindCustomTranslation_CaseInsensitive(const char *name); @@ -89,6 +90,7 @@ remaptable_t *R_GetTranslationByID(int id); UINT8 *R_GetTranslationRemap(int id, skincolornum_t skincolor, INT32 skinnum); void R_UpdateTranslationRemaps(skincolornum_t skincolor, INT32 skinnum); boolean R_TranslationIsValid(int id); +void R_DeleteCustomTranslations(void); void R_ParseTrnslate(INT32 wadNum, UINT16 lumpnum); void R_LoadParsedTranslations(void);