mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-09-12 00:47:06 +00:00
feat: templated tracer loading and dumping for IW4 and IW5 (#921)
Relates to https://github.com/Laupetin/OpenAssetTools/issues/626
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "Game/IW4/Image/ImageLoaderExternalIW4.h"
|
||||
#include "Game/IW4/Techset/PixelShaderLoaderIW4.h"
|
||||
#include "Game/IW4/Techset/VertexShaderLoaderIW4.h"
|
||||
#include "Game/IW4/Tracer/GdtLoaderTracerIW4.h"
|
||||
#include "Game/IW4/Tracer/RawLoaderTracerIW4.h"
|
||||
#include "Game/IW4/Weapon/AccuracyGraphLoaderIW4.h"
|
||||
#include "Game/IW4/XAnim/XAnimLoaderIW4.h"
|
||||
#include "Game/IW4/XModel/LoaderXModelIW4.h"
|
||||
@@ -159,7 +161,8 @@ namespace
|
||||
collection.AddAssetCreator(string_table::CreateLoaderIW4(memory, searchPath));
|
||||
collection.AddAssetCreator(leaderboard::CreateLoaderIW4(memory, searchPath));
|
||||
collection.AddAssetCreator(structured_data_def::CreateLoaderIW4(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTracer>(memory));
|
||||
collection.AddAssetCreator(tracer::CreateRawLoaderIW4(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(tracer::CreateGdtLoaderIW4(memory, gdt, zone));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderVehicle>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderAddonMapEnts>(memory));
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "Game/IW5/Image/ImageLoaderExternalIW5.h"
|
||||
#include "Game/IW5/Techset/PixelShaderLoaderIW5.h"
|
||||
#include "Game/IW5/Techset/VertexShaderLoaderIW5.h"
|
||||
#include "Game/IW5/Tracer/GdtLoaderTracerIW5.h"
|
||||
#include "Game/IW5/Tracer/RawLoaderTracerIW5.h"
|
||||
#include "Game/IW5/Weapon/AccuracyGraphLoaderIW5.h"
|
||||
#include "Game/IW5/XAnim/XAnimLoaderIW5.h"
|
||||
#include "Game/IW5/XModel/LoaderXModelIW5.h"
|
||||
@@ -170,7 +172,8 @@ namespace
|
||||
collection.AddAssetCreator(string_table::CreateLoaderIW5(memory, searchPath));
|
||||
collection.AddAssetCreator(leaderboard::CreateLoaderIW5(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderStructuredDataDef>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTracer>(memory));
|
||||
collection.AddAssetCreator(tracer::CreateRawLoaderIW5(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(tracer::CreateGdtLoaderIW5(memory, gdt, zone));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderVehicle>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderAddonMapEnts>(memory));
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/GdtLoaderTracer" + GAME + ".cpp"
|
||||
|
||||
#set LOADER_HEADER "\"GdtLoaderTracer" + GAME + ".h\""
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set OBJ_CONSTANTS_HEADER "\"Game/" + GAME + "/ObjConstants" + GAME + ".h\""
|
||||
#set INFO_STRING_LOADER_HEADER "\"InfoStringLoaderTracer" + GAME + ".h\""
|
||||
#set INFO_STRING_LOADER_CLASS "InfoStringLoader" + GAME
|
||||
#set FACTORY_NAME "CreateGdtLoader" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See GdtLoaderTracer.cpp.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#include LOADER_HEADER
|
||||
|
||||
#include GAME_HEADER
|
||||
#include OBJ_CONSTANTS_HEADER
|
||||
#include "InfoString/InfoString.h"
|
||||
#include INFO_STRING_LOADER_HEADER
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
using namespace GAME;
|
||||
|
||||
namespace
|
||||
{
|
||||
class GdtLoaderTracer final : public AssetCreator<AssetTracer>
|
||||
{
|
||||
public:
|
||||
GdtLoaderTracer(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
: m_gdt(gdt),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(GDF_FILENAME_TRACER, assetName);
|
||||
if (gdtEntry == nullptr)
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromGdtProperties(*gdtEntry))
|
||||
{
|
||||
con::error("Failed to read tracer gdt entry: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
IGdtQueryable& m_gdt;
|
||||
tracer::INFO_STRING_LOADER_CLASS m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> FACTORY_NAME(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
{
|
||||
return std::make_unique<GdtLoaderTracer>(memory, gdt, zone);
|
||||
}
|
||||
} // namespace tracer
|
||||
@@ -0,0 +1,24 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/GdtLoaderTracer" + GAME + ".h"
|
||||
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set FACTORY_NAME "CreateGdtLoader" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See GdtLoaderTracer.h.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include GAME_HEADER
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<GAME::AssetTracer>> FACTORY_NAME(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace tracer
|
||||
@@ -0,0 +1,77 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/InfoStringLoaderTracer" + GAME + ".cpp"
|
||||
|
||||
#set LOADER_HEADER "\"InfoStringLoaderTracer" + GAME + ".h\""
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set INFO_STRING_CONVERTER_HEADER "\"Game/" + GAME + "/InfoString/InfoStringToStructConverter.h\""
|
||||
#set TRACER_FIELDS_HEADER "\"Game/" + GAME + "/Tracer/TracerFields.h\""
|
||||
#set CLASS_NAME "InfoStringLoader" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See InfoStringLoaderTracer.cpp.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#include LOADER_HEADER
|
||||
|
||||
#include GAME_HEADER
|
||||
#include INFO_STRING_CONVERTER_HEADER
|
||||
#include TRACER_FIELDS_HEADER
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace GAME;
|
||||
|
||||
namespace
|
||||
{
|
||||
class InfoStringToTracerConverter final : public InfoStringToStructConverter
|
||||
{
|
||||
protected:
|
||||
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||
{
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringToTracerConverter(const InfoString& infoString,
|
||||
TracerDef& tracer,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
AssetRegistration<AssetTracer>& registration,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount)
|
||||
: InfoStringToStructConverter(infoString, &tracer, zoneScriptStrings, memory, context, registration, fields, fieldCount)
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
CLASS_NAME::CLASS_NAME(MemoryManager& memory, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CLASS_NAME::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())
|
||||
{
|
||||
con::error("Failed to parse tracer: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
} // namespace tracer
|
||||
@@ -0,0 +1,30 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/InfoStringLoaderTracer" + GAME + ".h"
|
||||
|
||||
#set CLASS_NAME "InfoStringLoader" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See InfoStringLoaderTracer.h.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreationContext.h"
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
class CLASS_NAME
|
||||
{
|
||||
public:
|
||||
CLASS_NAME(MemoryManager& memory, Zone& zone);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
Zone& m_zone;
|
||||
};
|
||||
} // namespace tracer
|
||||
@@ -0,0 +1,67 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/RawLoaderTracer" + GAME + ".cpp"
|
||||
|
||||
#set LOADER_HEADER "\"RawLoaderTracer" + GAME + ".h\""
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set OBJ_CONSTANTS_HEADER "\"Game/" + GAME + "/ObjConstants" + GAME + ".h\""
|
||||
#set INFO_STRING_LOADER_HEADER "\"InfoStringLoaderTracer" + GAME + ".h\""
|
||||
#set INFO_STRING_LOADER_CLASS "InfoStringLoader" + GAME
|
||||
#set FACTORY_NAME "CreateRawLoader" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See RawLoaderTracer.cpp.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#include LOADER_HEADER
|
||||
|
||||
#include GAME_HEADER
|
||||
#include OBJ_CONSTANTS_HEADER
|
||||
#include "InfoString/InfoString.h"
|
||||
#include INFO_STRING_LOADER_HEADER
|
||||
#include "Tracer/TracerCommon.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
using namespace GAME;
|
||||
|
||||
namespace
|
||||
{
|
||||
class RawLoaderTracer final : public AssetCreator<AssetTracer>
|
||||
{
|
||||
public:
|
||||
RawLoaderTracer(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_search_path(searchPath),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = tracer::GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromStream(INFO_STRING_PREFIX_TRACER, *file.m_stream))
|
||||
{
|
||||
con::error("Could not parse as info string file: \"{}\"", fileName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
tracer::INFO_STRING_LOADER_CLASS m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetTracer>> FACTORY_NAME(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<RawLoaderTracer>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace tracer
|
||||
@@ -0,0 +1,24 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/RawLoaderTracer" + GAME + ".h"
|
||||
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set FACTORY_NAME "CreateRawLoader" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See RawLoaderTracer.h.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include GAME_HEADER
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
std::unique_ptr<AssetCreator<GAME::AssetTracer>> FACTORY_NAME(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace tracer
|
||||
Reference in New Issue
Block a user