@@ -89,7 +89,7 @@ W3DTankDraw::W3DTankDraw( Thing *thing, const ModuleData* moduleData )
8989: W3DModelDraw( thing, moduleData )
9090, m_prevRenderObj(nullptr )
9191{
92- std::fill (m_treadDebris, m_treadDebris + ARRAY_SIZE (m_treadDebris ), nullptr );
92+ std::fill (m_treadDebrisIDs, m_treadDebrisIDs + ARRAY_SIZE (m_treadDebrisIDs ), INVALID_PARTICLE_SYSTEM_ID );
9393
9494 for (Int i=0 ; i<MAX_TREADS_PER_TANK; i++)
9595 m_treads[i].m_robj = nullptr ;
@@ -107,14 +107,14 @@ W3DTankDraw::W3DTankDraw( Thing *thing, const ModuleData* moduleData )
107107// -------------------------------------------------------------------------------------------------
108108void W3DTankDraw::tossEmitters ( void )
109109{
110- for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris ); ++i)
110+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebrisIDs ); ++i)
111111 {
112- if (m_treadDebris[i] != nullptr )
112+ if (ParticleSystem *particleSys = TheParticleSystemManager-> findParticleSystem (m_treadDebrisIDs[i]) )
113113 {
114- m_treadDebris[i]->attachToObject (nullptr );
115- m_treadDebris[i]->destroy ();
116- m_treadDebris[i] = nullptr ;
114+ particleSys->attachToObject (nullptr );
115+ particleSys->destroy ();
117116 }
117+ m_treadDebrisIDs[i] = INVALID_PARTICLE_SYSTEM_ID;
118118 }
119119}
120120
@@ -123,22 +123,23 @@ void W3DTankDraw::tossEmitters( void )
123123void W3DTankDraw::createEmitters ( void )
124124{
125125 const AsciiString *treadDebrisNames[2 ];
126- static_assert (ARRAY_SIZE (treadDebrisNames) == ARRAY_SIZE (m_treadDebris ), " Array size must match" );
126+ static_assert (ARRAY_SIZE (treadDebrisNames) == ARRAY_SIZE (m_treadDebrisIDs ), " Array size must match" );
127127 treadDebrisNames[0 ] = &getW3DTankDrawModuleData ()->m_treadDebrisNameLeft ;
128128 treadDebrisNames[1 ] = &getW3DTankDrawModuleData ()->m_treadDebrisNameRight ;
129129
130- for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris ); ++i)
130+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebrisIDs ); ++i)
131131 {
132- if (m_treadDebris [i] == nullptr )
132+ if (m_treadDebrisIDs [i] == INVALID_PARTICLE_SYSTEM_ID )
133133 {
134134 if (const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate (*treadDebrisNames[i]))
135135 {
136- m_treadDebris[i] = TheParticleSystemManager->createParticleSystem ( sysTemplate );
137- m_treadDebris[i] ->attachToDrawable (getDrawable ());
136+ ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem ( sysTemplate );
137+ particleSys ->attachToDrawable (getDrawable ());
138138 // important: mark it as do-not-save, since we'll just re-create it when we reload.
139- m_treadDebris[i] ->setSaveable (FALSE );
139+ particleSys ->setSaveable (FALSE );
140140 // they come into being stopped.
141- m_treadDebris[i]->stop ();
141+ particleSys->stop ();
142+ m_treadDebrisIDs[i] = particleSys->getSystemID ();
142143 }
143144 }
144145 }
@@ -156,33 +157,19 @@ W3DTankDraw::~W3DTankDraw()
156157 REF_PTR_RELEASE (m_treads[i].m_robj );
157158}
158159
159- // -------------------------------------------------------------------------------------------------
160- // -------------------------------------------------------------------------------------------------
161- /* *
162- * Start creating debris from the tank treads
163- */
164- void W3DTankDraw::startMoveDebris ( void )
165- {
166- if (getDrawable ()->isDrawableEffectivelyHidden ())
167- return ;
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- }
173- }
174-
175160// -------------------------------------------------------------------------------------------------
176161// -------------------------------------------------------------------------------------------------
177162/* *
178163 * Stop creating debris from the tank treads
179164 */
180165void W3DTankDraw::stopMoveDebris ( void )
181166{
182- for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris ); ++i)
167+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebrisIDs ); ++i)
183168 {
184- if (m_treadDebris[i] != nullptr )
185- m_treadDebris[i]->stop ();
169+ if (ParticleSystem *particleSys = TheParticleSystemManager->findParticleSystem (m_treadDebrisIDs[i]))
170+ {
171+ particleSys->stop ();
172+ }
186173 }
187174}
188175
@@ -330,10 +317,7 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx)
330317 // if tank is moving, kick up dust and debris
331318 Real velMag = vel->x *vel->x + vel->y *vel->y ; // only care about moving on the ground
332319
333- if (velMag > DEBRIS_THRESHOLD && !getDrawable ()->isDrawableEffectivelyHidden () && !getFullyObscuredByShroud ())
334- startMoveDebris ();
335- else
336- stopMoveDebris ();
320+ const Bool doStartMoveDebris = velMag > DEBRIS_THRESHOLD && !getDrawable ()->isDrawableEffectivelyHidden () && !getFullyObscuredByShroud ();
337321
338322 // kick debris higher the faster we move
339323 Coord3D velMult;
@@ -349,10 +333,18 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx)
349333 if (velMult.z > 1 .0f )
350334 velMult.z = 1 .0f ;
351335
352- for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebris ); ++i)
336+ for (size_t i = 0 ; i < ARRAY_SIZE (m_treadDebrisIDs ); ++i)
353337 {
354- m_treadDebris[i]->setVelocityMultiplier ( &velMult );
355- m_treadDebris[i]->setBurstCountMultiplier ( velMult.z );
338+ if (ParticleSystem *particleSys = TheParticleSystemManager->findParticleSystem (m_treadDebrisIDs[i]))
339+ {
340+ if (doStartMoveDebris)
341+ particleSys->start ();
342+ else
343+ particleSys->stop ();
344+
345+ particleSys->setVelocityMultiplier ( &velMult );
346+ particleSys->setBurstCountMultiplier ( velMult.z );
347+ }
356348 }
357349
358350 // Update movement of treads
0 commit comments