| Attached Files |  dmflags-data.diff [^] (7,253 bytes) 2014-05-17 21:37 [Show Content] [Hide Content] diff -r 7bd5059677f1 src/c_cvars.cpp
--- a/src/c_cvars.cpp	Sun May 04 23:57:26 2014 +0300
+++ b/src/c_cvars.cpp	Sun May 18 00:28:47 2014 +0300
@@ -688,7 +688,7 @@
 {
 	DefaultValue = def;
 	if (Flags & CVAR_ISDEFAULT)
-		Value = def;
+		Value = PastValue = def; // [Dusk] Store PastValue here
 }
 
 ECVarType FIntCVar::GetRealType () const
@@ -734,6 +734,7 @@
 
 void FIntCVar::DoSet (UCVarValue value, ECVarType type)
 {
+	PastValue = Value; // [Dusk]
 	Value = ToInt (value, type);
 }
 
@@ -1447,6 +1448,12 @@
 	}
 }
 
+// [Dusk]
+FBaseCVar* C_GetRootCVar()
+{
+	return CVars;
+}
+
 void FBaseCVar::CmdSet (const char *newval)
 {
 	UCVarValue val;
diff -r 7bd5059677f1 src/c_cvars.h
--- a/src/c_cvars.h	Sun May 04 23:57:26 2014 +0300
+++ b/src/c_cvars.h	Sun May 18 00:28:47 2014 +0300
@@ -130,6 +130,8 @@
 
 	static void ListVars (const char *filter, bool plain);
 
+	inline FBaseCVar* GetNext() const { return m_Next; } // [Dusk]
+
 protected:
 	FBaseCVar () {}
 	virtual void DoSet (UCVarValue value, ECVarType type) = 0;
@@ -241,11 +243,15 @@
 	inline operator int () const { return Value; }
 	inline int operator *() const { return Value; }
 
+	// [Dusk]
+	inline int const& GetPastValue() const { return PastValue; }
+
 protected:
 	virtual void DoSet (UCVarValue value, ECVarType type);
 
 	int Value;
 	int DefaultValue;
+	int PastValue; // [Dusk] What was this CVar before?
 
 	friend class FFlagCVar;
 };
@@ -338,6 +344,9 @@
 	virtual UCVarValue GetFavoriteRepDefault (ECVarType *type) const;
 	virtual void SetGenericRepDefault (UCVarValue value, ECVarType type);
 
+	inline FIntCVar const& GetValueVar() const { return ValueVar; } // [Dusk]
+	inline uint32 const& GetBitVal() const { return BitVal; } // [Dusk]
+
 	bool operator= (bool boolval)
 		{ UCVarValue val; val.Bool = boolval; SetGenericRep (val, CVAR_Bool); return boolval; }
 	bool operator= (FFlagCVar &flag)
@@ -399,6 +408,8 @@
 
 void C_ForgetCVars (void);
 
+// [Dusk] For CVar iteration
+FBaseCVar* C_GetRootCVar();
 
 #define CUSTOM_CVAR(type,name,def,flags) \
 	static void cvarfunc_##name(F##type##CVar &); \
diff -r 7bd5059677f1 src/d_main.cpp
--- a/src/d_main.cpp	Sun May 04 23:57:26 2014 +0300
+++ b/src/d_main.cpp	Sun May 18 00:28:47 2014 +0300
@@ -311,6 +311,73 @@
 
 //==========================================================================
 //
