Use hunk allocation for CMod_LoadSurfaces

This commit is contained in:
Denis Pauk 2023-10-10 00:00:27 +03:00
parent 9c55d2fe0f
commit 371fb99c50

View file

@ -87,7 +87,7 @@ typedef struct
cbrushside_t *map_brushsides; cbrushside_t *map_brushsides;
int numbrushsides; int numbrushsides;
mapsurface_t map_surfaces[MAX_MAP_TEXINFO]; mapsurface_t *map_surfaces;
int numtexinfo; int numtexinfo;
/* TODO: big amount code expect static submodels */ /* TODO: big amount code expect static submodels */
@ -1259,7 +1259,8 @@ CMod_LoadSubmodels(const char *name, cmodel_t *map_cmodels, int *numcmodels,
} }
static void static void
CMod_LoadSurfaces(const byte *cmod_base, const lump_t *l) CMod_LoadSurfaces(const char *name, mapsurface_t **map_surfaces, int *numtexinfo,
const byte *cmod_base, const lump_t *l)
{ {
texinfo_t *in; texinfo_t *in;
mapsurface_t *out; mapsurface_t *out;
@ -1279,13 +1280,8 @@ CMod_LoadSurfaces(const byte *cmod_base, const lump_t *l)
Com_Error(ERR_DROP, "%s: Map with no surfaces", __func__); Com_Error(ERR_DROP, "%s: Map with no surfaces", __func__);
} }
if (count > MAX_MAP_TEXINFO) *numtexinfo = count;
{ out = *map_surfaces = Hunk_Alloc(count * sizeof(*out));
Com_Error(ERR_DROP, "%s: Map has too many surfaces", __func__);
}
cmod.numtexinfo = count;
out = cmod.map_surfaces;
for (i = 0; i < count; i++, in++, out++) for (i = 0; i < count; i++, in++, out++)
{ {
@ -1914,13 +1910,14 @@ CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
cmod_base = (byte *)buf; cmod_base = (byte *)buf;
CMod_LoadSurfaces(cmod_base, &header.lumps[LUMP_TEXINFO]);
/* load into heap */ /* load into heap */
strcpy(cmod.name, name); strcpy(cmod.name, name);
int hunkSize = 0; int hunkSize = 0;
hunkSize += Mod_CalcLumpHunkSize(&header.lumps[LUMP_LEAFS],
sizeof(texinfo_t), sizeof(mapsurface_t), 0);
if (header.ident == IDBSPHEADER) if (header.ident == IDBSPHEADER)
{ {
hunkSize += Mod_CalcLumpHunkSize(&header.lumps[LUMP_LEAFS], hunkSize += Mod_CalcLumpHunkSize(&header.lumps[LUMP_LEAFS],
@ -1967,6 +1964,8 @@ CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
cmod.extradata = Hunk_Begin(hunkSize); cmod.extradata = Hunk_Begin(hunkSize);
CMod_LoadSurfaces(cmod.name, &cmod.map_surfaces, &cmod.numtexinfo,
cmod_base, &header.lumps[LUMP_TEXINFO]);
if (header.ident == IDBSPHEADER) if (header.ident == IDBSPHEADER)
{ {
CMod_LoadLeafs(cmod.name, &cmod.map_leafs, &cmod.numleafs, &cmod.emptyleaf, CMod_LoadLeafs(cmod.name, &cmod.map_leafs, &cmod.numleafs, &cmod.emptyleaf,