Skip to content

Commit

Permalink
Enforce magic check before using any particle group
Browse files Browse the repository at this point in the history
Particle group IDs now pack the index + a magic number into one int32_t.

This fixes fire particles not appearing when lv5 beehive is burning at high framerates (>100 fps).

May fix other particle effects with timed emitters if the game merely checked that the group wasn't -1 without looking at the magic number.
  • Loading branch information
jorio committed Nov 8, 2023
1 parent 4e6128d commit 775a46a
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 239 deletions.
1 change: 0 additions & 1 deletion src/Enemies/Enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ short i;
gNumEnemyOfKind[i] = 0;

gCurrentGasParticleGroup = -1;
gCurrentGasParticleMagicNum = 0;
}


Expand Down
5 changes: 2 additions & 3 deletions src/Enemies/Enemy_Bee_Flying.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ Boolean KillFlyingBee(ObjNode *theNode, float dx, float dy, float dz)
(void) dy;
(void) dz;

long pg,i;
TQ3Vector3D delta;


Expand All @@ -544,7 +543,7 @@ TQ3Vector3D delta;

/* white sparks */

pg = NewParticleGroup( 0, // magic num
int32_t pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE, // flags
400, // gravity
Expand All @@ -554,7 +553,7 @@ TQ3Vector3D delta;
0, // fade rate
PARTICLE_TEXTURE_YELLOWBALL); // texture

