diff --git a/src/ObjCommon/PhysConstraints/PhysConstraintsCommon.cpp b/src/ObjCommon/PhysConstraints/PhysConstraintsCommon.cpp new file mode 100644 index 00000000..222a2615 --- /dev/null +++ b/src/ObjCommon/PhysConstraints/PhysConstraintsCommon.cpp @@ -0,0 +1,11 @@ +#include "PhysConstraintsCommon.h" + +#include + +namespace phys_constraints +{ + std::string GetFileNameForAssetName(const std::string& assetName) + { + return std::format("physconstraints/{}", assetName); + } +} // namespace phys_constraints diff --git a/src/ObjCommon/PhysConstraints/PhysConstraintsCommon.h b/src/ObjCommon/PhysConstraints/PhysConstraintsCommon.h new file mode 100644 index 00000000..90ccfb1c --- /dev/null +++ b/src/ObjCommon/PhysConstraints/PhysConstraintsCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace phys_constraints +{ + std::string GetFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp b/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp index 607a3c82..0555c180 100644 --- a/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp +++ b/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp @@ -4,6 +4,7 @@ #include "Game/T6/T6.h" #include "InfoString/InfoString.h" #include "InfoStringLoaderPhysConstraintsT6.h" +#include "PhysConstraints/PhysConstraintsCommon.h" #include #include @@ -24,7 +25,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = std::format("physconstraints/{}", assetName); + const auto fileName = phys_constraints::GetFileNameForAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); diff --git a/src/ObjWriting/Game/T5/ObjWriterT5.cpp b/src/ObjWriting/Game/T5/ObjWriterT5.cpp index 1660e0d1..b12857e8 100644 --- a/src/ObjWriting/Game/T5/ObjWriterT5.cpp +++ b/src/ObjWriting/Game/T5/ObjWriterT5.cpp @@ -6,7 +6,6 @@ #include "Image/ImageDumperT5.h" #include "Localize/LocalizeDumperT5.h" #include "ObjWriting.h" -#include "PhysConstraints/AssetDumperPhysConstraints.h" #include "PhysPreset/AssetDumperPhysPreset.h" #include "RawFile/AssetDumperRawFile.h" #include "Sound/AssetDumperSndBank.h" diff --git a/src/ObjWriting/Game/T5/PhysConstraints/AssetDumperPhysConstraints.cpp b/src/ObjWriting/Game/T5/PhysConstraints/AssetDumperPhysConstraints.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjWriting/Game/T5/PhysConstraints/AssetDumperPhysConstraints.h b/src/ObjWriting/Game/T5/PhysConstraints/AssetDumperPhysConstraints.h deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjWriting/Game/T6/ObjWriterT6.cpp b/src/ObjWriting/Game/T6/ObjWriterT6.cpp index c32e8ac0..3aeaf091 100644 --- a/src/ObjWriting/Game/T6/ObjWriterT6.cpp +++ b/src/ObjWriting/Game/T6/ObjWriterT6.cpp @@ -9,7 +9,7 @@ #include "Localize/LocalizeDumperT6.h" #include "Maps/MapEntsDumperT6.h" #include "ObjWriting.h" -#include "PhysConstraints/AssetDumperPhysConstraints.h" +#include "PhysConstraints/PhysConstraintsInfoStringDumperT6.h" #include "PhysPreset/AssetDumperPhysPreset.h" #include "Qdb/AssetDumperQdb.h" #include "RawFile/AssetDumperRawFile.h" @@ -47,7 +47,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const const auto* assetPools = dynamic_cast(context.m_zone.m_pools.get()); DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET) - DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS) + DUMP_ASSET_POOL(phys_constraints::InfoStringDumper, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS) // DUMP_ASSET_POOL(AssetDumperDestructibleDef, m_destructible_def, ASSET_TYPE_DESTRUCTIBLEDEF) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) diff --git a/src/ObjWriting/Game/T6/PhysConstraints/AssetDumperPhysConstraints.cpp b/src/ObjWriting/Game/T6/PhysConstraints/AssetDumperPhysConstraints.cpp deleted file mode 100644 index 7be1250a..00000000 --- a/src/ObjWriting/Game/T6/PhysConstraints/AssetDumperPhysConstraints.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "AssetDumperPhysConstraints.h" - -#include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/PhysConstraints/PhysConstraintsFields.h" - -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringFromPhysConstraintsConverter final : public InfoStringFromStructConverter - { - protected: - void FillFromExtensionField(const cspField_t& field) override - { - switch (static_cast(field.iFieldType)) - { - case CFT_TYPE: - FillFromEnumInt(std::string(field.szName), field.iOffset, s_constraintTypeNames, std::extent_v); - break; - - default: - assert(false); - break; - } - } - - public: - InfoStringFromPhysConstraintsConverter(const PhysConstraints* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) - { - } - }; -} // namespace T6 - -InfoString AssetDumperPhysConstraints::CreateInfoString(XAssetInfo* asset) -{ - assert(asset->Asset()->count <= 4); - - InfoStringFromPhysConstraintsConverter converter(asset->Asset(), - phys_constraints_fields, - std::extent_v, - [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]; - }); - - return converter.Convert(); -} - -bool AssetDumperPhysConstraints::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperPhysConstraints::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - // Only dump raw when no gdt available - if (context.m_gdt) - { - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_PHYS_CONSTRAINTS); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, gdtEntry); - context.m_gdt->WriteEntry(gdtEntry); - } - else - { - const auto assetFile = context.OpenAssetFile("physconstraints/" + asset->m_name); - - if (!assetFile) - return; - - auto& stream = *assetFile; - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS); - stream.write(stringValue.c_str(), stringValue.size()); - } -} diff --git a/src/ObjWriting/Game/T6/PhysConstraints/PhysConstraintsInfoStringDumperT6.cpp b/src/ObjWriting/Game/T6/PhysConstraints/PhysConstraintsInfoStringDumperT6.cpp new file mode 100644 index 00000000..e34862e8 --- /dev/null +++ b/src/ObjWriting/Game/T6/PhysConstraints/PhysConstraintsInfoStringDumperT6.cpp @@ -0,0 +1,93 @@ +#include "PhysConstraintsInfoStringDumperT6.h" + +#include "Game/T6/InfoString/InfoStringFromStructConverter.h" +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/PhysConstraints/PhysConstraintsFields.h" +#include "PhysConstraints/PhysConstraintsCommon.h" + +#include +#include + +using namespace T6; +using namespace ::phys_constraints; + +namespace +{ + class InfoStringFromPhysConstraintsConverter final : public InfoStringFromStructConverter + { + protected: + void FillFromExtensionField(const cspField_t& field) override + { + switch (static_cast(field.iFieldType)) + { + case CFT_TYPE: + FillFromEnumInt(std::string(field.szName), field.iOffset, s_constraintTypeNames, std::extent_v); + break; + + default: + assert(false); + break; + } + } + + public: + InfoStringFromPhysConstraintsConverter(const PhysConstraints* structure, + const cspField_t* fields, + const size_t fieldCount, + std::function scriptStringValueCallback) + : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + { + } + }; + + InfoString CreateInfoString(XAssetInfo* asset) + { + assert(asset->Asset()->count <= 4); + + InfoStringFromPhysConstraintsConverter converter(asset->Asset(), + phys_constraints_fields, + std::extent_v, + [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]; + }); + + return converter.Convert(); + } +} // namespace + +namespace T6::phys_constraints +{ + bool InfoStringDumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void InfoStringDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_PHYS_CONSTRAINTS); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS); + stream.write(stringValue.c_str(), stringValue.size()); + } + } +} // namespace T6::phys_constraints diff --git a/src/ObjWriting/Game/T6/PhysConstraints/AssetDumperPhysConstraints.h b/src/ObjWriting/Game/T6/PhysConstraints/PhysConstraintsInfoStringDumperT6.h similarity index 60% rename from src/ObjWriting/Game/T6/PhysConstraints/AssetDumperPhysConstraints.h rename to src/ObjWriting/Game/T6/PhysConstraints/PhysConstraintsInfoStringDumperT6.h index 8f3d938e..2af16570 100644 --- a/src/ObjWriting/Game/T6/PhysConstraints/AssetDumperPhysConstraints.h +++ b/src/ObjWriting/Game/T6/PhysConstraints/PhysConstraintsInfoStringDumperT6.h @@ -4,14 +4,12 @@ #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -namespace T6 +namespace T6::phys_constraints { - class AssetDumperPhysConstraints final : public AbstractAssetDumper + class InfoStringDumper final : public AbstractAssetDumper { - static InfoString CreateInfoString(XAssetInfo* asset); - protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace T6 +} // namespace T6::phys_constraints