Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|GameMap: Replaced methods for retrieving GameMap's SurfaceSets
- GameMap_DecoratedSurfaces() => GameMap::decoratedSurfaces()
- GameMap_GlowingSurfaces()   => GameMap::glowingSurfaces()
- GameMap_ScrollingSurfaces() => GameMap::scrollingSurfaces()

Removed the now redundant R_SurfaceList* family of functions.
  • Loading branch information
danij-deng committed Feb 6, 2013
1 parent cc5d52a commit b8da0ab
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 172 deletions.
45 changes: 18 additions & 27 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -112,9 +112,9 @@ class GameMap
EntityDatabase* entityDatabase;

PlaneSet trackedPlanes;
SurfaceSet scrollingSurfaces;
SurfaceSet decoratedSurfaces;
SurfaceSet glowingSurfaces;
SurfaceSet scrollingSurfaces_;
SurfaceSet decoratedSurfaces_;
SurfaceSet glowingSurfaces_;

struct blockmap_s* mobjBlockmap;
struct blockmap_s* polyobjBlockmap;
Expand Down Expand Up @@ -148,6 +148,21 @@ class GameMap
uint sideDefCount() const { return sideDefs.size(); }

uint lineDefCount() const { return lineDefs.size(); }

/**
* Returns the set of scrolling surfaces for the map.
*/
SurfaceSet &scrollingSurfaces();

/**
* Returns the set of decorated surfaces for the map.
*/
SurfaceSet &decoratedSurfaces();

/**
* Returns the set of glowing surfaces for the map.
*/
SurfaceSet &glowingSurfaces();
};

/**
Expand Down Expand Up @@ -603,30 +618,6 @@ struct clplane_s* GameMap_NewClPlane(GameMap* map, uint sectornum, clplanetype_t
*/
struct generators_s* GameMap_Generators(GameMap* map);

/**
* Retrieve a pointer to the decorated surface list for this map.
*
* @param map GameMap instance.
* @return List of decorated surfaces.
*/
SurfaceSet* GameMap_DecoratedSurfaces(GameMap* map);

/**
* Retrieve a pointer to the glowing surface list for this map.
*
* @param map GameMap instance.
* @return List of glowing surfaces.
*/
SurfaceSet* GameMap_GlowingSurfaces(GameMap* map);

/**
* Retrieve a pointer to the scrolling surface list for this map.
*
* @param map GameMap instance.
* @return List of scrolling surfaces.
*/
SurfaceSet* GameMap_ScrollingSurfaces(GameMap* map);

/**
* Retrieve a pointer to the tracked plane list for this map.
*
Expand Down
21 changes: 1 addition & 20 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -167,26 +167,7 @@ boolean R_UpdateSidedef(SideDef *side, boolean forceUpdate);
boolean R_UpdatePlane(Plane *pln, boolean forceUpdate);
boolean R_UpdateSurface(Surface *suf, boolean forceUpdate);

/**
* Adds the surface to the given surface list.
*
* @param sl The surface list to add the surface to.
* @param suf The surface to add to the list.
*/
void R_SurfaceListAdd(SurfaceSet* sl, Surface *suf);
boolean R_SurfaceListRemove(SurfaceSet* sl, Surface *suf);
void R_SurfaceListClear(SurfaceSet* sl);

/**
* Iterate the list of surfaces making a callback for each.
*
* @param callback The callback to make. Iteration will continue until
* a callback returns a zero value.
* @param context Is passed to the callback function.
*/
boolean R_SurfaceListIterate(SurfaceSet* sl, boolean (*callback) (Surface *suf, void*), void* context);

void R_MarkDependantSurfacesForDecorationUpdate(Plane* pln);
void R_MarkDependantSurfacesForDecorationUpdate(Plane* pln);

