Skip to content

Commit f832a5d

Browse files
committed
unify(particlesys): Compile out superfluous X and Y particle angles in Generals (TheSuperHackers#2153)
1 parent 3cfe550 commit f832a5d

9 files changed

Lines changed: 309 additions & 8 deletions

File tree

Generals/Code/GameEngine/Include/GameClient/ParticleSys.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ enum ParticleSystemID CPP_11(: Int)
6161
#define DEFAULT_VOLUME_PARTICLE_DEPTH ( 0 )//The Default is not to do the volume thing!
6262
#define OPTIMUM_VOLUME_PARTICLE_DEPTH ( 6 )
6363

64+
// TheSuperHackers @info The X and Y angles are not necessary for particles because there are only 2 placement modes:
65+
// Billboard (always facing camera) and Ground Aligned, which overwrite any rotations on the X and Y axis by design.
66+
// Therefore particles can only be rotated on the Z axis. Zero Hour never had X and Y angles, but Generals did.
67+
#define PARTICLE_USE_XY_ROTATION (0)
6468

6569
//--------------------------------------------------------------------------------------------------------------
6670

@@ -122,11 +126,15 @@ class ParticleInfo : public Snapshot
122126
Coord3D m_emitterPos; ///< position of the emitter
123127
Real m_velDamping; ///< velocity damping coefficient
124128

129+
#if PARTICLE_USE_XY_ROTATION
125130
Real m_angleX; ///< initial angle around X axis
126131
Real m_angleY; ///< initial angle around Y axis
132+
#endif
127133
Real m_angleZ; ///< initial angle around Z axis
134+
#if PARTICLE_USE_XY_ROTATION
128135
Real m_angularRateX; ///< initial angle around X axis
129136
Real m_angularRateY; ///< initial angle around Y axis
137+
#endif
130138
Real m_angularRateZ; ///< initial angle around Z axis
131139
Real m_angularDamping; ///< angular velocity damping coefficient
132140

@@ -278,11 +286,15 @@ class ParticleSystemInfo : public Snapshot
278286

279287
AsciiString m_particleTypeName; ///< if PARTICLE, texture filename, if DRAWABLE, Drawable name
280288

289+
#if PARTICLE_USE_XY_ROTATION
281290
GameClientRandomVariable m_angleX; ///< initial angle around X axis
282291
GameClientRandomVariable m_angleY; ///< initial angle around Y axis
292+
#endif
283293
GameClientRandomVariable m_angleZ; ///< initial angle around Z axis
294+
#if PARTICLE_USE_XY_ROTATION
284295
GameClientRandomVariable m_angularRateX; ///< initial angle around X axis
285296
GameClientRandomVariable m_angularRateY; ///< initial angle around Y axis
297+
#endif
286298
GameClientRandomVariable m_angularRateZ; ///< initial angle around Z axis
287299
GameClientRandomVariable m_angularDamping; ///< angular velocity damping coefficient
288300

Generals/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ ParticleSystemManager *TheParticleSystemManager = nullptr;
6868
// ------------------------------------------------------------------------------------------------
6969
ParticleInfo::ParticleInfo( void )
7070
{
71-
m_angleX = m_angleY = m_angleZ = 0.0f;
71+
#if PARTICLE_USE_XY_ROTATION
72+
m_angleX = 0.0f;
73+
m_angleY = 0.0f;
74+
#endif
75+
m_angleZ = 0.0f;
76+
#if PARTICLE_USE_XY_ROTATION
77+
m_angularRateX = 0.0f;
78+
m_angularRateY = 0.0f;
79+
#endif
80+
m_angularRateZ = 0.0f;
7281
m_angularDamping = 0.0f;
73-
m_angularRateX = m_angularRateY = m_angularRateZ = 0.0f;
7482
m_colorScale =0.0f;
7583
m_size = 0.0f;
7684
m_sizeRate = 0.0f;
@@ -122,13 +130,24 @@ void ParticleInfo::xfer( Xfer *xfer )
122130
xfer->xferReal( &m_velDamping );
123131

124132
// angle
133+
#if PARTICLE_USE_XY_ROTATION
125134
xfer->xferReal( &m_angleX );
126135
xfer->xferReal( &m_angleY );
136+
#else
137+
Real tempAngle=0; //temporary value to save out for backwards compatibility when we supported x,y
138+
xfer->xferReal( &tempAngle );
139+
xfer->xferReal( &tempAngle );
140+
#endif
127141
xfer->xferReal( &m_angleZ );
128142

129143
// angular rate
144+
#if PARTICLE_USE_XY_ROTATION
130145
xfer->xferReal( &m_angularRateX );
131146
xfer->xferReal( &m_angularRateY );
147+
#else
148+
xfer->xferReal( &tempAngle );
149+
xfer->xferReal( &tempAngle );
150+
#endif
132151
xfer->xferReal( &m_angularRateZ );
133152

134153
// lifetime
@@ -281,18 +300,21 @@ Particle::Particle( ParticleSystem *system, const ParticleInfo *info )
281300
m_vel = info->m_vel;
282301
m_pos = info->m_pos;
283302

303+
#if PARTICLE_USE_XY_ROTATION
284304
m_angleX = info->m_angleX;
285305
m_angleY = info->m_angleY;
306+
#endif
286307
m_angleZ = info->m_angleZ;
287308

288309
m_lastPos.zero();
289310
m_windRandomness = info->m_windRandomness;
290311
m_particleUpTowardsEmitter = info->m_particleUpTowardsEmitter;
291312
m_emitterPos = info->m_emitterPos;
292313

293-
314+
#if PARTICLE_USE_XY_ROTATION
294315
m_angularRateX = info->m_angularRateX;
295316
m_angularRateY = info->m_angularRateY;
317+
#endif
296318
m_angularRateZ = info->m_angularRateZ;
297319
m_angularDamping = info->m_angularDamping;
298320

@@ -394,11 +416,15 @@ Bool Particle::update( void )
394416
doWindMotion();
395417

396418
// update orientation
419+
#if PARTICLE_USE_XY_ROTATION
397420
m_angleX += m_angularRateX;
398421
m_angleY += m_angularRateY;
422+
#endif
399423
m_angleZ += m_angularRateZ;
424+
#if PARTICLE_USE_XY_ROTATION
400425
m_angularRateX *= m_angularDamping;
401426
m_angularRateY *= m_angularDamping;
427+
#endif
402428
m_angularRateZ *= m_angularDamping;
403429

404430
if (m_particleUpTowardsEmitter) {
@@ -841,13 +867,24 @@ void ParticleSystemInfo::xfer( Xfer *xfer )
841867
xfer->xferAsciiString( &m_particleTypeName );
842868

843869
// angles
870+
#if PARTICLE_USE_XY_ROTATION
844871
xfer->xferUser( &m_angleX, sizeof( GameClientRandomVariable ) );
845872
xfer->xferUser( &m_angleY, sizeof( GameClientRandomVariable ) );
873+
#else
874+
GameClientRandomVariable tempRandom; //for backwards compatibility when we supported x,y
875+
xfer->xferUser( &tempRandom, sizeof( GameClientRandomVariable ) );
876+
xfer->xferUser( &tempRandom, sizeof( GameClientRandomVariable ) );
877+
#endif
846878
xfer->xferUser( &m_angleZ, sizeof( GameClientRandomVariable ) );
847879

848880
// angular rate
881+
#if PARTICLE_USE_XY_ROTATION
849882
xfer->xferUser( &m_angularRateX, sizeof( GameClientRandomVariable ) );
850883
xfer->xferUser( &m_angularRateY, sizeof( GameClientRandomVariable ) );
884+
#else
885+
xfer->xferUser( &tempRandom, sizeof( GameClientRandomVariable ) );
886+
xfer->xferUser( &tempRandom, sizeof( GameClientRandomVariable ) );
887+
#endif
851888
xfer->xferUser( &m_angularRateZ, sizeof( GameClientRandomVariable ) );
852889

853890
// angular damping
@@ -1145,11 +1182,15 @@ ParticleSystem::ParticleSystem( const ParticleSystemTemplate *sysTemplate,
11451182

11461183
m_velDamping = sysTemplate->m_velDamping;
11471184

1185+
#if PARTICLE_USE_XY_ROTATION
11481186
m_angleX = sysTemplate->m_angleX;
11491187
m_angleY = sysTemplate->m_angleY;
1188+
#endif
11501189
m_angleZ = sysTemplate->m_angleZ;
1190+
#if PARTICLE_USE_XY_ROTATION
11511191
m_angularRateX = sysTemplate->m_angularRateX;
11521192
m_angularRateY = sysTemplate->m_angularRateY;
1193+
#endif
11531194
m_angularRateZ = sysTemplate->m_angularRateZ;
11541195
m_angularDamping = sysTemplate->m_angularDamping;
11551196

@@ -1829,11 +1870,15 @@ const ParticleInfo *ParticleSystem::generateParticleInfo( Int particleNum, Int p
18291870
info.m_velDamping = m_velDamping.getValue();
18301871
info.m_angularDamping = m_angularDamping.getValue();
18311872

1873+
#if PARTICLE_USE_XY_ROTATION
18321874
info.m_angleX = m_angleX.getValue();
18331875
info.m_angleY = m_angleY.getValue();
1876+
#endif
18341877
info.m_angleZ = m_angleZ.getValue();
1878+
#if PARTICLE_USE_XY_ROTATION
18351879
info.m_angularRateX = m_angularRateX.getValue();
18361880
info.m_angularRateY = m_angularRateY.getValue();
1881+
#endif
18371882
info.m_angularRateZ = m_angularRateZ.getValue();
18381883

18391884
info.m_lifetime = (UnsignedInt)m_lifetime.getValue();
@@ -2352,11 +2397,15 @@ ParticleInfo ParticleSystem::mergeRelatedParticleSystems( ParticleSystem *master
23522397
mergeInfo.m_sizeRate *= info->m_sizeRate;
23532398
mergeInfo.m_sizeRateDamping *= info->m_sizeRateDamping;
23542399

2400+
#if PARTICLE_USE_XY_ROTATION
23552401
mergeInfo.m_angleX = info->m_angleX;
23562402
mergeInfo.m_angleY = info->m_angleY;
2403+
#endif
23572404
mergeInfo.m_angleZ = info->m_angleZ;
2405+
#if PARTICLE_USE_XY_ROTATION
23582406
mergeInfo.m_angularRateX = info->m_angularRateX;
23592407
mergeInfo.m_angularRateY = info->m_angularRateY;
2408+
#endif
23602409
mergeInfo.m_angularRateZ = info->m_angularRateZ;
23612410
mergeInfo.m_angularDamping = info->m_angularDamping;
23622411

@@ -2647,11 +2696,15 @@ const FieldParse ParticleSystemTemplate::m_fieldParseTable[] =
26472696
{ "Shader", INI::parseIndexList, ParticleShaderTypeNames, offsetof( ParticleSystemTemplate, m_shaderType ) },
26482697
{ "Type", INI::parseIndexList, ParticleTypeNames, offsetof( ParticleSystemTemplate, m_particleType ) },
26492698
{ "ParticleName", INI::parseAsciiString, nullptr, offsetof( ParticleSystemTemplate, m_particleTypeName ) },
2699+
#if PARTICLE_USE_XY_ROTATION
26502700
{ "AngleX", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angleX ) },
26512701
{ "AngleY", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angleY ) },
2702+
#endif
26522703
{ "AngleZ", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angleZ ) },
2704+
#if PARTICLE_USE_XY_ROTATION
26532705
{ "AngularRateX", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angularRateX ) },
26542706
{ "AngularRateY", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angularRateY ) },
2707+
#endif
26552708
{ "AngularRateZ", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angularRateZ ) },
26562709
{ "AngularDamping", INI::parseGameClientRandomVariable, nullptr, offsetof( ParticleSystemTemplate, m_angularDamping ) },
26572710

Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9111,25 +9111,29 @@ void _writeSingleParticleSystem( File *out, ParticleSystemTemplate *templ )
91119111
thisEntry.append(SEP_HEAD).append(F_TYPE).append(EQ_WITH_SPACES).append(ParticleTypeNames[templ->m_particleType]).append(SEP_EOL);
91129112
thisEntry.append(SEP_HEAD).append(F_PARTICLENAME).append(EQ_WITH_SPACES).append(templ->m_particleTypeName.str()).append(SEP_EOL);
91139113

9114+
#if PARTICLE_USE_XY_ROTATION
91149115
sprintf(buff1, FORMAT_STRING, templ->m_angleX.getMinimumValue());
91159116
sprintf(buff2, FORMAT_STRING, templ->m_angleX.getMaximumValue());
91169117
thisEntry.append(SEP_HEAD).append(F_ANGLEX).append(EQ_WITH_SPACES).append(buff1).append(SEP_SPACE).append(buff2).append(SEP_EOL);
91179118

91189119
sprintf(buff1, FORMAT_STRING, templ->m_angleY.getMinimumValue());
91199120
sprintf(buff2, FORMAT_STRING, templ->m_angleY.getMaximumValue());
91209121
thisEntry.append(SEP_HEAD).append(F_ANGLEY).append(EQ_WITH_SPACES).append(buff1).append(SEP_SPACE).append(buff2).append(SEP_EOL);
9122+
#endif
91219123

91229124
sprintf(buff1, FORMAT_STRING, templ->m_angleZ.getMinimumValue());
91239125
sprintf(buff2, FORMAT_STRING, templ->m_angleZ.getMaximumValue());
91249126
thisEntry.append(SEP_HEAD).append(F_ANGLEZ).append(EQ_WITH_SPACES).append(buff1).append(SEP_SPACE).append(buff2).append(SEP_EOL);
91259127

