From bbc7388e6d9c73ce503742f265eea38d7f9868a9 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 12 Nov 2022 17:03:58 +1000 Subject: [PATCH] Introduce g_BeamsActive so we can avoid iterating props --- src/game/bondgun.c | 13 ++++++++----- src/game/chraction.c | 7 +++++-- src/game/gunfx.c | 12 ++++++++++++ src/game/gunfxreset.c | 2 ++ src/game/lv.c | 6 +++++- src/game/propobj.c | 17 ++--------------- src/include/bss.h | 1 + src/include/game/bondgun.h | 4 ++-- 8 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/game/bondgun.c b/src/game/bondgun.c index a32d24c64..68a317ad4 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -7508,18 +7508,21 @@ void bgunTickGameplay2(void) bgunIsUsingSecondaryFunction(); } -s8 bgunFreeFireslotWrapper(s32 slotnum) +void bgunFreeFireslotWrapper(s32 slotnum) { - return bgunFreeFireslot(slotnum); + bgunFreeFireslot(slotnum); } -s8 bgunFreeFireslot(s32 fireslot_id) +void bgunFreeFireslot(s32 fireslot_id) { if (fireslot_id >= 0 && fireslot_id < NUM_FIRESLOTS) { + if (g_Fireslots[fireslot_id].endlvframe >= 0 && g_Fireslots[fireslot_id].beam.age >= 0) { + g_Fireslots[fireslot_id].beam.age = -1; + g_BeamsActive--; + } + g_Fireslots[fireslot_id].endlvframe = -1; } - - return -1; } s32 bgunAllocateFireslot(void) diff --git a/src/game/chraction.c b/src/game/chraction.c index 08ea31ebf..d1fd81dc0 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -8572,8 +8572,11 @@ void chrStopFiring(struct chrdata *chr) chrResetAimEndProperties(chr); - chr->fireslots[0] = bgunFreeFireslot(chr->fireslots[0]); - chr->fireslots[1] = bgunFreeFireslot(chr->fireslots[1]); + bgunFreeFireslot(chr->fireslots[0]); + bgunFreeFireslot(chr->fireslots[1]); + + chr->fireslots[0] = -1; + chr->fireslots[1] = -1; } } diff --git a/src/game/gunfx.c b/src/game/gunfx.c index 8d8a6cf3a..961146b02 100644 --- a/src/game/gunfx.c +++ b/src/game/gunfx.c @@ -24,6 +24,8 @@ struct casing g_Casings[20]; struct boltbeam g_BoltBeams[8]; struct lasersight g_LaserSights[4]; +s32 g_BeamsActive; + void beamCreate(struct beam *beam, s32 weaponnum, struct coord *from, struct coord *to) { f32 distance; @@ -96,6 +98,8 @@ void beamCreate(struct beam *beam, s32 weaponnum, struct coord *from, struct coo if (beam->dist >= beam->maxdist) { beam->age = -1; + } else { + g_BeamsActive++; } } @@ -120,6 +124,12 @@ void beamCreateForHand(s32 handnum) } beam = &hand->beam; + + if (beam->age >= 0) { + beam->age = -1; + g_BeamsActive--; + } + beamCreate(beam, weaponnum, &hand->muzzlepos, &hand->hitpos); if (beam->weaponnum == WEAPON_MAULER) { @@ -611,6 +621,7 @@ void beamTick(struct beam *beam) if (beam->age > 1) { beam->age = -1; + g_BeamsActive--; } } else { if (g_Vars.lvupdate240 <= 8) { @@ -623,6 +634,7 @@ void beamTick(struct beam *beam) if (beam->dist >= beam->maxdist) { beam->age = -1; + g_BeamsActive--; } } } diff --git a/src/game/gunfxreset.c b/src/game/gunfxreset.c index ab0ae527b..1edd766b8 100644 --- a/src/game/gunfxreset.c +++ b/src/game/gunfxreset.c @@ -19,6 +19,8 @@ void boltbeamsReset(void) for (i = 0; i < 8; i++) { g_BoltBeams[i].unk00 = -1; } + + g_BeamsActive = 0; } void lasersightsReset(void) diff --git a/src/game/lv.c b/src/game/lv.c index ee8a535ca..ce577a28b 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -1288,7 +1288,11 @@ Gfx *lvRender(Gfx *gdl) PROFILE(PROFILEMARKER_LVR_PICKUP, propsTestForPickup()); PROFILE(PROFILEMARKER_LVR_BG, gdl = bgRender(gdl)); chr0f028498(false); - PROFILE(PROFILEMARKER_LVR_BEAMS, gdl = propsRenderBeams(gdl)); + + if (g_BeamsActive > 0) { + PROFILE(PROFILEMARKER_LVR_BEAMS, gdl = propsRenderBeams(gdl)); + } + PROFILE(PROFILEMARKER_LVR_SHARDS, gdl = shardsRender(gdl)); PROFILE(PROFILEMARKER_LVR_SPARKS, gdl = sparksRender(gdl)); PROFILE(PROFILEMARKER_LVR_WEATHER, gdl = weatherRender(gdl)); diff --git a/src/game/propobj.c b/src/game/propobj.c index e4b237c7c..e2a0794d6 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -18160,8 +18160,6 @@ void projectileCreate(struct prop *fromprop, struct fireslotthing *arg1, struct f32 sqdist; struct prop *obstacle = NULL; s16 sp1c8[8]; - u8 forcebeam = false; - struct beam beam; struct coord frompos; u32 stack2; u8 drug = false; @@ -18170,10 +18168,7 @@ void projectileCreate(struct prop *fromprop, struct fireslotthing *arg1, struct frompos = *pos; if (weaponnum == WEAPON_TRANQUILIZER) { - forcebeam = true; - beam.age = -1; drug = true; - frompos.y -= 40.0f; } if (arg1 && arg1->unk08 < g_Vars.lvframe60) { @@ -18367,16 +18362,8 @@ void projectileCreate(struct prop *fromprop, struct fireslotthing *arg1, struct } } - if (forcebeam || (arg1 && arg1->unk01)) { - struct beam *beamptr; - - if (forcebeam) { - beamptr = &beam; - } else { - beamptr = arg1->beam; - } - - beamCreate(beamptr, forcebeam ? WEAPON_FALCON2 : weaponnum, &frompos, &endpos); + if (arg1 && arg1->unk01) { + beamCreate(arg1->beam, weaponnum, &frompos, &endpos); } } } diff --git a/src/include/bss.h b/src/include/bss.h index f2e9b1ca4..cb9a1ad61 100644 --- a/src/include/bss.h +++ b/src/include/bss.h @@ -286,5 +286,6 @@ extern u8 g_AmBotCommands[16]; extern struct mpsetup g_MpSetup; extern struct bossfile g_BossFile; extern struct chrdata *g_MpBotChrPtrs[MAX_BOTS]; +extern s32 g_BeamsActive; #endif diff --git a/src/include/game/bondgun.h b/src/include/game/bondgun.h index 46c4c63f7..f07fdd1f0 100644 --- a/src/include/game/bondgun.h +++ b/src/include/game/bondgun.h @@ -182,7 +182,7 @@ void bgunSetSightVisible(u32 bits, bool visible); Gfx *bgunDrawSight(Gfx *gdl); void bgun0f0abd30(s32 handnum); s32 bgunGetWeaponNum2(s32 handnum); -s8 bgunFreeFireslotWrapper(s32 fireslot); -s8 bgunFreeFireslot(s32 fireslot); +void bgunFreeFireslotWrapper(s32 fireslot); +void bgunFreeFireslot(s32 fireslot); #endif