Browse Source

Adjustments to save out code when writing fields such that if the TAML writer is marked as not writing defaults, it doesn't. And makes the regular simobject save out not write default values as the default behavior

JeffR 3 years ago
parent
commit
b4e346aa3f
2 changed files with 41 additions and 8 deletions
  1. 12 0
      Engine/source/console/simObject.cpp
  2. 29 8
      Engine/source/persistence/taml/taml.cpp

+ 12 - 0
Engine/source/console/simObject.cpp

@@ -304,6 +304,10 @@ bool SimObject::writeField(StringTableEntry fieldname, const char* value)
 void SimObject::writeFields(Stream &stream, U32 tabStop)
 void SimObject::writeFields(Stream &stream, U32 tabStop)
 {
 {
    // Write static fields.
    // Write static fields.
+
+   // Create a default object of the same type
+   ConsoleObject* defaultConObject = ConsoleObject::create(getClassName());
+   SimObject* defaultObject = dynamic_cast<SimObject*>(defaultConObject);
    
    
    const AbstractClassRep::FieldList &list = getFieldList();
    const AbstractClassRep::FieldList &list = getFieldList();
 
 
@@ -332,6 +336,11 @@ void SimObject::writeFields(Stream &stream, U32 tabStop)
          if (!writeField(f->pFieldname, valCopy))
          if (!writeField(f->pFieldname, valCopy))
             continue;
             continue;
 
 
+         //If the field hasn't been changed from the default value, then don't bother writing it out
+         const char* defaultValueCheck = defaultObject->getDataField(f->pFieldname, array);
+         if (dStricmp(defaultValueCheck, valCopy) == 0)
+            continue;
+
          val = valCopy;
          val = valCopy;
 
 
          U32 expandedBufferSize = ( nBufferSize  * 2 ) + dStrlen(f->pFieldname) + 32;
          U32 expandedBufferSize = ( nBufferSize  * 2 ) + dStrlen(f->pFieldname) + 32;
@@ -366,6 +375,9 @@ void SimObject::writeFields(Stream &stream, U32 tabStop)
    
    
    if(mFieldDictionary && mCanSaveFieldDictionary)
    if(mFieldDictionary && mCanSaveFieldDictionary)
       mFieldDictionary->writeFields(this, stream, tabStop);
       mFieldDictionary->writeFields(this, stream, tabStop);
+
+   // Cleanup our created default object
+   delete defaultConObject;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 29 - 8
Engine/source/persistence/taml/taml.cpp

@@ -217,11 +217,6 @@ ImplementEnumType(_TamlFormatMode,
 
 
       FileStream stream;
       FileStream stream;
 
 
-      if (StringTable->insert("c://.asset.taml") == StringTable->insert(mFilePathBuffer))
-      {
-         bool asdfasdf = true;
-      }
-
       // File opened?
       // File opened?
       if (!stream.open(mFilePathBuffer, Torque::FS::File::Write))
       if (!stream.open(mFilePathBuffer, Torque::FS::File::Write))
       {
       {
@@ -643,6 +638,19 @@ ImplementEnumType(_TamlFormatMode,
       // Fetch field count.
       // Fetch field count.
       const U32 fieldCount = fieldList.size();
       const U32 fieldCount = fieldList.size();
 
 
+      ConsoleObject* defaultConObject;
+      SimObject* defaultObject;
+      if (!getWriteDefaults())
+      {
+         // Create a default object of the same type
+         defaultConObject = ConsoleObject::create(pSimObject->getClassName());
+         defaultObject = dynamic_cast<SimObject*>(defaultConObject);
+      
+         // ***Really*** shouldn't happen
+         if (!defaultObject)
+            return;
+      }
+
       // Iterate fields.
       // Iterate fields.
       U8 arrayDepth = 0;
       U8 arrayDepth = 0;
       TamlCustomNode* currentArrayNode = NULL;
       TamlCustomNode* currentArrayNode = NULL;
@@ -709,9 +717,6 @@ ImplementEnumType(_TamlFormatMode,
             if (!pFieldValue)
             if (!pFieldValue)
                pFieldValue = StringTable->EmptyString();
                pFieldValue = StringTable->EmptyString();
 
 
-            if (pField->type == TypeBool)
-               pFieldValue = dAtob(pFieldValue) ? "true" : "false";
-
             U32 nBufferSize = dStrlen(pFieldValue) + 1;
             U32 nBufferSize = dStrlen(pFieldValue) + 1;
             FrameTemp<char> valueCopy(nBufferSize);
             FrameTemp<char> valueCopy(nBufferSize);
             dStrcpy((char *)valueCopy, pFieldValue, nBufferSize);
             dStrcpy((char *)valueCopy, pFieldValue, nBufferSize);
@@ -720,9 +725,19 @@ ImplementEnumType(_TamlFormatMode,
             if (!pSimObject->writeField(fieldName, valueCopy))
             if (!pSimObject->writeField(fieldName, valueCopy))
                continue;
                continue;
 
 
+            if (!getWriteDefaults())
+            {
+               //If the field hasn't been changed from the default value, then don't bother writing it out
+               if (dStricmp(defaultObject->getDataField(fieldName, indexBuffer), pFieldValue) == 0)
+                  continue;
+            }
+
             // Reassign field value.
             // Reassign field value.
             pFieldValue = valueCopy;
             pFieldValue = valueCopy;
 
 
+            if (pField->type == TypeBool)
+               pFieldValue = dAtob(pFieldValue) ? "true" : "false";
+
             // Detect and collapse relative path information
             // Detect and collapse relative path information
             char fnBuf[1024];
             char fnBuf[1024];
             if ((S32)pField->type == TypeFilename)
             if ((S32)pField->type == TypeFilename)
@@ -741,6 +756,12 @@ ImplementEnumType(_TamlFormatMode,
             }
             }
          }
          }
       }
       }
+
+      if (!getWriteDefaults())
+      {
+         // Cleanup our created default object
+         delete defaultConObject;
+      }
    }
    }
 
 
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------