Browse Source

- Taml serialization WIP.

MelvMay-GG 12 years ago
parent
commit
5a3b2a4

+ 15 - 47
engine/source/persistence/taml/tamlCustom.cc

@@ -28,18 +28,6 @@
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-void TamlCustomNodeField::resetState( void )
-{
-    mFieldName = StringTable->EmptyString;
-    *mFieldValue = 0;
-
-    // We don't need to delete the write node as it'll get destroyed when the compilation is reset!
-    mpFieldWriteNode = NULL;
-    mpFieldObject = NULL;
-}
-
-//-----------------------------------------------------------------------------
-
 void TamlCustomNodeField::set( const char* pFieldName, const char* pFieldValue )
 void TamlCustomNodeField::set( const char* pFieldName, const char* pFieldValue )
 {
 {
     // Sanity!
     // Sanity!
@@ -61,59 +49,39 @@ void TamlCustomNodeField::set( const char* pFieldName, const char* pFieldValue )
 #endif
 #endif
     // Copy field value.
     // Copy field value.
     dStrcpy( mFieldValue, pFieldValue );
     dStrcpy( mFieldValue, pFieldValue );
-
-    // Reset field object.
-    mpFieldObject = NULL;
-    SAFE_DELETE( mpFieldWriteNode );
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-void TamlCustomNodeField::set( const char* pFieldName, SimObject* pFieldObject )
+void TamlCustomNode::set( const char* pFieldName, SimObject* pProxyObject )
 {
 {
     // Sanity!
     // Sanity!
     AssertFatal( pFieldName != NULL, "Field name cannot be NULL." );
     AssertFatal( pFieldName != NULL, "Field name cannot be NULL." );
-    AssertFatal( pFieldObject != NULL, "Field object cannot be NULL." );
-    AssertFatal( mpFieldWriteNode == NULL, "Field write node must be NULL." );
+    AssertFatal( pProxyObject != NULL, "Field object cannot be NULL." );
+    AssertFatal( mpProxyWriteNode == NULL, "Field write node must be NULL." );
 
 
-    // Set field name.
-    mFieldName = StringTable->insert( pFieldName );
+    // Set node name.
+    mNodeName = StringTable->insert( pFieldName );
 
 
-    mpFieldObject = pFieldObject;
-    SAFE_DELETE( mpFieldWriteNode );
+    // Set proxy object.
+    mpProxyObject = pProxyObject;
 
 
-    // Reset field value.
-    *mFieldValue = 0;
+    // Remove any existing proxy write node.
+    SAFE_DELETE( mpProxyWriteNode );
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-void TamlCustomNodeField::setWriteNode( TamlWriteNode* pWriteNode )
+void TamlCustomNode::setWriteNode( TamlWriteNode* pWriteNode )
 {
 {
     // Sanity!
     // Sanity!
-    AssertFatal( mFieldName != StringTable->EmptyString, "Cannot set write node with an empty field name." );
+    AssertFatal( mNodeName != StringTable->EmptyString, "Cannot set write node with an empty node name." );
     AssertFatal( pWriteNode != NULL, "Write node cannot be NULL." );
     AssertFatal( pWriteNode != NULL, "Write node cannot be NULL." );
-    AssertFatal( pWriteNode->mpSimObject == mpFieldObject, "Write node does not match existing field object." );
-    AssertFatal( mpFieldWriteNode == NULL, "Field write node must be NULL." );
-
-    // Set field object.
-    mpFieldWriteNode = pWriteNode;
+    AssertFatal( pWriteNode->mpSimObject == mpProxyObject, "Write node does not match existing proxy object." );
+    AssertFatal( mpProxyWriteNode == NULL, "Field write node must be NULL." );
 
 
-    // Reset field value.
-    *mFieldValue = 0;
+    // Set proxy write node.
+    mpProxyWriteNode = pWriteNode;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-
-SimObject* TamlCustomNodeField::getFieldObject( void ) const
-{
-    return mpFieldObject != NULL ? mpFieldObject : NULL;
-}
-
-//-----------------------------------------------------------------------------
-
-bool TamlCustomNodeField::isObjectField( void ) const
-{
-    return mpFieldObject != NULL;
-}
 
 

+ 27 - 18
engine/source/persistence/taml/tamlCustom.h

@@ -64,11 +64,6 @@ class TamlCustomNodeField : public IFactoryObjectReset
 public:
 public:
     TamlCustomNodeField()
     TamlCustomNodeField()
     {
     {
-        // Reset field object.
-        // NOTE: This MUST be done before the state is reset otherwise we'll be touching uninitialized stuff.
-        mpFieldWriteNode = NULL;
-        mpFieldObject = NULL;
-
         resetState();
         resetState();
     }
     }
 
 
@@ -80,14 +75,14 @@ public:
         // pretty much anything or everything could be invalid!
         // pretty much anything or everything could be invalid!
     }
     }
 
 
-    virtual void resetState( void );
+    virtual void resetState( void )
+    {
+        mFieldName = StringTable->EmptyString;
+        *mFieldValue = 0;
+    }
 
 
     void set( const char* pFieldName, const char* pFieldValue );
     void set( const char* pFieldName, const char* pFieldValue );
 
 
-    void set( const char* pFieldName, SimObject* pFieldObject );
-
-    void setWriteNode( TamlWriteNode* pWriteNode );
-
     inline void getFieldValue( ColorF& fieldValue ) const
     inline void getFieldValue( ColorF& fieldValue ) const
     {
     {
         fieldValue.set( 1.0f, 1.0f, 1.0f, 1.0f );
         fieldValue.set( 1.0f, 1.0f, 1.0f, 1.0f );
@@ -158,12 +153,6 @@ public:
         return mFieldValue;
         return mFieldValue;
     }
     }
 
 
-    SimObject* getFieldObject( void ) const;
-
-    inline const TamlWriteNode* getWriteNode( void ) const { return mpFieldWriteNode; }
-
-    bool isObjectField( void ) const;
-
     inline StringTableEntry getFieldName( void ) const { return mFieldName; }
     inline StringTableEntry getFieldName( void ) const { return mFieldName; }
 
 
     bool fieldNameBeginsWith( const char* pComparison )
     bool fieldNameBeginsWith( const char* pComparison )
@@ -191,8 +180,6 @@ public:
 private:
 private:
     StringTableEntry    mFieldName;
     StringTableEntry    mFieldName;
     char                mFieldValue[MAX_TAML_NODE_FIELDVALUE_LENGTH];
     char                mFieldValue[MAX_TAML_NODE_FIELDVALUE_LENGTH];
-    SimObject*          mpFieldObject;
-    TamlWriteNode*      mpFieldWriteNode;
 };
 };
 
 
 static FactoryCache<TamlCustomNodeField> TamlCustomNodeFieldFactory;
 static FactoryCache<TamlCustomNodeField> TamlCustomNodeFieldFactory;
@@ -205,6 +192,11 @@ class TamlCustomNode : public IFactoryObjectReset
 public:
 public:
     TamlCustomNode()
     TamlCustomNode()
     {
     {
+        // Reset proxy object.
+        // NOTE: This MUST be done before the state is reset otherwise we'll be touching uninitialized stuff.
+        mpProxyWriteNode = NULL;
+        mpProxyObject = NULL;
+
         resetState();
         resetState();
     }
     }
 
 
@@ -218,6 +210,10 @@ public:
 
 
     virtual void resetState( void )
     virtual void resetState( void )
     {
     {
+        // We don't need to delete the write node as it'll get destroyed when the compilation is reset!
+        mpProxyWriteNode = NULL;
+        mpProxyObject = NULL;
+
         // Cache the children.
         // Cache the children.
         while ( mChildren.size() > 0 )
         while ( mChildren.size() > 0 )
         {
         {
@@ -247,6 +243,10 @@ public:
         mNodeName = StringTable->insert( pNodeName );
         mNodeName = StringTable->insert( pNodeName );
     }
     }
 
 
+    void set( const char* pNodeName, SimObject* pProxyObject );
+
+    void setWriteNode( TamlWriteNode* pWriteNode );
+
     TamlCustomNode* addNode( const char* pNodeName, const bool ignoreEmpty = true )
     TamlCustomNode* addNode( const char* pNodeName, const bool ignoreEmpty = true )
     {
     {
         // Create a custom node.
         // Create a custom node.
@@ -467,6 +467,12 @@ public:
         return NULL;
         return NULL;
     }
     }
 
 
+    inline bool isProxyObject( void ) const { return mpProxyObject != NULL; }
+    SimObject* getProxyObject( void ) const { return mpProxyObject != NULL ? mpProxyObject : NULL; }
+    inline const TamlWriteNode* getProxyWriteNode( void ) const { return mpProxyWriteNode; }
+
+
+
     const TamlCustomNodeVector& getChildren( void ) const { return mChildren; }
     const TamlCustomNodeVector& getChildren( void ) const { return mChildren; }
     const TamlCustomFieldVector& getFields( void ) const { return mFields; }
     const TamlCustomFieldVector& getFields( void ) const { return mFields; }
 
 
@@ -474,6 +480,9 @@ public:
     Vector<TamlCustomNode*> mChildren;
     Vector<TamlCustomNode*> mChildren;
     TamlCustomFieldVector   mFields;
     TamlCustomFieldVector   mFields;
     bool                    mIgnoreEmpty;
     bool                    mIgnoreEmpty;
+
+    SimObject*              mpProxyObject;
+    TamlWriteNode*          mpProxyWriteNode;
 };
 };
 
 
 static FactoryCache<TamlCustomNode> TamlCustomNodeFactory;
 static FactoryCache<TamlCustomNode> TamlCustomNodeFactory;