/**
* To be called in response to a Material property changing which may
Expand Down
33 changes: 15 additions & 18 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -74,6 +74,21 @@ GameMap::~GameMap()
{
}

SurfaceSet &GameMap::scrollingSurfaces()
{
return scrollingSurfaces_;
}

SurfaceSet &GameMap::decoratedSurfaces()
{
return decoratedSurfaces_;
}

SurfaceSet &GameMap::glowingSurfaces()
{
return glowingSurfaces_;
}

const Uri* GameMap_Uri(GameMap* map)
{
DENG2_ASSERT(map);
Expand Down Expand Up @@ -456,24 +471,6 @@ Generators* GameMap_Generators(GameMap* map)
return map->generators;
}

SurfaceSet* GameMap_DecoratedSurfaces(GameMap* map)
{
DENG2_ASSERT(map);
return &map->decoratedSurfaces;
}

SurfaceSet* GameMap_GlowingSurfaces(GameMap* map)
{
DENG2_ASSERT(map);
return &map->glowingSurfaces;
}

SurfaceSet* GameMap_ScrollingSurfaces(GameMap* map)
{
DENG2_ASSERT(map);
return &map->scrollingSurfaces;
}

PlaneSet* GameMap_TrackedPlanes(GameMap* map)
{
DENG2_ASSERT(map);
Expand Down
129 changes: 44 additions & 85 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -53,71 +53,37 @@ byte rendSkyLightAuto = true;
boolean firstFrameAfterLoad;
boolean ddMapSetup;

void R_SurfaceListAdd(SurfaceSet *sl, Surface *suf)
{
if(!sl || !suf) return;
sl->insert(suf);
}

boolean R_SurfaceListRemove(SurfaceSet *sl, Surface *suf)
{
if(!sl || !suf) return false;
return sl->remove(suf);
}

void R_SurfaceListClear(SurfaceSet *sl)
/**
* $smoothmatoffset: Roll the surface material offset tracker buffers.
*/
void R_UpdateSurfaceScroll()
{
if(!sl) return;
sl->clear();
}
if(!theMap) return;

boolean R_SurfaceListIterate(SurfaceSet *sl, boolean (*callback)(Surface *suf, void *), void *context)
{
if(sl)
foreach(Surface *surface, theMap->scrollingSurfaces())
{
DENG2_FOR_EACH(SurfaceSet, i, *sl)
{
if(!callback(*i, context))
return false;
}
}
return true;
}

