Ejemplo n.º 1
0
        public static EventQueueListener alloc()
        {
            EventQueueListener l_instance = new EventQueueListener();

            l_instance.EventsListener = new Dictionary <Type, List <IEventListener> >(4);
            return(l_instance);
        }
Ejemplo n.º 2
0
        public static void registerEvent(EventQueueListener p_eventQueueListener, IEventListener p_eventListener)
        {
            Type l_eventType = p_eventListener.get_eventType();

            if (!p_eventQueueListener.EventsListener.ContainsKey(l_eventType))
            {
                p_eventQueueListener.EventsListener.Add(l_eventType, new List <IEventListener>(4));
            }

            p_eventListener.buildUniqueKey();
            p_eventQueueListener.EventsListener[l_eventType].Add(p_eventListener);
        }
Ejemplo n.º 3
0
        public static void onEventExecuted(EventQueueListener p_eventQueueListener, EventQueue p_eventQueue, AEvent p_event)
        {
            Type l_eventType = p_event.GetType();

            if (p_eventQueueListener.EventsListener.ContainsKey(l_eventType))
            {
                List <IEventListener> l_eventListeners = p_eventQueueListener.EventsListener[l_eventType];
                for (int i = l_eventListeners.Count - 1; i >= 0; i--)
                {
                    l_eventListeners[i].I_OnEventExecuted(p_eventQueue, p_event);
                }
            }
        }
Ejemplo n.º 4
0
        public static void unRegisterEvent(EventQueueListener p_eventQueueListener, IEventListener p_eventListener)
        {
            Type l_eventType = p_eventListener.get_eventType();

            if (p_eventQueueListener.EventsListener.ContainsKey(l_eventType))
            {
                List <IEventListener> l_eventListeners = p_eventQueueListener.EventsListener[l_eventType];

                for (int i = 0; i < l_eventListeners.Count; i++)
                {
                    if (l_eventListeners[i].compareUniqueKey(p_eventListener))
                    {
                        l_eventListeners.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void iterate(EventQueue p_eventQueue)
        {
            while (p_eventQueue.Events.Count > 0)
            {
                //Pop the first element
                AEvent l_firstEvent = p_eventQueue.Events[0];

                AAsyncEvent l_firstEventAsAsync = l_firstEvent as AAsyncEvent;
                if (l_firstEventAsAsync != null)
                {
                    if (!l_firstEventAsAsync.IsRunning && !l_firstEventAsAsync.IsCompleted())
                    {
                        l_firstEventAsAsync.IsRunning = true;
                        l_firstEventAsAsync.Execute(p_eventQueue);
                    }

                    if (l_firstEventAsAsync.IsRunning)
                    {
                        l_firstEventAsAsync.ExecuteEveryIteration();

                        if (l_firstEventAsAsync.IsCompleted())
                        {
                            p_eventQueue.Events.RemoveAt(0);
                            EventQueueListener.onEventExecuted(EventQueueListener.UniqueInstance, p_eventQueue, l_firstEvent);
                            l_firstEventAsAsync.IsRunning = false;
                            l_firstEventAsAsync.OnCompleted(p_eventQueue);
                            OnEventExecuted?.Invoke(l_firstEvent);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    p_eventQueue.Events.RemoveAt(0);
                    l_firstEvent.Execute(p_eventQueue);
                    EventQueueListener.onEventExecuted(EventQueueListener.UniqueInstance, p_eventQueue, l_firstEvent);
                    OnEventExecuted?.Invoke(l_firstEvent);
                }
            }
        }
Ejemplo n.º 6
0
 static EventQueueListener()
 {
     UniqueInstance = EventQueueListener.alloc();
 }