public void Initialize(Scene scene, IConfigSource config)
        {
            if (config.Configs["Messaging"] != null)
            {
                // Allow disabling this module in config
                //
                if (config.Configs["Messaging"].GetString(
                        "InventoryTransferModule", "InventoryTransferModule") !=
                        "InventoryTransferModule")
                    return;
            }

            if (!m_Scenelist.Contains(scene))
            {
                if (m_Scenelist.Count == 0)
                {
                    m_TransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
                    if (m_TransferModule == null)
                        m_log.Error("[INVENTORY TRANSFER]: No Message transfer module found, transfers will be local only");
                }

                m_Scenelist.Add(scene);

                scene.RegisterModuleInterface<IInventoryTransferModule>(this);

                scene.EventManager.OnNewClient += OnNewClient;
                scene.EventManager.OnClientClosed += ClientLoggedOut;
                scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;

                m_TransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
            }
        }
Ejemplo n.º 2
0
 public void Initialise(Scene scene, IConfigSource source)
 {
     m_scene = scene;
     m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>();
     m_scene.RegisterModuleInterface<IGodsModule>(this);
     m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
 }
Ejemplo n.º 3
0
        public void RegionLoaded(Scene scene)
        {
            if (!m_Enabled)
                return;
			
            if (m_TransferModule == null)
            {
                m_TransferModule =
                    scene.RequestModuleInterface<IMessageTransferModule>();

                if (m_TransferModule == null)
                {
                    m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+
                    "lures will not work!");

                    m_Enabled = false;
                    m_scenes.Clear();
                    scene.EventManager.OnNewClient -= OnNewClient;
                    scene.EventManager.OnClosingClient -= OnClosingClient;
                    scene.EventManager.OnIncomingInstantMessage -=
                            OnGridInstantMessage;
                }
            }

        }
 public void RegionLoaded(Scene scene)
 {
     m_scriptModule = scene.RequestModuleInterface<IScriptModule>();
     
     if (m_scriptModule != null)
         m_log.Info("[MODULE COMMANDS]: Script engine found, module active");
 }
Ejemplo n.º 5
0
 public void AddRegion(Scene scene)
 {
     m_scene = scene;
     m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>();
     m_scene.RegisterModuleInterface<IAttachmentsModule>(this);
     m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
     // TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI
 }
Ejemplo n.º 6
0
 public void AddRegion(Scene scene)
 {
     if (ENABLED)
     {
         m_scene = scene;
         m_scene.EventManager.OnSceneGroupMove += OnSceneGroupMove;
         m_dialogMod = m_scene.RequestModuleInterface<IDialogModule>();
     }
 }
Ejemplo n.º 7
0
 public void RemoveRegion(Scene scene)
 {
     ISyncMessagePosterService syncMessage = scene.RequestModuleInterface<ISyncMessagePosterService>();
     if (syncMessage != null)
         syncMessage.Post(SyncMessageHelper.LogoutRegionAgents(scene.RegionInfo.RegionHandle), scene.RegionInfo.RegionHandle);
     scene.EventManager.OnNewClient -= OnNewClient;
     scene.EventManager.OnClosingClient -= OnClosingClient;
     m_scenes.Remove (scene);
 }
 public void RegionLoaded(Scene scene)
 {
     if (m_cache == null)
     {
         IImprovedAssetCache cache = scene.RequestModuleInterface<IImprovedAssetCache>();
         if (cache is ISharedRegionModule)
             m_cache = cache;
     }
 }
Ejemplo n.º 9
0
        public void AddRegion(Scene scene)
        {
            if (ENABLED)
            {
                m_scene = scene;
                m_scene.EventManager.OnSceneGroupMove += OnSceneGroupMove;
                m_dialogMod = m_scene.RequestModuleInterface<IDialogModule>();

                m_log.DebugFormat("[DA EXAMPLE MODULE]: Added region {0}", m_scene.Name);
            }
        }
Ejemplo n.º 10
0
        public void RegionLoaded(Scene scene)
        {
            if (!m_Enabled)
                return;
            m_Generator = scene.RequestModuleInterface<IMapImageGenerator>();
            if (m_Generator == null)
            {
                m_Enabled = false;
                return;
            }

            m_log.Info("[WORLDVIEW]: Configured and enabled");
            ISimulationBase simulationBase = scene.RequestModuleInterface<ISimulationBase>();
            if (simulationBase != null)
            {
                IHttpServer server = simulationBase.GetHttpServer(0);
                server.AddStreamHandler(new WorldViewRequestHandler(this,
                        scene.RegionInfo.RegionID.ToString()));
            }
        }
Ejemplo n.º 11
0
        public void Close(Scene scene)
        {
            //Deregister the interface
            scene.UnregisterModuleInterface<IGridRegisterModule>(this);

            m_log.InfoFormat("[RegisterRegionWithGrid]: Deregistering region {0} from the grid...", scene.RegionInfo.RegionName);

            //Deregister from the grid server
            IGridService GridService = scene.RequestModuleInterface<IGridService>();
            if (!GridService.DeregisterRegion(scene.RegionInfo.RegionID, scene.RegionInfo.GridSecureSessionID))
                m_log.WarnFormat("[RegisterRegionWithGrid]: Deregister from grid failed for region {0}", scene.RegionInfo.RegionName);
        }
        public void RegionLoaded(Scene scene)
        {
            m_scene = scene;

            IScriptModuleComms comms = scene.RequestModuleInterface<IScriptModuleComms>();
            if (comms != null)
            {
                comms.RegisterScriptInvocation( this, "llAttachToAvatarTemp");
                m_log.DebugFormat("[TEMP ATTACHS]: Registered script functions");
                m_console = scene.RequestModuleInterface<IRegionConsole>();

                if (m_console != null)
                {
                    m_console.AddCommand("TempAttachModule", false, "set auto_grant_attach_perms", "set auto_grant_attach_perms true|false", "Allow objects owned by the region owner or estate managers to obtain attach permissions without asking the user", SetAutoGrantAttachPerms);
                }
            }
            else
            {
                m_log.ErrorFormat("[TEMP ATTACHS]: Failed to register script functions");
            }
        }
Ejemplo n.º 13
0
        public TerrainSyncInfo(Scene scene, string actorID)
        {
            Scene = scene;
            LastUpdateValue = Scene.Heightmap.SaveToXmlString();
            ActorID = actorID;

            TerrainModule = scene.RequestModuleInterface<ITerrainModule>();
            if (TerrainModule == null)
                throw (new NullReferenceException("Could not get a reference to terrain module for region \"" + Scene.RegionInfo.RegionName + "\""));
            // Initialize time stamp to 0. Any changes anywhere will cause an update after initial load.
            LastUpdateTimeStamp = 0;
        }
Ejemplo n.º 14
0
 public void AddRegion(Scene scene)
 {
     if (m_enabled)
     {
         scene.EventManager.OnRegisterCaps += delegate(UUID agentID, IHttpServer server)
         {
             return OnRegisterCaps(scene, agentID, server);
         };
         //Add this to the OpenRegionSettings module so we can inform the client about it
         IOpenRegionSettingsModule ORSM = scene.RequestModuleInterface<IOpenRegionSettingsModule>();
         if (ORSM != null)
             ORSM.RegisterGenericValue("Voice", "Mumble");
     }
 }
        public void RegionLoaded(Scene scene)
        {
            if (!m_enabled)
                return;

            m_scene = scene;

            m_scriptModuleComms = scene.RequestModuleInterface<IScriptModuleComms>();

            if (m_scriptModuleComms == null)
            {
                m_log.Error("IScriptModuleComms could not be found, cannot add script functions");
                return;
            }

            m_scriptModuleComms.RegisterScriptInvocations(this);
        }
        public void RegionLoaded(Scene scene)
        {
            if (!m_enabled)
                return;

            IScriptModuleComms m_scriptModuleComms = scene.RequestModuleInterface<IScriptModuleComms>();

            if (m_scriptModuleComms == null)
            {
                m_log.Error("IScriptModuleComms could not be found, cannot add script functions");
                return;
            }

            m_scriptModuleComms.RegisterScriptInvocation(GetType(), new string[]{
                "primDescendantsCount",
                "primDescendantsCheck"
            });
        }
Ejemplo n.º 17
0
        public void AddRegion (Scene scene)
        {
            if (scene.RegionInfo.Startup != StartupType.Normal)
            {
                m_scene = scene;
                //Disable the heartbeat for this region
                scene.ShouldRunHeartbeat = false;

                scene.EventManager.OnRemovePresence += OnRemovePresence;
                scene.AuroraEventManager.OnGenericEvent += OnGenericEvent;

                if (scene.RegionInfo.Startup == StartupType.Soft)
                {
                    //If the region startup is soft, we arn't to load prims until they are needed, so kill it
                    IBackupModule backup = scene.RequestModuleInterface<IBackupModule> ();
                    if (backup != null)
                        backup.LoadPrims = false;
                }
            }
        }
