コード例 #1
0
ファイル: Scene.cs プロジェクト: sonjamichelle/WhiteCore-Dev
        void Heartbeat()
        {
            IMonitorModule             monitorModule           = RequestModuleInterface <IMonitorModule>();
            ISimFrameMonitor           simFrameMonitor         = monitorModule.GetMonitor <ISimFrameMonitor>(this);
            ITotalFrameTimeMonitor     totalFrameMonitor       = monitorModule.GetMonitor <ITotalFrameTimeMonitor>(this);
            ILastFrameTimeMonitor      lastFrameMonitor        = monitorModule.GetMonitor <ILastFrameTimeMonitor>(this);
            IOtherFrameMonitor         otherFrameMonitor       = monitorModule.GetMonitor <IOtherFrameMonitor>(this);
            ISleepFrameMonitor         sleepFrameMonitor       = monitorModule.GetMonitor <ISleepFrameMonitor>(this);
            IPhysicsFrameMonitor       physicsFrameMonitor     = monitorModule.GetMonitor <IPhysicsFrameMonitor>(this);
            IPhysicsUpdateFrameMonitor physicsFrameTimeMonitor = monitorModule.GetMonitor <IPhysicsUpdateFrameMonitor>(this);

            IPhysicsMonitor    physicsMonitor  = RequestModuleInterface <IPhysicsMonitor>();
            ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>();

            while (true)
            {
                if (!ShouldRunHeartbeat) //If we aren't supposed to be running, kill ourselves
                {
                    return;
                }

                int maintc             = Util.EnvironmentTickCount();
                int BeginningFrameTime = maintc;
                // Increment the frame counter
                ++Frame;

                try
                {
                    int            OtherFrameTime = Util.EnvironmentTickCount();
                    ISceneEntity[] entities       = null;
                    lock (PhysicsReturns)
                    {
                        if (PhysicsReturns.Count != 0)
                        {
                            entities = PhysicsReturns.ToArray();
                            PhysicsReturns.Clear();
                        }
                    }
                    if (entities != null && inventoryModule != null)
                    {
                        inventoryModule.ReturnObjects(entities, UUID.Zero);
                    }

                    if (Frame % m_update_entities == 0)
                    {
                        m_sceneGraph.UpdateEntities();
                    }

                    if (Frame % m_update_events == 0)
                    {
                        m_sceneGraph.PhysicsScene.UpdatesLoop();
                    }

                    if (Frame % m_update_events == 0)
                    {
                        m_eventManager.TriggerOnFrame();
                    }

                    if (Frame % m_update_coarse_locations == 0)
                    {
                        List <Vector3> coarseLocations;
                        List <UUID>    avatarUUIDs;
                        if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60))
                        {
                            // Send coarse locations to clients
                            foreach (IScenePresence presence in GetScenePresences())
                            {
                                presence.SendCoarseLocations(coarseLocations, avatarUUIDs);
                            }
                        }
                    }

                    int PhysicsUpdateTime = Util.EnvironmentTickCount();

                    if (Frame % m_update_physics == 0)
                    {
                        TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate;
                        if (!RegionInfo.RegionSettings.DisablePhysics &&
                            ApproxEquals((float)SinceLastFrame.TotalMilliseconds,
                                         m_updatetimespan, 3))
                        {
                            m_sceneGraph.UpdatePreparePhysics();
                            m_sceneGraph.UpdatePhysics((float)SinceLastFrame.TotalSeconds);
                            m_lastphysupdate = DateTime.UtcNow;
                            int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime);

                            if (MonitorPhysicsUpdateTime != 0)
                            {
                                if (physicsFrameTimeMonitor != null)
                                {
                                    physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime);
                                }
                                if (physicsMonitor != null)
                                {
                                    physicsMonitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene);
                                }
                                if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                                {
                                    StartPhysicsScene();
                                }
                            }
                            if (physicsFrameMonitor != null)
                            {
                                physicsFrameMonitor.AddFPS(1);
                            }
                        }
                        else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                        {
                            StopPhysicsScene();
                        }
                        m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics;
                    }

                    //Now fix the sim stats
                    int MonitorOtherFrameTime     = Util.EnvironmentTickCountSubtract(OtherFrameTime);
                    int MonitorLastCompletedFrame = Util.EnvironmentTickCount();

                    simFrameMonitor.AddFPS(1);
                    lastFrameMonitor.SetValue(MonitorLastCompletedFrame);
                    otherFrameMonitor.AddTime(MonitorOtherFrameTime);
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Error("[Scene]: Failed with exception " + e + " in region: " +
                                               RegionInfo.RegionName);
                    return;
                }

                //Get the time between beginning and end
                maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime);
                //Beginning + (time between beginning and end) = end
                int MonitorEndFrameTime = BeginningFrameTime + maintc;

                int getSleepTime = GetHeartbeatSleepTime(maintc);
                if (getSleepTime > 0)
                {
                    Thread.Sleep(getSleepTime);
                }

                if (sleepFrameMonitor != null)
                {
                    sleepFrameMonitor.AddTime(getSleepTime);
                    totalFrameMonitor.AddFrameTime(MonitorEndFrameTime);
                }
            }
        }
