# HG changeset patch # User Adam Kaminski # Date 1609703308 18000 # Sun Jan 03 14:48:28 2021 -0500 # Node ID 4ececb1b037a02b675e04e61ffe01a87c890097b # Parent 6525c11ad2c26201401706e1d13bab5e51d50306 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 6525c11ad2c2 -r 4ececb1b037a src/d_main.cpp --- a/src/d_main.cpp Fri Jan 01 11:28:27 2021 -0500 +++ b/src/d_main.cpp Sun Jan 03 14:48:28 2021 -0500 @@ -402,6 +402,64 @@ //========================================================================== // +// [AK] D_PrintFlagsetChanges +// +// 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 is printed too. +// +//========================================================================== + +void D_PrintFlagsetChanges( FIntCVar& flagset, int maxflags = 2 ) +{ + FString result; + int oldValue = flagset.GetPastValue( ); + 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 ((( (int)flagset ^ 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( ), ( (int)flagset & 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( ), (int)flagset, result ); +} + +//========================================================================== +// // CVAR dmflags // //========================================================================== @@ -443,9 +501,11 @@ } // [BC] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) + // [AK] Only do this if the value is different from what it was before. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && + ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue( ) )) { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); + D_PrintFlagsetChanges( self ); SERVERCOMMANDS_SetGameDMFlags( ); } } @@ -498,9 +558,11 @@ 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 )) + // [AK] Only do this if the value is different from what it was before. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && + ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue( ) )) { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); + D_PrintFlagsetChanges( self ); SERVERCOMMANDS_SetGameDMFlags( ); } @@ -591,9 +653,11 @@ SERVER_SyncSharedKeys( MAXPLAYERS, true ); // [BB] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) + // [AK] Only do this if the value is different from what it was before. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && + ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue( ) )) { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); + D_PrintFlagsetChanges( self ); SERVERCOMMANDS_SetGameDMFlags( ); } @@ -666,9 +730,11 @@ } // [BC] If we're the server, tell clients that the dmflags changed. - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) + // [AK] Only do this if the value is different from what it was before. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && + ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue( ) )) { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); + D_PrintFlagsetChanges( self ); SERVERCOMMANDS_SetGameDMFlags( ); } } @@ -679,9 +745,11 @@ 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 )) + // [AK] Only do this if the value is different from what it was before. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && + ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue( ) )) { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); + D_PrintFlagsetChanges( self ); SERVERCOMMANDS_SetGameDMFlags( ); } } @@ -695,9 +763,11 @@ 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 )) + // [AK] Only do this if the value is different from what it was before. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && + ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue( ) )) { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); + D_PrintFlagsetChanges( self ); SERVERCOMMANDS_SetGameDMFlags( ); } }