Browse Source

Expose UnsubscribeFromAllEventsExcept() to script.

Lasse Öörni 13 years ago
parent
commit
53adf6fc5b
5 changed files with 28 additions and 16 deletions
  1. 1 0
      Docs/ScriptAPI.dox
  2. 2 2
      Engine/Core/Object.cpp
  3. 1 1
      Engine/Core/Object.h
  4. 15 0
      Engine/Engine/CoreAPI.cpp
  5. 9 13
      Engine/Resource/Image.cpp

+ 1 - 0
Docs/ScriptAPI.dox

@@ -44,6 +44,7 @@ namespace Urho3D
 - void UnsubscribeFromEvent(Object@, const String&)
 - void UnsubscribeFromEvents(Object@)
 - void UnsubscribeFromAllEvents()
+- void UnsubscribeFromAllEventsExcept(String[]@)
 - Object@ GetEventSender()
 - const String& GetTypeName(ShortStringHash)
 - void Print(const String&)

+ 2 - 2
Engine/Core/Object.cpp

@@ -184,7 +184,7 @@ void Object::UnsubscribeFromAllEvents()
     }
 }
 
-void Object::UnsubscribeFromAllEventsExcept(const PODVector<StringHash>& exceptions, bool needUserData)
+void Object::UnsubscribeFromAllEventsExcept(const PODVector<StringHash>& exceptions, bool onlyUserData)
 {
     EventHandler* handler = eventHandlers_.First();
     EventHandler* previous = 0;
@@ -193,7 +193,7 @@ void Object::UnsubscribeFromAllEventsExcept(const PODVector<StringHash>& excepti
     {
         EventHandler* next = eventHandlers_.Next(handler);
         
-        if ((!needUserData || handler->GetUserData()) && !exceptions.Contains(handler->GetEventType()))
+        if ((!onlyUserData || handler->GetUserData()) && !exceptions.Contains(handler->GetEventType()))
         {
             if (handler->GetSender())
                 context_->RemoveEventReceiver(this, handler->GetSender(), handler->GetEventType());

+ 1 - 1
Engine/Core/Object.h

@@ -63,7 +63,7 @@ public:
     /// Unsubscribe from all events.
     void UnsubscribeFromAllEvents();
     /// Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
-    void UnsubscribeFromAllEventsExcept(const PODVector<StringHash>& exceptions, bool needUserData);
+    void UnsubscribeFromAllEventsExcept(const PODVector<StringHash>& exceptions, bool onlyUserData);
     /// Send event to all subscribers.
     void SendEvent(StringHash eventType);
     /// Send event with parameters to all subscribers.

+ 15 - 0
Engine/Engine/CoreAPI.cpp

@@ -680,6 +680,20 @@ static void UnsubscribeFromAllEvents()
         listener->UnsubscribeFromAllEventsExcept(PODVector<StringHash>(), true);
 }
 
+static void UnsubscribeFromAllEventsExcept(CScriptArray* exceptions)
+{
+    Object* listener = GetScriptContextEventListenerObject();
+    if (!listener || !exceptions)
+        return;
+    
+    unsigned numExceptions = exceptions->GetSize();
+    PODVector<StringHash> destExceptions(numExceptions);
+    for (unsigned i = 0; i < numExceptions; ++i)
+        destExceptions[i] = StringHash(*(static_cast<String*>(exceptions->At(i))));
+    
+    listener->UnsubscribeFromAllEventsExcept(destExceptions, true);
+}
+
 static Object* GetEventSender()
 {
     return GetScriptContext()->GetEventSender();
@@ -733,6 +747,7 @@ void RegisterObject(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("void UnsubscribeFromEvent(Object@+, const String&in)", asFUNCTION(UnsubscribeFromSenderEvent), asCALL_CDECL);
     engine->RegisterGlobalFunction("void UnsubscribeFromEvents(Object@+)", asFUNCTION(UnsubscribeFromSenderEvents), asCALL_CDECL);
     engine->RegisterGlobalFunction("void UnsubscribeFromAllEvents()", asFUNCTION(UnsubscribeFromAllEvents), asCALL_CDECL);
+    engine->RegisterGlobalFunction("void UnsubscribeFromAllEventsExcept(Array<String>@+)", asFUNCTION(UnsubscribeFromAllEventsExcept), asCALL_CDECL);
     engine->RegisterGlobalFunction("Object@+ GetEventSender()", asFUNCTION(GetEventSender), asCALL_CDECL);
     engine->RegisterGlobalFunction("const String& GetTypeName(ShortStringHash)", asFUNCTION(GetTypeName), asCALL_CDECL);
     

+ 9 - 13
Engine/Resource/Image.cpp

@@ -258,20 +258,18 @@ bool Image::Load(Deserializer& source)
         
         unsigned endianness = source.ReadUInt();
         unsigned type = source.ReadUInt();
-        unsigned typeSize = source.ReadUInt();
+        /* unsigned typeSize = */ source.ReadUInt();
         unsigned format = source.ReadUInt();
         unsigned internalFormat = source.ReadUInt();
-        unsigned baseInternalFormat = source.ReadUInt();
+        /* unsigned baseInternalFormat = */ source.ReadUInt();
         unsigned width = source.ReadUInt();
         unsigned height = source.ReadUInt();
         unsigned depth = source.ReadUInt();
-        unsigned arrayElements = source.ReadUInt();
+        /* unsigned arrayElements = */ source.ReadUInt();
         unsigned faces = source.ReadUInt();
         unsigned mipmaps = source.ReadUInt();
         unsigned keyValueBytes = source.ReadUInt();
-
-#pragma unused (typeSize, baseInternalFormat, arrayElements)
-
+        
         if (endianness != 0x04030201)
         {
             LOGERROR("Big-endian KTX files not supported");
@@ -374,20 +372,18 @@ bool Image::Load(Deserializer& source)
     }
     else if (fileID == "PVR\3")
     {
-        unsigned flags = source.ReadUInt();
+        /* unsigned flags = */ source.ReadUInt();
         unsigned pixelFormatLo = source.ReadUInt();
-        unsigned pixelFormatHi = source.ReadUInt();
-        unsigned colourSpace = source.ReadUInt();
-        unsigned channelType = source.ReadUInt();
+        /* unsigned pixelFormatHi = */ source.ReadUInt();
+        /* unsigned colourSpace = */ source.ReadUInt();
+        /* unsigned channelType = */ source.ReadUInt();
         unsigned height = source.ReadUInt();
         unsigned width = source.ReadUInt();
         unsigned depth = source.ReadUInt();
-        unsigned numSurfaces = source.ReadUInt();
+        /* unsigned numSurfaces = */ source.ReadUInt();
         unsigned numFaces = source.ReadUInt();
         unsigned mipmapCount = source.ReadUInt();
         unsigned metaDataSize = source.ReadUInt();
-   
-#pragma unused (flags, pixelFormatHi, colourSpace, channelType, numSurfaces)
         
         if (depth > 1 || numFaces > 1)
         {