Skip to content

Commit

Permalink
Client|Bias Lighting: Cleanup
Browse files Browse the repository at this point in the history
Also added a TODO comment about the under performing algorithm used
for unlinking BiasSurface data in SB_DestroySurface()
  • Loading branch information
danij-deng committed Jun 19, 2013
1 parent 1ac4221 commit 5d15fe9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 84 deletions.
14 changes: 8 additions & 6 deletions doomsday/client/include/render/rend_bias.h
Expand Up @@ -45,8 +45,8 @@ typedef struct vilight_s {
#define VIF_STILL_UNSEEN 0x2 ///< The color of the vertex is still unknown.

typedef struct vertexillum_s {
float color[3]; // Current color of the vertex.
float dest[3]; // Destination color of the vertex.
float color[3]; // Current light at the vertex.
float dest[3]; // Destination light at the vertex (interpolated to).
uint updatetime; // When the value was calculated.
short flags;
vilight_t casted[MAX_BIAS_AFFECTED];
Expand Down Expand Up @@ -107,13 +107,15 @@ void SB_Register();
*/
void SB_InitForMap();

void SB_InitVertexIllum(vertexillum_t *villum);
void SB_VertexIllumInit(vertexillum_t &illum);

BiasSurface *SB_CreateSurface(void);
BiasSurface *SB_CreateSurface();

void SB_DestroySurface(BiasSurface *bsuf);
void SB_DestroySurface(BiasSurface &bsuf);

void SB_SurfaceMoved(BiasSurface *bsuf);
//void SB_SurfaceInit(BiasSurface &bsuf);

void SB_SurfaceMoved(BiasSurface &bsuf);

/**
* Do initial processing that needs to be done before rendering a
Expand Down
117 changes: 46 additions & 71 deletions doomsday/client/src/render/rend_bias.cpp
Expand Up @@ -34,32 +34,36 @@

using namespace de;

static float const biasIgnoreLimit = .005f;

BEGIN_PROF_TIMERS()
PROF_BIAS_UPDATE
END_PROF_TIMERS()

typedef struct affection_s {
struct Affection
{
float intensities[MAX_BIAS_AFFECTED];
int numFound;
biasaffection_t *affected;
} affection_t;
};

void SB_EvalPoint(float light[4], vertexillum_t *illum, biasaffection_t *affectedSources,
Vector3d const &point, Vector3f const &normal);

int useBias;
int numSources;
int useBias; //cvar

static int useSightCheck = true; //cvar
static float biasMin = .85f; //cvar
static float biasMax = 1.f; //cvar
static int doUpdateAffected = true; //cvar
static int lightSpeed = 130; //cvar

uint currentTimeSB;

int numSources;
static source_t sources[MAX_BIAS_LIGHTS];
static int numSourceDelta;

static int useSightCheck = true;
static float biasMin = .85f;
static float biasMax = 1.f;
static int doUpdateAffected = true;
static float biasIgnoreLimit = .005f;
static int lightSpeed = 130;
static uint lastChangeOnFrame;

/**
Expand Down Expand Up @@ -88,77 +92,52 @@ void SB_Register()
C_VAR_INT("rend-dev-bias-sight", &useSightCheck, CVF_NO_ARCHIVE, 0, 1);

C_VAR_INT("rend-dev-bias-affected", &doUpdateAffected, CVF_NO_ARCHIVE, 0, 1);

/* C_VAR_INT("rend-dev-bias-solo", &editSelector, CVF_NO_ARCHIVE, -1, 255);*/
}

static inline BiasSurface *allocBiasSurface()
{
if(biasSurfaceBlockSet)
{
// Use the block allocator.
BiasSurface *bsuf = (BiasSurface *) ZBlockSet_Allocate(biasSurfaceBlockSet);
std::memset(bsuf, 0, sizeof(*bsuf));
return bsuf;
}

return (BiasSurface *) M_Calloc(sizeof(BiasSurface));
}

static inline void freeBiasSurface(BiasSurface *bsuf)
{
if(biasSurfaceBlockSet)
{
// Ignore, it'll be free'd along with the block allocator.
return;
}

M_Free(bsuf);
}

BiasSurface *SB_CreateSurface()
{
BiasSurface *bsuf = allocBiasSurface();
DENG_ASSERT(biasSurfaceBlockSet != 0);

BiasSurface *bsuf = (BiasSurface *) ZBlockSet_Allocate(biasSurfaceBlockSet);
zapPtr(bsuf);

// Link it in to the global list.
// Link it in the global list.
bsuf->next = surfaces;
surfaces = bsuf;

return bsuf;
}

void SB_DestroySurface(BiasSurface *bsuf)
void SB_DestroySurface(BiasSurface &bsuf)
{
if(!bsuf) return;

// Unlink this surface from the global list.
/// @todo Optimize: This O(n) algorithm is entirely inadequate given the scale
/// of "modern" maps which can often require upward of 150k surfaces.
if(surfaces)
{
if(bsuf == surfaces)
if(&bsuf == surfaces)
{
surfaces = surfaces->next;
}
else if(surfaces->next)
else
{
BiasSurface *p = surfaces->next, *last = surfaces;

do
BiasSurface *last = surfaces;
BiasSurface *p = last;
while((p = p->next))
{
if(p == bsuf)
if(p == &bsuf)
{
last->next = p->next;
break;
}

last = p;
p = p->next;
} while(p);
}
}
}

/// Bias surfaces and vertex illum data is block-allocated.
//Z_Free(bsuf->illum);
//Z_Free(bsuf);
//Z_Free(bsuf.illum);
//Z_Free(&bsuf);
}

