コード例 #1
0
        /// <summary>
        /// 处理事件结点。
        /// </summary>
        /// <param name="sender">事件源。</param>
        /// <param name="e">事件参数。</param>
        private void HandleEvent(object sender, T e)
        {
            bool noHandlerException = false;

            if (_eventHandlers.TryGetValue(e.Id, out LinkedListRange <EventHandler <T> > range))
            {
                LinkedListNode <EventHandler <T> > current = range.First;
                while (current != null && current != range.Terminal)
                {
                    _cachedNodes[e] = current.Next != range.Terminal ? current.Next : null;
                    current.Value(sender, e);
                    current = _cachedNodes[e];
                }

                _cachedNodes.Remove(e);
            }
            else if (_defaultHandler != null)
            {
                _defaultHandler(sender, e);
            }
            else if ((_eventPoolMode & EventPoolMode.AllowNoHandler) == 0)
            {
                noHandlerException = true;
            }

            ReferencePool.Return(e);

            if (noHandlerException)
            {
                throw new GameException(Utility.Text.Format("Event '{0}' not allow no handler.", e.Id.ToString()));
            }
        }
コード例 #2
0
        /// <summary>
        /// 事件池轮询。
        /// </summary>
        public void Update(float deltaTime)
        {
            while (_events.Count > 0)
            {
                Event eventNode = null;
                lock (_events)
                {
                    eventNode = _events.Dequeue();
                    HandleEvent(eventNode.Sender, eventNode.EventArgs);
                }

                ReferencePool.Return(eventNode);
            }
        }
コード例 #3
0
 /// <summary>
 /// 关闭并清理有限状态机。
 /// </summary>
 internal override void Shutdown()
 {
     ReferencePool.Return(this);
 }