Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tTimer"></param>
        /// <param name="newIndex"></param>
        /// <param name="isAdd"></param>
        /// <returns></returns>
        public static AIChangeEntry Instance(BaseAIEvent aiEventInfo, bool isAdd)
        {
            AIChangeEntry l_AIChangeEntry = null;

            Monitor.Enter(s_LockAIChangeEntryPool);
            {
                if (s_AIChangeEntryPool.Count > 0)
                {
                    l_AIChangeEntry = s_AIChangeEntryPool.Dequeue();
                }
            }
            Monitor.Exit(s_LockAIChangeEntryPool);

            if (l_AIChangeEntry == null)
            {
                l_AIChangeEntry = new AIChangeEntry(aiEventInfo, isAdd);
            }
            else
            {
                l_AIChangeEntry.m_AIEventInfo      = aiEventInfo;
                l_AIChangeEntry.m_IsAddAIEventInfo = isAdd;
            }

            return(l_AIChangeEntry);
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="nTriggerID"></param>
 public void RemoveAIEvent(BaseAIEvent aiEventInfo)
 {
     Monitor.Enter(m_LockAIEvent);
     {
         m_AIEvent.Remove(aiEventInfo.AIEventType, aiEventInfo);
     }
     Monitor.Exit(m_LockAIEvent);
 }
Пример #3
0
        /// <summary>
        /// 处理添加或修改或移去的时间片
        /// </summary>
        private static void ProcessChangeQueue()
        {
            AIChangeEntry[] l_AIChangeEntryArray = null;

            Monitor.Enter(s_LockAIChangeEntryChangeQueue);
            {
                if (s_AIChangeEntryChangeQueue.Count > 0)
                {
                    l_AIChangeEntryArray = s_AIChangeEntryChangeQueue.ToArray();
                    s_AIChangeEntryChangeQueue.Clear();
                }
            }
            Monitor.Exit(s_LockAIChangeEntryChangeQueue);

            if (l_AIChangeEntryArray == null)
            {
                return;
            }

            foreach (AIChangeEntry aiChangeEntry in l_AIChangeEntryArray)
            {
                if (aiChangeEntry == null)
                {
                    Debug.WriteLine("MobileAIThread.ProcessChangeQueue(...) - aiChangeEntry == null error!");

                    continue;
                }

                BaseAIEvent l_nonceAIEventInfo = aiChangeEntry.AIEventInfo;
                //long l_newIndex = aiChangeEntry.TimerPriority;

                //// 先从当前的优先级时间片列表中移去
                //if ( l_nonceTimer.TimeSliceList != null )
                //    l_nonceTimer.TimeSliceList.Remove( l_nonceTimer );

                //// 如果是添加的话,初始化时间片数据
                //if ( timerChangeEntry.AddTimerSlice )
                //{
                //    l_nonceTimer.SetNextTime( DateTime.Now + l_nonceTimer.DelayTime ); // 计算下次调用的延迟的时间(m_Delay只计算使用一次)
                //    l_nonceTimer.SetAdding( 0 );
                //}

                //// 如果优先级大于或等于零则添加到新的时间片列表中去,否则置空
                //if ( l_newIndex >= 0 && l_newIndex < 8 ) // 8种时间片, -1 将不添加进列表,删除掉
                //{
                //    l_nonceTimer.TimeSliceList = s_Timers[l_newIndex];
                //    l_nonceTimer.TimeSliceList.Add( l_nonceTimer );
                //}
                //else
                //    l_nonceTimer.TimeSliceList = null;

                // 释放自己进内存池
                aiChangeEntry.Release();
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iTriggerType"></param>
        /// <param name="processPriority"></param>
        /// <returns></returns>
        public Serial RegisterAIEvent(BaseAIEvent aiEventInfo)
        {
            aiEventInfo.InternalSerial = m_AIEventExclusiveSerial.GetExclusiveSerial();

            Monitor.Enter(m_LockAIEvent);
            {
                m_AIEvent.Add(aiEventInfo.AIEventType, aiEventInfo);
            }
            Monitor.Exit(m_LockAIEvent);

            return(aiEventInfo.Serial);
        }
Пример #5
0
        /// <summary>
        /// 添加或修改或移去的时间片
        /// </summary>
        /// <param name="tTimer"></param>
        /// <param name="newIndex"></param>
        /// <param name="isAdd"></param>
        private static void Change(BaseAIEvent aiEventInfo, bool isAdd)
        {
            Monitor.Enter(s_LockAIChangeEntryChangeQueue);
            {
                // 在ProcessChangeQueue(...)中释放入不使用的列表中
                s_AIChangeEntryChangeQueue.Enqueue(AIChangeEntry.Instance(aiEventInfo, isAdd));
            }
            Monitor.Exit(s_LockAIChangeEntryChangeQueue);

            // 发生事件
            s_Signal.Set();
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iTriggerType"></param>
        /// <param name="processPriority"></param>
        /// <returns></returns>
        public BaseAIEvent RegisterAIEvent(long iAIEventType)
        {
            BaseAIEvent l_newBaseAIEvent = new BaseAIEvent(iAIEventType);

            l_newBaseAIEvent.InternalSerial = m_AIEventExclusiveSerial.GetExclusiveSerial();

            Monitor.Enter(m_LockAIEvent);
            {
                m_AIEvent.Add(l_newBaseAIEvent.AIEventType, l_newBaseAIEvent);
            }
            Monitor.Exit(m_LockAIEvent);

            return(l_newBaseAIEvent);
        }
Пример #7
0
 /// <summary>
 /// 移去时间片
 /// </summary>
 /// <param name="tTimer"></param>
 public static void RemoveAIEventInfo( BaseAIEvent aiEventInfo )
 {
     Change( aiEventInfo, false );
 }
Пример #8
0
 /// <summary>
 /// 移去时间片
 /// </summary>
 /// <param name="tTimer"></param>
 public static void RemoveAIEventInfo(BaseAIEvent aiEventInfo)
 {
     Change(aiEventInfo, false);
 }
Пример #9
0
 /// <summary>
 /// 添加或修改或移去时间片
 /// </summary>
 /// <param name="tTimer"></param>
 public static void AddAIEventInfo(BaseAIEvent aiEventInfo)
 {
     Change(aiEventInfo, true);
 }
Пример #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="nTriggerID"></param>
 public void RemoveAIEvent( BaseAIEvent aiEventInfo )
 {
     Monitor.Enter( m_LockAIEvent );
     {
         m_AIEvent.Remove( aiEventInfo.AIEventType, aiEventInfo );
     }
     Monitor.Exit( m_LockAIEvent );
 }
Пример #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="iTriggerType"></param>
        /// <param name="processPriority"></param>
        /// <returns></returns>
        public BaseAIEvent RegisterAIEvent( long iAIEventType )
        {
            BaseAIEvent l_newBaseAIEvent = new BaseAIEvent( iAIEventType );
            l_newBaseAIEvent.InternalSerial = m_AIEventExclusiveSerial.GetExclusiveSerial();

            Monitor.Enter( m_LockAIEvent );
            {
                m_AIEvent.Add( l_newBaseAIEvent.AIEventType, l_newBaseAIEvent );
            }
            Monitor.Exit( m_LockAIEvent );

            return l_newBaseAIEvent;
        }
Пример #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="iTriggerType"></param>
        /// <param name="processPriority"></param>
        /// <returns></returns>
        public Serial RegisterAIEvent( BaseAIEvent aiEventInfo )
        {
            aiEventInfo.InternalSerial = m_AIEventExclusiveSerial.GetExclusiveSerial();
            
            Monitor.Enter( m_LockAIEvent );
            {
                m_AIEvent.Add( aiEventInfo.AIEventType, aiEventInfo );
            }
            Monitor.Exit( m_LockAIEvent );

            return aiEventInfo.Serial;
        }
Пример #13
0
        /// <summary>
        /// 添加或修改或移去的时间片
        /// </summary>
        /// <param name="tTimer"></param>
        /// <param name="newIndex"></param>
        /// <param name="isAdd"></param>
        private static void Change( BaseAIEvent aiEventInfo, bool isAdd )
        {
            Monitor.Enter( s_LockAIChangeEntryChangeQueue );
            {
                // 在ProcessChangeQueue(...)中释放入不使用的列表中
                s_AIChangeEntryChangeQueue.Enqueue( AIChangeEntry.Instance( aiEventInfo, isAdd ) );
            }
            Monitor.Exit( s_LockAIChangeEntryChangeQueue );

            // 发生事件
            s_Signal.Set();
        }
Пример #14
0
 /// <summary>
 /// 添加或修改或移去时间片
 /// </summary>
 /// <param name="tTimer"></param>
 public static void AddAIEventInfo( BaseAIEvent aiEventInfo )
 {
     Change( aiEventInfo, true );
 }
Пример #15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="tTimer"></param>
 /// <param name="newIndex"></param>
 /// <param name="isAdd"></param>
 private AIChangeEntry( BaseAIEvent aiEventInfo, bool isAdd )
 {
     m_AIEventInfo = aiEventInfo;
     m_IsAddAIEventInfo = isAdd;
 }
Пример #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tTimer"></param>
        /// <param name="newIndex"></param>
        /// <param name="isAdd"></param>
        /// <returns></returns>
        public static AIChangeEntry Instance( BaseAIEvent aiEventInfo, bool isAdd )
        {
            AIChangeEntry l_AIChangeEntry = null;

            Monitor.Enter( s_LockAIChangeEntryPool );
            {
                if ( s_AIChangeEntryPool.Count > 0 )
                    l_AIChangeEntry = s_AIChangeEntryPool.Dequeue();
            }
            Monitor.Exit( s_LockAIChangeEntryPool );

            if ( l_AIChangeEntry == null )
                l_AIChangeEntry = new AIChangeEntry( aiEventInfo, isAdd );
            else
            {
                l_AIChangeEntry.m_AIEventInfo = aiEventInfo;
                l_AIChangeEntry.m_IsAddAIEventInfo = isAdd;
            }

            return l_AIChangeEntry;
        }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tTimer"></param>
 /// <param name="newIndex"></param>
 /// <param name="isAdd"></param>
 private AIChangeEntry(BaseAIEvent aiEventInfo, bool isAdd)
 {
     m_AIEventInfo      = aiEventInfo;
     m_IsAddAIEventInfo = isAdd;
 }