From a210049839f7bb3fe82c4e28f7d7c5f6dc221592 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 15 Feb 2021 11:43:45 +0000 Subject: [PATCH 1/5] Attempt to calculate postimg during chasecam hitlag - otherwise encore mode will temporarily flip back and it'll be confusing. --- src/p_user.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/p_user.c b/src/p_user.c index e4785b249..8ab54980d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3074,6 +3074,10 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall { // Do not move the camera while in hitlag! // The camera zooming out after you got hit makes it hard to focus on the vibration. + // of course, if you're in chase, don't forget the postimage - otherwise encore will flip back + if (thiscam->chase) + P_CalcChasePostImg(player, thiscam); + return true; } From 8a4542a5ef15ad4772aefe5665feed2a3fc5780f Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 15 Feb 2021 12:26:22 +0000 Subject: [PATCH 2/5] Reintroduce the mirroring aspect of Encore in OpenGL. I'm not familiar enough with the renderer to recreate the rest of the changes at current, but this is the most significant regression. --- src/hardware/hw_main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c299d9c87..df265e504 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5526,6 +5526,11 @@ static void HWR_DrawSkyBackground(player_t *player) else dometransform.flip = false; + if (*type == postimg_mirror) + dometransform.mirror = true; + else + dometransform.mirror = false; + dometransform.scalex = 1; dometransform.scaley = (float)vid.width/vid.height; dometransform.scalez = 1; @@ -5802,6 +5807,11 @@ void HWR_RenderSkyboxView(player_t *player) else atransform.flip = false; + if (*type == postimg_mirror) + atransform.mirror = true; + else + atransform.mirror = false; + atransform.x = gl_viewx; // FIXED_TO_FLOAT(viewx) atransform.y = gl_viewy; // FIXED_TO_FLOAT(viewy) atransform.z = gl_viewz; // FIXED_TO_FLOAT(viewz) @@ -6005,6 +6015,11 @@ void HWR_RenderPlayerView(void) else atransform.flip = false; + if (*type == postimg_mirror) + atransform.mirror = true; + else + atransform.mirror = false; + atransform.x = gl_viewx; // FIXED_TO_FLOAT(viewx) atransform.y = gl_viewy; // FIXED_TO_FLOAT(viewy) atransform.z = gl_viewz; // FIXED_TO_FLOAT(viewz) From a597d9b4636d575af110bd0fdd6b2c2c1619f74d Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 15 Feb 2021 16:37:37 +0000 Subject: [PATCH 3/5] Fixed a too-small memory allocation for Encore remaps, removing all memory-related crashes in Software. --- src/r_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_data.c b/src/r_data.c index 39c41d8bf..851e0cd93 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -731,7 +731,7 @@ 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 * 34) + 10, PU_LEVEL, NULL, 8); + colormap_p = Z_MallocAlign((256 * (encoremap ? 64 : 32)) + 10, PU_LEVEL, NULL, 8); lighttable = (UINT8 *)colormap_p; // Calculate the palette index for each palette index, for each light level From f40836dcecf87ff4004a15db2e86bfabbdfb4678 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 15 Feb 2021 21:55:40 +0000 Subject: [PATCH 4/5] Fix skies not being Encore-remapped (only affected software :regret:) --- src/r_plane.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/r_plane.c b/src/r_plane.c index 3ec74bc47..a987fa330 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -644,6 +644,8 @@ static void R_DrawSkyPlane(visplane_t *pl) // Because of this hack, sky is not affected // by sector colormaps (INVUL inverse mapping is not implemented in SRB2 so is irrelevant). dc_colormap = colormaps; + if (encoremap) + dc_colormap += (256*32); dc_texturemid = skytexturemid; dc_texheight = textureheight[skytexture] >>FRACBITS; From 4052e01f4a6055e4e51a49538a8975090e05ff99 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 16 Feb 2021 14:34:00 +0000 Subject: [PATCH 5/5] Introduce a sequence of macros to reduce the reliance of Colormap-related code (especially but not limited to Encore mode) on magic numbers. --- src/hardware/hw_cache.c | 4 ++-- src/hardware/hw_main.c | 4 ++-- src/r_data.c | 14 ++++++++------ src/r_draw8.c | 4 ++-- src/r_main.h | 2 +- src/r_plane.c | 4 ++-- src/r_segs.c | 16 ++++++++-------- src/r_state.h | 4 ++++ src/r_things.c | 4 ++-- src/v_video.c | 2 +- 10 files changed, 32 insertions(+), 26 deletions(-) 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)