protected void SendCompleteMessage(IClientAPI remoteClient) { remoteClient.SendAssetUploadCompleteMessage(m_asset.Type, true, m_asset.FullID); m_finished = true; if (m_createItem) { DoCreateItem(m_createItemCallback, remoteClient); } else if (m_storeLocal) { m_userTransactions.Manager.MyScene.AssetService.Store(m_asset); } IMonitorModule monitorModule = m_userTransactions.Manager.MyScene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor)monitorModule.GetMonitor(m_userTransactions.Manager.MyScene.RegionInfo.RegionID.ToString(), "Network Monitor"); networkMonitor.AddPendingUploads(-1); } m_log.DebugFormat( "[ASSET TRANSACTIONS]: Uploaded asset {0} for transaction {1}", m_asset.FullID, TransactionID); if (m_dumpAssetToFile) { DateTime now = DateTime.Now; string filename = String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, m_asset.Name, m_asset.Type); SaveAssetToFile(filename, m_asset.Data); } }
protected void SendCompleteMessage(IClientAPI remoteClient) { lock (_finishedLock) { m_finished = true; if (FinishedEvent != null) { FinishedEvent(); } if (m_createItem) { DoCreateItem(m_createItemCallback, remoteClient); } else if (m_storeLocal) { m_asset.ID = m_userTransactions.Manager.MyScene.AssetService.Store(m_asset); } } remoteClient.SendAssetUploadCompleteMessage((sbyte)m_asset.Type, true, m_asset.ID); IMonitorModule monitorModule = m_userTransactions.Manager.MyScene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor) monitorModule.GetMonitor(m_userTransactions.Manager.MyScene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor); networkMonitor.AddPendingUploads(-1); } MainConsole.Instance.DebugFormat( "[ASSET TRANSACTIONS]: Uploaded asset {0} for transaction {1}", m_asset.ID, TransactionID); }
/// <summary> /// Return the xfer uploader for the given transaction. /// </summary> /// <remarks> /// If an uploader does not already exist for this transaction then it is created, otherwise the existing /// uploader is returned. /// </remarks> /// <param name="transactionID"></param> /// <returns>The asset xfer uploader</returns> public AssetXferUploader RequestXferUploader(UUID transactionID) { AssetXferUploader uploader; lock (XferUploaders) { if (!XferUploaders.ContainsKey(transactionID)) { uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile); // MainConsole.Instance.DebugFormat( // "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID); XferUploaders.Add(transactionID, uploader); } else { uploader = XferUploaders[transactionID]; } } IMonitorModule monitorModule = m_Scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = monitorModule.GetMonitor <INetworkMonitor>(m_Scene); networkMonitor.AddPendingUploads(1); } return(uploader); }
public void FinishedStartup() { IMonitorModule monitor = m_simulationBase.ApplicationRegistry.RequestModuleInterface <IMonitorModule>(); if (monitor != null) { _assetMonitor = monitor.GetMonitor <IAssetMonitor>(null); } }
public bool CmdHandlerQueue() { if (m_ScriptEngine.Worlds.Count == 0) { CmdHandlerQueueIsRunning = false; return(false); } CmdHandlerQueueIsRunning = true; IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return(true); } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return(true); } //Check timers, etc bool didAnything = false; try { didAnything = m_ScriptEngine.DoOneScriptPluginPass(); } catch (Exception ex) { m_log.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex); } Thread.Sleep(10); // don't burn cpu if (module != null) { foreach (Scene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), "Script Frame Time"); scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } if (didAnything) { CmdHandlerQueueIsRunning = true; threadpool.QueueEvent(CmdHandlerQueue, 2); } else { CmdHandlerQueueIsRunning = false; } return(false); }
public void CmdHandlerQueue() { if (m_ScriptEngine.Scene == null) { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); return; } Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 1); IMonitorModule module = m_ScriptEngine.Scene.RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); return; } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled || !m_ScriptEngine.Scene.ShouldRunHeartbeat) { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); return; } //Check timers, etc bool didAnything = false; try { didAnything = m_ScriptEngine.DoOneScriptPluginPass(); } catch (Exception ex) { MainConsole.Instance.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex); } if (module != null) { IScriptFrameTimeMonitor scriptMonitor = module.GetMonitor <IScriptFrameTimeMonitor>(m_ScriptEngine.Scene); if (scriptMonitor != null) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } if (didAnything) //If we did something, run us again soon { cmdThreadpool.QueueEvent(CmdHandlerQueue, 2); } else { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); } }
//private void CreateItemFromUpload(AssetBase asset, IClientAPI ourClient, UUID inventoryFolderID, uint nextPerms, uint wearableType) //{ // Manager.MyScene.CommsManager.AssetCache.AddAsset(asset); // CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( // ourClient.AgentId); // if (userInfo != null) // { // InventoryItemBase item = new InventoryItemBase(); // item.Owner = ourClient.AgentId; // item.Creator = ourClient.AgentId; // item.ID = UUID.Random(); // item.AssetID = asset.FullID; // item.Description = asset.Description; // item.Name = asset.Name; // item.AssetType = asset.Type; // item.InvType = asset.Type; // item.Folder = inventoryFolderID; // item.BasePermissions = 0x7fffffff; // item.CurrentPermissions = 0x7fffffff; // item.EveryOnePermissions = 0; // item.NextPermissions = nextPerms; // item.Flags = wearableType; // item.CreationDate = Util.UnixTimeSinceEpoch(); // userInfo.AddItem(item); // ourClient.SendInventoryItemCreateUpdate(item); // } // else // { // MainConsole.Instance.ErrorFormat( // "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item creation", // ourClient.AgentId); // } //} public void RequestUpdateTaskInventoryItem( IClientAPI remoteClient, ISceneChildEntity part, UUID transactionID, TaskInventoryItem item) { if (XferUploaders.ContainsKey(transactionID)) { AssetBase asset = XferUploaders[transactionID].GetAssetData(); if (asset != null) { MainConsole.Instance.DebugFormat( "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}", item.Name, part.Name, transactionID); asset.Name = item.Name; asset.Description = item.Description; asset.Type = (sbyte)item.Type; item.AssetID = asset.ID; IMonitorModule monitorModule = Manager.MyScene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor) monitorModule.GetMonitor(Manager.MyScene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor); networkMonitor.AddPendingUploads(-1); } asset.ID = Manager.MyScene.AssetService.Store(asset); item.AssetID = asset.ID; if (part.Inventory.UpdateInventoryItem(item)) { if ((InventoryType)item.InvType == InventoryType.Notecard) { remoteClient.SendAgentAlertMessage("Notecard saved", false); } else if ((InventoryType)item.InvType == InventoryType.LSL) { remoteClient.SendAgentAlertMessage("Script saved", false); } else { remoteClient.SendAgentAlertMessage("Item saved", false); } part.GetProperties(remoteClient); } } } }
public bool ProcessImageQueue(int packetsToSend) { int StartTime = Util.EnvironmentTickCount(); int packetsSent = 0; while (packetsSent < packetsToSend) { J2KImage image = GetHighestPriorityImage(); // If null was returned, the texture priority queue is currently empty if (image == null) { return(false); } if (image.IsDecoded) { int sent; bool imageDone = image.SendPackets(m_client, packetsToSend - packetsSent, out sent); packetsSent += sent; // If the send is complete, destroy any knowledge of this transfer if (imageDone) { RemoveImageFromQueue(image); } } else { // TODO: This is a limitation of how LLImageManager is currently // written. Undecoded textures should not be going into the priority // queue, because a high priority undecoded texture will clog up the // pipeline for a client return(true); } } int EndTime = Util.EnvironmentTickCountSubtract(StartTime); IMonitorModule module = m_client.Scene.RequestModuleInterface <IMonitorModule>(); if (module != null) { IImageFrameTimeMonitor monitor = (IImageFrameTimeMonitor)module.GetMonitor(m_client.Scene.RegionInfo.RegionID.ToString(), "Images Frame Time"); monitor.AddImageTime(EndTime); } return(m_priorityQueue.Count > 0); }
/// <summary> /// Handle asset transfer data packets received in response to the asset upload request in /// HandleUDPUploadRequest() /// </summary> /// <param name="remoteClient"></param> /// <param name="xferID"></param> /// <param name="packetID"></param> /// <param name="data"></param> public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { //MainConsole.Instance.Debug("xferID: " + xferID + " packetID: " + packetID + " data!"); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); IMonitorModule monitorModule = m_scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = monitorModule.GetMonitor <INetworkMonitor>(m_scene); networkMonitor.AddPendingUploads(1); } transactions.HandleXfer(remoteClient, xferID, packetID, data); }
/// <summary> /// Handle asset transfer data packets received in response to the asset upload request in /// HandleUDPUploadRequest() /// </summary> /// <param name="remoteClient"></param> /// <param name="xferID"></param> /// <param name="packetID"></param> /// <param name="data"></param> public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { //m_log.Debug("xferID: " + xferID + " packetID: " + packetID + " data!"); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); IMonitorModule monitorModule = m_scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor)monitorModule.GetMonitor(m_scene.RegionInfo.RegionID.ToString(), "Network Monitor"); networkMonitor.AddPendingUploads(1); } transactions.HandleXfer(remoteClient, xferID, packetID, data); }
private void DoCreateItem(uint callbackID, IClientAPI remoteClient) { m_asset.ID = m_userTransactions.Manager.MyScene.AssetService.Store(m_asset); IMonitorModule monitorModule = m_userTransactions.Manager.MyScene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor) monitorModule.GetMonitor(m_userTransactions.Manager.MyScene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor); networkMonitor.AddPendingUploads(-1); } InventoryItemBase item = new InventoryItemBase { Owner = remoteClient.AgentId, CreatorId = remoteClient.AgentId.ToString(), ID = UUID.Random(), AssetID = m_asset.ID, Description = m_description, Name = m_name, AssetType = type, InvType = invType, Folder = InventFolder, BasePermissions = 0x7fffffff, CurrentPermissions = 0x7fffffff, GroupPermissions = 0, EveryOnePermissions = 0, NextPermissions = nextPerm, Flags = wearableType, CreationDate = Util.UnixTimeSinceEpoch() }; ILLClientInventory inventoryModule = m_userTransactions.Manager.MyScene.RequestModuleInterface <ILLClientInventory>(); if (inventoryModule != null && inventoryModule.AddInventoryItem(item)) { remoteClient.SendInventoryItemCreateUpdate(item, callbackID); } else { remoteClient.SendAlertMessage("Unable to create inventory item"); } }
/// <summary> /// Update a task inventory item with data that has been received through a transaction. /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction /// and comes through this method. /// </summary> /// <param name="remoteClient"></param> /// <param name="part"></param> /// <param name="transactionID"></param> /// <param name="item"></param> public void HandleTaskItemUpdateFromTransaction( IClientAPI remoteClient, ISceneChildEntity part, UUID transactionID, TaskInventoryItem item) { // MainConsole.Instance.DebugFormat("[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}", item.Name); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); IMonitorModule monitorModule = m_scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = monitorModule.GetMonitor <INetworkMonitor>(m_scene); networkMonitor.AddPendingUploads(1); } transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item); }
/// <summary> /// Request that a client (agent) begin an asset transfer. /// </summary> /// <param name = "remoteClient"></param> /// <param name = "assetID"></param> /// <param name = "transaction"></param> /// <param name = "type"></param> /// <param name = "data"></param> /// </param> /// <param name = "tempFile"></param> public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data, bool storeLocal, bool tempFile) { // MainConsole.Instance.Debug("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile); if (((AssetType)type == AssetType.Texture || (AssetType)type == AssetType.Sound || (AssetType)type == AssetType.TextureTGA || (AssetType)type == AssetType.Animation) && tempFile == false) { IScene scene = remoteClient.Scene; IMoneyModule mm = scene.RequestModuleInterface <IMoneyModule>(); if (mm != null) { if (!mm.Charge(remoteClient, mm.UploadCharge)) { remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); return; } } } AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); IMonitorModule monitorModule = m_scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor) monitorModule.GetMonitor(m_scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor); networkMonitor.AddPendingUploads(1); } AssetXferUploader uploader = transactions.RequestXferUploader(transaction); if (uploader != null) { uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); } }
/// <summary> /// Update an inventory item with data that has been received through a transaction. /// /// This is called when clothing or body parts are updated (for instance, with new textures or /// colours). It may also be called in other situations. /// </summary> /// <param name="remoteClient"></param> /// <param name="transactionID"></param> /// <param name="item"></param> public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item) { // m_log.DebugFormat( // "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}", // item.Name); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); IMonitorModule monitorModule = m_scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor)monitorModule.GetMonitor(m_scene.RegionInfo.RegionID.ToString(), "Network Monitor"); networkMonitor.AddPendingUploads(1); } transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item); }
/// <summary> /// Create an inventory item from data that has been received through a transaction. /// This is called when new clothing or body parts are created. It may also be called in other /// situations. /// </summary> /// <param name="remoteClient"></param> /// <param name="transactionID"></param> /// <param name="folderID"></param> /// <param name="callbackID"></param> /// <param name="description"></param> /// <param name="name"></param> /// <param name="invType"></param> /// <param name="type"></param> /// <param name="wearableType"></param> /// <param name="nextOwnerMask"></param> public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID, uint callbackID, string description, string name, sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask) { // MainConsole.Instance.DebugFormat("[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); IMonitorModule monitorModule = m_scene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = monitorModule.GetMonitor <INetworkMonitor>(m_scene); networkMonitor.AddPendingUploads(1); } transactions.RequestCreateInventoryItem( remoteClient, transactionID, folderID, callbackID, description, name, invType, type, wearableType, nextOwnerMask); }
public void RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item) { if (XferUploaders.ContainsKey(transactionID)) { UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId); AssetBase asset = Manager.MyScene.AssetService.Get(assetID.ToString()); if (asset == null) { asset = GetTransactionAsset(transactionID); } if (asset != null && asset.ID == assetID) { // Assets never get updated, new ones get created asset.ID = UUID.Random(); asset.Name = item.Name; asset.Description = item.Description; asset.Type = (sbyte)item.AssetType; item.AssetID = asset.ID; asset.ID = Manager.MyScene.AssetService.Store(asset); item.AssetID = asset.ID; } IMonitorModule monitorModule = Manager.MyScene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor) monitorModule.GetMonitor(Manager.MyScene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor); networkMonitor.AddPendingUploads(-1); } IInventoryService invService = Manager.MyScene.InventoryService; invService.UpdateItem(item); } }
private void UpdateInventoryItemWithAsset(InventoryItemBase item, UUID assetID, UUID transactionID) { AssetXferUploader uploader = XferUploaders[transactionID]; AssetBase asset = uploader.GetAssetData(); if (asset != null && asset.ID == assetID) { // Assets never get updated, new ones get created asset.ID = UUID.Random(); asset.Name = item.Name; asset.Description = item.Description; asset.Type = (sbyte)item.AssetType; item.AssetID = asset.ID; asset.ID = Manager.MyScene.AssetService.Store(asset); item.AssetID = asset.ID; XferUploaders.Remove(transactionID); } else { return; } IMonitorModule monitorModule = Manager.MyScene.RequestModuleInterface <IMonitorModule>(); if (monitorModule != null) { INetworkMonitor networkMonitor = (INetworkMonitor) monitorModule.GetMonitor(Manager.MyScene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor); networkMonitor.AddPendingUploads(-1); } IInventoryService invService = Manager.MyScene.InventoryService; invService.UpdateItem(item); }
private bool Update() { IMonitorModule monitorModule = RequestModuleInterface <IMonitorModule>(); ISimFrameMonitor simFrameMonitor = monitorModule.GetMonitor <ISimFrameMonitor>(this); ITotalFrameTimeMonitor totalFrameMonitor = monitorModule.GetMonitor <ITotalFrameTimeMonitor>(this); ILastFrameTimeMonitor lastFrameMonitor = monitorModule.GetMonitor <ILastFrameTimeMonitor>(this); IOtherFrameMonitor otherFrameMonitor = monitorModule.GetMonitor <IOtherFrameMonitor>(this); ISleepFrameMonitor sleepFrameMonitor = monitorModule.GetMonitor <ISleepFrameMonitor>(this); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++m_frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); if (m_frame % m_update_coarse_locations == 0) { List <Vector3> coarseLocations; List <UUID> avatarUUIDs; if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60)) { // Send coarse locations to clients foreach (IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } } if (m_frame % m_update_entities == 0) { m_sceneGraph.UpdateEntities(); } Action[] events; lock (m_events) { events = new Action[m_events.Count]; m_events.CopyTo(events); m_events.Clear(); } foreach (Action h in events) { try { h(); } catch { } } if (m_frame % m_update_events == 0) { m_sceneGraph.PhysicsScene.UpdatesLoop(); } if (m_frame % m_update_events == 0) { m_eventManager.TriggerOnFrame(); } //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); } catch (Exception e) { MainConsole.Instance.Error("[REGION]: Failed with exception " + e + " in region: " + RegionInfo.RegionName); return(true); } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); //Beginning + (time between beginning and end) = end int MonitorEndFrameTime = BeginningFrameTime + maintc; int getSleepTime = GetHeartbeatSleepTime(maintc, false); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } if (sleepFrameMonitor != null) { sleepFrameMonitor.AddTime(maintc); totalFrameMonitor.AddFrameTime(MonitorEndFrameTime); } } }
private bool PhysUpdate() { IMonitorModule monitorModule = RequestModuleInterface <IMonitorModule>(); IPhysicsFrameMonitor physicsFrameMonitor = monitorModule.GetMonitor <IPhysicsFrameMonitor>(this); IPhysicsUpdateFrameMonitor physicsFrameTimeMonitor = monitorModule.GetMonitor <IPhysicsUpdateFrameMonitor>(this); IPhysicsMonitor monitor2 = RequestModuleInterface <IPhysicsMonitor>(); ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>(); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; ISceneEntity[] entities = null; lock (PhysicsReturns) { if (PhysicsReturns.Count != 0) { entities = PhysicsReturns.ToArray(); PhysicsReturns.Clear(); } } if (entities != null && inventoryModule != null) { inventoryModule.ReturnObjects(entities, UUID.Zero); } int PhysicsUpdateTime = Util.EnvironmentTickCount(); if (m_frame % m_update_physics == 0) { TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate; if (!RegionInfo.RegionSettings.DisablePhysics && ApproxEquals((float)SinceLastFrame.TotalMilliseconds, m_updatetimespan, 3)) { m_sceneGraph.UpdatePreparePhysics(); m_sceneGraph.UpdatePhysics((float)SinceLastFrame.TotalSeconds); m_lastphysupdate = DateTime.UtcNow; int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime); if (MonitorPhysicsUpdateTime != 0) { if (physicsFrameTimeMonitor != null) { physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime); } if (monitor2 != null) { monitor2.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene); } if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StartPhysicsScene(); } } if (physicsFrameMonitor != null) { physicsFrameMonitor.AddFPS(1); } } else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StopPhysicsScene(); } m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics; } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); if (maintc == 0) { continue; } int getSleepTime = GetHeartbeatSleepTime(maintc, true); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } } }
void Heartbeat() { IMonitorModule monitorModule = RequestModuleInterface <IMonitorModule>(); ISimFrameMonitor simFrameMonitor = monitorModule.GetMonitor <ISimFrameMonitor>(this); ITotalFrameTimeMonitor totalFrameMonitor = monitorModule.GetMonitor <ITotalFrameTimeMonitor>(this); ILastFrameTimeMonitor lastFrameMonitor = monitorModule.GetMonitor <ILastFrameTimeMonitor>(this); IOtherFrameMonitor otherFrameMonitor = monitorModule.GetMonitor <IOtherFrameMonitor>(this); ISleepFrameMonitor sleepFrameMonitor = monitorModule.GetMonitor <ISleepFrameMonitor>(this); IPhysicsFrameMonitor physicsFrameMonitor = monitorModule.GetMonitor <IPhysicsFrameMonitor>(this); IPhysicsUpdateFrameMonitor physicsFrameTimeMonitor = monitorModule.GetMonitor <IPhysicsUpdateFrameMonitor>(this); IPhysicsMonitor physicsMonitor = RequestModuleInterface <IPhysicsMonitor>(); ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>(); while (true) { if (!ShouldRunHeartbeat) //If we aren't supposed to be running, kill ourselves { return; } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++Frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); ISceneEntity[] entities = null; lock (PhysicsReturns) { if (PhysicsReturns.Count != 0) { entities = PhysicsReturns.ToArray(); PhysicsReturns.Clear(); } } if (entities != null && inventoryModule != null) { inventoryModule.ReturnObjects(entities, UUID.Zero); } if (Frame % m_update_entities == 0) { m_sceneGraph.UpdateEntities(); } if (Frame % m_update_events == 0) { m_sceneGraph.PhysicsScene.UpdatesLoop(); } if (Frame % m_update_events == 0) { m_eventManager.TriggerOnFrame(); } if (Frame % m_update_coarse_locations == 0) { List <Vector3> coarseLocations; List <UUID> avatarUUIDs; if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60)) { // Send coarse locations to clients foreach (IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } } int PhysicsUpdateTime = Util.EnvironmentTickCount(); if (Frame % m_update_physics == 0) { TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate; if (!RegionInfo.RegionSettings.DisablePhysics && ApproxEquals((float)SinceLastFrame.TotalMilliseconds, m_updatetimespan, 3)) { m_sceneGraph.UpdatePreparePhysics(); m_sceneGraph.UpdatePhysics((float)SinceLastFrame.TotalSeconds); m_lastphysupdate = DateTime.UtcNow; int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime); if (MonitorPhysicsUpdateTime != 0) { if (physicsFrameTimeMonitor != null) { physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime); } if (physicsMonitor != null) { physicsMonitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene); } if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StartPhysicsScene(); } } if (physicsFrameMonitor != null) { physicsFrameMonitor.AddFPS(1); } } else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StopPhysicsScene(); } m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics; } //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); } catch (Exception e) { MainConsole.Instance.Error("[Scene]: Failed with exception " + e + " in region: " + RegionInfo.RegionName); return; } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); //Beginning + (time between beginning and end) = end int MonitorEndFrameTime = BeginningFrameTime + maintc; int getSleepTime = GetHeartbeatSleepTime(maintc); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } if (sleepFrameMonitor != null) { sleepFrameMonitor.AddTime(getSleepTime); totalFrameMonitor.AddFrameTime(MonitorEndFrameTime); } } }
public bool ProcessImageQueue(int packetsToSend) { int StartTime = Util.EnvironmentTickCount(); int packetsSent = 0; List <J2KImage> imagesToReAdd = new List <J2KImage>(); while (packetsSent < packetsToSend) { J2KImage image = GetHighestPriorityImage(); // If null was returned, the texture priority queue is currently empty if (image == null) { break; } //Break so that we add any images back that we might remove because they arn't finished decoding if (image.IsDecoded) { if (image.Layers == null) { //We don't have it, tell the client that it doesn't exist m_client.SendAssetUploadCompleteMessage((sbyte)AssetType.Texture, false, image.TextureID); packetsSent++; } else { int sent; bool imageDone = image.SendPackets(m_client, packetsToSend - packetsSent, out sent); packetsSent += sent; // If the send is complete, destroy any knowledge of this transfer if (!imageDone) { AddImageToQueue(image); } } } else { //Add it to the other queue and delete it from the top imagesToReAdd.Add(image); packetsSent++; //We tried to send one } } //Add all the ones we removed so that we wouldn't block the queue if (imagesToReAdd.Count != 0) { foreach (J2KImage image in imagesToReAdd) { AddImageToQueue(image); } } int EndTime = Util.EnvironmentTickCountSubtract(StartTime); IMonitorModule module = m_client.Scene.RequestModuleInterface <IMonitorModule>(); if (module != null) { IImageFrameTimeMonitor monitor = module.GetMonitor <IImageFrameTimeMonitor>(m_client.Scene); monitor.AddImageTime(EndTime); } lock (m_syncRoot) return(m_queue.Count > 0); }
public bool ProcessImageQueue(int packetsToSend) { int StartTime = Util.EnvironmentTickCount(); int packetsSent = 0; List <J2KImage> imagesToReAdd = new List <J2KImage>(); while (packetsSent < packetsToSend) { J2KImage image = GetHighestPriorityImage(); // If null was returned, the texture priority queue is currently empty if (image == null) { break; //Break so that we add any images back that we might remove because they arn't finished decoding } if (image.IsDecoded) { if (image.Layers == null) { //We don't have it, tell the client that it doesn't exist m_client.SendAssetUploadCompleteMessage((sbyte)AssetType.Texture, false, image.TextureID); RemoveImageFromQueue(image); packetsSent++; } else { int sent; bool imageDone = image.SendPackets(m_client, packetsToSend - packetsSent, out sent); packetsSent += sent; // If the send is complete, destroy any knowledge of this transfer if (imageDone) { RemoveImageFromQueue(image); } } } else { //Add it to the other queue and delete it from the top imagesToReAdd.Add(image); m_priorityQueue.DeleteMax(); packetsSent++; //We tried to send one // UNTODO: This was a limitation of how LLImageManager is currently // written. Undecoded textures should not be going into the priority // queue, because a high priority undecoded texture will clog up the // pipeline for a client //return true; } } //Add all the ones we removed so that we wouldn't block the queue if (imagesToReAdd.Count != 0) { foreach (J2KImage image in imagesToReAdd) { this.AddImageToQueue(image); } } int EndTime = Util.EnvironmentTickCountSubtract(StartTime); IMonitorModule module = m_client.Scene.RequestModuleInterface <IMonitorModule>(); if (module != null) { IImageFrameTimeMonitor monitor = (IImageFrameTimeMonitor)module.GetMonitor(m_client.Scene.RegionInfo.RegionID.ToString(), "Images Frame Time"); monitor.AddImageTime(EndTime); } return(m_priorityQueue.Count > 0); }
/// <summary> /// This loop deals with starting and stoping scripts /// </summary> /// <returns></returns> public bool ScriptChangeQueue() { IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return(true); } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return(true); } ScriptChangeIsRunning = true; object oitems; if (LUQueue.GetNext(out oitems)) { LUStruct[] items = oitems as LUStruct[]; List <LUStruct> NeedsFired = new List <LUStruct>(); foreach (LUStruct item in items) { if (item.Action == LUType.Unload) { //Close item.ID.CloseAndDispose(true); } else if (item.Action == LUType.Load) { try { //Start if (item.ID.Start(false)) { NeedsFired.Add(item); } } catch (Exception ex) { m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: LEAKED COMPILE ERROR: " + ex); } } else if (item.Action == LUType.Reupload) { try { //Start, but don't add to the queue's again if (item.ID.Start(true)) { NeedsFired.Add(item); } } catch (Exception ex) { m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: LEAKED COMPILE ERROR: " + ex); } } } foreach (LUStruct item in NeedsFired) { //Fire the events afterward so that they all start at the same time item.ID.FireEvents(); } threadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us Thread.Sleep(5); return(false); } if (!FiredStartupEvent) { //If we are empty, we are all done with script startup and can tell the region that we are all done if (LUQueue.Count() == 0) { FiredStartupEvent = true; foreach (OpenSim.Region.Framework.Scenes.Scene scene in m_ScriptEngine.Worlds) { scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount, m_ScriptEngine.ScriptErrorMessages); scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string>() { m_ScriptEngine.ScriptFailCount.ToString(), m_ScriptEngine.ScriptErrorMessages }); //Tell that we are done } } } ScriptChangeIsRunning = false; Thread.Sleep(20); if (module != null) { foreach (Scene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), "Script Frame Time"); scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } return(false); }
public void CmdHandlerQueue() { if (m_ScriptEngine.Worlds.Count == 0) { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); return; } Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 1); IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return; } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return; } //Check timers, etc bool didAnything = false; try { didAnything = m_ScriptEngine.DoOneScriptPluginPass(); } catch (Exception ex) { MainConsole.Instance.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex); } if (module != null) { #if (!ISWIN) foreach (IScene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime); if (scriptMonitor != null) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } #else foreach (ITimeMonitor scriptMonitor in m_ScriptEngine.Worlds.Select(scene => (ITimeMonitor) module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime)).Where(scriptMonitor => scriptMonitor != null)) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } #endif } if (didAnything) //If we did something, run us again soon { cmdThreadpool.QueueEvent(CmdHandlerQueue, 2); } else { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); } }
/// <summary> /// This loop deals with starting and stoping scripts /// </summary> /// <returns></returns> public void ScriptChangeQueue() { if (m_ScriptEngine.Scene == null) { return; } IMonitorModule module = m_ScriptEngine.Scene.RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return; } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled || !m_ScriptEngine.Scene.ShouldRunHeartbeat) { return; } ScriptChangeIsRunning = true; object oitems; bool broken = false; for (int i = 0; i < 5; i++) { if (LUQueue.GetNext(out oitems)) { StartScripts(oitems as LUStruct[]); } else { //None left, stop looping broken = true; break; } } if (!broken) { scriptChangeThreadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us, still more to do return; } if (!FiredStartupEvent) { //If we are empty, we are all done with script startup and can tell the region that we are all done if (LUQueue.Count() == 0) { FiredStartupEvent = true; m_ScriptEngine.Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount, m_ScriptEngine.ScriptErrorMessages); m_ScriptEngine.Scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string> { m_ScriptEngine.ScriptFailCount.ToString(), m_ScriptEngine.ScriptErrorMessages }); //Tell that we are done } } ScriptChangeIsRunning = false; Thread.Sleep(20); if (module != null) { IScriptFrameTimeMonitor scriptMonitor = module.GetMonitor <IScriptFrameTimeMonitor>(m_ScriptEngine.Scene); if (scriptMonitor != null) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } }