From b7cfb072459d2a1043ec394bd4fac88eecd68a67 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 25 Nov 2021 19:18:13 +0100 Subject: [PATCH] - all sectnums that can trivially be replaced. Most of the rest is in backend calling code and should be done while cleaning up the backend API. --- source/games/sw/src/misc.h | 2 +- source/games/sw/src/rotator.cpp | 1 - source/games/sw/src/sector.cpp | 2 +- source/games/sw/src/spike.cpp | 25 +++++++++++-------------- source/games/sw/src/sprite.cpp | 10 ++++------ source/games/sw/src/vator.cpp | 9 ++++----- source/games/sw/src/weapon.cpp | 2 +- 7 files changed, 22 insertions(+), 29 deletions(-) diff --git a/source/games/sw/src/misc.h b/source/games/sw/src/misc.h index 182e8d38a..d486e9b36 100644 --- a/source/games/sw/src/misc.h +++ b/source/games/sw/src/misc.h @@ -54,7 +54,7 @@ void PutStringInfo(PLAYERp pp, const char* string); void DoSlidorMatch(PLAYERp pp, short match, bool); bool TestSlidorMatchActive(short match); -void InterpSectorSprites(short sectnum, bool state); +void InterpSectorSprites(sectortype* sect, bool state); using INTERP_FUNC = void(*)(walltype*, int); diff --git a/source/games/sw/src/rotator.cpp b/source/games/sw/src/rotator.cpp index 4a7734b0b..c79fe2871 100644 --- a/source/games/sw/src/rotator.cpp +++ b/source/games/sw/src/rotator.cpp @@ -40,7 +40,6 @@ BEGIN_SW_NS void DoRotatorMatch(PLAYERp pp, short match, bool); bool TestRotatorMatchActive(short match); -void InterpSectorSprites(short sectnum, bool state); void DoMatchEverything(PLAYERp pp, short match, short state); void DoRotatorSetInterp(DSWActor*); void DoRotatorStopInterp(DSWActor*); diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 0edcd8a33..2a7e30eec 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -2373,7 +2373,7 @@ void PlayerOperateEnv(PLAYERp pp) { case TAG_VATOR: DoVatorOperate(pp, pp->cursector()); - DoSpikeOperate(pp->cursectnum); + DoSpikeOperate(pp->cursector()); DoRotatorOperate(pp, pp->cursector()); DoSlidorOperate(pp, pp->cursector()); break; diff --git a/source/games/sw/src/spike.cpp b/source/games/sw/src/spike.cpp index 0adddfcf3..fb32cb045 100644 --- a/source/games/sw/src/spike.cpp +++ b/source/games/sw/src/spike.cpp @@ -37,7 +37,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS bool TestSpikeMatchActive(short match); -void InterpSectorSprites(short sectnum, bool state); void ReverseSpike(DSWActor* actor) { @@ -102,7 +101,7 @@ void SetSpikeActive(DSWActor* actor) else StartInterpolation(sp->sector(), Interp_Sect_Floorheinum); - InterpSectorSprites(sp->sectnum, true); + InterpSectorSprites(sp->sector(), true); // play activate sound DoSoundSpotMatch(SP_TAG2(sp), 1, SOUND_OBJECT_TYPE); @@ -130,7 +129,7 @@ void SetSpikeInactive(DSWActor* actor) else StopInterpolation(sp->sector(), Interp_Sect_Floorheinum); - InterpSectorSprites(sp->sectnum, false); + InterpSectorSprites(sp->sector(), false); // play activate sound DoSoundSpotMatch(SP_TAG2(sp), 2, SOUND_OBJECT_TYPE); @@ -139,20 +138,18 @@ void SetSpikeInactive(DSWActor* actor) } // called for operation from the space bar -void DoSpikeOperate(short sectnum) +void DoSpikeOperate(sectortype* sect) { SPRITEp fsp; short match; - SWSectIterator it(sectnum); + SWSectIterator it(sect); while (auto actor = it.Next()) { fsp = &actor->s(); if (fsp->statnum == STAT_SPIKE && SP_TAG1(fsp) == SECT_SPIKE && SP_TAG3(fsp) == 0) { - sectnum = fsp->sectnum; - match = SP_TAG2(fsp); if (match > 0) { @@ -267,9 +264,9 @@ void SpikeAlign(DSWActor* actor) if ((int8_t)SP_TAG7(sp) < 0) { if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP)) - alignceilslope(sp->sectnum, sp->x, sp->y, u->zclip); + alignceilslope(sp->sector(), sp->x, sp->y, u->zclip); else - alignflorslope(sp->sectnum, sp->x, sp->y, u->zclip); + alignflorslope(sp->sector(), sp->x, sp->y, u->zclip); } else { @@ -280,12 +277,12 @@ void SpikeAlign(DSWActor* actor) } } -void MoveSpritesWithSpike(short sectnum) +void MoveSpritesWithSpike(sectortype* sect) { SPRITEp sp; int cz,fz; - SWSectIterator it(sectnum); + SWSectIterator it(sect); while (auto actor = it.Next()) { sp = &actor->s(); @@ -296,7 +293,7 @@ void MoveSpritesWithSpike(short sectnum) if (TEST(sp->extra, SPRX_STAY_PUT_VATOR)) continue; - getzsofslope(sectnum, sp->x, sp->y, &cz, &fz); + getzsofslopeptr(sect, sp->x, sp->y, &cz, &fz); sp->z = fz; } } @@ -315,7 +312,7 @@ int DoSpike(DSWActor* actor) lptr = &u->zclip; DoSpikeMove(actor, lptr); - MoveSpritesWithSpike(sp->sectnum); + MoveSpritesWithSpike(sp->sector()); SpikeAlign(actor); // EQUAL this entry has finished @@ -427,7 +424,7 @@ int DoSpikeAuto(DSWActor* actor) lptr = &u->zclip; DoSpikeMove(actor, lptr); - MoveSpritesWithSpike(sp->sectnum); + MoveSpritesWithSpike(sp->sector()); SpikeAlign(actor); // EQUAL this entry has finished diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index c3be00231..656189247 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -780,12 +780,10 @@ void KillActor(DSWActor* actor) soundEngine->RelinkSound(SOURCE_Actor, &actor->s(), nullptr, &pos); deletesprite(actor->GetSpriteIndex()); - // shred your garbage - but not statnum - statnum = sp->statnum; - sectnum = sp->sectnum; - memset(sp, 0xCC, sizeof(SPRITE)); - sp->statnum = statnum; - sp->sectnum = sectnum; + // shred your garbage - but not statnum and sectnum, which the backend needs to manage the sprite. + sp->clear(); + sp->statnum = MAXSTATUS; + sp->sectnum = MAXSECTORS; // Kill references in all users - slow but unavoidable if we don't want the game to crash on stale pointers. SWSpriteIterator it; diff --git a/source/games/sw/src/vator.cpp b/source/games/sw/src/vator.cpp index 27c1db684..0c89aed1d 100644 --- a/source/games/sw/src/vator.cpp +++ b/source/games/sw/src/vator.cpp @@ -42,7 +42,6 @@ BEGIN_SW_NS void DoVatorMatch(PLAYERp pp, short match); bool TestVatorMatchActive(short match); -void InterpSectorSprites(short sectnum, bool state); void ReverseVator(DSWActor* actor) { @@ -107,7 +106,7 @@ void SetVatorActive(DSWActor* actor) else StartInterpolation(sp->sector(), Interp_Sect_Floorz); - InterpSectorSprites(sp->sectnum, true); + InterpSectorSprites(sp->sector(), true); // play activate sound DoSoundSpotMatch(SP_TAG2(sp), 1, SOUND_OBJECT_TYPE); @@ -135,7 +134,7 @@ void SetVatorInactive(DSWActor* actor) else StopInterpolation(sp->sector(), Interp_Sect_Floorz); - InterpSectorSprites(sp->sectnum, false); + InterpSectorSprites(sp->sector(), false); // play inactivate sound DoSoundSpotMatch(SP_TAG2(sp), 2, SOUND_OBJECT_TYPE); @@ -269,11 +268,11 @@ bool TestVatorMatchActive(short match) return false; } -void InterpSectorSprites(short sectnum, bool state) +void InterpSectorSprites(sectortype* sect, bool state) { SPRITEp sp; - SWSectIterator it(sectnum); + SWSectIterator it(sect); while (auto actor = it.Next()) { sp = &actor->s(); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index f9889d665..e2eb40bd1 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -3173,7 +3173,7 @@ int SpawnShrap(DSWActor* parentActor, DSWActor* secondaryActor, int means, BREAK return 0; // Don't spawn shrapnel in invalid sectors gosh dern it! - if (!validSectorIndex(parent->sectnum)) + if (!parent->insector()) { return 0; }