diff --git a/source/core/rendering/hw_entrypoint.cpp b/source/core/rendering/hw_entrypoint.cpp index b38dfecca..f41a25754 100644 --- a/source/core/rendering/hw_entrypoint.cpp +++ b/source/core/rendering/hw_entrypoint.cpp @@ -381,9 +381,7 @@ FSerializer& Serialize(FSerializer& arc, const char* key, PortalDesc& obj, Porta if (arc.BeginObject(key)) { arc("type", obj.type) - ("dx", obj.dx) - ("dy", obj.dy) - ("dz", obj.dz) + ("d", obj.delta) ("targets", obj.targets) .EndObject(); } diff --git a/source/core/rendering/hw_sections.cpp b/source/core/rendering/hw_sections.cpp index 6465dd020..72ca158b8 100644 --- a/source/core/rendering/hw_sections.cpp +++ b/source/core/rendering/hw_sections.cpp @@ -42,6 +42,7 @@ #include "hw_sections.h" #include "memarena.h" #include "c_cvars.h" +#include "gamefuncs.h" void CreateVertexMap(); diff --git a/source/core/rendering/render.h b/source/core/rendering/render.h index 4270164a2..ba43b0b16 100644 --- a/source/core/rendering/render.h +++ b/source/core/rendering/render.h @@ -11,7 +11,7 @@ void render_camtex(DCoreActor* playersprite, const DVector3& position, sectortyp struct PortalDesc { int type; - int dx, dy, dz; + DVector3 delta; TArray targets; }; @@ -30,9 +30,7 @@ inline int portalAdd(int type, int target, const DVector3& offset) auto& pt = allPortals[allPortals.Reserve(1)]; pt.type = type; if (target >= 0) pt.targets.Push(target); - pt.dx = offset.X * worldtoint; - pt.dy = offset.Y * worldtoint; - pt.dz = offset.Z * zworldtoint; + pt.delta = offset; return allPortals.Size() - 1; } @@ -52,7 +50,7 @@ inline void mergePortals() for (unsigned j = i + 1; j < allPortals.Size(); j++) { auto& pt2 = allPortals[j]; - if (pt1.type != pt2.type || pt1.dx != pt2.dx || pt1.dy != pt2.dy || pt1.dz != pt2.dz) continue; + if (pt1.type != pt2.type || pt1.delta != pt2.delta) continue; for (unsigned s = 0; s < pt1.targets.Size() && pt2.targets.Size(); s++) { for (unsigned t = 0; t < pt2.targets.Size(); t++) diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index b4483d664..83129beb1 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -796,7 +796,7 @@ bool HWSectorStackPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c auto portal = origin; auto &vp = di->Viewpoint; - vp.Pos += DVector3(portal->dx / 16., portal->dy / -16., portal->dz / -256.); + vp.Pos += DVector3(portal->delta.X, -portal->delta.Y, -portal->delta.Z); vp.SectNums = portal->targets.Data(); vp.SectCount = portal->targets.Size(); type = origin->type; diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 6ef174016..66aca1671 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -855,12 +855,13 @@ static void SpawnPortals() { if (act->spr.picnum == SECTOREFFECTOR && act->spr.lotag == tag) { - if (processedTags.Find(act->spr.hitag) == processedTags.Size()) + int hitag = act->spr.hitag; + if (processedTags.Find(hitag) == processedTags.Size()) { DukeStatIterator it2(STAT_RAROR); while (auto act2 = it2.Next()) { - if (act2->spr.picnum == SECTOREFFECTOR && act2->spr.lotag == tag + 1 && act2->spr.hitag == act->spr.hitag) + if (act2->spr.picnum == SECTOREFFECTOR && act2->spr.lotag == tag + 1 && act2->spr.hitag == hitag) { if (processedTags.Find(act->spr.hitag) == processedTags.Size()) { @@ -868,15 +869,15 @@ static void SpawnPortals() s1->portalflags = PORTAL_SECTOR_FLOOR; s2->portalflags = PORTAL_SECTOR_CEILING; DVector2 diff = act->spr.pos.XY() - act2->spr.pos.XY(); - s1->portalnum = portalAdd(PORTAL_SECTOR_FLOOR, sectnum(s2), DVector3(-diff, act->spr.hitag * zmaptoworld)); - s2->portalnum = portalAdd(PORTAL_SECTOR_CEILING, sectnum(s1), DVector3(diff, act->spr.hitag * zmaptoworld)); + s1->portalnum = portalAdd(PORTAL_SECTOR_FLOOR, sectnum(s2), DVector3(-diff, hitag)); // uses delta.Z as temporary storage, not a real coordinate. + s2->portalnum = portalAdd(PORTAL_SECTOR_CEILING, sectnum(s1), DVector3(diff, hitag)); processedTags.Push(act->spr.hitag); } else { for (auto& p : allPortals) { - if (p.type == PORTAL_SECTOR_FLOOR && p.dz == act->spr.hitag) + if (p.type == PORTAL_SECTOR_FLOOR && p.delta.Z == hitag) { p.targets.Push(act2->sectno()); } @@ -889,7 +890,7 @@ static void SpawnPortals() { for (auto& p : allPortals) { - if (p.type == PORTAL_SECTOR_CEILING && p.dz == act->spr.hitag) + if (p.type == PORTAL_SECTOR_CEILING && p.delta.Z == hitag) { p.targets.Push(act->sectno()); } @@ -942,7 +943,8 @@ static void SpawnPortals() } nexti:; } - for (auto& p : allPortals) p.dz = 0; + // clean out the tags we stored in delta.Z + for (auto& p : allPortals) p.delta.Z = 0; mergePortals(); }