- 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:
parent
602ea8f723
commit
3448749de6
10 changed files with 60 additions and 39 deletions
|
|
@ -1281,6 +1281,30 @@ void FWadCollection::ReadLump (int lump, void *dest)
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// W_ReadLump
|
||||
//
|
||||
// Loads the lump into a TArray and returns it.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
TArray<uint8_t> FWadCollection::ReadLumpIntoArray(int lump, int pad)
|
||||
{
|
||||
auto lumpr = OpenLumpReader(lump);
|
||||
auto size = lumpr.GetLength();
|
||||
TArray<uint8_t> data(size + pad);
|
||||
auto numread = lumpr.Read(data.Data(), size);
|
||||
|
||||
if (numread != size)
|
||||
{
|
||||
I_Error("W_ReadLump: only read %ld of %ld on lump %i\n",
|
||||
numread, size, lump);
|
||||
}
|
||||
if (pad > 0) memset(&data[size], 0, pad);
|
||||
return data;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ReadLump - variant 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue