From 6e96b1ee819a01a43a4156500518aa78afa9ec22 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 27 Jan 2022 20:40:44 +0100 Subject: [PATCH] - floatify SW's sector object rotation. --- source/core/gamefuncs.cpp | 11 ++++++++++- source/core/gamefuncs.h | 1 + source/core/maptypes.h | 10 ++++++++-- source/games/sw/src/game.h | 1 + source/games/sw/src/interpso.cpp | 10 +++++++--- source/games/sw/src/player.cpp | 4 ++-- source/games/sw/src/slidor.cpp | 32 ++++++++++++++++---------------- source/games/sw/src/sprite.cpp | 2 +- source/games/sw/src/track.cpp | 16 +++++++++------- source/games/sw/src/wallmove.cpp | 2 +- 10 files changed, 56 insertions(+), 33 deletions(-) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index a5416fa2ac1..06c8786c4f5 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -399,11 +399,20 @@ void dragpoint(walltype* startwall, int newx, int newy) { vertexscan(startwall, [&](walltype* wal) { - wal->move(newx, newy); + wal->movexy(newx, newy); wal->sectorp()->exflags |= SECTOREX_DRAGGED; }); } +void dragpoint(walltype* startwall, const DVector2& pos) +{ + vertexscan(startwall, [&](walltype* wal) + { + wal->move(pos); + wal->sectorp()->exflags |= SECTOREX_DRAGGED; + }); +} + //========================================================================== // // diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 85961d9c42b..af3afa84f59 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -169,6 +169,7 @@ void GetFlatSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, int* void checkRotatedWalls(); bool sectorsConnected(int sect1, int sect2); void dragpoint(walltype* wal, int newx, int newy); +void dragpoint(walltype* wal, const DVector2& pos); DVector2 rotatepoint(const DVector2& pivot, const DVector2& point, binangle angle); // y is negated so that the orientation is the same as in GZDoom, in order to use its utilities. diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 298b8c09c58..90e6aca9cc0 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -417,7 +417,13 @@ struct walltype bool twoSided() const { return nextsector >= 0; } int Length(); void calcLength(); // this is deliberately not inlined and stored in a file where it can't be found at compile time. - void move(int newx, int newy); + void movexy(int newx, int newy); + void move(const DVector2& vec) + { + pos = vec; + moved(); + } + void moved(); Blood::XWALL& xw() const { return *_xw; } @@ -553,7 +559,7 @@ inline void walltype::moved() sectorp()->dirty = EDirty::AllDirty; } -inline void walltype::move(int newx, int newy) +inline void walltype::movexy(int newx, int newy) { pos.X = newx * maptoworld; pos.Y = newy * maptoworld; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index ca4994ccb9d..e8c163f3e0a 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -100,6 +100,7 @@ enum #define PRODUCTION_ASSERT(f) \ + assert(f);\ do { \ if (!(f)) \ I_FatalError("Assertion failed: %s %s, line %u", #f, __FILE__, __LINE__); \ diff --git a/source/games/sw/src/interpso.cpp b/source/games/sw/src/interpso.cpp index cee0c7862fd..e95c5f5b980 100644 --- a/source/games/sw/src/interpso.cpp +++ b/source/games/sw/src/interpso.cpp @@ -340,7 +340,9 @@ void so_updateinterpolations(void) // Stick at beginning of domovethings } } else + { data->oldipos = getvalue(*data); + } if (!interpolating) data->lastipos = data->lastoldipos = data->oldipos; @@ -352,7 +354,7 @@ void so_updateinterpolations(void) // Stick at beginning of domovethings // make sure you don't exit void so_dointerpolations(int32_t smoothratio) // Stick at beginning of drawscreen { - int32_t i, delta; + int32_t i; SECTOR_OBJECT* sop; so_interp *interp; so_interp::interp_data *data; @@ -445,8 +447,8 @@ void so_dointerpolations(int32_t smoothratio) // Stick at b } else { - delta = data->lastipos - data->lastoldipos; - setvalue(*data, data->lastoldipos + MulScale(delta, ratio, 16)); + double delta = data->lastipos - data->lastoldipos; + setvalue(*data, data->lastoldipos + MulScaleF(delta, ratio, 16)); } } } @@ -473,7 +475,9 @@ void so_restoreinterpolations(void) // Stick at end of drawscree if (actorofang) actorofang->spr.ang = data->bakipos; } else + { setvalue(*data, data->bakipos); + } } } diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 7b00ca1b36b..4799513e65a 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -3830,7 +3830,7 @@ int PlayerCanDiveNoWarp(PLAYER* pp) int GetOverlapSector(int x, int y, sectortype** over, sectortype** under) { int i, found = 0; - sectortype* sf[2]= {nullptr,nullptr}; // sectors found + sectortype* sf[3]= {nullptr,nullptr}; // sectors found auto secto = *over; auto sectu = *under; @@ -3859,7 +3859,7 @@ int GetOverlapSector(int x, int y, sectortype** over, sectortype** under) { sf[found] = § found++; - PRODUCTION_ASSERT(found <= 2); + if (found > 2) return 0; } } } diff --git a/source/games/sw/src/slidor.cpp b/source/games/sw/src/slidor.cpp index 6215b4a38c9..41df4dfb2b9 100644 --- a/source/games/sw/src/slidor.cpp +++ b/source/games/sw/src/slidor.cpp @@ -274,11 +274,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt) if (!wal->twoSided()) { // white wall - move 4 points - wal->move(wal->wall_int_pos().X - amt, wal->wall_int_pos().Y); - pwal->move(pwal->wall_int_pos().X - amt, pwal->wall_int_pos().Y); - wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X - amt, wal->point2Wall()->wall_int_pos().Y); + wal->movexy(wal->wall_int_pos().X - amt, wal->wall_int_pos().Y); + pwal->movexy(pwal->wall_int_pos().X - amt, pwal->wall_int_pos().Y); + wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X - amt, wal->point2Wall()->wall_int_pos().Y); auto pwal2 = wal->point2Wall()->point2Wall(); - pwal2->move(pwal2->wall_int_pos().X - amt, pwal2->wall_int_pos().Y); + pwal2->movexy(pwal2->wall_int_pos().X - amt, pwal2->wall_int_pos().Y); } else { @@ -299,11 +299,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt) if (!wal->twoSided()) { // white wall - move 4 points - wal->move(wal->wall_int_pos().X + amt, wal->wall_int_pos().Y); - pwal->move(pwal->wall_int_pos().X + amt, pwal->wall_int_pos().Y); - wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X + amt, wal->point2Wall()->wall_int_pos().Y); + wal->movexy(wal->wall_int_pos().X + amt, wal->wall_int_pos().Y); + pwal->movexy(pwal->wall_int_pos().X + amt, pwal->wall_int_pos().Y); + wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X + amt, wal->point2Wall()->wall_int_pos().Y); auto pwal2 = wal->point2Wall()->point2Wall(); - pwal2->move(pwal2->wall_int_pos().X + amt, pwal2->wall_int_pos().Y); + pwal2->movexy(pwal2->wall_int_pos().X + amt, pwal2->wall_int_pos().Y); } else { @@ -323,11 +323,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt) if (!wal->twoSided()) { - wal->move(wal->wall_int_pos().X, wal->wall_int_pos().Y - amt); - pwal->move(pwal->wall_int_pos().X, pwal->wall_int_pos().Y - amt); - wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y - amt); + wal->movexy(wal->wall_int_pos().X, wal->wall_int_pos().Y - amt); + pwal->movexy(pwal->wall_int_pos().X, pwal->wall_int_pos().Y - amt); + wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y - amt); auto pwal2 = wal->point2Wall()->point2Wall(); - pwal2->move(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y - amt); + pwal2->movexy(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y - amt); } else { @@ -346,11 +346,11 @@ int DoSlidorMoveWalls(DSWActor* actor, int amt) if (!wal->twoSided()) { - wal->move(wal->wall_int_pos().X, wal->wall_int_pos().Y + amt); - pwal->move(pwal->wall_int_pos().X, pwal->wall_int_pos().Y + amt); - wal->point2Wall()->move(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y + amt); + wal->movexy(wal->wall_int_pos().X, wal->wall_int_pos().Y + amt); + pwal->movexy(pwal->wall_int_pos().X, pwal->wall_int_pos().Y + amt); + wal->point2Wall()->movexy(wal->point2Wall()->wall_int_pos().X, wal->point2Wall()->wall_int_pos().Y + amt); auto pwal2 = wal->point2Wall()->point2Wall(); - pwal2->move(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y + amt); + pwal2->movexy(pwal2->wall_int_pos().X, pwal2->wall_int_pos().Y + amt); } else { diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 711ee7b4f8a..712e639cd31 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -1454,7 +1454,7 @@ void PreMapCombineFloors(void) for (auto& wal : wallsofsector(dasect)) { - wal.move(wal.wall_int_pos().X + dx, wal.wall_int_pos().Y + dy); + wal.movexy(wal.wall_int_pos().X + dx, wal.wall_int_pos().Y + dy); if (wal.twoSided()) search.Add(wal.nextSector()); diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index 8ee397d6afd..51fd8713b12 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -1610,6 +1610,8 @@ void MovePoints(SECTOR_OBJECT* sop, short delta_ang, int nx, int ny) if ((sop->flags & SOBJ_ZMID_FLOOR)) sop->pmid.Z = sop->mid_sector->floorz; + DVector2 pivot = { sop->pmid.X * maptoworld, sop->pmid.Y * maptoworld }; + DVector2 move = { nx * maptoworld, ny * maptoworld }; for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++) { if ((sop->flags & (SOBJ_SPRITE_OBJ | SOBJ_DONT_ROTATE))) @@ -1623,11 +1625,11 @@ void MovePoints(SECTOR_OBJECT* sop, short delta_ang, int nx, int ny) if (wal.extra && (wal.extra & WALLFX_LOOP_OUTER)) { - dragpoint(&wal, wal.wall_int_pos().X + nx, wal.wall_int_pos().Y + ny); + dragpoint(&wal, wal.pos + move); } else { - wal.move(wal.wall_int_pos().X + nx, wal.wall_int_pos().Y + ny); + wal.move(wal.pos + move); } rot_ang = delta_ang; @@ -1641,15 +1643,15 @@ void MovePoints(SECTOR_OBJECT* sop, short delta_ang, int nx, int ny) if ((wal.extra & WALLFX_LOOP_SPIN_4X)) rot_ang = NORM_ANGLE(rot_ang * 4); - rotatepoint(sop->pmid.vec2, wal.wall_int_pos(), rot_ang, &rxy); + auto vec = rotatepoint(pivot, wal.pos, buildang(rot_ang)); if (wal.extra && (wal.extra & WALLFX_LOOP_OUTER)) { - dragpoint(&wal, rxy.X, rxy.Y); + dragpoint(&wal, vec); } else { - wal.move(rxy.X, rxy.Y); + wal.move(vec); } } @@ -1870,7 +1872,7 @@ void RefreshPoints(SECTOR_OBJECT* sop, int nx, int ny, bool dynamic) } else { - wal.move(dx, dy); + wal.movexy(dx, dy); } } @@ -2018,7 +2020,7 @@ void CollapseSectorObject(SECTOR_OBJECT* sop, int nx, int ny) } else { - wal.move(nx, ny); + wal.movexy(nx, ny); } } } diff --git a/source/games/sw/src/wallmove.cpp b/source/games/sw/src/wallmove.cpp index a8acdc2efd1..4090417bed4 100644 --- a/source/games/sw/src/wallmove.cpp +++ b/source/games/sw/src/wallmove.cpp @@ -115,7 +115,7 @@ int DoWallMove(DSWActor* actor) } else { - wal.move(actor->spr.pos.X + nx, actor->spr.pos.Y + ny); + wal.movexy(actor->spr.pos.X + nx, actor->spr.pos.Y + ny); } if (shade1)