9128+
#if PARTICLE_USE_XY_ROTATION
91269129
sprintf(buff1, FORMAT_STRING, templ->m_angularRateX.getMinimumValue());
91279130
sprintf(buff2, FORMAT_STRING, templ->m_angularRateX.getMaximumValue());
91289131
thisEntry.append(SEP_HEAD).append(F_ANGLERATEX).append(EQ_WITH_SPACES).append(buff1).append(SEP_SPACE).append(buff2).append(SEP_EOL);
91299132

91309133
sprintf(buff1, FORMAT_STRING, templ->m_angularRateY.getMinimumValue());
91319134
sprintf(buff2, FORMAT_STRING, templ->m_angularRateY.getMaximumValue());
91329135
thisEntry.append(SEP_HEAD).append(F_ANGLERATEY).append(EQ_WITH_SPACES).append(buff1).append(SEP_SPACE).append(buff2).append(SEP_EOL);
9136+
#endif
91339137

91349138
sprintf(buff1, FORMAT_STRING, templ->m_angularRateZ.getMinimumValue());
91359139
sprintf(buff2, FORMAT_STRING, templ->m_angularRateZ.getMaximumValue());

Generals/Code/Tools/ParticleEditor/ParticleEditorDialog.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,22 +1342,34 @@ void DebugWindowDialog::performUpdate( IN Bool toUI )
13421342
pWnd = GetDlgItem(IDC_PSEd_AngleXMin);
13431343
if (pWnd) {
13441344
if (toUI) {
1345+
#if PARTICLE_USE_XY_ROTATION
13451346
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angleX.getMinimumValue());
1347+
#else
1348+
sprintf(buff, FORMAT_STRING, 0.0f);
1349+
#endif
13461350
pWnd->SetWindowText(buff);
13471351
} else {
1352+
#if PARTICLE_USE_XY_ROTATION
13481353
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
13491354
m_particleSystem->m_angleX.m_low = atof(buff);
1355+
#endif
13501356
}
13511357
}
13521358