+// [Dusk] D_CompareFlagsets
+//
+// Describes the differences between the flagset and its past value.
+//
+//==========================================================================
+
+static FString D_CompareFlagsets( FIntCVar& flagset, int maxflags = 5 )
+{
+	FString result;
+	int flagschanged = 0;
+	int oldValue = flagset.GetPastValue();
+
+	for ( int i = 0; i < 32; ++i )
+	{
+		uint32 bit = ( 1 << i );
+
+		// [Dusk] Skip flags that haven't changed
+		if ((( flagset ^ oldValue ) & bit ) == 0 )
+			continue;
+
+		flagschanged++;
+
+		if ( flagschanged <= maxflags )
+		{
+			bool isOn = ( flagset & bit ) != 0;
+
+			// [Dusk] Find the CVar for this flag
+			FFlagCVar* flag = NULL;
+
+			for ( FBaseCVar* var = C_GetRootCVar(); var != NULL; var = var->GetNext() )
+			{
+				FFlagCVar* varflag = static_cast<FFlagCVar*>( var );
+
+				if (( var->GetRealType() == CVAR_Dummy ) &&
+					( &varflag->GetValueVar() == &flagset ) &&
+					( varflag->GetBitVal() == bit ))
+				{
+					flag = varflag;
+					break;
+				}
+			}
+
+			// [Dusk] If we found the flag, write the change down
+			if ( flag != NULL )
+			{
+				if ( result.IsNotEmpty() )
+					result += ", ";
+
+				result.AppendFormat( "%s %s", flag->GetName(), isOn ? "ON" : "OFF" );
+			}
+		}
+	}
+
+	if ( flagschanged > maxflags )
+	{
+		// [Dusk] Too much changes, just give a number on how many changed, we
+		// don't want to spam the messages.
+		FString msg;
+		msg.Format( "%d flags changed", flagschanged );
+		return msg;
+	}
+
+	return result;
+}
+
+//==========================================================================
+//
 // CVAR dmflags
 //
 //==========================================================================
@@ -352,9 +419,12 @@
 	}
 
 	// [BC] If we're the server, tell clients that the dmflags changed.
-	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ))
+	// [Dusk] Not if the flagset didn't change. Also include a description of
+	// what changed.
+	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue() ))
 	{
-		SERVER_Printf( PRINT_HIGH, "%s changed to: %d\n", self.GetName( ), (LONG)self );
+		SERVER_Printf( PRINT_HIGH, "%s changed to %d (%s)\n",
+			self.GetName( ), (LONG)self, D_CompareFlagsets( self ).GetChars() );
 		SERVERCOMMANDS_SetGameDMFlags( );
 	}
 }
@@ -408,9 +478,12 @@
 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 ))
+	// [Dusk] Not if the flagset didn't change. Also include a description of
+	// what changed.
+	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue() ))
 	{
-		SERVER_Printf( PRINT_HIGH, "%s changed to: %d\n", self.GetName( ), (LONG)self );
+		SERVER_Printf( PRINT_HIGH, "%s changed to %d (%s)\n",
+			self.GetName( ), (LONG)self, D_CompareFlagsets( self ).GetChars() );
 		SERVERCOMMANDS_SetGameDMFlags( );
 	}
 
@@ -502,9 +575,12 @@
 CUSTOM_CVAR (Int, dmflags3, 0, CVAR_SERVERINFO)
 {
 	// [BB] If we're the server, tell clients that the dmflags changed.
-	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ))
+	// [Dusk] Not if the flagset didn't change. Also include a description of
+	// what changed.
+	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue() ))
 	{
-		SERVER_Printf( PRINT_HIGH, "%s changed to: %d\n", self.GetName( ), (LONG)self );
+		SERVER_Printf( PRINT_HIGH, "%s changed to %d (%s)\n",
+			self.GetName( ), (LONG)self, D_CompareFlagsets( self ).GetChars() );
 		SERVERCOMMANDS_SetGameDMFlags( );
 	}
 }
@@ -539,9 +615,12 @@
 	i_compatflags = GetCompatibility(self) | ii_compatflags;
 
 	// [BC] If we're the server, tell clients that the dmflags changed.
-	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ))
+	// [Dusk] Not if the flagset didn't change. Also include a description of
+	// what changed.
+	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ) && ( self != self.GetPastValue() ))
 	{
-		SERVER_Printf( PRINT_HIGH, "%s changed to: %d\n", self.GetName( ), (LONG)self );
+		SERVER_Printf( PRINT_HIGH, "%s changed to %d (%s)\n",
+			self.GetName( ), (LONG)self, D_CompareFlagsets( self ).GetChars() );
 		SERVERCOMMANDS_SetGameDMFlags( );
 	}
 }
@@ -557,7 +636,8 @@
 	// [BC] If we're the server, tell clients that the dmflags changed.
 	if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP ))
 	{
-		SERVER_Printf( PRINT_HIGH, "%s changed to: %d\n", self.GetName( ), (LONG)self );
+		SERVER_Printf( PRINT_HIGH, "%s changed to %d (%s)\n",
+			self.GetName( ), (LONG)self, D_CompareFlagsets( self ).GetChars() );
 		SERVERCOMMANDS_SetGameDMFlags( );
 	}
 }
 |