Skip to content

Commit

Permalink
Refactor: Surface owner is a map element
Browse files Browse the repository at this point in the history
Replacing the use of void* with the new, safer de::MapElement.
  • Loading branch information
skyjake committed Jan 15, 2013
1 parent 9526852 commit fdac7bf
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/include/map/surface.h
Expand Up @@ -43,7 +43,7 @@ typedef struct surfacedecor_s {
typedef struct surface_s {
//runtime_mapdata_header_t header;
ddmobj_base_t base;
void* owner; // Either @c DMU_SIDEDEF, or @c DMU_PLANE
de::MapElement *owner; // Either @c DMU_SIDEDEF, or @c DMU_PLANE
int flags; // SUF_ flags
int oldFlags;
material_t* material;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/src/edit_map.cpp
Expand Up @@ -98,9 +98,9 @@ static SideDef* createSide(void)
e_map->sideDefs.push_back(side);

side->buildData.index = e_map->sideDefs.size(); // 1-based index, 0 = NIL.
side->SW_bottomsurface.owner = (void*) side;
side->SW_middlesurface.owner = (void*) side;
side->SW_topsurface.owner = (void*) side;
side->SW_bottomsurface.owner = side;
side->SW_middlesurface.owner = side;
side->SW_topsurface.owner = side;
return side;
}

Expand Down Expand Up @@ -1955,7 +1955,7 @@ uint MPE_PlaneCreate(uint sector, coord_t height, const ddstring_t* materialUri,
Sector* s = e_map->sectors[sector - 1];

Plane* pln = new Plane;
pln->surface.owner = (void*) pln;
pln->surface.owner = pln;
pln->height = height;

assignSurfaceMaterial(&pln->surface, materialUri);
Expand Down
4 changes: 3 additions & 1 deletion doomsday/engine/src/map/bsp/partitioner.cpp
Expand Up @@ -371,7 +371,7 @@ struct Partitioner::Instance
scanRegion.maxX = MAX_OF(line->L_v1origin[VX], line->L_v2origin[VX]) + DIST_EPSILON;
}
validCount++;
GameMap_LineDefsBoxIterator(map, &scanRegion, testForWindowEffectWorker, (void*)&p);
GameMap_LineDefsBoxIterator(map, &scanRegion, testForWindowEffectWorker, &p);

if(p.backOpen && p.frontOpen && line->L_frontsector == p.backOpen)
{
Expand Down Expand Up @@ -1931,11 +1931,13 @@ struct Partitioner::Instance

if(tree.isLeaf())
{
DENG2_ASSERT(dmuOb->type() == DMU_BSPLEAF);
// There is now one less BspLeaf.
numLeafs -= 1;
}
else
{
DENG2_ASSERT(dmuOb->type() == DMU_BSPNODE);
// There is now one less BspNode.
numNodes -= 1;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/hedge.cpp
Expand Up @@ -422,7 +422,7 @@ int HEdge_GetProperty(const HEdge* hedge, setargs_t* args)
DMU_GetValue(DMT_HEDGE_LINEDEF, &hedge->lineDef, args, 0);
break;
case DMU_FRONT_SECTOR: {
Sector* sec = hedge->sector? hedge->sector : NULL;
Sector* sec = hedge->sector;
DMU_GetValue(DMT_HEDGE_SECTOR, &sec, args, 0);
break; }
case DMU_BACK_SECTOR: {
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/src/map/p_dmu.cpp
Expand Up @@ -1128,18 +1128,18 @@ static int setProperty(void *obj, void *context)
{
if(R_UpdateSurface(updateSurface, false))
{
switch(DMU_GetType(updateSurface->owner))
switch(updateSurface->owner->type())
{
case DMU_SIDEDEF:
updateSidedef = (SideDef *)updateSurface->owner;
updateSidedef = updateSurface->owner->castTo<SideDef>();
break;

case DMU_PLANE:
updatePlane = (Plane *)updateSurface->owner;
updatePlane = updateSurface->owner->castTo<Plane>();
break;

default:
LegacyCore_FatalError("SetPropert: Internal error, surface owner unknown.");
DENG2_ASSERT(false); // Unsupported type.
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/r_world.cpp
Expand Up @@ -485,7 +485,7 @@ Plane *R_NewPlaneForSector(Sector *sec)
suf->normal[VZ] = 1;
V3f_BuildTangents(suf->tangent, suf->bitangent, suf->normal);

suf->owner = (void*) plane;
suf->owner = plane;
/// @todo The initial material should be the "unknown" material.
Surface_SetMaterial(suf, NULL);
Surface_SetMaterialOrigin(suf, 0, 0);
Expand Down
17 changes: 9 additions & 8 deletions doomsday/engine/src/map/surface.cpp
Expand Up @@ -46,9 +46,9 @@ boolean Surface_AttachedToMap(Surface *suf)
{
DENG_ASSERT(suf);
if(!suf->owner) return false;
if(DMU_GetType(suf->owner) == DMU_PLANE)
if(suf->owner->type() == DMU_PLANE)
{
Sector *sec = ((Plane *)suf->owner)->sector;
Sector *sec = suf->owner->castTo<Plane>()->sector;
if(0 == sec->bspLeafCount)
return false;
}
Expand Down Expand Up @@ -87,10 +87,10 @@ boolean Surface_SetMaterial(Surface *suf, material_t *mat)
R_SurfaceListAdd(GameMap_DecoratedSurfaces(map), suf);
}

if(DMU_GetType(suf->owner) == DMU_PLANE)
if(suf->owner->type() == DMU_PLANE)
{
ded_ptcgen_t const *def = App_Materials()->ptcGenDef(*mat);
P_SpawnPlaneParticleGen(def, (Plane *)suf->owner);
P_SpawnPlaneParticleGen(def, suf->owner->castTo<Plane>());
}
}
}
Expand Down Expand Up @@ -265,10 +265,10 @@ void Surface_UpdateBaseOrigin(Surface *suf)
LOG_AS("Surface_UpdateBaseOrigin");

if(!suf->owner) return;
switch(DMU_GetType(suf->owner))
switch(suf->owner->type())
{
case DMU_PLANE: {
Plane *pln = (Plane *)suf->owner;
Plane *pln = suf->owner->castTo<Plane>();
Sector *sec = pln->sector;
DENG_ASSERT(sec);

Expand All @@ -278,7 +278,7 @@ void Surface_UpdateBaseOrigin(Surface *suf)
break; }

case DMU_SIDEDEF: {
SideDef *side = (SideDef *)suf->owner;
SideDef *side = suf->owner->castTo<SideDef>();
LineDef *line = side->line;
Sector *sec;
DENG_ASSERT(line);
Expand Down Expand Up @@ -327,7 +327,8 @@ void Surface_UpdateBaseOrigin(Surface *suf)

default:
LOG_DEBUG("Invalid DMU type %s for owner object %p.")
<< DMU_Str(DMU_GetType(suf->owner)) << de::dintptr(suf->owner);
<< DMU_Str(suf->owner->type()) << de::dintptr(suf->owner);
DENG2_ASSERT(false);
}
}

Expand Down
7 changes: 3 additions & 4 deletions doomsday/engine/src/render/lumobj.cpp
Expand Up @@ -951,10 +951,10 @@ END_PROF( PROF_LUMOBJ_FRAME_SORT );
*/
static boolean createGlowLightForSurface(Surface *suf, void * /*parameters*/)
{
switch(DMU_GetType(suf->owner))
switch(suf->owner->type())
{
case DMU_PLANE: {
Plane *pln = reinterpret_cast<Plane *>(suf->owner);
Plane *pln = suf->owner->castTo<Plane>();
Sector *sec = pln->sector;

// Only produce a light for sectors with open space.
Expand Down Expand Up @@ -997,8 +997,7 @@ static boolean createGlowLightForSurface(Surface *suf, void * /*parameters*/)
return true; // Not yet supported by this algorithm.

default:
Con_Error("createGlowLightForSurface: Internal error, unknown type %s.",
DMU_Str(DMU_GetType(suf->owner)));
DENG2_ASSERT(false); // Invalid type.
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/src/render/rend_decor.cpp
Expand Up @@ -347,20 +347,20 @@ boolean R_ProjectSurfaceDecorations(Surface *suf, void *context)
{
R_ClearSurfaceDecorations(suf);

switch(DMU_GetType(suf->owner))
switch(suf->owner->type())
{
case DMU_SIDEDEF: {
SideDef *sideDef = (SideDef *)suf->owner;
SideDef *sideDef = suf->owner->castTo<SideDef>();
LineDef *line = sideDef->line;
updateSideSectionDecorations(line, sideDef == line->L_frontsidedef? FRONT : BACK,
&sideDef->SW_middlesurface == suf? SS_MIDDLE :
&sideDef->SW_bottomsurface == suf? SS_BOTTOM : SS_TOP);
break; }
case DMU_PLANE:
updatePlaneDecorations((Plane *)suf->owner);
updatePlaneDecorations(suf->owner->castTo<Plane>());
break;
default:
Con_Error("R_ProjectSurfaceDecorations: Internal Error, unknown type %s.", DMU_Str(DMU_GetType(suf->owner)));
DENG2_ASSERT(false); // Invalid type.
break;
}
suf->inFlags &= ~SUIF_UPDATE_DECORATIONS;
Expand Down
7 changes: 3 additions & 4 deletions doomsday/engine/src/server/sv_pool.cpp
Expand Up @@ -2318,10 +2318,10 @@ void Sv_NewSoundDelta(int soundId, mobj_t* emitter, Sector* sourceSector,
else if(sourceSurface)
{
type = DT_SECTOR_SOUND;
switch(DMU_GetType(sourceSurface->owner))
switch(sourceSurface->owner->type())
{
case DMU_PLANE: {
Plane* pln = (Plane*)sourceSurface->owner;
Plane* pln = sourceSurface->owner->castTo<Plane>();

// Clients need to know which emitter to use.
if(emitter)
Expand Down Expand Up @@ -2369,8 +2369,7 @@ void Sv_NewSoundDelta(int soundId, mobj_t* emitter, Sector* sourceSector,
break; } */

default:
DEBUG_Message(("Sv_NewSoundDelta: Invalid DMU type %s for sourceSurface object %p. Sector origin will be used.",
DMU_Str(DMU_GetType(sourceSurface->owner)), sourceSurface->owner));
DENG2_ASSERT(false); // Invalid map element type.
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/scriptsys/scriptlex.cpp
Expand Up @@ -474,7 +474,7 @@ String ScriptLex::unescapeStringToken(Token const &token)
}
else if(*ptr == 'x' && (end - ptr > 2))
{
QString num(reinterpret_cast<QChar const *>(ptr + 1), 2);
QString num(const_cast<QChar const *>(ptr + 1), 2);
duint code = num.toInt(0, 16);
c = QChar(code);
ptr += 2;
Expand Down

0 comments on commit fdac7bf

Please sign in to comment.