2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-04-29 15:09:38 +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,14 +40,14 @@ namespace
private:
IGdtQueryable& m_gdt;
InfoStringLoaderVehicle m_info_string_loader;
T6::vehicle::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::vehicle
{
std::unique_ptr<AssetCreator<AssetVehicle>> CreateGdtVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
std::unique_ptr<AssetCreator<AssetVehicle>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderVehicle>(memory, searchPath, gdt, zone);
}
} // namespace T6
} // namespace T6::vehicle
@@ -8,7 +8,7 @@
#include <memory>
namespace T6
namespace T6::vehicle
{
std::unique_ptr<AssetCreator<AssetVehicle>> CreateGdtVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetVehicle>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6::vehicle
@@ -107,27 +107,30 @@ namespace
};
} // namespace
InfoStringLoaderVehicle::InfoStringLoaderVehicle(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
namespace T6::vehicle
{
}
AssetCreationResult InfoStringLoaderVehicle::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* vehicleDef = m_memory.Alloc<VehicleDef>();
vehicleDef->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetVehicle> registration(assetName, vehicleDef);
InfoStringToVehicleConverter converter(
infoString, *vehicleDef, m_zone.m_script_strings, m_memory, context, registration, vehicle_fields, std::extent_v<decltype(vehicle_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 vehicle: \"{}\"\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* vehicleDef = m_memory.Alloc<VehicleDef>();
vehicleDef->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetVehicle> registration(assetName, vehicleDef);
InfoStringToVehicleConverter converter(
infoString, *vehicleDef, m_zone.m_script_strings, m_memory, context, registration, vehicle_fields, std::extent_v<decltype(vehicle_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse vehicle: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace T6::vehicle
@@ -4,12 +4,12 @@
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace T6
namespace T6::vehicle
{
class InfoStringLoaderVehicle
class InfoStringLoader
{
public:
InfoStringLoaderVehicle(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::vehicle
@@ -43,14 +43,14 @@ namespace
private:
ISearchPath& m_search_path;
InfoStringLoaderVehicle m_info_string_loader;
T6::vehicle::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::vehicle
{
std::unique_ptr<AssetCreator<AssetVehicle>> CreateRawVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetVehicle>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderVehicle>(memory, searchPath, zone);
}
} // namespace T6
} // namespace T6::vehicle
@@ -7,7 +7,7 @@
#include <memory>
namespace T6
namespace T6::vehicle
{
std::unique_ptr<AssetCreator<AssetVehicle>> CreateRawVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetVehicle>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6::vehicle