Exemplo n.º 1
0
        private bool Update()
        {
            ISimFrameMonitor       simFrameMonitor         = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats);
            ITotalFrameTimeMonitor totalFrameMonitor       = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule> ().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime);
            ISetMonitor            lastFrameMonitor        = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt);
            ITimeMonitor           otherFrameMonitor       = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime);
            ITimeMonitor           sleepFrameMonitor       = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime);
            IPhysicsFrameMonitor   physicsFrameMonitor     = (IPhysicsFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalPhysicsFrameTime);
            ITimeMonitor           physicsFrameTimeMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.PhysicsUpdateFrameTime);
            IPhysicsMonitor        physicsMonitor          = RequestModuleInterface <IPhysicsMonitor>();

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

                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_entities == 0)
                    {
                        m_sceneGraph.UpdateEntities();
                    }

                    /*BlankHandler[] events;
                     * lock (m_events)
                     * {
                     *  events = new BlankHandler[m_events.Count];
                     *  m_events.CopyTo(events);
                     *  m_events.Clear();
                     * }
                     * foreach (BlankHandler h in events)
                     *  try { h(); }
                     *  catch { }*/

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

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

                    if (m_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 (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(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();

                    if (simFrameMonitor != null)
                    {
                        simFrameMonitor.AddFPS(1);
                        lastFrameMonitor.SetValue(MonitorLastCompletedFrame);
                        otherFrameMonitor.AddTime(MonitorOtherFrameTime);
                    }
                    else
                    {
                        simFrameMonitor   = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats);
                        totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime);
                        lastFrameMonitor  = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt);
                        otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime);
                        sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime);
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Error("[REGION]: Failed with exception " + e + " in region: " + RegionInfo.RegionName);
                    return(true);
                }

                //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);
                }
            }
        }
Exemplo n.º 2
0
        private bool Update()
        {
            ISimFrameMonitor       simFrameMonitor   = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats);
            ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule> ().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime);
            ISetMonitor            lastFrameMonitor  = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt);
            ITimeMonitor           otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime);
            ITimeMonitor           sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime);

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

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

                try
                {
                    int OtherFrameTime = Util.EnvironmentTickCount();
                    if (m_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);
                            }
                        }
                    }

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

                    BlankHandler[] events;
                    lock (m_events)
                    {
                        events = new BlankHandler[m_events.Count];
                        m_events.CopyTo(events);
                        m_events.Clear();
                    }
                    foreach (BlankHandler h in events)
                    {
                        try { h(); }
                        catch { }
                    }

                    if (m_frame % m_update_events == 0)
                    {
                        try
                        {
                            m_sceneGraph.PhysicsScene.UpdatesLoop();
                        }
                        catch
                        {
                        }
                    }

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

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

                    if (simFrameMonitor != null)
                    {
                        simFrameMonitor.AddFPS(1);
                        lastFrameMonitor.SetValue(MonitorLastCompletedFrame);
                        otherFrameMonitor.AddTime(MonitorOtherFrameTime);
                    }
                    else
                    {
                        simFrameMonitor   = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats);
                        totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime);
                        lastFrameMonitor  = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt);
                        otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime);
                        sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime);
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Error("[REGION]: Failed with exception " + e + " in region: " + RegionInfo.RegionName);
                    return(true);
                }

                //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, false);
                if (getSleepTime > 0)
                {
                    Thread.Sleep(getSleepTime);
                }

                if (sleepFrameMonitor != null)
                {
                    sleepFrameMonitor.AddTime(maintc);
                    totalFrameMonitor.AddFrameTime(MonitorEndFrameTime);
                }
            }
        }
Exemplo n.º 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);
        }