Skip to content

Commit

Permalink
Cleaned up wall divisions in preparation for further refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed May 22, 2012
1 parent 7c1b1a2 commit 90ee984
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 76 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/hedge.h
Expand Up @@ -40,7 +40,7 @@ void HEdge_Delete(HEdge* hedge);

boolean HEdge_PrepareWallDivs(HEdge* hedge, SideDefSection section,
Sector* frontSector, Sector* backSector,
walldiv_t* leftWallDivs, walldiv_t* rightWallDivs, float matOffset[2]);
walldivs_t* leftWallDivs, walldivs_t* rightWallDivs, float matOffset[2]);

/**
* Get a property value, selected by DMU_* name.
Expand Down
28 changes: 17 additions & 11 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -145,11 +145,17 @@ typedef struct glcommand_vertex_s {
int index;
} glcommand_vertex_t;

#define RL_MAX_DIVS 64
typedef struct walldiv_s {
unsigned int num;
coord_t pos[RL_MAX_DIVS];
} walldiv_t;
/// Maximum number of walldivnode_ts in a walldivs_t dataset.
#define WALLDIVS_MAX_NODES 64

typedef struct walldivnode_s {
coord_t height;
} walldivnode_t;

typedef struct walldivs_s {
uint num;
walldivnode_t nodes[WALLDIVS_MAX_NODES];
} walldivs_t;

typedef struct rvertex_s {
float pos[3];
Expand Down Expand Up @@ -298,14 +304,14 @@ void R_FreeRendColors(ColorRawf* rcolors);
void R_FreeRendTexCoords(rtexcoord_t* rtexcoords);
void R_InfoRendVerticesPool(void);

void R_DivVerts(rvertex_t* dst, const rvertex_t* src, const walldiv_t* leftDivs,
const walldiv_t* rightDivs);
void R_DivVerts(rvertex_t* dst, const rvertex_t* src, const walldivs_t* leftDivs,
const walldivs_t* rightDivs);

void R_DivVertColors(ColorRawf* dst, const ColorRawf* src, const walldiv_t* leftDivs,
const walldiv_t* rightDivs, float bL, float tL, float bR, float tR);
void R_DivVertColors(ColorRawf* dst, const ColorRawf* src, const walldivs_t* leftDivs,
const walldivs_t* rightDivs, float bL, float tL, float bR, float tR);

void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldiv_t* leftDivs,
const walldiv_t* rightDivs, float bL, float tL, float bR, float tR);
void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldivs_t* leftDivs,
const walldivs_t* rightDivs, float bL, float tL, float bR, float tR);

void R_InitTranslationTables(void);
void R_UpdateTranslationTables(void);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/rend_dynlight.h
Expand Up @@ -32,8 +32,8 @@ typedef struct {
uint numVertices, realNumVertices;
const coord_t* texTL, *texBR;
boolean isWall;
const walldiv_t* leftWallDivs;
const walldiv_t* rightWallDivs;
const walldivs_t* leftWallDivs;
const walldivs_t* rightWallDivs;
} renderlightprojectionparams_t;

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/rend_fakeradio.h
Expand Up @@ -55,7 +55,7 @@ void Rend_RadioUpdateLinedef(LineDef* line, boolean backSide);
* Render FakeRadio for the given hedge section.
*/
void Rend_RadioSegSection(const rvertex_t* rvertices,
const walldiv_t* leftWallDivs, const walldiv_t* rightWallDivs,
const walldivs_t* leftWallDivs, const walldivs_t* rightWallDivs,
const rendsegradio_params_t* params);

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/rend_shadow.h
Expand Up @@ -49,8 +49,8 @@ typedef struct {
uint numVertices, realNumVertices;
const coord_t* texTL, *texBR;
boolean isWall;
const walldiv_t* leftWallDivs;
const walldiv_t* rightWallDivs;
const walldivs_t* leftWallDivs;
const walldivs_t* rightWallDivs;
} rendershadowprojectionparams_t;

