Skip to content

Commit

Permalink
Refactor|Line: Various Line API improvements
Browse files Browse the repository at this point in the history
The majority of the time when one references a Line::Side section it
is to return the Surface owned by the section. Accordingly the API
should reflect that.

The middle(), bottom() and top() methods of Line::Side now return
the associated Surface. The less usual case of returning the Section
itself is now serviced by the section() method.
  • Loading branch information
danij-deng committed Apr 14, 2013
1 parent 4457f2d commit 36e1103
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 236 deletions.
128 changes: 89 additions & 39 deletions doomsday/client/include/map/line.h
Expand Up @@ -140,11 +140,13 @@ class Line : public de::MapElement
/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);

struct Section
class Section
{
public: /// @todo make private:
Surface _surface;
ddmobj_base_t _soundEmitter;

public:
Section(Side &side)
: _surface(dynamic_cast<MapElement &>(side))
{
Expand All @@ -158,6 +160,14 @@ class Line : public de::MapElement
Surface const &surface() const {
return const_cast<Surface const &>(const_cast<Section &>(*this).surface());
}

ddmobj_base_t &soundEmitter() {
return _soundEmitter;
}

ddmobj_base_t const &soundEmitter() const {
return const_cast<ddmobj_base_t const &>(const_cast<Section &>(*this).soundEmitter());
}
};

struct Sections /// @todo choose a better name
Expand Down Expand Up @@ -272,58 +282,68 @@ class Line : public de::MapElement
Section const &section(SideSection sectionId) const;

/**
* Returns the middle section of the side.
* Returns the specified surface of the side.
*
* @param sectionId Identifier of the surface to return.
*/
inline Section &middle() { return section(SS_MIDDLE); }
inline Surface &surface(SideSection sectionId) {
return section(sectionId).surface();
}

/// @copydoc middle()
inline Section const &middle() const { return section(SS_MIDDLE); }
/// @copydoc surface()
inline Surface const &surface(SideSection sectionId) const {
return const_cast<Surface const &>(const_cast<Side *>(this)->surface(sectionId));
}

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

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

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

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

#ifdef __CLIENT__
/// @copydoc bottom()
inline Surface const &bottom() const { return surface(SS_BOTTOM); }

/**
* Returns the FakeRadio data for the side.
* Returns the middle surface of the side.
*/
FakeRadioData &fakeRadioData();

/// @copydoc fakeRadioData()
FakeRadioData const &fakeRadioData() const;
inline Surface &top() { return surface(SS_TOP); }

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

/**
* Returns the left-most HEdge for the side.
* Returns the specified sound emitter of the side.
*
* @param sectionId Identifier of the sound emitter to return.
*/
HEdge &leftHEdge() const;
inline ddmobj_base_t &soundEmitter(SideSection sectionId) {
return section(sectionId).soundEmitter();
}

/**
* Returns the right-most HEdge for the side.
*/
HEdge &rightHEdge() const;
/// @copydoc surface()
inline ddmobj_base_t const &soundEmitter(SideSection sectionId) const {
return const_cast<ddmobj_base_t const &>(const_cast<Side *>(this)->soundEmitter(sectionId));
}

/**
* Returns the sound emitter for the middle surface.
* Returns the middle sound emitter of the side.
*/
ddmobj_base_t &middleSoundEmitter();
inline ddmobj_base_t &middleSoundEmitter() {
return section(SS_MIDDLE).soundEmitter();
}

/// @copydoc soundEmitter()
ddmobj_base_t const &middleSoundEmitter() const;
/// @copydoc middleSoundEmitter()
inline ddmobj_base_t const &middleSoundEmitter() const {
return section(SS_MIDDLE).soundEmitter();
}

/**
* Update the middle sound emitter origin according to the point defined by
Expand All @@ -333,12 +353,16 @@ class Line : public de::MapElement
void updateMiddleSoundEmitterOrigin();

/**
* Returns the sound emitter for the bottom surface.
* Returns the bottom sound emitter (tee-hee) for the side.
*/
ddmobj_base_t &bottomSoundEmitter();
inline ddmobj_base_t &bottomSoundEmitter() {
return section(SS_BOTTOM).soundEmitter();
}

/// @copydoc soundEmitter()
ddmobj_base_t const &bottomSoundEmitter() const;
/// @copydoc bottomSoundEmitter()
inline ddmobj_base_t const &bottomSoundEmitter() const {
return section(SS_BOTTOM).soundEmitter();
}

/**
* Update the bottom sound emitter origin according to the point defined by
Expand All @@ -348,12 +372,16 @@ class Line : public de::MapElement
void updateBottomSoundEmitterOrigin();

/**
* Returns the sound emitter for the top surface.
* Returns the top sound emitter for the side.
*/
ddmobj_base_t &topSoundEmitter();
inline ddmobj_base_t &topSoundEmitter() {
return section(SS_TOP).soundEmitter();
}

/// @copydoc soundEmitter()
ddmobj_base_t const &topSoundEmitter() const;
/// @copydoc topSoundEmitter()
inline ddmobj_base_t const &topSoundEmitter() const {
return section(SS_TOP).soundEmitter();
}

/**
* Update the top sound emitter origin according to the point defined by the
Expand All @@ -369,6 +397,28 @@ class Line : public de::MapElement
*/
void updateAllSoundEmitterOrigins();

#ifdef __CLIENT__

/**
* Returns the FakeRadio data for the side.
*/
FakeRadioData &fakeRadioData();

/// @copydoc fakeRadioData()
FakeRadioData const &fakeRadioData() const;

#endif // __CLIENT__

/**
* Returns the left-most HEdge for the side.
*/
HEdge &leftHEdge() const;

/**
* Returns the right-most HEdge for the side.
*/
HEdge &rightHEdge() const;

/**
* Update the tangent space normals of the side's surfaces according to the
* points defined by the Line's vertices. If no Sections are defined this is
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->hasLine() && hedge->lineSide().hasSections() && hedge->lineSide().middle().surface().hasMaterial())
if(hedge->hasLine() && hedge->lineSide().hasSections() && hedge->lineSide().middle().hasMaterial())
{
Material &material = hedge->lineSide().middle().surface().material();
Material &material = hedge->lineSide().middle().material();
AudioEnvironmentClass env = material.audioEnvironment();
if(!(env >= 0 && env < NUM_AUDIO_ENVIRONMENT_CLASSES))
env = AEC_WOOD; // Assume it's wood if unknown.
Expand Down
28 changes: 14 additions & 14 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -767,42 +767,42 @@ void Cl_ReadSideDelta2(int deltaType, boolean skip)

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

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

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

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

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

if(df & SIDF_FLAGS)
{
Expand Down
24 changes: 12 additions & 12 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -1143,18 +1143,18 @@ void MPE_LineAddSide(uint lineIdx, int sideId, short flags, ddstring_t const *to
side.setSideDefArchiveIndex(sideDefArchiveIndex);

// Assign the resolved material if found.
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);
side.top().setMaterial(findMaterialInDict(topMaterialUri));
side.top().setMaterialOrigin(topOffsetX, topOffsetY);
side.top().setTintColor(topRed, topGreen, topBlue);

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

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

#undef MPE_PlaneCreate
Expand Down
20 changes: 10 additions & 10 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -340,13 +340,13 @@ DENG2_PIMPL(GameMap)

Line::Side &side = line->side(line->frontSectorPtr() == &sector? FRONT : BACK);

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

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

if(top > self.skyFixCeiling())
{
Expand All @@ -358,8 +358,8 @@ DENG2_PIMPL(GameMap)
if(skyFloor)
{
coord_t const bottom = sector.floor().visHeight()
+ side.middle().surface().visMaterialOrigin()[VY]
- side.middle().surface().material().height();
+ side.middle().visMaterialOrigin()[VY]
- side.middle().material().height();

if(bottom < self.skyFixFloor())
{
Expand Down Expand Up @@ -586,9 +586,9 @@ void GameMap::buildSurfaceLists()
continue;

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

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

Expand Down

0 comments on commit 36e1103

Please sign in to comment.