aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAdam Frisby2009-08-21 15:12:50 +1000
committerAdam Frisby2009-08-21 15:12:50 +1000
commitf7c5eca978717c0adc16ad28b30b02678ba75892 (patch)
treee304f0d8dd1dd2383017b2807e26057ea0b7fc47
parent* Make cache, actually cache. (diff)
downloadopensim-SC_OLD-f7c5eca978717c0adc16ad28b30b02678ba75892.zip
opensim-SC_OLD-f7c5eca978717c0adc16ad28b30b02678ba75892.tar.gz
opensim-SC_OLD-f7c5eca978717c0adc16ad28b30b02678ba75892.tar.bz2
opensim-SC_OLD-f7c5eca978717c0adc16ad28b30b02678ba75892.tar.xz
* Moves NPC Creation across AppDomains to prevent a major perfomance issue.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs86
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs2
2 files changed, 70 insertions, 18 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index eeb74d9..c710723 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -26,12 +26,14 @@
26 */ 26 */
27 27
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Threading;
29using OpenMetaverse; 30using OpenMetaverse;
30using Nini.Config; 31using Nini.Config;
31using OpenSim.Region.Framework.Interfaces; 32using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
33using OpenSim.Region.CoreModules.Avatar.NPC; 34using OpenSim.Region.CoreModules.Avatar.NPC;
34using OpenSim.Framework; 35using OpenSim.Framework;
36using Timer=System.Timers.Timer;
35 37
36namespace OpenSim.Region.OptionalModules.World.NPC 38namespace OpenSim.Region.OptionalModules.World.NPC
37{ 39{
@@ -39,10 +41,25 @@ namespace OpenSim.Region.OptionalModules.World.NPC
39 { 41 {
40 // private const bool m_enabled = false; 42 // private const bool m_enabled = false;
41 43
44 private Mutex m_createMutex = new Mutex(false);
45
46 private Timer m_timer = new Timer(500);
47
42 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 48 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
43 49
44 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); 50 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
45 51
52 // Timer vars.
53 private bool p_inUse = false;
54 private readonly object p_lock = new object();
55 // Private Temporary Variables.
56 private string p_firstname;
57 private string p_lastname;
58 private Vector3 p_position;
59 private Scene p_scene;
60 private UUID p_cloneAppearanceFrom;
61 private UUID p_returnUuid;
62
46 private AvatarAppearance GetAppearance(UUID target, Scene scene) 63 private AvatarAppearance GetAppearance(UUID target, Scene scene)
47 { 64 {
48 if (m_appearanceCache.ContainsKey(target)) 65 if (m_appearanceCache.ContainsKey(target))
@@ -57,29 +74,23 @@ namespace OpenSim.Region.OptionalModules.World.NPC
57 74
58 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) 75 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom)
59 { 76 {
60 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); 77 // Block.
61 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue); 78 m_createMutex.WaitOne();
62
63 scene.ClientManager.Add(npcAvatar.CircuitCode, npcAvatar);
64 scene.AddNewClient(npcAvatar);
65 79
66 ScenePresence sp; 80 // Copy Temp Variables for Timer to pick up.
67 if(scene.TryGetAvatar(npcAvatar.AgentId, out sp)) 81 lock (p_lock)
68 { 82 {
69 AvatarAppearance x = GetAppearance(cloneAppearanceFrom, scene); 83 p_firstname = firstname;
70 84 p_lastname = lastname;
71 List<byte> wearbyte = new List<byte>(); 85 p_position = position;
72 for (int i = 0; i < x.VisualParams.Length; i++) 86 p_scene = scene;
73 { 87 p_cloneAppearanceFrom = cloneAppearanceFrom;
74 wearbyte.Add(x.VisualParams[i]); 88 p_inUse = true;
75 }
76
77 sp.SetAppearance(x.Texture.GetBytes(), wearbyte);
78 } 89 }
79 90
80 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 91 m_createMutex.ReleaseMutex();
81 92
82 return npcAvatar.AgentId; 93 return p_returnUuid;
83 } 94 }
84 95
85 public void Autopilot(UUID agentID, Scene scene, Vector3 pos) 96 public void Autopilot(UUID agentID, Scene scene, Vector3 pos)
@@ -116,6 +127,45 @@ namespace OpenSim.Region.OptionalModules.World.NPC
116 public void Initialise(Scene scene, IConfigSource source) 127 public void Initialise(Scene scene, IConfigSource source)
117 { 128 {
118 scene.RegisterModuleInterface<INPCModule>(this); 129 scene.RegisterModuleInterface<INPCModule>(this);
130
131 m_timer.Elapsed += m_timer_Elapsed;
132 m_timer.Start();
133 }
134
135 void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
136 {
137 lock (p_lock)
138 {
139 if (p_inUse)
140 {
141 p_inUse = false;
142
143
144 NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene);
145 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue);
146
147 p_scene.ClientManager.Add(npcAvatar.CircuitCode, npcAvatar);
148 p_scene.AddNewClient(npcAvatar);
149
150 ScenePresence sp;
151 if (p_scene.TryGetAvatar(npcAvatar.AgentId, out sp))
152 {
153 AvatarAppearance x = GetAppearance(p_cloneAppearanceFrom, p_scene);
154
155 List<byte> wearbyte = new List<byte>();
156 for (int i = 0; i < x.VisualParams.Length; i++)
157 {
158 wearbyte.Add(x.VisualParams[i]);
159 }
160
161 sp.SetAppearance(x.Texture.GetBytes(), wearbyte);
162 }
163
164 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
165
166 p_returnUuid = npcAvatar.AgentId;
167 }
168 }
119 } 169 }
120 170
121 public void PostInitialise() 171 public void PostInitialise()
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index fcfa9fc..6190349 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
31using System.Runtime.Remoting.Lifetime; 31using System.Runtime.Remoting.Lifetime;
32using System.Text; 32using System.Text;
33using System.Net; 33using System.Net;
34using System.Threading;
34using OpenMetaverse; 35using OpenMetaverse;
35using Nini.Config; 36using Nini.Config;
36using OpenSim; 37using OpenSim;
@@ -1766,6 +1767,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1766 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) 1767 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
1767 { 1768 {
1768 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 1769 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
1770 //QueueUserWorkItem
1769 1771
1770 INPCModule module = World.RequestModuleInterface<INPCModule>(); 1772 INPCModule module = World.RequestModuleInterface<INPCModule>();
1771 if (module != null) 1773 if (module != null)