From 53b92a16011a2e235c9f158c321886017956b080 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 10 Sep 2018 21:56:09 -0400 Subject: [PATCH 01/22] Make default extracolormap on init * Calc fadedist in R_CreateLightTable --- src/p_saveg.c | 5 +---- src/r_data.c | 28 ++++++++++++++++++++++------ src/r_defs.h | 1 - 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 66db8a383..7ee41dffd 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -660,7 +660,6 @@ static void P_NetArchiveWorld(void) { WRITEUINT8(put, ss->extra_colormap->fadestart); WRITEUINT8(put, ss->extra_colormap->fadeend); - WRITEUINT8(put, ss->extra_colormap->fadedist); WRITEUINT8(put, (UINT8)ss->extra_colormap->fog); WRITEUINT8(put, ss->extra_colormap->cr); @@ -880,8 +879,7 @@ static void P_NetUnArchiveWorld(void) //size_t dbg_i = 0; UINT8 fadestart = READUINT8(get), - fadeend = READUINT8(get), - fadedist = READUINT8(get); + fadeend = READUINT8(get); boolean fog = (boolean)READUINT8(get); @@ -952,7 +950,6 @@ static void P_NetUnArchiveWorld(void) exc->fadestart = fadestart; exc->fadeend = fadeend; - exc->fadedist = fadedist; exc->fog = fog; exc->cr = cr; diff --git a/src/r_data.c b/src/r_data.c index e51eb32e9..f1f04b2d2 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1330,7 +1330,25 @@ void R_ClearColormaps(void) memset(exc, 0, sizeof(*exc)); } - extra_colormaps = NULL; + // make a default extra_colormap + exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL); + exc->cr = exc->cg = exc->cb = 0xff; + exc->ca = 0; + exc->cfr = exc->cfg = exc->cfb = 0; + exc->cfa = 18; + exc->fadestart = 0; + exc->fadeend = 31; + exc->fog = 0; + exc->rgba = 0; + exc->fadergba = 0x19000000; + exc->colormap = R_CreateLightTable(exc); +#ifdef EXTRACOLORMAPLUMPS + exc->lump = LUMPERROR; + exc->lumpname[0] = 0; +#endif + exc->next = exc->prev = NULL; + + extra_colormaps = exc; } // @@ -1427,8 +1445,8 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) cfb = extra_colormap->cfb; // cfa = extra_colormap->cfa; // unused in software - UINT32 fadestart = (UINT16)extra_colormap->fadestart, - fadedist = extra_colormap->fadedist; + UINT8 fadestart = extra_colormap->fadestart, + fadedist = extra_colormap->fadeend - extra_colormap->fadestart; lighttable_t *lighttable = NULL; size_t i; @@ -1548,7 +1566,7 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) extracolormap_t *extra_colormap, *exc; UINT8 cr, cg, cb, ca, cfr, cfg, cfb, cfa; - UINT32 fadestart = 0, fadeend = 31, fadedist = 31; + UINT32 fadestart = 0, fadeend = 31; INT32 rgba, fadergba; @@ -1596,7 +1614,6 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) fadestart = 0; if (fadeend > 31 || fadeend < 1) fadeend = 31; - fadedist = fadeend - fadestart; fog = (boolean)NUMFROMCHAR(p2[1]); } #undef NUMFROMCHAR @@ -1662,7 +1679,6 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) extra_colormap->fadestart = (UINT16)fadestart; extra_colormap->fadeend = (UINT16)fadeend; - extra_colormap->fadedist = fadedist; extra_colormap->fog = fog; extra_colormap->cr = cr; diff --git a/src/r_defs.h b/src/r_defs.h index 8dd34cd15..22d4fdf14 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -53,7 +53,6 @@ typedef UINT8 lighttable_t; typedef struct extracolormap_s { UINT8 fadestart, fadeend; - UINT8 fadedist; boolean fog; // rgba for colormap table generation From 9038ba4d9c941d4ae0d06c418d115cbb7b3ffe75 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 10 Sep 2018 22:35:03 -0400 Subject: [PATCH 02/22] Add COLORMAPREVERSELIST ifdef to toggle Newest -> Oldest extra_colormaps order --- src/r_data.c | 7 +++++++ src/r_data.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/r_data.c b/src/r_data.c index f1f04b2d2..160539437 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1369,11 +1369,18 @@ void R_AddColormapToList(extracolormap_t *extra_colormap) return; } +#ifdef COLORMAPREVERSELIST + extra_colormaps->prev = extra_colormap; + extra_colormap->next = extra_colormaps; + extra_colormaps = extra_colormap; + extra_colormap->prev = 0; +#else for (exc = extra_colormaps; exc->next; exc = exc->next); exc->next = extra_colormap; extra_colormap->prev = exc; extra_colormap->next = 0; +#endif } #ifdef EXTRACOLORMAPLUMPS diff --git a/src/r_data.h b/src/r_data.h index 5600d36dc..e6eec41b4 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -100,6 +100,9 @@ INT32 R_CheckTextureNumForName(const char *name); // Uncomment to enable //#define EXTRACOLORMAPLUMPS +// Uncomment to make extra_colormaps order Newest -> Oldest +//#define COLORMAPREVERSELIST + void R_ReInitColormaps(UINT16 num); void R_ClearColormaps(void); void R_AddColormapToList(extracolormap_t *extra_colormap); From 56b947ae95afe2ea1767ef3a82aac3fb4197e2e7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 13:10:14 -0400 Subject: [PATCH 03/22] Remove cr/cg/cb/ca in favor of rgba * Change default colormap values to be in sync with rgba/fadergba --- src/p_saveg.c | 51 +++++---------------------------------- src/r_data.c | 66 +++++++++++++-------------------------------------- src/r_defs.h | 6 ++--- 3 files changed, 24 insertions(+), 99 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 7ee41dffd..710c24821 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -662,15 +662,6 @@ static void P_NetArchiveWorld(void) WRITEUINT8(put, ss->extra_colormap->fadeend); WRITEUINT8(put, (UINT8)ss->extra_colormap->fog); - WRITEUINT8(put, ss->extra_colormap->cr); - WRITEUINT8(put, ss->extra_colormap->cg); - WRITEUINT8(put, ss->extra_colormap->cb); - WRITEUINT8(put, ss->extra_colormap->ca); - WRITEUINT8(put, ss->extra_colormap->cfr); - WRITEUINT8(put, ss->extra_colormap->cfg); - WRITEUINT8(put, ss->extra_colormap->cfb); - WRITEUINT8(put, ss->extra_colormap->cfa); - WRITEINT32(put, ss->extra_colormap->rgba); WRITEINT32(put, ss->extra_colormap->fadergba); @@ -883,15 +874,6 @@ static void P_NetUnArchiveWorld(void) boolean fog = (boolean)READUINT8(get); - UINT8 cr = READUINT8(get), - cg = READUINT8(get), - cb = READUINT8(get), - ca = READUINT8(get), - cfr = READUINT8(get), - cfg = READUINT8(get), - cfb = READUINT8(get), - cfa = READUINT8(get); - INT32 rgba = READINT32(get), fadergba = READINT32(get); @@ -905,20 +887,6 @@ static void P_NetUnArchiveWorld(void) { #endif - for (exc = extra_colormaps; exc; exc = exc->next) - { -#ifdef EXTRACOLORMAPLUMPS - if (exc->lump != LUMPERROR) - continue; -#endif - if (cr == exc->cr && cg == exc->cg && cb == exc->cb && ca == exc->ca - && cfr == exc->cfr && cfg == exc->cfg && cfb == exc->cfb && cfa == exc->cfa - && fadestart == exc->fadestart - && fadeend == exc->fadeend - && fog == exc->fog) - break; - } - for (exc = extra_colormaps; exc; exc = exc->next) { #ifdef EXTRACOLORMAPLUMPS @@ -928,14 +896,15 @@ static void P_NetUnArchiveWorld(void) continue; } #endif - if (cr == exc->cr && cg == exc->cg && cb == exc->cb && ca == exc->ca - && cfr == exc->cfr && cfg == exc->cfg && cfb == exc->cfb && cfa == exc->cfa + if (rgba == exc->rgba + && fadergba == exc->fadergba && fadestart == exc->fadestart && fadeend == exc->fadeend && fog == exc->fog) { // CONS_Debug(DBG_RENDER, "P_NetUnArchiveWorld: Found map %d: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", - // dbg_i, cr, cg, cb, ca, cfr, cfg, cfb, cfa); + // dbg_i, (rgba)&0xFF, (rgba>>8)&0xFF, (rgba>>16)&0xFF, (rgba>>24)&0xFF, + // (fadergba)&0xFF, (fadergba>>8)&0xFF, (fadergba>>16)&0xFF, (fadergba>>24)&0xFF); break; } //dbg_i++; @@ -944,7 +913,8 @@ static void P_NetUnArchiveWorld(void) if (!exc) { // CONS_Debug(DBG_RENDER, "P_NetUnArchiveWorld: Creating map %d: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", - // dbg_i, cr, cg, cb, ca, cfr, cfg, cfb, cfa); + // dbg_i, (rgba)&0xFF, (rgba>>8)&0xFF, (rgba>>16)&0xFF, (rgba>>24)&0xFF, + // (fadergba)&0xFF, (fadergba>>8)&0xFF, (fadergba>>16)&0xFF, (fadergba>>24)&0xFF); exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL); @@ -952,15 +922,6 @@ static void P_NetUnArchiveWorld(void) exc->fadeend = fadeend; exc->fog = fog; - exc->cr = cr; - exc->cg = cg; - exc->cb = cb; - exc->ca = ca; - exc->cfr = cfr; - exc->cfg = cfg; - exc->cfb = cfb; - exc->cfa = cfa; - exc->rgba = rgba; exc->fadergba = fadergba; diff --git a/src/r_data.c b/src/r_data.c index ffc6cc7fd..005056ec0 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1332,10 +1332,6 @@ void R_ClearColormaps(void) // make a default extra_colormap exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL); - exc->cr = exc->cg = exc->cb = 0xff; - exc->ca = 0; - exc->cfr = exc->cfg = exc->cfb = 0; - exc->cfa = 18; exc->fadestart = 0; exc->fadeend = 31; exc->fog = 0; @@ -1411,10 +1407,6 @@ extracolormap_t *R_ColormapForName(char *name) // We set all params of the colormap to normal because there // is no real way to tell how GL should handle a colormap lump anyway.. - exc->cr = exc->cg = exc->cb = 0xff; - exc->ca = 0; - exc->cfr = exc->cfg = exc->cfb = 0; - exc->cfa = 18; exc->fadestart = 0; exc->fadeend = 31; exc->fog = 0; @@ -1445,14 +1437,14 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; double maskamt = 0, othermask = 0; - UINT8 cr = extra_colormap->cr, - cg = extra_colormap->cg, - cb = extra_colormap->cb, - ca = extra_colormap->ca, - cfr = extra_colormap->cfr, - cfg = extra_colormap->cfg, - cfb = extra_colormap->cfb; -// cfa = extra_colormap->cfa; // unused in software + UINT8 cr = (extra_colormap->rgba) & 0xFF, + cg = (extra_colormap->rgba >> 8) & 0xFF, + cb = (extra_colormap->rgba >> 16) & 0xFF, + ca = (extra_colormap->rgba >> 24) & 0xFF, + cfr = (extra_colormap->fadergba) & 0xFF, + cfg = (extra_colormap->fadergba >> 8) & 0xFF, + cfb = (extra_colormap->fadergba >> 16) & 0xFF; +// cfa = (extra_colormap->fadergba >> 24) & 0xFF; // unused in software UINT8 fadestart = extra_colormap->fadestart, fadedist = extra_colormap->fadeend - extra_colormap->fadestart; @@ -1594,22 +1586,13 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) else if (p1[7] >= 'A' && p1[7] <= 'Z') ca = (p1[7] - 'A'); else - ca = 24; + ca = 25; - // for opengl; generate on software too for netsync - rgba = (HEX2INT(p1[1]) << 4) + (HEX2INT(p1[2]) << 0) + - (HEX2INT(p1[3]) << 12) + (HEX2INT(p1[4]) << 8) + - (HEX2INT(p1[5]) << 20) + (HEX2INT(p1[6]) << 16); - - if ((p1[7] >= 'a' && p1[7] <= 'z') || (p1[7] >= 'A' && p1[7] <= 'Z')) - rgba += (ALPHA2INT(p1[7]) << 24); - else - rgba += (25 << 24); + rgba = cr + (cg << 8) + (cb << 16) + (ca << 24); } else { - cr = cg = cb = 0xff; - ca = 0; + cr = cg = cb = ca = 0; rgba = 0; } @@ -1638,22 +1621,14 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) else if (p1[7] >= 'A' && p1[7] <= 'Z') cfa = (p1[7] - 'A'); else - cfa = 18; + cfa = 25; - // for opengl; generate on software too for netsync - fadergba = (HEX2INT(p3[1]) << 4) + (HEX2INT(p3[2]) << 0) + - (HEX2INT(p3[3]) << 12) + (HEX2INT(p3[4]) << 8) + - (HEX2INT(p3[5]) << 20) + (HEX2INT(p3[6]) << 16); - - if ((p3[7] >= 'a' && p3[7] <= 'z') || (p3[7] >= 'A' && p3[7] <= 'Z')) - fadergba += (ALPHA2INT(p3[7]) << 24); - else - fadergba += (25 << 24); + fadergba = cfr + (cfg << 8) + (cfb << 16) + (cfa << 24); } else { cfr = cfg = cfb = 0; - cfa = 18; + cfa = 25; fadergba = 0x19000000; // default alpha for fade, (25 << 24) } #undef ALPHA2INT @@ -1668,8 +1643,8 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) continue; } #endif - if (cr == exc->cr && cg == exc->cg && cb == exc->cb && ca == exc->ca - && cfr == exc->cfr && cfg == exc->cfg && cfb == exc->cfb && cfa == exc->cfa + if (rgba == exc->rgba + && fadergba == exc->fadergba && fadestart == exc->fadestart && fadeend == exc->fadeend && fog == exc->fog) @@ -1690,15 +1665,6 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) extra_colormap->fadeend = (UINT16)fadeend; extra_colormap->fog = fog; - extra_colormap->cr = cr; - extra_colormap->cg = cg; - extra_colormap->cb = cb; - extra_colormap->ca = ca; - extra_colormap->cfr = cfr; - extra_colormap->cfg = cfg; - extra_colormap->cfb = cfb; - extra_colormap->cfa = cfa; - extra_colormap->rgba = rgba; extra_colormap->fadergba = fadergba; diff --git a/src/r_defs.h b/src/r_defs.h index 22d4fdf14..99fad2b44 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -55,10 +55,8 @@ typedef struct extracolormap_s UINT8 fadestart, fadeend; boolean fog; - // rgba for colormap table generation - UINT8 cr, cg, cb, ca, cfr, cfg, cfb, cfa; - - // rgba is used in hw mode for colored sector lighting + // store rgba values in combined bitwise + // also used in OpenGL instead lighttables INT32 rgba; // similar to maskcolor in sw mode INT32 fadergba; // The colour the colourmaps fade to From ead14becd7184340102fbf5d5fc0d72a8be85053 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 22:34:29 -0400 Subject: [PATCH 04/22] Add R_CheckEqualColormaps comparison method --- src/r_data.c | 27 +++++++++++++++++++++++++++ src/r_data.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/r_data.c b/src/r_data.c index c84e61fce..1de51fedd 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1472,6 +1472,33 @@ boolean R_CheckDefaultColormap(extracolormap_t *extra_colormap, boolean checkrgb #endif } +boolean R_CheckEqualColormaps(extracolormap_t *exc_a, extracolormap_t *exc_b, boolean checkrgba, boolean checkfadergba, boolean checkparams) +{ + // Treat NULL as default colormap + // We need this because what if one exc is a default colormap, and the other is NULL? They're really both equal. + if (!exc_a) + exc_a = R_GetDefaultColormap(); + if (!exc_b) + exc_b = R_GetDefaultColormap(); + + if (exc_a == exc_b) + return true; + + return ( + (!checkparams ? true : + (exc_a->fadestart == exc_b->fadestart + && exc_a->fadeend == exc_b->fadeend + && exc_a->fog == exc_b->fog) + ) + && (!checkrgba ? true : exc_a->rgba == exc_b->rgba) + && (!checkfadergba ? true : exc_a->fadergba == exc_b->fadergba) +#ifdef EXTRACOLORMAPLUMPS + && exc_a->lump == exc_b->lump + && !strncmp(exc_a->lumpname, exc_b->lumpname, 9) +#endif + ); +} + // // R_GetColormapFromListByValues() // NOTE: Returns NULL if no match is found diff --git a/src/r_data.h b/src/r_data.h index 6f8d08120..f6db2953d 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -120,6 +120,7 @@ boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, boolean fog); #endif boolean R_CheckDefaultColormap(extracolormap_t *extra_colormap, boolean checkrgba, boolean checkfadergba, boolean checkparams); +boolean R_CheckEqualColormaps(extracolormap_t *exc_a, extracolormap_t *exc_b); extracolormap_t *R_GetColormapFromList(extracolormap_t *extra_colormap); lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap); From 14b71bdbc574c9255fb7a2eca5cfca3ba24ad36b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 09:06:38 -0400 Subject: [PATCH 05/22] Fade colormap special 455! And stop fade colormap 456 * Added T_FadeColormap thinker and netsync * Added sector_t fadecolormapdata property --- src/p_saveg.c | 47 ++++++++++++- src/p_setup.c | 1 + src/p_spec.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/p_spec.h | 14 ++++ src/r_defs.h | 1 + 5 files changed, 251 insertions(+), 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index fc767d9cf..b3953c53c 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1099,6 +1099,7 @@ typedef enum tc_noenemies, tc_eachtime, tc_disappear, + tc_fadecolormap, tc_planedisplace, #ifdef POLYOBJECTS tc_polyrotate, // haleyjd 03/26/06: polyobjects @@ -1663,6 +1664,22 @@ static void SaveDisappearThinker(const thinker_t *th, const UINT8 type) WRITEINT32(save_p, ht->exists); } +// +// SaveFadeColormapThinker +// +// Saves a fadecolormap_t thinker +// +static void SaveFadeColormapThinker(const thinker_t *th, const UINT8 type) +{ + const fadecolormap_t *ht = (const void *)th; + WRITEUINT8(save_p, type); + WRITEUINT32(save_p, SaveSector(ht->sector)); + SaveExtraColormap(save_p, ht->source_exc); + SaveExtraColormap(save_p, ht->dest_exc); + WRITEINT32(save_p, ht->duration); + WRITEINT32(save_p, ht->timer); +} + // // SavePlaneDisplaceThinker // @@ -1965,6 +1982,11 @@ static void P_NetArchiveThinkers(void) SaveDisappearThinker(th, tc_disappear); continue; } + else if (th->function.acp1 == (actionf_p1)T_FadeColormap) + { + SaveFadeColormapThinker(th, tc_fadecolormap); + continue; + } else if (th->function.acp1 == (actionf_p1)T_PlaneDisplace) { @@ -2641,6 +2663,25 @@ static inline void LoadDisappearThinker(actionf_p1 thinker) P_AddThinker(&ht->thinker); } +// +// LoadFadeColormapThinker +// +// Loads a fadecolormap_t from a save game +// +static inline void LoadFadeColormapThinker(actionf_p1 thinker) +{ + fadecolormap_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); + ht->thinker.function.acp1 = thinker; + ht->sector = LoadSector(READUINT32(save_p)); + ht->source_exc = LoadExtraColormap(save_p); + ht->dest_exc = LoadExtraColormap(save_p); + ht->duration = READINT32(save_p); + ht->timer = READINT32(save_p); + if (ht->sector) + ht->sector->fadecolormapdata = ht; + P_AddThinker(&ht->thinker); +} + // // LoadPlaneDisplaceThinker // @@ -2827,7 +2868,7 @@ static void P_NetUnArchiveThinkers(void) // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) { - sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = NULL; + sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; } // read in saved thinkers @@ -2944,6 +2985,10 @@ static void P_NetUnArchiveThinkers(void) LoadDisappearThinker((actionf_p1)T_Disappear); break; + case tc_fadecolormap: + LoadFadeColormapThinker((actionf_p1)T_FadeColormap); + break; + case tc_planedisplace: LoadPlaneDisplaceThinker((actionf_p1)T_PlaneDisplace); break; diff --git a/src/p_setup.c b/src/p_setup.c index c08c2ac58..b26459759 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1466,6 +1466,7 @@ static void P_LoadRawSideDefs2(void *data) { case 63: // variable colormap via 242 linedef case 606: //SoM: 4/4/2000: Just colormap transfer + 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. sec->extra_colormap = sec->spawn_extra_colormap = R_CreateColormap(msd->toptexture, msd->midtexture, diff --git a/src/p_spec.c b/src/p_spec.c index 5135676ab..e20d85af6 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -103,6 +103,9 @@ static void P_SpawnFriction(void); static void P_SpawnPushers(void); static void Add_Pusher(pushertype_e type, fixed_t x_mag, fixed_t y_mag, mobj_t *source, INT32 affectee, INT32 referrer, INT32 exclusive, INT32 slider); //SoM: 3/9/2000 static void Add_MasterDisappearer(tic_t appeartime, tic_t disappeartime, tic_t offset, INT32 line, INT32 sourceline); +static void P_ResetColormapFader(sector_t *sector); +static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, extracolormap_t *dest_exc, + INT32 duration); static void P_AddBlockThinker(sector_t *sec, line_t *sourceline); static void P_AddFloatThinker(sector_t *sec, INT32 tag, line_t *sourceline); //static void P_AddBridgeThinker(line_t *sourceline, sector_t *sec); @@ -3310,6 +3313,82 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; } + case 455: // Fade colormap + for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + { + extracolormap_t *source_exc, *dest_exc, *exc; + + exc = (line->flags & ML_TFERLINE) ? line->backsector->extra_colormap // TFERLINE: use back colormap instead of target sector + : sectors[secnum].extra_colormap; + + if (!(line->flags & ML_BOUNCY) // BOUNCY: Do not override fade from default rgba + && !R_CheckDefaultColormap(line->frontsector->extra_colormap, true, false, false) + && R_CheckDefaultColormap(exc, true, false, false)) + { + exc = R_CopyColormap(exc, false); + exc->rgba = R_GetRgbaRGB(line->frontsector->extra_colormap->rgba) + R_PutRgbaA(R_GetRgbaA(exc->rgba)); + exc->fadergba = R_GetRgbaRGB(line->frontsector->extra_colormap->rgba) + R_PutRgbaA(R_GetRgbaA(exc->fadergba)); + + if (!(source_exc = R_GetColormapFromList(exc))) + { + exc->colormap = R_CreateLightTable(exc); + R_AddColormapToList(exc); + source_exc = exc; + } + else + Z_Free(exc); + } + else + source_exc = exc; + + if (line->flags & ML_EFFECT3) // relative calc + { + exc = R_AddColormaps( + source_exc, + line->frontsector->extra_colormap, + 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 Fog (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); + } + else if (line->flags & ML_DONTPEGBOTTOM) // alternate alpha (by texture offsets) + { + exc = R_CopyColormap(line->frontsector->extra_colormap, 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(line->frontsector->extra_colormap, false); + + if (!(dest_exc = R_GetColormapFromList(exc))) + { + exc->colormap = R_CreateLightTable(exc); + R_AddColormapToList(exc); + dest_exc = exc; + } + else + Z_Free(exc); + + Add_ColormapFader(§ors[secnum], source_exc, dest_exc, + (line->sidenum[1] != 0xFFFF ? abs(sides[line->sidenum[1]].rowoffset >> FRACBITS) : abs(P_AproxDistance(line->dx, line->dy) >> FRACBITS))); + } + break; + + case 456: // Stop fade colormap + for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + P_ResetColormapFader(§ors[secnum]); + #ifdef POLYOBJECTS case 480: // Polyobj_DoorSlide case 481: // Polyobj_DoorSwing @@ -7322,6 +7401,116 @@ void T_Disappear(disappear_t *d) } } +static void P_ResetColormapFader(sector_t *sector) +{ + if (sector->fadecolormapdata) + { + // The thinker is the first member in all the action structs, + // so just let the thinker get freed, and that will free the whole + // structure. + P_RemoveThinker(&((elevator_t *)sector->fadecolormapdata)->thinker); + sector->fadecolormapdata = NULL; + } +} + +static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, extracolormap_t *dest_exc, + INT32 duration) +{ + P_ResetColormapFader(sector); + + // nothing to do, set immediately + if (!duration || R_CheckEqualColormaps(source_exc, dest_exc, true, true, true)) + { + sector->extra_colormap = dest_exc; + return; + } + + fadecolormap_t *d = Z_Malloc(sizeof *d, PU_LEVSPEC, NULL); + d->thinker.function.acp1 = (actionf_p1)T_FadeColormap; + d->sector = sector; + d->source_exc = source_exc; + d->dest_exc = dest_exc; + d->duration = d->timer = duration; + + sector->fadecolormapdata = d; + P_AddThinker(&d->thinker); // add thinker +} + +void T_FadeColormap(fadecolormap_t *d) +{ + if (--d->timer <= 0) + { + d->sector->extra_colormap = d->dest_exc; + P_ResetColormapFader(d->sector); + } + else + { + extracolormap_t *exc; + fixed_t factor = min(FixedDiv(d->duration - d->timer, d->duration), 1*FRACUNIT); + INT16 cr, cg, cb, ca, fadestart, fadeend, fog; + INT32 rgba, fadergba; + + // For each var (rgba + fadergba + params = 11 vars), we apply + // percentage fading: currentval = sourceval + (delta * percent of duration elapsed) + // delta is negative when fading out (destval is lower) + // max/min are used to ensure progressive calcs don't go backwards and to cap values to dest. + +#define APPLYFADE(dest, src, cur) (\ +(dest-src < 0) ? \ + max(\ + min(cur,\ + src + (UINT8)FixedMul(dest-src, factor)),\ + dest)\ +: (dest-src > 0) ? \ + min(\ + max(cur,\ + src + (UINT8)FixedMul(dest-src, factor)),\ + dest)\ +: \ + dest\ +) + + cr = APPLYFADE(R_GetRgbaR(d->dest_exc->rgba), R_GetRgbaR(d->source_exc->rgba), R_GetRgbaR(d->sector->extra_colormap->rgba)); + cg = APPLYFADE(R_GetRgbaG(d->dest_exc->rgba), R_GetRgbaG(d->source_exc->rgba), R_GetRgbaG(d->sector->extra_colormap->rgba)); + cb = APPLYFADE(R_GetRgbaB(d->dest_exc->rgba), R_GetRgbaB(d->source_exc->rgba), R_GetRgbaB(d->sector->extra_colormap->rgba)); + ca = APPLYFADE(R_GetRgbaA(d->dest_exc->rgba), R_GetRgbaA(d->source_exc->rgba), R_GetRgbaA(d->sector->extra_colormap->rgba)); + + rgba = R_PutRgbaRGBA(cr, cg, cb, ca); + + cr = APPLYFADE(R_GetRgbaR(d->dest_exc->fadergba), R_GetRgbaR(d->source_exc->fadergba), R_GetRgbaR(d->sector->extra_colormap->fadergba)); + cg = APPLYFADE(R_GetRgbaG(d->dest_exc->fadergba), R_GetRgbaG(d->source_exc->fadergba), R_GetRgbaG(d->sector->extra_colormap->fadergba)); + cb = APPLYFADE(R_GetRgbaB(d->dest_exc->fadergba), R_GetRgbaB(d->source_exc->fadergba), R_GetRgbaB(d->sector->extra_colormap->fadergba)); + ca = APPLYFADE(R_GetRgbaA(d->dest_exc->fadergba), R_GetRgbaA(d->source_exc->fadergba), R_GetRgbaA(d->sector->extra_colormap->fadergba)); + + fadergba = R_PutRgbaRGBA(cr, cg, cb, ca); + + fadestart = APPLYFADE(d->dest_exc->fadestart, d->source_exc->fadestart, d->sector->extra_colormap->fadestart); + fadeend = APPLYFADE(d->dest_exc->fadeend, d->source_exc->fadeend, d->sector->extra_colormap->fadeend); + // fog: essentially we're switching from source_exc->fog to dest_exc->fog with a delta + // of 1 or -1, and hoping the factor rounds appropriately in the timing. + fog = APPLYFADE(d->dest_exc->fog, d->source_exc->fog, d->sector->extra_colormap->fog); + +#undef APPLYFADE + + ////////////////// + // setup new colormap + ////////////////// + + if (!(d->sector->extra_colormap = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, fog))) + { + exc = R_CreateDefaultColormap(false); + exc->fadestart = fadestart; + exc->fadeend = fadeend; + exc->fog = (boolean)fog; + exc->rgba = rgba; + exc->fadergba = fadergba; + exc->colormap = R_CreateLightTable(exc); + R_AddColormapToList(exc); + d->sector->extra_colormap = exc; + } + } +} + /* SoM: 3/8/2000: Friction functions start. Add_Friction, diff --git a/src/p_spec.h b/src/p_spec.h index e0bcc18eb..9e0b7d5c4 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -453,6 +453,20 @@ typedef struct void T_Disappear(disappear_t *d); +// Model for fading colormaps + +typedef struct +{ + thinker_t thinker; ///< Thinker structure for effect. + sector_t *sector; ///< Sector where action is taking place. + extracolormap_t *source_exc; + extracolormap_t *dest_exc; + INT32 duration; ///< Total duration for tic-based logic + INT32 timer; ///< Timer for tic-based logic +} fadecolormap_t; + +void T_FadeColormap(fadecolormap_t *d); + // Prototype functions for pushers void T_Pusher(pusher_t *p); mobj_t *P_GetPushThing(UINT32 s); diff --git a/src/r_defs.h b/src/r_defs.h index 99fad2b44..8c610cd4d 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -315,6 +315,7 @@ typedef struct sector_s void *floordata; // floor move thinker void *ceilingdata; // ceiling move thinker void *lightingdata; // lighting change thinker + void *fadecolormapdata; // fade colormap thinker // floor and ceiling texture offsets fixed_t floor_xoffs, floor_yoffs; From 4d9925e8cf2459d8a4e8e81fddd3761dff914aab Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 09:09:10 -0400 Subject: [PATCH 06/22] 447: ResetColormapFader when changing colormap explicitly --- src/p_spec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_spec.c b/src/p_spec.c index 7d6ffaf2a..b38fa37c4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3260,6 +3260,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // -- Monster Iestyn 14/06/18 for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) { + P_ResetColormapFader(§ors[secnum]); + if (line->flags & ML_EFFECT3) // relative calc { extracolormap_t *exc = R_AddColormaps( From 8190433b71fdf258280bb99724d5287259674c45 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 09:42:51 -0400 Subject: [PATCH 07/22] 456: Missing break --- src/p_spec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_spec.c b/src/p_spec.c index b38fa37c4..e8f1c3cb8 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3447,6 +3447,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 456: // Stop fade colormap for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) P_ResetColormapFader(§ors[secnum]); + break; #ifdef POLYOBJECTS case 480: // Polyobj_DoorSlide From e95cd0f962f2567bc060ff981a6f01d1fe81f6fd Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 11:01:12 -0400 Subject: [PATCH 08/22] Colormap savegame failsafe - Handle NULL (default colormap) --- src/p_saveg.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index b3953c53c..c18837e17 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -476,6 +476,9 @@ static void P_NetUnArchivePlayers(void) static void SaveExtraColormap(UINT8 *put, extracolormap_t *exc) { + if (!exc) // Just give it default values, we done goofed. (or sector->extra_colormap was intentionally set to default (NULL)) + exc = R_GetDefaultColormap(); + WRITEUINT8(put, exc->fadestart); WRITEUINT8(put, exc->fadeend); WRITEUINT8(put, (UINT8)exc->fog); @@ -490,7 +493,7 @@ static void SaveExtraColormap(UINT8 *put, extracolormap_t *exc) static extracolormap_t *LoadExtraColormap(UINT8 *get) { - extracolormap_t *exc; + extracolormap_t *exc, *exc_exist; //size_t dbg_i = 0; UINT8 fadestart = READUINT8(get), @@ -525,14 +528,21 @@ static extracolormap_t *LoadExtraColormap(UINT8 *get) exc->rgba = rgba; exc->fadergba = fadergba; - exc->colormap = R_CreateLightTable(exc); - - R_AddColormapToList(exc); - #ifdef EXTRACOLORMAPLUMPS exc->lump = LUMPERROR; exc->lumpname[0] = 0; #endif + + if (!(exc_exist = R_GetColormapFromList(exc))) + { + exc->colormap = R_CreateLightTable(exc); + R_AddColormapToList(exc); + } + else + { + Z_Free(exc); + exc = R_CheckDefaultColormap(exc_exist, true, true, true) ? NULL : exc_exist; + } } return exc; From d85019b4e4db8b9e2806b5a859a12b8ed325a6e7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 11:11:22 -0400 Subject: [PATCH 09/22] More NULL failsafes --- src/p_spec.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index e8f1c3cb8..7ae3c7871 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3396,9 +3396,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } else Z_Free(exc); + + sectors[secnum].extra_colormap = source_exc; } else - source_exc = exc; + source_exc = exc ? exc : R_GetDefaultColormap(); if (line->flags & ML_EFFECT3) // relative calc { @@ -7510,6 +7512,16 @@ void T_FadeColormap(fadecolormap_t *d) INT16 cr, cg, cb, ca, fadestart, fadeend, fog; INT32 rgba, fadergba; + // NULL failsafes (or intentionally set to signify default) + if (!d->sector->extra_colormap) + d->sector->extra_colormap = R_GetDefaultColormap(); + + if (!d->source_exc) + d->source_exc = R_GetDefaultColormap(); + + if (!d->dest_exc) + d->dest_exc = R_GetDefaultColormap(); + // For each var (rgba + fadergba + params = 11 vars), we apply // percentage fading: currentval = sourceval + (delta * percent of duration elapsed) // delta is negative when fading out (destval is lower) From 51a298222649e6e5f7b4564c20c45b57663b0e8e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 11:21:49 -0400 Subject: [PATCH 10/22] 455: TFERLINE - Set target sector's colormap first to control backsector's colormap --- src/p_spec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 7ae3c7871..9e4d38f97 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3377,8 +3377,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { extracolormap_t *source_exc, *dest_exc, *exc; - exc = (line->flags & ML_TFERLINE) ? line->backsector->extra_colormap // TFERLINE: use back colormap instead of target sector - : sectors[secnum].extra_colormap; + if (line->flags & ML_TFERLINE) // use back colormap instead of target sector + sectors[secnum].extra_colormap = line->backsector->extra_colormap; + + exc = sectors[secnum].extra_colormap; if (!(line->flags & ML_BOUNCY) // BOUNCY: Do not override fade from default rgba && !R_CheckDefaultColormap(line->frontsector->extra_colormap, true, false, false) From d2f636d5a2fcc678bbd0018dad00ca235a6f2fb6 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 11:33:44 -0400 Subject: [PATCH 11/22] T_FadeColormap: Fade subtraction error --- src/p_spec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 9e4d38f97..3e428c1f6 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -7533,12 +7533,12 @@ void T_FadeColormap(fadecolormap_t *d) (dest-src < 0) ? \ max(\ min(cur,\ - src + (UINT8)FixedMul(dest-src, factor)),\ + src + (INT16)FixedMul(dest-src, factor)),\ dest)\ : (dest-src > 0) ? \ min(\ max(cur,\ - src + (UINT8)FixedMul(dest-src, factor)),\ + src + (INT16)FixedMul(dest-src, factor)),\ dest)\ : \ dest\ From 05c91f1f81aea11738269d84e5cf5816b56bfe46 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 12 Sep 2018 20:52:05 -0400 Subject: [PATCH 12/22] 455: Change to side->colormap_data --- src/p_spec.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 8797200c2..491671c40 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3379,17 +3379,18 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) extracolormap_t *source_exc, *dest_exc, *exc; if (line->flags & ML_TFERLINE) // use back colormap instead of target sector - sectors[secnum].extra_colormap = line->backsector->extra_colormap; + sectors[secnum].extra_colormap = (line->sidenum[1] != 0xFFFF) ? + 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(line->frontsector->extra_colormap, true, false, false) + && !R_CheckDefaultColormap(sides[line->sidenum[0]].colormap_data, true, false, false) && R_CheckDefaultColormap(exc, true, false, false)) { exc = R_CopyColormap(exc, false); - exc->rgba = R_GetRgbaRGB(line->frontsector->extra_colormap->rgba) + R_PutRgbaA(R_GetRgbaA(exc->rgba)); - exc->fadergba = R_GetRgbaRGB(line->frontsector->extra_colormap->rgba) + R_PutRgbaA(R_GetRgbaA(exc->fadergba)); + 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)); if (!(source_exc = R_GetColormapFromList(exc))) { @@ -3409,7 +3410,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { exc = R_AddColormaps( source_exc, - line->frontsector->extra_colormap, + sides[line->sidenum[0]].colormap_data, line->flags & ML_EFFECT1, // subtract R line->flags & ML_NOCLIMB, // subtract G line->flags & ML_EFFECT2, // subtract B @@ -3428,12 +3429,12 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } else if (line->flags & ML_DONTPEGBOTTOM) // alternate alpha (by texture offsets) { - exc = R_CopyColormap(line->frontsector->extra_colormap, false); + 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(line->frontsector->extra_colormap, false); + exc = R_CopyColormap(sides[line->sidenum[0]].colormap_data, false); if (!(dest_exc = R_GetColormapFromList(exc))) { From 5aa66f887270733ebfe4bb3452fc58c8f4453995 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Sep 2018 10:38:15 -0400 Subject: [PATCH 13/22] 455: Add speed increment timing (~EFFECT4) to FadeColormap --- src/p_saveg.c | 2 ++ src/p_spec.c | 25 +++++++++++++++++++------ src/p_spec.h | 5 +++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 1c8d46aa1..e0d3f1e94 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1687,6 +1687,7 @@ static void SaveFadeColormapThinker(const thinker_t *th, const UINT8 type) WRITEUINT32(save_p, SaveSector(ht->sector)); SaveExtraColormap(save_p, ht->source_exc); SaveExtraColormap(save_p, ht->dest_exc); + WRITEUINT8(save_p, (UINT8)ht->ticbased); WRITEINT32(save_p, ht->duration); WRITEINT32(save_p, ht->timer); } @@ -2686,6 +2687,7 @@ static inline void LoadFadeColormapThinker(actionf_p1 thinker) ht->sector = LoadSector(READUINT32(save_p)); ht->source_exc = LoadExtraColormap(save_p); ht->dest_exc = LoadExtraColormap(save_p); + ht->ticbased = (boolean)READUINT8(save_p); ht->duration = READINT32(save_p); ht->timer = READINT32(save_p); if (ht->sector) diff --git a/src/p_spec.c b/src/p_spec.c index 491671c40..bed5a89b4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -105,7 +105,7 @@ static void Add_Pusher(pushertype_e type, fixed_t x_mag, fixed_t y_mag, mobj_t * static void Add_MasterDisappearer(tic_t appeartime, tic_t disappeartime, tic_t offset, INT32 line, INT32 sourceline); static void P_ResetColormapFader(sector_t *sector); static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, extracolormap_t *dest_exc, - INT32 duration); + boolean ticbased, INT32 duration); static void P_AddBlockThinker(sector_t *sec, line_t *sourceline); static void P_AddFloatThinker(sector_t *sec, INT32 tag, line_t *sourceline); //static void P_AddBridgeThinker(line_t *sourceline, sector_t *sec); @@ -3445,7 +3445,7 @@ 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, + Add_ColormapFader(§ors[secnum], source_exc, dest_exc, (line->flags & ML_EFFECT4), // tic-based timing (line->sidenum[1] != 0xFFFF ? abs(sides[line->sidenum[1]].rowoffset >> FRACBITS) : abs(P_AproxDistance(line->dx, line->dy) >> FRACBITS))); } break; @@ -7480,7 +7480,7 @@ static void P_ResetColormapFader(sector_t *sector) } static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, extracolormap_t *dest_exc, - INT32 duration) + boolean ticbased, INT32 duration) { P_ResetColormapFader(sector); @@ -7496,7 +7496,18 @@ static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, ext d->sector = sector; d->source_exc = source_exc; d->dest_exc = dest_exc; - d->duration = d->timer = duration; + + if (ticbased) + { + d->ticbased = true; + d->duration = d->timer = duration; + } + else + { + d->ticbased = false; + d->timer = 256; + d->duration = duration; // use as speed + } sector->fadecolormapdata = d; P_AddThinker(&d->thinker); // add thinker @@ -7504,7 +7515,8 @@ static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, ext void T_FadeColormap(fadecolormap_t *d) { - if (--d->timer <= 0) + if ((d->ticbased && --d->timer <= 0) + || (!d->ticbased && (d->timer -= d->duration) <= 0)) // d->duration used as speed decrement { d->sector->extra_colormap = d->dest_exc; P_ResetColormapFader(d->sector); @@ -7512,7 +7524,8 @@ void T_FadeColormap(fadecolormap_t *d) else { extracolormap_t *exc; - fixed_t factor = min(FixedDiv(d->duration - d->timer, d->duration), 1*FRACUNIT); + INT32 duration = d->ticbased ? d->duration : 256; + fixed_t factor = min(FixedDiv(duration - d->timer, duration), 1*FRACUNIT); INT16 cr, cg, cb, ca, fadestart, fadeend, fog; INT32 rgba, fadergba; diff --git a/src/p_spec.h b/src/p_spec.h index 9e0b7d5c4..0a798ffcc 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -461,8 +461,9 @@ typedef struct sector_t *sector; ///< Sector where action is taking place. extracolormap_t *source_exc; extracolormap_t *dest_exc; - INT32 duration; ///< Total duration for tic-based logic - INT32 timer; ///< Timer for tic-based logic + boolean ticbased; ///< Tic-based timing + INT32 duration; ///< Total duration for tic-based logic (OR: speed increment) + INT32 timer; ///< Timer for tic-based logic (OR: internal speed counter) } fadecolormap_t; void T_FadeColormap(fadecolormap_t *d); From 94939f661357bdf1c6c20b9894cf9d4aee33637b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Sep 2018 10:41:22 -0400 Subject: [PATCH 14/22] 455: Don't override fadergba on default/no colormap init (~BOUNCY) --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index bed5a89b4..72b215163 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3390,7 +3390,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { 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->fadergba = R_GetRgbaRGB(sides[line->sidenum[0]].colormap_data->rgba) + R_PutRgbaA(R_GetRgbaA(exc->fadergba)); if (!(source_exc = R_GetColormapFromList(exc))) { From 3fc8ed5a9f05d8a387517ae657f7e224cdddb196 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Sep 2018 10:53:03 -0400 Subject: [PATCH 15/22] 455: Set timing by either Back Y or Front Y, but not line length --- src/p_spec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 72b215163..1d213b63e 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3446,7 +3446,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) Z_Free(exc); Add_ColormapFader(§ors[secnum], source_exc, dest_exc, (line->flags & ML_EFFECT4), // tic-based timing - (line->sidenum[1] != 0xFFFF ? abs(sides[line->sidenum[1]].rowoffset >> FRACBITS) : abs(P_AproxDistance(line->dx, line->dy) >> FRACBITS))); + ((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)); } break; From 761150b12d3b0fcf1a7f392d609b4a43e75ae982 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Sep 2018 12:18:10 -0400 Subject: [PATCH 16/22] 455: Fog flag fix for fading --- src/p_spec.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 1d213b63e..88a046b37 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -7577,9 +7577,7 @@ void T_FadeColormap(fadecolormap_t *d) fadestart = APPLYFADE(d->dest_exc->fadestart, d->source_exc->fadestart, d->sector->extra_colormap->fadestart); fadeend = APPLYFADE(d->dest_exc->fadeend, d->source_exc->fadeend, d->sector->extra_colormap->fadeend); - // fog: essentially we're switching from source_exc->fog to dest_exc->fog with a delta - // of 1 or -1, and hoping the factor rounds appropriately in the timing. - fog = APPLYFADE(d->dest_exc->fog, d->source_exc->fog, d->sector->extra_colormap->fog); + fog = abs(factor) > FRACUNIT/2 ? d->dest_exc->fog : d->source_exc->fog; // set new fog flag halfway through fade #undef APPLYFADE From 1db8aee539dea8942dafa30a8281f29f2d8704c8 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 15 Sep 2018 00:51:55 -0400 Subject: [PATCH 17/22] 455: Mixed D+C fix --- src/p_spec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 88a046b37..a408b2140 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -7484,6 +7484,8 @@ static void P_ResetColormapFader(sector_t *sector) static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, extracolormap_t *dest_exc, boolean ticbased, INT32 duration) { + fadecolormap_t *d; + P_ResetColormapFader(sector); // nothing to do, set immediately @@ -7493,7 +7495,7 @@ static void Add_ColormapFader(sector_t *sector, extracolormap_t *source_exc, ext return; } - fadecolormap_t *d = Z_Malloc(sizeof *d, PU_LEVSPEC, NULL); + d = Z_Malloc(sizeof *d, PU_LEVSPEC, NULL); d->thinker.function.acp1 = (actionf_p1)T_FadeColormap; d->sector = sector; d->source_exc = source_exc; From d4a18fd456749c6d3db6c1055bf2e1972d60c460 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sun, 16 Sep 2018 20:27:24 -0400 Subject: [PATCH 18/22] 455: Fade colormap netsync use new colormap saving --- src/p_saveg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index cea40a4e9..109102dfc 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1795,8 +1795,8 @@ static void SaveFadeColormapThinker(const thinker_t *th, const UINT8 type) const fadecolormap_t *ht = (const void *)th; WRITEUINT8(save_p, type); WRITEUINT32(save_p, SaveSector(ht->sector)); - SaveExtraColormap(save_p, ht->source_exc); - SaveExtraColormap(save_p, ht->dest_exc); + WRITEUINT32(save_p, CheckAddNetColormapToList(ht->source_exc)); + WRITEUINT32(save_p, CheckAddNetColormapToList(ht->dest_exc)); WRITEUINT8(save_p, (UINT8)ht->ticbased); WRITEINT32(save_p, ht->duration); WRITEINT32(save_p, ht->timer); @@ -2795,8 +2795,8 @@ static inline void LoadFadeColormapThinker(actionf_p1 thinker) fadecolormap_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; ht->sector = LoadSector(READUINT32(save_p)); - ht->source_exc = LoadExtraColormap(save_p); - ht->dest_exc = LoadExtraColormap(save_p); + ht->source_exc = GetNetColormapFromList(READUINT32(save_p)); + ht->dest_exc = GetNetColormapFromList(READUINT32(save_p)); ht->ticbased = (boolean)READUINT8(save_p); ht->duration = READINT32(save_p); ht->timer = READINT32(save_p); From 0a998fec02a84981008fad81163d40765d979341 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sun, 16 Sep 2018 22:41:08 -0400 Subject: [PATCH 19/22] New colormap netsync fixes --- src/p_saveg.c | 79 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 109102dfc..517211726 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -485,29 +485,30 @@ static UINT32 num_net_colormaps = 0; // But also check for equality and return the matching index static UINT32 CheckAddNetColormapToList(extracolormap_t *extra_colormap) { - extracolormap_t *exc; + extracolormap_t *exc, *exc_prev; UINT32 i = 0; if (!net_colormaps) { - net_colormaps = extra_colormap; + net_colormaps = R_CopyColormap(extra_colormap, false); net_colormaps->next = 0; net_colormaps->prev = 0; + num_net_colormaps = i+1; return i; } - for (exc = net_colormaps; exc->next; exc = exc->next) + for (exc = net_colormaps; exc; exc_prev = exc, exc = exc->next) { if (R_CheckEqualColormaps(exc, extra_colormap, true, true, true)) return i; i++; } - exc->next = extra_colormap; - extra_colormap->prev = exc; + exc_prev->next = R_CopyColormap(extra_colormap, false); + extra_colormap->prev = exc_prev; extra_colormap->next = 0; - num_net_colormaps = i; + num_net_colormaps = i+1; return i; } @@ -522,14 +523,24 @@ static extracolormap_t *GetNetColormapFromList(UINT32 index) extracolormap_t *exc, *last_exc = NULL; UINT32 i = 0; + if (!net_colormaps) // initialize our list + net_colormaps = R_CreateDefaultColormap(false); + for (exc = net_colormaps; exc; last_exc = exc, exc = exc->next) { if (i++ == index) return exc; } + + // LET'S HOPE that index is a sane value, because we create up to [index] + // entries in net_colormaps. At this point, we don't know + // what the total colormap count is + if (index >= numsectors*3) // if every sector had a unique colormap change AND a fade thinker which has two colormap entries + I_Error("Colormap %d from server is too high for sectors %d", index, numsectors); + // our index doesn't exist, so just make the entry - for (; i <= index && i < num_net_colormaps; i++) + for (; i <= index; i++) { exc = R_CreateDefaultColormap(false); if (last_exc) @@ -556,15 +567,20 @@ static void ClearNetColormaps(void) net_colormaps = NULL; } -static void P_NetArchiveColormaps() +static void P_NetArchiveColormaps(void) { // We save and then we clean up our colormap mess extracolormap_t *exc, *exc_next; - + UINT32 i = 0; WRITEUINT32(save_p, num_net_colormaps); // save for safety - for (exc = net_colormaps; exc; exc = exc_next) + for (exc = net_colormaps; i < num_net_colormaps; i++, exc = exc_next) { + // We must save num_net_colormaps worth of data + // So fill non-existent entries with default. + if (!exc) + exc = R_CreateDefaultColormap(false); + WRITEUINT8(save_p, exc->fadestart); WRITEUINT8(save_p, exc->fadeend); WRITEUINT8(save_p, exc->fog); @@ -581,31 +597,44 @@ static void P_NetArchiveColormaps() } num_net_colormaps = 0; + net_colormaps = NULL; } -static void P_NetUnArchiveColormaps() +static void P_NetUnArchiveColormaps(void) { // When we reach this point, we already populated our list with // dummy colormaps. Now that we are loading the color data, // set up the dummies. - extracolormap_t *exc, *existing_exc; + extracolormap_t *exc, *existing_exc, *exc_next = NULL; num_net_colormaps = READUINT32(save_p); + UINT32 i = 0; - for (exc = net_colormaps; exc; exc = exc->next) + for (exc = net_colormaps; i < num_net_colormaps; i++, exc = exc_next) { - UINT8 fadestart = READUINT8(save_p), - fadeend = READUINT8(save_p), - fog = READUINT8(save_p); - - INT32 rgba = READINT32(save_p), - fadergba = READINT32(save_p); - + UINT8 fadestart, fadeend, fog; + INT32 rgba, fadergba; #ifdef EXTRACOLORMAPLUMPS char lumpname[9]; +#endif + + fadestart = READUINT8(save_p); + fadeend = READUINT8(save_p); + fog = READUINT8(save_p); + + rgba = READINT32(save_p); + fadergba = READINT32(save_p); + +#ifdef EXTRACOLORMAPLUMPS READSTRINGN(save_p, lumpname, 9); if (lumpname[0]) { + if (!exc) + // no point making a new entry since nothing points to it, + // but we needed to read the data so now continue + continue; + + exc_next = exc->next; // this gets overwritten during our operations here, so get it now existing_exc = R_ColormapForName(lumpname); *exc = *existing_exc; R_AddColormapToList(exc); // see HACK note below on why we're adding duplicates @@ -613,6 +642,13 @@ static void P_NetUnArchiveColormaps() } #endif + if (!exc) + // no point making a new entry since nothing points to it, + // but we needed to read the data so now continue + continue; + + exc_next = exc->next; // this gets overwritten during our operations here, so get it now + exc->fadestart = fadestart; exc->fadeend = fadeend; exc->fog = fog; @@ -640,6 +676,9 @@ static void P_NetUnArchiveColormaps() // than going through every loaded sector and correcting their // colormap address to the pre-existing one, PER net_colormap entry R_AddColormapToList(exc); + + if (i < num_net_colormaps-1 && !exc_next) + exc_next = R_CreateDefaultColormap(false); } // Don't need these anymore From 64b96c7192565b1f47561c9f4210ef2425e60b94 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Sep 2018 21:16:27 -0400 Subject: [PATCH 20/22] 455: Don't interrupt current color fading --- src/p_spec.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_spec.c b/src/p_spec.c index a408b2140..b855e9641 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3378,6 +3378,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { extracolormap_t *source_exc, *dest_exc, *exc; + // Prevent continuous execs from interfering on an existing fade + if (!(line->flags & ML_EFFECT5) + && sectors[secnum].fadecolormapdata) + continue; + if (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; From 56ee711f332daad06ecec3d612d0d8b84318be59 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 05:45:28 -0400 Subject: [PATCH 21/22] 455: Commented out, but allow existing fade overlap of 2 tics (or speed*2) --- src/p_spec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index b855e9641..95119cfd3 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3377,11 +3377,18 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, 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) && sectors[secnum].fadecolormapdata) + //&& ((fadecolormap_t*)sectors[secnum].fadecolormapdata)->timer > (ticbased ? 2 : speed*2)) + { + CONS_Debug(DBG_GAMELOGIC, "Line type 455 Executor: Fade color thinker already exists, timer: %d", ((fadecolormap_t*)sectors[secnum].fadecolormapdata)->timer); continue; + } if (line->flags & ML_TFERLINE) // use back colormap instead of target sector sectors[secnum].extra_colormap = (line->sidenum[1] != 0xFFFF) ? @@ -3451,9 +3458,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) Z_Free(exc); Add_ColormapFader(§ors[secnum], source_exc, dest_exc, (line->flags & ML_EFFECT4), // tic-based timing - ((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)); + speed); } break; From 9778cc2ad57bbc1c4c4a51a93b4aea4e88f91a38 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 07:07:30 -0400 Subject: [PATCH 22/22] 455: A line break --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 95119cfd3..80580403c 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3386,7 +3386,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) && sectors[secnum].fadecolormapdata) //&& ((fadecolormap_t*)sectors[secnum].fadecolormapdata)->timer > (ticbased ? 2 : speed*2)) { - CONS_Debug(DBG_GAMELOGIC, "Line type 455 Executor: Fade color thinker already exists, timer: %d", ((fadecolormap_t*)sectors[secnum].fadecolormapdata)->timer); + CONS_Debug(DBG_GAMELOGIC, "Line type 455 Executor: Fade color thinker already exists, timer: %d\n", ((fadecolormap_t*)sectors[secnum].fadecolormapdata)->timer); continue; }