Skip to content

Commit

Permalink
Refactor|GameMap: Moved more GameMap_* functions to methods of GameMap
Browse files Browse the repository at this point in the history
Everything to do with sky fix heights...
  • Loading branch information
danij-deng committed Apr 3, 2013
1 parent e62d9bb commit 36245cd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 62 deletions.
42 changes: 22 additions & 20 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -144,7 +144,7 @@ class GameMap

int _ambientLightLevel; // Ambient lightlevel for the current map.

skyfix_t skyFix[2]; // [floor, ceiling]
skyfix_t _skyFix[2]; // [floor, ceiling]

/// Current LOS trace state.
/// @todo Refactor to support concurrent traces.
Expand Down Expand Up @@ -261,6 +261,20 @@ class GameMap
bool lineOfSight(const_pvec3d_t from, const_pvec3d_t to, coord_t bottomSlope,
coord_t topSlope, int flags);

coord_t skyFix(bool ceiling) const;

inline coord_t skyFixFloor() const { return skyFix(false /*the floor*/); }
inline coord_t skyFixCeiling() const { return skyFix(true /*the ceiling*/); }

void setSkyFix(bool ceiling, coord_t height);

inline void setSkyFixFloor(coord_t height) {
setSkyFix(false /*the floor*/, height);
}
inline void setSkyFixCeiling(coord_t height) {
setSkyFix(true /*the ceiling*/, height);
}

/**
* Link the specified @a bspLeaf in internal data structures for
* bookkeeping purposes.
Expand Down Expand Up @@ -376,6 +390,13 @@ class GameMap
*/
void updateBounds();

/**
* Fixing the sky means that for adjacent sky sectors the lower sky
* ceiling is lifted to match the upper sky. The raising only affects
* rendering, it has no bearing on gameplay.
*/
void initSkyFix();

void addSurfaceToLists(Surface &suf);

#ifdef __CLIENT__
Expand Down Expand Up @@ -416,25 +437,6 @@ TraceOpening const *GameMap_TraceOpening(GameMap *map);
*/
void GameMap_SetTraceOpening(GameMap *map, LineDef *line);

coord_t GameMap_SkyFix(GameMap *map, boolean ceiling);

#define GameMap_SkyFixCeiling(m) GameMap_SkyFix((m), true)
#define GameMap_SkyFixFloor(m) GameMap_SkyFix((m), false)

GameMap *GameMap_SetSkyFix(GameMap *map, boolean ceiling, coord_t height);

#define GameMap_SetSkyFixCeiling(m, h) GameMap_SetSkyFix((m), true, (h))
#define GameMap_SetSkyFixFloor(m, h) GameMap_SetSkyFix((m), false, (h))

/**
* Fixing the sky means that for adjacent sky sectors the lower sky
* ceiling is lifted to match the upper sky. The raising only affects
* rendering, it has no bearing on gameplay.
*/
void GameMap_InitSkyFix(GameMap *map);

void GameMap_UpdateSkyFixForSector(GameMap *map, Sector *sec);