13531359
pWnd = GetDlgItem(IDC_PSEd_AngleYMin);
13541360
if (pWnd) {
13551361
if (toUI) {
1362+
#if PARTICLE_USE_XY_ROTATION
13561363
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angleY.getMinimumValue());
1364+
#else
1365+
sprintf(buff, FORMAT_STRING, 0.0f);
1366+
#endif
13571367
pWnd->SetWindowText(buff);
13581368
} else {
1369+
#if PARTICLE_USE_XY_ROTATION
13591370
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
13601371
m_particleSystem->m_angleY.m_low = atof(buff);
1372+
#endif
13611373
}
13621374
}
13631375

@@ -1375,22 +1387,34 @@ void DebugWindowDialog::performUpdate( IN Bool toUI )
13751387
pWnd = GetDlgItem(IDC_PSEd_AngleXMax);
13761388
if (pWnd) {
13771389
if (toUI) {
1390+
#if PARTICLE_USE_XY_ROTATION
13781391
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angleX.getMaximumValue());
1392+
#else
1393+
sprintf(buff, FORMAT_STRING, 0.0f);
1394+
#endif
13791395
pWnd->SetWindowText(buff);
13801396
} else {
1397+
#if PARTICLE_USE_XY_ROTATION
13811398
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
13821399
m_particleSystem->m_angleX.m_high = atof(buff);
1400+
#endif
13831401
}
13841402
}
13851403

