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
This commit is contained in:
Jan Laupetin
2026-07-22 21:08:36 +02:00
committed by GitHub
parent 37bb67a3a5
commit 04b6b5b4bf
33 changed files with 916 additions and 329 deletions
@@ -0,0 +1,46 @@
#include "Game/IW3/PhysPreset/RawLoaderPhysPresetIW3.h"
#include "SearchPath/MockSearchPath.h"
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
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<XAssetInfo<PhysPreset>*>(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<float>::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
@@ -0,0 +1,47 @@
#include "Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h"
#include "SearchPath/MockSearchPath.h"
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
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<XAssetInfo<PhysPreset>*>(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<float>::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
@@ -0,0 +1,56 @@
#include "Game/IW5/PhysPreset/RawLoaderPhysPresetIW5.h"
#include "SearchPath/MockSearchPath.h"
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
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<XAssetInfo<PhysPreset>*>(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<float>::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
@@ -0,0 +1,48 @@
#include "Game/T4/PhysPreset/RawLoaderPhysPresetT4.h"
#include "Game/T4/ObjConstantsT4.h"
#include "SearchPath/MockSearchPath.h"
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
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<XAssetInfo<PhysPreset>*>(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
@@ -0,0 +1,58 @@
#include "Game/T5/PhysPreset/RawLoaderPhysPresetT5.h"
#include "Game/T5/ObjConstantsT5.h"
#include "SearchPath/MockSearchPath.h"
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
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<XAssetInfo<PhysPreset>*>(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
@@ -0,0 +1,58 @@
#include "Game/T6/PhysPreset/RawLoaderPhysPresetT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "SearchPath/MockSearchPath.h"
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
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<XAssetInfo<PhysPreset>*>(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
@@ -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 <catch2/catch_test_macros.hpp>
using namespace IW3;
namespace
{
std::unique_ptr<PhysPreset> CreateTestPhysPreset()
{
auto physPreset = std::make_unique<PhysPreset>();
physPreset->name = "test_phys_preset";
physPreset->mass = 1.25f;
physPreset->bounce = 0.25f;
physPreset->friction = std::numeric_limits<float>::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<XAssetInfo<PhysPreset>>(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
@@ -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 <catch2/catch_test_macros.hpp>
using namespace IW4;
namespace
{
std::unique_ptr<PhysPreset> CreateTestPhysPreset()
{
auto physPreset = std::make_unique<PhysPreset>();
physPreset->name = "test_phys_preset";
physPreset->mass = 1.25f;
physPreset->bounce = 0.25f;
physPreset->friction = std::numeric_limits<float>::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<XAssetInfo<PhysPreset>>(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
@@ -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 <catch2/catch_test_macros.hpp>
using namespace IW5;
namespace
{
std::unique_ptr<PhysPreset> CreateTestPhysPreset()
{
auto physPreset = std::make_unique<PhysPreset>();
physPreset->name = "test_phys_preset";
physPreset->mass = 1.25f;
physPreset->bounce = 0.25f;
physPreset->friction = std::numeric_limits<float>::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<XAssetInfo<PhysPreset>>(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
@@ -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 <catch2/catch_test_macros.hpp>
#include <memory>
#include <sstream>
#include <string>
using namespace T4;
namespace
{
constexpr auto PHYS_PRESET_NAME = "test_phys_preset";
constexpr auto SOUND_ALIAS_PREFIX = "physics_metal";
std::unique_ptr<PhysPreset> CreateTestPhysPreset()
{
auto physPreset = std::make_unique<PhysPreset>();
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<XAssetInfo<PhysPreset>*>(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
@@ -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 <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
using namespace T5;
using namespace Catch;
namespace
{
std::unique_ptr<PhysPreset> CreateTestPhysPreset()
{
auto physPreset = std::make_unique<PhysPreset>();
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<XAssetInfo<PhysPreset>>(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
@@ -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 <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
using namespace T6;
using namespace Catch;
namespace
{
std::unique_ptr<PhysPreset> CreateTestPhysPreset()
{
auto physPreset = std::make_unique<PhysPreset>();
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<XAssetInfo<PhysPreset>>(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