From 80e369541a55d0c2dc7c2ef0eb28f543af6b120f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 30 Dec 2016 06:42:20 +0100 Subject: [PATCH] Move visplane_t to its own file --- src/CMakeLists.txt | 1 + src/swrenderer/r_main.cpp | 2 +- src/swrenderer/scene/r_plane.cpp | 119 ----------------------- src/swrenderer/scene/r_plane.h | 80 +-------------- src/swrenderer/scene/r_visible_plane.cpp | 106 ++++++++++++++++++++ src/swrenderer/scene/r_visible_plane.h | 67 +++++++++++++ 6 files changed, 178 insertions(+), 197 deletions(-) create mode 100644 src/swrenderer/scene/r_visible_plane.cpp create mode 100644 src/swrenderer/scene/r_visible_plane.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f30cc647b..46dc1b118 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -825,6 +825,7 @@ set( FASTMATH_PCH_SOURCES swrenderer/scene/r_draw_segment.cpp swrenderer/scene/r_portal_segment.cpp swrenderer/scene/r_portal.cpp + swrenderer/scene/r_visible_plane.cpp polyrenderer/poly_renderer.cpp polyrenderer/scene/poly_scene.cpp polyrenderer/scene/poly_portal.cpp diff --git a/src/swrenderer/r_main.cpp b/src/swrenderer/r_main.cpp index 2d14a2308..7027a7767 100644 --- a/src/swrenderer/r_main.cpp +++ b/src/swrenderer/r_main.cpp @@ -377,7 +377,6 @@ void R_InitRenderer() // viewwidth / viewheight are set by the defaults fillshort (zeroarray, MAXWIDTH, 0); - R_InitPlanes (); R_InitShadeMaps(); R_InitColumnDrawers (); } @@ -392,6 +391,7 @@ static void R_ShutdownRenderer() { R_DeinitSprites(); R_DeinitPlanes(); + fakeActive = 0; // Free openings if (openings != NULL) { diff --git a/src/swrenderer/scene/r_plane.cpp b/src/swrenderer/scene/r_plane.cpp index 3eb619228..cfb6cda28 100644 --- a/src/swrenderer/scene/r_plane.cpp +++ b/src/swrenderer/scene/r_plane.cpp @@ -89,20 +89,9 @@ static void R_DrawSkyStriped (visplane_t *pl); planefunction_t floorfunc; planefunction_t ceilingfunc; -// [RH] Allocate one extra for sky box planes. -visplane_t *visplanes[MAXVISPLANES+1]; -visplane_t *freetail; -visplane_t **freehead = &freetail; - visplane_t *floorplane; visplane_t *ceilingplane; -// killough -- hash function for visplanes -// Empirically verified to be fairly uniform: - -#define visplane_hash(picnum,lightlevel,height) \ - ((unsigned)((picnum)*3+(lightlevel)+(FLOAT2FIXED((height).fD()))*7) & (MAXVISPLANES-1)) - // These are copies of the main parameters used when drawing stacked sectors. // When you change the main parameters, you should copy them here too *unless* // you are changing them to draw a stacked sector. Otherwise, stacked sectors @@ -146,44 +135,6 @@ static double basexfrac, baseyfrac; void R_DrawSinglePlane (visplane_t *, fixed_t alpha, bool additive, bool masked); -//========================================================================== -// -// R_InitPlanes -// -// Called at game startup. -// -//========================================================================== - -void R_InitPlanes () -{ -} - -//========================================================================== -// -// R_DeinitPlanes -// -//========================================================================== - -void R_DeinitPlanes () -{ - fakeActive = 0; - - // do not use R_ClearPlanes because at this point the screen pointer is no longer valid. - for (int i = 0; i <= MAXVISPLANES; i++) // new code -- killough - { - for (*freehead = visplanes[i], visplanes[i] = NULL; *freehead; ) - { - freehead = &(*freehead)->next; - } - } - for (visplane_t *pl = freetail; pl != NULL; ) - { - visplane_t *next = pl->next; - free (pl); - pl = next; - } -} - //========================================================================== // // R_MapPlane @@ -537,38 +488,6 @@ void R_ClearPlanes (bool fullclear) } } -//========================================================================== -// -// new_visplane -// -// New function, by Lee Killough -// [RH] top and bottom buffers get allocated immediately after the visplane. -// -//========================================================================== - -static visplane_t *new_visplane (unsigned hash) -{ - visplane_t *check = freetail; - - if (check == NULL) - { - check = (visplane_t *)M_Malloc (sizeof(*check) + 3 + sizeof(*check->top)*(MAXWIDTH*2)); - memset(check, 0, sizeof(*check) + 3 + sizeof(*check->top)*(MAXWIDTH*2)); - check->bottom = check->top + MAXWIDTH+2; - } - else if (NULL == (freetail = freetail->next)) - { - freehead = &freetail; - } - - check->lights = nullptr; - - check->next = visplanes[hash]; - visplanes[hash] = check; - return check; -} - - //========================================================================== // // R_FindPlane @@ -1754,42 +1673,4 @@ void R_MapVisPlane (visplane_t *pl, void (*mapfunc)(int y, int x1)) ds_light_list = nullptr; } -//========================================================================== -// -// R_PlaneInitData -// -//========================================================================== - -bool R_PlaneInitData () -{ - int i; - visplane_t *pl; - - // Free all visplanes and let them be re-allocated as needed. - pl = freetail; - - while (pl) - { - visplane_t *next = pl->next; - M_Free (pl); - pl = next; - } - freetail = NULL; - freehead = &freetail; - - for (i = 0; i < MAXVISPLANES; i++) - { - pl = visplanes[i]; - visplanes[i] = NULL; - while (pl) - { - visplane_t *next = pl->next; - M_Free (pl); - pl = next; - } - } - - return true; -} - } diff --git a/src/swrenderer/scene/r_plane.h b/src/swrenderer/scene/r_plane.h index 176b9d2c8..c2f885c85 100644 --- a/src/swrenderer/scene/r_plane.h +++ b/src/swrenderer/scene/r_plane.h @@ -23,63 +23,11 @@ #ifndef __R_PLANE_H__ #define __R_PLANE_H__ -#include - -class ASkyViewpoint; -class ADynamicLight; -struct FLightNode; +#include "r_visible_plane.h" namespace swrenderer { -struct visplane_light -{ - ADynamicLight *lightsource; - visplane_light *next; -}; - -// -// The infamous visplane -// -struct visplane_s -{ - struct visplane_s *next; // Next visplane in hash chain -- killough - - FDynamicColormap *colormap; // [RH] Support multiple colormaps - FSectorPortal *portal; // [RH] Support sky boxes - visplane_light *lights; - - FTransform xform; - secplane_t height; - FTextureID picnum; - int lightlevel; - int left, right; - int sky; - - // [RH] This set of variables copies information from the time when the - // visplane is created. They are only used by stacks so that you can - // have stacked sectors inside a skybox. If the visplane is not for a - // stack, then they are unused. - int extralight; - double visibility; - DVector3 viewpos; - DAngle viewangle; - fixed_t Alpha; - bool Additive; - - // kg3D - keep track of mirror and skybox owner - int CurrentSkybox; - int CurrentPortalUniq; // mirror counter, counts all of them - int MirrorFlags; // this is not related to CurrentMirror - - unsigned short *bottom; // [RH] bottom and top arrays are dynamically - unsigned short pad; // allocated immediately after the - unsigned short top[]; // visplane. -}; -typedef struct visplane_s visplane_t; - - - typedef void (*planefunction_t) (int top, int bottom); extern planefunction_t floorfunc; @@ -90,8 +38,6 @@ extern short ceilingclip[MAXWIDTH]; extern float yslope[MAXHEIGHT]; -void R_InitPlanes (); -void R_DeinitPlanes (); void R_ClearPlanes (bool fullclear); void R_AddPlaneLights(visplane_t *plane, FLightNode *light_head); @@ -108,32 +54,12 @@ void R_MapColoredPlane(int y, int x1); void R_DrawFogBoundary(int x1, int x2, short *uclip, short *dclip); -visplane_t *R_FindPlane -( const secplane_t &height, - FTextureID picnum, - int lightlevel, - double alpha, - bool additive, - const FTransform &xform, - int sky, - FSectorPortal *portal); - -visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop); - - -// [RH] Added for multires support -bool R_PlaneInitData (void); - +visplane_t *R_FindPlane(const secplane_t &height, FTextureID picnum, int lightlevel, double alpha, bool additive, const FTransform &xform, int sky, FSectorPortal *portal); +visplane_t *R_CheckPlane(visplane_t *pl, int start, int stop); extern visplane_t* floorplane; extern visplane_t* ceilingplane; -#define MAXVISPLANES 128 /* must be a power of 2 */ - -extern visplane_t *visplanes[MAXVISPLANES + 1]; -extern visplane_t *freetail; -extern visplane_t **freehead; - } #endif // __R_PLANE_H__ diff --git a/src/swrenderer/scene/r_visible_plane.cpp b/src/swrenderer/scene/r_visible_plane.cpp new file mode 100644 index 000000000..4a9e11ce9 --- /dev/null +++ b/src/swrenderer/scene/r_visible_plane.cpp @@ -0,0 +1,106 @@ + +#include +#include + +#include "templates.h" +#include "i_system.h" +#include "w_wad.h" +#include "doomdef.h" +#include "doomstat.h" +#include "swrenderer/r_main.h" +#include "swrenderer/scene/r_things.h" +#include "r_sky.h" +#include "stats.h" +#include "v_video.h" +#include "a_sharedglobal.h" +#include "c_console.h" +#include "cmdlib.h" +#include "d_net.h" +#include "g_level.h" +#include "r_bsp.h" +#include "r_visible_plane.h" + +namespace swrenderer +{ + // [RH] Allocate one extra for sky box planes. + visplane_t *visplanes[MAXVISPLANES + 1]; + visplane_t *freetail; + visplane_t **freehead = &freetail; + + namespace + { + enum { max_plane_lights = 32 * 1024 }; + visplane_light plane_lights[max_plane_lights]; + int next_plane_light = 0; + } + + void R_DeinitPlanes() + { + // do not use R_ClearPlanes because at this point the screen pointer is no longer valid. + for (int i = 0; i <= MAXVISPLANES; i++) // new code -- killough + { + for (*freehead = visplanes[i], visplanes[i] = NULL; *freehead; ) + { + freehead = &(*freehead)->next; + } + } + for (visplane_t *pl = freetail; pl != NULL; ) + { + visplane_t *next = pl->next; + free(pl); + pl = next; + } + } + + visplane_t *new_visplane(unsigned hash) + { + visplane_t *check = freetail; + + if (check == NULL) + { + check = (visplane_t *)M_Malloc(sizeof(*check) + 3 + sizeof(*check->top)*(MAXWIDTH * 2)); + memset(check, 0, sizeof(*check) + 3 + sizeof(*check->top)*(MAXWIDTH * 2)); + check->bottom = check->top + MAXWIDTH + 2; + } + else if (NULL == (freetail = freetail->next)) + { + freehead = &freetail; + } + + check->lights = nullptr; + + check->next = visplanes[hash]; + visplanes[hash] = check; + return check; + } + + void R_PlaneInitData() + { + int i; + visplane_t *pl; + + // Free all visplanes and let them be re-allocated as needed. + pl = freetail; + + while (pl) + { + visplane_t *next = pl->next; + M_Free(pl); + pl = next; + } + freetail = NULL; + freehead = &freetail; + + for (i = 0; i < MAXVISPLANES; i++) + { + pl = visplanes[i]; + visplanes[i] = NULL; + while (pl) + { + visplane_t *next = pl->next; + M_Free(pl); + pl = next; + } + } + } +} diff --git a/src/swrenderer/scene/r_visible_plane.h b/src/swrenderer/scene/r_visible_plane.h new file mode 100644 index 000000000..28e703505 --- /dev/null +++ b/src/swrenderer/scene/r_visible_plane.h @@ -0,0 +1,67 @@ + +#pragma once + +#include +#include "r_defs.h" + +class ASkyViewpoint; +class ADynamicLight; +struct FLightNode; +struct FDynamicColormap; +struct FSectorPortal; + +namespace swrenderer +{ + struct visplane_light + { + ADynamicLight *lightsource; + visplane_light *next; + }; + + struct visplane_t + { + visplane_t *next; // Next visplane in hash chain -- killough + + FDynamicColormap *colormap; // [RH] Support multiple colormaps + FSectorPortal *portal; // [RH] Support sky boxes + visplane_light *lights; + + FTransform xform; + secplane_t height; + FTextureID picnum; + int lightlevel; + int left, right; + int sky; + + // [RH] This set of variables copies information from the time when the + // visplane is created. They are only used by stacks so that you can + // have stacked sectors inside a skybox. If the visplane is not for a + // stack, then they are unused. + int extralight; + double visibility; + DVector3 viewpos; + DAngle viewangle; + fixed_t Alpha; + bool Additive; + + // kg3D - keep track of mirror and skybox owner + int CurrentSkybox; + int CurrentPortalUniq; // mirror counter, counts all of them + int MirrorFlags; // this is not related to CurrentMirror + + unsigned short *bottom; // [RH] bottom and top arrays are dynamically + unsigned short pad; // allocated immediately after the + unsigned short top[]; // visplane. + }; + + #define MAXVISPLANES 128 /* must be a power of 2 */ + #define visplane_hash(picnum,lightlevel,height) ((unsigned)((picnum)*3+(lightlevel)+(FLOAT2FIXED((height).fD()))*7) & (MAXVISPLANES-1)) + + extern visplane_t *visplanes[MAXVISPLANES + 1]; + extern visplane_t *freetail; + extern visplane_t **freehead; + + void R_DeinitPlanes(); + visplane_t *new_visplane(unsigned hash); + void R_PlaneInitData(); +}