Skip to content

Commit

Permalink
Refactor|Line::Side: Made private more Line::Side instance data
Browse files Browse the repository at this point in the history
Line/sector/sidedef archive index/sections/left and right hedges.
  • Loading branch information
danij-deng committed Apr 14, 2013
1 parent 5ee4d8f commit 7fafdc9
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 45 deletions.
97 changes: 74 additions & 23 deletions doomsday/client/include/map/line.h
Expand Up @@ -184,27 +184,6 @@ class Line : public de::MapElement
};

public: /// @todo make private:
/// Line owner of the side.
Line &_line;

/// Attributed sector.
Sector *_sector;

/// 1-based index of the associated sidedef in the archived map; otherwise @c 0.
uint _sideDefArchiveIndex;

/// Sections.
Sections *_sections;

/// Left-most half-edge on this side of the owning line.
HEdge *_leftHEdge;

/// Right-most half-edge on this side of the owning line.
HEdge *_rightHEdge;

/// Framecount of last time shadows were drawn on this side.
int _shadowVisCount;

/// @ref sdefFlags
short _flags;

Expand Down Expand Up @@ -271,10 +250,19 @@ class Line : public de::MapElement
*/
bool hasSections() const;

/**
* Add default sections to the side if they aren't already defined.
*
* @see hasSections()
*/
void addSections();

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

