瀏覽代碼

Merge pull request #210 from blackberry-gaming/next-dgough

Next dgough
Sean Paul Taylor 13 年之前
父節點
當前提交
83a9fc6b04

+ 0 - 2
gameplay/gameplay.vcxproj

@@ -30,7 +30,6 @@
     <ClCompile Include="src\Button.cpp" />
     <ClCompile Include="src\Camera.cpp" />
     <ClCompile Include="src\CheckBox.cpp" />
-    <ClCompile Include="src\CloneContext.cpp" />
     <ClCompile Include="src\Container.cpp" />
     <ClCompile Include="src\Control.cpp" />
     <ClCompile Include="src\Curve.cpp" />
@@ -121,7 +120,6 @@
     <ClInclude Include="src\Button.h" />
     <ClInclude Include="src\Camera.h" />
     <ClInclude Include="src\CheckBox.h" />
-    <ClInclude Include="src\CloneContext.h" />
     <ClInclude Include="src\Container.h" />
     <ClInclude Include="src\Control.h" />
     <ClInclude Include="src\Curve.h" />

+ 0 - 6
gameplay/gameplay.vcxproj.filters

@@ -276,9 +276,6 @@
     <ClCompile Include="src\PhysicsCollisionShape.cpp">
       <Filter>src</Filter>
     </ClCompile>
-    <ClCompile Include="src\CloneContext.cpp">
-      <Filter>src</Filter>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">
@@ -548,9 +545,6 @@
     <ClInclude Include="src\PhysicsCollisionShape.h">
       <Filter>src</Filter>
     </ClInclude>
-    <ClInclude Include="src\CloneContext.h">
-      <Filter>src</Filter>
-    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="res\shaders\bumped-specular.vsh">

+ 3 - 2
gameplay/src/AnimationTarget.cpp

@@ -2,6 +2,7 @@
 #include "AnimationTarget.h"
 #include "Animation.h"
 #include "Game.h"
+#include "Node.h"
 
 namespace gameplay
 {
@@ -118,7 +119,7 @@ void AnimationTarget::deleteChannel(Animation::Channel* channel)
     }
 }
 
-void AnimationTarget::cloneInto(AnimationTarget* target, CloneContext &context) const
+void AnimationTarget::cloneInto(AnimationTarget* target, NodeCloneContext &context) const
 {
     if (_animationChannels)
     {
@@ -129,7 +130,7 @@ void AnimationTarget::cloneInto(AnimationTarget* target, CloneContext &context)
 
             bool animationCloned = false;
 
-            // Don't clone the Animaton if it is already in the CloneContext.
+            // Don't clone the Animaton if it is already in the clone context.
             Animation* animation = context.findClonedAnimation(channel->_animation);
             if (animation == NULL)
             {

+ 2 - 2
gameplay/src/AnimationTarget.h

@@ -3,13 +3,13 @@
 
 #include "Curve.h"
 #include "AnimationController.h"
-#include "CloneContext.h"
 
 namespace gameplay
 {
 
 class Animation;
 class AnimationValue;
+class NodeCloneContext;
 
 /**
  * Defines an interface allowing animation to target
@@ -87,7 +87,7 @@ protected:
      * @param target The target to copy into.
      * @param context The clone context.
      */
-    void cloneInto(AnimationTarget* target, CloneContext &context) const;
+    void cloneInto(AnimationTarget* target, NodeCloneContext &context) const;
 
     TargetType _targetType;             // The type of target this is.
 

+ 2 - 1
gameplay/src/AudioSource.cpp

@@ -4,6 +4,7 @@
 #include "AudioController.h"
 #include "AudioSource.h"
 #include "Game.h"
+#include "Node.h"
 
 namespace gameplay
 {
@@ -481,7 +482,7 @@ void AudioSource::transformChanged(Transform* transform, long cookie)
 #endif
 }
 
-AudioSource* AudioSource::clone(CloneContext &context) const
+AudioSource* AudioSource::clone(NodeCloneContext &context) const
 {
 #ifndef __ANDROID__
     ALuint alSource = 0;

+ 2 - 1
gameplay/src/AudioSource.h

@@ -10,6 +10,7 @@ namespace gameplay
 
 class AudioBuffer;
 class Node;
+class NodeCloneContext;
 
 /**
  *  Declares an audio source in 3D space.
@@ -183,7 +184,7 @@ private:
      * 
      * @return The newly created audio source.
      */
-    AudioSource* clone(CloneContext &context) const;
+    AudioSource* clone(NodeCloneContext &context) const;
 
 #ifndef __ANDROID__
     ALuint _alSource;

+ 1 - 1
gameplay/src/Camera.cpp

@@ -343,7 +343,7 @@ void Camera::pickRay(const Viewport* viewport, float x, float y, Ray* dst)
     dst->set(nearPoint, direction);
 }
 
-Camera* Camera::clone(CloneContext &context) const
+Camera* Camera::clone(NodeCloneContext &context) const
 {
     Camera* cameraClone = NULL;
     if (getCameraType() == PERSPECTIVE)

+ 2 - 1
gameplay/src/Camera.h

@@ -10,6 +10,7 @@ namespace gameplay
 {
 
 class Node;
+class NodeCloneContext;
 
 /**
  * Defines a camera which acts as a view of a scene to be rendered.
@@ -252,7 +253,7 @@ private:
      * 
      * @return The newly created camera.
      */
-    Camera* clone(CloneContext &context) const;
+    Camera* clone(NodeCloneContext &context) const;
 
     /**
      * @see Transform::Listener::transformChanged

+ 0 - 38
gameplay/src/CloneContext.cpp

@@ -1,38 +0,0 @@
-#include "CloneContext.h"
-
-namespace gameplay
-{
-
-CloneContext::CloneContext()
-{
-    
-}
-
-CloneContext::~CloneContext()
-{
-
-}
-
-Animation* CloneContext::findClonedAnimation(const Animation* animation)
-{
-    AnimationMap::iterator it = _clonedAnimations.find(animation);
-    return it != _clonedAnimations.end() ? it->second : NULL;
-}
-
-void CloneContext::registerClonedAnimation(const Animation* original, Animation* clone)
-{
-    _clonedAnimations[original] = clone;
-}
-
-Node* CloneContext::findClonedNode(const Node* node)
-{
-    NodeMap::iterator it = _clonedNodes.find(node);
-    return it != _clonedNodes.end() ? it->second : NULL;
-}
-
-void CloneContext::registerClonedNode(const Node* original, Node* clone)
-{
-    _clonedNodes[original] = clone;
-}
-
-}

+ 0 - 86
gameplay/src/CloneContext.h

@@ -1,86 +0,0 @@
-#ifndef CLONECONTEXT_H_
-#define CLONECONTEXT_H_
-
-#include <map>
-
-namespace gameplay
-{
-    class Animation;
-    class Node;
-
-/**
- * CloneContext represents the context data that is kept when cloning a node.
- * 
- * The CloneContext is used to make sure objects don't get cloned twice.
- */
-class CloneContext
-{
-public:
-
-    /**
-     * Constructor.
-     */
-    CloneContext();
-
-    /**
-     * Destructor.
-     */
-    ~CloneContext();
-
-    /**
-     * Finds the cloned animation of the given animation or NULL if this animation was not registered with this context.
-     * 
-     * @param animation The animation to search for the cloned copy of.
-     * 
-     * @return The cloned animation or NULL if not found.
-     */
-    Animation* findClonedAnimation(const Animation* animation);
-
-    /**
-     * Registers the cloned animation with this context so that it doesn't get cloned twice.
-     * 
-     * @param original The pointer to the original animation.
-     * @param clone The pointer to the cloned animation.
-     */
-    void registerClonedAnimation(const Animation* original, Animation* clone);
-
-    /**
-     * Finds the cloned node of the given node or NULL if this node was not registered with this context.
-     * 
-     * @param node The node to search for the cloned copy of.
-     * 
-     * @return The cloned node or NULL if not found.
-     */
-    Node* findClonedNode(const Node* node);
-
-    /**
-     * Registers the cloned node with this context so that it doens't get cloned twice.
-     * 
-     * @param original The pointer to the original node.
-     * @param clone The pointer to the cloned node.
-     */
-    void registerClonedNode(const Node* original, Node* clone);
-
-private:
-    
-    /**
-     * Hidden copy constructor.
-     */
-    CloneContext(const CloneContext&);
-
-    /**
-     * Hidden copy assignment operator.
-     */
-    CloneContext& operator=(const CloneContext&);
-
-private:
-    typedef std::map<const Animation*, Animation*> AnimationMap;
-    typedef std::map<const Node*, Node*> NodeMap;
-
-    AnimationMap _clonedAnimations;
-    NodeMap _clonedNodes;
-};
-
-}
-
-#endif

+ 1 - 1
gameplay/src/Joint.cpp

@@ -19,7 +19,7 @@ Joint* Joint::create(const char* id)
     return new Joint(id);
 }
 
-Node* Joint::cloneSingleNode(CloneContext &context) const
+Node* Joint::cloneSingleNode(NodeCloneContext &context) const
 {
     Joint* copy = Joint::create(getId());
     context.registerClonedNode(this, copy);

+ 1 - 1
gameplay/src/Joint.h

@@ -61,7 +61,7 @@ protected:
      * 
      * @return Pointer to the newly created joint.
      */
-    virtual Node* cloneSingleNode(CloneContext &context) const;
+    virtual Node* cloneSingleNode(NodeCloneContext &context) const;
 
     /**
      * Sets the inverse bind pose matrix.

+ 1 - 1
gameplay/src/Light.cpp

@@ -196,7 +196,7 @@ float Light::getOuterAngleCos()  const
     return _spot->outerAngleCos;
 }
 
-Light* Light::clone(CloneContext &context) const
+Light* Light::clone(NodeCloneContext &context) const
 {
     Light* lightClone = NULL;
     switch (_type)

+ 2 - 2
gameplay/src/Light.h

@@ -3,12 +3,12 @@
 
 #include "Ref.h"
 #include "Vector3.h"
-#include "CloneContext.h"
 
 namespace gameplay
 {
 
 class Node;
+class NodeCloneContext;
 
 /**
  * Defines a light.
@@ -231,7 +231,7 @@ private:
      * 
      * @return The newly created light.
      */
-    Light* clone(CloneContext &context) const;
+    Light* clone(NodeCloneContext &context) const;
 
     Light::Type _type;
     union

+ 2 - 1
gameplay/src/Material.cpp

@@ -5,6 +5,7 @@
 #include "Technique.h"
 #include "Pass.h"
 #include "Properties.h"
+#include "Node.h"
 
 namespace gameplay
 {
@@ -125,7 +126,7 @@ Material* Material::create(const char* vshPath, const char* fshPath, const char*
     return material;
 }
 
-Material* Material::clone(CloneContext &context) const
+Material* Material::clone(NodeCloneContext &context) const
 {
     Material* material = new Material();
     RenderState::cloneInto(material, context);

+ 3 - 1
gameplay/src/Material.h

@@ -8,6 +8,8 @@
 namespace gameplay
 {
 
+class NodeCloneContext;
+
 /**
  * Defines a material for an object to be rendered.
  *
@@ -75,7 +77,7 @@ public:
      * 
      * @return The newly created material.
      */
-    Material* clone(CloneContext &context) const;
+    Material* clone(NodeCloneContext &context) const;
 
     /**
      * Returns the number of techniques in the material.

+ 1 - 1
gameplay/src/Model.cpp

@@ -359,7 +359,7 @@ void Model::validatePartCount()
     }
 }
 
-Model* Model::clone(CloneContext &context)
+Model* Model::clone(NodeCloneContext &context)
 {
     Model* model = Model::create(getMesh());
     if (getSkin())

+ 2 - 1
gameplay/src/Model.h

@@ -11,6 +11,7 @@ namespace gameplay
 class Package;
 class MeshSkin;
 class Node;
+class NodeCloneContext;
 
 /**
  * Defines a Model which is an instance of a Mesh that can be drawn
@@ -184,7 +185,7 @@ private:
      * 
      * @return The new cloned model.
      */
-    Model* clone(CloneContext &context);
+    Model* clone(NodeCloneContext &context);
 
     Mesh* _mesh;
     Material* _material;

+ 36 - 4
gameplay/src/Node.cpp

@@ -704,11 +704,11 @@ const BoundingSphere& Node::getBoundingSphere() const
 
 Node* Node::clone() const
 {
-    CloneContext context;
+    NodeCloneContext context;
     return cloneRecursive(context);
 }
 
-Node* Node::cloneSingleNode(CloneContext &context) const
+Node* Node::cloneSingleNode(NodeCloneContext &context) const
 {
     Node* copy = Node::create(getId());
     context.registerClonedNode(this, copy);
@@ -716,7 +716,7 @@ Node* Node::cloneSingleNode(CloneContext &context) const
     return copy;
 }
 
-Node* Node::cloneRecursive(CloneContext &context) const
+Node* Node::cloneRecursive(NodeCloneContext &context) const
 {
     Node* copy = cloneSingleNode(context);
 
@@ -729,7 +729,7 @@ Node* Node::cloneRecursive(CloneContext &context) const
     return copy;
 }
 
-void Node::cloneInto(Node* node, CloneContext &context) const
+void Node::cloneInto(Node* node, NodeCloneContext &context) const
 {
     Transform::cloneInto(node, context);
 
@@ -867,4 +867,36 @@ PhysicsCollisionObject* Node::setCollisionObject(Properties* properties)
 	return _collisionObject;
 }
 
+NodeCloneContext::NodeCloneContext()
+{
+    
+}
+
+NodeCloneContext::~NodeCloneContext()
+{
+
+}
+
+Animation* NodeCloneContext::findClonedAnimation(const Animation* animation)
+{
+    AnimationMap::iterator it = _clonedAnimations.find(animation);
+    return it != _clonedAnimations.end() ? it->second : NULL;
+}
+
+void NodeCloneContext::registerClonedAnimation(const Animation* original, Animation* clone)
+{
+    _clonedAnimations[original] = clone;
+}
+
+Node* NodeCloneContext::findClonedNode(const Node* node)
+{
+    NodeMap::iterator it = _clonedNodes.find(node);
+    return it != _clonedNodes.end() ? it->second : NULL;
+}
+
+void NodeCloneContext::registerClonedNode(const Node* original, Node* clone)
+{
+    _clonedNodes[original] = clone;
+}
+
 }

+ 76 - 3
gameplay/src/Node.h

@@ -477,7 +477,7 @@ protected:
      * 
      * @return Pointer to the newly created node.
      */
-    virtual Node* cloneSingleNode(CloneContext &context) const;
+    virtual Node* cloneSingleNode(NodeCloneContext &context) const;
 
     /**
      * Recursively clones this node and its children.
@@ -486,7 +486,7 @@ protected:
      * 
      * @return The newly created node.
      */
-    Node* cloneRecursive(CloneContext &context) const;
+    Node* cloneRecursive(NodeCloneContext &context) const;
 
     /**
      * Copies the data from this node into the given node.
@@ -494,7 +494,7 @@ protected:
      * @param node The node to copy the data to.
      * @param context The clone context.
      */
-    void cloneInto(Node* node, CloneContext &context) const;
+    void cloneInto(Node* node, NodeCloneContext &context) const;
 
     /**
      * Removes this node from its parent.
@@ -550,6 +550,79 @@ protected:
     mutable BoundingSphere _bounds;
 };
 
+/**
+ * NodeCloneContext represents the context data that is kept when cloning a node.
+ * 
+ * The NodeCloneContext is used to make sure objects don't get cloned twice.
+ */
+class NodeCloneContext
+{
+public:
+
+    /**
+     * Constructor.
+     */
+    NodeCloneContext();
+
+    /**
+     * Destructor.
+     */
+    ~NodeCloneContext();
+
+    /**
+     * Finds the cloned animation of the given animation or NULL if this animation was not registered with this context.
+     * 
+     * @param animation The animation to search for the cloned copy of.
+     * 
+     * @return The cloned animation or NULL if not found.
+     */
+    Animation* findClonedAnimation(const Animation* animation);
+
+    /**
+     * Registers the cloned animation with this context so that it doesn't get cloned twice.
+     * 
+     * @param original The pointer to the original animation.
+     * @param clone The pointer to the cloned animation.
+     */
+    void registerClonedAnimation(const Animation* original, Animation* clone);
+
+    /**
+     * Finds the cloned node of the given node or NULL if this node was not registered with this context.
+     * 
+     * @param node The node to search for the cloned copy of.
+     * 
+     * @return The cloned node or NULL if not found.
+     */
+    Node* findClonedNode(const Node* node);
+
+    /**
+     * Registers the cloned node with this context so that it doens't get cloned twice.
+     * 
+     * @param original The pointer to the original node.
+     * @param clone The pointer to the cloned node.
+     */
+    void registerClonedNode(const Node* original, Node* clone);
+
+private:
+    
+    /**
+     * Hidden copy constructor.
+     */
+    NodeCloneContext(const NodeCloneContext&);
+
+    /**
+     * Hidden copy assignment operator.
+     */
+    NodeCloneContext& operator=(const NodeCloneContext&);
+
+private:
+    typedef std::map<const Animation*, Animation*> AnimationMap;
+    typedef std::map<const Node*, Node*> NodeMap;
+
+    AnimationMap _clonedAnimations;
+    NodeMap _clonedNodes;
+};
+
 }
 
 #endif

+ 2 - 1
gameplay/src/Pass.cpp

@@ -2,6 +2,7 @@
 #include "Pass.h"
 #include "Technique.h"
 #include "Material.h"
+#include "Node.h"
 
 namespace gameplay
 {
@@ -79,7 +80,7 @@ void Pass::unbind()
     }
 }
 
-Pass* Pass::clone(Technique* technique, CloneContext &context) const
+Pass* Pass::clone(Technique* technique, NodeCloneContext &context) const
 {
     Effect* effect = getEffect();
     effect->addRef();

+ 2 - 1
gameplay/src/Pass.h

@@ -8,6 +8,7 @@ namespace gameplay
 {
 
 class Technique;
+class NodeCloneContext;
 
 /**
  * Defines a pass for an object to be rendered.
@@ -100,7 +101,7 @@ private:
      * 
      * @return The newly created Pass.
      */
-    Pass* clone(Technique* technique, CloneContext &context) const;
+    Pass* clone(Technique* technique, NodeCloneContext &context) const;
 
     std::string _id;
     Technique* _technique;

+ 2 - 1
gameplay/src/RenderState.cpp

@@ -3,6 +3,7 @@
 #include "Node.h"
 #include "Pass.h"
 #include "Technique.h"
+#include "Node.h"
 
 // Render state override bits
 #define RS_BLEND 1
@@ -307,7 +308,7 @@ RenderState* RenderState::getTopmost(RenderState* below)
     return NULL;
 }
 
-void RenderState::cloneInto(RenderState* renderState, CloneContext& context) const
+void RenderState::cloneInto(RenderState* renderState, NodeCloneContext& context) const
 {
     for (std::map<std::string, AutoBinding>::const_iterator it = _autoBindings.begin(); it != _autoBindings.end(); ++it)
     {

+ 2 - 2
gameplay/src/RenderState.h

@@ -2,13 +2,13 @@
 #define RENDERSTATE_H_
 
 #include "Ref.h"
-#include "CloneContext.h"
 
 namespace gameplay
 {
 
 class MaterialParameter;
 class Node;
+class NodeCloneContext;
 class Pass;
 
 class RenderState : public Ref
@@ -338,7 +338,7 @@ protected:
      * @param renderState The RenderState to copy the data to.
      * @param context The clone context.
      */
-    void cloneInto(RenderState* renderState, CloneContext& context) const;
+    void cloneInto(RenderState* renderState, NodeCloneContext& context) const;
 
 private:
 

+ 2 - 1
gameplay/src/Technique.cpp

@@ -1,6 +1,7 @@
 #include "Base.h"
 #include "Technique.h"
 #include "Material.h"
+#include "Node.h"
 
 namespace gameplay
 {
@@ -53,7 +54,7 @@ Pass* Technique::getPass(const char* id) const
     return NULL;
 }
 
-Technique* Technique::clone(Material* material, CloneContext &context) const
+Technique* Technique::clone(Material* material, NodeCloneContext &context) const
 {
     Technique* technique = new Technique(getId(), material);
     technique->_material = material;

+ 2 - 1
gameplay/src/Technique.h

@@ -7,6 +7,7 @@ namespace gameplay
 {
 
 class Material;
+class NodeCloneContext;
 
 /**
  * Defines a technique for an object to be rendered.
@@ -63,7 +64,7 @@ private:
      */
     Technique& operator=(const Technique&);
 
-    Technique* clone(Material* material, CloneContext &context) const;
+    Technique* clone(Material* material, NodeCloneContext &context) const;
 
     std::string _id;
     Material* _material;

+ 2 - 1
gameplay/src/Transform.cpp

@@ -1,6 +1,7 @@
 #include "Base.h"
 #include "Transform.h"
 #include "Game.h"
+#include "Node.h"
 
 namespace gameplay
 {
@@ -780,7 +781,7 @@ void Transform::transformChanged()
     }
 }
 
-void Transform::cloneInto(Transform* transform, CloneContext &context) const
+void Transform::cloneInto(Transform* transform, NodeCloneContext &context) const
 {
     AnimationTarget::cloneInto(transform, context);
     transform->_scale.set(_scale);

+ 2 - 1
gameplay/src/Transform.h

@@ -12,6 +12,7 @@ namespace gameplay
 
 class BoundingBox;
 class BoundingSphere;
+class NodeCloneContext;
 
 /**
  * Defines a 3-dimensional transformation.
@@ -737,7 +738,7 @@ protected:
 
     void dirty();
     virtual void transformChanged();
-    void cloneInto(Transform* transform, CloneContext &context) const;
+    void cloneInto(Transform* transform, NodeCloneContext &context) const;
 
     Vector3 _scale;
     Quaternion _rotation;