2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-05-12 21:31:43 +00:00

Merge pull request #788 from Laupetin/fix/iw4-physpreset-clamping

fix: iw4 physpreset clamping
This commit is contained in:
Jan
2026-05-03 16:32:48 +02:00
committed by GitHub
6 changed files with 24 additions and 6 deletions
+1
View File
@@ -206,6 +206,7 @@ namespace IW5
float mass;
float bounce;
float friction;
int isFrictionInfinity;
float bulletForceScale;
float explosiveForceScale;
const char* sndAliasPrefix;
@@ -8,6 +8,7 @@ namespace IW5
{"mass", offsetof(PhysPresetInfo, mass), CSPFT_FLOAT },
{"bounce", offsetof(PhysPresetInfo, bounce), CSPFT_FLOAT },
{"friction", offsetof(PhysPresetInfo, friction), CSPFT_FLOAT },
{"isFrictionInfinity", offsetof(PhysPresetInfo, isFrictionInfinity), CSPFT_QBOOLEAN},
{"bulletForceScale", offsetof(PhysPresetInfo, bulletForceScale), CSPFT_FLOAT },
{"explosiveForceScale", offsetof(PhysPresetInfo, explosiveForceScale), CSPFT_FLOAT },
{"sndAliasPrefix", offsetof(PhysPresetInfo, sndAliasPrefix), CSPFT_STRING },
@@ -41,11 +41,11 @@ namespace
void CopyFromPhysPresetInfo(const PhysPresetInfo& physPresetInfo, PhysPreset& physPreset)
{
physPreset.mass = std::clamp(physPresetInfo.mass, 1.0f, 2000.0f) * 0.001f;
physPreset.mass = physPresetInfo.mass;
physPreset.bounce = physPresetInfo.bounce;
if (physPresetInfo.isFrictionInfinity != 0)
physPreset.friction = std::numeric_limits<float>::infinity();
physPreset.friction = std::numeric_limits<float>::max();
else
physPreset.friction = physPresetInfo.friction;
@@ -48,7 +48,12 @@ namespace
{
physPreset.mass = physPresetInfo.mass;
physPreset.bounce = physPresetInfo.bounce;
physPreset.friction = physPresetInfo.friction;
if (physPresetInfo.isFrictionInfinity != 0)
physPreset.friction = std::numeric_limits<float>::max();
else
physPreset.friction = physPresetInfo.friction;
physPreset.bulletForceScale = physPresetInfo.bulletForceScale;
physPreset.explosiveForceScale = physPresetInfo.explosiveForceScale;
physPreset.sndAliasPrefix = physPresetInfo.sndAliasPrefix;
@@ -34,10 +34,10 @@ namespace
void CopyToPhysPresetInfo(const PhysPreset* physPreset, PhysPresetInfo* physPresetInfo)
{
physPresetInfo->mass = std::clamp(physPreset->mass * 1000.0f, 1.0f, 2000.0f);
physPresetInfo->mass = physPreset->mass;
physPresetInfo->bounce = physPreset->bounce;
if (std::isinf(physPreset->friction))
if (physPreset->friction >= std::numeric_limits<float>::max())
{
physPresetInfo->isFrictionInfinity = 1;
physPresetInfo->friction = 0;
@@ -47,7 +47,18 @@ namespace
{
physPresetInfo->mass = physPreset->mass;
physPresetInfo->bounce = physPreset->bounce;
physPresetInfo->friction = physPreset->friction;
if (physPreset->friction >= std::numeric_limits<float>::max())
{
physPresetInfo->isFrictionInfinity = 1;
physPresetInfo->friction = 0;
}
else
{
physPresetInfo->isFrictionInfinity = 0;
physPresetInfo->friction = physPreset->friction;
}
physPresetInfo->bulletForceScale = physPreset->bulletForceScale;
physPresetInfo->explosiveForceScale = physPreset->explosiveForceScale;
physPresetInfo->sndAliasPrefix = physPreset->sndAliasPrefix;