Move openings to r_memory

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

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