Skip to content

Commit 0a739e0

Browse files
committed
DOOM: Fixed/Improved pre-caching to reduce stuttering
1 parent 94bf570 commit 0a739e0

File tree

15 files changed

+185
-325
lines changed

15 files changed

+185
-325
lines changed

base.sdkconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ CONFIG_SPIRAM_MEMTEST=n
8787
CONFIG_SPIRAM_CACHE_WORKAROUND=n
8888
CONFIG_SPIRAM_BANKSWITCH_ENABLE=n
8989
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=32768
90-
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=4096
90+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192
9191
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=n
9292
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
9393
CONFIG_SPIRAM_OCCUPY_HSPI_HOST=n

components/retro-go/rg_display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void rg_display_reset_config(void)
606606
// TO DO: We probably should call the setters to ensure valid values...
607607
.screen.width = RG_SCREEN_WIDTH - RG_SCREEN_MARGIN_LEFT - RG_SCREEN_MARGIN_RIGHT,
608608
.screen.height = RG_SCREEN_HEIGHT - RG_SCREEN_MARGIN_TOP - RG_SCREEN_MARGIN_BOTTOM,
609-
.config.backlight = RG_MIN(RG_MAX(rg_settings_get_int32(SETTING_BACKLIGHT, 40), 0), 100),
609+
.config.backlight = RG_MIN(RG_MAX(rg_settings_get_int32(SETTING_BACKLIGHT, 80), 0), 100),
610610
.config.scaling = rg_settings_get_app_int32(SETTING_SCALING, RG_DISPLAY_SCALING_FILL),
611611
.config.filter = rg_settings_get_app_int32(SETTING_FILTER, RG_DISPLAY_FILTER_HORIZ),
612612
.config.rotation = rg_settings_get_app_int32(SETTING_ROTATION, RG_DISPLAY_ROTATION_AUTO),

components/retro-go/rg_gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ static dialog_return_t brightness_update_cb(dialog_option_t *option, dialog_even
710710
if (event == RG_DIALOG_PREV) level -= 10;
711711
if (event == RG_DIALOG_NEXT) level += 10;
712712

713-
level = RG_MIN(RG_MAX(level, 10), 100);
713+
level = RG_MIN(RG_MAX(level & ~1, 1), 100);
714714

715715
if (level != old_level)
716716
rg_display_set_backlight(level);

prboom-go/components/prboom/d_main.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ void D_StartTitle (void)
519519
//
520520
// Add files to be loaded later by W_Init()
521521
//
522-
boolean D_AddFile(const char *file, wad_source_t source)
522+
bool D_AddFile(const char *file)
523523
{
524524
char relpath[PATH_MAX + 1];
525525

@@ -691,11 +691,11 @@ static void D_DoomMainSetup(void)
691691

692692
// Try loading iwad specified as parameter
693693
if ((p = M_CheckParm("-iwad")) && (++p < myargc))
694-
D_AddFile(myargv[p], source_iwad);
694+
D_AddFile(myargv[p]);
695695

696696
// If that fails then try known standard iwad names
697697
for (int i = 0; !numwadfiles && standard_iwads[i]; i++)
698-
D_AddFile(standard_iwads[i], source_iwad);
698+
D_AddFile(standard_iwads[i]);
699699

700700
if (!numwadfiles)
701701
I_Error("IWAD not found\n");
@@ -745,6 +745,20 @@ static void D_DoomMainSetup(void)
745745
"It comes with ABSOLUTELY NO WARRANTY. See the file COPYING for details.\n",
746746
PACKAGE, VERSION, version_date, doomverstr);
747747

748+
// Add prboom.wad at the very beginning so it can be overriden by mods
749+
#ifdef PRBOOMWAD
750+
#include "prboom_wad.h"
751+
wadfiles[numwadfiles++] = (wadfile_info_t){
752+
.name = "prboom.wad",
753+
.data = prboom_wad,
754+
.size = prboom_wad_size,
755+
.handle = NULL,
756+
};
757+
#else
758+
if (!D_AddFile("prboom.wad"))
759+
I_Error("PRBOOM.WAD not found\n");
760+
#endif
761+
748762
if ((devparm = M_CheckParm("-devparm")))
749763
lprintf(LO_CONFIRM, "%s", s_D_DEVSTR);
750764

@@ -901,7 +915,7 @@ static void D_DoomMainSetup(void)
901915
// the parms after p are wadfile/lump names,
902916
// until end of parms or another - preceded parm
903917
while (++p != myargc && *myargv[p] != '-')
904-
if (D_AddFile(myargv[p], source_pwad))
918+
if (D_AddFile(myargv[p]))
905919
modifiedgame = true;
906920
}
907921

