diff --git a/source/build/include/build.h b/source/build/include/build.h index d1723f35f..2dd305da6 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -777,6 +777,11 @@ inline walltype* sectortype::firstWall() const return &wall[wallptr]; // cannot be -1 in a proper map } +inline walltype* sectortype::lastWall() const +{ + return &wall[wallptr + wallnum - 1]; // cannot be -1 in a proper map +} + inline int cansee(int x1, int y1, int z1, sectortype* sect1, int x2, int y2, int z2, sectortype* sect2) { return cansee(x1, y1, z1, sector.IndexOf(sect1), x2, y2, z2, sector.IndexOf(sect2)); diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 51f026c18..5889386bd 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -142,7 +142,8 @@ struct sectortype void addfloorypan(float add) { floorypan_ = fmodf(floorypan_ + add + 512, 256); } // +512 is for handling negative offsets void addceilingxpan(float add) { ceilingxpan_ = fmodf(ceilingxpan_ + add + 512, 256); } // +512 is for handling negative offsets void addceilingypan(float add) { ceilingypan_ = fmodf(ceilingypan_ + add + 512, 256); } // +512 is for handling negative offsets - walltype *firstWall() const; + walltype* firstWall() const; + walltype* lastWall() const; // These will unfortunately have to be within the base struct to refactor Blood properly. They can later be removed again, once everything is done. diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index e01fc0d67..447cd3e61 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -76,6 +76,9 @@ struct Collision int setSprite(DSWActor* num); int setSky(); int setFromEngine(int value); + + walltype* wall() const { assert(type == kHitWall); return &::wall[index]; } + sectortype* sector() const { assert(type == kHitSector); return &::sector[index]; } }; typedef struct diff --git a/source/games/sw/src/rotator.cpp b/source/games/sw/src/rotator.cpp index acf035da9..3ea1b7202 100644 --- a/source/games/sw/src/rotator.cpp +++ b/source/games/sw/src/rotator.cpp @@ -234,22 +234,17 @@ bool TestRotatorMatchActive(short match) void DoRotatorSetInterp(DSWActor* actor) { SPRITEp sp = &actor->s(); - short w,startwall,endwall; - startwall = sp->sector()->wallptr; - endwall = startwall + sp->sector()->wallnum - 1; - - // move points - for (w = startwall; w <= endwall; w++) + for(auto& wal : wallsofsector(sp->sector())) { - StartInterpolation(w, Interp_Wall_X); - StartInterpolation(w, Interp_Wall_Y); + StartInterpolation(&wal, Interp_Wall_X); + StartInterpolation(&wal, Interp_Wall_Y); - uint16_t const nextwall = wall[w].nextwall; - if (validWallIndex(nextwall)) + if (wal.twoSided()) { - StartInterpolation(wall[nextwall].point2, Interp_Wall_X); - StartInterpolation(wall[nextwall].point2, Interp_Wall_Y); + auto w2 = wal.nextWall()->point2Wall(); + StartInterpolation(w2, Interp_Wall_X); + StartInterpolation(w2, Interp_Wall_Y); } } } @@ -257,22 +252,16 @@ void DoRotatorSetInterp(DSWActor* actor) void DoRotatorStopInterp(DSWActor* actor) { SPRITEp sp = &actor->s(); - short w,startwall,endwall; - - startwall = sp->sector()->wallptr; - endwall = startwall + sp->sector()->wallnum - 1; - - // move points - for (w = startwall; w <= endwall; w++) + for (auto& wal : wallsofsector(sp->sector())) { - StopInterpolation(w, Interp_Wall_X); - StopInterpolation(w, Interp_Wall_Y); + StopInterpolation(&wal, Interp_Wall_X); + StopInterpolation(&wal, Interp_Wall_Y); - uint16_t const nextwall = wall[w].nextwall; - if (validWallIndex(nextwall)) + if (wal.twoSided()) { - StopInterpolation(wall[nextwall].point2, Interp_Wall_X); - StopInterpolation(wall[nextwall].point2, Interp_Wall_Y); + auto w2 = wal.nextWall()->point2Wall(); + StopInterpolation(w2, Interp_Wall_X); + StopInterpolation(w2, Interp_Wall_Y); } } } diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index c2d93d30f..d41771da3 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -19601,15 +19601,7 @@ int DoItemFly(DSWActor* actor) case kHitWall: { - short hit_wall,nw,wall_ang; - WALLp wph; - - hit_wall = u->coll.index; - wph = &wall[hit_wall]; - - nw = wall[hit_wall].point2; - wall_ang = NORM_ANGLE(getangle(wall[nw].x - wph->x, wall[nw].y - wph->y)+512); - + int wall_ang = NORM_ANGLE(getangle(u->coll.wall()->delta())+512); WallBounce(actor, wall_ang); ScaleSpriteVector(actor, 32000); break;