From bef21dab3234ba422e836cf8c0c16651e08fce5a Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 9 Mar 2012 22:02:29 +0000 Subject: [PATCH] Refactor: Removed global surface list pointers Added accessor methods to GameMap for retrieving the lists. --- doomsday/engine/portable/include/gamemap.h | 24 +++++ doomsday/engine/portable/include/p_mapdata.h | 3 - doomsday/engine/portable/include/r_world.h | 4 +- doomsday/engine/portable/src/gamemap.c | 18 ++++ doomsday/engine/portable/src/p_data.c | 9 -- doomsday/engine/portable/src/p_surface.c | 35 +++++--- doomsday/engine/portable/src/r_lumobjs.c | 9 +- doomsday/engine/portable/src/r_main.c | 4 +- doomsday/engine/portable/src/r_world.c | 95 +++++++++++--------- doomsday/engine/portable/src/rend_decor.c | 15 ++-- 10 files changed, 139 insertions(+), 77 deletions(-) diff --git a/doomsday/engine/portable/include/gamemap.h b/doomsday/engine/portable/include/gamemap.h index 85edb452b1..46c40889bb 100644 --- a/doomsday/engine/portable/include/gamemap.h +++ b/doomsday/engine/portable/include/gamemap.h @@ -529,6 +529,30 @@ 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. + */ +surfacelist_t* GameMap_DecoratedSurfaces(GameMap* map); + +/** + * Retrieve a pointer to the glowing surface list for this map. + * + * @param map GameMap instance. + * @return List of glowing surfaces. + */ +surfacelist_t* GameMap_GlowingSurfaces(GameMap* map); + +/** + * Retrieve a pointer to the scrolling surface list for this map. + * + * @param map GameMap instance. + * @return List of scrolling surfaces. + */ +surfacelist_t* GameMap_ScrollingSurfaces(GameMap* map); + /** * Initialize all Polyobjs in the map. To be called after map load. * diff --git a/doomsday/engine/portable/include/p_mapdata.h b/doomsday/engine/portable/include/p_mapdata.h index e7bfad32f0..caaa6df06c 100644 --- a/doomsday/engine/portable/include/p_mapdata.h +++ b/doomsday/engine/portable/include/p_mapdata.h @@ -183,9 +183,6 @@ extern sidedef_t* sideDefs; extern polyobj_t** polyObjs; ///< List of all polyobjs on the current map. extern watchedplanelist_t* watchedPlaneList; -extern surfacelist_t* movingSurfaceList; -extern surfacelist_t* decoratedSurfaceList; -extern surfacelist_t* glowingSurfaceList; #include "gamemap.h" diff --git a/doomsday/engine/portable/include/r_world.h b/doomsday/engine/portable/include/r_world.h index 40d67097ff..4687c8e806 100644 --- a/doomsday/engine/portable/include/r_world.h +++ b/doomsday/engine/portable/include/r_world.h @@ -127,8 +127,8 @@ void R_AddWatchedPlane(watchedplanelist_t* wpl, plane_t* pln); boolean R_RemoveWatchedPlane(watchedplanelist_t* wpl, const plane_t* pln); -void R_UpdateMovingSurfaces(void); -void R_InterpolateMovingSurfaces(boolean resetNextViewer); +void R_UpdateSurfaceScroll(void); +void R_InterpolateSurfaceScroll(boolean resetNextViewer); /** * Adds the surface to the given surface list. diff --git a/doomsday/engine/portable/src/gamemap.c b/doomsday/engine/portable/src/gamemap.c index 4d3f3e6ad1..8ef8e2de2c 100644 --- a/doomsday/engine/portable/src/gamemap.c +++ b/doomsday/engine/portable/src/gamemap.c @@ -377,6 +377,24 @@ Generators* GameMap_Generators(GameMap* map) return map->generators; } +surfacelist_t* GameMap_DecoratedSurfaces(GameMap* map) +{ + assert(map); + return &map->decoratedSurfaceList; +} + +surfacelist_t* GameMap_GlowingSurfaces(GameMap* map) +{ + assert(map); + return &map->glowingSurfaceList; +} + +surfacelist_t* GameMap_ScrollingSurfaces(GameMap* map) +{ + assert(map); + return &map->movingSurfaceList; +} + void GameMap_InitPolyobjs(GameMap* map) { uint i; diff --git a/doomsday/engine/portable/src/p_data.c b/doomsday/engine/portable/src/p_data.c index ffdd415d71..903700271e 100644 --- a/doomsday/engine/portable/src/p_data.c +++ b/doomsday/engine/portable/src/p_data.c @@ -60,9 +60,6 @@ sidedef_t* sideDefs = NULL; polyobj_t** polyObjs = NULL; // List of all poly-objects in the map. watchedplanelist_t* watchedPlaneList = NULL; -surfacelist_t* movingSurfaceList = NULL; -surfacelist_t* decoratedSurfaceList = NULL; -surfacelist_t* glowingSurfaceList = NULL; GameMap* theMap = NULL; @@ -133,9 +130,6 @@ void P_SetCurrentMap(GameMap* map) polyObjs = 0; watchedPlaneList = 0; - movingSurfaceList = 0; - decoratedSurfaceList = 0; - glowingSurfaceList = 0; theMap = map; return; @@ -153,9 +147,6 @@ void P_SetCurrentMap(GameMap* map) polyObjs = map->polyObjs; watchedPlaneList = &map->watchedPlaneList; - movingSurfaceList = &map->movingSurfaceList; - decoratedSurfaceList = &map->decoratedSurfaceList; - glowingSurfaceList = &map->glowingSurfaceList; theMap = map; } diff --git a/doomsday/engine/portable/src/p_surface.c b/doomsday/engine/portable/src/p_surface.c index 3c57b56d11..034f15a265 100644 --- a/doomsday/engine/portable/src/p_surface.c +++ b/doomsday/engine/portable/src/p_surface.c @@ -60,17 +60,19 @@ boolean Surface_SetMaterial(surface_t* suf, material_t* mat) if(!ddMapSetup) { + GameMap* map = theMap; /// @fixme Do not assume surface is from the CURRENT map. + // If this plane's surface is in the decorated list, remove it. - R_SurfaceListRemove(decoratedSurfaceList, suf); + R_SurfaceListRemove(GameMap_DecoratedSurfaces(map), suf); // If this plane's surface is in the glowing list, remove it. - R_SurfaceListRemove(glowingSurfaceList, suf); + R_SurfaceListRemove(GameMap_GlowingSurfaces(map), suf); if(mat) { if(Material_HasGlow(mat)) - R_SurfaceListAdd(glowingSurfaceList, suf); + R_SurfaceListAdd(GameMap_GlowingSurfaces(map), suf); if(Materials_HasDecorations(mat)) - R_SurfaceListAdd(decoratedSurfaceList, suf); + R_SurfaceListAdd(GameMap_DecoratedSurfaces(map), suf); if(DMU_GetType(suf->owner) == DMU_PLANE) { @@ -99,7 +101,10 @@ boolean Surface_SetMaterialOriginX(surface_t* suf, float x) { suf->inFlags |= SUIF_UPDATE_DECORATIONS; if(!ddMapSetup) - R_SurfaceListAdd(movingSurfaceList, suf); + { + /// @fixme Do not assume surface is from the CURRENT map. + R_SurfaceListAdd(GameMap_ScrollingSurfaces(theMap), suf); + } } } return true; @@ -115,7 +120,10 @@ boolean Surface_SetMaterialOriginY(surface_t* suf, float y) { suf->inFlags |= SUIF_UPDATE_DECORATIONS; if(!ddMapSetup) - R_SurfaceListAdd(movingSurfaceList, suf); + { + /// @fixme Do not assume surface is from the CURRENT map. + R_SurfaceListAdd(GameMap_ScrollingSurfaces(theMap), suf); + } } } return true; @@ -132,7 +140,10 @@ boolean Surface_SetMaterialOrigin(surface_t* suf, float x, float y) { suf->inFlags |= SUIF_UPDATE_DECORATIONS; if(!ddMapSetup) - R_SurfaceListAdd(movingSurfaceList, suf); + { + /// @fixme Do not assume surface is from the CURRENT map. + R_SurfaceListAdd(GameMap_ScrollingSurfaces(theMap), suf); + } } } return true; @@ -144,7 +155,7 @@ boolean Surface_SetColorRed(surface_t* suf, float r) r = MINMAX_OF(0, r, 1); if(suf->rgba[CR] != r) { - // \todo when surface colours are intergrated with the + // @todo when surface colours are intergrated with the // bias lighting model we will need to recalculate the // vertex colours when they are changed. suf->rgba[CR] = r; @@ -158,7 +169,7 @@ boolean Surface_SetColorGreen(surface_t* suf, float g) g = MINMAX_OF(0, g, 1); if(suf->rgba[CG] != g) { - // \todo when surface colours are intergrated with the + // @todo when surface colours are intergrated with the // bias lighting model we will need to recalculate the // vertex colours when they are changed. suf->rgba[CG] = g; @@ -172,7 +183,7 @@ boolean Surface_SetColorBlue(surface_t* suf, float b) b = MINMAX_OF(0, b, 1); if(suf->rgba[CB] != b) { - // \todo when surface colours are intergrated with the + // @todo when surface colours are intergrated with the // bias lighting model we will need to recalculate the // vertex colours when they are changed. suf->rgba[CB] = b; @@ -186,7 +197,7 @@ boolean Surface_SetAlpha(surface_t* suf, float a) a = MINMAX_OF(0, a, 1); if(suf->rgba[CA] != a) { - // \todo when surface colours are intergrated with the + // @todo when surface colours are intergrated with the // bias lighting model we will need to recalculate the // vertex colours when they are changed. suf->rgba[CA] = a; @@ -207,7 +218,7 @@ boolean Surface_SetColorAndAlpha(surface_t* suf, float r, float g, float b, floa suf->rgba[CA] == a) return true; - // \todo when surface colours are intergrated with the + // @todo when surface colours are intergrated with the // bias lighting model we will need to recalculate the // vertex colours when they are changed. suf->rgba[CR] = r; diff --git a/doomsday/engine/portable/src/r_lumobjs.c b/doomsday/engine/portable/src/r_lumobjs.c index df8be44891..dffecf22fb 100644 --- a/doomsday/engine/portable/src/r_lumobjs.c +++ b/doomsday/engine/portable/src/r_lumobjs.c @@ -1021,8 +1021,7 @@ static boolean createGlowLightForSurface(surface_t* suf, void* paramaters) void LO_AddLuminousMobjs(void) { - if(!useDynlights && !useWallGlow) - return; + if(!useDynlights && !useWallGlow) return; BEGIN_PROF( PROF_LUMOBJ_INIT_ADD ); @@ -1045,7 +1044,11 @@ BEGIN_PROF( PROF_LUMOBJ_INIT_ADD ); // to create dynlights and link them. if(useWallGlow) { - R_SurfaceListIterate(glowingSurfaceList, createGlowLightForSurface, 0); + surfacelist_t* slist = GameMap_GlowingSurfaces(theMap); + if(slist) + { + R_SurfaceListIterate(slist, createGlowLightForSurface, 0); + } } END_PROF( PROF_LUMOBJ_INIT_ADD ); diff --git a/doomsday/engine/portable/src/r_main.c b/doomsday/engine/portable/src/r_main.c index 542d147792..050f0a9080 100644 --- a/doomsday/engine/portable/src/r_main.c +++ b/doomsday/engine/portable/src/r_main.c @@ -781,7 +781,7 @@ void R_NewSharpWorld(void) } R_UpdateWatchedPlanes(watchedPlaneList); - R_UpdateMovingSurfaces(); + R_UpdateSurfaceScroll(); } void R_CreateMobjLinks(void) @@ -821,7 +821,7 @@ void R_BeginWorldFrame(void) R_ClearSectorFlags(); R_InterpolateWatchedPlanes(watchedPlaneList, resetNextViewer); - R_InterpolateMovingSurfaces(resetNextViewer); + R_InterpolateSurfaceScroll(resetNextViewer); if(!freezeRLs) { diff --git a/doomsday/engine/portable/src/r_world.c b/doomsday/engine/portable/src/r_world.c index 8cfc777023..eeaf81a728 100644 --- a/doomsday/engine/portable/src/r_world.c +++ b/doomsday/engine/portable/src/r_world.c @@ -223,7 +223,7 @@ boolean R_SurfaceListIterate(surfacelist_t* sl, boolean (*callback) (surface_t* return result; } -boolean updateMovingSurface(surface_t* suf, void* context) +boolean updateSurfaceScroll(surface_t* suf, void* context) { // X Offset suf->oldOffset[0][0] = suf->oldOffset[0][1]; @@ -253,15 +253,17 @@ boolean updateMovingSurface(surface_t* suf, void* context) /** * $smoothmatoffset: Roll the surface material offset tracker buffers. */ -void R_UpdateMovingSurfaces(void) +void R_UpdateSurfaceScroll(void) { - if(!movingSurfaceList) - return; + surfacelist_t* slist; + if(!theMap) return; + slist = GameMap_ScrollingSurfaces(theMap); + if(!slist) return; - R_SurfaceListIterate(movingSurfaceList, updateMovingSurface, NULL); + R_SurfaceListIterate(slist, updateSurfaceScroll, NULL); } -boolean resetMovingSurface(surface_t* suf, void* context) +boolean resetSurfaceScroll(surface_t* suf, void* context) { // X Offset. suf->visOffsetDelta[0] = 0; @@ -272,12 +274,13 @@ boolean resetMovingSurface(surface_t* suf, void* context) suf->oldOffset[1][0] = suf->oldOffset[1][1] = suf->offset[1]; Surface_Update(suf); - R_SurfaceListRemove(movingSurfaceList, suf); + /// @fixme Do not assume surface is from the CURRENT map. + R_SurfaceListRemove(GameMap_ScrollingSurfaces(theMap), suf); return true; } -boolean interpMovingSurface(surface_t* suf, void* context) +boolean interpSurfaceScroll(surface_t* suf, void* context) { // X Offset. suf->visOffsetDelta[0] = @@ -296,9 +299,11 @@ boolean interpMovingSurface(surface_t* suf, void* context) Surface_Update(suf); // Has this material reached its destination? - if(suf->visOffset[0] == suf->offset[0] && - suf->visOffset[1] == suf->offset[1]) - R_SurfaceListRemove(movingSurfaceList, suf); + if(suf->visOffset[0] == suf->offset[0] && suf->visOffset[1] == suf->offset[1]) + { + /// @fixme Do not assume surface is from the CURRENT map. + R_SurfaceListRemove(GameMap_ScrollingSurfaces(theMap), suf); + } return true; } @@ -306,22 +311,25 @@ boolean interpMovingSurface(surface_t* suf, void* context) /** * $smoothmatoffset: interpolate the visual offset. */ -void R_InterpolateMovingSurfaces(boolean resetNextViewer) +void R_InterpolateSurfaceScroll(boolean resetNextViewer) { - if(!movingSurfaceList) - return; + surfacelist_t* slist; + + if(!theMap) return; + slist = GameMap_ScrollingSurfaces(theMap); + if(!slist) return; if(resetNextViewer) { // Reset the material offset trackers. - R_SurfaceListIterate(movingSurfaceList, resetMovingSurface, NULL); + R_SurfaceListIterate(slist, resetSurfaceScroll, NULL); } // While the game is paused there is no need to calculate any // visual material offsets. else //if(!clientPaused) { // Set the visible material offsets. - R_SurfaceListIterate(movingSurfaceList, interpMovingSurface, NULL); + R_SurfaceListIterate(slist, interpSurfaceScroll, NULL); } } @@ -526,11 +534,14 @@ static boolean markSurfaceForDecorationUpdate(surface_t* surface, void* paramate void R_UpdateMapSurfacesOnMaterialChange(material_t* material) { - GameMap* map = theMap; - if(NULL == material || NULL == map || ddMapSetup) return; + surfacelist_t* slist; + + if(!material || !theMap || ddMapSetup) return; + slist = GameMap_DecoratedSurfaces(theMap); + if(!slist) return; // Light decorations will need a refresh. - R_SurfaceListIterate(decoratedSurfaceList, markSurfaceForDecorationUpdate, material); + R_SurfaceListIterate(slist, markSurfaceForDecorationUpdate, material); } /** @@ -652,10 +663,10 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec) { plane_t* plane, **newList = NULL; subsector_t** ssecIter; + surfacelist_t* slist; uint i; - if(!sec) - return; // Do wha? + if(!sec) return; // Do wha? if(id >= sec->planeCount) Con_Error("P_DestroyPlaneOfSector: Plane id #%i is not valid for " @@ -666,7 +677,7 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec) // Create a new plane list? if(sec->planeCount > 1) { - uint n; + uint n; newList = Z_Malloc(sizeof(plane_t**) * sec->planeCount, PU_MAP, 0); @@ -674,8 +685,7 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec) n = 0; for(i = 0; i < sec->planeCount; ++i) { - if(i == id) - continue; + if(i == id) continue; newList[n++] = sec->planes[i]; } newList[n] = NULL; // Terminate. @@ -683,12 +693,18 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec) // If this plane is currently being watched, remove it. R_RemoveWatchedPlane(watchedPlaneList, plane); + // If this plane's surface is in the moving list, remove it. - R_SurfaceListRemove(movingSurfaceList, &plane->surface); + slist = GameMap_ScrollingSurfaces(theMap); + if(slist) R_SurfaceListRemove(slist, &plane->surface); + // If this plane's surface is in the deocrated list, remove it. - R_SurfaceListRemove(decoratedSurfaceList, &plane->surface); + slist = GameMap_DecoratedSurfaces(theMap); + if(slist) R_SurfaceListRemove(slist, &plane->surface); + // If this plane's surface is in the glowing list, remove it. - R_SurfaceListRemove(glowingSurfaceList, &plane->surface); + slist = GameMap_GlowingSurfaces(theMap); + if(slist) R_SurfaceListRemove(slist, &plane->surface); // Destroy the biassurfaces for this plane. ssecIter = sec->subsectors; @@ -710,20 +726,18 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec) sec->planes = newList; } -surfacedecor_t* R_CreateSurfaceDecoration(surface_t *suf) +surfacedecor_t* R_CreateSurfaceDecoration(surface_t* suf) { surfacedecor_t* d, *s, *decorations; uint i; - if(!suf) - return NULL; + if(!suf) return NULL; - decorations = - Z_Malloc(sizeof(*decorations) * (++suf->numDecorations), - PU_MAP, 0); + decorations = Z_Malloc(sizeof(*decorations) * (++suf->numDecorations), PU_MAP, 0); if(suf->numDecorations > 1) - { // Copy the existing decorations. + { + // Copy the existing decorations. for(i = 0; i < suf->numDecorations - 1; ++i) { d = &decorations[i]; @@ -743,10 +757,9 @@ surfacedecor_t* R_CreateSurfaceDecoration(surface_t *suf) return d; } -void R_ClearSurfaceDecorations(surface_t *suf) +void R_ClearSurfaceDecorations(surface_t* suf) { - if(!suf) - return; + if(!suf) return; if(suf->decorations) Z_Free(suf->decorations); @@ -1317,16 +1330,16 @@ static void addToSurfaceLists(surface_t* suf, material_t* mat) { if(!suf || !mat) return; - if(Material_HasGlow(mat)) R_SurfaceListAdd(glowingSurfaceList, suf); - if(Materials_HasDecorations(mat)) R_SurfaceListAdd(decoratedSurfaceList, suf); + if(Material_HasGlow(mat)) R_SurfaceListAdd(GameMap_GlowingSurfaces(theMap), suf); + if(Materials_HasDecorations(mat)) R_SurfaceListAdd(GameMap_DecoratedSurfaces(theMap), suf); } void R_MapInitSurfaceLists(void) { if(novideo) return; - R_SurfaceListClear(decoratedSurfaceList); - R_SurfaceListClear(glowingSurfaceList); + R_SurfaceListClear(GameMap_DecoratedSurfaces(theMap)); + R_SurfaceListClear(GameMap_GlowingSurfaces(theMap)); { uint i; for(i = 0; i < NUM_SIDEDEFS; ++i) diff --git a/doomsday/engine/portable/src/rend_decor.c b/doomsday/engine/portable/src/rend_decor.c index 4c196a47ae..de8ff4b570 100644 --- a/doomsday/engine/portable/src/rend_decor.c +++ b/doomsday/engine/portable/src/rend_decor.c @@ -671,6 +671,7 @@ static void updateSideSectionDecorations(sidedef_t* side, sidedefsection_t secti */ void Rend_InitDecorationsForFrame(void) { + surfacelist_t* slist; #ifdef DD_PROFILE static int i; @@ -684,13 +685,17 @@ void Rend_InitDecorationsForFrame(void) #endif // This only needs to be done if decorations have been enabled. - if(0 != useLightDecorations) - { + if(!useLightDecorations) return; + BEGIN_PROF( PROF_DECOR_PROJECT ); - clearDecorations(); - R_SurfaceListIterate(decoratedSurfaceList, R_ProjectSurfaceDecorations, &decorMaxDist); + clearDecorations(); -END_PROF( PROF_DECOR_PROJECT ); + slist = GameMap_DecoratedSurfaces(theMap); + if(slist) + { + R_SurfaceListIterate(slist, R_ProjectSurfaceDecorations, &decorMaxDist); } + +END_PROF( PROF_DECOR_PROJECT ); }