mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-26 18:00:38 +00:00
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:
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
inline const char* szPhysPresetScalingNames[]{
|
||||
"linear",
|
||||
"quadratic",
|
||||
};
|
||||
} // namespace IW5
|
||||
+7
-1
@@ -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<decltype(szPhysPresetScalingNames)> == PHYSPRESET_SCALING_COUNT);
|
||||
} // namespace IW5
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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 },
|
||||
@@ -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,
|
||||
|
||||
@@ -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 <cassert>
|
||||
@@ -22,56 +22,42 @@ 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->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<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
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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 <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace IW4;
|
||||
@@ -23,57 +22,43 @@ 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->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<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
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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 <algorithm>
|
||||
|
||||
@@ -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 <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T5;
|
||||
@@ -23,59 +22,45 @@ 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 = 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<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
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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 <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T6;
|
||||
@@ -23,59 +22,45 @@ 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 = 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<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
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user