Skip to content

Commit

Permalink
Make allocate a template param when parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Jan 21, 2024
1 parent a19a3ef commit 5c46132
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 80 deletions.
2 changes: 1 addition & 1 deletion YRpp
6 changes: 3 additions & 3 deletions src/Ext/AnimType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void AnimTypeExt::ExtData::LoadFromINIFile(CCINIClass* pINI)
INI_EX exINI(pINI);

this->Palette.LoadFromINI(pINI, pID, "CustomPalette");
this->CreateUnit.Read(exINI, pID, "CreateUnit", true);
this->CreateUnit.Read<true>(exINI, pID, "CreateUnit");
this->CreateUnit_Facing.Read(exINI, pID, "CreateUnit.Facing");
this->CreateUnit_InheritDeathFacings.Read(exINI, pID, "CreateUnit.InheritFacings");
this->CreateUnit_InheritTurretFacings.Read(exINI, pID, "CreateUnit.InheritTurretFacings");
Expand All @@ -99,7 +99,7 @@ void AnimTypeExt::ExtData::LoadFromINIFile(CCINIClass* pINI)
this->HideIfNoOre_Threshold.Read(exINI, pID, "HideIfNoOre.Threshold");
this->Layer_UseObjectLayer.Read(exINI, pID, "Layer.UseObjectLayer");
this->UseCenterCoordsIfAttached.Read(exINI, pID, "UseCenterCoordsIfAttached");
this->Weapon.Read(exINI, pID, "Weapon", true);
this->Weapon.Read<true>(exINI, pID, "Weapon");
this->Damage_Delay.Read(exINI, pID, "Damage.Delay");
this->Damage_DealtByInvoker.Read(exINI, pID, "Damage.DealtByInvoker");
this->Damage_ApplyOncePerLoop.Read(exINI, pID, "Damage.ApplyOncePerLoop");
Expand All @@ -108,7 +108,7 @@ void AnimTypeExt::ExtData::LoadFromINIFile(CCINIClass* pINI)
this->WakeAnim.Read(exINI, pID, "WakeAnim");
this->SplashAnims.Read(exINI, pID, "SplashAnims");
this->SplashAnims_PickRandom.Read(exINI, pID, "SplashAnims.PickRandom");
this->AttachedSystem.Read(exINI, pID, "AttachedSystem", true);
this->AttachedSystem.Read<true>(exINI, pID, "AttachedSystem");
this->AltPalette_ApplyLighting.Read(exINI, pID, "AltPalette.ApplyLighting");
this->MakeInfantryOwner.Read(exINI, pID, "MakeInfantryOwner");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/BuildingType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Grinding_DisallowTypes.Read(exINI, pSection, "Grinding.DisallowTypes");
this->Grinding_Sound.Read(exINI, pSection, "Grinding.Sound");
this->Grinding_PlayDieSound.Read(exINI, pSection, "Grinding.PlayDieSound");
this->Grinding_Weapon.Read(exINI, pSection, "Grinding.Weapon", true);
this->Grinding_Weapon.Read<true>(exINI, pSection, "Grinding.Weapon");

this->DisplayIncome.Read(exINI, pSection, "DisplayIncome");
this->DisplayIncome_Houses.Read(exINI, pSection, "DisplayIncome.Houses");
Expand Down
15 changes: 11 additions & 4 deletions src/Ext/Bullet/Hooks.DetonateLogics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,40 @@ DEFINE_HOOK(0x4690C1, BulletClass_Logics_DetonateOnAllMapObjects, 0x8)
}
};

auto copy_dvc = []<typename T>(const DynamicVectorClass<T>& dvc)
{
std::vector<T> vec(dvc.Count);
std::copy(dvc.begin(), dvc.end(), vec.begin());
return vec;
};

if ((pWHExt->DetonateOnAllMapObjects_AffectTargets & AffectedTarget::Aircraft) != AffectedTarget::None)
{
auto const aircraft = DynamicVectorClass<AircraftClass*>(*AircraftClass::Array);
auto const aircraft = copy_dvc(*AircraftClass::Array);

for (auto pAircraft : aircraft)
tryDetonate(pAircraft);
}

if ((pWHExt->DetonateOnAllMapObjects_AffectTargets & AffectedTarget::Building) != AffectedTarget::None)
{
auto const buildings = DynamicVectorClass<BuildingClass*>(*BuildingClass::Array);
auto const buildings = copy_dvc(*BuildingClass::Array);

for (auto pBuilding : buildings)
tryDetonate(pBuilding);
}

if ((pWHExt->DetonateOnAllMapObjects_AffectTargets & AffectedTarget::Infantry) != AffectedTarget::None)
{
auto const infantry = DynamicVectorClass<InfantryClass*>(*InfantryClass::Array);
auto const infantry = copy_dvc(*InfantryClass::Array);

for (auto pInf : infantry)
tryDetonate(pInf);
}