13861404
pWnd = GetDlgItem(IDC_PSEd_AngleYMax);
13871405
if (pWnd) {
13881406
if (toUI) {
1407+
#if PARTICLE_USE_XY_ROTATION
13891408
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angleY.getMaximumValue());
1409+
#else
1410+
sprintf(buff, FORMAT_STRING, 0.0f);
1411+
#endif
13901412
pWnd->SetWindowText(buff);
13911413
} else {
1414+
#if PARTICLE_USE_XY_ROTATION
13921415
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
13931416
m_particleSystem->m_angleY.m_high = atof(buff);
1417+
#endif
13941418
}
13951419
}
13961420

@@ -1408,22 +1432,34 @@ void DebugWindowDialog::performUpdate( IN Bool toUI )
14081432
pWnd = GetDlgItem(IDC_PSEd_AngularRateXMin);
14091433
if (pWnd) {
14101434
if (toUI) {
1435+
#if PARTICLE_USE_XY_ROTATION
14111436
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angularRateX.getMinimumValue());
1437+
#else
1438+
sprintf(buff, FORMAT_STRING, 0.0f);
1439+
#endif
14121440
pWnd->SetWindowText(buff);
14131441
} else {
1442+
#if PARTICLE_USE_XY_ROTATION
14141443
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
14151444
m_particleSystem->m_angularRateX.m_low = atof(buff);
1445+
#endif
14161446
}
14171447
}
14181448

14191449
pWnd = GetDlgItem(IDC_PSEd_AngularRateYMin);
14201450
if (pWnd) {
14211451
if (toUI) {
1452+
#if PARTICLE_USE_XY_ROTATION
14221453
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angularRateY.getMinimumValue());
1454+
#else
1455+
sprintf(buff, FORMAT_STRING, 0.0f);
1456+
#endif
14231457
pWnd->SetWindowText(buff);
14241458
} else {
1459+
#if PARTICLE_USE_XY_ROTATION
14251460
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
14261461
m_particleSystem->m_angularRateY.m_low = atof(buff);
1462+
#endif
14271463
}
14281464
}
14291465

@@ -1441,22 +1477,34 @@ void DebugWindowDialog::performUpdate( IN Bool toUI )
14411477
pWnd = GetDlgItem(IDC_PSEd_AngularRateXMax);
14421478
if (pWnd) {
14431479
if (toUI) {
1480+
#if PARTICLE_USE_XY_ROTATION
14441481
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angularRateX.getMaximumValue());
1482+
#else
1483+
sprintf(buff, FORMAT_STRING, 0.0f);
1484+
#endif
14451485
pWnd->SetWindowText(buff);
14461486
} else {
1487+
#if PARTICLE_USE_XY_ROTATION
14471488
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
14481489
m_particleSystem->m_angularRateX.m_high = atof(buff);
1490+
#endif
14491491
}
14501492
}
14511493

14521494
pWnd = GetDlgItem(IDC_PSEd_AngularRateYMax);
14531495
if (pWnd) {
14541496
if (toUI) {
1497+
#if PARTICLE_USE_XY_ROTATION
14551498
sprintf(buff, FORMAT_STRING, m_particleSystem->m_angularRateY.getMaximumValue());
1499+
#else
1500+
sprintf(buff, FORMAT_STRING, 0.0f);
1501+
#endif
14561502
pWnd->SetWindowText(buff);
14571503
} else {
1504+
#if PARTICLE_USE_XY_ROTATION
14581505
pWnd->GetWindowText(buff, ARBITRARY_BUFF_SIZE - 1);
14591506
m_particleSystem->m_angularRateY.m_high = atof(buff);
1507+
#endif
14601508
}
14611509
}
14621510

0 commit comments

Comments
 (0)