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
@@ -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 <algorithm>
#include <cassert>
#include <cstring>
#include <format>
#include <iostream>
#include <limits>
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<AssetPhysPreset>& 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>();
physPreset->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
InfoStringToPhysPresetConverter converter(
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
PhysPresetInfo physPresetInfo{};
InfoStringToPhysPresetConverter converter(infoString,
physPresetInfo,
m_zone.m_script_strings,
m_memory,
context,
registration,
phys_preset_fields,
std::extent_v<decltype(phys_preset_fields)>);
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)));
}
@@ -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 <algorithm>
#include <cassert>
#include <cstring>
#include <format>
#include <iostream>
#include <limits>
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<AssetPhysPreset>& 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>();
physPreset->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
InfoStringToPhysPresetConverter converter(
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
PhysPresetInfo physPresetInfo{};
InfoStringToPhysPresetConverter converter(infoString,
physPresetInfo,
m_zone.m_script_strings,
m_memory,
context,
registration,
phys_preset_fields,
std::extent_v<decltype(phys_preset_fields)>);
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)));
}
@@ -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 <cassert>
#include <cstring>
#include <limits>
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<AssetPhysPreset>& 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>();
physPreset->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
InfoStringToPhysPresetConverter converter(
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
PhysPresetInfo physPresetInfo{};
InfoStringToPhysPresetConverter converter(infoString,
physPresetInfo,
m_zone.m_script_strings,
m_memory,
context,
registration,
phys_preset_fields,
std::extent_v<decltype(phys_preset_fields)>);
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)));
}
@@ -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"
@@ -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 <algorithm>
#include <cassert>
#include <cstring>
#include <format>
#include <iostream>
#include <limits>
#include <type_traits>
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<AssetPhysPreset> registration(assetName, physPreset);
PhysPresetInfo physPresetInfo;
memset(&physPresetInfo, 0, sizeof(physPresetInfo));
PhysPresetInfo physPresetInfo{};
InfoStringToPhysPresetConverter converter(infoString,
physPresetInfo,
m_zone.m_script_strings,
@@ -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 <algorithm>
#include <cassert>
#include <cstring>
#include <format>
#include <iostream>
#include <limits>
#include <type_traits>
using namespace T6;
@@ -45,7 +43,7 @@ namespace
physPreset.bounce = physPresetInfo.bounce;
if (physPresetInfo.isFrictionInfinity != 0)
physPreset.friction = std::numeric_limits<float>::infinity();
physPreset.friction = PHYS_PRESET_MAX_FRICTION;
else
physPreset.friction = physPresetInfo.friction;
@@ -76,8 +74,7 @@ namespace phys_preset
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
PhysPresetInfo physPresetInfo;
memset(&physPresetInfo, 0, sizeof(physPresetInfo));
PhysPresetInfo physPresetInfo{};
InfoStringToPhysPresetConverter converter(infoString,
physPresetInfo,
m_zone.m_script_strings,