Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions src/Core/Resource/CPoiToWorld.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
#include "CPoiToWorld.h"

#include <algorithm>

CPoiToWorld::CPoiToWorld(CResourceEntry *pEntry /*= 0*/)
: CResource(pEntry)
{
}

CPoiToWorld::~CPoiToWorld()
{
for (auto it = mMaps.begin(); it != mMaps.end(); it++)
delete *it;
}
CPoiToWorld::~CPoiToWorld() = default;

void CPoiToWorld::AddPoi(uint32 PoiID)
{
// Check if this POI already exists
auto it = mPoiLookupMap.find(PoiID);

if (it == mPoiLookupMap.end())
const auto it = mPoiLookupMap.find(PoiID);
if (it != mPoiLookupMap.cend())
{
SPoiMap *pMap = new SPoiMap();
pMap->PoiID = PoiID;

mMaps.push_back(pMap);
mPoiLookupMap[PoiID] = pMap;
return;
}

auto pMap = std::make_unique<SPoiMap>();
pMap->PoiID = PoiID;

mPoiLookupMap.insert_or_assign(PoiID, pMap.get());
mMaps.push_back(std::move(pMap));
}

void CPoiToWorld::AddPoiMeshMap(uint32 PoiID, uint32 ModelID)
Expand All @@ -33,10 +32,11 @@ void CPoiToWorld::AddPoiMeshMap(uint32 PoiID, uint32 ModelID)
SPoiMap *pMap = mPoiLookupMap[PoiID];

// Check whether this model ID is already mapped to this POI
for (auto it = pMap->ModelIDs.begin(); it != pMap->ModelIDs.end(); it++)
const bool exists = std::any_of(pMap->ModelIDs.cbegin(), pMap->ModelIDs.cend(),
[ModelID](const auto ID) { return ID == ModelID; });
if (exists)
{
if (*it == ModelID)
return;
return;
}

// We didn't return, so this is a new mapping
Expand All @@ -45,7 +45,7 @@ void CPoiToWorld::AddPoiMeshMap(uint32 PoiID, uint32 ModelID)

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)
{
Expand All @@ -58,19 +58,19 @@ void CPoiToWorld::RemovePoi(uint32 PoiID)

void CPoiToWorld::RemovePoiMeshMap(uint32 PoiID, uint32 ModelID)
{
auto MapIt = mPoiLookupMap.find(PoiID);

if (MapIt != mPoiLookupMap.end())
const auto MapIt = mPoiLookupMap.find(PoiID);
if (MapIt == mPoiLookupMap.end())
{
SPoiMap *pMap = MapIt->second;
return;
}

for (auto ListIt = pMap->ModelIDs.begin(); ListIt != pMap->ModelIDs.end(); ListIt++)
SPoiMap *pMap = MapIt->second;
for (auto ListIt = pMap->ModelIDs.begin(); ListIt != pMap->ModelIDs.end(); ++ListIt)
{
if (*ListIt == ModelID)
{
if (*ListIt == ModelID)
{
pMap->ModelIDs.erase(ListIt);
break;
}
pMap->ModelIDs.erase(ListIt);
break;
}
}
}
15 changes: 8 additions & 7 deletions src/Core/Resource/CPoiToWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CResource.h"
#include <list>
#include <map>
#include <memory>
#include <vector>

class CPoiToWorld : public CResource
Expand All @@ -18,29 +19,29 @@ class CPoiToWorld : public CResource
};

private:
std::vector<SPoiMap*> mMaps;
std::vector<std::unique_ptr<SPoiMap>> mMaps;
std::map<uint32,SPoiMap*> mPoiLookupMap;

public:
CPoiToWorld(CResourceEntry *pEntry = 0);
~CPoiToWorld();
explicit CPoiToWorld(CResourceEntry *pEntry = nullptr);
~CPoiToWorld() override;

void AddPoi(uint32 PoiID);
void AddPoiMeshMap(uint32 PoiID, uint32 ModelID);
void RemovePoi(uint32 PoiID);
void RemovePoiMeshMap(uint32 PoiID, uint32 ModelID);

inline uint32 NumMappedPOIs() const
uint32 NumMappedPOIs() const
{
return mMaps.size();
}

inline const SPoiMap* MapByIndex(uint32 Index) const
const SPoiMap* MapByIndex(uint32 Index) const
{
return mMaps[Index];
return mMaps[Index].get();
}

inline const SPoiMap* MapByID(uint32 InstanceID) const
const SPoiMap* MapByID(uint32 InstanceID) const
{
auto it = mPoiLookupMap.find(InstanceID);

Expand Down