diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 73ba81c58..aa7338ad2 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -478,7 +478,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) #ifdef GLENCORE if (encoremap) - grtex->mipmap.colormap += (256*32); + grtex->mipmap.colormap += COLORMAP_REMAPOFFSET; #endif blockwidth = texture->width; @@ -833,7 +833,7 @@ void HWR_LiterallyGetFlat(lumpnum_t flatlumpnum, boolean noencoremap) #ifdef GLENCORE if (!noencoremap && encoremap) - grmip->colormap += (256*32); + grmip->colormap += COLORMAP_REMAPOFFSET; #endif grmip = HWR_GetCachedGLPatch(flatlumpnum)->mipmap; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index df265e504..4c06c8604 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5224,7 +5224,7 @@ static void HWR_ProjectSprite(mobj_t *thing) vis->colormap = colormaps; #ifdef GLENCORE if (encoremap && (thing->flags & (MF_SCENERY|MF_NOTHINK)) && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += (256*32); + vis->colormap += COLORMAP_REMAPOFFSET; #endif } @@ -5331,7 +5331,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #ifdef GLENCORE if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += (256*32); + vis->colormap += COLORMAP_REMAPOFFSET; #endif // set top/bottom coords diff --git a/src/r_data.c b/src/r_data.c index 851e0cd93..7c5fb6ce5 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -287,7 +287,9 @@ static void R_InitColormaps(void) // Load in the light tables lump = W_GetNumForName("COLORMAP"); len = W_LumpLength(lump); - colormaps = Z_MallocAlign(len * 2, PU_STATIC, NULL, 8); // * 2 for encore + if (len < COLORMAP_SIZE*2) // accomodate encore mode later + len = COLORMAP_SIZE*2; + colormaps = Z_MallocAlign(len, PU_STATIC, NULL, 8); W_ReadLump(lump, colormaps); // no need to init encoremap at this stage @@ -330,9 +332,9 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) encoremap = Z_MallocAlign(256 + 10, PU_LEVEL, NULL, 8); W_ReadLump(newencoremap, encoremap); colormap_p = colormap_p2 = colormaps; - colormap_p += (256 * 32); + colormap_p += COLORMAP_REMAPOFFSET; - for (p = 0; p < 32; p++) + for (p = 0; p < LIGHTLEVELS; p++) { for (i = 0; i < 256; i++) { @@ -731,12 +733,12 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) // Now allocate memory for the actual colormap array itself! // aligned on 8 bit for asm code - colormap_p = Z_MallocAlign((256 * (encoremap ? 64 : 32)) + 10, PU_LEVEL, NULL, 8); + colormap_p = Z_MallocAlign((COLORMAP_SIZE * (encoremap ? 2 : 1)) + 10, PU_LEVEL, NULL, 8); lighttable = (UINT8 *)colormap_p; // Calculate the palette index for each palette index, for each light level // (as well as the two unused colormap lines we inherited from Doom) - for (p = 0; p < 32; p++) + for (p = 0; p < LIGHTLEVELS; p++) { for (i = 0; i < 256; i++) { @@ -776,7 +778,7 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) { lighttable_t *colormap_p2 = lighttable; - for (p = 0; p < 32; p++) + for (p = 0; p < LIGHTLEVELS; p++) { for (i = 0; i < 256; i++) { diff --git a/src/r_draw8.c b/src/r_draw8.c index 2f7bb64b8..41c74ba3c 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -1698,7 +1698,7 @@ void R_DrawColumnShadowed_8(void) { dc_colormap = dc_lightlist[i].rcolormap; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (solid && dc_yl < bheight) dc_yl = bheight; continue; @@ -1716,7 +1716,7 @@ void R_DrawColumnShadowed_8(void) dc_colormap = dc_lightlist[i].rcolormap; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } dc_yh = realyh; if (dc_yl <= realyh) diff --git a/src/r_main.h b/src/r_main.h index b4845af18..b7b4c9fd5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -41,7 +41,7 @@ extern size_t validcount, linecount, loopcount, framecount; // Lighting constants. // Now with 32 levels. -#define LIGHTLEVELS 32 +// LIGHTLEVELS is now defined in r_state.h #define LIGHTSEGSHIFT 3 #define MAXLIGHTSCALE 48 diff --git a/src/r_plane.c b/src/r_plane.c index a987fa330..9ca8eb608 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -232,7 +232,7 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) ds_colormap = planezlight[pindex]; if (encoremap && !currentplane->noencore) - ds_colormap += (256*32); + ds_colormap += COLORMAP_REMAPOFFSET; if (currentplane->extra_colormap) ds_colormap = currentplane->extra_colormap->colormap + (ds_colormap - colormaps); @@ -645,7 +645,7 @@ static void R_DrawSkyPlane(visplane_t *pl) // by sector colormaps (INVUL inverse mapping is not implemented in SRB2 so is irrelevant). dc_colormap = colormaps; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = skytexturemid; dc_texheight = textureheight[skytexture] >>FRACBITS; diff --git a/src/r_segs.c b/src/r_segs.c index 8dcb61992..b0be67062 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -203,7 +203,7 @@ static void R_DrawWallSplats(void) pindex = MAXLIGHTSCALE - 1; dc_colormap = walllights[pindex]; if (encoremap && !(seg->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (frontsector->extra_colormap) dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -578,7 +578,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) { dc_colormap = rlight->rcolormap; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; continue; } @@ -599,7 +599,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) windowtop = windowbottom + 1; dc_colormap = rlight->rcolormap; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } windowbottom = realbot; if (windowtop < windowbottom) @@ -617,7 +617,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) dc_colormap = walllights[pindex]; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (frontsector->extra_colormap) dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -1163,7 +1163,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { dc_colormap = rlight->rcolormap; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } if (solid && windowtop < bheight) windowtop = bheight; @@ -1195,7 +1195,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { dc_colormap = rlight->rcolormap; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } } windowbottom = sprbotscreen; @@ -1216,7 +1216,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = walllights[pindex]; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -1476,7 +1476,7 @@ static void R_RenderSegLoop (void) dc_colormap = walllights[pindex]; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_x = rw_x; dc_iscale = 0xffffffffu / (unsigned)rw_scale; diff --git a/src/r_state.h b/src/r_state.h index 1ae0adcf6..cb55e2c2b 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -44,6 +44,10 @@ extern UINT8 *encoremap; extern UINT8 invertmap[256]; #endif +#define LIGHTLEVELS 32 +#define COLORMAP_SIZE (256*LIGHTLEVELS) +#define COLORMAP_REMAPOFFSET COLORMAP_SIZE + // Boom colormaps. extern extracolormap_t *extra_colormaps; diff --git a/src/r_things.c b/src/r_things.c index c4e76303d..9824081dd 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -863,7 +863,7 @@ static void R_DrawVisSprite(vissprite_t *vis) dc_colormap = colormaps; if (encoremap && !vis->mobj->color && !(vis->mobj->flags & MF_DONTENCOREMAP)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = vis->texturemid; dc_texheight = 0; @@ -993,7 +993,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) dc_colormap = colormaps; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_iscale = FixedDiv(FRACUNIT, vis->scale); dc_texturemid = vis->texturemid; diff --git a/src/v_video.c b/src/v_video.c index f0c7e1a13..6ccddd89d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1454,7 +1454,7 @@ void V_DrawCustomFadeScreen(const char *lump, UINT8 strength) if (lumpnum != LUMPERROR) { - clm = Z_MallocAlign((256 * 32), PU_STATIC, NULL, 8); + clm = Z_MallocAlign(COLORMAP_SIZE, PU_STATIC, NULL, 8); W_ReadLump(lumpnum, clm); if (clm != NULL)