mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
Reuse previously loaded techniques
This commit is contained in:
parent
99f3f6fe0c
commit
a47370613b
@ -4,6 +4,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
#include "Game/IW4/IW4.h"
|
#include "Game/IW4/IW4.h"
|
||||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||||
@ -12,6 +13,29 @@
|
|||||||
|
|
||||||
using namespace IW4;
|
using namespace IW4;
|
||||||
|
|
||||||
|
namespace IW4
|
||||||
|
{
|
||||||
|
class TechniqueZoneLoadingState final : IZoneAssetLoaderState
|
||||||
|
{
|
||||||
|
std::map<std::string, MaterialTechnique*> m_loaded_techniques;
|
||||||
|
|
||||||
|
public:
|
||||||
|
_NODISCARD MaterialTechnique* FindLoadedTechnique(const std::string& techniqueName) const
|
||||||
|
{
|
||||||
|
const auto loadedTechnique = m_loaded_techniques.find(techniqueName);
|
||||||
|
if (loadedTechnique != m_loaded_techniques.end())
|
||||||
|
return loadedTechnique->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddLoadedTechnique(std::string techniqueName, MaterialTechnique* technique)
|
||||||
|
{
|
||||||
|
m_loaded_techniques.emplace(std::make_pair(std::move(techniqueName), technique));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void* AssetLoaderTechniqueSet::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
void* AssetLoaderTechniqueSet::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||||
{
|
{
|
||||||
auto* techset = memory->Create<MaterialTechniqueSet>();
|
auto* techset = memory->Create<MaterialTechniqueSet>();
|
||||||
@ -34,8 +58,9 @@ std::string AssetLoaderTechniqueSet::GetTechsetFileName(const std::string& techs
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialTechnique* AssetLoaderTechniqueSet::LoadTechniqueWithName(const std::string& techniqueName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager)
|
MaterialTechnique* AssetLoaderTechniqueSet::LoadTechniqueFromRaw(const std::string& techniqueName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager)
|
||||||
{
|
{
|
||||||
|
const auto techniqueFileName = GetTechniqueFileName(techniqueName);
|
||||||
// TODO: Load technique or use previously loaded one
|
// TODO: Load technique or use previously loaded one
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -47,14 +72,21 @@ bool AssetLoaderTechniqueSet::CreateTechsetFromDefinition(const std::string& ass
|
|||||||
memset(techset, 0, sizeof(MaterialTechniqueSet));
|
memset(techset, 0, sizeof(MaterialTechniqueSet));
|
||||||
techset->name = memory->Dup(assetName.c_str());
|
techset->name = memory->Dup(assetName.c_str());
|
||||||
|
|
||||||
|
auto* techniqueZoneLoadingState = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<TechniqueZoneLoadingState>();
|
||||||
for (auto i = 0u; i < std::extent_v<decltype(MaterialTechniqueSet::techniques)>; i++)
|
for (auto i = 0u; i < std::extent_v<decltype(MaterialTechniqueSet::techniques)>; i++)
|
||||||
{
|
{
|
||||||
std::string techniqueName;
|
std::string techniqueName;
|
||||||
if (definition.GetTechniqueByIndex(i, techniqueName))
|
if (definition.GetTechniqueByIndex(i, techniqueName))
|
||||||
{
|
{
|
||||||
auto* technique = LoadTechniqueWithName(techniqueName, searchPath, memory, manager);
|
auto* technique = techniqueZoneLoadingState->FindLoadedTechnique(techniqueName);
|
||||||
|
if (!technique)
|
||||||
|
{
|
||||||
|
technique = LoadTechniqueFromRaw(techniqueName, searchPath, memory, manager);
|
||||||
if (technique == nullptr)
|
if (technique == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
techniqueZoneLoadingState->AddLoadedTechnique(techniqueName, technique);
|
||||||
|
}
|
||||||
|
|
||||||
techset->techniques[i] = technique;
|
techset->techniques[i] = technique;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace IW4
|
|||||||
{
|
{
|
||||||
static std::string GetTechniqueFileName(const std::string& techniqueName);
|
static std::string GetTechniqueFileName(const std::string& techniqueName);
|
||||||
static std::string GetTechsetFileName(const std::string& techsetAssetName);
|
static std::string GetTechsetFileName(const std::string& techsetAssetName);
|
||||||
static MaterialTechnique* LoadTechniqueWithName(const std::string& techniqueName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager);
|
static MaterialTechnique* LoadTechniqueFromRaw(const std::string& techniqueName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager);
|
||||||
static bool CreateTechsetFromDefinition(const std::string& assetName, const techset::TechsetDefinition& definition, ISearchPath* searchPath, MemoryManager* memory,
|
static bool CreateTechsetFromDefinition(const std::string& assetName, const techset::TechsetDefinition& definition, ISearchPath* searchPath, MemoryManager* memory,
|
||||||
IAssetLoadingManager* manager);
|
IAssetLoadingManager* manager);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user