mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-12 19:47:27 +00:00
refactor: streamline T6 asset loading
This commit is contained in:
@@ -40,14 +40,14 @@ namespace
|
||||
|
||||
private:
|
||||
IGdtQueryable& m_gdt;
|
||||
InfoStringLoaderTracer m_info_string_loader;
|
||||
T6::tracer::InfoStringLoader m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace T6
|
||||
namespace T6::tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateGdtTracerLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
|
||||
{
|
||||
return std::make_unique<GdtLoaderTracer>(memory, searchPath, gdt, zone);
|
||||
}
|
||||
} // namespace T6
|
||||
} // namespace T6::tracer
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace T6
|
||||
namespace T6::tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateGdtTracerLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace T6
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace T6::tracer
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Game/T6/Tracer/TracerFields.h"
|
||||
#include "Tracer/TracerCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
@@ -11,6 +12,7 @@
|
||||
#include <limits>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::tracer;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -46,27 +48,31 @@ namespace
|
||||
};
|
||||
} // namespace
|
||||
|
||||
InfoStringLoaderTracer::InfoStringLoaderTracer(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath),
|
||||
m_zone(zone)
|
||||
namespace T6::tracer
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult InfoStringLoaderTracer::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
auto* tracer = m_memory.Alloc<TracerDef>();
|
||||
tracer->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
AssetRegistration<AssetTracer> registration(assetName, tracer);
|
||||
|
||||
InfoStringToTracerConverter converter(
|
||||
infoString, *tracer, m_zone.m_script_strings, m_memory, context, registration, tracer_fields, std::extent_v<decltype(tracer_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 tracer: \"{}\"\n", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
auto* tracer = m_memory.Alloc<TracerDef>();
|
||||
tracer->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
AssetRegistration<AssetTracer> registration(assetName, tracer);
|
||||
|
||||
InfoStringToTracerConverter converter(
|
||||
infoString, *tracer, m_zone.m_script_strings, m_memory, context, registration, tracer_fields, std::extent_v<decltype(tracer_fields)>);
|
||||
if (!converter.Convert())
|
||||
{
|
||||
std::cerr << std::format("Failed to parse tracer: \"{}\"\n", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
|
||||
} // namespace T6::tracer
|
||||
|
@@ -4,12 +4,12 @@
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
namespace T6::tracer
|
||||
{
|
||||
class InfoStringLoaderTracer
|
||||
class InfoStringLoader
|
||||
{
|
||||
public:
|
||||
InfoStringLoaderTracer(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::tracer
|
||||
|
@@ -43,14 +43,14 @@ namespace
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
InfoStringLoaderTracer m_info_string_loader;
|
||||
T6::tracer::InfoStringLoader m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace T6
|
||||
namespace T6::tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateRawTracerLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<RawLoaderTracer>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace T6
|
||||
} // namespace T6::tracer
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace T6
|
||||
namespace T6::tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateRawTracerLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace T6
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace T6::tracer
|
||||
|
Reference in New Issue
Block a user