Example #1
0
        /// <summary>
        /// 保存世界服务
        /// </summary>
        internal void OnSave()
        {
            if (SpinLockEx.QuickTryEnter(ref m_LockSave) == false)
            {
                LOGs.WriteLine(LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.BaseWorldString003);
                return;
            }
            else
            {
                // 保存数据
                EventHandler <BaseWorldEventArgs> tempEvent = m_EventSaveWorld;
                if (tempEvent != null)
                {
                    // 保存数据中......
                    m_Saving = true;

                    LOGs.WriteLine(LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.BaseWorldString001);

                    BaseWorldEventArgs worldEventArgs = new BaseWorldEventArgs(this);
                    tempEvent(this, worldEventArgs);

                    LOGs.WriteLine(LogMessageType.MSG_NOTICE, LanguageString.SingletonInstance.BaseWorldString002);

                    // 保存数据结束......
                    m_Saving = false;
                }
            }
            m_LockSave.Exit();
        }
Example #2
0
        /// <summary>
        /// 处理全部的已断开连接的客户,不要处理过多的断开,以影响时间片的处理
        /// 主要是处理NetStateManage内的NetState
        /// </summary>
        internal void ProcessDisposed()
        {
            // 检查是否已经在处理ProcessDisposed(...)的调用
            if (m_LockInProcessDisposed.InLock() == false)
            {
                return;
            }

            // 已经在处理ProcessDisposed(...)中

            do
            {
                // 使用数组减少锁定时间
                NetState[] netStateArray = null;

                if (SpinLockEx.QuickTryEnter(ref m_LockNetStateDisposed) == false)
                {
                    break;
                }
                {
                    if (m_NetStateDisposed.Count > 0)
                    {
                        // 断开连接的客户先进先出列队集合的数量(和中断处理比较)
                        long iQueueCountAtNetState = m_NetStateDisposed.Count;
                        if (iQueueCountAtNetState <= BREAK_COUNT)
                        {
                            netStateArray = m_NetStateDisposed.ToArray();
                            m_NetStateDisposed.Clear();
                        }
                        else
                        {
                            netStateArray = new NetState[BREAK_COUNT];
                            for (long iIndex = 0; iIndex < BREAK_COUNT; iIndex++)
                            {
                                netStateArray[iIndex] = m_NetStateDisposed.Dequeue();
                            }
                        }
                    }
                }
                m_LockNetStateDisposed.Exit();

                // 如果没有需要处理的数据则返回
                if (netStateArray == null)
                {
                    break;
                }

                for (int iIndex = 0; iIndex < netStateArray.Length; iIndex++)
                {
                    netStateArray[iIndex].ExitWorld();
                }
            } while (false);

            // 已经处理完ProcessDisposed(...)的调用
            m_LockInProcessDisposed.OutLock();
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="flag"></param>
        public void Slice()
        {
            if (m_SliceQueue.Count <= 0)
            {
                return;
            }

            // 使用数组减少锁定时间
            T[] arrayT = null;

            if (SpinLockEx.QuickTryEnter(ref m_LockSliceQueue) == false)
            {
                return;
            }
            {
                if (m_SliceQueue.Count > 0)
                {
                    arrayT = m_SliceQueue.ToArray();
                    m_SliceQueue.Clear();
                }
            }
            m_LockSliceQueue.Exit();

            // 如果没有需要处理的数据则返回
            if (arrayT == null)
            {
                return;
            }

            // 现在的时间
            DateTime nowTime = DateTime.Now;

            // 用于计算经过的时间(因为Stopwatch的计算速度比DateTime.Now快近3倍)
            Stopwatch updateTime = Stopwatch.StartNew();

            for (int iIndex = 0; iIndex < arrayT.Length; iIndex++)
            {
                T itemT = arrayT[iIndex];
                itemT.OnProcessSlice(nowTime + updateTime.Elapsed);

                if (m_MultiThreadedCall == false)
                {
                    itemT.OutLockProcessSlice();
                }
            }

            // 计算结束
            updateTime.Stop();
        }