From e545e5f9baccac7d5468fbcbab646fe7261d92fb Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Sun, 15 Mar 2020 09:55:57 +0100 Subject: [PATCH 1/4] Add UDMF colormap fields --- src/p_setup.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/r_data.c | 26 +++++++++-------- src/r_data.h | 3 +- 3 files changed, 93 insertions(+), 14 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 96a901a55..100de27e5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1130,8 +1130,7 @@ static void P_LoadSidedefs(UINT8 *data) case 455: // Fade colormaps! mazmazz 9/12/2018 (:flag_us:) // SoM: R_CreateColormap will only create a colormap in software mode... // Perhaps we should just call it instead of doing the calculations here. - sd->colormap_data = R_CreateColormap(msd->toptexture, msd->midtexture, - msd->bottomtexture); + sd->colormap_data = R_CreateColormapFromLinedef(msd->toptexture, msd->midtexture, msd->bottomtexture); sd->toptexture = sd->midtexture = sd->bottomtexture = 0; break; @@ -1384,6 +1383,19 @@ static void ParseTextmapVertexParameter(UINT32 i, char *param, char *val) } } +typedef struct textmap_colormap_s { + boolean used; + INT32 lightcolor; + UINT8 lightalpha; + INT32 fadecolor; + UINT8 fadealpha; + UINT8 fadestart; + UINT8 fadeend; + UINT8 flags; +} textmap_colormap_t; + +textmap_colormap_t textmap_colormap = { false, 0, 25, 0, 25, 0, 31, 0 }; + static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "heightfloor")) @@ -1412,6 +1424,46 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) sectors[i].floorpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(val))); else if (fastcmp(param, "rotationceiling")) sectors[i].ceilingpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(val))); + else if (fastcmp(param, "lightcolor")) + { + textmap_colormap.used = true; + textmap_colormap.lightcolor = atol(val); + } + else if (fastcmp(param, "lightalpha")) + { + textmap_colormap.used = true; + textmap_colormap.lightalpha = atol(val); + } + else if (fastcmp(param, "fadecolor")) + { + textmap_colormap.used = true; + textmap_colormap.fadecolor = atol(val); + } + else if (fastcmp(param, "fadealpha")) + { + textmap_colormap.used = true; + textmap_colormap.fadealpha = atol(val); + } + else if (fastcmp(param, "fadestart")) + { + textmap_colormap.used = true; + textmap_colormap.fadestart = atol(val); + } + else if (fastcmp(param, "fadeend")) + { + textmap_colormap.used = true; + textmap_colormap.fadeend = atol(val); + } + else if (fastcmp(param, "colormapfog") && fastcmp("true", val)) + { + textmap_colormap.used = true; + textmap_colormap.flags |= CMF_FOG; + } + else if (fastcmp(param, "colormapfadesprites") && fastcmp("true", val)) + { + textmap_colormap.used = true; + textmap_colormap.flags |= CMF_FADEFULLBRIGHTSPRITES; + } } static void ParseTextmapSidedefParameter(UINT32 i, char *param, char *val) @@ -1585,6 +1637,14 @@ static void TextmapFixFlatOffsets(sector_t *sec) } } +static INT32 P_ColorToRGBA(INT32 color, UINT8 alpha) +{ + UINT8 r = (color >> 16) & 0xFF; + UINT8 g = (color >> 8) & 0xFF; + UINT8 b = color & 0xFF; + return R_PutRgbaRGBA(r, g, b, alpha); +} + /** Loads the textmap data, after obtaining the elements count and allocating their respective space. */ static void P_LoadTextmap(void) @@ -1638,8 +1698,22 @@ static void P_LoadTextmap(void) sc->floorpic_angle = sc->ceilingpic_angle = 0; + textmap_colormap.used = false; + textmap_colormap.lightcolor = 0; + textmap_colormap.lightalpha = 25; + textmap_colormap.fadecolor = 0; + textmap_colormap.fadealpha = 25; + textmap_colormap.fadestart = 0; + textmap_colormap.fadeend = 31; + textmap_colormap.flags = 0; TextmapParse(sectorsPos[i], i, ParseTextmapSectorParameter); P_InitializeSector(sc); + if (textmap_colormap.used) + { + INT32 rgba = P_ColorToRGBA(textmap_colormap.lightcolor, textmap_colormap.lightalpha); + INT32 fadergba = P_ColorToRGBA(textmap_colormap.fadecolor, textmap_colormap.fadealpha); + sc->extra_colormap = R_CreateColormap(rgba, fadergba, textmap_colormap.fadestart, textmap_colormap.fadeend, textmap_colormap.flags); + } TextmapFixFlatOffsets(sc); } diff --git a/src/r_data.c b/src/r_data.c index f5a24c2c4..776292c46 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -2046,7 +2046,7 @@ extracolormap_t *R_ColormapForName(char *name) #endif // -// R_CreateColormap +// R_CreateColormapFromLinedef // // This is a more GL friendly way of doing colormaps: Specify colormap // data in a special linedef's texture areas and use that to generate @@ -2185,10 +2185,8 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) return lighttable; } -extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) +extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) { - extracolormap_t *extra_colormap, *exc; - // default values UINT8 cr = 0, cg = 0, cb = 0, ca = 0, cfr = 0, cfg = 0, cfb = 0, cfa = 25; UINT32 fadestart = 0, fadeend = 31; @@ -2311,6 +2309,13 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) rgba = R_PutRgbaRGBA(cr, cg, cb, ca); fadergba = R_PutRgbaRGBA(cfr, cfg, cfb, cfa); + return R_CreateColormap(rgba, fadergba, fadestart, fadeend, flags); +} + +extracolormap_t *R_CreateColormap(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags) +{ + extracolormap_t *extra_colormap; + // Did we just make a default colormap? #ifdef EXTRACOLORMAPLUMPS if (R_CheckDefaultColormapByValues(true, true, true, rgba, fadergba, fadestart, fadeend, flags, LUMPERROR)) @@ -2322,17 +2327,16 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) // Look for existing colormaps #ifdef EXTRACOLORMAPLUMPS - exc = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, flags, LUMPERROR); + extra_colormap = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, flags, LUMPERROR); #else - exc = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, flags); + extra_colormap = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, flags); #endif - if (exc) - return exc; + if (extra_colormap) + return extra_colormap; - CONS_Debug(DBG_RENDER, "Creating Colormap: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", - cr, cg, cb, ca, cfr, cfg, cfb, cfa); + CONS_Debug(DBG_RENDER, "Creating Colormap: rgba(%x) fadergba(%x)\n", rgba, fadergba); - extra_colormap = Z_Calloc(sizeof (*extra_colormap), PU_LEVEL, NULL); + extra_colormap = Z_Calloc(sizeof(*extra_colormap), PU_LEVEL, NULL); extra_colormap->fadestart = (UINT16)fadestart; extra_colormap->fadeend = (UINT16)fadeend; diff --git a/src/r_data.h b/src/r_data.h index 0569893cd..114a2072b 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -147,7 +147,8 @@ boolean R_CheckEqualColormaps(extracolormap_t *exc_a, extracolormap_t *exc_b, bo extracolormap_t *R_GetColormapFromList(extracolormap_t *extra_colormap); lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap); -extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3); +extracolormap_t * R_CreateColormapFromLinedef(char *p1, char *p2, char *p3); +extracolormap_t* R_CreateColormap(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags); extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *exc_addend, boolean subR, boolean subG, boolean subB, boolean subA, boolean subFadeR, boolean subFadeG, boolean subFadeB, boolean subFadeA, From 7cf9ad2f2b7caac40f5907963c227f27a4217666 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Fri, 20 Mar 2020 11:19:30 +0100 Subject: [PATCH 2/4] Adapt setup of colormap linedefs --- src/p_setup.c | 88 +++++++++++++++++++++-- src/p_spec.c | 188 +++++++++++++++++++++++++++++--------------------- src/r_data.c | 7 +- src/r_data.h | 1 - 4 files changed, 197 insertions(+), 87 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index fc8b8c063..3a70b8af3 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1131,8 +1131,11 @@ static void P_LoadSidedefs(UINT8 *data) case 455: // Fade colormaps! mazmazz 9/12/2018 (:flag_us:) // SoM: R_CreateColormap will only create a colormap in software mode... // Perhaps we should just call it instead of doing the calculations here. - sd->colormap_data = R_CreateColormapFromLinedef(msd->toptexture, msd->midtexture, msd->bottomtexture); - sd->toptexture = sd->midtexture = sd->bottomtexture = 0; + if (!udmf) + { + sd->colormap_data = R_CreateColormapFromLinedef(msd->toptexture, msd->midtexture, msd->bottomtexture); + sd->toptexture = sd->midtexture = sd->bottomtexture = 0; + } break; case 413: // Change music @@ -1713,7 +1716,7 @@ static void P_LoadTextmap(void) { INT32 rgba = P_ColorToRGBA(textmap_colormap.lightcolor, textmap_colormap.lightalpha); INT32 fadergba = P_ColorToRGBA(textmap_colormap.fadecolor, textmap_colormap.fadealpha); - sc->extra_colormap = R_CreateColormap(rgba, fadergba, textmap_colormap.fadestart, textmap_colormap.fadeend, textmap_colormap.flags); + sc->extra_colormap = sc->spawn_extra_colormap = R_CreateColormap(rgba, fadergba, textmap_colormap.fadestart, textmap_colormap.fadeend, textmap_colormap.flags); } TextmapFixFlatOffsets(sc); } @@ -1787,9 +1790,9 @@ static void P_ProcessLinedefsAfterSidedefs(void) ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; - // Compile linedef 'text' from both sidedefs 'text' for appropriate specials. switch (ld->special) { + // Compile linedef 'text' from both sidedefs 'text' for appropriate specials. case 331: // Trigger linedef executor: Skin - Continuous case 332: // Trigger linedef executor: Skin - Each time case 333: // Trigger linedef executor: Skin - Once @@ -1805,6 +1808,41 @@ static void P_ProcessLinedefsAfterSidedefs(void) M_Memcpy(ld->text + strlen(ld->text) + 1, sides[ld->sidenum[1]].text, strlen(sides[ld->sidenum[1]].text) + 1); } break; + case 447: // Change colormap + case 455: // Fade colormap + if (udmf) + break; + if (ld->flags & ML_DONTPEGBOTTOM) // alternate alpha (by texture offsets) + { + extracolormap_t *exc = R_CopyColormap(sides[ld->sidenum[0]].colormap_data, false); + INT16 alpha = max(min(sides[ld->sidenum[0]].textureoffset >> FRACBITS, 25), -25); + INT16 fadealpha = max(min(sides[ld->sidenum[0]].rowoffset >> FRACBITS, 25), -25); + + // If alpha is negative, set "subtract alpha" flag and store absolute value + if (alpha < 0) + { + alpha *= -1; + ld->args[2] |= 16; + } + if (fadealpha < 0) + { + fadealpha *= -1; + ld->args[2] |= 256; + } + + exc->rgba = R_GetRgbaRGB(exc->rgba) + R_PutRgbaA(alpha); + exc->fadergba = R_GetRgbaRGB(exc->fadergba) + R_PutRgbaA(fadealpha); + + if (!(sides[ld->sidenum[0]].colormap_data = R_GetColormapFromList(exc))) + { + exc->colormap = R_CreateLightTable(exc); + R_AddColormapToList(exc); + sides[ld->sidenum[0]].colormap_data = exc; + } + else + Z_Free(exc); + } + break; } } } @@ -2768,6 +2806,48 @@ static void P_ConvertBinaryMap(void) else CONS_Alert(CONS_WARNING, "Linedef %s is missing the hook name of the Lua function to call! (This should be given in the front texture fields)\n", sizeu1(i)); break; + case 447: //Change colormap + lines[i].args[0] = lines[i].tag; + if (lines[i].flags & ML_EFFECT3) + lines[i].args[2] |= 1; + if (lines[i].flags & ML_EFFECT1) + lines[i].args[2] |= 34; + if (lines[i].flags & ML_NOCLIMB) + lines[i].args[2] |= 68; + if (lines[i].flags & ML_EFFECT2) + lines[i].args[2] |= 136; + break; + case 455: //Fade colormap + { + INT32 speed = (INT32)((((lines[i].flags & ML_DONTPEGBOTTOM) || !sides[lines[i].sidenum[0]].rowoffset) && lines[i].sidenum[1] != 0xFFFF) ? + abs(sides[lines[i].sidenum[1]].rowoffset >> FRACBITS) + : abs(sides[lines[i].sidenum[0]].rowoffset >> FRACBITS)); + + lines[i].args[0] = lines[i].tag; + if (lines[i].flags & ML_EFFECT4) + lines[i].args[2] = speed; + else + lines[i].args[2] = (256 + speed - 1)/speed; + if (lines[i].flags & ML_EFFECT3) + lines[i].args[3] |= 1; + if (lines[i].flags & ML_EFFECT1) + lines[i].args[3] |= 34; + if (lines[i].flags & ML_NOCLIMB) + lines[i].args[3] |= 68; + if (lines[i].flags & ML_EFFECT2) + lines[i].args[3] |= 136; + if (lines[i].flags & ML_BOUNCY) + lines[i].args[3] |= 4096; + if (lines[i].flags & ML_EFFECT5) + lines[i].args[3] |= 8192; + break; + } + case 456: //Stop fading colormap + lines[i].args[0] = lines[i].tag; + break; + case 606: //Colormap + lines[i].args[0] = lines[i].tag; + break; case 700: //Slope front sector floor case 701: //Slope front sector ceiling case 702: //Slope front sector floor and ceiling diff --git a/src/p_spec.c b/src/p_spec.c index b04a8d66e..2cd76f129 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3496,46 +3496,50 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Except it is activated by linedef executor, not level load // This could even override existing colormaps I believe // -- Monster Iestyn 14/06/18 - for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + { + extracolormap_t *source; + if (!udmf) + source = sides[line->sidenum[0]].colormap_data; + else + { + if (!line->args[1]) + source = line->frontsector->extra_colormap; + else + { + INT32 sourcesec = P_FindSectorFromTag(line->args[1], -1); + if (sourcesec == -1) + { + CONS_Debug(DBG_GAMELOGIC, "Line type 447 Executor: Can't find sector with source colormap (tag %d)!\n", line->args[1]); + return; + } + source = sectors[sourcesec].extra_colormap; + } + } + + for (secnum = -1; (secnum = P_FindSectorFromTag(line->args[0], secnum)) >= 0;) { P_ResetColormapFader(§ors[secnum]); - if (line->flags & ML_EFFECT3) // relative calc + if (line->args[2] & 1) // relative calc { - extracolormap_t *exc = R_AddColormaps( - (line->flags & ML_TFERLINE) && line->sidenum[1] != 0xFFFF ? - sides[line->sidenum[1]].colormap_data : sectors[secnum].extra_colormap, // use back colormap instead of target sector - sides[line->sidenum[0]].colormap_data, - line->flags & ML_EFFECT1, // subtract R - line->flags & ML_NOCLIMB, // subtract G - line->flags & ML_EFFECT2, // subtract B - false, // subtract A (no flag for this, just pass negative alpha) - line->flags & ML_EFFECT1, // subtract FadeR - line->flags & ML_NOCLIMB, // subtract FadeG - line->flags & ML_EFFECT2, // subtract FadeB - false, // subtract FadeA (no flag for this, just pass negative alpha) - false, // subtract FadeStart (we ran out of flags) - false, // subtract FadeEnd (we ran out of flags) - false, // ignore Flags (we ran out of flags) - line->flags & ML_DONTPEGBOTTOM, - (line->flags & ML_DONTPEGBOTTOM) ? (sides[line->sidenum[0]].textureoffset >> FRACBITS) : 0, - (line->flags & ML_DONTPEGBOTTOM) ? (sides[line->sidenum[0]].rowoffset >> FRACBITS) : 0, - false); + extracolormap_t *target = (!udmf && (line->flags & ML_TFERLINE) && line->sidenum[1] != 0xFFFF) ? + sides[line->sidenum[1]].colormap_data : sectors[secnum].extra_colormap; // use back colormap instead of target sector - if (!(sectors[secnum].extra_colormap = R_GetColormapFromList(exc))) - { - exc->colormap = R_CreateLightTable(exc); - R_AddColormapToList(exc); - sectors[secnum].extra_colormap = exc; - } - else - Z_Free(exc); - } - else if (line->flags & ML_DONTPEGBOTTOM) // alternate alpha (by texture offsets) - { - extracolormap_t *exc = R_CopyColormap(sides[line->sidenum[0]].colormap_data, false); - exc->rgba = R_GetRgbaRGB(exc->rgba) + R_PutRgbaA(max(min(sides[line->sidenum[0]].textureoffset >> FRACBITS, 25), 0)); - exc->fadergba = R_GetRgbaRGB(exc->fadergba) + R_PutRgbaA(max(min(sides[line->sidenum[0]].rowoffset >> FRACBITS, 25), 0)); + extracolormap_t *exc = R_AddColormaps( + target, + source, + line->args[2] & 2, // subtract R + line->args[2] & 4, // subtract G + line->args[2] & 8, // subtract B + line->args[2] & 16, // subtract A + line->args[2] & 32, // subtract FadeR + line->args[2] & 64, // subtract FadeG + line->args[2] & 128, // subtract FadeB + line->args[2] & 256, // subtract FadeA + line->args[2] & 512, // subtract FadeStart + line->args[2] & 1024, // subtract FadeEnd + line->args[2] & 2048, // ignore Flags + false); if (!(sectors[secnum].extra_colormap = R_GetColormapFromList(exc))) { @@ -3547,10 +3551,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) Z_Free(exc); } else - sectors[secnum].extra_colormap = sides[line->sidenum[0]].colormap_data; + sectors[secnum].extra_colormap = source; } break; - + } case 448: // Change skybox viewpoint/centerpoint if ((mo && mo->player && P_IsLocalPlayer(mo->player)) || (line->flags & ML_NOCLIMB)) { @@ -3824,15 +3828,32 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } case 455: // Fade colormap - for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + { + extracolormap_t *dest; + if (!udmf) + dest = sides[line->sidenum[0]].colormap_data; + else + { + if (!line->args[1]) + dest = line->frontsector->extra_colormap; + else + { + INT32 destsec = P_FindSectorFromTag(line->args[1], -1); + if (destsec == -1) + { + CONS_Debug(DBG_GAMELOGIC, "Line type 455 Executor: Can't find sector with destination colormap (tag %d)!\n", line->args[1]); + return; + } + dest = sectors[destsec].extra_colormap; + } + } + + for (secnum = -1; (secnum = P_FindSectorFromTag(line->args[0], secnum)) >= 0;) { extracolormap_t *source_exc, *dest_exc, *exc; - INT32 speed = (INT32)((line->flags & ML_DONTPEGBOTTOM) || !sides[line->sidenum[0]].rowoffset) && line->sidenum[1] != 0xFFFF ? - abs(sides[line->sidenum[1]].rowoffset >> FRACBITS) - : abs(sides[line->sidenum[0]].rowoffset >> FRACBITS); - // Prevent continuous execs from interfering on an existing fade - if (!(line->flags & ML_EFFECT5) + // Don't interrupt ongoing fade + if (!(line->args[3] & 8192) && sectors[secnum].fadecolormapdata) //&& ((fadecolormap_t*)sectors[secnum].fadecolormapdata)->timer > (ticbased ? 2 : speed*2)) { @@ -3840,19 +3861,19 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) continue; } - if (line->flags & ML_TFERLINE) // use back colormap instead of target sector + if (!udmf && (line->flags & ML_TFERLINE)) // use back colormap instead of target sector sectors[secnum].extra_colormap = (line->sidenum[1] != 0xFFFF) ? - sides[line->sidenum[1]].colormap_data : NULL; + sides[line->sidenum[1]].colormap_data : NULL; exc = sectors[secnum].extra_colormap; - if (!(line->flags & ML_BOUNCY) // BOUNCY: Do not override fade from default rgba - && !R_CheckDefaultColormap(sides[line->sidenum[0]].colormap_data, true, false, false) + if (!(line->args[3] & 4096) // Override fade from default rgba + && !R_CheckDefaultColormap(dest, true, false, false) && R_CheckDefaultColormap(exc, true, false, false)) { exc = R_CopyColormap(exc, false); - exc->rgba = R_GetRgbaRGB(sides[line->sidenum[0]].colormap_data->rgba) + R_PutRgbaA(R_GetRgbaA(exc->rgba)); - //exc->fadergba = R_GetRgbaRGB(sides[line->sidenum[0]].colormap_data->rgba) + R_PutRgbaA(R_GetRgbaA(exc->fadergba)); + exc->rgba = R_GetRgbaRGB(dest->rgba) + R_PutRgbaA(R_GetRgbaA(exc->rgba)); + //exc->fadergba = R_GetRgbaRGB(dest->rgba) + R_PutRgbaA(R_GetRgbaA(exc->fadergba)); if (!(source_exc = R_GetColormapFromList(exc))) { @@ -3868,35 +3889,26 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) else source_exc = exc ? exc : R_GetDefaultColormap(); - if (line->flags & ML_EFFECT3) // relative calc + if (line->args[3] & 1) // relative calc { exc = R_AddColormaps( source_exc, - sides[line->sidenum[0]].colormap_data, - line->flags & ML_EFFECT1, // subtract R - line->flags & ML_NOCLIMB, // subtract G - line->flags & ML_EFFECT2, // subtract B - false, // subtract A (no flag for this, just pass negative alpha) - line->flags & ML_EFFECT1, // subtract FadeR - line->flags & ML_NOCLIMB, // subtract FadeG - line->flags & ML_EFFECT2, // subtract FadeB - false, // subtract FadeA (no flag for this, just pass negative alpha) - false, // subtract FadeStart (we ran out of flags) - false, // subtract FadeEnd (we ran out of flags) - false, // ignore Flags (we ran out of flags) - line->flags & ML_DONTPEGBOTTOM, - (line->flags & ML_DONTPEGBOTTOM) ? (sides[line->sidenum[0]].textureoffset >> FRACBITS) : 0, - (line->flags & ML_DONTPEGBOTTOM) ? (sides[line->sidenum[0]].rowoffset >> FRACBITS) : 0, + dest, + line->args[3] & 2, // subtract R + line->args[3] & 4, // subtract G + line->args[3] & 8, // subtract B + line->args[3] & 16, // subtract A + line->args[3] & 32, // subtract FadeR + line->args[3] & 64, // subtract FadeG + line->args[3] & 128, // subtract FadeB + line->args[3] & 256, // subtract FadeA + line->args[3] & 512, // subtract FadeStart + line->args[3] & 1024, // subtract FadeEnd + line->args[3] & 2048, // ignore Flags false); } - else if (line->flags & ML_DONTPEGBOTTOM) // alternate alpha (by texture offsets) - { - exc = R_CopyColormap(sides[line->sidenum[0]].colormap_data, false); - exc->rgba = R_GetRgbaRGB(exc->rgba) + R_PutRgbaA(max(min(sides[line->sidenum[0]].textureoffset >> FRACBITS, 25), 0)); - exc->fadergba = R_GetRgbaRGB(exc->fadergba) + R_PutRgbaA(max(min(sides[line->sidenum[0]].rowoffset >> FRACBITS, 25), 0)); - } else - exc = R_CopyColormap(sides[line->sidenum[0]].colormap_data, false); + exc = R_CopyColormap(dest, false); if (!(dest_exc = R_GetColormapFromList(exc))) { @@ -3907,13 +3919,13 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) else Z_Free(exc); - Add_ColormapFader(§ors[secnum], source_exc, dest_exc, (line->flags & ML_EFFECT4), // tic-based timing - speed); + Add_ColormapFader(§ors[secnum], source_exc, dest_exc, true, // tic-based timing + line->args[2]); } break; - + } case 456: // Stop fade colormap - for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + for (secnum = -1; (secnum = P_FindSectorFromTag(line->args[0], secnum)) >= 0 ;) P_ResetColormapFader(§ors[secnum]); break; @@ -7398,8 +7410,28 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 606: // HACK! Copy colormaps. Just plain colormaps. - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) - sectors[s].extra_colormap = sectors[s].spawn_extra_colormap = sides[lines[i].sidenum[0]].colormap_data; + for (s = -1; (s = P_FindSectorFromTag(lines[i].args[0], s)) >= 0;) + { + extracolormap_t *exc; + if (!udmf) + exc = sides[lines[i].sidenum[0]].colormap_data; + else + { + if (!lines[i].args[1]) + exc = lines[i].frontsector->extra_colormap; + else + { + INT32 sourcesec = P_FindSectorFromTag(lines[i].args[1], -1); + if (sourcesec == -1) + { + CONS_Debug(DBG_GAMELOGIC, "Line type 606: Can't find sector with source colormap (tag %d)!\n", lines[i].args[1]); + return; + } + exc = sectors[sourcesec].extra_colormap; + } + } + sectors[s].extra_colormap = sectors[s].spawn_extra_colormap = exc; + } break; default: diff --git a/src/r_data.c b/src/r_data.c index 031731873..db6c13d0f 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -2373,7 +2373,6 @@ extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *ex boolean subR, boolean subG, boolean subB, boolean subA, boolean subFadeR, boolean subFadeG, boolean subFadeB, boolean subFadeA, boolean subFadeStart, boolean subFadeEnd, boolean ignoreFlags, - boolean useAltAlpha, INT16 altAlpha, INT16 altFadeAlpha, boolean lighttable) { INT16 red, green, blue, alpha; @@ -2409,7 +2408,7 @@ extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *ex * R_GetRgbaB(exc_addend->rgba) , 255), 0); - alpha = useAltAlpha ? altAlpha : R_GetRgbaA(exc_addend->rgba); + alpha = R_GetRgbaA(exc_addend->rgba); alpha = max(min(R_GetRgbaA(exc_augend->rgba) + (subA ? -1 : 1) * alpha, 25), 0); exc_augend->rgba = R_PutRgbaRGBA(red, green, blue, alpha); @@ -2436,8 +2435,8 @@ extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *ex * R_GetRgbaB(exc_addend->fadergba) , 255), 0); - alpha = useAltAlpha ? altFadeAlpha : R_GetRgbaA(exc_addend->fadergba); - if (alpha == 25 && !useAltAlpha && !R_GetRgbaRGB(exc_addend->fadergba)) + alpha = R_GetRgbaA(exc_addend->fadergba); + if (alpha == 25 && !R_GetRgbaRGB(exc_addend->fadergba)) alpha = 0; // HACK: fadergba A defaults at 25, so don't add anything in this case alpha = max(min(R_GetRgbaA(exc_augend->fadergba) + (subFadeA ? -1 : 1) * alpha, 25), 0); diff --git a/src/r_data.h b/src/r_data.h index c2c38be05..87e2a05bc 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -153,7 +153,6 @@ extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *ex boolean subR, boolean subG, boolean subB, boolean subA, boolean subFadeR, boolean subFadeG, boolean subFadeB, boolean subFadeA, boolean subFadeStart, boolean subFadeEnd, boolean ignoreFlags, - boolean useAltAlpha, INT16 altAlpha, INT16 altFadeAlpha, boolean lighttable); #ifdef EXTRACOLORMAPLUMPS extracolormap_t *R_ColormapForName(char *name); From 0ecf8616ba9046133b835c5b43c6244bdccf13b4 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Fri, 20 Mar 2020 12:19:02 +0100 Subject: [PATCH 3/4] Add sector flag that protects the colormap from being changed --- src/p_setup.c | 6 ++++++ src/p_spec.c | 12 +++++++++++- src/r_defs.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 3a70b8af3..56bfb2444 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -947,6 +947,8 @@ static void P_LoadSectors(UINT8 *data) ss->floorpic_angle = ss->ceilingpic_angle = 0; + ss->colormap_protected = false; + P_InitializeSector(ss); } } @@ -1468,6 +1470,8 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) textmap_colormap.used = true; textmap_colormap.flags |= CMF_FADEFULLBRIGHTSPRITES; } + else if (fastcmp(param, "colormapprotected") && fastcmp("true", val)) + sectors[i].colormap_protected = true; } static void ParseTextmapSidedefParameter(UINT32 i, char *param, char *val) @@ -1702,6 +1706,8 @@ static void P_LoadTextmap(void) sc->floorpic_angle = sc->ceilingpic_angle = 0; + sc->colormap_protected = false; + textmap_colormap.used = false; textmap_colormap.lightcolor = 0; textmap_colormap.lightalpha = 25; diff --git a/src/p_spec.c b/src/p_spec.c index 2cd76f129..1b41ae015 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3518,6 +3518,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (secnum = -1; (secnum = P_FindSectorFromTag(line->args[0], secnum)) >= 0;) { + if (sectors[secnum].colormap_protected) + continue; + P_ResetColormapFader(§ors[secnum]); if (line->args[2] & 1) // relative calc @@ -3852,6 +3855,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { extracolormap_t *source_exc, *dest_exc, *exc; + if (sectors[secnum].colormap_protected) + continue; + // Don't interrupt ongoing fade if (!(line->args[3] & 8192) && sectors[secnum].fadecolormapdata) @@ -7413,6 +7419,10 @@ void P_SpawnSpecials(boolean fromnetsave) for (s = -1; (s = P_FindSectorFromTag(lines[i].args[0], s)) >= 0;) { extracolormap_t *exc; + + if (sectors[s].colormap_protected) + continue; + if (!udmf) exc = sides[lines[i].sidenum[0]].colormap_data; else @@ -8370,7 +8380,7 @@ static void P_AddFakeFloorFader(ffloor_t *rover, size_t sectornum, size_t ffloor d->destlightlevel = -1; // Set a separate thinker for colormap fading - if (docolormap && !(rover->flags & FF_NOSHADE) && sectors[rover->secnum].spawn_extra_colormap) + if (docolormap && !(rover->flags & FF_NOSHADE) && sectors[rover->secnum].spawn_extra_colormap && !sectors[rover->secnum].colormap_protected) { extracolormap_t *dest_exc, *source_exc = sectors[rover->secnum].extra_colormap ? sectors[rover->secnum].extra_colormap : R_GetDefaultColormap(); diff --git a/src/r_defs.h b/src/r_defs.h index c51f420ff..0f85c9a57 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -352,6 +352,7 @@ typedef struct sector_s // per-sector colormaps! extracolormap_t *extra_colormap; + boolean colormap_protected; #ifdef HWRENDER // ----- for special tricks with HW renderer ----- boolean pseudoSector; From 2a300bcea4d9d5ea5347aefa25fbddefb4d2b270 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Sat, 18 Apr 2020 12:23:01 +0200 Subject: [PATCH 4/4] Fix NULL pointer crash involving stringargs --- src/p_saveg.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_saveg.c b/src/p_saveg.c index 4449a9d2b..34392886d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -787,8 +787,13 @@ static boolean P_AreStringArgsEqual(const line_t *li, const line_t *spawnli) { UINT8 i; for (i = 0; i < NUMLINESTRINGARGS; i++) + { + if (!li->stringargs[i]) + return !spawnli->stringargs[i]; + if (strcmp(li->stringargs[i], spawnli->stringargs[i])) return false; + } return true; }