Skip to content

Commit

Permalink
Refactor|Client: Moved FakeRadioData from SideDef to LineDef::Side
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 12, 2013
1 parent 1ab1450 commit f4854db
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 96 deletions.
61 changes: 45 additions & 16 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -113,11 +113,6 @@ class LineDef : public de::MapElement
struct Side
{
public: /// @todo make private:
/// Sound emitters.
ddmobj_base_t _middleSoundEmitter;
ddmobj_base_t _bottomSoundEmitter;
ddmobj_base_t _topSoundEmitter;

/// Sector on this side.
Sector *_sector;

Expand All @@ -133,6 +128,28 @@ class LineDef : public de::MapElement
/// Framecount of last time shadows were drawn on this side.
int _shadowVisCount;

/// 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
{
/// Frame number of last update
int updateCount;

shadowcorner_t topCorners[2];
shadowcorner_t bottomCorners[2];
shadowcorner_t sideCorners[2];

/// [left, right]
edgespan_t spans[2];
} _fakeRadioData;

#endif // __CLIENT__

public:
Side(Sector *sector = 0);

Expand Down Expand Up @@ -174,6 +191,28 @@ class LineDef : public de::MapElement
*/
inline SideDef *sideDefPtr() const { return hasSideDef()? &sideDef() : 0; }

#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;

/**
* Returns the sound emitter for the middle surface.
*/
Expand Down Expand Up @@ -219,22 +258,12 @@ class LineDef : public de::MapElement
*/
void updateTopSoundEmitterOrigin();

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

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

/**
* Update the side's sound emitter origins according to the points defined by
* the LineDef's vertices and the plane heights of the Sector on this side.
* If no SideDef is associated this is a no-op.
*/
void updateSoundEmitterOrigins();
void updateAllSoundEmitterOrigins();

/**
* Update the tangent space normals of the side's surfaces according to the
Expand Down
30 changes: 0 additions & 30 deletions doomsday/client/include/map/sidedef.h
Expand Up @@ -94,24 +94,6 @@ class SideDef : public de::MapElement
int refCount;
} _buildData;

#ifdef __CLIENT__

/// @todo Does not belong here - move to the map renderer. -ds
struct FakeRadioData
{
/// Frame number of last update
int updateCount;

shadowcorner_t topCorners[2];
shadowcorner_t bottomCorners[2];
shadowcorner_t sideCorners[2];

/// [left, right]
edgespan_t spans[2];
} _fakeRadioData;

#endif // __CLIENT__

public:
SideDef();
~SideDef();
Expand Down Expand Up @@ -160,18 +142,6 @@ class SideDef : public de::MapElement
*/
short flags() const;

#ifdef __CLIENT__

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

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

#endif // __CLIENT__

/**
* Get a property value, selected by DMU_* name.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/gamemap.cpp
Expand Up @@ -165,7 +165,7 @@ DENG2_PIMPL(GameMap)
for(int i = 0; i < 2; ++i)
{
line->side(i).updateSurfaceNormals();
line->side(i).updateSoundEmitterOrigins();
line->side(i).updateAllSoundEmitterOrigins();
}
}

Expand Down
64 changes: 43 additions & 21 deletions doomsday/client/src/map/linedef.cpp
Expand Up @@ -52,6 +52,14 @@ LineDef::Side::Side(Sector *sector)
std::memset(&_middleSoundEmitter, 0, sizeof(_middleSoundEmitter));
std::memset(&_bottomSoundEmitter, 0, sizeof(_bottomSoundEmitter));
std::memset(&_topSoundEmitter, 0, sizeof(_topSoundEmitter));

#ifdef __CLIENT__
_fakeRadioData.updateCount = 0;
std::memset(_fakeRadioData.topCorners, 0, sizeof(_fakeRadioData.topCorners));
std::memset(_fakeRadioData.bottomCorners, 0, sizeof(_fakeRadioData.bottomCorners));
std::memset(_fakeRadioData.sideCorners, 0, sizeof(_fakeRadioData.sideCorners));
std::memset(_fakeRadioData.spans, 0, sizeof(_fakeRadioData.spans));
#endif
}

bool LineDef::Side::hasSector() const
Expand Down Expand Up @@ -84,14 +92,26 @@ SideDef &LineDef::Side::sideDef() const
throw LineDef::MissingSideDefError("LineDef::Side::sideDef", "No sidedef is configured");
}

HEdge &LineDef::Side::leftHEdge() const
{
DENG_ASSERT(_leftHEdge != 0);
return *_leftHEdge;
}

HEdge &LineDef::Side::rightHEdge() const
{
DENG_ASSERT(_rightHEdge != 0);
return *_rightHEdge;
}

ddmobj_base_t &LineDef::Side::middleSoundEmitter()
{
return _middleSoundEmitter;
}

ddmobj_base_t const &LineDef::Side::middleSoundEmitter() const
{
return const_cast<ddmobj_base_t const &>(const_cast<LineDef::Side &>(*this).middleSoundEmitter());
return const_cast<ddmobj_base_t const &>(const_cast<Side &>(*this).middleSoundEmitter());
}

void LineDef::Side::updateMiddleSoundEmitterOrigin()
Expand Down Expand Up @@ -123,7 +143,7 @@ ddmobj_base_t &LineDef::Side::bottomSoundEmitter()

ddmobj_base_t const &LineDef::Side::bottomSoundEmitter() const
{
return const_cast<ddmobj_base_t const &>(const_cast<LineDef::Side &>(*this).bottomSoundEmitter());
return const_cast<ddmobj_base_t const &>(const_cast<Side &>(*this).bottomSoundEmitter());
}

void LineDef::Side::updateBottomSoundEmitterOrigin()
Expand Down Expand Up @@ -159,7 +179,7 @@ ddmobj_base_t &LineDef::Side::topSoundEmitter()

ddmobj_base_t const &LineDef::Side::topSoundEmitter() const
{
return const_cast<ddmobj_base_t const &>(const_cast<LineDef::Side &>(*this).topSoundEmitter());
return const_cast<ddmobj_base_t const &>(const_cast<Side &>(*this).topSoundEmitter());
}

void LineDef::Side::updateTopSoundEmitterOrigin()
Expand Down Expand Up @@ -188,24 +208,7 @@ void LineDef::Side::updateTopSoundEmitterOrigin()
}
}

HEdge &LineDef::Side::leftHEdge() const
{
DENG_ASSERT(_leftHEdge != 0);
return *_leftHEdge;
}

HEdge &LineDef::Side::rightHEdge() const
{
DENG_ASSERT(_rightHEdge != 0);
return *_rightHEdge;
}

int LineDef::Side::shadowVisCount() const
{
return _shadowVisCount;
}

void LineDef::Side::updateSoundEmitterOrigins()
void LineDef::Side::updateAllSoundEmitterOrigins()
{
if(!_sideDef) return;

Expand Down Expand Up @@ -235,6 +238,25 @@ void LineDef::Side::updateSurfaceNormals()
topSurface.setNormal(normal);
}

#ifdef __CLIENT__

LineDef::Side::FakeRadioData &LineDef::Side::fakeRadioData()
{
return _fakeRadioData;
}

LineDef::Side::FakeRadioData const &LineDef::Side::fakeRadioData() const
{
return const_cast<FakeRadioData const &>(const_cast<Side *>(this)->fakeRadioData());
}

#endif // __CLIENT__

int LineDef::Side::shadowVisCount() const
{
return _shadowVisCount;
}

DENG2_PIMPL(LineDef)
{
/// Vertexes:
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/src/map/p_dmu.cpp
Expand Up @@ -1405,7 +1405,6 @@ static int getProperty(void *ptr, void *context)
case DMU_ALPHA:
case DMU_BLENDMODE:
case DMU_FLAGS:
case DMU_BASE:
elem = &elem->castTo<Plane>()->surface();
args->type = DMU_SURFACE;
DENG2_ASSERT(elem->type() == args->type);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/sector.cpp
Expand Up @@ -396,8 +396,8 @@ void Sector::planeHeightChanged(Plane &plane, coord_t oldHeight)
// Update the sound emitter origins for all dependent wall surfaces.
foreach(LineDef *line, d->lines)
{
line->front().updateSoundEmitterOrigins();
line->back().updateSoundEmitterOrigins();
line->front().updateAllSoundEmitterOrigins();
line->back().updateAllSoundEmitterOrigins();
}

#ifdef __CLIENT__
Expand Down
22 changes: 0 additions & 22 deletions doomsday/client/src/map/sidedef.cpp
Expand Up @@ -35,14 +35,6 @@ SideDef::SideDef()
_line = 0;
_flags = 0;
std::memset(&_buildData, 0, sizeof(_buildData));

#ifdef __CLIENT__
_fakeRadioData.updateCount = 0;
std::memset(_fakeRadioData.topCorners, 0, sizeof(_fakeRadioData.topCorners));
std::memset(_fakeRadioData.bottomCorners, 0, sizeof(_fakeRadioData.bottomCorners));
std::memset(_fakeRadioData.sideCorners, 0, sizeof(_fakeRadioData.sideCorners));
std::memset(_fakeRadioData.spans, 0, sizeof(_fakeRadioData.spans));
#endif
}

SideDef::~SideDef()
Expand Down Expand Up @@ -76,20 +68,6 @@ short SideDef::flags() const
return _flags;
}

#ifdef __CLIENT__

SideDef::FakeRadioData &SideDef::fakeRadioData()
{
return _fakeRadioData;
}

SideDef::FakeRadioData const &SideDef::fakeRadioData() const
{
return const_cast<FakeRadioData const &>(const_cast<SideDef *>(this)->fakeRadioData());
}

#endif // __CLIENT__

int SideDef::property(setargs_t &args) const
{
switch(args.prop)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -86,7 +86,7 @@ void Rend_RadioUpdateLine(LineDef &line, int backSide)
if(!line.hasSector(backSide)) return;

// Have already determined the shadow properties on this side?
SideDef::FakeRadioData &frData = line.sideDef(backSide).fakeRadioData();
LineDef::Side::FakeRadioData &frData = line.side(backSide).fakeRadioData();
if(frData.updateCount == frameCount) return;

// Not yet - Calculate now.
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1222,7 +1222,6 @@ static boolean doRenderHEdge(HEdge *hedge, Vector3f const &normal,
MaterialSnapshot const &ms,
boolean isTwosidedMiddle)
{
SideDef *sideDef = hedge->hasLine()? hedge->lineSide().sideDefPtr() : 0;
rvertex_t *rvertices;

// Init the params.
Expand Down Expand Up @@ -1298,7 +1297,7 @@ static boolean doRenderHEdge(HEdge *hedge, Vector3f const &normal,

radioParams.line = hedge->linePtr();

SideDef::FakeRadioData &frData = sideDef->fakeRadioData();
LineDef::Side::FakeRadioData &frData = hedge->lineSide().fakeRadioData();
radioParams.botCn = frData.bottomCorners;
radioParams.topCn = frData.topCorners;
radioParams.sideCn = frData.sideCorners;
Expand Down

0 comments on commit f4854db

Please sign in to comment.