Ejemplo n.º 18
0
 public void AddRegion(Scene scene)
 {
     if(!enabled) return;
     log("Adding region to MGM");
     npc = (NPCModule)scene.RequestModuleInterface<INPCModule>();
     if(npc == null || !npc.Enabled)
     {
         enabled = false;
         log("ERROR: NPC module must be enabled for MGM");
         return;
     }
     scene.AddCommand("mgm",this,"mgm status","status","Print the status of the MGM module", consoleStatus);
     scene.AddCommand("mgm",this,"mgm addUser","addUser","Test adding a user", addUser);
     mgmLink = new MGMLink(new IPEndPoint(mgmAddress, mgmPort), log);
     mgmLink.start();
     registerEvents(scene.EventManager);
     string regMsg = MGMJson.Register(scene.Name, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, scene.RegionInfo.RegionSizeX);
     mgmLink.send(regMsg);
     this.scene = scene;
     mgr = new MGMClientManager(scene,log);
 }
Ejemplo n.º 19
0
        public AuthorizationService(IConfig config, Scene scene)
        {
            m_Scene = scene;
            m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
            m_GridService = scene.GridService;

            if (config != null)
            {
                string accessStr = config.GetString("Region_" + scene.RegionInfo.RegionName.Replace(' ', '_'), String.Empty);
                if (accessStr != string.Empty)
                {
                    try
                    {
                        m_accessValue = (AccessFlags)Enum.Parse(typeof(AccessFlags), accessStr);
                    }
                    catch (ArgumentException)
                    {
                        m_log.WarnFormat("[AuthorizationService]: {0} is not a valid access flag", accessStr);
                    }
                }
                m_log.DebugFormat("[AuthorizationService]: Region {0} access restrictions: {1}", m_Scene.RegionInfo.RegionName, m_accessValue);
            }

        }
Ejemplo n.º 20
0
        public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
        {
            m_scene = scene;

            m_landBitmap = new bool[m_scene.RegionInfo.RegionSizeX / 4, m_scene.RegionInfo.RegionSizeY / 4];

            LandData.Maturity = m_scene.RegionInfo.RegionSettings.Maturity;
            LandData.OwnerID = owner_id;
            if (is_group_owned)
                LandData.GroupID = owner_id;
            else
                LandData.GroupID = UUID.Zero;
            LandData.IsGroupOwned = is_group_owned;

            LandData.RegionID = scene.RegionInfo.RegionID;
            LandData.RegionHandle = scene.RegionInfo.RegionHandle;

            m_parcelManagementModule = scene.RequestModuleInterface<IParcelManagementModule>();

            //We don't set up the InfoID here... it will just be overwriten
        }
        public void RegionLoaded(Scene scene)
        {
            if (!m_groupMessagingEnabled)
                return;

            if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();

            // No groups module, no groups messaging
            if (m_groupData == null)
            {
                m_log.Error("[GROUPS-MESSAGING]: Could not get IGroupsServicesConnector, GroupsMessagingModule is now disabled.");
                Close();
                m_groupMessagingEnabled = false;
                return;
            }

            m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>();

            // No message transfer module, no groups messaging
            if (m_msgTransferModule == null)
            {
                m_log.Error("[GROUPS-MESSAGING]: Could not get MessageTransferModule");
                Close();
                m_groupMessagingEnabled = false;
                return;
            }

            if (m_presenceService == null)
                m_presenceService = scene.PresenceService;

            m_sceneList.Add(scene);

            scene.EventManager.OnNewClient += OnNewClient;
            scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
            scene.EventManager.OnClientLogin += OnClientLogin;
        }
Ejemplo n.º 22
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            if (!m_scene.Active)
            {
                return;
            }

            SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[22];
            SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();

            // Know what's not thread safe in Mono... modifying timers.
            // m_log.Debug("Firing Stats Heart Beat");
            lock (m_report)
            {
                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                #region various statistic googly moogly

                // We're going to lie about the FPS because we've been lying since 2008.  The actual FPS is currently
                // locked at a maximum of 11.  Maybe at some point this can change so that we're not lying.
                int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor);

                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = reportedFPS / m_statsUpdateFactor;

                float physfps = ((m_pfps / 1000));

                //if (physfps > 600)
                //physfps = physfps - (physfps - 600);

                if (physfps < 0)
                {
                    physfps = 0;
                }

                #endregion various statistic googly moogly

                m_rootAgents    = m_scene.SceneGraph.GetRootAgentCount();
                m_childAgents   = m_scene.SceneGraph.GetChildAgentCount();
                m_numPrim       = m_scene.SceneGraph.GetTotalObjectsCount();
                m_activePrim    = m_scene.SceneGraph.GetActiveObjectsCount();
                m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount();

                // FIXME: Checking for stat sanity is a complex approach.  What we really need to do is fix the code
                // so that stat numbers are always consistent.
                CheckStatSanity();

                //Our time dilation is 0.91 when we're running a full speed,
                // therefore to make sure we get an appropriate range,
                // we have to factor in our error.   (0.10f * statsUpdateFactor)
                // multiplies the fix for the error times the amount of times it'll occur a second
                // / 10 divides the value by the number of times the sim heartbeat runs (10fps)
                // Then we divide the whole amount by the amount of seconds pass in between stats updates.

                // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change
                // values to X-per-second values.

                uint  thisFrame     = m_scene.Frame;
                float framesUpdated = (float)(thisFrame - m_lastUpdateFrame) * m_reportedFpsCorrectionFactor;
                m_lastUpdateFrame = thisFrame;

                // Avoid div-by-zero if somehow we've not updated any frames.
                if (framesUpdated == 0)
                {
                    framesUpdated = 1;
                }

                for (int i = 0; i < 22; i++)
                {
                    sb[i] = new SimStatsPacket.StatBlock();
                }

                sb[0].StatID    = (uint)Stats.TimeDilation;
                sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation; //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10)  / statsUpdateFactor));

                sb[1].StatID    = (uint)Stats.SimFPS;
                sb[1].StatValue = reportedFPS / m_statsUpdateFactor;

                sb[2].StatID    = (uint)Stats.PhysicsFPS;
                sb[2].StatValue = physfps / m_statsUpdateFactor;

                sb[3].StatID    = (uint)Stats.AgentUpdates;
                sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor);

                sb[4].StatID    = (uint)Stats.Agents;
                sb[4].StatValue = m_rootAgents;

                sb[5].StatID    = (uint)Stats.ChildAgents;
                sb[5].StatValue = m_childAgents;

                sb[6].StatID    = (uint)Stats.TotalPrim;
                sb[6].StatValue = m_numPrim;

                sb[7].StatID    = (uint)Stats.ActivePrim;
                sb[7].StatValue = m_activePrim;

                sb[8].StatID    = (uint)Stats.FrameMS;
                sb[8].StatValue = m_frameMS / framesUpdated;

                sb[9].StatID    = (uint)Stats.NetMS;
                sb[9].StatValue = m_netMS / framesUpdated;

                sb[10].StatID    = (uint)Stats.PhysicsMS;
                sb[10].StatValue = m_physicsMS / framesUpdated;

                sb[11].StatID    = (uint)Stats.ImageMS;
                sb[11].StatValue = m_imageMS / framesUpdated;

                sb[12].StatID    = (uint)Stats.OtherMS;
                sb[12].StatValue = m_otherMS / framesUpdated;

                sb[13].StatID    = (uint)Stats.InPacketsPerSecond;
                sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor);

                sb[14].StatID    = (uint)Stats.OutPacketsPerSecond;
                sb[14].StatValue = (m_outPacketsPerSecond / m_statsUpdateFactor);

                sb[15].StatID    = (uint)Stats.UnAckedBytes;
                sb[15].StatValue = m_unAckedBytes;

                sb[16].StatID    = (uint)Stats.AgentMS;
                sb[16].StatValue = m_agentMS / framesUpdated;

                sb[17].StatID    = (uint)Stats.PendingDownloads;
                sb[17].StatValue = m_pendingDownloads;

                sb[18].StatID    = (uint)Stats.PendingUploads;
                sb[18].StatValue = m_pendingUploads;

                sb[19].StatID    = (uint)Stats.ActiveScripts;
                sb[19].StatValue = m_activeScripts;

                sb[20].StatID    = (uint)Stats.ScriptLinesPerSecond;
                sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor;

                sb[21].StatID    = (uint)Stats.SimSpareMs;
                sb[21].StatValue = m_spareMS / framesUpdated;

                for (int i = 0; i < 22; i++)
                {
                    lastReportedSimStats[i] = sb[i].StatValue;
                }

                SimStats simStats
                    = new SimStats(
                          ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity,
                          rb, sb, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }

                // Extra statistics that aren't currently sent to clients
                lock (m_lastReportedExtraSimStats)
                {
                    m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor;
                    m_lastReportedExtraSimStats[SlowFramesStat.ShortName]         = (float)SlowFramesStat.Value;

                    Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats();

                    if (physicsStats != null)
                    {
                        foreach (KeyValuePair <string, float> tuple in physicsStats)
                        {
                            // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second
                            // Need to change things so that stats source can indicate whether they are per second or
                            // per frame.
                            if (tuple.Key.EndsWith("MS"))
                            {
                                m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated;
                            }
                            else
                            {
                                m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor;
                            }
                        }
                    }
                }

                ResetValues();
            }
        }
