@@ -86,10 +86,10 @@ void W3DTankDrawModuleData::buildFieldParse(MultiIniFieldParse& p)
8686// -------------------------------------------------------------------------------------------------
8787// -------------------------------------------------------------------------------------------------
8888W3DTankDraw::W3DTankDraw ( Thing *thing, const ModuleData* moduleData )
89- : W3DModelDraw( thing, moduleData ),m_prevRenderObj(nullptr ), m_treadDebrisLeft(nullptr ), m_treadDebrisRight(nullptr )
89+ : W3DModelDraw( thing, moduleData )
90+ , m_prevRenderObj(nullptr )
9091{
91- m_treadDebrisLeft = nullptr ;
92- m_treadDebrisRight = nullptr ;
92+ std::fill (m_treadDebris, m_treadDebris + ARRAY_SIZE (m_treadDebris), nullptr );
9393
9494 for (Int i=0 ; i<MAX_TREADS_PER_TANK; i++)
9595 m_treads[i].m_robj = nullptr ;
@@ -107,50 +107,39 @@ W3DTankDraw::W3DTankDraw( Thing *thing, const ModuleData* moduleData )
107107// -------------------------------------------------------------------------------------------------
108108void W3DTankDraw::tossEmitters ( void )
109109{
110- if (m_treadDebrisLeft )
110+ for ( size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris); ++i )
111111 {
112- m_treadDebrisLeft->attachToObject (nullptr );
113- m_treadDebrisLeft->destroy ();
114- m_treadDebrisLeft = nullptr ;
115- }
116- if (m_treadDebrisRight)
117- {
118- m_treadDebrisRight->attachToObject (nullptr );
119- m_treadDebrisRight->destroy ();
120- m_treadDebrisRight = nullptr ;
112+ if (m_treadDebris[i] != nullptr )
113+ {
114+ m_treadDebris[i]->attachToObject (nullptr );
115+ m_treadDebris[i]->destroy ();
116+ m_treadDebris[i] = nullptr ;
117+ }
121118 }
122119}
123120
124121// -------------------------------------------------------------------------------------------------
125122// -------------------------------------------------------------------------------------------------
126123void W3DTankDraw::createEmitters ( void )
127124{
128- if (!m_treadDebrisLeft)
129- {
130- const ParticleSystemTemplate *sysTemplate;
131- sysTemplate = TheParticleSystemManager->findTemplate (getW3DTankDrawModuleData ()->m_treadDebrisNameLeft );
132- if (sysTemplate)
133- {
134- m_treadDebrisLeft = TheParticleSystemManager->createParticleSystem ( sysTemplate );
135- m_treadDebrisLeft->attachToDrawable (getDrawable ());
136- // important: mark it as do-not-save, since we'll just re-create it when we reload.
137- m_treadDebrisLeft->setSaveable (FALSE );
138- // they come into being stopped.
139- m_treadDebrisLeft->stop ();
140- }
141- }
142- if (!m_treadDebrisRight)
125+ const AsciiString *treadDebrisNames[2 ];
126+ static_assert (ARRAY_SIZE (treadDebrisNames) == ARRAY_SIZE (m_treadDebris), " Array size must match" );
127+ treadDebrisNames[0 ] = &getW3DTankDrawModuleData ()->m_treadDebrisNameLeft ;
128+ treadDebrisNames[1 ] = &getW3DTankDrawModuleData ()->m_treadDebrisNameRight ;
129+
130+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris); ++i)
143131 {
144- const ParticleSystemTemplate *sysTemplate;
145- sysTemplate = TheParticleSystemManager->findTemplate (getW3DTankDrawModuleData ()->m_treadDebrisNameRight );
146- if (sysTemplate)
132+ if (m_treadDebris[i] == nullptr )
147133 {
148- m_treadDebrisRight = TheParticleSystemManager->createParticleSystem ( sysTemplate );
149- m_treadDebrisRight->attachToDrawable (getDrawable ());
150- // important: mark it as do-not-save, since we'll just re-create it when we reload.
151- m_treadDebrisRight->setSaveable (FALSE );
152- // they come into being stopped.
153- m_treadDebrisRight->stop ();
134+ if (const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate (*treadDebrisNames[i]))
135+ {
136+ m_treadDebris[i] = TheParticleSystemManager->createParticleSystem ( sysTemplate );
137+ m_treadDebris[i]->attachToDrawable (getDrawable ());
138+ // important: mark it as do-not-save, since we'll just re-create it when we reload.
139+ m_treadDebris[i]->setSaveable (FALSE );
140+ // they come into being stopped.
141+ m_treadDebris[i]->stop ();
142+ }
154143 }
155144 }
156145}
@@ -170,17 +159,17 @@ W3DTankDraw::~W3DTankDraw()
170159// -------------------------------------------------------------------------------------------------
171160// -------------------------------------------------------------------------------------------------
172161/* *
173-
174162 * Start creating debris from the tank treads
175163 */
176164void W3DTankDraw::startMoveDebris ( void )
177165{
178166 if (getDrawable ()->isDrawableEffectivelyHidden ())
179167 return ;
180- if (m_treadDebrisLeft)
181- m_treadDebrisLeft->start ();
182- if (m_treadDebrisRight)
183- m_treadDebrisRight->start ();
168+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris); ++i)
169+ {
170+ if (m_treadDebris[i] != nullptr )
171+ m_treadDebris[i]->start ();
172+ }
184173}
185174
186175// -------------------------------------------------------------------------------------------------
@@ -190,10 +179,11 @@ void W3DTankDraw::startMoveDebris( void )
190179 */
191180void W3DTankDraw::stopMoveDebris ( void )
192181{
193- if (m_treadDebrisLeft)
194- m_treadDebrisLeft->stop ();
195- if (m_treadDebrisRight)
196- m_treadDebrisRight->stop ();
182+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris); ++i)
183+ {
184+ if (m_treadDebris[i] != nullptr )
185+ m_treadDebris[i]->stop ();
186+ }
197187}
198188
199189// -------------------------------------------------------------------------------------------------
@@ -359,11 +349,11 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx)
359349 if (velMult.z > 1 .0f )
360350 velMult.z = 1 .0f ;
361351
362- m_treadDebrisLeft-> setVelocityMultiplier ( &velMult );
363- m_treadDebrisRight-> setVelocityMultiplier ( &velMult );
364-
365- m_treadDebrisLeft ->setBurstCountMultiplier ( velMult.z );
366- m_treadDebrisRight-> setBurstCountMultiplier ( velMult. z );
352+ for ( size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris); ++i)
353+ {
354+ m_treadDebris[i]-> setVelocityMultiplier ( &velMult );
355+ m_treadDebris[i] ->setBurstCountMultiplier ( velMult.z );
356+ }
367357
368358 // Update movement of treads
369359 if (m_treadCount)
0 commit comments