From 9dd27ee3a2f196cb3b8bd8873bc5cc2b4f0f04ea Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 30 Sep 2022 13:31:02 +1000 Subject: [PATCH] - Remove old integer `dragpoint()` interface that was used by floats in lots of places. * Cannot wait until all the narrowing warnings can be re-enabled... --- source/core/gamefuncs.cpp | 9 --- source/core/gamefuncs.h | 1 - source/core/maptypes.h | 9 --- source/core/vmexports.cpp | 4 +- source/games/exhumed/src/init.cpp | 19 ++----- source/games/exhumed/src/object.cpp | 88 +++++++++++------------------ source/games/sw/src/sector.cpp | 16 ++---- 7 files changed, 47 insertions(+), 99 deletions(-) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index 8045d562d..ad384f753 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -408,15 +408,6 @@ bool sectorsConnected(int sect1, int sect2) // //========================================================================== -void dragpoint(walltype* startwall, int newx, int newy) -{ - vertexscan(startwall, [&](walltype* wal) - { - wal->movexy(newx, newy); - wal->sectorp()->exflags |= SECTOREX_DRAGGED; - }); -} - void dragpoint(walltype* startwall, const DVector2& pos) { vertexscan(startwall, [&](walltype* wal) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index da6d39497..512017bcf 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -256,7 +256,6 @@ EClose IsCloseToWall(const DVector2& vect, walltype* wal, double walldist); void checkRotatedWalls(); bool sectorsConnected(int sect1, int sect2); -[[deprecated]] void dragpoint(walltype* wal, int newx, int newy); void dragpoint(walltype* wal, const DVector2& pos); int32_t inside(double x, double y, const sectortype* sect); int insidePoly(double x, double y, const DVector2* points, int count); diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 60b7b592b..44cfc5a5d 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -421,7 +421,6 @@ struct walltype bool twoSided() const { return nextsector >= 0; } double Length(); void calcLength(); // this is deliberately not inlined and stored in a file where it can't be found at compile time. - void movexy(int newx, int newy); void move(const DVector2& vec) { pos = vec; @@ -609,14 +608,6 @@ inline void walltype::moved() sectorp()->dirty = EDirty::AllDirty; } -inline void walltype::movexy(int newx, int newy) -{ - pos.X = newx * inttoworld; - pos.Y = newy * inttoworld; - lengthflags = 3; - sectorp()->dirty = EDirty::AllDirty; -} - inline double walltype::Length() { if ((lengthflags & 1) || (point2Wall()->lengthflags & 2)) diff --git a/source/core/vmexports.cpp b/source/core/vmexports.cpp index 503af40c4..02975833b 100644 --- a/source/core/vmexports.cpp +++ b/source/core/vmexports.cpp @@ -485,7 +485,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_walltype, length, wall_length) void wall_move(walltype* wal, double x, double y) { if (!wal) ThrowAbortException(X_READ_NIL, nullptr); - wal->movexy(x, y); + wal->move(DVector2(x, y)); } DEFINE_ACTION_FUNCTION_NATIVE(_walltype, move, wall_move) @@ -493,7 +493,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_walltype, move, wall_move) PARAM_SELF_STRUCT_PROLOGUE(walltype); PARAM_FLOAT(x); PARAM_FLOAT(y); - self->movexy(x, y); + self->move(DVector2(x, y)); return 0; } diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 6a1868163..b90a6dd32 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -229,30 +229,23 @@ void SnapSectors(sectortype* pSectorA, sectortype* pSectorB, int b) { for(auto& wal1 : wallsofsector(pSectorA)) { - int bestx = 0x7FFFFFF; - int besty = bestx; - - double x = wal1.pos.X; - int y = wal1.pos.Y; + DVector2 bestxy = { 0x7FFFFFF, 0x7FFFFFF }; + DVector2 w1pos = wal1.pos; walltype* bestwall = nullptr; for(auto& wal2 : wallsofsector(pSectorB)) { - double thisx = x - wal2.pos.X; - double thisy = y - wal2.pos.Y; - double thisdist = abs(thisx) + abs(thisy); - double bestdist = abs(bestx) + abs(besty); + DVector2 thisxy = w1pos - wal2.pos; - if (thisdist < bestdist) + if (thisxy.Sum() < bestxy.Sum()) { - bestx = thisx; - besty = thisy; + bestxy = thisxy; bestwall = &wal2; } } - dragpoint(bestwall, bestwall->pos.X + bestx, bestwall->pos.Y + besty); + dragpoint(bestwall, bestwall->pos + bestxy); } if (b) { diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index a4f65eb88..9b320affb 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -589,6 +589,11 @@ static double LongSeek(double* pZVal, double a2, double a3, double a4) return v4; } +static inline DVector2 LongSeek(DVector2& pZVals, const DVector2& a2, double a3, double a4) +{ + return DVector2(LongSeek(&pZVals.X, a2.X, a3, a4), LongSeek(&pZVals.Y, a2.Y, a3, a4)); +} + //--------------------------------------------------------------------------- // // @@ -1126,90 +1131,63 @@ void AISlide::Tick(RunListEvent* ev) if (cx == 1) { auto pWall = SlideData[nSlide].pWall1; - double x = pWall->pos.X; - double y = pWall->pos.Y; + auto wlPos = pWall->pos; + auto nSeek = LongSeek(wlPos, SlideData[nSlide].pos[4], 1.25, 1.25); + dragpoint(pWall, wlPos); + movesprite(SlideData[nSlide].pActor, nSeek, 0, 0, CLIPMASK1); - double nSeekA = LongSeek(&x, SlideData[nSlide].pos[4].X, 1.25, 1.25); - double nSeekB = LongSeek(&y, SlideData[nSlide].pos[4].Y, 1.25, 1.25); - - dragpoint(SlideData[nSlide].pWall1, x, y); - movesprite(SlideData[nSlide].pActor, DVector2(nSeekA, nSeekB), 0, 0, CLIPMASK1); - - if (nSeekA == 0 && nSeekB == 0) + if (nSeek.isZero()) { clipstate = clipmask; } pWall = SlideData[nSlide].pStartWall; - - x = pWall->pos.X + nSeekA; - y = pWall->pos.Y + nSeekB; - - dragpoint(SlideData[nSlide].pStartWall, x, y); + wlPos = pWall->pos + nSeek; + dragpoint(pWall, wlPos); pWall = SlideData[nSlide].pWall3; + wlPos = pWall->pos; + nSeek = LongSeek(wlPos, SlideData[nSlide].pos[5], 1.25, 1.25); + dragpoint(pWall, wlPos); - x = pWall->pos.X; - y = pWall->pos.Y; - - int nSeekC = LongSeek(&x, SlideData[nSlide].pos[5].X, 1.25, 1.25); - int nSeekD = LongSeek(&y, SlideData[nSlide].pos[5].Y, 1.25, 1.25); - - dragpoint(SlideData[nSlide].pWall3, x, y); - - if (nSeekC == 0 && nSeekD == 0) { + if (nSeek.isZero()) + { clipstate++; } pWall = SlideData[nSlide].pWall2; - - x = pWall->pos.X + nSeekC; - y = pWall->pos.Y + nSeekD; - - dragpoint(SlideData[nSlide].pWall2, x, y); + wlPos = pWall->pos + nSeek; + dragpoint(pWall, wlPos); } else if (cx == 0) // right branch { auto pWall = SlideData[nSlide].pStartWall; - double x = pWall->pos.X; - double y = pWall->pos.Y; + auto wlPos = pWall->pos; + auto nSeek = LongSeek(wlPos, SlideData[nSlide].pos[0], 1.25, 1.25); + dragpoint(pWall, wlPos); - int nSeekA = LongSeek(&x, SlideData[nSlide].pos[0].X, 1.25, 1.25); - int nSeekB = LongSeek(&y, SlideData[nSlide].pos[0].Y, 1.25, 1.25); - - dragpoint(SlideData[nSlide].pStartWall, x, y); - - if (nSeekA == 0 && nSeekB == 0) { + if (nSeek.isZero()) + { clipstate = clipmask; } pWall = SlideData[nSlide].pWall1; - - y = pWall->pos.Y + nSeekB; - x = pWall->pos.X + nSeekA; - - dragpoint(SlideData[nSlide].pWall1, x, y); + wlPos = pWall->pos + nSeek; + dragpoint(pWall, wlPos); pWall = SlideData[nSlide].pWall2; + wlPos = pWall->pos; + nSeek = LongSeek(wlPos, SlideData[nSlide].pos[1], 1.25, 1.25); + dragpoint(pWall, wlPos); - x = pWall->pos.X; - y = pWall->pos.Y; - - int nSeekC = LongSeek(&x, SlideData[nSlide].pos[1].X, 1.25, 1.25); - int nSeekD = LongSeek(&y, SlideData[nSlide].pos[1].Y, 1.25, 1.25); - - dragpoint(SlideData[nSlide].pWall2, x, y); - - if (nSeekC == 0 && nSeekD == 0) { + if (nSeek.isZero()) + { clipstate++; } pWall = SlideData[nSlide].pWall3; - - y = pWall->pos.Y + nSeekD; - x = pWall->pos.X + nSeekC; - - dragpoint(SlideData[nSlide].pWall3, x, y); + wlPos = pWall->pos + nSeek; + dragpoint(pWall, wlPos); } // loc_21A51: diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index a37709801..b85c57531 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -2625,28 +2625,24 @@ void DoSineWaveFloor(void) void DoSineWaveWall(void) { - SINE_WALL *sw; - double New; - short sw_num; - - for (sw_num = 0; sw_num < MAX_SINE_WALL; sw_num++) + for (short sw_num = 0; sw_num < MAX_SINE_WALL; sw_num++) { - for (sw = &SineWall[sw_num][0]; sw->wallp != nullptr && sw < &SineWall[sw_num][MAX_SINE_WALL_POINTS]; sw++) + for (SINE_WALL* sw = &SineWall[sw_num][0]; sw->wallp != nullptr && sw < &SineWall[sw_num][MAX_SINE_WALL_POINTS]; sw++) { auto wal = sw->wallp; + DVector2 newpos = wal->pos; // move through the sintable sw->sintable_ndx = NORM_ANGLE(sw->sintable_ndx + (synctics << sw->speed_shift)); if (!sw->type) { - New = sw->origXY + sw->Range * BobVal(sw->sintable_ndx); - dragpoint(wal, DVector2(wal->pos.X, New)); + newpos.Y = sw->origXY + sw->Range * BobVal(sw->sintable_ndx); } else { - New = sw->origXY + sw->Range * BobVal(sw->sintable_ndx); - dragpoint(wal, DVector2(New, wal->pos.Y)); + newpos.X = sw->origXY + sw->Range * BobVal(sw->sintable_ndx); } + dragpoint(wal, newpos); } } }