if ((pWHExt->DetonateOnAllMapObjects_AffectTargets & AffectedTarget::Unit) != AffectedTarget::None)
{
auto const units = DynamicVectorClass<UnitClass*>(*UnitClass::Array);
auto const units = copy_dvc(*UnitClass::Array);

for (auto const pUnit : units)
tryDetonate(pUnit);
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/BulletType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void BulletTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Armor.Read(exINI, pSection, "Armor");
this->Interceptable.Read(exINI, pSection, "Interceptable");
this->Interceptable_DeleteOnIntercept.Read(exINI, pSection, "Interceptable.DeleteOnIntercept");
this->Interceptable_WeaponOverride.Read(exINI, pSection, "Interceptable.WeaponOverride", true);
this->Interceptable_WeaponOverride.Read<true>(exINI, pSection, "Interceptable.WeaponOverride");
this->Gravity.Read(exINI, pSection, "Gravity");

PhobosTrajectoryType::CreateType(this->TrajectoryType, pINI, pSection, "Trajectory");
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/SWType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void SWTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
}

this->Detonate_Warhead.Read(exINI, pSection, "Detonate.Warhead");
this->Detonate_Weapon.Read(exINI, pSection, "Detonate.Weapon", true);
this->Detonate_Weapon.Read<true>(exINI, pSection, "Detonate.Weapon");
this->Detonate_Damage.Read(exINI, pSection, "Detonate.Damage");
this->Detonate_AtFirer.Read(exINI, pSection, "Detonate.AtFirer");

Expand Down
8 changes: 4 additions & 4 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->InitialStrength = Math::clamp(this->InitialStrength, 1, pThis->Strength);

this->ReloadInTransport.Read(exINI, pSection, "ReloadInTransport");
this->ShieldType.Read(exINI, pSection, "ShieldType", true);
this->ShieldType.Read<true>(exINI, pSection, "ShieldType");

this->Ammo_AddOnDeploy.Read(exINI, pSection, "Ammo.AddOnDeploy");
this->Ammo_AutoDeployMinimumAmount.Read(exINI, pSection, "Ammo.AutoDeployMinimumAmount");
Expand Down Expand Up @@ -191,9 +191,9 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->ChronoRangeMinimum.Read(exINI, pSection, "ChronoRangeMinimum");
this->ChronoDelay.Read(exINI, pSection, "ChronoDelay");

this->WarpInWeapon.Read(exINI, pSection, "WarpInWeapon", true);
this->WarpInMinRangeWeapon.Read(exINI, pSection, "WarpInMinRangeWeapon", true);
this->WarpOutWeapon.Read(exINI, pSection, "WarpOutWeapon", true);
this->WarpInWeapon.Read<true>(exINI, pSection, "WarpInWeapon");
this->WarpInMinRangeWeapon.Read<true>(exINI, pSection, "WarpInMinRangeWeapon");
this->WarpOutWeapon.Read<true>(exINI, pSection, "WarpOutWeapon");
this->WarpInWeapon_UseDistanceAsDamage.Read(exINI, pSection, "WarpInWeapon.UseDistanceAsDamage");

this->OreGathering_Anims.Read(exINI, pSection, "OreGathering.Anims");
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Shield_Break.Read(exINI, pSection, "Shield.Break");
this->Shield_BreakAnim.Read(exINI, pSection, "Shield.BreakAnim");
this->Shield_HitAnim.Read(exINI, pSection, "Shield.HitAnim");
this->Shield_BreakWeapon.Read(exINI, pSection, "Shield.BreakWeapon", true);
this->Shield_BreakWeapon.Read<true>(exINI, pSection, "Shield.BreakWeapon");
this->Shield_AbsorbPercent.Read(exINI, pSection, "Shield.AbsorbPercent");
this->Shield_PassPercent.Read(exINI, pSection, "Shield.PassPercent");
this->Shield_ReceivedDamage_Minimum.Read(exINI, pSection, "Shield.ReceivedDamage.Minimum");
Expand Down
4 changes: 2 additions & 2 deletions src/Ext/WeaponType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void WeaponTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)

this->Bolt_Arcs.Read(exINI, pSection, "Bolt.Arcs");

this->RadType.Read(exINI, pSection, "RadType", true);
this->RadType.Read<true>(exINI, pSection, "RadType");

