From e5225e98e07cd5b7caca884e47adbdb5bf3e0eae Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Dec 2022 11:11:50 +0100 Subject: [PATCH] - migrated SW's portal setup code to texture IDs. --- source/core/gamefuncs.cpp | 2 +- source/core/maptypes.h | 6 ++++-- source/core/textures/buildtiles.cpp | 16 ++++++++++++++-- source/games/sw/src/copysect.cpp | 2 +- source/games/sw/src/game.cpp | 15 +++++++++++++++ source/games/sw/src/game.h | 11 ++++------- source/games/sw/src/rooms.cpp | 28 ++++++++++++++-------------- source/games/sw/src/sector.cpp | 12 ++++++------ source/games/sw/src/weapon.cpp | 2 +- 9 files changed, 60 insertions(+), 34 deletions(-) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index fc3a22afc..7b6fe4055 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -525,7 +525,7 @@ int testpointinquad(const DVector2& pt, const DVector2* quad) double intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor) { auto end = start + direction; - if (direction.isZero()) return false; + if (direction.XY().isZero()) return false; // get point on trace that is closest to the sprite double factor = NearestPointOnLineFast(actor->spr.pos.X, actor->spr.pos.Y, start.X, start.Y, end.X, end.Y); diff --git a/source/core/maptypes.h b/source/core/maptypes.h index a443fe787..52b937577 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -440,8 +440,10 @@ struct sectortype int getfloorslope() const { return floorstat & CSTAT_SECTOR_SLOPE ? floorheinum : 0; } int getceilingslope() const { return ceilingstat & CSTAT_SECTOR_SLOPE ? ceilingheinum : 0; } - FTextureID ceilingtexture() const; - FTextureID floortexture() const; + const FTextureID ceilingtexture() const; + const FTextureID floortexture() const; + void setfloortexture(FTextureID tex); + void setceilingtexture(FTextureID tex); Blood::XSECTOR& xs() const { return *_xs; } diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index 137fea1a2..4acef569e 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -704,13 +704,13 @@ FTextureID walltype::overtexture() const return tex ? tex->GetID() : FNullTextureID(); } -FTextureID sectortype::ceilingtexture() const +const FTextureID sectortype::ceilingtexture() const { auto tex = tileGetTexture(ceilingpicnum); return tex ? tex->GetID() : FNullTextureID(); } -FTextureID sectortype::floortexture() const +const FTextureID sectortype::floortexture() const { auto tex = tileGetTexture(floorpicnum); return tex ? tex->GetID() : FNullTextureID(); @@ -721,3 +721,15 @@ FTextureID spritetypebase::spritetexture() const auto tex = tileGetTexture(picnum); return tex ? tex->GetID() : FNullTextureID(); } + +void sectortype::setfloortexture(FTextureID tex) +{ + auto p = TileFiles.textotile.CheckKey(tex.GetIndex()); + if (p) floorpicnum = *p; +} + +void sectortype::setceilingtexture(FTextureID tex) +{ + auto p = TileFiles.textotile.CheckKey(tex.GetIndex()); + if (p) ceilingpicnum = *p; +} diff --git a/source/games/sw/src/copysect.cpp b/source/games/sw/src/copysect.cpp index f0cebb8ef..4b4a20ce8 100644 --- a/source/games/sw/src/copysect.cpp +++ b/source/games/sw/src/copysect.cpp @@ -247,7 +247,7 @@ void CopySectorMatch(int match) dsectp->extra = ssectp->extra; dsectp->visibility = ssectp->visibility; - if (ssectp->floorpicnum == FAF_MIRROR_PIC || ssectp->ceilingpicnum == FAF_MIRROR_PIC) + if (ssectp->floortexture() == FAFMirrorPic[0] || ssectp->ceilingtexture() == FAFMirrorPic[0]) { CollectPortals(); // unavoidable. Since these portals are not static we have to reinitialize all of them. } diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index ae99186e1..82ef5482e 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -227,13 +227,28 @@ void GameInterface::LoadGameTextures() void GameInterface::SetupSpecialTextures() { + enum + { + FAF_PLACE_MIRROR_PIC = 341, + FAF_MIRROR_PIC = 2356 + }; + tileDelete(MIRROR); // mirror for (int i = 0; i < MAXMIRRORS; i++) { tileDelete(i + MIRRORLABEL); TileFiles.MakeCanvas(CAMSPRITE + i, 128, 114); } + // make these two unique, they are empty by default. + tileDelete(FAF_MIRROR_PIC); + tileDelete(FAF_MIRROR_PIC + 1); TileFiles.lock(); + + // these are frequently checked markers. + FAFPlaceMirrorPic[0] = tileGetTextureID(FAF_PLACE_MIRROR_PIC); + FAFPlaceMirrorPic[1] = tileGetTextureID(FAF_PLACE_MIRROR_PIC + 1); + FAFMirrorPic[0] = tileGetTextureID(FAF_MIRROR_PIC); + FAFMirrorPic[1] = tileGetTextureID(FAF_MIRROR_PIC + 1); } //--------------------------------------------------------------------------- // diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 94ab5519e..72e5cd2ed 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1455,20 +1455,17 @@ void CollectPortals(); int SpawnBlood(DSWActor* actor, DSWActor* weapActor, DAngle hit_angle = nullAngle, const DVector3* hitpos = nullptr); -enum -{ - FAF_PLACE_MIRROR_PIC = 341, - FAF_MIRROR_PIC = 2356 -}; +inline FTextureID FAFPlaceMirrorPic[2]; +inline FTextureID FAFMirrorPic[2]; inline bool FAF_ConnectCeiling(sectortype* sect) { - return (sect && sect->ceilingpicnum == FAF_MIRROR_PIC); + return (sect && sect->ceilingtexture() == FAFMirrorPic[0]); } inline bool FAF_ConnectFloor(sectortype* sect) { - return (sect && sect->floorpicnum == FAF_MIRROR_PIC); + return (sect && sect->floortexture() == FAFMirrorPic[0]); } inline bool FAF_ConnectArea(sectortype* sect) diff --git a/source/games/sw/src/rooms.cpp b/source/games/sw/src/rooms.cpp index cac48b002..dfdae15b3 100644 --- a/source/games/sw/src/rooms.cpp +++ b/source/games/sw/src/rooms.cpp @@ -628,23 +628,23 @@ void SetupMirrorTiles(void) SWStatIterator it(STAT_FAF); while (auto actor = it.Next()) { - if (actor->sector()->ceilingpicnum == FAF_PLACE_MIRROR_PIC) + if (actor->sector()->ceilingtexture() == FAFPlaceMirrorPic[0]) { - actor->sector()->ceilingpicnum = FAF_MIRROR_PIC; + actor->sector()->setceilingtexture(FAFMirrorPic[0]); actor->sector()->ceilingstat |= (CSTAT_SECTOR_SKY); } - if (actor->sector()->floorpicnum == FAF_PLACE_MIRROR_PIC) + if (actor->sector()->floortexture() == FAFPlaceMirrorPic[0]) { - actor->sector()->floorpicnum = FAF_MIRROR_PIC; + actor->sector()->setfloortexture(FAFMirrorPic[0]); actor->sector()->floorstat |= (CSTAT_SECTOR_SKY); } - if (actor->sector()->ceilingpicnum == FAF_PLACE_MIRROR_PIC+1) - actor->sector()->ceilingpicnum = FAF_MIRROR_PIC+1; + if (actor->sector()->ceilingtexture() == FAFPlaceMirrorPic[1]) + actor->sector()->setceilingtexture(FAFMirrorPic[1]); - if (actor->sector()->floorpicnum == FAF_PLACE_MIRROR_PIC+1) - actor->sector()->floorpicnum = FAF_MIRROR_PIC+1; + if (actor->sector()->floortexture() == FAFPlaceMirrorPic[1]) + actor->sector()->setfloortexture(FAFMirrorPic[1]); } } @@ -908,7 +908,7 @@ void CollectPortals() for (unsigned i = 0; i < sector.Size(); i++) { - if (sector[i].floorpicnum == FAF_MIRROR_PIC && !floordone[i]) + if (sector[i].floortexture() == FAFMirrorPic[0] && !floordone[i]) { auto& fp = floorportals[floorportals.Reserve(1)]; fp.sectors.Push(i); @@ -920,13 +920,13 @@ void CollectPortals() if (!wal.twoSided()) continue; auto nsec = wal.nextSector(); auto ns = sectindex(nsec); - if (floordone[ns] || nsec->floorpicnum != FAF_MIRROR_PIC) continue; + if (floordone[ns] || nsec->floortexture() != FAFMirrorPic[0]) continue; fp.sectors.Push(ns); floordone.Set(ns); } } } - if (sector[i].ceilingpicnum == FAF_MIRROR_PIC && !ceilingdone[i]) + if (sector[i].ceilingtexture() == FAFMirrorPic[0] && !ceilingdone[i]) { auto& fp = ceilingportals[ceilingportals.Reserve(1)]; fp.sectors.Push(i); @@ -938,7 +938,7 @@ void CollectPortals() if (!wal.twoSided()) continue; auto nsec = wal.nextSector(); auto ns = sectindex(nsec); - if (ceilingdone[ns] || nsec->ceilingpicnum != FAF_MIRROR_PIC) continue; + if (ceilingdone[ns] || nsec->ceilingtexture() != FAFMirrorPic[0]) continue; fp.sectors.Push(ns); ceilingdone.Set(ns); } @@ -961,7 +961,7 @@ void CollectPortals() if (match != -1) { FindCeilingView(match, &tpos.X, &tpos.Y, tpos.Z, &tsect); - if (tsect != nullptr &&tsect->floorpicnum == FAF_MIRROR_PIC) + if (tsect != nullptr &&tsect->floortexture() == FAFMirrorPic[0]) { // got something! fp.othersector = sectindex(tsect); @@ -988,7 +988,7 @@ void CollectPortals() if (match != -1) { FindFloorView(match, &tpos.X, &tpos.Y, tpos.Z, &tsect); - if (tsect != nullptr && tsect->ceilingpicnum == FAF_MIRROR_PIC) + if (tsect != nullptr && tsect->ceilingtexture() == FAFMirrorPic[0]) { // got something! fp.othersector = sectindex(tsect); diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 0b3e37f13..8db348c14 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -191,11 +191,11 @@ void WallSetup(void) for (auto& wal : wall) { - if (wal.wallpicnum == FAF_PLACE_MIRROR_PIC) - wal.wallpicnum = FAF_MIRROR_PIC; + if (wal.walltexture() == FAFPlaceMirrorPic[0]) + wal.setwalltexture(FAFMirrorPic[0]); - if (wal.wallpicnum == FAF_PLACE_MIRROR_PIC+1) - wal.wallpicnum = FAF_MIRROR_PIC+1; + if (wal.walltexture() == FAFPlaceMirrorPic[1]) + wal.setwalltexture(FAFMirrorPic[1]); // this overwrites the lotag so it needs to be called LAST - its down there // SetupWallForBreak(wp); @@ -453,7 +453,7 @@ void SectorSetup(void) if ((sectp->floorstat & CSTAT_SECTOR_SKY)) { // don't do a z adjust for FAF area - if (sectp->floorpicnum != FAF_PLACE_MIRROR_PIC) + if (sectp->floortexture() != FAFPlaceMirrorPic[0]) { sectp->extra |= (SECTFX_Z_ADJUST); } @@ -462,7 +462,7 @@ void SectorSetup(void) if ((sectp->ceilingstat & CSTAT_SECTOR_SKY)) { // don't do a z adjust for FAF area - if (sectp->ceilingpicnum != FAF_PLACE_MIRROR_PIC) + if (sectp->ceilingtexture() != FAFPlaceMirrorPic[0]) { sectp->extra |= (SECTFX_Z_ADJUST); } diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 226712b17..7d2d5863f 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -4346,7 +4346,7 @@ bool WeaponMoveHit(DSWActor* actor) } } - if ((sectp->ceilingstat & CSTAT_SECTOR_SKY) && sectp->ceilingpicnum != FAF_MIRROR_PIC) + if ((sectp->ceilingstat & CSTAT_SECTOR_SKY) && sectp->ceilingtexture() != FAFMirrorPic[0]) { if (abs(actor->spr.pos.Z - sectp->ceilingz) < ActorSizeZ(actor)) {