mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Fix unlinking every single asset in the global asset pools on unloading a zone
This commit is contained in:
parent
4abb846ccd
commit
1a36912b44
@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "AssetPool.h"
|
#include "AssetPool.h"
|
||||||
|
|
||||||
@ -24,12 +25,12 @@ class GlobalAssetPool
|
|||||||
LinkedAssetPool* m_asset_pool;
|
LinkedAssetPool* m_asset_pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<LinkedAssetPool*> m_linked_asset_pools;
|
static std::vector<std::unique_ptr<LinkedAssetPool>> m_linked_asset_pools;
|
||||||
static std::unordered_map<std::string, GameAssetPoolEntry> m_assets;
|
static std::unordered_map<std::string, GameAssetPoolEntry> m_assets;
|
||||||
|
|
||||||
static void SortLinkedAssetPools()
|
static void SortLinkedAssetPools()
|
||||||
{
|
{
|
||||||
std::sort(m_linked_asset_pools.begin(), m_linked_asset_pools.end(), [](const LinkedAssetPool* a, const LinkedAssetPool* b) -> bool
|
std::sort(m_linked_asset_pools.begin(), m_linked_asset_pools.end(), [](const std::unique_ptr<LinkedAssetPool>& a, const std::unique_ptr<LinkedAssetPool>& b) -> bool
|
||||||
{
|
{
|
||||||
return a->m_priority < b->m_priority;
|
return a->m_priority < b->m_priority;
|
||||||
});
|
});
|
||||||
@ -39,7 +40,7 @@ class GlobalAssetPool
|
|||||||
{
|
{
|
||||||
int occurrences = 0;
|
int occurrences = 0;
|
||||||
|
|
||||||
for(auto linkedAssetPool : m_linked_asset_pools)
|
for (const auto& linkedAssetPool : m_linked_asset_pools)
|
||||||
{
|
{
|
||||||
XAssetInfo<T>* foundAsset = linkedAssetPool->m_asset_pool->GetAsset(assetEntry.m_asset->m_name);
|
XAssetInfo<T>* foundAsset = linkedAssetPool->m_asset_pool->GetAsset(assetEntry.m_asset->m_name);
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class GlobalAssetPool
|
|||||||
{
|
{
|
||||||
assetEntry.m_asset = foundAsset;
|
assetEntry.m_asset = foundAsset;
|
||||||
assetEntry.m_duplicate = false;
|
assetEntry.m_duplicate = false;
|
||||||
assetEntry.m_asset_pool = linkedAssetPool;
|
assetEntry.m_asset_pool = linkedAssetPool.get();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -94,16 +95,17 @@ class GlobalAssetPool
|
|||||||
public:
|
public:
|
||||||
static void LinkAssetPool(AssetPool<T>* assetPool, const int priority)
|
static void LinkAssetPool(AssetPool<T>* assetPool, const int priority)
|
||||||
{
|
{
|
||||||
auto* newLink = new LinkedAssetPool();
|
auto newLink = std::make_unique<LinkedAssetPool>();
|
||||||
newLink->m_asset_pool = assetPool;
|
newLink->m_asset_pool = assetPool;
|
||||||
newLink->m_priority = priority;
|
newLink->m_priority = priority;
|
||||||
|
|
||||||
m_linked_asset_pools.push_back(newLink);
|
auto* newLinkPtr = newLink.get();
|
||||||
|
m_linked_asset_pools.emplace_back(std::move(newLink));
|
||||||
SortLinkedAssetPools();
|
SortLinkedAssetPools();
|
||||||
|
|
||||||
for (auto asset : *assetPool)
|
for (auto asset : *assetPool)
|
||||||
{
|
{
|
||||||
LinkAsset(newLink, asset);
|
LinkAsset(newLinkPtr, asset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +113,11 @@ public:
|
|||||||
{
|
{
|
||||||
LinkedAssetPool* link = nullptr;
|
LinkedAssetPool* link = nullptr;
|
||||||
|
|
||||||
for(auto existingLink : m_linked_asset_pools)
|
for (const auto& existingLink : m_linked_asset_pools)
|
||||||
{
|
{
|
||||||
if (existingLink->m_asset_pool == assetPool)
|
if (existingLink->m_asset_pool == assetPool)
|
||||||
{
|
{
|
||||||
link = existingLink;
|
link = existingLink.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +135,7 @@ public:
|
|||||||
|
|
||||||
for (; iLinkEntry != m_linked_asset_pools.end(); ++iLinkEntry)
|
for (; iLinkEntry != m_linked_asset_pools.end(); ++iLinkEntry)
|
||||||
{
|
{
|
||||||
LinkedAssetPool* linkEntry = *iLinkEntry;
|
LinkedAssetPool* linkEntry = iLinkEntry->get();
|
||||||
if (linkEntry->m_asset_pool == assetPool)
|
if (linkEntry->m_asset_pool == assetPool)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -144,12 +146,19 @@ public:
|
|||||||
if (iLinkEntry == m_linked_asset_pools.end())
|
if (iLinkEntry == m_linked_asset_pools.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto assetPoolToUnlink = std::move(*iLinkEntry);
|
||||||
m_linked_asset_pools.erase(iLinkEntry);
|
m_linked_asset_pools.erase(iLinkEntry);
|
||||||
|
|
||||||
for (auto iAssetEntry = m_assets.begin(); iAssetEntry != m_assets.end();)
|
for (auto iAssetEntry = m_assets.begin(); iAssetEntry != m_assets.end();)
|
||||||
{
|
{
|
||||||
auto& assetEntry = *iAssetEntry;
|
auto& assetEntry = *iAssetEntry;
|
||||||
|
|
||||||
|
if (assetEntry.second.m_asset_pool != assetPoolToUnlink.get())
|
||||||
|
{
|
||||||
|
++iAssetEntry;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (assetEntry.second.m_duplicate && ReplaceAssetPoolEntry(assetEntry.second))
|
if (assetEntry.second.m_duplicate && ReplaceAssetPoolEntry(assetEntry.second))
|
||||||
{
|
{
|
||||||
++iAssetEntry;
|
++iAssetEntry;
|
||||||
@ -171,7 +180,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::vector<typename GlobalAssetPool<T>::LinkedAssetPool*> GlobalAssetPool<T>::m_linked_asset_pools = std::vector<LinkedAssetPool*>();
|
std::vector<std::unique_ptr<typename GlobalAssetPool<T>::LinkedAssetPool>> GlobalAssetPool<T>::m_linked_asset_pools = std::vector<std::unique_ptr<LinkedAssetPool>>();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::unordered_map<std::string, typename GlobalAssetPool<T>::GameAssetPoolEntry> GlobalAssetPool<T>::m_assets = std::unordered_map<std::string, GameAssetPoolEntry>();
|
std::unordered_map<std::string, typename GlobalAssetPool<T>::GameAssetPoolEntry> GlobalAssetPool<T>::m_assets = std::unordered_map<std::string, GameAssetPoolEntry>();
|
Loading…
x
Reference in New Issue
Block a user