瀏覽代碼

Remove the Ref::Hold inner class.

Jon Watte 10 年之前
父節點
當前提交
c1072bdb21
共有 3 個文件被更改,包括 9 次插入38 次删除
  1. 6 2
      gameplay/src/AnimationClip.cpp
  2. 3 1
      gameplay/src/Control.cpp
  3. 0 35
      gameplay/src/Ref.h

+ 6 - 2
gameplay/src/AnimationClip.cpp

@@ -588,7 +588,7 @@ bool AnimationClip::update(float elapsedTime)
 
 
 void AnimationClip::onBegin()
 void AnimationClip::onBegin()
 {
 {
-    Ref::Hold ref(this);
+    this->addRef();
 
 
     // Initialize animation to play.
     // Initialize animation to play.
     setClipStateBit(CLIP_IS_STARTED_BIT);
     setClipStateBit(CLIP_IS_STARTED_BIT);
@@ -621,11 +621,13 @@ void AnimationClip::onBegin()
 
 
     // Fire script begin event
     // Fire script begin event
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(AnimationClip, clipBegin), this);
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(AnimationClip, clipBegin), this);
+
+    this->release();
 }
 }
 
 
 void AnimationClip::onEnd()
 void AnimationClip::onEnd()
 {
 {
-    Ref::Hold ref(this);
+    this->addRef();
 
 
     _blendWeight = 1.0f;
     _blendWeight = 1.0f;
     resetClipStateBit(CLIP_ALL_BITS);
     resetClipStateBit(CLIP_ALL_BITS);
@@ -644,6 +646,8 @@ void AnimationClip::onEnd()
 
 
     // Fire script end event
     // Fire script end event
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(AnimationClip, clipEnd), this);
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(AnimationClip, clipEnd), this);
+
+    this->release();
 }
 }
 
 
 bool AnimationClip::isClipStateBitSet(unsigned char bit) const
 bool AnimationClip::isClipStateBitSet(unsigned char bit) const

+ 3 - 1
gameplay/src/Control.cpp

@@ -1060,7 +1060,7 @@ void Control::notifyListeners(Control::Listener::EventType eventType)
     // This method runs untrusted code by notifying listeners of events.
     // This method runs untrusted code by notifying listeners of events.
     // If the user calls exit() or otherwise releases this control, we
     // If the user calls exit() or otherwise releases this control, we
     // need to keep it alive until the method returns.
     // need to keep it alive until the method returns.
-    Ref::Hold ref(this);
+    this->addRef();
 
 
     controlEvent(eventType);
     controlEvent(eventType);
 
 
@@ -1079,6 +1079,8 @@ void Control::notifyListeners(Control::Listener::EventType eventType)
     }
     }
 
 
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(Control, controlEvent), dynamic_cast<void*>(this), eventType);
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(Control, controlEvent), dynamic_cast<void*>(this), eventType);
+
+    this->release();
 }
 }
 
 
 void Control::controlEvent(Control::Listener::EventType evt)
 void Control::controlEvent(Control::Listener::EventType evt)

+ 0 - 35
gameplay/src/Ref.h

@@ -43,41 +43,6 @@ public:
      */
      */
     unsigned int getRefCount() const;
     unsigned int getRefCount() const;
 
 
-    /**
-     * Temporarily hold a refcount on the stack, safely releasing when needed.
-     */
-    class Hold {
-        public:
-            /**
-             * Acquire and hold a reference to a given Ref object.
-             *
-             * The reference will go away when this object leaves scope.
-             */
-            Hold(Ref *r) : r_(r) {
-                r_->addRef();
-            }
-            ~Hold() {
-                if (r_) {
-                    r_->release();
-                }
-            }
-            Hold() = delete;
-            Hold(Hold const &) = delete;
-            Hold &operator=(Hold const &) = delete;
-
-            /**
-             * Remove the reference without releasing the object.
-             *
-             * @return the object, with the reference held.
-             */
-            Ref *unset() {
-                Ref *ret = r_;
-                r_ = nullptr;
-                return ret;
-            }
-        private:
-            Ref *r_;
-    };
 protected:
 protected:
 
 
     /**
     /**