this->Strafing_Shots.Read(exINI, pSection, "Strafing.Shots");
this->Strafing_SimulateBurst.Read(exINI, pSection, "Strafing.SimulateBurst");
Expand All @@ -53,7 +53,7 @@ void WeaponTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Burst_Delays.Read(exINI, pSection, "Burst.Delays");
this->Burst_FireWithinSequence.Read(exINI, pSection, "Burst.FireWithinSequence");
this->AreaFire_Target.Read(exINI, pSection, "AreaFire.Target");
this->FeedbackWeapon.Read(exINI, pSection, "FeedbackWeapon", true);
this->FeedbackWeapon.Read<true>(exINI, pSection, "FeedbackWeapon");
this->Laser_IsSingleColor.Read(exINI, pSection, "IsSingleColor");
this->ROF_RandomDelay.Read(exINI, pSection, "ROF.RandomDelay");
this->OmniFire_TurnToTarget.Read(exINI, pSection, "OmniFire.TurnToTarget");
Expand Down
6 changes: 3 additions & 3 deletions src/Misc/Hooks.INIInheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace INIInheritance
INI_EX exINI(ini);
T result;

if (!detail::read<T>(result, exINI, section, entry, false))
if (!detail::read<T>(result, exINI, section, entry))
result = defaultValue;
return result;
}
Expand All @@ -44,7 +44,7 @@ namespace INIInheritance
GET_STACK(T*, defaultValue, 0x10);
INI_EX exINI(ini);

if (!detail::read<T>(*result, exINI, section, entry, false))
if (!detail::read<T>(*result, exINI, section, entry))
*result = *defaultValue;
return result;
}
Expand All @@ -60,7 +60,7 @@ namespace INIInheritance
GET_STACK(CLSID, defaultValue, 0x10);
INI_EX exINI(ini);

if (!detail::read<CLSID>(*result, exINI, section, entry, false))
if (!detail::read<CLSID>(*result, exINI, section, entry))
*result = defaultValue;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/New/Type/Affiliated/InterceptorTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void InterceptorTypeClass::LoadFromINI(CCINIClass* pINI, const char* pSection)
this->MinimumGuardRange.Read(exINI, pSection, "Interceptor.%sMinimumGuardRange");
this->Weapon.Read(exINI, pSection, "Interceptor.Weapon");
this->DeleteOnIntercept.Read(exINI, pSection, "Interceptor.DeleteOnIntercept");
this->WeaponOverride.Read(exINI, pSection, "Interceptor.WeaponOverride", true);
this->WeaponOverride.Read<true>(exINI, pSection, "Interceptor.WeaponOverride");
this->WeaponReplaceProjectile.Read(exINI, pSection, "Interceptor.WeaponReplaceProjectile");
this->WeaponCumulativeDamage.Read(exINI, pSection, "Interceptor.WeaponCumulativeDamage");
this->KeepIntact.Read(exINI, pSection, "Interceptor.KeepIntact");
Expand Down
2 changes: 1 addition & 1 deletion src/New/Type/RadTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void RadTypeClass::LoadFromINI(CCINIClass* pINI)

INI_EX exINI(pINI);

this->RadWarhead.Read(exINI, section, "RadSiteWarhead", true);
this->RadWarhead.Read(exINI, section, "RadSiteWarhead");
this->RadWarhead_Detonate.Read(exINI, section, "RadSiteWarhead.Detonate");
this->RadSiteColor.Read(exINI, section, "RadColor");
this->DurationMultiple.Read(exINI, section, "RadDurationMultiple");
Expand Down
2 changes: 1 addition & 1 deletion src/New/Type/ShieldTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void ShieldTypeClass::LoadFromINI(CCINIClass* pINI)

this->BreakAnim.Read(exINI, pSection, "BreakAnim");
this->HitAnim.Read(exINI, pSection, "HitAnim");
this->BreakWeapon.Read(exINI, pSection, "BreakWeapon", true);
this->BreakWeapon.Read<true>(exINI, pSection, "BreakWeapon");

this->AbsorbPercent.Read(exINI, pSection, "AbsorbPercent");
this->PassPercent.Read(exINI, pSection, "PassPercent");
Expand Down
6 changes: 4 additions & 2 deletions src/Utilities/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class Valueable
return &this->Value;
}

inline void Read(INI_EX& parser, const char* pSection, const char* pKey, bool Allocate = false);
template<bool Allocate = false>
inline void Read(INI_EX& parser, const char* pSection, const char* pKey);

inline bool Load(PhobosStreamReader& Stm, bool RegisterForChange);

Expand Down Expand Up @@ -217,7 +218,8 @@ class Nullable : public Valueable<T>
this->HasValue = false;
}

inline void Read(INI_EX& parser, const char* pSection, const char* pKey, bool Allocate = false);
template<bool Allocate = false>
inline void Read(INI_EX& parser, const char* pSection, const char* pKey);

inline bool Load(PhobosStreamReader& Stm, bool RegisterForChange);

Expand Down
Loading

0 comments on commit 5c46132

Please sign in to comment.