boolean updateSurfaceScroll(Surface *suf, void * /*context*/)
{
// X Offset
suf->oldOffset[0][0] = suf->oldOffset[0][1];
suf->oldOffset[0][1] = suf->offset[0];
if(suf->oldOffset[0][0] != suf->oldOffset[0][1])
if(fabs(suf->oldOffset[0][0] - suf->oldOffset[0][1]) >=
// X Offset
surface->oldOffset[0][0] = surface->oldOffset[0][1];
surface->oldOffset[0][1] = surface->offset[0];
if(surface->oldOffset[0][0] != surface->oldOffset[0][1])
if(de::abs(surface->oldOffset[0][0] - surface->oldOffset[0][1]) >=
MAX_SMOOTH_MATERIAL_MOVE)
{
// Too fast: make an instantaneous jump.
suf->oldOffset[0][0] = suf->oldOffset[0][1];
surface->oldOffset[0][0] = surface->oldOffset[0][1];
}

// Y Offset
suf->oldOffset[1][0] = suf->oldOffset[1][1];
suf->oldOffset[1][1] = suf->offset[1];
if(suf->oldOffset[1][0] != suf->oldOffset[1][1])
if(fabs(suf->oldOffset[1][0] - suf->oldOffset[1][1]) >=
// Y Offset
surface->oldOffset[1][0] = surface->oldOffset[1][1];
surface->oldOffset[1][1] = surface->offset[1];
if(surface->oldOffset[1][0] != surface->oldOffset[1][1])
if(de::abs(surface->oldOffset[1][0] - surface->oldOffset[1][1]) >=
MAX_SMOOTH_MATERIAL_MOVE)
{
// Too fast: make an instantaneous jump.
suf->oldOffset[1][0] = suf->oldOffset[1][1];
surface->oldOffset[1][0] = surface->oldOffset[1][1];
}

return true;
}

/**
* $smoothmatoffset: Roll the surface material offset tracker buffers.
*/
void R_UpdateSurfaceScroll()
{
if(!theMap) return;
R_SurfaceListIterate(GameMap_ScrollingSurfaces(theMap), updateSurfaceScroll, 0);
}
}

/**
Expand All @@ -126,11 +92,9 @@ void R_UpdateSurfaceScroll()
void R_InterpolateSurfaceScroll(boolean resetNextViewer)
{
if(!theMap) return;
SurfaceSet *slist = GameMap_ScrollingSurfaces(theMap);
if(!slist) return;

SurfaceSet::iterator it = slist->begin();
while(it != slist->end())
SurfaceSet &surfaces = theMap->scrollingSurfaces();
SurfaceSet::iterator it = surfaces.begin();
while(it != surfaces.end())
{
Surface &suf = **it;

Expand Down Expand Up @@ -172,7 +136,7 @@ void R_InterpolateSurfaceScroll(boolean resetNextViewer)
// Has this material reached its destination?
if(suf.visOffset[0] == suf.offset[0] && suf.visOffset[1] == suf.offset[1])
{
it = slist->erase(it);
it = surfaces.erase(it);
}
else
{
Expand Down Expand Up @@ -319,21 +283,18 @@ void R_MarkDependantSurfacesForDecorationUpdate(Plane *pln)
}
}

static boolean markSurfaceForDecorationUpdate(Surface *surface, void *parameters)
{
Material *material = (Material *) parameters;
if(material == surface->material)
{
Surface_Update(surface);
}
return 1; // Continue iteration.
}

void R_UpdateMapSurfacesOnMaterialChange(Material *material)
{
if(!material || !theMap || ddMapSetup) return;
if(!material || ddMapSetup) return;
if(!theMap) return;

R_SurfaceListIterate(GameMap_DecoratedSurfaces(theMap), markSurfaceForDecorationUpdate, material);
foreach(Surface *surface, theMap->decoratedSurfaces())
{
if(material == surface->material)
{
Surface_Update(surface);
}
}
}

/**
Expand Down Expand Up @@ -454,13 +415,13 @@ void R_DestroyPlaneOfSector(uint id, Sector *sec)
R_RemoveTrackedPlane(GameMap_TrackedPlanes(theMap), plane);

// If this plane's surface is in the moving list, remove it.
R_SurfaceListRemove(GameMap_ScrollingSurfaces(theMap), &plane->surface);
theMap->scrollingSurfaces().remove(&plane->surface);

// If this plane's surface is in the deocrated list, remove it.
R_SurfaceListRemove(GameMap_DecoratedSurfaces(theMap), &plane->surface);
theMap->decoratedSurfaces().remove(&plane->surface);

// If this plane's surface is in the glowing list, remove it.
R_SurfaceListRemove(GameMap_GlowingSurfaces(theMap), &plane->surface);
theMap->glowingSurfaces().remove(&plane->surface);

// Destroy the biassurfaces for this plane.
for(BspLeaf **bspLeafIter = sec->bspLeafs; *bspLeafIter; bspLeafIter++)
Expand Down Expand Up @@ -1072,35 +1033,33 @@ void R_MapInitSurfaces(boolean forceUpdate)
}
}

static void addToSurfaceLists(Surface *suf, Material *material)
static void addToSurfaceSets(Surface *suf, Material *material)
{
if(!suf || !material) return;

if(material->hasGlow())
{
R_SurfaceListAdd(GameMap_GlowingSurfaces(theMap), suf);
theMap->glowingSurfaces().insert(suf);
}

if(material->isDecorated())
{
R_SurfaceListAdd(GameMap_DecoratedSurfaces(theMap), suf);
theMap->decoratedSurfaces().insert(suf);
}
}

void R_MapInitSurfaceLists()
{
if(novideo) return;

R_SurfaceListClear(GameMap_DecoratedSurfaces(theMap));
R_SurfaceListClear(GameMap_GlowingSurfaces(theMap));
theMap->decoratedSurfaces().clear();
theMap->glowingSurfaces().clear();

for(uint i = 0; i < NUM_SIDEDEFS; ++i)
{
SideDef *side = SIDE_PTR(i);

addToSurfaceLists(&side->SW_middlesurface, side->SW_middlematerial);
addToSurfaceLists(&side->SW_topsurface, side->SW_topmaterial);
addToSurfaceLists(&side->SW_bottomsurface, side->SW_bottommaterial);
addToSurfaceSets(&side->SW_middlesurface, side->SW_middlematerial);
addToSurfaceSets(&side->SW_topsurface, side->SW_topmaterial);
addToSurfaceSets(&side->SW_bottomsurface, side->SW_bottommaterial);
}

for(uint i = 0; i < NUM_SECTORS; ++i)
Expand All @@ -1110,7 +1069,7 @@ void R_MapInitSurfaceLists()

for(uint j = 0; j < sec->planeCount; ++j)
{
addToSurfaceLists(&sec->SP_planesurface(j), sec->SP_planematerial(j));
addToSurfaceSets(&sec->SP_planesurface(j), sec->SP_planematerial(j));
}
}
}
Expand Down

0 comments on commit b8da0ab

Please sign in to comment.