Skip to content

Commit

Permalink
Refactor: Moved wall Surfaces from SideDef to LineDef::Side
Browse files Browse the repository at this point in the history
The SideDef class is now redundant.
  • Loading branch information
danij-deng committed Apr 12, 2013
1 parent 0181657 commit abf0baf
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 233 deletions.
83 changes: 77 additions & 6 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -30,6 +30,8 @@
//#include "resource/r_data.h"

#include "MapElement"
#include "map/sidedef.h"
#include "map/surface.h"
#include "map/vertex.h"
//#include "map/r_world.h"
//#include "p_mapdata.h"
Expand All @@ -39,7 +41,6 @@
class HEdge;
class LineOwner;
class Sector;
class SideDef;

// Internal flags:
#define LF_POLYOBJ 0x1 ///< Line is part of a polyobject.
Expand Down Expand Up @@ -126,6 +127,9 @@ class LineDef : public de::MapElement
/// Required sector attribution is missing. @ingroup errors
DENG2_ERROR(MissingSectorError);

/// The given side section identifier is invalid. @ingroup errors
DENG2_ERROR(InvalidSectionIdError);

/// Required sidedef attribution is missing. @ingroup errors
DENG2_ERROR(MissingSideDefError);

Expand All @@ -140,13 +144,50 @@ class LineDef : public de::MapElement
*/
struct Side
{
public:
struct Section
{
Surface _surface;
ddmobj_base_t _soundEmitter;

Section(SideDef &sideDef)
: _surface(dynamic_cast<MapElement &>(sideDef))
{
std::memset(&_soundEmitter, 0, sizeof(_soundEmitter));
}

Surface &surface() {
return _surface;
}

Surface const &surface() const {
return const_cast<Surface const &>(const_cast<Section &>(*this).surface());
}
};

struct Sections /// @todo choose a better name
{
Section middle;
Section bottom;
Section top;

Sections(SideDef &sideDef)
: middle(sideDef),
bottom(sideDef),
top(sideDef)
{}
};

public: /// @todo make private:
/// Sector on this side.
Sector *_sector;

/// SideDef on this side.
SideDef *_sideDef;

/// Sections.
Sections *_sections;

/// Left-most HEdge on this side.
HEdge *_leftHEdge;

Expand All @@ -159,11 +200,6 @@ class LineDef : public de::MapElement
/// @ref sdefFlags
short _flags;

/// Sound emitters.
ddmobj_base_t _middleSoundEmitter;
ddmobj_base_t _bottomSoundEmitter;
ddmobj_base_t _topSoundEmitter;

#ifdef __CLIENT__
/// @todo Does not belong here - move to the map renderer. -ds
struct FakeRadioData
Expand All @@ -183,6 +219,7 @@ class LineDef : public de::MapElement

public:
Side(Sector *sector = 0);
~Side();

/**
* Returns @c true iff a Sector is attributed to the side.
Expand Down Expand Up @@ -222,6 +259,40 @@ class LineDef : public de::MapElement
*/
inline SideDef *sideDefPtr() const { return hasSideDef()? &sideDef() : 0; }

/**
* Returns the specified section of the side.
*
* @param sectionId Identifier of the section to return.
*/
Section &section(SideDefSection sectionId);

/// @copydoc section()
Section const &section(SideDefSection sectionId) const;

/**
* Returns the middle section of the side.
*/
inline Section &middle() { return section(SS_MIDDLE); }

/// @copydoc middle()
inline Section const &middle() const { return section(SS_MIDDLE); }

/**
* Returns the bottom section of the side.
*/
inline Section &bottom() { return section(SS_BOTTOM); }

/// @copydoc bottom()
inline Section const &bottom() const { return section(SS_BOTTOM); }

/**
* Returns the middle section of the side.
*/
inline Section &top() { return section(SS_TOP); }

/// @copydoc top()
inline Section const &top() const { return section(SS_TOP); }

#ifdef __CLIENT__

/**
Expand Down
12 changes: 3 additions & 9 deletions doomsday/client/include/map/sidedef.h
Expand Up @@ -40,33 +40,26 @@ class LineDef;
class SideDef : public de::MapElement
{
public:
/// The given surface section identifier is invalid. @ingroup errors
DENG2_ERROR(InvalidSectionError);

/// The referenced property does not exist. @ingroup errors
DENG2_ERROR(UnknownPropertyError);

/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);

public:
/// Component section surfaces:
Surface _middleSurface;
Surface _bottomSurface;
Surface _topSurface;

/// Owning line of the sidedef.
LineDef *_line;

public:
SideDef();
SideDef(LineDef &line);
~SideDef();

/**
* Returns the line which owns the sidedef.
*/
LineDef &line() const;

#if 0
/**
* Returns the specified surface of the sidedef.
*
Expand Down Expand Up @@ -100,6 +93,7 @@ class SideDef : public de::MapElement

/// @copydoc middle()
inline Surface const &top() const { return surface(SS_TOP); }
#endif

/**
* Get a property value, selected by DMU_* name.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -250,9 +250,9 @@ static boolean calcBspLeafReverb(BspLeaf *bspLeaf)
HEdge *hedge = base;
do
{
if(hedge->hasLineSideDef() && hedge->lineSideDef().middle().hasMaterial())
if(hedge->hasLineSideDef() && hedge->lineSide().middle().surface().hasMaterial())
{
Material &material = hedge->lineSideDef().middle().material();
Material &material = hedge->lineSide().middle().surface().material();
AudioEnvironmentClass env = material.audioEnvironment();
if(!(env >= 0 && env < NUM_AUDIO_ENVIRONMENT_CLASSES))
env = AEC_WOOD; // Assume it's wood if unknown.
Expand Down
33 changes: 16 additions & 17 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -764,58 +764,57 @@ void Cl_ReadSideDelta2(int deltaType, boolean skip)

DENG_ASSERT(num < theMap->sideDefCount());
SideDef *sideDef = theMap->sideDefs().at(num);
LineDef &line = sideDef->line();
LineDef::Side &side = line.side(line.frontSideDefPtr() == sideDef? FRONT : BACK);

if(df & SIDF_TOP_MATERIAL)
{
sideDef->top().setMaterial(Cl_FindLocalMaterial(topMat));
side.top().surface().setMaterial(Cl_FindLocalMaterial(topMat));
}
if(df & SIDF_MID_MATERIAL)
{
sideDef->middle().setMaterial(Cl_FindLocalMaterial(midMat));
side.middle().surface().setMaterial(Cl_FindLocalMaterial(midMat));
}
if(df & SIDF_BOTTOM_MATERIAL)
{
sideDef->bottom().setMaterial(Cl_FindLocalMaterial(botMat));
side.bottom().surface().setMaterial(Cl_FindLocalMaterial(botMat));
}

if(df & SIDF_TOP_COLOR_RED)
sideDef->top().setTintRed(toprgb[CR]);
side.top().surface().setTintRed(toprgb[CR]);
if(df & SIDF_TOP_COLOR_GREEN)
sideDef->top().setTintGreen(toprgb[CG]);
side.top().surface().setTintGreen(toprgb[CG]);
if(df & SIDF_TOP_COLOR_BLUE)
sideDef->top().setTintBlue(toprgb[CB]);
side.top().surface().setTintBlue(toprgb[CB]);

if(df & SIDF_MID_COLOR_RED)
sideDef->middle().setTintRed(midrgba[CR]);
side.middle().surface().setTintRed(midrgba[CR]);
if(df & SIDF_MID_COLOR_GREEN)
sideDef->middle().setTintGreen(midrgba[CG]);
side.middle().surface().setTintGreen(midrgba[CG]);
if(df & SIDF_MID_COLOR_BLUE)
sideDef->middle().setTintBlue(midrgba[CB]);
side.middle().surface().setTintBlue(midrgba[CB]);
if(df & SIDF_MID_COLOR_ALPHA)
sideDef->middle().setOpacity(midrgba[CA]);
side.middle().surface().setOpacity(midrgba[CA]);

if(df & SIDF_BOTTOM_COLOR_RED)
sideDef->bottom().setTintRed(bottomrgb[CR]);
side.bottom().surface().setTintRed(bottomrgb[CR]);
if(df & SIDF_BOTTOM_COLOR_GREEN)
sideDef->bottom().setTintGreen(bottomrgb[CG]);
side.bottom().surface().setTintGreen(bottomrgb[CG]);
if(df & SIDF_BOTTOM_COLOR_BLUE)
sideDef->bottom().setTintBlue(bottomrgb[CB]);
side.bottom().surface().setTintBlue(bottomrgb[CB]);

if(df & SIDF_MID_BLENDMODE)
sideDef->middle().setBlendMode(blendmode_t(blendmode));
side.middle().surface().setBlendMode(blendmode_t(blendmode));

if(df & SIDF_FLAGS)
{
// The delta includes the entire lowest byte.
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)
{
LineDef &line = sideDef->line();
// The delta includes the entire lowest byte.
line._flags &= ~0xff;
line._flags |= lineFlags;
Expand Down
30 changes: 15 additions & 15 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -112,10 +112,10 @@ class EditableMap

SideDef *createSideDef(LineDef &line, int side)
{
DENG_ASSERT(line.side(side).sideDefPtr() == 0);
SideDef *sideDef = new SideDef;
sideDef->_line = &line;
DENG_ASSERT(!line.side(side).hasSideDef());
SideDef *sideDef = new SideDef(line);
line.side(side)._sideDef = sideDef;
line.side(side)._sections = new LineDef::Side::Sections(*sideDef);
sideDefs.append(sideDef);
return sideDef;
}
Expand Down Expand Up @@ -1200,18 +1200,18 @@ void MPE_LinedefAddSide(uint lineIdx, int sideId, short flags, ddstring_t const
side._flags = flags;

// Assign the resolved material if found.
s->top().setMaterial(findMaterialInDict(topMaterialUri));
s->top().setMaterialOrigin(topOffsetX, topOffsetY);
s->top().setTintColor(topRed, topGreen, topBlue);

s->middle().setMaterial(findMaterialInDict(middleMaterialUri));
s->middle().setMaterialOrigin(middleOffsetX, middleOffsetY);
s->middle().setTintColor(middleRed, middleGreen, middleBlue);
s->middle().setOpacity(middleAlpha);

s->bottom().setMaterial(findMaterialInDict(bottomMaterialUri));
s->bottom().setMaterialOrigin(bottomOffsetX, bottomOffsetY);
s->bottom().setTintColor(bottomRed, bottomGreen, bottomBlue);
side.top().surface().setMaterial(findMaterialInDict(topMaterialUri));
side.top().surface().setMaterialOrigin(topOffsetX, topOffsetY);
side.top().surface().setTintColor(topRed, topGreen, topBlue);

side.middle().surface().setMaterial(findMaterialInDict(middleMaterialUri));
side.middle().surface().setMaterialOrigin(middleOffsetX, middleOffsetY);
side.middle().surface().setTintColor(middleRed, middleGreen, middleBlue);
side.middle().surface().setOpacity(middleAlpha);

side.bottom().surface().setMaterial(findMaterialInDict(bottomMaterialUri));
side.bottom().surface().setMaterialOrigin(bottomOffsetX, bottomOffsetY);
side.bottom().surface().setTintColor(bottomRed, bottomGreen, bottomBlue);
}

#undef MPE_PlaneCreate
Expand Down
27 changes: 14 additions & 13 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -338,15 +338,15 @@ DENG2_PIMPL(GameMap)
if(!line->hasFrontSideDef() || !line->hasBackSideDef())
continue;

int side = line->frontSectorPtr() == &sector? FRONT : BACK;
SideDef const &sideDef = line->sideDef(side);
LineDef::Side &side = line->side(line->frontSectorPtr() == &sector? FRONT : BACK);

if(!sideDef.middle().hasMaterial())
if(!side.middle().surface().hasMaterial())
continue;

if(skyCeil)
{
coord_t const top = sector.ceiling().visHeight() + sideDef.middle().visMaterialOrigin()[VY];
coord_t const top = sector.ceiling().visHeight()
+ side.middle().surface().visMaterialOrigin()[VY];

if(top > self.skyFixCeiling())
{
Expand All @@ -357,8 +357,9 @@ DENG2_PIMPL(GameMap)

if(skyFloor)
{
coord_t const bottom = sector.floor().visHeight() +
sideDef.middle().visMaterialOrigin()[VY] - sideDef.middle().material().height();
coord_t const bottom = sector.floor().visHeight()
+ side.middle().surface().visMaterialOrigin()[VY]
- side.middle().surface().material().height();

if(bottom < self.skyFixFloor())
{
Expand Down Expand Up @@ -585,10 +586,10 @@ void GameMap::buildSurfaceLists()
if(!line->hasSideDef(i))
continue;

SideDef &sideDef = line->sideDef(i);
d->addSurfaceToLists(sideDef.middle());
d->addSurfaceToLists(sideDef.top());
d->addSurfaceToLists(sideDef.bottom());
LineDef::Side &side = line->side(i);
d->addSurfaceToLists(side.middle().surface());
d->addSurfaceToLists(side.top().surface());
d->addSurfaceToLists(side.bottom().surface());
}

foreach(Sector *sector, _sectors)
Expand Down Expand Up @@ -762,15 +763,15 @@ Surface *GameMap::surfaceBySoundEmitter(ddmobj_base_t const &soundEmitter) const
LineDef::Side &side = line->side(i);
if(&soundEmitter == &side.middleSoundEmitter())
{
return &side.sideDef().middle();
return &side.middle().surface();
}
if(&soundEmitter == &side.bottomSoundEmitter())
{
return &side.sideDef().bottom();
return &side.bottom().surface();
}
if(&soundEmitter == &side.topSoundEmitter())
{
return &side.sideDef().top();
return &side.top().surface();
}
}

Expand Down

0 comments on commit abf0baf

Please sign in to comment.