Example #1
0
            public NativeEventDataCache(Type type)
            {
                eventData = new NativeEventData[eventDataMax];

                for (int i = 0; i < eventDataMax; i++)
                {
                    eventData[i] = (NativeEventData)Activator.CreateInstance(type);
                }
            }
        public static void EventDispatch(IntPtr sender, uint eventType, IntPtr eventData)
        {
            List <EventSubscription> eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            // iterate over copy of list so we can modify it while running
            ScriptVariantMap scriptMap       = null;
            NativeEventData  nativeEventData = null;

            AObject receiver;

            foreach (EventSubscription er in eventReceivers.ToList())
            {
                // GC'd?
                if (!er.Receiver.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (er.Sender != IntPtr.Zero && er.Sender != sender)
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                    nativeEventData = NativeEvents.GetNativeEventData(eventType, scriptMap);
                    nativeEventData.sourceEventData = eventData;
                }

                receiver.HandleEvent(eventType, scriptMap, nativeEventData);
            }

            if (scriptMap != null)
            {
                svmDepth--;

                if (nativeEventData != null)
                {
                    NativeEvents.ReleaseNativeEventData(nativeEventData);
                }
            }
        }
Example #3
0
        internal void HandleEvent(uint eventType, ScriptVariantMap eventData, NativeEventData nativeEventData)
        {
            NativeEventDelegate nativeDelegate;

            if (NativeEventHandlers.TryGetValue(eventType, out nativeDelegate))
            {
                nativeDelegate(nativeEventData);
                return;
            }

            EventDelegate eventDelegate;

            if (EventHandlers.TryGetValue(eventType, out eventDelegate))
            {
                eventDelegate(eventType, eventData);
                return;
            }

            // Reaching here should be a warning, possibly an error
        }
Example #4
0
        public static void ReleaseNativeEventData(NativeEventData eventData)
        {
            Type dataType = eventData.GetType();

            eventData.scriptMap       = null;
            eventData.sourceEventData = IntPtr.Zero;

            NativeEventDataCache cache;

            if (eventCache.TryGetValue(dataType, out cache))
            {
#if DEBUG
                if (cache.eventData[cache.eventDataDepth - 1] != eventData)
                {
                    throw new InvalidOperationException("ReleaseNativeEventData - unexpected event data");
                }
#endif
                cache.eventDataDepth--;
            }
        }