Ejemplo n.º 23
0
 /// -----------------------------------------------------------------
 /// <summary>
 /// </summary>
 /// -----------------------------------------------------------------
 public AssetHandlers(Scene scene, IDispatcherModule dispatcher, string domain)
     : base(scene,dispatcher,domain)
 {
     IImprovedAssetCache cache = scene.RequestModuleInterface<IImprovedAssetCache>();
     if (cache is ISharedRegionModule)
         m_cache = cache;
 }
Ejemplo n.º 24
0
        public void InformClientToInitiateTeleportToLocationAsync(ScenePresence agent, uint regionX, uint regionY, Vector3 position,
            Scene initiatingScene)
        {
            Thread.Sleep(10000);
            IMessageTransferModule im = initiatingScene.RequestModuleInterface<IMessageTransferModule>();
            if (im != null)
            {
                UUID gotoLocation = Util.BuildFakeParcelID(
                    Util.UIntsToLong(
                                              (regionX *
                                               (uint)Constants.RegionSize),
                                              (regionY *
                                               (uint)Constants.RegionSize)),
                    (uint)(int)position.X,
                    (uint)(int)position.Y,
                    (uint)(int)position.Z);
                GridInstantMessage m = new GridInstantMessage(initiatingScene, UUID.Zero,
                "Region", agent.UUID,
                (byte)InstantMessageDialog.GodLikeRequestTeleport, false,
                "", gotoLocation, false, new Vector3(127, 0, 0),
                new Byte[0]);
                im.SendInstantMessage(m, delegate(bool success)
                {
                    //m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Client Initiating Teleport sending IM success = {0}", success);
                });

            }
        }
Ejemplo n.º 25
0
        public ScenePresence(
            IClientAPI client, Scene world, AvatarAppearance appearance, PresenceType type)
        {            
            m_scene = world;
            AttachmentsSyncLock = new Object();
            AllowMovement = true;
            IsChildAgent = true;
            IsLoggingIn = false;
            m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
            Animator = new ScenePresenceAnimator(this);
            Overrides = new MovementAnimationOverrides();
            PresenceType = type;
            DrawDistance = world.DefaultDrawDistance;
            RegionHandle = world.RegionInfo.RegionHandle;
            ControllingClient = client;
            Firstname = ControllingClient.FirstName;
            Lastname = ControllingClient.LastName;
            m_name = String.Format("{0} {1}", Firstname, Lastname);
            m_uuid = client.AgentId;
            LocalId = m_scene.AllocateLocalId();
            LegacySitOffsets = m_scene.LegacySitOffsets;

            UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
            if (account != null)
                m_userFlags = account.UserFlags;
            else
                m_userFlags = 0;

            if (account != null)
                UserLevel = account.UserLevel;

            IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
            if (gm != null)
               Grouptitle = gm.GetGroupTitle(m_uuid);

            m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>();
            
            AbsolutePosition = posLastSignificantMove = CameraPosition =
                m_lastCameraPosition = ControllingClient.StartPos;

            m_reprioritization_timer = new Timer(world.ReprioritizationInterval);
            m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize);
            m_reprioritization_timer.AutoReset = false;

            AdjustKnownSeeds();

            RegisterToEvents();
            SetDirectionVectors();

            Appearance = appearance;

            m_stateMachine = new ScenePresenceStateMachine(this);
        }
Ejemplo n.º 26
0
 public void RegionLoaded(Scene scene) 
 {
     m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
 }
Ejemplo n.º 27
0
        public void RegionLoaded(Scene scene)
        {
            if (!m_groupsEnabled)
                return;

            if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            scene.EventManager.OnNewClient += OnNewClient;
            scene.EventManager.OnMakeRootAgent += OnMakeRoot;
            scene.EventManager.OnMakeChildAgent += OnMakeChild;
            scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
            // The InstantMessageModule itself doesn't do this, 
            // so lets see if things explode if we don't do it
            // scene.EventManager.OnClientClosed += OnClientClosed;

            if (m_groupData == null)
            {
                m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();

                // No Groups Service Connector, then nothing works...
                if (m_groupData == null)
                {
                    m_groupsEnabled = false;
                    m_log.Error("[Groups]: Could not get IGroupsServicesConnector");
                    RemoveRegion(scene);
                    return;
                }
            }

            if (m_msgTransferModule == null)
            {
                m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>();

                // No message transfer module, no notices, group invites, rejects, ejects, etc
                if (m_msgTransferModule == null)
                {
                    m_log.Warn("[Groups]: Could not get MessageTransferModule");
                }
            }

            if (m_UserManagement == null)
            {
                m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
                if (m_UserManagement == null)
                    m_log.Warn("[Groups]: Could not get UserManagementModule");
            }

            lock (m_sceneList)
            {
                m_sceneList.Add(scene);
            }


        }
Ejemplo n.º 28
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            if (statsRunning)
            {
                return;
            }

            try
            {
                statsRunning = true;

                SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21];
                SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();

                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                float simfps = (int)m_fps;
                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = (float)simfps / statsUpdateFactor;

                float physfps = m_pfps;

                if (physfps < 0)
                {
                    physfps = 0;
                }

                //Our time dilation is 0.91 when we're running a full speed,
                // therefore to make sure we get an appropriate range,
                // we have to factor in our error.   (0.10f * statsUpdateFactor)
                // multiplies the fix for the error times the amount of times it'll occur a second
                // / 10 divides the value by the number of times the sim heartbeat runs (10fps)
                // Then we divide the whole amount by the amount of seconds pass in between stats updates.

                for (int i = 0; i < 21; i++)
                {
                    sb[i] = new SimStatsPacket.StatBlock();
                }

                sb[0].StatID    = (uint)Stats.TimeDilation;
                sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation; //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10)  / statsUpdateFactor));

                sb[1].StatID    = (uint)Stats.SimFPS;
                sb[1].StatValue = simfps / statsUpdateFactor;

                sb[2].StatID    = (uint)Stats.PhysicsFPS;
                sb[2].StatValue = physfps;

                sb[3].StatID    = (uint)Stats.AgentUpdates;
                sb[3].StatValue = (m_agentUpdates / statsUpdateFactor);

                sb[4].StatID    = (uint)Stats.Agents;
                sb[4].StatValue = m_rootAgents;

                sb[5].StatID    = (uint)Stats.ChildAgents;
                sb[5].StatValue = m_childAgents;

                sb[6].StatID    = (uint)Stats.TotalPrim;
                sb[6].StatValue = m_numPrim;

                sb[7].StatID    = (uint)Stats.ActivePrim;
                sb[7].StatValue = m_activePrim;

                sb[8].StatID    = (uint)Stats.FrameMS;
                sb[8].StatValue = m_frameMS / statsUpdateFactor;

                sb[9].StatID    = (uint)Stats.NetMS;
                sb[9].StatValue = m_netMS / statsUpdateFactor;

                sb[10].StatID    = (uint)Stats.PhysicsMS;
                sb[10].StatValue = m_physicsMS / statsUpdateFactor;

                sb[11].StatID    = (uint)Stats.ImageMS;
                sb[11].StatValue = m_imageMS / statsUpdateFactor;

                sb[12].StatID    = (uint)Stats.OtherMS;
                sb[12].StatValue = m_otherMS / statsUpdateFactor;

                sb[13].StatID    = (uint)Stats.InPacketsPerSecond;
                sb[13].StatValue = (m_inPacketsPerSecond);

                sb[14].StatID    = (uint)Stats.OutPacketsPerSecond;
                sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor);

                sb[15].StatID    = (uint)Stats.UnAckedBytes;
                sb[15].StatValue = m_unAckedBytes;

                sb[16].StatID    = (uint)Stats.AgentMS;
                sb[16].StatValue = m_agentMS / statsUpdateFactor;

                sb[17].StatID    = (uint)Stats.PendingDownloads;
                sb[17].StatValue = m_pendingDownloads;

                sb[18].StatID    = (uint)Stats.PendingUploads;
                sb[18].StatValue = m_pendingUploads;

                sb[19].StatID    = (uint)Stats.ActiveScripts;
                sb[19].StatValue = m_activeScripts;

                sb[20].StatID    = (uint)Stats.ScriptLinesPerSecond;
                sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor;

                SimStats simStats
                    = new SimStats(
                          ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }
                resetvalues();
            }
            finally
            {
                statsRunning = false;
            }
        }
