Exemple #1
0
        public void _clear()
        {
            if (firstNode == null)
            {
                return;
            }

            SignalNode <T> t = firstNode;
            SignalNode <T> n;

            while (t != null)
            {
                t.action = null;
                if (nodePool.Count > MAX)
                {
                    break;
                }

                n        = t.next;
                t.action = null;
                t.pre    = t.next = null;
                nodePool.Push(t);

                t = n;
            }

            mapping   = null;
            firstNode = lastNode = null;
            len       = 0;
        }
Exemple #2
0
        public bool __addHandle(Action <T> value, T data, bool forceData = false)
        {
            if (mapping == null)
            {
                mapping = new Dictionary <Action <T>, SignalNode <T> >();
            }

            SignalNode <T> t = null;

            if (mapping.TryGetValue(value, out t))
            {
                if (t.active == NodeActiveState.TodoDelete)
                {
                    if (dispatching)
                    {
                        t.active = NodeActiveState.TodoAdd;
                    }
                    else
                    {
                        t.active = NodeActiveState.Runing;
                    }
                    t.data = data;
                    return(true);
                }
                if (forceData)
                {
                    t.data = data;
                }
                return(false);
            }

            t        = getSignalNode();
            t.action = value;
            t.data   = data;
            mapping.Add(value, t);

            if (dispatching)
            {
                t.active = NodeActiveState.TodoAdd;
            }
            else
            {
                firstNode = lastNode = t;
            }

            len++;
            return(true);
        }
Exemple #3
0
        protected SignalNode <T> getSignalNode()
        {
            SignalNode <T> t;

            if (nodePool.Count > 0)
            {
                t        = nodePool.Pop();
                t.active = NodeActiveState.Runing;
            }
            else
            {
                t = new SignalNode <T>();
            }

            return(t);
        }
        public bool invokeEvent(SAEventX e)
        {
            if (mEventListeners == null)
            {
                return(false);
            }

            Signal signal;

            if (mEventListeners.TryGetValue(e.type, out signal) == false)
            {
                return(false);
            }

            SignalNode <SAEventX> t = signal.firstNode;

            if (t == null)
            {
                return(false);
            }

            List <Action <SAEventX> > temp = SimpleListPool <Action <SAEventX> > .Get();

            int i = 0;

            while (t != null)
            {
                temp.Add(t.action);
                t = t.next;
                i++;
            }

            e.setCurrentTarget(e.target);

            Action <SAEventX> listener;

            for (int j = 0; j < i; j++)
            {
                listener = temp[j];
                listener(e);
//                return true;
            }

            SimpleListPool <Action <SAEventX> > .Release(temp);

            return(true);
        }
Exemple #5
0
        protected bool _remove(SignalNode <T> t, Action <T> value)
        {
            if (t == null)
            {
                Debug.Log("queueHandle error nil");
            }

            SignalNode <T> pre  = t.pre;
            SignalNode <T> next = t.next;

            if (pre != null)
            {
                pre.next = next;
            }
            else
            {
                firstNode = next;
            }

            if (next != null)
            {
                next.pre = pre;
            }
            else
            {
                lastNode = pre;
            }

            t.active = NodeActiveState.TodoDelete;
            mapping.Remove(value);

            if (nodePool.Count < MAX)
            {
                t.action = null;
                t.pre    = t.next = null;
                nodePool.Push(t);
            }

            len--;

            if (len < 0)
            {
                Debug.LogError("QueueHandle lenError:" + len);
            }

            return(true);
        }
Exemple #6
0
        private void render(float deltaTime)
        {
            if (len > 0)
            {
                dispatching = true;
                SignalNode <float> t = firstNode;

                List <SignalNode <float> > temp = getSignalNodeList();
                float now = Time.time;
                while (t != null)
                {
                    if (t.active == NodeActiveState.Runing)
                    {
                        if (now > t.data)
                        {
                            Remove(t.action);
                            t.action(t.data);
                        }
                    }
                    temp.Add(t);
                    t = t.next;
                }
                dispatching = false;
                int l = temp.Count;
                for (int i = 0; i < l; i++)
                {
                    SignalNode <float> item = temp[i];
                    if (item.active == NodeActiveState.TodoDelete)
                    {
                        _remove(item, item.action);
                    }
                    else if (item.active == NodeActiveState.TodoAdd)
                    {
                        item.active = NodeActiveState.Runing;
                    }
                }
                recycle(temp);
            }
            else
            {
                TickManager.Remove(render);
            }
        }
Exemple #7
0
        public void dispatch(T e)
        {
            if (len > 0)
            {
                dispatching = true;
                SignalNode <T> t = firstNode;

                List <SignalNode <T> > temp = getSignalNodeList();

                while (t != null)
                {
                    if (t.active == NodeActiveState.Runing)
                    {
                        t.action(e);
                    }
                    temp.Add(t);
                    t = t.next;
                }

                dispatching = false;

                int l = temp.Count;
                for (int i = 0; i < l; i++)
                {
                    SignalNode <T> item = temp[i];

                    if (item.active == NodeActiveState.TodoDelete)
                    {
                        _remove(item, item.action);
                    }
                    else if (item.active == NodeActiveState.TodoAdd)
                    {
                        item.active = NodeActiveState.Runing;
                    }
                }

                recycle(temp);
            }
        }
Exemple #8
0
        public bool __removeHandle(Action <T> value)
        {
            if (lastNode == null || mapping == null)
            {
                return(false);
            }

            SignalNode <T> t = null;

            if (mapping.TryGetValue(value, out t) == false)
            {
                return(false);
            }

            if (dispatching)
            {
                t.active = NodeActiveState.TodoDelete;
                return(true);
            }

            return(_remove(t, value));
        }
Exemple #9
0
        public bool add(Action <SAEventX> value, int priority = 0)
        {
            if (mapping == null)
            {
                mapping = new Dictionary <Action <SAEventX>, SignalNode <SAEventX> >();
            }

            SignalNode <SAEventX> t = null;

            if (mapping.TryGetValue(value, out t))
            {
                if (t.active == NodeActiveState.TodoDelete)
                {
                    if (dispatching)
                    {
                        t.active = NodeActiveState.TodoAdd;
                    }
                    else
                    {
                        t.active = NodeActiveState.Runing;
                    }

                    return(true);
                }
                return(false);
            }

            SignalNode <SAEventX> newNode = getSignalNode();

            newNode.action   = value;
            newNode.priority = priority;
            mapping[value]   = newNode;

            if (dispatching)
            {
                newNode.active = NodeActiveState.TodoAdd;
            }

            if (firstNode == null)
            {
                len      = 1;
                lastNode = firstNode = newNode;
                return(true);
            }

            SignalNode <SAEventX> findNode = null;

            if (priority > lastNode.priority)
            {
                t = firstNode;
                SignalNode <SAEventX> pre;
                while (t != null)
                {
                    if (priority > t.priority)
                    {
                        pre          = t.pre;
                        newNode.next = t;
                        t.pre        = newNode;

                        if (pre != null)
                        {
                            pre.next    = newNode;
                            newNode.pre = pre;
                        }
                        else
                        {
                            firstNode = newNode;
                        }

                        findNode = t;
                        break;
                    }

                    t = t.next;
                }
            }

            if (findNode == null)
            {
                lastNode.next = newNode;
                newNode.pre   = lastNode;
                lastNode      = newNode;
            }

            len++;
            return(true);
        }