コード例 #2
0
        private bool PhysUpdate()
        {
            IMonitorModule             monitorModule           = RequestModuleInterface <IMonitorModule>();
            IPhysicsFrameMonitor       physicsFrameMonitor     = monitorModule.GetMonitor <IPhysicsFrameMonitor>(this);
            IPhysicsUpdateFrameMonitor physicsFrameTimeMonitor = monitorModule.GetMonitor <IPhysicsUpdateFrameMonitor>(this);

            IPhysicsMonitor    monitor2        = RequestModuleInterface <IPhysicsMonitor>();
            ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>();

            while (true)
            {
                if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves
                {
                    return(false);
                }
                int maintc             = Util.EnvironmentTickCount();
                int BeginningFrameTime = maintc;

                ISceneEntity[] entities = null;
                lock (PhysicsReturns)
                {
                    if (PhysicsReturns.Count != 0)
                    {
                        entities = PhysicsReturns.ToArray();
                        PhysicsReturns.Clear();
                    }
                }
                if (entities != null && inventoryModule != null)
                {
                    inventoryModule.ReturnObjects(entities, UUID.Zero);
                }

                int PhysicsUpdateTime = Util.EnvironmentTickCount();

                if (m_frame % m_update_physics == 0)
                {
                    TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate;
                    if (!RegionInfo.RegionSettings.DisablePhysics &&
                        ApproxEquals((float)SinceLastFrame.TotalMilliseconds,
                                     m_updatetimespan, 3))
                    {
                        m_sceneGraph.UpdatePreparePhysics();
                        m_sceneGraph.UpdatePhysics((float)SinceLastFrame.TotalSeconds);
                        m_lastphysupdate = DateTime.UtcNow;
                        int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime);

                        if (MonitorPhysicsUpdateTime != 0)
                        {
                            if (physicsFrameTimeMonitor != null)
                            {
                                physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime);
                            }
                            if (monitor2 != null)
                            {
                                monitor2.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene);
                            }
                            if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                            {
                                StartPhysicsScene();
                            }
                        }
                        if (physicsFrameMonitor != null)
                        {
                            physicsFrameMonitor.AddFPS(1);
                        }
                    }
                    else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                    {
                        StopPhysicsScene();
                    }
                    m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics;
                }

                //Get the time between beginning and end
                maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime);
                if (maintc == 0)
                {
                    continue;
                }
                int getSleepTime = GetHeartbeatSleepTime(maintc, true);
                if (getSleepTime > 0)
                {
                    Thread.Sleep(getSleepTime);
                }
            }
        }
