mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-07-04 12:15:58 +00:00
CPoiToWorld: Make use of unique_ptr
Safer memory management.
This commit is contained in:
parent
df29cc2109
commit
a6caff1387
@ -1,29 +1,25 @@
|
|||||||
#include "CPoiToWorld.h"
|
#include "CPoiToWorld.h"
|
||||||
|
|
||||||
CPoiToWorld::CPoiToWorld(CResourceEntry *pEntry /*= 0*/)
|
CPoiToWorld::CPoiToWorld(CResourceEntry *pEntry)
|
||||||
: CResource(pEntry)
|
: CResource(pEntry)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CPoiToWorld::~CPoiToWorld()
|
CPoiToWorld::~CPoiToWorld() = default;
|
||||||
{
|
|
||||||
for (auto it = mMaps.begin(); it != mMaps.end(); it++)
|
|
||||||
delete *it;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPoiToWorld::AddPoi(uint32 PoiID)
|
void CPoiToWorld::AddPoi(uint32 PoiID)
|
||||||
{
|
{
|
||||||
// Check if this POI already exists
|
// Check if this POI already exists
|
||||||
auto it = mPoiLookupMap.find(PoiID);
|
const auto it = mPoiLookupMap.find(PoiID);
|
||||||
|
|
||||||
if (it == mPoiLookupMap.end())
|
if (it != mPoiLookupMap.end())
|
||||||
{
|
return;
|
||||||
SPoiMap *pMap = new SPoiMap();
|
|
||||||
|
auto pMap = std::make_unique<SPoiMap>();
|
||||||
pMap->PoiID = PoiID;
|
pMap->PoiID = PoiID;
|
||||||
|
|
||||||
mMaps.push_back(pMap);
|
auto* ptr = mMaps.emplace_back(std::move(pMap)).get();
|
||||||
mPoiLookupMap[PoiID] = pMap;
|
mPoiLookupMap.insert_or_assign(PoiID, ptr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPoiToWorld::AddPoiMeshMap(uint32 PoiID, uint32 ModelID)
|
void CPoiToWorld::AddPoiMeshMap(uint32 PoiID, uint32 ModelID)
|
||||||
@ -45,7 +41,7 @@ void CPoiToWorld::AddPoiMeshMap(uint32 PoiID, uint32 ModelID)
|
|||||||
|
|
||||||
void CPoiToWorld::RemovePoi(uint32 PoiID)
|
void CPoiToWorld::RemovePoi(uint32 PoiID)
|
||||||
{
|
{
|
||||||
for (auto it = mMaps.begin(); it != mMaps.end(); it++)
|
for (auto it = mMaps.begin(); it != mMaps.end(); ++it)
|
||||||
{
|
{
|
||||||
if ((*it)->PoiID == PoiID)
|
if ((*it)->PoiID == PoiID)
|
||||||
{
|
{
|
||||||
@ -58,13 +54,14 @@ void CPoiToWorld::RemovePoi(uint32 PoiID)
|
|||||||
|
|
||||||
void CPoiToWorld::RemovePoiMeshMap(uint32 PoiID, uint32 ModelID)
|
void CPoiToWorld::RemovePoiMeshMap(uint32 PoiID, uint32 ModelID)
|
||||||
{
|
{
|
||||||
auto MapIt = mPoiLookupMap.find(PoiID);
|
const auto MapIt = mPoiLookupMap.find(PoiID);
|
||||||
|
|
||||||
|
if (MapIt == mPoiLookupMap.end())
|
||||||
|
return;
|
||||||
|
|
||||||
if (MapIt != mPoiLookupMap.end())
|
|
||||||
{
|
|
||||||
SPoiMap *pMap = MapIt->second;
|
SPoiMap *pMap = MapIt->second;
|
||||||
|
|
||||||
for (auto ListIt = pMap->ModelIDs.begin(); ListIt != pMap->ModelIDs.end(); ListIt++)
|
for (auto ListIt = pMap->ModelIDs.begin(); ListIt != pMap->ModelIDs.end(); ++ListIt)
|
||||||
{
|
{
|
||||||
if (*ListIt == ModelID)
|
if (*ListIt == ModelID)
|
||||||
{
|
{
|
||||||
@ -73,4 +70,3 @@ void CPoiToWorld::RemovePoiMeshMap(uint32 PoiID, uint32 ModelID)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "CResource.h"
|
#include "CResource.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class CPoiToWorld : public CResource
|
class CPoiToWorld : public CResource
|
||||||
@ -18,7 +19,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<SPoiMap*> mMaps;
|
std::vector<std::unique_ptr<SPoiMap>> mMaps;
|
||||||
std::map<uint32,SPoiMap*> mPoiLookupMap;
|
std::map<uint32,SPoiMap*> mPoiLookupMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -37,7 +38,7 @@ public:
|
|||||||
|
|
||||||
const SPoiMap* MapByIndex(size_t Index) const
|
const SPoiMap* MapByIndex(size_t Index) const
|
||||||
{
|
{
|
||||||
return mMaps[Index];
|
return mMaps[Index].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SPoiMap* MapByID(uint32 InstanceID) const
|
const SPoiMap* MapByID(uint32 InstanceID) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user