CCollisionMeshGroup: Make use of unique_ptr
This commit is contained in:
parent
48d8d361b6
commit
a51604ca91
|
@ -5,42 +5,38 @@
|
||||||
#include "Core/Resource/CResource.h"
|
#include "Core/Resource/CResource.h"
|
||||||
#include "Core/Resource/TResPtr.h"
|
#include "Core/Resource/TResPtr.h"
|
||||||
#include <Common/Math/CTransform4f.h>
|
#include <Common/Math/CTransform4f.h>
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class CCollisionMeshGroup : public CResource
|
class CCollisionMeshGroup : public CResource
|
||||||
{
|
{
|
||||||
DECLARE_RESOURCE_TYPE(DynamicCollision)
|
DECLARE_RESOURCE_TYPE(DynamicCollision)
|
||||||
std::vector<CCollisionMesh*> mMeshes;
|
std::vector<std::unique_ptr<CCollisionMesh>> mMeshes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CCollisionMeshGroup(CResourceEntry *pEntry = 0) : CResource(pEntry) {}
|
explicit CCollisionMeshGroup(CResourceEntry *pEntry = nullptr) : CResource(pEntry) {}
|
||||||
|
~CCollisionMeshGroup() = default;
|
||||||
|
|
||||||
~CCollisionMeshGroup()
|
uint32 NumMeshes() const { return mMeshes.size(); }
|
||||||
{
|
CCollisionMesh* MeshByIndex(uint32 Index) const { return mMeshes[Index].get(); }
|
||||||
for (auto it = mMeshes.begin(); it != mMeshes.end(); it++)
|
void AddMesh(std::unique_ptr<CCollisionMesh>&& pMesh) { mMeshes.push_back(std::move(pMesh)); }
|
||||||
delete *it;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 NumMeshes() const { return mMeshes.size(); }
|
|
||||||
CCollisionMesh* MeshByIndex(uint32 Index) const { return mMeshes[Index]; }
|
|
||||||
void AddMesh(CCollisionMesh *pMesh) { mMeshes.push_back(pMesh); }
|
|
||||||
|
|
||||||
void BuildRenderData()
|
void BuildRenderData()
|
||||||
{
|
{
|
||||||
for (auto It = mMeshes.begin(); It != mMeshes.end(); It++)
|
for (auto& mesh : mMeshes)
|
||||||
(*It)->BuildRenderData();
|
mesh->BuildRenderData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw()
|
void Draw()
|
||||||
{
|
{
|
||||||
for (auto it = mMeshes.begin(); it != mMeshes.end(); it++)
|
for (auto& mesh : mMeshes)
|
||||||
(*it)->GetRenderData().Render(false);
|
mesh->GetRenderData().Render(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawWireframe()
|
void DrawWireframe()
|
||||||
{
|
{
|
||||||
for (auto it = mMeshes.begin(); it != mMeshes.end(); it++)
|
for (auto& mesh : mMeshes)
|
||||||
(*it)->GetRenderData().Render(true);
|
mesh->GetRenderData().Render(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -204,9 +204,11 @@ std::unique_ptr<CCollisionMeshGroup> CCollisionLoader::LoadAreaCollision(IInputS
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto mesh = std::make_unique<CCollisionMesh>();
|
||||||
|
|
||||||
CCollisionLoader Loader;
|
CCollisionLoader Loader;
|
||||||
Loader.mVersion = GetFormatVersion(rMREA.ReadLong());
|
Loader.mVersion = GetFormatVersion(rMREA.ReadLong());
|
||||||
Loader.mpMesh = new CCollisionMesh;
|
Loader.mpMesh = mesh.get();
|
||||||
|
|
||||||
// Octree - structure is known, but not coding this right now
|
// Octree - structure is known, but not coding this right now
|
||||||
Loader.mpMesh->mAABox = CAABox(rMREA);
|
Loader.mpMesh->mAABox = CAABox(rMREA);
|
||||||
|
@ -218,7 +220,7 @@ std::unique_ptr<CCollisionMeshGroup> CCollisionLoader::LoadAreaCollision(IInputS
|
||||||
Loader.LoadCollisionIndices(rMREA, Loader.mpMesh->mIndexData);
|
Loader.LoadCollisionIndices(rMREA, Loader.mpMesh->mIndexData);
|
||||||
|
|
||||||
auto pOut = std::make_unique<CCollisionMeshGroup>();
|
auto pOut = std::make_unique<CCollisionMeshGroup>();
|
||||||
pOut->AddMesh(Loader.mpMesh);
|
pOut->AddMesh(std::move(mesh));
|
||||||
return pOut;
|
return pOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,9 +245,9 @@ std::unique_ptr<CCollisionMeshGroup> CCollisionLoader::LoadDCLN(IInputStream& rD
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto mesh = std::make_unique<CCollidableOBBTree>();
|
||||||
Loader.mVersion = GetFormatVersion(rDCLN.ReadLong());
|
Loader.mVersion = GetFormatVersion(rDCLN.ReadLong());
|
||||||
|
Loader.mpMesh = mesh.get();
|
||||||
Loader.mpMesh = new CCollidableOBBTree;
|
|
||||||
|
|
||||||
if (Loader.mVersion == EGame::DKCReturns)
|
if (Loader.mVersion == EGame::DKCReturns)
|
||||||
Loader.mpMesh->mAABox = CAABox(rDCLN);
|
Loader.mpMesh->mAABox = CAABox(rDCLN);
|
||||||
|
@ -253,7 +255,7 @@ std::unique_ptr<CCollisionMeshGroup> CCollisionLoader::LoadDCLN(IInputStream& rD
|
||||||
// Read indices and return
|
// Read indices and return
|
||||||
rDCLN.Seek(0x4, SEEK_CUR);
|
rDCLN.Seek(0x4, SEEK_CUR);
|
||||||
Loader.LoadCollisionIndices(rDCLN, Loader.mpMesh->mIndexData);
|
Loader.LoadCollisionIndices(rDCLN, Loader.mpMesh->mIndexData);
|
||||||
Loader.mpGroup->AddMesh(Loader.mpMesh);
|
Loader.mpGroup->AddMesh(std::move(mesh));
|
||||||
|
|
||||||
// Build bounding box
|
// Build bounding box
|
||||||
if (Loader.mVersion != EGame::DKCReturns)
|
if (Loader.mVersion != EGame::DKCReturns)
|
||||||
|
|
Loading…
Reference in New Issue