Ejemplo n.º 29
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21];
            SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();

            // Know what's not thread safe in Mono... modifying timers.
            // m_log.Debug("Firing Stats Heart Beat");
            lock (m_report)
            {
                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                #region various statistic googly moogly

                // We're going to lie about the FPS because we've been lying since 2008.  The actual FPS is currently
                // locked at a maximum of 11.  Maybe at some point this can change so that we're not lying.
                int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor);

                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = reportedFPS / statsUpdateFactor;

                float physfps = ((m_pfps / 1000));

                //if (physfps > 600)
                //physfps = physfps - (physfps - 600);

                if (physfps < 0)
                {
                    physfps = 0;
                }

                #endregion

                //Our time dilation is 0.91 when we're running a full speed,
                // therefore to make sure we get an appropriate range,
                // we have to factor in our error.   (0.10f * statsUpdateFactor)
                // multiplies the fix for the error times the amount of times it'll occur a second
                // / 10 divides the value by the number of times the sim heartbeat runs (10fps)
                // Then we divide the whole amount by the amount of seconds pass in between stats updates.

                // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change
                // values to X-per-second values.

                for (int i = 0; i < 21; i++)
                {
                    sb[i] = new SimStatsPacket.StatBlock();
                }

                sb[0].StatID    = (uint)Stats.TimeDilation;
                sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation;  //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10)  / statsUpdateFactor));

                sb[1].StatID    = (uint)Stats.SimFPS;
                sb[1].StatValue = reportedFPS / statsUpdateFactor;

                sb[2].StatID    = (uint)Stats.PhysicsFPS;
                sb[2].StatValue = physfps / statsUpdateFactor;

                sb[3].StatID    = (uint)Stats.AgentUpdates;
                sb[3].StatValue = (m_agentUpdates / statsUpdateFactor);

                sb[4].StatID    = (uint)Stats.Agents;
                sb[4].StatValue = m_rootAgents;

                sb[5].StatID    = (uint)Stats.ChildAgents;
                sb[5].StatValue = m_childAgents;

                sb[6].StatID    = (uint)Stats.TotalPrim;
                sb[6].StatValue = m_numPrim;

                sb[7].StatID    = (uint)Stats.ActivePrim;
                sb[7].StatValue = m_activePrim;

                sb[8].StatID    = (uint)Stats.FrameMS;
                sb[8].StatValue = m_frameMS / statsUpdateFactor;

                sb[9].StatID    = (uint)Stats.NetMS;
                sb[9].StatValue = m_netMS / statsUpdateFactor;

                sb[10].StatID    = (uint)Stats.PhysicsMS;
                sb[10].StatValue = m_physicsMS / statsUpdateFactor;

                sb[11].StatID    = (uint)Stats.ImageMS;
                sb[11].StatValue = m_imageMS / statsUpdateFactor;

                sb[12].StatID    = (uint)Stats.OtherMS;
                sb[12].StatValue = m_otherMS / statsUpdateFactor;

                sb[13].StatID    = (uint)Stats.InPacketsPerSecond;
                sb[13].StatValue = (m_inPacketsPerSecond / statsUpdateFactor);

                sb[14].StatID    = (uint)Stats.OutPacketsPerSecond;
                sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor);

                sb[15].StatID    = (uint)Stats.UnAckedBytes;
                sb[15].StatValue = m_unAckedBytes;

                sb[16].StatID    = (uint)Stats.AgentMS;
                sb[16].StatValue = m_agentMS / statsUpdateFactor;

                sb[17].StatID    = (uint)Stats.PendingDownloads;
                sb[17].StatValue = m_pendingDownloads;

                sb[18].StatID    = (uint)Stats.PendingUploads;
                sb[18].StatValue = m_pendingUploads;

                sb[19].StatID    = (uint)Stats.ActiveScripts;
                sb[19].StatValue = m_activeScripts;

                sb[20].StatID    = (uint)Stats.ScriptLinesPerSecond;
                sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor;

                for (int i = 0; i < 21; i++)
                {
                    lastReportedSimStats[i] = sb[i].StatValue;
                }

                SimStats simStats
                    = new SimStats(
                          ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity,
                          rb, sb, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }

                // Extra statistics that aren't currently sent to clients
                LastReportedObjectUpdates = m_objectUpdates / statsUpdateFactor;

                resetvalues();
            }
        }
Ejemplo n.º 30
0
        public override void RegionLoaded(Scene scene)
        {
            base.RegionLoaded(scene);

            if (m_Enabled)
            {
                m_GatekeeperConnector = new GatekeeperServiceConnector(scene.AssetService);
                m_UAS = scene.RequestModuleInterface<IUserAgentService>();
                if (m_UAS == null)
                    m_UAS = new UserAgentServiceConnector(m_ThisHomeURI);

            }
        }
Ejemplo n.º 31
0
 public void RegionLoaded(Scene scene)
 {
     RegionCombinerModule = scene.RequestModuleInterface<IRegionCombinerModule>();
 }
