Skip to content

Commit b489322

Browse files
committed
fix(draw): Recover tread debris effects for W3DTankTruckDraw (TheSuperHackers#2251)
Tread debris can be enabled in W3DTankTruckDraw INI modules by setting TreadDebrisLeft=TrackDebrisDirtLeft TreadDebrisRight=TrackDebrisDirtRight
1 parent caac64f commit b489322

3 files changed

Lines changed: 86 additions & 44 deletions

File tree

Core/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankTruckDraw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "WW3D2/rendobj.h"
3939
#include "WW3D2/part_emt.h"
4040

41+
//-------------------------------------------------------------------------------------------------
42+
// TheSuperHackers @fix xezon 01/02/2026 The Tread Effects are now usable in W3DTankTruckDraw.
4143
//-------------------------------------------------------------------------------------------------
4244
class W3DTankTruckDrawModuleData : public W3DModelDrawModuleData
4345
{
@@ -139,6 +141,9 @@ class W3DTankTruckDraw : public W3DModelDraw
139141

140142
RenderObjClass *m_prevRenderObj;
141143

144+
void createTreadEmitters( void ); ///< Create particle effects for treads.
145+
void tossTreadEmitters( void ); ///< Destroy particle effects for treads.
146+
142147
void createWheelEmitters( void ); ///< Create particle effects for wheels.
143148
void tossWheelEmitters( void ); ///< Destroy particle effects for wheels.
144149
void enableWheelEmitters( Bool enable ); ///< Start or stop creating effects from the wheels.

Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@
5151

5252
class Matrix3D;
5353

54+
// TheSuperHackers @info Is enabled by default and therefore compatible with the Retail INI setups.
55+
#define SHOW_DEFAULT_TANK_DEBRIS (1)
56+
5457
//-------------------------------------------------------------------------------------------------
55-
W3DTankDrawModuleData::W3DTankDrawModuleData() :
56-
m_treadDebrisNameLeft("TrackDebrisDirtLeft"),
57-
m_treadDebrisNameRight("TrackDebrisDirtRight"),
58-
m_treadAnimationRate(0.0f),
59-
m_treadPivotSpeedFraction(0.6f),
60-
m_treadDriveSpeedFraction(0.3f)
58+
W3DTankDrawModuleData::W3DTankDrawModuleData()
59+
: m_treadAnimationRate(0.0f)
60+
, m_treadPivotSpeedFraction(0.6f)
61+
, m_treadDriveSpeedFraction(0.3f)
6162
{
63+
if constexpr (SHOW_DEFAULT_TANK_DEBRIS)
64+
{
65+
m_treadDebrisNameLeft = "TrackDebrisDirtLeft"; // TheSuperHackers @todo Remove data particle names from code
66+
m_treadDebrisNameRight = "TrackDebrisDirtRight";
67+
}
6268
}
6369

6470
//-------------------------------------------------------------------------------------------------

Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,20 @@
4747
#include "W3DDevice/GameClient/Module/W3DTankTruckDraw.h"
4848
#include "WW3D2/matinfo.h"
4949

50-
//#define SHOW_TANK_DEBRIS
50+
// TheSuperHackers @info Is disabled by default and therefore compatible with the Retail INI setups.
51+
#define SHOW_DEFAULT_TANK_DEBRIS (0)
52+
5153
//-------------------------------------------------------------------------------------------------
52-
W3DTankTruckDrawModuleData::W3DTankTruckDrawModuleData():
53-
m_treadDebrisNameLeft("TrackDebrisDirtLeft"),
54-
m_treadDebrisNameRight("TrackDebrisDirtRight"),
55-
m_treadAnimationRate(0.0f),
56-
m_treadPivotSpeedFraction(0.6f),
57-
m_treadDriveSpeedFraction(0.3f)
54+
W3DTankTruckDrawModuleData::W3DTankTruckDrawModuleData()
55+
: m_treadAnimationRate(0.0f)
56+
, m_treadPivotSpeedFraction(0.6f)
57+
, m_treadDriveSpeedFraction(0.3f)
5858
{
59+
if constexpr (SHOW_DEFAULT_TANK_DEBRIS)
60+
{
61+
m_treadDebrisNameLeft = "TrackDebrisDirtLeft"; // TheSuperHackers @todo Remove data particle names from code
62+
m_treadDebrisNameRight = "TrackDebrisDirtRight";
63+
}
5964
}
6065

6166
//-------------------------------------------------------------------------------------------------
@@ -114,40 +119,15 @@ m_prevRenderObj(nullptr)
114119

115120
m_treadCount=0;
116121

117-
#ifdef SHOW_TANK_DEBRIS
118-
if (getW3DTankTruckDrawModuleData())
119-
{
120-
const AsciiString *treadDebrisNames[2];
121-
static_assert(ARRAY_SIZE(treadDebrisNames) == ARRAY_SIZE(m_treadDebrisIDs), "Array size must match");
122-
treadDebrisNames[0] = &getW3DTankTruckDrawModuleData()->m_treadDebrisNameLeft;
123-
treadDebrisNames[1] = &getW3DTankTruckDrawModuleData()->m_treadDebrisNameRight;
124-
125-
for (size_t i = 0; i < ARRAY_SIZE(m_treadDebrisIDs); ++i)
126-
{
127-
if (m_treadDebrisIDs[i] == INVALID_PARTICLE_SYSTEM_ID)
128-
{
129-
if (const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate(*treadDebrisNames[i]))
130-
{
131-
ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem( sysTemplate );
132-
particleSys->attachToDrawable(getDrawable());
133-
DEBUG_CRASH(("test me, may not work (srj)"));
134-
// important: mark it as do-not-save, since we'll just re-create it when we reload.
135-
particleSys->setSaveable(FALSE);
136-
// they come into being stopped.
137-
//particleSys->stop();
138-
m_treadDebrisIDs[i] = particleSys->getSystemID();
139-
}
140-
}
141-
}
142-
}
143-
#endif
122+
createTreadEmitters();
144123
}
145124

146125
//-------------------------------------------------------------------------------------------------
147126
//-------------------------------------------------------------------------------------------------
148127
W3DTankTruckDraw::~W3DTankTruckDraw()
149128
{
150129
tossWheelEmitters();
130+
tossTreadEmitters();
151131

152132
for (Int i=0; i<MAX_TREADS_PER_TANK; i++)
153133
if (m_treads[i].m_robj)
@@ -188,13 +168,63 @@ void W3DTankTruckDraw::setFullyObscuredByShroud(Bool fullyObscured)
188168
if (fullyObscured != getFullyObscuredByShroud())
189169
{
190170
if (fullyObscured)
171+
{
191172
tossWheelEmitters();
173+
stopMoveDebris();
174+
}
192175
else
176+
{
193177
createWheelEmitters();
178+
}
194179
}
195180
W3DModelDraw::setFullyObscuredByShroud(fullyObscured);
196181
}
197182

183+
//-------------------------------------------------------------------------------------------------
184+
//-------------------------------------------------------------------------------------------------
185+
void W3DTankTruckDraw::createTreadEmitters( void )
186+
{
187+
if (getW3DTankTruckDrawModuleData())
188+
{
189+
const AsciiString *treadDebrisNames[2];
190+
static_assert(ARRAY_SIZE(treadDebrisNames) == ARRAY_SIZE(m_treadDebrisIDs), "Array size must match");
191+
treadDebrisNames[0] = &getW3DTankTruckDrawModuleData()->m_treadDebrisNameLeft;
192+
treadDebrisNames[1] = &getW3DTankTruckDrawModuleData()->m_treadDebrisNameRight;
193+
194+
for (size_t i = 0; i < ARRAY_SIZE(m_treadDebrisIDs); ++i)
195+
{
196+
if (m_treadDebrisIDs[i] == INVALID_PARTICLE_SYSTEM_ID)
197+
{
198+
if (const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate(*treadDebrisNames[i]))
199+
{
200+
ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem( sysTemplate );
201+
particleSys->attachToDrawable(getDrawable());
202+
// important: mark it as do-not-save, since we'll just re-create it when we reload.
203+
particleSys->setSaveable(FALSE);
204+
// they come into being stopped.
205+
particleSys->stop();
206+
m_treadDebrisIDs[i] = particleSys->getSystemID();
207+
}
208+
}
209+
}
210+
}
211+
}
212+
213+
//-------------------------------------------------------------------------------------------------
214+
//-------------------------------------------------------------------------------------------------
215+
void W3DTankTruckDraw::tossTreadEmitters( void )
216+
{
217+
for (size_t i = 0; i < ARRAY_SIZE(m_treadDebrisIDs); ++i)
218+
{
219+
if (ParticleSystem *particleSys = TheParticleSystemManager->findParticleSystem(m_treadDebrisIDs[i]))
220+
{
221+
particleSys->attachToObject(nullptr);
222+
particleSys->destroy();
223+
}
224+
m_treadDebrisIDs[i] = INVALID_PARTICLE_SYSTEM_ID;
225+
}
226+
}
227+
198228
//-------------------------------------------------------------------------------------------------
199229
//-------------------------------------------------------------------------------------------------
200230
void W3DTankTruckDraw::createWheelEmitters( void )
@@ -341,9 +371,7 @@ void W3DTankTruckDraw::setHidden(Bool h)
341371
if (h)
342372
{
343373
enableWheelEmitters(false);
344-
#ifdef SHOW_TANK_DEBRIS
345374
stopMoveDebris();
346-
#endif
347375
}
348376
}
349377

@@ -619,7 +647,6 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)
619647
}
620648

621649
//Tank update
622-
#ifdef SHOW_TANK_DEBRIS
623650
const Real DEBRIS_THRESHOLD = 0.00001f;
624651

625652
// if tank is moving, kick up dust and debris
@@ -654,7 +681,7 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)
654681
particleSys->setBurstCountMultiplier( velMult.z );
655682
}
656683
}
657-
#endif
684+
658685
//Update movement of treads
659686
if (m_treadCount)
660687
{
@@ -734,4 +761,8 @@ void W3DTankTruckDraw::loadPostProcess( void )
734761
// toss any existing wheel emitters (no need to re-create; we'll do that on demand)
735762
tossWheelEmitters();
736763

764+
// toss any existing tread emitters and re-create 'em (since this module expects 'em to always be around)
765+
tossTreadEmitters();
766+
createTreadEmitters();
767+
737768
}

0 commit comments

Comments
 (0)