From e6c625f6e8f5a57915b1f1a84e4dc92482653b7f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Nov 2021 22:44:31 +0100 Subject: [PATCH] - second part of slidor.cpp. --- source/games/sw/src/misc.h | 2 +- source/games/sw/src/slidor.cpp | 62 ++++++++++++++-------------------- source/games/sw/src/sprite.cpp | 4 +-- 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/source/games/sw/src/misc.h b/source/games/sw/src/misc.h index 59908d59d..5e0d2a91d 100644 --- a/source/games/sw/src/misc.h +++ b/source/games/sw/src/misc.h @@ -78,7 +78,7 @@ void InterpSectorSprites(short sectnum, bool state); using INTERP_FUNC = void(*)(int, int); void SetSlidorActive(DSWActor*); -void DoSlidorInterp(short, INTERP_FUNC); +void DoSlidorInterp(DSWActor*, INTERP_FUNC); int DoBeginJump(DSWActor* actor); int DoJump(DSWActor* actor); diff --git a/source/games/sw/src/slidor.cpp b/source/games/sw/src/slidor.cpp index 7d1fdbb97..949da82f1 100644 --- a/source/games/sw/src/slidor.cpp +++ b/source/games/sw/src/slidor.cpp @@ -96,7 +96,7 @@ void SetSlidorActive(DSWActor* actor) r = u->rotator.Data(); - DoSlidorInterp(actor->GetSpriteIndex(), StartInterpolation); + DoSlidorInterp(actor, StartInterpolation); // play activate sound DoSoundSpotMatch(SP_TAG2(sp), 1, SOUND_OBJECT_TYPE); @@ -111,12 +111,12 @@ void SetSlidorActive(DSWActor* actor) VatorSwitch(SP_TAG2(sp), ON); } -void SetSlidorInactive(short SpriteNum) +void SetSlidorInactive(DSWActor* actor) { - USERp u = User[SpriteNum].Data(); - SPRITEp sp = u->SpriteP; + USERp u = actor->u(); + SPRITEp sp = &actor->s(); - DoSlidorInterp(SpriteNum, StopInterpolation); + DoSlidorInterp(actor, StopInterpolation); // play inactivate sound DoSoundSpotMatch(SP_TAG2(sp), 2, SOUND_OBJECT_TYPE); @@ -224,12 +224,13 @@ bool TestSlidorMatchActive(short match) return false; } -void DoSlidorInterp(short SpriteNum, INTERP_FUNC interp_func) +void DoSlidorInterp(DSWActor* actor, INTERP_FUNC interp_func) { + auto sp = &actor->s(); short w, pw, startwall, endwall; - w = startwall = sector[sprite[SpriteNum].sectnum].wallptr; - endwall = startwall + sector[sprite[SpriteNum].sectnum].wallnum - 1; + w = startwall = sector[sp->sectnum].wallptr; + endwall = startwall + sector[sp->sectnum].wallnum - 1; do { @@ -349,12 +350,13 @@ void DoSlidorInterp(short SpriteNum, INTERP_FUNC interp_func) while (w != startwall); } -int DoSlidorMoveWalls(short SpriteNum, int amt) +int DoSlidorMoveWalls(DSWActor* actor, int amt) { + auto sp = &actor->s(); short w, pw, startwall, endwall; - w = startwall = sector[sprite[SpriteNum].sectnum].wallptr; - endwall = startwall + sector[sprite[SpriteNum].sectnum].wallnum - 1; + w = startwall = sector[sp->sectnum].wallptr; + endwall = startwall + sector[sp->sectnum].wallnum - 1; do { @@ -461,13 +463,13 @@ int DoSlidorMoveWalls(short SpriteNum, int amt) return 0; } -int DoSlidorInstantClose(short SpriteNum) +int DoSlidorInstantClose(DSWActor* actor) { - SPRITEp sp = &sprite[SpriteNum]; + SPRITEp sp = &actor->s(); short w, startwall; int diff; - w = startwall = sector[sprite[SpriteNum].sectnum].wallptr; + w = startwall = sector[sp->sectnum].wallptr; do { @@ -475,22 +477,22 @@ int DoSlidorInstantClose(short SpriteNum) { case TAG_WALL_SLIDOR_LEFT: diff = wall[w].x - sp->x; - DoSlidorMoveWalls(SpriteNum, diff); + DoSlidorMoveWalls(actor, diff); break; case TAG_WALL_SLIDOR_RIGHT: diff = wall[w].x - sp->x; - DoSlidorMoveWalls(SpriteNum, -diff); + DoSlidorMoveWalls(actor, -diff); break; case TAG_WALL_SLIDOR_UP: diff = wall[w].y - sp->y; - DoSlidorMoveWalls(SpriteNum, diff); + DoSlidorMoveWalls(actor, diff); break; case TAG_WALL_SLIDOR_DOWN: diff = wall[w].y - sp->y; - DoSlidorMoveWalls(SpriteNum, -diff); + DoSlidorMoveWalls(actor, -diff); break; } @@ -502,9 +504,8 @@ int DoSlidorInstantClose(short SpriteNum) } -int DoSlidorMove(short SpriteNum) +int DoSlidor(DSWActor* actor) { - auto actor = &swActors[SpriteNum]; USERp u = actor->u(); SPRITEp sp = &actor->s(); ROTATORp r; @@ -548,7 +549,7 @@ int DoSlidorMove(short SpriteNum) // new tgt is CLOSED (0) r->tgt = 0; r->vel = -r->vel; - SetSlidorInactive(SpriteNum); + SetSlidorInactive(actor); if (SP_TAG6(sp) && !TEST_BOOL8(sp)) DoMatchEverything(nullptr, SP_TAG6(sp), -1); @@ -568,7 +569,7 @@ int DoSlidorMove(short SpriteNum) r->vel = labs(r->vel); r->tgt = r->open_dest; - SetSlidorInactive(SpriteNum); + SetSlidorInactive(actor); RESET_BOOL8(sp); @@ -635,11 +636,11 @@ int DoSlidorMove(short SpriteNum) } - DoSlidorMoveWalls(SpriteNum, r->pos - old_pos); + DoSlidorMoveWalls(actor, r->pos - old_pos); if (kill) { - SetSlidorInactive(SpriteNum); + SetSlidorInactive(actor); KillActor(actor); return 0; } @@ -647,19 +648,6 @@ int DoSlidorMove(short SpriteNum) return 0; } -int DoSlidor(DSWActor* actor) -{ - USER* u = actor->u(); - int SpriteNum = u->SpriteNum; - SPRITEp sp = &sprite[SpriteNum]; - SECTORp sectp = §or[sp->sectnum]; - - DoSlidorMove(SpriteNum); - - return 0; -} - - #include "saveable.h" static saveable_code saveable_slidor_code[] = diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index ca8fa4368..be3b93b30 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -87,7 +87,7 @@ ANIMATOR DoRotator; ANIMATOR DoSlidor; ANIMATOR DoSpike, DoSpikeAuto; ANIMATOR DoLavaErupt; -int DoSlidorInstantClose(short SpriteNum); +int DoSlidorInstantClose(DSWActor*); void InitWeaponRocket(PLAYERp); void InitWeaponUzi(PLAYERp); @@ -2539,7 +2539,7 @@ SpriteSetup(void) if (TEST_BOOL5(sp)) { - DoSlidorInstantClose(SpriteNum); + DoSlidorInstantClose(actor); } change_actor_stat(actor, STAT_SLIDOR);