From 1388794032c6fcba5be516e0be5aad15a5d677cd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Nov 2021 19:41:37 +0100 Subject: [PATCH] - first half of rotator.cpp. --- source/games/sw/src/game.h | 2 +- source/games/sw/src/rotator.cpp | 46 +++++++++++++++------------------ source/games/sw/src/sprite.cpp | 2 +- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index ba3aacaba..80f397c54 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2115,7 +2115,7 @@ int LoadGame(short save_num); // save.c int LoadGameFullHeader(short save_num, char *descr, short *level, short *skill); // save,c void LoadGameDescr(short save_num, char *descr); // save.c -void SetRotatorActive(short SpriteNum); // rotator.c +void SetRotatorActive(DSWActor* actor); // rotator.c bool VatorSwitch(short match, short setting); // vator.c void MoveSpritesWithSector(short sectnum,int z_amt,bool type); // vator.c diff --git a/source/games/sw/src/rotator.cpp b/source/games/sw/src/rotator.cpp index 32f65ad74..4856438aa 100644 --- a/source/games/sw/src/rotator.cpp +++ b/source/games/sw/src/rotator.cpp @@ -45,9 +45,9 @@ void DoMatchEverything(PLAYERp pp, short match, short state); void DoRotatorSetInterp(short SpriteNum); void DoRotatorStopInterp(short SpriteNum); -void ReverseRotator(short SpriteNum) +void ReverseRotator(DSWActor* actor) { - USERp u = User[SpriteNum].Data(); + USERp u = actor->u(); ROTATORp r; r = u->rotator.Data(); @@ -56,7 +56,7 @@ void ReverseRotator(short SpriteNum) if (u->Tics) { u->Tics = 0; - SetRotatorActive(SpriteNum); + SetRotatorActive(actor); return; } @@ -73,17 +73,15 @@ void ReverseRotator(short SpriteNum) r->vel = -r->vel; } -bool -RotatorSwitch(short match, short setting) +bool RotatorSwitch(short match, short setting) { SPRITEp sp; - int i; bool found = false; - StatIterator it(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + SWStatIterator it(STAT_DEFAULT); + while (auto actor = it.Next()) { - sp = &sprite[i]; + sp = &actor->s(); if (sp->lotag == TAG_SPRITE_SWITCH_VATOR && sp->hitag == match) { @@ -95,15 +93,15 @@ RotatorSwitch(short match, short setting) return found; } -void SetRotatorActive(short SpriteNum) +void SetRotatorActive(DSWActor* actor) { - USERp u = User[SpriteNum].Data(); - SPRITEp sp = u->SpriteP; + USERp u = actor->u(); + SPRITEp sp = &actor->s(); ROTATORp r; r = u->rotator.Data(); - DoRotatorSetInterp(SpriteNum); + DoRotatorSetInterp(actor->GetSpriteIndex()); // play activate sound DoSoundSpotMatch(SP_TAG2(sp), 1, SOUND_OBJECT_TYPE); @@ -157,20 +155,18 @@ DoRotatorMatch(PLAYERp pp, short match, bool manual) USERp fu; SPRITEp fsp; short sectnum; - short first_vator = -1; - - int i; + DSWActor* firstVator = nullptr; //RotatorSwitch(match, ON); - StatIterator it(STAT_ROTATOR); - while ((i = it.NextIndex()) >= 0) + SWStatIterator it(STAT_ROTATOR); + while (auto actor = it.Next()) { - fsp = &sprite[i]; + fsp = &actor->s(); if (SP_TAG1(fsp) == SECT_ROTATOR && SP_TAG2(fsp) == match) { - fu = User[i].Data(); + fu = actor->u(); // single play only vator // bool 8 must be set for message to display @@ -188,8 +184,8 @@ DoRotatorMatch(PLAYERp pp, short match, bool manual) continue; } - if (first_vator == -1) - first_vator = i; + if (firstVator == nullptr) + firstVator = actor; sectnum = fsp->sectnum; @@ -207,15 +203,15 @@ DoRotatorMatch(PLAYERp pp, short match, bool manual) if (TEST(fu->Flags, SPR_ACTIVE)) { - ReverseRotator(i); + ReverseRotator(actor); continue; } - SetRotatorActive(i); + SetRotatorActive(actor); } } - return first_vator; + return firstVator->GetSpriteIndex(); } diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 6e21b8a07..532e8e8c7 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -6816,7 +6816,7 @@ SpriteControl(void) if (u->Tics) { if ((u->Tics -= synctics) <= 0) - SetRotatorActive(i); + SetRotatorActive(actor); else continue; }