chore: refactor IW4 asset loaders

This commit is contained in:
Jan
2024-12-25 21:39:05 +01:00
parent f9456101e6
commit 7ef944ebd4
139 changed files with 2370 additions and 2965 deletions

View File

@ -2,49 +2,6 @@
AssetLoadingContext::AssetLoadingContext(Zone& zone, ISearchPath& rawSearchPath, std::vector<Gdt*> gdtFiles)
: m_zone(zone),
m_raw_search_path(rawSearchPath),
m_gdt_files(std::move(gdtFiles))
m_raw_search_path(rawSearchPath)
{
BuildGdtEntryCache();
}
void AssetLoadingContext::BuildGdtEntryCache()
{
for (const auto* gdt : m_gdt_files)
{
for (const auto& entry : gdt->m_entries)
{
auto gdfMapEntry = m_entries_by_gdf_and_by_name.find(entry->m_gdf_name);
if (gdfMapEntry == m_entries_by_gdf_and_by_name.end())
{
std::unordered_map<std::string, GdtEntry*> entryMap;
entryMap.emplace(std::make_pair(entry->m_name, entry.get()));
m_entries_by_gdf_and_by_name.emplace(std::make_pair(entry->m_gdf_name, std::move(entryMap)));
}
else
{
auto entryMapEntry = gdfMapEntry->second.find(entry->m_name);
if (entryMapEntry == gdfMapEntry->second.end())
gdfMapEntry->second.emplace(std::make_pair(entry->m_name, entry.get()));
else
entryMapEntry->second = entry.get();
}
}
}
}
GdtEntry* AssetLoadingContext::GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName)
{
const auto foundGdtMap = m_entries_by_gdf_and_by_name.find(gdfName);
if (foundGdtMap == m_entries_by_gdf_and_by_name.end())
return nullptr;
const auto foundGdtEntry = foundGdtMap->second.find(entryName);
if (foundGdtEntry == foundGdtMap->second.end())
return nullptr;
return foundGdtEntry->second;
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "IGdtQueryable.h"
#include "Gdt/IGdtQueryable.h"
#include "IZoneAssetLoaderState.h"
#include "Obj/Gdt/Gdt.h"
#include "SearchPath/ISearchPath.h"
@ -32,15 +32,10 @@ public:
return newStatePtr;
}
private:
void BuildGdtEntryCache();
public:
Zone& m_zone;
ISearchPath& m_raw_search_path;
const std::vector<Gdt*> m_gdt_files;
std::unordered_map<std::string, asset_type_t> m_ignored_asset_map;
std::unordered_map<std::string, std::unordered_map<std::string, GdtEntry*>> m_entries_by_gdf_and_by_name;
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
};

View File

@ -1,6 +1,7 @@
#pragma once
#include "Gdt/IGdtQueryable.h"
#include "IAssetLoadingManager.h"
#include "IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/ClassUtils.h"
#include "Zone/ZoneTypes.h"

View File

@ -1,17 +0,0 @@
#pragma once
#include "Obj/Gdt/GdtEntry.h"
#include <string>
class IGdtQueryable
{
public:
IGdtQueryable() = default;
virtual ~IGdtQueryable() = default;
IGdtQueryable(const IGdtQueryable& other) = default;
IGdtQueryable(IGdtQueryable&& other) noexcept = default;
IGdtQueryable& operator=(const IGdtQueryable& other) = default;
IGdtQueryable& operator=(IGdtQueryable&& other) noexcept = default;
virtual GdtEntry* GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) = 0;
};