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>
        /// 保存世界的数据
        /// </summary>
        public void Save()
        {
            // 保存世界的数据必须要成功才返回
            m_LockSave.Enter();
            {
                // 保存数据中......
                m_Saving = true;

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

                // 保存数据
                EventHandler <BaseWorldEventArgs> tempEvent = m_EventSaveWorld;
                if (tempEvent != null)
                {
                    BaseWorldEventArgs worldEventArgs = new BaseWorldEventArgs(this);
                    tempEvent(this, worldEventArgs);
                }

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

                // 保存数据结束......
                m_Saving = false;
            }
            m_LockSave.Exit();
        }
Example #3
0
        /// <summary>
        /// 结束世界服务
        /// </summary>
        internal void OnExit()
        {
            // 在结束世界之前,调用一次
            EventHandler <BaseWorldEventArgs> tempEvent = m_EventExitWorld;

            if (tempEvent != null)
            {
                BaseWorldEventArgs worldEventArgs = new BaseWorldEventArgs(this);
                tempEvent(this, worldEventArgs);
            }
        }
Example #4
0
        /// <summary>
        /// 初始化世界服务
        /// </summary>
        internal void OnInitOnce()
        {
            // 在开始运行世界之前,初始化一次BaseWorld
            // 需要一个副本是因为可能在需要调用的时候,已经注销掉了
            EventHandler <BaseWorldEventArgs> tempEvent = m_EventInitOnceWorld;

            if (tempEvent != null)
            {
                BaseWorldEventArgs worldEventArgs = new BaseWorldEventArgs(this);
                tempEvent(this, worldEventArgs);
            }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEventArgs"></typeparam>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartSlice(object sender, BaseWorldEventArgs eventArgs)
        {
            //////////////////////////////////////////////////////////////////////////
            // WOW世界的全部物体开始更新

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

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

            ISupportSlice[] updateSliceArray = m_NeedUpdateQueue.Dequeue();
            if (updateSliceArray != null)
            {
                for (int iIndex = 0; iIndex < updateSliceArray.Length; iIndex++)
                {
                    var updateSlice = updateSliceArray[iIndex];

                    // 进入锁定
                    if (updateSlice.InLockProcessSlice() == false)
                    {
                        continue;
                    }

                    // 只允许单线程内处理调用
                    updateSlice.OnProcessSlice(nowTime + updateTime.Elapsed);

                    // 离开锁定
                    updateSlice.OutLockProcessSlice();
                }

                // 先处理部分,然后再次处理剩下的
                base.SetWorldSignal();
            }

            // 计算结束
            updateTime.Stop();
        }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 public BaseWorld()
 {
     m_BaseWorldEventArgs = new BaseWorldEventArgs(this); // 在世界时间片中调用
     m_WaitExecute        = new WorldWaitExecute(this);   // 初始化
 }