Skip to content

Commit

Permalink
Refactor|MapElement: Renamed castTo() to as()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 13, 2013
1 parent 0d6753f commit d711ae9
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 57 deletions.
6 changes: 2 additions & 4 deletions doomsday/client/include/world/mapelement.h
Expand Up @@ -84,18 +84,16 @@ class MapElement

void setIndexInMap(int newIndex = NoIndex);

/// @todo Rename to as().
template <typename Type>
inline Type *castTo()
inline Type *as()
{
Type *t = dynamic_cast<Type *>(this);
DENG2_ASSERT(t != 0);
return t;
}

/// @todo Rename to as().
template <typename Type>
inline Type const *castTo() const
inline Type const *as() const
{
Type const *t = dynamic_cast<Type const *>(this);
DENG_ASSERT(t != 0);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/world/segment.h
Expand Up @@ -101,7 +101,7 @@ class Segment : public de::MapElement
* @see hasBspLeaf(), Face::mapElement()
*/
inline BspLeaf &bspLeaf() const {
return *hedge().face().mapElement()->castTo<BspLeaf>();
return *hedge().face().mapElement()->as<BspLeaf>();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/lumobj.cpp
Expand Up @@ -989,7 +989,7 @@ static void createGlowLightForSurface(Surface &suf)
if(suf.owner().type() != DMU_PLANE)
return;

Plane *pln = suf.owner().castTo<Plane>();
Plane *pln = suf.owner().as<Plane>();
Sector *sec = &pln->sector();

// Only produce a light for sectors with open space.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_bias.cpp
Expand Up @@ -792,13 +792,13 @@ void SB_RendPoly(struct ColorRawf_s *rcolors, BiasSurface *bsuf,
*/
if(mapElement->type() == DMU_SEGMENT)
{
Segment const *segment = mapElement->castTo<Segment>();
Segment const *segment = mapElement->as<Segment>();

updateAffected(bsuf, segment->from().origin(), segment->to().origin(), surfaceNormal);
}
else
{
BspLeaf const *bspLeaf = mapElement->castTo<BspLeaf>();
BspLeaf const *bspLeaf = mapElement->as<BspLeaf>();
DENG_ASSERT(!bspLeaf->isDegenerate());

Vector3d point(bspLeaf->face().center(),
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_decor.cpp
Expand Up @@ -329,13 +329,13 @@ static void plotSourcesForSurface(Surface &suf)
switch(suf.owner().type())
{
case DMU_SIDE: {
Line::Side *side = suf.owner().castTo<Line::Side>();
Line::Side *side = suf.owner().as<Line::Side>();
plotSourcesForLineSide(*side, &side->middle() == &suf? Line::Side::Middle :
&side->bottom() == &suf? Line::Side::Bottom : Line::Side::Top);
break; }

case DMU_PLANE: {
Plane *plane = suf.owner().castTo<Plane>();
Plane *plane = suf.owner().as<Plane>();
plotSourcesForPlane(*plane);
break; }

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2374,7 +2374,7 @@ static void traverseBspAndDrawLeafs(MapElement *bspElement)
while(bspElement->type() != DMU_BSPLEAF)
{
// Descend deeper into the nodes.
BspNode const *bspNode = bspElement->castTo<BspNode>();
BspNode const *bspNode = bspElement->as<BspNode>();

// Decide which side the view point is on.
int eyeSide = bspNode->partition().pointOnSide(eyeOrigin) < 0;
Expand All @@ -2393,7 +2393,7 @@ static void traverseBspAndDrawLeafs(MapElement *bspElement)
}

// We've arrived at a leaf.
BspLeaf *bspLeaf = bspElement->castTo<BspLeaf>();
BspLeaf *bspLeaf = bspElement->as<BspLeaf>();

// Skip null leafs (those with zero volume). Neighbors handle adding the
// solid clipper segments.
Expand Down
56 changes: 28 additions & 28 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -276,7 +276,7 @@ void *P_DummyExtraData(void *dummy)
if(P_IsDummy(dummy))
{
MapElement *elem = IN_ELEM(dummy);
return elem->castTo<DummyData>()->extraData;
return elem->as<DummyData>()->extraData;
}
return 0;
}
Expand All @@ -301,10 +301,10 @@ int P_ToIndex(void const *ptr)
return elem->indexInMap();

case DMU_PLANE:
return elem->castTo<Plane>()->inSectorIndex();
return elem->as<Plane>()->inSectorIndex();

case DMU_MATERIAL:
return elem->castTo<Material>()->manifest().id(); // 1-based
return elem->as<Material>()->manifest().id(); // 1-based

default:
/// @todo Throw exception.
Expand Down Expand Up @@ -391,23 +391,23 @@ int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p,
switch(prop)
{
case DMU_LINE:
foreach(Line::Side *side, elem->castTo<Sector>()->sides())
foreach(Line::Side *side, elem->as<Sector>()->sides())
{
int result = callback(&side->line(), context);
if(result) return result;
}
return false; // Continue iteration

case DMU_PLANE:
foreach(Plane *plane, elem->castTo<Sector>()->planes())
foreach(Plane *plane, elem->as<Sector>()->planes())
{
int result = callback(plane, context);
if(result) return result;
}
return false; // Continue iteration

case DMU_BSPLEAF:
foreach(BspLeaf *bspLeaf, elem->castTo<Sector>()->bspLeafs())
foreach(BspLeaf *bspLeaf, elem->as<Sector>()->bspLeafs())
{
int result = callback(bspLeaf, context);
if(result) return result;
Expand All @@ -422,7 +422,7 @@ int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p,
switch(prop)
{
case DMU_SEGMENT:
foreach(Segment *seg, elem->castTo<BspLeaf>()->allSegments())
foreach(Segment *seg, elem->as<BspLeaf>()->allSegments())
{
int result = callback(seg, context);
if(result) return result;
Expand Down Expand Up @@ -583,12 +583,12 @@ static void setProperty(MapElement *elem, DmuArgs &args)
{
if(args.modifiers & DMU_FLOOR_OF_SECTOR)
{
elem = elem->castTo<BspLeaf>()->sectorPtr();
elem = elem->as<BspLeaf>()->sectorPtr();
args.type = DMU_SECTOR;
}
else if(args.modifiers & DMU_CEILING_OF_SECTOR)
{
elem = elem->castTo<BspLeaf>()->sectorPtr();
elem = elem->as<BspLeaf>()->sectorPtr();
args.type = DMU_SECTOR;
}
}
Expand All @@ -597,12 +597,12 @@ static void setProperty(MapElement *elem, DmuArgs &args)
{
if(args.modifiers & DMU_FLOOR_OF_SECTOR)
{
elem = &elem->castTo<Sector>()->floor();
elem = &elem->as<Sector>()->floor();
args.type = DMU_PLANE;
}
else if(args.modifiers & DMU_CEILING_OF_SECTOR)
{
elem = &elem->castTo<Sector>()->ceiling();
elem = &elem->as<Sector>()->ceiling();
args.type = DMU_PLANE;
}
}
Expand All @@ -611,12 +611,12 @@ static void setProperty(MapElement *elem, DmuArgs &args)
{
if(args.modifiers & DMU_FRONT_OF_LINE)
{
elem = &elem->castTo<Line>()->front();
elem = &elem->as<Line>()->front();
args.type = DMU_SIDE;
}
else if(args.modifiers & DMU_BACK_OF_LINE)
{
elem = &elem->castTo<Line>()->back();
elem = &elem->as<Line>()->back();
args.type = DMU_SIDE;
}
}
Expand All @@ -625,17 +625,17 @@ static void setProperty(MapElement *elem, DmuArgs &args)
{
if(args.modifiers & DMU_TOP_OF_SIDE)
{
elem = &elem->castTo<Line::Side>()->top();
elem = &elem->as<Line::Side>()->top();
args.type = DMU_SURFACE;
}
else if(args.modifiers & DMU_MIDDLE_OF_SIDE)
{
elem = &elem->castTo<Line::Side>()->middle();
elem = &elem->as<Line::Side>()->middle();
args.type = DMU_SURFACE;
}
else if(args.modifiers & DMU_BOTTOM_OF_SIDE)
{
elem = &elem->castTo<Line::Side>()->bottom();
elem = &elem->as<Line::Side>()->bottom();
args.type = DMU_SURFACE;
}
}
Expand Down Expand Up @@ -667,7 +667,7 @@ static void setProperty(MapElement *elem, DmuArgs &args)
case DMU_ALPHA:
case DMU_BLENDMODE:
case DMU_FLAGS:
elem = &elem->castTo<Plane>()->surface();
elem = &elem->as<Plane>()->surface();
args.type = DMU_SURFACE;
break;

Expand All @@ -689,12 +689,12 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
{
if(args.modifiers & DMU_FLOOR_OF_SECTOR)
{
elem = elem->castTo<BspLeaf>()->sectorPtr();
elem = elem->as<BspLeaf>()->sectorPtr();
args.type = elem->type();
}
else if(args.modifiers & DMU_CEILING_OF_SECTOR)
{
elem = elem->castTo<BspLeaf>()->sectorPtr();
elem = elem->as<BspLeaf>()->sectorPtr();
args.type = elem->type();
}
else
Expand All @@ -703,7 +703,7 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
{
case DMU_LIGHT_LEVEL:
case DMT_MOBJS:
elem = elem->castTo<BspLeaf>()->sectorPtr();
elem = elem->as<BspLeaf>()->sectorPtr();
args.type = elem->type();
break;

Expand All @@ -716,12 +716,12 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
{
if(args.modifiers & DMU_FLOOR_OF_SECTOR)
{
elem = &elem->castTo<Sector>()->floor();
elem = &elem->as<Sector>()->floor();
args.type = elem->type();
}
else if(args.modifiers & DMU_CEILING_OF_SECTOR)
{
elem = &elem->castTo<Sector>()->ceiling();
elem = &elem->as<Sector>()->ceiling();
args.type = elem->type();
}
}
Expand All @@ -730,12 +730,12 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
{
if(args.modifiers & DMU_FRONT_OF_LINE)
{
elem = &elem->castTo<Line>()->front();
elem = &elem->as<Line>()->front();
args.type = elem->type();
}
else if(args.modifiers & DMU_BACK_OF_LINE)
{
elem = &elem->castTo<Line>()->back();
elem = &elem->as<Line>()->back();
args.type = elem->type();
}
}
Expand All @@ -744,17 +744,17 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
{
if(args.modifiers & DMU_TOP_OF_SIDE)
{
elem = &elem->castTo<Line::Side>()->top();
elem = &elem->as<Line::Side>()->top();
args.type = elem->type();
}
else if(args.modifiers & DMU_MIDDLE_OF_SIDE)
{
elem = &elem->castTo<Line::Side>()->middle();
elem = &elem->as<Line::Side>()->middle();
args.type = elem->type();
}
else if(args.modifiers & DMU_BOTTOM_OF_SIDE)
{
elem = &elem->castTo<Line::Side>()->bottom();
elem = &elem->as<Line::Side>()->bottom();
args.type = elem->type();
}
}
Expand Down Expand Up @@ -786,7 +786,7 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
case DMU_ALPHA:
case DMU_BLENDMODE:
case DMU_FLAGS:
elem = &elem->castTo<Plane>()->surface();
elem = &elem->as<Plane>()->surface();
args.type = elem->type();
break;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/bsp/partitioner.cpp
Expand Up @@ -1550,7 +1550,7 @@ DENG2_PIMPL(Partitioner)
switch(elm->type())
{
case DMU_VERTEX: {
Vertex *vtx = elm->castTo<Vertex>();
Vertex *vtx = elm->as<Vertex>();
/// @todo optimize: Poor performance O(n).
for(uint i = 0; i < vertexes.size(); ++i)
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -148,7 +148,7 @@ DENG2_PIMPL(BspLeaf)
{
if(MapElement *elem = hedge->mapElement())
{
clockwiseSegments.append(elem->castTo<Segment>());
clockwiseSegments.append(elem->as<Segment>());
}
} while((hedge = &hedge->next()) != face.hedge());

Expand Down Expand Up @@ -207,7 +207,7 @@ DENG2_PIMPL(BspLeaf)
{
if(MapElement *elem = hedge->mapElement())
{
allSegments.append(elem->castTo<Segment>());
allSegments.append(elem->as<Segment>());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/linesighttest.cpp
Expand Up @@ -278,7 +278,7 @@ DENG2_PIMPL(LineSightTest)

while(bspElement->type() != DMU_BSPLEAF)
{
BspNode const *bspNode = bspElement->castTo<BspNode>();
BspNode const *bspNode = bspElement->as<BspNode>();

// Does the ray intersect the partition?
/// @todo Optionally use the fixed precision version -ds
Expand All @@ -300,7 +300,7 @@ DENG2_PIMPL(LineSightTest)
}

// We've arrived at a leaf.
return crossBspLeaf(*bspElement->castTo<BspLeaf>());
return crossBspLeaf(*bspElement->as<BspLeaf>());
}
};

Expand Down

0 comments on commit d711ae9

Please sign in to comment.