/**
* Lookup a Sector in the map by it's sound emitter.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/dam_main.cpp
Expand Up @@ -359,7 +359,7 @@ boolean DAM_AttemptMapLoad(uri_s const *_uri)
Rend_RadioInitForMap();
#endif

GameMap_InitSkyFix(map);
map->initSkyFix();
}
}

Expand Down
13 changes: 5 additions & 8 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -59,7 +59,7 @@ GameMap::GameMap()
_globalGravity = 0;
_effectiveGravity = 0;
_ambientLightLevel = 0;
std::memset(skyFix, 0, sizeof(skyFix));
std::memset(_skyFix, 0, sizeof(_skyFix));
std::memset(&traceOpening, 0, sizeof(traceOpening));
std::memset(&traceLOS, 0, sizeof(traceLOS));
}
Expand Down Expand Up @@ -175,19 +175,16 @@ int GameMap::ambientLightLevel() const
return _ambientLightLevel;
}

coord_t GameMap_SkyFix(GameMap *map, boolean ceiling)
coord_t GameMap::skyFix(bool ceiling) const
{
DENG2_ASSERT(map);
Plane::Type plane = ceiling? Plane::Ceiling : Plane::Floor;
return map->skyFix[plane].height;
return _skyFix[plane].height;
}

GameMap *GameMap_SetSkyFix(GameMap *map, boolean ceiling, coord_t height)
void GameMap::setSkyFix(bool ceiling, coord_t height)
{
DENG2_ASSERT(map);
Plane::Type plane = ceiling? Plane::Ceiling : Plane::Floor;
map->skyFix[plane].height = height;
return map;
_skyFix[plane].height = height;
}

int GameMap_VertexIndex(GameMap *map, Vertex const *vtx)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/p_players.cpp
Expand Up @@ -124,7 +124,7 @@ boolean P_IsInVoid(player_t *player)

if(sec.ceilingSurface().hasSkyMaskedMaterial())
{
coord_t const skyCeil = GameMap_SkyFixCeiling(theMap);
coord_t const skyCeil = theMap->skyFixCeiling();
if(skyCeil < DDMAXFLOAT && ddpl->mo->origin[VZ] > skyCeil - 4)
return true;
}
Expand All @@ -135,7 +135,7 @@ boolean P_IsInVoid(player_t *player)

if(sec.floorSurface().hasSkyMaskedMaterial())
{
coord_t const skyFloor = GameMap_SkyFixFloor(theMap);
coord_t const skyFloor = theMap->skyFixFloor();
if(skyFloor > DDMINFLOAT && ddpl->mo->origin[VZ] < skyFloor + 4)
return true;
}
Expand Down
51 changes: 25 additions & 26 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -217,11 +217,11 @@ void GameMap::updateSurfacesOnMaterialChange(Material &material)
#endif
}

void GameMap_UpdateSkyFixForSector(GameMap *map, Sector *sec)
static void updateMapSkyFixForSector(GameMap *map, Sector *sec)
{
DENG_ASSERT(map);
DENG_ASSERT(map && sec);

if(!sec || !sec->lineCount()) return;
if(!sec->lineCount()) return;

bool skyFloor = sec->floorSurface().hasSkyMaskedMaterial();
bool skyCeil = sec->ceilingSurface().hasSkyMaskedMaterial();
Expand All @@ -231,32 +231,32 @@ void GameMap_UpdateSkyFixForSector(GameMap *map, Sector *sec)
if(skyCeil)
{
// Adjust for the plane height.
if(sec->ceiling().visHeight() > map->skyFix[Plane::Ceiling].height)
if(sec->ceiling().visHeight() > map->skyFixCeiling())
{
// Must raise the skyfix ceiling.
map->skyFix[Plane::Ceiling].height = sec->ceiling().visHeight();
map->setSkyFixCeiling(sec->ceiling().visHeight());
}

// Check that all the mobjs in the sector fit in.
for(mobj_t *mo = sec->firstMobj(); mo; mo = mo->sNext)
{
float extent = mo->origin[VZ] + mo->height;
coord_t extent = mo->origin[VZ] + mo->height;

if(extent > map->skyFix[Plane::Ceiling].height)
if(extent > map->skyFixCeiling())
{
// Must raise the skyfix ceiling.
map->skyFix[Plane::Ceiling].height = extent;
map->setSkyFixCeiling(extent);
}
}
}

if(skyFloor)
{
// Adjust for the plane height.
if(sec->floor().visHeight() < map->skyFix[Plane::Floor].height)
if(sec->floor().visHeight() < map->skyFixFloor())
{
// Must lower the skyfix floor.
map->skyFix[Plane::Floor].height = sec->floor().visHeight();
map->setSkyFixFloor(sec->floor().visHeight());
}
}

Expand All @@ -276,45 +276,43 @@ void GameMap_UpdateSkyFixForSector(GameMap *map, Sector *sec)

if(skyCeil)
{
float const top = sec->ceiling().visHeight() + sideDef.middle().visMaterialOrigin()[VY];
coord_t const top = sec->ceiling().visHeight() + sideDef.middle().visMaterialOrigin()[VY];

if(top > map->skyFix[Plane::Ceiling].height)
if(top > map->skyFixCeiling())
{
// Must raise the skyfix ceiling.
map->skyFix[Plane::Ceiling].height = top;
map->setSkyFixCeiling(top);
}
}

if(skyFloor)
{
float const bottom = sec->floor().visHeight() +
coord_t const bottom = sec->floor().visHeight() +
sideDef.middle().visMaterialOrigin()[VY] - sideDef.middle().material().height();

if(bottom < map->skyFix[Plane::Floor].height)
if(bottom < map->skyFixFloor())
{
// Must lower the skyfix floor.
map->skyFix[Plane::Floor].height = bottom;
map->setSkyFixFloor(bottom);
}
}
}
}

void GameMap_InitSkyFix(GameMap *map)
void GameMap::initSkyFix()
{
DENG_ASSERT(map);

Time begunAt;

map->skyFix[Plane::Floor].height = DDMAXFLOAT;
map->skyFix[Plane::Ceiling].height = DDMINFLOAT;
_skyFix[Plane::Floor].height = DDMAXFLOAT;
_skyFix[Plane::Ceiling].height = DDMINFLOAT;

// Update for sector plane heights and mobjs which intersect the ceiling.
foreach(Sector *sector, map->_sectors)
foreach(Sector *sector, _sectors)
{
GameMap_UpdateSkyFixForSector(map, sector);
updateMapSkyFixForSector(this, sector);
}

LOG_INFO(String("GameMap_InitSkyFix: Done in %1 seconds.").arg(begunAt.since(), 0, 'g', 2));
LOG_INFO(String("GameMap::initSkyFix: Done in %1 seconds.").arg(begunAt.since(), 0, 'g', 2));
}

/**
Expand Down Expand Up @@ -841,7 +839,7 @@ DENG_EXTERN_C void R_SetupMap(int mode, int flags)

// Update everything again. Its possible that after loading we
// now have more HOMs to fix, etc..
GameMap_InitSkyFix(theMap);
theMap->initSkyFix();

updateAllMapSectors(*theMap, true /*force*/);
initAllMapSurfaceMaterialOrigins(*theMap);
Expand Down Expand Up @@ -1398,6 +1396,7 @@ coord_t R_SkyCapZ(BspLeaf *bspLeaf, int skyCap)
{
DENG_ASSERT(bspLeaf);
Plane::Type const plane = (skyCap & SKYCAP_UPPER)? Plane::Ceiling : Plane::Floor;
if(!bspLeaf->hasSector() || !P_IsInVoid(viewPlayer)) return GameMap_SkyFix(theMap, plane == Plane::Ceiling);
if(!bspLeaf->hasSector() || !P_IsInVoid(viewPlayer))
return theMap->skyFix(plane == Plane::Ceiling);
return bspLeaf->sector().plane(plane).visHeight();
}
4 changes: 2 additions & 2 deletions doomsday/client/src/render/r_things.cpp
Expand Up @@ -1412,10 +1412,10 @@ int RIT_AddSprite(void *ptr, void *parameters)
mo->origin[VZ] >= sec.floor().height())
{
coord_t visibleTop = mo->origin[VZ] + material->height();
if(visibleTop > GameMap_SkyFixCeiling(map))
if(visibleTop > map->skyFixCeiling())
{
// Raise skyfix ceiling.
GameMap_SetSkyFixCeiling(map, visibleTop + 16/*leeway*/);
map->setSkyFixCeiling(visibleTop + 16/*leeway*/);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2060,15 +2060,15 @@ static coord_t skyFixFloorZ(Plane const *frontFloor, Plane const *backFloor)
DENG_UNUSED(backFloor);
if(devRendSkyMode || P_IsInVoid(viewPlayer))
return frontFloor->visHeight();
return GameMap_SkyFixFloor(theMap);
return theMap->skyFixFloor();
}

static coord_t skyFixCeilZ(Plane const *frontCeil, Plane const *backCeil)
{
DENG_UNUSED(backCeil);
if(devRendSkyMode || P_IsInVoid(viewPlayer))
return frontCeil->visHeight();
return GameMap_SkyFixCeiling(theMap);
return theMap->skyFixCeiling();
}

/**
Expand Down Expand Up @@ -3069,7 +3069,7 @@ void Rend_RenderSurfaceVectors()
plane->visHeight());

if(plane->type() != Plane::Middle && plane->surface().hasSkyMaskedMaterial())
origin[VZ] = GameMap_SkyFix(theMap, plane->type() == Plane::Ceiling);
origin[VZ] = theMap->skyFix(plane->type() == Plane::Ceiling);

drawSurfaceTangentSpaceVectors(&plane->surface(), origin);
}
Expand Down

0 comments on commit 36245cd

Please sign in to comment.