mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-12 07:04:15 +00:00
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:
parent
b6f69da662
commit
dbcd1d0d6d
6 changed files with 57 additions and 10 deletions
|
@ -2592,7 +2592,7 @@ uint8_t *QVk_GetStagingBuffer(VkDeviceSize size, int alignment, VkCommandBuffer
|
|||
stagingBuffer = &vk_stagingBuffers[vk_activeStagingBuffer];
|
||||
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);
|
||||
|
||||
DestroyStagingBuffer(stagingBuffer);
|
||||
|
|
|
@ -783,8 +783,6 @@ YQ2_ATTR_NORETURN void Com_Quit(void);
|
|||
|
||||
/* Ugly work around for unsupported
|
||||
* format specifiers unter mingw. */
|
||||
#define YQ2_COM_PRIu64 PRIu64
|
||||
|
||||
#ifdef WIN32
|
||||
#define YQ2_COM_PRId64 "%I64d"
|
||||
#define YQ2_COM_PRIdS "%Id"
|
||||
|
|
|
@ -118,6 +118,8 @@ ShutdownGame(void)
|
|||
|
||||
gi.FreeTags(TAG_LEVEL);
|
||||
gi.FreeTags(TAG_GAME);
|
||||
SpawnFree();
|
||||
LocalizationFree();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -2220,7 +2220,7 @@ DynamicSpawnInit(void)
|
|||
|
||||
if (ndynamicentities)
|
||||
{
|
||||
dynamicentities = gi.TagMalloc(ndynamicentities * sizeof(*dynamicentities), TAG_GAME);
|
||||
dynamicentities = malloc(ndynamicentities * sizeof(*dynamicentities));
|
||||
memset(dynamicentities, 0, ndynamicentities * sizeof(*dynamicentities));
|
||||
}
|
||||
curr_pos = 0;
|
||||
|
@ -2449,3 +2449,16 @@ SpawnInit(void)
|
|||
StaticSpawnInit();
|
||||
DynamicSpawnInit();
|
||||
}
|
||||
|
||||
void
|
||||
SpawnFree(void)
|
||||
{
|
||||
if (dynamicentities || ndynamicentities)
|
||||
{
|
||||
gi.dprintf("Free %d dynamic definitions\n", ndynamicentities);
|
||||
free(dynamicentities);
|
||||
}
|
||||
|
||||
dynamicentities = NULL;
|
||||
ndynamicentities = 0;
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ LocalizationInit(void)
|
|||
|
||||
if (nlocalmessages)
|
||||
{
|
||||
localmessages = gi.TagMalloc(nlocalmessages * sizeof(*localmessages), TAG_GAME);
|
||||
localmessages = malloc(nlocalmessages * sizeof(*localmessages));
|
||||
memset(localmessages, 0, nlocalmessages * sizeof(*localmessages));
|
||||
}
|
||||
|
||||
|
@ -225,10 +225,10 @@ LocalizationInit(void)
|
|||
*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] = '$';
|
||||
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);
|
||||
/* ReRelease does not have merged sound files to message */
|
||||
localmessages[curr_pos].sound = NULL;
|
||||
|
@ -301,16 +301,16 @@ LocalizationInit(void)
|
|||
currend++;
|
||||
}
|
||||
|
||||
localmessages[curr_pos].key = gi.TagMalloc(6, TAG_GAME);
|
||||
localmessages[curr_pos].key = malloc(6);
|
||||
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);
|
||||
/* Some Heretic message could have no sound effects */
|
||||
localmessages[curr_pos].sound = NULL;
|
||||
if (sign)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
@ -344,6 +344,38 @@ LocalizationInit(void)
|
|||
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
|
||||
LocalizationSearch(const char *name)
|
||||
{
|
||||
|
|
|
@ -1014,6 +1014,7 @@ void EndDMLevel(void);
|
|||
|
||||
/* g_translate.c */
|
||||
void LocalizationInit(void);
|
||||
void LocalizationFree(void);
|
||||
const char* LocalizationMessage(const char *message, int *sound_index);
|
||||
|
||||
/* g_chase.c */
|
||||
|
@ -1100,6 +1101,7 @@ void ED_CallSpawn(edict_t *ent);
|
|||
void DynamicResetSpawnModels(edict_t *self);
|
||||
char *ED_NewString(const char *string, qboolean raw);
|
||||
void SpawnInit(void);
|
||||
void SpawnFree(void);
|
||||
void P_ToggleFlashlight(edict_t *ent, qboolean state);
|
||||
edict_t *CreateFlyMonster(vec3_t origin, vec3_t angles, vec3_t mins,
|
||||
vec3_t maxs, char *classname);
|
||||
|
|
Loading…
Reference in a new issue