Skip to content

Commit

Permalink
Refactor: Continued to marginalize SideDef
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 12, 2013
1 parent c5be353 commit 0181657
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 127 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/de_render.h
Expand Up @@ -50,7 +50,7 @@
#include "render/vlight.h"
#endif

#include "map/r_world.h"
//#include "map/r_world.h"
#include "r_util.h"

#endif /* DOOMSDAY_CLIENT_RENDERER */
42 changes: 39 additions & 3 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -22,22 +22,24 @@
#define LIBDENG_MAP_LINEDEF

#include <de/binangle.h>
#include <de/vector1.h>

#include <de/Vector>
#include <de/Error>

//#include "resource/r_data.h"

#include "MapElement"
#include "map/r_world.h"
#include "map/vertex.h"
//#include "map/r_world.h"
//#include "p_mapdata.h"

#include "p_dmu.h"

class Vertex;
class HEdge;
class LineOwner;
class Sector;
class SideDef;
class HEdge;

// Internal flags:
#define LF_POLYOBJ 0x1 ///< Line is part of a polyobject.
Expand Down Expand Up @@ -71,6 +73,32 @@ class HEdge;
#define SSF_TOP 0x4
///@}

#ifdef __CLIENT__

/**
* FakeRadio shadow data.
* @ingroup map
*/
struct shadowcorner_t
{
float corner;
Sector *proximity;
float pOffset;
float pHeight;
};

/**
* FakeRadio connected edge data.
* @ingroup map
*/
struct edgespan_t
{
float length;
float shift;
};

#endif // __CLIENT__

/**
* World map line.
*
Expand Down Expand Up @@ -128,6 +156,9 @@ class LineDef : public de::MapElement
/// Framecount of last time shadows were drawn on this side.
int _shadowVisCount;

/// @ref sdefFlags
short _flags;

/// Sound emitters.
ddmobj_base_t _middleSoundEmitter;
ddmobj_base_t _bottomSoundEmitter;
Expand Down Expand Up @@ -272,6 +303,11 @@ class LineDef : public de::MapElement
*/
void updateSurfaceNormals();

/**
* Returns the @ref sdefFlags fro the side.
*/
short flags() const;

/**
* Returns the frame number of the last time shadows were drawn for the side.
*/
Expand Down
14 changes: 8 additions & 6 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -24,6 +24,7 @@
#include <de/Vector>

#include "resource/r_data.h"
#include "map/linedef.h"
#include "map/plane.h"
#include "map/sector.h"
#include "map/sidedef.h"
Expand Down Expand Up @@ -83,8 +84,8 @@ void R_OrderVertices(LineDef *line, Sector const *sector, Vertex *verts[2]);
* @param lineFlags @ref ldefFlags.
* @param frontSec Sector in front of the wall.
* @param backSec Sector behind the wall. Can be @c NULL
* @param frontDef Definition for the front side. Can be @c NULL
* @param backDef Definition for the back side. Can be @c NULL
* @param front Front line side. Can be @c NULL. @todo Refactor away
* @param back Back line side. Can be @c NULL. @todo Refactor away
*
* Return values:
* @param low Z map space coordinate at the bottom of the wall section.
Expand All @@ -94,7 +95,8 @@ void R_OrderVertices(LineDef *line, Sector const *sector, Vertex *verts[2]);
* @return @c true iff the determined wall section height is @c >0
*/
boolean R_FindBottomTop(SideDefSection section, int lineFlags,
Sector const *frontSec, Sector const *backSec, SideDef const *frontDef, SideDef const *backDef,
Sector const *frontSec, Sector const *backSec,
LineDef::Side const *front, LineDef::Side const *back,
coord_t *low, coord_t *hi, pvec2f_t matOffset = 0);

/**
Expand Down Expand Up @@ -153,15 +155,15 @@ coord_t R_VisOpenRange(LineDef const &line, int side, coord_t *bottom, coord_t *
* @param lineFlags @ref ldefFlags.
* @param frontSec Sector in front of the wall.
* @param backSec Sector behind the wall. Can be @c NULL
* @param frontDef Definition for the front side. Can be @c NULL
* @param backDef Definition for the back side. Can be @c NULL
* @param front Front line side. Can be @c NULL. @todo Refactor away
* @param back Back line side. Can be @c NULL. @todo Refactor away
* @param ignoreOpacity @c true= material opacity should be ignored.
*
* @return @c true iff SideDef @a frontDef has a "middle" Material which completely
* covers the open range defined by sectors @a frontSec and @a backSec.
*/
boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
Sector const *backSec, SideDef const *frontDef, SideDef const *backDef,
Sector const *backSec, LineDef::Side const *front, LineDef::Side const *back,
boolean ignoreOpacity = true);

