Navigation Menu

Skip to content

Commit

Permalink
Map Renderer: Began remodeling wall geometry construction
Browse files Browse the repository at this point in the history
Transitioning to an edge-centric model.
  • Loading branch information
danij-deng committed May 2, 2013
1 parent d578c42 commit 085b4a5
Show file tree
Hide file tree
Showing 12 changed files with 723 additions and 541 deletions.
49 changes: 49 additions & 0 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -29,6 +29,7 @@
#include "Vertex"

#include "render/rend_bias.h"
#include "render/walldiv.h"

class Sector;

Expand All @@ -40,6 +41,54 @@ class Sector;
#define HEDGEINF_FACINGFRONT 0x0001
///@}

class SectionEdge
{
public:
de::WallDivs wallDivs;

public:
SectionEdge(HEdge &hedge, int section, int right);

void prepare(coord_t bottom, coord_t top);

void configure() {
_firstIntercept = &wallDivs.first();
_lastIntercept = &wallDivs.last();
_interceptCount = wallDivs.count();
}

int divisionCount() const { return _interceptCount - 2; }

de::WallDivs::Intercept &firstDivision() const;

de::WallDivs::Intercept &lastDivision() const;

de::WallDivs::Intercept &bottom() const;

de::WallDivs::Intercept &top() const;

HEdge &hedge() const;

int section() const;

de::Vector2d const &origin() const;

coord_t offset() const;

private:
void assertDivisionsInRange(coord_t low, coord_t hi);

void addPlaneIntercepts(coord_t bottom, coord_t top);

HEdge *_hedge;
int _section;
int _right;

int _interceptCount;
de::WallDivs::Intercept *_firstIntercept;
de::WallDivs::Intercept *_lastIntercept;
};

/**
* Map geometry half-edge.
*
Expand Down
15 changes: 5 additions & 10 deletions doomsday/client/include/render/rend_dynlight.h
Expand Up @@ -22,8 +22,9 @@

#include <de/Vector>

#include "render/rendpoly.h"
#include "render/walldiv.h"
//#include "render/rendpoly.h"

#include "HEdge"

/// Paramaters for Rend_RenderLightProjections (POD).
typedef struct {
Expand All @@ -34,14 +35,8 @@ typedef struct {
de::Vector3d const *texBR;
bool isWall;
struct {
struct {
de::WallDivs::Intercept *firstDiv;
uint divCount;
} left;
struct {
de::WallDivs::Intercept *firstDiv;
uint divCount;
} right;
SectionEdge const *leftEdge;
SectionEdge const *rightEdge;
} wall;
} renderlightprojectionparams_t;

Expand Down
18 changes: 5 additions & 13 deletions doomsday/client/include/render/rend_fakeradio.h
Expand Up @@ -34,11 +34,11 @@
#ifndef DENG_RENDER_FAKERADIO
#define DENG_RENDER_FAKERADIO

#include "HEdge"
#include "Line"
#include "Vertex"
#include "Sector"
#include "render/rendpoly.h"
#include "render/walldiv.h"
#include "Vertex"
//#include "render/rendpoly.h"

/**
* Used to link a line to a BSP leaf for the purposes of FakeRadio shadowing.
Expand Down Expand Up @@ -159,16 +159,8 @@ struct RendRadioWallSectionParms
coord_t segLength;
Line const *line;
Sector const *frontSec, *backSec;
struct {
struct {
de::WallDivs::Intercept *firstDiv;
uint divCount;
} left;
struct {
de::WallDivs::Intercept *firstDiv;
uint divCount;
} right;
} wall;
SectionEdge const *leftEdge;
SectionEdge const *rightEdge;
};

/**
Expand Down
15 changes: 5 additions & 10 deletions doomsday/client/include/render/rend_shadow.h
Expand Up @@ -22,8 +22,9 @@

#include <de/Vector>

#include "render/rendpoly.h"
#include "render/walldiv.h"
//#include "render/rendpoly.h"

#include "HEdge"

/**
* This value defines the offset from the shadowed surface applied to
Expand Down Expand Up @@ -51,14 +52,8 @@ typedef struct {
de::Vector3d const *texBR;
bool isWall;
struct {
struct {
de::WallDivs::Intercept *firstDiv;
uint divCount;
} left;
struct {
de::WallDivs::Intercept *firstDiv;
uint divCount;
} right;
SectionEdge const *leftEdge;
SectionEdge const *rightEdge;
} wall;
} rendershadowprojectionparams_t;

Expand Down
11 changes: 4 additions & 7 deletions doomsday/client/include/render/rendpoly.h
Expand Up @@ -29,7 +29,7 @@

#include <de/Vector>

#include "render/walldiv.h"
class SectionEdge;

typedef struct rvertex_s {
float pos[3];
Expand Down Expand Up @@ -211,17 +211,14 @@ inline void Rtu_TranslateOffset(rtexmapunit_t *rtu, float s, float t)
}

void R_DivVerts(rvertex_t *dst, rvertex_t const *src,
de::WallDivs::Intercept *leftDivFirst, uint leftDivCount,
de::WallDivs::Intercept *rightDivFirst, uint rightDivCount);
SectionEdge const &leftEdge, SectionEdge const &rightEdge);

void R_DivTexCoords(rtexcoord_t *dst, rtexcoord_t const *src,
de::WallDivs::Intercept *leftDivFirst, uint leftDivCount,
de::WallDivs::Intercept *rightDivFirst, uint rightDivCount,
SectionEdge const &leftEdge, SectionEdge const &rightEdge,
float bL, float tL, float bR, float tR);

void R_DivVertColors(ColorRawf *dst, ColorRawf const *src,
de::WallDivs::Intercept *leftDivFirst, uint leftDivCount,
de::WallDivs::Intercept *rightDivFirst, uint rightDivCount,
SectionEdge const &leftEdge, SectionEdge const &rightEdge,
float bL, float tL, float bR, float tR);

#endif // DENG_RENDER_RENDPOLY_H
105 changes: 31 additions & 74 deletions doomsday/client/include/render/walldiv.h
Expand Up @@ -37,19 +37,23 @@ class WallDivs
class Intercept
{
protected:
Intercept() : _wallDivs(0), _distance(0) {}
Intercept(ddouble distance = 0);

public:
ddouble operator - (Intercept const &other) const
{
return distance() - other.distance();
bool operator < (Intercept const &other) const {
return _distance < other._distance;
}

bool operator < (Intercept const &other) const
{
return distance() < other.distance();
/**
* Determine the distance between "this" and the @a other intercept.
*/
ddouble operator - (Intercept const &other) const {
return _distance - other._distance;
}

