@@ -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
616618void 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
0 commit comments