# HG changeset patch # User Adam Kaminski # Date 1610305117 18000 # Sun Jan 10 13:58:37 2021 -0500 # Node ID 8aacd1c3b17a6629d7c4c2f15a8c1dc3fb964ba6 # Parent 96d83561db40423b79dde79c637b25a1ea5839a3 Gameplay or compatibility flagsets that are changed now also print exactly which flags were affected, or just the total number of flags changed if too many were affected. diff -r 96d83561db40 -r 8aacd1c3b17a src/d_main.cpp --- a/src/d_main.cpp Sat Dec 26 23:30:30 2020 -0500 +++ b/src/d_main.cpp Sun Jan 10 13:58:37 2021 -0500 @@ -402,6 +402,71 @@ //========================================================================== // +// [AK] D_CompareFlagset +// +// Lists all flag-type CVars belonging to a particular flagset which have +// been changed through modification of the flagset, then prints them to the +// console. If too many flags were changed, then the total number of flags +// is printed to the console instead, thereby shortening the length of the +// message. The name of the flagset and its new value are printed too. +// +//========================================================================== + +void D_CompareFlagset( FIntCVar& flagset, int maxflags = 2 ) +{ + int value = static_cast( flagset ); + int oldValue = flagset.GetPastValue( ); + + // [AK] Only continue if we're the server, and the value actually changed from before. + if (( NETWORK_GetState( ) != NETSTATE_SERVER ) || ( gamestate == GS_STARTUP ) || ( value == oldValue )) + return; + + FString result; + int flagsChanged = 0; + + for ( int i = 0; i < 32; i++ ) + { + unsigned int bit = ( 1 << i ); + + // [AK] Don't continue if this bit hasn't changed. + if ((( value ^ oldValue ) & bit ) == 0 ) + continue; + + // [AK] Print the name of the CVar and its new value while we still can. + if ( ++flagsChanged <= maxflags ) + { + for ( FBaseCVar* cvar = CVars; cvar; cvar = cvar->GetNext( ) ) + { + // [AK] Make sure that this CVar is a flag. + if ( cvar->IsFlagCVar( ) == false ) + continue; + + FFlagCVar* flagCVar = static_cast( cvar ); + + // [AK] Check if this CVar belongs to the flagset and matches the corresponding bit. + if (( flagCVar->GetValueVar( ) == &flagset ) && ( flagCVar->GetBitVal( ) == bit )) + { + if ( flagsChanged > 1 ) + result += ", "; + + result.AppendFormat( "%s %s", flagCVar->GetName( ), ( value & bit ) ? "ON" : "OFF" ); + break; + } + } + } + } + + // [AK] If too many flags changed, just print how many flags were changed instead. + // This way, we don't print an excessively long message to the console. + if ( flagsChanged > maxflags ) + result.Format( "%d flags changed", flagsChanged ); + + SERVER_Printf( "%s changed to: %d (%s)\n", flagset.GetName( ), value, result ); + SERVERCOMMANDS_SetGameDMFlags( ); +} + +//========================================================================== +// // CVAR dmflags // //========================================================================== @@ -443,11 +508,8 @@ } // [BC] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - SERVERCOMMANDS_SetGameDMFlags( ); - } + // [AK] Moved everything into a separate function to avoid code duplication. + D_CompareFlagset( self ); } CVAR (Flag, sv_nohealth, dmflags, DF_NO_HEALTH); @@ -498,11 +560,8 @@ CUSTOM_CVAR (Int, dmflags2, 0, CVAR_SERVERINFO | CVAR_CAMPAIGNLOCK) { // [BC] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - SERVERCOMMANDS_SetGameDMFlags( ); - } + // [AK] Moved everything into a separate function to avoid code duplication. + D_CompareFlagset( self ); // Stop the automap if we aren't allowed to use it. if ((self & DF2_NO_AUTOMAP) && automapactive) @@ -590,12 +649,9 @@ if ((( self ^ self.GetPastValue() ) & ZADF_SHARE_KEYS ) & ( self & ZADF_SHARE_KEYS )) SERVER_SyncSharedKeys( MAXPLAYERS, true ); - // [BB] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - SERVERCOMMANDS_SetGameDMFlags( ); - } + // [BC] If we're the server, tell clients that the dmflags changed. + // [AK] Moved everything into a separate function to avoid code duplication. + D_CompareFlagset( self ); #ifndef NO_GL // [BB/EP] This makes gl_lightmode and gl_distfog handle ZADF_FORCE_VIDEO_DEFAULTS. @@ -666,11 +722,8 @@ } // [BC] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - SERVERCOMMANDS_SetGameDMFlags( ); - } + // [AK] Moved everything into a separate function to avoid code duplication. + D_CompareFlagset( self ); } // [BB] Removed the CVAR_ARCHIVE flag. @@ -678,12 +731,9 @@ { i_compatflags2 = GetCompatibility2(self) | ii_compatflags2; - // [BB] If we're the server, tell clients that compatflags2 changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - SERVERCOMMANDS_SetGameDMFlags( ); - } + // [BC] If we're the server, tell clients that the dmflags changed. + // [AK] Moved everything into a separate function to avoid code duplication. + D_CompareFlagset( self ); } //========================================================================== @@ -695,11 +745,8 @@ CUSTOM_CVAR (Int, zacompatflags, 0, CVAR_SERVERINFO) { // [BC] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - SERVERCOMMANDS_SetGameDMFlags( ); - } + // [AK] Moved everything into a separate function to avoid code duplication. + D_CompareFlagset( self ); } // [TP] Added CVAR_SERVERINFO