mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-22 11:22:18 -04:00
more efficient use of zone memory features (#1888)
* use PU_RENDERER for allocation of renderer buffers * add Z_StrDup function
This commit is contained in:
parent
be5f634318
commit
7a50a0317e
@ -1835,6 +1835,7 @@ static void CreateSurfaces(int w, int h)
|
||||
|
||||
SDL_SetTextureScaleMode(texture, SDL_ScaleModeNearest);
|
||||
|
||||
Z_FreeTag(PU_RENDERER);
|
||||
R_InitAnyRes();
|
||||
ST_InitRes();
|
||||
|
||||
|
20
src/r_draw.c
20
src/r_draw.c
@ -763,23 +763,9 @@ void R_ShadeScreen(boolean toggle)
|
||||
|
||||
void R_InitBufferRes(void)
|
||||
{
|
||||
if (solidcol)
|
||||
{
|
||||
Z_Free(solidcol);
|
||||
}
|
||||
if (columnofs)
|
||||
{
|
||||
Z_Free(columnofs);
|
||||
}
|
||||
if (ylookup)
|
||||
{
|
||||
Z_Free(ylookup);
|
||||
}
|
||||
|
||||
columnofs = Z_Malloc(video.width * sizeof(*columnofs), PU_STATIC, NULL);
|
||||
ylookup = Z_Malloc(video.height * sizeof(*ylookup), PU_STATIC, NULL);
|
||||
|
||||
solidcol = Z_Calloc(1, video.width * sizeof(*solidcol), PU_STATIC, NULL);
|
||||
columnofs = Z_Malloc(video.width * sizeof(*columnofs), PU_RENDERER, NULL);
|
||||
ylookup = Z_Malloc(video.height * sizeof(*ylookup), PU_RENDERER, NULL);
|
||||
solidcol = Z_Calloc(1, video.width * sizeof(*solidcol), PU_RENDERER, NULL);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -113,33 +113,19 @@ void R_InitPlanes (void)
|
||||
|
||||
void R_InitPlanesRes(void)
|
||||
{
|
||||
if (floorclip) Z_Free(floorclip);
|
||||
if (ceilingclip) Z_Free(ceilingclip);
|
||||
if (spanstart) Z_Free(spanstart);
|
||||
floorclip = Z_Calloc(1, video.width * sizeof(*floorclip), PU_RENDERER, NULL);
|
||||
ceilingclip = Z_Calloc(1, video.width * sizeof(*ceilingclip), PU_RENDERER, NULL);
|
||||
spanstart = Z_Calloc(1, video.height * sizeof(*spanstart), PU_RENDERER, NULL);
|
||||
|
||||
if (cachedheight) Z_Free(cachedheight);
|
||||
if (cacheddistance) Z_Free(cacheddistance);
|
||||
if (cachedxstep) Z_Free(cachedxstep);
|
||||
if (cachedystep) Z_Free(cachedystep);
|
||||
cachedheight = Z_Calloc(1, video.height * sizeof(*cachedheight), PU_RENDERER, NULL);
|
||||
cacheddistance = Z_Calloc(1, video.height * sizeof(*cacheddistance), PU_RENDERER, NULL);
|
||||
cachedxstep = Z_Calloc(1, video.height * sizeof(*cachedxstep), PU_RENDERER, NULL);
|
||||
cachedystep = Z_Calloc(1, video.height * sizeof(*cachedystep), PU_RENDERER, NULL);
|
||||
|
||||
if (yslope) Z_Free(yslope);
|
||||
if (distscale) Z_Free(distscale);
|
||||
yslope = Z_Calloc(1, video.height * sizeof(*yslope), PU_RENDERER, NULL);
|
||||
distscale = Z_Calloc(1, video.width * sizeof(*distscale), PU_RENDERER, NULL);
|
||||
|
||||
if (openings) Z_Free(openings);
|
||||
|
||||
floorclip = Z_Calloc(1, video.width * sizeof(*floorclip), PU_STATIC, NULL);
|
||||
ceilingclip = Z_Calloc(1, video.width * sizeof(*ceilingclip), PU_STATIC, NULL);
|
||||
spanstart = Z_Calloc(1, video.height * sizeof(*spanstart), PU_STATIC, NULL);
|
||||
|
||||
cachedheight = Z_Calloc(1, video.height * sizeof(*cachedheight), PU_STATIC, NULL);
|
||||
cacheddistance = Z_Calloc(1, video.height * sizeof(*cacheddistance), PU_STATIC, NULL);
|
||||
cachedxstep = Z_Calloc(1, video.height * sizeof(*cachedxstep), PU_STATIC, NULL);
|
||||
cachedystep = Z_Calloc(1, video.height * sizeof(*cachedystep), PU_STATIC, NULL);
|
||||
|
||||
yslope = Z_Calloc(1, video.height * sizeof(*yslope), PU_STATIC, NULL);
|
||||
distscale = Z_Calloc(1, video.width * sizeof(*distscale), PU_STATIC, NULL);
|
||||
|
||||
openings = Z_Calloc(1, video.width * video.height * sizeof(*openings), PU_STATIC, NULL);
|
||||
openings = Z_Calloc(1, video.width * video.height * sizeof(*openings), PU_RENDERER, NULL);
|
||||
|
||||
xtoskyangle = linearsky ? linearskyangle : xtoviewangle;
|
||||
}
|
||||
|
@ -119,19 +119,12 @@ static int maxframe;
|
||||
|
||||
void R_InitSpritesRes(void)
|
||||
{
|
||||
if (xtoviewangle) Z_Free(xtoviewangle);
|
||||
if (linearskyangle) Z_Free(linearskyangle);
|
||||
if (negonearray) Z_Free(negonearray);
|
||||
if (screenheightarray) Z_Free(screenheightarray);
|
||||
xtoviewangle = Z_Calloc(1, (video.width + 1) * sizeof(*xtoviewangle), PU_RENDERER, NULL);
|
||||
linearskyangle = Z_Calloc(1, (video.width + 1) * sizeof(*linearskyangle), PU_RENDERER, NULL);
|
||||
negonearray = Z_Calloc(1, video.width * sizeof(*negonearray), PU_RENDERER, NULL);
|
||||
screenheightarray = Z_Calloc(1, video.width * sizeof(*screenheightarray), PU_RENDERER, NULL);
|
||||
|
||||
xtoviewangle = Z_Calloc(1, (video.width + 1) * sizeof(*xtoviewangle), PU_STATIC, NULL);
|
||||
linearskyangle = Z_Calloc(1, (video.width + 1) * sizeof(*linearskyangle), PU_STATIC, NULL);
|
||||
negonearray = Z_Calloc(1, video.width * sizeof(*negonearray), PU_STATIC, NULL);
|
||||
screenheightarray = Z_Calloc(1, video.width * sizeof(*screenheightarray), PU_STATIC, NULL);
|
||||
|
||||
if (clipbot) Z_Free(clipbot);
|
||||
|
||||
clipbot = Z_Calloc(1, 2 * video.width * sizeof(*clipbot), PU_STATIC, NULL);
|
||||
clipbot = Z_Calloc(1, 2 * video.width * sizeof(*clipbot), PU_RENDERER, NULL);
|
||||
cliptop = clipbot + video.width;
|
||||
}
|
||||
|
||||
|
@ -1427,13 +1427,8 @@ void ST_InitRes(void)
|
||||
{
|
||||
int height = V_ScaleY(StatusBarBufferHeight());
|
||||
|
||||
if (st_backing_screen)
|
||||
{
|
||||
Z_Free(st_backing_screen);
|
||||
}
|
||||
|
||||
// killough 11/98: allocate enough for hires
|
||||
st_backing_screen = Z_Malloc(video.pitch * height * sizeof(*st_backing_screen), PU_STATIC, 0);
|
||||
st_backing_screen = Z_Malloc(video.pitch * height * sizeof(*st_backing_screen), PU_RENDERER, 0);
|
||||
}
|
||||
|
||||
void ST_Warnings(void)
|
||||
|
@ -13,9 +13,6 @@
|
||||
|
||||
#include "wi_interlvl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "i_printf.h"
|
||||
#include "w_wad.h"
|
||||
@ -28,11 +25,6 @@
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
static char *WI_StringDuplicate(const char *orig)
|
||||
{
|
||||
return strcpy(Z_Malloc(strlen(orig) + 1, PU_LEVEL, NULL), orig);
|
||||
}
|
||||
|
||||
static boolean ParseCondition(cJSON *json, interlevelcond_t *out)
|
||||
{
|
||||
cJSON *condition = cJSON_GetObjectItemCaseSensitive(json, "condition");
|
||||
@ -59,7 +51,7 @@ static boolean ParseFrame(cJSON *json, interlevelframe_t *out)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
out->image_lump = WI_StringDuplicate(image_lump->valuestring);
|
||||
out->image_lump = Z_StrDup(image_lump->valuestring, PU_LEVEL);
|
||||
|
||||
cJSON *type = cJSON_GetObjectItemCaseSensitive(json, "type");
|
||||
if (!cJSON_IsNumber(type))
|
||||
@ -160,20 +152,14 @@ static void ParseLevelLayer(cJSON *json, interlevellayer_t *out)
|
||||
|
||||
interlevel_t *WI_ParseInterlevel(const char *lumpname)
|
||||
{
|
||||
interlevel_t *out = Z_Calloc(1, sizeof(*out), PU_LEVEL, NULL);
|
||||
|
||||
cJSON *json = cJSON_Parse(W_CacheLumpName(lumpname, PU_CACHE));
|
||||
if (json == NULL)
|
||||
{
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL)
|
||||
{
|
||||
char error_buf[32] = {0};
|
||||
memcpy(error_buf, error_ptr, sizeof(error_buf) - 1);
|
||||
I_Printf(VB_ERROR, "WI_ParseInterlevel: Error before: %s\n",
|
||||
error_buf);
|
||||
I_Printf(VB_ERROR, "Error parsing %s", lumpname);
|
||||
}
|
||||
free(out);
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
@ -181,7 +167,6 @@ interlevel_t *WI_ParseInterlevel(const char *lumpname)
|
||||
cJSON *data = cJSON_GetObjectItemCaseSensitive(json, "data");
|
||||
if (!cJSON_IsObject(data))
|
||||
{
|
||||
free(out);
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
@ -192,13 +177,14 @@ interlevel_t *WI_ParseInterlevel(const char *lumpname)
|
||||
|
||||
if (!cJSON_IsString(music) || !cJSON_IsString(backgroundimage))
|
||||
{
|
||||
free(out);
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->music_lump = WI_StringDuplicate(music->valuestring);
|
||||
out->background_lump = WI_StringDuplicate(backgroundimage->valuestring);
|
||||
interlevel_t *out = Z_Calloc(1, sizeof(*out), PU_LEVEL, NULL);
|
||||
|
||||
out->music_lump = Z_StrDup(music->valuestring, PU_LEVEL);
|
||||
out->background_lump = Z_StrDup(backgroundimage->valuestring, PU_LEVEL);
|
||||
|
||||
cJSON *js_layers = cJSON_GetObjectItemCaseSensitive(data, "layers");
|
||||
cJSON *js_layer = NULL;
|
||||
|
11
src/z_zone.c
11
src/z_zone.c
@ -202,6 +202,17 @@ void *Z_Calloc(size_t n1, size_t n2, pu_tag tag, void **user)
|
||||
(n1*=n2) ? memset(Z_Malloc(n1, tag, user), 0, n1) : NULL;
|
||||
}
|
||||
|
||||
char *Z_StrDup(const char *orig, pu_tag tag)
|
||||
{
|
||||
size_t size = strlen(orig) + 1;
|
||||
|
||||
char *result = Z_Malloc(size, tag, NULL);
|
||||
|
||||
memcpy(result, orig, size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Log: z_zone.c,v $
|
||||
|
@ -33,6 +33,7 @@
|
||||
typedef enum {
|
||||
PU_STATIC,
|
||||
PU_LEVEL,
|
||||
PU_RENDERER,
|
||||
PU_VALLOC,
|
||||
PU_CACHE,
|
||||
/* Must always be last -- killough */
|
||||
@ -48,6 +49,8 @@ void Z_ChangeTag(void *ptr, pu_tag tag);
|
||||
void *Z_Calloc(size_t n, size_t n2, pu_tag tag, void **user);
|
||||
void *Z_Realloc(void *p, size_t n, pu_tag tag, void **user);
|
||||
|
||||
char *Z_StrDup(const char *orig, pu_tag tag);
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user