diff --git a/source/common/statistics.cpp b/source/common/statistics.cpp index d6b5d23b1..868ff3e5c 100644 --- a/source/common/statistics.cpp +++ b/source/common/statistics.cpp @@ -546,14 +546,14 @@ bool ReadStatistics() sjson_node* root = sjson_decode(ctx, (const char*)text.Data()); LevelName = sjson_get_string(root, "levelname", ""); - StartEpisode = sjson_get_int(root, "episode", -1); + StartEpisode = sjson_get_string(root, "episode", ""); StartSkill = sjson_get_int(root, "skill", -1); sjson_node* levels = sjson_find_member(root, "levels"); - if (LevelName.Len() == 0 || StartEpisode == -1 || StartSkill == -1 || levels == nullptr) + if (LevelName.Len() == 0 || StartEpisode.Len() == 0 || StartSkill == -1 || levels == nullptr) { sjson_destroy_context(ctx); - return false; + return true; // do not error out on this. } int numlevels = sjson_child_count(levels); diff --git a/source/common/utility/palentry.h b/source/common/utility/palentry.h index e52e62cd3..bfc6121d0 100644 --- a/source/common/utility/palentry.h +++ b/source/common/utility/palentry.h @@ -1,5 +1,6 @@ #pragma once +#include #include struct PalEntry @@ -34,6 +35,11 @@ struct PalEntry return (r * 77 + g * 143 + b * 37) >> 8; } + int Amplitude() const + { + return std::max(r, std::max(g, b)); + } + void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark. { int v = (r + g + b); diff --git a/source/glbackend/gl_palmanager.cpp b/source/glbackend/gl_palmanager.cpp index 30e865f82..4ce12c231 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/glbackend/gl_palmanager.cpp @@ -145,6 +145,25 @@ unsigned PaletteManager::FindPalswap(const uint8_t* paldata, palette_t &fadecolo pd.lookup = paldata; pd.crc32 = crc32; pd.swaptexture = nullptr; + memset(pd.brightcolors, 0, 256); + pd.isbright = false; + + for (int i = 0; i < 255; i++) + { + int firstmap = paldata[i]; + int lastmap = paldata[i + 256 * (numshades - 2)]; + + PalEntry color1 = palettes[palettemap[0]].colors[firstmap]; + PalEntry color2 = palettes[palettemap[0]].colors[lastmap]; + int lum1 = color1.Amplitude(); + int lum2 = color2.Amplitude(); + if (lum1 > 40 && lum2 * 10 >= lum1 * 9) + { + pd.brightcolors[i] = 255; + pd.isbright = true; + } + } + if (fadecolor.f == 0) { @@ -288,13 +307,18 @@ int PaletteManager::LookupPalette(int palette, int palswap, bool brightmap) } else { + if (!swapdata->isbright) + { + swappedpalmap.Insert(combined, -1); + return -1; + } + bool found = false; memset(swappedpalette, 0, sizeof(swappedpalette)); for (int i = 0; i < 255; i++) { - int swapi = swapdata->lookup[i]; - auto swapc = paldata->colors[swapi]; - if (swapc.a) + int swapi = swapdata->brightcolors[i]; + if (swapi) { found = true; swappedpalette[i] = 0xffffffff; diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index 4219d7a41..37cc41136 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -258,6 +258,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int BindTexture(4, htex, SamplerRepeat); } } +#if 1 if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap]) { if (TextureType == TT_HICREPLACE) @@ -293,6 +294,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int } } } +#endif } else return false; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index cb95ca4b2..7201c5406 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -226,6 +226,7 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) if (activeShader == polymostShader) { + if (istrans) renderState.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all. renderState.Apply(polymostShader); if (renderState.VertexBuffer != LastVertexBuffer || LastVB_Offset[0] != renderState.VB_Offset[0] || LastVB_Offset[1] != renderState.VB_Offset[1]) { @@ -400,6 +401,7 @@ void GLInstance::SetCull(int type, int winding) void GLInstance::SetColor(float r, float g, float b, float a) { glVertexAttrib4f(2, r, g, b, a); + istrans = (a != 1); } void GLInstance::SetDepthFunc(int func) diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index b5d125fdd..632c27fa9 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -37,9 +37,11 @@ struct PalShade struct PalswapData { int32_t crc32; + bool isbright; const uint8_t *lookup; // points to the original data. This is static so no need to copy FHardwareTexture* swaptexture; PalEntry fadeColor; + uint8_t brightcolors[255]; }; enum @@ -198,6 +200,7 @@ class GLInstance FTexture* currentTexture = nullptr; int TextureType; int MatrixChange = 0; + bool istrans = false; IVertexBuffer* LastVertexBuffer = nullptr; int LastVB_Offset[2] = {}; diff --git a/source/platform/win32/winbits.cpp b/source/platform/win32/winbits.cpp index dd6f632dd..d68b23149 100644 --- a/source/platform/win32/winbits.cpp +++ b/source/platform/win32/winbits.cpp @@ -1,5 +1,6 @@ // Windows layer-independent code +#define NOMINMAX #include #include "compat.h" #include "build.h"