mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-06 16:57:25 +00:00
chore: refactor IW4 asset loaders
This commit is contained in:
44
src/ObjLoading/Gdt/GdtLookup.cpp
Normal file
44
src/ObjLoading/Gdt/GdtLookup.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "GdtLookup.h"
|
||||
|
||||
void GdtLookup::Initialize(const std::vector<const Gdt*>& gdtFiles)
|
||||
{
|
||||
m_entries_by_gdf_and_by_name.clear();
|
||||
|
||||
for (const auto* gdt : gdtFiles)
|
||||
{
|
||||
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(entry->m_name, entry.get());
|
||||
m_entries_by_gdf_and_by_name.emplace(entry->m_gdf_name, std::move(entryMap));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto entryMapEntry = gdfMapEntry->second.find(entry->m_name);
|
||||
|
||||
if (entryMapEntry == gdfMapEntry->second.end())
|
||||
gdfMapEntry->second.emplace(entry->m_name, entry.get());
|
||||
else
|
||||
entryMapEntry->second = entry.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GdtEntry* GdtLookup::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;
|
||||
}
|
18
src/ObjLoading/Gdt/GdtLookup.h
Normal file
18
src/ObjLoading/Gdt/GdtLookup.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "IGdtQueryable.h"
|
||||
#include "Obj/Gdt/Gdt.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class GdtLookup : public IGdtQueryable
|
||||
{
|
||||
public:
|
||||
void Initialize(const std::vector<const Gdt*>& gdtFiles);
|
||||
GdtEntry* GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, GdtEntry*>> m_entries_by_gdf_and_by_name;
|
||||
};
|
18
src/ObjLoading/Gdt/IGdtQueryable.h
Normal file
18
src/ObjLoading/Gdt/IGdtQueryable.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
};
|
Reference in New Issue
Block a user