- replaced a few temporary allocations with TArray and added a few convenience loader functions for this.

Amazingly with today's optimizers this creates code which is just as good as doing it all manually with the added benefit of being safer.
This commit is contained in:
Christoph Oelckers 2018-11-10 11:56:18 +01:00
commit 3448749de6
10 changed files with 60 additions and 39 deletions

View file

@ -1691,15 +1691,10 @@ uint16_t MakeSkill(int flags)
void P_LoadThings (MapData * map)
{
int lumplen = map->Size(ML_THINGS);
int numthings = lumplen / sizeof(mapthing_t);
char *mtp;
mapthing_t *mt;
mtp = new char[lumplen];
map->Read(ML_THINGS, mtp);
mt = (mapthing_t*)mtp;
auto mtp = map->Read(ML_THINGS);
int numthings = mtp.Size() / sizeof(mapthing_t);
mt = (mapthing_t*)mtp.Data();
MapThingsConverted.Resize(numthings);
FMapThing *mti = &MapThingsConverted[0];
@ -1767,7 +1762,6 @@ void P_LoadThings (MapData * map)
if (flags & BTF_NOTSINGLE) mti[i].flags &= ~MTF_SINGLE;
}
}
delete [] mtp;
}
//===========================================================================
@ -2109,29 +2103,24 @@ void P_LoadLineDefs (MapData * map)
{
int i, skipped;
line_t *ld;
int lumplen = map->Size(ML_LINEDEFS);
char * mldf;
maplinedef_t *mld;
int numlines = lumplen / sizeof(maplinedef_t);
auto mldf = map->Read(ML_LINEDEFS);
int numlines = mldf.Size() / sizeof(maplinedef_t);
linemap.Resize(numlines);
mldf = new char[lumplen];
map->Read(ML_LINEDEFS, mldf);
// [RH] Count the number of sidedef references. This is the number of
// sidedefs we need. The actual number in the SIDEDEFS lump might be less.
// Lines with 0 length are also removed.
for (skipped = sidecount = i = 0; i < numlines; )
{
mld = ((maplinedef_t*)mldf) + i;
mld = ((maplinedef_t*)mldf.Data()) + i;
unsigned v1 = LittleShort(mld->v1);
unsigned v2 = LittleShort(mld->v2);
if (v1 >= level.vertexes.Size() || v2 >= level.vertexes.Size())
{
delete [] mldf;
I_Error ("Line %d has invalid vertices: %d and/or %d.\nThe map only contains %u vertices.", i+skipped, v1, v2, level.vertexes.Size());
}
else if (v1 == v2 ||
@ -2164,7 +2153,7 @@ void P_LoadLineDefs (MapData * map)
P_AllocateSideDefs (map, sidecount);
mld = (maplinedef_t *)mldf;
mld = (maplinedef_t *)mldf.Data();
ld = &level.lines[0];
for (i = 0; i < numlines; i++, mld++, ld++)
{
@ -2203,7 +2192,6 @@ void P_LoadLineDefs (MapData * map)
if (level.flags2 & LEVEL2_WRAPMIDTEX) ld->flags |= ML_WRAP_MIDTEX;
if (level.flags2 & LEVEL2_CHECKSWITCHRANGE) ld->flags |= ML_CHECKSWITCHRANGE;
}
delete[] mldf;
}
//===========================================================================