game: allocate translation and dynamic entities by malloc

gi.TagMalloc can't be used as free up all tags on save load
This commit is contained in:
Denis Pauk 2024-12-25 00:35:10 +02:00
parent b6f69da662
commit dbcd1d0d6d
6 changed files with 57 additions and 10 deletions

View file

@ -2592,7 +2592,7 @@ uint8_t *QVk_GetStagingBuffer(VkDeviceSize size, int alignment, VkCommandBuffer
stagingBuffer = &vk_stagingBuffers[vk_activeStagingBuffer]; stagingBuffer = &vk_stagingBuffers[vk_activeStagingBuffer];
if (size > stagingBuffer->resource.size) if (size > stagingBuffer->resource.size)
{ {
R_Printf(PRINT_ALL, "%s: %d: Resize stanging buffer %" YQ2_COM_PRIu64 "-> %" YQ2_COM_PRIu64 "\n", R_Printf(PRINT_ALL, "%s: %d: Resize stanging buffer " YQ2_COM_PRIdS "-> " YQ2_COM_PRIdS "\n",
__func__, vk_activeStagingBuffer, stagingBuffer->resource.size, size); __func__, vk_activeStagingBuffer, stagingBuffer->resource.size, size);
DestroyStagingBuffer(stagingBuffer); DestroyStagingBuffer(stagingBuffer);

View file

@ -783,8 +783,6 @@ YQ2_ATTR_NORETURN void Com_Quit(void);
/* Ugly work around for unsupported /* Ugly work around for unsupported
* format specifiers unter mingw. */ * format specifiers unter mingw. */
#define YQ2_COM_PRIu64 PRIu64
#ifdef WIN32 #ifdef WIN32
#define YQ2_COM_PRId64 "%I64d" #define YQ2_COM_PRId64 "%I64d"
#define YQ2_COM_PRIdS "%Id" #define YQ2_COM_PRIdS "%Id"

View file

@ -118,6 +118,8 @@ ShutdownGame(void)
gi.FreeTags(TAG_LEVEL); gi.FreeTags(TAG_LEVEL);
gi.FreeTags(TAG_GAME); gi.FreeTags(TAG_GAME);
SpawnFree();
LocalizationFree();
} }
/* /*

View file

@ -2220,7 +2220,7 @@ DynamicSpawnInit(void)
if (ndynamicentities) if (ndynamicentities)
{ {
dynamicentities = gi.TagMalloc(ndynamicentities * sizeof(*dynamicentities), TAG_GAME); dynamicentities = malloc(ndynamicentities * sizeof(*dynamicentities));
memset(dynamicentities, 0, ndynamicentities * sizeof(*dynamicentities)); memset(dynamicentities, 0, ndynamicentities * sizeof(*dynamicentities));
} }
curr_pos = 0; curr_pos = 0;
@ -2449,3 +2449,16 @@ SpawnInit(void)
StaticSpawnInit(); StaticSpawnInit();
DynamicSpawnInit(); DynamicSpawnInit();
} }
void
SpawnFree(void)
{
if (dynamicentities || ndynamicentities)
{
gi.dprintf("Free %d dynamic definitions\n", ndynamicentities);
free(dynamicentities);
}
dynamicentities = NULL;
ndynamicentities = 0;
}

View file

@ -135,7 +135,7 @@ LocalizationInit(void)
if (nlocalmessages) if (nlocalmessages)
{ {
localmessages = gi.TagMalloc(nlocalmessages * sizeof(*localmessages), TAG_GAME); localmessages = malloc(nlocalmessages * sizeof(*localmessages));
memset(localmessages, 0, nlocalmessages * sizeof(*localmessages)); memset(localmessages, 0, nlocalmessages * sizeof(*localmessages));
} }
@ -225,10 +225,10 @@ LocalizationInit(void)
*currend = 0; *currend = 0;
} }
localmessages[curr_pos].key = gi.TagMalloc(strlen(curr) + 2, TAG_GAME); localmessages[curr_pos].key = malloc(strlen(curr) + 2);
localmessages[curr_pos].key[0] = '$'; localmessages[curr_pos].key[0] = '$';
strcpy(localmessages[curr_pos].key + 1, curr); strcpy(localmessages[curr_pos].key + 1, curr);
localmessages[curr_pos].value = gi.TagMalloc(strlen(sign) + 1, TAG_GAME); localmessages[curr_pos].value = malloc(strlen(sign) + 1);
strcpy(localmessages[curr_pos].value, sign); strcpy(localmessages[curr_pos].value, sign);
/* ReRelease does not have merged sound files to message */ /* ReRelease does not have merged sound files to message */
localmessages[curr_pos].sound = NULL; localmessages[curr_pos].sound = NULL;
@ -301,16 +301,16 @@ LocalizationInit(void)
currend++; currend++;
} }
localmessages[curr_pos].key = gi.TagMalloc(6, TAG_GAME); localmessages[curr_pos].key = malloc(6);
snprintf(localmessages[curr_pos].key, 5, "%d", i); snprintf(localmessages[curr_pos].key, 5, "%d", i);
localmessages[curr_pos].value = gi.TagMalloc(strlen(curr) + 1, TAG_GAME); localmessages[curr_pos].value = malloc(strlen(curr) + 1);
strcpy(localmessages[curr_pos].value, curr); strcpy(localmessages[curr_pos].value, curr);
/* Some Heretic message could have no sound effects */ /* Some Heretic message could have no sound effects */
localmessages[curr_pos].sound = NULL; localmessages[curr_pos].sound = NULL;
if (sign) if (sign)
{ {
/* has some sound aligned with message */ /* has some sound aligned with message */
localmessages[curr_pos].sound = gi.TagMalloc(strlen(sign) + 1, TAG_GAME); localmessages[curr_pos].sound = malloc(strlen(sign) + 1);
strcpy(localmessages[curr_pos].sound, sign); strcpy(localmessages[curr_pos].sound, sign);
} }
@ -344,6 +344,38 @@ LocalizationInit(void)
qsort(localmessages, nlocalmessages, sizeof(localmessages_t), LocalizationSort); qsort(localmessages, nlocalmessages, sizeof(localmessages_t), LocalizationSort);
} }
void
LocalizationFree(void)
{
if (localmessages || nlocalmessages)
{
int i;
for (i = 0; i < nlocalmessages; i++)
{
if (localmessages[i].key)
{
free(localmessages[i].key);
}
if (localmessages[i].value)
{
free(localmessages[i].value);
}
if (localmessages[i].sound)
{
free(localmessages[i].sound);
}
}
free(localmessages);
gi.dprintf("Free %d translated lines\n", nlocalmessages);
}
localmessages = NULL;
nlocalmessages = 0;
}
static int static int
LocalizationSearch(const char *name) LocalizationSearch(const char *name)
{ {

View file

@ -1014,6 +1014,7 @@ void EndDMLevel(void);
/* g_translate.c */ /* g_translate.c */
void LocalizationInit(void); void LocalizationInit(void);
void LocalizationFree(void);
const char* LocalizationMessage(const char *message, int *sound_index); const char* LocalizationMessage(const char *message, int *sound_index);
/* g_chase.c */ /* g_chase.c */
@ -1100,6 +1101,7 @@ void ED_CallSpawn(edict_t *ent);
void DynamicResetSpawnModels(edict_t *self); void DynamicResetSpawnModels(edict_t *self);
char *ED_NewString(const char *string, qboolean raw); char *ED_NewString(const char *string, qboolean raw);
void SpawnInit(void); void SpawnInit(void);
void SpawnFree(void);
void P_ToggleFlashlight(edict_t *ent, qboolean state); void P_ToggleFlashlight(edict_t *ent, qboolean state);
edict_t *CreateFlyMonster(vec3_t origin, vec3_t angles, vec3_t mins, edict_t *CreateFlyMonster(vec3_t origin, vec3_t angles, vec3_t mins,
vec3_t maxs, char *classname); vec3_t maxs, char *classname);