@@ -228,8 +228,8 @@ int MOSRotating::Create(const MOSRotating& reference) {
228228 }
229229 m_ReferenceHardcodedAttachableUniqueIDs.clear ();
230230
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) );
233233 }
234234
235235 m_GibImpulseLimit = reference.m_GibImpulseLimit ;
@@ -302,8 +302,8 @@ int MOSRotating::ReadProperty(const std::string_view& propName, Reader& reader)
302302 });
303303 MatchProperty (" AddGib" ,
304304 {
305- Gib gib;
306- reader >> gib;
305+ Gib* gib = new Gib () ;
306+ reader >> * gib;
307307 m_Gibs.push_back (gib);
308308 });
309309 MatchProperty (" GibImpulseLimit" , { reader >> m_GibImpulseLimit; });
@@ -356,7 +356,7 @@ int MOSRotating::Save(Writer& writer) const {
356356 */
357357 for (auto gItr = m_Gibs.begin (); gItr != m_Gibs.end (); ++gItr ) {
358358 writer.NewProperty (" AddGib" );
359- writer << (*gItr );
359+ writer << (** gItr );
360360 }
361361 /*
362362 writer.NewProperty("GibImpulseLimit");
@@ -555,6 +555,10 @@ void MOSRotating::Destroy(bool notInherited) {
555555 delete (*itr);
556556 }
557557
558+ for (auto gib = m_Gibs.begin (); gib != m_Gibs.end (); ++gib) {
559+ delete (*gib);
560+ }
561+
558562 for (auto aItr = m_Attachables.begin (); aItr != m_Attachables.end (); ++aItr) {
559563 if (m_HardcodedAttachableUniqueIDsAndRemovers.find ((*aItr)->GetUniqueID ()) == m_HardcodedAttachableUniqueIDsAndRemovers.end ()) {
560564 delete (*aItr);
@@ -895,17 +899,17 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
895899 g_CameraMan.AddScreenShake (m_GibScreenShakeAmount, m_Pos);
896900 }
897901
898- for (const Gib& gibSettingsObject: m_Gibs) {
899- if (gibSettingsObject. GetCount () == 0 ) {
902+ for (const Gib* gibSettingsObject: m_Gibs) {
903+ if (gibSettingsObject-> GetCount () == 0 ) {
900904 continue ;
901905 }
902- MovableObject* gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject. GetParticlePreset ()->Clone ());
906+ MovableObject* gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject-> GetParticlePreset ()->Clone ());
903907
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 ();
909913
910914 float mass = (gibParticleClone->GetMass () != 0 ? gibParticleClone->GetMass () : 0 .0001F );
911915 int lifetime = gibParticleClone->GetLifetime ();
@@ -923,18 +927,18 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
923927 }
924928
925929 float velocityRange = maxVelocity - minVelocity;
926- Vector rotatedGibOffset = RotateOffset (gibSettingsObject. GetOffset ());
930+ Vector rotatedGibOffset = RotateOffset (gibSettingsObject-> GetOffset ());
927931
928932 // 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) {
930934 float maxRadius = std::sqrt (static_cast <float >(count));
931935 float scale = velocityRange / maxRadius;
932936 float randAngle = c_PI * RandomNormalNum ();
933937 float goldenAngle = 2 .39996F ;
934938
935939 for (int i = 0 ; i < count; i++) {
936940 if (i > 0 ) {
937- gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject. GetParticlePreset ()->Clone ());
941+ gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject-> GetParticlePreset ()->Clone ());
938942 }
939943
940944 float radius = std::sqrt (static_cast <float >(count - i));
@@ -944,20 +948,20 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
944948 gibVelocity.RadRotate (randAngle + RandomNum (0 .0F , spread) + static_cast <float >(i) * goldenAngle);
945949
946950 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;
948952 gibVelocity += rotationalVelocity;
949- gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject. InheritsAngularVelocity ());
953+ gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject-> InheritsAngularVelocity ());
950954
951955 if (lifetime != 0 ) {
952956 gibParticleClone->SetLifetime (std::max (static_cast <int >(static_cast <float >(lifetime) * (1 .0F - lifeVariation * ((radius / maxRadius) * 0 .75F + RandomNormalNum () * 0 .25F ))), 1 ));
953957 }
954958 gibParticleClone->SetRotAngle (gibVelocity.GetAbsRadAngle () + (m_HFlipped ? c_PI : 0 ));
955959 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 ());
957961 if (movableObjectToIgnore) {
958962 gibParticleClone->SetWhichMOToNotHit (movableObjectToIgnore);
959963 }
960- if (gibSettingsObject. IgnoresTeamHits ()) {
964+ if (gibSettingsObject-> IgnoresTeamHits ()) {
961965 gibParticleClone->SetTeam (m_Team);
962966 gibParticleClone->SetIgnoresTeamHits (true );
963967 }
@@ -967,7 +971,7 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
967971 } else {
968972 for (int i = 0 ; i < count; i++) {
969973 if (i > 0 ) {
970- gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject. GetParticlePreset ()->Clone ());
974+ gibParticleClone = dynamic_cast <MovableObject*>(gibSettingsObject-> GetParticlePreset ()->Clone ());
971975 }
972976
973977 if (gibParticleClone->GetLifetime () != 0 ) {
@@ -991,31 +995,31 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
991995 // TODO: Figure out how much the magnitude of an offset should affect spread
992996 float gibSpread = (rotatedGibOffset.IsZero () && spread == 0 .1F ) ? c_PI : spread;
993997 // Determine the primary direction of the gib particles.
994- if (gibSettingsObject. InheritsVelocity () > 0 && !impactImpulse.IsZero ()) {
998+ if (gibSettingsObject-> InheritsVelocity () > 0 && !impactImpulse.IsZero ()) {
995999 gibVelocity.RadRotate (impactImpulse.GetAbsRadAngle ());
9961000 } else if (!rotatedGibOffset.IsZero ()) {
9971001 gibVelocity.RadRotate (rotatedGibOffset.GetAbsRadAngle ());
9981002 } else {
9991003 gibVelocity.RadRotate (m_Rotation.GetRadAngle () + (m_HFlipped ? c_PI : 0 ));
10001004 }
10011005 // 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) {
10031007 gibVelocity.RadRotate (gibSpread - (gibSpread * 2 .0F * static_cast <float >(i) / static_cast <float >(count)));
10041008 } else {
10051009 gibVelocity.RadRotate (gibSpread * RandomNormalNum ());
10061010 }
10071011
10081012 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;
10101014 gibVelocity += rotationalVelocity;
1011- gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject. InheritsAngularVelocity ());
1015+ gibParticleClone->SetAngularVel (gibParticleClone->GetAngularVel () + GetRootParent ()->GetAngularVel () * gibSettingsObject-> InheritsAngularVelocity ());
10121016
1013- gibParticleClone->SetVel (gibVelocity + ((m_PrevVel + m_Vel) / 2 ) * gibSettingsObject. InheritsVelocity ());
1017+ gibParticleClone->SetVel (gibVelocity + ((m_PrevVel + m_Vel) / 2 ) * gibSettingsObject-> InheritsVelocity ());
10141018
10151019 if (movableObjectToIgnore) {
10161020 gibParticleClone->SetWhichMOToNotHit (movableObjectToIgnore);
10171021 }
1018- if (gibSettingsObject. IgnoresTeamHits ()) {
1022+ if (gibSettingsObject-> IgnoresTeamHits ()) {
10191023 gibParticleClone->SetTeam (m_Team);
10201024 gibParticleClone->SetIgnoresTeamHits (true );
10211025 }
0 commit comments