Expand All @@ -285,6 +273,8 @@ class Line : public de::MapElement
* Returns the specified surface of the side.
*
* @param sectionId Identifier of the surface to return.
*
* @see section()
*/
inline Surface &surface(SideSection sectionId) {
return section(sectionId).surface();
Expand All @@ -297,6 +287,8 @@ class Line : public de::MapElement

/**
* Returns the middle surface of the side.
*
* @see surface()
*/
inline Surface &middle() { return surface(SS_MIDDLE); }

Expand All @@ -305,6 +297,8 @@ class Line : public de::MapElement

/**
* Returns the bottom surface of the side.
*
* @see surface()
*/
inline Surface &bottom() { return surface(SS_BOTTOM); }

Expand All @@ -313,6 +307,8 @@ class Line : public de::MapElement

/**
* Returns the top surface of the side.
*
* @see surface()
*/
inline Surface &top() { return surface(SS_TOP); }

Expand All @@ -323,6 +319,8 @@ class Line : public de::MapElement
* Returns the specified sound emitter of the side.
*
* @param sectionId Identifier of the sound emitter to return.
*
* @see section(), Section::soundEmitter()
*/
inline ddmobj_base_t &soundEmitter(SideSection sectionId) {
return section(sectionId).soundEmitter();
Expand All @@ -335,6 +333,8 @@ class Line : public de::MapElement

/**
* Returns the middle sound emitter of the side.
*
* @see section(), Section::soundEmitter()
*/
inline ddmobj_base_t &middleSoundEmitter() {
return section(SS_MIDDLE).soundEmitter();
Expand All @@ -354,6 +354,8 @@ class Line : public de::MapElement

/**
* Returns the bottom sound emitter (tee-hee) for the side.
*
* @see section(), Section::soundEmitter()
*/
inline ddmobj_base_t &bottomSoundEmitter() {
return section(SS_BOTTOM).soundEmitter();
Expand All @@ -373,6 +375,8 @@ class Line : public de::MapElement

/**
* Returns the top sound emitter for the side.
*
* @see section(), Section::soundEmitter()
*/
inline ddmobj_base_t &topSoundEmitter() {
return section(SS_TOP).soundEmitter();
Expand Down Expand Up @@ -410,15 +414,33 @@ class Line : public de::MapElement
#endif // __CLIENT__

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

/**
* Returns the right-most HEdge for the side.
* Change the left-most half-edge for the side.
*
* @param newHEdge New half-edge to set as the left-most. Can be @c 0.
*
* @todo Refactor away. Only needed presently because of Polyobj.
*/
void setLeftHEdge(HEdge *newHEdge);

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

/**
* Change the right-most half-edge for the side.
*
* @param newHEdge New half-edge to set as the right-most. Can be @c 0.
*
* @todo Refactor away. Only needed presently because of Polyobj.
*/
void setRightHEdge(HEdge *newHEdge);

/**
* 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 All @@ -436,6 +458,13 @@ class Line : public de::MapElement
*/
int shadowVisCount() const;

/**
* Change the frame number of the last time shadows were drawn for the side.
*
* @param newCount New shadow vis count.
*/
void setShadowVisCount(int newCount);

/**
* Change the "archive index" of the associated sidedef. The archive
* index is the position of the sidedef in the archived map data. Note
Expand All @@ -460,6 +489,28 @@ class Line : public de::MapElement
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);

private: /// @todo Move to a private Instance.
/// Line owner of the side.
Line &_line;

/// Attributed sector.
Sector *_sector;

/// 1-based index of the associated sidedef in the archived map; otherwise @c 0.
uint _sideDefArchiveIndex;

/// Sections.
Sections *_sections;

/// Left-most half-edge on this side of the owning line.
HEdge *_leftHEdge;

/// Right-most half-edge on this side of the owning line.
HEdge *_rightHEdge;

/// Framecount of last time shadows were drawn on this side.
int _shadowVisCount;
};

public: /// @todo make private:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/polyobj.h
Expand Up @@ -63,7 +63,7 @@ typedef struct polyobj_s
{
foreach(Line *line, lines())
{
delete line->front()._leftHEdge;
delete &line->front().leftHEdge();
}

delete static_cast<Lines *>(_lines);
Expand Down
20 changes: 5 additions & 15 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -108,14 +108,6 @@ class EditableMap
return line;
}

Line::Side *createLineSideSections(Line &line, int sideId)
{
Line::Side &side = line.side(sideId);
DENG_ASSERT(!side._sections);
side._sections = new Line::Side::Sections(side);
return &side;
}

Sector *createSector(float lightLevel, Vector3f const &lightColor)
{
Sector *sector = new Sector(lightLevel, lightColor);
Expand Down Expand Up @@ -985,8 +977,8 @@ boolean MPE_End()
hedge->_twin = 0;
hedge->_bspLeaf = 0;

line->front()._leftHEdge =
line->front()._rightHEdge = hedge;
line->front().setLeftHEdge(hedge);
line->front().setRightHEdge(hedge);
}

polyobj->buildUniqueVertexes();
Expand Down Expand Up @@ -1132,16 +1124,14 @@ void MPE_LineAddSide(uint lineIdx, int sideId, short flags, ddstring_t const *to
if(lineIdx == 0 || lineIdx > (uint)editMap.lines.count()) return;

Line *line = editMap.lines[lineIdx - 1];
if(!line->hasSections(sideId))
{
editMap.createLineSideSections(*line, sideId);
}

Line::Side &side = line->side(sideId);

side._flags = flags;
side.setSideDefArchiveIndex(sideDefArchiveIndex);

// Ensure sections are defined if they aren't already.
side.addSections();

// Assign the resolved material if found.
side.top().setMaterial(findMaterialInDict(topMaterialUri));
side.top().setMaterialOrigin(topOffsetX, topOffsetY);
Expand Down
33 changes: 28 additions & 5 deletions doomsday/client/src/map/line.cpp
Expand Up @@ -43,14 +43,14 @@ using namespace de;

Line::Side::Side(Line &line, Sector *sector)
: MapElement(DMU_SIDE),
_flags(0),
_line(line),
_sector(sector),
_sections(0),
_sideDefArchiveIndex(0), // no-index
_leftHEdge(0),
_rightHEdge(0),
_shadowVisCount(0),
_flags(0)
_shadowVisCount(0)
{
#ifdef __CLIENT__
_fakeRadioData.updateCount = 0;
Expand Down Expand Up @@ -101,6 +101,14 @@ bool Line::Side::hasSections() const
return _sections != 0;
}

void Line::Side::addSections()
{
// Already defined?
if(_sections) return;

_sections = new Sections(*this);
}

void Line::Side::setSideDefArchiveIndex(uint newIndex)
{
_sideDefArchiveIndex = newIndex;
Expand All @@ -124,7 +132,7 @@ Line::Side::Section &Line::Side::section(SideSection sectionId)

Line::Side::Section const &Line::Side::section(SideSection sectionId) const
{
return const_cast<Section const &>(const_cast<Side &>(*this).section(sectionId));
return const_cast<Section const &>(const_cast<Side *>(this)->section(sectionId));
}

HEdge &Line::Side::leftHEdge() const
Expand All @@ -133,6 +141,16 @@ HEdge &Line::Side::leftHEdge() const
return *_leftHEdge;
}

void Line::Side::setLeftHEdge(HEdge *newLeftHEdge)
{
_leftHEdge = newLeftHEdge;
}

void Line::Side::setRightHEdge(HEdge *newRightHEdge)
{
_rightHEdge = newRightHEdge;
}

HEdge &Line::Side::rightHEdge() const
{
DENG_ASSERT(_rightHEdge != 0);
Expand Down Expand Up @@ -256,6 +274,11 @@ int Line::Side::shadowVisCount() const
return _shadowVisCount;
}

void Line::Side::setShadowVisCount(int newCount)
{
_shadowVisCount = newCount;
}

int Line::Side::property(setargs_t &args) const
{
switch(args.prop)
Expand Down Expand Up @@ -597,7 +620,7 @@ int Line::setProperty(setargs_t const &args)

switch(args.prop)
{
case DMU_FRONT_SECTOR: {
/*case DMU_FRONT_SECTOR: {
Sector *newFrontSector = frontSectorPtr();
DMU_SetValue(DMT_LINE_SECTOR, &newFrontSector, &args, 0);
d->front._sector = newFrontSector;
Expand All @@ -607,7 +630,7 @@ int Line::setProperty(setargs_t const &args)
DMU_SetValue(DMT_LINE_SECTOR, &newBackSector, &args, 0);
d->back._sector = newBackSector;
break; }
/*case DMU_FRONT: {
case DMU_FRONT: {
SideDef *newFrontSideDef = frontSideDefPtr();
DMU_SetValue(DMT_LINE_SIDE, &newFrontSideDef, &args, 0);
d->front._sideDef = newFrontSideDef;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1440,7 +1440,7 @@ static void drawLinkedEdgeShadows(BspLeaf const &bspLeaf, ShadowLink &link,
}

// Mark it rendered for this frame.
link.lineSide()._shadowVisCount = frameCount;
link.lineSide().setShadowVisCount(frameCount);
}

/**
Expand Down

0 comments on commit 7fafdc9

Please sign in to comment.