/**
* Returns distance along the half-plane relative to the origin.
*/
ddouble distance() const { return _distance; }

bool hasNext() const
Expand Down Expand Up @@ -84,11 +88,17 @@ class WallDivs
throw WallDivs::MissingInterceptError("WallDivs::Intercept", "No previous neighbor");
}

#ifdef DENG_DEBUG
void debugPrint() const;
#endif

friend class WallDivs;

private:
WallDivs *_wallDivs;
/// Distance along the half-plane relative to the origin.
ddouble _distance;

WallDivs *_wallDivs;
};

typedef Intercept Intercepts[WALLDIVS_MAX_INTERCEPTS];
Expand Down Expand Up @@ -121,80 +131,27 @@ class WallDivs
throw MissingInterceptError("WallDivs::last", "Intercepts list is empty");
}

void append(ddouble distance)
{
Intercept *node = &_intercepts[_interceptCount++];
node->_wallDivs = this;
node->_distance = distance;
}
bool intercept(ddouble distance);

Intercept *find(ddouble distance) const
{
for(int i = 0; i < _interceptCount; ++i)
{
Intercept *icpt = const_cast<Intercept *>(&_intercepts[i]);
if(icpt->distance() == distance)
return icpt;
}
return 0;
}

static int compareIntercepts(void const *e1, void const *e2)
{
ddouble const delta = (*reinterpret_cast<Intercept const *>(e1)) - (*reinterpret_cast<Intercept const *>(e2));
if(delta > 0) return 1;
if(delta < 0) return -1;
return 0;
}

void sort()
{
if(count() < 2) return;

// Sorting is required. This shouldn't take too long...
// There seldom are more than two or three intercepts.
qsort(_intercepts, _interceptCount, sizeof(*_intercepts), compareIntercepts);
assertSorted();
}
void sort();

#ifdef DENG_DEBUG
void debugPrint() const
{
LOG_DEBUG("WallDivs [%p]:") << de::dintptr(this);
for(int i = 0; i < _interceptCount; ++i)
{
Intercept const *node = &_intercepts[i];
LOG_DEBUG(" %i: %f") << i << node->distance();
}
}
void printIntercepts() const;
#endif

Intercepts const &intercepts() const
{
return _intercepts;
}

private:
/**
* Ensure the intercepts are sorted (in ascending distance order).
* Returns the list of intercepts for the half-plane for efficient traversal.
*
* @note This list may or may not yet be sorted. If a sorted list is desired
* then sortAndMergeIntercepts() should first be called.
*
* @see interceptLineSegment(), intercepts()
*/
void assertSorted() const
{
#ifdef DENG_DEBUG
if(isEmpty()) return;

WallDivs::Intercept *node = &first();
ddouble farthest = node->distance();
forever
{
DENG2_ASSERT(node->distance() >= farthest);
farthest = node->distance();
Intercepts const &intercepts() const;

if(!node->hasNext()) break;
node = &node->next();
}
#endif
}
private:
Intercept *find(ddouble distance) const;
void assertSorted() const;

int _interceptCount;
Intercepts _intercepts;
Expand Down

0 comments on commit 085b4a5

Please sign in to comment.