for (i = 0; i < 60; i++)
for (int i = 0; i < 60; i++)
{
delta.x = (RandomFloat()-.5f) * 1400.0f;
delta.y = (RandomFloat()-.5f) * 1400.0f;
Expand Down
43 changes: 10 additions & 33 deletions src/Enemies/Enemy_FireAnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ enum
#define BreathRegulator SpecialF[3] // timer for fire spewing regulation

#define ButtTimer SpecialF[0] // timer for on butt
#define FireParticleMagicNum SpecialL[2]
#define FireTimer SpecialF[1]


Expand Down Expand Up @@ -609,7 +608,7 @@ Boolean isVisible;

Boolean BallHitFireAnt(ObjNode *me, ObjNode *enemy)
{
long pg,i;
int32_t pg;
TQ3Vector3D delta;
Boolean killed = false;

Expand All @@ -623,7 +622,7 @@ Boolean killed = false;

/* white sparks */

pg = NewParticleGroup( 0, // magic num
pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE|PARTICLE_FLAGS_HOT, // flags
500, // gravity
Expand All @@ -635,7 +634,7 @@ Boolean killed = false;

if (pg != -1)
{
for (i = 0; i < 50; i++)
for (int i = 0; i < 50; i++)
{
delta.x = (RandomFloat()-.5f) * 1000.0f;
delta.y = (RandomFloat()-.5f) * 1000.0f;
Expand All @@ -646,7 +645,7 @@ Boolean killed = false;

/* fire sparks */

pg = NewParticleGroup( 0, // magic num
pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE|PARTICLE_FLAGS_HOT, // flags
500, // gravity
Expand All @@ -658,7 +657,7 @@ Boolean killed = false;

if (pg != -1)
{
for (i = 0; i < 50; i++)
for (int i = 0; i < 50; i++)
{
delta.x = (RandomFloat()-.5f) * 500.0f;
delta.y = (RandomFloat()-.4f) * 500.0f;
Expand Down Expand Up @@ -765,11 +764,9 @@ static void UpdateFireAnt(ObjNode *theNode, Boolean updateFlame)
{
if (!(theNode->StatusBits & STATUS_BIT_ISCULLED)) // only update fire if is not culled
{
if ((theNode->ParticleGroup == -1) || (!VerifyParticleGroupMagicNum(theNode->ParticleGroup, theNode->FireParticleMagicNum)))
if (!VerifyParticleGroup(theNode->ParticleGroup))
{
theNode->FireParticleMagicNum = MyRandomLong(); // generate a random magic num

theNode->ParticleGroup = NewParticleGroup( theNode->FireParticleMagicNum, // magic num
theNode->ParticleGroup = NewParticleGroup(
PARTICLE_TYPE_GRAVITOIDS, // type
PARTICLE_FLAGS_HOT, // flags
0, // gravity
Expand All @@ -778,7 +775,6 @@ static void UpdateFireAnt(ObjNode *theNode, Boolean updateFlame)
1.0, // decay rate
0, // fade rate
PARTICLE_TEXTURE_FIRE); // texture

}

if (theNode->ParticleGroup != -1)
Expand Down Expand Up @@ -861,10 +857,10 @@ long i;

/* MAKE GROUP */

if (theNode->BreathParticleGroup == -1)
if (!VerifyParticleGroup(theNode->BreathParticleGroup))
{
new_pgroup:
theNode->BreathParticleGroup = NewParticleGroup(0, // magic num
new_pgroup:
theNode->BreathParticleGroup = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE|PARTICLE_FLAGS_HURTPLAYER|PARTICLE_FLAGS_HOT, // flags
400, // gravity
Expand Down Expand Up @@ -902,22 +898,3 @@ long i;
}
}
}



















32 changes: 13 additions & 19 deletions src/Enemies/Enemy_KingAnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ static float gStaffCharge;
#define ButtTimer SpecialF[1]
#define DeathTimer SpecialF[1]
#define FireTimer SpecialF[2]
#define FireParticleMagicNum SpecialL[3]

#define SparkTimer SpecialF[0]

Expand Down Expand Up @@ -513,11 +512,9 @@ static void UpdateKingAnt(ObjNode *theNode)
theNode->FireTimer += gFramesPerSecondFrac;
if (theNode->FireTimer > .01f)
{
if ((theNode->ParticleGroup == -1) || (!VerifyParticleGroupMagicNum(theNode->ParticleGroup, theNode->FireParticleMagicNum)))
if (!VerifyParticleGroup(theNode->ParticleGroup))
{
theNode->FireParticleMagicNum = MyRandomLong(); // generate a random magic num

theNode->ParticleGroup = NewParticleGroup( theNode->FireParticleMagicNum, // magic num
theNode->ParticleGroup = NewParticleGroup(
PARTICLE_TYPE_GRAVITOIDS, // type
PARTICLE_FLAGS_ROOF|PARTICLE_FLAGS_HOT, // flags
0, // gravity
Expand Down Expand Up @@ -654,11 +651,10 @@ float fps = gFramesPerSecondFrac;
theNode->FireTimer += fps;
if (theNode->FireTimer > .02f)
{
if ((theNode->ParticleGroup == -1) || (!VerifyParticleGroupMagicNum(theNode->ParticleGroup, theNode->FireParticleMagicNum)))
if (!VerifyParticleGroup(theNode->ParticleGroup))
{
new_group:
theNode->FireParticleMagicNum = MyRandomLong(); // generate a random magic num
theNode->ParticleGroup = NewParticleGroup(theNode->FireParticleMagicNum, // magic num
new_group:
theNode->ParticleGroup = NewParticleGroup(
PARTICLE_TYPE_GRAVITOIDS, // type
PARTICLE_FLAGS_ROOF|PARTICLE_FLAGS_HOT, // flags
0, // gravity
Expand All @@ -667,7 +663,6 @@ float fps = gFramesPerSecondFrac;
.6, // decay rate
0, // fade rate
PARTICLE_TEXTURE_BLUEFIRE); // texture

}

if (theNode->ParticleGroup != -1)
Expand Down Expand Up @@ -804,10 +799,10 @@ float fps = gFramesPerSecondFrac;
/*********************/

/* SEE IF MAKE NEW GROUP */
if (theNode->PGroupA == -1)

if (!VerifyParticleGroup(theNode->PGroupA))
{
theNode->PGroupA = NewParticleGroup(0, // magic num
theNode->PGroupA = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS,// type
PARTICLE_FLAGS_HOT, // flags
0, // gravity
Expand Down Expand Up @@ -837,7 +832,7 @@ float fps = gFramesPerSecondFrac;

if (theNode->PGroupB == -1)
{
theNode->PGroupB = NewParticleGroup(0, // magic num
theNode->PGroupB = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS,// type
PARTICLE_FLAGS_HOT, // flags
900, // gravity
Expand Down Expand Up @@ -870,16 +865,15 @@ float fps = gFramesPerSecondFrac;

static void ExplodeStaffBullet(ObjNode *theNode)
{
long pg,i;
TQ3Vector3D delta;

/*******************/
/* SPARK EXPLOSION */
/*******************/

/* white sparks */
pg = NewParticleGroup( 0, // magic num

int32_t pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE|PARTICLE_FLAGS_HURTPLAYER|PARTICLE_FLAGS_ROOF|PARTICLE_FLAGS_HOT, // flags
400, // gravity
Expand All @@ -888,8 +882,8 @@ TQ3Vector3D delta;
0, // decay rate
.7, // fade rate
PARTICLE_TEXTURE_BLUEFIRE); // texture
for (i = 0; i < 60; i++)

for (int i = 0; i < 60; i++)
{
delta.x = (RandomFloat()-.5f) * 1400.0f;
delta.y = (RandomFloat()-.5f) * 1400.0f;
Expand Down
29 changes: 15 additions & 14 deletions src/Enemies/Enemy_QueenBee.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ Boolean killed = false;

Boolean KnockQueenBeeOnButt(ObjNode *enemy, float dx, float dz, float damage)
{
long pg,i;
TQ3Vector3D delta;

if (enemy->Skeleton->AnimNum == QUEENBEE_ANIM_ONBUTT) // see if already in butt mode
Expand Down Expand Up @@ -552,7 +551,7 @@ TQ3Vector3D delta;

/* white sparks */

pg = NewParticleGroup( 0, // magic num
int32_t pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE, // flags
500, // gravity
Expand All @@ -561,15 +560,15 @@ TQ3Vector3D delta;
.9, // decay rate
0, // fade rate
PARTICLE_TEXTURE_YELLOWBALL); // texture
for (i = 0; i < 35; i++)

for (int i = 0; i < 35; i++)
{
delta.x = (RandomFloat()-.5f) * 1000.0f;
delta.y = (RandomFloat()-.5f) * 1000.0f;
delta.z = (RandomFloat()-.5f) * 1000.0f;
AddParticleToGroup(pg, &enemy->Coord, &delta, RandomFloat() + 1.0f, FULL_ALPHA);
}



/* HURT & SEE IF KILLED */
Expand All @@ -592,7 +591,6 @@ TQ3Vector3D delta;

Boolean KillQueenBee(ObjNode *theNode)
{
long pg,i;
TQ3Vector3D delta;

/* STOP BUZZ */
Expand All @@ -614,7 +612,7 @@ TQ3Vector3D delta;

/* white sparks */

pg = NewParticleGroup( 0, // magic num
int32_t pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_BOUNCE, // flags
400, // gravity
Expand All @@ -623,15 +621,18 @@ TQ3Vector3D delta;
.8, // decay rate
0, // fade rate
PARTICLE_TEXTURE_YELLOWBALL); // texture
for (i = 0; i < 60; i++)

if (pg != -1)
{
delta.x = (RandomFloat()-.5f) * 1400.0f;
delta.y = (RandomFloat()-.5f) * 1400.0f;
delta.z = (RandomFloat()-.5f) * 1400.0f;
AddParticleToGroup(pg, &theNode->Coord, &delta, RandomFloat() + 1.0f, FULL_ALPHA);
for (int i = 0; i < 60; i++)
{
delta.x = (RandomFloat()-.5f) * 1400.0f;
delta.y = (RandomFloat()-.5f) * 1400.0f;
delta.z = (RandomFloat()-.5f) * 1400.0f;
AddParticleToGroup(pg, &theNode->Coord, &delta, RandomFloat() + 1.0f, FULL_ALPHA);
}
}

theNode->DeathTimer = 4;

return(false);
Expand Down
28 changes: 7 additions & 21 deletions src/Enemies/Enemy_Roach.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ enum
#define RotDeltaY SpecialF[2]
#define ButtTimer SpecialF[3]

short gCurrentGasParticleGroup = -1;
u_long gCurrentGasParticleMagicNum = 0;
int32_t gCurrentGasParticleGroup = -1;


/************************ ADD ROACH ENEMY *************************/
Expand Down Expand Up @@ -654,16 +653,14 @@ float fps = gFramesPerSecondFrac;

static void ExplodeGas(ObjNode *theNode)
{
long pg,i;
int32_t pg;
TQ3Vector3D delta;

/* SEE IF NEED TO CREATE NEW PARTICLE GROUP */

if ((gCurrentGasParticleGroup == -1) || (!VerifyParticleGroupMagicNum(gCurrentGasParticleGroup, gCurrentGasParticleMagicNum)))
{
gCurrentGasParticleMagicNum = MyRandomLong(); // generate a random magic num

pg = NewParticleGroup( gCurrentGasParticleMagicNum, // magic num
if (!VerifyParticleGroup(gCurrentGasParticleGroup))
{
pg = NewParticleGroup(
PARTICLE_TYPE_FALLINGSPARKS, // type
PARTICLE_FLAGS_HURTPLAYER|PARTICLE_FLAGS_HOT|PARTICLE_FLAGS_HURTENEMY, // flags
500, // gravity
Expand All @@ -682,7 +679,7 @@ TQ3Vector3D delta;

if (pg != -1)
{
for (i = 0; i < 25; i++)
for (int i = 0; i < 25; i++)
{
delta.x = (RandomFloat()-.5f) * 800.0f;
delta.y = RandomFloat() * 600.0f;
Expand All @@ -693,20 +690,9 @@ TQ3Vector3D delta;
break;
}
}
}
}

PlayEffect_Parms3D(EFFECT_FIRECRACKER, &theNode->Coord, kMiddleC-10, .9);

DeleteObject(theNode);

}










Loading

0 comments on commit 775a46a

Please sign in to comment.