add auto reallocate

This commit is contained in:
Denis Pauk 2018-07-24 17:49:14 +03:00
parent 25cb7acda8
commit e1a9e7e4e2
3 changed files with 32 additions and 21 deletions

View file

@ -173,7 +173,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -fwrapv
CFLAGS += $(OSX_ARCH)
else
CFLAGS := -std=gnu99 -fno-strict-aliasing \
CFLAGS := -std=gnu99 -O2 -fno-strict-aliasing \
-Wall -pipe -g -ggdb -MMD -fwrapv
endif

View file

@ -158,10 +158,6 @@ extern oldrefdef_t r_refdef;
#define DS_SPAN_LIST_END -128
#define NUMSTACKEDGES 3072
#define NUMSTACKSURFACES 2048
#define MAXALIASVERTS 2048 // TODO: tune this
// flags in finalvert_t.flags
#define ALIAS_LEFT_CLIP 0x0001
#define ALIAS_TOP_CLIP 0x0002
@ -569,7 +565,6 @@ extern void *colormap;
//====================================================================
void R_NewMap (void);
void R_ReallocateMapBuffers (void);
void Draw_InitLocal(void);
void R_InitCaches(void);
void D_FlushCaches(void);

View file

@ -31,6 +31,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "header/local.h"
#define NUMSTACKEDGES 2048
#define NUMSTACKSURFACES 1024
#define MAXALIASVERTS 2048
viddef_t vid;
pixel_t *vid_buffer = NULL;
espan_t *vid_polygon_spans = NULL;
@ -403,24 +407,30 @@ void R_NewMap (void)
r_viewcluster = -1;
}
surf_t *lsurfs;
static surf_t *lsurfs;
/*
===============
R_ReallocateMapBuffers
===============
*/
void
static void
R_ReallocateMapBuffers (void)
{
if (!r_cnumsurfs)
if (!r_cnumsurfs || r_outofsurfaces)
{
if(lsurfs)
{
free(lsurfs);
}
if (r_outofsurfaces)
{
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n",
__func__, r_cnumsurfs, r_outofsurfaces);
r_cnumsurfs *= 2;
}
if (r_cnumsurfs < NUMSTACKSURFACES)
r_cnumsurfs = NUMSTACKSURFACES;
@ -446,13 +456,20 @@ R_ReallocateMapBuffers (void)
}
if (!r_numallocatededges)
if (!r_numallocatededges || r_outofedges)
{
if (!r_edges)
{
free(r_edges);
}
if (r_outofedges)
{
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n",
__func__, r_numallocatededges, r_outofedges * 2 / 3);
r_numallocatededges *= 2;
}
if (r_numallocatededges < NUMSTACKEDGES)
r_numallocatededges = NUMSTACKEDGES;
@ -471,13 +488,20 @@ R_ReallocateMapBuffers (void)
__func__, r_numallocatededges);
}
if (!r_numallocatedverts)
if (!r_numallocatedverts || r_outofverts)
{
if (finalverts)
{
free(finalverts);
}
if (r_outofverts)
{
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n",
__func__, r_numallocatedverts, r_outofverts);
r_numallocatedverts *= 2;
}
if (r_numallocatedverts < MAXALIASVERTS)
r_numallocatedverts = MAXALIASVERTS;
@ -1118,19 +1142,11 @@ RE_RenderFrame (refdef_t *fd)
if (sw_reportsurfout->value && r_outofsurfaces)
R_Printf(PRINT_ALL,"Short %d surfaces\n", r_outofsurfaces);
else if (r_outofsurfaces)
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) surfaces\n",
__func__, r_cnumsurfs, r_outofsurfaces);
if (sw_reportedgeout->value && r_outofedges)
R_Printf(PRINT_ALL,"Short roughly %d edges\n", r_outofedges * 2 / 3);
else if (r_outofedges)
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) edges\n",
__func__, r_numallocatededges, r_outofedges * 2 / 3);
if (r_outofverts)
R_Printf(PRINT_ALL, "%s: not enough %d(+%d) finalverts\n",
__func__, r_numallocatedverts, r_outofverts);
R_ReallocateMapBuffers();
}
/*