DOOM: Fixed/Improved pre-caching to reduce stuttering
This commit is contained in:
parent
94bf5700b9
commit
0a739e0d9d
@ -87,7 +87,7 @@ CONFIG_SPIRAM_MEMTEST=n
|
||||
CONFIG_SPIRAM_CACHE_WORKAROUND=n
|
||||
CONFIG_SPIRAM_BANKSWITCH_ENABLE=n
|
||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=32768
|
||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=4096
|
||||
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192
|
||||
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=n
|
||||
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
|
||||
CONFIG_SPIRAM_OCCUPY_HSPI_HOST=n
|
||||
|
||||
@ -606,7 +606,7 @@ void rg_display_reset_config(void)
|
||||
// TO DO: We probably should call the setters to ensure valid values...
|
||||
.screen.width = RG_SCREEN_WIDTH - RG_SCREEN_MARGIN_LEFT - RG_SCREEN_MARGIN_RIGHT,
|
||||
.screen.height = RG_SCREEN_HEIGHT - RG_SCREEN_MARGIN_TOP - RG_SCREEN_MARGIN_BOTTOM,
|
||||
.config.backlight = RG_MIN(RG_MAX(rg_settings_get_int32(SETTING_BACKLIGHT, 40), 0), 100),
|
||||
.config.backlight = RG_MIN(RG_MAX(rg_settings_get_int32(SETTING_BACKLIGHT, 80), 0), 100),
|
||||
.config.scaling = rg_settings_get_app_int32(SETTING_SCALING, RG_DISPLAY_SCALING_FILL),
|
||||
.config.filter = rg_settings_get_app_int32(SETTING_FILTER, RG_DISPLAY_FILTER_HORIZ),
|
||||
.config.rotation = rg_settings_get_app_int32(SETTING_ROTATION, RG_DISPLAY_ROTATION_AUTO),
|
||||
|
||||
@ -710,7 +710,7 @@ static dialog_return_t brightness_update_cb(dialog_option_t *option, dialog_even
|
||||
if (event == RG_DIALOG_PREV) level -= 10;
|
||||
if (event == RG_DIALOG_NEXT) level += 10;
|
||||
|
||||
level = RG_MIN(RG_MAX(level, 10), 100);
|
||||
level = RG_MIN(RG_MAX(level & ~1, 1), 100);
|
||||
|
||||
if (level != old_level)
|
||||
rg_display_set_backlight(level);
|
||||
|
||||
@ -519,7 +519,7 @@ void D_StartTitle (void)
|
||||
//
|
||||
// Add files to be loaded later by W_Init()
|
||||
//
|
||||
boolean D_AddFile(const char *file, wad_source_t source)
|
||||
bool D_AddFile(const char *file)
|
||||
{
|
||||
char relpath[PATH_MAX + 1];
|
||||
|
||||
@ -691,11 +691,11 @@ static void D_DoomMainSetup(void)
|
||||
|
||||
// Try loading iwad specified as parameter
|
||||
if ((p = M_CheckParm("-iwad")) && (++p < myargc))
|
||||
D_AddFile(myargv[p], source_iwad);
|
||||
D_AddFile(myargv[p]);
|
||||
|
||||
// If that fails then try known standard iwad names
|
||||
for (int i = 0; !numwadfiles && standard_iwads[i]; i++)
|
||||
D_AddFile(standard_iwads[i], source_iwad);
|
||||
D_AddFile(standard_iwads[i]);
|
||||
|
||||
if (!numwadfiles)
|
||||
I_Error("IWAD not found\n");
|
||||
@ -745,6 +745,20 @@ static void D_DoomMainSetup(void)
|
||||
"It comes with ABSOLUTELY NO WARRANTY. See the file COPYING for details.\n",
|
||||
PACKAGE, VERSION, version_date, doomverstr);
|
||||
|
||||
// Add prboom.wad at the very beginning so it can be overriden by mods
|
||||
#ifdef PRBOOMWAD
|
||||
#include "prboom_wad.h"
|
||||
wadfiles[numwadfiles++] = (wadfile_info_t){
|
||||
.name = "prboom.wad",
|
||||
.data = prboom_wad,
|
||||
.size = prboom_wad_size,
|
||||
.handle = NULL,
|
||||
};
|
||||
#else
|
||||
if (!D_AddFile("prboom.wad"))
|
||||
I_Error("PRBOOM.WAD not found\n");
|
||||
#endif
|
||||
|
||||
if ((devparm = M_CheckParm("-devparm")))
|
||||
lprintf(LO_CONFIRM, "%s", s_D_DEVSTR);
|
||||
|
||||
@ -901,7 +915,7 @@ static void D_DoomMainSetup(void)
|
||||
// the parms after p are wadfile/lump names,
|
||||
// until end of parms or another - preceded parm
|
||||
while (++p != myargc && *myargv[p] != '-')
|
||||
if (D_AddFile(myargv[p], source_pwad))
|
||||
if (D_AddFile(myargv[p]))
|
||||
modifiedgame = true;
|
||||
}
|
||||
|
||||
@ -917,32 +931,14 @@ static void D_DoomMainSetup(void)
|
||||
char file[PATH_MAX+1]; // cph - localised
|
||||
strcpy(file,myargv[p+1]);
|
||||
AddDefaultExtension(file,".lmp"); // killough
|
||||
D_AddFile (file,source_lmp);
|
||||
D_AddFile (file);
|
||||
//jff 9/3/98 use logical output routine
|
||||
lprintf(LO_CONFIRM,"Playing demo %s\n",file);
|
||||
if ((p = M_CheckParm ("-ffmap")) && p < myargc-1) {
|
||||
ffmap = atoi(myargv[p+1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add prboom.wad at the very end
|
||||
if (!D_AddFile("prboom.wad", source_auto_load))
|
||||
{
|
||||
#ifdef PRBOOMWAD
|
||||
lprintf(LO_WARN, "PRBOOM.WAD not found. Using bundled version.\n");
|
||||
#include "prboom_wad.h"
|
||||
wadfiles[numwadfiles++] = (wadfile_info_t){
|
||||
.name = "prboom.wad",
|
||||
.data = prboom_wad,
|
||||
.size = prboom_wad_size,
|
||||
.handle = NULL,
|
||||
};
|
||||
#else
|
||||
I_Error("PRBOOM.WAD not found\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
// internal translucency set to config file value // phares
|
||||
general_translucency = default_translucency; // phares
|
||||
|
||||
|
||||
@ -69,6 +69,6 @@ void D_Display(void);
|
||||
void D_PageTicker(void);
|
||||
void D_StartTitle(void);
|
||||
void D_DoomMain(void);
|
||||
boolean D_AddFile(const char *file, wad_source_t source);
|
||||
bool D_AddFile(const char *file);
|
||||
|
||||
#endif
|
||||
|
||||
@ -178,7 +178,7 @@ default_t defaults[] =
|
||||
def_int,ss_none}, // 1=take special steps ensuring demo sync, 2=only during recordings
|
||||
// {"endoom_mode", {&endoom_mode},{5},0,7, // CPhipps - endoom flags
|
||||
// def_hex, ss_none}, // 0, +1 for colours, +2 for non-ascii chars, +4 for skip-last-line
|
||||
{"level_precache",{(int*)&precache},{0},0,1,
|
||||
{"level_precache",{(int*)&precache},{1},0,1,
|
||||
def_bool,ss_none}, // precache level data?
|
||||
{"demo_smoothturns", {&demo_smoothturns}, {0},0,1,
|
||||
def_bool,ss_stat},
|
||||
|
||||
@ -456,20 +456,19 @@ void R_InitTranMap(int progress)
|
||||
// If a tranlucency filter map lump is present, use it
|
||||
if ((lump = W_CheckNumForName("TRANMAP")) != -1)
|
||||
{
|
||||
lprintf(LO_INFO, "R_InitTranMap: TRANMAP lump: %d\n", lump);
|
||||
lprintf(LO_INFO, "R_InitTranMap: Using TRANMAP(%d) directly\n", lump);
|
||||
main_tranmap = W_CacheLumpNum(lump);
|
||||
}
|
||||
// Compose a default transparent filter map based on PLAYPAL.
|
||||
else if ((lump = W_CheckNumForName("PLAYPAL")) != -1)
|
||||
{
|
||||
lprintf(LO_INFO, "R_InitTranMap: PLAYPAL lump: %d\n", lump);
|
||||
if (progress)
|
||||
lprintf(LO_INFO, "Tranmap build [ ]\x08\x08\x08\x08\x08\x08\x08\x08\x08");
|
||||
lprintf(LO_INFO, "R_InitTranMap: Gen from PLAYPAL(%d) [ ]"
|
||||
"\x08\x08\x08\x08\x08\x08\x08\x08\x08", lump);
|
||||
|
||||
const struct PACKEDATTR {byte r, g, b;} *pal = W_CacheLumpNum(lump);
|
||||
byte *my_tranmap = Z_Malloc(256*256, PU_STATIC, 0);
|
||||
int w1 = ((unsigned)tran_filter_pct<<TSC)/100;
|
||||
int w2 = (1l<<TSC)-w1;
|
||||
int w1 = (tran_filter_pct << TSC) / 100;
|
||||
int w2 = (1 << TSC) - w1;
|
||||
int total[256];
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
@ -491,24 +490,27 @@ void R_InitTranMap(int progress)
|
||||
if (!(i & 31) && progress)
|
||||
lprintf(LO_INFO,".");
|
||||
|
||||
for (int j = 0; j < 256; j++, tp++)
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
int r = r1 + (pal[j].r * w1);
|
||||
int g = g1 + (pal[j].g * w1);
|
||||
int b = b1 + (pal[j].b * w1);
|
||||
int best = INT_MAX;
|
||||
int bc = 0, best = INT_MAX;
|
||||
for (int color = 255; color >= 0; --color)
|
||||
{
|
||||
int err = total[color] - pal[color].r*r - pal[color].g*g - pal[color].b*b;
|
||||
if (err < best)
|
||||
best = err, *tp = color;
|
||||
best = err, bc = color;
|
||||
}
|
||||
*tp++ = bc;
|
||||
}
|
||||
}
|
||||
|
||||
main_tranmap = my_tranmap;
|
||||
|
||||
W_UnlockLumpName("PLAYPAL");
|
||||
|
||||
lprintf(LO_INFO, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,79 +617,85 @@ static inline void precache_lump(int l)
|
||||
|
||||
void R_PrecacheLevel(void)
|
||||
{
|
||||
register int i;
|
||||
register byte *hitlist;
|
||||
|
||||
if (demoplayback)
|
||||
return;
|
||||
|
||||
{
|
||||
size_t size = numflats > numsprites ? numflats : numsprites;
|
||||
hitlist = malloc((size_t)numtextures > size ? numtextures : size);
|
||||
}
|
||||
size_t maxitems = MAX(numtextures, MAX(numflats, numsprites));
|
||||
byte hitlist[maxitems];
|
||||
size_t count = 0;
|
||||
|
||||
// Precache flats.
|
||||
memset(hitlist, 0, maxitems);
|
||||
count = 0;
|
||||
|
||||
memset(hitlist, 0, numflats);
|
||||
for (int i = numsectors; --i >= 0; )
|
||||
{
|
||||
hitlist[sectors[i].floorpic] = 1;
|
||||
hitlist[sectors[i].ceilingpic] = 1;
|
||||
}
|
||||
|
||||
for (i = numsectors; --i >= 0; )
|
||||
hitlist[sectors[i].floorpic] = hitlist[sectors[i].ceilingpic] = 1;
|
||||
|
||||
for (i = numflats; --i >= 0; )
|
||||
for (int i = numflats; --i >= 0; )
|
||||
{
|
||||
if (hitlist[i])
|
||||
{
|
||||
precache_lump(firstflat + i);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
lprintf(LO_INFO, "R_PrecacheLevel: pre-cached %d flats\n", count);
|
||||
|
||||
|
||||
// Precache textures.
|
||||
memset(hitlist, 0, maxitems);
|
||||
count = 0;
|
||||
|
||||
memset(hitlist, 0, numtextures);
|
||||
|
||||
for (i = numsides; --i >= 0;)
|
||||
hitlist[sides[i].bottomtexture] =
|
||||
hitlist[sides[i].toptexture] =
|
||||
hitlist[sides[i].midtexture] = 1;
|
||||
|
||||
// Sky texture is always present.
|
||||
// Note that F_SKY1 is the name used to
|
||||
// indicate a sky floor/ceiling as a flat,
|
||||
// while the sky texture is stored like
|
||||
// a wall texture, with an episode dependend
|
||||
// name.
|
||||
|
||||
for (int i = numsides; --i >= 0; )
|
||||
{
|
||||
hitlist[sides[i].bottomtexture] = 1;
|
||||
hitlist[sides[i].toptexture] = 1;
|
||||
hitlist[sides[i].midtexture] = 1;
|
||||
}
|
||||
hitlist[skytexture] = 1;
|
||||
|
||||
for (i = numtextures; --i >= 0; )
|
||||
for (int i = numtextures; --i >= 0; )
|
||||
if (hitlist[i])
|
||||
{
|
||||
texture_t *texture = textures[i];
|
||||
int j = texture->patchcount;
|
||||
while (--j >= 0)
|
||||
for (int j = texture->patchcount; --j >= 0; )
|
||||
{
|
||||
precache_lump(texture->patches[j].patch);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
lprintf(LO_INFO, "R_PrecacheLevel: pre-cached %d textures\n", count);
|
||||
|
||||
|
||||
// Precache sprites.
|
||||
memset(hitlist, 0, numsprites);
|
||||
memset(hitlist, 0, maxitems);
|
||||
count = 0;
|
||||
|
||||
{
|
||||
thinker_t *th = NULL;
|
||||
while ((th = P_NextThinker(th,th_all)) != NULL)
|
||||
if (th->function == P_MobjThinker)
|
||||
hitlist[((mobj_t *)th)->sprite] = 1;
|
||||
}
|
||||
thinker_t *th = NULL;
|
||||
while ((th = P_NextThinker(th,th_all)))
|
||||
if (th->function == P_MobjThinker)
|
||||
hitlist[((mobj_t *)th)->sprite] = 1;
|
||||
|
||||
for (i=numsprites; --i >= 0;)
|
||||
for (int i = numsprites; --i >= 0; )
|
||||
if (hitlist[i])
|
||||
{
|
||||
int j = sprites[i].numframes;
|
||||
while (--j >= 0)
|
||||
for (int j = sprites[i].numframes; --j >= 0; )
|
||||
{
|
||||
short *sflump = sprites[i].spriteframes[j].lump;
|
||||
int k = 7;
|
||||
do
|
||||
for (int k = 7; --k >= 0; )
|
||||
{
|
||||
precache_lump(firstspritelump + sflump[k]);
|
||||
while (--k >= 0);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(hitlist);
|
||||
|
||||
lprintf(LO_INFO, "R_PrecacheLevel: pre-cached %d sprites\n", count);
|
||||
}
|
||||
|
||||
// Proff - Added for OpenGL
|
||||
|
||||
@ -490,22 +490,25 @@ static int currentPaletteIndex = 0;
|
||||
// V_UpdateTrueColorPalette
|
||||
//
|
||||
void V_UpdateTrueColorPalette(video_mode_t mode) {
|
||||
static int usegammaOnLastPaletteGeneration = -1;
|
||||
int i, w, p;
|
||||
byte r,g,b;
|
||||
int nr,ng,nb;
|
||||
float t;
|
||||
int paletteNum = currentPaletteIndex;
|
||||
static int usegammaOnLastPaletteGeneration = -1;
|
||||
|
||||
int pplump = W_GetNumForName("PLAYPAL");
|
||||
int gtlump = W_CheckNumForNameNs("GAMMATBL",ns_prboom);
|
||||
const byte *pal = W_CacheLumpNum(pplump);
|
||||
const byte *gtable = W_CacheLumpNum(gtlump) + 256*(usegamma);
|
||||
|
||||
int numPals = W_LumpLength(pplump) / (3*256);
|
||||
const float dontRoundAbove = 220;
|
||||
float roundUpR, roundUpG, roundUpB;
|
||||
|
||||
byte gtable[256];
|
||||
|
||||
// Note: this isn't right but I haven't reverse engineered how GAMMATBL
|
||||
// was generated yet and we don't even use truecolors for now...
|
||||
for (i = 0; i < 256; i++)
|
||||
gtable[i] = i << usegamma;
|
||||
|
||||
if (usegammaOnLastPaletteGeneration != usegamma) {
|
||||
if (Palettes15) free(Palettes15);
|
||||
if (Palettes16) free(Palettes16);
|
||||
@ -608,7 +611,6 @@ void V_UpdateTrueColorPalette(video_mode_t mode) {
|
||||
}
|
||||
|
||||
W_UnlockLumpNum(pplump);
|
||||
W_UnlockLumpNum(gtlump);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,134 +0,0 @@
|
||||
/* Emacs style mode select -*- C++ -*-
|
||||
*-----------------------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
|
||||
* based on BOOM, a modified and improved DOOM engine
|
||||
* Copyright (C) 2001 by
|
||||
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
|
||||
* Copyright 2005, 2006 by
|
||||
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* Transparent access to data in WADs using mmap or caching
|
||||
*
|
||||
*-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "doomstat.h"
|
||||
#include "doomtype.h"
|
||||
#include "w_wad.h"
|
||||
#include "z_zone.h"
|
||||
#include "lprintf.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *ptr;
|
||||
short lump;
|
||||
short locks;
|
||||
} segment_t;
|
||||
|
||||
#define MAX_CACHE_HANDLES 192
|
||||
static segment_t segments[MAX_CACHE_HANDLES];
|
||||
static int cursor = 0;
|
||||
|
||||
void W_InitCache(void)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
void W_DoneCache(void)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
const void *W_CacheLumpNum(int lump)
|
||||
{
|
||||
#ifdef RANGECHECK
|
||||
if ((unsigned)lump >= (unsigned)numlumps)
|
||||
I_Error("W_CacheLumpNum: %d >= numlumps(%d)", lump, numlumps);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < MAX_CACHE_HANDLES; i++)
|
||||
{
|
||||
if (segments[i].lump == lump && segments[i].ptr)
|
||||
{
|
||||
if (++segments[i].locks <= 1)
|
||||
{
|
||||
Z_ChangeTag(segments[i].ptr, PU_STATIC);
|
||||
segments[i].locks = 1;
|
||||
}
|
||||
return segments[i].ptr;
|
||||
}
|
||||
}
|
||||
|
||||
int n = MAX_CACHE_HANDLES;
|
||||
while (segments[cursor].locks > 0)
|
||||
{
|
||||
if (++cursor == MAX_CACHE_HANDLES)
|
||||
cursor = 0;
|
||||
if (--n == 0)
|
||||
I_Error("Out of cache handles!");
|
||||
}
|
||||
|
||||
int handle = cursor++;
|
||||
|
||||
if (cursor == MAX_CACHE_HANDLES)
|
||||
cursor = 0;
|
||||
|
||||
if (segments[handle].ptr)
|
||||
Z_Free(segments[handle].ptr);
|
||||
|
||||
W_ReadLump(Z_Malloc(W_LumpLength(lump), PU_STATIC, &segments[handle].ptr), lump);
|
||||
|
||||
segments[handle].lump = lump;
|
||||
segments[handle].locks = 1;
|
||||
|
||||
return segments[handle].ptr;
|
||||
}
|
||||
|
||||
void W_UnlockLumpNum(int lump)
|
||||
{
|
||||
#ifdef RANGECHECK
|
||||
if ((unsigned)lump >= (unsigned)numlumps)
|
||||
I_Error("W_UnlockLumpNum: %d >= numlumps(%d)", lump, numlumps);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < MAX_CACHE_HANDLES; i++)
|
||||
{
|
||||
if (segments[i].lump == lump && segments[i].ptr)
|
||||
{
|
||||
if (--segments[i].locks == 0)
|
||||
{
|
||||
Z_ChangeTag(segments[i].ptr, PU_CACHE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HEAPDUMP
|
||||
void W_PrintLump(FILE *fp, void *p)
|
||||
{
|
||||
//
|
||||
}
|
||||
#endif
|
||||
@ -173,6 +173,8 @@ static void W_AddFile(wadfile_info_t *wadfile)
|
||||
lump_p->position = LONG(fileinfo->filepos);
|
||||
lump_p->size = LONG(fileinfo->size);
|
||||
lump_p->li_namespace = ns_global; // killough 4/17/98
|
||||
lump_p->locks = 0;
|
||||
lump_p->ptr = NULL;
|
||||
memcpy(lump_p->name, fileinfo->name, 8);
|
||||
}
|
||||
|
||||
@ -342,7 +344,6 @@ void W_HashLumps(void)
|
||||
// End of lump hashing -- killough 1/31/98
|
||||
|
||||
|
||||
|
||||
// W_GetNumForName
|
||||
// Calls W_CheckNumForName, but bombs out if not found.
|
||||
//
|
||||
@ -355,7 +356,6 @@ int W_GetNumForName (const char* name) // killough -- const added
|
||||
}
|
||||
|
||||
|
||||
|
||||
// W_Init
|
||||
// Loads each of the files in the wadfiles array.
|
||||
// All files are optional, but at least one file
|
||||
@ -380,18 +380,11 @@ void W_Init(void)
|
||||
if (!numlumps)
|
||||
I_Error ("W_Init: No files found");
|
||||
|
||||
//jff 1/23/98
|
||||
// get all the sprites and flats into one marked block each
|
||||
// killough 1/24/98: change interface to use M_START/M_END explicitly
|
||||
// killough 4/17/98: Add namespace tags to each entry
|
||||
// killough 4/4/98: add colormap markers
|
||||
W_CoalesceMarkedResource("S_START", "S_END", ns_sprites);
|
||||
W_CoalesceMarkedResource("F_START", "F_END", ns_flats);
|
||||
W_CoalesceMarkedResource("C_START", "C_END", ns_colormaps);
|
||||
W_CoalesceMarkedResource("B_START", "B_END", ns_prboom);
|
||||
|
||||
W_HashLumps(); // killough 1/31/98: initialize lump hash table
|
||||
W_InitCache(); // cph 2001/07/07 - separated cache setup
|
||||
W_HashLumps();
|
||||
}
|
||||
|
||||
//
|
||||
@ -400,11 +393,11 @@ void W_Init(void)
|
||||
//
|
||||
int W_Read(void *dest, size_t size, size_t offset, wadfile_info_t *wad)
|
||||
{
|
||||
#ifdef RANGECHECK
|
||||
if (offset + size >= wad->size)
|
||||
I_Error("W_Read: %d+%d >= wad->size", offset, size);
|
||||
#endif
|
||||
if (wad->data)
|
||||
{
|
||||
lprintf(LO_WARN, "W_Read: %d+%d >= %d\n", offset, size, wad->size);
|
||||
}
|
||||
else if (wad->data)
|
||||
{
|
||||
memcpy(dest, wad->data + offset, size);
|
||||
return size;
|
||||
@ -424,10 +417,9 @@ int W_Read(void *dest, size_t size, size_t offset, wadfile_info_t *wad)
|
||||
//
|
||||
int W_LumpLength(int lump)
|
||||
{
|
||||
#ifdef RANGECHECK
|
||||
if ((unsigned)lump >= (unsigned)numlumps)
|
||||
I_Error ("W_LumpLength: %i >= numlumps",lump);
|
||||
#endif
|
||||
if ((unsigned)lump >= numlumps)
|
||||
I_Error("W_LumpLength: index out of bounds");
|
||||
|
||||
return lumpinfo[lump].size;
|
||||
}
|
||||
|
||||
@ -438,13 +430,53 @@ int W_LumpLength(int lump)
|
||||
//
|
||||
void W_ReadLump(void *dest, int lump)
|
||||
{
|
||||
#ifdef RANGECHECK
|
||||
if ((unsigned)lump >= (unsigned)numlumps)
|
||||
I_Error ("W_ReadLump: %i >= numlumps",lump);
|
||||
#endif
|
||||
if ((unsigned)lump >= numlumps)
|
||||
I_Error("W_ReadLump: index out of bounds");
|
||||
|
||||
lumpinfo_t *l = lumpinfo + lump;
|
||||
if (l->wadfile)
|
||||
{
|
||||
W_Read(dest, l->size, l->position, l->wadfile);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// W_CacheLumpNum
|
||||
//
|
||||
const void *W_CacheLumpNum(int lump)
|
||||
{
|
||||
if ((unsigned)lump >= numlumps)
|
||||
I_Error("W_CacheLumpNum: index out of bounds");
|
||||
|
||||
lumpinfo_t *l = &lumpinfo[lump];
|
||||
|
||||
if (!l->ptr)
|
||||
{
|
||||
// Bypass caching if we have the WAD mapped in memory
|
||||
if (l->wadfile && l->wadfile->data)
|
||||
return l->wadfile->data + l->position;
|
||||
W_ReadLump(Z_Malloc(W_LumpLength(lump), PU_STATIC, &l->ptr), lump);
|
||||
l->locks = 0;
|
||||
}
|
||||
|
||||
if (++l->locks == 1)
|
||||
{
|
||||
Z_ChangeTag(l->ptr, PU_STATIC);
|
||||
l->locks = 1;
|
||||
}
|
||||
|
||||
return l->ptr;
|
||||
}
|
||||
|
||||
//
|
||||
// W_UnlockLumpNum
|
||||
//
|
||||
void W_UnlockLumpNum(int lump)
|
||||
{
|
||||
if ((unsigned)lump >= numlumps)
|
||||
I_Error("W_UnlockLumpNum: index out of bounds");
|
||||
|
||||
lumpinfo_t *l = &lumpinfo[lump];
|
||||
if (l->ptr && l->locks && --l->locks == 0)
|
||||
Z_ChangeTag(l->ptr, PU_CACHE);
|
||||
}
|
||||
|
||||
@ -35,10 +35,6 @@
|
||||
#ifndef __W_WAD__
|
||||
#define __W_WAD__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
//
|
||||
// WADFILE I/O related stuff.
|
||||
//
|
||||
@ -57,16 +53,6 @@ typedef struct
|
||||
char name[8];
|
||||
} filelump_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
source_iwad=0, // iwad file load
|
||||
source_pre, // predefined lump
|
||||
source_auto_load, // lump auto-loaded by config file
|
||||
source_pwad, // pwad file load
|
||||
source_lmp, // lmp file load
|
||||
source_net // CPhipps
|
||||
} wad_source_t;
|
||||
|
||||
typedef enum {
|
||||
ns_global=0,
|
||||
ns_sprites,
|
||||
@ -86,11 +72,13 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
char name[8]; // lump name, uppercased
|
||||
short li_namespace; // lump namespace
|
||||
short li_namespace:5; // lump namespace
|
||||
short locks:11; // ptr locks
|
||||
short index, next; // Index in lumpinfo[]
|
||||
size_t size; // lump size
|
||||
size_t position; // position in wadfile
|
||||
wadfile_info_t *wadfile;// source file
|
||||
void *ptr; // data/cache pointer
|
||||
} lumpinfo_t;
|
||||
|
||||
#define MAX_WAD_FILES 8
|
||||
@ -100,30 +88,28 @@ extern size_t numwadfiles;
|
||||
extern lumpinfo_t *lumpinfo;
|
||||
extern size_t numlumps;
|
||||
|
||||
void W_Init(void); // CPhipps - uses the above array
|
||||
void W_InitCache(void);
|
||||
void W_DoneCache(void);
|
||||
|
||||
// killough 4/17/98: if W_CheckNumForName() called with only
|
||||
// one argument, pass ns_global as the default namespace
|
||||
|
||||
#define W_CheckNumForName(name) W_CheckNumForNameNs(name, ns_global)
|
||||
int W_CheckNumForNameNs(const char* name, int); // killough 4/17/98
|
||||
void W_Init(void);
|
||||
int W_CheckNumForNameNs(const char* name, int);
|
||||
int W_GetNumForName(const char* name);
|
||||
int W_LumpLength(int lump);
|
||||
int W_Read(void *dest, size_t size, size_t offset, wadfile_info_t *wad);
|
||||
void W_ReadLump(void *dest, int lump);
|
||||
void W_HashLumps(void);
|
||||
unsigned W_LumpNameHash(const char *s);
|
||||
|
||||
void W_InitCache(void);
|
||||
void W_DoneCache(void);
|
||||
const void* W_CacheLumpNum(int lump);
|
||||
const void* W_LockLumpNum(int lump);
|
||||
void W_UnlockLumpNum(int lump);
|
||||
|
||||
// CPhipps - convenience macros
|
||||
#define W_CacheLumpName(name) W_CacheLumpNum (W_GetNumForName(name))
|
||||
#define W_UnlockLumpName(name) W_UnlockLumpNum (W_GetNumForName(name))
|
||||
#define W_CheckNumForName(name) W_CheckNumForNameNs(name, ns_global)
|
||||
#define W_CacheLumpName(name) W_CacheLumpNum(W_GetNumForName(name))
|
||||
#define W_UnlockLumpName(name) W_UnlockLumpNum(W_GetNumForName(name))
|
||||
#define W_LockLumpName(name) W_CacheLumpName(name)
|
||||
#define W_LockLumpNum(n) W_CacheLumpNum(n)
|
||||
|
||||
char *AddDefaultExtension(char *, const char *); // killough 1/18/98
|
||||
void ExtractFileBase(const char *, char *); // killough
|
||||
unsigned W_LumpNameHash(const char *s); // killough 1/31/98
|
||||
void W_HashLumps(void); // cph 2001/07/07 - made public
|
||||
|
||||
#endif
|
||||
|
||||
@ -57,10 +57,6 @@
|
||||
#include "lprintf.h"
|
||||
#include "i_system.h"
|
||||
|
||||
#ifdef DJGPP
|
||||
#include <dpmi.h>
|
||||
#endif
|
||||
|
||||
// Tunables
|
||||
|
||||
// Alignment of zone memory (benefit may be negated by HEADER_SIZE, CHUNK_SIZE)
|
||||
@ -387,11 +383,7 @@ void *(Z_Malloc)(size_t size, int tag, void **user
|
||||
block = NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDMALLOC
|
||||
while (!(block = dmalloc_malloc(file,line,size + HEADER_SIZE,DMALLOC_FUNC_MALLOC,0,0))) {
|
||||
#else
|
||||
while (!(block = (malloc)(size + HEADER_SIZE))) {
|
||||
#endif
|
||||
if (!blockbytag[PU_CACHE])
|
||||
I_Error ("Z_Malloc: Failure trying to allocate %lu bytes"
|
||||
#ifdef INSTRUMENTED
|
||||
@ -402,7 +394,8 @@ void *(Z_Malloc)(size_t size, int tag, void **user
|
||||
, file, line
|
||||
#endif
|
||||
);
|
||||
Z_FreeTags(PU_CACHE,PU_CACHE);
|
||||
// RG: Don't nuke the whole cache at once!
|
||||
(Z_FreeTags)(PU_CACHE, PU_CACHE, 2);
|
||||
}
|
||||
|
||||
if (!blockbytag[tag])
|
||||
@ -506,17 +499,14 @@ void (Z_Free)(void *p
|
||||
memset(block, gametic & 0xff, block->size + HEADER_SIZE);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBDMALLOC
|
||||
dmalloc_free(file,line,block,DMALLOC_FUNC_MALLOC);
|
||||
#else
|
||||
(free)(block);
|
||||
#endif
|
||||
|
||||
#ifdef INSTRUMENTED
|
||||
Z_DrawStats(); // print memory allocation stats
|
||||
#endif
|
||||
}
|
||||
|
||||
void (Z_FreeTags)(int lowtag, int hightag
|
||||
void (Z_FreeTags)(int lowtag, int hightag, int max
|
||||
#ifdef INSTRUMENTED
|
||||
, const char *file, int line
|
||||
#endif
|
||||
@ -539,7 +529,7 @@ void (Z_FreeTags)(int lowtag, int hightag
|
||||
if (!block)
|
||||
continue;
|
||||
end_block = block->prev;
|
||||
while (1)
|
||||
while (max--)
|
||||
{
|
||||
memblock_t *next = block->next;
|
||||
#ifdef INSTRUMENTED
|
||||
|
||||
@ -66,13 +66,13 @@ enum {PU_FREE, PU_STATIC, PU_SOUND, PU_MUSIC, PU_LEVEL, PU_LEVSPEC, PU_CACHE,
|
||||
#define DA(x,y) ,x,y
|
||||
#define DAC(x,y) x,y
|
||||
#else
|
||||
#define DA(x,y)
|
||||
#define DA(x,y)
|
||||
#define DAC(x,y)
|
||||
#endif
|
||||
|
||||
void *(Z_Malloc)(size_t size, int tag, void **ptr DA(const char *, int));
|
||||
void (Z_Free)(void *ptr DA(const char *, int));
|
||||
void (Z_FreeTags)(int lowtag, int hightag DA(const char *, int));
|
||||
void (Z_FreeTags)(int lowtag, int hightag, int max DA(const char *, int));
|
||||
void (Z_ChangeTag)(void *ptr, int tag DA(const char *, int));
|
||||
void (Z_Init)(void);
|
||||
void Z_Close(void);
|
||||
@ -81,18 +81,21 @@ void *(Z_Realloc)(void *p, size_t n, int tag, void **user DA(const char *, int))
|
||||
char *(Z_Strdup)(const char *s, int tag, void **user DA(const char *, int));
|
||||
void (Z_CheckHeap)(DAC(const char *,int)); // killough 3/22/98: add file/line info
|
||||
void Z_DumpHistory(char *);
|
||||
void Z_ZoneHistory(char *);
|
||||
|
||||
#ifdef INSTRUMENTED
|
||||
/* cph - save space if not debugging, don't require file
|
||||
/* cph - save space if not debugging, don't require file
|
||||
* and line to memory calls */
|
||||
#define Z_Free(a) (Z_Free) (a, __FILE__,__LINE__)
|
||||
#define Z_FreeTags(a,b) (Z_FreeTags) (a,b, __FILE__,__LINE__)
|
||||
#define Z_FreeTags(a,b) (Z_FreeTags) (a,b,-1, __FILE__,__LINE__)
|
||||
#define Z_ChangeTag(a,b) (Z_ChangeTag)(a,b, __FILE__,__LINE__)
|
||||
#define Z_Malloc(a,b,c) (Z_Malloc) (a,b,c, __FILE__,__LINE__)
|
||||
#define Z_Strdup(a,b,c) (Z_Strdup) (a,b,c, __FILE__,__LINE__)
|
||||
#define Z_Calloc(a,b,c,d) (Z_Calloc) (a,b,c,d,__FILE__,__LINE__)
|
||||
#define Z_Realloc(a,b,c,d) (Z_Realloc) (a,b,c,d,__FILE__,__LINE__)
|
||||
#define Z_CheckHeap() (Z_CheckHeap)(__FILE__,__LINE__)
|
||||
#else
|
||||
#define Z_FreeTags(a,b) (Z_FreeTags) (a,b,-1)
|
||||
#endif
|
||||
|
||||
/* cphipps 2001/11/18 -
|
||||
@ -101,9 +104,6 @@ void Z_DumpHistory(char *);
|
||||
* directly, for efficiency. Except we do need a wrapper to handle out of memory
|
||||
* errors... damn, ok, we'll leave it for now.
|
||||
*/
|
||||
#ifndef HAVE_LIBDMALLOC
|
||||
// Remove all definitions before including system definitions
|
||||
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef realloc
|
||||
@ -116,14 +116,4 @@ void Z_DumpHistory(char *);
|
||||
#define calloc(n1,n2) Z_Calloc(n1,n2,PU_STATIC,0)
|
||||
#define strdup(s) Z_Strdup(s,PU_STATIC,0)
|
||||
|
||||
#else
|
||||
|
||||
#ifdef HAVE_LIBDMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
void Z_ZoneHistory(char *);
|
||||
|
||||
#endif
|
||||
|
||||
@ -325,31 +325,18 @@ void I_InitSound(void)
|
||||
{
|
||||
for (int i = 1; i < NUMSFX; i++)
|
||||
{
|
||||
// Map unknown sounds to pistol
|
||||
if (S_sfx[i].lumpnum == -1)
|
||||
sfx[i] = sfx[1]; // Map unknown sounds to pistol
|
||||
else
|
||||
{
|
||||
sfx[i] = sfx[1];
|
||||
continue;
|
||||
size_t size = W_LumpLength(S_sfx[i].lumpnum);
|
||||
sfx[i].length = ((size + (SAMPLECOUNT - 1)) / SAMPLECOUNT) * SAMPLECOUNT;
|
||||
sfx[i].data = Z_Malloc(sfx[i].length, PU_SOUND, 0);
|
||||
W_ReadLump(sfx[i].data, S_sfx[i].lumpnum);
|
||||
memset(sfx[i].data + size, 0x80, sfx[i].length - size);
|
||||
}
|
||||
|
||||
int sfxlump = S_sfx[i].lumpnum;
|
||||
const void *data = W_CacheLumpNum(sfxlump) + 8;
|
||||
size_t size = W_LumpLength(sfxlump) - 8;
|
||||
|
||||
// Pads the sound effect out to the mixing buffer size.
|
||||
size_t paddedsize = ((size + (SAMPLECOUNT - 1)) / SAMPLECOUNT) * SAMPLECOUNT;
|
||||
void *paddedsfx = Z_Malloc(paddedsize, PU_SOUND, 0);
|
||||
|
||||
memcpy(paddedsfx, data, size);
|
||||
memset(paddedsfx + size, 0x80, paddedsize - size);
|
||||
|
||||
sfx[i].data = paddedsfx;
|
||||
sfx[i].length = paddedsize;
|
||||
|
||||
W_UnlockLumpNum(sfxlump);
|
||||
Z_FreeTags(PU_CACHE, PU_CACHE);
|
||||
}
|
||||
RG_LOGI("pre-cached all sound data!\n");
|
||||
RG_LOGI("all sound effects loaded.\n");
|
||||
|
||||
music_player->init(snd_samplerate);
|
||||
music_player->setvolume(snd_MusicVolume);
|
||||
@ -482,6 +469,7 @@ void I_Init(void)
|
||||
|
||||
static bool screenshot_handler(const char *filename, int width, int height)
|
||||
{
|
||||
Z_FreeTags(PU_CACHE, PU_CACHE); // At this point the heap is usually full. Let's reclaim some!
|
||||
return rg_display_save_frame(filename, &update, width, height);
|
||||
}
|
||||
|
||||
@ -511,7 +499,7 @@ static void event_handler(int event, void *arg)
|
||||
{
|
||||
// DOOM fully fills the internal heap and this causes some shutdown
|
||||
// steps to fail so we try to free everything!
|
||||
Z_FreeTags(PU_STATIC, PU_CACHE);
|
||||
Z_FreeTags(0, PU_MAX);
|
||||
rg_audio_set_mute(true);
|
||||
}
|
||||
return;
|
||||
|
||||
@ -41,7 +41,9 @@
|
||||
"PROJECT_VER",
|
||||
"IS_LITTLE_ENDIAN",
|
||||
"INLINE=",
|
||||
"uint=unsigned int"
|
||||
"uint=unsigned int",
|
||||
"CONFIG_FREERTOS_HZ=100",
|
||||
"CONFIG_TCPIP_LWIP=1"
|
||||
],
|
||||
"C_Cpp.default.includePath": [
|
||||
"${workspaceFolder}/components/**",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user