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
@@ -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 <algorithm>
#include <cassert>
#include <cmath>
#include <limits>
#include <type_traits>
using namespace IW5;
@@ -34,63 +32,49 @@ namespace
}
public:
InfoStringFromPhysPresetConverter(const PhysPresetInfo* structure,
const cspField_t* fields,
const size_t fieldCount,
std::function<std::string(scr_string_t)> 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<float>::max())
if (physPreset.friction >= std::numeric_limits<float>::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<PhysPreset>& asset)
InfoString CreateInfoString(const PhysPreset& physPreset)
{
auto* physPresetInfo = new PhysPresetInfo;
CopyToPhysPresetInfo(asset.Asset(), physPresetInfo);
InfoStringFromPhysPresetConverter converter(physPresetInfo,
phys_preset_fields,
std::extent_v<decltype(phys_preset_fields)>,
[asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset.m_zone->m_script_strings.Count());
if (scrStr >= asset.m_zone->m_script_strings.Count())
return "";
return asset.m_zone->m_script_strings[scrStr];
});
PhysPresetInfo physPresetInfo{};
CopyToPhysPresetInfo(physPreset, physPresetInfo);
InfoStringFromPhysPresetConverter converter(&physPresetInfo, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
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());
}