/**
Expand Down
34 changes: 0 additions & 34 deletions doomsday/client/include/map/sidedef.h
Expand Up @@ -29,32 +29,6 @@

class LineDef;

#ifdef __CLIENT__

/**
* FakeRadio shadow data.
* @ingroup map
*/
struct shadowcorner_t
{
float corner;
Sector *proximity;
float pOffset;
float pHeight;
};

/**
* FakeRadio connected edge data.
* @ingroup map
*/
struct edgespan_t
{
float length;
float shift;
};

#endif // __CLIENT__

/**
* @attention SideDef is in the process of being replaced by lineside_t. All
* data/values which concern the geometry of surfaces should be relocated to
Expand Down Expand Up @@ -84,9 +58,6 @@ class SideDef : public de::MapElement
/// Owning line of the sidedef.
LineDef *_line;

/// @ref sdefFlags
short _flags;

public:
SideDef();
~SideDef();
Expand Down Expand Up @@ -130,11 +101,6 @@ class SideDef : public de::MapElement
/// @copydoc middle()
inline Surface const &top() const { return surface(SS_TOP); }

/**
* Returns the @ref sdefFlags of the sidedef.
*/
short flags() const;

/**
* Get a property value, selected by DMU_* name.
*
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -807,8 +807,10 @@ void Cl_ReadSideDelta2(int deltaType, boolean skip)
if(df & SIDF_FLAGS)
{
// The delta includes the entire lowest byte.
sideDef->_flags &= ~0xff;
sideDef->_flags |= sideFlags;
LineDef &line = sideDef->line();
LineDef::Side &side = line.side(sideDef == line.frontSideDefPtr()? FRONT : BACK);
side._flags &= ~0xff;
side._flags |= sideFlags;
}

if(df & SIDF_LINE_FLAGS)
Expand Down
29 changes: 17 additions & 12 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -110,11 +110,12 @@ class EditableMap
return line;
}

SideDef *createSideDef(LineDef &line)
SideDef *createSideDef(LineDef &line, int side)
{
DENG_ASSERT(line.side(side).sideDefPtr() == 0);
SideDef *sideDef = new SideDef;
sideDef->_line = &line;

line.side(side)._sideDef = sideDef;
sideDefs.append(sideDef);
return sideDef;
}
Expand Down Expand Up @@ -952,6 +953,14 @@ boolean MPE_End()
* Perform cleanup on the loaded map data, removing duplicate vertexes,
* pruning unused sectors etc, etc...
*/

/// Ensure one sided lines are flagged as blocking. @todo Refactor away.
foreach(LineDef *line, editMap.lines)
{
if(!line->hasFrontSideDef() || !line->hasBackSideDef())
line->_flags |= DDLF_BLOCKING;
}

#if 0
markDuplicateVertexes(editMap);
pruneMapElements(editMap, PRUNE_ALL);
Expand Down Expand Up @@ -1165,7 +1174,7 @@ uint MPE_LinedefCreate(uint v1, uint v2, uint frontSectorIdx, uint backSectorIdx
}

