Skip to content

Commit

Permalink
Refactor|Renderer: Use an object-oriented model for AngleClipper
Browse files Browse the repository at this point in the history
Todo for later: Much more can be done to improve the implementation.
Although, it remains to be seen whether we'll still need this in the
future.
  • Loading branch information
danij-deng committed Apr 14, 2015
1 parent d52a26c commit 9a7c162
Show file tree
Hide file tree
Showing 16 changed files with 1,272 additions and 1,213 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/client.pro
Expand Up @@ -265,6 +265,7 @@ DENG_HEADERS += \
include/network/sys_network.h \
include/partition.h \
include/r_util.h \
include/render/angleclipper.h \
include/render/biasdigest.h \
include/render/biasillum.h \
include/render/biassource.h \
Expand Down Expand Up @@ -294,7 +295,6 @@ DENG_HEADERS += \
include/render/r_draw.h \
include/render/r_main.h \
include/render/r_things.h \
include/render/rend_clip.h \
include/render/rend_dynlight.h \
include/render/rend_fakeradio.h \
include/render/rend_font.h \
Expand Down Expand Up @@ -597,6 +597,7 @@ SOURCES += \
src/network/serverlink.cpp \
src/network/sys_network.cpp \
src/r_util.cpp \
src/render/angleclipper.cpp \
src/render/api_render.cpp \
src/render/biasdigest.cpp \
src/render/biasillum.cpp \
Expand Down Expand Up @@ -626,7 +627,6 @@ SOURCES += \
src/render/r_fakeradio.cpp \
src/render/r_main.cpp \
src/render/r_things.cpp \
src/render/rend_clip.cpp \
src/render/rend_dynlight.cpp \
src/render/rend_fakeradio.cpp \
src/render/rend_font.cpp \
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/include/de_render.h
Expand Up @@ -29,7 +29,6 @@
#include "render/r_draw.h"
#include "render/r_main.h"
#include "render/r_things.h"
#include "render/rend_clip.h"
#include "render/rend_halo.h"
#include "render/rend_particle.h"
#include "render/rend_main.h"
Expand Down
120 changes: 120 additions & 0 deletions doomsday/client/include/render/angleclipper.h
@@ -0,0 +1,120 @@
/** @file angleclipper.h Angle Clipper.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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</small>
*/

#ifndef CLIENT_RENDER_ANGLECLIPPER
#define CLIENT_RENDER_ANGLECLIPPER

#include <de/binangle.h>
#include <de/Vector>
#include "Face"

/**
* 360 degree, polar angle(-range) clipper.
*
* The idea is to keep track of occluded angles around the camera. Since BSP leafs are
* rendered front-to-back, the occlusion lists start a frame empty and eventually fill
* up to cover the whole 360 degrees around the camera.
*
* Oranges (occlusion ranges) clip a half-space on an angle range. These are produced
* by horizontal edges that have empty space behind.
*
* @ingroup render
*/
class AngleClipper
{
public:
AngleClipper();

/**
* Returns non-zero if clipnodes cover the whole range [0..360] degrees.
*/
de::dint isFull() const;

/**
* Returns non-zero if the given map-space @param angle is @em not-yet occluded.
*/
de::dint isAngleVisible(binangle_t angle) const;

/**
* Returns non-zero if the given map-space @a point is @em not-yet occluded.
*
* @param point Map-space coordinates to test.
*/
de::dint isPointVisible(de::Vector3d const &point) const;

/**
* Returns non-zero if @em any portion of the given map-space, convex face geometry
* is @em not-yet occluded.
*
* @param poly Map-space convex face geometry to test.
*/
de::dint isPolyVisible(de::Face const &poly) const;

public: // ---------------------------------------------------------------------------

/**
*
*/
void clearRanges();

/**
*
*/
de::dint safeAddRange(binangle_t startAngle, binangle_t endAngle);

/**
* Add a segment relative to the current viewpoint.
*
* @param from Map-space coordinates describing the start-point.
* @param to Map-space coordinates describing the end-point.
*/
void addRangeFromViewRelPoints(de::Vector2d const &from, de::Vector2d const &to);

/**
* Add an occlusion segment relative to the current viewpoint.
*
* @param from Map-space coordinates for the start-point.
* @param to Map-space coordinates for the end-point.
* @param height
* @param topHalf
*/
void addViewRelOcclusion(de::Vector2d const &from, de::Vector2d const &to, coord_t height,
bool topHalf);

/**
* Check a segment relative to the current viewpoint.
*
* @param from Map-space coordinates for the start-point.
* @param to Map-space coordinates for the end-point.
*/
de::dint checkRangeFromViewRelPoints(de::Vector2d const &from, de::Vector2d const &to);

#ifdef DENG2_DEBUG
/**
* A debugging aid: checks if clipnode links are valid.
*/
void validate();
#endif

private:
DENG2_PRIVATE(d)
};

