- floatified the portal displacement

This commit is contained in:
Christoph Oelckers 2022-09-16 19:56:46 +02:00
parent c87b4a581b
commit c44fd07f37
5 changed files with 15 additions and 16 deletions

View file

@ -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();
}

View file

@ -42,6 +42,7 @@
#include "hw_sections.h"
#include "memarena.h"
#include "c_cvars.h"
#include "gamefuncs.h"
void CreateVertexMap();

View file

@ -11,7 +11,7 @@ void render_camtex(DCoreActor* playersprite, const DVector3& position, sectortyp
struct PortalDesc
{
int type;
int dx, dy, dz;
DVector3 delta;
TArray<int> 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++)

View file

@ -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;

View file

@ -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();
}