Browse Source

- Taml serialization WIP.

MelvMay-GG 12 years ago
parent
commit
a4800c6

+ 100 - 83
engine/source/persistence/taml/tamlBinaryWriter.cc

@@ -126,89 +126,6 @@ void TamlBinaryWriter::writeElement( Stream& stream, const TamlWriteNode* pTamlW
 
 //-----------------------------------------------------------------------------
 
-void TamlBinaryWriter::writeCustomElements( Stream& stream, const TamlWriteNode* pTamlWriteNode )
-{
-    // Debug Profiling.
-    PROFILE_SCOPE(TamlBinaryWriter_WriteCustomElements);
-
-    // Fetch custom properties.
-    const TamlCustomNodes& customNodes = pTamlWriteNode->mCustomProperties;
-
-    // Write custom element count.
-    stream.write( (U32)customProperties.size() );
-
-    // Iterate custom properties.
-    for( TamlCustomNodes::const_iterator customPropertyItr = customProperties.begin(); customPropertyItr != customProperties.end(); ++customPropertyItr )
-    {
-        // Fetch custom property.
-        TamlCustomProperty* pCustomProperty = *customPropertyItr;
-
-        // Write custom element name.
-        stream.writeString( pCustomProperty->mPropertyName );
-
-        // Fetch property alias count.
-        U32 propertyAliasCount = (U32)pCustomProperty->size();
-
-        // Write property count.
-        stream.write( propertyAliasCount );
-
-        // Skip if no property alias.
-        if (propertyAliasCount == 0 )
-            continue;
-
-        // Iterate property alias.
-        for( TamlCustomProperty::const_iterator propertyAliasItr = pCustomProperty->begin(); propertyAliasItr != pCustomProperty->end(); ++propertyAliasItr )
-        {
-            // Fetch property alias.
-            TamlPropertyAlias* pPropertyAlias = *propertyAliasItr;
-
-            // Write property alias name.
-            stream.writeString( pPropertyAlias->mAliasName );
-
-            // Write property field count.
-            stream.write( (U32)pPropertyAlias->size() );
-
-            // Skip if no property fields.
-            if ( pPropertyAlias->size() == 0 )
-                continue;
-
-            // Iterate property fields.
-            for ( TamlPropertyAlias::const_iterator propertyFieldItr = pPropertyAlias->begin(); propertyFieldItr != pPropertyAlias->end(); ++propertyFieldItr )
-            {
-                // Fetch property field.
-                TamlCustomNodeField* pPropertyField = *propertyFieldItr;
-
-                // Fetch object field flag,
-                const bool isObjectField = pPropertyField->isObjectField();
-
-                // Write flag.
-                stream.write( isObjectField );
-
-                // Is it an object field?
-                if ( isObjectField )
-                {
-                    // Yes, so fetch write node.
-                    const TamlWriteNode* pObjectWriteField = pPropertyField->getWriteNode();
-
-                    // Write reference field.
-                    stream.writeString( pObjectWriteField->mRefField );
-
-                    // Write field object.
-                    writeElement( stream, pObjectWriteField );
-                }
-                else
-                {
-                    // No, so write property attribute.
-                    stream.writeString( pPropertyField->getFieldName() );
-                    stream.writeLongString( MAX_TAML_NODE_FIELDVALUE_LENGTH, pPropertyField->getFieldValue() );
-                }
-            }
-        }
-    }
-}
-
-//-----------------------------------------------------------------------------
-
 void TamlBinaryWriter::writeAttributes( Stream& stream, const TamlWriteNode* pTamlWriteNode )
 {
     // Debug Profiling.
@@ -261,4 +178,104 @@ void TamlBinaryWriter::writeChildren( Stream& stream, const TamlWriteNode* pTaml
         // Write child.
         writeElement( stream, (*itr) );
     }
+}
+
+//-----------------------------------------------------------------------------
+
+void TamlBinaryWriter::writeCustomElements( Stream& stream, const TamlWriteNode* pTamlWriteNode )
+{
+    // Debug Profiling.
+    PROFILE_SCOPE(TamlBinaryWriter_WriteCustomElements);
+
+    // Fetch custom nodes.
+    const TamlCustomNodes& customNodes = pTamlWriteNode->mCustomNodes;
+
+    // Fetch custom nodes.
+    const TamlCustomNodeVector& nodes = customNodes.getNodes();
+
+    // Write custom element count.
+    stream.write( (U32)nodes.size() );
+
+    // Finish if there are no nodes.
+    if ( nodes.size() == 0 )
+        return;
+
+    // Iterate custom nodes.
+    for( TamlCustomNodeVector::const_iterator customNodesItr = nodes.begin(); customNodesItr != nodes.end(); ++customNodesItr )
+    {
+        // Fetch the custom node.
+        TamlCustomNode* pCustomNode = *customNodesItr;
+
+        // Write the custom node.
+        writeCustomNode( stream, pCustomNode );
+    }
+}
+
+//-----------------------------------------------------------------------------
+
+void TamlBinaryWriter::writeCustomNode( Stream& stream, const TamlCustomNode* pCustomNode )
+{
+    // Write custom node name.
+    stream.writeString( pCustomNode->mNodeName );
+
+    // Is the node a proxy object?
+    if ( pCustomNode->isProxyObject() )
+    {
+        // Yes, so flag as element.
+        stream.write( true );
+
+        // Write the element.
+        writeElement( stream, pCustomNode->getProxyWriteNode() );
+        return;
+    }
+
+    // No, so flag as custom node.
+    stream.write( false );
+
+    // Fetch node children.
+    const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
+
+    // Fetch node count.
+    const U32 customNodeCount = (U32)nodeChildren.size();
+
+    // Write custom node count.
+    stream.write( customNodeCount );
+
+    // Do we have any nodes.
+    if ( customNodeCount > 0 )
+    {
+        // Yes, so iterate children nodes.
+        for( TamlCustomNodeVector::const_iterator childNodeItr = nodeChildren.begin(); childNodeItr != nodeChildren.end(); ++childNodeItr )
+        {
+            // Fetch child node.
+            const TamlCustomNode* pChildNode = *childNodeItr;
+
+            // Write the custom node.
+            writeCustomNode( stream, pChildNode );
+        }
+    }
+
+    // Fetch node fields.
+    const TamlCustomFieldVector& nodeFields = pCustomNode->getFields();
+
+    // Fetch node field count.
+    const U32 nodeFieldCount = (U32)nodeFields.size();
+
+    // Write custom node field count.
+    stream.write( nodeFieldCount );
+
+    // Do we have any node fields?
+    if ( nodeFieldCount > 0 )
+    {
+        // Yes, so iterate node fields.
+        for ( TamlCustomFieldVector::const_iterator nodeFieldItr = nodeFields.begin(); nodeFieldItr != nodeFields.end(); ++nodeFieldItr )
+        {
+            // Fetch node field.
+            const TamlCustomNodeField* pNodeField = *nodeFieldItr;
+
+            // Write the node field.
+            stream.writeString( pNodeField->getFieldName() );
+            stream.writeLongString( MAX_TAML_NODE_FIELDVALUE_LENGTH, pNodeField->getFieldValue() );
+        }
+    }
 }

+ 2 - 1
engine/source/persistence/taml/tamlBinaryWriter.h

@@ -48,9 +48,10 @@ private:
 
 private:
     void writeElement( Stream& stream, const TamlWriteNode* pTamlWriteNode );
-    void writeCustomElements( Stream& stream, const TamlWriteNode* pTamlWriteNode );
     void writeAttributes( Stream& stream, const TamlWriteNode* pTamlWriteNode );
     void writeChildren( Stream& stream, const TamlWriteNode* pTamlWriteNode );
+    void writeCustomElements( Stream& stream, const TamlWriteNode* pTamlWriteNode );
+    void writeCustomNode( Stream& stream, const TamlCustomNode* pCustomNode );
 };
 
 #endif // _TAML_BINARYWRITER_H_

+ 8 - 7
engine/source/persistence/taml/tamlXmlWriter.cc

@@ -159,7 +159,7 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
     if ( nodes.size() == 0 )
         return;
 
-    // Iterate custom properties.
+    // Iterate custom nodes.
     for( TamlCustomNodeVector::const_iterator customNodesItr = nodes.begin(); customNodesItr != nodes.end(); ++customNodesItr )
     {
         // Fetch the custom node.
@@ -182,8 +182,8 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
             // Fetch child node.
             const TamlCustomNode* pChildNode = *childNodeItr;
 
-            // Compile the custom nodes.
-            compileCustomNodes( pExtendedPropertyElement, pChildNode );
+            // Compile the custom node.
+            compileCustomNode( pExtendedPropertyElement, pChildNode );
         }
 
         // Finish if the node is set to ignore if empty and it is empty.
@@ -203,7 +203,7 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
 
 //-----------------------------------------------------------------------------
 
-void TamlXmlWriter::compileCustomNodes( TiXmlElement* pXmlElement, const TamlCustomNode* pCustomNode )
+void TamlXmlWriter::compileCustomNode( TiXmlElement* pXmlElement, const TamlCustomNode* pCustomNode )
 {
     // Finish if the node is set to ignore if empty and it is empty.
     if ( pCustomNode->mIgnoreEmpty && pCustomNode->isEmpty() )
@@ -226,18 +226,19 @@ void TamlXmlWriter::compileCustomNodes( TiXmlElement* pXmlElement, const TamlCus
         {
             // Yes, so write the proxy object.
             pNodeElement->LinkEndChild( compileElement( pChildNode->getProxyWriteNode() ) );
+            continue;
         }
         else
         {
-            // No, so compile the child nodes.
-            compileCustomNodes( pNodeElement, pChildNode );
+            // No, so compile the child node.
+            compileCustomNode( pNodeElement, pChildNode );
         }
     }
 
     // Fetch node fields.
     const TamlCustomFieldVector& nodeFields = pCustomNode->getFields();
 
-    // Iterate property fields.
+    // Iterate node fields.
     for ( TamlCustomFieldVector::const_iterator nodeFieldItr = nodeFields.begin(); nodeFieldItr != nodeFields.end(); ++nodeFieldItr )
     {
         // Fetch node field.

+ 1 - 1
engine/source/persistence/taml/tamlXmlWriter.h

@@ -53,7 +53,7 @@ private:
     TiXmlNode* compileElement( const TamlWriteNode* pTamlWriteNode );
     void compileAttributes( TiXmlElement* pXmlElement, const TamlWriteNode* pTamlWriteNode );
     void compileCustomElements( TiXmlElement* pXmlElement, const TamlWriteNode* pTamlWriteNode );
-    void compileCustomNodes( TiXmlElement* pXmlElement, const TamlCustomNode* pCustomNode );
+    void compileCustomNode( TiXmlElement* pXmlElement, const TamlCustomNode* pCustomNode );
 };
 
 #endif // _TAML_XMLWRITER_H_