From a8e7d1ef74cf7d252695840c26402953202dccf2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 15 Oct 2020 18:59:11 +0200 Subject: [PATCH] - the rest for SW. --- source/sw/src/game.h | 2 -- source/sw/src/jsector.cpp | 11 ++++++----- source/sw/src/player.cpp | 19 ++++++++++--------- source/sw/src/sector.cpp | 5 +++-- source/sw/src/sprite.cpp | 7 ++++--- source/sw/src/track.cpp | 24 ++++++------------------ 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 03547fa9e..e0a150b9b 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -253,8 +253,6 @@ inline int32_t FIXED(int32_t msw, int32_t lsw) #define SectorIsDiveArea(sect) (TEST(sector[sect].extra, SECTFX_DIVE_AREA) ? true : false) #define SectorIsUnderwaterArea(sect) (TEST(sector[sect].extra, SECTFX_UNDERWATER|SECTFX_UNDERWATER2) ? true : false) -#define TRAVERSE_SPRITE_SECT(l, o, n) for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritesect[o], (o) != -1; (o) = (n)) -#define TRAVERSE_SPRITE_STAT(l, o, n) for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritestat[o], (o) != -1; (o) = (n)) #define TRAVERSE_CONNECT(i) for (i = connecthead; i != -1; i = connectpoint2[i]) diff --git a/source/sw/src/jsector.cpp b/source/sw/src/jsector.cpp index 40469463b..d3c007783 100644 --- a/source/sw/src/jsector.cpp +++ b/source/sw/src/jsector.cpp @@ -337,11 +337,13 @@ void JS_InitMirrors(void) mirror[mirrorcnt].ismagic = false; do if (wall[i].lotag == TAG_WALL_MAGIC_MIRROR) { - short ii, nextii; + int ii; SPRITEp sp; Found_Cam = false; - TRAVERSE_SPRITE_STAT(headspritestat[STAT_ST1], ii, nextii) + + StatIterator it(STAT_ST1); + while ((ii = it.NextIndex()) >= 0) { sp = &sprite[ii]; // if correct type and matches @@ -355,10 +357,9 @@ void JS_InitMirrors(void) } } - ii = nextii = 0; - TRAVERSE_SPRITE_STAT(headspritestat[STAT_SPAWN_SPOT], ii, nextii) + it.Reset(STAT_SPAWN_SPOT); + while ((ii = it.NextIndex()) >= 0) { - sp = &sprite[ii]; // if correct type and matches diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 6c1a70aad..4dc48de71 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -2740,7 +2740,7 @@ DriveCrush(PLAYERp pp, int *x, int *y) // all players for (stat = 0; stat < MAX_SW_PLAYERS; stat++) { - i = headspritestat[STAT_PLAYER0 + stat]; + i = StatIterator::First(STAT_PLAYER0 + stat); if (i < 0) continue; @@ -4007,12 +4007,13 @@ DoPlayerFly(PLAYERp pp) SPRITEp FindNearSprite(SPRITEp sp, short stat) { - short fs, next_fs; + int fs; int dist, near_dist = 15000; SPRITEp fp, near_fp = NULL; - TRAVERSE_SPRITE_STAT(headspritestat[stat], fs, next_fs) + StatIterator it(stat); + while ((fs = it.NextIndex()) >= 0) { fp = &sprite[fs]; @@ -7423,7 +7424,7 @@ int SearchSpawnPosition(PLAYERp pp) { // get a spawn position pos_num = RANDOM_RANGE(MAX_SW_PLAYERS); - spawn_sprite = headspritestat[STAT_MULTI_START + pos_num]; + spawn_sprite = StatIterator::First(STAT_MULTI_START + pos_num); if (spawn_sprite <= -1) return 0; @@ -7481,7 +7482,7 @@ PlayerSpawnPosition(PLAYERp pp) { case MULTI_GAME_NONE: // start from the beginning - spawn_sprite = headspritestat[STAT_MULTI_START + 0]; + spawn_sprite = StatIterator::First(STAT_MULTI_START + 0); break; case MULTI_GAME_COMMBAT: case MULTI_GAME_AI_BOTS: @@ -7491,11 +7492,11 @@ PlayerSpawnPosition(PLAYERp pp) pos_num = SearchSpawnPosition(pp); } - spawn_sprite = headspritestat[STAT_MULTI_START + pos_num]; + spawn_sprite = StatIterator::First(STAT_MULTI_START + pos_num); break; case MULTI_GAME_COOPERATIVE: // start your assigned spot - spawn_sprite = headspritestat[STAT_CO_OP_START + pos_num]; + spawn_sprite = StatIterator::First(STAT_MULTI_START + pos_num); break; } @@ -7503,7 +7504,7 @@ PlayerSpawnPosition(PLAYERp pp) if (spawn_sprite < 0) { - spawn_sprite = headspritestat[STAT_MULTI_START + 0]; + spawn_sprite = StatIterator::First(STAT_MULTI_START + 0); } ASSERT(spawn_sprite >= 0); @@ -7570,7 +7571,7 @@ InitMultiPlayerInfo(void) if (gNet.MultiGameType != MULTI_GAME_NONE) { // if start position is physically set then don't spawn a new one - if (headspritestat[MultiStatList[stat] + 0] >= 0) + if (StatIterator::First(MultiStatList[stat] + 0) >= 0) continue; } diff --git a/source/sw/src/sector.cpp b/source/sw/src/sector.cpp index 107f8cd08..d63b7c8b0 100644 --- a/source/sw/src/sector.cpp +++ b/source/sw/src/sector.cpp @@ -1067,14 +1067,15 @@ DoExplodeSector(short match) { short orig_ang; int zh; - short cf,nextcf; + int cf; SPRITEp esp; SECTORp sectp; orig_ang = 0; //sp->ang; - TRAVERSE_SPRITE_STAT(headspritestat[STAT_EXPLODING_CEIL_FLOOR], cf, nextcf) + StatIterator it(STAT_EXPLODING_CEIL_FLOOR); + while ((cf = it.NextIndex()) >= 0) { esp = &sprite[cf]; diff --git a/source/sw/src/sprite.cpp b/source/sw/src/sprite.cpp index cabe9c4c2..4bb5301ad 100644 --- a/source/sw/src/sprite.cpp +++ b/source/sw/src/sprite.cpp @@ -4156,11 +4156,12 @@ int ActorCoughItem(short SpriteNum) int SpawnItemsMatch(short match) { - short SpriteNum; - short si, nextsi; + int SpriteNum; + int si; SPRITEp sp,sip; - TRAVERSE_SPRITE_STAT(headspritestat[STAT_SPAWN_ITEMS],si,nextsi) + StatIterator it(STAT_SPAWN_ITEMS); + while ((si = it.NextIndex()) >= 0) { sip = &sprite[si]; diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index 73bfdda28..e2ed342d4 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -607,7 +607,7 @@ TrackSetup(void) // put points on track for (ndx = 0; ndx < MAX_TRACKS; ndx++) { - if (headspritestat[STAT_TRACK + ndx] == -1) + if (StatIterator::First(STAT_TRACK + ndx) == -1) { // for some reason I need at least one record allocated // can't remember why at this point @@ -643,7 +643,7 @@ TrackSetup(void) if (t->NumPoints == 0) { int i; - auto const sp = (uspritetype const *)&sprite[headspritestat[STAT_TRACK+ndx]]; + auto const sp = (uspritetype const *)&sprite[StatIterator::First(STAT_TRACK+ndx)]; Printf("WARNING: Did not find first point of Track Number %d, x %d, y %d\n", ndx, sp->x, sp->y); StatIterator it(STAT_TRACK + ndx); while ((i = it.NextIndex()) >= 0) @@ -659,7 +659,7 @@ TrackSetup(void) SET(t->ttflags, BIT(tp->tag_high)); // while there are still sprites on this status list - while (headspritestat[STAT_TRACK + ndx] != -1) + while (StatIterator::First(STAT_TRACK + ndx) != -1) { short next_sprite = -1; int dist, low_dist = 999999; @@ -730,7 +730,7 @@ void SectorObjectSetupBounds(SECTOR_OBJECTp sop) { int xlow, ylow, xhigh, yhigh; - short sp_num, next_sp_num, startwall, endwall; + int sp_num, startwall, endwall; int i, k, j; SPRITEp BoundSprite; bool FoundOutsideLoop = false; @@ -891,7 +891,8 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop) for (i = 0; i < (int)SIZ(StatList); i++) { - TRAVERSE_SPRITE_STAT(headspritestat[StatList[i]], sp_num, next_sp_num) + StatIterator it(StatList[i]); + while ((sp_num = it.NextIndex()) >= 0) { SPRITEp sp = &sprite[sp_num]; USERp u; @@ -1790,19 +1791,6 @@ PlayerPart: if (TEST(sector[pp->lo_sectp - sector].extra, SECTFX_NO_RIDE)) { -#if 0 - short nr, nextnr; - bool skip = true; - TRAVERSE_SPRITE_STAT(headspritestat[STAT_NO_RIDE], nr, nextnr) - { - if (sprite[nr].lotag == sop - SectorObject) - skip = true; - else - skip = false; - } - - if (skip) -#endif continue; }