2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-05 08:17:25 +00:00

refactor: streamline obj compiling asset loading

This commit is contained in:
Jan Laupetin
2025-08-05 18:51:56 +02:00
parent 95a6a028ab
commit 33c09dfe61
31 changed files with 505 additions and 495 deletions

View File

@@ -14,6 +14,7 @@
#include "StateMap/StateMapHandler.h"
#include "Techset/TechniqueFileReader.h"
#include "Techset/TechniqueStateMapCache.h"
#include "Techset/TechsetCommon.h"
#include "Techset/TechsetDefinitionCache.h"
#include <cmath>
@@ -45,9 +46,9 @@ namespace
m_search_path(searchPath),
m_context(context),
m_registration(registration),
m_state_map_cache(context.GetZoneAssetCreationState<techset::TechniqueStateMapCache>()),
m_state_map_cache(context.GetZoneAssetCreationState<::techset::TechniqueStateMapCache>()),
m_base_state_bits{},
m_techset_creator(CreateTechsetLoader(memory, searchPath))
m_techset_creator(IW4::techset::CreateLoader(memory, searchPath))
{
}
@@ -793,7 +794,7 @@ namespace
m_registration.AddDependency(techset);
m_material.techniqueSet = techset->Asset();
auto& definitionCache = m_context.GetZoneAssetCreationState<techset::TechsetDefinitionCache>();
auto& definitionCache = m_context.GetZoneAssetCreationState<::techset::TechsetDefinitionCache>();
bool failure = false;
const auto* techsetDefinition = m_techset_creator->LoadTechsetDefinition(techsetName, m_context, failure);
@@ -806,7 +807,7 @@ namespace
SetTechniqueSetCameraRegion(techsetDefinition);
}
void SetTechniqueSetStateBits(const techset::TechsetDefinition* techsetDefinition)
void SetTechniqueSetStateBits(const ::techset::TechsetDefinition* techsetDefinition)
{
for (auto i = 0; i < TECHNIQUE_COUNT; i++)
{
@@ -854,19 +855,19 @@ namespace
return stateBits;
}
_NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const
[[nodiscard]] const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const
{
const auto* preloadedStateMap = m_state_map_cache.GetStateMapForTechnique(techniqueName);
if (preloadedStateMap)
return preloadedStateMap;
const auto techniqueFileName = GetTechniqueFileName(techniqueName);
const auto techniqueFileName = ::techset::GetFileNameForTechniqueName(techniqueName);
const auto file = m_search_path.Open(techniqueFileName);
if (!file.IsOpen())
return nullptr;
state_map::StateMapFromTechniqueExtractor extractor;
const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor);
const ::techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor);
if (!reader.ReadTechniqueDefinition())
{
m_state_map_cache.SetTechniqueUsesStateMap(techniqueName, nullptr);
@@ -890,7 +891,7 @@ namespace
return outBits;
}
void SetTechniqueSetCameraRegion(const techset::TechsetDefinition* techsetDefinition) const
void SetTechniqueSetCameraRegion(const ::techset::TechsetDefinition* techsetDefinition) const
{
std::string tempName;
if (techsetDefinition->GetTechniqueByIndex(TECHNIQUE_LIT, tempName))
@@ -1316,7 +1317,7 @@ namespace
AssetCreationContext& m_context;
AssetRegistration<AssetMaterial>& m_registration;
techset::TechniqueStateMapCache& m_state_map_cache;
::techset::TechniqueStateMapCache& m_state_map_cache;
std::unordered_map<const state_map::StateMapDefinition*, GfxStateBits> m_state_bits_per_state_map;
GfxStateBits m_base_state_bits;
@@ -1324,7 +1325,7 @@ namespace
std::vector<MaterialTextureDef> m_textures;
std::vector<MaterialConstantDef> m_constants;
std::unique_ptr<ITechsetCreator> m_techset_creator;
std::unique_ptr<::IW4::techset::ICreator> m_techset_creator;
};
class MaterialLoader final : public AssetCreator<AssetMaterial>
@@ -1374,10 +1375,10 @@ namespace
};
} // namespace
namespace IW4
namespace IW4::material
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt)
std::unique_ptr<AssetCreator<AssetMaterial>> CreateCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt)
{
return std::make_unique<MaterialLoader>(memory, searchPath, gdt);
}
} // namespace IW4
} // namespace IW4::material