From 60c0dcc3c73cabb8bc81748c067ed304039bd446 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 30 Dec 2016 05:35:25 +0100 Subject: [PATCH] Move openings to r_memory --- src/CMakeLists.txt | 1 + src/swrenderer/r_memory.cpp | 52 +++++++++++++++++++++++++ src/swrenderer/r_memory.h | 10 +++++ src/swrenderer/scene/r_draw_segment.cpp | 16 -------- src/swrenderer/scene/r_draw_segment.h | 1 - src/swrenderer/scene/r_plane.cpp | 15 +------ src/swrenderer/scene/r_plane.h | 4 -- src/swrenderer/scene/r_segs.cpp | 1 + src/swrenderer/scene/r_segs.h | 4 -- src/swrenderer/scene/r_things.cpp | 1 + 10 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 src/swrenderer/r_memory.cpp create mode 100644 src/swrenderer/r_memory.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 454ed25daa..87841b3802 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -808,6 +808,7 @@ set( NOT_COMPILED_SOURCE_FILES set( FASTMATH_PCH_SOURCES swrenderer/r_swrenderer.cpp swrenderer/r_main.cpp + swrenderer/r_memory.cpp swrenderer/drawers/r_draw.cpp swrenderer/drawers/r_draw_pal.cpp swrenderer/drawers/r_draw_rgba.cpp diff --git a/src/swrenderer/r_memory.cpp b/src/swrenderer/r_memory.cpp new file mode 100644 index 0000000000..855d851be7 --- /dev/null +++ b/src/swrenderer/r_memory.cpp @@ -0,0 +1,52 @@ + +#include +#include "templates.h" +#include "doomdef.h" +#include "m_bbox.h" +#include "i_system.h" +#include "p_lnspec.h" +#include "p_setup.h" +#include "swrenderer/r_main.h" +#include "swrenderer/drawers/r_draw.h" +#include "a_sharedglobal.h" +#include "g_level.h" +#include "p_effect.h" +#include "doomstat.h" +#include "r_state.h" +#include "v_palette.h" +#include "r_sky.h" +#include "po_man.h" +#include "r_data/colormaps.h" +#include "r_memory.h" + +namespace swrenderer +{ + short *openings; + + namespace + { + size_t maxopenings; + ptrdiff_t lastopening; + } + + ptrdiff_t R_NewOpening(ptrdiff_t len) + { + ptrdiff_t res = lastopening; + len = (len + 1) & ~1; // only return DWORD aligned addresses because some code stores fixed_t's and floats in openings... + lastopening += len; + if ((size_t)lastopening > maxopenings) + { + do + maxopenings = maxopenings ? maxopenings * 2 : 16384; + while ((size_t)lastopening > maxopenings); + openings = (short *)M_Realloc(openings, maxopenings * sizeof(*openings)); + DPrintf(DMSG_NOTIFY, "MaxOpenings increased to %zu\n", maxopenings); + } + return res; + } + + void R_FreeOpenings() + { + lastopening = 0; + } +} diff --git a/src/swrenderer/r_memory.h b/src/swrenderer/r_memory.h new file mode 100644 index 0000000000..06a03c3ffc --- /dev/null +++ b/src/swrenderer/r_memory.h @@ -0,0 +1,10 @@ + +#pragma once + +namespace swrenderer +{ + extern short *openings; + + ptrdiff_t R_NewOpening(ptrdiff_t len); + void R_FreeOpenings(); +} diff --git a/src/swrenderer/scene/r_draw_segment.cpp b/src/swrenderer/scene/r_draw_segment.cpp index 6181911f2a..2200f0ea51 100644 --- a/src/swrenderer/scene/r_draw_segment.cpp +++ b/src/swrenderer/scene/r_draw_segment.cpp @@ -74,20 +74,4 @@ namespace swrenderer return ds_p++; } - - ptrdiff_t R_NewOpening(ptrdiff_t len) - { - ptrdiff_t res = lastopening; - len = (len + 1) & ~1; // only return DWORD aligned addresses because some code stores fixed_t's and floats in openings... - lastopening += len; - if ((size_t)lastopening > maxopenings) - { - do - maxopenings = maxopenings ? maxopenings * 2 : 16384; - while ((size_t)lastopening > maxopenings); - openings = (short *)M_Realloc(openings, maxopenings * sizeof(*openings)); - DPrintf(DMSG_NOTIFY, "MaxOpenings increased to %zu\n", maxopenings); - } - return res; - } } diff --git a/src/swrenderer/scene/r_draw_segment.h b/src/swrenderer/scene/r_draw_segment.h index 05d6c3846f..61f6d4d580 100644 --- a/src/swrenderer/scene/r_draw_segment.h +++ b/src/swrenderer/scene/r_draw_segment.h @@ -43,5 +43,4 @@ namespace swrenderer void R_FreeDrawSegs(); drawseg_t *R_AddDrawSegment(); - ptrdiff_t R_NewOpening(ptrdiff_t len); } diff --git a/src/swrenderer/scene/r_plane.cpp b/src/swrenderer/scene/r_plane.cpp index 2b698e2728..b6648da712 100644 --- a/src/swrenderer/scene/r_plane.cpp +++ b/src/swrenderer/scene/r_plane.cpp @@ -65,6 +65,7 @@ #include "r_clip_segment.h" #include "r_draw_segment.h" #include "r_portal_segment.h" +#include "swrenderer\r_memory.h" #ifdef _MSC_VER #pragma warning(disable:4244) @@ -118,15 +119,6 @@ double stacked_visibility; DVector3 stacked_viewpos; DAngle stacked_angle; - -// -// opening -// - -size_t maxopenings; -short *openings; -ptrdiff_t lastopening; - // // Clip values are the solid pixel bounding the range. // floorclip starts out SCREENHEIGHT and is just outside the range @@ -546,7 +538,7 @@ void R_ClearPlanes (bool fullclear) !screen->Accel2D && ConBottom > viewwindowy && !bRenderingToCanvas ? (ConBottom - viewwindowy) : 0); - lastopening = 0; + R_FreeOpenings(); next_plane_light = 0; } @@ -1351,7 +1343,6 @@ void R_DrawPortals () DAngle savedangle = ViewAngle; ptrdiff_t savedvissprite_p = vissprite_p - vissprites; ptrdiff_t savedds_p = ds_p - drawsegs; - ptrdiff_t savedlastopening = lastopening; size_t savedinteresting = FirstInterestingDrawseg; double savedvisibility = R_GetVisibility(); AActor *savedcamera = camera; @@ -1520,8 +1511,6 @@ void R_DrawPortals () InterestingDrawsegs.Resize ((unsigned int)FirstInterestingDrawseg); FirstInterestingDrawseg = savedinteresting; - lastopening = savedlastopening; - camera = savedcamera; viewsector = savedsector; ViewPos = savedpos; diff --git a/src/swrenderer/scene/r_plane.h b/src/swrenderer/scene/r_plane.h index e8fe7882cf..39bf56b5cc 100644 --- a/src/swrenderer/scene/r_plane.h +++ b/src/swrenderer/scene/r_plane.h @@ -80,10 +80,6 @@ typedef struct visplane_s visplane_t; -// Visplane related. -extern ptrdiff_t lastopening; // type short - - typedef void (*planefunction_t) (int top, int bottom); extern planefunction_t floorfunc; diff --git a/src/swrenderer/scene/r_segs.cpp b/src/swrenderer/scene/r_segs.cpp index e8439ab140..079700d880 100644 --- a/src/swrenderer/scene/r_segs.cpp +++ b/src/swrenderer/scene/r_segs.cpp @@ -51,6 +51,7 @@ #include "r_walldraw.h" #include "r_draw_segment.h" #include "r_portal_segment.h" +#include "swrenderer\r_memory.h" #define WALLYREPEAT 8 diff --git a/src/swrenderer/scene/r_segs.h b/src/swrenderer/scene/r_segs.h index a4aa36b652..8aafa6ccee 100644 --- a/src/swrenderer/scene/r_segs.h +++ b/src/swrenderer/scene/r_segs.h @@ -31,10 +31,6 @@ struct drawseg_t; bool R_StoreWallRange(int start, int stop); void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2); -extern short *openings; -extern ptrdiff_t lastopening; -extern size_t maxopenings; - int R_CreateWallSegmentY (short *outbuf, double z1, double z2, const FWallCoords *wallc); int R_CreateWallSegmentYSloped (short *outbuf, const secplane_t &plane, const FWallCoords *wallc); inline int R_CreateWallSegmentY(short *outbuf, double z, const FWallCoords *wallc) diff --git a/src/swrenderer/scene/r_things.cpp b/src/swrenderer/scene/r_things.cpp index f53d0531a6..3a6e7dff16 100644 --- a/src/swrenderer/scene/r_things.cpp +++ b/src/swrenderer/scene/r_things.cpp @@ -70,6 +70,7 @@ #include "r_voxel.h" #include "r_draw_segment.h" #include "r_portal_segment.h" +#include "swrenderer\r_memory.h" EXTERN_CVAR(Bool, st_scale) EXTERN_CVAR(Bool, r_shadercolormaps)