Ejemplo n.º 32
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            if (!m_scene.Active)
            {
                return;
            }

            // dont do it if if still been done

            if (Monitor.TryEnter(m_statsLock))
            {
                // m_log.Debug("Firing Stats Heart Beat");

                SimStatsPacket.StatBlock[] sb   = new SimStatsPacket.StatBlock[m_statisticViewerArraySize];
                SimStatsPacket.StatBlock[] sbex = new SimStatsPacket.StatBlock[m_statisticExtraArraySize];
                SimStatsPacket.RegionBlock rb   = new SimStatsPacket.RegionBlock();
                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                #region various statistic googly moogly
                double timeTmp = m_lastUpdateTS;
                m_lastUpdateTS = Util.GetTimeStampMS();
                float updateElapsed = (float)((m_lastUpdateTS - timeTmp) / 1000.0);

                // factor to consider updates integration time
                float updateTimeFactor = 1.0f / updateElapsed;


                // scene frame stats
                float reportedFPS;
                float physfps;
                float timeDilation;
                float agentMS;
                float physicsMS;
                float otherMS;
                float sleeptime;
                float scriptTimeMS;
                float totalFrameTime;

                float invFrameElapsed;

                // get a copy under lock and reset
                lock (m_statsFrameLock)
                {
                    timeDilation   = m_timeDilation;
                    reportedFPS    = m_fps;
                    physfps        = m_pfps;
                    agentMS        = m_agentMS;
                    physicsMS      = m_physicsMS;
                    otherMS        = m_otherMS;
                    sleeptime      = m_sleeptimeMS;
                    scriptTimeMS   = m_scriptTimeMS;
                    totalFrameTime = m_frameMS;
                    // still not inv
                    invFrameElapsed = (float)((m_FrameStatsTS - m_prevFrameStatsTS) / 1000.0);

                    ResetFrameStats();
                }

                if (invFrameElapsed / updateElapsed < 0.8)
                {
                    // scene is in trouble, its account of time is most likely wrong
                    // can even be in stall
                    invFrameElapsed = updateTimeFactor;
                }
                else
                {
                    invFrameElapsed = 1.0f / invFrameElapsed;
                }

                float perframefactor;
                if (reportedFPS <= 0)
                {
                    reportedFPS    = 0.0f;
                    physfps        = 0.0f;
                    perframefactor = 1.0f;
                    timeDilation   = 0.0f;
                }
                else
                {
                    timeDilation  /= reportedFPS;
                    reportedFPS   *= m_statisticsFPSfactor;
                    perframefactor = 1.0f / (float)reportedFPS;
                    reportedFPS   *= invFrameElapsed;
                    physfps       *= invFrameElapsed * m_statisticsFPSfactor;
                }

                // some engines track frame time with error related to the simulation step size
                if (physfps > reportedFPS)
                {
                    physfps = reportedFPS;
                }

                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = reportedFPS;

                // scale frame stats

                totalFrameTime *= perframefactor;
                sleeptime      *= perframefactor;
                otherMS        *= perframefactor;
                physicsMS      *= perframefactor;
                agentMS        *= perframefactor;
                scriptTimeMS   *= perframefactor;

                // estimate spare time
                float sparetime;
                sparetime = m_targetFrameTime - (physicsMS + agentMS + otherMS);

                if (sparetime < 0)
                {
                    sparetime = 0;
                }
                else if (sparetime > totalFrameTime)
                {
                    sparetime = totalFrameTime;
                }

                #endregion

                m_rootAgents           = m_scene.SceneGraph.GetRootAgentCount();
                m_childAgents          = m_scene.SceneGraph.GetChildAgentCount();
                m_numPrim              = m_scene.SceneGraph.GetTotalObjectsCount();
                m_numGeoPrim           = m_scene.SceneGraph.GetTotalPrimObjectsCount();
                m_numMesh              = m_scene.SceneGraph.GetTotalMeshObjectsCount();
                m_activePrim           = m_scene.SceneGraph.GetActiveObjectsCount();
                m_activeScripts        = m_scene.SceneGraph.GetActiveScriptsCount();
                m_scriptLinesPerSecond = m_scene.SceneGraph.GetScriptLPS();

                // FIXME: Checking for stat sanity is a complex approach.  What we really need to do is fix the code
                // so that stat numbers are always consistent.
                CheckStatSanity();

                for (int i = 0; i < m_statisticViewerArraySize; i++)
                {
                    sb[i] = new SimStatsPacket.StatBlock();
                }

                sb[0].StatID    = (uint)Stats.TimeDilation;
                sb[0].StatValue = (Single.IsNaN(timeDilation)) ? 0.0f : (float)Math.Round(timeDilation, 3);

                sb[1].StatID    = (uint)Stats.SimFPS;
                sb[1].StatValue = (float)Math.Round(reportedFPS, 1);;

                sb[2].StatID    = (uint)Stats.PhysicsFPS;
                sb[2].StatValue = (float)Math.Round(physfps, 1);

                sb[3].StatID    = (uint)Stats.AgentUpdates;
                sb[3].StatValue = m_agentUpdates * updateTimeFactor;

                sb[4].StatID    = (uint)Stats.Agents;
                sb[4].StatValue = m_rootAgents;

                sb[5].StatID    = (uint)Stats.ChildAgents;
                sb[5].StatValue = m_childAgents;

                sb[6].StatID    = (uint)Stats.TotalPrim;
                sb[6].StatValue = m_numPrim;

                sb[7].StatID    = (uint)Stats.ActivePrim;
                sb[7].StatValue = m_activePrim;

                sb[8].StatID    = (uint)Stats.FrameMS;
                sb[8].StatValue = totalFrameTime;

                sb[9].StatID    = (uint)Stats.NetMS;
                sb[9].StatValue = m_netMS * perframefactor;

                sb[10].StatID    = (uint)Stats.PhysicsMS;
                sb[10].StatValue = physicsMS;

                sb[11].StatID    = (uint)Stats.ImageMS;
                sb[11].StatValue = m_imageMS * perframefactor;

                sb[12].StatID    = (uint)Stats.OtherMS;
                sb[12].StatValue = otherMS;

                sb[13].StatID    = (uint)Stats.InPacketsPerSecond;
                sb[13].StatValue = (float)Math.Round(m_inPacketsPerSecond * updateTimeFactor);

                sb[14].StatID    = (uint)Stats.OutPacketsPerSecond;
                sb[14].StatValue = (float)Math.Round(m_outPacketsPerSecond * updateTimeFactor);

                sb[15].StatID    = (uint)Stats.UnAckedBytes;
                sb[15].StatValue = m_unAckedBytes;

                sb[16].StatID    = (uint)Stats.AgentMS;
                sb[16].StatValue = agentMS;

                sb[17].StatID    = (uint)Stats.PendingDownloads;
                sb[17].StatValue = m_pendingDownloads;

                sb[18].StatID    = (uint)Stats.PendingUploads;
                sb[18].StatValue = m_pendingUploads;

                sb[19].StatID    = (uint)Stats.ActiveScripts;
                sb[19].StatValue = m_activeScripts;

                sb[20].StatID    = (uint)Stats.SimSleepMs;
                sb[20].StatValue = sleeptime;

                sb[21].StatID    = (uint)Stats.SimSpareMs;
                sb[21].StatValue = sparetime;

                //  this should came from phys engine
                sb[22].StatID    = (uint)Stats.SimPhysicsStepMs;
                sb[22].StatValue = 20;

                // send the ones we dont have as zeros, to clean viewers state
                // specially arriving from regions with wrond IDs in use

                sb[23].StatID    = (uint)Stats.VirtualSizeKb;
                sb[23].StatValue = 0;

                sb[24].StatID    = (uint)Stats.ResidentSizeKb;
                sb[24].StatValue = 0;

                sb[25].StatID    = (uint)Stats.PendingLocalUploads;
                sb[25].StatValue = 0;

                sb[26].StatID    = (uint)Stats.PhysicsPinnedTasks;
                sb[26].StatValue = 0;

                sb[27].StatID    = (uint)Stats.PhysicsLodTasks;
                sb[27].StatValue = 0;

                sb[28].StatID    = (uint)Stats.ScriptEps; // we actually have this, but not messing array order AGAIN
                sb[28].StatValue = (float)Math.Round(m_scriptEventsPerSecond * updateTimeFactor);

                sb[29].StatID    = (uint)Stats.SimAIStepTimeMS;
                sb[29].StatValue = 0;

                sb[30].StatID    = (uint)Stats.SimIoPumpTime;
                sb[30].StatValue = 0;

                sb[31].StatID    = (uint)Stats.SimPCTSscriptsRun;
                sb[31].StatValue = 0;

                sb[32].StatID    = (uint)Stats.SimRegionIdle;
                sb[32].StatValue = 0;

                sb[33].StatID    = (uint)Stats.SimRegionIdlePossible;
                sb[33].StatValue = 0;

                sb[34].StatID    = (uint)Stats.SimSkippedSillouet_PS;
                sb[34].StatValue = 0;

                sb[35].StatID    = (uint)Stats.SimSkippedCharsPerC;
                sb[35].StatValue = 0;

                sb[36].StatID    = (uint)Stats.SimPhysicsMemory;
                sb[36].StatValue = 0;

                sb[37].StatID    = (uint)Stats.ScriptMS;
                sb[37].StatValue = scriptTimeMS;

                for (int i = 0; i < m_statisticViewerArraySize; i++)
                {
                    lastReportedSimStats[i] = sb[i].StatValue;
                }


                // add extra stats for internal use

                for (int i = 0; i < m_statisticExtraArraySize; i++)
                {
                    sbex[i] = new SimStatsPacket.StatBlock();
                }

                sbex[0].StatID           = (uint)Stats.LSLScriptLinesPerSecond;
                sbex[0].StatValue        = m_scriptLinesPerSecond * updateTimeFactor;
                lastReportedSimStats[38] = m_scriptLinesPerSecond * updateTimeFactor;

                sbex[1].StatID           = (uint)Stats.FrameDilation2;
                sbex[1].StatValue        = (Single.IsNaN(timeDilation)) ? 0.1f : timeDilation;
                lastReportedSimStats[39] = (Single.IsNaN(timeDilation)) ? 0.1f : timeDilation;

                sbex[2].StatID           = (uint)Stats.UsersLoggingIn;
                sbex[2].StatValue        = m_usersLoggingIn;
                lastReportedSimStats[40] = m_usersLoggingIn;

                sbex[3].StatID           = (uint)Stats.TotalGeoPrim;
                sbex[3].StatValue        = m_numGeoPrim;
                lastReportedSimStats[41] = m_numGeoPrim;

                sbex[4].StatID           = (uint)Stats.TotalMesh;
                sbex[4].StatValue        = m_numMesh;
                lastReportedSimStats[42] = m_numMesh;

                sbex[5].StatID           = (uint)Stats.ThreadCount;
                sbex[5].StatValue        = m_inUseThreads;
                lastReportedSimStats[43] = m_inUseThreads;

                SimStats simStats
                    = new SimStats(
                          ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity,
                          rb, sb, sbex, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }

                // Extra statistics that aren't currently sent to clients
                if (m_scene.PhysicsScene != null)
                {
                    lock (m_lastReportedExtraSimStats)
                    {
                        m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates * updateTimeFactor;
                        m_lastReportedExtraSimStats[SlowFramesStat.ShortName]         = (float)SlowFramesStat.Value;

                        Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats();

                        if (physicsStats != null)
                        {
                            foreach (KeyValuePair <string, float> tuple in physicsStats)
                            {
                                // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second
                                // Need to change things so that stats source can indicate whether they are per second or
                                // per frame.
                                if (tuple.Key.EndsWith("MS"))
                                {
                                    m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * perframefactor;
                                }
                                else
                                {
                                    m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * updateTimeFactor;
                                }
                            }
                        }
                    }
                }

                //                LastReportedObjectUpdates = m_objectUpdates / m_statsUpdateFactor;
                ResetValues();
                Monitor.Exit(m_statsLock);
            }
        }
Ejemplo n.º 33
0
 public void PostFinishStartup(Scene scene, IConfigSource source, ISimulationBase openSimBase)
 {
     m_manager = scene.RequestModuleInterface<SceneManager>();
     m_backup[scene].FinishStartup();
 }
Ejemplo n.º 34
0
        public static float GetBilinearInterpolate(float x, float y, ITerrainChannel map, List <Scene> scenes)
        {
            int w = map.Width;
            int h = map.Height;

            Scene scene = null;

            if (x > w - 2)
            {
                scene = FindScene(map, scenes, map.Scene.RegionInfo.RegionSizeX, 0);
                if (scene != null)
                {
                    //Fix this position in the new heightmap
                    x  -= w;
                    map = scene.RequestModuleInterface <ITerrainChannel>();
                }
                else //1 away from the edge if we don't have a sim on this instance
                {
                    x = w - 2;
                }
            }
            if (y > h - 2)
            {
                scene = FindScene(map, scenes, 0, map.Scene.RegionInfo.RegionSizeY);
                if (scene != null)
                {
                    //Fix this position in the new heightmap
                    y  -= h;
                    map = scene.RequestModuleInterface <ITerrainChannel>();
                }
                else //1 away from the edge if we don't have a sim on this instance
                {
                    y = h - 2;
                }
            }
            if (x < 0.0)
            {
                scene = FindScene(map, scenes, -map.Scene.RegionInfo.RegionSizeX, 0);
                if (scene != null)
                {
                    //Fix this position in the new heightmap
                    x  += w;
                    map = scene.RequestModuleInterface <ITerrainChannel>();
                }
                else //1 away from the edge if we don't have a sim on this instance
                {
                    x = 0;
                }
            }
            if (y < 0.0)
            {
                scene = FindScene(map, scenes, 0, -map.Scene.RegionInfo.RegionSizeY);
                if (scene != null)
                {
                    //Fix this position in the new heightmap
                    y  += h;
                    map = scene.RequestModuleInterface <ITerrainChannel>();
                }
                else //1 away from the edge if we don't have a sim on this instance
                {
                    y = 0;
                }
            }

            if (x > map.Width - 2)
            {
                x = map.Width - 2;
            }
            if (x < 0)
            {
                x = 0;
            }
            if (y > map.Height - 2)
            {
                y = map.Height - 2;
            }
            if (y < 0)
            {
                y = 0;
            }

            const int stepSize = 1;
            float     h00      = map[(int)x, (int)y];
            float     h10      = map[(int)x + stepSize, (int)y];
            float     h01      = map[(int)x, (int)y + stepSize];
            float     h11      = map[(int)x + stepSize, (int)y + stepSize];
            float     h1       = h00;
            float     h2       = h10;
            float     h3       = h01;
            float     h4       = h11;
            float     a00      = h1;
            float     a10      = h2 - h1;
            float     a01      = h3 - h1;
            float     a11      = h1 - h2 - h3 + h4;
            float     partialx = x - (int)x;
            float     partialz = y - (int)y;
            float     hi       = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);

            return(hi);
        }
