diff options
author | root | 2011-07-05 04:01:59 +0100 |
---|---|---|
committer | root | 2011-07-05 04:01:59 +0100 |
commit | 47cf9c8fe060af89cc14817dc762bcbfef956d5e (patch) | |
tree | 56b21e617bbb4ce3a613780c81178de41ff062d3 /OpenSim/Region/OptionalModules | |
parent | Merge branch 'careminster-presence-refactor' of ssh://3dhosting.de/var/git/ca... (diff) | |
parent | Add TestClearCache() (diff) | |
download | opensim-SC_OLD-47cf9c8fe060af89cc14817dc762bcbfef956d5e.zip opensim-SC_OLD-47cf9c8fe060af89cc14817dc762bcbfef956d5e.tar.gz opensim-SC_OLD-47cf9c8fe060af89cc14817dc762bcbfef956d5e.tar.bz2 opensim-SC_OLD-47cf9c8fe060af89cc14817dc762bcbfef956d5e.tar.xz |
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 142 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | 71 |
2 files changed, 109 insertions, 104 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 48d236f..3cdd06d 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -34,7 +34,6 @@ using Nini.Config; | |||
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Region.Framework.Interfaces; | 35 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
37 | using OpenSim.Region.CoreModules.Avatar.NPC; | ||
38 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
39 | using Timer=System.Timers.Timer; | 38 | using Timer=System.Timers.Timer; |
40 | using OpenSim.Services.Interfaces; | 39 | using OpenSim.Services.Interfaces; |
@@ -47,31 +46,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
47 | 46 | ||
48 | // private const bool m_enabled = false; | 47 | // private const bool m_enabled = false; |
49 | 48 | ||
50 | private Mutex m_createMutex; | ||
51 | private Timer m_timer; | ||
52 | |||
53 | private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); | 49 | private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); |
54 | private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); | 50 | private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); |
55 | 51 | ||
56 | // Timer vars. | ||
57 | private bool p_inUse = false; | ||
58 | private readonly object p_lock = new object(); | ||
59 | // Private Temporary Variables. | ||
60 | private string p_firstname; | ||
61 | private string p_lastname; | ||
62 | private Vector3 p_position; | ||
63 | private Scene p_scene; | ||
64 | private UUID p_cloneAppearanceFrom; | ||
65 | private UUID p_returnUuid; | ||
66 | |||
67 | public void Initialise(Scene scene, IConfigSource source) | 52 | public void Initialise(Scene scene, IConfigSource source) |
68 | { | 53 | { |
69 | m_createMutex = new Mutex(false); | ||
70 | |||
71 | m_timer = new Timer(500); | ||
72 | m_timer.Elapsed += m_timer_Elapsed; | ||
73 | m_timer.Start(); | ||
74 | |||
75 | scene.RegisterModuleInterface<INPCModule>(this); | 54 | scene.RegisterModuleInterface<INPCModule>(this); |
76 | } | 55 | } |
77 | 56 | ||
@@ -90,35 +69,53 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
90 | return new AvatarAppearance(); | 69 | return new AvatarAppearance(); |
91 | } | 70 | } |
92 | 71 | ||
93 | public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) | 72 | public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom) |
94 | { | 73 | { |
74 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); | ||
75 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); | ||
76 | |||
95 | m_log.DebugFormat( | 77 | m_log.DebugFormat( |
96 | "[NPC MODULE]: Queueing request to create NPC {0} {1} at {2} in {3} cloning appearance of {4}", | 78 | "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}", |
97 | firstname, lastname, position, scene.RegionInfo.RegionName, cloneAppearanceFrom); | 79 | firstname, lastname, npcAvatar.AgentId, position, scene.RegionInfo.RegionName); |
80 | |||
81 | AgentCircuitData acd = new AgentCircuitData(); | ||
82 | acd.AgentID = npcAvatar.AgentId; | ||
83 | acd.firstname = firstname; | ||
84 | acd.lastname = lastname; | ||
85 | acd.ServiceURLs = new Dictionary<string, object>(); | ||
98 | 86 | ||
99 | // Block. | 87 | AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene); |
100 | m_createMutex.WaitOne(); | 88 | AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); |
89 | acd.Appearance = npcAppearance; | ||
101 | 90 | ||
102 | // Copy Temp Variables for Timer to pick up. | 91 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); |
103 | lock (p_lock) | 92 | scene.AddNewClient(npcAvatar); |
93 | |||
94 | ScenePresence sp; | ||
95 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | ||
104 | { | 96 | { |
105 | p_firstname = firstname; | 97 | m_log.DebugFormat( |
106 | p_lastname = lastname; | 98 | "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); |
107 | p_position = position; | 99 | |
108 | p_scene = scene; | 100 | // Shouldn't call this - temporary. |
109 | p_cloneAppearanceFrom = cloneAppearanceFrom; | 101 | sp.CompleteMovement(npcAvatar); |
110 | p_inUse = true; | ||
111 | p_returnUuid = UUID.Zero; | ||
112 | } | ||
113 | 102 | ||
114 | while (p_returnUuid == UUID.Zero) | 103 | // sp.SendAppearanceToAllOtherAgents(); |
104 | // | ||
105 | // // Send animations back to the avatar as well | ||
106 | // sp.Animator.SendAnimPack(); | ||
107 | } | ||
108 | else | ||
115 | { | 109 | { |
116 | Thread.Sleep(250); | 110 | m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); |
117 | } | 111 | } |
118 | 112 | ||
119 | m_createMutex.ReleaseMutex(); | 113 | lock (m_avatars) |
114 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | ||
120 | 115 | ||
121 | return p_returnUuid; | 116 | m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId); |
117 | |||
118 | return npcAvatar.AgentId; | ||
122 | } | 119 | } |
123 | 120 | ||
124 | public void Autopilot(UUID agentID, Scene scene, Vector3 pos) | 121 | public void Autopilot(UUID agentID, Scene scene, Vector3 pos) |
@@ -157,69 +154,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
157 | } | 154 | } |
158 | } | 155 | } |
159 | 156 | ||
160 | void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) | ||
161 | { | ||
162 | try | ||
163 | { | ||
164 | lock (p_lock) | ||
165 | { | ||
166 | if (p_inUse) | ||
167 | { | ||
168 | p_inUse = false; | ||
169 | |||
170 | NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene); | ||
171 | npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue); | ||
172 | |||
173 | m_log.DebugFormat( | ||
174 | "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}", | ||
175 | p_firstname, p_lastname, npcAvatar.AgentId, p_position, p_scene.RegionInfo.RegionName); | ||
176 | |||
177 | AgentCircuitData acd = new AgentCircuitData(); | ||
178 | acd.AgentID = npcAvatar.AgentId; | ||
179 | acd.firstname = p_firstname; | ||
180 | acd.lastname = p_lastname; | ||
181 | acd.ServiceURLs = new Dictionary<string, object>(); | ||
182 | |||
183 | AvatarAppearance originalAppearance = GetAppearance(p_cloneAppearanceFrom, p_scene); | ||
184 | AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); | ||
185 | acd.Appearance = npcAppearance; | ||
186 | |||
187 | p_scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); | ||
188 | p_scene.AddNewClient(npcAvatar); | ||
189 | |||
190 | ScenePresence sp; | ||
191 | if (p_scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | ||
192 | { | ||
193 | m_log.DebugFormat( | ||
194 | "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); | ||
195 | |||
196 | // Shouldn't call this - temporary. | ||
197 | sp.CompleteMovement(npcAvatar); | ||
198 | |||
199 | // sp.SendAppearanceToAllOtherAgents(); | ||
200 | // | ||
201 | // // Send animations back to the avatar as well | ||
202 | // sp.Animator.SendAnimPack(); | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); | ||
207 | } | ||
208 | |||
209 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | ||
210 | |||
211 | p_returnUuid = npcAvatar.AgentId; | ||
212 | |||
213 | m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", p_returnUuid); | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | catch (Exception ex) | ||
218 | { | ||
219 | m_log.ErrorFormat("[NPC MODULE]: NPC creation failed with exception {0} {1}", ex.Message, ex.StackTrace); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | public void PostInitialise() | 157 | public void PostInitialise() |
224 | { | 158 | { |
225 | } | 159 | } |
@@ -238,4 +172,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
238 | get { return true; } | 172 | get { return true; } |
239 | } | 173 | } |
240 | } | 174 | } |
241 | } | 175 | } \ No newline at end of file |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs new file mode 100644 index 0000000..899e721 --- /dev/null +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using NUnit.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.AvatarService; | ||
39 | using OpenSim.Tests.Common; | ||
40 | using OpenSim.Tests.Common.Mock; | ||
41 | |||
42 | namespace OpenSim.Region.OptionalModules.World.NPC.Tests | ||
43 | { | ||
44 | [TestFixture] | ||
45 | public class NPCModuleTests | ||
46 | { | ||
47 | [Test] | ||
48 | public void TestCreate() | ||
49 | { | ||
50 | TestHelper.InMethod(); | ||
51 | // log4net.Config.XmlConfigurator.Configure(); | ||
52 | |||
53 | IConfigSource config = new IniConfigSource(); | ||
54 | |||
55 | config.AddConfig("Modules"); | ||
56 | config.Configs["Modules"].Set("AvatarServices", "LocalAvatarServicesConnector"); | ||
57 | config.AddConfig("AvatarService"); | ||
58 | config.Configs["AvatarService"].Set("LocalServiceModule", "OpenSim.Services.AvatarService.dll:AvatarService"); | ||
59 | config.Configs["AvatarService"].Set("StorageProvider", "OpenSim.Data.Null.dll"); | ||
60 | |||
61 | TestScene scene = SceneSetupHelpers.SetupScene(); | ||
62 | SceneSetupHelpers.SetupSceneModules(scene, config, new NPCModule(), new LocalAvatarServicesConnector()); | ||
63 | |||
64 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | ||
65 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, UUID.Zero); | ||
66 | |||
67 | ScenePresence npc = scene.GetScenePresence(npcId); | ||
68 | Assert.That(npc, Is.Not.Null); | ||
69 | } | ||
70 | } | ||
71 | } \ No newline at end of file | ||