#endif // CLIENT_RENDER_ANGLECLIPPER
96 changes: 0 additions & 96 deletions doomsday/client/include/render/rend_clip.h

This file was deleted.

3 changes: 1 addition & 2 deletions doomsday/client/include/render/rend_main.h
Expand Up @@ -119,6 +119,7 @@ DENG_EXTERN_C dd_bool noHighResPatches;
DENG_EXTERN_C dd_bool highResWithPWAD;
DENG_EXTERN_C byte loadExtAlways;

DENG_EXTERN_C int devNoCulling;
DENG_EXTERN_C byte devRendSkyAlways;
DENG_EXTERN_C byte rendInfoLums;
DENG_EXTERN_C byte devDrawLums;
Expand All @@ -127,8 +128,6 @@ DENG_EXTERN_C byte freezeRLs;

void Rend_Register();

void Rend_Init();
void Rend_Shutdown();
void Rend_Reset();

/// @return @c true iff multitexturing is currently enabled for lights.
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/include/render/rendersystem.h
Expand Up @@ -26,6 +26,7 @@
#include "DrawLists"
#include "settingsregister.h"

class AngleClipper;
class ModelRenderer;
class SkyDrawable;

Expand Down Expand Up @@ -78,6 +79,8 @@ class RenderSystem : public de::System
SettingsRegister &settings();
SettingsRegister &appearanceSettings();

AngleClipper &angleClipper() const;

ModelRenderer &modelRenderer();

SkyDrawable &sky();
Expand Down
14 changes: 7 additions & 7 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -112,7 +112,7 @@ DENG2_PIMPL(ClientApp)
SettingsRegister logSettings;
QMenuBar *menuBar;
InputSystem *inputSys;
RenderSystem *renderSys;
RenderSystem *rendSys;
ResourceSystem *resourceSys;
ClientWindowSystem *winSys;
InFineSystem infineSys; // instantiated at construction time
Expand Down Expand Up @@ -187,7 +187,7 @@ DENG2_PIMPL(ClientApp)
: Base(i)
, menuBar (0)
, inputSys (0)
, renderSys (0)
, rendSys (0)
, resourceSys(0)
, winSys (0)
//, infineSys (0)
Expand All @@ -213,7 +213,7 @@ DENG2_PIMPL(ClientApp)
//delete infineSys;
delete winSys;
delete svLink;
delete renderSys;
delete rendSys;
delete resourceSys;
delete inputSys;
delete menuBar;
Expand Down Expand Up @@ -369,8 +369,8 @@ void ClientApp::initialize()
#endif

// Create the render system.
d->renderSys = new RenderSystem;
addSystem(*d->renderSys);
d->rendSys = new RenderSystem;
addSystem(*d->rendSys);

// Create the window system.
d->winSys = new ClientWindowSystem;
Expand Down Expand Up @@ -508,12 +508,12 @@ RenderSystem &ClientApp::renderSystem()
{
ClientApp &a = ClientApp::app();
DENG2_ASSERT(hasRenderSystem());
return *a.d->renderSys;
return *a.d->rendSys;
}

bool ClientApp::hasRenderSystem()
{
return ClientApp::app().d->renderSys != 0;
return ClientApp::app().d->rendSys != 0;
}

ResourceSystem &ClientApp::resourceSystem()
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -65,8 +65,8 @@
# include "render/cameralensfx.h"
# include "render/r_draw.h" // R_InitViewWindow
# include "render/r_main.h" // R_Init, R_ResetViewer
# include "render/rend_font.h"
# include "render/rend_main.h"
# include "render/rend_font.h"
# include "render/rend_particle.h" // Rend_ParticleLoadSystemTextures
# include "render/vr.h"
# include "Contact"
Expand Down Expand Up @@ -2202,7 +2202,6 @@ static int DD_StartupWorker(void * /*context*/)
R_InitSvgs();
#ifdef __CLIENT__
R_InitViewWindow();
Rend_Init();
R_ResetFrameCount();
#endif
Con_SetProgress(165);
Expand Down
9 changes: 8 additions & 1 deletion doomsday/client/src/dd_pinit.cpp
Expand Up @@ -34,6 +34,10 @@
#include "de_ui.h"
#include "de_filesys.h"

#ifdef __CLIENT__
# include "clientapp.h"
#endif

#include "def_main.h"
#include "gl/svg.h"

Expand Down Expand Up @@ -170,7 +174,10 @@ void DD_ShutdownAll()
R_ShutdownSvgs();
#ifdef __CLIENT__
R_ShutdownViewWindow();
Rend_Shutdown();
if(ClientApp::hasRenderSystem())
{
ClientApp::renderSystem().clearDrawLists();
}
#endif
Def_Destroy();
F_Shutdown();
Expand Down

0 comments on commit 9a7c162

Please sign in to comment.