示例#1
0
        private bool _DetachListenerAsync(int inEventKey, IGEventListener inListener)
        {
            bool ret = false;

            if (inListener == null)
            {
                Log.LMN.LogUtil.Error("MBLogicNode._DetachListenerAsync: inLogicNode is null");
                return(ret);
            }

            //置脏,导致这棵子树需要进入更新流程//
            IsListenerTreeNeedsUpdate = true;
            IGLogicNode parent = ParentNode;

            while (parent != null && !parent.IsListenerTreeNeedsUpdate)
            {
                parent.IsListenerTreeNeedsUpdate = true;
                parent = parent.ParentNode;
            }

            List <GEventListenerWrapper> listenerWrappers = null;

            if (!mEventListenerMap.TryGetValue(inEventKey, out listenerWrappers))
            {
                Log.LMN.LogUtil.Error("MBLogicNode._DetachListenerAsync: no event listener for -> {0} on {1}", inEventKey, inListener);
                return(ret);
            }

            //快速找出需要移除的节点位置//
            int priority = inListener.GetPriority(inEventKey);
            int index    = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GEventListenerWrapper>(priority, listenerWrappers);

            for (int i = index; i < listenerWrappers.Count && listenerWrappers[i].PriorityVal == priority; i++)
            {
                GEventListenerWrapper wrapper = listenerWrappers[i];
                object listenerObj            = wrapper.mEventListenerWeakRef.Target;
                if (listenerObj == inListener)
                {
                    inListener.ListenerStatus = AttachableStatus.Detaching;
                    ret = true;
                    break;
                }
            }

            if (ret)
            {
                EventListenerUpdateOperation updateOp = new EventListenerUpdateOperation();
                updateOp.mListener      = inListener;
                updateOp.mIsAddOrRemove = false;
                updateOp.mEventKey      = inEventKey;
                mAsyncListenerOps.Add(updateOp);
            }

            return(ret);
        }
示例#2
0
        private bool _AttachNodeSync(IGLogicNode inLogicNode)
        {
            bool ret = false;

            if (inLogicNode == null)
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._AttachNodeSync: inLogicNode is null");
                return(ret);
            }

#if DEBUG_G_LOGIC_NODE
            bool foundDuplicate = false;

            for (int i = 0; i < mSubNodes.Count; i++)
            {
                GLogicNodeWrapper wrapper = mSubNodes[i];
                if (wrapper.mLogicNode == inLogicNode)
                {
                    foundDuplicate = true;
                    break;
                }
            }

            //请替换成你的log函数//
            System.Diagnostics.Debug.Assert(!foundDuplicate, "ObjLogicNode._AttachNodeSync: found duplicated LogicNode -> " + inLogicNode);
#endif

            GLogicNodeWrapper newLogicNodeWrapper = new GLogicNodeWrapper();
            newLogicNodeWrapper.mLogicNode            = inLogicNode;
            newLogicNodeWrapper.mLogicNode.NodeStatus = AttachableStatus.Attached;

            //找出插入位置//
            int index = PrioritySortUtil.GetDecSeqRefArrayInsertIndex <GLogicNodeWrapper>(inLogicNode.LogicNodePriority, mSubNodes);
            mSubNodes.Insert(index, newLogicNodeWrapper);

            //赋值父节点//
            inLogicNode.ParentNode = this;

            //如果节点有名字,那注册名字//
            if (inLogicNode.NodeName != 0)
            {
                mNameAndNodeMap.Add(inLogicNode.NodeName, inLogicNode);
            }

            inLogicNode.OnAttached(this);

            ret = true;

            return(ret);
        }
示例#3
0
        private bool _DetachListenerSync(int inEventKey, IGEventListener inListener)
        {
            bool ret = false;

            if (inListener == null)
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._DetachListenerSync: inLogicNode is null");
                return(ret);
            }

            List <GEventListenerWrapper> listenerWrappers = null;

            if (!mEventListenerMap.TryGetValue(inEventKey, out listenerWrappers))
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._DetachListenerSync: no event listener for -> {0} on {1}", inEventKey, inListener);
                return(ret);
            }

            //快速找出需要移除的节点位置,注意这里其实兼顾了同一优先级节点的GC功能//
            int priority = inListener.GetPriority(inEventKey);
            int index    = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GEventListenerWrapper>(priority, listenerWrappers);
            List <GEventListenerWrapper> listenersToRemove = new List <GEventListenerWrapper>();

            for (int i = index; i < listenerWrappers.Count && listenerWrappers[i].PriorityVal == priority; i++)
            {
                GEventListenerWrapper wrapper = listenerWrappers[i];
                object listenerObj            = wrapper.mEventListenerWeakRef.Target;
                if (listenerObj == null || listenerObj == inListener)
                {
                    listenersToRemove.Add(wrapper);
                }
            }

            for (int i = 0; i < listenersToRemove.Count; i++)
            {
                listenerWrappers.Remove(listenersToRemove[i]);
            }

            inListener.ListenerStatus = AttachableStatus.Detached;

            ret = listenersToRemove.Count != 0;
            return(ret);
        }
