2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-05-17 07:21:43 +00:00

refactor: streamline T6 asset loading

This commit is contained in:
Jan Laupetin
2025-08-04 23:48:30 +02:00
parent 472e59991f
commit a5024d40b0
59 changed files with 380 additions and 383 deletions
@@ -40,15 +40,14 @@ namespace
private:
IGdtQueryable& m_gdt;
InfoStringLoaderPhysConstraints m_info_string_loader;
T6::phys_constraints::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::phys_constraints
{
std::unique_ptr<AssetCreator<AssetPhysConstraints>>
CreateGdtPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
std::unique_ptr<AssetCreator<AssetPhysConstraints>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderPhysConstraints>(memory, searchPath, gdt, zone);
}
} // namespace T6
} // namespace T6::phys_constraints
@@ -8,8 +8,7 @@
#include <memory>
namespace T6
namespace T6::phys_constraints
{
std::unique_ptr<AssetCreator<AssetPhysConstraints>>
CreateGdtPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetPhysConstraints>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6::phys_constraints
@@ -76,35 +76,38 @@ namespace
}
} // namespace
InfoStringLoaderPhysConstraints::InfoStringLoaderPhysConstraints(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
namespace T6::phys_constraints
{
}
AssetCreationResult InfoStringLoaderPhysConstraints::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* physConstraints = m_memory.Alloc<PhysConstraints>();
physConstraints->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetPhysConstraints> registration(assetName, physConstraints);
InfoStringToPhysConstraintsConverter converter(infoString,
*physConstraints,
m_zone.m_script_strings,
m_memory,
context,
registration,
phys_constraints_fields,
std::extent_v<decltype(phys_constraints_fields)>);
if (!converter.Convert())
InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
std::cerr << std::format("Failed to parse phys constraints: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculatePhysConstraintsFields(*physConstraints, m_zone.m_script_strings);
registration.AddScriptString(m_zone.m_script_strings.AddOrGetScriptString(""));
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* physConstraints = m_memory.Alloc<PhysConstraints>();
physConstraints->name = m_memory.Dup(assetName.c_str());
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
AssetRegistration<AssetPhysConstraints> registration(assetName, physConstraints);
InfoStringToPhysConstraintsConverter converter(infoString,
*physConstraints,
m_zone.m_script_strings,
m_memory,
context,
registration,
phys_constraints_fields,
std::extent_v<decltype(phys_constraints_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse phys constraints: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculatePhysConstraintsFields(*physConstraints, m_zone.m_script_strings);
registration.AddScriptString(m_zone.m_script_strings.AddOrGetScriptString(""));
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace T6::phys_constraints
@@ -4,12 +4,12 @@
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace T6
namespace T6::phys_constraints
{
class InfoStringLoaderPhysConstraints
class InfoStringLoader
{
public:
InfoStringLoaderPhysConstraints(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
@@ -18,4 +18,4 @@ namespace T6
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace T6
} // namespace T6::phys_constraints
@@ -11,6 +11,7 @@
#include <iostream>
using namespace T6;
using namespace ::phys_constraints;
namespace
{
@@ -25,7 +26,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = phys_constraints::GetFileNameForAssetName(assetName);
const auto fileName = GetFileNameForAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -42,14 +43,14 @@ namespace
private:
ISearchPath& m_search_path;
InfoStringLoaderPhysConstraints m_info_string_loader;
T6::phys_constraints::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::phys_constraints
{
std::unique_ptr<AssetCreator<AssetPhysConstraints>> CreateRawPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetPhysConstraints>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderPhysConstraints>(memory, searchPath, zone);
}
} // namespace T6
} // namespace T6::phys_constraints
@@ -7,7 +7,7 @@
#include <memory>
namespace T6
namespace T6::phys_constraints
{
std::unique_ptr<AssetCreator<AssetPhysConstraints>> CreateRawPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetPhysConstraints>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6::phys_constraints