コード例 #3
0
        private bool Update()
        {
            if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves
            {
                return(false);
            }

            ISimFrameMonitor       simFrameMonitor         = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "SimFrameStats");
            ITotalFrameTimeMonitor totalFrameMonitor       = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Total Frame Time");
            ISetMonitor            lastFrameMonitor        = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Last Completed Frame At");
            ITimeMonitor           otherFrameMonitor       = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Other Frame Time");
            ITimeMonitor           sleepFrameMonitor       = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Sleep Frame Time");
            IPhysicsFrameMonitor   physicsFrameMonitor     = (IPhysicsFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Total Physics Frame Time");
            ITimeMonitor           physicsSyncFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Physics Sync Frame Time");
            ITimeMonitor           physicsFrameTimeMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Physics Update Frame Time");
            int maintc             = Util.EnvironmentTickCount();
            int BeginningFrameTime = maintc;

            // Increment the frame counter
            ++m_frame;

            try
            {
                int OtherFrameTime = Util.EnvironmentTickCount();
                if (PhysicsReturns.Count != 0)
                {
                    lock (PhysicsReturns)
                    {
                        ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>();
                        if (inventoryModule != null)
                        {
                            inventoryModule.ReturnObjects(PhysicsReturns.ToArray(), UUID.Zero);
                        }
                        PhysicsReturns.Clear();
                    }
                }
                if (m_frame % m_update_coarse_locations == 0)
                {
                    List <Vector3> coarseLocations;
                    List <UUID>    avatarUUIDs;
                    SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60);
                    // Send coarse locations to clients
                    foreach (IScenePresence presence in GetScenePresences())
                    {
                        presence.SendCoarseLocations(coarseLocations, avatarUUIDs);
                    }
                }

                if (m_frame % m_update_entities == 0)
                {
                    m_sceneGraph.UpdateEntities();
                }

                if (m_frame % m_update_events == 0)
                {
                    m_eventManager.TriggerOnFrame();
                }

                int      PhysicsSyncTime = Util.EnvironmentTickCount();
                TimeSpan SinceLastFrame  = DateTime.UtcNow - m_lastphysupdate;

                if ((m_frame % m_update_physics == 0) && !RegionInfo.RegionSettings.DisablePhysics)
                {
                    m_sceneGraph.UpdatePreparePhysics();
                }

                int MonitorPhysicsSyncTime = Util.EnvironmentTickCountSubtract(PhysicsSyncTime);

                int PhysicsUpdateTime = Util.EnvironmentTickCount();

                if (m_frame % m_update_physics == 0)
                {
                    if (!RegionInfo.RegionSettings.DisablePhysics && SinceLastFrame.TotalSeconds > m_physicstimespan)
                    {
                        m_sceneGraph.UpdatePhysics(SinceLastFrame.TotalSeconds);
                        m_lastphysupdate = DateTime.UtcNow;
                    }
                }

                int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime) + MonitorPhysicsSyncTime;

                physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime);
                physicsFrameMonitor.AddFPS(1);
                physicsSyncFrameMonitor.AddTime(MonitorPhysicsSyncTime);

                IPhysicsMonitor monitor = RequestModuleInterface <IPhysicsMonitor>();
                if (monitor != null)
                {
                    monitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene);
                }

                //Now fix the sim stats
                int MonitorOtherFrameTime     = Util.EnvironmentTickCountSubtract(OtherFrameTime);
                int MonitorLastCompletedFrame = Util.EnvironmentTickCount();

                simFrameMonitor.AddFPS(1);
                lastFrameMonitor.SetValue(MonitorLastCompletedFrame);
                otherFrameMonitor.AddTime(MonitorOtherFrameTime);

                maintc = Util.EnvironmentTickCountSubtract(maintc);
                maintc = (int)(m_updatetimespan * 1000) - maintc;
            }
            catch (Exception e)
            {
                m_log.Error("[REGION]: Failed with exception " + e.ToString() + " in region: " + RegionInfo.RegionName);
                return(true);
            }

            int MonitorEndFrameTime = Util.EnvironmentTickCountSubtract(BeginningFrameTime) + maintc;

            if (maintc > 0)
            {
                Thread.Sleep(maintc);
            }

            sleepFrameMonitor.AddTime(maintc);

            totalFrameMonitor.AddFrameTime(MonitorEndFrameTime);
            return(true);
        }