diff --git a/src/ObjCommon/Game/T6/InfoString/PhysConstraintsFields.h b/src/ObjCommon/Game/T6/PhysConstraints/PhysConstraintsFields.h similarity index 96% rename from src/ObjCommon/Game/T6/InfoString/PhysConstraintsFields.h rename to src/ObjCommon/Game/T6/PhysConstraints/PhysConstraintsFields.h index 39d1eaee..a161fd83 100644 --- a/src/ObjCommon/Game/T6/InfoString/PhysConstraintsFields.h +++ b/src/ObjCommon/Game/T6/PhysConstraints/PhysConstraintsFields.h @@ -81,4 +81,17 @@ namespace T6 {"c4_yaw", offsetof(PhysConstraints, data[3].scale.y), CSPFT_FLOAT }, {"c4_pitch", offsetof(PhysConstraints, data[3].scale.x), CSPFT_FLOAT }, }; -} + + inline const char* s_constraintTypeNames[]{ + "none", + "point", + "distance", + "hinge", + "joint", + "actuator", + "fake_shake", + "launch", + "rope", + "light", + }; +} // namespace T6 diff --git a/src/ObjCommon/Game/T6/InfoString/PhysPresetFields.h b/src/ObjCommon/Game/T6/PhysPreset/PhysPresetFields.h similarity index 100% rename from src/ObjCommon/Game/T6/InfoString/PhysPresetFields.h rename to src/ObjCommon/Game/T6/PhysPreset/PhysPresetFields.h diff --git a/src/ObjCommon/Game/T6/InfoString/TracerFields.h b/src/ObjCommon/Game/T6/Tracer/TracerFields.h similarity index 96% rename from src/ObjCommon/Game/T6/InfoString/TracerFields.h rename to src/ObjCommon/Game/T6/Tracer/TracerFields.h index 80b2e3e7..2fd24d09 100644 --- a/src/ObjCommon/Game/T6/InfoString/TracerFields.h +++ b/src/ObjCommon/Game/T6/Tracer/TracerFields.h @@ -36,4 +36,9 @@ namespace T6 {"colorB4", offsetof(TracerDef, colors[4].b), CSPFT_FLOAT }, {"colorA4", offsetof(TracerDef, colors[4].a), CSPFT_FLOAT }, }; -} + + inline const char* tracerTypeNames[]{ + "Laser", + "Smoke", + }; +} // namespace T6 diff --git a/src/ObjCommon/Game/T6/InfoString/VehicleFields.h b/src/ObjCommon/Game/T6/Vehicle/VehicleFields.h similarity index 99% rename from src/ObjCommon/Game/T6/InfoString/VehicleFields.h rename to src/ObjCommon/Game/T6/Vehicle/VehicleFields.h index 3cfe0dcc..ead970fb 100644 --- a/src/ObjCommon/Game/T6/InfoString/VehicleFields.h +++ b/src/ObjCommon/Game/T6/Vehicle/VehicleFields.h @@ -561,4 +561,31 @@ namespace T6 {"customBool1", offsetof(VehicleDef, customBool1), CSPFT_BOOL }, {"customBool2", offsetof(VehicleDef, customBool2), CSPFT_BOOL }, }; -} + + inline const char* s_vehicleClassNames[]{ + "4 wheel", + "motorcycle", + "tank", + "plane", + "boat", + "artillery", + "helicopter", + }; + + inline const char* s_vehicleCameraModes[]{ + "first", + "chase", + "view", + "strafe", + "horse", + "oldtank", + "hover", + "vtol", + }; + + inline const char* s_tractionTypeNames[]{ + "TRACTION_TYPE_FRONT", + "TRACTION_TYPE_BACK", + "TRACTION_TYPE_ALL_WD", + }; +} // namespace T6 diff --git a/src/ObjCommon/Game/T6/InfoString/WeaponAttachmentFields.h b/src/ObjCommon/Game/T6/Weapon/AttachmentFields.h similarity index 99% rename from src/ObjCommon/Game/T6/InfoString/WeaponAttachmentFields.h rename to src/ObjCommon/Game/T6/Weapon/AttachmentFields.h index eff3387c..7fd2d40d 100644 --- a/src/ObjCommon/Game/T6/InfoString/WeaponAttachmentFields.h +++ b/src/ObjCommon/Game/T6/Weapon/AttachmentFields.h @@ -81,4 +81,4 @@ namespace T6 {"customBool1", offsetof(WeaponAttachment, customBool1), CSPFT_BOOL }, {"customBool2", offsetof(WeaponAttachment, customBool2), CSPFT_BOOL }, }; -} +} // namespace T6 diff --git a/src/ObjCommon/Game/T6/InfoString/WeaponAttachmentUniqueFields.h b/src/ObjCommon/Game/T6/Weapon/AttachmentUniqueFields.h similarity index 99% rename from src/ObjCommon/Game/T6/InfoString/WeaponAttachmentUniqueFields.h rename to src/ObjCommon/Game/T6/Weapon/AttachmentUniqueFields.h index 654a6627..819b7a16 100644 --- a/src/ObjCommon/Game/T6/InfoString/WeaponAttachmentUniqueFields.h +++ b/src/ObjCommon/Game/T6/Weapon/AttachmentUniqueFields.h @@ -206,4 +206,4 @@ namespace T6 {"customBool1", offsetof(WeaponAttachmentUniqueFull, attachment.customBool1), CSPFT_BOOL }, {"customBool2", offsetof(WeaponAttachmentUniqueFull, attachment.customBool2), CSPFT_BOOL }, }; -} +} // namespace T6 diff --git a/src/ObjCommon/Game/T6/InfoString/WeaponFields.h b/src/ObjCommon/Game/T6/Weapon/WeaponFields.h similarity index 100% rename from src/ObjCommon/Game/T6/InfoString/WeaponFields.h rename to src/ObjCommon/Game/T6/Weapon/WeaponFields.h diff --git a/src/ObjCommon/Game/T6/InfoString/EnumStrings.h b/src/ObjCommon/Game/T6/Weapon/WeaponStrings.h similarity index 86% rename from src/ObjCommon/Game/T6/InfoString/EnumStrings.h rename to src/ObjCommon/Game/T6/Weapon/WeaponStrings.h index 756db3e1..1bdcae24 100644 --- a/src/ObjCommon/Game/T6/InfoString/EnumStrings.h +++ b/src/ObjCommon/Game/T6/Weapon/WeaponStrings.h @@ -36,31 +36,11 @@ namespace T6 "crosshair", }; - inline const char* szWeapInventoryTypeNames[]{ - "primary", - "offhand", - "item", - "altmode", - "melee", - "dwlefthand", - }; - - inline const char* szWeapClipTypeNames[]{ - "bottom", - "top", - "left", - "dp28", - "ptrs", - "lmg", - }; - - inline const char* barrelTypeNames[]{ - "Single", - "Dual Barrel", - "Dual Barrel Alternate", - "Quad Barrel", - "Quad Barrel Alternate", - "Quad Barrel Double Alternate", + inline const char* penetrateTypeNames[]{ + "none", + "small", + "medium", + "large", }; inline const char* impactTypeNames[]{ @@ -165,6 +145,37 @@ namespace T6 "Turret Scope", }; + inline const char* szWeapInventoryTypeNames[]{ + "primary", + "offhand", + "item", + "altmode", + "melee", + "dwlefthand", + }; + + inline const char* szWeapFireTypeNames[]{ + "Full Auto", + "Single Shot", + "2-Round Burst", + "3-Round Burst", + "4-Round Burst", + "5-Round Burst", + "Stacked Fire", + "Minigun", + "Charge Shot", + "Jetgun", + }; + + inline const char* szWeapClipTypeNames[]{ + "bottom", + "top", + "left", + "dp28", + "ptrs", + "lmg", + }; + inline const char* ammoCounterClipNames[]{ "None", "Magazine", @@ -181,75 +192,13 @@ namespace T6 "4:1", }; - inline const char* szAttachmentTypeNames[]{ - "none", "acog", "dualclip", "dualoptic", "dw", "extbarrel", "extclip", "extramags", "fastads", "fastreload", - "fmj", "gl", "grip", "holo", "ir", "is", "longbreath", "mk", "mms", "rangefinder", - "reflex", "rf", "sf", "silencer", "stackfire", "stalker", "steadyaim", "swayreduc", "tacknife", "vzoom", - }; - - inline const char* szWeapFireTypeNames[]{ - "Full Auto", - "Single Shot", - "2-Round Burst", - "3-Round Burst", - "4-Round Burst", - "5-Round Burst", - "Stacked Fire", - "Minigun", - "Charge Shot", - "Jetgun", - }; - - inline const char* penetrateTypeNames[]{ - "none", - "small", - "medium", - "large", - }; - - inline const char* s_constraintTypeNames[]{ - "none", - "point", - "distance", - "hinge", - "joint", - "actuator", - "fake_shake", - "launch", - "rope", - "light", - }; - - inline const char* s_vehicleClassNames[]{ - "4 wheel", - "motorcycle", - "tank", - "plane", - "boat", - "artillery", - "helicopter", - }; - - inline const char* s_vehicleCameraModes[]{ - "first", - "chase", - "view", - "strafe", - "horse", - "oldtank", - "hover", - "vtol", - }; - - inline const char* s_tractionTypeNames[]{ - "TRACTION_TYPE_FRONT", - "TRACTION_TYPE_BACK", - "TRACTION_TYPE_ALL_WD", - }; - - inline const char* tracerTypeNames[]{ - "Laser", - "Smoke", + inline const char* barrelTypeNames[]{ + "Single", + "Dual Barrel", + "Dual Barrel Alternate", + "Quad Barrel", + "Quad Barrel Alternate", + "Quad Barrel Double Alternate", }; inline const char* bounceSoundSuffixes[]{ @@ -257,4 +206,10 @@ namespace T6 "_gravel", "_ice", "_metal", "_mud", "_paper", "_plaster", "_rock", "_sand", "_snow", "_water", "_wood", "_asphalt", "_ceramic", "_plastic", "_rubber", "_cushion", "_fruit", "_paintedmetal", "_player", "_tallgrass", "_riotshield", }; + + inline const char* szAttachmentTypeNames[]{ + "none", "acog", "dualclip", "dualoptic", "dw", "extbarrel", "extclip", "extramags", "fastads", "fastreload", + "fmj", "gl", "grip", "holo", "ir", "is", "longbreath", "mk", "mms", "rangefinder", + "reflex", "rf", "sf", "silencer", "stackfire", "stalker", "steadyaim", "swayreduc", "tacknife", "vzoom", + }; } // namespace T6 diff --git a/src/ObjCommon/Game/T6/InfoString/ZBarrierFields.h b/src/ObjCommon/Game/T6/ZBarrier/ZBarrierFields.h similarity index 100% rename from src/ObjCommon/Game/T6/InfoString/ZBarrierFields.h rename to src/ObjCommon/Game/T6/ZBarrier/ZBarrierFields.h diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderAddonMapEnts.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderAddonMapEnts.cpp deleted file mode 100644 index cb51edca..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderAddonMapEnts.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderAddonMapEnts.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderAddonMapEnts::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderAddonMapEnts.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderAddonMapEnts.h deleted file mode 100644 index 1f7f0ae9..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderAddonMapEnts.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderAddonMapEnts final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderClipMap.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderClipMap.cpp deleted file mode 100644 index 16d161e3..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderClipMap.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "AssetLoaderClipMap.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderClipMapBase::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -asset_type_t AssetLoaderClipMap::GetHandlingAssetType() const -{ - return ASSET_TYPE_CLIPMAP; -} - -asset_type_t AssetLoaderClipMapPvs::GetHandlingAssetType() const -{ - return ASSET_TYPE_CLIPMAP_PVS; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderClipMap.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderClipMap.h deleted file mode 100644 index fbe0145b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderClipMap.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderClipMapBase : public BasicAssetLoaderWithoutType - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; - - class AssetLoaderClipMap final : public AssetLoaderClipMapBase - { - public: - [[nodiscard]] asset_type_t GetHandlingAssetType() const override; - }; - - class AssetLoaderClipMapPvs final : public AssetLoaderClipMapBase - { - public: - [[nodiscard]] asset_type_t GetHandlingAssetType() const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderComWorld.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderComWorld.cpp deleted file mode 100644 index db595fa5..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderComWorld.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderComWorld.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderComWorld::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderComWorld.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderComWorld.h deleted file mode 100644 index 7a8879b0..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderComWorld.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderComWorld final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDDL.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDDL.cpp deleted file mode 100644 index 9dfe415a..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDDL.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderDDL.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderDDL::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDDL.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDDL.h deleted file mode 100644 index fa63756a..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDDL.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderDDL final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDestructibleDef.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDestructibleDef.cpp deleted file mode 100644 index 95162e2e..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDestructibleDef.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderDestructibleDef.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderDestructibleDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDestructibleDef.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDestructibleDef.h deleted file mode 100644 index 67bc6e10..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderDestructibleDef.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderDestructibleDef final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderEmblemSet.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderEmblemSet.cpp deleted file mode 100644 index a6c99892..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderEmblemSet.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderEmblemSet.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderEmblemSet::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - // Asset does not have a name - // So this cannot be an asset reference - return nullptr; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderEmblemSet.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderEmblemSet.h deleted file mode 100644 index e28fd74b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderEmblemSet.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderEmblemSet final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFont.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFont.cpp deleted file mode 100644 index af8fd342..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFont.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderFont.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderFont::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->fontName = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFont.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFont.h deleted file mode 100644 index 50826ebd..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFont.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderFont final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFontIcon.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFontIcon.cpp deleted file mode 100644 index e89d739c..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFontIcon.cpp +++ /dev/null @@ -1,270 +0,0 @@ -#include "AssetLoaderFontIcon.h" - -#include "Csv/CsvStream.h" -#include "Game/T6/CommonT6.h" -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace T6; - -void* AssetLoaderFontIcon::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderFontIcon::CanLoadFromRaw() const -{ - return true; -} - -std::string AssetLoaderFontIcon::ErrorPrefix(const std::string& assetName, const unsigned rowIndex) -{ - std::ostringstream str; - str << "FontIcon \"" << assetName << "\" Row " << rowIndex << ": "; - return str.str(); -} - -void AssetLoaderFontIcon::PreprocessRow(std::vector& row) -{ - for (auto& cell : row) - { - for (auto c : cell) - { - if (isspace(c)) - continue; - if (c == '#') - cell = ""; - break; - } - } -} - -bool AssetLoaderFontIcon::RowIsEmpty(const std::vector& row) -{ - return std::ranges::all_of(row, - [](const std::string& cell) - { - return cell.empty(); - }); -} - -bool AssetLoaderFontIcon::ParseInt(int& value, const std::string& str) -{ - char* endPtr; - value = strtol(str.c_str(), &endPtr, 0); - if (endPtr != &str[str.size()]) - return false; - return true; -} - -bool AssetLoaderFontIcon::ParseFloat(float& value, const std::string& str) -{ - char* endPtr; - value = strtof(str.c_str(), &endPtr); - if (endPtr != &str[str.size()]) - return false; - return true; -} - -bool AssetLoaderFontIcon::ParseHashStr(int& value, const std::string& str) -{ - if (!str.empty() && str[0] == '@' && str.size() > 1) - { - char* endPtr; - value = strtol(&str[1], &endPtr, 16); - - if (endPtr != &str[str.size()]) - return false; - } - else - { - value = Common::Com_HashString(str.c_str()); - } - - return true; -} - -bool AssetLoaderFontIcon::ReadIconRow(const std::vector& row, - FontIconEntry& icon, - const std::string& assetName, - const unsigned rowIndex, - MemoryManager* memory, - IAssetLoadingManager* manager, - std::vector& dependencies) -{ - if (row.size() < COL_COUNT_ICON) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Column count lower than min column count for entries (" << COL_COUNT_ICON << ")\n"; - return false; - } - - if (!ParseInt(icon.fontIconSize, row[ROW_ICON_SIZE])) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Failed to parse size\n"; - return false; - } - - if (!ParseFloat(icon.xScale, row[ROW_ICON_XSCALE]) || !ParseFloat(icon.yScale, row[ROW_ICON_YSCALE])) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Failed to parse scale\n"; - return false; - } - - auto* materialDependency = manager->LoadDependency(row[ROW_ICON_MATERIAL]); - if (materialDependency == nullptr) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Failed to load material \"" << row[ROW_ICON_MATERIAL] << "\"\n"; - return false; - } - - icon.fontIconMaterialHandle = materialDependency->Asset(); - icon.fontIconName.string = memory->Dup(row[ROW_ICON_NAME].c_str()); - icon.fontIconName.hash = Common::Com_HashString(icon.fontIconName.string); - - return true; -} - -bool AssetLoaderFontIcon::ReadAliasRow(const std::vector& row, - FontIconAlias& alias, - const std::string& assetName, - const unsigned rowIndex, - MemoryManager* memory, - IAssetLoadingManager* manager) -{ - if (row.size() < COL_COUNT_ALIAS) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Column count lower than min column count for aliases (" << COL_COUNT_ALIAS << ")\n"; - return false; - } - - if (!ParseHashStr(alias.aliasHash, row[ROW_ALIAS_NAME])) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Failed to parse alias \"" << row[ROW_ALIAS_NAME] << "\"\n"; - return false; - } - - if (!ParseHashStr(alias.buttonHash, row[ROW_ALIAS_BUTTON])) - { - std::cout << ErrorPrefix(assetName, rowIndex) << "Failed to parse button \"" << row[ROW_ALIAS_BUTTON] << "\"\n"; - return false; - } - - return true; -} - -bool AssetLoaderFontIcon::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - auto* fontIcon = memory->Create(); - fontIcon->name = memory->Dup(assetName.c_str()); - - const CsvInputStream csv(*file.m_stream); - std::vector dependencies; - std::vector currentRow; - std::vector entries; - std::vector aliases; - auto currentRowIndex = 0u; - - while (csv.NextRow(currentRow)) - { - currentRowIndex++; - PreprocessRow(currentRow); - - if (RowIsEmpty(currentRow)) - continue; - - if (currentRow.size() < COL_COUNT_MIN) - { - std::cout << ErrorPrefix(assetName, currentRowIndex) << "Column count lower than min column count (" << COL_COUNT_MIN << ")\n"; - return true; - } - - int index; - if (!ParseInt(index, currentRow[ROW_INDEX]) || index < 0) - { - std::cout << ErrorPrefix(assetName, currentRowIndex) << "Failed to parse index\n"; - return true; - } - - if (currentRow[ROW_TYPE] == VALUE_TYPE_ICON) - { - FontIconEntry icon{}; - if (!ReadIconRow(currentRow, icon, assetName, currentRowIndex, memory, manager, dependencies)) - return true; - - if (static_cast(index) == entries.size()) - { - entries.push_back(icon); - } - else if (static_cast(index) > entries.size()) - { - entries.reserve(index + 1); - entries[index] = icon; - } - else - { - entries[index] = icon; - } - } - else if (currentRow[ROW_TYPE] == VALUE_TYPE_ALIAS) - { - FontIconAlias alias{}; - if (!ReadAliasRow(currentRow, alias, assetName, currentRowIndex, memory, manager)) - return true; - - if (static_cast(index) == aliases.size()) - { - aliases.push_back(alias); - } - else if (static_cast(index) > aliases.size()) - { - aliases.reserve(index + 1); - aliases[index] = alias; - } - else - { - aliases[index] = alias; - } - } - else - { - std::cout << ErrorPrefix(assetName, currentRowIndex) << "Unknown row type \"" << currentRow[ROW_TYPE] << "\"\n"; - return true; - } - } - - fontIcon->numEntries = entries.size(); - fontIcon->numAliasEntries = aliases.size(); - - if (fontIcon->numEntries > 0) - { - fontIcon->fontIconEntry = memory->Alloc(fontIcon->numEntries); - for (auto i = 0u; i < entries.size(); i++) - fontIcon->fontIconEntry[i] = entries[i]; - } - else - fontIcon->fontIconEntry = nullptr; - - if (fontIcon->numAliasEntries > 0) - { - fontIcon->fontIconAlias = memory->Alloc(fontIcon->numAliasEntries); - for (auto i = 0u; i < aliases.size(); i++) - fontIcon->fontIconAlias[i] = aliases[i]; - } - else - fontIcon->fontIconAlias = nullptr; - - manager->AddAsset(assetName, fontIcon); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFontIcon.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFontIcon.h deleted file mode 100644 index 7f78f0ee..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFontIcon.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -#include -#include -#include - -namespace T6 -{ - class AssetLoaderFontIcon final : public BasicAssetLoader - { - static constexpr unsigned ROW_INDEX = 0; - static constexpr unsigned ROW_TYPE = 1; - - static constexpr unsigned ROW_ICON_NAME = 2; - static constexpr unsigned ROW_ICON_MATERIAL = 3; - static constexpr unsigned ROW_ICON_SIZE = 4; - static constexpr unsigned ROW_ICON_XSCALE = 5; - static constexpr unsigned ROW_ICON_YSCALE = 6; - - static constexpr unsigned ROW_ALIAS_NAME = 2; - static constexpr unsigned ROW_ALIAS_BUTTON = 3; - - static constexpr const char* VALUE_TYPE_ICON = "icon"; - static constexpr const char* VALUE_TYPE_ALIAS = "alias"; - - static constexpr unsigned COL_COUNT_ICON = 7; - static constexpr unsigned COL_COUNT_ALIAS = 4; - static constexpr unsigned COL_COUNT_MIN = std::min(COL_COUNT_ICON, COL_COUNT_ALIAS); - - static std::string ErrorPrefix(const std::string& assetName, unsigned rowIndex); - static void PreprocessRow(std::vector& row); - static bool RowIsEmpty(const std::vector& row); - - static bool ParseInt(int& value, const std::string& str); - static bool ParseFloat(float& value, const std::string& str); - static bool ParseHashStr(int& value, const std::string& str); - - static bool ReadIconRow(const std::vector& row, - FontIconEntry& icon, - const std::string& assetName, - unsigned rowIndex, - MemoryManager* memory, - IAssetLoadingManager* manager, - std::vector& dependencies); - static bool ReadAliasRow(const std::vector& row, - FontIconAlias& alias, - const std::string& assetName, - unsigned rowIndex, - MemoryManager* memory, - IAssetLoadingManager* manager); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepFxTable.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepFxTable.cpp deleted file mode 100644 index e2ca8f02..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepFxTable.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderFootstepFxTable.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderFootstepFxTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepFxTable.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepFxTable.h deleted file mode 100644 index 141ddf9c..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepFxTable.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderFootstepFxTable final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepTable.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepTable.cpp deleted file mode 100644 index 8dcd8534..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepTable.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderFootstepTable.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderFootstepTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepTable.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepTable.h deleted file mode 100644 index 66c00426..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFootstepTable.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderFootstepTable final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFx.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFx.cpp deleted file mode 100644 index b20d5d6e..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFx.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderFx.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderFx::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFx.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFx.h deleted file mode 100644 index ba190b4a..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderFx.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderFx final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldMp.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldMp.cpp deleted file mode 100644 index a09751f9..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldMp.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderGameWorldMp.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderGameWorldMp::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldMp.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldMp.h deleted file mode 100644 index 092ea981..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldMp.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderGameWorldMp final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldSp.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldSp.cpp deleted file mode 100644 index f69f7bbe..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldSp.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderGameWorldSp.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderGameWorldSp::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldSp.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldSp.h deleted file mode 100644 index bfd3ac1b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGameWorldSp.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderGameWorldSp final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp deleted file mode 100644 index 5c47dceb..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "AssetLoaderGfxImage.h" - -#include "Game/T6/CommonT6.h" -#include "Game/T6/T6.h" -#include "Image/IwiLoader.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include -#include -#include - -using namespace T6; - -void* AssetLoaderGfxImage::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderGfxImage::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderGfxImage::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = std::format("images/{}.iwi", assetName); - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - const auto fileSize = static_cast(file.m_length); - const auto fileData = std::make_unique(fileSize); - file.m_stream->read(fileData.get(), fileSize); - const auto dataHash = static_cast(crc32(0u, reinterpret_cast(fileData.get()), fileSize)); - - std::istringstream ss(std::string(fileData.get(), fileSize)); - const auto texture = iwi::LoadIwi(ss); - if (!texture) - { - std::cerr << std::format("Failed to load texture from: {}\n", fileName); - return false; - } - - auto* image = memory->Create(); - memset(image, 0, sizeof(GfxImage)); - - image->name = memory->Dup(assetName.c_str()); - image->hash = Common::R_HashString(image->name, 0); - image->delayLoadPixels = true; - - image->noPicmip = !texture->HasMipMaps(); - image->width = static_cast(texture->GetWidth()); - image->height = static_cast(texture->GetHeight()); - image->depth = static_cast(texture->GetDepth()); - - image->streaming = 1; - image->streamedParts[0].levelCount = 1; - image->streamedParts[0].levelSize = static_cast(fileSize); - image->streamedParts[0].hash = dataHash & 0x1FFFFFFF; - image->streamedPartCount = 1; - - manager->AddAsset(assetName, image); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h deleted file mode 100644 index c88788bd..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderGfxImage final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxLightDef.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxLightDef.cpp deleted file mode 100644 index a46bef80..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxLightDef.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderGfxLightDef.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxLightDef.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxLightDef.h deleted file mode 100644 index dd8c88c3..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxLightDef.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderGfxLightDef final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxWorld.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxWorld.cpp deleted file mode 100644 index 6243579b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxWorld.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderGfxWorld.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderGfxWorld::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxWorld.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxWorld.h deleted file mode 100644 index 3653ff15..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxWorld.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderGfxWorld final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGlasses.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGlasses.cpp deleted file mode 100644 index dd1e5ef5..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGlasses.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderGlasses.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderGlasses::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGlasses.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGlasses.h deleted file mode 100644 index c8deb7e4..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGlasses.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderGlasses final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderImpactFx.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderImpactFx.cpp deleted file mode 100644 index e9478c0f..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderImpactFx.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderImpactFx.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderImpactFx::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderImpactFx.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderImpactFx.h deleted file mode 100644 index 779ee741..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderImpactFx.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderImpactFx final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderLeaderboard.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderLeaderboard.cpp deleted file mode 100644 index 8db736f2..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderLeaderboard.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "AssetLoaderLeaderboard.h" - -#include "Game/T6/CommonT6.h" -#include "Game/T6/Leaderboard/JsonLeaderboardDefLoader.h" -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace T6; - -void* AssetLoaderLeaderboard::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderLeaderboard::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderLeaderboard::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(std::format("leaderboards/{}.json", assetName)); - if (!file.IsOpen()) - return false; - - auto* leaderboardDef = memory->Alloc(); - leaderboardDef->name = memory->Dup(assetName.c_str()); - - if (LoadLeaderboardAsJson(*file.m_stream, *leaderboardDef, memory)) - manager->AddAsset(assetName, leaderboardDef); - else - std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderLeaderboard.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderLeaderboard.h deleted file mode 100644 index 13c3e2a2..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderLeaderboard.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderLeaderboard final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMapEnts.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMapEnts.cpp deleted file mode 100644 index ed2c3a2f..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMapEnts.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderMapEnts.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderMapEnts::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMapEnts.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMapEnts.h deleted file mode 100644 index 59ce1a65..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMapEnts.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderMapEnts final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMaterial.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMaterial.cpp deleted file mode 100644 index 8bfbe12b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMaterial.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "AssetLoaderMaterial.h" - -#include "Game/T6/Material/JsonMaterialLoader.h" -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace T6; - -void* AssetLoaderMaterial::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->info.name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderMaterial::CanLoadFromRaw() const -{ - return true; -} - -std::string AssetLoaderMaterial::GetFileNameForAsset(const std::string& assetName) -{ - std::string sanitizedFileName(assetName); - if (sanitizedFileName[0] == '*') - { - std::ranges::replace(sanitizedFileName, '*', '_'); - const auto parenthesisPos = sanitizedFileName.find('('); - if (parenthesisPos != std::string::npos) - sanitizedFileName.erase(parenthesisPos); - sanitizedFileName = "generated/" + sanitizedFileName; - } - - return std::format("materials/{}.json", sanitizedFileName); -} - -bool AssetLoaderMaterial::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(GetFileNameForAsset(assetName)); - if (!file.IsOpen()) - return false; - - auto* material = memory->Alloc(); - material->info.name = memory->Dup(assetName.c_str()); - - std::vector dependencies; - if (LoadMaterialAsJson(*file.m_stream, *material, memory, manager, dependencies)) - manager->AddAsset(assetName, material, std::move(dependencies)); - else - std::cerr << "Failed to load material \"" << assetName << "\"\n"; - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMaterial.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMaterial.h deleted file mode 100644 index 6ed4075e..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMaterial.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderMaterial final : public BasicAssetLoader - { - static std::string GetFileNameForAsset(const std::string& assetName); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMemoryBlock.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMemoryBlock.cpp deleted file mode 100644 index c07acc51..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMemoryBlock.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderMemoryBlock.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderMemoryBlock::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMemoryBlock.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMemoryBlock.h deleted file mode 100644 index 055703ce..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMemoryBlock.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderMemoryBlock final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenu.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenu.cpp deleted file mode 100644 index dd90466e..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenu.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderMenu.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderMenu::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->window.name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenu.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenu.h deleted file mode 100644 index 372b1de7..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenu.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderMenu final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenuList.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenuList.cpp deleted file mode 100644 index 71f1bdd3..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenuList.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderMenuList.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderMenuList::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenuList.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenuList.h deleted file mode 100644 index a786e7a2..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderMenuList.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderMenuList final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp deleted file mode 100644 index 22433770..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include "AssetLoaderPhysConstraints.h" - -#include "Game/T6/InfoString/EnumStrings.h" -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/PhysConstraintsFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringToPhysConstraintsConverter final : public InfoStringToStructConverter - { - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - switch (static_cast(field.iFieldType)) - { - case CFT_TYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, s_constraintTypeNames, std::extent_v); - - default: - assert(false); - return false; - } - } - - public: - InfoStringToPhysConstraintsConverter(const InfoString& infoString, - PhysConstraints* physConstraints, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, physConstraints, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace T6 - -void AssetLoaderPhysConstraints::CalculatePhysConstraintsFields(PhysConstraints* physConstraints, Zone* zone) -{ - for (auto& constraint : physConstraints->data) - { - constraint.targetname = zone->m_script_strings.AddOrGetScriptString(""); - constraint.target_ent1 = zone->m_script_strings.AddOrGetScriptString(""); - constraint.target_ent2 = zone->m_script_strings.AddOrGetScriptString(""); - constraint.attach_point_type1 = ATTACH_POINT_BONE; - constraint.attach_point_type2 = ATTACH_POINT_BONE; - constraint.target_bone1 = ""; - constraint.target_bone2 = ""; - } - - // count - { - auto foundEnd = false; - for (auto i = 0u; i < std::extent_v; i++) - { - if (physConstraints->data[i].type == CONSTRAINT_NONE) - { - foundEnd = true; - physConstraints->count = i; - break; - } - } - - if (!foundEnd) - physConstraints->count = std::extent_v; - } -} - -bool AssetLoaderPhysConstraints::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - auto* physConstraints = memory->Create(); - memset(physConstraints, 0, sizeof(PhysConstraints)); - - InfoStringToPhysConstraintsConverter converter( - infoString, physConstraints, zone->m_script_strings, memory, manager, phys_constraints_fields, std::extent_v); - if (!converter.Convert()) - { - std::cout << "Failed to parse phys constraints: \"" << assetName << "\"\n"; - return true; - } - - CalculatePhysConstraintsFields(physConstraints, zone); - physConstraints->name = memory->Dup(assetName.c_str()); - - auto scrStrings = converter.GetUsedScriptStrings(); - scrStrings.push_back(zone->m_script_strings.AddOrGetScriptString("")); - manager->AddAsset(assetName, physConstraints, converter.GetDependencies(), scrStrings); - - return true; -} - -void* AssetLoaderPhysConstraints::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderPhysConstraints::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderPhysConstraints::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_CONSTRAINTS, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cout << "Failed to read phys constraints gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderPhysConstraints::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderPhysConstraints::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "physconstraints/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.h deleted file mode 100644 index c8b54e75..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderPhysConstraints final : public BasicAssetLoader - { - static void CalculatePhysConstraintsFields(PhysConstraints* physConstraints, Zone* zone); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp deleted file mode 100644 index e5fb21a1..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "AssetLoaderPhysPreset.h" - -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/PhysPresetFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -#include -#include -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter - { - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - assert(false); - return false; - } - - public: - InfoStringToPhysPresetConverter(const InfoString& infoString, - PhysPresetInfo* physPreset, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, physPreset, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace T6 - -void AssetLoaderPhysPreset::CopyFromPhysPresetInfo(const PhysPresetInfo* physPresetInfo, PhysPreset* physPreset) -{ - physPreset->mass = std::clamp(physPresetInfo->mass, 1.0f, 2000.0f) * 0.001f; - physPreset->bounce = physPresetInfo->bounce; - - if (physPresetInfo->isFrictionInfinity != 0) - physPreset->friction = std::numeric_limits::infinity(); - else - physPreset->friction = physPresetInfo->friction; - - physPreset->bulletForceScale = physPresetInfo->bulletForceScale; - physPreset->explosiveForceScale = physPresetInfo->explosiveForceScale; - physPreset->piecesSpreadFraction = physPresetInfo->piecesSpreadFraction; - physPreset->piecesUpwardVelocity = physPresetInfo->piecesUpwardVelocity; - physPreset->canFloat = physPresetInfo->canFloat; - physPreset->gravityScale = std::clamp(physPresetInfo->gravityScale, 0.01f, 10.0f); - physPreset->centerOfMassOffset = physPresetInfo->centerOfMassOffset; - physPreset->buoyancyBoxMin = physPresetInfo->buoyancyBoxMin; - physPreset->buoyancyBoxMax = physPresetInfo->buoyancyBoxMax; -} - -bool AssetLoaderPhysPreset::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - const auto presetInfo = std::make_unique(); - memset(presetInfo.get(), 0, sizeof(PhysPresetInfo)); - InfoStringToPhysPresetConverter converter( - infoString, presetInfo.get(), zone->m_script_strings, memory, manager, phys_preset_fields, std::extent_v); - if (!converter.Convert()) - { - std::cout << "Failed to parse phys preset: \"" << assetName << "\"\n"; - return true; - } - - auto* physPreset = memory->Create(); - - CopyFromPhysPresetInfo(presetInfo.get(), physPreset); - physPreset->name = memory->Dup(assetName.c_str()); - - manager->AddAsset(assetName, physPreset, converter.GetDependencies(), converter.GetUsedScriptStrings()); - - return true; -} - -void* AssetLoaderPhysPreset::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderPhysPreset::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderPhysPreset::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cout << "Failed to read phys preset gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderPhysPreset::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderPhysPreset::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "physic/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.h deleted file mode 100644 index a0c6db0b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderPhysPreset final : public BasicAssetLoader - { - static void CopyFromPhysPresetInfo(const PhysPresetInfo* physPresetInfo, PhysPreset* physPreset); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderQdb.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderQdb.cpp deleted file mode 100644 index 514878ff..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderQdb.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "AssetLoaderQdb.h" - -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace T6; - -void* AssetLoaderQdb::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderQdb::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderQdb::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - auto* qdb = memory->Create(); - qdb->name = memory->Dup(assetName.c_str()); - qdb->len = static_cast(file.m_length); - - auto* fileBuffer = memory->Alloc(static_cast(file.m_length + 1)); - file.m_stream->read(fileBuffer, file.m_length); - if (file.m_stream->gcount() != file.m_length) - return false; - fileBuffer[qdb->len] = '\0'; - - qdb->buffer = static_cast(fileBuffer); - manager->AddAsset(assetName, qdb); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderQdb.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderQdb.h deleted file mode 100644 index ad5f2e13..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderQdb.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderQdb final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp deleted file mode 100644 index f279574a..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "AssetLoaderRawFile.h" - -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include -#include -#include - -using namespace T6; - -namespace fs = std::filesystem; - -void* AssetLoaderRawFile::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderRawFile::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderRawFile::LoadAnimtree( - const SearchPathOpenFile& file, const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) -{ - const auto uncompressedBuffer = std::make_unique(static_cast(file.m_length)); - file.m_stream->read(uncompressedBuffer.get(), file.m_length); - if (file.m_stream->gcount() != file.m_length) - return false; - - const auto compressionBufferSize = static_cast(file.m_length + sizeof(uint32_t) + COMPRESSED_BUFFER_SIZE_PADDING); - auto* compressedBuffer = memory->Alloc(compressionBufferSize); - - z_stream_s zs{}; - - zs.zalloc = Z_NULL; - zs.zfree = Z_NULL; - zs.opaque = Z_NULL; - zs.avail_in = static_cast(file.m_length); - zs.avail_out = compressionBufferSize; - zs.next_in = reinterpret_cast(uncompressedBuffer.get()); - zs.next_out = reinterpret_cast(&compressedBuffer[sizeof(uint32_t)]); - - int ret = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -DEF_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); - - if (ret != Z_OK) - { - throw std::runtime_error("Initializing deflate failed"); - } - - ret = deflate(&zs, Z_FINISH); - - if (ret != Z_STREAM_END) - { - std::cerr << "Deflate failed for loading animtree file \"" << assetName << "\"\n"; - deflateEnd(&zs); - return false; - } - - const auto compressedSize = compressionBufferSize + sizeof(uint32_t) - zs.avail_out; - - reinterpret_cast(compressedBuffer)[0] = static_cast(file.m_length); // outLen - - auto* rawFile = memory->Create(); - rawFile->name = memory->Dup(assetName.c_str()); - rawFile->len = static_cast(compressedSize); - rawFile->buffer = static_cast(compressedBuffer); - - deflateEnd(&zs); - - manager->AddAsset(assetName, rawFile); - - return true; -} - -bool AssetLoaderRawFile::LoadDefault( - const SearchPathOpenFile& file, const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) -{ - auto* rawFile = memory->Create(); - rawFile->name = memory->Dup(assetName.c_str()); - rawFile->len = static_cast(file.m_length); - - auto* fileBuffer = memory->Alloc(static_cast(file.m_length + 1)); - file.m_stream->read(fileBuffer, file.m_length); - if (file.m_stream->gcount() != file.m_length) - return false; - fileBuffer[rawFile->len] = '\0'; - - rawFile->buffer = static_cast(fileBuffer); - manager->AddAsset(assetName, rawFile); - - return true; -} - -bool AssetLoaderRawFile::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - const fs::path rawFilePath(assetName); - const auto extension = rawFilePath.extension().string(); - - if (extension == ".atr") - return LoadAnimtree(file, assetName, searchPath, memory, manager); - - return LoadDefault(file, assetName, searchPath, memory, manager); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.h deleted file mode 100644 index 2e4a5412..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderRawFile final : public BasicAssetLoader - { - static constexpr size_t COMPRESSED_BUFFER_SIZE_PADDING = 64; - - static bool LoadAnimtree( - const SearchPathOpenFile& file, const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager); - static bool LoadDefault( - const SearchPathOpenFile& file, const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderScriptParseTree.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderScriptParseTree.cpp deleted file mode 100644 index c2ed0069..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderScriptParseTree.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "AssetLoaderScriptParseTree.h" - -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace T6; - -void* AssetLoaderScriptParseTree::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderScriptParseTree::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderScriptParseTree::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - auto* scriptParseTree = memory->Create(); - scriptParseTree->name = memory->Dup(assetName.c_str()); - scriptParseTree->len = static_cast(file.m_length); - - auto* fileBuffer = memory->Alloc(static_cast(file.m_length + 1)); - file.m_stream->read(fileBuffer, file.m_length); - if (file.m_stream->gcount() != file.m_length) - return false; - fileBuffer[scriptParseTree->len] = '\0'; - - scriptParseTree->buffer = static_cast(fileBuffer); - manager->AddAsset(assetName, scriptParseTree); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderScriptParseTree.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderScriptParseTree.h deleted file mode 100644 index 2d4ea3e2..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderScriptParseTree.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderScriptParseTree final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSkinnedVerts.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSkinnedVerts.cpp deleted file mode 100644 index 89565253..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSkinnedVerts.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderSkinnedVerts.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderSkinnedVerts::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSkinnedVerts.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSkinnedVerts.h deleted file mode 100644 index 2d96097c..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSkinnedVerts.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderSkinnedVerts final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSlug.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSlug.cpp deleted file mode 100644 index 49f6a8d6..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSlug.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "AssetLoaderSlug.h" - -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace T6; - -void* AssetLoaderSlug::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderSlug::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderSlug::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - auto* slug = memory->Create(); - slug->name = memory->Dup(assetName.c_str()); - slug->len = static_cast(file.m_length); - - auto* fileBuffer = memory->Alloc(static_cast(file.m_length + 1)); - file.m_stream->read(fileBuffer, file.m_length); - if (file.m_stream->gcount() != file.m_length) - return false; - fileBuffer[slug->len] = '\0'; - - slug->buffer = static_cast(fileBuffer); - manager->AddAsset(assetName, slug); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSlug.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSlug.h deleted file mode 100644 index 375a48ba..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSlug.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderSlug final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundBank.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundBank.h deleted file mode 100644 index 2327467e..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundBank.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderSoundBank final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundDriverGlobals.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundDriverGlobals.cpp deleted file mode 100644 index ff897a85..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundDriverGlobals.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderSoundDriverGlobals.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderSoundDriverGlobals::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundDriverGlobals.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundDriverGlobals.h deleted file mode 100644 index de2863c9..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundDriverGlobals.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderSoundDriverGlobals final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundPatch.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundPatch.cpp deleted file mode 100644 index 9594fc40..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundPatch.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderSoundPatch.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderSoundPatch::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundPatch.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundPatch.h deleted file mode 100644 index 02db1c40..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundPatch.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderSoundPatch final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderStringTable.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderStringTable.cpp deleted file mode 100644 index e4a0321d..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderStringTable.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "AssetLoaderStringTable.h" - -#include "Csv/CsvStream.h" -#include "Game/T6/CommonT6.h" -#include "Game/T6/T6.h" -#include "Pool/GlobalAssetPool.h" -#include "StringTable/StringTableLoader.h" - -#include - -using namespace T6; - -void* AssetLoaderStringTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderStringTable::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderStringTable::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - string_table::StringTableLoaderV3 loader; - auto* stringTable = loader.LoadFromStream(assetName, *memory, *file.m_stream); - - manager->AddAsset(assetName, stringTable); - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderStringTable.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderStringTable.h deleted file mode 100644 index 2d9b3bc0..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderStringTable.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderStringTable final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTechniqueSet.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTechniqueSet.cpp deleted file mode 100644 index bf4bf380..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTechniqueSet.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderTechniqueSet.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderTechniqueSet::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTechniqueSet.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTechniqueSet.h deleted file mode 100644 index c9b8b6b7..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTechniqueSet.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderTechniqueSet final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp deleted file mode 100644 index 7ac19a8c..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "AssetLoaderTracer.h" - -#include "Game/T6/InfoString/EnumStrings.h" -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/TracerFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringToTracerConverter final : public InfoStringToStructConverter - { - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - switch (static_cast(field.iFieldType)) - { - case TFT_TRACERTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, tracerTypeNames, std::extent_v); - - case TFT_NUM_FIELD_TYPES: - default: - assert(false); - return false; - } - } - - public: - InfoStringToTracerConverter(const InfoString& infoString, - TracerDef* tracer, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, tracer, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace T6 - -bool AssetLoaderTracer::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - auto* tracer = memory->Create(); - memset(tracer, 0, sizeof(TracerDef)); - - InfoStringToTracerConverter converter(infoString, tracer, zone->m_script_strings, memory, manager, tracer_fields, std::extent_v); - if (!converter.Convert()) - { - std::cout << "Failed to parse tracer: \"" << assetName << "\"\n"; - return true; - } - - tracer->name = memory->Dup(assetName.c_str()); - - manager->AddAsset(assetName, tracer, converter.GetDependencies(), converter.GetUsedScriptStrings()); - - return true; -} - -void* AssetLoaderTracer::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderTracer::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderTracer::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_TRACER, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cout << "Failed to read tracer gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderTracer::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderTracer::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "tracer/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_TRACER, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.h deleted file mode 100644 index ea650439..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderTracer final : public BasicAssetLoader - { - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.h deleted file mode 100644 index aaa6ccda..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderVehicle final : public BasicAssetLoader - { - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp deleted file mode 100644 index 6fad7e7e..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp +++ /dev/null @@ -1,683 +0,0 @@ -#include "AssetLoaderWeapon.h" - -#include "AssetLoaderWeaponAttachmentUnique.h" -#include "Game/T6/InfoString/EnumStrings.h" -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/WeaponFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "Utils/ClassUtils.h" -#include "Utils/StringUtils.h" -#include "Weapon/AccuracyGraphLoader.h" - -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringToWeaponConverter final : public InfoStringToStructConverter - { - bool ConvertHideTags(const cspField_t& field, const std::string& value) - { - std::vector valueArray; - if (!ParseAsArray(value, valueArray)) - { - std::cerr << "Failed to parse hide tags as array\n"; - return false; - } - - if (valueArray.size() > std::extent_v) - { - std::cerr << "Cannot have more than " << std::extent_v << " hide tags!\n"; - return false; - } - - auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - - if (valueArray.size() < std::extent_v) - { - m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString(nullptr)); - } - - auto currentHideTag = 0u; - for (; currentHideTag < valueArray.size(); currentHideTag++) - { - const auto& currentValue = valueArray[currentHideTag]; - const auto scrString = - !currentValue.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue) : m_zone_script_strings.AddOrGetScriptString(nullptr); - hideTags[currentHideTag] = scrString; - m_used_script_string_list.emplace(scrString); - } - - for (; currentHideTag < std::extent_v; currentHideTag++) - { - hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(nullptr); - } - - return true; - } - - _NODISCARD bool ConvertBounceSounds(const cspField_t& field, const std::string& value) const - { - auto*** bounceSound = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - if (value.empty()) - { - *bounceSound = nullptr; - return true; - } - - assert(std::extent_v == SURF_TYPE_NUM); - *bounceSound = m_memory->Alloc(SURF_TYPE_NUM); - for (auto i = 0u; i < SURF_TYPE_NUM; i++) - { - const auto currentBounceSound = value + bounceSoundSuffixes[i]; - (*bounceSound)[i] = m_memory->Dup(currentBounceSound.c_str()); - } - return true; - } - - _NODISCARD bool ConvertNotetrackSoundMap(const cspField_t& field, const std::string& value) - { - std::vector> pairs; - if (!ParseAsArray(value, pairs)) - { - std::cerr << "Failed to parse notetracksoundmap as pairs\n"; - return false; - } - - if (pairs.size() > std::extent_v) - { - std::cerr << "Cannot have more than " << std::extent_v << " notetracksoundmap entries!\n"; - return false; - } - - auto* keys = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - auto* values = &keys[std::extent_v]; - auto currentEntryNum = 0u; - - if (pairs.size() < std::extent_v) - { - m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString(nullptr)); - } - - for (; currentEntryNum < pairs.size(); currentEntryNum++) - { - const auto& currentValue = pairs[currentEntryNum]; - const auto keyScriptString = !currentValue[0].empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue[0]) - : m_zone_script_strings.AddOrGetScriptString(nullptr); - const auto valueScriptString = !currentValue[1].empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue[1]) - : m_zone_script_strings.AddOrGetScriptString(nullptr); - - keys[currentEntryNum] = keyScriptString; - m_used_script_string_list.emplace(keyScriptString); - - values[currentEntryNum] = valueScriptString; - m_used_script_string_list.emplace(valueScriptString); - } - - for (; currentEntryNum < std::extent_v; currentEntryNum++) - { - const auto emptyScr = m_zone_script_strings.GetScriptString(nullptr); - keys[currentEntryNum] = emptyScr; - values[currentEntryNum] = emptyScr; - } - - return true; - } - - _NODISCARD bool ConvertWeaponCamo(const cspField_t& field, const std::string& value) - { - if (value.empty()) - { - *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = nullptr; - return true; - } - - auto* camo = m_loading_manager->LoadDependency(value); - - if (camo == nullptr) - { - std::cerr << "Failed to load camo asset \"" << value << "\"\n"; - return false; - } - - m_dependencies.emplace(camo); - *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = camo->Asset(); - - return true; - } - - _NODISCARD bool ConvertAttachments(const cspField_t& field, const std::string& value) - { - std::vector valueArray; - if (!ParseAsArray(value, valueArray)) - { - std::cerr << "Failed to parse attachments as array\n"; - return false; - } - - auto** attachments = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - - for (const auto& attachmentName : valueArray) - { - auto* attachmentAssetInfo = m_loading_manager->LoadDependency(attachmentName); - if (attachmentAssetInfo == nullptr) - { - std::cerr << "Failed to load attachment asset \"" << attachmentName << "\"\n"; - return false; - } - - auto* attachmentAsset = attachmentAssetInfo->Asset(); - - if (static_cast(attachmentAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT) - { - std::cerr << "Invalid attachment type " << attachmentAsset->attachmentType << " for attachment asset \"" << attachmentName << "\"\n"; - return false; - } - - if (attachments[attachmentAsset->attachmentType] != nullptr) - { - std::cerr << "Already loaded attachment with same type " << attachmentAsset->attachmentType << ": \"" - << attachments[attachmentAsset->attachmentType]->szInternalName << "\", \"" << attachmentName << "\"\n"; - return false; - } - - attachments[attachmentAsset->attachmentType] = attachmentAsset; - m_dependencies.emplace(attachmentAssetInfo); - } - - return true; - } - - _NODISCARD static bool HasMoreThanOneAttachmentSetInMask(const int mask) - { - // Check if int has more than 1 bit set - return (mask & (mask - 1)) != 0; - } - - _NODISCARD bool ConvertAttachmentUniques(const cspField_t& field, const std::string& value) - { - std::vector valueArray; - if (!ParseAsArray(value, valueArray)) - { - std::cerr << "Failed to parse attachment uniques as array\n"; - return false; - } - - auto** attachmentUniques = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - auto attachmentCombinationIndex = std::extent_v; - - for (const auto& attachmentUniqueName : valueArray) - { - auto* attachmentUniqueAssetInfo = m_loading_manager->LoadDependency(attachmentUniqueName); - if (attachmentUniqueAssetInfo == nullptr) - { - std::cerr << "Failed to load attachment unique asset \"" << attachmentUniqueName << "\"\n"; - return false; - } - - auto* attachmentUniqueAsset = attachmentUniqueAssetInfo->Asset(); - - if (HasMoreThanOneAttachmentSetInMask(attachmentUniqueAsset->combinedAttachmentTypeMask)) - { - if (attachmentCombinationIndex >= std::extent_v) - { - std::cerr << "Cannot have more than " - << (std::extent_v - std::extent_v) - << " combined attachment attachment unique entries!\n"; - return false; - } - - attachmentUniques[attachmentCombinationIndex++] = attachmentUniqueAsset; - m_dependencies.emplace(attachmentUniqueAssetInfo); - } - else - { - if (static_cast(attachmentUniqueAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT) - { - std::cerr << "Invalid attachment type " << attachmentUniqueAsset->attachmentType << " for attachment unique asset \"" - << attachmentUniqueName << "\"\n"; - return false; - } - - if (attachmentUniques[attachmentUniqueAsset->attachmentType] != nullptr) - { - std::cerr << "Already loaded attachment unique with same type " << attachmentUniqueAsset->attachmentType << ": \"" - << attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName << "\", \"" << attachmentUniqueName << "\"\n"; - return false; - } - - attachmentUniques[attachmentUniqueAsset->attachmentType] = attachmentUniqueAsset; - m_dependencies.emplace(attachmentUniqueAssetInfo); - } - } - - return true; - } - - bool ConvertAnimName(const cspField_t& field, const std::string& value) - { - if (ConvertString(value, field.iOffset)) - { - if (!value.empty()) - m_indirect_asset_references.emplace(m_loading_manager->LoadIndirectAssetReference(value)); - - return true; - } - - return false; - } - - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - switch (static_cast(field.iFieldType)) - { - case WFT_WEAPONTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapTypeNames, std::extent_v); - - case WFT_WEAPONCLASS: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapClassNames, std::extent_v); - - case WFT_OVERLAYRETICLE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapOverlayReticleNames, std::extent_v); - - case WFT_PENETRATE_TYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, penetrateTypeNames, std::extent_v); - - case WFT_IMPACT_TYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, impactTypeNames, std::extent_v); - - case WFT_STANCE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapStanceNames, std::extent_v); - - case WFT_PROJ_EXPLOSION: - return ConvertEnumInt(field.szName, value, field.iOffset, szProjectileExplosionNames, std::extent_v); - - case WFT_OFFHAND_CLASS: - return ConvertEnumInt(field.szName, value, field.iOffset, offhandClassNames, std::extent_v); - - case WFT_OFFHAND_SLOT: - return ConvertEnumInt(field.szName, value, field.iOffset, offhandSlotNames, std::extent_v); - - case WFT_ANIMTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, playerAnimTypeNames, std::extent_v); - - case WFT_ACTIVE_RETICLE_TYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, activeReticleNames, std::extent_v); - - case WFT_GUIDED_MISSILE_TYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, guidedMissileNames, std::extent_v); - - case WFT_BOUNCE_SOUND: - return ConvertBounceSounds(field, value); - - case WFT_STICKINESS: - return ConvertEnumInt(field.szName, value, field.iOffset, stickinessNames, std::extent_v); - - case WFT_ROTATETYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, rotateTypeNames, std::extent_v); - - case WFT_OVERLAYINTERFACE: - return ConvertEnumInt(field.szName, value, field.iOffset, overlayInterfaceNames, std::extent_v); - - case WFT_INVENTORYTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapInventoryTypeNames, std::extent_v); - - case WFT_FIRETYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapFireTypeNames, std::extent_v); - - case WFT_CLIPTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapClipTypeNames, std::extent_v); - - case WFT_AMMOCOUNTER_CLIPTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, ammoCounterClipNames, std::extent_v); - - case WFT_ICONRATIO_HUD: - case WFT_ICONRATIO_AMMOCOUNTER: - case WFT_ICONRATIO_KILL: - case WFT_ICONRATIO_DPAD: - case WFT_ICONRATIO_INDICATOR: - return ConvertEnumInt(field.szName, value, field.iOffset, weapIconRatioNames, std::extent_v); - - case WFT_BARRELTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, barrelTypeNames, std::extent_v); - - case WFT_HIDETAGS: - return ConvertHideTags(field, value); - - case WFT_EXPLOSION_TAG: - return ConvertScriptString(value, field.iOffset); - - case WFT_NOTETRACKSOUNDMAP: - return ConvertNotetrackSoundMap(field, value); - - case WFT_WEAPON_CAMO: - return ConvertWeaponCamo(field, value); - - case WFT_ATTACHMENTS: - return ConvertAttachments(field, value); - - case WFT_ATTACHMENT_UNIQUES: - return ConvertAttachmentUniques(field, value); - - case WFT_ANIM_NAME: - return ConvertAnimName(field, value); - - default: - assert(false); - return false; - } - } - - public: - InfoStringToWeaponConverter(const InfoString& infoString, - WeaponFullDef* weaponFullDef, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, weaponFullDef, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; - - void ConvertAccuracyGraph( - const GenericGraph2D& graph, vec2_t*& originalGraphKnots, int& originalGraphKnotCount, vec2_t*& graphKnots, int& graphKnotCount, MemoryManager* memory) - { - originalGraphKnotCount = static_cast(graph.knots.size()); - originalGraphKnots = memory->Alloc(originalGraphKnotCount); - - for (auto i = 0; i < originalGraphKnotCount; i++) - { - const auto& commonKnot = graph.knots[i]; - originalGraphKnots[i].x = static_cast(commonKnot.x); - originalGraphKnots[i].y = static_cast(commonKnot.y); - } - - graphKnots = originalGraphKnots; - graphKnotCount = originalGraphKnotCount; - } - - bool LoadAccuracyGraphs(WeaponFullDef* weaponFullDef, MemoryManager* memory, const IAssetLoadingManager* manager) - { - auto* accuracyGraphLoader = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState(); - - if (weaponFullDef->weapDef.aiVsAiAccuracyGraphName && weaponFullDef->weapDef.aiVsAiAccuracyGraphName[0]) - { - const auto* graph = accuracyGraphLoader->LoadAiVsAiGraph(manager, weaponFullDef->weapDef.aiVsAiAccuracyGraphName); - if (!graph) - return false; - - ConvertAccuracyGraph(*graph, - weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnots, - weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnotCount, - weaponFullDef->weapDef.aiVsAiAccuracyGraphKnots, - weaponFullDef->weapDef.aiVsAiAccuracyGraphKnotCount, - memory); - } - - if (weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName && weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName[0]) - { - const auto* graph = accuracyGraphLoader->LoadAiVsPlayerGraph(manager, weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName); - if (!graph) - return false; - - ConvertAccuracyGraph(*graph, - weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnots, - weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnotCount, - weaponFullDef->weapDef.aiVsPlayerAccuracyGraphKnots, - weaponFullDef->weapDef.aiVsPlayerAccuracyGraphKnotCount, - memory); - } - - return true; - } -} // namespace T6 - -void AssetLoaderWeapon::LinkWeaponFullDefSubStructs(WeaponFullDef* weapon) -{ - weapon->weapVariantDef.weapDef = &weapon->weapDef; - weapon->weapVariantDef.attachments = weapon->attachments; - weapon->weapVariantDef.attachmentUniques = weapon->attachmentUniques; - weapon->weapDef.gunXModel = weapon->gunXModel; - weapon->weapVariantDef.szXAnims = weapon->szXAnims; - weapon->weapVariantDef.hideTags = weapon->hideTags; - weapon->weapDef.notetrackSoundMapKeys = weapon->notetrackSoundMapKeys; - weapon->weapDef.notetrackSoundMapValues = weapon->notetrackSoundMapValues; - weapon->weapDef.worldModel = weapon->worldModel; - weapon->weapVariantDef.attachViewModel = weapon->attachViewModel; - weapon->weapVariantDef.attachWorldModel = weapon->attachWorldModel; - weapon->weapVariantDef.attachViewModelTag = weapon->attachViewModelTag; - weapon->weapVariantDef.attachWorldModelTag = weapon->attachWorldModelTag; - weapon->weapDef.parallelBounce = weapon->parallelBounce; - weapon->weapDef.perpendicularBounce = weapon->perpendicularBounce; - weapon->weapDef.locationDamageMultipliers = weapon->locationDamageMultipliers; -} - -void AssetLoaderWeapon::CalculateWeaponFields(WeaponFullDef* weapon) -{ - // iAttachments - weapon->weapVariantDef.iAttachments = 0; - for (auto i = 1u; i < sizeof(WeaponVariantDef::iAttachments) * 8; i++) // Bit for default attachment always 0 - { - if (weapon->attachments[i]) - weapon->weapVariantDef.iAttachments |= 1 << i; - } - - if (weapon->weapVariantDef.iAdsTransInTime <= 0) - weapon->weapVariantDef.fOOPosAnimLength[0] = 0.0033333334f; - else - weapon->weapVariantDef.fOOPosAnimLength[0] = 1.0f / static_cast(weapon->weapVariantDef.iAdsTransInTime); - - if (weapon->weapVariantDef.iAdsTransOutTime <= 0) - weapon->weapVariantDef.fOOPosAnimLength[1] = 0.0020000001f; - else - weapon->weapVariantDef.fOOPosAnimLength[1] = 1.0f / static_cast(weapon->weapVariantDef.iAdsTransOutTime); -} - -bool AssetLoaderWeapon::IsStringOverride(const char* baseString, const char* overrideString) -{ - if (overrideString == nullptr || overrideString[0] == '\0') - return false; - - if (baseString == nullptr || baseString[0] == '\0') - return true; - - return strcmp(baseString, overrideString) != 0; -} - -bool AssetLoaderWeapon::IsFxOverride(const FxEffectDef* baseEffect, const FxEffectDef* overrideEffect) -{ - if (overrideEffect == nullptr) - return false; - - if (baseEffect == nullptr) - return true; - - return strcmp(baseEffect->name, overrideEffect->name) != 0; -} - -void AssetLoaderWeapon::HandleSoundOverride(WeaponAttachmentUnique* attachmentUnique, - const char* snd1, - const char* snd2, - const eAttachmentOverrideSounds sndOverrideIndex) -{ - if (IsStringOverride(snd1, snd2)) - attachmentUnique->soundOverrides |= 1 << static_cast(sndOverrideIndex); -} - -void AssetLoaderWeapon::HandleFxOverride(WeaponAttachmentUnique* attachmentUnique, - const FxEffectDef* effect1, - const FxEffectDef* effect2, - const eAttachmentOverrideEffects fxOverrideIndex) -{ - if (IsFxOverride(effect1, effect2)) - attachmentUnique->effectOverrides |= 1 << static_cast(fxOverrideIndex); -} - -void AssetLoaderWeapon::CalculateAttachmentFields(const WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique) -{ - for (auto& val : attachmentUnique->animationOverrides) - val = 0; - - for (auto animIndex = 0u; animIndex < std::extent_v; animIndex++) - { - if (IsStringOverride(weapon->szXAnims[animIndex], attachmentUnique->szXAnims[animIndex])) - attachmentUnique->animationOverrides[animIndex / 32] |= 1 << (animIndex % 32); - } - - attachmentUnique->soundOverrides = 0; - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireSound, attachmentUnique->fireSound, ATTACHMENT_OVERRIDE_SOUND_FIRE); - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireSoundPlayer, attachmentUnique->fireSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_PLAYER); - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireLoopSound, attachmentUnique->fireLoopSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP); - HandleSoundOverride( - attachmentUnique, weapon->weapDef.fireLoopSoundPlayer, attachmentUnique->fireLoopSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP_PLAYER); - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireLoopEndSound, attachmentUnique->fireLoopEndSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP_END); - HandleSoundOverride( - attachmentUnique, weapon->weapDef.fireLoopEndSoundPlayer, attachmentUnique->fireLoopEndSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP_END_PLAYER); - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireStartSound, attachmentUnique->fireStartSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_START); - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireStopSound, attachmentUnique->fireStopSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_STOP); - HandleSoundOverride( - attachmentUnique, weapon->weapDef.fireStartSoundPlayer, attachmentUnique->fireStartSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_START_PLAYER); - HandleSoundOverride( - attachmentUnique, weapon->weapDef.fireStopSoundPlayer, attachmentUnique->fireStopSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_STOP_PLAYER); - HandleSoundOverride(attachmentUnique, weapon->weapDef.fireLastSound, attachmentUnique->fireLastSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_LAST); - HandleSoundOverride( - attachmentUnique, weapon->weapDef.fireLastSoundPlayer, attachmentUnique->fireLastSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_LAST_PLAYER); - - attachmentUnique->effectOverrides = 0; - HandleFxOverride(attachmentUnique, weapon->weapDef.viewFlashEffect, attachmentUnique->viewFlashEffect, ATTACHMENT_OVERRIDE_EFFECT_VIEW_FLASH); - HandleFxOverride(attachmentUnique, weapon->weapDef.worldFlashEffect, attachmentUnique->worldFlashEffect, ATTACHMENT_OVERRIDE_EFFECT_WORLD_FLASH); - - attachmentUnique->childLink = 0; - if (attachmentUnique->combinedAttachmentTypeMask == 0) - { - WeaponAttachmentUnique* lastSibling = nullptr; - for (auto attachmentUniqueIndex = std::extent_v; - attachmentUniqueIndex < std::extent_v; - attachmentUniqueIndex++) - { - if (weapon->attachmentUniques[attachmentUniqueIndex] != nullptr - && weapon->attachmentUniques[attachmentUniqueIndex]->combinedAttachmentTypeMask & (1 << static_cast(attachmentUnique->attachmentType)) - && weapon->attachmentUniques[attachmentUniqueIndex]->attachmentType != attachmentUnique->attachmentType) - { - std::vector attachments; - if (AssetLoaderWeaponAttachmentUnique::ExtractAttachmentsFromAssetName(weapon->attachmentUniques[attachmentUniqueIndex]->szInternalName, - attachments) - && attachments.front() == attachmentUnique->attachmentType) - { - if (lastSibling == nullptr) - { - attachmentUnique->childLink = attachmentUniqueIndex; - lastSibling = weapon->attachmentUniques[attachmentUniqueIndex]; - } - else - { - lastSibling->siblingLink = attachmentUniqueIndex; - lastSibling = weapon->attachmentUniques[attachmentUniqueIndex]; - } - } - } - } - } -} - -void AssetLoaderWeapon::CalculateAttachmentFields(const WeaponFullDef* weapon) -{ - for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent_v; attachmentUniqueIndex++) - { - if (weapon->attachmentUniques[attachmentUniqueIndex] == nullptr) - continue; - - CalculateAttachmentFields(weapon, attachmentUniqueIndex, weapon->attachmentUniques[attachmentUniqueIndex]); - } -} - -bool AssetLoaderWeapon::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - auto* weaponFullDef = memory->Create(); - memset(weaponFullDef, 0, sizeof(WeaponFullDef)); - LinkWeaponFullDefSubStructs(weaponFullDef); - - InfoStringToWeaponConverter converter( - infoString, weaponFullDef, zone->m_script_strings, memory, manager, weapon_fields, std::extent_v); - if (!converter.Convert()) - { - std::cerr << "Failed to parse weapon: \"" << assetName << "\"\n"; - return true; - } - - weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str()); - - // TODO: Load flametable - CalculateWeaponFields(weaponFullDef); - CalculateAttachmentFields(weaponFullDef); - - LoadAccuracyGraphs(weaponFullDef, memory, manager); - - manager->AddAsset( - assetName, &weaponFullDef->weapVariantDef, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences()); - - return true; -} - -void* AssetLoaderWeapon::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* weaponFullDef = memory->Alloc(); - LinkWeaponFullDefSubStructs(weaponFullDef); - CalculateWeaponFields(weaponFullDef); - weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str()); - return weaponFullDef; -} - -bool AssetLoaderWeapon::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderWeapon::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cerr << "Failed to read weapon gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderWeapon::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderWeapon::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "weapons/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h deleted file mode 100644 index 9a9cb4fc..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderWeapon final : public BasicAssetLoader - { - static void LinkWeaponFullDefSubStructs(WeaponFullDef* weapon); - - static bool IsStringOverride(const char* baseString, const char* overrideString); - static bool IsFxOverride(const FxEffectDef* baseEffect, const FxEffectDef* overrideEffect); - static void - HandleSoundOverride(WeaponAttachmentUnique* attachmentUnique, const char* snd1, const char* snd2, eAttachmentOverrideSounds sndOverrideIndex); - static void HandleFxOverride(WeaponAttachmentUnique* attachmentUnique, - const FxEffectDef* effect1, - const FxEffectDef* effect2, - eAttachmentOverrideEffects fxOverrideIndex); - - static void CalculateWeaponFields(WeaponFullDef* weapon); - static void CalculateAttachmentFields(const WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique); - static void CalculateAttachmentFields(const WeaponFullDef* weapon); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp deleted file mode 100644 index 46ce62f9..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include "AssetLoaderWeaponAttachment.h" - -#include "Game/T6/InfoString/EnumStrings.h" -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/WeaponAttachmentFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - eAttachmentPoint attachmentPointByAttachmentTable[]{ - ATTACHMENT_POINT_NONE, // none - ATTACHMENT_POINT_TOP, // acog - ATTACHMENT_POINT_TRIGGER, // dualclip - ATTACHMENT_POINT_TOP, // dualoptic - ATTACHMENT_POINT_BOTTOM, // dw - ATTACHMENT_POINT_MUZZLE, // extbarrel - ATTACHMENT_POINT_TRIGGER, // extclip - ATTACHMENT_POINT_TRIGGER, // extramags - ATTACHMENT_POINT_GUNPERK, // fastads - ATTACHMENT_POINT_TOP, // fastreload - ATTACHMENT_POINT_TRIGGER, // fmj - ATTACHMENT_POINT_BOTTOM, // gl - ATTACHMENT_POINT_BOTTOM, // grip - ATTACHMENT_POINT_TOP, // holo - ATTACHMENT_POINT_BOTTOM, // ir - ATTACHMENT_POINT_BOTTOM, // is - ATTACHMENT_POINT_GUNPERK, // longbreath - ATTACHMENT_POINT_BOTTOM, // mk - ATTACHMENT_POINT_TOP, // mms - ATTACHMENT_POINT_TOP, // rangefinder - ATTACHMENT_POINT_TOP, // reflex - ATTACHMENT_POINT_MUZZLE, // rf - ATTACHMENT_POINT_BOTTOM, // sf - ATTACHMENT_POINT_MUZZLE, // silencer - ATTACHMENT_POINT_TRIGGER, // stackfire - ATTACHMENT_POINT_GUNPERK, // stalker - ATTACHMENT_POINT_GUNPERK, // steadyaim - ATTACHMENT_POINT_GUNPERK, // swayreduc - ATTACHMENT_POINT_TOP, // tacknife - ATTACHMENT_POINT_TOP, // vzoom - }; - - static_assert(std::extent_v == ATTACHMENT_TYPE_COUNT); - - class InfoStringToWeaponAttachmentConverter final : public InfoStringToStructConverter - { - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - switch (static_cast(field.iFieldType)) - { - case AFT_ATTACHMENTTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szAttachmentTypeNames, std::extent_v); - - case AFT_PENETRATE_TYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, penetrateTypeNames, std::extent_v); - - case AFT_FIRETYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapFireTypeNames, std::extent_v); - - default: - assert(false); - return false; - } - } - - public: - InfoStringToWeaponAttachmentConverter(const InfoString& infoString, - WeaponAttachment* weaponAttachment, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, weaponAttachment, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace T6 - -void AssetLoaderWeaponAttachment::CalculateAttachmentFields(WeaponAttachment* attachment) -{ - // attachmentPoint - if (static_cast(attachment->attachmentType) < ATTACHMENT_TYPE_COUNT) - { - attachment->attachmentPoint = attachmentPointByAttachmentTable[attachment->attachmentType]; - } -} - -bool AssetLoaderWeaponAttachment::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - auto* attachment = memory->Create(); - memset(attachment, 0, sizeof(WeaponAttachment)); - - InfoStringToWeaponAttachmentConverter converter( - infoString, attachment, zone->m_script_strings, memory, manager, attachment_fields, std::extent_v); - if (!converter.Convert()) - { - std::cerr << "Failed to parse attachment: \"" << assetName << "\"\n"; - return true; - } - - CalculateAttachmentFields(attachment); - attachment->szInternalName = memory->Dup(assetName.c_str()); - - manager->AddAsset( - assetName, attachment, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences()); - - return true; -} - -void* AssetLoaderWeaponAttachment::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* attachment = memory->Alloc(); - CalculateAttachmentFields(attachment); - attachment->szInternalName = memory->Dup(assetName.c_str()); - return attachment; -} - -bool AssetLoaderWeaponAttachment::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderWeaponAttachment::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cerr << "Failed to read attachment gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderWeaponAttachment::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderWeaponAttachment::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "attachment/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.h deleted file mode 100644 index 9c03b87b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderWeaponAttachment final : public BasicAssetLoader - { - static void CalculateAttachmentFields(WeaponAttachment* attachment); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp deleted file mode 100644 index 885576d1..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp +++ /dev/null @@ -1,292 +0,0 @@ -#include "AssetLoaderWeaponAttachmentUnique.h" - -#include "Game/T6/InfoString/EnumStrings.h" -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/WeaponAttachmentUniqueFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "Utils/ClassUtils.h" - -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringToWeaponAttachmentUniqueConverter final : public InfoStringToStructConverter - { - bool ConvertHideTags(const cspField_t& field, const std::string& value) - { - std::vector valueArray; - if (!ParseAsArray(value, valueArray)) - { - std::cerr << "Failed to parse hide tags as array\n"; - return false; - } - - if (valueArray.size() > std::extent_v) - { - std::cerr << "Cannot have more than " << std::extent_v << " hide tags!\n"; - return false; - } - - auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - - if (valueArray.size() < std::extent_v) - { - m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString(nullptr)); - } - - auto currentHideTag = 0u; - for (; currentHideTag < valueArray.size(); currentHideTag++) - { - const auto& currentValue = valueArray[currentHideTag]; - const auto scrString = - !currentValue.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue) : m_zone_script_strings.AddOrGetScriptString(nullptr); - hideTags[currentHideTag] = scrString; - m_used_script_string_list.emplace(scrString); - } - - for (; currentHideTag < std::extent_v; currentHideTag++) - { - hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(nullptr); - } - - return true; - } - - _NODISCARD bool ConvertWeaponCamo(const cspField_t& field, const std::string& value) - { - if (value.empty()) - { - *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = nullptr; - return true; - } - - auto* camo = m_loading_manager->LoadDependency(value); - - if (camo == nullptr) - { - std::cerr << "Failed to load camo asset \"" << value << "\"\n"; - return false; - } - - m_dependencies.emplace(camo); - *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = camo->Asset(); - - return true; - } - - bool ConvertAnimName(const cspField_t& field, const std::string& value) - { - if (ConvertString(value, field.iOffset)) - { - if (!value.empty()) - m_indirect_asset_references.emplace(m_loading_manager->LoadIndirectAssetReference(value)); - - return true; - } - - return false; - } - - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - switch (static_cast(field.iFieldType)) - { - case AUFT_ATTACHMENTTYPE: - return ConvertEnumInt(field.szName, value, field.iOffset, szAttachmentTypeNames, std::extent_v); - - case AUFT_HIDETAGS: - return ConvertHideTags(field, value); - - case AUFT_OVERLAYRETICLE: - return ConvertEnumInt(field.szName, value, field.iOffset, szWeapOverlayReticleNames, std::extent_v); - - case AUFT_CAMO: - return ConvertWeaponCamo(field, value); - - case AUFT_ANIM_NAME: - return ConvertAnimName(field, value); - - default: - assert(false); - return false; - } - } - - public: - InfoStringToWeaponAttachmentUniqueConverter(const InfoString& infoString, - WeaponAttachmentUniqueFull* attachmentUniqueFull, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, attachmentUniqueFull, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace T6 - -bool AssetLoaderWeaponAttachmentUnique::ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList) -{ - std::vector parts; - - auto attachCount = 1u; - auto partStart = 0u; - for (auto ci = 0u; ci < assetName.size(); ci++) - { - if (assetName[ci] == '_') - { - parts.emplace_back(assetName, partStart, ci - partStart); - partStart = ci + 1; - } - else if (assetName[ci] == '+') - { - attachCount++; - parts.emplace_back(assetName, partStart, ci - partStart); - partStart = ci + 1; - } - } - - if (partStart < assetName.size()) - parts.emplace_back(assetName, partStart, assetName.size() - partStart); - - for (auto attachPartOffset = parts.size() - attachCount; attachPartOffset < parts.size(); attachPartOffset++) - { - auto& specifiedAttachName = parts[attachPartOffset]; - - for (auto& c : specifiedAttachName) - c = static_cast(tolower(c)); - - auto foundAttachment = false; - for (auto attachIndex = 0u; attachIndex < std::extent_v; attachIndex++) - { - if (specifiedAttachName == szAttachmentTypeNames[attachIndex]) - { - attachmentList.push_back(static_cast(attachIndex)); - foundAttachment = true; - break; - } - } - - if (!foundAttachment) - return false; - } - - return true; -} - -void AssetLoaderWeaponAttachmentUnique::LinkAttachmentUniqueFullSubStructs(WeaponAttachmentUniqueFull* attachmentUnique) -{ - attachmentUnique->attachment.hideTags = attachmentUnique->hideTags; - attachmentUnique->attachment.szXAnims = attachmentUnique->szXAnims; - attachmentUnique->attachment.locationDamageMultipliers = attachmentUnique->locationDamageMultipliers; -} - -bool AssetLoaderWeaponAttachmentUnique::CalculateAttachmentUniqueFields(const std::string& assetName, WeaponAttachmentUniqueFull* attachmentUnique) -{ - // combinedAttachmentTypeMask - std::vector attachmentsFromName; - if (!ExtractAttachmentsFromAssetName(assetName, attachmentsFromName)) - { - std::cerr << "Failed to determine attachments from attachment unique name \"" << assetName << "\"\n"; - return false; - } - - if (attachmentsFromName.size() > 1) - { - for (const auto attachment : attachmentsFromName) - { - attachmentUnique->attachment.combinedAttachmentTypeMask |= 1 << attachment; - } - } - - return true; -} - -bool AssetLoaderWeaponAttachmentUnique::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - - auto* attachmentUniqueFull = memory->Create(); - memset(attachmentUniqueFull, 0, sizeof(WeaponAttachmentUniqueFull)); - LinkAttachmentUniqueFullSubStructs(attachmentUniqueFull); - - InfoStringToWeaponAttachmentUniqueConverter converter( - infoString, attachmentUniqueFull, zone->m_script_strings, memory, manager, attachment_unique_fields, std::extent_v); - if (!converter.Convert()) - { - std::cerr << "Failed to parse attachment unique: \"" << assetName << "\"\n"; - return true; - } - - if (!CalculateAttachmentUniqueFields(assetName, attachmentUniqueFull)) - return true; - - attachmentUniqueFull->attachment.szInternalName = memory->Dup(assetName.c_str()); - - manager->AddAsset( - assetName, &attachmentUniqueFull->attachment, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences()); - - return true; -} - -void* AssetLoaderWeaponAttachmentUnique::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* attachmentUniqueFull = memory->Alloc(); - LinkAttachmentUniqueFullSubStructs(attachmentUniqueFull); - CalculateAttachmentUniqueFields(assetName, attachmentUniqueFull); - attachmentUniqueFull->attachment.szInternalName = memory->Dup(assetName.c_str()); - return attachmentUniqueFull; -} - -bool AssetLoaderWeaponAttachmentUnique::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderWeaponAttachmentUnique::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cerr << "Failed to read attachment unique gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderWeaponAttachmentUnique::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderWeaponAttachmentUnique::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "attachmentunique/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.h deleted file mode 100644 index 23f5548d..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderWeaponAttachmentUnique final : public BasicAssetLoader - { - static void LinkAttachmentUniqueFullSubStructs(WeaponAttachmentUniqueFull* attachmentUnique); - static bool CalculateAttachmentUniqueFields(const std::string& assetName, WeaponAttachmentUniqueFull* attachmentUnique); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - static bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList); - - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.cpp deleted file mode 100644 index 671ecbb8..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "AssetLoaderWeaponCamo.h" - -#include "Game/T6/T6.h" -#include "Game/T6/WeaponCamo/JsonWeaponCamoLoader.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace T6; - -void* AssetLoaderWeaponCamo::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderWeaponCamo::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderWeaponCamo::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = std::format("camo/{}.json", assetName); - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - auto* weaponCamo = memory->Alloc(); - weaponCamo->name = memory->Dup(assetName.c_str()); - - std::vector dependencies; - if (LoadWeaponCamoAsJson(*file.m_stream, *weaponCamo, memory, manager, dependencies)) - manager->AddAsset(assetName, weaponCamo, std::move(dependencies)); - else - std::cerr << "Failed to load weapon camo \"" << assetName << "\"\n"; - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.h deleted file mode 100644 index bd8a75c6..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderWeaponCamo final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXAnim.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXAnim.cpp deleted file mode 100644 index 9e2516a0..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXAnim.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderXAnim.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderXAnim::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXAnim.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXAnim.h deleted file mode 100644 index 3e270ac6..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXAnim.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderXAnim final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXGlobals.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXGlobals.cpp deleted file mode 100644 index e1c2b937..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXGlobals.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "AssetLoaderXGlobals.h" - -#include "Game/T6/T6.h" -#include "ObjLoading.h" - -using namespace T6; - -void* AssetLoaderXGlobals::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXGlobals.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXGlobals.h deleted file mode 100644 index c510101b..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXGlobals.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderXGlobals final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.cpp deleted file mode 100644 index 28dfcc01..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "AssetLoaderXModel.h" - -#include "Game/T6/T6.h" -#include "Game/T6/XModel/XModelLoaderT6.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace T6; - -void* AssetLoaderXModel::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderXModel::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderXModel::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(std::format("xmodel/{}.json", assetName)); - if (!file.IsOpen()) - return false; - - auto* xmodel = memory->Alloc(); - xmodel->name = memory->Dup(assetName.c_str()); - - std::vector dependencies; - if (LoadXModel(*file.m_stream, *xmodel, memory, manager, dependencies)) - { - manager->AddAsset(assetName, xmodel, std::move(dependencies)); - } - else - { - std::cerr << std::format("Failed to load xmodel \"{}\"\n", assetName); - return false; - } - - return true; -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.h deleted file mode 100644 index 8a39a8dc..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderXModel.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderXModel final : public BasicAssetLoader - { - static std::string GetFileNameForAsset(const std::string& assetName); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp deleted file mode 100644 index c8cf1fda..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "AssetLoaderZBarrier.h" - -#include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/ZBarrierFields.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringToZBarrierConverter final : public InfoStringToStructConverter - { - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - assert(false); - return false; - } - - public: - InfoStringToZBarrierConverter(const InfoString& infoString, - ZBarrierDef* zbarrier, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, zbarrier, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace T6 - -void AssetLoaderZBarrier::CalculateZBarrierFields(ZBarrierDef* zbarrier) -{ - // numBoardsInBarrier - { - auto foundEnd = false; - for (auto i = 0u; i < std::extent_v; i++) - { - if (zbarrier->boards[i].pBoardModel == nullptr) - { - foundEnd = true; - zbarrier->numBoardsInBarrier = i; - break; - } - } - - if (!foundEnd) - zbarrier->numBoardsInBarrier = std::extent_v; - } -} - -bool AssetLoaderZBarrier::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - auto* zbarrier = memory->Create(); - memset(zbarrier, 0, sizeof(ZBarrierDef)); - - InfoStringToZBarrierConverter converter( - infoString, zbarrier, zone->m_script_strings, memory, manager, zbarrier_fields, std::extent_v); - if (!converter.Convert()) - { - std::cout << "Failed to parse zbarrier: \"" << assetName << "\"\n"; - return true; - } - - CalculateZBarrierFields(zbarrier); - zbarrier->name = memory->Dup(assetName.c_str()); - - manager->AddAsset(assetName, zbarrier, converter.GetDependencies(), converter.GetUsedScriptStrings()); - - return true; -} - -void* AssetLoaderZBarrier::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* zbarrier = memory->Alloc(); - CalculateZBarrierFields(zbarrier); - zbarrier->name = memory->Dup(assetName.c_str()); - return zbarrier; -} - -bool AssetLoaderZBarrier::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderZBarrier::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_ZBARRIER, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cout << "Failed to read zbarrier gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderZBarrier::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderZBarrier::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "zbarrier/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.h deleted file mode 100644 index 77e23b17..00000000 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace T6 -{ - class AssetLoaderZBarrier final : public BasicAssetLoader - { - static void CalculateZBarrierFields(ZBarrierDef* zbarrier); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/FontIcon/LoaderFontIconT6.cpp b/src/ObjLoading/Game/T6/FontIcon/LoaderFontIconT6.cpp new file mode 100644 index 00000000..bcdfb938 --- /dev/null +++ b/src/ObjLoading/Game/T6/FontIcon/LoaderFontIconT6.cpp @@ -0,0 +1,292 @@ +#include "LoaderFontIconT6.h" + +#include "Csv/CsvStream.h" +#include "Game/T6/CommonT6.h" +#include "Game/T6/T6.h" + +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + constexpr unsigned ROW_INDEX = 0; + constexpr unsigned ROW_TYPE = 1; + + constexpr unsigned ROW_ICON_NAME = 2; + constexpr unsigned ROW_ICON_MATERIAL = 3; + constexpr unsigned ROW_ICON_SIZE = 4; + constexpr unsigned ROW_ICON_XSCALE = 5; + constexpr unsigned ROW_ICON_YSCALE = 6; + + constexpr unsigned ROW_ALIAS_NAME = 2; + constexpr unsigned ROW_ALIAS_BUTTON = 3; + + constexpr const char* VALUE_TYPE_ICON = "icon"; + constexpr const char* VALUE_TYPE_ALIAS = "alias"; + + constexpr unsigned COL_COUNT_ICON = 7; + constexpr unsigned COL_COUNT_ALIAS = 4; + constexpr unsigned COL_COUNT_MIN = std::min(COL_COUNT_ICON, COL_COUNT_ALIAS); + + class FontIconLoader final : public AssetCreator + { + public: + FontIconLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* fontIcon = m_memory.Alloc(); + fontIcon->name = m_memory.Dup(assetName.c_str()); + AssetRegistration registration(assetName, fontIcon); + + const CsvInputStream csv(*file.m_stream); + std::vector currentRow; + std::vector entries; + std::vector aliases; + auto currentRowIndex = 0u; + + while (csv.NextRow(currentRow)) + { + currentRowIndex++; + PreprocessRow(currentRow); + + if (RowIsEmpty(currentRow)) + continue; + + if (currentRow.size() < COL_COUNT_MIN) + { + std::cerr << std::format("{} Column count lower than min column count ({})\n", ErrorPrefix(assetName, currentRowIndex), COL_COUNT_MIN); + return AssetCreationResult::Failure(); + } + + int index; + if (!ParseInt(index, currentRow[ROW_INDEX]) || index < 0) + { + std::cerr << std::format("{} Failed to parse index\n", ErrorPrefix(assetName, currentRowIndex)); + return AssetCreationResult::Failure(); + } + + if (currentRow[ROW_TYPE] == VALUE_TYPE_ICON) + { + FontIconEntry icon{}; + if (!ReadIconRow(currentRow, icon, assetName, currentRowIndex, context, registration)) + return AssetCreationResult::Failure(); + + if (static_cast(index) == entries.size()) + { + entries.push_back(icon); + } + else if (static_cast(index) > entries.size()) + { + entries.reserve(index + 1); + entries[index] = icon; + } + else + { + entries[index] = icon; + } + } + else if (currentRow[ROW_TYPE] == VALUE_TYPE_ALIAS) + { + FontIconAlias alias{}; + if (!ReadAliasRow(currentRow, alias, assetName, currentRowIndex, context)) + return AssetCreationResult::Failure(); + + if (static_cast(index) == aliases.size()) + { + aliases.push_back(alias); + } + else if (static_cast(index) > aliases.size()) + { + aliases.reserve(index + 1); + aliases[index] = alias; + } + else + { + aliases[index] = alias; + } + } + else + { + std::cerr << std::format("{} Unknown row type \"{}\"\n", ErrorPrefix(assetName, currentRowIndex), currentRow[ROW_TYPE]); + return AssetCreationResult::Failure(); + } + } + + fontIcon->numEntries = entries.size(); + fontIcon->numAliasEntries = aliases.size(); + + if (fontIcon->numEntries > 0) + { + fontIcon->fontIconEntry = m_memory.Alloc(fontIcon->numEntries); + for (auto i = 0u; i < entries.size(); i++) + fontIcon->fontIconEntry[i] = entries[i]; + } + else + fontIcon->fontIconEntry = nullptr; + + if (fontIcon->numAliasEntries > 0) + { + fontIcon->fontIconAlias = m_memory.Alloc(fontIcon->numAliasEntries); + for (auto i = 0u; i < aliases.size(); i++) + fontIcon->fontIconAlias[i] = aliases[i]; + } + else + fontIcon->fontIconAlias = nullptr; + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + + private: + static std::string ErrorPrefix(const std::string& assetName, const unsigned rowIndex) + { + return std::format("FontIcon \"{}\" Row {}:", assetName, rowIndex); + } + + static void PreprocessRow(std::vector& row) + { + for (auto& cell : row) + { + for (auto c : cell) + { + if (isspace(c)) + continue; + if (c == '#') + cell = ""; + break; + } + } + } + + static bool RowIsEmpty(const std::vector& row) + { + return std::ranges::all_of(row, + [](const std::string& cell) + { + return cell.empty(); + }); + } + + static bool ParseInt(int& value, const std::string& str) + { + char* endPtr; + value = strtol(str.c_str(), &endPtr, 0); + if (endPtr != &str[str.size()]) + return false; + return true; + } + + static bool ParseFloat(float& value, const std::string& str) + { + char* endPtr; + value = strtof(str.c_str(), &endPtr); + if (endPtr != &str[str.size()]) + return false; + return true; + } + + static bool ParseHashStr(int& value, const std::string& str) + { + if (!str.empty() && str[0] == '@' && str.size() > 1) + { + char* endPtr; + value = strtol(&str[1], &endPtr, 16); + + if (endPtr != &str[str.size()]) + return false; + } + else + { + value = Common::Com_HashString(str.c_str()); + } + + return true; + } + + bool ReadIconRow(const std::vector& row, + FontIconEntry& icon, + const std::string& assetName, + const unsigned rowIndex, + AssetCreationContext& context, + AssetRegistration& registration) + { + if (row.size() < COL_COUNT_ICON) + { + std::cerr << std::format("{} Column count lower than min column count for entries ({})\n", ErrorPrefix(assetName, rowIndex), COL_COUNT_ICON); + return false; + } + + if (!ParseInt(icon.fontIconSize, row[ROW_ICON_SIZE])) + { + std::cerr << std::format("{} Failed to parse size\n", ErrorPrefix(assetName, rowIndex)); + return false; + } + + if (!ParseFloat(icon.xScale, row[ROW_ICON_XSCALE]) || !ParseFloat(icon.yScale, row[ROW_ICON_YSCALE])) + { + std::cerr << std::format("{} Failed to parse scale\n", ErrorPrefix(assetName, rowIndex)); + return false; + } + + auto* materialDependency = context.LoadDependency(row[ROW_ICON_MATERIAL]); + if (materialDependency == nullptr) + { + std::cerr << std::format("{} Failed to load material \"{}\"\n", ErrorPrefix(assetName, rowIndex), row[ROW_ICON_MATERIAL]); + return false; + } + + icon.fontIconMaterialHandle = materialDependency->Asset(); + icon.fontIconName.string = m_memory.Dup(row[ROW_ICON_NAME].c_str()); + icon.fontIconName.hash = Common::Com_HashString(icon.fontIconName.string); + + return true; + } + + bool ReadAliasRow( + const std::vector& row, FontIconAlias& alias, const std::string& assetName, const unsigned rowIndex, AssetCreationContext& context) + { + if (row.size() < COL_COUNT_ALIAS) + { + std::cerr << std::format("{} Column count lower than min column count for aliases ({})\n", ErrorPrefix(assetName, rowIndex), COL_COUNT_ALIAS); + return false; + } + + if (!ParseHashStr(alias.aliasHash, row[ROW_ALIAS_NAME])) + { + std::cerr << std::format("{} Failed to parse alias \"{}\"\n", ErrorPrefix(assetName, rowIndex), row[ROW_ALIAS_NAME]); + return false; + } + + if (!ParseHashStr(alias.buttonHash, row[ROW_ALIAS_BUTTON])) + { + std::cerr << std::format("{} Failed to parse button \"{}\"\n", ErrorPrefix(assetName, rowIndex), row[ROW_ALIAS_BUTTON]); + return false; + } + + return true; + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateFontIconLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/FontIcon/LoaderFontIconT6.h b/src/ObjLoading/Game/T6/FontIcon/LoaderFontIconT6.h new file mode 100644 index 00000000..e9f658e8 --- /dev/null +++ b/src/ObjLoading/Game/T6/FontIcon/LoaderFontIconT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateFontIconLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Image/LoaderImageT6.cpp b/src/ObjLoading/Game/T6/Image/LoaderImageT6.cpp new file mode 100644 index 00000000..76e74131 --- /dev/null +++ b/src/ObjLoading/Game/T6/Image/LoaderImageT6.cpp @@ -0,0 +1,77 @@ +#include "LoaderImageT6.h" + +#include "Game/T6/CommonT6.h" +#include "Game/T6/T6.h" +#include "Image/IwiLoader.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class ImageLoader final : public AssetCreator + { + public: + ImageLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("images/{}.iwi", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + const auto fileSize = static_cast(file.m_length); + const auto fileData = std::make_unique(fileSize); + file.m_stream->read(fileData.get(), fileSize); + const auto dataHash = static_cast(crc32(0u, reinterpret_cast(fileData.get()), fileSize)); + + std::istringstream ss(std::string(fileData.get(), fileSize)); + const auto texture = iwi::LoadIwi(ss); + if (!texture) + { + std::cerr << std::format("Failed to load texture from: {}\n", fileName); + return AssetCreationResult::Failure(); + } + + auto* image = m_memory.Alloc(); + image->name = m_memory.Dup(assetName.c_str()); + image->hash = Common::R_HashString(image->name, 0); + image->delayLoadPixels = true; + + image->noPicmip = !texture->HasMipMaps(); + image->width = static_cast(texture->GetWidth()); + image->height = static_cast(texture->GetHeight()); + image->depth = static_cast(texture->GetDepth()); + + image->streaming = 1; + image->streamedParts[0].levelCount = 1; + image->streamedParts[0].levelSize = static_cast(fileSize); + image->streamedParts[0].hash = dataHash & 0x1FFFFFFF; + image->streamedPartCount = 1; + + return AssetCreationResult::Success(context.AddAsset(assetName, image)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Image/LoaderImageT6.h b/src/ObjLoading/Game/T6/Image/LoaderImageT6.h new file mode 100644 index 00000000..6c1bfb1f --- /dev/null +++ b/src/ObjLoading/Game/T6/Image/LoaderImageT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.cpp b/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.cpp index 6866a586..d7fd2678 100644 --- a/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.cpp +++ b/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.cpp @@ -7,33 +7,36 @@ using namespace T6; +namespace +{ + bool GetHashValue(const std::string& value, unsigned& hash) + { + if (!value.empty() && value[0] == '@') + { + char* endPtr; + hash = strtoul(&value[1], &endPtr, 16); + return endPtr == &value[value.size()]; + } + + hash = Common::Com_HashString(value.c_str()); + return true; + } +} // namespace + InfoStringToStructConverter::InfoStringToStructConverter(const InfoString& infoString, void* structure, ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration, const cspField_t* fields, const size_t fieldCount) - : InfoStringToStructConverterBase(infoString, structure, zoneScriptStrings, memory), - m_loading_manager(manager), + : InfoStringToStructConverterBase(infoString, structure, zoneScriptStrings, memory, context, registration), m_fields(fields), m_field_count(fieldCount) { } -bool InfoStringToStructConverter::GetHashValue(const std::string& value, unsigned& hash) -{ - if (!value.empty() && value[0] == '@') - { - char* endPtr; - hash = strtoul(&value[1], &endPtr, 16); - return endPtr == &value[value.size()]; - } - - hash = Common::Com_HashString(value.c_str()); - return true; -} - bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, const std::string& value) { switch (static_cast(field.iFieldType)) @@ -76,15 +79,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* fx = m_loading_manager->LoadDependency(value); + auto* fx = m_context.LoadDependency(value); if (fx == nullptr) { - std::cout << "Failed to load fx asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load fx asset \"{}\"\n", value); return false; } - m_dependencies.emplace(fx); + m_registration.AddDependency(fx); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = fx->Asset(); return true; @@ -98,15 +101,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* xmodel = m_loading_manager->LoadDependency(value); + auto* xmodel = m_context.LoadDependency(value); if (xmodel == nullptr) { - std::cout << "Failed to load xmodel asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load xmodel asset \"{}\"\n", value); return false; } - m_dependencies.emplace(xmodel); + m_registration.AddDependency(xmodel); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = xmodel->Asset(); return true; @@ -121,15 +124,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* material = m_loading_manager->LoadDependency(value); + auto* material = m_context.LoadDependency(value); if (material == nullptr) { - std::cout << "Failed to load material asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load material asset \"{}\"\n", value); return false; } - m_dependencies.emplace(material); + m_registration.AddDependency(material); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = material->Asset(); return true; @@ -143,15 +146,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* physPreset = m_loading_manager->LoadDependency(value); + auto* physPreset = m_context.LoadDependency(value); if (physPreset == nullptr) { - std::cout << "Failed to load physpreset asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load physpreset asset \"{}\"\n", value); return false; } - m_dependencies.emplace(physPreset); + m_registration.AddDependency(physPreset); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = physPreset->Asset(); return true; @@ -168,15 +171,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* tracer = m_loading_manager->LoadDependency(value); + auto* tracer = m_context.LoadDependency(value); if (tracer == nullptr) { - std::cout << "Failed to load tracer asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load tracer asset \"{}\"\n", value); return false; } - m_dependencies.emplace(tracer); + m_registration.AddDependency(tracer); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = tracer->Asset(); return true; @@ -187,7 +190,7 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons unsigned int soundAliasHash; if (!GetHashValue(value, soundAliasHash)) { - std::cout << "Failed to parse value \"" << value << "\" as hash\n"; + std::cerr << std::format("Failed to parse value \"{}\" as hash\n", value); return false; } diff --git a/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.h b/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.h index 5adb8cf0..5c533635 100644 --- a/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.h +++ b/src/ObjLoading/Game/T6/InfoString/InfoStringToStructConverter.h @@ -1,4 +1,5 @@ #pragma once + #include "AssetLoading/IAssetLoadingManager.h" #include "Game/T6/T6.h" #include "InfoString/InfoStringToStructConverterBase.h" @@ -7,24 +8,22 @@ namespace T6 { class InfoStringToStructConverter : public InfoStringToStructConverterBase { - protected: - IAssetLoadingManager* m_loading_manager; - const cspField_t* m_fields; - size_t m_field_count; - - static bool GetHashValue(const std::string& value, unsigned int& hash); - - virtual bool ConvertExtensionField(const cspField_t& field, const std::string& value) = 0; - bool ConvertBaseField(const cspField_t& field, const std::string& value); - public: InfoStringToStructConverter(const InfoString& infoString, void* structure, ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration, const cspField_t* fields, size_t fieldCount); bool Convert() override; + + protected: + virtual bool ConvertExtensionField(const cspField_t& field, const std::string& value) = 0; + bool ConvertBaseField(const cspField_t& field, const std::string& value); + + const cspField_t* m_fields; + size_t m_field_count; }; } // namespace T6 diff --git a/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp b/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp index 1fb1d400..6e8686c3 100644 --- a/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp +++ b/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.cpp @@ -1,4 +1,3 @@ - #include "JsonLeaderboardDefLoader.h" #include "Game/T6/CommonT6.h" @@ -129,9 +128,9 @@ namespace namespace T6 { - bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory) + bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager& memory) { - const JsonLoader loader(stream, *memory); + const JsonLoader loader(stream, memory); return loader.Load(leaderboard); } } // namespace T6 diff --git a/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.h b/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.h index 9c145ae5..6145d04d 100644 --- a/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.h +++ b/src/ObjLoading/Game/T6/Leaderboard/JsonLeaderboardDefLoader.h @@ -7,5 +7,5 @@ namespace T6 { - bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory); + bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager& memory); } // namespace T6 diff --git a/src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.cpp b/src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.cpp new file mode 100644 index 00000000..ae08c020 --- /dev/null +++ b/src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.cpp @@ -0,0 +1,54 @@ +#include "LoaderLeaderboardT6.h" + +#include "Game/T6/CommonT6.h" +#include "Game/T6/T6.h" +#include "JsonLeaderboardDefLoader.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class LeaderboardLoader final : public AssetCreator + { + public: + LeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(std::format("leaderboards/{}.json", assetName)); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* leaderboardDef = m_memory.Alloc(); + leaderboardDef->name = m_memory.Dup(assetName.c_str()); + + if (!LoadLeaderboardAsJson(*file.m_stream, *leaderboardDef, m_memory)) + { + std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(assetName, leaderboardDef)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.h b/src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.h new file mode 100644 index 00000000..df060b90 --- /dev/null +++ b/src/ObjLoading/Game/T6/Leaderboard/LoaderLeaderboardT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Localize/AssetLoaderLocalizeT6.cpp b/src/ObjLoading/Game/T6/Localize/AssetLoaderLocalizeT6.cpp deleted file mode 100644 index 5a5564d0..00000000 --- a/src/ObjLoading/Game/T6/Localize/AssetLoaderLocalizeT6.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "AssetLoaderLocalizeT6.h" - -using namespace T6; - -AssetLoaderLocalize::AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) - : CommonLocalizeLoader(searchPath, zone), - m_memory(memory) -{ -} - -AssetCreationResult AssetLoaderLocalize::CreateAsset(const std::string& assetName, AssetCreationContext& context) -{ - return CreateLocalizeAsset(assetName, context); -} - -AssetCreationResult AssetLoaderLocalize::CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) -{ - auto* asset = m_memory.Alloc(); - asset->name = m_memory.Dup(localizeEntry.m_key.c_str()); - asset->value = m_memory.Dup(localizeEntry.m_value.c_str()); - - return AssetCreationResult::Success(context.AddAsset(localizeEntry.m_key, asset)); -} diff --git a/src/ObjLoading/Game/T6/Localize/AssetLoaderLocalizeT6.h b/src/ObjLoading/Game/T6/Localize/AssetLoaderLocalizeT6.h deleted file mode 100644 index 72db181f..00000000 --- a/src/ObjLoading/Game/T6/Localize/AssetLoaderLocalizeT6.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "Asset/AssetCreationContext.h" -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "Localize/CommonLocalizeLoader.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" -#include "Zone/Zone.h" - -namespace T6 -{ - class AssetLoaderLocalize final : public AssetCreator, public CommonLocalizeLoader - { - public: - AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); - AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override; - - protected: - AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override; - - private: - MemoryManager& m_memory; - }; -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Localize/LoaderLocalizeT6.cpp b/src/ObjLoading/Game/T6/Localize/LoaderLocalizeT6.cpp new file mode 100644 index 00000000..c4a3b77d --- /dev/null +++ b/src/ObjLoading/Game/T6/Localize/LoaderLocalizeT6.cpp @@ -0,0 +1,44 @@ +#include "LoaderLocalizeT6.h" + +#include "Localize/CommonLocalizeLoader.h" + +using namespace T6; + +namespace +{ + class LocalizeLoader final : public AssetCreator, public CommonLocalizeLoader + { + public: + LocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : CommonLocalizeLoader(searchPath, zone), + m_memory(memory) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + return CreateLocalizeAsset(assetName, context); + } + + protected: + AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override + { + auto* asset = m_memory.Alloc(); + asset->name = m_memory.Dup(localizeEntry.m_key.c_str()); + asset->value = m_memory.Dup(localizeEntry.m_value.c_str()); + + return AssetCreationResult::Success(context.AddAsset(localizeEntry.m_key, asset)); + } + + private: + MemoryManager& m_memory; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Localize/LoaderLocalizeT6.h b/src/ObjLoading/Game/T6/Localize/LoaderLocalizeT6.h new file mode 100644 index 00000000..991f53b1 --- /dev/null +++ b/src/ObjLoading/Game/T6/Localize/LoaderLocalizeT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" +#include "Zone/Zone.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.cpp b/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.cpp index 09517f39..aa3be869 100644 --- a/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.cpp +++ b/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.cpp @@ -15,11 +15,11 @@ namespace class JsonLoader { public: - JsonLoader(std::istream& stream, MemoryManager& memory, IAssetLoadingManager& manager, std::vector& dependencies) + JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) : m_stream(stream), m_memory(memory), - m_manager(manager), - m_dependencies(dependencies) + m_context(context), + m_registration(registration) { } @@ -35,7 +35,7 @@ namespace if (type != "material" || version != 1u) { - std::cerr << "Tried to load material \"" << material.info.name << "\" but did not find expected type material of version 1\n"; + std::cerr << std::format("Tried to load material \"{}\" but did not find expected type material of version 1\n", material.info.name); return false; } @@ -55,7 +55,7 @@ namespace private: static void PrintError(const Material& material, const std::string& message) { - std::cerr << "Cannot load material \"" << material.info.name << "\": " << message << "\n"; + std::cerr << std::format("Cannot load material \"{}\": {}\n", material.info.name, message); } static bool CreateGameFlagsFromJson(const JsonMaterial& jMaterial, unsigned& gameFlags) @@ -108,13 +108,13 @@ namespace textureDef.semantic = jTexture.semantic; textureDef.isMatureContent = jTexture.isMatureContent; - auto* image = m_manager.LoadDependency(jTexture.image); + auto* image = m_context.LoadDependency(jTexture.image); if (!image) { PrintError(material, std::format("Could not find textureDef image: {}", jTexture.image)); return false; } - m_dependencies.push_back(image); + m_registration.AddDependency(image); textureDef.image = image->Asset(); return true; @@ -284,13 +284,13 @@ namespace material.cameraRegion = jMaterial.cameraRegion; material.probeMipBits = jMaterial.probeMipBits; - auto* techniqueSet = m_manager.LoadDependency(jMaterial.techniqueSet); + auto* techniqueSet = m_context.LoadDependency(jMaterial.techniqueSet); if (!techniqueSet) { PrintError(material, "Could not find technique set"); return false; } - m_dependencies.push_back(techniqueSet); + m_registration.AddDependency(techniqueSet); material.techniqueSet = techniqueSet->Asset(); if (!jMaterial.textures.empty()) @@ -346,13 +346,13 @@ namespace if (jMaterial.thermalMaterial) { - auto* thermalMaterial = m_manager.LoadDependency(jMaterial.thermalMaterial.value()); + auto* thermalMaterial = m_context.LoadDependency(jMaterial.thermalMaterial.value()); if (!thermalMaterial) { PrintError(material, "Could not find thermal material"); return false; } - m_dependencies.push_back(thermalMaterial); + m_registration.AddDependency(thermalMaterial); material.thermalMaterial = thermalMaterial->Asset(); } else @@ -365,17 +365,17 @@ namespace std::istream& m_stream; MemoryManager& m_memory; - IAssetLoadingManager& m_manager; - std::vector& m_dependencies; + AssetCreationContext& m_context; + AssetRegistration& m_registration; }; } // namespace namespace T6 { bool LoadMaterialAsJson( - std::istream& stream, Material& material, MemoryManager* memory, IAssetLoadingManager* manager, std::vector& dependencies) + std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) { - const JsonLoader loader(stream, *memory, *manager, dependencies); + const JsonLoader loader(stream, memory, context, registration); return loader.Load(material); } diff --git a/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.h b/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.h index 5e502e90..0356ed0e 100644 --- a/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.h +++ b/src/ObjLoading/Game/T6/Material/JsonMaterialLoader.h @@ -1,6 +1,7 @@ #pragma once -#include "AssetLoading/IAssetLoadingManager.h" +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetRegistration.h" #include "Game/T6/T6.h" #include "Utils/MemoryManager.h" @@ -9,5 +10,5 @@ namespace T6 { bool LoadMaterialAsJson( - std::istream& stream, Material& material, MemoryManager* memory, IAssetLoadingManager* manager, std::vector& dependencies); + std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration); } // namespace T6 diff --git a/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp b/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp new file mode 100644 index 00000000..08add739 --- /dev/null +++ b/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.cpp @@ -0,0 +1,70 @@ +#include "LoaderMaterialT6.h" + +#include "Game/T6/Material/JsonMaterialLoader.h" +#include "Game/T6/T6.h" + +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class MaterialLoader final : public AssetCreator + { + public: + MaterialLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(GetFileNameForAsset(assetName)); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* material = m_memory.Alloc(); + material->info.name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, material); + if (!LoadMaterialAsJson(*file.m_stream, *material, m_memory, context, registration)) + { + std::cerr << std::format("Failed to load material \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + + private: + static std::string GetFileNameForAsset(const std::string& assetName) + { + std::string sanitizedFileName(assetName); + if (sanitizedFileName[0] == '*') + { + std::ranges::replace(sanitizedFileName, '*', '_'); + const auto parenthesisPos = sanitizedFileName.find('('); + if (parenthesisPos != std::string::npos) + sanitizedFileName.erase(parenthesisPos); + sanitizedFileName = "generated/" + sanitizedFileName; + } + + return std::format("materials/{}.json", sanitizedFileName); + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.h b/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.h new file mode 100644 index 00000000..22cd78dc --- /dev/null +++ b/src/ObjLoading/Game/T6/Material/LoaderMaterialT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index b6c25e53..59324dda 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -1,18 +1,45 @@ #include "ObjLoaderT6.h" #include "Asset/GlobalAssetPoolsLoader.h" -#include "AssetLoading/AssetLoadingManager.h" +#include "FontIcon/LoaderFontIconT6.h" #include "Game/T6/CommonT6.h" #include "Game/T6/GameAssetPoolT6.h" #include "Game/T6/GameT6.h" #include "Game/T6/T6.h" +#include "Game/T6/XModel/LoaderXModelT6.h" #include "Image/Dx12TextureLoader.h" #include "Image/IwiLoader.h" #include "Image/IwiTypes.h" +#include "Image/LoaderImageT6.h" #include "Image/Texture.h" -#include "Localize/AssetLoaderLocalizeT6.h" +#include "Leaderboard/LoaderLeaderboardT6.h" +#include "Localize/LoaderLocalizeT6.h" +#include "Material/LoaderMaterialT6.h" #include "ObjContainer/IPak/IPak.h" #include "ObjLoading.h" +#include "PhysConstraints/GdtLoaderPhysConstraintsT6.h" +#include "PhysConstraints/RawLoaderPhysConstraintsT6.h" +#include "PhysPreset/GdtLoaderPhysPresetT6.h" +#include "PhysPreset/RawLoaderPhysPresetT6.h" +#include "Qdb/LoaderQdbT6.h" +#include "RawFile/LoaderRawFileT6.h" +#include "Script/LoaderScriptT6.h" +#include "Slug/LoaderSlugT6.h" +#include "Sound/LoaderSoundBankT6.h" +#include "StringTable/LoaderStringTableT6.h" +#include "Tracer/GdtLoaderTracerT6.h" +#include "Tracer/RawLoaderTracerT6.h" +#include "Vehicle/GdtLoaderVehicleT6.h" +#include "Vehicle/RawLoaderVehicleT6.h" +#include "Weapon/GdtLoaderAttachmentT6.h" +#include "Weapon/GdtLoaderAttachmentUniqueT6.h" +#include "Weapon/GdtLoaderWeaponT6.h" +#include "Weapon/LoaderWeaponCamoT6.h" +#include "Weapon/RawLoaderAttachmentT6.h" +#include "Weapon/RawLoaderAttachmentUniqueT6.h" +#include "Weapon/RawLoaderWeaponT6.h" +#include "ZBarrier/GdtLoaderZBarrierT6.h" +#include "ZBarrier/RawLoaderZBarrierT6.h" #include #include @@ -361,19 +388,21 @@ namespace T6 collection.AddAssetCreator(std::make_unique>(zone)); } - void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) + void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) { auto& memory = *zone.GetMemory(); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateRawPhysPresetLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtPhysPresetLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(CreateRawPhysConstraintsLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtPhysConstraintsLoader(memory, searchPath, gdt, zone)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateImageLoader(memory, searchPath)); + collection.AddAssetCreator(CreateSoundBankLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); @@ -384,42 +413,47 @@ namespace T6 // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateFontIconLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateRawWeaponLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtWeaponLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(CreateRawAttachmentLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtAttachmentLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(CreateRawAttachmentUniqueLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtAttachmentUniqueLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(CreateWeaponCamoLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateRawFileLoader(memory, searchPath)); + collection.AddAssetCreator(CreateStringTableLoader(memory, searchPath)); + collection.AddAssetCreator(CreateLeaderboardLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateScriptLoader(memory, searchPath)); + collection.AddAssetCreator(CreateRawVehicleLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtVehicleLoader(memory, searchPath, gdt, zone)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateQdbLoader(memory, searchPath)); + collection.AddAssetCreator(CreateSlugLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateRawZBarrierLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateGdtZBarrierLoader(memory, searchPath, gdt, zone)); } } // namespace - void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const + void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const { ConfigureDefaultCreators(collection, zone); - ConfigureLoaders(collection, zone, searchPath); + ConfigureLoaders(collection, zone, searchPath, gdt); ConfigureGlobalAssetPoolsLoaders(collection, zone); } } // namespace T6 diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.h b/src/ObjLoading/Game/T6/ObjLoaderT6.h index f571c294..0eb8669a 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.h +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.h @@ -19,7 +19,7 @@ namespace T6 void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override; void UnloadContainersOfZone(Zone& zone) const override; - void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const override; + void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const override; private: static bool VerifySoundBankChecksum(const SoundBank& soundBank, const SndRuntimeAssetBank& sndRuntimeAssetBank); diff --git a/src/ObjLoading/Game/T6/PhysConstraints/GdtLoaderPhysConstraintsT6.cpp b/src/ObjLoading/Game/T6/PhysConstraints/GdtLoaderPhysConstraintsT6.cpp new file mode 100644 index 00000000..d6c35c5d --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysConstraints/GdtLoaderPhysConstraintsT6.cpp @@ -0,0 +1,54 @@ +#include "GdtLoaderPhysConstraintsT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderPhysConstraintsT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderPhysConstraints final : public AssetCreator + { + public: + GdtLoaderPhysConstraints(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read phys constraints gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderPhysConstraints m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> + CreateGdtPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysConstraints/GdtLoaderPhysConstraintsT6.h b/src/ObjLoading/Game/T6/PhysConstraints/GdtLoaderPhysConstraintsT6.h new file mode 100644 index 00000000..45b70188 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysConstraints/GdtLoaderPhysConstraintsT6.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> + CreateGdtPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysConstraints/InfoStringLoaderPhysConstraintsT6.cpp b/src/ObjLoading/Game/T6/PhysConstraints/InfoStringLoaderPhysConstraintsT6.cpp new file mode 100644 index 00000000..ab29df7e --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysConstraints/InfoStringLoaderPhysConstraintsT6.cpp @@ -0,0 +1,110 @@ +#include "InfoStringLoaderPhysConstraintsT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/PhysConstraints/PhysConstraintsFields.h" +#include "Game/T6/T6.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class InfoStringToPhysConstraintsConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + switch (static_cast(field.iFieldType)) + { + case CFT_TYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, s_constraintTypeNames, std::extent_v); + + default: + assert(false); + return false; + } + } + + public: + InfoStringToPhysConstraintsConverter(const InfoString& infoString, + PhysConstraints& physConstraints, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &physConstraints, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; + + void CalculatePhysConstraintsFields(PhysConstraints& physConstraints, ZoneScriptStrings& scriptStrings) + { + for (auto& constraint : physConstraints.data) + { + constraint.targetname = scriptStrings.AddOrGetScriptString(""); + constraint.target_ent1 = scriptStrings.AddOrGetScriptString(""); + constraint.target_ent2 = scriptStrings.AddOrGetScriptString(""); + constraint.attach_point_type1 = ATTACH_POINT_BONE; + constraint.attach_point_type2 = ATTACH_POINT_BONE; + constraint.target_bone1 = ""; + constraint.target_bone2 = ""; + } + + // count + { + auto foundEnd = false; + for (auto i = 0u; i < std::extent_v; i++) + { + if (physConstraints.data[i].type == CONSTRAINT_NONE) + { + foundEnd = true; + physConstraints.count = i; + break; + } + } + + if (!foundEnd) + physConstraints.count = std::extent_v; + } + } +} // namespace + +InfoStringLoaderPhysConstraints::InfoStringLoaderPhysConstraints(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderPhysConstraints::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* physConstraints = m_memory.Alloc(); + physConstraints->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, physConstraints); + InfoStringToPhysConstraintsConverter converter(infoString, + *physConstraints, + m_zone.m_script_strings, + m_memory, + context, + registration, + phys_constraints_fields, + std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse phys constraints: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculatePhysConstraintsFields(*physConstraints, m_zone.m_script_strings); + registration.AddScriptString(m_zone.m_script_strings.AddOrGetScriptString("")); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/PhysConstraints/InfoStringLoaderPhysConstraintsT6.h b/src/ObjLoading/Game/T6/PhysConstraints/InfoStringLoaderPhysConstraintsT6.h new file mode 100644 index 00000000..dbebb186 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysConstraints/InfoStringLoaderPhysConstraintsT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderPhysConstraints + { + public: + InfoStringLoaderPhysConstraints(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp b/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp new file mode 100644 index 00000000..607a3c82 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderPhysConstraintsT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderPhysConstraintsT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderPhysConstraints final : public AssetCreator + { + public: + RawLoaderPhysConstraints(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("physconstraints/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderPhysConstraints m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.h b/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.h new file mode 100644 index 00000000..dc88bc45 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysConstraints/RawLoaderPhysConstraintsT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawPhysConstraintsLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysPreset/GdtLoaderPhysPresetT6.cpp b/src/ObjLoading/Game/T6/PhysPreset/GdtLoaderPhysPresetT6.cpp new file mode 100644 index 00000000..9d7f179f --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysPreset/GdtLoaderPhysPresetT6.cpp @@ -0,0 +1,53 @@ +#include "GdtLoaderPhysPresetT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderPhysPresetT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderPhysPreset final : public AssetCreator + { + public: + GdtLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read phys preset gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderPhysPreset m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateGdtPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysPreset/GdtLoaderPhysPresetT6.h b/src/ObjLoading/Game/T6/PhysPreset/GdtLoaderPhysPresetT6.h new file mode 100644 index 00000000..c2fdbe8d --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysPreset/GdtLoaderPhysPresetT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateGdtPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp b/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp new file mode 100644 index 00000000..038382c5 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.cpp @@ -0,0 +1,89 @@ +#include "InfoStringLoaderPhysPresetT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/PhysPreset/PhysPresetFields.h" +#include "Game/T6/T6.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + assert(false); + return false; + } + + public: + InfoStringToPhysPresetConverter(const InfoString& infoString, + PhysPresetInfo& physPreset, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &physPreset, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; + + void CopyFromPhysPresetInfo(const PhysPresetInfo& physPresetInfo, PhysPreset& physPreset) + { + physPreset.mass = std::clamp(physPresetInfo.mass, 1.0f, 2000.0f) * 0.001f; + physPreset.bounce = physPresetInfo.bounce; + + if (physPresetInfo.isFrictionInfinity != 0) + physPreset.friction = std::numeric_limits::infinity(); + else + physPreset.friction = physPresetInfo.friction; + + physPreset.bulletForceScale = physPresetInfo.bulletForceScale; + physPreset.explosiveForceScale = physPresetInfo.explosiveForceScale; + physPreset.piecesSpreadFraction = physPresetInfo.piecesSpreadFraction; + physPreset.piecesUpwardVelocity = physPresetInfo.piecesUpwardVelocity; + physPreset.canFloat = physPresetInfo.canFloat; + physPreset.gravityScale = std::clamp(physPresetInfo.gravityScale, 0.01f, 10.0f); + physPreset.centerOfMassOffset = physPresetInfo.centerOfMassOffset; + physPreset.buoyancyBoxMin = physPresetInfo.buoyancyBoxMin; + physPreset.buoyancyBoxMax = physPresetInfo.buoyancyBoxMax; + } +} // namespace + +InfoStringLoaderPhysPreset::InfoStringLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderPhysPreset::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* physPreset = m_memory.Alloc(); + physPreset->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, physPreset); + + PhysPresetInfo physPresetInfo; + memset(&physPresetInfo, 0, sizeof(physPresetInfo)); + InfoStringToPhysPresetConverter converter( + infoString, physPresetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse phys preset: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CopyFromPhysPresetInfo(physPresetInfo, *physPreset); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.h b/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.h new file mode 100644 index 00000000..3e214d60 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysPreset/InfoStringLoaderPhysPresetT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderPhysPreset + { + public: + InfoStringLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysPreset/RawLoaderPhysPresetT6.cpp b/src/ObjLoading/Game/T6/PhysPreset/RawLoaderPhysPresetT6.cpp new file mode 100644 index 00000000..4fe78db8 --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysPreset/RawLoaderPhysPresetT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderPhysPresetT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderPhysPresetT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderPhysPreset final : public AssetCreator + { + public: + RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("physic/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderPhysPreset m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/PhysPreset/RawLoaderPhysPresetT6.h b/src/ObjLoading/Game/T6/PhysPreset/RawLoaderPhysPresetT6.h new file mode 100644 index 00000000..44070d9b --- /dev/null +++ b/src/ObjLoading/Game/T6/PhysPreset/RawLoaderPhysPresetT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Qdb/LoaderQdbT6.cpp b/src/ObjLoading/Game/T6/Qdb/LoaderQdbT6.cpp new file mode 100644 index 00000000..e00e88ac --- /dev/null +++ b/src/ObjLoading/Game/T6/Qdb/LoaderQdbT6.cpp @@ -0,0 +1,53 @@ +#include "LoaderQdbT6.h" + +#include "Game/T6/T6.h" + +#include + +using namespace T6; + +namespace +{ + class QdbLoader final : public AssetCreator + { + public: + QdbLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::Failure(); + + auto* qdb = m_memory.Alloc(); + qdb->name = m_memory.Dup(assetName.c_str()); + qdb->len = static_cast(file.m_length); + + auto* fileBuffer = m_memory.Alloc(static_cast(file.m_length + 1)); + file.m_stream->read(fileBuffer, file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + fileBuffer[qdb->len] = '\0'; + + qdb->buffer = static_cast(fileBuffer); + + return AssetCreationResult::Success(context.AddAsset(assetName, qdb)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateQdbLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Qdb/LoaderQdbT6.h b/src/ObjLoading/Game/T6/Qdb/LoaderQdbT6.h new file mode 100644 index 00000000..a8d5f9c9 --- /dev/null +++ b/src/ObjLoading/Game/T6/Qdb/LoaderQdbT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateQdbLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/RawFile/LoaderRawFileT6.cpp b/src/ObjLoading/Game/T6/RawFile/LoaderRawFileT6.cpp new file mode 100644 index 00000000..5e92aebc --- /dev/null +++ b/src/ObjLoading/Game/T6/RawFile/LoaderRawFileT6.cpp @@ -0,0 +1,123 @@ +#include "LoaderRawFileT6.h" + +#include "Game/T6/T6.h" +#include "Pool/GlobalAssetPool.h" + +#include +#include +#include +#include +#include +#include + +using namespace T6; +namespace fs = std::filesystem; + +namespace +{ + constexpr size_t COMPRESSED_BUFFER_SIZE_PADDING = 64; + + class RawFileLoader final : public AssetCreator + { + public: + RawFileLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + const fs::path rawFilePath(assetName); + const auto extension = rawFilePath.extension().string(); + + if (extension == ".atr") + return LoadAnimtree(file, assetName, context); + + return LoadDefault(file, assetName, context); + } + + private: + AssetCreationResult LoadAnimtree(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) + { + const auto uncompressedBuffer = std::make_unique(static_cast(file.m_length)); + file.m_stream->read(uncompressedBuffer.get(), file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + + const auto compressionBufferSize = static_cast(file.m_length + sizeof(uint32_t) + COMPRESSED_BUFFER_SIZE_PADDING); + auto* compressedBuffer = m_memory.Alloc(compressionBufferSize); + + z_stream_s zs{}; + + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + zs.avail_in = static_cast(file.m_length); + zs.avail_out = compressionBufferSize; + zs.next_in = reinterpret_cast(uncompressedBuffer.get()); + zs.next_out = reinterpret_cast(&compressedBuffer[sizeof(uint32_t)]); + + int ret = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -DEF_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); + + if (ret != Z_OK) + { + throw std::runtime_error("Initializing deflate failed"); + } + + ret = deflate(&zs, Z_FINISH); + + if (ret != Z_STREAM_END) + { + std::cerr << std::format("Deflate failed for loading animtree file \"{}\"\n", assetName); + deflateEnd(&zs); + return AssetCreationResult::Failure(); + } + + const auto compressedSize = compressionBufferSize + sizeof(uint32_t) - zs.avail_out; + + reinterpret_cast(compressedBuffer)[0] = static_cast(file.m_length); // outLen + + auto* rawFile = m_memory.Alloc(); + rawFile->name = m_memory.Dup(assetName.c_str()); + rawFile->len = static_cast(compressedSize); + rawFile->buffer = static_cast(compressedBuffer); + + deflateEnd(&zs); + + return AssetCreationResult::Success(context.AddAsset(assetName, rawFile)); + } + + AssetCreationResult LoadDefault(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) + { + auto* rawFile = m_memory.Alloc(); + rawFile->name = m_memory.Dup(assetName.c_str()); + rawFile->len = static_cast(file.m_length); + + auto* fileBuffer = m_memory.Alloc(static_cast(file.m_length + 1)); + file.m_stream->read(fileBuffer, file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + fileBuffer[rawFile->len] = '\0'; + + rawFile->buffer = static_cast(fileBuffer); + + return AssetCreationResult::Success(context.AddAsset(assetName, rawFile)); + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/RawFile/LoaderRawFileT6.h b/src/ObjLoading/Game/T6/RawFile/LoaderRawFileT6.h new file mode 100644 index 00000000..db44f9a5 --- /dev/null +++ b/src/ObjLoading/Game/T6/RawFile/LoaderRawFileT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Script/LoaderScriptT6.cpp b/src/ObjLoading/Game/T6/Script/LoaderScriptT6.cpp new file mode 100644 index 00000000..5d30b473 --- /dev/null +++ b/src/ObjLoading/Game/T6/Script/LoaderScriptT6.cpp @@ -0,0 +1,53 @@ +#include "LoaderScriptT6.h" + +#include "Game/T6/T6.h" + +#include + +using namespace T6; + +namespace +{ + class ScriptLoader final : public AssetCreator + { + public: + ScriptLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* scriptParseTree = m_memory.Alloc(); + scriptParseTree->name = m_memory.Dup(assetName.c_str()); + scriptParseTree->len = static_cast(file.m_length); + + auto* fileBuffer = m_memory.Alloc(static_cast(file.m_length + 1)); + file.m_stream->read(fileBuffer, file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + fileBuffer[scriptParseTree->len] = '\0'; + + scriptParseTree->buffer = static_cast(fileBuffer); + + return AssetCreationResult::Success(context.AddAsset(assetName, scriptParseTree)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateScriptLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Script/LoaderScriptT6.h b/src/ObjLoading/Game/T6/Script/LoaderScriptT6.h new file mode 100644 index 00000000..754da2ec --- /dev/null +++ b/src/ObjLoading/Game/T6/Script/LoaderScriptT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateScriptLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Slug/LoaderSlugT6.cpp b/src/ObjLoading/Game/T6/Slug/LoaderSlugT6.cpp new file mode 100644 index 00000000..f527a521 --- /dev/null +++ b/src/ObjLoading/Game/T6/Slug/LoaderSlugT6.cpp @@ -0,0 +1,53 @@ +#include "LoaderSlugT6.h" + +#include "Game/T6/T6.h" + +#include + +using namespace T6; + +namespace +{ + class SlugLoader final : public AssetCreator + { + public: + SlugLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* slug = m_memory.Alloc(); + slug->name = m_memory.Dup(assetName.c_str()); + slug->len = static_cast(file.m_length); + + auto* fileBuffer = m_memory.Alloc(static_cast(file.m_length + 1)); + file.m_stream->read(fileBuffer, file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + fileBuffer[slug->len] = '\0'; + + slug->buffer = static_cast(fileBuffer); + + return AssetCreationResult::Success(context.AddAsset(assetName, slug)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateSlugLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Slug/LoaderSlugT6.h b/src/ObjLoading/Game/T6/Slug/LoaderSlugT6.h new file mode 100644 index 00000000..49da9e84 --- /dev/null +++ b/src/ObjLoading/Game/T6/Slug/LoaderSlugT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateSlugLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundBank.cpp b/src/ObjLoading/Game/T6/Sound/LoaderSoundBankT6.cpp similarity index 85% rename from src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundBank.cpp rename to src/ObjLoading/Game/T6/Sound/LoaderSoundBankT6.cpp index f42fe26e..aab25cb4 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderSoundBank.cpp +++ b/src/ObjLoading/Game/T6/Sound/LoaderSoundBankT6.cpp @@ -1,4 +1,4 @@ -#include "AssetLoaderSoundBank.h" +#include "LoaderSoundBankT6.h" #include "Csv/CsvHeaderRow.h" #include "Csv/CsvStream.h" @@ -859,7 +859,7 @@ namespace return true; } - bool LoadSoundDuckList(ISearchPath* searchPath, MemoryManager& memory, SndBank* sndBank, const SearchPathOpenFile& file) + bool LoadSoundDuckList(ISearchPath& searchPath, MemoryManager& memory, SndBank* sndBank, const SearchPathOpenFile& file) { const CsvInputStream csv(*file.m_stream); CsvHeaderRow headerRow; @@ -879,7 +879,7 @@ namespace if (name.empty()) return false; - const auto duckFile = searchPath->Open(std::format("soundbank/ducks/{}.duk", name)); + const auto duckFile = searchPath.Open(std::format("soundbank/ducks/{}.duk", name)); if (!duckFile.IsOpen()) { std::cerr << std::format("Unable to find .duk file for {} in ducklist for sound bank {}\n", name, sndBank->name); @@ -930,151 +930,159 @@ namespace return true; } + + class SoundBankLoader final : public AssetCreator + { + public: + SoundBankLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + if (assetName.find('.') == std::string::npos) + { + std::cerr << "A language must be specific in the sound bank asset name! (Ex: mpl_common.all)\n"; + return AssetCreationResult::Failure(); + } + + const auto aliasFile = m_search_path.Open(std::format("soundbank/{}.aliases.csv", assetName)); + if (!aliasFile.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* sndBank = m_memory.Alloc(); + sndBank->name = m_memory.Dup(assetName.c_str()); + + const auto sndBankLocalization = utils::StringSplit(assetName, '.'); + + unsigned loadedEntryCount = 0u, streamedEntryCount = 0u; + if (!LoadSoundAliasList(m_memory, sndBank, aliasFile, loadedEntryCount, streamedEntryCount)) + return AssetCreationResult::Failure(); + + if (!LoadSoundAliasIndexList(m_memory, sndBank)) + return AssetCreationResult::Failure(); + + const auto radverbFile = m_search_path.Open(std::format("soundbank/{}.reverbs.csv", assetName)); + if (radverbFile.IsOpen()) + { + if (!LoadSoundRadverbs(m_memory, sndBank, radverbFile)) + { + std::cerr << std::format("Sound bank reverbs file for {} is invalid\n", assetName); + return AssetCreationResult::Failure(); + } + } + + const auto duckListFile = m_search_path.Open(std::format("soundbank/{}.ducklist.csv", assetName)); + if (duckListFile.IsOpen()) + { + if (!LoadSoundDuckList(m_search_path, m_memory, sndBank, duckListFile)) + { + std::cerr << std::format("Sound bank ducklist file for {} is invalid\n", assetName); + return AssetCreationResult::Failure(); + } + } + + std::unique_ptr sablStream, sabsStream; + std::unique_ptr sablWriter, sabsWriter; + + if (loadedEntryCount > 0) + { + sndBank->loadAssetBank.zone = m_memory.Dup(sndBankLocalization.at(0).c_str()); + sndBank->loadAssetBank.language = m_memory.Dup(sndBankLocalization.at(1).c_str()); + memset(sndBank->loadAssetBank.linkTimeChecksum, 0xCC, 16); + + sndBank->loadedAssets.loadedCount = 0; + sndBank->loadedAssets.zone = m_memory.Dup(sndBankLocalization.at(0).c_str()); + sndBank->loadedAssets.language = m_memory.Dup(sndBankLocalization.at(1).c_str()); + sndBank->loadedAssets.entryCount = loadedEntryCount; + sndBank->loadedAssets.entries = m_memory.Alloc(loadedEntryCount); + + sndBank->runtimeAssetLoad = true; + + const auto sablName = std::format("{}.sabl", assetName); + sablStream = OpenSoundBankOutputFile(sablName); + if (sablStream) + sablWriter = SoundBankWriter::Create(sablName, *sablStream, m_search_path); + } + + if (streamedEntryCount > 0) + { + sndBank->streamAssetBank.zone = m_memory.Dup(sndBankLocalization.at(0).c_str()); + sndBank->streamAssetBank.language = m_memory.Dup(sndBankLocalization.at(1).c_str()); + memset(sndBank->streamAssetBank.linkTimeChecksum, 0xCC, 16); + + const auto sabsName = std::format("{}.sabs", assetName); + sabsStream = OpenSoundBankOutputFile(sabsName); + if (sabsStream) + sabsWriter = SoundBankWriter::Create(sabsName, *sabsStream, m_search_path); + } + + // add aliases to the correct sound bank writer + for (auto i = 0u; i < sndBank->aliasCount; i++) + { + const auto* aliasList = &sndBank->alias[i]; + for (auto j = 0; j < aliasList->count; j++) + { + const auto* alias = &aliasList->head[j]; + + if (alias->assetFileName && alias->assetId) + { + if (sabsWriter && alias->flags.loadType == SA_STREAMED) + sabsWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping, true); + else if (sablWriter) + sablWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping); + } + } + } + + // write the output linked sound bank + if (sablWriter) + { + size_t dataSize = 0u; + const auto result = sablWriter->Write(dataSize); + sablStream->close(); + + if (result) + { + sndBank->loadedAssets.dataSize = dataSize; + sndBank->loadedAssets.data = m_memory.Alloc(dataSize); + } + else + { + std::cerr << std::format("Loaded sound bank for {} failed to generate. Please check your build files.\n", assetName); + return AssetCreationResult::Failure(); + } + } + + // write the output streamed sound bank + if (sabsWriter) + { + size_t dataSize = 0u; + const auto result = sabsWriter->Write(dataSize); + sabsStream->close(); + + if (!result) + { + std::cerr << std::format("Streamed sound bank for {} failed to generate. Please check your build files.\n", assetName); + return AssetCreationResult::Failure(); + } + } + + return AssetCreationResult::Success(context.AddAsset(assetName, sndBank)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; } // namespace -void* AssetLoaderSoundBank::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) +namespace T6 { - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderSoundBank::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderSoundBank::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - if (assetName.find('.') == std::string::npos) + std::unique_ptr> CreateSoundBankLoader(MemoryManager& memory, ISearchPath& searchPath) { - std::cerr << "A language must be specific in the sound bank asset name! (Ex: mpl_common.all)\n"; - return false; + return std::make_unique(memory, searchPath); } - - const auto aliasFile = searchPath->Open(std::format("soundbank/{}.aliases.csv", assetName)); - if (!aliasFile.IsOpen()) - return false; - - auto* sndBank = memory->Alloc(); - - sndBank->name = memory->Dup(assetName.c_str()); - const auto sndBankLocalization = utils::StringSplit(assetName, '.'); - - unsigned loadedEntryCount = 0u, streamedEntryCount = 0u; - if (!LoadSoundAliasList(*memory, sndBank, aliasFile, loadedEntryCount, streamedEntryCount)) - return false; - - if (!LoadSoundAliasIndexList(*memory, sndBank)) - return false; - - const auto radverbFile = searchPath->Open(std::format("soundbank/{}.reverbs.csv", assetName)); - if (radverbFile.IsOpen()) - { - if (!LoadSoundRadverbs(*memory, sndBank, radverbFile)) - { - std::cerr << std::format("Sound bank reverbs file for {} is invalid\n", assetName); - return false; - } - } - - const auto duckListFile = searchPath->Open(std::format("soundbank/{}.ducklist.csv", assetName)); - if (duckListFile.IsOpen()) - { - if (!LoadSoundDuckList(searchPath, *memory, sndBank, duckListFile)) - { - std::cerr << std::format("Sound bank ducklist file for {} is invalid\n", assetName); - return false; - } - } - - std::unique_ptr sablStream, sabsStream; - std::unique_ptr sablWriter, sabsWriter; - - if (loadedEntryCount > 0) - { - sndBank->loadAssetBank.zone = memory->Dup(sndBankLocalization.at(0).c_str()); - sndBank->loadAssetBank.language = memory->Dup(sndBankLocalization.at(1).c_str()); - memset(sndBank->loadAssetBank.linkTimeChecksum, 0xCC, 16); - - sndBank->loadedAssets.loadedCount = 0; - sndBank->loadedAssets.zone = memory->Dup(sndBankLocalization.at(0).c_str()); - sndBank->loadedAssets.language = memory->Dup(sndBankLocalization.at(1).c_str()); - sndBank->loadedAssets.entryCount = loadedEntryCount; - sndBank->loadedAssets.entries = memory->Alloc(loadedEntryCount); - - sndBank->runtimeAssetLoad = true; - - const auto sablName = std::format("{}.sabl", assetName); - sablStream = OpenSoundBankOutputFile(sablName); - if (sablStream) - sablWriter = SoundBankWriter::Create(sablName, *sablStream, searchPath); - } - - if (streamedEntryCount > 0) - { - sndBank->streamAssetBank.zone = memory->Dup(sndBankLocalization.at(0).c_str()); - sndBank->streamAssetBank.language = memory->Dup(sndBankLocalization.at(1).c_str()); - memset(sndBank->streamAssetBank.linkTimeChecksum, 0xCC, 16); - - const auto sabsName = std::format("{}.sabs", assetName); - sabsStream = OpenSoundBankOutputFile(sabsName); - if (sabsStream) - sabsWriter = SoundBankWriter::Create(sabsName, *sabsStream, searchPath); - } - - // add aliases to the correct sound bank writer - for (auto i = 0u; i < sndBank->aliasCount; i++) - { - const auto* aliasList = &sndBank->alias[i]; - for (auto j = 0; j < aliasList->count; j++) - { - const auto* alias = &aliasList->head[j]; - - if (alias->assetFileName && alias->assetId) - { - if (sabsWriter && alias->flags.loadType == SA_STREAMED) - sabsWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping, true); - else if (sablWriter) - sablWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping); - } - } - } - - // write the output linked sound bank - if (sablWriter) - { - size_t dataSize = 0u; - const auto result = sablWriter->Write(dataSize); - sablStream->close(); - - if (result) - { - sndBank->loadedAssets.dataSize = dataSize; - sndBank->loadedAssets.data = memory->Alloc(dataSize); - } - else - { - std::cerr << std::format("Loaded sound bank for {} failed to generate. Please check your build files.\n", assetName); - return false; - } - } - - // write the output streamed sound bank - if (sabsWriter) - { - size_t dataSize = 0u; - const auto result = sabsWriter->Write(dataSize); - sabsStream->close(); - - if (!result) - { - std::cerr << std::format("Streamed sound bank for {} failed to generate. Please check your build files.\n", assetName); - return false; - } - } - - manager->AddAsset(assetName, sndBank); - return true; -} +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Sound/LoaderSoundBankT6.h b/src/ObjLoading/Game/T6/Sound/LoaderSoundBankT6.h new file mode 100644 index 00000000..6e99e962 --- /dev/null +++ b/src/ObjLoading/Game/T6/Sound/LoaderSoundBankT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateSoundBankLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/StringTable/LoaderStringTableT6.cpp b/src/ObjLoading/Game/T6/StringTable/LoaderStringTableT6.cpp new file mode 100644 index 00000000..d9560241 --- /dev/null +++ b/src/ObjLoading/Game/T6/StringTable/LoaderStringTableT6.cpp @@ -0,0 +1,47 @@ +#include "LoaderStringTableT6.h" + +#include "Csv/CsvStream.h" +#include "Game/T6/CommonT6.h" +#include "Game/T6/T6.h" +#include "StringTable/StringTableLoader.h" + +#include + +using namespace T6; + +namespace +{ + class StringTableLoader final : public AssetCreator + { + public: + StringTableLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + string_table::StringTableLoaderV3 loader; + auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream); + + return AssetCreationResult::Success(context.AddAsset(assetName, stringTable)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/StringTable/LoaderStringTableT6.h b/src/ObjLoading/Game/T6/StringTable/LoaderStringTableT6.h new file mode 100644 index 00000000..7db144c6 --- /dev/null +++ b/src/ObjLoading/Game/T6/StringTable/LoaderStringTableT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Tracer/GdtLoaderTracerT6.cpp b/src/ObjLoading/Game/T6/Tracer/GdtLoaderTracerT6.cpp new file mode 100644 index 00000000..ee7376ed --- /dev/null +++ b/src/ObjLoading/Game/T6/Tracer/GdtLoaderTracerT6.cpp @@ -0,0 +1,53 @@ +#include "GdtLoaderTracerT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderTracerT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderTracer final : public AssetCreator + { + public: + GdtLoaderTracer(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_TRACER, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read tracer gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderTracer m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateGdtTracerLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Tracer/GdtLoaderTracerT6.h b/src/ObjLoading/Game/T6/Tracer/GdtLoaderTracerT6.h new file mode 100644 index 00000000..d3059ce3 --- /dev/null +++ b/src/ObjLoading/Game/T6/Tracer/GdtLoaderTracerT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateGdtTracerLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Tracer/InfoStringLoaderTracerT6.cpp b/src/ObjLoading/Game/T6/Tracer/InfoStringLoaderTracerT6.cpp new file mode 100644 index 00000000..00c21757 --- /dev/null +++ b/src/ObjLoading/Game/T6/Tracer/InfoStringLoaderTracerT6.cpp @@ -0,0 +1,72 @@ +#include "InfoStringLoaderTracerT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/T6.h" +#include "Game/T6/Tracer/TracerFields.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class InfoStringToTracerConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + switch (static_cast(field.iFieldType)) + { + case TFT_TRACERTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, tracerTypeNames, std::extent_v); + + case TFT_NUM_FIELD_TYPES: + default: + assert(false); + return false; + } + } + + public: + InfoStringToTracerConverter(const InfoString& infoString, + TracerDef& tracer, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &tracer, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; +} // namespace + +InfoStringLoaderTracer::InfoStringLoaderTracer(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderTracer::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* tracer = m_memory.Alloc(); + tracer->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, tracer); + + InfoStringToTracerConverter converter( + infoString, *tracer, m_zone.m_script_strings, m_memory, context, registration, tracer_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse tracer: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/Tracer/InfoStringLoaderTracerT6.h b/src/ObjLoading/Game/T6/Tracer/InfoStringLoaderTracerT6.h new file mode 100644 index 00000000..141c8216 --- /dev/null +++ b/src/ObjLoading/Game/T6/Tracer/InfoStringLoaderTracerT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderTracer + { + public: + InfoStringLoaderTracer(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Tracer/RawLoaderTracerT6.cpp b/src/ObjLoading/Game/T6/Tracer/RawLoaderTracerT6.cpp new file mode 100644 index 00000000..16eb7ea9 --- /dev/null +++ b/src/ObjLoading/Game/T6/Tracer/RawLoaderTracerT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderTracerT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderTracerT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderTracer final : public AssetCreator + { + public: + RawLoaderTracer(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("tracer/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_TRACER, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderTracer m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawTracerLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Tracer/RawLoaderTracerT6.h b/src/ObjLoading/Game/T6/Tracer/RawLoaderTracerT6.h new file mode 100644 index 00000000..a41e74c2 --- /dev/null +++ b/src/ObjLoading/Game/T6/Tracer/RawLoaderTracerT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawTracerLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Vehicle/GdtLoaderVehicleT6.cpp b/src/ObjLoading/Game/T6/Vehicle/GdtLoaderVehicleT6.cpp new file mode 100644 index 00000000..7b224773 --- /dev/null +++ b/src/ObjLoading/Game/T6/Vehicle/GdtLoaderVehicleT6.cpp @@ -0,0 +1,53 @@ +#include "GdtLoaderVehicleT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderVehicleT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderVehicle final : public AssetCreator + { + public: + GdtLoaderVehicle(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_VEHICLE, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read vehicle gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderVehicle m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateGdtVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Vehicle/GdtLoaderVehicleT6.h b/src/ObjLoading/Game/T6/Vehicle/GdtLoaderVehicleT6.h new file mode 100644 index 00000000..fee2a56d --- /dev/null +++ b/src/ObjLoading/Game/T6/Vehicle/GdtLoaderVehicleT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateGdtVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp b/src/ObjLoading/Game/T6/Vehicle/InfoStringLoaderVehicleT6.cpp similarity index 50% rename from src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp rename to src/ObjLoading/Game/T6/Vehicle/InfoStringLoaderVehicleT6.cpp index 2b36b60c..4999f0bb 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp +++ b/src/ObjLoading/Game/T6/Vehicle/InfoStringLoaderVehicleT6.cpp @@ -1,19 +1,18 @@ -#include "AssetLoaderVehicle.h" +#include "InfoStringLoaderVehicleT6.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringToStructConverter.h" -#include "Game/T6/InfoString/VehicleFields.h" -#include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" -#include "InfoString/InfoString.h" -#include "Pool/GlobalAssetPool.h" +#include "Game/T6/Vehicle/VehicleFields.h" +#include #include +#include #include +#include using namespace T6; -namespace T6 +namespace { class InfoStringToVehicleConverter final : public InfoStringToStructConverter { @@ -38,7 +37,7 @@ namespace T6 if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as mph\n"; + std::cerr << std::format("Failed to parse value \"{}\" as mph\n", value); return false; } @@ -52,7 +51,7 @@ namespace T6 if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as pounds\n"; + std::cerr << std::format("Failed to parse value \"{}\" as pounds\n", value); return false; } @@ -80,14 +79,13 @@ namespace T6 } *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = TEAM_BAD; - std::cout << "Failed to parse value \"" << value << "\" as team\n"; + std::cerr << std::format("Failed to parse value \"{}\" as team\n", value); return false; } case VFT_KEY_BINDING: case VFT_GRAPH: case VFT_WIIUCONTROLOVERRIDE: - case VFT_NUM: default: assert(false); return false; @@ -96,87 +94,40 @@ namespace T6 public: InfoStringToVehicleConverter(const InfoString& infoString, - VehicleDef* vehicleDef, + VehicleDef& vehicleDef, ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, const cspField_t* fields, const size_t fieldCount) - : InfoStringToStructConverter(infoString, vehicleDef, zoneScriptStrings, memory, manager, fields, fieldCount) + : InfoStringToStructConverter(infoString, &vehicleDef, zoneScriptStrings, memory, context, registration, fields, fieldCount) { } }; -} // namespace T6 +} // namespace -bool AssetLoaderVehicle::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) +InfoStringLoaderVehicle::InfoStringLoaderVehicle(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) { - auto* vehicleDef = memory->Create(); - memset(vehicleDef, 0, sizeof(VehicleDef)); +} + +AssetCreationResult InfoStringLoaderVehicle::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* vehicleDef = m_memory.Alloc(); + vehicleDef->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, vehicleDef); InfoStringToVehicleConverter converter( - infoString, vehicleDef, zone->m_script_strings, memory, manager, vehicle_fields, std::extent_v); + infoString, *vehicleDef, m_zone.m_script_strings, m_memory, context, registration, vehicle_fields, std::extent_v); if (!converter.Convert()) { - std::cout << "Failed to parse vehicle: \"" << assetName << "\"\n"; - return true; + std::cerr << std::format("Failed to parse vehicle: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); } - vehicleDef->name = memory->Dup(assetName.c_str()); - - manager->AddAsset(assetName, vehicleDef, converter.GetDependencies(), converter.GetUsedScriptStrings()); - - return true; -} - -void* AssetLoaderVehicle::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* asset = memory->Alloc(); - asset->name = memory->Dup(assetName.c_str()); - return asset; -} - -bool AssetLoaderVehicle::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderVehicle::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_VEHICLE, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cout << "Failed to read vehicle gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderVehicle::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderVehicle::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "vehicles/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_VEHICLE, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } diff --git a/src/ObjLoading/Game/T6/Vehicle/InfoStringLoaderVehicleT6.h b/src/ObjLoading/Game/T6/Vehicle/InfoStringLoaderVehicleT6.h new file mode 100644 index 00000000..9aed730e --- /dev/null +++ b/src/ObjLoading/Game/T6/Vehicle/InfoStringLoaderVehicleT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderVehicle + { + public: + InfoStringLoaderVehicle(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Vehicle/RawLoaderVehicleT6.cpp b/src/ObjLoading/Game/T6/Vehicle/RawLoaderVehicleT6.cpp new file mode 100644 index 00000000..68a8299e --- /dev/null +++ b/src/ObjLoading/Game/T6/Vehicle/RawLoaderVehicleT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderVehicleT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderVehicleT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderVehicle final : public AssetCreator + { + public: + RawLoaderVehicle(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("vehicles/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_VEHICLE, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderVehicle m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Vehicle/RawLoaderVehicleT6.h b/src/ObjLoading/Game/T6/Vehicle/RawLoaderVehicleT6.h new file mode 100644 index 00000000..e88d6909 --- /dev/null +++ b/src/ObjLoading/Game/T6/Vehicle/RawLoaderVehicleT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawVehicleLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.cpp b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.cpp new file mode 100644 index 00000000..ceecfd7f --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.cpp @@ -0,0 +1,53 @@ +#include "GdtLoaderAttachmentT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderAttachmentT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderAttachment final : public AssetCreator + { + public: + GdtLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read attachment gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderAttachment m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateGdtAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h new file mode 100644 index 00000000..6455b204 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateGdtAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.cpp b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.cpp new file mode 100644 index 00000000..ab53d947 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.cpp @@ -0,0 +1,54 @@ +#include "GdtLoaderAttachmentUniqueT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderAttachmentUniqueT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderAttachmentUnique final : public AssetCreator + { + public: + GdtLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read attachment unique gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderAttachmentUnique m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> + CreateGdtAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h new file mode 100644 index 00000000..3e39221d --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> + CreateGdtAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.cpp b/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.cpp new file mode 100644 index 00000000..702213dd --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.cpp @@ -0,0 +1,53 @@ +#include "GdtLoaderWeaponT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderWeaponT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderWeapon final : public AssetCreator + { + public: + GdtLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read weapon gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderWeapon m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.h b/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.h new file mode 100644 index 00000000..fdb1882b --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.cpp b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.cpp new file mode 100644 index 00000000..83f71735 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.cpp @@ -0,0 +1,121 @@ +#include "InfoStringLoaderAttachmentT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/T6.h" +#include "Game/T6/Weapon/AttachmentFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + eAttachmentPoint attachmentPointByAttachmentTable[]{ + ATTACHMENT_POINT_NONE, // none + ATTACHMENT_POINT_TOP, // acog + ATTACHMENT_POINT_TRIGGER, // dualclip + ATTACHMENT_POINT_TOP, // dualoptic + ATTACHMENT_POINT_BOTTOM, // dw + ATTACHMENT_POINT_MUZZLE, // extbarrel + ATTACHMENT_POINT_TRIGGER, // extclip + ATTACHMENT_POINT_TRIGGER, // extramags + ATTACHMENT_POINT_GUNPERK, // fastads + ATTACHMENT_POINT_TOP, // fastreload + ATTACHMENT_POINT_TRIGGER, // fmj + ATTACHMENT_POINT_BOTTOM, // gl + ATTACHMENT_POINT_BOTTOM, // grip + ATTACHMENT_POINT_TOP, // holo + ATTACHMENT_POINT_BOTTOM, // ir + ATTACHMENT_POINT_BOTTOM, // is + ATTACHMENT_POINT_GUNPERK, // longbreath + ATTACHMENT_POINT_BOTTOM, // mk + ATTACHMENT_POINT_TOP, // mms + ATTACHMENT_POINT_TOP, // rangefinder + ATTACHMENT_POINT_TOP, // reflex + ATTACHMENT_POINT_MUZZLE, // rf + ATTACHMENT_POINT_BOTTOM, // sf + ATTACHMENT_POINT_MUZZLE, // silencer + ATTACHMENT_POINT_TRIGGER, // stackfire + ATTACHMENT_POINT_GUNPERK, // stalker + ATTACHMENT_POINT_GUNPERK, // steadyaim + ATTACHMENT_POINT_GUNPERK, // swayreduc + ATTACHMENT_POINT_TOP, // tacknife + ATTACHMENT_POINT_TOP, // vzoom + }; + static_assert(std::extent_v == ATTACHMENT_TYPE_COUNT); + + class InfoStringToAttachmentConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + switch (static_cast(field.iFieldType)) + { + case AFT_ATTACHMENTTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szAttachmentTypeNames, std::extent_v); + + case AFT_PENETRATE_TYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, penetrateTypeNames, std::extent_v); + + case AFT_FIRETYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapFireTypeNames, std::extent_v); + + default: + assert(false); + return false; + } + } + + public: + InfoStringToAttachmentConverter(const InfoString& infoString, + WeaponAttachment& attachment, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &attachment, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; + + void CalculateAttachmentFields(WeaponAttachment& attachment) + { + assert(static_cast(attachment.attachmentType) < ATTACHMENT_TYPE_COUNT); + if (static_cast(attachment.attachmentType) < ATTACHMENT_TYPE_COUNT) + attachment.attachmentPoint = attachmentPointByAttachmentTable[attachment.attachmentType]; + } +} // namespace + +InfoStringLoaderAttachment::InfoStringLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderAttachment::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* attachment = m_memory.Alloc(); + attachment->szInternalName = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, attachment); + + InfoStringToAttachmentConverter converter( + infoString, *attachment, m_zone.m_script_strings, m_memory, context, registration, attachment_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse attachment: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateAttachmentFields(*attachment); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.h b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.h new file mode 100644 index 00000000..fc6d020d --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderAttachment + { + public: + InfoStringLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.cpp b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.cpp new file mode 100644 index 00000000..8172eddb --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.cpp @@ -0,0 +1,242 @@ +#include "InfoStringLoaderAttachmentUniqueT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/T6.h" +#include "Game/T6/Weapon/AttachmentUniqueFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class InfoStringToAttachmentUniqueConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + switch (static_cast(field.iFieldType)) + { + case AUFT_ATTACHMENTTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szAttachmentTypeNames, std::extent_v); + + case AUFT_HIDETAGS: + return ConvertHideTags(field, value); + + case AUFT_OVERLAYRETICLE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapOverlayReticleNames, std::extent_v); + + case AUFT_CAMO: + return ConvertWeaponCamo(field, value); + + case AUFT_ANIM_NAME: + return ConvertAnimName(field, value); + + default: + assert(false); + return false; + } + } + + bool ConvertHideTags(const cspField_t& field, const std::string& value) + { + std::vector valueArray; + if (!ParseAsArray(value, valueArray)) + { + std::cerr << "Failed to parse hide tags as array\n"; + return false; + } + + if (valueArray.size() > std::extent_v) + { + std::cerr << std::format("Cannot have more than {} hide tags!\n", std::extent_v); + return false; + } + + auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + + if (valueArray.size() < std::extent_v) + m_registration.AddScriptString(m_zone_script_strings.AddOrGetScriptString(nullptr)); + + auto currentHideTag = 0u; + for (; currentHideTag < valueArray.size(); currentHideTag++) + { + const auto& currentValue = valueArray[currentHideTag]; + const auto scrString = + !currentValue.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue) : m_zone_script_strings.AddOrGetScriptString(nullptr); + hideTags[currentHideTag] = scrString; + m_registration.AddScriptString(scrString); + } + + for (; currentHideTag < std::extent_v; currentHideTag++) + { + hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(nullptr); + } + + return true; + } + + [[nodiscard]] bool ConvertWeaponCamo(const cspField_t& field, const std::string& value) + { + if (value.empty()) + { + *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = nullptr; + return true; + } + + auto* camo = m_context.LoadDependency(value); + + if (camo == nullptr) + { + std::cerr << std::format("Failed to load camo asset \"{}\"\n", value); + return false; + } + + m_registration.AddDependency(camo); + *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = camo->Asset(); + + return true; + } + + bool ConvertAnimName(const cspField_t& field, const std::string& value) + { + if (ConvertString(value, field.iOffset)) + { + if (!value.empty()) + m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference(value)); + + return true; + } + + return false; + } + + public: + InfoStringToAttachmentUniqueConverter(const InfoString& infoString, + WeaponAttachmentUniqueFull& attachmentUniqueFull, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &attachmentUniqueFull, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; + + void LinkAttachmentUniqueFullSubStructs(WeaponAttachmentUniqueFull& attachmentUnique) + { + attachmentUnique.attachment.hideTags = attachmentUnique.hideTags; + attachmentUnique.attachment.szXAnims = attachmentUnique.szXAnims; + attachmentUnique.attachment.locationDamageMultipliers = attachmentUnique.locationDamageMultipliers; + } + + bool CalculateAttachmentUniqueFields(const std::string& assetName, WeaponAttachmentUniqueFull& attachmentUnique) + { + // combinedAttachmentTypeMask + std::vector attachmentsFromName; + if (!InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(assetName, attachmentsFromName)) + { + std::cerr << std::format("Failed to determine attachments from attachment unique name \"{}\"\n", assetName); + return false; + } + + if (attachmentsFromName.size() > 1) + { + for (const auto attachment : attachmentsFromName) + { + attachmentUnique.attachment.combinedAttachmentTypeMask |= 1 << attachment; + } + } + + return true; + } +} // namespace + +bool InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList) +{ + std::vector parts; + + auto attachCount = 1u; + auto partStart = 0u; + for (auto ci = 0u; ci < assetName.size(); ci++) + { + if (assetName[ci] == '_') + { + parts.emplace_back(assetName, partStart, ci - partStart); + partStart = ci + 1; + } + else if (assetName[ci] == '+') + { + attachCount++; + parts.emplace_back(assetName, partStart, ci - partStart); + partStart = ci + 1; + } + } + + if (partStart < assetName.size()) + parts.emplace_back(assetName, partStart, assetName.size() - partStart); + + for (auto attachPartOffset = parts.size() - attachCount; attachPartOffset < parts.size(); attachPartOffset++) + { + auto& specifiedAttachName = parts[attachPartOffset]; + + for (auto& c : specifiedAttachName) + c = static_cast(tolower(c)); + + auto foundAttachment = false; + for (auto attachIndex = 0u; attachIndex < std::extent_v; attachIndex++) + { + if (specifiedAttachName == szAttachmentTypeNames[attachIndex]) + { + attachmentList.push_back(static_cast(attachIndex)); + foundAttachment = true; + break; + } + } + + if (!foundAttachment) + return false; + } + + return true; +} + +InfoStringLoaderAttachmentUnique::InfoStringLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderAttachmentUnique::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* attachmentUniqueFull = m_memory.Alloc(); + attachmentUniqueFull->attachment.szInternalName = m_memory.Dup(assetName.c_str()); + + LinkAttachmentUniqueFullSubStructs(*attachmentUniqueFull); + + AssetRegistration registration(assetName, &attachmentUniqueFull->attachment); + + InfoStringToAttachmentUniqueConverter converter(infoString, + *attachmentUniqueFull, + m_zone.m_script_strings, + m_memory, + context, + registration, + attachment_unique_fields, + std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse attachment unique: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.h b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.h new file mode 100644 index 00000000..3ff89621 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.h @@ -0,0 +1,26 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" + +#include + +namespace T6 +{ + class InfoStringLoaderAttachmentUnique + { + public: + InfoStringLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + static bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.cpp b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.cpp new file mode 100644 index 00000000..940e3955 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.cpp @@ -0,0 +1,633 @@ +#include "InfoStringLoaderWeaponT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/T6.h" +#include "Game/T6/Weapon/WeaponFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" +#include "InfoStringLoaderAttachmentUniqueT6.h" +#include "Weapon/AccuracyGraphLoader.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class InfoStringToWeaponConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + switch (static_cast(field.iFieldType)) + { + case WFT_WEAPONTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapTypeNames, std::extent_v); + + case WFT_WEAPONCLASS: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapClassNames, std::extent_v); + + case WFT_OVERLAYRETICLE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapOverlayReticleNames, std::extent_v); + + case WFT_PENETRATE_TYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, penetrateTypeNames, std::extent_v); + + case WFT_IMPACT_TYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, impactTypeNames, std::extent_v); + + case WFT_STANCE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapStanceNames, std::extent_v); + + case WFT_PROJ_EXPLOSION: + return ConvertEnumInt(field.szName, value, field.iOffset, szProjectileExplosionNames, std::extent_v); + + case WFT_OFFHAND_CLASS: + return ConvertEnumInt(field.szName, value, field.iOffset, offhandClassNames, std::extent_v); + + case WFT_OFFHAND_SLOT: + return ConvertEnumInt(field.szName, value, field.iOffset, offhandSlotNames, std::extent_v); + + case WFT_ANIMTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, playerAnimTypeNames, std::extent_v); + + case WFT_ACTIVE_RETICLE_TYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, activeReticleNames, std::extent_v); + + case WFT_GUIDED_MISSILE_TYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, guidedMissileNames, std::extent_v); + + case WFT_BOUNCE_SOUND: + return ConvertBounceSounds(field, value); + + case WFT_STICKINESS: + return ConvertEnumInt(field.szName, value, field.iOffset, stickinessNames, std::extent_v); + + case WFT_ROTATETYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, rotateTypeNames, std::extent_v); + + case WFT_OVERLAYINTERFACE: + return ConvertEnumInt(field.szName, value, field.iOffset, overlayInterfaceNames, std::extent_v); + + case WFT_INVENTORYTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapInventoryTypeNames, std::extent_v); + + case WFT_FIRETYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapFireTypeNames, std::extent_v); + + case WFT_CLIPTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, szWeapClipTypeNames, std::extent_v); + + case WFT_AMMOCOUNTER_CLIPTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, ammoCounterClipNames, std::extent_v); + + case WFT_ICONRATIO_HUD: + case WFT_ICONRATIO_AMMOCOUNTER: + case WFT_ICONRATIO_KILL: + case WFT_ICONRATIO_DPAD: + case WFT_ICONRATIO_INDICATOR: + return ConvertEnumInt(field.szName, value, field.iOffset, weapIconRatioNames, std::extent_v); + + case WFT_BARRELTYPE: + return ConvertEnumInt(field.szName, value, field.iOffset, barrelTypeNames, std::extent_v); + + case WFT_HIDETAGS: + return ConvertHideTags(field, value); + + case WFT_EXPLOSION_TAG: + return ConvertScriptString(value, field.iOffset); + + case WFT_NOTETRACKSOUNDMAP: + return ConvertNotetrackSoundMap(field, value); + + case WFT_WEAPON_CAMO: + return ConvertWeaponCamo(field, value); + + case WFT_ATTACHMENTS: + return ConvertAttachments(field, value); + + case WFT_ATTACHMENT_UNIQUES: + return ConvertAttachmentUniques(field, value); + + case WFT_ANIM_NAME: + return ConvertAnimName(field, value); + + default: + assert(false); + return false; + } + } + + bool ConvertHideTags(const cspField_t& field, const std::string& value) + { + std::vector valueArray; + if (!ParseAsArray(value, valueArray)) + { + std::cerr << "Failed to parse hide tags as array\n"; + return false; + } + + if (valueArray.size() > std::extent_v) + { + std::cerr << std::format("Cannot have more than {} hide tags!\n", std::extent_v); + return false; + } + + auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + + if (valueArray.size() < std::extent_v) + m_registration.AddScriptString(m_zone_script_strings.AddOrGetScriptString(nullptr)); + + auto currentHideTag = 0u; + for (; currentHideTag < valueArray.size(); currentHideTag++) + { + const auto& currentValue = valueArray[currentHideTag]; + const auto scrString = + !currentValue.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue) : m_zone_script_strings.AddOrGetScriptString(nullptr); + hideTags[currentHideTag] = scrString; + m_registration.AddScriptString(scrString); + } + + for (; currentHideTag < std::extent_v; currentHideTag++) + { + hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(nullptr); + } + + return true; + } + + _NODISCARD bool ConvertBounceSounds(const cspField_t& field, const std::string& value) const + { + auto*** bounceSound = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + if (value.empty()) + { + *bounceSound = nullptr; + return true; + } + + assert(std::extent_v == SURF_TYPE_NUM); + *bounceSound = m_memory.Alloc(SURF_TYPE_NUM); + for (auto i = 0u; i < SURF_TYPE_NUM; i++) + { + const auto currentBounceSound = value + bounceSoundSuffixes[i]; + (*bounceSound)[i] = m_memory.Dup(currentBounceSound.c_str()); + } + return true; + } + + _NODISCARD bool ConvertNotetrackSoundMap(const cspField_t& field, const std::string& value) + { + std::vector> pairs; + if (!ParseAsArray(value, pairs)) + { + std::cerr << "Failed to parse notetracksoundmap as pairs\n"; + return false; + } + + if (pairs.size() > std::extent_v) + { + std::cerr << "Cannot have more than " << std::extent_v << " notetracksoundmap entries!\n"; + return false; + } + + auto* keys = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + auto* values = &keys[std::extent_v]; + auto currentEntryNum = 0u; + + if (pairs.size() < std::extent_v) + { + m_registration.AddScriptString(m_zone_script_strings.AddOrGetScriptString(nullptr)); + } + + for (; currentEntryNum < pairs.size(); currentEntryNum++) + { + const auto& currentValue = pairs[currentEntryNum]; + const auto keyScriptString = !currentValue[0].empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue[0]) + : m_zone_script_strings.AddOrGetScriptString(nullptr); + const auto valueScriptString = !currentValue[1].empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue[1]) + : m_zone_script_strings.AddOrGetScriptString(nullptr); + + keys[currentEntryNum] = keyScriptString; + m_registration.AddScriptString(keyScriptString); + + values[currentEntryNum] = valueScriptString; + m_registration.AddScriptString(valueScriptString); + } + + for (; currentEntryNum < std::extent_v; currentEntryNum++) + { + const auto emptyScr = m_zone_script_strings.GetScriptString(nullptr); + keys[currentEntryNum] = emptyScr; + values[currentEntryNum] = emptyScr; + } + + return true; + } + + _NODISCARD bool ConvertWeaponCamo(const cspField_t& field, const std::string& value) + { + if (value.empty()) + { + *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = nullptr; + return true; + } + + auto* camo = m_context.LoadDependency(value); + + if (camo == nullptr) + { + std::cerr << std::format("Failed to load camo asset \"{}\"\n", value); + return false; + } + + m_registration.AddDependency(camo); + *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = camo->Asset(); + + return true; + } + + _NODISCARD bool ConvertAttachments(const cspField_t& field, const std::string& value) + { + std::vector valueArray; + if (!ParseAsArray(value, valueArray)) + { + std::cerr << "Failed to parse attachments as array\n"; + return false; + } + + auto** attachments = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + + for (const auto& attachmentName : valueArray) + { + auto* attachmentAssetInfo = m_context.LoadDependency(attachmentName); + if (attachmentAssetInfo == nullptr) + { + std::cerr << std::format("Failed to load attachment asset \"{}\"\n", attachmentName); + return false; + } + + auto* attachmentAsset = attachmentAssetInfo->Asset(); + + if (static_cast(attachmentAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT) + { + std::cerr << std::format( + "Invalid attachment type {} for attachment asset \"{}\"\n", static_cast(attachmentAsset->attachmentType), attachmentName); + return false; + } + + if (attachments[attachmentAsset->attachmentType] != nullptr) + { + std::cerr << std::format("Already loaded attachment with same type {}: \"{}\", \"{}\"\n", + static_cast(attachmentAsset->attachmentType), + attachments[attachmentAsset->attachmentType]->szInternalName, + attachmentName); + return false; + } + + attachments[attachmentAsset->attachmentType] = attachmentAsset; + m_registration.AddDependency(attachmentAssetInfo); + } + + return true; + } + + _NODISCARD static bool HasMoreThanOneAttachmentSetInMask(const int mask) + { + // Check if int has more than 1 bit set + return (mask & (mask - 1)) != 0; + } + + _NODISCARD bool ConvertAttachmentUniques(const cspField_t& field, const std::string& value) + { + std::vector valueArray; + if (!ParseAsArray(value, valueArray)) + { + std::cerr << "Failed to parse attachment uniques as array\n"; + return false; + } + + auto** attachmentUniques = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + auto attachmentCombinationIndex = std::extent_v; + + for (const auto& attachmentUniqueName : valueArray) + { + auto* attachmentUniqueAssetInfo = m_context.LoadDependency(attachmentUniqueName); + if (attachmentUniqueAssetInfo == nullptr) + { + std::cerr << std::format("Failed to load attachment unique asset \"{}\"\n", attachmentUniqueName); + return false; + } + + auto* attachmentUniqueAsset = attachmentUniqueAssetInfo->Asset(); + + if (HasMoreThanOneAttachmentSetInMask(attachmentUniqueAsset->combinedAttachmentTypeMask)) + { + if (attachmentCombinationIndex >= std::extent_v) + { + std::cerr << std::format( + "Cannot have more than {} combined attachment attachment unique entries!\n", + (std::extent_v - std::extent_v)); + return false; + } + + attachmentUniques[attachmentCombinationIndex++] = attachmentUniqueAsset; + m_registration.AddDependency(attachmentUniqueAssetInfo); + } + else + { + if (static_cast(attachmentUniqueAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT) + { + std::cerr << std::format("Invalid attachment type {} for attachment unique asset \"{}\"\n", + static_cast(attachmentUniqueAsset->attachmentType), + attachmentUniqueName); + return false; + } + + if (attachmentUniques[attachmentUniqueAsset->attachmentType] != nullptr) + { + std::cerr << std::format("Already loaded attachment unique with same type {}: \"{}\", \"{}\"\n", + static_cast(attachmentUniqueAsset->attachmentType), + attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName, + attachmentUniqueName); + return false; + } + + attachmentUniques[attachmentUniqueAsset->attachmentType] = attachmentUniqueAsset; + m_registration.AddDependency(attachmentUniqueAssetInfo); + } + } + + return true; + } + + bool ConvertAnimName(const cspField_t& field, const std::string& value) + { + if (ConvertString(value, field.iOffset)) + { + if (!value.empty()) + m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference(value)); + + return true; + } + + return false; + } + + public: + InfoStringToWeaponConverter(const InfoString& infoString, + WeaponFullDef& weaponFullDef, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &weaponFullDef, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; + + void ConvertAccuracyGraph( + const GenericGraph2D& graph, vec2_t*& originalGraphKnots, int& originalGraphKnotCount, vec2_t*& graphKnots, int& graphKnotCount, MemoryManager& memory) + { + originalGraphKnotCount = static_cast(graph.knots.size()); + originalGraphKnots = memory.Alloc(originalGraphKnotCount); + + for (auto i = 0; i < originalGraphKnotCount; i++) + { + const auto& commonKnot = graph.knots[i]; + originalGraphKnots[i].x = static_cast(commonKnot.x); + originalGraphKnots[i].y = static_cast(commonKnot.y); + } + + graphKnots = originalGraphKnots; + graphKnotCount = originalGraphKnotCount; + } + + bool LoadAccuracyGraphs(WeaponFullDef& weaponFullDef, MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context) + { + auto* accuracyGraphLoader = context.GetZoneAssetLoaderState(); + + if (weaponFullDef.weapDef.aiVsAiAccuracyGraphName && weaponFullDef.weapDef.aiVsAiAccuracyGraphName[0]) + { + const auto* graph = accuracyGraphLoader->LoadAiVsAiGraph(searchPath, weaponFullDef.weapDef.aiVsAiAccuracyGraphName); + if (!graph) + return false; + + ConvertAccuracyGraph(*graph, + weaponFullDef.weapDef.originalAiVsAiAccuracyGraphKnots, + weaponFullDef.weapDef.originalAiVsAiAccuracyGraphKnotCount, + weaponFullDef.weapDef.aiVsAiAccuracyGraphKnots, + weaponFullDef.weapDef.aiVsAiAccuracyGraphKnotCount, + memory); + } + + if (weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName && weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName[0]) + { + const auto* graph = accuracyGraphLoader->LoadAiVsPlayerGraph(searchPath, weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName); + if (!graph) + return false; + + ConvertAccuracyGraph(*graph, + weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots, + weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount, + weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnots, + weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnotCount, + memory); + } + + return true; + } + + void LinkWeaponFullDefSubStructs(WeaponFullDef& weapon) + { + weapon.weapVariantDef.weapDef = &weapon.weapDef; + weapon.weapVariantDef.attachments = weapon.attachments; + weapon.weapVariantDef.attachmentUniques = weapon.attachmentUniques; + weapon.weapDef.gunXModel = weapon.gunXModel; + weapon.weapVariantDef.szXAnims = weapon.szXAnims; + weapon.weapVariantDef.hideTags = weapon.hideTags; + weapon.weapDef.notetrackSoundMapKeys = weapon.notetrackSoundMapKeys; + weapon.weapDef.notetrackSoundMapValues = weapon.notetrackSoundMapValues; + weapon.weapDef.worldModel = weapon.worldModel; + weapon.weapVariantDef.attachViewModel = weapon.attachViewModel; + weapon.weapVariantDef.attachWorldModel = weapon.attachWorldModel; + weapon.weapVariantDef.attachViewModelTag = weapon.attachViewModelTag; + weapon.weapVariantDef.attachWorldModelTag = weapon.attachWorldModelTag; + weapon.weapDef.parallelBounce = weapon.parallelBounce; + weapon.weapDef.perpendicularBounce = weapon.perpendicularBounce; + weapon.weapDef.locationDamageMultipliers = weapon.locationDamageMultipliers; + } + + void CalculateWeaponFields(WeaponFullDef& weapon) + { + // iAttachments + weapon.weapVariantDef.iAttachments = 0; + for (auto i = 1u; i < sizeof(WeaponVariantDef::iAttachments) * 8; i++) // Bit for default attachment always 0 + { + if (weapon.attachments[i]) + weapon.weapVariantDef.iAttachments |= 1 << i; + } + + if (weapon.weapVariantDef.iAdsTransInTime <= 0) + weapon.weapVariantDef.fOOPosAnimLength[0] = 0.0033333334f; + else + weapon.weapVariantDef.fOOPosAnimLength[0] = 1.0f / static_cast(weapon.weapVariantDef.iAdsTransInTime); + + if (weapon.weapVariantDef.iAdsTransOutTime <= 0) + weapon.weapVariantDef.fOOPosAnimLength[1] = 0.0020000001f; + else + weapon.weapVariantDef.fOOPosAnimLength[1] = 1.0f / static_cast(weapon.weapVariantDef.iAdsTransOutTime); + } + + bool IsStringOverride(const char* baseString, const char* overrideString) + { + if (overrideString == nullptr || overrideString[0] == '\0') + return false; + + if (baseString == nullptr || baseString[0] == '\0') + return true; + + return strcmp(baseString, overrideString) != 0; + } + + bool IsFxOverride(const FxEffectDef* baseEffect, const FxEffectDef* overrideEffect) + { + if (overrideEffect == nullptr) + return false; + + if (baseEffect == nullptr) + return true; + + return strcmp(baseEffect->name, overrideEffect->name) != 0; + } + + void HandleSoundOverride(WeaponAttachmentUnique& attachmentUnique, const char* snd1, const char* snd2, const eAttachmentOverrideSounds sndOverrideIndex) + { + if (IsStringOverride(snd1, snd2)) + attachmentUnique.soundOverrides |= 1 << static_cast(sndOverrideIndex); + } + + void HandleFxOverride(WeaponAttachmentUnique& attachmentUnique, + const FxEffectDef* effect1, + const FxEffectDef* effect2, + const eAttachmentOverrideEffects fxOverrideIndex) + { + if (IsFxOverride(effect1, effect2)) + attachmentUnique.effectOverrides |= 1 << static_cast(fxOverrideIndex); + } + + void CalculateAttachmentFields(const WeaponFullDef& weapon, unsigned attachmentIndex, WeaponAttachmentUnique& attachmentUnique) + { + for (auto& val : attachmentUnique.animationOverrides) + val = 0; + + for (auto animIndex = 0u; animIndex < std::extent_v; animIndex++) + { + if (IsStringOverride(weapon.szXAnims[animIndex], attachmentUnique.szXAnims[animIndex])) + attachmentUnique.animationOverrides[animIndex / 32] |= 1 << (animIndex % 32); + } + + attachmentUnique.soundOverrides = 0; + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireSound, attachmentUnique.fireSound, ATTACHMENT_OVERRIDE_SOUND_FIRE); + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireSoundPlayer, attachmentUnique.fireSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_PLAYER); + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireLoopSound, attachmentUnique.fireLoopSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP); + HandleSoundOverride( + attachmentUnique, weapon.weapDef.fireLoopSoundPlayer, attachmentUnique.fireLoopSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP_PLAYER); + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireLoopEndSound, attachmentUnique.fireLoopEndSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP_END); + HandleSoundOverride( + attachmentUnique, weapon.weapDef.fireLoopEndSoundPlayer, attachmentUnique.fireLoopEndSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_LOOP_END_PLAYER); + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireStartSound, attachmentUnique.fireStartSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_START); + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireStopSound, attachmentUnique.fireStopSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_STOP); + HandleSoundOverride( + attachmentUnique, weapon.weapDef.fireStartSoundPlayer, attachmentUnique.fireStartSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_START_PLAYER); + HandleSoundOverride( + attachmentUnique, weapon.weapDef.fireStopSoundPlayer, attachmentUnique.fireStopSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_STOP_PLAYER); + HandleSoundOverride(attachmentUnique, weapon.weapDef.fireLastSound, attachmentUnique.fireLastSound, ATTACHMENT_OVERRIDE_SOUND_FIRE_LAST); + HandleSoundOverride( + attachmentUnique, weapon.weapDef.fireLastSoundPlayer, attachmentUnique.fireLastSoundPlayer, ATTACHMENT_OVERRIDE_SOUND_FIRE_LAST_PLAYER); + + attachmentUnique.effectOverrides = 0; + HandleFxOverride(attachmentUnique, weapon.weapDef.viewFlashEffect, attachmentUnique.viewFlashEffect, ATTACHMENT_OVERRIDE_EFFECT_VIEW_FLASH); + HandleFxOverride(attachmentUnique, weapon.weapDef.worldFlashEffect, attachmentUnique.worldFlashEffect, ATTACHMENT_OVERRIDE_EFFECT_WORLD_FLASH); + + attachmentUnique.childLink = 0; + if (attachmentUnique.combinedAttachmentTypeMask == 0) + { + WeaponAttachmentUnique* lastSibling = nullptr; + for (auto attachmentUniqueIndex = std::extent_v; + attachmentUniqueIndex < std::extent_v; + attachmentUniqueIndex++) + { + if (weapon.attachmentUniques[attachmentUniqueIndex] != nullptr + && weapon.attachmentUniques[attachmentUniqueIndex]->combinedAttachmentTypeMask + & (1 << static_cast(attachmentUnique.attachmentType)) + && weapon.attachmentUniques[attachmentUniqueIndex]->attachmentType != attachmentUnique.attachmentType) + { + std::vector attachments; + if (InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(weapon.attachmentUniques[attachmentUniqueIndex]->szInternalName, + attachments) + && attachments.front() == attachmentUnique.attachmentType) + { + if (lastSibling == nullptr) + { + attachmentUnique.childLink = attachmentUniqueIndex; + lastSibling = weapon.attachmentUniques[attachmentUniqueIndex]; + } + else + { + lastSibling->siblingLink = attachmentUniqueIndex; + lastSibling = weapon.attachmentUniques[attachmentUniqueIndex]; + } + } + } + } + } + } + + void CalculateAttachmentFields(const WeaponFullDef& weapon) + { + for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent_v; attachmentUniqueIndex++) + { + if (weapon.attachmentUniques[attachmentUniqueIndex] == nullptr) + continue; + + CalculateAttachmentFields(weapon, attachmentUniqueIndex, *weapon.attachmentUniques[attachmentUniqueIndex]); + } + } +} // namespace + +InfoStringLoaderWeapon::InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderWeapon::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* weaponFullDef = m_memory.Alloc(); + weaponFullDef->weapVariantDef.szInternalName = m_memory.Dup(assetName.c_str()); + + LinkWeaponFullDefSubStructs(*weaponFullDef); + + AssetRegistration registration(assetName, &weaponFullDef->weapVariantDef); + + InfoStringToWeaponConverter converter( + infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateWeaponFields(*weaponFullDef); + CalculateAttachmentFields(*weaponFullDef); + + LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.h b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.h new file mode 100644 index 00000000..f745963a --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderWeapon + { + public: + InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/WeaponCamo/JsonWeaponCamoLoader.cpp b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp similarity index 86% rename from src/ObjLoading/Game/T6/WeaponCamo/JsonWeaponCamoLoader.cpp rename to src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp index 3c8a4c60..b98df329 100644 --- a/src/ObjLoading/Game/T6/WeaponCamo/JsonWeaponCamoLoader.cpp +++ b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp @@ -1,4 +1,4 @@ -#include "JsonWeaponCamoLoader.h" +#include "JsonWeaponCamoLoaderT6.h" #include "Game/T6/CommonT6.h" #include "Game/T6/Json/JsonWeaponCamo.h" @@ -15,11 +15,11 @@ namespace class JsonLoader { public: - JsonLoader(std::istream& stream, MemoryManager& memory, IAssetLoadingManager& manager, std::vector& dependencies) + JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) : m_stream(stream), m_memory(memory), - m_manager(manager), - m_dependencies(dependencies) + m_context(context), + m_registration(registration) { } @@ -35,7 +35,7 @@ namespace if (type != "weaponCamo" || version != 1u) { - std::cerr << "Tried to load weapon camo \"" << weaponCamo.name << "\" but did not find expected type weaponCamo of version 1\n"; + std::cerr << std::format("Tried to load weapon camo \"{}\" but did not find expected type weaponCamo of version {}\n", weaponCamo.name, 1u); return false; } @@ -62,25 +62,25 @@ namespace { if (jWeaponCamoSet.solidCamoImage) { - auto* image = m_manager.LoadDependency(jWeaponCamoSet.solidCamoImage.value()); + auto* image = m_context.LoadDependency(jWeaponCamoSet.solidCamoImage.value()); if (!image) { PrintError(weaponCamo, "Could not find solidCamoImage"); return false; } - m_dependencies.push_back(image); + m_registration.AddDependency(image); weaponCamoSet.solidCamoImage = image->Asset(); } if (jWeaponCamoSet.patternCamoImage) { - auto* image = m_manager.LoadDependency(jWeaponCamoSet.patternCamoImage.value()); + auto* image = m_context.LoadDependency(jWeaponCamoSet.patternCamoImage.value()); if (!image) { PrintError(weaponCamo, "Could not find patternCamoImage"); return false; } - m_dependencies.push_back(image); + m_registration.AddDependency(image); weaponCamoSet.patternCamoImage = image->Asset(); } @@ -111,8 +111,8 @@ namespace for (auto i = 0u; i < weaponCamoMaterial.numBaseMaterials; i++) { const auto& materialOverride = jWeaponCamoMaterial.materialOverrides[i]; - auto* baseMaterial = m_manager.LoadDependency(materialOverride.baseMaterial); - auto* camoMaterial = m_manager.LoadDependency(materialOverride.camoMaterial); + auto* baseMaterial = m_context.LoadDependency(materialOverride.baseMaterial); + auto* camoMaterial = m_context.LoadDependency(materialOverride.camoMaterial); if (!baseMaterial) { @@ -126,8 +126,8 @@ namespace return false; } - m_dependencies.push_back(baseMaterial); - m_dependencies.push_back(camoMaterial); + m_registration.AddDependency(baseMaterial); + m_registration.AddDependency(camoMaterial); weaponCamoMaterial.baseMaterials[i] = baseMaterial->Asset(); weaponCamoMaterial.camoMaterials[i] = camoMaterial->Asset(); @@ -173,25 +173,25 @@ namespace { if (jWeaponCamo.solidBaseImage) { - auto* image = m_manager.LoadDependency(jWeaponCamo.solidBaseImage.value()); + auto* image = m_context.LoadDependency(jWeaponCamo.solidBaseImage.value()); if (!image) { PrintError(weaponCamo, "Could not find solidBaseImage"); return false; } - m_dependencies.push_back(image); + m_registration.AddDependency(image); weaponCamo.solidBaseImage = image->Asset(); } if (jWeaponCamo.patternBaseImage) { - auto* image = m_manager.LoadDependency(jWeaponCamo.patternBaseImage.value()); + auto* image = m_context.LoadDependency(jWeaponCamo.patternBaseImage.value()); if (!image) { PrintError(weaponCamo, "Could not find patternBaseImage"); return false; } - m_dependencies.push_back(image); + m_registration.AddDependency(image); weaponCamo.patternBaseImage = image->Asset(); } @@ -234,17 +234,17 @@ namespace std::istream& m_stream; MemoryManager& m_memory; - IAssetLoadingManager& m_manager; - std::vector& m_dependencies; + AssetCreationContext& m_context; + AssetRegistration& m_registration; }; } // namespace namespace T6 { bool LoadWeaponCamoAsJson( - std::istream& stream, WeaponCamo& weaponCamo, MemoryManager* memory, IAssetLoadingManager* manager, std::vector& dependencies) + std::istream& stream, WeaponCamo& weaponCamo, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) { - const JsonLoader loader(stream, *memory, *manager, dependencies); + const JsonLoader loader(stream, memory, context, registration); return loader.Load(weaponCamo); } diff --git a/src/ObjLoading/Game/T6/WeaponCamo/JsonWeaponCamoLoader.h b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h similarity index 56% rename from src/ObjLoading/Game/T6/WeaponCamo/JsonWeaponCamoLoader.h rename to src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h index b0fc78bb..6f5aea17 100644 --- a/src/ObjLoading/Game/T6/WeaponCamo/JsonWeaponCamoLoader.h +++ b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h @@ -1,6 +1,7 @@ #pragma once -#include "AssetLoading/IAssetLoadingManager.h" +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetRegistration.h" #include "Game/T6/T6.h" #include "Utils/MemoryManager.h" @@ -9,5 +10,5 @@ namespace T6 { bool LoadWeaponCamoAsJson( - std::istream& stream, WeaponCamo& weaponCamo, MemoryManager* memory, IAssetLoadingManager* manager, std::vector& dependencies); + std::istream& stream, WeaponCamo& weaponCamo, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration); } // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp b/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp new file mode 100644 index 00000000..c3409ac8 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp @@ -0,0 +1,55 @@ +#include "LoaderWeaponCamoT6.h" + +#include "Game/T6/T6.h" +#include "JsonWeaponCamoLoaderT6.h" +#include "Pool/GlobalAssetPool.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class WeaponCamoLoader final : public AssetCreator + { + public: + WeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(std::format("camo/{}.json", assetName)); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* weaponCamo = m_memory.Alloc(); + weaponCamo->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, weaponCamo); + if (!LoadWeaponCamoAsJson(*file.m_stream, *weaponCamo, m_memory, context, registration)) + { + std::cerr << std::format("Failed to load weapon camo \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateWeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.h b/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.h new file mode 100644 index 00000000..b5270fba --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateWeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.cpp b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.cpp new file mode 100644 index 00000000..bf318b2d --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderAttachmentT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderAttachmentT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderAttachment final : public AssetCreator + { + public: + RawLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("attachment/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderAttachment m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h new file mode 100644 index 00000000..d83631d1 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.cpp b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.cpp new file mode 100644 index 00000000..f3af0c30 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderAttachmentUniqueT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderAttachmentUniqueT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderAttachmentUnique final : public AssetCreator + { + public: + RawLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("attachmentunique/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderAttachmentUnique m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.h b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.h new file mode 100644 index 00000000..47b66237 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.cpp b/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.cpp new file mode 100644 index 00000000..36cbcd48 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderWeaponT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderWeaponT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderWeapon final : public AssetCreator + { + public: + RawLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("weapons/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderWeapon m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h b/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h new file mode 100644 index 00000000..8eedbb71 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/ZBarrier/GdtLoaderZBarrierT6.cpp b/src/ObjLoading/Game/T6/ZBarrier/GdtLoaderZBarrierT6.cpp new file mode 100644 index 00000000..cba149e6 --- /dev/null +++ b/src/ObjLoading/Game/T6/ZBarrier/GdtLoaderZBarrierT6.cpp @@ -0,0 +1,53 @@ +#include "GdtLoaderZBarrierT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderZBarrierT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class GdtLoaderZBarrier final : public AssetCreator + { + public: + GdtLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + : m_gdt(gdt), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_ZBARRIER, assetName); + if (gdtEntry == nullptr) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromGdtProperties(*gdtEntry)) + { + std::cerr << std::format("Failed to read zbarrier gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + IGdtQueryable& m_gdt; + InfoStringLoaderZBarrier m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateGdtZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, searchPath, gdt, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/ZBarrier/GdtLoaderZBarrierT6.h b/src/ObjLoading/Game/T6/ZBarrier/GdtLoaderZBarrierT6.h new file mode 100644 index 00000000..af3796b9 --- /dev/null +++ b/src/ObjLoading/Game/T6/ZBarrier/GdtLoaderZBarrierT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateGdtZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/ZBarrier/InfoStringLoaderZBarrierT6.cpp b/src/ObjLoading/Game/T6/ZBarrier/InfoStringLoaderZBarrierT6.cpp new file mode 100644 index 00000000..23c460b9 --- /dev/null +++ b/src/ObjLoading/Game/T6/ZBarrier/InfoStringLoaderZBarrierT6.cpp @@ -0,0 +1,83 @@ +#include "InfoStringLoaderZBarrierT6.h" + +#include "Game/T6/InfoString/InfoStringToStructConverter.h" +#include "Game/T6/T6.h" +#include "Game/T6/ZBarrier/ZBarrierFields.h" + +#include +#include +#include +#include +#include + +using namespace T6; + +namespace +{ + class InfoStringToZBarrierConverter final : public InfoStringToStructConverter + { + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + assert(false); + return false; + } + + public: + InfoStringToZBarrierConverter(const InfoString& infoString, + ZBarrierDef& zbarrier, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + AssetRegistration& registration, + const cspField_t* fields, + const size_t fieldCount) + : InfoStringToStructConverter(infoString, &zbarrier, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + }; + + void CalculateZBarrierFields(ZBarrierDef& zbarrier) + { + auto foundEnd = false; + for (auto i = 0u; i < std::extent_v; i++) + { + if (zbarrier.boards[i].pBoardModel == nullptr) + { + foundEnd = true; + zbarrier.numBoardsInBarrier = i; + break; + } + } + + if (!foundEnd) + zbarrier.numBoardsInBarrier = std::extent_v; + } +} // namespace + +InfoStringLoaderZBarrier::InfoStringLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +AssetCreationResult InfoStringLoaderZBarrier::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) +{ + auto* zbarrier = m_memory.Alloc(); + zbarrier->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, zbarrier); + + InfoStringToZBarrierConverter converter( + infoString, *zbarrier, m_zone.m_script_strings, m_memory, context, registration, zbarrier_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse zbarrier: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateZBarrierFields(*zbarrier); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); +} diff --git a/src/ObjLoading/Game/T6/ZBarrier/InfoStringLoaderZBarrierT6.h b/src/ObjLoading/Game/T6/ZBarrier/InfoStringLoaderZBarrierT6.h new file mode 100644 index 00000000..5a70ec28 --- /dev/null +++ b/src/ObjLoading/Game/T6/ZBarrier/InfoStringLoaderZBarrierT6.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace T6 +{ + class InfoStringLoaderZBarrier + { + public: + InfoStringLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + Zone& m_zone; + }; +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/ZBarrier/RawLoaderZBarrierT6.cpp b/src/ObjLoading/Game/T6/ZBarrier/RawLoaderZBarrierT6.cpp new file mode 100644 index 00000000..0a7d56d0 --- /dev/null +++ b/src/ObjLoading/Game/T6/ZBarrier/RawLoaderZBarrierT6.cpp @@ -0,0 +1,54 @@ +#include "RawLoaderZBarrierT6.h" + +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderZBarrierT6.h" + +#include +#include +#include + +using namespace T6; + +namespace +{ + class RawLoaderZBarrier final : public AssetCreator + { + public: + RawLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_search_path(searchPath), + m_info_string_loader(memory, searchPath, zone) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("zbarrier/{}", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + InfoString infoString; + if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *file.m_stream)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + return m_info_string_loader.CreateAsset(assetName, infoString, context); + } + + private: + ISearchPath& m_search_path; + InfoStringLoaderZBarrier m_info_string_loader; + }; +} // namespace + +namespace T6 +{ + std::unique_ptr> CreateRawZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace T6 diff --git a/src/ObjLoading/Game/T6/ZBarrier/RawLoaderZBarrierT6.h b/src/ObjLoading/Game/T6/ZBarrier/RawLoaderZBarrierT6.h new file mode 100644 index 00000000..007b2306 --- /dev/null +++ b/src/ObjLoading/Game/T6/ZBarrier/RawLoaderZBarrierT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6 +{ + std::unique_ptr> CreateRawZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6 diff --git a/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.cpp b/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.cpp index 6a68d6f8..878b9a61 100644 --- a/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.cpp +++ b/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.cpp @@ -61,7 +61,7 @@ class SoundBankWriterImpl : public SoundBankWriter }; public: - explicit SoundBankWriterImpl(std::string fileName, std::ostream& stream, ISearchPath* assetSearchPath) + explicit SoundBankWriterImpl(std::string fileName, std::ostream& stream, ISearchPath& assetSearchPath) : m_file_name(std::move(fileName)), m_stream(stream), m_asset_search_path(assetSearchPath), @@ -212,7 +212,7 @@ public: if (extension.empty()) return false; - const auto file = m_asset_search_path->Open(filePath); + const auto file = m_asset_search_path.Open(filePath); if (!file.IsOpen()) return false; @@ -323,7 +323,7 @@ public: private: std::string m_file_name; std::ostream& m_stream; - ISearchPath* m_asset_search_path; + ISearchPath& m_asset_search_path; std::vector m_sounds; int64_t m_current_offset; @@ -336,7 +336,7 @@ private: std::filesystem::path SoundBankWriter::OutputPath; -std::unique_ptr SoundBankWriter::Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath) +std::unique_ptr SoundBankWriter::Create(const std::string& fileName, std::ostream& stream, ISearchPath& assetSearchPath) { return std::make_unique(fileName, stream, assetSearchPath); } diff --git a/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.h b/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.h index ccd338b3..74de0ae6 100644 --- a/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.h +++ b/src/ObjLoading/ObjContainer/SoundBank/SoundBankWriter.h @@ -19,7 +19,7 @@ public: virtual void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping = false, bool streamed = false) = 0; virtual bool Write(size_t& dataSize) = 0; - static std::unique_ptr Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath); + static std::unique_ptr Create(const std::string& fileName, std::ostream& stream, ISearchPath& assetSearchPath); static std::filesystem::path OutputPath; }; diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp index f4294adf..7be1250a 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp @@ -1,9 +1,8 @@ #include "AssetDumperPhysConstraints.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/PhysConstraintsFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/PhysConstraints/PhysConstraintsFields.h" #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp index e801928d..d11819f4 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp @@ -1,8 +1,8 @@ #include "AssetDumperPhysPreset.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/PhysPresetFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/PhysPreset/PhysPresetFields.h" #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp index 1ecefb98..0c87e4ee 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp @@ -1,9 +1,8 @@ #include "AssetDumperTracer.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/TracerFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Tracer/TracerFields.h" #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp index 2da65383..cccf418a 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp @@ -1,9 +1,8 @@ #include "AssetDumperVehicle.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/VehicleFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Vehicle/VehicleFields.h" #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp index 79eb9963..24223dc4 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp @@ -1,9 +1,9 @@ #include "AssetDumperWeapon.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/WeaponFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Weapon/WeaponFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" #include "Weapon/AccuracyGraphWriter.h" #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp index eafec094..0c7fd032 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp @@ -1,9 +1,9 @@ #include "AssetDumperWeaponAttachment.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/WeaponAttachmentFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Weapon/AttachmentFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp index a24006ee..6730771a 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp @@ -1,9 +1,9 @@ #include "AssetDumperWeaponAttachmentUnique.h" -#include "Game/T6/InfoString/EnumStrings.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/WeaponAttachmentUniqueFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Weapon/AttachmentUniqueFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp index 1272de95..da165648 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp @@ -1,8 +1,8 @@ #include "AssetDumperZBarrier.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/InfoString/ZBarrierFields.h" #include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/ZBarrier/ZBarrierFields.h" #include #include