Ejemplo n.º 35
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21];
            SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();

            // Know what's not thread safe in Mono... modifying timers.
            // m_log.Debug("Firing Stats Heart Beat");
            lock (m_report)
            {
                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                #region various statistic googly moogly

                // Our FPS is actually 10fps, so multiplying by 5 to get the amount that people expect there
                // 0-50 is pretty close to 0-45
                float simfps = (int)((m_fps * 5));
                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = (float)simfps / statsUpdateFactor;

                //if (simfps > 45)
                //simfps = simfps - (simfps - 45);
                //if (simfps < 0)
                //simfps = 0;

                //
                float physfps = ((m_pfps / 1000));

                //if (physfps > 600)
                //physfps = physfps - (physfps - 600);

                if (physfps < 0)
                {
                    physfps = 0;
                }

                #endregion

                //Our time dilation is 0.91 when we're running a full speed,
                // therefore to make sure we get an appropriate range,
                // we have to factor in our error.   (0.10f * statsUpdateFactor)
                // multiplies the fix for the error times the amount of times it'll occur a second
                // / 10 divides the value by the number of times the sim heartbeat runs (10fps)
                // Then we divide the whole amount by the amount of seconds pass in between stats updates.

                for (int i = 0; i < 21; i++)
                {
                    sb[i] = new SimStatsPacket.StatBlock();
                }

                sb[0].StatID    = (uint)Stats.TimeDilation;
                sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation;  //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10)  / statsUpdateFactor));

                sb[1].StatID    = (uint)Stats.SimFPS;
                sb[1].StatValue = simfps / statsUpdateFactor;

                sb[2].StatID    = (uint)Stats.PhysicsFPS;
                sb[2].StatValue = physfps / statsUpdateFactor;

                sb[3].StatID    = (uint)Stats.AgentUpdates;
                sb[3].StatValue = (m_agentUpdates / statsUpdateFactor);

                sb[4].StatID    = (uint)Stats.Agents;
                sb[4].StatValue = m_rootAgents;

                sb[5].StatID    = (uint)Stats.ChildAgents;
                sb[5].StatValue = m_childAgents;

                sb[6].StatID    = (uint)Stats.TotalPrim;
                sb[6].StatValue = m_numPrim;

                sb[7].StatID    = (uint)Stats.ActivePrim;
                sb[7].StatValue = m_activePrim;

                sb[8].StatID    = (uint)Stats.FrameMS;
                sb[8].StatValue = m_frameMS / statsUpdateFactor;

                sb[9].StatID    = (uint)Stats.NetMS;
                sb[9].StatValue = m_netMS / statsUpdateFactor;

                sb[10].StatID    = (uint)Stats.PhysicsMS;
                sb[10].StatValue = m_physicsMS / statsUpdateFactor;

                sb[11].StatID    = (uint)Stats.ImageMS;
                sb[11].StatValue = m_imageMS / statsUpdateFactor;

                sb[12].StatID    = (uint)Stats.OtherMS;
                sb[12].StatValue = m_otherMS / statsUpdateFactor;

                sb[13].StatID    = (uint)Stats.InPacketsPerSecond;
                sb[13].StatValue = (m_inPacketsPerSecond);

                sb[14].StatID    = (uint)Stats.OutPacketsPerSecond;
                sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor);

                sb[15].StatID    = (uint)Stats.UnAckedBytes;
                sb[15].StatValue = m_unAckedBytes;

                sb[16].StatID    = (uint)Stats.AgentMS;
                sb[16].StatValue = m_agentMS / statsUpdateFactor;

                sb[17].StatID    = (uint)Stats.PendingDownloads;
                sb[17].StatValue = m_pendingDownloads;

                sb[18].StatID    = (uint)Stats.PendingUploads;
                sb[18].StatValue = m_pendingUploads;

                sb[19].StatID    = (uint)Stats.ActiveScripts;
                sb[19].StatValue = m_activeScripts;

                sb[20].StatID    = (uint)Stats.ScriptLinesPerSecond;
                sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor;

                SimStats simStats
                    = new SimStats(
                          ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }
                resetvalues();
            }
        }
