Move statemap for technique loading to AssetLoaderTechniqueSet

This commit is contained in:
Jan 2022-09-24 15:35:12 +02:00
parent d11f8122f3
commit 63f636d401
3 changed files with 33 additions and 30 deletions

View File

@ -883,7 +883,7 @@ namespace IW4
GfxStateBits GetStateBitsForTechnique(const std::string& techniqueName) GfxStateBits GetStateBitsForTechnique(const std::string& techniqueName)
{ {
const auto* stateMap = GetStateMapForTechnique(techniqueName); const auto* stateMap = AssetLoaderTechniqueSet::GetStateMapForTechnique(techniqueName, m_search_path, m_state_map_cache);
if (!stateMap) if (!stateMap)
return m_base_state_bits; return m_base_state_bits;
@ -897,35 +897,6 @@ namespace IW4
return stateBits; return stateBits;
} }
_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 = AssetLoaderTechniqueSet::GetTechniqueFileName(techniqueName);
const auto file = m_search_path->Open(techniqueFileName);
if (!file.IsOpen())
{
std::cerr << "Failed to find file for technique \"" << techniqueName << "\"\n";
return nullptr;
}
state_map::StateMapFromTechniqueExtractor extractor;
const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor);
if (!reader.ReadTechniqueDefinition())
{
m_state_map_cache->SetTechniqueUsesStateMap(techniqueName, nullptr);
return nullptr;
}
const auto stateMapName = extractor.RetrieveStateMap();
const auto* loadedStateMap = AssetLoaderTechniqueSet::LoadStateMapDefinition(stateMapName, m_search_path, m_state_map_cache);
m_state_map_cache->SetTechniqueUsesStateMap(techniqueName, loadedStateMap);
return loadedStateMap;
}
GfxStateBits CalculateStateBitsWithStateMap(const state_map::StateMapDefinition* stateMap) const GfxStateBits CalculateStateBitsWithStateMap(const state_map::StateMapDefinition* stateMap) const
{ {
const state_map::StateMapHandler stateMapHandler(stateMapLayout, *stateMap); const state_map::StateMapHandler stateMapHandler(stateMapLayout, *stateMap);

View File

@ -17,6 +17,7 @@
#include "Techset/TechniqueFileReader.h" #include "Techset/TechniqueFileReader.h"
#include "Techset/TechsetFileReader.h" #include "Techset/TechsetFileReader.h"
#include "Shader/D3D9ShaderAnalyser.h" #include "Shader/D3D9ShaderAnalyser.h"
#include "StateMap/StateMapFromTechniqueExtractor.h"
#include "StateMap/StateMapReader.h" #include "StateMap/StateMapReader.h"
#include "Techset/TechniqueStateMapCache.h" #include "Techset/TechniqueStateMapCache.h"
#include "Techset/TechsetDefinitionCache.h" #include "Techset/TechsetDefinitionCache.h"
@ -1293,6 +1294,35 @@ bool AssetLoaderTechniqueSet::CreateTechsetFromDefinition(const std::string& ass
return true; return true;
} }
const state_map::StateMapDefinition* AssetLoaderTechniqueSet::GetStateMapForTechnique(const std::string& techniqueName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache)
{
const auto* preloadedStateMap = stateMapCache->GetStateMapForTechnique(techniqueName);
if (preloadedStateMap)
return preloadedStateMap;
const auto techniqueFileName = GetTechniqueFileName(techniqueName);
const auto file = searchPath->Open(techniqueFileName);
if (!file.IsOpen())
{
std::cerr << "Failed to find file for technique \"" << techniqueName << "\"\n";
return nullptr;
}
state_map::StateMapFromTechniqueExtractor extractor;
const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor);
if (!reader.ReadTechniqueDefinition())
{
stateMapCache->SetTechniqueUsesStateMap(techniqueName, nullptr);
return nullptr;
}
const auto stateMapName = extractor.RetrieveStateMap();
const auto* loadedStateMap = LoadStateMapDefinition(stateMapName, searchPath, stateMapCache);
stateMapCache->SetTechniqueUsesStateMap(techniqueName, loadedStateMap);
return loadedStateMap;
}
techset::TechsetDefinition* AssetLoaderTechniqueSet::LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache) techset::TechsetDefinition* AssetLoaderTechniqueSet::LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache)
{ {
auto* cachedTechsetDefinition = definitionCache->GetCachedTechsetDefinition(assetName); auto* cachedTechsetDefinition = definitionCache->GetCachedTechsetDefinition(assetName);

View File

@ -20,6 +20,8 @@ namespace IW4
static std::string GetTechniqueFileName(const std::string& techniqueName); static std::string GetTechniqueFileName(const std::string& techniqueName);
static std::string GetStateMapFileName(const std::string& stateMapName); static std::string GetStateMapFileName(const std::string& stateMapName);
static const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache);
static techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache); static techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache);
static const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache); static const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache);