Browse Source

- Taml serialization WIP.

MelvMay-GG 12 years ago
parent
commit
33be5e8

+ 1 - 1
engine/source/2d/core/SpriteBatchItem.cc

@@ -580,5 +580,5 @@ void SpriteBatchItem::onTamlCustomRead( const TamlCustomNode* pSpriteNode )
 
     // Set the data object if a single child exists.
     if ( spriteChildren.size() == 1 )
-        setDataObject( spriteChildren[0]->composeProxyObject<SimObject>() );
+        setDataObject( spriteChildren[0]->getProxyObject<SimObject>(true) );
 }

+ 20 - 20
engine/source/2d/scene/Scene.cc

@@ -3646,8 +3646,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -3714,8 +3714,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -3772,8 +3772,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -3861,8 +3861,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -3924,8 +3924,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -4013,8 +4013,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -4076,8 +4076,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -4169,8 +4169,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -4248,7 +4248,7 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObject = jointChildren.size() == 1 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObject = jointChildren.size() == 1 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObject == NULL )
@@ -4309,8 +4309,8 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
                 const TamlCustomNodeVector& jointChildren = pJointNode->getChildren();
 
                 // Fetch joint objects.
-                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->composeProxyObject<SceneObject>() : NULL;
-                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->composeProxyObject<SceneObject>() : NULL;
+                SceneObject* pSceneObjectA = jointChildren.size() > 0 ? jointChildren[0]->getProxyObject<SceneObject>(true) : NULL;
+                SceneObject* pSceneObjectB = jointChildren.size() == 2 ? jointChildren[1]->getProxyObject<SceneObject>(true) : NULL;
 
                 // Did we get any connected objects?
                 if( pSceneObjectA == NULL && pSceneObjectB == NULL )
@@ -4411,7 +4411,7 @@ void Scene::onTamlPostRead( const TamlCustomNodes& customNodes )
             }
 
             // Add the proxy object.
-            SimObject* pProxyObject = pControllerNode->getProxyObject();
+            SimObject* pProxyObject = pControllerNode->getProxyObject<SimObject>(false);
 
             // Is it a scene controller?
             if ( dynamic_cast<SceneController*>( pProxyObject ) == NULL )

+ 32 - 1
engine/source/2d/sceneobject/SceneObject.cc

@@ -3687,7 +3687,8 @@ void SceneObject::onTamlCustomRead( const TamlCustomNodes& customNodes )
             const U32 shapeChildrenCount = (U32)shapeChildren.size();
 
             // Do we have any shape children.
-            if ( shapeChildrenCount > 0 )
+            // NOTE: Only do this if the old methods has not been used.
+            if ( pointCount == 0 && shapeChildrenCount > 0 )
             {
                 // Yes, so iterate them.
                 for( TamlCustomNodeVector::const_iterator childItr = shapeChildren.begin(); childItr != shapeChildren.end(); ++childItr )
@@ -3779,6 +3780,36 @@ void SceneObject::onTamlCustomRead( const TamlCustomNodes& customNodes )
                 }
             }
 
+            // Fetch shape children.
+            const TamlCustomNodeVector& shapeChildren = pShapeNode->getChildren();
+
+            // Fetch shape children count.
+            const U32 shapeChildrenCount = (U32)shapeChildren.size();
+
+            // Do we have any shape children.
+            // NOTE: Only do this if the old methods has not been used.
+            if ( points.size() == 0 && shapeChildrenCount > 0 )
+            {
+                // Yes, so iterate them.
+                for( TamlCustomNodeVector::const_iterator childItr = shapeChildren.begin(); childItr != shapeChildren.end(); ++childItr )
+                {
+                    TamlCustomNode* pChildNode = *childItr;
+
+                    // Skip if it's not a point.
+                    if ( pChildNode->getNodeName() != polygonPointName )
+                        continue;
+                    
+                    // Skip if it's empty.
+                    if ( pChildNode->getNodeTextField().isValueEmpty() )
+                        continue;
+
+                    // Read point.
+                    b2Vec2 point;
+                    pChildNode->getNodeTextField().getFieldValue( point );
+                    points.push_back( point );
+                }
+            }
+
             // Is point count valid?
             if ( points.size() == 0 )
             {

+ 1 - 1
engine/source/persistence/taml/taml.cc

@@ -716,7 +716,7 @@ void Taml::compileCustomNodeState( TamlCustomNode* pCustomNode )
     const TamlCustomNodeVector& children = pCustomNode->getChildren();
 
     // Fetch proxy object.
-    SimObject* pProxyObject = pCustomNode->getProxyObject();
+    SimObject* pProxyObject = pCustomNode->getProxyObject<SimObject>(false);
 
     // Do we have a proxy object?
     if ( pProxyObject != NULL )

+ 19 - 1
engine/source/persistence/taml/tamlCustom.h

@@ -508,7 +508,25 @@ public:
     inline const TamlCustomFieldVector& getFields( void ) const { return mFields; }
 
     inline bool isProxyObject( void ) const { return mpProxyObject != NULL; }
-    inline SimObject* getProxyObject( void ) const { return mpProxyObject != NULL ? mpProxyObject : NULL; }
+    template<typename T> T* getProxyObject( const bool deleteIfNotType ) const
+    {
+        // Return nothing if no proxy object.
+        if ( mpProxyObject == NULL )
+            return NULL;
+
+        // Cast object to specified type.
+        T* pTypeCast = dynamic_cast<T*>( mpProxyObject );
+
+        // Destroy the object if not the specified type and requested to do so.
+        if ( deleteIfNotType && pTypeCast == NULL )
+        {
+            mpProxyObject->deleteObject();
+            const_cast<SimObject*>(mpProxyObject) = NULL;
+            return NULL;
+        }
+
+        return pTypeCast;
+    }
     inline const TamlWriteNode* getProxyWriteNode( void ) const { return mpProxyWriteNode; }
 
     inline bool isEmpty( void ) const { return mNodeText.isValueEmpty() && mFields.size() == 0 && mChildren.size() == 0; }