Skip to content

Commit

Permalink
Refactor|LineDef: Began cleaning up LineDef
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 9, 2013
1 parent 76c680a commit 29b9f3a
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 155 deletions.
37 changes: 28 additions & 9 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -124,6 +124,8 @@ class LineDef : public de::MapElement
int _shadowVisCount;

public:
Side();

/**
* Returns @c true iff a Sector is attributed to the side.
*/
Expand Down Expand Up @@ -193,14 +195,17 @@ class LineDef : public de::MapElement
};

public: /// @todo make private:
/// Vertexes [From, To]
Vertex *_v[2];
/// Vertexes:
Vertex *_v1;
Vertex *_v2;

/// Links to vertex line owner nodes [From, To].
LineOwner *_vo[2];
/// Links to vertex line owner nodes:
LineOwner *_vo1;
LineOwner *_vo2;

/// Logical sides [Front, Back]
Side _sides[2];
/// Logical sides:
Side _front;
Side _back;

/// Public DDLF_* flags.
int _flags;
Expand Down Expand Up @@ -232,7 +237,6 @@ class LineDef : public de::MapElement

public:
LineDef();
~LineDef();

/**
* Returns @c true iff the line is part of some Polyobj.
Expand Down Expand Up @@ -636,8 +640,12 @@ class LineDef : public de::MapElement
/**
* @param offset Returns the position of the nearest point along the line [0..1].
*/
coord_t pointDistance(const_pvec2d_t point, coord_t *offset) const;
inline coord_t pointDistance(const_pvec2d_t point, coord_t *offset) const
{
return V2d_PointLineDistance(point, v1().origin(), direction(), offset);
}

/// @copydoc pointDistance()
inline coord_t pointDistance(coord_t x, coord_t y, coord_t *offset) const
{
coord_t point[2] = { x, y };
Expand All @@ -654,8 +662,12 @@ class LineDef : public de::MapElement
* - Zero: @a point lies directly on the line.
* - Positive: @a point is to the right/front side.
*/
coord_t pointOnSide(const_pvec2d_t point) const;
inline coord_t pointOnSide(const_pvec2d_t point) const
{
return V2d_PointOnLineSide(point, v1().origin(), direction());
}

/// @copydoc pointOnSide()
inline coord_t pointOnSide(coord_t x, coord_t y) const
{
coord_t point[2] = { x, y };
Expand Down Expand Up @@ -704,6 +716,8 @@ class LineDef : public de::MapElement
*/
void unitVector(pvec2f_t unitVec) const;

#ifdef __CLIENT__

/**
* The DOOM lighting model applies a sector light level delta when drawing
* line segments based on their 2D world angle.
Expand All @@ -717,6 +731,8 @@ class LineDef : public de::MapElement
*/
void lightLevelDelta(int side, float *deltaL, float *deltaR) const;

#endif // __CLIENT__

/**
* Get a property value, selected by DMU_* name.
*
Expand All @@ -732,6 +748,9 @@ class LineDef : public de::MapElement
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);

private:
DENG2_PRIVATE(d)
};

#endif // LIBDENG_MAP_LINEDEF
21 changes: 11 additions & 10 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -698,9 +698,9 @@ static void setVertexLineOwner(Vertex *vtx, LineDef *lineptr, LineOwner **storag

// Link the line to its respective owner node.
if(vtx == &lineptr->v1())
lineptr->_vo[FROM] = newOwner;
lineptr->_vo1 = newOwner;
else
lineptr->_vo[TO] = newOwner;
lineptr->_vo2 = newOwner;
}

#ifdef DENG2_DEBUG
Expand Down Expand Up @@ -1004,6 +1004,7 @@ boolean MPE_End()
map->_lines.append(editMap.lines.takeFirst());
LineDef *line = map->_lines.back();

/// @todo This init should already have been done elsewhere. -ds
line->updateSlopeType();
line->updateAABox();

Expand Down Expand Up @@ -1199,17 +1200,17 @@ uint MPE_LinedefCreate(uint v1, uint v2, uint frontSector, uint backSector,
SideDef *back = backSide? editMap.sideDefs[backSide - 1] : 0;

LineDef *l = editMap.createLine();
l->_v[FROM] = vtx1;
l->_v[TO] = vtx2;
l->_v1 = vtx1;
l->_v2 = vtx2;

l->_v[FROM]->_buildData.refCount++;
l->_v[TO]->_buildData.refCount++;
l->_v1->_buildData.refCount++;
l->_v2->_buildData.refCount++;

l->_sides[FRONT]._sector = (frontSector == 0? NULL: editMap.sectors[frontSector-1]);
l->_sides[BACK]._sector = (backSector == 0? NULL: editMap.sectors[backSector-1]);
l->_front._sector = (frontSector == 0? NULL: editMap.sectors[frontSector-1]);
l->_back._sector = (backSector == 0? NULL: editMap.sectors[backSector-1]);

l->_sides[FRONT]._sideDef = front;
l->_sides[BACK]._sideDef = back;
l->_front._sideDef = front;
l->_back._sideDef = back;

l->_length = length;

Expand Down

0 comments on commit 29b9f3a

Please sign in to comment.