Prechádzať zdrojové kódy

Added CloneContext class.

Darryl Gough 13 rokov pred
rodič
commit
f87a1195bb
2 zmenil súbory, kde vykonal 124 pridanie a 0 odobranie
  1. 38 0
      gameplay/src/CloneContext.cpp
  2. 86 0
      gameplay/src/CloneContext.h

+ 38 - 0
gameplay/src/CloneContext.cpp

@@ -0,0 +1,38 @@
+#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;
+}
+
+}

+ 86 - 0
gameplay/src/CloneContext.h

@@ -0,0 +1,86 @@
+#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