Add calculation of fields not specified via weapon fields to asset loader weapon

This commit is contained in:
Jan 2021-03-25 13:34:14 +01:00
parent cb3e4386a9
commit aaf350d088
2 changed files with 27 additions and 1 deletions

View File

@ -344,11 +344,33 @@ void AssetLoaderWeapon::LinkWeaponFullDefSubStructs(WeaponFullDef* weapon)
weapon->weapDef.locationDamageMultipliers = weapon->locationDamageMultipliers; 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<float>(weapon->weapVariantDef.iAdsTransInTime);
if (weapon->weapVariantDef.iAdsTransOutTime <= 0)
weapon->weapVariantDef.fOOPosAnimLength[1] = 0.0020000001f;
else
weapon->weapVariantDef.fOOPosAnimLength[1] = 1.0f / static_cast<float>(weapon->weapVariantDef.iAdsTransOutTime);
}
void* AssetLoaderWeapon::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) void* AssetLoaderWeapon::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{ {
auto* weaponFullDef = memory->Create<WeaponFullDef>(); auto* weaponFullDef = memory->Create<WeaponFullDef>();
memset(weaponFullDef, 0, sizeof(WeaponFullDef)); memset(weaponFullDef, 0, sizeof(WeaponFullDef));
LinkWeaponFullDefSubStructs(weaponFullDef); LinkWeaponFullDefSubStructs(weaponFullDef);
CalculateWeaponFields(weaponFullDef);
weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str()); weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str());
return weaponFullDef; return weaponFullDef;
} }
@ -385,7 +407,10 @@ bool AssetLoaderWeapon::LoadFromRaw(const std::string& assetName, ISearchPath* s
weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str()); weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str());
manager->AddAsset(ASSET_TYPE_WEAPON, assetName, weaponFullDef, converter.GetDependencies(), converter.GetUsedScriptStrings()); // TODO: Load accuracy graph and flametable
CalculateWeaponFields(weaponFullDef);
manager->AddAsset(ASSET_TYPE_WEAPON, assetName, &weaponFullDef->weapVariantDef, converter.GetDependencies(), converter.GetUsedScriptStrings());
return true; return true;
} }

View File

@ -9,6 +9,7 @@ namespace T6
class AssetLoaderWeapon final : public BasicAssetLoader<ASSET_TYPE_WEAPON, WeaponVariantDef> class AssetLoaderWeapon final : public BasicAssetLoader<ASSET_TYPE_WEAPON, WeaponVariantDef>
{ {
static void LinkWeaponFullDefSubStructs(WeaponFullDef* weapon); static void LinkWeaponFullDefSubStructs(WeaponFullDef* weapon);
static void CalculateWeaponFields(WeaponFullDef* weapon);
public: public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;