Ejemplo n.º 36
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            double totalSumFrameTime;
            double simulationSumFrameTime;
            double physicsSumFrameTime;
            double networkSumFrameTime;
            double networkSumQueueSize;
            float  frameDilation;
            int    currentFrame;

            if (!m_scene.Active)
            {
                return;
            }

            // Create arrays to hold the statistics for this current scene,
            // these will be passed to the SimExtraStatsCollector, they are also
            // sent to the SimStats class
            SimStatsPacket.StatBlock[] sb = new
                                            SimStatsPacket.StatBlock[m_statisticArraySize];
            SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();

            // Know what's not thread safe in Mono... modifying timers.
            // m_log.Debug("Firing Stats Heart Beat");
            lock (m_report)
            {
                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                #region various statistic googly moogly

                // ORIGINAL code commented out until we have time to add our own
                // statistics to the statistics window, this will be done as a
                // new section given the title of our current project
                // We're going to lie about the FPS because we've been lying since 2008.  The actual FPS is currently
                // locked at a maximum of 11.  Maybe at some point this can change so that we're not lying.
                //int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor);
                int reportedFPS = m_fps;

                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = reportedFPS / m_statsUpdateFactor;

                // ORIGINAL code commented out until we have time to add our own
                // statistics to the statistics window
                //float physfps = ((m_pfps / 1000));
                float physfps = m_numberPhysicsFrames;

                //if (physfps > 600)
                //physfps = physfps - (physfps - 600);

                if (physfps < 0)
                {
                    physfps = 0;
                }

                #endregion

                m_rootAgents    = m_scene.SceneGraph.GetRootAgentCount();
                m_childAgents   = m_scene.SceneGraph.GetChildAgentCount();
                m_numPrim       = m_scene.SceneGraph.GetTotalObjectsCount();
                m_numGeoPrim    = m_scene.SceneGraph.GetTotalPrimObjectsCount();
                m_numMesh       = m_scene.SceneGraph.GetTotalMeshObjectsCount();
                m_activePrim    = m_scene.SceneGraph.GetActiveObjectsCount();
                m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount();

                // FIXME: Checking for stat sanity is a complex approach.  What we really need to do is fix the code
                // so that stat numbers are always consistent.
                CheckStatSanity();

                //Our time dilation is 0.91 when we're running a full speed,
                // therefore to make sure we get an appropriate range,
                // we have to factor in our error.   (0.10f * statsUpdateFactor)
                // multiplies the fix for the error times the amount of times it'll occur a second
                // / 10 divides the value by the number of times the sim heartbeat runs (10fps)
                // Then we divide the whole amount by the amount of seconds pass in between stats updates.

                // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change
                // values to X-per-second values.

                uint  thisFrame     = m_scene.Frame;
                float framesUpdated = (float)(thisFrame - m_lastUpdateFrame) * m_reportedFpsCorrectionFactor;
                m_lastUpdateFrame = thisFrame;

                // Avoid div-by-zero if somehow we've not updated any frames.
                if (framesUpdated == 0)
                {
                    framesUpdated = 1;
                }

                for (int i = 0; i < m_statisticArraySize; i++)
                {
                    sb[i] = new SimStatsPacket.StatBlock();
                }

                // Resetting the sums of the frame times to prevent any errors
                // in calculating the moving average for frame time
                totalSumFrameTime      = 0;
                simulationSumFrameTime = 0;
                physicsSumFrameTime    = 0;
                networkSumFrameTime    = 0;
                networkSumQueueSize    = 0;

                // Loop through all the frames that were stored for the current
                // heartbeat to process the moving average of frame times
                for (int i = 0; i < m_numberFramesStored; i++)
                {
                    // Sum up each frame time in order to calculate the moving
                    // average of frame time
                    totalSumFrameTime      += m_totalFrameTimeMilliseconds[i];
                    simulationSumFrameTime +=
                        m_simulationFrameTimeMilliseconds[i];
                    physicsSumFrameTime += m_physicsFrameTimeMilliseconds[i];
                    networkSumFrameTime += m_networkFrameTimeMilliseconds[i];
                    networkSumQueueSize += m_networkQueueSize[i];
                }

                // Get the index that represents the current frame based on the next one known; go back
                // to the last index if next one is stated to restart at 0
                if (m_nextLocation == 0)
                {
                    currentFrame = m_numberFramesStored - 1;
                }
                else
                {
                    currentFrame = m_nextLocation - 1;
                }

                // Calculate the frame dilation; which is currently based on the ratio between the sum of the
                // physics and simulation rate, and the set minimum time to run a scene's frame
                frameDilation = (float)(m_simulationFrameTimeMilliseconds[currentFrame] +
                                        m_physicsFrameTimeMilliseconds[currentFrame]) / m_scene.MinFrameTicks;

                // ORIGINAL code commented out until we have time to add our own
                sb[0].StatID    = (uint)Stats.TimeDilation;
                sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation;  //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10)  / statsUpdateFactor));

                sb[1].StatID    = (uint)Stats.SimFPS;
                sb[1].StatValue = reportedFPS / m_statsUpdateFactor;

                sb[2].StatID    = (uint)Stats.PhysicsFPS;
                sb[2].StatValue = physfps / m_statsUpdateFactor;

                sb[3].StatID    = (uint)Stats.AgentUpdates;
                sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor);

                sb[4].StatID    = (uint)Stats.Agents;
                sb[4].StatValue = m_rootAgents;

                sb[5].StatID    = (uint)Stats.ChildAgents;
                sb[5].StatValue = m_childAgents;

                sb[6].StatID    = (uint)Stats.TotalPrim;
                sb[6].StatValue = m_numPrim;

                sb[7].StatID    = (uint)Stats.ActivePrim;
                sb[7].StatValue = m_activePrim;

                // ORIGINAL code commented out until we have time to add our own
                // statistics to the statistics window
                sb[8].StatID = (uint)Stats.FrameMS;
                //sb[8].StatValue = m_frameMS / framesUpdated;
                sb[8].StatValue = (float)totalSumFrameTime / m_numberFramesStored;

                sb[9].StatID = (uint)Stats.NetMS;
                //sb[9].StatValue = m_netMS / framesUpdated;
                sb[9].StatValue = (float)networkSumFrameTime / m_numberFramesStored;

                sb[10].StatID = (uint)Stats.PhysicsMS;
                //sb[10].StatValue = m_physicsMS / framesUpdated;
                sb[10].StatValue = (float)physicsSumFrameTime / m_numberFramesStored;

                sb[11].StatID    = (uint)Stats.ImageMS;
                sb[11].StatValue = m_imageMS / framesUpdated;

                sb[12].StatID = (uint)Stats.OtherMS;
                //sb[12].StatValue = m_otherMS / framesUpdated;
                sb[12].StatValue = (float)simulationSumFrameTime /
                                   m_numberFramesStored;

                sb[13].StatID    = (uint)Stats.InPacketsPerSecond;
                sb[13].StatValue = (float)m_inPacketsPerSecond;

                sb[14].StatID    = (uint)Stats.OutPacketsPerSecond;
                sb[14].StatValue = (float)m_outPacketsPerSecond;

                sb[15].StatID    = (uint)Stats.UnAckedBytes;
                sb[15].StatValue = m_unAckedBytes;

                sb[16].StatID    = (uint)Stats.AgentMS;
                sb[16].StatValue = m_agentMS / framesUpdated;

                sb[17].StatID    = (uint)Stats.PendingDownloads;
                sb[17].StatValue = m_pendingDownloads;

                sb[18].StatID    = (uint)Stats.PendingUploads;
                sb[18].StatValue = m_pendingUploads;

                sb[19].StatID    = (uint)Stats.ActiveScripts;
                sb[19].StatValue = m_activeScripts;

                sb[20].StatID    = (uint)Stats.ScriptLinesPerSecond;
                sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor;

                sb[21].StatID    = (uint)Stats.SimSpareMs;
                sb[21].StatValue = m_spareMS / framesUpdated;

                // Current ratio between the sum of physics and sim rate, and the
                // minimum time to run a scene's frame
                sb[22].StatID    = (uint)Stats.FrameDilation;
                sb[22].StatValue = frameDilation;

                // Current number of users currently attemptint to login to region
                sb[23].StatID    = (uint)Stats.UsersLoggingIn;
                sb[23].StatValue = m_usersLoggingIn.Count;

                // Total number of geometric primitives in the scene
                sb[24].StatID    = (uint)Stats.TotalGeoPrim;
                sb[24].StatValue = m_numGeoPrim;

                // Total number of mesh objects in the scene
                sb[25].StatID    = (uint)Stats.TotalMesh;
                sb[25].StatValue = m_numMesh;

                // Current number of threads that XEngine is using
                sb[26].StatID    = (uint)Stats.ThreadCount;
                sb[26].StatValue = m_inUseThreads;

                // Tracks the number of bytes that are received by the server's
                // UDP network handler
                sb[27].StatID    = (uint)Stats.UDPInRate;
                sb[27].StatValue = (float)m_inByteRate;

                // Tracks the number of bytes that are sent by the server's UDP
                // network handler
                sb[28].StatID    = (uint)Stats.UDPOutRate;
                sb[28].StatValue = (float)m_outByteRate;

                // Tracks the number of packets that were received by the
                // server's UDP network handler, that were unable to be processed
                sb[29].StatID    = (uint)Stats.UDPErrorRate;
                sb[29].StatValue = (float)m_errorPacketRate;

                // Track the queue size of the network as a moving average
                sb[30].StatID    = (uint)Stats.NetworkQueueSize;
                sb[30].StatValue = (float)networkSumQueueSize /
                                   m_numberFramesStored;

                // Current average ping between the server and a subset of its conneced users
                sb[31].StatID    = (uint)Stats.ClientPingAvg;
                sb[31].StatValue = (float)m_clientPing;

                for (int i = 0; i < m_statisticArraySize; i++)
                {
                    lastReportedSimStats[i] = sb[i].StatValue;
                }

                SimStats simStats
                    = new SimStats(
                          ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity,
                          rb, sb, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }

                // Extra statistics that aren't currently sent to clients
                lock (m_lastReportedExtraSimStats)
                {
                    m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor;
                    m_lastReportedExtraSimStats[SlowFramesStat.ShortName]         = (float)SlowFramesStat.Value;

                    Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats();

                    if (physicsStats != null)
                    {
                        foreach (KeyValuePair <string, float> tuple in physicsStats)
                        {
                            // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second
                            // Need to change things so that stats source can indicate whether they are per second or
                            // per frame.
                            if (tuple.Key.EndsWith("MS"))
                            {
                                m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated;
                            }
                            else
                            {
                                m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor;
                            }
                        }
                    }
                }

                ResetValues();
            }
        }
Ejemplo n.º 37
0
            /// <summary>
            /// Called once new texture data has been received for this updater.
            /// </summary>
            public void DataReceived(byte[] data, Scene scene)
            {
                SceneObjectPart part = scene.GetSceneObjectPart(PrimID);

                if (part == null || data == null || data.Length <= 1)
                {
                    string msg = 
                        String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
                    scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say,
                                  0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false);
                    return;
                }

                byte[] assetData = null;
                AssetBase oldAsset = null;
                
                if (BlendWithOldTexture)
                {
                    Primitive.TextureEntryFace defaultFace = part.Shape.Textures.DefaultTexture;
                    if (defaultFace != null)
                    {
                        oldAsset = scene.AssetService.Get(defaultFace.TextureID.ToString());

                        if (oldAsset != null)
                            assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
                    }
                }

                if (assetData == null)
                {
                    assetData = new byte[data.Length];
                    Array.Copy(data, assetData, data.Length);
                }

                // Create a new asset for user
                AssetBase asset
                    = new AssetBase(
                        UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000), (sbyte)AssetType.Texture,
                        scene.RegionInfo.RegionID.ToString());
                asset.Data = assetData;
                asset.Description = String.Format("URL image : {0}", Url);
                asset.Local = false;
                asset.Temporary = ((Disp & DISP_TEMP) != 0);
                scene.AssetService.Store(asset);

                IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
                if (cacheLayerDecode != null)
                {
                    cacheLayerDecode.Decode(asset.FullID, asset.Data);
                    cacheLayerDecode = null;
                }

                UUID oldID = UUID.Zero;

                lock (part)
                {
                    // mostly keep the values from before
                    Primitive.TextureEntry tmptex = part.Shape.Textures;

                    // remove the old asset from the cache
                    oldID = tmptex.DefaultTexture.TextureID;
                    
                    if (Face == ALL_SIDES)
                    {
                        tmptex.DefaultTexture.TextureID = asset.FullID;
                    }
                    else
                    {
                        try
                        {
                            Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face);
                            texface.TextureID = asset.FullID;
                            tmptex.FaceTextures[Face] = texface;
                        }
                        catch (Exception)
                        {
                            tmptex.DefaultTexture.TextureID = asset.FullID;
                        }
                    }

                    // I'm pretty sure we always want to force this to true
                    // I'm pretty sure noone whats to set fullbright true if it wasn't true before.
                    // tmptex.DefaultTexture.Fullbright = true;

                    part.UpdateTexture(tmptex);
                }

                if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0))
                {
                    if (oldAsset == null) oldAsset = scene.AssetService.Get(oldID.ToString());
                    if (oldAsset != null)
                    {
                        if (oldAsset.Temporary == true)
                        {
                            scene.AssetService.Delete(oldID.ToString());
                        }
                    }
                }
            }
