From f0c11eb13572e041b1f7762d569f9e821c336d10 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 21:02:58 -0400 Subject: [PATCH 1/3] R_AddColormaps method --- src/r_data.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/r_data.h | 5 +++ 2 files changed, 91 insertions(+) diff --git a/src/r_data.c b/src/r_data.c index e0899e4cf..c84e61fce 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1867,6 +1867,92 @@ extracolormap_t *R_CreateColormap(char *p1, char *p2, char *p3) return extra_colormap; } +// +// R_AddColormaps() +// NOTE: The result colormap DOES get added to the extra_colormaps chain! +// +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, + boolean useAltAlpha, INT16 altAlpha, INT16 altFadeAlpha, + boolean lighttable) +{ + extracolormap_t *exc; + + // exc_augend is added (or subtracted) onto by exc_addend + // In Rennaisance times, the first number was considered the augend, the second number the addend + // But since the commutative property was discovered, today they're both called addends! + // So let's be Olde English for a hot second. + + exc_augend = R_CopyColormap(exc_augend, false); + if(!exc_addend) + exc_addend = R_GetDefaultColormap(); + + INT16 red, green, blue, alpha; + + // base rgba + red = max(min( + R_GetRgbaR(exc_augend->rgba) + + (subR ? -1 : 1) // subtract R + * R_GetRgbaR(exc_addend->rgba) + , 255), 0); + + green = max(min( + R_GetRgbaG(exc_augend->rgba) + + (subG ? -1 : 1) // subtract G + * R_GetRgbaG(exc_addend->rgba) + , 255), 0); + + blue = max(min( + R_GetRgbaB(exc_augend->rgba) + + (subB ? -1 : 1) // subtract B + * R_GetRgbaB(exc_addend->rgba) + , 255), 0); + + alpha = useAltAlpha ? altAlpha : 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); + + // fade rgba + red = max(min( + R_GetRgbaR(exc_augend->fadergba) + + (subFadeR ? -1 : 1) // subtract R + * R_GetRgbaR(exc_addend->fadergba) + , 255), 0); + + green = max(min( + R_GetRgbaG(exc_augend->fadergba) + + (subFadeG ? -1 : 1) // subtract G + * R_GetRgbaG(exc_addend->fadergba) + , 255), 0); + + blue = max(min( + R_GetRgbaB(exc_augend->fadergba) + + (subFadeB ? -1 : 1) // subtract B + * R_GetRgbaB(exc_addend->fadergba) + , 255), 0); + + alpha = useAltAlpha ? altFadeAlpha : R_GetRgbaA(exc_addend->fadergba); + if (alpha == 25) + 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); + + exc_augend->fadergba = R_PutRgbaRGBA(red, green, blue, alpha); + + if (!(exc = R_GetColormapFromList(exc_augend))) + { + exc_augend->colormap = lighttable ? R_CreateLightTable(exc_augend) : NULL; + R_AddColormapToList(exc_augend); + return exc_augend; + } + else + { + Z_Free(exc_augend); + return exc; + } +} + // Thanks to quake2 source! // utils3/qdata/images.c static UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) diff --git a/src/r_data.h b/src/r_data.h index d980e9c56..6f8d08120 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -124,6 +124,11 @@ 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_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, + boolean useAltAlpha, INT16 altAlpha, INT16 altFadeAlpha, + boolean lighttable); #ifdef EXTRACOLORMAPLUMPS extracolormap_t *R_ColormapForName(char *name); const char *R_NameForColormap(extracolormap_t *extra_colormap); From 90aeac5058bae5cdc6c7097ce13bc1f4dd688df3 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 22:34:29 -0400 Subject: [PATCH 2/3] 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..df0fe75b3 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, boolean checkrgba, boolean checkfadergba, boolean checkparams); extracolormap_t *R_GetColormapFromList(extracolormap_t *extra_colormap); lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap); From 92a97fb1a64ec3e2b88203011a5ca11abfeacef8 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 11 Sep 2018 22:44:31 -0400 Subject: [PATCH 3/3] Split colormap netsync to Load/SaveExtraColormap methods --- src/p_saveg.c | 131 +++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index b887b8a73..fc767d9cf 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -474,6 +474,70 @@ static void P_NetUnArchivePlayers(void) } } +static void SaveExtraColormap(UINT8 *put, extracolormap_t *exc) +{ + WRITEUINT8(put, exc->fadestart); + WRITEUINT8(put, exc->fadeend); + WRITEUINT8(put, (UINT8)exc->fog); + + WRITEINT32(put, exc->rgba); + WRITEINT32(put, exc->fadergba); + +#ifdef EXTRACOLORMAPLUMPS + WRITESTRINGN(put, exc->lumpname, 9); +#endif +} + +static extracolormap_t *LoadExtraColormap(UINT8 *get) +{ + extracolormap_t *exc; + //size_t dbg_i = 0; + + UINT8 fadestart = READUINT8(get), + fadeend = READUINT8(get); + + boolean fog = (boolean)READUINT8(get); + + INT32 rgba = READINT32(get), + fadergba = READINT32(get); + +#ifdef EXTRACOLORMAPLUMPS + char lumpname[9]; + READSTRINGN(get, lumpname, 9); + + if (lumpname[0]) + return R_ColormapForName(lumpname); +#endif + exc = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, fog); + + if (!exc) + { + // CONS_Debug(DBG_RENDER, "Creating Colormap: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", + // (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); + + exc->fadestart = fadestart; + exc->fadeend = fadeend; + exc->fog = fog; + + exc->rgba = rgba; + exc->fadergba = fadergba; + + exc->colormap = R_CreateLightTable(exc); + + R_AddColormapToList(exc); + +#ifdef EXTRACOLORMAPLUMPS + exc->lump = LUMPERROR; + exc->lumpname[0] = 0; +#endif + } + + return exc; +} + #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 #define SD_FLOORPIC 0x04 @@ -657,18 +721,7 @@ static void P_NetArchiveWorld(void) } if (diff3 & SD_COLORMAP) - { - WRITEUINT8(put, ss->extra_colormap->fadestart); - WRITEUINT8(put, ss->extra_colormap->fadeend); - WRITEUINT8(put, (UINT8)ss->extra_colormap->fog); - - WRITEINT32(put, ss->extra_colormap->rgba); - WRITEINT32(put, ss->extra_colormap->fadergba); - -#ifdef EXTRACOLORMAPLUMPS - WRITESTRINGN(put, ss->extra_colormap->lumpname, 9); -#endif - } + SaveExtraColormap(put, ss->extra_colormap); // Special case: save the stats of all modified ffloors along with their ffloor "number"s // we don't bother with ffloors that haven't changed, that would just add to savegame even more than is really needed @@ -865,59 +918,7 @@ static void P_NetUnArchiveWorld(void) } if (diff3 & SD_COLORMAP) - { - extracolormap_t *exc; - //size_t dbg_i = 0; - - UINT8 fadestart = READUINT8(get), - fadeend = READUINT8(get); - - boolean fog = (boolean)READUINT8(get); - - INT32 rgba = READINT32(get), - fadergba = READINT32(get); - -#ifdef EXTRACOLORMAPLUMPS - char lumpname[9]; - READSTRINGN(get, lumpname, 9); - - if (lumpname[0]) - sectors[i].extra_colormap = R_ColormapForName(lumpname); - else - { -#endif - exc = R_GetColormapFromListByValues(rgba, fadergba, fadestart, fadeend, fog); - - if (!exc) - { - // CONS_Debug(DBG_RENDER, "Creating Colormap: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", - // (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); - - exc->fadestart = fadestart; - exc->fadeend = fadeend; - exc->fog = fog; - - exc->rgba = rgba; - exc->fadergba = fadergba; - - exc->colormap = R_CreateLightTable(exc); - - R_AddColormapToList(exc); - -#ifdef EXTRACOLORMAPLUMPS - exc->lump = LUMPERROR; - exc->lumpname[0] = 0; -#endif - } - - sectors[i].extra_colormap = exc; -#ifdef EXTRACOLORMAPLUMPS - } -#endif - } + sectors[i].extra_colormap = LoadExtraColormap(get); if (diff & SD_FFLOORS) {