/**
Expand Down
41 changes: 21 additions & 20 deletions doomsday/engine/portable/src/hedge.cpp
Expand Up @@ -27,25 +27,26 @@

static int C_DECL sortWallDivNode(const void* e1, const void* e2)
{
const coord_t f1 = *(coord_t*)e1;
const coord_t f2 = *(coord_t*)e2;
if(f1 > f2) return 1;
if(f2 > f1) return -1;
const coord_t h1 = ((walldivnode_t*)e1)->height;
const coord_t h2 = ((walldivnode_t*)e2)->height;
if(h1 > h2) return 1;
if(h2 > h1) return -1;
return 0;
}

static coord_t* findWallDivNodeByZOrigin(walldiv_t* wallDivs, float height)
static walldivnode_t* findWallDivNodeByZOrigin(walldivs_t* wallDivs, float height)
{
Q_ASSERT(wallDivs);
for(uint i = 0; i < wallDivs->num; ++i)
{
if(wallDivs->pos[i] == height)
return &wallDivs->pos[i];
walldivnode_t* node = &wallDivs->nodes[i];
if(node->height == height)
return node;
}
return NULL;
}

static void addWallDivNodesForPlaneIntercepts(HEdge* hedge, walldiv_t* wallDivs,
static void addWallDivNodesForPlaneIntercepts(HEdge* hedge, walldivs_t* wallDivs,
SideDefSection section, coord_t bottomZ, coord_t topZ, boolean doRight)
{
const boolean isTwoSided = (hedge->lineDef && hedge->lineDef->L_frontside && hedge->lineDef->L_backside)? true:false;
Expand Down Expand Up @@ -109,10 +110,10 @@ static void addWallDivNodesForPlaneIntercepts(HEdge* hedge, walldiv_t* wallDivs,
{
if(!findWallDivNodeByZOrigin(wallDivs, pln->visHeight))
{
wallDivs->pos[wallDivs->num++] = pln->visHeight;
wallDivs->nodes[wallDivs->num++].height = pln->visHeight;

// Have we reached the div limit?
if(wallDivs->num == RL_MAX_DIVS)
if(wallDivs->num == WALLDIVS_MAX_NODES)
stopScan = true;
}
}
Expand Down Expand Up @@ -146,10 +147,10 @@ static void addWallDivNodesForPlaneIntercepts(HEdge* hedge, walldiv_t* wallDivs,
{
if(!findWallDivNodeByZOrigin(wallDivs, z))
{
wallDivs->pos[wallDivs->num++] = z;
wallDivs->nodes[wallDivs->num++].height = z;

// Have we reached the div limit?
if(wallDivs->num == RL_MAX_DIVS)
if(wallDivs->num == WALLDIVS_MAX_NODES)
stopScan = true;
}
}
Expand All @@ -164,42 +165,42 @@ static void addWallDivNodesForPlaneIntercepts(HEdge* hedge, walldiv_t* wallDivs,
} while(!stopScan);
}

static void buildWallDiv(walldiv_t* wallDivs, HEdge* hedge,
static void buildWallDiv(walldivs_t* wallDivs, HEdge* hedge,
SideDefSection section, coord_t bottomZ, coord_t topZ, boolean doRight)
{
wallDivs->num = 0;

// Add the first node.
wallDivs->pos[wallDivs->num++] = bottomZ;
wallDivs->nodes[wallDivs->num++].height = bottomZ;

// Add nodes for intercepts.
addWallDivNodesForPlaneIntercepts(hedge, wallDivs, section, bottomZ, topZ, doRight);

// Add the last node.
wallDivs->pos[wallDivs->num++] = topZ;
wallDivs->nodes[wallDivs->num++].height = topZ;

if(!(wallDivs->num > 2)) return;

// Sorting is required. This shouldn't take too long...
// There seldom are more than two or three nodes.
qsort(wallDivs->pos, wallDivs->num, sizeof(*wallDivs->pos), sortWallDivNode);
qsort(wallDivs->nodes, wallDivs->num, sizeof(*wallDivs->nodes), sortWallDivNode);

#ifdef RANGECHECK
for(uint i = 1; i < wallDivs->num - 1; ++i)
{
const coord_t pos = wallDivs->pos[i];
if(pos > topZ || pos < bottomZ)
const walldivnode_t* node = &wallDivs->nodes[i];
if(node->height > topZ || node->height < bottomZ)
{
Con_Error("WallDiv node #%i pos (%f) <> hi (%f), low (%f), num=%i\n",
i, pos, topZ, bottomZ, wallDivs->num);
i, node->height, topZ, bottomZ, wallDivs->num);
}
}
#endif
}

boolean HEdge_PrepareWallDivs(HEdge* hedge, SideDefSection section,
Sector* frontSec, Sector* backSec,
walldiv_t* leftWallDivs, walldiv_t* rightWallDivs, float matOffset[2])
walldivs_t* leftWallDivs, walldivs_t* rightWallDivs, float matOffset[2])
{
Q_ASSERT(hedge);
SideDef* frontSide = HEDGE_SIDEDEF(hedge);
Expand Down
24 changes: 12 additions & 12 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -896,8 +896,8 @@ void Rtu_TranslateOffsetv(rtexmapunit_t* rtu, float const st[2])
Rtu_TranslateOffset(rtu, st[0], st[1]);
}

void R_DivVerts(rvertex_t* dst, const rvertex_t* src, const walldiv_t* leftDivs,
const walldiv_t* rightDivs)
void R_DivVerts(rvertex_t* dst, const rvertex_t* src, const walldivs_t* leftDivs,
const walldivs_t* rightDivs)
{
#define COPYVERT(d, s) (d)->pos[VX] = (s)->pos[VX]; \
(d)->pos[VY] = (s)->pos[VY]; \
Expand All @@ -919,7 +919,7 @@ void R_DivVerts(rvertex_t* dst, const rvertex_t* src, const walldiv_t* leftDivs,
{
dst[numL + 2 + i].pos[VX] = src[2].pos[VX];
dst[numL + 2 + i].pos[VY] = src[2].pos[VY];
dst[numL + 2 + i].pos[VZ] = rightDivs->pos[rightDivs->num-1 - 1 - i];
dst[numL + 2 + i].pos[VZ] = rightDivs->nodes[rightDivs->num-1 - 1 - i].height;
}

// Left fan:
Expand All @@ -931,14 +931,14 @@ void R_DivVerts(rvertex_t* dst, const rvertex_t* src, const walldiv_t* leftDivs,
{
dst[2 + i].pos[VX] = src[0].pos[VX];
dst[2 + i].pos[VY] = src[0].pos[VY];
dst[2 + i].pos[VZ] = leftDivs->pos[1 + i];
dst[2 + i].pos[VZ] = leftDivs->nodes[1 + i].height;
}

#undef COPYVERT
}

void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldiv_t* leftDivs,
const walldiv_t* rightDivs, float bL, float tL, float bR, float tR)
void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldivs_t* leftDivs,
const walldivs_t* rightDivs, float bL, float tL, float bR, float tR)
{
#define COPYTEXCOORD(d, s) (d)->st[0] = (s)->st[0]; \
(d)->st[1] = (s)->st[1];
Expand All @@ -959,7 +959,7 @@ void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldiv_t* l
height = tR - bR;
for(i = 0; i < rightDivs->num - 2; ++i)
{
float inter = (rightDivs->pos[rightDivs->num-1 - 1 - i] - bR) / height;
float inter = (rightDivs->nodes[rightDivs->num-1 - 1 - i].height - bR) / height;

dst[numL + 2 + i].st[0] = src[3].st[0];
dst[numL + 2 + i].st[1] = src[2].st[1] +
Expand All @@ -974,7 +974,7 @@ void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldiv_t* l
height = tL - bL;
for(i = 0; i < leftDivs->num - 2; ++i)
{
float inter = (leftDivs->pos[1 + i] - bL) / height;
float inter = (leftDivs->nodes[1 + i].height - bL) / height;

dst[2 + i].st[0] = src[0].st[0];
dst[2 + i].st[1] = src[0].st[1] +
Expand All @@ -984,8 +984,8 @@ void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src, const walldiv_t* l
#undef COPYTEXCOORD
}

void R_DivVertColors(ColorRawf* dst, const ColorRawf* src, const walldiv_t* leftDivs,
const walldiv_t* rightDivs, float bL, float tL, float bR, float tR)
void R_DivVertColors(ColorRawf* dst, const ColorRawf* src, const walldivs_t* leftDivs,
const walldivs_t* rightDivs, float bL, float tL, float bR, float tR)
{
#define COPYVCOLOR(d, s) (d)->rgba[CR] = (s)->rgba[CR]; \
(d)->rgba[CG] = (s)->rgba[CG]; \
Expand All @@ -1009,7 +1009,7 @@ void R_DivVertColors(ColorRawf* dst, const ColorRawf* src, const walldiv_t* left
for(i = 0; i < rightDivs->num - 2; ++i)
{
uint c;
float inter = (rightDivs->pos[rightDivs->num-1 - 1 - i] - bR) / height;
float inter = (rightDivs->nodes[rightDivs->num-1 - 1 - i].height - bR) / height;

for(c = 0; c < 4; ++c)
{
Expand All @@ -1027,7 +1027,7 @@ void R_DivVertColors(ColorRawf* dst, const ColorRawf* src, const walldiv_t* left
for(i = 0; i < leftDivs->num - 2; ++i)
{
uint c;
float inter = (leftDivs->pos[1 + i] - bL) / height;
float inter = (leftDivs->nodes[1 + i].height - bL) / height;

for(c = 0; c < 4; ++c)
{
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/rend_fakeradio.c
Expand Up @@ -964,8 +964,8 @@ static void quadTexCoords(rtexcoord_t* tc, const rvertex_t* rverts,
tc[0].st[1] = tc[3].st[1] + (rverts[3].pos[VZ] - rverts[2].pos[VZ]) / texHeight;
}

static void renderShadowSeg(const rvertex_t* origVertices, const walldiv_t* leftWallDivs,
const walldiv_t* rightWallDivs, const rendershadowseg_params_t* p,
static void renderShadowSeg(const rvertex_t* origVertices, const walldivs_t* leftWallDivs,
const walldivs_t* rightWallDivs, const rendershadowseg_params_t* p,
const float shadowRGB[3], float shadowDark)
{
float texOrigin[2][3];
Expand Down Expand Up @@ -1054,7 +1054,7 @@ static void renderShadowSeg(const rvertex_t* origVertices, const walldiv_t* left
* Create the appropriate FakeRadio shadow polygons for the wall segment.
*/
static void rendRadioSegSection(const rvertex_t* rvertices,
const walldiv_t* leftWallDivs, const walldiv_t* rightWallDivs,
const walldivs_t* leftWallDivs, const walldivs_t* rightWallDivs,
const rendsegradio_params_t* p)
{
const coord_t* fFloor, *fCeil, *bFloor, *bCeil;
Expand Down Expand Up @@ -1146,8 +1146,8 @@ static void rendRadioSegSection(const rvertex_t* rvertices,
}
}

void Rend_RadioSegSection(const rvertex_t* rvertices, const walldiv_t* leftWallDivs,
const walldiv_t* rightWallDivs, const rendsegradio_params_t* params)
void Rend_RadioSegSection(const rvertex_t* rvertices, const walldivs_t* leftWallDivs,
const walldivs_t* rightWallDivs, const rendsegradio_params_t* params)
{
if(!rvertices || !params) return;
// Disabled?
Expand Down

0 comments on commit 90ee984

Please sign in to comment.