chore: refactor pool allocation and add indirect references

This commit is contained in:
Jan
2024-02-06 23:03:40 +01:00
parent 1e5475e5ce
commit ac0d8a83a0
24 changed files with 1001 additions and 1083 deletions

View File

@ -19,17 +19,15 @@ AssetLoadingContext* AssetLoadingManager::GetAssetLoadingContext() const
return &m_context;
}
XAssetInfoGeneric* AssetLoadingManager::AddAsset(const asset_type_t assetType,
const std::string& assetName,
void* asset,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> usedScriptStrings,
Zone* zone)
XAssetInfoGeneric* AssetLoadingManager::AddAssetInternal(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
{
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings), zone);
const auto assetType = xAssetInfo->m_type;
const auto* pAssetName = xAssetInfo->m_name.c_str();
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(std::move(xAssetInfo));
if (m_last_dependency_loaded == nullptr)
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << assetName << "\""
<< std::endl;
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << pAssetName << "\"\n";
return m_last_dependency_loaded;
}
@ -39,11 +37,13 @@ XAssetInfoGeneric* AssetLoadingManager::AddAsset(const asset_type_t assetType,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> usedScriptStrings)
{
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings));
if (m_last_dependency_loaded == nullptr)
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << assetName << "\""
<< std::endl;
return m_last_dependency_loaded;
return AddAsset(std::make_unique<XAssetInfoGeneric>(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings)));
}
XAssetInfoGeneric* AssetLoadingManager::AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
{
xAssetInfo->m_zone = m_context.m_zone;
return AddAssetInternal(std::move(xAssetInfo));
}
XAssetInfoGeneric* AssetLoadingManager::LoadIgnoredDependency(const asset_type_t assetType, const std::string& assetName, IAssetLoader* loader)
@ -64,20 +64,13 @@ XAssetInfoGeneric* AssetLoadingManager::LoadIgnoredDependency(const asset_type_t
auto* existingAsset = loader->LoadFromGlobalAssetPools(assetName);
if (existingAsset)
{
std::vector<XAssetInfoGeneric*> dependencies;
AddAsset(existingAsset->m_type,
existingAsset->m_name,
existingAsset->m_ptr,
std::vector<XAssetInfoGeneric*>(),
std::vector<scr_string_t>(),
existingAsset->m_zone);
AddAssetInternal(std::make_unique<XAssetInfoGeneric>(*existingAsset));
auto* lastDependency = m_last_dependency_loaded;
m_last_dependency_loaded = nullptr;
return lastDependency;
}
std::cout << "Failed to create empty asset \"" << assetName << "\" for type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\""
<< std::endl;
std::cout << "Failed to create empty asset \"" << assetName << "\" for type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\"\n";
return nullptr;
}
@ -119,12 +112,14 @@ XAssetInfoGeneric* AssetLoadingManager::LoadAssetDependency(const asset_type_t a
for (const auto scrString : existingAsset->m_used_script_strings)
m_context.m_zone->m_script_strings.AddOrGetScriptString(existingAsset->m_zone->m_script_strings.CValue(scrString));
AddAsset(existingAsset->m_type,
existingAsset->m_name,
existingAsset->m_ptr,
std::move(dependencies),
existingAsset->m_used_script_strings,
existingAsset->m_zone);
AddAssetInternal(std::make_unique<XAssetInfoGeneric>(existingAsset->m_type,
existingAsset->m_name,
existingAsset->m_ptr,
std::move(dependencies),
existingAsset->m_used_script_strings,
existingAsset->m_indirect_asset_references,
existingAsset->m_zone));
auto* lastDependency = m_last_dependency_loaded;
m_last_dependency_loaded = nullptr;
return lastDependency;

View File

@ -14,12 +14,7 @@ class AssetLoadingManager final : public IAssetLoadingManager
XAssetInfoGeneric* LoadIgnoredDependency(asset_type_t assetType, const std::string& assetName, IAssetLoader* loader);
XAssetInfoGeneric* LoadAssetDependency(asset_type_t assetType, const std::string& assetName, IAssetLoader* loader);
XAssetInfoGeneric* AddAsset(asset_type_t assetType,
const std::string& assetName,
void* asset,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> usedScriptStrings,
Zone* zone);
XAssetInfoGeneric* AddAssetInternal(std::unique_ptr<XAssetInfoGeneric> xAssetInfo);
public:
AssetLoadingManager(const std::map<asset_type_t, std::unique_ptr<IAssetLoader>>& assetLoadersByType, AssetLoadingContext& context);
@ -33,5 +28,6 @@ public:
void* asset,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> usedScriptStrings) override;
XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
};

View File

@ -23,6 +23,7 @@ public:
void* asset,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> usedScriptStrings) = 0;
virtual XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) = 0;
XAssetInfoGeneric* AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset)
{