Skip to content

Commit

Permalink
Refactor|Renderer|Client: Moved FakeRadio shadow line initialization …
Browse files Browse the repository at this point in the history
…into de::Map
  • Loading branch information
danij-deng committed Jun 30, 2015
1 parent 479625a commit 1141190
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 128 deletions.
6 changes: 0 additions & 6 deletions doomsday/apps/client/include/render/rend_fakeradio.h
Expand Up @@ -34,7 +34,6 @@
#ifndef CLIENT_RENDER_FAKERADIO
#define CLIENT_RENDER_FAKERADIO

#include "world/map.h"
#include "Line"
#include "WallEdge"

Expand Down Expand Up @@ -63,11 +62,6 @@ struct edgespan_t
de::dfloat shift;
};

/**
* To be called after map load to perform necessary initialization within this module.
*/
void Rend_RadioInitForMap(de::Map &map);

/**
* To be called to update the shadow properties for the specified line @a side.
*/
Expand Down
5 changes: 5 additions & 0 deletions doomsday/apps/client/include/world/map.h
Expand Up @@ -861,6 +861,11 @@ class Map
*/
void initContactBlockmaps();

/**
* Initialize data and structures needed for FakeRadio.
*/
void initRadio();

/**
* Spawn all generators for the map which should be initialized automatically
* during map setup.
Expand Down
118 changes: 0 additions & 118 deletions doomsday/apps/client/src/render/r_fakeradio.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions doomsday/apps/client/src/render/rend_fakeradio.cpp
Expand Up @@ -828,8 +828,8 @@ static void setBottomShadowParams(WallEdge const &leftEdge, WallEdge const &righ
}
}

static void setSideShadowParams(WallEdge const &leftEdge, WallEdge const &rightEdge, bool rightSide, ddouble shadowSize,
ProjectedShadowData &projected)
static void setSideShadowParams(WallEdge const &leftEdge, WallEdge const &rightEdge, bool rightSide,
ddouble shadowSize, ProjectedShadowData &projected)
{
LineSide /*const*/ &side = leftEdge.mapLineSide();
HEdge const *hedge = side.leftHEdge();
Expand Down
75 changes: 75 additions & 0 deletions doomsday/apps/client/src/world/map.cpp
Expand Up @@ -1942,6 +1942,81 @@ void Map::buildMaterialLists()
}
}

void Map::initRadio()
{
LOG_AS("Map::initRadio");

Time begunAt;

for(Vertex *vtx : d->mesh.vertexs())
{
vtx->updateShadowOffsets();
}

/// The algorithm:
///
/// 1. Use the subspace blockmap to look for all the blocks that are within the line's shadow
/// bounding box.
/// 2. Check the ConvexSubspaces whose sector is the same as the line.
/// 3. If any of the shadow points are in the subspace, or any of the shadow edges cross one
/// of the subspace's edges (not parallel), link the line to the ConvexSubspace.
for(Line *line : d->lines)
{
if(!line->castsShadow()) continue;

// For each side of the line.
for(dint i = 0; i < 2; ++i)
{
LineSide &side = line->side(i);

if(!side.hasSector()) continue;
if(!side.hasSections()) continue;

Vertex const &vtx0 = line->vertex(i);
Vertex const &vtx1 = line->vertex(i ^ 1);
LineOwner const &vo0 = line->vertexOwner(i)->next();
LineOwner const &vo1 = line->vertexOwner(i ^ 1)->prev();

AABoxd bounds = line->aaBox();

// Use the extended points, they are wider than inoffsets.
Vector2d const sv0 = vtx0.origin() + vo0.extendedShadowOffset();
V2d_AddToBoxXY(bounds.arvec2, sv0.x, sv0.y);

Vector2d const sv1 = vtx1.origin() + vo1.extendedShadowOffset();
V2d_AddToBoxXY(bounds.arvec2, sv1.x, sv1.y);

// Link the shadowing line to all the subspaces whose axis-aligned bounding box
// intersects 'bounds'.
::validCount++;
dint const localValidCount = ::validCount;
subspaceBlockmap().forAllInBox(bounds, [&bounds, &side, &localValidCount] (void *object)
{
auto &sub = *(ConvexSubspace *)object;
if(sub.validCount() != localValidCount) // not yet processed
{
sub.setValidCount(localValidCount);
if(&sub.sector() == side.sectorPtr())
{
// Check the bounds.
AABoxd const &polyBox = sub.poly().aaBox();
if(!(polyBox.maxX < bounds.minX ||
polyBox.minX > bounds.maxX ||
polyBox.minY > bounds.maxY ||
polyBox.maxY < bounds.minY))
{
sub.addShadowLine(side);
}
}
}
return LoopContinue;
});
}
}

LOGDEV_GL_MSG("Completed in %.2f seconds") << begunAt.since();
}

void Map::initContactBlockmaps()
{
d->initContactBlockmaps();
Expand Down
3 changes: 1 addition & 2 deletions doomsday/apps/client/src/world/worldsystem.cpp
Expand Up @@ -605,8 +605,7 @@ DENG2_PIMPL(WorldSystem)
R_InitRendPolyPools();
Rend_UpdateLightModMatrix();

Rend_RadioInitForMap(*map);

map->initRadio();
map->initContactBlockmaps();
R_InitContactLists(*map);
rendSys().worldSystemMapChanged(*map);
Expand Down

0 comments on commit 1141190

Please sign in to comment.