Example #1
0
        private bool _DetachAllSubNodesAsync()
        {
            bool ret = false;

            for (int i = 0; i < mSubNodes.Count; i++)
            {
                GLogicNodeWrapper wrapper = mSubNodes[i];
                wrapper.mLogicNode.NodeStatus = AttachableStatus.Detaching;
            }

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

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

            LogicNodeUpdateOperation updateOp = new LogicNodeUpdateOperation();

            updateOp.mIsRemoveAll   = true;
            updateOp.mIsAddOrRemove = false;
            mAsyncNodeOps.Add(updateOp);

            return(ret);
        }
Example #2
0
        /// <summary>
        /// 用于提供双buffer缓冲规范
        /// </summary>
        public void SwapEventQueues()
        {
            if (IsNodeActive)
            {
                //交换消息队列和listener操作队列//
                if (ThreadSafeLock != null)
                {
                    lock (ThreadSafeLock)
                    {
                        List <IGEvent> tempEventList = mEventQueueForNextFrame;
                        mEventQueueForNextFrame = mEventQueueForThisFrame;
                        mEventQueueForThisFrame = tempEventList;
                    }
                }
                else
                {
                    List <IGEvent> tempEventList = mEventQueueForNextFrame;
                    mEventQueueForNextFrame = mEventQueueForThisFrame;
                    mEventQueueForThisFrame = tempEventList;
                }

                for (int i = 0; i < mSubNodes.Count; i++)
                {
                    GLogicNodeWrapper wrapper = mSubNodes[i];
                    if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching && wrapper.mLogicNode.IsNodeActive)
                    {
                        wrapper.mLogicNode.SwapEventQueues();
                    }
                }
            }
        }
Example #3
0
        private bool _DetachAllSubNodesSync()
        {
            bool ret = false;

            for (int i = 0; i < mSubNodes.Count; i++)
            {
                GLogicNodeWrapper wrapper = mSubNodes[i];

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

                //标注自己的状态是Detach//
                wrapper.mLogicNode.NodeStatus = AttachableStatus.Detached;

                //递归进入Detach所有的子节点//
                wrapper.mLogicNode.DetachAllSubNodes();

                //回调PreDetach接口//
                wrapper.mLogicNode.OnPreDetach(this);

                //回调Detach接口//
                wrapper.mLogicNode.OnDetached(this);

                wrapper.mLogicNode.ParentNode = null;
            }

            mSubNodes.Clear();

            ret = true;
            return(ret);
        }
Example #4
0
        /// <summary>
        /// 广播一个消息
        /// </summary>
        /// <param name="inEvent">Evt.</param>
        public virtual bool DispatchAnEvent(IGEvent inEvent)
        {
            if (AsEventDispatcher)
            {
                if (TriggerEvent(inEvent))
                {
                    return(true);
                }

                for (int i = 0; i < mSubNodes.Count; i++)
                {
                    GLogicNodeWrapper wrapper = mSubNodes[i];
                    if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching &&
                        wrapper.mLogicNode.IsNodeActive)
                    {
                        if (wrapper.mLogicNode.DispatchAnEvent(inEvent))
                        {
                            //说明某个消息监听器要求拦截消息,终止了消息的继续广播//
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #5
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);
        }
Example #6
0
 /// <summary>
 /// 帧循环
 /// </summary>
 /// <param name="inDeltaTime"></param>
 public virtual void OnLogicNodeUpdate(float inDeltaTime)
 {
     if (IsNodeActive)
     {
         for (int i = 0; i < mSubNodes.Count; i++)
         {
             GLogicNodeWrapper wrapper = mSubNodes[i];
             if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching && wrapper.mLogicNode.IsNodeActive)
             {
                 wrapper.mLogicNode.OnLogicNodeUpdate(inDeltaTime);
             }
         }
     }
 }
Example #7
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);
        }
Example #8
0
        /// <summary>
        /// 用于实现对消息监听器Dic等 的GC
        /// </summary>
        public void GC()
        {
            Dictionary <int, List <GEventListenerWrapper> > .Enumerator iter = mEventListenerMap.GetEnumerator();
            while (iter.MoveNext())
            {
                List <GEventListenerWrapper> wrapperList = iter.Current.Value;
                wrapperList.RemoveAll(mEventListenerWrapperRemoveDelegate);
            }

            for (int i = 0; i < mSubNodes.Count; i++)
            {
                GLogicNodeWrapper wrapper = mSubNodes[i];
                if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching)
                {
                    wrapper.mLogicNode.GC();
                }
            }
        }
Example #9
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);
        }
Example #10
0
        /// <summary>
        /// 广播消息
        /// </summary>
        public virtual void DispatchEvents()
        {
            //先把在我身上抛的消息dispatch掉//
            for (int i = 0; i < mEventQueueForThisFrame.Count; i++)
            {
                IGEvent evt = mEventQueueForThisFrame[i];
                DispatchAnEvent(evt);
                TryToRecycleThisEvent(evt);
            }
            mEventQueueForThisFrame.Clear();

            if (AsEventDispatcher)
            {
                for (int i = 0; i < mSubNodes.Count; i++)
                {
                    GLogicNodeWrapper wrapper = mSubNodes[i];
                    if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching &&
                        wrapper.mLogicNode.IsNodeActive)
                    {
                        wrapper.mLogicNode.DispatchEvents();
                    }
                }
            }
        }