Skip to content

Commit

Permalink
Refactor: Removed global plane list pointers
Browse files Browse the repository at this point in the history
Added accessor methods to GameMap for retrieving the lists.
  • Loading branch information
danij-deng committed Mar 9, 2012
1 parent bef21da commit f414552
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 71 deletions.
16 changes: 12 additions & 4 deletions doomsday/engine/portable/include/gamemap.h
Expand Up @@ -104,10 +104,10 @@ typedef struct gamemap_s {

gameobjdata_t gameObjData;

watchedplanelist_t watchedPlaneList;
surfacelist_t movingSurfaceList;
surfacelist_t decoratedSurfaceList;
surfacelist_t glowingSurfaceList;
planelist_t trackedPlanes;
surfacelist_t scrollingSurfaces;
surfacelist_t decoratedSurfaces;
surfacelist_t glowingSurfaces;

struct blockmap_s* mobjBlockmap;
struct blockmap_s* polyobjBlockmap;
Expand Down Expand Up @@ -553,6 +553,14 @@ surfacelist_t* GameMap_GlowingSurfaces(GameMap* map);
*/
surfacelist_t* GameMap_ScrollingSurfaces(GameMap* map);

/**
* Retrieve a pointer to the tracked plane list for this map.
*
* @param map GameMap instance.
* @return List of tracked planes.
*/
planelist_t* GameMap_TrackedPlanes(GameMap* map);

/**
* Initialize all Polyobjs in the map. To be called after map load.
*
Expand Down
8 changes: 3 additions & 5 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -88,10 +88,10 @@ typedef struct edgespan_s {
float shift;
} edgespan_t;

typedef struct watchedplanelist_s {
typedef struct planelist_s {
uint num, maxNum;
struct plane_s** list;
} watchedplanelist_t;
struct plane_s** array;
} planelist_t;

typedef struct surfacelistnode_s {
void* data;
Expand Down Expand Up @@ -182,8 +182,6 @@ extern linedef_t* lineDefs;
extern sidedef_t* sideDefs;
extern polyobj_t** polyObjs; ///< List of all polyobjs on the current map.

extern watchedplanelist_t* watchedPlaneList;

#include "gamemap.h"

// The current map.
Expand Down
11 changes: 5 additions & 6 deletions doomsday/engine/portable/include/r_world.h
Expand Up @@ -120,12 +120,11 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec);
surfacedecor_t* R_CreateSurfaceDecoration(surface_t* suf);
void R_ClearSurfaceDecorations(surface_t* suf);

void R_UpdateWatchedPlanes(watchedplanelist_t* wpl);
void R_InterpolateWatchedPlanes(watchedplanelist_t* wpl,
boolean resetNextViewer);
void R_AddWatchedPlane(watchedplanelist_t* wpl, plane_t* pln);
boolean R_RemoveWatchedPlane(watchedplanelist_t* wpl,
const plane_t* pln);
void R_UpdateTrackedPlanes(void);
void R_InterpolateTrackedPlanes(boolean resetNextViewer);

void R_AddTrackedPlane(planelist_t* plist, plane_t* pln);
boolean R_RemoveTrackedPlane(planelist_t* plist, const plane_t* pln);

void R_UpdateSurfaceScroll(void);
void R_InterpolateSurfaceScroll(boolean resetNextViewer);
Expand Down
12 changes: 9 additions & 3 deletions doomsday/engine/portable/src/gamemap.c
Expand Up @@ -380,19 +380,25 @@ Generators* GameMap_Generators(GameMap* map)
surfacelist_t* GameMap_DecoratedSurfaces(GameMap* map)
{
assert(map);
return &map->decoratedSurfaceList;
return &map->decoratedSurfaces;
}

surfacelist_t* GameMap_GlowingSurfaces(GameMap* map)
{
assert(map);
return &map->glowingSurfaceList;
return &map->glowingSurfaces;
}

surfacelist_t* GameMap_ScrollingSurfaces(GameMap* map)
{
assert(map);
return &map->movingSurfaceList;
return &map->scrollingSurfaces;
}

planelist_t* GameMap_TrackedPlanes(GameMap* map)
{
assert(map);
return &map->trackedPlanes;
}

void GameMap_InitPolyobjs(GameMap* map)
Expand Down
6 changes: 0 additions & 6 deletions doomsday/engine/portable/src/p_data.c
Expand Up @@ -59,8 +59,6 @@ linedef_t* lineDefs = NULL;
sidedef_t* sideDefs = NULL;
polyobj_t** polyObjs = NULL; // List of all poly-objects in the map.

watchedplanelist_t* watchedPlaneList = NULL;

GameMap* theMap = NULL;

// Bad texture list
Expand Down Expand Up @@ -129,8 +127,6 @@ void P_SetCurrentMap(GameMap* map)
sideDefs = 0;
polyObjs = 0;

watchedPlaneList = 0;

theMap = map;
return;
}
Expand All @@ -146,8 +142,6 @@ void P_SetCurrentMap(GameMap* map)
sideDefs = map->sideDefs;
polyObjs = map->polyObjs;

watchedPlaneList = &map->watchedPlaneList;

theMap = map;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/p_plane.c
Expand Up @@ -35,7 +35,7 @@ int Plane_SetProperty(plane_t* pln, const setargs_t* args)
DMU_SetValue(DMT_PLANE_HEIGHT, &pln->height, args, 0);
if(!ddMapSetup)
{
R_AddWatchedPlane(watchedPlaneList, pln);
R_AddTrackedPlane(GameMap_TrackedPlanes(theMap), pln);
R_MarkDependantSurfacesForDecorationUpdate(pln);
}
break;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/r_main.c
Expand Up @@ -780,7 +780,7 @@ void R_NewSharpWorld(void)
R_CheckViewerLimits(vd->lastSharp, &sharpView);
}

R_UpdateWatchedPlanes(watchedPlaneList);
R_UpdateTrackedPlanes();
R_UpdateSurfaceScroll();
}

Expand Down Expand Up @@ -820,7 +820,7 @@ void R_BeginWorldFrame(void)
{
R_ClearSectorFlags();

R_InterpolateWatchedPlanes(watchedPlaneList, resetNextViewer);
R_InterpolateTrackedPlanes(resetNextViewer);
R_InterpolateSurfaceScroll(resetNextViewer);

if(!freezeRLs)
Expand Down
92 changes: 48 additions & 44 deletions doomsday/engine/portable/src/r_world.c
Expand Up @@ -333,56 +333,55 @@ void R_InterpolateSurfaceScroll(boolean resetNextViewer)
}
}

void R_AddWatchedPlane(watchedplanelist_t *wpl, plane_t *pln)
void R_AddTrackedPlane(planelist_t* plist, plane_t *pln)
{
uint i;
uint i;

if(!wpl || !pln)
return;
if(!plist || !pln) return;

// Check whether we are already tracking this plane.
for(i = 0; i < wpl->num; ++i)
if(wpl->list[i] == pln)
for(i = 0; i < plist->num; ++i)
{
if(plist->array[i] == pln)
return; // Yes we are.
}

wpl->num++;
plist->num++;

// Only allocate memory when it's needed.
if(wpl->num > wpl->maxNum)
if(plist->num > plist->maxNum)
{
wpl->maxNum *= 2;
plist->maxNum *= 2;

// The first time, allocate 8 watched plane nodes.
if(!wpl->maxNum)
wpl->maxNum = 8;
if(!plist->maxNum)
plist->maxNum = 8;

wpl->list =
Z_Realloc(wpl->list, sizeof(plane_t*) * (wpl->maxNum + 1),
PU_MAP);
plist->array = Z_Realloc(plist->array, sizeof(plane_t*) * (plist->maxNum + 1), PU_MAP);
}

// Add the plane to the list.
wpl->list[wpl->num-1] = pln;
wpl->list[wpl->num] = NULL; // Terminate.
plist->array[plist->num-1] = pln;
plist->array[plist->num] = NULL; // Terminate.
}

boolean R_RemoveWatchedPlane(watchedplanelist_t *wpl, const plane_t *pln)
boolean R_RemoveTrackedPlane(planelist_t *plist, const plane_t *pln)
{
uint i;

if(!wpl || !pln)
if(!plist || !pln)
return false;

for(i = 0; i < wpl->num; ++i)
for(i = 0; i < plist->num; ++i)
{
if(wpl->list[i] == pln)
if(plist->array[i] == pln)
{
if(i == wpl->num - 1)
wpl->list[i] = NULL;
if(i == plist->num - 1)
plist->array[i] = NULL;
else
memmove(&wpl->list[i], &wpl->list[i+1],
sizeof(plane_t*) * (wpl->num - 1 - i));
wpl->num--;
memmove(&plist->array[i], &plist->array[i+1],
sizeof(plane_t*) * (plist->num - 1 - i));
plist->num--;
return true;
}
}
Expand All @@ -393,16 +392,18 @@ boolean R_RemoveWatchedPlane(watchedplanelist_t *wpl, const plane_t *pln)
/**
* $smoothplane: Roll the height tracker buffers.
*/
void R_UpdateWatchedPlanes(watchedplanelist_t *wpl)
void R_UpdateTrackedPlanes(void)
{
uint i;
planelist_t* plist;
uint i;

if(!wpl)
return;
if(!theMap) return;
plist = GameMap_TrackedPlanes(theMap);
if(!plist) return;

for(i = 0; i < wpl->num; ++i)
for(i = 0; i < plist->num; ++i)
{
plane_t *pln = wpl->list[i];
plane_t* pln = plist->array[i];

pln->oldHeight[0] = pln->oldHeight[1];
pln->oldHeight[1] = pln->height;
Expand All @@ -420,21 +421,22 @@ void R_UpdateWatchedPlanes(watchedplanelist_t *wpl)
/**
* $smoothplane: interpolate the visual offset.
*/
void R_InterpolateWatchedPlanes(watchedplanelist_t *wpl,
boolean resetNextViewer)
void R_InterpolateTrackedPlanes(boolean resetNextViewer)
{
uint i;
plane_t *pln;
planelist_t* plist;
plane_t* pln;
uint i;

if(!wpl)
return;
if(!theMap) return;
plist = GameMap_TrackedPlanes(theMap);
if(!plist) return;

if(resetNextViewer)
{
// $smoothplane: Reset the plane height trackers.
for(i = 0; i < wpl->num; ++i)
for(i = 0; i < plist->num; ++i)
{
pln = wpl->list[i];
pln = plist->array[i];

pln->visHeightDelta = 0;
pln->visHeight = pln->oldHeight[0] = pln->oldHeight[1] = pln->height;
Expand All @@ -444,7 +446,7 @@ void R_InterpolateWatchedPlanes(watchedplanelist_t *wpl,
R_MarkDependantSurfacesForDecorationUpdate(pln);
}

if(R_RemoveWatchedPlane(wpl, pln))
if(R_RemoveTrackedPlane(plist, pln))
i = (i > 0? i-1 : 0);
}
}
Expand All @@ -453,9 +455,9 @@ void R_InterpolateWatchedPlanes(watchedplanelist_t *wpl,
else //if(!clientPaused)
{
// $smoothplane: Set the visible offsets.
for(i = 0; i < wpl->num; ++i)
for(i = 0; i < plist->num; ++i)
{
pln = wpl->list[i];
pln = plist->array[i];

pln->visHeightDelta = pln->oldHeight[0] * (1 - frameTimePos) +
pln->height * frameTimePos -
Expand All @@ -472,7 +474,7 @@ void R_InterpolateWatchedPlanes(watchedplanelist_t *wpl,
// Has this plane reached its destination?
if(pln->visHeight == pln->height) /// @todo Can this fail? (float equality)
{
if(R_RemoveWatchedPlane(wpl, pln))
if(R_RemoveTrackedPlane(plist, pln))
i = (i > 0? i-1 : 0);
}
}
Expand Down Expand Up @@ -664,6 +666,7 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec)
plane_t* plane, **newList = NULL;
subsector_t** ssecIter;
surfacelist_t* slist;
planelist_t* plist;
uint i;

if(!sec) return; // Do wha?
Expand Down Expand Up @@ -692,7 +695,8 @@ void R_DestroyPlaneOfSector(uint id, sector_t* sec)
}

// If this plane is currently being watched, remove it.
R_RemoveWatchedPlane(watchedPlaneList, plane);
plist = GameMap_TrackedPlanes(theMap);
if(plist) R_RemoveTrackedPlane(plist, plane);

// If this plane's surface is in the moving list, remove it.
slist = GameMap_ScrollingSurfaces(theMap);
Expand Down

0 comments on commit f414552

Please sign in to comment.