- fixed parentheses in ADynamicLight::DistToSeg.

- floatifed OpenGL sector grouping.
- optimized light node collection. It should not create light nodes for out of range segs.
This commit is contained in:
Christoph Oelckers 2016-04-08 12:38:09 +02:00
parent 3e94832bfd
commit 25d7eaed0a
3 changed files with 29 additions and 26 deletions

View File

@ -102,7 +102,8 @@ GLSectorStackPortal *FPortal::GetGLPortal()
//========================================================================== //==========================================================================
// //
// // this is left as fixed_t because the nodes also are, it makes no sense
// to convert this without converting the nodes as well.
// //
//========================================================================== //==========================================================================

View File

@ -102,11 +102,11 @@ static void DoSetMapSection(subsector_t *sub, int num)
struct cvertex_t struct cvertex_t
{ {
fixed_t x, y; double X, Y;
operator int () const { return ((x>>16)&0xffff) | y; } operator int() const { return xs_FloorToInt(X) + 65536 * xs_FloorToInt(Y); }
bool operator!= (const cvertex_t &other) const { return x != other.x || y != other.y; } bool operator!= (const cvertex_t &other) const { return fabs(X - other.X) >= EQUAL_EPSILON || fabs(Y - other.Y) >= EQUAL_EPSILON; }
cvertex_t& operator =(const vertex_t *v) { x = v->fixX(); y = v->fixY(); return *this; } cvertex_t& operator =(const vertex_t *v) { X = v->fX(); Y = v->fY(); return *this; }
}; };
typedef TMap<cvertex_t, int> FSectionVertexMap; typedef TMap<cvertex_t, int> FSectionVertexMap;

View File

@ -4,7 +4,7 @@
** **
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** Copyright 2003 Timothy Stump ** Copyright 2003 Timothy Stump
** Copyright 2005 Christoph Oelckers ** Copyright 2005-2016 Christoph Oelckers
** All rights reserved. ** All rights reserved.
** **
** Redistribution and use in source and binary forms, with or without ** Redistribution and use in source and binary forms, with or without
@ -515,7 +515,7 @@ double ADynamicLight::DistToSeg(const DVector3 &pos, seg_t *seg)
double seg_dy = seg->v2->fY() - seg->v1->fY(); double seg_dy = seg->v2->fY() - seg->v1->fY();
double seg_length_sq = seg_dx * seg_dx + seg_dy * seg_dy; double seg_length_sq = seg_dx * seg_dx + seg_dy * seg_dy;
u = ((pos.X - seg->v1->fX()) * seg_dx + pos.Y - seg->v1->fY()) * seg_dy / seg_length_sq; u = (((pos.X - seg->v1->fX()) * seg_dx) + (pos.Y - seg->v1->fY()) * seg_dy) / seg_length_sq;
if (u < 0.) u = 0.; // clamp the test point to the line segment if (u < 0.) u = 0.; // clamp the test point to the line segment
else if (u > 1.) u = 1.; else if (u > 1.) u = 1.;
@ -553,10 +553,14 @@ void ADynamicLight::CollectWithinRadius(const DVector3 &pos, subsector_t *subSec
{ {
seg_t * seg = subSec->firstline + i; seg_t * seg = subSec->firstline + i;
if (seg->sidedef && seg->linedef && seg->linedef->validcount!=::validcount) // check distance from x/y to seg and if within radius add this seg and, if present the opposing subsector (lather/rinse/repeat)
// If out of range we do not need to bother with this seg.
if (DistToSeg(pos, seg) <= radius)
{
if (seg->sidedef && seg->linedef && seg->linedef->validcount != ::validcount)
{ {
// light is in front of the seg // light is in front of the seg
if ((pos.Y - seg->v1->fixY()) * (seg->v2->fX() - seg->v1->fixX()) + (seg->v1->fX() - pos.X * (seg->v2->fY() - seg->v1->fY())) <= 0) if ((pos.Y - seg->v1->fY()) * (seg->v2->fX() - seg->v1->fX()) + (seg->v1->fX() - pos.X * (seg->v2->fY() - seg->v1->fY())) <= 0)
{ {
seg->linedef->validcount = validcount; seg->linedef->validcount = validcount;
touching_sides = AddLightNode(&seg->sidedef->lighthead, seg->sidedef, this, touching_sides); touching_sides = AddLightNode(&seg->sidedef->lighthead, seg->sidedef, this, touching_sides);
@ -566,8 +570,6 @@ void ADynamicLight::CollectWithinRadius(const DVector3 &pos, subsector_t *subSec
{ {
FLinePortal *port = seg->linedef->getPortal(); FLinePortal *port = seg->linedef->getPortal();
if (port && port->mType == PORTT_LINKED) if (port && port->mType == PORTT_LINKED)
{
if (DistToSeg(pos, seg) <= radius)
{ {
line_t *other = port->mDestination; line_t *other = port->mDestination;
if (other->validcount != ::validcount) if (other->validcount != ::validcount)
@ -577,16 +579,12 @@ void ADynamicLight::CollectWithinRadius(const DVector3 &pos, subsector_t *subSec
} }
} }
} }
}
seg_t *partner = seg->PartnerSeg; seg_t *partner = seg->PartnerSeg;
if (partner) if (partner)
{ {
subsector_t *sub = partner->Subsector; subsector_t *sub = partner->Subsector;
if (sub != NULL && sub->validcount!=::validcount) if (sub != NULL && sub->validcount != ::validcount)
{
// check distance from x/y to seg and if within radius add opposing subsector (lather/rinse/repeat)
if (DistToSeg(pos, seg) <= radius)
{ {
CollectWithinRadius(pos, sub, radius); CollectWithinRadius(pos, sub, radius);
} }
@ -625,6 +623,10 @@ void ADynamicLight::CollectWithinRadius(const DVector3 &pos, subsector_t *subSec
void ADynamicLight::LinkLight() void ADynamicLight::LinkLight()
{ {
if (X() == 1088 && Y() == 2832)
{
int a = 0;
}
// mark the old light nodes // mark the old light nodes
FLightNode * node; FLightNode * node;