From e71254dfa69b041b3fc9670ecba67b60f0a0e7fa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 20 Aug 2022 10:03:21 +0200 Subject: [PATCH] - floatified some parts of the SO interface for consistent use of MAXSO. --- source/core/textures/buildtiles.cpp | 4 ---- source/games/sw/src/game.h | 4 +++- source/games/sw/src/misc.h | 2 +- source/games/sw/src/player.cpp | 17 ++++++++--------- source/games/sw/src/track.cpp | 18 +++++++++--------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index a9a93a7b5..a58b07967 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -371,10 +371,6 @@ FGameTexture* BuildTiles::ValidateCustomTile(int tilenum, ReplacementType type) { // Creates an empty writable tile. // Current use cases are: - // Camera textures (should be made to be creatable by the hardware renderer instead of falling back on the software renderer.) - // thumbnails for savegame and loadgame (should bypass the texture manager entirely.) - // view tilting in the software renderer (this should just use a local buffer instead of relying on the texture manager.) - // Movie playback (like thumbnails this should bypass the texture manager entirely.) // Blood's 'lens' effect (apparently MP only) - combination of a camera texture with a distortion map - should be made a shader effect to be applied to the camera texture. replacement = new FImageTexture(new FWritableTile); } diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 7b47bf93b..ec283f4f1 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1569,7 +1569,9 @@ enum // #define SO_SPEED_BOAT 99 }; -constexpr double MAXSO = INT32_MAX / 32; // make sure this does not overflow when converted to a Build int coordinate. +// make sure this does not overflow when converted to a Build int coordinate and survives a round trip through conversions. +constexpr double MAXSO = 0x7fffffe0 / 32; +static_assert(MAXSO == int(MAXSO * worldtoint) * inttoworld); inline bool SO_EMPTY(SECTOR_OBJECT* sop) { return (sop->pmid.X == MAXSO); } diff --git a/source/games/sw/src/misc.h b/source/games/sw/src/misc.h index 323a83971..44fa46885 100644 --- a/source/games/sw/src/misc.h +++ b/source/games/sw/src/misc.h @@ -48,7 +48,7 @@ int ActorFollowTrack(DSWActor*, short locktics); void ActorLeaveTrack(DSWActor*); void RefreshPoints(SECTOR_OBJECT* sop, int nx, int ny, bool dynamic); void TrackSetup(void); -void PlaceSectorObject(SECTOR_OBJECT* sop, int newx, int newy); +void PlaceSectorObject(SECTOR_OBJECT* sop, const DVector2& newpos); void PlaceSectorObjectsOnTracks(void); void PlaceActorsOnTracks(void); void SetupSectorObject(sectortype* sect, short tag); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 3007c7854..b44079915 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -161,7 +161,7 @@ void DoPlayerBeginDive(PLAYER* pp); void DoPlayerDive(PLAYER* pp); void DoPlayerTeleportPause(PLAYER* pp); bool PlayerFlyKey(void); -void OperateSectorObject(SECTOR_OBJECT* sop, short newang, int newx, int newy); +void OperateSectorObject(SECTOR_OBJECT* sop, short newang, const DVector2& newpos); void CheckFootPrints(PLAYER* pp); bool DoPlayerTestCrawl(PLAYER* pp); void DoPlayerDeathFlip(PLAYER* pp); @@ -1566,7 +1566,7 @@ void DoPlayerTurnTurret(PLAYER* pp, float avel) pp->actor->set_int_ang(pp->angle.ang.Buildang()); } - OperateSectorObject(pp->sop, pp->angle.ang.Buildang(), pp->sop->int_pmid().X, pp->sop->int_pmid().Y); + OperateSectorObject(pp->sop, pp->angle.ang.Buildang(), pp->sop->pmid); } void SlipSlope(PLAYER* pp) @@ -2581,7 +2581,7 @@ void DoPlayerMoveVehicle(PLAYER* pp) } auto save_sect = pp->cursector; - OperateSectorObject(pp->sop, pp->angle.ang.Buildang(), MAXSO, MAXSO); + OperateSectorObject(pp->sop, pp->angle.ang.Buildang(), { MAXSO, MAXSO }); pp->setcursector(pp->sop->op_main_sector); // for speed floor_dist = labs(z - pp->sop->floor_loz); @@ -2686,7 +2686,7 @@ void DoPlayerMoveVehicle(PLAYER* pp) } } - OperateSectorObject(pp->sop, pp->angle.ang.Buildang(), pp->pos.X, pp->pos.Y); + OperateSectorObject(pp->sop, pp->angle.ang.Buildang(), { pp->pos.X * inttoworld, pp->pos.Y * inttoworld }); pp->cursector = save_sect; // for speed if (!SyncInput()) @@ -4821,17 +4821,16 @@ void FindMainSector(SECTOR_OBJECT* sop) // find the main sector - only do this once for each sector object if (sop->op_main_sector == nullptr) { - int sx = sop->int_pmid().X; - int sy = sop->int_pmid().Y; + auto oldpos = sop->pmid; - PlaceSectorObject(sop, MAXSO, MAXSO); + PlaceSectorObject(sop, { MAXSO, MAXSO }); // set it to something valid sop->op_main_sector = §or[0]; - updatesectorz(sx, sy, sop->int_pmid().Z, &sop->op_main_sector); + updatesectorz(oldpos, &sop->op_main_sector); - PlaceSectorObject(sop, sx, sy); + PlaceSectorObject(sop, oldpos.XY()); } } diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index dd2c52dcb..836a66c3a 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -1856,7 +1856,7 @@ void RefreshPoints(SECTOR_OBJECT* sop, int nx, int ny, bool dynamic) } } - if (wal.extra && (wal.extra & WALLFX_LOOP_OUTER)) + if (wal.extra & WALLFX_LOOP_OUTER) { dragpoint(&wal, dx, dy); } @@ -2568,7 +2568,7 @@ void DoTrack(SECTOR_OBJECT* sop, short locktics, int *nx, int *ny) } -void OperateSectorObjectForTics(SECTOR_OBJECT* sop, short newang, int newx, int newy, short locktics) +void OperateSectorObjectForTics(SECTOR_OBJECT* sop, short newang, const DVector2& pos, short locktics) { int i; sectortype* *sectp; @@ -2604,18 +2604,18 @@ void OperateSectorObjectForTics(SECTOR_OBJECT* sop, short newang, int newx, int sop->spin_ang = 0; sop->ang = newang; - RefreshPoints(sop, newx - sop->int_pmid().X, newy - sop->int_pmid().Y, false); + RefreshPoints(sop, int((pos.X - sop->pmid.X) * worldtoint), int((pos.Y - sop->pmid.Y) * worldtoint), false); } -void OperateSectorObject(SECTOR_OBJECT* sop, short newang, int newx, int newy) +void OperateSectorObject(SECTOR_OBJECT* sop, short newang, const DVector2& pos) { - OperateSectorObjectForTics(sop, newang, newx, newy, synctics); + OperateSectorObjectForTics(sop, newang, pos, synctics); } -void PlaceSectorObject(SECTOR_OBJECT* sop, int newx, int newy) +void PlaceSectorObject(SECTOR_OBJECT* sop, const DVector2& pos) { so_setinterpolationtics(sop, synctics); - RefreshPoints(sop, newx - sop->int_pmid().X, newy - sop->int_pmid().Y, false); + RefreshPoints(sop, int((pos.X - sop->pmid.X) * worldtoint), int((pos.Y - sop->pmid.Y) * worldtoint), false); } void VehicleSetSmoke(SECTOR_OBJECT* sop, ANIMATOR* animator) @@ -2707,7 +2707,7 @@ void DoTornadoObject(SECTOR_OBJECT* sop) pos.Y = sop->int_pmid().Y; pos.Z = floor_dist; - PlaceSectorObject(sop, MAXSO, MAXSO); + PlaceSectorObject(sop, {MAXSO, MAXSO}); Collision coll; clipmove(pos, &cursect, xvect, yvect, (int)sop->clipdist, Z(0), floor_dist, CLIPMASK_ACTOR, coll); @@ -2810,7 +2810,7 @@ void DoAutoTurretObject(SECTOR_OBJECT* sop) } } - OperateSectorObjectForTics(sop, sop->ang, sop->int_pmid().X, sop->int_pmid().Y, 2*synctics); + OperateSectorObjectForTics(sop, sop->ang, sop->pmid, 2*synctics); } }