From 3344fa9f30ca4628cc9df7f4314b5cf929639a22 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 19 Mar 2011 04:45:59 +0000 Subject: [PATCH] - Fixed: COLORMAP tricks to produce bright lights do not work with the hardware renderer, so do not hardware accelerate weapon sprites that use them. (see Harmony) SVN r3170 (trunk) --- src/r_data.cpp | 50 +++++++++++++++++++++++++++++++++++++++++ src/r_things.cpp | 8 +++++++ src/textures/textures.h | 2 +- src/v_palette.cpp | 7 ++---- src/v_palette.h | 1 + 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/r_data.cpp b/src/r_data.cpp index 8983d5e55..edd5e6992 100644 --- a/src/r_data.cpp +++ b/src/r_data.cpp @@ -50,6 +50,7 @@ static int R_CountTexturesX (); static int R_CountLumpTextures (int lumpnum); +static bool R_CheckForFixedLights(const BYTE *colormaps); extern void R_DeinitBuildTiles(); extern int R_CountBuildTiles(); @@ -230,9 +231,58 @@ void R_InitColormaps () } } NormalLight.Maps = realcolormaps; + NormalLightHasFixedLights = R_CheckForFixedLights(realcolormaps); numfakecmaps = fakecmaps.Size(); } +//========================================================================== +// +// R_CheckForFixedLights +// +// Returns true if there are any entries in the colormaps that are the +// same for every colormap and not the fade color. +// +//========================================================================== + +static bool R_CheckForFixedLights(const BYTE *colormaps) +{ + const BYTE *lastcolormap = colormaps + (NUMCOLORMAPS - 1) * 256; + BYTE freq[256]; + int i, j; + + // Count the frequencies of different colors in the final colormap. + // If they occur more than X amount of times, we ignore them as a + // potential fixed light. + + memset(freq, 0, sizeof(freq)); + for (i = 0; i < 256; ++i) + { + freq[lastcolormap[i]]++; + } + + // Now check the colormaps for fixed lights that are uncommon in the + // final coloramp. + for (i = 255; i >= 0; --i) + { + BYTE color = lastcolormap[i]; + if (freq[color] > 10) // arbitrary number to decide "common" colors + { + continue; + } + // It's rare in the final colormap. See if it's the same for all colormaps. + for (j = 0; j < NUMCOLORMAPS - 1; ++j) + { + if (colormaps[j * 256 + i] != color) + break; + } + if (j == NUMCOLORMAPS - 1) + { // It was the same all the way across. + return true; + } + } + return false; +} + //========================================================================== // // [RH] Returns an index into realcolormaps. Multiply it by diff --git a/src/r_things.cpp b/src/r_things.cpp index d1cfef9e9..b1ceed7a2 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2301,6 +2301,14 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ } } } + // If the main colormap has fixed lights, and this sprite is being drawn with that + // colormap, disable acceleration so that the lights can remain fixed. + if (!noaccel && + NormalLightHasFixedLights && mybasecolormap == &NormalLight && + vis->pic->UseBasePalette()) + { + noaccel = true; + } VisPSpritesBaseColormap[pspnum] = mybasecolormap; } else diff --git a/src/textures/textures.h b/src/textures/textures.h index 4937e02ae..e7dd282b3 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -173,7 +173,7 @@ public: BYTE bHasCanvas:1; // Texture is based off FCanvasTexture BYTE bWarped:2; // This is a warped texture. Used to avoid multiple warps on one texture BYTE bComplex:1; // Will be used to mark extended MultipatchTextures that have to be - // fully composited before subjected to any kinf of postprocessing instead of + // fully composited before subjected to any kind of postprocessing instead of // doing it per patch. BYTE bMultiPatch:1; // This is a multipatch texture (we really could use real type info for textures...) diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 4db1ad57c..0d6c06f57 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -61,6 +61,7 @@ extern "C" { FDynamicColormap NormalLight; } +bool NormalLightHasFixedLights; FPalette GPalette; TArray SpecialColormaps; BYTE DesaturateColormap[31][256]; @@ -860,11 +861,7 @@ void FDynamicColormap::ChangeColor (PalEntry lightcolor, int desaturate) { Color = lightcolor; // [BB] desaturate must be in [0,255] - if( desaturate > 255 ) - desaturate = 255; - else if ( desaturate < 0 ) - desaturate = 0; - Desaturate = desaturate; + Desaturate = clamp(desaturate, 0, 255); if (Maps) BuildLights (); } } diff --git a/src/v_palette.h b/src/v_palette.h index 453365d53..8d97d9b3f 100644 --- a/src/v_palette.h +++ b/src/v_palette.h @@ -133,6 +133,7 @@ extern FPalette GPalette; extern "C" { extern FDynamicColormap NormalLight; } +extern bool NormalLightHasFixedLights; // The color overlay to use for depleted items #define DIM_OVERLAY MAKEARGB(170,0,0,0)