Move openings to r_memory

This commit is contained in:
Magnus Norddahl 2016-12-30 05:35:25 +01:00
parent 74e1955afa
commit 60c0dcc3c7
10 changed files with 67 additions and 38 deletions

View file

@ -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

View file

@ -0,0 +1,52 @@
#include <stdlib.h>
#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;
}
}

10
src/swrenderer/r_memory.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
namespace swrenderer
{
extern short *openings;
ptrdiff_t R_NewOpening(ptrdiff_t len);
void R_FreeOpenings();
}

View file

@ -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;
}
}

View file

@ -43,5 +43,4 @@ namespace swrenderer
void R_FreeDrawSegs();
drawseg_t *R_AddDrawSegment();
ptrdiff_t R_NewOpening(ptrdiff_t len);
}

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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)

View file

@ -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)