From b8da0ab3a09f9b278a4e0c70dd70597b919cc433 Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 6 Feb 2013 17:57:46 +0000 Subject: [PATCH] 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. --- doomsday/client/include/map/gamemap.h | 45 +++----- doomsday/client/include/map/r_world.h | 21 +--- doomsday/client/src/map/gamemap.cpp | 33 +++--- doomsday/client/src/map/r_world.cpp | 129 ++++++++-------------- doomsday/client/src/map/surface.cpp | 15 +-- doomsday/client/src/render/lumobj.cpp | 20 ++-- doomsday/client/src/render/rend_decor.cpp | 8 +- 7 files changed, 99 insertions(+), 172 deletions(-) diff --git a/doomsday/client/include/map/gamemap.h b/doomsday/client/include/map/gamemap.h index e0764ef8a6..b24cf5ca78 100644 --- a/doomsday/client/include/map/gamemap.h +++ b/doomsday/client/include/map/gamemap.h @@ -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; @@ -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(); }; /** @@ -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. * diff --git a/doomsday/client/include/map/r_world.h b/doomsday/client/include/map/r_world.h index d5eeb32895..efe070be8a 100644 --- a/doomsday/client/include/map/r_world.h +++ b/doomsday/client/include/map/r_world.h @@ -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 diff --git a/doomsday/client/src/map/gamemap.cpp b/doomsday/client/src/map/gamemap.cpp index f58d4cb7c6..108877b279 100644 --- a/doomsday/client/src/map/gamemap.cpp +++ b/doomsday/client/src/map/gamemap.cpp @@ -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); @@ -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); diff --git a/doomsday/client/src/map/r_world.cpp b/doomsday/client/src/map/r_world.cpp index ee2d778b7d..94f746ba0c 100644 --- a/doomsday/client/src/map/r_world.cpp +++ b/doomsday/client/src/map/r_world.cpp @@ -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); + } } /** @@ -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; @@ -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 { @@ -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); + } + } } /** @@ -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++) @@ -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) @@ -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)); } } } diff --git a/doomsday/client/src/map/surface.cpp b/doomsday/client/src/map/surface.cpp index 9fcd95d682..ab398123de 100644 --- a/doomsday/client/src/map/surface.cpp +++ b/doomsday/client/src/map/surface.cpp @@ -97,20 +97,21 @@ boolean Surface_SetMaterial(Surface *suf, Material *material) GameMap *map = theMap; /// @todo Do not assume surface is from the CURRENT map. // If this plane's surface is in the decorated list, remove it. - R_SurfaceListRemove(GameMap_DecoratedSurfaces(map), suf); + map->decoratedSurfaces().remove(suf); + // If this plane's surface is in the glowing list, remove it. - R_SurfaceListRemove(GameMap_GlowingSurfaces(map), suf); + map->glowingSurfaces().remove(suf); if(material) { if(material->hasGlow()) { - R_SurfaceListAdd(GameMap_GlowingSurfaces(map), suf); + map->glowingSurfaces().insert(suf); } if(material->isDecorated()) { - R_SurfaceListAdd(GameMap_DecoratedSurfaces(map), suf); + map->decoratedSurfaces().insert(suf); } if(suf->owner->type() == DMU_PLANE) @@ -143,7 +144,7 @@ boolean Surface_SetMaterialOriginX(Surface *suf, float x) if(!ddMapSetup) { /// @todo Do not assume surface is from the CURRENT map. - R_SurfaceListAdd(GameMap_ScrollingSurfaces(theMap), suf); + theMap->scrollingSurfaces().insert(suf); } } } @@ -162,7 +163,7 @@ boolean Surface_SetMaterialOriginY(Surface *suf, float y) if(!ddMapSetup) { /// @todo Do not assume surface is from the CURRENT map. - R_SurfaceListAdd(GameMap_ScrollingSurfaces(theMap), suf); + theMap->scrollingSurfaces().insert(suf); } } } @@ -182,7 +183,7 @@ boolean Surface_SetMaterialOrigin(Surface *suf, float x, float y) if(!ddMapSetup) { /// @todo Do not assume surface is from the CURRENT map. - R_SurfaceListAdd(GameMap_ScrollingSurfaces(theMap), suf); + theMap->scrollingSurfaces().insert(suf); } } } diff --git a/doomsday/client/src/render/lumobj.cpp b/doomsday/client/src/render/lumobj.cpp index 67fc202a65..ba49949672 100644 --- a/doomsday/client/src/render/lumobj.cpp +++ b/doomsday/client/src/render/lumobj.cpp @@ -946,22 +946,22 @@ END_PROF( PROF_LUMOBJ_FRAME_SORT ); * Generate one dynlight node for each plane glow. * The light is attached to the appropriate dynlight node list. */ -static boolean createGlowLightForSurface(Surface *suf, void * /*parameters*/) +static void createGlowLightForSurface(Surface &suf) { - switch(suf->owner->type()) + switch(suf.owner->type()) { case DMU_PLANE: { - Plane *pln = suf->owner->castTo(); + Plane *pln = suf.owner->castTo(); Sector *sec = pln->sector; // Only produce a light for sectors with open space. /// @todo Do not add surfaces from sectors with zero BSP leafs to the glowing list. if(!sec->bspLeafCount || sec->SP_floorvisheight >= sec->SP_ceilvisheight) - return true; // Continue iteration. + break; // Are we glowing at this moment in time? - MaterialSnapshot const &ms = suf->material->prepare(Rend_MapSurfaceMaterialSpec()); - if(!(ms.glowStrength() > .001f)) return true; // Continue iteration. + MaterialSnapshot const &ms = suf.material->prepare(Rend_MapSurfaceMaterialSpec()); + if(!(ms.glowStrength() > .001f)) break; averagecolor_analysis_t const *avgColorAmplified = (averagecolor_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_COLOR_AMPLIFIED); if(!avgColorAmplified) throw Error("createGlowLightForSurface", QString("Texture \"%1\" has no TA_COLOR_AMPLIFIED analysis)").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); @@ -994,12 +994,11 @@ static boolean createGlowLightForSurface(Surface *suf, void * /*parameters*/) break; } case DMU_SIDEDEF: - return true; // Not yet supported by this algorithm. + break; // Not yet supported by this algorithm. default: DENG2_ASSERT(false); // Invalid type. } - return true; } void LO_AddLuminousMobjs(void) @@ -1026,7 +1025,10 @@ BEGIN_PROF( PROF_LUMOBJ_INIT_ADD ); // Create dynlights for all glowing surfaces. if(useWallGlow) { - R_SurfaceListIterate(GameMap_GlowingSurfaces(theMap), createGlowLightForSurface, 0); + foreach(Surface *surface, theMap->glowingSurfaces()) + { + createGlowLightForSurface(*surface); + } } END_PROF( PROF_LUMOBJ_INIT_ADD ); diff --git a/doomsday/client/src/render/rend_decor.cpp b/doomsday/client/src/render/rend_decor.cpp index fdd6286ac1..e985d564ba 100644 --- a/doomsday/client/src/render/rend_decor.cpp +++ b/doomsday/client/src/render/rend_decor.cpp @@ -509,13 +509,9 @@ BEGIN_PROF( PROF_DECOR_BEGIN_FRAME ); recycleSources(); - SurfaceSet *decoratedSurfaces = GameMap_DecoratedSurfaces(theMap); - if(decoratedSurfaces) + foreach(Surface *surface, theMap->decoratedSurfaces()) { - DENG2_FOR_EACH(SurfaceSet, i, *decoratedSurfaces) - { - plotSourcesForSurface(**i); - } + plotSourcesForSurface(*surface); } END_PROF( PROF_DECOR_BEGIN_FRAME );