Ejemplo n.º 38
0
        private void statsHeartBeat(object sender, EventArgs e)
        {
            if (!m_scene.Active)
            {
                return;
            }

            // dont do it if if still been done

            if (Monitor.TryEnter(m_statsLock))
            {
                // m_log.Debug("Firing Stats Heart Beat");
                float[] newvalues = new float[(int)StatsIndex.ArraySize];

                uint regionFlags = 0;

                try
                {
                    if (estateModule == null)
                    {
                        estateModule = m_scene.RequestModuleInterface <IEstateModule>();
                    }
                    regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0;
                }
                catch (Exception)
                {
                    // leave region flags at 0
                }

                #region various statistic googly moogly
                double timeTmp = m_lastUpdateTS;
                m_lastUpdateTS = Util.GetTimeStampMS();
                float updateElapsed = (float)((m_lastUpdateTS - timeTmp) / 1000.0);

                // factor to consider updates integration time
                float updateTimeFactor = 1.0f / updateElapsed;

                // scene frame stats
                float reportedFPS;
                float physfps;
                float timeDilation;
                float agentMS;
                float physicsMS;
                float otherMS;
                float sleeptime;
                float scriptTimeMS;
                float totalFrameTime;

                float invFrameElapsed;

                // get a copy under lock and reset
                lock (m_statsFrameLock)
                {
                    timeDilation   = m_timeDilation;
                    reportedFPS    = m_fps;
                    physfps        = m_pfps;
                    agentMS        = m_agentMS;
                    physicsMS      = m_physicsMS;
                    otherMS        = m_otherMS;
                    sleeptime      = m_sleeptimeMS;
                    scriptTimeMS   = m_scriptTimeMS;
                    totalFrameTime = m_frameMS;
                    // still not inv
                    invFrameElapsed = (float)((m_FrameStatsTS - m_prevFrameStatsTS) / 1000.0);

                    ResetFrameStats();
                }

                if (invFrameElapsed / updateElapsed < 0.8)
                {
                    // scene is in trouble, its account of time is most likely wrong
                    // can even be in stall
                    invFrameElapsed = updateTimeFactor;
                }
                else
                {
                    invFrameElapsed = 1.0f / invFrameElapsed;
                }

                float perframefactor;
                if (reportedFPS <= 0)
                {
                    reportedFPS    = 0.0f;
                    physfps        = 0.0f;
                    perframefactor = 1.0f;
                    timeDilation   = 0.0f;
                }
                else
                {
                    timeDilation  /= reportedFPS;
                    reportedFPS   *= m_statisticsFPSfactor;
                    perframefactor = 1.0f / (float)reportedFPS;
                    reportedFPS   *= invFrameElapsed;
                    physfps       *= invFrameElapsed * m_statisticsFPSfactor;
                }

                // some engines track frame time with error related to the simulation step size
                if (physfps > reportedFPS)
                {
                    physfps = reportedFPS;
                }

                // save the reported value so there is something available for llGetRegionFPS
                lastReportedSimFPS = reportedFPS;

                // scale frame stats

                totalFrameTime *= perframefactor;
                sleeptime      *= perframefactor;
                otherMS        *= perframefactor;
                physicsMS      *= perframefactor;
                agentMS        *= perframefactor;
                scriptTimeMS   *= perframefactor;

                // estimate spare time
                float sparetime;
                sparetime = m_targetFrameTime - (physicsMS + agentMS + otherMS);

                if (sparetime < 0)
                {
                    sparetime = 0;
                }
                else if (sparetime > totalFrameTime)
                {
                    sparetime = totalFrameTime;
                }

                #endregion
                SceneGraph SG = m_scene.SceneGraph;
                OnStatsIncorrect?.Invoke(); // number of agents may still drift so fix

                m_activeScripts        = SG.GetActiveScriptsCount();
                m_scriptLinesPerSecond = SG.GetScriptLPS();

                newvalues[(int)StatsIndex.TimeDilation]        = (Single.IsNaN(timeDilation)) ? 0.0f : (float)Math.Round(timeDilation, 3);
                newvalues[(int)StatsIndex.SimFPS]              = (float)Math.Round(reportedFPS, 1);
                newvalues[(int)StatsIndex.PhysicsFPS]          = (float)Math.Round(physfps, 1);
                newvalues[(int)StatsIndex.AgentUpdates]        = m_agentUpdates * updateTimeFactor;
                newvalues[(int)StatsIndex.Agents]              = SG.GetRootAgentCount();
                newvalues[(int)StatsIndex.ChildAgents]         = SG.GetChildAgentCount();
                newvalues[(int)StatsIndex.TotalPrim]           = SG.GetTotalPrimObjectsCount();
                newvalues[(int)StatsIndex.ActivePrim]          = SG.GetActiveObjectsCount();
                newvalues[(int)StatsIndex.FrameMS]             = totalFrameTime;
                newvalues[(int)StatsIndex.NetMS]               = (float)Math.Round(m_netMS * perframefactor, 3);
                newvalues[(int)StatsIndex.PhysicsMS]           = (float)Math.Round(physicsMS, 3);
                newvalues[(int)StatsIndex.ImageMS]             = (float)Math.Round(m_imageMS * perframefactor, 3);
                newvalues[(int)StatsIndex.OtherMS]             = (float)Math.Round(otherMS, 3);
                newvalues[(int)StatsIndex.InPacketsPerSecond]  = (float)Math.Round(m_inPacketsPerSecond * updateTimeFactor);
                newvalues[(int)StatsIndex.OutPacketsPerSecond] = (float)Math.Round(m_outPacketsPerSecond * updateTimeFactor);
                newvalues[(int)StatsIndex.UnAckedBytes]        = m_unAckedBytes;
                newvalues[(int)StatsIndex.AgentMS]             = agentMS;
                newvalues[(int)StatsIndex.PendingDownloads]    = m_pendingDownloads;
                newvalues[(int)StatsIndex.PendingUploads]      = m_pendingUploads;
                newvalues[(int)StatsIndex.ActiveScripts]       = m_activeScripts;
                newvalues[(int)StatsIndex.SimSleepMs]          = (float)Math.Round(sleeptime, 3);
                newvalues[(int)StatsIndex.SimSpareMs]          = (float)Math.Round(sparetime, 3);
                newvalues[(int)StatsIndex.SimPhysicsStepMs]    = 20; // this should came from phys engine
                newvalues[(int)StatsIndex.ScriptMS]            = scriptTimeMS;
                newvalues[(int)StatsIndex.ScriptEps]           = (float)Math.Round(m_scriptEventsPerSecond * updateTimeFactor);

                // add extra stats for internal use
                newvalues[(int)StatsIndex.LSLScriptLinesPerSecond] = (float)Math.Round(m_scriptLinesPerSecond * updateTimeFactor, 3);
                newvalues[(int)StatsIndex.FrameDilation2]          = (Single.IsNaN(timeDilation)) ? 0.1f : (float)Math.Round(timeDilation, 1);
                newvalues[(int)StatsIndex.UsersLoggingIn]          = m_usersLoggingIn;
                newvalues[(int)StatsIndex.TotalGeoPrim]            = SG.GetTotalPrimObjectsCount();
                newvalues[(int)StatsIndex.TotalMesh] = SG.GetTotalMeshObjectsCount();
                newvalues[(int)StatsIndex.ScriptEngineThreadCount] = m_inUseThreads;
                newvalues[(int)StatsIndex.NPCs] = SG.GetRootNPCCount();

                lastReportedSimStats = newvalues;

                OnSendStatsResult?.Invoke(new SimStats(
                                              ReportingRegion.RegionLocX, ReportingRegion.RegionLocY,
                                              ReportingRegion.RegionSizeX, ReportingRegion.RegionSizeY,
                                              regionFlags, (uint)m_objectCapacity,
                                              newvalues,
                                              m_scene.RegionInfo.originRegionID,
                                              m_scene.RegionInfo.RegionName)
                                          );

                // Extra statistics that aren't currently sent elsewhere
                if (m_scene.PhysicsScene != null)
                {
                    lock (m_lastReportedExtraSimStats)
                    {
                        m_lastReportedExtraSimStats["LastReportedObjectUpdates"] = m_objectUpdates * updateTimeFactor;
                        m_lastReportedExtraSimStats[SlowFramesStat.ShortName]    = (float)SlowFramesStat.Value;

                        Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats();

                        if (physicsStats != null)
                        {
                            foreach (KeyValuePair <string, float> tuple in physicsStats)
                            {
                                // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second
                                // Need to change things so that stats source can indicate whether they are per second or
                                // per frame.
                                if (tuple.Key.EndsWith("MS"))
                                {
                                    m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * perframefactor;
                                }
                                else
                                {
                                    m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * updateTimeFactor;
                                }
                            }
                        }
                    }
                }

//                LastReportedObjectUpdates = m_objectUpdates / m_statsUpdateFactor;
                ResetValues();
                Monitor.Exit(m_statsLock);
            }
        }