int SB_NewSourceAt(coord_t x, coord_t y, coord_t z, float size, float minLight,
Expand Down Expand Up @@ -314,7 +293,7 @@ static void prepareSurfaces(Map &map)
vertexillum_t *illums = (vertexillum_t *) Z_Calloc(sizeof(*illums) * numVertIllums, PU_MAP, 0);
for(size_t i = 0; i < numVertIllums; ++i)
{
SB_InitVertexIllum(&illums[i]);
SB_VertexIllumInit(illums[i]);
}

// Allocate bias surfaces and attach vertexillum_ts.
Expand Down Expand Up @@ -409,7 +388,7 @@ void SB_SetColor(float *dest, float *src)
}
}

static void SB_AddAffected(affection_t *aff, uint sourceIdx, float intensity)
static void SB_AddAffected(Affection *aff, uint sourceIdx, float intensity)
{
DENG_ASSERT(aff);

Expand All @@ -435,33 +414,29 @@ static void SB_AddAffected(affection_t *aff, uint sourceIdx, float intensity)
}
}

void SB_InitVertexIllum(vertexillum_t *villum)
void SB_VertexIllumInit(vertexillum_t &illum)
{
DENG_ASSERT(villum);

villum->flags |= VIF_STILL_UNSEEN;
illum.flags |= VIF_STILL_UNSEEN;

for(int i = 0; i < MAX_BIAS_AFFECTED; ++i)
villum->casted[i].source = -1;
{
illum.casted[i].source = -1;
}
}

void SB_SurfaceInit(BiasSurface *bsuf)
void SB_SurfaceInit(BiasSurface &bsuf)
{
DENG_ASSERT(bsuf);

for(uint i = 0; i < bsuf->size; ++i)
for(uint i = 0; i < bsuf.size; ++i)
{
SB_InitVertexIllum(&bsuf->illum[i]);
SB_VertexIllumInit(bsuf.illum[i]);
}
}

void SB_SurfaceMoved(BiasSurface *bsuf)
void SB_SurfaceMoved(BiasSurface &bsuf)
{
DENG_ASSERT(bsuf);

for(int i = 0; i < MAX_BIAS_AFFECTED && bsuf->affected[i].source >= 0; ++i)
for(int i = 0; i < MAX_BIAS_AFFECTED && bsuf.affected[i].source >= 0; ++i)
{
sources[bsuf->affected[i].source].flags |= BLF_CHANGED;
sources[bsuf.affected[i].source].flags |= BLF_CHANGED;
}
}

Expand All @@ -487,7 +462,7 @@ static void updateAffected(BiasSurface *bsuf, Vector2d const &from,

bsuf->updated = lastChangeOnFrame;

affection_t aff;
Affection aff;
aff.affected = bsuf->affected;
aff.numFound = 0;
std::memset(aff.affected, -1, sizeof(bsuf->affected));
Expand Down Expand Up @@ -541,7 +516,7 @@ static void updateAffected2(BiasSurface *bsuf, struct rvertex_s const *rvertices

bsuf->updated = lastChangeOnFrame;

affection_t aff;
Affection aff;
aff.affected = bsuf->affected;
aff.numFound = 0;
std::memset(aff.affected, -1, sizeof(bsuf->affected)); // array of MAX_BIAS_AFFECTED
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -123,7 +123,7 @@ DENG2_PIMPL(BspLeaf)
{
for(int i = 0; i < sector->planeCount(); ++i)
{
SB_DestroySurface(biasSurfaces[i]);
SB_DestroySurface(*biasSurfaces[i]);
}
Z_Free(biasSurfaces);
}
Expand Down Expand Up @@ -521,7 +521,7 @@ void BspLeaf::setBiasSurface(int groupId, BiasSurface *biasSurface)
}
else if(d->biasSurfaces[groupId])
{
SB_DestroySurface(d->biasSurfaces[groupId]);
SB_DestroySurface(*d->biasSurfaces[groupId]);
}

d->biasSurfaces[groupId] = biasSurface;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/polyobj.cpp
Expand Up @@ -58,7 +58,7 @@ static void notifyGeometryChanged(Polyobj &po)

for(int i = 0; i < 3; ++i)
{
SB_SurfaceMoved(&segment->biasSurface(i));
SB_SurfaceMoved(segment->biasSurface(i));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -181,11 +181,11 @@ DENG2_OBSERVES(Plane, HeightChange)

for(uint i = 0; i < 3; ++i)
{
SB_SurfaceMoved(&seg->biasSurface(i));
SB_SurfaceMoved(seg->biasSurface(i));
}
}

SB_SurfaceMoved(&bspLeaf->biasSurface(plane.inSectorIndex()));
SB_SurfaceMoved(bspLeaf->biasSurface(plane.inSectorIndex()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/segment.cpp
Expand Up @@ -80,11 +80,11 @@ DENG2_PIMPL(Segment)
~Instance()
{
#ifdef __CLIENT__
for(uint i = 0; i < 3; ++i)
for(int i = 0; i < 3; ++i)
{
if(bsuf[i])
{
SB_DestroySurface(bsuf[i]);
SB_DestroySurface(*bsuf[i]);
}
}
#endif
Expand Down

0 comments on commit 5d15fe9

Please sign in to comment.