CCollisionLoader: Make LoadAreaCollision() return a unique_ptr

Same behavior, less boilerplate
This commit is contained in:
Lioncash 2020-06-11 20:46:36 -04:00
parent 55eee5da65
commit d0bd7eb292
3 changed files with 7 additions and 6 deletions

View File

@ -621,8 +621,7 @@ void CAreaLoader::LoadSectionDataBuffers()
void CAreaLoader::ReadCollision() void CAreaLoader::ReadCollision()
{ {
mpSectionMgr->ToSection(mCollisionBlockNum); mpSectionMgr->ToSection(mCollisionBlockNum);
CCollisionMeshGroup* pAreaCollision = CCollisionLoader::LoadAreaCollision(*mpMREA); mpArea->mpCollision = CCollisionLoader::LoadAreaCollision(*mpMREA);
mpArea->mpCollision = std::unique_ptr<CCollisionMeshGroup>(pAreaCollision);
} }
void CAreaLoader::ReadPATH() void CAreaLoader::ReadPATH()

View File

@ -189,9 +189,11 @@ void CCollisionLoader::LoadCollisionIndices(IInputStream& File, SCollisionIndexD
} }
// ************ STATIC ************ // ************ STATIC ************
CCollisionMeshGroup* CCollisionLoader::LoadAreaCollision(IInputStream& rMREA) std::unique_ptr<CCollisionMeshGroup> CCollisionLoader::LoadAreaCollision(IInputStream& rMREA)
{ {
if (!rMREA.IsValid()) return nullptr; if (!rMREA.IsValid())
return nullptr;
rMREA.Skip(0x8); // Skipping unknown value + collion section size rMREA.Skip(0x8); // Skipping unknown value + collion section size
// Validate magic // Validate magic
@ -215,7 +217,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadAreaCollision(IInputStream& rMREA)
// Read collision indices and return // Read collision indices and return
Loader.LoadCollisionIndices(rMREA, Loader.mpMesh->mIndexData); Loader.LoadCollisionIndices(rMREA, Loader.mpMesh->mIndexData);
CCollisionMeshGroup* pOut = new CCollisionMeshGroup(); auto pOut = std::make_unique<CCollisionMeshGroup>();
pOut->AddMesh(Loader.mpMesh); pOut->AddMesh(Loader.mpMesh);
return pOut; return pOut;
} }

View File

@ -25,7 +25,7 @@ class CCollisionLoader
void LoadCollisionIndices(IInputStream& File, SCollisionIndexData& OutData); void LoadCollisionIndices(IInputStream& File, SCollisionIndexData& OutData);
public: public:
static CCollisionMeshGroup* LoadAreaCollision(IInputStream& rMREA); static std::unique_ptr<CCollisionMeshGroup> LoadAreaCollision(IInputStream& rMREA);
static std::unique_ptr<CCollisionMeshGroup> LoadDCLN(IInputStream& rDCLN, CResourceEntry *pEntry); static std::unique_ptr<CCollisionMeshGroup> LoadDCLN(IInputStream& rDCLN, CResourceEntry *pEntry);
static EGame GetFormatVersion(uint32 Version); static EGame GetFormatVersion(uint32 Version);
}; };