Ejemplo n.º 1
0
        protected override void OnTick()
        {
            try
            {
                long curTime = TimeUtility.GetServerMilliseconds();
                if (m_LastLogTime + 60000 < curTime)
                {
                    m_LastLogTime = curTime;

                    DebugPoolCount((string msg) =>
                    {
                        LogSys.Log(LOG_TYPE.INFO, "RoomThread.ActionQueue {0}, thread {1}", msg, cur_thread_id_);
                    });
                }

                long tick_interval_us = tick_interval_ * 1000;
                TimeSnapshot.Start();
                DoTick();
                long elapsedTime = TimeSnapshot.End();
                if (elapsedTime >= tick_interval_us)
                {
                    if (elapsedTime >= tick_interval_us * 2)
                    {
                        LogSys.Log(LOG_TYPE.DEBUG, "*** Warning, RoomThread tick interval is {0} us !", elapsedTime);
                        foreach (Room room in active_room_)
                        {
                            Scene scene = room.GetActiveScene();
                            if (null != scene)
                            {
                                if (scene.SceneState == SceneState.Running)
                                {
                                    SceneProfiler profiler = scene.SceneProfiler;
                                    LogSys.Log(LOG_TYPE.DEBUG, "{0}", profiler.GenerateLogString(scene.SceneResId, scene.GameTime.ElapseMilliseconds));
                                }
                            }
                        }
                    }
                    Thread.Sleep(0);
                }
                else
                {
                    Thread.Sleep((int)(tick_interval_ - elapsedTime / 1000));
                }
            }
            catch (Exception ex)
            {
                LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        /**
         * @brief 逻辑循环
         */
        public void Tick()
        {
            TimeSnapshot.Start();
            TimeSnapshot.DoCheckPoint();
            if (m_CurScene == null || !m_CurScene.IsSuccessEnter)
            {
                return;
            }
            m_Profiler.sceneTickTime = TimeSnapshot.DoCheckPoint();

            EntityManager.Instance.Tick();
            m_Profiler.entityMgrTickTime = TimeSnapshot.DoCheckPoint();

            ControlSystem.Instance.Tick();
            m_Profiler.controlSystemTickTime = TimeSnapshot.DoCheckPoint();

            m_Profiler.movementSystemTickTime = TimeSnapshot.DoCheckPoint();

            m_SpatialSystem.Tick();
            m_Profiler.spatialSystemTickTime = TimeSnapshot.DoCheckPoint();
            if (m_Profiler.spatialSystemTickTime > 50000)
            {
                LogSystem.Warn("*** SpatialSystem tick time is {0}", m_Profiler.spatialSystemTickTime);
                for (LinkedListNode <UserInfo> node = UserManager.Users.FirstValue; null != node; node = node.Next)
                {
                    UserInfo userInfo = node.Value;
                    if (null != userInfo)
                    {
                        LogSystem.Warn("===>User:{0} Pos:{1}", userInfo.GetId(), userInfo.GetMovementStateInfo().GetPosition3D().ToString());
                    }
                }
                for (LinkedListNode <NpcInfo> node = NpcManager.Npcs.FirstValue; null != node; node = node.Next)
                {
                    NpcInfo npcInfo = node.Value;
                    if (null != npcInfo)
                    {
                        LogSystem.Warn("===>Npc:{0} Pos:{1}", npcInfo.GetId(), npcInfo.GetMovementStateInfo().GetPosition3D().ToString());
                    }
                }
            }

            m_AiSystem.Tick();
            m_Profiler.aiSystemTickTime = TimeSnapshot.DoCheckPoint();

            //obj特殊逻辑处理
            TickUsers();
            m_Profiler.usersTickTime = TimeSnapshot.DoCheckPoint();

            TickNpcs();
            m_Profiler.npcsTickTime = TimeSnapshot.DoCheckPoint();

            try {
                TickSystemByCharacters();
            } catch (Exception e) {
                GfxSystem.GfxLog("Exception:{0}\n{1}", e.Message, e.StackTrace);
            }
            m_Profiler.combatSystemTickTime = TimeSnapshot.DoCheckPoint();

            if (IsPveScene())
            {
                TickPve();
            }

            long tickTime = TimeSnapshot.End();

            if (tickTime > 100000)
            {
                LogSystem.Debug("*** PerformanceWarning: {0}", m_Profiler.GenerateLogString(tickTime));
            }
        }