示例#4
0
        private bool _AttachListenerSync(int inEventKey, IGEventListener inListener)
        {
            bool ret = false;

            if (inListener == null)
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._AttachListenerSync: inLogicNode is null");
                return(ret);
            }

            List <GEventListenerWrapper> eventListenerList = null;

            if (!mEventListenerMap.TryGetValue(inEventKey, out eventListenerList))
            {
                eventListenerList = new List <GEventListenerWrapper>();
                mEventListenerMap.Add(inEventKey, eventListenerList);
            }

#if DEBUG_G_LOGIC_NODE
            for (int i = 0; i < eventListenerList.Count; i++)
            {
                GEventListenerWrapper wrapper = eventListenerList[i];
                if (wrapper.mEventListenerWeakRef.IsAlive &&
                    wrapper.mEventListenerWeakRef.Target == inListener)
                {
                    //请替换成你的log函数//
                    Log.LMN.LogUtil.Error("ObjLogicNode._AttachListenerSync: duplicated -> " + inListener + ", in -> " + this + ", for -> " + inEventKey);
                    return(ret);
                }
            }
#endif

            int priority = inListener.GetPriority(inEventKey);
            GEventListenerWrapper listenerWrapper;
            listenerWrapper.mEventListenerWeakRef  = new WeakReference(inListener);
            listenerWrapper.mEventListenerPriority = priority;
            inListener.ListenerStatus = AttachableStatus.Attached;

            int index = PrioritySortUtil.GetDecSeqRefArrayInsertIndex <GEventListenerWrapper>(priority, eventListenerList);
            eventListenerList.Insert(index, listenerWrapper);

            ret = true;
            return(ret);
        }
示例#5
0
        private bool _DetachNodeSync(IGLogicNode inLogicNode)
        {
            bool ret = false;

            if (inLogicNode == null)
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._DetachNodeSync: inLogicNode is null");
                return(ret);
            }

            //快速找出节点位置//
            int index         = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GLogicNodeWrapper>(inLogicNode.LogicNodePriority, mSubNodes);
            int indexToRemove = -1;

            for (int i = index; i < mSubNodes.Count && mSubNodes[i].PriorityVal == inLogicNode.LogicNodePriority; i++)
            {
                GLogicNodeWrapper wrapper = mSubNodes[i];
                if (wrapper.mLogicNode == inLogicNode)
                {
                    indexToRemove = i;
                    break;
                }
            }

            if (indexToRemove != -1)
            {
                mSubNodes.RemoveAt(indexToRemove);

                //如果节点有名字,那注销//
                if (inLogicNode.NodeName != 0)
                {
                    mNameAndNodeMap.Remove(inLogicNode.NodeName);
                }

                inLogicNode.NodeStatus = AttachableStatus.Detached;
                inLogicNode.OnPreDetach(this);
                inLogicNode.OnDetached(this);
                inLogicNode.ParentNode = null;

                ret = true;
            }

            return(ret);
        }
示例#6
0
        private bool _DetachNodeAsync(IGLogicNode inLogicNode)
        {
            bool ret = false;

            if (inLogicNode == null)
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._DetachNodeAsync: inLogicNode is null");
                return(ret);
            }

            //快速找出节点位置//
            int index = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GLogicNodeWrapper>(inLogicNode.LogicNodePriority, mSubNodes);

            for (int i = index; i < mSubNodes.Count && mSubNodes[i].PriorityVal == inLogicNode.LogicNodePriority; i++)
            {
                GLogicNodeWrapper wrapper = mSubNodes[i];
                if (wrapper.mLogicNode == inLogicNode)
                {
                    wrapper.mLogicNode.NodeStatus = AttachableStatus.Detaching;
                    break;
                }
            }

            //置脏,导致这棵子树需要进入更新流程//
            IsLogicTreeNeedsUpdate = true;
            IGLogicNode parent = ParentNode;

            while (parent != null && !parent.IsLogicTreeNeedsUpdate)
            {
                parent.IsLogicTreeNeedsUpdate = true;
                parent = parent.ParentNode;
            }

            LogicNodeUpdateOperation updateOp = new LogicNodeUpdateOperation();

            updateOp.mIsAddOrRemove = false;
            updateOp.mLogicNode     = inLogicNode;
            mAsyncNodeOps.Add(updateOp);

            ret = true;
            return(ret);
        }