@@ -917,32 +931,14 @@ static void D_DoomMainSetup(void)
917931
char file[PATH_MAX+1]; // cph - localised
918932
strcpy(file,myargv[p+1]);
919933
AddDefaultExtension(file,".lmp"); // killough
920-
D_AddFile (file,source_lmp);
934+
D_AddFile (file);
921935
//jff 9/3/98 use logical output routine
922936
lprintf(LO_CONFIRM,"Playing demo %s\n",file);
923937
if ((p = M_CheckParm ("-ffmap")) && p < myargc-1) {
924938
ffmap = atoi(myargv[p+1]);
925939
}
926-
927940
}
928941

929-
// Add prboom.wad at the very end
930-
if (!D_AddFile("prboom.wad", source_auto_load))
931-
{
932-
#ifdef PRBOOMWAD
933-
lprintf(LO_WARN, "PRBOOM.WAD not found. Using bundled version.\n");
934-
#include "prboom_wad.h"
935-
wadfiles[numwadfiles++] = (wadfile_info_t){
936-
.name = "prboom.wad",
937-
.data = prboom_wad,
938-
.size = prboom_wad_size,
939-
.handle = NULL,
940-
};
941-
#else
942-
I_Error("PRBOOM.WAD not found\n");
943-
#endif
944-
}
945-
946942
// internal translucency set to config file value // phares
947943
general_translucency = default_translucency; // phares
948944

prboom-go/components/prboom/d_main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ void D_Display(void);
6969
void D_PageTicker(void);
7070
void D_StartTitle(void);
7171
void D_DoomMain(void);
72-
boolean D_AddFile(const char *file, wad_source_t source);
72+
bool D_AddFile(const char *file);
7373

7474
#endif

