Skip to content

Commit

Permalink
World|Map|Line: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 6, 2013
1 parent ef382f7 commit 8d51554
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions doomsday/client/src/world/line.cpp
Expand Up @@ -53,7 +53,7 @@ struct Section

DENG2_PIMPL_NOREF(Line::Side)
#ifdef __CLIENT__
, DENG2_OBSERVES(Line, FlagsChange)
, DENG2_OBSERVES(Line, FlagsChange)
#endif
{
struct Sections
Expand All @@ -69,9 +69,6 @@ DENG2_PIMPL_NOREF(Line::Side)
/// @ref sdefFlags
int flags;

/// Line owner of the side.
Line &line;

/// Sections.
QScopedPointer<Sections> sections;

Expand All @@ -87,20 +84,34 @@ DENG2_PIMPL_NOREF(Line::Side)
/// Framecount of last time shadows were drawn on this side.
int shadowVisCount;

Instance(Line &line, Sector *sector)
Instance(Sector *sector)
: flags(0),
line(line),
sector(sector),
leftSegment(0),
rightSegment(0),
shadowVisCount(0)
{}

/**
* Retrieve the Section associated with @a sectionId.
*/
Section &sectionById(int sectionId)
{
#ifdef __CLIENT__
line.audienceForFlagsChange += this;
#endif
if(!sections.isNull())
{
switch(sectionId)
{
case Middle: return sections->middle;
case Bottom: return sections->bottom;
case Top: return sections->top;
}
}
/// @throw Line::InvalidSectionIdError The given section identifier is not valid.
throw Line::InvalidSectionIdError("Line::Side::section", QString("Invalid section id %1").arg(sectionId));
}

#ifdef __CLIENT__
/// Observes Line FlagsChange
void lineFlagsChanged(Line &line, int oldFlags)
{
if(!sections.isNull())
Expand All @@ -117,37 +128,24 @@ DENG2_PIMPL_NOREF(Line::Side)
}
#endif

/**
* Retrieve the Section associated with @a sectionId.
*/
Section &sectionById(int sectionId)
{
if(!sections.isNull())
{
switch(sectionId)
{
case Middle: return sections->middle;
case Bottom: return sections->bottom;
case Top: return sections->top;
}
}
/// @throw Line::InvalidSectionIdError The given section identifier is not valid.
throw Line::InvalidSectionIdError("Line::Side::section", QString("Invalid section id %1").arg(sectionId));
}
};

Line::Side::Side(Line &line, Sector *sector)
: MapElement(DMU_SIDE, &line), d(new Instance(line, sector))
{}
: MapElement(DMU_SIDE, &line), d(new Instance(sector))
{
#ifdef __CLIENT__
line.audienceForFlagsChange += d;
#endif
}

Line &Line::Side::line() const
{
return d->line;
return *this->parent().as<Line>();
}

int Line::Side::sideId() const
{
return &d->line.front() == this? Line::Front : Line::Back;
return &line().front() == this? Line::Front : Line::Back;
}

bool Line::Side::considerOneSided() const
Expand All @@ -159,7 +157,7 @@ bool Line::Side::considerOneSided() const
// Front side of a "one-way window"?
if(!back().hasSections()) return true;

if(!d->line.definesPolyobj())
if(!line().definesPolyobj())
{
// If no segment is linked then the convex subspace on "this" side must
// have been degenerate (thus no geometry).
Expand Down Expand Up @@ -254,7 +252,7 @@ void Line::Side::updateSoundEmitterOrigin(int sectionId)

ddmobj_base_t &emitter = d->sectionById(sectionId).soundEmitter;

Vector2d lineCenter = d->line.center();
Vector2d lineCenter = line().center();
emitter.origin[VX] = lineCenter.x;
emitter.origin[VY] = lineCenter.y;

Expand All @@ -266,7 +264,7 @@ void Line::Side::updateSoundEmitterOrigin(int sectionId)
switch(sectionId)
{
case Middle:
if(!back().hasSections() || d->line.isSelfReferencing())
if(!back().hasSections() || line().isSelfReferencing())
{
emitter.origin[VZ] = (ffloor + fceil) / 2;
}
Expand All @@ -278,7 +276,7 @@ void Line::Side::updateSoundEmitterOrigin(int sectionId)
break;

case Bottom:
if(!back().hasSections() || d->line.isSelfReferencing() ||
if(!back().hasSections() || line().isSelfReferencing() ||
back().sector().floor().height() <= ffloor)
{
emitter.origin[VZ] = ffloor;
Expand All @@ -290,7 +288,7 @@ void Line::Side::updateSoundEmitterOrigin(int sectionId)
break;

case Top:
if(!back().hasSections() || d->line.isSelfReferencing() ||
if(!back().hasSections() || line().isSelfReferencing() ||
back().sector().ceiling().height() >= fceil)
{
emitter.origin[VZ] = fceil;
Expand All @@ -316,8 +314,8 @@ void Line::Side::updateSurfaceNormals()
{
if(!hasSections()) return;

Vector3f normal(( to().origin().y - from().origin().y) / d->line.length(),
(from().origin().x - to().origin().x) / d->line.length(),
Vector3f normal(( to().origin().y - from().origin().y) / line().length(),
(from().origin().x - to().origin().x) / line().length(),
0);

// All line side surfaces have the same normals.
Expand Down Expand Up @@ -410,8 +408,8 @@ int Line::Side::property(DmuArgs &args) const
args.setValue(DMT_LINESIDE_SECTOR, &d->sector, 0);
break;
case DMU_LINE: {
Line *line = &d->line;
args.setValue(DMT_LINESIDE_LINE, &line, 0);
Line *lineAdr = &line();
args.setValue(DMT_LINESIDE_LINE, &lineAdr, 0);
break; }
case DMU_FLAGS:
args.setValue(DMT_LINESIDE_FLAGS, &d->flags, 0);
Expand Down

0 comments on commit 8d51554

Please sign in to comment.