From 9c6ba8d18f4b3c4b457240f251612691cb271d90 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 8 Feb 2012 13:04:23 +0100 Subject: Push more NPC stuff into threads --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 37 +++++++++++++--------- .../Shared/Api/Implementation/OSSL_Api.cs | 26 ++++++++++----- 2 files changed, 40 insertions(+), 23 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 6a48b89..3ea7352 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -140,26 +140,33 @@ namespace OpenSim.Region.OptionalModules.World.NPC // acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); // } - lock (m_avatars) - { - scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); - scene.AddNewClient(npcAvatar, PresenceType.Npc); + ManualResetEvent ev = new ManualResetEvent(false); - ScenePresence sp; - if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) + Util.FireAndForget(delegate(object x) { + lock (m_avatars) { - m_log.DebugFormat( - "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); + scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); + scene.AddNewClient(npcAvatar, PresenceType.Npc); - sp.CompleteMovement(npcAvatar, false); - } - else - { - m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); + ScenePresence sp; + if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) + { + m_log.DebugFormat( + "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); + + sp.CompleteMovement(npcAvatar, false); + } + else + { + m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); + } + + m_avatars.Add(npcAvatar.AgentId, npcAvatar); } + ev.Set(); + }); - m_avatars.Add(npcAvatar.AgentId, npcAvatar); - } + ev.WaitOne(); m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 614872e..c83df4e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2584,18 +2584,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); m_host.AddScriptLPS(1); + ManualResetEvent ev = new ManualResetEvent(false); + Util.FireAndForget(delegate(object x) { - INPCModule module = World.RequestModuleInterface(); - if (module != null) + try { - UUID npcId = new UUID(npc.m_string); + INPCModule module = World.RequestModuleInterface(); + if (module != null) + { + UUID npcId = new UUID(npc.m_string); - if (!module.CheckPermissions(npcId, m_host.OwnerID)) - return; + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; - module.DeleteNPC(npcId, World); - }); - } + module.DeleteNPC(npcId, World); + } + } + finally + { + ev.Set(); + } + }); + ev.WaitOne(); } public void osNpcPlayAnimation(LSL_Key npc, string animation) -- cgit v1.1