浏览代码

Blocking events for Object.
SendEvent() which supports initializer lists.

Rokas Kupstys 8 年之前
父节点
当前提交
c73ee9e34a
共有 2 个文件被更改,包括 30 次插入2 次删除
  1. 20 1
      Source/Atomic/Core/Object.cpp
  2. 10 1
      Source/Atomic/Core/Object.h

+ 20 - 1
Source/Atomic/Core/Object.cpp

@@ -75,7 +75,10 @@ bool TypeInfo::IsTypeOf(const TypeInfo* typeInfo) const
 }
 
 Object::Object(Context* context) :
-    context_(context)
+    context_(context),
+    // ATOMIC BEGIN
+    blockEvents_(false)
+    // ATOMIC END
 {
     assert(context_);
 }
@@ -88,6 +91,11 @@ Object::~Object()
 
 void Object::OnEvent(Object* sender, StringHash eventType, VariantMap& eventData)
 {
+    // ATOMIC BEGIN
+    if (blockEvents_)
+        return;
+    // ATOMIC END
+
     // Make a copy of the context pointer in case the object is destroyed during event handler invocation
     Context* context = context_;
     EventHandler* specific = 0;
@@ -340,6 +348,11 @@ void Object::SendEventNonProfiled(StringHash eventType, VariantMap& eventData)
         return;
     }
 
+    // ATOMIC BEGIN
+    if (blockEvents_)
+        return;
+    // ATOMIC END
+
     // Make a weak pointer to self to check for destruction during event handling
     WeakPtr<Object> self(this);
     Context* context = context_;
@@ -721,6 +734,12 @@ template <> Metrics* Object::GetSubsystem<Metrics>() const
     return context_->metrics_;
 }
 
+void Object::SendEvent(StringHash eventType, const VariantMap& eventData)
+{
+    VariantMap eventDataCopy = eventData;
+    SendEvent(eventType, eventDataCopy);
+}
+
 // ATOMIC END
 
 }

+ 10 - 1
Source/Atomic/Core/Object.h

@@ -215,7 +215,12 @@ public:
 
     static ClassID GetClassIDStatic() { static const int typeID = 0; return (ClassID) &typeID; }
     static const Atomic::String& GetTypeNameStatic() { static const Atomic::String typeNameStatic("Object"); return typeNameStatic; }
-
+    /// Send event with parameters to all subscribers.
+    void SendEvent(StringHash eventType, const VariantMap& eventData);
+    /// Block object from sending and receiving events.
+    void SetBlockEvents(bool block) { blockEvents_ = block; }
+    /// Return sending and receiving events blocking status.
+    bool GetBlockEvents() const { return blockEvents_; }
     // ATOMIC END
 
 protected:
@@ -237,6 +242,10 @@ private:
 
     /// Event handlers. Sender is null for non-specific handlers.
     LinkedList<EventHandler> eventHandlers_;
+
+    // ATOMIC BEGIN
+    bool blockEvents_;
+    // ATOMIC END
 };
 
 template <class T> T* Object::GetSubsystem() const { return static_cast<T*>(GetSubsystem(T::GetTypeStatic())); }