From 68b6f922f7a825c742510e8366b86c83e1a94684 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 3 Jun 2017 20:00:53 -0400 Subject: [PATCH] - Added auto-detection scheme for r_vanillatrans It now works the following way: (0) - Force off (ZDoom defaults) (1) - Force on (Doom defaults) (2) - Auto off (Prefer ZDoom defaults - if DEHACKED is detected with no ZSCRIPT it will turn on) (default) (3) - Auto on (Prefer Doom defaults - if DECORATE is detected with no ZSCRIPT it will turn off) --- src/CMakeLists.txt | 1 + src/d_main.cpp | 4 ++ src/gl/scene/gl_sprite.cpp | 4 +- src/polyrenderer/scene/poly_sprite.cpp | 4 +- src/r_data/r_vanillatrans.cpp | 67 ++++++++++++++++++++++++++ src/r_data/r_vanillatrans.h | 3 ++ src/r_data/renderstyle.cpp | 1 - src/swrenderer/things/r_sprite.cpp | 4 +- wadsrc/static/language.enu | 4 ++ wadsrc/static/menudef.txt | 6 ++- 10 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 src/r_data/r_vanillatrans.cpp create mode 100644 src/r_data/r_vanillatrans.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a9b2aa87..10fe6e84d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1071,6 +1071,7 @@ set (PCH_SOURCES r_data/voxels.cpp r_data/renderstyle.cpp r_data/r_interpolate.cpp + r_data/r_vanillatrans.cpp scripting/symbols.cpp scripting/types.cpp scripting/thingdef.cpp diff --git a/src/d_main.cpp b/src/d_main.cpp index 650d99ae8..b4b6947a6 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -116,6 +116,7 @@ #include "r_utility.h" #include "vm.h" #include "types.h" +#include "r_data/r_vanillatrans.h" EXTERN_CVAR(Bool, hud_althud) void DrawHUD(); @@ -2606,6 +2607,9 @@ void D_DoomMain (void) D_CheckNetGame (); } + // [SP] Force vanilla transparency auto-detection to re-detect our game lumps now + UpdateVanillaTransparency(); + // [RH] Lock any cvars that should be locked now that we're // about to begin the game. FBaseCVar::EnableNoSet (); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 8d053e81c..d50c5722e 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -39,6 +39,7 @@ #include "g_levellocals.h" #include "events.h" #include "actorinlines.h" +#include "r_data/r_vanillatrans.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_framebuffer.h" @@ -75,7 +76,6 @@ CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE) } EXTERN_CVAR (Float, transsouls) -EXTERN_CVAR (Bool, r_vanillatrans) extern TArray sprites; extern TArray SpriteFrames; @@ -993,7 +993,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) { trans = 1.f; } - if (r_vanillatrans) + if (UseVanillaTransparency()) { // [SP] "canonical transparency" - with the flip of a CVar, disable transparency for Doom objects, // and disable 'additive' translucency for certain objects from other games. diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index ba91f005b..10d6772af 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -28,10 +28,10 @@ #include "poly_sprite.h" #include "polyrenderer/poly_renderer.h" #include "polyrenderer/scene/poly_light.h" +#include "r_data/r_vanillatrans.h" EXTERN_CVAR(Float, transsouls) EXTERN_CVAR(Int, r_drawfuzz) -EXTERN_CVAR (Bool, r_vanillatrans) bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) { @@ -146,7 +146,7 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane args.SetStencilTestValue(stencilValue); args.SetWriteStencil(true, stencilValue); args.SetClipPlane(clipPlane); - if ((thing->renderflags & RF_ZDOOMTRANS) && r_vanillatrans) + if ((thing->renderflags & RF_ZDOOMTRANS) && UseVanillaTransparency()) args.SetStyle(LegacyRenderStyles[STYLE_Normal], 1.0f, thing->fillcolor, thing->Translation, tex, fullbrightSprite); else args.SetStyle(thing->RenderStyle, thing->Alpha, thing->fillcolor, thing->Translation, tex, fullbrightSprite); diff --git a/src/r_data/r_vanillatrans.cpp b/src/r_data/r_vanillatrans.cpp new file mode 100644 index 000000000..3c40e9dea --- /dev/null +++ b/src/r_data/r_vanillatrans.cpp @@ -0,0 +1,67 @@ + +#include "templates.h" +#include "c_cvars.h" +#include "w_wad.h" +#ifdef _DEBUG +#include "c_dispatch.h" +#endif + +CVAR (Int, r_vanillatrans, 2, CVAR_ARCHIVE) + +namespace +{ + bool firstTime = true; + bool foundDehacked = false; + bool foundDecorate = false; + bool foundZScript = false; +} +#ifdef _DEBUG +CCMD (debug_checklumps) +{ + Printf("firstTime: %d\n", firstTime); + Printf("foundDehacked: %d\n", foundDehacked); + Printf("foundDecorate: %d\n", foundDecorate); + Printf("foundZScript: %d\n", foundZScript); +} +#endif + +void UpdateVanillaTransparency() +{ + firstTime = true; +} + +bool UseVanillaTransparency() +{ + if (firstTime) + { + int lastlump = 0; + Wads.FindLump("ZSCRIPT", &lastlump); // ignore first ZScript + if (Wads.FindLump("ZSCRIPT", &lastlump) == -1) // no loaded ZScript + { + lastlump = 0; + foundDehacked = Wads.FindLump("DEHACKED", &lastlump) != -1; + lastlump = 0; + foundDecorate = Wads.FindLump("DECORATE", &lastlump) != -1; + foundZScript = false; + } + else + { + foundZScript = true; + foundDehacked = false; + foundDecorate = false; + } + firstTime = false; + } + + switch (r_vanillatrans) + { + case 0: return false; + case 1: return true; + default: + if (foundDehacked) + return true; + if (foundDecorate) + return false; + return r_vanillatrans == 3; + } +} diff --git a/src/r_data/r_vanillatrans.h b/src/r_data/r_vanillatrans.h new file mode 100644 index 000000000..61d988074 --- /dev/null +++ b/src/r_data/r_vanillatrans.h @@ -0,0 +1,3 @@ + +void UpdateVanillaTransparency(); +bool UseVanillaTransparency(); \ No newline at end of file diff --git a/src/r_data/renderstyle.cpp b/src/r_data/renderstyle.cpp index fc1905f91..987de82b9 100644 --- a/src/r_data/renderstyle.cpp +++ b/src/r_data/renderstyle.cpp @@ -38,7 +38,6 @@ #include "serializer.h" CVAR (Bool, r_drawtrans, true, 0) -CVAR (Bool, r_vanillatrans, false, CVAR_ARCHIVE) CVAR (Int, r_drawfuzz, 1, CVAR_ARCHIVE) // Convert legacy render styles to flexible render styles. diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index d067b9007..f28cff787 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -65,10 +65,10 @@ #include "swrenderer/r_memory.h" #include "swrenderer/r_renderthread.h" #include "a_dynlight.h" +#include "r_data/r_vanillatrans.h" EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) EXTERN_CVAR(Bool, gl_light_sprites) -EXTERN_CVAR (Bool, r_vanillatrans) namespace swrenderer { @@ -213,7 +213,7 @@ namespace swrenderer if (thing->flags5 & MF5_BRIGHT) vis->renderflags |= RF_FULLBRIGHT; // kg3D vis->RenderStyle = thing->RenderStyle; - if (r_vanillatrans) + if (UseVanillaTransparency()) { if (thing->renderflags & RF_ZDOOMTRANS) vis->RenderStyle = LegacyRenderStyles[STYLE_Normal]; diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index 09bc6580f..fd9ef8969 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2369,6 +2369,10 @@ OPTVAL_SWDOOM = "Doom Software Renderer"; OPTVAL_DEDICATED = "High-Performance"; OPTVAL_INTEGRATED = "Power-Saving"; OPTVAL_VANILLA = "Vanilla"; +OPTVAL_VTFZDOOM = "ZDoom (Forced)"; +OPTVAL_VTFVANILLA = "Vanilla (Forced)"; +OPTVAL_VTAZDOOM = "Auto (Vanilla Preferred)"; +OPTVAL_VTAVANILLA = "Auto (ZDoom Preferred)"; // Colors C_BRICK = "\cabrick"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index b1a602665..68763a552 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -692,8 +692,10 @@ OptionValue Fuzziness OptionValue VanillaTrans { - 0.0, "$OPTVAL_ZDOOM" - 1.0, "$OPTVAL_VANILLA" + 0.0, "$OPTVAL_VTFZDOOM" + 1.0, "$OPTVAL_VTFVANILLA" + 0.0, "$OPTVAL_VTAZDOOM" + 1.0, "$OPTVAL_VTAVANILLA" } OptionValue GPUSwitch