From 04b6b5b4bf4120d296e990e95ddd76e590837dae Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Wed, 22 Jul 2026 21:08:36 +0200 Subject: [PATCH] refactor: physpreset codestyle (#928) * chore: adjust phys preset code to use similar code style * fix: infinity friction for t6 * fix: t6 phys preset canFloat qboolean * chore: move iw5 phys preset enum strings to enum strings header * chore: add phys preset tests for all games * chore: rename PhysPresetFields headers --- ...ysPresetFields.h => PhysPresetFieldsIW3.h} | 0 ...ysPresetFields.h => PhysPresetFieldsIW4.h} | 0 .../Game/IW5/InfoString/EnumStrings.h | 9 -- ...ysPresetFields.h => PhysPresetFieldsIW5.h} | 8 +- ...hysPresetFields.h => PhysPresetFieldsT4.h} | 0 src/ObjCommon/Game/T5/ObjConstantsT5.h | 2 +- ...hysPresetFields.h => PhysPresetFieldsT5.h} | 0 src/ObjCommon/Game/T6/ObjConstantsT6.h | 2 + ...hysPresetFields.h => PhysPresetFieldsT6.h} | 2 +- .../InfoStringLoaderPhysPresetIW3.cpp | 33 +++---- .../InfoStringLoaderPhysPresetIW4.cpp | 33 +++---- .../InfoStringLoaderPhysPresetIW5.cpp | 31 ++++--- .../InfoStringLoaderPhysPresetT4.cpp | 2 +- .../InfoStringLoaderPhysPresetT5.cpp | 12 +-- .../InfoStringLoaderPhysPresetT6.cpp | 13 ++- .../PhysPresetInfoStringDumperIW3.cpp | 60 +++++-------- .../PhysPresetInfoStringDumperIW4.cpp | 65 ++++++-------- .../PhysPresetInfoStringDumperIW5.cpp | 78 +++++++---------- .../PhysPresetInfoStringDumperT4.cpp | 2 +- .../PhysPresetInfoStringDumperT5.cpp | 67 ++++++-------- .../PhysPresetInfoStringDumperT6.cpp | 67 ++++++-------- .../PhysPreset/RawLoaderPhysPresetIW3Test.cpp | 46 ++++++++++ .../PhysPreset/RawLoaderPhysPresetIW4Test.cpp | 47 ++++++++++ .../PhysPreset/RawLoaderPhysPresetIW5Test.cpp | 56 ++++++++++++ .../PhysPreset/RawLoaderPhysPresetT4Test.cpp | 48 ++++++++++ .../PhysPreset/RawLoaderPhysPresetT5Test.cpp | 58 +++++++++++++ .../PhysPreset/RawLoaderPhysPresetT6Test.cpp | 58 +++++++++++++ .../PhysPresetInfoStringDumperIW3Test.cpp | 67 ++++++++++++++ .../PhysPresetInfoStringDumperIW4Test.cpp | 69 +++++++++++++++ .../PhysPresetInfoStringDumperIW5Test.cpp | 81 +++++++++++++++++ .../PhysPresetInfoStringDumperT4Test.cpp} | 55 ++---------- .../PhysPresetInfoStringDumperT5Test.cpp | 87 +++++++++++++++++++ .../PhysPresetInfoStringDumperT6Test.cpp | 87 +++++++++++++++++++ 33 files changed, 916 insertions(+), 329 deletions(-) rename src/ObjCommon/Game/IW3/PhysPreset/{PhysPresetFields.h => PhysPresetFieldsIW3.h} (100%) rename src/ObjCommon/Game/IW4/PhysPreset/{PhysPresetFields.h => PhysPresetFieldsIW4.h} (100%) delete mode 100644 src/ObjCommon/Game/IW5/InfoString/EnumStrings.h rename src/ObjCommon/Game/IW5/PhysPreset/{PhysPresetFields.h => PhysPresetFieldsIW5.h} (89%) rename src/ObjCommon/Game/T4/PhysPreset/{PhysPresetFields.h => PhysPresetFieldsT4.h} (100%) rename src/ObjCommon/Game/T5/PhysPreset/{PhysPresetFields.h => PhysPresetFieldsT5.h} (100%) rename src/ObjCommon/Game/T6/PhysPreset/{PhysPresetFields.h => PhysPresetFieldsT6.h} (98%) create mode 100644 test/ObjLoadingTests/Game/IW3/PhysPreset/RawLoaderPhysPresetIW3Test.cpp create mode 100644 test/ObjLoadingTests/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4Test.cpp create mode 100644 test/ObjLoadingTests/Game/IW5/PhysPreset/RawLoaderPhysPresetIW5Test.cpp create mode 100644 test/ObjLoadingTests/Game/T4/PhysPreset/RawLoaderPhysPresetT4Test.cpp create mode 100644 test/ObjLoadingTests/Game/T5/PhysPreset/RawLoaderPhysPresetT5Test.cpp create mode 100644 test/ObjLoadingTests/Game/T6/PhysPreset/RawLoaderPhysPresetT6Test.cpp create mode 100644 test/ObjWritingTests/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3Test.cpp create mode 100644 test/ObjWritingTests/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4Test.cpp create mode 100644 test/ObjWritingTests/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5Test.cpp rename test/{SystemTests/Game/T4/PhysPresetT4.cpp => ObjWritingTests/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4Test.cpp} (52%) create mode 100644 test/ObjWritingTests/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5Test.cpp create mode 100644 test/ObjWritingTests/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6Test.cpp diff --git a/src/ObjCommon/Game/IW3/PhysPreset/PhysPresetFields.h b/src/ObjCommon/Game/IW3/PhysPreset/PhysPresetFieldsIW3.h similarity index 100% rename from src/ObjCommon/Game/IW3/PhysPreset/PhysPresetFields.h rename to src/ObjCommon/Game/IW3/PhysPreset/PhysPresetFieldsIW3.h diff --git a/src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFields.h b/src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFieldsIW4.h similarity index 100% rename from src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFields.h rename to src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFieldsIW4.h diff --git a/src/ObjCommon/Game/IW5/InfoString/EnumStrings.h b/src/ObjCommon/Game/IW5/InfoString/EnumStrings.h deleted file mode 100644 index 3d5c9721..00000000 --- a/src/ObjCommon/Game/IW5/InfoString/EnumStrings.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace IW5 -{ - inline const char* szPhysPresetScalingNames[]{ - "linear", - "quadratic", - }; -} // namespace IW5 diff --git a/src/ObjCommon/Game/IW5/PhysPreset/PhysPresetFields.h b/src/ObjCommon/Game/IW5/PhysPreset/PhysPresetFieldsIW5.h similarity index 89% rename from src/ObjCommon/Game/IW5/PhysPreset/PhysPresetFields.h rename to src/ObjCommon/Game/IW5/PhysPreset/PhysPresetFieldsIW5.h index 98d0bfba..ee73821d 100644 --- a/src/ObjCommon/Game/IW5/PhysPreset/PhysPresetFields.h +++ b/src/ObjCommon/Game/IW5/PhysPreset/PhysPresetFieldsIW5.h @@ -23,4 +23,10 @@ namespace IW5 {"tempDefaultToCylinder", offsetof(PhysPresetInfo, tempDefaultToCylinder), CSPFT_QBOOLEAN}, {"perSurfaceSndAlias", offsetof(PhysPresetInfo, perSurfaceSndAlias), CSPFT_QBOOLEAN}, }; -} + + inline const char* szPhysPresetScalingNames[]{ + "linear", + "quadratic", + }; + static_assert(std::extent_v == PHYSPRESET_SCALING_COUNT); +} // namespace IW5 diff --git a/src/ObjCommon/Game/T4/PhysPreset/PhysPresetFields.h b/src/ObjCommon/Game/T4/PhysPreset/PhysPresetFieldsT4.h similarity index 100% rename from src/ObjCommon/Game/T4/PhysPreset/PhysPresetFields.h rename to src/ObjCommon/Game/T4/PhysPreset/PhysPresetFieldsT4.h diff --git a/src/ObjCommon/Game/T5/ObjConstantsT5.h b/src/ObjCommon/Game/T5/ObjConstantsT5.h index 9a1f45b5..e71556f6 100644 --- a/src/ObjCommon/Game/T5/ObjConstantsT5.h +++ b/src/ObjCommon/Game/T5/ObjConstantsT5.h @@ -11,5 +11,5 @@ namespace T5 static constexpr auto GDF_FILENAME_PHYS_PRESET = "physpreset.gdf"; static constexpr auto GDF_FILENAME_WEAPON = "weapon.gdf"; - static constexpr float MAX_FRICTION = 1e+10; + static constexpr float PHYS_PRESET_MAX_FRICTION = 1e+10; } // namespace T5 diff --git a/src/ObjCommon/Game/T5/PhysPreset/PhysPresetFields.h b/src/ObjCommon/Game/T5/PhysPreset/PhysPresetFieldsT5.h similarity index 100% rename from src/ObjCommon/Game/T5/PhysPreset/PhysPresetFields.h rename to src/ObjCommon/Game/T5/PhysPreset/PhysPresetFieldsT5.h diff --git a/src/ObjCommon/Game/T6/ObjConstantsT6.h b/src/ObjCommon/Game/T6/ObjConstantsT6.h index 5f1b82cf..9935ba13 100644 --- a/src/ObjCommon/Game/T6/ObjConstantsT6.h +++ b/src/ObjCommon/Game/T6/ObjConstantsT6.h @@ -20,4 +20,6 @@ namespace T6 static constexpr auto GDF_FILENAME_WEAPON_ATTACHMENT = "attachment.gdf"; static constexpr auto GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE = "attachmentunique.gdf"; static constexpr auto GDF_FILENAME_ZBARRIER = "zbarrier.gdf"; + + static constexpr float PHYS_PRESET_MAX_FRICTION = 1e+10; } // namespace T6 diff --git a/src/ObjCommon/Game/T6/PhysPreset/PhysPresetFields.h b/src/ObjCommon/Game/T6/PhysPreset/PhysPresetFieldsT6.h similarity index 98% rename from src/ObjCommon/Game/T6/PhysPreset/PhysPresetFields.h rename to src/ObjCommon/Game/T6/PhysPreset/PhysPresetFieldsT6.h index 65fc14cb..b50553f0 100644 --- a/src/ObjCommon/Game/T6/PhysPreset/PhysPresetFields.h +++ b/src/ObjCommon/Game/T6/PhysPreset/PhysPresetFieldsT6.h @@ -12,7 +12,7 @@ namespace T6 {"explosiveForceScale", offsetof(PhysPresetInfo, explosiveForceScale), CSPFT_FLOAT }, {"piecesSpreadFraction", offsetof(PhysPresetInfo, piecesSpreadFraction), CSPFT_FLOAT }, {"piecesUpwardVelocity", offsetof(PhysPresetInfo, piecesUpwardVelocity), CSPFT_FLOAT }, - {"canFloat", offsetof(PhysPresetInfo, canFloat), CSPFT_INT }, + {"canFloat", offsetof(PhysPresetInfo, canFloat), CSPFT_QBOOLEAN}, {"gravityScale", offsetof(PhysPresetInfo, gravityScale), CSPFT_FLOAT }, {"massOffsetX", offsetof(PhysPresetInfo, centerOfMassOffset.x), CSPFT_FLOAT }, {"massOffsetY", offsetof(PhysPresetInfo, centerOfMassOffset.y), CSPFT_FLOAT }, diff --git a/src/ObjLoading/Game/IW3/PhysPreset/InfoStringLoaderPhysPresetIW3.cpp b/src/ObjLoading/Game/IW3/PhysPreset/InfoStringLoaderPhysPresetIW3.cpp index 540083ac..957357bc 100644 --- a/src/ObjLoading/Game/IW3/PhysPreset/InfoStringLoaderPhysPresetIW3.cpp +++ b/src/ObjLoading/Game/IW3/PhysPreset/InfoStringLoaderPhysPresetIW3.cpp @@ -2,14 +2,10 @@ #include "Game/IW3/IW3.h" #include "Game/IW3/InfoString/InfoStringToStructConverter.h" -#include "Game/IW3/PhysPreset/PhysPresetFields.h" +#include "Game/IW3/PhysPreset/PhysPresetFieldsIW3.h" #include "Utils/Logging/Log.h" -#include #include -#include -#include -#include #include using namespace IW3; @@ -20,14 +16,14 @@ namespace { public: InfoStringToPhysPresetConverter(const InfoString& infoString, - void* structure, + PhysPresetInfo& physPreset, ZoneScriptStrings& zoneScriptStrings, MemoryManager& memory, AssetCreationContext& context, - GenericAssetRegistration& registration, + AssetRegistration& registration, const cspField_t* fields, - size_t fieldCount) - : InfoStringToStructConverter(infoString, structure, zoneScriptStrings, memory, context, registration, fields, fieldCount) + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &physPreset, zoneScriptStrings, memory, context, registration, fields, fieldCount) { } @@ -68,22 +64,27 @@ namespace phys_preset AssetCreationResult InfoStringLoaderIW3::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) { - PhysPresetInfo presetInfo; - std::memset(&presetInfo, 0, sizeof(presetInfo)); - auto* physPreset = m_memory.Alloc(); + physPreset->name = m_memory.Dup(assetName.c_str()); + AssetRegistration registration(assetName, physPreset); - InfoStringToPhysPresetConverter converter( - infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v); + PhysPresetInfo physPresetInfo{}; + InfoStringToPhysPresetConverter converter(infoString, + physPresetInfo, + m_zone.m_script_strings, + m_memory, + context, + registration, + phys_preset_fields, + std::extent_v); if (!converter.Convert()) { con::error("Failed to parse phys preset: \"{}\"", assetName); return AssetCreationResult::Failure(); } - CopyFromPhysPresetInfo(presetInfo, *physPreset); - physPreset->name = m_memory.Dup(assetName.c_str()); + CopyFromPhysPresetInfo(physPresetInfo, *physPreset); return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } diff --git a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp index c71d4726..5f228e2b 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp +++ b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp @@ -2,14 +2,10 @@ #include "Game/IW4/IW4.h" #include "Game/IW4/InfoString/InfoStringToStructConverter.h" -#include "Game/IW4/PhysPreset/PhysPresetFields.h" +#include "Game/IW4/PhysPreset/PhysPresetFieldsIW4.h" #include "Utils/Logging/Log.h" -#include #include -#include -#include -#include #include using namespace IW4; @@ -20,14 +16,14 @@ namespace { public: InfoStringToPhysPresetConverter(const InfoString& infoString, - void* structure, + PhysPresetInfo& physPreset, ZoneScriptStrings& zoneScriptStrings, MemoryManager& memory, AssetCreationContext& context, - GenericAssetRegistration& registration, + AssetRegistration& registration, const cspField_t* fields, - size_t fieldCount) - : InfoStringToStructConverter(infoString, structure, zoneScriptStrings, memory, context, registration, fields, fieldCount) + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &physPreset, zoneScriptStrings, memory, context, registration, fields, fieldCount) { } @@ -69,22 +65,27 @@ namespace phys_preset AssetCreationResult InfoStringLoaderIW4::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) { - PhysPresetInfo presetInfo; - std::memset(&presetInfo, 0, sizeof(presetInfo)); - auto* physPreset = m_memory.Alloc(); + physPreset->name = m_memory.Dup(assetName.c_str()); + AssetRegistration registration(assetName, physPreset); - InfoStringToPhysPresetConverter converter( - infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v); + PhysPresetInfo physPresetInfo{}; + InfoStringToPhysPresetConverter converter(infoString, + physPresetInfo, + m_zone.m_script_strings, + m_memory, + context, + registration, + phys_preset_fields, + std::extent_v); if (!converter.Convert()) { con::error("Failed to parse phys preset: \"{}\"", assetName); return AssetCreationResult::Failure(); } - CopyFromPhysPresetInfo(presetInfo, *physPreset); - physPreset->name = m_memory.Dup(assetName.c_str()); + CopyFromPhysPresetInfo(physPresetInfo, *physPreset); return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } diff --git a/src/ObjLoading/Game/IW5/PhysPreset/InfoStringLoaderPhysPresetIW5.cpp b/src/ObjLoading/Game/IW5/PhysPreset/InfoStringLoaderPhysPresetIW5.cpp index bfc29fd5..4c5afaa3 100644 --- a/src/ObjLoading/Game/IW5/PhysPreset/InfoStringLoaderPhysPresetIW5.cpp +++ b/src/ObjLoading/Game/IW5/PhysPreset/InfoStringLoaderPhysPresetIW5.cpp @@ -1,13 +1,11 @@ #include "InfoStringLoaderPhysPresetIW5.h" #include "Game/IW5/IW5.h" -#include "Game/IW5/InfoString/EnumStrings.h" #include "Game/IW5/InfoString/InfoStringToStructConverter.h" -#include "Game/IW5/PhysPreset/PhysPresetFields.h" +#include "Game/IW5/PhysPreset/PhysPresetFieldsIW5.h" #include "Utils/Logging/Log.h" #include -#include #include using namespace IW5; @@ -18,14 +16,14 @@ namespace { public: InfoStringToPhysPresetConverter(const InfoString& infoString, - void* structure, + PhysPresetInfo& physPreset, ZoneScriptStrings& zoneScriptStrings, MemoryManager& memory, AssetCreationContext& context, - GenericAssetRegistration& registration, + AssetRegistration& registration, const cspField_t* fields, - size_t fieldCount) - : InfoStringToStructConverter(infoString, structure, zoneScriptStrings, memory, context, registration, fields, fieldCount) + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &physPreset, zoneScriptStrings, memory, context, registration, fields, fieldCount) { } @@ -80,22 +78,27 @@ namespace phys_preset AssetCreationResult InfoStringLoaderIW5::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) { - PhysPresetInfo presetInfo; - std::memset(&presetInfo, 0, sizeof(presetInfo)); - auto* physPreset = m_memory.Alloc(); + physPreset->name = m_memory.Dup(assetName.c_str()); + AssetRegistration registration(assetName, physPreset); - InfoStringToPhysPresetConverter converter( - infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v); + PhysPresetInfo physPresetInfo{}; + InfoStringToPhysPresetConverter converter(infoString, + physPresetInfo, + m_zone.m_script_strings, + m_memory, + context, + registration, + phys_preset_fields, + std::extent_v); if (!converter.Convert()) { con::error("Failed to parse phys preset: \"{}\"", assetName); return AssetCreationResult::Failure(); } - CopyFromPhysPresetInfo(presetInfo, *physPreset); - physPreset->name = m_memory.Dup(assetName.c_str()); + CopyFromPhysPresetInfo(physPresetInfo, *physPreset); return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } diff --git a/src/ObjLoading/Game/T4/PhysPreset/InfoStringLoaderPhysPresetT4.cpp b/src/ObjLoading/Game/T4/PhysPreset/InfoStringLoaderPhysPresetT4.cpp index 283370bb..e9b61dc6 100644 --- a/src/ObjLoading/Game/T4/PhysPreset/InfoStringLoaderPhysPresetT4.cpp +++ b/src/ObjLoading/Game/T4/PhysPreset/InfoStringLoaderPhysPresetT4.cpp @@ -2,7 +2,7 @@ #include "Game/T4/InfoString/InfoStringToStructConverter.h" #include "Game/T4/ObjConstantsT4.h" -#include "Game/T4/PhysPreset/PhysPresetFields.h" +#include "Game/T4/PhysPreset/PhysPresetFieldsT4.h" #include "Game/T4/T4.h" #include "Utils/Logging/Log.h" diff --git a/src/ObjLoading/Game/T5/PhysPreset/InfoStringLoaderPhysPresetT5.cpp b/src/ObjLoading/Game/T5/PhysPreset/InfoStringLoaderPhysPresetT5.cpp index 42c1d22d..3f0d07b2 100644 --- a/src/ObjLoading/Game/T5/PhysPreset/InfoStringLoaderPhysPresetT5.cpp +++ b/src/ObjLoading/Game/T5/PhysPreset/InfoStringLoaderPhysPresetT5.cpp @@ -2,16 +2,13 @@ #include "Game/T5/InfoString/InfoStringToStructConverter.h" #include "Game/T5/ObjConstantsT5.h" -#include "Game/T5/PhysPreset/PhysPresetFields.h" +#include "Game/T5/PhysPreset/PhysPresetFieldsT5.h" #include "Game/T5/T5.h" #include "Utils/Logging/Log.h" #include #include -#include -#include -#include -#include +#include using namespace T5; @@ -46,7 +43,7 @@ namespace physPreset.bounce = physPresetInfo.bounce; if (physPresetInfo.isFrictionInfinity != 0) - physPreset.friction = MAX_FRICTION; + physPreset.friction = PHYS_PRESET_MAX_FRICTION; else physPreset.friction = physPresetInfo.friction; @@ -77,8 +74,7 @@ namespace phys_preset AssetRegistration registration(assetName, physPreset); - PhysPresetInfo physPresetInfo; - memset(&physPresetInfo, 0, sizeof(physPresetInfo)); + PhysPresetInfo physPresetInfo{}; InfoStringToPhysPresetConverter converter(infoString, physPresetInfo, m_zone.m_script_strings, diff --git a/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp b/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp index 647f2353..07297de3 100644 --- a/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp +++ b/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp @@ -1,16 +1,14 @@ #include "InfoStringLoaderPhysPresetT6.h" #include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/PhysPreset/PhysPresetFields.h" +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/PhysPreset/PhysPresetFieldsT6.h" #include "Game/T6/T6.h" #include "Utils/Logging/Log.h" #include #include -#include -#include -#include -#include +#include using namespace T6; @@ -45,7 +43,7 @@ namespace physPreset.bounce = physPresetInfo.bounce; if (physPresetInfo.isFrictionInfinity != 0) - physPreset.friction = std::numeric_limits::infinity(); + physPreset.friction = PHYS_PRESET_MAX_FRICTION; else physPreset.friction = physPresetInfo.friction; @@ -76,8 +74,7 @@ namespace phys_preset AssetRegistration registration(assetName, physPreset); - PhysPresetInfo physPresetInfo; - memset(&physPresetInfo, 0, sizeof(physPresetInfo)); + PhysPresetInfo physPresetInfo{}; InfoStringToPhysPresetConverter converter(infoString, physPresetInfo, m_zone.m_script_strings, diff --git a/src/ObjWriting/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3.cpp b/src/ObjWriting/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3.cpp index 150f57e7..2089e1b8 100644 --- a/src/ObjWriting/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3.cpp +++ b/src/ObjWriting/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3.cpp @@ -2,7 +2,7 @@ #include "Game/IW3/InfoString/InfoStringFromStructConverter.h" #include "Game/IW3/ObjConstantsIW3.h" -#include "Game/IW3/PhysPreset/PhysPresetFields.h" +#include "Game/IW3/PhysPreset/PhysPresetFieldsIW3.h" #include "PhysPreset/PhysPresetCommon.h" #include @@ -22,56 +22,42 @@ namespace } public: - InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, const cspField_t* fields, const size_t fieldCount) + : InfoStringFromStructConverter(structure, fields, fieldCount) { } }; - void CopyToPhysPresetInfo(const PhysPreset* physPreset, PhysPresetInfo* physPresetInfo) + void CopyToPhysPresetInfo(const PhysPreset& physPreset, PhysPresetInfo& physPresetInfo) { - physPresetInfo->mass = physPreset->mass; - physPresetInfo->bounce = physPreset->bounce; + physPresetInfo.mass = physPreset.mass; + physPresetInfo.bounce = physPreset.bounce; - if (physPreset->friction >= std::numeric_limits::max()) + if (physPreset.friction >= std::numeric_limits::max()) { - physPresetInfo->isFrictionInfinity = 1; - physPresetInfo->friction = 0; + physPresetInfo.isFrictionInfinity = 1; + physPresetInfo.friction = 0; } else { - physPresetInfo->isFrictionInfinity = 0; - physPresetInfo->friction = physPreset->friction; + physPresetInfo.isFrictionInfinity = 0; + physPresetInfo.friction = physPreset.friction; } - physPresetInfo->bulletForceScale = physPreset->bulletForceScale; - physPresetInfo->explosiveForceScale = physPreset->explosiveForceScale; - physPresetInfo->sndAliasPrefix = physPreset->sndAliasPrefix; - physPresetInfo->piecesSpreadFraction = physPreset->piecesSpreadFraction; - physPresetInfo->piecesUpwardVelocity = physPreset->piecesUpwardVelocity; - physPresetInfo->tempDefaultToCylinder = physPreset->tempDefaultToCylinder ? 1 : 0; + physPresetInfo.bulletForceScale = physPreset.bulletForceScale; + physPresetInfo.explosiveForceScale = physPreset.explosiveForceScale; + physPresetInfo.sndAliasPrefix = physPreset.sndAliasPrefix; + physPresetInfo.piecesSpreadFraction = physPreset.piecesSpreadFraction; + physPresetInfo.piecesUpwardVelocity = physPreset.piecesUpwardVelocity; + physPresetInfo.tempDefaultToCylinder = physPreset.tempDefaultToCylinder ? 1 : 0; } - InfoString CreateInfoString(const XAssetInfo& asset) + InfoString CreateInfoString(const PhysPreset& physPreset) { - auto* physPresetInfo = new PhysPresetInfo; - CopyToPhysPresetInfo(asset.Asset(), physPresetInfo); - - InfoStringFromPhysPresetConverter converter(physPresetInfo, - phys_preset_fields, - std::extent_v, - [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]; - }); + PhysPresetInfo physPresetInfo{}; + CopyToPhysPresetInfo(physPreset, physPresetInfo); + InfoStringFromPhysPresetConverter converter(&physPresetInfo, phys_preset_fields, std::extent_v); return converter.Convert(); } } // namespace @@ -83,7 +69,7 @@ namespace phys_preset // Only dump raw when no gdt available if (context.m_gdt) { - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); GdtEntry gdtEntry(asset.m_name, GDF_FILENAME_PHYS_PRESET); infoString.ToGdtProperties(INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); context.m_gdt->WriteEntry(gdtEntry); @@ -96,7 +82,7 @@ namespace phys_preset return; auto& stream = *assetFile; - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); const auto stringValue = infoString.ToString(INFO_STRING_PREFIX_PHYS_PRESET); stream.write(stringValue.c_str(), stringValue.size()); } diff --git a/src/ObjWriting/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4.cpp b/src/ObjWriting/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4.cpp index bd734f92..5252bf57 100644 --- a/src/ObjWriting/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4.cpp +++ b/src/ObjWriting/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4.cpp @@ -2,12 +2,11 @@ #include "Game/IW4/InfoString/InfoStringFromStructConverter.h" #include "Game/IW4/ObjConstantsIW4.h" -#include "Game/IW4/PhysPreset/PhysPresetFields.h" +#include "Game/IW4/PhysPreset/PhysPresetFieldsIW4.h" #include "PhysPreset/PhysPresetCommon.h" -#include #include -#include +#include #include using namespace IW4; @@ -23,57 +22,43 @@ namespace } public: - InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, const cspField_t* fields, const size_t fieldCount) + : InfoStringFromStructConverter(structure, fields, fieldCount) { } }; - void CopyToPhysPresetInfo(const PhysPreset* physPreset, PhysPresetInfo* physPresetInfo) + void CopyToPhysPresetInfo(const PhysPreset& physPreset, PhysPresetInfo& physPresetInfo) { - physPresetInfo->mass = physPreset->mass; - physPresetInfo->bounce = physPreset->bounce; + physPresetInfo.mass = physPreset.mass; + physPresetInfo.bounce = physPreset.bounce; - if (physPreset->friction >= std::numeric_limits::max()) + if (physPreset.friction >= std::numeric_limits::max()) { - physPresetInfo->isFrictionInfinity = 1; - physPresetInfo->friction = 0; + physPresetInfo.isFrictionInfinity = 1; + physPresetInfo.friction = 0; } else { - physPresetInfo->isFrictionInfinity = 0; - physPresetInfo->friction = physPreset->friction; + physPresetInfo.isFrictionInfinity = 0; + physPresetInfo.friction = physPreset.friction; } - physPresetInfo->bulletForceScale = physPreset->bulletForceScale; - physPresetInfo->explosiveForceScale = physPreset->explosiveForceScale; - physPresetInfo->sndAliasPrefix = physPreset->sndAliasPrefix; - physPresetInfo->piecesSpreadFraction = physPreset->piecesSpreadFraction; - physPresetInfo->piecesUpwardVelocity = physPreset->piecesUpwardVelocity; - physPresetInfo->tempDefaultToCylinder = physPreset->tempDefaultToCylinder ? 1 : 0; - physPresetInfo->perSurfaceSndAlias = physPreset->perSurfaceSndAlias ? 1 : 0; + physPresetInfo.bulletForceScale = physPreset.bulletForceScale; + physPresetInfo.explosiveForceScale = physPreset.explosiveForceScale; + physPresetInfo.sndAliasPrefix = physPreset.sndAliasPrefix; + physPresetInfo.piecesSpreadFraction = physPreset.piecesSpreadFraction; + physPresetInfo.piecesUpwardVelocity = physPreset.piecesUpwardVelocity; + physPresetInfo.tempDefaultToCylinder = physPreset.tempDefaultToCylinder ? 1 : 0; + physPresetInfo.perSurfaceSndAlias = physPreset.perSurfaceSndAlias ? 1 : 0; } - InfoString CreateInfoString(const XAssetInfo& asset) + InfoString CreateInfoString(const PhysPreset& physPreset) { - auto* physPresetInfo = new PhysPresetInfo; - CopyToPhysPresetInfo(asset.Asset(), physPresetInfo); - - InfoStringFromPhysPresetConverter converter(physPresetInfo, - phys_preset_fields, - std::extent_v, - [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]; - }); + PhysPresetInfo physPresetInfo{}; + CopyToPhysPresetInfo(physPreset, physPresetInfo); + InfoStringFromPhysPresetConverter converter(&physPresetInfo, phys_preset_fields, std::extent_v); return converter.Convert(); } } // namespace @@ -85,7 +70,7 @@ namespace phys_preset // Only dump raw when no gdt available if (context.m_gdt) { - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); GdtEntry gdtEntry(asset.m_name, GDF_FILENAME_PHYS_PRESET); infoString.ToGdtProperties(INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); context.m_gdt->WriteEntry(gdtEntry); @@ -98,7 +83,7 @@ namespace phys_preset return; auto& stream = *assetFile; - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); const auto stringValue = infoString.ToString(INFO_STRING_PREFIX_PHYS_PRESET); stream.write(stringValue.c_str(), stringValue.size()); } diff --git a/src/ObjWriting/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5.cpp b/src/ObjWriting/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5.cpp index 6599a957..d72aecd4 100644 --- a/src/ObjWriting/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5.cpp +++ b/src/ObjWriting/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5.cpp @@ -1,14 +1,12 @@ #include "PhysPresetInfoStringDumperIW5.h" -#include "Game/IW5/InfoString/EnumStrings.h" #include "Game/IW5/InfoString/InfoStringFromStructConverter.h" #include "Game/IW5/ObjConstantsIW5.h" -#include "Game/IW5/PhysPreset/PhysPresetFields.h" +#include "Game/IW5/PhysPreset/PhysPresetFieldsIW5.h" #include "PhysPreset/PhysPresetCommon.h" -#include #include -#include +#include #include using namespace IW5; @@ -34,63 +32,49 @@ namespace } public: - InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, const cspField_t* fields, const size_t fieldCount) + : InfoStringFromStructConverter(structure, fields, fieldCount) { } }; - void CopyToPhysPresetInfo(const PhysPreset* physPreset, PhysPresetInfo* physPresetInfo) + void CopyToPhysPresetInfo(const PhysPreset& physPreset, PhysPresetInfo& physPresetInfo) { - physPresetInfo->mass = physPreset->mass; - physPresetInfo->bounce = physPreset->bounce; + physPresetInfo.mass = physPreset.mass; + physPresetInfo.bounce = physPreset.bounce; - if (physPreset->friction >= std::numeric_limits::max()) + if (physPreset.friction >= std::numeric_limits::max()) { - physPresetInfo->isFrictionInfinity = 1; - physPresetInfo->friction = 0; + physPresetInfo.isFrictionInfinity = 1; + physPresetInfo.friction = 0; } else { - physPresetInfo->isFrictionInfinity = 0; - physPresetInfo->friction = physPreset->friction; + physPresetInfo.isFrictionInfinity = 0; + physPresetInfo.friction = physPreset.friction; } - physPresetInfo->bulletForceScale = physPreset->bulletForceScale; - physPresetInfo->explosiveForceScale = physPreset->explosiveForceScale; - physPresetInfo->sndAliasPrefix = physPreset->sndAliasPrefix; - physPresetInfo->piecesSpreadFraction = physPreset->piecesSpreadFraction; - physPresetInfo->piecesUpwardVelocity = physPreset->piecesUpwardVelocity; - physPresetInfo->minMomentum = physPreset->minMomentum; - physPresetInfo->maxMomentum = physPreset->maxMomentum; - physPresetInfo->minPitch = physPreset->minPitch; - physPresetInfo->maxPitch = physPreset->maxPitch; - physPresetInfo->volumeType = physPreset->volumeType; - physPresetInfo->pitchType = physPreset->pitchType; - physPresetInfo->tempDefaultToCylinder = physPreset->tempDefaultToCylinder ? 1 : 0; - physPresetInfo->perSurfaceSndAlias = physPreset->perSurfaceSndAlias ? 1 : 0; + physPresetInfo.bulletForceScale = physPreset.bulletForceScale; + physPresetInfo.explosiveForceScale = physPreset.explosiveForceScale; + physPresetInfo.sndAliasPrefix = physPreset.sndAliasPrefix; + physPresetInfo.piecesSpreadFraction = physPreset.piecesSpreadFraction; + physPresetInfo.piecesUpwardVelocity = physPreset.piecesUpwardVelocity; + physPresetInfo.minMomentum = physPreset.minMomentum; + physPresetInfo.maxMomentum = physPreset.maxMomentum; + physPresetInfo.minPitch = physPreset.minPitch; + physPresetInfo.maxPitch = physPreset.maxPitch; + physPresetInfo.volumeType = physPreset.volumeType; + physPresetInfo.pitchType = physPreset.pitchType; + physPresetInfo.tempDefaultToCylinder = physPreset.tempDefaultToCylinder ? 1 : 0; + physPresetInfo.perSurfaceSndAlias = physPreset.perSurfaceSndAlias ? 1 : 0; } - InfoString CreateInfoString(const XAssetInfo& asset) + InfoString CreateInfoString(const PhysPreset& physPreset) { - auto* physPresetInfo = new PhysPresetInfo; - CopyToPhysPresetInfo(asset.Asset(), physPresetInfo); - - InfoStringFromPhysPresetConverter converter(physPresetInfo, - phys_preset_fields, - std::extent_v, - [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]; - }); + PhysPresetInfo physPresetInfo{}; + CopyToPhysPresetInfo(physPreset, physPresetInfo); + InfoStringFromPhysPresetConverter converter(&physPresetInfo, phys_preset_fields, std::extent_v); return converter.Convert(); } } // namespace @@ -102,7 +86,7 @@ namespace phys_preset // Only dump raw when no gdt available if (context.m_gdt) { - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); GdtEntry gdtEntry(asset.m_name, GDF_FILENAME_PHYS_PRESET); infoString.ToGdtProperties(INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); context.m_gdt->WriteEntry(gdtEntry); @@ -115,7 +99,7 @@ namespace phys_preset return; auto& stream = *assetFile; - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); const auto stringValue = infoString.ToString(INFO_STRING_PREFIX_PHYS_PRESET); stream.write(stringValue.c_str(), stringValue.size()); } diff --git a/src/ObjWriting/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4.cpp b/src/ObjWriting/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4.cpp index 29a43b12..2d7d6490 100644 --- a/src/ObjWriting/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4.cpp +++ b/src/ObjWriting/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4.cpp @@ -2,7 +2,7 @@ #include "Game/T4/InfoString/InfoStringFromStructConverter.h" #include "Game/T4/ObjConstantsT4.h" -#include "Game/T4/PhysPreset/PhysPresetFields.h" +#include "Game/T4/PhysPreset/PhysPresetFieldsT4.h" #include "PhysPreset/PhysPresetCommon.h" #include diff --git a/src/ObjWriting/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5.cpp b/src/ObjWriting/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5.cpp index 9de34a25..d8e4583a 100644 --- a/src/ObjWriting/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5.cpp +++ b/src/ObjWriting/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5.cpp @@ -2,12 +2,11 @@ #include "Game/T5/InfoString/InfoStringFromStructConverter.h" #include "Game/T5/ObjConstantsT5.h" -#include "Game/T5/PhysPreset/PhysPresetFields.h" +#include "Game/T5/PhysPreset/PhysPresetFieldsT5.h" #include "PhysPreset/PhysPresetCommon.h" #include #include -#include #include using namespace T5; @@ -23,59 +22,45 @@ namespace } public: - InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, const cspField_t* fields, const size_t fieldCount) + : InfoStringFromStructConverter(structure, fields, fieldCount) { } }; - void CopyToPhysPresetInfo(const PhysPreset* physPreset, PhysPresetInfo* physPresetInfo) + void CopyToPhysPresetInfo(const PhysPreset& physPreset, PhysPresetInfo& physPresetInfo) { - physPresetInfo->mass = std::clamp(physPreset->mass * 1000.0f, 1.0f, 2000.0f); - physPresetInfo->bounce = physPreset->bounce; + physPresetInfo.mass = std::clamp(physPreset.mass * 1000.0f, 1.0f, 2000.0f); + physPresetInfo.bounce = physPreset.bounce; - if (physPreset->friction >= MAX_FRICTION) + if (physPreset.friction >= PHYS_PRESET_MAX_FRICTION) { - physPresetInfo->isFrictionInfinity = 1; - physPresetInfo->friction = 0; + physPresetInfo.isFrictionInfinity = 1; + physPresetInfo.friction = 0; } else { - physPresetInfo->isFrictionInfinity = 0; - physPresetInfo->friction = physPreset->friction; + physPresetInfo.isFrictionInfinity = 0; + physPresetInfo.friction = physPreset.friction; } - physPresetInfo->bulletForceScale = physPreset->bulletForceScale; - physPresetInfo->explosiveForceScale = physPreset->explosiveForceScale; - physPresetInfo->piecesSpreadFraction = physPreset->piecesSpreadFraction; - physPresetInfo->piecesUpwardVelocity = physPreset->piecesUpwardVelocity; - physPresetInfo->canFloat = physPreset->canFloat; - physPresetInfo->gravityScale = std::clamp(physPreset->gravityScale, 0.01f, 10.0f); - physPresetInfo->centerOfMassOffset = physPreset->centerOfMassOffset; - physPresetInfo->buoyancyBoxMin = physPreset->buoyancyBoxMin; - physPresetInfo->buoyancyBoxMax = physPreset->buoyancyBoxMax; + physPresetInfo.bulletForceScale = physPreset.bulletForceScale; + physPresetInfo.explosiveForceScale = physPreset.explosiveForceScale; + physPresetInfo.piecesSpreadFraction = physPreset.piecesSpreadFraction; + physPresetInfo.piecesUpwardVelocity = physPreset.piecesUpwardVelocity; + physPresetInfo.canFloat = physPreset.canFloat; + physPresetInfo.gravityScale = std::clamp(physPreset.gravityScale, 0.01f, 10.0f); + physPresetInfo.centerOfMassOffset = physPreset.centerOfMassOffset; + physPresetInfo.buoyancyBoxMin = physPreset.buoyancyBoxMin; + physPresetInfo.buoyancyBoxMax = physPreset.buoyancyBoxMax; } - InfoString CreateInfoString(const XAssetInfo& asset) + InfoString CreateInfoString(const PhysPreset& physPreset) { - auto* physPresetInfo = new PhysPresetInfo; - CopyToPhysPresetInfo(asset.Asset(), physPresetInfo); - - InfoStringFromPhysPresetConverter converter(physPresetInfo, - phys_preset_fields, - std::extent_v, - [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]; - }); + PhysPresetInfo physPresetInfo{}; + CopyToPhysPresetInfo(physPreset, physPresetInfo); + InfoStringFromPhysPresetConverter converter(&physPresetInfo, phys_preset_fields, std::extent_v); return converter.Convert(); } } // namespace @@ -87,7 +72,7 @@ namespace phys_preset // Only dump raw when no gdt available if (context.m_gdt) { - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); GdtEntry gdtEntry(asset.m_name, GDF_FILENAME_PHYS_PRESET); infoString.ToGdtProperties(INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); context.m_gdt->WriteEntry(gdtEntry); @@ -100,7 +85,7 @@ namespace phys_preset return; auto& stream = *assetFile; - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); const auto stringValue = infoString.ToString(INFO_STRING_PREFIX_PHYS_PRESET); stream.write(stringValue.c_str(), stringValue.size()); } diff --git a/src/ObjWriting/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6.cpp b/src/ObjWriting/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6.cpp index ce939d96..427aa25d 100644 --- a/src/ObjWriting/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6.cpp +++ b/src/ObjWriting/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6.cpp @@ -2,12 +2,11 @@ #include "Game/T6/InfoString/InfoStringFromStructConverter.h" #include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/PhysPreset/PhysPresetFields.h" +#include "Game/T6/PhysPreset/PhysPresetFieldsT6.h" #include "PhysPreset/PhysPresetCommon.h" #include #include -#include #include using namespace T6; @@ -23,59 +22,45 @@ namespace } public: - InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure, const cspField_t* fields, const size_t fieldCount) + : InfoStringFromStructConverter(structure, fields, fieldCount) { } }; - void CopyToPhysPresetInfo(const PhysPreset* physPreset, PhysPresetInfo* physPresetInfo) + void CopyToPhysPresetInfo(const PhysPreset& physPreset, PhysPresetInfo& physPresetInfo) { - physPresetInfo->mass = std::clamp(physPreset->mass * 1000.0f, 1.0f, 2000.0f); - physPresetInfo->bounce = physPreset->bounce; + physPresetInfo.mass = std::clamp(physPreset.mass * 1000.0f, 1.0f, 2000.0f); + physPresetInfo.bounce = physPreset.bounce; - if (std::isinf(physPreset->friction)) + if (physPreset.friction >= PHYS_PRESET_MAX_FRICTION) { - physPresetInfo->isFrictionInfinity = 1; - physPresetInfo->friction = 0; + physPresetInfo.isFrictionInfinity = 1; + physPresetInfo.friction = 0; } else { - physPresetInfo->isFrictionInfinity = 0; - physPresetInfo->friction = physPreset->friction; + physPresetInfo.isFrictionInfinity = 0; + physPresetInfo.friction = physPreset.friction; } - physPresetInfo->bulletForceScale = physPreset->bulletForceScale; - physPresetInfo->explosiveForceScale = physPreset->explosiveForceScale; - physPresetInfo->piecesSpreadFraction = physPreset->piecesSpreadFraction; - physPresetInfo->piecesUpwardVelocity = physPreset->piecesUpwardVelocity; - physPresetInfo->canFloat = physPreset->canFloat; - physPresetInfo->gravityScale = std::clamp(physPreset->gravityScale, 0.01f, 10.0f); - physPresetInfo->centerOfMassOffset = physPreset->centerOfMassOffset; - physPresetInfo->buoyancyBoxMin = physPreset->buoyancyBoxMin; - physPresetInfo->buoyancyBoxMax = physPreset->buoyancyBoxMax; + physPresetInfo.bulletForceScale = physPreset.bulletForceScale; + physPresetInfo.explosiveForceScale = physPreset.explosiveForceScale; + physPresetInfo.piecesSpreadFraction = physPreset.piecesSpreadFraction; + physPresetInfo.piecesUpwardVelocity = physPreset.piecesUpwardVelocity; + physPresetInfo.canFloat = physPreset.canFloat; + physPresetInfo.gravityScale = std::clamp(physPreset.gravityScale, 0.01f, 10.0f); + physPresetInfo.centerOfMassOffset = physPreset.centerOfMassOffset; + physPresetInfo.buoyancyBoxMin = physPreset.buoyancyBoxMin; + physPresetInfo.buoyancyBoxMax = physPreset.buoyancyBoxMax; } - InfoString CreateInfoString(const XAssetInfo& asset) + InfoString CreateInfoString(const PhysPreset& physPreset) { - auto* physPresetInfo = new PhysPresetInfo; - CopyToPhysPresetInfo(asset.Asset(), physPresetInfo); - - InfoStringFromPhysPresetConverter converter(physPresetInfo, - phys_preset_fields, - std::extent_v, - [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]; - }); + PhysPresetInfo physPresetInfo{}; + CopyToPhysPresetInfo(physPreset, physPresetInfo); + InfoStringFromPhysPresetConverter converter(&physPresetInfo, phys_preset_fields, std::extent_v); return converter.Convert(); } } // namespace @@ -87,7 +72,7 @@ namespace phys_preset // Only dump raw when no gdt available if (context.m_gdt) { - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); GdtEntry gdtEntry(asset.m_name, GDF_FILENAME_PHYS_PRESET); infoString.ToGdtProperties(INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); context.m_gdt->WriteEntry(gdtEntry); @@ -100,7 +85,7 @@ namespace phys_preset return; auto& stream = *assetFile; - const auto infoString = CreateInfoString(asset); + const auto infoString = CreateInfoString(*asset.Asset()); const auto stringValue = infoString.ToString(INFO_STRING_PREFIX_PHYS_PRESET); stream.write(stringValue.c_str(), stringValue.size()); } diff --git a/test/ObjLoadingTests/Game/IW3/PhysPreset/RawLoaderPhysPresetIW3Test.cpp b/test/ObjLoadingTests/Game/IW3/PhysPreset/RawLoaderPhysPresetIW3Test.cpp new file mode 100644 index 00000000..6bfa3b7d --- /dev/null +++ b/test/ObjLoadingTests/Game/IW3/PhysPreset/RawLoaderPhysPresetIW3Test.cpp @@ -0,0 +1,46 @@ +#include "Game/IW3/PhysPreset/RawLoaderPhysPresetIW3.h" + +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace IW3; +using namespace Catch; + +namespace +{ + TEST_CASE("PhysPreset loader restores stock raw fields (IW3)", "[iw3][physpreset][system]") + { + constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\mass\1.25\bounce\0.25\friction\0.5\isFrictionInfinity\1)" + R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" + R"(\sndAliasPrefix\physics_metal)" + R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" + R"(\tempDefaultToCylinder\1)"; + + MockSearchPath loadingSearchPath; + loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); + + Zone loadingZone("LoadingZone", 0, GameId::IW3, GamePlatform::PC); + AssetCreatorCollection creatorCollection(loadingZone); + IgnoredAssetLookup ignoredAssetLookup; + AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); + const auto loader = phys_preset::CreateRawLoaderIW3(loadingZone.Memory(), loadingSearchPath, loadingZone); + const auto result = loader->CreateAsset("test_phys_preset", loadingContext); + + REQUIRE(result.HasBeenSuccessful()); + const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); + const auto* loadedPhysPreset = loadedAssetInfo->Asset(); + + REQUIRE(std::string(loadedPhysPreset->name) == "test_phys_preset"); + REQUIRE(loadedPhysPreset->mass == Approx(1.25f)); + REQUIRE(loadedPhysPreset->bounce == Approx(0.25f)); + REQUIRE(loadedPhysPreset->friction == Approx(std::numeric_limits::max())); + REQUIRE(loadedPhysPreset->bulletForceScale == Approx(0.5f)); + REQUIRE(loadedPhysPreset->explosiveForceScale == Approx(0.75f)); + REQUIRE(std::string(loadedPhysPreset->sndAliasPrefix) == "physics_metal"); + REQUIRE(loadedPhysPreset->piecesSpreadFraction == Approx(0.125f)); + REQUIRE(loadedPhysPreset->piecesUpwardVelocity == Approx(64.0f)); + REQUIRE(loadedPhysPreset->tempDefaultToCylinder == true); + } +} // namespace diff --git a/test/ObjLoadingTests/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4Test.cpp b/test/ObjLoadingTests/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4Test.cpp new file mode 100644 index 00000000..dc90e7b6 --- /dev/null +++ b/test/ObjLoadingTests/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4Test.cpp @@ -0,0 +1,47 @@ +#include "Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h" + +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace IW4; +using namespace Catch; + +namespace +{ + TEST_CASE("PhysPreset loader restores stock raw fields (IW4)", "[iw4][physpreset][system]") + { + constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\mass\1.25\bounce\0.25\friction\0.5\isFrictionInfinity\1)" + R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" + R"(\sndAliasPrefix\physics_metal)" + R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" + R"(\tempDefaultToCylinder\1\perSurfaceSndAlias\1)"; + + MockSearchPath loadingSearchPath; + loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); + + Zone loadingZone("LoadingZone", 0, GameId::IW4, GamePlatform::PC); + AssetCreatorCollection creatorCollection(loadingZone); + IgnoredAssetLookup ignoredAssetLookup; + AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); + const auto loader = phys_preset::CreateRawLoaderIW4(loadingZone.Memory(), loadingSearchPath, loadingZone); + const auto result = loader->CreateAsset("test_phys_preset", loadingContext); + + REQUIRE(result.HasBeenSuccessful()); + const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); + const auto* loadedPhysPreset = loadedAssetInfo->Asset(); + + REQUIRE(std::string(loadedPhysPreset->name) == "test_phys_preset"); + REQUIRE(loadedPhysPreset->mass == Approx(1.25f)); + REQUIRE(loadedPhysPreset->bounce == Approx(0.25f)); + REQUIRE(loadedPhysPreset->friction == Approx(std::numeric_limits::max())); + REQUIRE(loadedPhysPreset->bulletForceScale == Approx(0.5f)); + REQUIRE(loadedPhysPreset->explosiveForceScale == Approx(0.75f)); + REQUIRE(std::string(loadedPhysPreset->sndAliasPrefix) == "physics_metal"); + REQUIRE(loadedPhysPreset->piecesSpreadFraction == Approx(0.125f)); + REQUIRE(loadedPhysPreset->piecesUpwardVelocity == Approx(64.0f)); + REQUIRE(loadedPhysPreset->tempDefaultToCylinder == true); + REQUIRE(loadedPhysPreset->perSurfaceSndAlias == true); + } +} // namespace diff --git a/test/ObjLoadingTests/Game/IW5/PhysPreset/RawLoaderPhysPresetIW5Test.cpp b/test/ObjLoadingTests/Game/IW5/PhysPreset/RawLoaderPhysPresetIW5Test.cpp new file mode 100644 index 00000000..0529e2b0 --- /dev/null +++ b/test/ObjLoadingTests/Game/IW5/PhysPreset/RawLoaderPhysPresetIW5Test.cpp @@ -0,0 +1,56 @@ +#include "Game/IW5/PhysPreset/RawLoaderPhysPresetIW5.h" + +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace IW5; +using namespace Catch; + +namespace +{ + TEST_CASE("PhysPreset loader restores stock raw fields (IW5)", "[iw5][physpreset][system]") + { + constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\mass\1.25\bounce\0.25\friction\0.5\isFrictionInfinity\1)" + R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" + R"(\sndAliasPrefix\physics_metal)" + R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" + R"(\minMomentum\1.0\maxMomentum\2.0)" + R"(\minPitch\3.0\maxPitch\4.0)" + R"(\volumeType\linear\pitchType\quadratic)" + R"(\tempDefaultToCylinder\1\perSurfaceSndAlias\1)"; + + MockSearchPath loadingSearchPath; + loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); + + Zone loadingZone("LoadingZone", 0, GameId::IW5, GamePlatform::PC); + AssetCreatorCollection creatorCollection(loadingZone); + IgnoredAssetLookup ignoredAssetLookup; + AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); + const auto loader = phys_preset::CreateRawLoaderIW5(loadingZone.Memory(), loadingSearchPath, loadingZone); + const auto result = loader->CreateAsset("test_phys_preset", loadingContext); + + REQUIRE(result.HasBeenSuccessful()); + const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); + const auto* loadedPhysPreset = loadedAssetInfo->Asset(); + + REQUIRE(std::string(loadedPhysPreset->name) == "test_phys_preset"); + REQUIRE(loadedPhysPreset->mass == Approx(1.25f)); + REQUIRE(loadedPhysPreset->bounce == Approx(0.25f)); + REQUIRE(loadedPhysPreset->friction == Approx(std::numeric_limits::max())); + REQUIRE(loadedPhysPreset->bulletForceScale == Approx(0.5f)); + REQUIRE(loadedPhysPreset->explosiveForceScale == Approx(0.75f)); + REQUIRE(std::string(loadedPhysPreset->sndAliasPrefix) == "physics_metal"); + REQUIRE(loadedPhysPreset->piecesSpreadFraction == Approx(0.125f)); + REQUIRE(loadedPhysPreset->piecesUpwardVelocity == Approx(64.0f)); + REQUIRE(loadedPhysPreset->minMomentum == Approx(1.0f)); + REQUIRE(loadedPhysPreset->maxMomentum == Approx(2.0f)); + REQUIRE(loadedPhysPreset->minPitch == Approx(3.0f)); + REQUIRE(loadedPhysPreset->maxPitch == Approx(4.0f)); + REQUIRE(loadedPhysPreset->volumeType == PHYSPRESET_SCALING_LINEAR); + REQUIRE(loadedPhysPreset->pitchType == PHYSPRESET_SCALING_QUADRATIC); + REQUIRE(loadedPhysPreset->tempDefaultToCylinder == true); + REQUIRE(loadedPhysPreset->perSurfaceSndAlias == true); + } +} // namespace diff --git a/test/ObjLoadingTests/Game/T4/PhysPreset/RawLoaderPhysPresetT4Test.cpp b/test/ObjLoadingTests/Game/T4/PhysPreset/RawLoaderPhysPresetT4Test.cpp new file mode 100644 index 00000000..5a6c8b2e --- /dev/null +++ b/test/ObjLoadingTests/Game/T4/PhysPreset/RawLoaderPhysPresetT4Test.cpp @@ -0,0 +1,48 @@ +#include "Game/T4/PhysPreset/RawLoaderPhysPresetT4.h" + +#include "Game/T4/ObjConstantsT4.h" +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace T4; +using namespace Catch; + +namespace +{ + TEST_CASE("PhysPreset loader restores stock raw fields (T4)", "[t4][physpreset][system]") + { + constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\sndAliasPrefix\physics_metal)" + R"(\mass\1250\friction\0.5\isFrictionInfinity\1\bounce\0.25)" + R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" + R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" + R"(\tempDefaultToCylinder\1\canFloat\1\gravityScale\2)"; + + MockSearchPath loadingSearchPath; + loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); + + Zone loadingZone("LoadingZone", 0, GameId::T4, GamePlatform::PC); + AssetCreatorCollection creatorCollection(loadingZone); + IgnoredAssetLookup ignoredAssetLookup; + AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); + const auto loader = phys_preset::CreateRawLoaderT4(loadingZone.Memory(), loadingSearchPath, loadingZone); + const auto result = loader->CreateAsset("test_phys_preset", loadingContext); + + REQUIRE(result.HasBeenSuccessful()); + const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); + const auto* loadedPhysPreset = loadedAssetInfo->Asset(); + + REQUIRE(std::string(loadedPhysPreset->name) == "test_phys_preset"); + REQUIRE(loadedPhysPreset->mass == Approx(1.25f)); + REQUIRE(loadedPhysPreset->bounce == Approx(0.25f)); + REQUIRE(loadedPhysPreset->friction == Approx(PHYS_PRESET_MAX_FRICTION)); + REQUIRE(loadedPhysPreset->bulletForceScale == Approx(0.5f)); + REQUIRE(loadedPhysPreset->explosiveForceScale == Approx(0.75f)); + REQUIRE(std::string(loadedPhysPreset->sndAliasPrefix) == "physics_metal"); + REQUIRE(loadedPhysPreset->piecesSpreadFraction == Approx(0.125f)); + REQUIRE(loadedPhysPreset->piecesUpwardVelocity == Approx(64.0f)); + REQUIRE(loadedPhysPreset->canFloat == 1); + REQUIRE(loadedPhysPreset->gravityScale == Approx(2.0f)); + } +} // namespace diff --git a/test/ObjLoadingTests/Game/T5/PhysPreset/RawLoaderPhysPresetT5Test.cpp b/test/ObjLoadingTests/Game/T5/PhysPreset/RawLoaderPhysPresetT5Test.cpp new file mode 100644 index 00000000..75299849 --- /dev/null +++ b/test/ObjLoadingTests/Game/T5/PhysPreset/RawLoaderPhysPresetT5Test.cpp @@ -0,0 +1,58 @@ +#include "Game/T5/PhysPreset/RawLoaderPhysPresetT5.h" + +#include "Game/T5/ObjConstantsT5.h" +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace T5; +using namespace Catch; + +namespace +{ + TEST_CASE("PhysPreset loader restores stock raw fields (T5)", "[t5][physpreset][system]") + { + constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\mass\1250\bounce\0.25\friction\0.5\isFrictionInfinity\1)" + R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" + R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" + R"(\canFloat\1\gravityScale\2)" + R"(\massOffsetX\1\massOffsetY\2\massOffsetZ\3)" + R"(\buoyancyMinX\3\buoyancyMinY\4\buoyancyMinZ\5)" + R"(\buoyancyMaxX\6\buoyancyMaxY\7\buoyancyMaxZ\8)"; + + MockSearchPath loadingSearchPath; + loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); + + Zone loadingZone("LoadingZone", 0, GameId::T5, GamePlatform::PC); + AssetCreatorCollection creatorCollection(loadingZone); + IgnoredAssetLookup ignoredAssetLookup; + AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); + const auto loader = phys_preset::CreateRawLoaderT5(loadingZone.Memory(), loadingSearchPath, loadingZone); + const auto result = loader->CreateAsset("test_phys_preset", loadingContext); + + REQUIRE(result.HasBeenSuccessful()); + const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); + const auto* loadedPhysPreset = loadedAssetInfo->Asset(); + + REQUIRE(std::string(loadedPhysPreset->name) == "test_phys_preset"); + REQUIRE(loadedPhysPreset->mass == Approx(1.25f)); + REQUIRE(loadedPhysPreset->bounce == Approx(0.25f)); + REQUIRE(loadedPhysPreset->friction == Approx(PHYS_PRESET_MAX_FRICTION)); + REQUIRE(loadedPhysPreset->bulletForceScale == Approx(0.5f)); + REQUIRE(loadedPhysPreset->explosiveForceScale == Approx(0.75f)); + REQUIRE(loadedPhysPreset->piecesSpreadFraction == Approx(0.125f)); + REQUIRE(loadedPhysPreset->piecesUpwardVelocity == Approx(64.0f)); + REQUIRE(loadedPhysPreset->canFloat == 1); + REQUIRE(loadedPhysPreset->gravityScale == Approx(2.0f)); + REQUIRE(loadedPhysPreset->centerOfMassOffset.x == Approx(1.0f)); + REQUIRE(loadedPhysPreset->centerOfMassOffset.y == Approx(2.0f)); + REQUIRE(loadedPhysPreset->centerOfMassOffset.z == Approx(3.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMin.x == Approx(3.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMin.y == Approx(4.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMin.z == Approx(5.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMax.x == Approx(6.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMax.y == Approx(7.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMax.z == Approx(8.0f)); + } +} // namespace diff --git a/test/ObjLoadingTests/Game/T6/PhysPreset/RawLoaderPhysPresetT6Test.cpp b/test/ObjLoadingTests/Game/T6/PhysPreset/RawLoaderPhysPresetT6Test.cpp new file mode 100644 index 00000000..1e088adb --- /dev/null +++ b/test/ObjLoadingTests/Game/T6/PhysPreset/RawLoaderPhysPresetT6Test.cpp @@ -0,0 +1,58 @@ +#include "Game/T6/PhysPreset/RawLoaderPhysPresetT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace T6; +using namespace Catch; + +namespace +{ + TEST_CASE("PhysPreset loader restores stock raw fields (T6)", "[t6][physpreset][system]") + { + constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\mass\1250\bounce\0.25\friction\0.5\isFrictionInfinity\1)" + R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" + R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" + R"(\canFloat\1\gravityScale\2)" + R"(\massOffsetX\1\massOffsetY\2\massOffsetZ\3)" + R"(\buoyancyMinX\3\buoyancyMinY\4\buoyancyMinZ\5)" + R"(\buoyancyMaxX\6\buoyancyMaxY\7\buoyancyMaxZ\8)"; + + MockSearchPath loadingSearchPath; + loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); + + Zone loadingZone("LoadingZone", 0, GameId::T6, GamePlatform::PC); + AssetCreatorCollection creatorCollection(loadingZone); + IgnoredAssetLookup ignoredAssetLookup; + AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); + const auto loader = phys_preset::CreateRawLoaderT6(loadingZone.Memory(), loadingSearchPath, loadingZone); + const auto result = loader->CreateAsset("test_phys_preset", loadingContext); + + REQUIRE(result.HasBeenSuccessful()); + const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); + const auto* loadedPhysPreset = loadedAssetInfo->Asset(); + + REQUIRE(std::string(loadedPhysPreset->name) == "test_phys_preset"); + REQUIRE(loadedPhysPreset->mass == Approx(1.25f)); + REQUIRE(loadedPhysPreset->bounce == Approx(0.25f)); + REQUIRE(loadedPhysPreset->friction == Approx(PHYS_PRESET_MAX_FRICTION)); + REQUIRE(loadedPhysPreset->bulletForceScale == Approx(0.5f)); + REQUIRE(loadedPhysPreset->explosiveForceScale == Approx(0.75f)); + REQUIRE(loadedPhysPreset->piecesSpreadFraction == Approx(0.125f)); + REQUIRE(loadedPhysPreset->piecesUpwardVelocity == Approx(64.0f)); + REQUIRE(loadedPhysPreset->canFloat == 1); + REQUIRE(loadedPhysPreset->gravityScale == Approx(2.0f)); + REQUIRE(loadedPhysPreset->centerOfMassOffset.x == Approx(1.0f)); + REQUIRE(loadedPhysPreset->centerOfMassOffset.y == Approx(2.0f)); + REQUIRE(loadedPhysPreset->centerOfMassOffset.z == Approx(3.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMin.x == Approx(3.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMin.y == Approx(4.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMin.z == Approx(5.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMax.x == Approx(6.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMax.y == Approx(7.0f)); + REQUIRE(loadedPhysPreset->buoyancyBoxMax.z == Approx(8.0f)); + } +} // namespace diff --git a/test/ObjWritingTests/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3Test.cpp b/test/ObjWritingTests/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3Test.cpp new file mode 100644 index 00000000..a73833e5 --- /dev/null +++ b/test/ObjWritingTests/Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3Test.cpp @@ -0,0 +1,67 @@ + +#include "Game/IW3/PhysPreset/PhysPresetInfoStringDumperIW3.h" + +#include "Game/IW3/ObjConstantsIW3.h" +#include "InfoString/InfoString.h" +#include "SearchPath/MockOutputPath.h" +#include "SearchPath/MockSearchPath.h" + +#include + +using namespace IW3; + +namespace +{ + std::unique_ptr CreateTestPhysPreset() + { + auto physPreset = std::make_unique(); + + physPreset->name = "test_phys_preset"; + physPreset->mass = 1.25f; + physPreset->bounce = 0.25f; + physPreset->friction = std::numeric_limits::max(); + physPreset->bulletForceScale = 0.5f; + physPreset->explosiveForceScale = 0.75f; + physPreset->sndAliasPrefix = "physics_metal"; + physPreset->piecesSpreadFraction = 0.125f; + physPreset->piecesUpwardVelocity = 64.0f; + physPreset->tempDefaultToCylinder = true; + + return physPreset; + } + + std::string DumpPhysPreset(PhysPreset& physPreset) + { + Zone dumpingZone("DumpingZone", 0, GameId::IW3, GamePlatform::PC); + dumpingZone.m_pools.AddAsset(std::make_unique>(ASSET_TYPE_PHYSPRESET, physPreset.name, &physPreset)); + + MockSearchPath dumpingObjPath; + MockOutputPath dumpingOutput; + AssetDumpingContext dumpingContext(dumpingZone, "", dumpingOutput, dumpingObjPath, std::nullopt); + phys_preset::InfoStringDumperIW3 dumper; + dumper.Dump(dumpingContext); + + const auto* dumpedFile = dumpingOutput.GetMockedFile("physic/test_phys_preset"); + REQUIRE(dumpedFile != nullptr); + return dumpedFile->AsString(); + } + + TEST_CASE("PhysPreset dumper serializes raw fields (IW3)", "[iw3][physpreset][system]") + { + const auto testPhysPreset = CreateTestPhysPreset(); + std::istringstream dumpedStream(DumpPhysPreset(*testPhysPreset)); + + InfoString infoString; + REQUIRE(infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, dumpedStream)); + REQUIRE(infoString.GetValueForKey("mass") == "1.25"); + REQUIRE(infoString.GetValueForKey("bounce") == "0.25"); + REQUIRE(infoString.GetValueForKey("friction") == "0"); + REQUIRE(infoString.GetValueForKey("isFrictionInfinity") == "1"); + REQUIRE(infoString.GetValueForKey("bulletForceScale") == "0.5"); + REQUIRE(infoString.GetValueForKey("explosiveForceScale") == "0.75"); + REQUIRE(infoString.GetValueForKey("sndAliasPrefix") == "physics_metal"); + REQUIRE(infoString.GetValueForKey("piecesSpreadFraction") == "0.125"); + REQUIRE(infoString.GetValueForKey("piecesUpwardVelocity") == "64"); + REQUIRE(infoString.GetValueForKey("tempDefaultToCylinder") == "1"); + } +} // namespace diff --git a/test/ObjWritingTests/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4Test.cpp b/test/ObjWritingTests/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4Test.cpp new file mode 100644 index 00000000..84fd7f3c --- /dev/null +++ b/test/ObjWritingTests/Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4Test.cpp @@ -0,0 +1,69 @@ + +#include "Game/IW4/PhysPreset/PhysPresetInfoStringDumperIW4.h" + +#include "Game/IW4/ObjConstantsIW4.h" +#include "InfoString/InfoString.h" +#include "SearchPath/MockOutputPath.h" +#include "SearchPath/MockSearchPath.h" + +#include + +using namespace IW4; + +namespace +{ + std::unique_ptr CreateTestPhysPreset() + { + auto physPreset = std::make_unique(); + + physPreset->name = "test_phys_preset"; + physPreset->mass = 1.25f; + physPreset->bounce = 0.25f; + physPreset->friction = std::numeric_limits::max(); + physPreset->bulletForceScale = 0.5f; + physPreset->explosiveForceScale = 0.75f; + physPreset->sndAliasPrefix = "physics_metal"; + physPreset->piecesSpreadFraction = 0.125f; + physPreset->piecesUpwardVelocity = 64.0f; + physPreset->tempDefaultToCylinder = true; + physPreset->perSurfaceSndAlias = true; + + return physPreset; + } + + std::string DumpPhysPreset(PhysPreset& physPreset) + { + Zone dumpingZone("DumpingZone", 0, GameId::IW4, GamePlatform::PC); + dumpingZone.m_pools.AddAsset(std::make_unique>(ASSET_TYPE_PHYSPRESET, physPreset.name, &physPreset)); + + MockSearchPath dumpingObjPath; + MockOutputPath dumpingOutput; + AssetDumpingContext dumpingContext(dumpingZone, "", dumpingOutput, dumpingObjPath, std::nullopt); + phys_preset::InfoStringDumperIW4 dumper; + dumper.Dump(dumpingContext); + + const auto* dumpedFile = dumpingOutput.GetMockedFile("physic/test_phys_preset"); + REQUIRE(dumpedFile != nullptr); + return dumpedFile->AsString(); + } + + TEST_CASE("PhysPreset dumper serializes raw fields (IW4)", "[iw4][physpreset][system]") + { + const auto testPhysPreset = CreateTestPhysPreset(); + std::istringstream dumpedStream(DumpPhysPreset(*testPhysPreset)); + + InfoString infoString; + REQUIRE(infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, dumpedStream)); + REQUIRE(infoString.GetValueForKey("mass") == "1.25"); + REQUIRE(infoString.GetValueForKey("bounce") == "0.25"); + REQUIRE(infoString.GetValueForKey("friction") == "0"); + REQUIRE(infoString.GetValueForKey("isFrictionInfinity") == "1"); + REQUIRE(infoString.GetValueForKey("bulletForceScale") == "0.5"); + REQUIRE(infoString.GetValueForKey("explosiveForceScale") == "0.75"); + REQUIRE(infoString.GetValueForKey("sndAliasPrefix") == "physics_metal"); + REQUIRE(infoString.GetValueForKey("piecesSpreadFraction") == "0.125"); + REQUIRE(infoString.GetValueForKey("piecesUpwardVelocity") == "64"); + REQUIRE(infoString.GetValueForKey("tempDefaultToCylinder") == "1"); + REQUIRE(infoString.GetValueForKey("perSurfaceSndAlias") == "1"); + } +} // namespace diff --git a/test/ObjWritingTests/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5Test.cpp b/test/ObjWritingTests/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5Test.cpp new file mode 100644 index 00000000..968727ff --- /dev/null +++ b/test/ObjWritingTests/Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5Test.cpp @@ -0,0 +1,81 @@ + +#include "Game/IW5/PhysPreset/PhysPresetInfoStringDumperIW5.h" + +#include "Game/IW5/ObjConstantsIW5.h" +#include "InfoString/InfoString.h" +#include "SearchPath/MockOutputPath.h" +#include "SearchPath/MockSearchPath.h" + +#include + +using namespace IW5; + +namespace +{ + std::unique_ptr CreateTestPhysPreset() + { + auto physPreset = std::make_unique(); + + physPreset->name = "test_phys_preset"; + physPreset->mass = 1.25f; + physPreset->bounce = 0.25f; + physPreset->friction = std::numeric_limits::max(); + physPreset->bulletForceScale = 0.5f; + physPreset->explosiveForceScale = 0.75f; + physPreset->sndAliasPrefix = "physics_metal"; + physPreset->piecesSpreadFraction = 0.125f; + physPreset->piecesUpwardVelocity = 64.0f; + physPreset->minMomentum = 1.5f; + physPreset->maxMomentum = 2.5f; + physPreset->minPitch = 3.5f; + physPreset->maxPitch = 4.5f; + physPreset->volumeType = PHYSPRESET_SCALING_LINEAR; + physPreset->pitchType = PHYSPRESET_SCALING_QUADRATIC; + physPreset->tempDefaultToCylinder = true; + physPreset->perSurfaceSndAlias = true; + + return physPreset; + } + + std::string DumpPhysPreset(PhysPreset& physPreset) + { + Zone dumpingZone("DumpingZone", 0, GameId::IW5, GamePlatform::PC); + dumpingZone.m_pools.AddAsset(std::make_unique>(ASSET_TYPE_PHYSPRESET, physPreset.name, &physPreset)); + + MockSearchPath dumpingObjPath; + MockOutputPath dumpingOutput; + AssetDumpingContext dumpingContext(dumpingZone, "", dumpingOutput, dumpingObjPath, std::nullopt); + phys_preset::InfoStringDumperIW5 dumper; + dumper.Dump(dumpingContext); + + const auto* dumpedFile = dumpingOutput.GetMockedFile("physic/test_phys_preset"); + REQUIRE(dumpedFile != nullptr); + return dumpedFile->AsString(); + } + + TEST_CASE("PhysPreset dumper serializes raw fields (IW5)", "[iw5][physpreset][system]") + { + const auto testPhysPreset = CreateTestPhysPreset(); + std::istringstream dumpedStream(DumpPhysPreset(*testPhysPreset)); + + InfoString infoString; + REQUIRE(infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, dumpedStream)); + REQUIRE(infoString.GetValueForKey("mass") == "1.25"); + REQUIRE(infoString.GetValueForKey("bounce") == "0.25"); + REQUIRE(infoString.GetValueForKey("friction") == "0"); + REQUIRE(infoString.GetValueForKey("isFrictionInfinity") == "1"); + REQUIRE(infoString.GetValueForKey("bulletForceScale") == "0.5"); + REQUIRE(infoString.GetValueForKey("explosiveForceScale") == "0.75"); + REQUIRE(infoString.GetValueForKey("sndAliasPrefix") == "physics_metal"); + REQUIRE(infoString.GetValueForKey("piecesSpreadFraction") == "0.125"); + REQUIRE(infoString.GetValueForKey("piecesUpwardVelocity") == "64"); + REQUIRE(infoString.GetValueForKey("minMomentum") == "1.5"); + REQUIRE(infoString.GetValueForKey("maxMomentum") == "2.5"); + REQUIRE(infoString.GetValueForKey("minPitch") == "3.5"); + REQUIRE(infoString.GetValueForKey("maxPitch") == "4.5"); + REQUIRE(infoString.GetValueForKey("volumeType") == "linear"); + REQUIRE(infoString.GetValueForKey("pitchType") == "quadratic"); + REQUIRE(infoString.GetValueForKey("tempDefaultToCylinder") == "1"); + REQUIRE(infoString.GetValueForKey("perSurfaceSndAlias") == "1"); + } +} // namespace diff --git a/test/SystemTests/Game/T4/PhysPresetT4.cpp b/test/ObjWritingTests/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4Test.cpp similarity index 52% rename from test/SystemTests/Game/T4/PhysPresetT4.cpp rename to test/ObjWritingTests/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4Test.cpp index eff3ee12..63b527f9 100644 --- a/test/SystemTests/Game/T4/PhysPresetT4.cpp +++ b/test/ObjWritingTests/Game/T4/PhysPreset/PhysPresetInfoStringDumperT4Test.cpp @@ -1,37 +1,33 @@ -#include "Game/T4/ObjConstantsT4.h" + #include "Game/T4/PhysPreset/PhysPresetInfoStringDumperT4.h" -#include "Game/T4/PhysPreset/RawLoaderPhysPresetT4.h" + +#include "Game/T4/ObjConstantsT4.h" #include "InfoString/InfoString.h" #include "SearchPath/MockOutputPath.h" #include "SearchPath/MockSearchPath.h" -#include "ZoneLoading.h" #include -#include -#include -#include using namespace T4; namespace { - constexpr auto PHYS_PRESET_NAME = "test_phys_preset"; - constexpr auto SOUND_ALIAS_PREFIX = "physics_metal"; - std::unique_ptr CreateTestPhysPreset() { auto physPreset = std::make_unique(); - physPreset->name = PHYS_PRESET_NAME; + + physPreset->name = "test_phys_preset"; physPreset->mass = 1.25f; physPreset->bounce = 0.25f; physPreset->friction = PHYS_PRESET_MAX_FRICTION; physPreset->bulletForceScale = 0.5f; physPreset->explosiveForceScale = 0.75f; - physPreset->sndAliasPrefix = SOUND_ALIAS_PREFIX; + physPreset->sndAliasPrefix = "physics_metal"; physPreset->piecesSpreadFraction = 0.125f; physPreset->piecesUpwardVelocity = 64.0f; physPreset->canFloat = 1; physPreset->gravityScale = 2.0f; + return physPreset; } @@ -64,7 +60,7 @@ namespace REQUIRE(infoString.GetValueForKey("isFrictionInfinity") == "1"); REQUIRE(infoString.GetValueForKey("bulletForceScale") == "0.5"); REQUIRE(infoString.GetValueForKey("explosiveForceScale") == "0.75"); - REQUIRE(infoString.GetValueForKey("sndAliasPrefix") == SOUND_ALIAS_PREFIX); + REQUIRE(infoString.GetValueForKey("sndAliasPrefix") == "physics_metal"); REQUIRE(infoString.GetValueForKey("piecesSpreadFraction") == "0.125"); REQUIRE(infoString.GetValueForKey("piecesUpwardVelocity") == "64"); REQUIRE(infoString.GetValueForKey("canFloat") == "1"); @@ -74,39 +70,4 @@ namespace infoString.GetValueForKey("tempDefaultToCylinder", &foundObsoleteField); REQUIRE_FALSE(foundObsoleteField); } - - TEST_CASE("PhysPreset loader restores stock raw fields (T4)", "[t4][physpreset][system]") - { - constexpr auto RAW_PHYS_PRESET = R"(PHYSIC\sndAliasPrefix\physics_metal)" - R"(\mass\1250\friction\0.5\isFrictionInfinity\1\bounce\0.25)" - R"(\bulletForceScale\0.5\explosiveForceScale\0.75)" - R"(\piecesSpreadFraction\0.125\piecesUpwardVelocity\64)" - R"(\tempDefaultToCylinder\1\canFloat\1\gravityScale\2)"; - - MockSearchPath loadingSearchPath; - loadingSearchPath.AddFileData("physic/test_phys_preset", RAW_PHYS_PRESET); - - Zone loadingZone("LoadingZone", 0, GameId::T4, GamePlatform::PC); - AssetCreatorCollection creatorCollection(loadingZone); - IgnoredAssetLookup ignoredAssetLookup; - AssetCreationContext loadingContext(loadingZone, &creatorCollection, &ignoredAssetLookup); - const auto loader = phys_preset::CreateRawLoaderT4(loadingZone.Memory(), loadingSearchPath, loadingZone); - const auto result = loader->CreateAsset(PHYS_PRESET_NAME, loadingContext); - - REQUIRE(result.HasBeenSuccessful()); - const auto* loadedAssetInfo = reinterpret_cast*>(result.GetAssetInfo()); - const auto* loadedPhysPreset = loadedAssetInfo->Asset(); - - REQUIRE(std::string(loadedPhysPreset->name) == PHYS_PRESET_NAME); - REQUIRE(loadedPhysPreset->mass == 1.25f); - REQUIRE(loadedPhysPreset->bounce == 0.25f); - REQUIRE(loadedPhysPreset->friction == PHYS_PRESET_MAX_FRICTION); - REQUIRE(loadedPhysPreset->bulletForceScale == 0.5f); - REQUIRE(loadedPhysPreset->explosiveForceScale == 0.75f); - REQUIRE(std::string(loadedPhysPreset->sndAliasPrefix) == SOUND_ALIAS_PREFIX); - REQUIRE(loadedPhysPreset->piecesSpreadFraction == 0.125f); - REQUIRE(loadedPhysPreset->piecesUpwardVelocity == 64.0f); - REQUIRE(loadedPhysPreset->canFloat == 1); - REQUIRE(loadedPhysPreset->gravityScale == 2.0f); - } } // namespace diff --git a/test/ObjWritingTests/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5Test.cpp b/test/ObjWritingTests/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5Test.cpp new file mode 100644 index 00000000..8cad1ed0 --- /dev/null +++ b/test/ObjWritingTests/Game/T5/PhysPreset/PhysPresetInfoStringDumperT5Test.cpp @@ -0,0 +1,87 @@ + +#include "Game/T5/PhysPreset/PhysPresetInfoStringDumperT5.h" + +#include "Game/T5/ObjConstantsT5.h" +#include "InfoString/InfoString.h" +#include "SearchPath/MockOutputPath.h" +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace T5; +using namespace Catch; + +namespace +{ + std::unique_ptr CreateTestPhysPreset() + { + auto physPreset = std::make_unique(); + + physPreset->name = "test_phys_preset"; + physPreset->mass = 1.25f; + physPreset->bounce = 0.25f; + physPreset->friction = PHYS_PRESET_MAX_FRICTION; + physPreset->bulletForceScale = 0.5f; + physPreset->explosiveForceScale = 0.75f; + physPreset->piecesSpreadFraction = 0.125f; + physPreset->piecesUpwardVelocity = 64.0f; + physPreset->canFloat = 1; + physPreset->gravityScale = 2.0f; + physPreset->centerOfMassOffset.x = 1.5f; + physPreset->centerOfMassOffset.y = 2.5f; + physPreset->centerOfMassOffset.z = 3.5f; + physPreset->buoyancyBoxMin.x = 4.5f; + physPreset->buoyancyBoxMin.y = 5.5f; + physPreset->buoyancyBoxMin.z = 6.5f; + physPreset->buoyancyBoxMax.x = 7.5f; + physPreset->buoyancyBoxMax.y = 8.5f; + physPreset->buoyancyBoxMax.z = 9.5f; + + return physPreset; + } + + std::string DumpPhysPreset(PhysPreset& physPreset) + { + Zone dumpingZone("DumpingZone", 0, GameId::T5, GamePlatform::PC); + dumpingZone.m_pools.AddAsset(std::make_unique>(ASSET_TYPE_PHYSPRESET, physPreset.name, &physPreset)); + + MockSearchPath dumpingObjPath; + MockOutputPath dumpingOutput; + AssetDumpingContext dumpingContext(dumpingZone, "", dumpingOutput, dumpingObjPath, std::nullopt); + phys_preset::InfoStringDumperT5 dumper; + dumper.Dump(dumpingContext); + + const auto* dumpedFile = dumpingOutput.GetMockedFile("physic/test_phys_preset"); + REQUIRE(dumpedFile != nullptr); + return dumpedFile->AsString(); + } + + TEST_CASE("PhysPreset dumper serializes raw fields (T5)", "[t5][physpreset][system]") + { + const auto testPhysPreset = CreateTestPhysPreset(); + std::istringstream dumpedStream(DumpPhysPreset(*testPhysPreset)); + + InfoString infoString; + REQUIRE(infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, dumpedStream)); + REQUIRE(infoString.GetValueForKey("mass") == "1250"); + REQUIRE(infoString.GetValueForKey("bounce") == "0.25"); + REQUIRE(infoString.GetValueForKey("friction") == "0"); + REQUIRE(infoString.GetValueForKey("isFrictionInfinity") == "1"); + REQUIRE(infoString.GetValueForKey("bulletForceScale") == "0.5"); + REQUIRE(infoString.GetValueForKey("explosiveForceScale") == "0.75"); + REQUIRE(infoString.GetValueForKey("piecesSpreadFraction") == "0.125"); + REQUIRE(infoString.GetValueForKey("piecesUpwardVelocity") == "64"); + REQUIRE(infoString.GetValueForKey("canFloat") == "1"); + REQUIRE(infoString.GetValueForKey("gravityScale") == "2"); + REQUIRE(infoString.GetValueForKey("massOffsetX") == "1.5"); + REQUIRE(infoString.GetValueForKey("massOffsetY") == "2.5"); + REQUIRE(infoString.GetValueForKey("massOffsetZ") == "3.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMinX") == "4.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMinY") == "5.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMinZ") == "6.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMaxX") == "7.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMaxY") == "8.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMaxZ") == "9.5"); + } +} // namespace diff --git a/test/ObjWritingTests/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6Test.cpp b/test/ObjWritingTests/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6Test.cpp new file mode 100644 index 00000000..4ff2e751 --- /dev/null +++ b/test/ObjWritingTests/Game/T6/PhysPreset/PhysPresetInfoStringDumperT6Test.cpp @@ -0,0 +1,87 @@ + +#include "Game/T6/PhysPreset/PhysPresetInfoStringDumperT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "InfoString/InfoString.h" +#include "SearchPath/MockOutputPath.h" +#include "SearchPath/MockSearchPath.h" + +#include +#include + +using namespace T6; +using namespace Catch; + +namespace +{ + std::unique_ptr CreateTestPhysPreset() + { + auto physPreset = std::make_unique(); + + physPreset->name = "test_phys_preset"; + physPreset->mass = 1.25f; + physPreset->bounce = 0.25f; + physPreset->friction = PHYS_PRESET_MAX_FRICTION; + physPreset->bulletForceScale = 0.5f; + physPreset->explosiveForceScale = 0.75f; + physPreset->piecesSpreadFraction = 0.125f; + physPreset->piecesUpwardVelocity = 64.0f; + physPreset->canFloat = 1; + physPreset->gravityScale = 2.0f; + physPreset->centerOfMassOffset.x = 1.5f; + physPreset->centerOfMassOffset.y = 2.5f; + physPreset->centerOfMassOffset.z = 3.5f; + physPreset->buoyancyBoxMin.x = 4.5f; + physPreset->buoyancyBoxMin.y = 5.5f; + physPreset->buoyancyBoxMin.z = 6.5f; + physPreset->buoyancyBoxMax.x = 7.5f; + physPreset->buoyancyBoxMax.y = 8.5f; + physPreset->buoyancyBoxMax.z = 9.5f; + + return physPreset; + } + + std::string DumpPhysPreset(PhysPreset& physPreset) + { + Zone dumpingZone("DumpingZone", 0, GameId::T6, GamePlatform::PC); + dumpingZone.m_pools.AddAsset(std::make_unique>(ASSET_TYPE_PHYSPRESET, physPreset.name, &physPreset)); + + MockSearchPath dumpingObjPath; + MockOutputPath dumpingOutput; + AssetDumpingContext dumpingContext(dumpingZone, "", dumpingOutput, dumpingObjPath, std::nullopt); + phys_preset::InfoStringDumperT6 dumper; + dumper.Dump(dumpingContext); + + const auto* dumpedFile = dumpingOutput.GetMockedFile("physic/test_phys_preset"); + REQUIRE(dumpedFile != nullptr); + return dumpedFile->AsString(); + } + + TEST_CASE("PhysPreset dumper serializes raw fields (T6)", "[t6][physpreset][system]") + { + const auto testPhysPreset = CreateTestPhysPreset(); + std::istringstream dumpedStream(DumpPhysPreset(*testPhysPreset)); + + InfoString infoString; + REQUIRE(infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, dumpedStream)); + REQUIRE(infoString.GetValueForKey("mass") == "1250"); + REQUIRE(infoString.GetValueForKey("bounce") == "0.25"); + REQUIRE(infoString.GetValueForKey("friction") == "0"); + REQUIRE(infoString.GetValueForKey("isFrictionInfinity") == "1"); + REQUIRE(infoString.GetValueForKey("bulletForceScale") == "0.5"); + REQUIRE(infoString.GetValueForKey("explosiveForceScale") == "0.75"); + REQUIRE(infoString.GetValueForKey("piecesSpreadFraction") == "0.125"); + REQUIRE(infoString.GetValueForKey("piecesUpwardVelocity") == "64"); + REQUIRE(infoString.GetValueForKey("canFloat") == "1"); + REQUIRE(infoString.GetValueForKey("gravityScale") == "2"); + REQUIRE(infoString.GetValueForKey("massOffsetX") == "1.5"); + REQUIRE(infoString.GetValueForKey("massOffsetY") == "2.5"); + REQUIRE(infoString.GetValueForKey("massOffsetZ") == "3.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMinX") == "4.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMinY") == "5.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMinZ") == "6.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMaxX") == "7.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMaxY") == "8.5"); + REQUIRE(infoString.GetValueForKey("buoyancyMaxZ") == "9.5"); + } +} // namespace