mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-21 15:30:33 +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:
@@ -74,7 +74,7 @@ using `Linker`):
|
||||
| StringTable | ✅ | ✅ | |
|
||||
| LeaderboardDef | ✅ | ✅ | |
|
||||
| StructuredDataDefSet | ✅ | ✅ | The format is custom due to lacking information about original format. |
|
||||
| TracerDef | ✅ | ❌ | |
|
||||
| TracerDef | ✅ | ✅ | |
|
||||
| VehicleDef | ✅ | ❌ | |
|
||||
| AddonMapEnts | ⁉️ | ❌ | MapEnts String can be exported. Binary data currently not. |
|
||||
|
||||
@@ -119,7 +119,7 @@ using `Linker`):
|
||||
| StringTable | ✅ | ✅ | |
|
||||
| LeaderboardDef | ✅ | ✅ | |
|
||||
| StructuredDataDefSet | ❌ | ❌ | |
|
||||
| TracerDef | ❌ | ❌ | |
|
||||
| TracerDef | ✅ | ✅ | |
|
||||
| VehicleDef | ❌ | ❌ | |
|
||||
| AddonMapEnts | ⁉️ | ❌ | MapEnts String can be exported. Binary data currently not. |
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
inline cspField_t tracer_fields[]{
|
||||
{"material", offsetof(TracerDef, material), CSPFT_MATERIAL},
|
||||
{"drawInterval", offsetof(TracerDef, drawInterval), CSPFT_INT },
|
||||
{"speed", offsetof(TracerDef, speed), CSPFT_FLOAT },
|
||||
{"beamLength", offsetof(TracerDef, beamLength), CSPFT_FLOAT },
|
||||
{"beamWidth", offsetof(TracerDef, beamWidth), CSPFT_FLOAT },
|
||||
{"screwRadius", offsetof(TracerDef, screwRadius), CSPFT_FLOAT },
|
||||
{"screwDist", offsetof(TracerDef, screwDist), CSPFT_FLOAT },
|
||||
{"colorR0", offsetof(TracerDef, colors[0][0]), CSPFT_FLOAT },
|
||||
{"colorG0", offsetof(TracerDef, colors[0][1]), CSPFT_FLOAT },
|
||||
{"colorB0", offsetof(TracerDef, colors[0][2]), CSPFT_FLOAT },
|
||||
{"colorA0", offsetof(TracerDef, colors[0][3]), CSPFT_FLOAT },
|
||||
{"colorR1", offsetof(TracerDef, colors[1][0]), CSPFT_FLOAT },
|
||||
{"colorG1", offsetof(TracerDef, colors[1][1]), CSPFT_FLOAT },
|
||||
{"colorB1", offsetof(TracerDef, colors[1][2]), CSPFT_FLOAT },
|
||||
{"colorA1", offsetof(TracerDef, colors[1][3]), CSPFT_FLOAT },
|
||||
{"colorR2", offsetof(TracerDef, colors[2][0]), CSPFT_FLOAT },
|
||||
{"colorG2", offsetof(TracerDef, colors[2][1]), CSPFT_FLOAT },
|
||||
{"colorB2", offsetof(TracerDef, colors[2][2]), CSPFT_FLOAT },
|
||||
{"colorA2", offsetof(TracerDef, colors[2][3]), CSPFT_FLOAT },
|
||||
{"colorR3", offsetof(TracerDef, colors[3][0]), CSPFT_FLOAT },
|
||||
{"colorG3", offsetof(TracerDef, colors[3][1]), CSPFT_FLOAT },
|
||||
{"colorB3", offsetof(TracerDef, colors[3][2]), CSPFT_FLOAT },
|
||||
{"colorA3", offsetof(TracerDef, colors[3][3]), CSPFT_FLOAT },
|
||||
{"colorR4", offsetof(TracerDef, colors[4][0]), CSPFT_FLOAT },
|
||||
{"colorG4", offsetof(TracerDef, colors[4][1]), CSPFT_FLOAT },
|
||||
{"colorB4", offsetof(TracerDef, colors[4][2]), CSPFT_FLOAT },
|
||||
{"colorA4", offsetof(TracerDef, colors[4][3]), CSPFT_FLOAT },
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Game/IW4/Techset/PixelShaderDumperIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetDumperIW4.h"
|
||||
#include "Game/IW4/Techset/VertexShaderDumperIW4.h"
|
||||
#include "Game/IW4/Tracer/TracerDumperIW4.h"
|
||||
#include "Game/IW4/XAnim/XAnimDumperIW4.h"
|
||||
#include "Game/IW4/XModel/XModelDumperIW4.h"
|
||||
#include "Leaderboard/LeaderboardJsonDumperIW4.h"
|
||||
@@ -22,7 +23,6 @@
|
||||
#include "Sound/SndCurveDumperIW4.h"
|
||||
#include "StringTable/StringTableDumperIW4.h"
|
||||
#include "StructuredDataDef/StructuredDataDefDumperIW4.h"
|
||||
#include "Tracer/TracerDumperIW4.h"
|
||||
#include "Vehicle/VehicleDumperIW4.h"
|
||||
#include "Weapon/WeaponDumperIW4.h"
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
class DumperIW4 final : public AbstractAssetDumper<IW4::AssetTracer>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW4::AssetTracer::Type>& asset) override;
|
||||
};
|
||||
} // namespace tracer
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Game/IW5/Techset/PixelShaderDumperIW5.h"
|
||||
#include "Game/IW5/Techset/TechsetDumperIW5.h"
|
||||
#include "Game/IW5/Techset/VertexShaderDumperIW5.h"
|
||||
#include "Game/IW5/Tracer/TracerDumperIW5.h"
|
||||
#include "Game/IW5/XModel/XModelDumperIW5.h"
|
||||
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
|
||||
#include "LightDef/LightDefDumperIW5.h"
|
||||
@@ -68,7 +69,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
|
||||
RegisterAssetDumper(std::make_unique<string_table::DumperIW5>());
|
||||
RegisterAssetDumper(std::make_unique<leaderboard::JsonDumperIW5>());
|
||||
// REGISTER_DUMPER(AssetDumperStructuredDataDefSet)
|
||||
// REGISTER_DUMPER(AssetDumperTracerDef)
|
||||
RegisterAssetDumper(std::make_unique<tracer::DumperIW5>());
|
||||
// REGISTER_DUMPER(AssetDumperVehicleDef)
|
||||
RegisterAssetDumper(std::make_unique<addon_map_ents::DumperIW5>());
|
||||
}
|
||||
|
||||
+23
-25
@@ -1,16 +1,28 @@
|
||||
#include "TracerDumperIW4.h"
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#include "Game/IW4/CommonIW4.h"
|
||||
#include "Game/IW4/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/IW4/ObjConstantsIW4.h"
|
||||
#include "Game/IW4/Tracer/TracerFields.h"
|
||||
#filename "Game/" + GAME + "/Tracer/TracerDumper" + GAME + ".cpp"
|
||||
|
||||
#set DUMPER_HEADER "\"TracerDumper" + GAME + ".h\""
|
||||
#set INFO_STRING_CONVERTER_HEADER "\"Game/" + GAME + "/InfoString/InfoStringFromStructConverter.h\""
|
||||
#set OBJ_CONSTANTS_HEADER "\"Game/" + GAME + "/ObjConstants" + GAME + ".h\""
|
||||
#set TRACER_FIELDS_HEADER "\"Game/" + GAME + "/Tracer/TracerFields.h\""
|
||||
#set CLASS_NAME "Dumper" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See TracerDumper.cpp.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#include DUMPER_HEADER
|
||||
|
||||
#include INFO_STRING_CONVERTER_HEADER
|
||||
#include OBJ_CONSTANTS_HEADER
|
||||
#include TRACER_FIELDS_HEADER
|
||||
#include "Tracer/TracerCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace IW4;
|
||||
using namespace GAME;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -23,36 +35,22 @@ namespace
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringFromTracerConverter(const TracerDef* structure,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount,
|
||||
std::function<std::string(scr_string_t)> scriptStringValueCallback)
|
||||
: InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback))
|
||||
InfoStringFromTracerConverter(const TracerDef* structure, const cspField_t* fields, const size_t fieldCount)
|
||||
: InfoStringFromStructConverter(structure, fields, fieldCount)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
InfoString CreateInfoString(const XAssetInfo<TracerDef>& asset)
|
||||
{
|
||||
InfoStringFromTracerConverter converter(asset.Asset(),
|
||||
tracer_fields,
|
||||
std::extent_v<decltype(tracer_fields)>,
|
||||
[asset](const scr_string_t scrStr) -> std::string
|
||||
{
|
||||
assert(scrStr < asset.m_zone->m_script_strings.Count());
|
||||
if (scrStr >= asset.m_zone->m_script_strings.Count())
|
||||
return "";
|
||||
|
||||
return asset.m_zone->m_script_strings[scrStr];
|
||||
});
|
||||
|
||||
InfoStringFromTracerConverter converter(asset.Asset(), tracer_fields, std::extent_v<decltype(tracer_fields)>);
|
||||
return converter.Convert();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
void DumperIW4::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetTracer::Type>& asset)
|
||||
void CLASS_NAME::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetTracer::Type>& asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
@@ -0,0 +1,24 @@
|
||||
#options GAME(IW4, IW5)
|
||||
|
||||
#filename "Game/" + GAME + "/Tracer/TracerDumper" + GAME + ".h"
|
||||
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set CLASS_NAME "Dumper" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See TracerDumper.h.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include GAME_HEADER
|
||||
|
||||
namespace tracer
|
||||
{
|
||||
class CLASS_NAME final : public AbstractAssetDumper<GAME::AssetTracer>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<GAME::AssetTracer::Type>& asset) override;
|
||||
};
|
||||
} // namespace tracer
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "Game/IW4/Tracer/RawLoaderTracerIW4.h"
|
||||
#include "Game/IW4/Tracer/TracerDumperIW4.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "SearchPath/MockOutputPath.h"
|
||||
#include "SearchPath/MockSearchPath.h"
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto TRACER_NAME = "test_tracer";
|
||||
constexpr auto MATERIAL_NAME = "tracer_material";
|
||||
|
||||
struct TestTracer
|
||||
{
|
||||
std::unique_ptr<Material> material;
|
||||
std::unique_ptr<TracerDef> tracer;
|
||||
};
|
||||
|
||||
TestTracer CreateTestTracer()
|
||||
{
|
||||
TestTracer result{std::make_unique<Material>(), std::make_unique<TracerDef>()};
|
||||
result.material->info.name = ",tracer_material";
|
||||
|
||||
result.tracer->name = TRACER_NAME;
|
||||
result.tracer->material = result.material.get();
|
||||
result.tracer->drawInterval = 7;
|
||||
result.tracer->speed = 8.25f;
|
||||
result.tracer->beamLength = 9.5f;
|
||||
result.tracer->beamWidth = 10.75f;
|
||||
result.tracer->screwRadius = 11.25f;
|
||||
result.tracer->screwDist = 12.5f;
|
||||
|
||||
for (auto colorIndex = 0u; colorIndex < 5u; colorIndex++)
|
||||
{
|
||||
for (auto componentIndex = 0u; componentIndex < 4u; componentIndex++)
|
||||
result.tracer->colors[colorIndex][componentIndex] = static_cast<float>(13u + colorIndex * 4u + componentIndex);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string DumpTracer(TracerDef& tracerDef)
|
||||
{
|
||||
Zone dumpingZone("DumpingZone", 0, GameId::IW4, GamePlatform::PC);
|
||||
dumpingZone.m_pools.AddAsset(std::make_unique<XAssetInfo<TracerDef>>(ASSET_TYPE_TRACER, tracerDef.name, &tracerDef));
|
||||
|
||||
MockSearchPath dumpingObjPath;
|
||||
MockOutputPath dumpingOutput;
|
||||
AssetDumpingContext dumpingContext(dumpingZone, "", dumpingOutput, dumpingObjPath, std::nullopt);
|
||||
tracer::DumperIW4 dumper;
|
||||
dumper.Dump(dumpingContext);
|
||||
|
||||
const auto* dumpedFile = dumpingOutput.GetMockedFile("tracer/test_tracer");
|
||||
REQUIRE(dumpedFile != nullptr);
|
||||
|
||||
return dumpedFile->AsString();
|
||||
}
|
||||
|
||||
void RequireTracerValues(const TracerDef& actual, const TracerDef& expected)
|
||||
{
|
||||
REQUIRE(std::string(actual.name) == expected.name);
|
||||
REQUIRE(actual.drawInterval == expected.drawInterval);
|
||||
REQUIRE(actual.speed == expected.speed);
|
||||
REQUIRE(actual.beamLength == expected.beamLength);
|
||||
REQUIRE(actual.beamWidth == expected.beamWidth);
|
||||
REQUIRE(actual.screwRadius == expected.screwRadius);
|
||||
REQUIRE(actual.screwDist == expected.screwDist);
|
||||
|
||||
for (auto colorIndex = 0u; colorIndex < 5u; colorIndex++)
|
||||
{
|
||||
for (auto componentIndex = 0u; componentIndex < 4u; componentIndex++)
|
||||
REQUIRE(actual.colors[colorIndex][componentIndex] == expected.colors[colorIndex][componentIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Tracer dumper serializes raw fields (IW4)", "[iw4][tracer][system]")
|
||||
{
|
||||
auto testTracer = CreateTestTracer();
|
||||
std::istringstream dumpedStream(DumpTracer(*testTracer.tracer));
|
||||
|
||||
InfoString infoString;
|
||||
REQUIRE(infoString.FromStream("TRACER", dumpedStream));
|
||||
REQUIRE(infoString.GetValueForKey("material") == MATERIAL_NAME);
|
||||
REQUIRE(infoString.GetValueForKey("drawInterval") == "7");
|
||||
REQUIRE(infoString.GetValueForKey("speed") == "8.25");
|
||||
REQUIRE(infoString.GetValueForKey("beamLength") == "9.5");
|
||||
REQUIRE(infoString.GetValueForKey("beamWidth") == "10.75");
|
||||
REQUIRE(infoString.GetValueForKey("screwRadius") == "11.25");
|
||||
REQUIRE(infoString.GetValueForKey("screwDist") == "12.5");
|
||||
|
||||
constexpr std::array colorFields{
|
||||
"colorR0", "colorG0", "colorB0", "colorA0", "colorR1", "colorG1", "colorB1", "colorA1", "colorR2", "colorG2",
|
||||
"colorB2", "colorA2", "colorR3", "colorG3", "colorB3", "colorA3", "colorR4", "colorG4", "colorB4", "colorA4",
|
||||
};
|
||||
for (auto fieldIndex = 0u; fieldIndex < colorFields.size(); fieldIndex++)
|
||||
{
|
||||
REQUIRE(infoString.GetValueForKey(colorFields[fieldIndex]) == std::to_string(13u + fieldIndex));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Tracer loader restores dumped raw asset (IW4)", "[iw4][tracer][system]")
|
||||
{
|
||||
auto testTracer = CreateTestTracer();
|
||||
MockSearchPath loadingSearchPath;
|
||||
loadingSearchPath.AddFileData("tracer/test_tracer", DumpTracer(*testTracer.tracer));
|
||||
|
||||
Zone loadingZone("LoadingZone", 0, GameId::IW4, GamePlatform::PC);
|
||||
auto loadingMaterial = std::make_unique<Material>();
|
||||
loadingMaterial->info.name = MATERIAL_NAME;
|
||||
auto* loadingMaterialInfo =
|
||||
loadingZone.m_pools.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, MATERIAL_NAME, loadingMaterial.get()));
|
||||
|
||||
AssetCreatorCollection creatorCollection(loadingZone);
|
||||
IgnoredAssetLookup ignoredAssetLookup;
|
||||
AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup);
|
||||
const auto loader = tracer::CreateRawLoaderIW4(loadingZone.Memory(), loadingSearchPath, loadingZone);
|
||||
const auto result = loader->CreateAsset(TRACER_NAME, loadingContext);
|
||||
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
const auto* loadedAssetInfo = reinterpret_cast<XAssetInfo<TracerDef>*>(result.GetAssetInfo());
|
||||
const auto* loadedTracer = loadedAssetInfo->Asset();
|
||||
|
||||
RequireTracerValues(*loadedTracer, *testTracer.tracer);
|
||||
REQUIRE(loadedTracer->material == loadingMaterial.get());
|
||||
REQUIRE(loadedAssetInfo->m_dependencies.size() == 1u);
|
||||
REQUIRE(loadedAssetInfo->m_dependencies[0] == loadingMaterialInfo);
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user