/// <summary> /// Adding a New Client and Create a Presence for it. /// Called by the LLClientView when the UseCircuitCode packet comes in /// Used by NPCs to add themselves to the Scene /// </summary> /// <param name="client"></param> /// <param name="completed"></param> public void AddNewClient(IClientAPI client, BlankHandler completed) { AddAsyncEvent(delegate { try { AgentCircuitData aCircuit = AuthenticateHandler.GetAgentCircuitData(client.AgentId); m_clientManager.Add(client); //Create the scenepresence IScenePresence sp = CreateAndAddChildScenePresence(client); sp.IsChildAgent = aCircuit.IsChildAgent; //Trigger events m_eventManager.TriggerOnNewPresence(sp); if (GetScenePresence(client.AgentId) != null) { EventManager.TriggerOnNewClient(client); if ((aCircuit.TeleportFlags & (uint)TeleportFlags.ViaLogin) != 0) { EventManager.TriggerOnClientLogin(client); } } //Add the client to login stats ILoginMonitor monitor3 = RequestModuleInterface <IMonitorModule>().GetMonitor <ILoginMonitor>(null); if ((aCircuit.TeleportFlags & (uint)TeleportFlags.ViaLogin) != 0 && monitor3 != null) { monitor3.AddSuccessfulLogin(); } if (sp.IsChildAgent) { //If we're a child, trigger this so that we get updated in the modules sp.TriggerSignificantClientMovement(); } if (completed != null) { completed(); } } catch (Exception ex) { MainConsole.Instance.Warn("[Scene]: Error in AddNewClient: " + ex); } }); }
/// <summary> /// Adding a New Client and Create a Presence for it. /// Called by the LLClientView when the UseCircuitCode packet comes in /// Used by NPCs to add themselves to the Scene /// </summary> /// <param name="client"></param> /// <param name="completed"></param> public void AddNewClient(IClientAPI client, BlankHandler completed) { AddAsyncEvent(delegate { try { AgentCircuitData aCircuit = AuthenticateHandler.GetAgentCircuitData(client.AgentId); m_clientManager.Add(client); //Create the scenepresence IScenePresence sp = CreateAndAddChildScenePresence(client); sp.IsChildAgent = aCircuit.IsChildAgent; //Trigger events m_eventManager.TriggerOnNewPresence(sp); if (GetScenePresence(client.AgentId) != null) { EventManager.TriggerOnNewClient(client); if ((aCircuit.TeleportFlags & (uint)TeleportFlags.ViaLogin) != 0) EventManager.TriggerOnClientLogin(client); } //Add the client to login stats ILoginMonitor monitor3 = RequestModuleInterface<IMonitorModule>().GetMonitor<ILoginMonitor>(null); if ((aCircuit.TeleportFlags & (uint)TeleportFlags.ViaLogin) != 0 && monitor3 != null) monitor3.AddSuccessfulLogin(); if (sp.IsChildAgent) //If we're a child, trigger this so that we get updated in the modules sp.TriggerSignificantClientMovement(); if (completed != null) completed(); } catch (Exception ex) { MainConsole.Instance.Warn("[Scene]: Error in AddNewClient: " + ex); } }); }
/// <summary> /// Adding a New Client and Create a Presence for it. /// Called by the LLClientView when the UseCircuitCode packet comes in /// Used by NPCs to add themselves to the Scene /// </summary> /// <param name="client"></param> /// <param name="completed"></param> public void AddNewClient(IClientAPI client, BlankHandler completed) { lock (m_events) m_events.Add(delegate { try { System.Net.IPEndPoint ep = (System.Net.IPEndPoint)client.GetClientEP(); AgentCircuitData aCircuit = AuthenticateHandler.AuthenticateSession(client.SessionId, client.AgentId, client.CircuitCode, ep); if (aCircuit == null) // no good, didn't pass NewUserConnection successfully { completed(); return; } m_clientManager.Add(client); //Create the scenepresence IScenePresence sp = CreateAndAddChildScenePresence(client); sp.IsChildAgent = aCircuit.child; sp.DrawDistance = aCircuit.DrawDistance; //Trigger events m_eventManager.TriggerOnNewPresence(sp); //Make sure the appearanace is updated IAvatarAppearanceModule appearance = sp.RequestModuleInterface <IAvatarAppearanceModule>(); if (appearance != null) { appearance.Appearance = aCircuit.Appearance ?? sp.Scene.AvatarService.GetAppearance(sp.UUID); if (appearance.Appearance == null) { MainConsole.Instance.Error("[AsyncScene]: NO AVATAR APPEARANCE FOUND FOR " + sp.Name); appearance.Appearance = new AvatarAppearance(sp.UUID); } } if (GetScenePresence(client.AgentId) != null) { EventManager.TriggerOnNewClient(client); if ((aCircuit.teleportFlags & (uint)TeleportFlags.ViaLogin) != 0) { EventManager.TriggerOnClientLogin(client); } } //Add the client to login stats ILoginMonitor monitor3 = (ILoginMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor("", MonitorModuleHelper.LoginMonitor); if ((aCircuit.teleportFlags & (uint)TeleportFlags.ViaLogin) != 0 && monitor3 != null) { monitor3.AddSuccessfulLogin(); } if (sp.IsChildAgent)//If we're a child, trigger this so that we get updated in the modules { sp.TriggerSignificantClientMovement(); } completed(); } catch (Exception ex) { MainConsole.Instance.Warn("[Scene]: Error in AddNewClient: " + ex); } }); }
private bool Update() { ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule> ().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); ISetMonitor lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); ITimeMonitor otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++m_frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); if (m_frame % m_update_coarse_locations == 0) { List <Vector3> coarseLocations; List <UUID> avatarUUIDs; if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60)) { // Send coarse locations to clients foreach (IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } } if (m_frame % m_update_entities == 0) { m_sceneGraph.UpdateEntities(); } BlankHandler[] events; lock (m_events) { events = new BlankHandler[m_events.Count]; m_events.CopyTo(events); m_events.Clear(); } foreach (BlankHandler h in events) { try { h(); } catch { } } if (m_frame % m_update_events == 0) { try { m_sceneGraph.PhysicsScene.UpdatesLoop(); } catch { } } if (m_frame % m_update_events == 0) { m_eventManager.TriggerOnFrame(); } //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); if (simFrameMonitor != null) { simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); } else { simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); } } catch (Exception e) { MainConsole.Instance.Error("[REGION]: Failed with exception " + e + " in region: " + RegionInfo.RegionName); return(true); } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); //Beginning + (time between beginning and end) = end int MonitorEndFrameTime = BeginningFrameTime + maintc; int getSleepTime = GetHeartbeatSleepTime(maintc, false); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } if (sleepFrameMonitor != null) { sleepFrameMonitor.AddTime(maintc); totalFrameMonitor.AddFrameTime(MonitorEndFrameTime); } } }
/// <summary> /// Adding a New Client and Create a Presence for it. /// Called by the LLClientView when the UseCircuitCode packet comes in /// Used by NPCs to add themselves to the Scene /// </summary> /// <param name="client"></param> public void AddNewClient (IClientAPI client, BlankHandler completed) { lock(m_events) m_events.Add(delegate() { try { System.Net.IPEndPoint ep = (System.Net.IPEndPoint)client.GetClientEP(); AgentCircuitData aCircuit = AuthenticateHandler.AuthenticateSession(client.SessionId, client.AgentId, client.CircuitCode, ep); if(aCircuit == null) // no good, didn't pass NewUserConnection successfully { completed(); return; } m_clientManager.Add(client); //Create the scenepresence IScenePresence sp = CreateAndAddChildScenePresence(client); sp.IsChildAgent = aCircuit.child; sp.DrawDistance = aCircuit.DrawDistance; //Trigger events m_eventManager.TriggerOnNewPresence(sp); //Make sure the appearanace is updated IAvatarAppearanceModule appearance = sp.RequestModuleInterface<IAvatarAppearanceModule>(); if (appearance != null) { if (aCircuit != null && aCircuit.Appearance != null) appearance.Appearance = aCircuit.Appearance; else appearance.Appearance = sp.Scene.AvatarService.GetAppearance(sp.UUID); if (appearance.Appearance == null) { m_log.Error("[AsyncScene]: NO AVATAR APPEARANCE FOUND FOR " + sp.Name); appearance.Appearance = new AvatarAppearance(sp.UUID); } } if(GetScenePresence(client.AgentId) != null) { EventManager.TriggerOnNewClient(client); if((aCircuit.teleportFlags & (uint)TeleportFlags.ViaLogin) != 0) EventManager.TriggerOnClientLogin(client); } //Add the client to login stats ILoginMonitor monitor = (ILoginMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor("", MonitorModuleHelper.LoginMonitor); if((aCircuit.teleportFlags & (uint)TeleportFlags.ViaLogin) != 0 && monitor != null) monitor.AddSuccessfulLogin(); if(sp.IsChildAgent)//If we're a child, trigger this so that we get updated in the modules sp.TriggerSignificantClientMovement(); completed(); } catch(Exception ex) { m_log.Warn("[Scene]: Error in AddNewClient: " + ex.ToString()); } }); }
private bool Update() { ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface<IMonitorModule> ().GetMonitor (RegionInfo.RegionID.ToString (), MonitorModuleHelper.TotalFrameTime); ISetMonitor lastFrameMonitor = (ISetMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); ITimeMonitor otherFrameMonitor = (ITimeMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves return false; int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++m_frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); if(m_frame % m_update_coarse_locations == 0) { List<Vector3> coarseLocations; List<UUID> avatarUUIDs; if(SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60)) { // Send coarse locations to clients foreach(IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } } if(m_frame % m_update_entities == 0) m_sceneGraph.UpdateEntities(); BlankHandler[] events; lock(m_events) { events = new BlankHandler[m_events.Count]; m_events.CopyTo(events); m_events.Clear(); } foreach(BlankHandler h in events) try { h(); } catch { } if(m_frame % m_update_events == 0) { try { m_sceneGraph.PhysicsScene.UpdatesLoop(); } catch { } } if (m_frame % m_update_events == 0) m_eventManager.TriggerOnFrame(); //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); if(simFrameMonitor != null) { simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); } else { simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); lastFrameMonitor = (ISetMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); otherFrameMonitor = (ITimeMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface<IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); } } catch (Exception e) { m_log.Error("[REGION]: Failed with exception " + e.ToString() + " 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); } } }