From 9b9ed64360a22273d49faa1d8decaf598a4b469a Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 15 Nov 2016 19:37:30 -0500 Subject: [PATCH 1/2] - Implemented sv_overridegetcvar: This will override the return value for GetCVar checks for certain CVars marked with the CVAR_OVERRIDEGET flag. Instead of returning their true value, they only return defaults instead. - Implemented dummy CVar vid_renderer with a default value of 1. This allows mods not designed for the software renderer to run if sv_overridegetcvar is turned on. --- src/c_cvars.cpp | 7 +++++++ src/c_cvars.h | 1 + src/p_acs.cpp | 20 ++++++++++++++++++++ src/p_actionfunctions.cpp | 6 ++++++ 4 files changed, 34 insertions(+) diff --git a/src/c_cvars.cpp b/src/c_cvars.cpp index c8f1ee4c6..1af07e176 100644 --- a/src/c_cvars.cpp +++ b/src/c_cvars.cpp @@ -52,6 +52,13 @@ #include "v_video.h" #include "colormatcher.h" +// [SP] This is a dummy CVAR that needs to be removed in child ports that implement the real version. +CVAR(Int, vid_renderer, 1, CVAR_GLOBALCONFIG | CVAR_OVERRIDEGET | CVAR_ARCHIVE) + +// [SP] Lets the player (arbitrator) choose whether to override GetCVar checks. +// Danger of desync? Can we just make it a client var? This probably *fixes* desyncs, actually... +CVAR(Bool, sv_overridegetcvar, true, CVAR_SERVERINFO | CVAR_GLOBALCONFIG | CVAR_ARCHIVE) + struct FLatchedValue { FBaseCVar *Variable; diff --git a/src/c_cvars.h b/src/c_cvars.h index be7676e89..d74d3b5c9 100644 --- a/src/c_cvars.h +++ b/src/c_cvars.h @@ -63,6 +63,7 @@ enum CVAR_NOSAVE = 4096, // when used with CVAR_SERVERINFO, do not save var to savegame CVAR_MOD = 8192, // cvar was defined by a mod CVAR_IGNORE = 16384,// do not send cvar across the network/inaccesible from ACS (dummy mod cvar) + CVAR_OVERRIDEGET = 32768,// this cvar disguises its return value for GetCVAR }; union UCVarValue diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 1a60a0c4f..1d309307d 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4549,6 +4549,8 @@ static void DoSetCVar(FBaseCVar *cvar, int value, bool is_string, bool force=fal } } +EXTERN_CVAR(Bool, sv_overridegetcvar) + // Converts floating- to fixed-point as required. static int DoGetCVar(FBaseCVar *cvar, bool is_string) { @@ -4558,6 +4560,24 @@ static int DoGetCVar(FBaseCVar *cvar, bool is_string) { return 0; } + else if (sv_overridegetcvar && (cvar->GetFlags() & CVAR_OVERRIDEGET)) + { + if (is_string) + { + val = cvar->GetGenericRepDefault(CVAR_String); + return GlobalACSStrings.AddString(val.String); + } + else if (cvar->GetRealType() == CVAR_Float) + { + val = cvar->GetGenericRepDefault(CVAR_Float); + return DoubleToACS(val.Float); + } + else + { + val = cvar->GetGenericRepDefault(CVAR_Int); + return val.Int; + } + } else if (is_string) { val = cvar->GetGenericRep(CVAR_String); diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 73cade49a..df5852473 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -621,6 +621,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetCrouchFactor) // //========================================================================== +EXTERN_CVAR(Bool, sv_overridegetcvar) + DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetCVar) { if (numret > 0) @@ -634,6 +636,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetCVar) { ret->SetFloat(0); } + else if (sv_overridegetcvar && (cvar->GetFlags() & CVAR_OVERRIDEGET)) + { + ret->SetFloat(cvar->GetGenericRepDefault(CVAR_Float).Float); + } else { ret->SetFloat(cvar->GetGenericRep(CVAR_Float).Float); From 813030efef234305b53b4032fa6d6dd8326dd7a1 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 15 Nov 2016 19:52:40 -0500 Subject: [PATCH 2/2] - Fully implemented CVAR_OVERRIDEGET for vid_renderer from the ZDoom code submission. --- src/c_cvars.cpp | 3 --- src/posix/cocoa/i_video.mm | 2 +- src/posix/sdl/hardware.cpp | 2 +- src/win32/hardware.cpp | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/c_cvars.cpp b/src/c_cvars.cpp index 1af07e176..18648db28 100644 --- a/src/c_cvars.cpp +++ b/src/c_cvars.cpp @@ -52,9 +52,6 @@ #include "v_video.h" #include "colormatcher.h" -// [SP] This is a dummy CVAR that needs to be removed in child ports that implement the real version. -CVAR(Int, vid_renderer, 1, CVAR_GLOBALCONFIG | CVAR_OVERRIDEGET | CVAR_ARCHIVE) - // [SP] Lets the player (arbitrator) choose whether to override GetCVar checks. // Danger of desync? Can we just make it a client var? This probably *fixes* desyncs, actually... CVAR(Bool, sv_overridegetcvar, true, CVAR_SERVERINFO | CVAR_GLOBALCONFIG | CVAR_ARCHIVE) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 08a563b25..edd7de570 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -123,7 +123,7 @@ CUSTOM_CVAR(Bool, vid_autoswitch, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_ static int s_currentRenderer; -CUSTOM_CVAR(Int, vid_renderer, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) +CUSTOM_CVAR(Int, vid_renderer, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL | CVAR_OVERRIDEGET) { // 0: Software renderer // 1: OpenGL renderer diff --git a/src/posix/sdl/hardware.cpp b/src/posix/sdl/hardware.cpp index f4ac13fc5..5dcf62367 100644 --- a/src/posix/sdl/hardware.cpp +++ b/src/posix/sdl/hardware.cpp @@ -64,7 +64,7 @@ void I_RestartRenderer(); int currentrenderer; // [ZDoomGL] -CUSTOM_CVAR (Int, vid_renderer, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) +CUSTOM_CVAR (Int, vid_renderer, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL | CVAR_OVERRIDEGET) { // 0: Software renderer // 1: OpenGL renderer diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 787c0a4f3..e0338c0dd 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -71,7 +71,7 @@ int currentrenderer = -1; bool changerenderer; // [ZDoomGL] -CUSTOM_CVAR (Int, vid_renderer, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) +CUSTOM_CVAR (Int, vid_renderer, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL | CVAR_OVERRIDEGET) { // 0: Software renderer // 1: OpenGL renderer