From 11411909ffa16cca8c10d3d25b3ad4806c864022 Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 30 Jun 2015 04:26:36 +0100 Subject: [PATCH] Refactor|Renderer|Client: Moved FakeRadio shadow line initialization into de::Map --- .../client/include/render/rend_fakeradio.h | 6 - doomsday/apps/client/include/world/map.h | 5 + .../apps/client/src/render/r_fakeradio.cpp | 118 ------------------ .../apps/client/src/render/rend_fakeradio.cpp | 4 +- doomsday/apps/client/src/world/map.cpp | 75 +++++++++++ .../apps/client/src/world/worldsystem.cpp | 3 +- 6 files changed, 83 insertions(+), 128 deletions(-) delete mode 100644 doomsday/apps/client/src/render/r_fakeradio.cpp diff --git a/doomsday/apps/client/include/render/rend_fakeradio.h b/doomsday/apps/client/include/render/rend_fakeradio.h index ad6f5f2209..72df005d8d 100644 --- a/doomsday/apps/client/include/render/rend_fakeradio.h +++ b/doomsday/apps/client/include/render/rend_fakeradio.h @@ -34,7 +34,6 @@ #ifndef CLIENT_RENDER_FAKERADIO #define CLIENT_RENDER_FAKERADIO -#include "world/map.h" #include "Line" #include "WallEdge" @@ -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. */ diff --git a/doomsday/apps/client/include/world/map.h b/doomsday/apps/client/include/world/map.h index 0d011da0bf..0ba19471c5 100644 --- a/doomsday/apps/client/include/world/map.h +++ b/doomsday/apps/client/include/world/map.h @@ -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. diff --git a/doomsday/apps/client/src/render/r_fakeradio.cpp b/doomsday/apps/client/src/render/r_fakeradio.cpp deleted file mode 100644 index 8fa4010eb2..0000000000 --- a/doomsday/apps/client/src/render/r_fakeradio.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/** @file r_fakeradio.cpp Faked Radiosity Lighting. - * - * @authors Copyright © 2003-2014 Jaakko Keränen - * @authors Copyright © 2006-2015 Daniel Swanson - * - * @par License - * GPL: http://www.gnu.org/licenses/gpl.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. This program is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with this program; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "de_base.h" -#include "render/rend_fakeradio.h" - -#include /// @todo remove me -#include /// @todo remove me -#include -#include -#include "world/blockmap.h" -#include "world/lineowner.h" -#include "world/map.h" -#include "ConvexSubspace" -#include "Face" -#include "MaterialAnimator" -#include "SectorCluster" -#include "Surface" -#include "Vertex" - -#include "render/rend_main.h" - -using namespace de; - -void Rend_RadioInitForMap(Map &map) -{ - Time begunAt; - - LOG_AS("Rend_RadioInitForMap"); - - map.forAllVertexs([] (Vertex &vertex) - { - vertex.updateShadowOffsets(); - return LoopContinue; - }); - - /// 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. - map.forAllLines([] (Line &line) - { - if(line.castsShadow()) - { - // 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; - line.map().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; - }); - } - } - return LoopContinue; - }); - - LOGDEV_GL_MSG("Completed in %.2f seconds") << begunAt.since(); -} diff --git a/doomsday/apps/client/src/render/rend_fakeradio.cpp b/doomsday/apps/client/src/render/rend_fakeradio.cpp index bea565d0ec..c53cd978d0 100644 --- a/doomsday/apps/client/src/render/rend_fakeradio.cpp +++ b/doomsday/apps/client/src/render/rend_fakeradio.cpp @@ -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(); diff --git a/doomsday/apps/client/src/world/map.cpp b/doomsday/apps/client/src/world/map.cpp index e6c875a2a2..9e5d3e995a 100644 --- a/doomsday/apps/client/src/world/map.cpp +++ b/doomsday/apps/client/src/world/map.cpp @@ -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(); diff --git a/doomsday/apps/client/src/world/worldsystem.cpp b/doomsday/apps/client/src/world/worldsystem.cpp index 39428fedad..87c0d20ce6 100644 --- a/doomsday/apps/client/src/world/worldsystem.cpp +++ b/doomsday/apps/client/src/world/worldsystem.cpp @@ -605,8 +605,7 @@ DENG2_PIMPL(WorldSystem) R_InitRendPolyPools(); Rend_UpdateLightModMatrix(); - Rend_RadioInitForMap(*map); - + map->initRadio(); map->initContactBlockmaps(); R_InitContactLists(*map); rendSys().worldSystemMapChanged(*map);