@@ -228,8 +228,8 @@ int MOSRotating::Create(const MOSRotating& reference) {
228
228
}
229
229
m_ReferenceHardcodedAttachableUniqueIDs.clear ();
230
230
231
- for (const Gib& gib: reference.m_Gibs ) {
232
- m_Gibs.push_back (gib);
231
+ for (const Gib* gib: reference.m_Gibs ) {
232
+ m_Gibs.push_back (new Gib (* gib) );
233
233
}
234
234
235
235
m_GibImpulseLimit = reference.m_GibImpulseLimit ;
@@ -302,8 +302,8 @@ int MOSRotating::ReadProperty(const std::string_view& propName, Reader& reader)
302
302
});
303
303
MatchProperty (" AddGib" ,
304
304
{
305
- Gib gib;
306
- reader >> gib;
305
+ Gib* gib = new Gib () ;
306
+ reader >> * gib;
307
307
m_Gibs.push_back (gib);
308
308
});
309
309
MatchProperty (" GibImpulseLimit" , { reader >> m_GibImpulseLimit; });
@@ -356,7 +356,7 @@ int MOSRotating::Save(Writer& writer) const {
356
356
*/
357
357
for (auto gItr = m_Gibs.begin (); gItr != m_Gibs.end (); ++gItr ) {
358
358
writer.NewProperty (" AddGib" );
359
- writer << (*gItr );
359
+ writer << (** gItr );
360
360
}
361
361
/*
362
362
writer.NewProperty("GibImpulseLimit");
@@ -555,6 +555,10 @@ void MOSRotating::Destroy(bool notInherited) {
555
555
delete (*itr);
556
556
}
557
557
558
+ for (auto gib = m_Gibs.begin (); gib != m_Gibs.end (); ++gib) {
559
+ delete (*gib);
560
+ }
561
+
558
562
for (auto aItr = m_Attachables.begin (); aItr != m_Attachables.end (); ++aItr) {
559
563
if (m_HardcodedAttachableUniqueIDsAndRemovers.find ((*aItr)->GetUniqueID ()) == m_HardcodedAttachableUniqueIDsAndRemovers.end ()) {
560
564
delete (*aItr);
@@ -895,17 +899,17 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
895
899
g_CameraMan.AddScreenShake (m_GibScreenShakeAmount, m_Pos);
896
900
}
897
901
898
- for (const Gib& gibSettingsObject: m_Gibs) {
899
- if (gibSettingsObject. GetCount () == 0 ) {
902
+ for (const Gib* gibSettingsObject: m_Gibs) {
903
+ if (gibSettingsObject-> GetCount () == 0 ) {
900
904
continue ;
901
905
}
902
- MovableObject* gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject. GetParticlePreset ()->Clone ());
906
+ MovableObject* gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject-> GetParticlePreset ()->Clone ());
903
907
904
- int count = gibSettingsObject. GetCount ();
905
- float lifeVariation = gibSettingsObject. GetLifeVariation ();
906
- float spread = gibSettingsObject. GetSpread ();
907
- float minVelocity = gibSettingsObject. GetMinVelocity ();
908
- float maxVelocity = gibSettingsObject. GetMaxVelocity ();
908
+ int count = gibSettingsObject-> GetCount ();
909
+ float lifeVariation = gibSettingsObject-> GetLifeVariation ();
910
+ float spread = gibSettingsObject-> GetSpread ();
911
+ float minVelocity = gibSettingsObject-> GetMinVelocity ();
912
+ float maxVelocity = gibSettingsObject-> GetMaxVelocity ();
909
913
910
914
float mass = (gibParticleClone->GetMass () != 0 ? gibParticleClone->GetMass () : 0 .0001F );
911
915
int lifetime = gibParticleClone->GetLifetime ();
@@ -923,18 +927,18 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
923
927
}
924
928
925
929
float velocityRange = maxVelocity - minVelocity;
926
- Vector rotatedGibOffset = RotateOffset (gibSettingsObject. GetOffset ());
930
+ Vector rotatedGibOffset = RotateOffset (gibSettingsObject-> GetOffset ());
927
931
928
932
// The "Spiral" spread mode uses the fermat spiral as means to determine the velocity of the gib particles, resulting in a evenly spaced out circle (or ring) of particles.
929
- if (gibSettingsObject. GetSpreadMode () == Gib::SpreadMode::SpreadSpiral) {
933
+ if (gibSettingsObject-> GetSpreadMode () == Gib::SpreadMode::SpreadSpiral) {
930
934
float maxRadius = std::sqrt (static_cast <float >(count));
931
935
float scale = velocityRange / maxRadius;
932
936
float randAngle = c_PI * RandomNormalNum ();
933
937
float goldenAngle = 2 .39996F ;
934
938
935
939
for (int i = 0 ; i < count; i++) {
936
940
if (i > 0 ) {
937
- gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject. GetParticlePreset ()->Clone ());
941
+ gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject-> GetParticlePreset ()->Clone ());
938
942
}
939
943
940
944
float radius = std::sqrt (static_cast <float >(count - i));
@@ -944,20 +948,20 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
944
948
gibVelocity.RadRotate (randAngle + RandomNum (0 .0F , spread) + static_cast <float >(i) * goldenAngle);
945
949
946
950
Vector offsetFromRootParent = m_Pos - GetRootParent ()->GetPos () + rotatedGibOffset;
947
- Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular () * GetRootParent ()->GetAngularVel () * gibSettingsObject. InheritsVelocity ()) / c_PPM;
951
+ Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular () * GetRootParent ()->GetAngularVel () * gibSettingsObject-> InheritsVelocity ()) / c_PPM;
948
952
gibVelocity += rotationalVelocity;
949
- gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject. InheritsAngularVelocity ());
953
+ gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject-> InheritsAngularVelocity ());
950
954
951
955
if (lifetime != 0 ) {
952
956
gibParticleClone->SetLifetime (std::max (static_cast <int >(static_cast <float >(lifetime) * (1 .0F - lifeVariation * ((radius / maxRadius) * 0 .75F + RandomNormalNum () * 0 .25F ))), 1 ));
953
957
}
954
958
gibParticleClone->SetRotAngle (gibVelocity.GetAbsRadAngle () + (m_HFlipped ? c_PI : 0 ));
955
959
gibParticleClone->SetAngularVel ((gibParticleClone->GetAngularVel () * 0 .35F ) + (gibParticleClone->GetAngularVel () * 0 .65F / mass) * RandomNum ());
956
- gibParticleClone->SetVel (gibVelocity + ((m_PrevVel + m_Vel) / 2 ) * gibSettingsObject. InheritsVelocity ());
960
+ gibParticleClone->SetVel (gibVelocity + ((m_PrevVel + m_Vel) / 2 ) * gibSettingsObject-> InheritsVelocity ());
957
961
if (movableObjectToIgnore) {
958
962
gibParticleClone->SetWhichMOToNotHit (movableObjectToIgnore);
959
963
}
960
- if (gibSettingsObject. IgnoresTeamHits ()) {
964
+ if (gibSettingsObject-> IgnoresTeamHits ()) {
961
965
gibParticleClone->SetTeam (m_Team);
962
966
gibParticleClone->SetIgnoresTeamHits (true );
963
967
}
@@ -967,7 +971,7 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
967
971
} else {
968
972
for (int i = 0 ; i < count; i++) {
969
973
if (i > 0 ) {
970
- gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject. GetParticlePreset ()->Clone ());
974
+ gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject-> GetParticlePreset ()->Clone ());
971
975
}
972
976
973
977
if (gibParticleClone->GetLifetime () != 0 ) {
@@ -991,31 +995,31 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
991
995
// TODO: Figure out how much the magnitude of an offset should affect spread
992
996
float gibSpread = (rotatedGibOffset.IsZero () && spread == 0 .1F ) ? c_PI : spread;
993
997
// Determine the primary direction of the gib particles.
994
- if (gibSettingsObject. InheritsVelocity () > 0 && !impactImpulse.IsZero ()) {
998
+ if (gibSettingsObject-> InheritsVelocity () > 0 && !impactImpulse.IsZero ()) {
995
999
gibVelocity.RadRotate (impactImpulse.GetAbsRadAngle ());
996
1000
} else if (!rotatedGibOffset.IsZero ()) {
997
1001
gibVelocity.RadRotate (rotatedGibOffset.GetAbsRadAngle ());
998
1002
} else {
999
1003
gibVelocity.RadRotate (m_Rotation.GetRadAngle () + (m_HFlipped ? c_PI : 0 ));
1000
1004
}
1001
1005
// The "Even" spread will spread all gib particles evenly in an arc, while maintaining a randomized velocity magnitude.
1002
- if (gibSettingsObject. GetSpreadMode () == Gib::SpreadMode::SpreadEven) {
1006
+ if (gibSettingsObject-> GetSpreadMode () == Gib::SpreadMode::SpreadEven) {
1003
1007
gibVelocity.RadRotate (gibSpread - (gibSpread * 2 .0F * static_cast <float >(i) / static_cast <float >(count)));
1004
1008
} else {
1005
1009
gibVelocity.RadRotate (gibSpread * RandomNormalNum ());
1006
1010
}
1007
1011
1008
1012
Vector offsetFromRootParent = m_Pos - GetRootParent ()->GetPos () + rotatedGibOffset;
1009
- Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular () * GetRootParent ()->GetAngularVel () * gibSettingsObject. InheritsVelocity ()) / c_PPM;
1013
+ Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular () * GetRootParent ()->GetAngularVel () * gibSettingsObject-> InheritsVelocity ()) / c_PPM;
1010
1014
gibVelocity += rotationalVelocity;
1011
- gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject. InheritsAngularVelocity ());
1015
+ gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject-> InheritsAngularVelocity ());
1012
1016
1013
- gibParticleClone->SetVel (gibVelocity + ((m_PrevVel + m_Vel) / 2 ) * gibSettingsObject. InheritsVelocity ());
1017
+ gibParticleClone->SetVel (gibVelocity + ((m_PrevVel + m_Vel) / 2 ) * gibSettingsObject-> InheritsVelocity ());
1014
1018
1015
1019
if (movableObjectToIgnore) {
1016
1020
gibParticleClone->SetWhichMOToNotHit (movableObjectToIgnore);
1017
1021
}
1018
- if (gibSettingsObject. IgnoresTeamHits ()) {
1022
+ if (gibSettingsObject-> IgnoresTeamHits ()) {
1019
1023
gibParticleClone->SetTeam (m_Team);
1020
1024
gibParticleClone->SetIgnoresTeamHits (true );
1021
1025
}
0 commit comments