#undef MPE_LinedefAddSide
void MPE_LinedefAddSide(uint lineIdx, int side, short flags, ddstring_t const *topMaterialUri,
void MPE_LinedefAddSide(uint lineIdx, int sideId, short flags, ddstring_t const *topMaterialUri,
float topOffsetX, float topOffsetY, float topRed, float topGreen, float topBlue,
ddstring_t const *middleMaterialUri, float middleOffsetX, float middleOffsetY, float middleRed,
float middleGreen, float middleBlue, float middleAlpha, ddstring_t const *bottomMaterialUri,
Expand All @@ -1178,16 +1187,17 @@ void MPE_LinedefAddSide(uint lineIdx, int side, short flags, ddstring_t const *t

LineDef *line = editMap.lines[lineIdx - 1];
SideDef *s;
if(line->hasSideDef(side))
if(line->hasSideDef(sideId))
{
s = line->sideDefPtr(side);
s = line->sideDefPtr(sideId);
}
else
{
s = line->side(side)._sideDef = editMap.createSideDef(*line);
s = editMap.createSideDef(*line, sideId);
}

s->_flags = flags;
LineDef::Side &side = line->side(sideId);
side._flags = flags;

// Assign the resolved material if found.
s->top().setMaterial(findMaterialInDict(topMaterialUri));
Expand All @@ -1202,11 +1212,6 @@ void MPE_LinedefAddSide(uint lineIdx, int side, short flags, ddstring_t const *t
s->bottom().setMaterial(findMaterialInDict(bottomMaterialUri));
s->bottom().setMaterialOrigin(bottomOffsetX, bottomOffsetY);
s->bottom().setTintColor(bottomRed, bottomGreen, bottomBlue);

// Update line flags.
line->_flags &= ~DDLF_BLOCKING;
if(!line->hasFrontSideDef() || !line->hasBackSideDef())
line->_flags |= DDLF_BLOCKING;
}

#undef MPE_PlaneCreate
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -365,11 +365,12 @@ bool HEdge::prepareWallDivs(SideDefSection section, Sector *frontSec, Sector *ba
walldivs_t *leftWallDivs, walldivs_t *rightWallDivs, pvec2f_t matOffset) const
{
int lineFlags = _line? _line->flags() : 0;
SideDef *frontDef = _line? _line->side(_lineSide).sideDefPtr() : 0;
SideDef *backDef = _twin && _twin->hasLine()? _twin->lineSide().sideDefPtr() : 0;
LineDef::Side *front = _line? &_line->side(_lineSide) : 0;
LineDef::Side *back = _twin && _twin->hasLine()? &_twin->lineSide() : 0;
coord_t low, hi;
bool visible = R_FindBottomTop(section, lineFlags, frontSec, backSec, frontDef, backDef,
&low, &hi, matOffset);
bool visible = R_FindBottomTop(section, lineFlags, frontSec, backSec, front, back,
&low, &hi, matOffset);

matOffset[0] += float(_line? _lineOffset : 0);
if(!visible) return false;

Expand Down
8 changes: 7 additions & 1 deletion doomsday/client/src/map/linedef.cpp
Expand Up @@ -47,7 +47,8 @@ LineDef::Side::Side(Sector *sector)
_sideDef(0),
_leftHEdge(0),
_rightHEdge(0),
_shadowVisCount(0)
_shadowVisCount(0),
_flags(0)
{
std::memset(&_middleSoundEmitter, 0, sizeof(_middleSoundEmitter));
std::memset(&_bottomSoundEmitter, 0, sizeof(_bottomSoundEmitter));
Expand Down Expand Up @@ -252,6 +253,11 @@ LineDef::Side::FakeRadioData const &LineDef::Side::fakeRadioData() const

#endif // __CLIENT__

short LineDef::Side::flags() const
{
return _flags;
}

int LineDef::Side::shadowVisCount() const
{
return _shadowVisCount;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/map/p_objlink.cpp
Expand Up @@ -379,12 +379,12 @@ static void processSeg(HEdge *hedge, void *parameters)
LineDef &line = hedge->line();
Sector *frontSec = lineSide == FRONT? leaf->sectorPtr() : backLeaf->sectorPtr();
Sector *backSec = lineSide == FRONT? backLeaf->sectorPtr() : leaf->sectorPtr();
SideDef *frontDef = line.sideDefPtr(lineSide);
SideDef *backDef = line.sideDefPtr(lineSide^1);
LineDef::Side &front = line.side(lineSide);
LineDef::Side &back = line.side(lineSide^1);

if(backSec && !backDef) return; // One-sided window.
if(backSec && !back.hasSideDef()) return; // One-sided window.

if(R_MiddleMaterialCoversOpening(line.flags(), frontSec, backSec, frontDef, backDef,
if(R_MiddleMaterialCoversOpening(line.flags(), frontSec, backSec, &front, &back,
false /*do not ignore material opacity*/)) return;
}

Expand Down

0 comments on commit 0181657

Please sign in to comment.