prboom-go/components/prboom/m_misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ default_t defaults[] =
178178
def_int,ss_none}, // 1=take special steps ensuring demo sync, 2=only during recordings
179179
// {"endoom_mode", {&endoom_mode},{5},0,7, // CPhipps - endoom flags
180180
// def_hex, ss_none}, // 0, +1 for colours, +2 for non-ascii chars, +4 for skip-last-line
181-
{"level_precache",{(int*)&precache},{0},0,1,
181+
{"level_precache",{(int*)&precache},{1},0,1,
182182
def_bool,ss_none}, // precache level data?
183183
{"demo_smoothturns", {&demo_smoothturns}, {0},0,1,
184184
def_bool,ss_stat},

prboom-go/components/prboom/r_data.c

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -456,20 +456,19 @@ void R_InitTranMap(int progress)
456456
// If a tranlucency filter map lump is present, use it
457457
if ((lump = W_CheckNumForName("TRANMAP")) != -1)
458458
{
459-
lprintf(LO_INFO, "R_InitTranMap: TRANMAP lump: %d\n", lump);
459+
lprintf(LO_INFO, "R_InitTranMap: Using TRANMAP(%d) directly\n", lump);
460460
main_tranmap = W_CacheLumpNum(lump);
461461
}
462462
// Compose a default transparent filter map based on PLAYPAL.
463463
else if ((lump = W_CheckNumForName("PLAYPAL")) != -1)
464464
{
465-
lprintf(LO_INFO, "R_InitTranMap: PLAYPAL lump: %d\n", lump);
466-
if (progress)
467-
lprintf(LO_INFO, "Tranmap build [ ]\x08\x08\x08\x08\x08\x08\x08\x08\x08");
465+
lprintf(LO_INFO, "R_InitTranMap: Gen from PLAYPAL(%d) [ ]"
466+
"\x08\x08\x08\x08\x08\x08\x08\x08\x08", lump);
468467

469468
const struct PACKEDATTR {byte r, g, b;} *pal = W_CacheLumpNum(lump);
470469
byte *my_tranmap = Z_Malloc(256*256, PU_STATIC, 0);
471-
int w1 = ((unsigned)tran_filter_pct<<TSC)/100;
472-
int w2 = (1l<<TSC)-w1;
470+
int w1 = (tran_filter_pct << TSC) / 100;
471+
int w2 = (1 << TSC) - w1;
473472
int total[256];
474473

475474
for (int i = 0; i < 256; ++i)
@@ -491,24 +490,27 @@ void R_InitTranMap(int progress)
491490
if (!(i & 31) && progress)
492491
lprintf(LO_INFO,".");
493492

494-
for (int j = 0; j < 256; j++, tp++)
493+
for (int j = 0; j < 256; j++)
495494
{
496495
int r = r1 + (pal[j].r * w1);
497496
int g = g1 + (pal[j].g * w1);
498497
int b = b1 + (pal[j].b * w1);
499-
int best = INT_MAX;
498+
int bc = 0, best = INT_MAX;
500499
for (int color = 255; color >= 0; --color)
501500
{
502501
int err = total[color] - pal[color].r*r - pal[color].g*g - pal[color].b*b;
503502
if (err < best)
504-
best = err, *tp = color;
503+
best = err, bc = color;
505504
}
505+
*tp++ = bc;
506506
}
507507
}
508508

509509
main_tranmap = my_tranmap;
510510

511511
W_UnlockLumpName("PLAYPAL");
512+
513+
lprintf(LO_INFO, "\n");
512514
}
513515
}
514516

@@ -615,79 +617,85 @@ static inline void precache_lump(int l)
615617

