From d711ae92af47ae09a47daeed1e74d07b328a3ea8 Mon Sep 17 00:00:00 2001 From: danij Date: Thu, 13 Jun 2013 04:30:45 +0100 Subject: [PATCH] Refactor|MapElement: Renamed castTo() to as() --- doomsday/client/include/world/mapelement.h | 6 +- doomsday/client/include/world/segment.h | 2 +- doomsday/client/src/render/lumobj.cpp | 2 +- doomsday/client/src/render/rend_bias.cpp | 4 +- doomsday/client/src/render/rend_decor.cpp | 4 +- doomsday/client/src/render/rend_main.cpp | 4 +- doomsday/client/src/world/api_map.cpp | 56 +++++++++---------- doomsday/client/src/world/bsp/partitioner.cpp | 2 +- doomsday/client/src/world/bspleaf.cpp | 4 +- doomsday/client/src/world/linesighttest.cpp | 4 +- doomsday/client/src/world/map.cpp | 12 ++-- doomsday/client/src/world/surface.cpp | 10 ++-- doomsday/server/src/server/sv_pool.cpp | 2 +- 13 files changed, 55 insertions(+), 57 deletions(-) diff --git a/doomsday/client/include/world/mapelement.h b/doomsday/client/include/world/mapelement.h index 02840b535d..4f7ba0caa4 100644 --- a/doomsday/client/include/world/mapelement.h +++ b/doomsday/client/include/world/mapelement.h @@ -84,18 +84,16 @@ class MapElement void setIndexInMap(int newIndex = NoIndex); - /// @todo Rename to as(). template - inline Type *castTo() + inline Type *as() { Type *t = dynamic_cast(this); DENG2_ASSERT(t != 0); return t; } - /// @todo Rename to as(). template - inline Type const *castTo() const + inline Type const *as() const { Type const *t = dynamic_cast(this); DENG_ASSERT(t != 0); diff --git a/doomsday/client/include/world/segment.h b/doomsday/client/include/world/segment.h index 0ca9ada7b7..0a1137244a 100644 --- a/doomsday/client/include/world/segment.h +++ b/doomsday/client/include/world/segment.h @@ -101,7 +101,7 @@ class Segment : public de::MapElement * @see hasBspLeaf(), Face::mapElement() */ inline BspLeaf &bspLeaf() const { - return *hedge().face().mapElement()->castTo(); + return *hedge().face().mapElement()->as(); } /** diff --git a/doomsday/client/src/render/lumobj.cpp b/doomsday/client/src/render/lumobj.cpp index 89da25d46d..7fdbe5e179 100644 --- a/doomsday/client/src/render/lumobj.cpp +++ b/doomsday/client/src/render/lumobj.cpp @@ -989,7 +989,7 @@ static void createGlowLightForSurface(Surface &suf) if(suf.owner().type() != DMU_PLANE) return; - Plane *pln = suf.owner().castTo(); + Plane *pln = suf.owner().as(); Sector *sec = &pln->sector(); // Only produce a light for sectors with open space. diff --git a/doomsday/client/src/render/rend_bias.cpp b/doomsday/client/src/render/rend_bias.cpp index a213f617a5..f0dc5d562b 100644 --- a/doomsday/client/src/render/rend_bias.cpp +++ b/doomsday/client/src/render/rend_bias.cpp @@ -792,13 +792,13 @@ void SB_RendPoly(struct ColorRawf_s *rcolors, BiasSurface *bsuf, */ if(mapElement->type() == DMU_SEGMENT) { - Segment const *segment = mapElement->castTo(); + Segment const *segment = mapElement->as(); updateAffected(bsuf, segment->from().origin(), segment->to().origin(), surfaceNormal); } else { - BspLeaf const *bspLeaf = mapElement->castTo(); + BspLeaf const *bspLeaf = mapElement->as(); DENG_ASSERT(!bspLeaf->isDegenerate()); Vector3d point(bspLeaf->face().center(), diff --git a/doomsday/client/src/render/rend_decor.cpp b/doomsday/client/src/render/rend_decor.cpp index be19c9a947..9d4cdf8f0e 100644 --- a/doomsday/client/src/render/rend_decor.cpp +++ b/doomsday/client/src/render/rend_decor.cpp @@ -329,13 +329,13 @@ static void plotSourcesForSurface(Surface &suf) switch(suf.owner().type()) { case DMU_SIDE: { - Line::Side *side = suf.owner().castTo(); + Line::Side *side = suf.owner().as(); 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 = suf.owner().as(); plotSourcesForPlane(*plane); break; } diff --git a/doomsday/client/src/render/rend_main.cpp b/doomsday/client/src/render/rend_main.cpp index 5d68733750..f5c900b9aa 100644 --- a/doomsday/client/src/render/rend_main.cpp +++ b/doomsday/client/src/render/rend_main.cpp @@ -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 const *bspNode = bspElement->as(); // Decide which side the view point is on. int eyeSide = bspNode->partition().pointOnSide(eyeOrigin) < 0; @@ -2393,7 +2393,7 @@ static void traverseBspAndDrawLeafs(MapElement *bspElement) } // We've arrived at a leaf. - BspLeaf *bspLeaf = bspElement->castTo(); + BspLeaf *bspLeaf = bspElement->as(); // Skip null leafs (those with zero volume). Neighbors handle adding the // solid clipper segments. diff --git a/doomsday/client/src/world/api_map.cpp b/doomsday/client/src/world/api_map.cpp index 210111acab..bb52d8bad3 100644 --- a/doomsday/client/src/world/api_map.cpp +++ b/doomsday/client/src/world/api_map.cpp @@ -276,7 +276,7 @@ void *P_DummyExtraData(void *dummy) if(P_IsDummy(dummy)) { MapElement *elem = IN_ELEM(dummy); - return elem->castTo()->extraData; + return elem->as()->extraData; } return 0; } @@ -301,10 +301,10 @@ int P_ToIndex(void const *ptr) return elem->indexInMap(); case DMU_PLANE: - return elem->castTo()->inSectorIndex(); + return elem->as()->inSectorIndex(); case DMU_MATERIAL: - return elem->castTo()->manifest().id(); // 1-based + return elem->as()->manifest().id(); // 1-based default: /// @todo Throw exception. @@ -391,7 +391,7 @@ int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p, switch(prop) { case DMU_LINE: - foreach(Line::Side *side, elem->castTo()->sides()) + foreach(Line::Side *side, elem->as()->sides()) { int result = callback(&side->line(), context); if(result) return result; @@ -399,7 +399,7 @@ int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p, return false; // Continue iteration case DMU_PLANE: - foreach(Plane *plane, elem->castTo()->planes()) + foreach(Plane *plane, elem->as()->planes()) { int result = callback(plane, context); if(result) return result; @@ -407,7 +407,7 @@ int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p, return false; // Continue iteration case DMU_BSPLEAF: - foreach(BspLeaf *bspLeaf, elem->castTo()->bspLeafs()) + foreach(BspLeaf *bspLeaf, elem->as()->bspLeafs()) { int result = callback(bspLeaf, context); if(result) return result; @@ -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()->allSegments()) + foreach(Segment *seg, elem->as()->allSegments()) { int result = callback(seg, context); if(result) return result; @@ -583,12 +583,12 @@ static void setProperty(MapElement *elem, DmuArgs &args) { if(args.modifiers & DMU_FLOOR_OF_SECTOR) { - elem = elem->castTo()->sectorPtr(); + elem = elem->as()->sectorPtr(); args.type = DMU_SECTOR; } else if(args.modifiers & DMU_CEILING_OF_SECTOR) { - elem = elem->castTo()->sectorPtr(); + elem = elem->as()->sectorPtr(); args.type = DMU_SECTOR; } } @@ -597,12 +597,12 @@ static void setProperty(MapElement *elem, DmuArgs &args) { if(args.modifiers & DMU_FLOOR_OF_SECTOR) { - elem = &elem->castTo()->floor(); + elem = &elem->as()->floor(); args.type = DMU_PLANE; } else if(args.modifiers & DMU_CEILING_OF_SECTOR) { - elem = &elem->castTo()->ceiling(); + elem = &elem->as()->ceiling(); args.type = DMU_PLANE; } } @@ -611,12 +611,12 @@ static void setProperty(MapElement *elem, DmuArgs &args) { if(args.modifiers & DMU_FRONT_OF_LINE) { - elem = &elem->castTo()->front(); + elem = &elem->as()->front(); args.type = DMU_SIDE; } else if(args.modifiers & DMU_BACK_OF_LINE) { - elem = &elem->castTo()->back(); + elem = &elem->as()->back(); args.type = DMU_SIDE; } } @@ -625,17 +625,17 @@ static void setProperty(MapElement *elem, DmuArgs &args) { if(args.modifiers & DMU_TOP_OF_SIDE) { - elem = &elem->castTo()->top(); + elem = &elem->as()->top(); args.type = DMU_SURFACE; } else if(args.modifiers & DMU_MIDDLE_OF_SIDE) { - elem = &elem->castTo()->middle(); + elem = &elem->as()->middle(); args.type = DMU_SURFACE; } else if(args.modifiers & DMU_BOTTOM_OF_SIDE) { - elem = &elem->castTo()->bottom(); + elem = &elem->as()->bottom(); args.type = DMU_SURFACE; } } @@ -667,7 +667,7 @@ static void setProperty(MapElement *elem, DmuArgs &args) case DMU_ALPHA: case DMU_BLENDMODE: case DMU_FLAGS: - elem = &elem->castTo()->surface(); + elem = &elem->as()->surface(); args.type = DMU_SURFACE; break; @@ -689,12 +689,12 @@ static void getProperty(MapElement const *elem, DmuArgs &args) { if(args.modifiers & DMU_FLOOR_OF_SECTOR) { - elem = elem->castTo()->sectorPtr(); + elem = elem->as()->sectorPtr(); args.type = elem->type(); } else if(args.modifiers & DMU_CEILING_OF_SECTOR) { - elem = elem->castTo()->sectorPtr(); + elem = elem->as()->sectorPtr(); args.type = elem->type(); } else @@ -703,7 +703,7 @@ static void getProperty(MapElement const *elem, DmuArgs &args) { case DMU_LIGHT_LEVEL: case DMT_MOBJS: - elem = elem->castTo()->sectorPtr(); + elem = elem->as()->sectorPtr(); args.type = elem->type(); break; @@ -716,12 +716,12 @@ static void getProperty(MapElement const *elem, DmuArgs &args) { if(args.modifiers & DMU_FLOOR_OF_SECTOR) { - elem = &elem->castTo()->floor(); + elem = &elem->as()->floor(); args.type = elem->type(); } else if(args.modifiers & DMU_CEILING_OF_SECTOR) { - elem = &elem->castTo()->ceiling(); + elem = &elem->as()->ceiling(); args.type = elem->type(); } } @@ -730,12 +730,12 @@ static void getProperty(MapElement const *elem, DmuArgs &args) { if(args.modifiers & DMU_FRONT_OF_LINE) { - elem = &elem->castTo()->front(); + elem = &elem->as()->front(); args.type = elem->type(); } else if(args.modifiers & DMU_BACK_OF_LINE) { - elem = &elem->castTo()->back(); + elem = &elem->as()->back(); args.type = elem->type(); } } @@ -744,17 +744,17 @@ static void getProperty(MapElement const *elem, DmuArgs &args) { if(args.modifiers & DMU_TOP_OF_SIDE) { - elem = &elem->castTo()->top(); + elem = &elem->as()->top(); args.type = elem->type(); } else if(args.modifiers & DMU_MIDDLE_OF_SIDE) { - elem = &elem->castTo()->middle(); + elem = &elem->as()->middle(); args.type = elem->type(); } else if(args.modifiers & DMU_BOTTOM_OF_SIDE) { - elem = &elem->castTo()->bottom(); + elem = &elem->as()->bottom(); args.type = elem->type(); } } @@ -786,7 +786,7 @@ static void getProperty(MapElement const *elem, DmuArgs &args) case DMU_ALPHA: case DMU_BLENDMODE: case DMU_FLAGS: - elem = &elem->castTo()->surface(); + elem = &elem->as()->surface(); args.type = elem->type(); break; diff --git a/doomsday/client/src/world/bsp/partitioner.cpp b/doomsday/client/src/world/bsp/partitioner.cpp index a2a6e1f0ea..fc1460f8af 100644 --- a/doomsday/client/src/world/bsp/partitioner.cpp +++ b/doomsday/client/src/world/bsp/partitioner.cpp @@ -1550,7 +1550,7 @@ DENG2_PIMPL(Partitioner) switch(elm->type()) { case DMU_VERTEX: { - Vertex *vtx = elm->castTo(); + Vertex *vtx = elm->as(); /// @todo optimize: Poor performance O(n). for(uint i = 0; i < vertexes.size(); ++i) { diff --git a/doomsday/client/src/world/bspleaf.cpp b/doomsday/client/src/world/bspleaf.cpp index 82a86e9aa5..c999dd9861 100644 --- a/doomsday/client/src/world/bspleaf.cpp +++ b/doomsday/client/src/world/bspleaf.cpp @@ -148,7 +148,7 @@ DENG2_PIMPL(BspLeaf) { if(MapElement *elem = hedge->mapElement()) { - clockwiseSegments.append(elem->castTo()); + clockwiseSegments.append(elem->as()); } } while((hedge = &hedge->next()) != face.hedge()); @@ -207,7 +207,7 @@ DENG2_PIMPL(BspLeaf) { if(MapElement *elem = hedge->mapElement()) { - allSegments.append(elem->castTo()); + allSegments.append(elem->as()); } } } diff --git a/doomsday/client/src/world/linesighttest.cpp b/doomsday/client/src/world/linesighttest.cpp index 2b9418968f..6589460264 100644 --- a/doomsday/client/src/world/linesighttest.cpp +++ b/doomsday/client/src/world/linesighttest.cpp @@ -278,7 +278,7 @@ DENG2_PIMPL(LineSightTest) while(bspElement->type() != DMU_BSPLEAF) { - BspNode const *bspNode = bspElement->castTo(); + BspNode const *bspNode = bspElement->as(); // Does the ray intersect the partition? /// @todo Optionally use the fixed precision version -ds @@ -300,7 +300,7 @@ DENG2_PIMPL(LineSightTest) } // We've arrived at a leaf. - return crossBspLeaf(*bspElement->castTo()); + return crossBspLeaf(*bspElement->as()); } }; diff --git a/doomsday/client/src/world/map.cpp b/doomsday/client/src/world/map.cpp index 23fda696c7..5d73c07a85 100644 --- a/doomsday/client/src/world/map.cpp +++ b/doomsday/client/src/world/map.cpp @@ -306,7 +306,7 @@ DENG2_PIMPL(Map) { // Take ownership of the BspLeaf. DENG2_ASSERT(tree.userData() != 0); - BspLeaf *leaf = tree.userData()->castTo(); + BspLeaf *leaf = tree.userData()->as(); builder.take(leaf); // Add this BspLeaf to the LUT. @@ -329,7 +329,7 @@ DENG2_PIMPL(Map) // Take ownership of this BspNode. DENG2_ASSERT(tree.userData() != 0); - BspNode *node = tree.userData()->castTo(); + BspNode *node = tree.userData()->as(); builder.take(node); // Add this BspNode to the LUT. @@ -1674,7 +1674,7 @@ BspLeaf *Map::bspLeafAtPoint(Vector2d const &point) const MapElement *bspElement = d->bspRoot; while(bspElement->type() != DMU_BSPLEAF) { - BspNode const *bspNode = bspElement->castTo(); + BspNode const *bspNode = bspElement->as(); int side = bspNode->partition().pointOnSide(point) < 0; @@ -1683,7 +1683,7 @@ BspLeaf *Map::bspLeafAtPoint(Vector2d const &point) const } // We've arrived at a leaf. - return bspElement->castTo(); + return bspElement->as(); } BspLeaf *Map::bspLeafAtPoint_FixedPrecision(Vector2d const &point) const @@ -1693,7 +1693,7 @@ BspLeaf *Map::bspLeafAtPoint_FixedPrecision(Vector2d const &point) const MapElement *bspElement = d->bspRoot; while(bspElement->type() != DMU_BSPLEAF) { - BspNode const *bspNode = bspElement->castTo(); + BspNode const *bspNode = bspElement->as(); Partition const &partition = bspNode->partition(); fixed_t lineOriginX[2] = { DBL2FIX(partition.origin.x), DBL2FIX(partition.origin.y) }; @@ -1706,7 +1706,7 @@ BspLeaf *Map::bspLeafAtPoint_FixedPrecision(Vector2d const &point) const } // We've arrived at a leaf. - return bspElement->castTo(); + return bspElement->as(); } void Map::updateSurfacesOnMaterialChange(Material &material) diff --git a/doomsday/client/src/world/surface.cpp b/doomsday/client/src/world/surface.cpp index 8b07148f5e..2552060f73 100644 --- a/doomsday/client/src/world/surface.cpp +++ b/doomsday/client/src/world/surface.cpp @@ -99,14 +99,14 @@ DENG2_PIMPL(Surface) /// @todo Refactor away -ds inline bool isSideMiddle() { - return owner.type() == DMU_SIDE && &self == &owner.castTo()->middle(); + return owner.type() == DMU_SIDE && &self == &owner.as()->middle(); } /// @todo Refactor away -ds inline bool isSectorExtraPlane() { if(owner.type() != DMU_PLANE) return false; - Plane const &plane = *owner.castTo(); + Plane const &plane = *owner.as(); return !(plane.isSectorFloor() || plane.isSectorCeiling()); } @@ -290,7 +290,7 @@ bool Surface::isAttachedToMap() const { if(d->owner.type() == DMU_PLANE) { - Sector const §or = d->owner.castTo()->sector(); + Sector const §or = d->owner.as()->sector(); if(!sector.bspLeafCount()) return false; } @@ -309,7 +309,7 @@ bool Surface::setMaterial(Material *newMaterial, bool isMissingFix) d->materialIsMissingFix = true; // Sides of selfreferencing map lines should never receive fix materials. - DENG_ASSERT(!(d->owner.type() == DMU_SIDE && d->owner.castTo()->line().isSelfReferencing())); + DENG_ASSERT(!(d->owner.type() == DMU_SIDE && d->owner.as()->line().isSelfReferencing())); } } else if(newMaterial && d->materialIsMissingFix) @@ -346,7 +346,7 @@ bool Surface::setMaterial(Material *newMaterial, bool isMissingFix) { de::Uri uri = newMaterial->manifest().composeUri(); ded_ptcgen_t const *def = Def_GetGenerator(reinterpret_cast(&uri)); - P_SpawnPlaneParticleGen(def, d->owner.castTo()); + P_SpawnPlaneParticleGen(def, d->owner.as()); } } diff --git a/doomsday/server/src/server/sv_pool.cpp b/doomsday/server/src/server/sv_pool.cpp index ed9321de7b..1af5813a4e 100644 --- a/doomsday/server/src/server/sv_pool.cpp +++ b/doomsday/server/src/server/sv_pool.cpp @@ -2355,7 +2355,7 @@ void Sv_NewSoundDelta(int soundId, mobj_t* emitter, Sector* sourceSector, type = DT_SIDE_SOUND; // Clients need to know which emitter to use. - Line::Side *side = sourceSurface->owner().castTo(); + Line::Side *side = sourceSurface->owner().as(); if(&side->middle() == sourceSurface) {