616618
void R_PrecacheLevel(void)
617619
{
618-
register int i;
619-
register byte *hitlist;
620-
621620
if (demoplayback)
622621
return;
623622

624-
{
625-
size_t size = numflats > numsprites ? numflats : numsprites;
626-
hitlist = malloc((size_t)numtextures > size ? numtextures : size);
627-
}
623+
size_t maxitems = MAX(numtextures, MAX(numflats, numsprites));
624+
byte hitlist[maxitems];
625+
size_t count = 0;
628626

629627
// Precache flats.
628+
memset(hitlist, 0, maxitems);
629+
count = 0;
630630

631-
memset(hitlist, 0, numflats);
632-
633-
for (i = numsectors; --i >= 0; )
634-
hitlist[sectors[i].floorpic] = hitlist[sectors[i].ceilingpic] = 1;
631+
for (int i = numsectors; --i >= 0; )
632+
{
633+
hitlist[sectors[i].floorpic] = 1;
634+
hitlist[sectors[i].ceilingpic] = 1;
635+
}
635636

636-
for (i = numflats; --i >= 0; )
637+
for (int i = numflats; --i >= 0; )
638+
{
637639
if (hitlist[i])
640+
{
638641
precache_lump(firstflat + i);
642+
count++;
643+
}
644+
}
639645

640-
// Precache textures.
641-
642-
memset(hitlist, 0, numtextures);
646+
lprintf(LO_INFO, "R_PrecacheLevel: pre-cached %d flats\n", count);
643647

644-
for (i = numsides; --i >= 0;)
645-
hitlist[sides[i].bottomtexture] =
646-
hitlist[sides[i].toptexture] =
647-
hitlist[sides[i].midtexture] = 1;
648648

649-
// Sky texture is always present.
650-
// Note that F_SKY1 is the name used to
651-
// indicate a sky floor/ceiling as a flat,
652-
// while the sky texture is stored like
653-
// a wall texture, with an episode dependend
654-
// name.
649+
// Precache textures.
650+
memset(hitlist, 0, maxitems);
651+
count = 0;
655652

653+
for (int i = numsides; --i >= 0; )
654+
{
655+
hitlist[sides[i].bottomtexture] = 1;
656+
hitlist[sides[i].toptexture] = 1;
657+
hitlist[sides[i].midtexture] = 1;
658+
}
656659
hitlist[skytexture] = 1;
657660

658-
for (i = numtextures; --i >= 0; )
661+
for (int i = numtextures; --i >= 0; )
659662
if (hitlist[i])
660663
{
661664
texture_t *texture = textures[i];
662-
int j = texture->patchcount;
663-
while (--j >= 0)
665+
for (int j = texture->patchcount; --j >= 0; )
666+
{
664667
precache_lump(texture->patches[j].patch);
668+
count++;
669+
}
665670
}
666671

672+
lprintf(LO_INFO, "R_PrecacheLevel: pre-cached %d textures\n", count);
673+
674+
667675
// Precache sprites.
668-
memset(hitlist, 0, numsprites);
676+
memset(hitlist, 0, maxitems);
677+
count = 0;
669678

670-
{
671-
thinker_t *th = NULL;
672-
while ((th = P_NextThinker(th,th_all)) != NULL)
673-
if (th->function == P_MobjThinker)
674-
hitlist[((mobj_t *)th)->sprite] = 1;
675-
}
679+
thinker_t *th = NULL;
680+
while ((th = P_NextThinker(th,th_all)))
681+
if (th->function == P_MobjThinker)
682+
hitlist[((mobj_t *)th)->sprite] = 1;
676683

677-
for (i=numsprites; --i >= 0;)
684+
for (int i = numsprites; --i >= 0; )
678685
if (hitlist[i])
679686
{
680-
int j = sprites[i].numframes;
681-
while (--j >= 0)
687+
for (int j = sprites[i].numframes; --j >= 0; )
682688
{
683689
short *sflump = sprites[i].spriteframes[j].lump;
684-
int k = 7;
685-
do
690+
for (int k = 7; --k >= 0; )
691+
{
686692
precache_lump(firstspritelump + sflump[k]);
687-
while (--k >= 0);
693+
count++;
694+
}
688695
}
689696
}
690-
free(hitlist);
697+
698+
lprintf(LO_INFO, "R_PrecacheLevel: pre-cached %d sprites\n", count);
691699
}
692700

693701
// Proff - Added for OpenGL

prboom-go/components/prboom/v_video.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,25 @@ static int currentPaletteIndex = 0;
490490
// V_UpdateTrueColorPalette
491491
//
492492
void V_UpdateTrueColorPalette(video_mode_t mode) {
493+
static int usegammaOnLastPaletteGeneration = -1;
493494
int i, w, p;
494495
byte r,g,b;
495496
int nr,ng,nb;
496497
float t;
497498
int paletteNum = currentPaletteIndex;
498-
static int usegammaOnLastPaletteGeneration = -1;
499-
500499
int pplump = W_GetNumForName("PLAYPAL");
501-
int gtlump = W_CheckNumForNameNs("GAMMATBL",ns_prboom);
502500
const byte *pal = W_CacheLumpNum(pplump);
503-
const byte *gtable = W_CacheLumpNum(gtlump) + 256*(usegamma);
504-
505501
int numPals = W_LumpLength(pplump) / (3*256);
506502
const float dontRoundAbove = 220;
507503
float roundUpR, roundUpG, roundUpB;
508504

505+
byte gtable[256];
506+
507+
// Note: this isn't right but I haven't reverse engineered how GAMMATBL
508+
// was generated yet and we don't even use truecolors for now...
509+
for (i = 0; i < 256; i++)
510+
gtable[i] = i << usegamma;
511+
509512
if (usegammaOnLastPaletteGeneration != usegamma) {
510513
if (Palettes15) free(Palettes15);
511514
if (Palettes16) free(Palettes16);
@@ -608,7 +611,6 @@ void V_UpdateTrueColorPalette(video_mode_t mode) {
608611
}
609612

610613
W_UnlockLumpNum(pplump);
611-
W_UnlockLumpNum(gtlump);
612614
}
613615

614616

0 commit comments

Comments
 (0)