From d44b7c486a5b51bbfbea2c3d2efd2c9dc0f99d0e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 6 Mar 2012 01:27:30 +0000 Subject: Go back to setting appearance directly in NPCModule.SetAppearance() to fix mantis 5914 The part reverted is from commit 2ebb421. Unfortunately, IAvatarFactoryModule.SetAppearance() does not transfer attachments. I'm not sure how to do this separately, unfortunately I'll need to leave it to Dan :) Regression test added for this case. Mantis ref: http://opensimulator.org/mantis/view.php?id=5914 --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 20 ++++++---- .../World/NPC/Tests/NPCModuleTests.cs | 46 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 2052cdb..2b8379d 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -88,22 +88,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene) { - ScenePresence sp = scene.GetScenePresence(agentId); - if (sp == null || sp.IsChildAgent) + ScenePresence npc = scene.GetScenePresence(agentId); + if (npc == null || npc.IsChildAgent) return false; lock (m_avatars) if (!m_avatars.ContainsKey(agentId)) return false; - // Delete existing sp attachments - scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false); + // Delete existing npc attachments + scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); - // Set new sp appearance. Also sends to clients. - scene.RequestModuleInterface().SetAppearance(sp, new AvatarAppearance(appearance, true)); + // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments + AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); + npc.Appearance = npcAppearance; - // Rez needed sp attachments - scene.AttachmentsModule.RezAttachments(sp); + // Rez needed npc attachments + scene.AttachmentsModule.RezAttachments(npc); + + IAvatarFactoryModule module = scene.RequestModuleInterface(); + module.SendAppearance(npc.UUID); return true; } diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index d507822..36e2d4a 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -139,7 +139,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests } [Test] - public void TestAttachments() + public void TestCreateWithAttachments() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); @@ -179,6 +179,50 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests } [Test] + public void TestLoadAppearance() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + UUID userId = TestHelpers.ParseTail(0x1); + UserAccountHelpers.CreateUserWithInventory(scene, userId); + ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId); + + INPCModule npcModule = scene.RequestModuleInterface(); + UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance); + + // Now add the attachment to the original avatar and use that to load a new appearance + // TODO: Could also run tests loading from a notecard though this isn't much different for our purposes here + UUID attItemId = TestHelpers.ParseTail(0x2); + UUID attAssetId = TestHelpers.ParseTail(0x3); + string attName = "att"; + + UserInventoryHelpers.CreateInventoryItem(scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); + + am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); + + npcModule.SetNPCAppearance(npcId, sp.Appearance, scene); + + ScenePresence npc = scene.GetScenePresence(npcId); + + // Check scene presence status + Assert.That(npc.HasAttachments(), Is.True); + List attachments = npc.GetAttachments(); + Assert.That(attachments.Count, Is.EqualTo(1)); + SceneObjectGroup attSo = attachments[0]; + + // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item + // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC. +// Assert.That(attSo.Name, Is.EqualTo(attName)); + + Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); + Assert.That(attSo.IsAttachment); + Assert.That(attSo.UsesPhysics, Is.False); + Assert.That(attSo.IsTemporary, Is.False); + Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID)); + } + + [Test] public void TestMove() { TestHelpers.InMethod(); -- cgit v1.1 From 1dc03e5c4f76064fc193dab3c8f3e1f3783ec227 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 6 Mar 2012 01:47:43 +0000 Subject: Simplify NPCModuleTests code by putting the NPCModule in an instance variable rather than making each test fetch it seperately. Also rename instance variables in the test to conform to naming standards and for understandability --- .../World/NPC/Tests/NPCModuleTests.cs | 117 ++++++++++----------- 1 file changed, 56 insertions(+), 61 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 36e2d4a..9a7e9e8 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -50,10 +50,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests [TestFixture] public class NPCModuleTests { - private TestScene scene; - private AvatarFactoryModule afm; - private UserManagementModule umm; - private AttachmentsModule am; + private TestScene m_scene; + private AvatarFactoryModule m_afMod; + private UserManagementModule m_umMod; + private AttachmentsModule m_attMod; + private NPCModule m_npcMod; [TestFixtureSetUp] public void FixtureInit() @@ -79,12 +80,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests config.AddConfig("Modules"); config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); - afm = new AvatarFactoryModule(); - umm = new UserManagementModule(); - am = new AttachmentsModule(); + m_afMod = new AvatarFactoryModule(); + m_umMod = new UserManagementModule(); + m_attMod = new AttachmentsModule(); + m_npcMod = new NPCModule(); - scene = SceneHelpers.SetupScene(); - SceneHelpers.SetupSceneModules(scene, config, afm, umm, am, new BasicInventoryAccessModule(), new NPCModule()); + m_scene = SceneHelpers.SetupScene(); + SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); } [Test] @@ -93,7 +95,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); // 8 is the index of the first baked texture in AvatarAppearance @@ -104,18 +106,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell // ScenePresence.SendInitialData() to reset our entire appearance. - scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); + m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); - afm.SetAppearance(sp, originalTe, null); + m_afMod.SetAppearance(sp, originalTe, null); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); - ScenePresence npc = scene.GetScenePresence(npcId); + ScenePresence npc = m_scene.GetScenePresence(npcId); Assert.That(npc, Is.Not.Null); Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId)); - Assert.That(umm.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname))); + Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname))); } [Test] @@ -124,16 +125,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); Vector3 startPos = new Vector3(128, 128, 30); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); - npcModule.DeleteNPC(npcId, scene); + m_npcMod.DeleteNPC(npcId, m_scene); - ScenePresence deletedNpc = scene.GetScenePresence(npcId); + ScenePresence deletedNpc = m_scene.GetScenePresence(npcId); Assert.That(deletedNpc, Is.Null); } @@ -145,21 +145,20 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests // log4net.Config.XmlConfigurator.Configure(); UUID userId = TestHelpers.ParseTail(0x1); - UserAccountHelpers.CreateUserWithInventory(scene, userId); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId); + UserAccountHelpers.CreateUserWithInventory(m_scene, userId); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); UUID attItemId = TestHelpers.ParseTail(0x2); UUID attAssetId = TestHelpers.ParseTail(0x3); string attName = "att"; - UserInventoryHelpers.CreateInventoryItem(scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); + UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); - am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); + m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); - ScenePresence npc = scene.GetScenePresence(npcId); + ScenePresence npc = m_scene.GetScenePresence(npcId); // Check scene presence status Assert.That(npc.HasAttachments(), Is.True); @@ -185,11 +184,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests // log4net.Config.XmlConfigurator.Configure(); UUID userId = TestHelpers.ParseTail(0x1); - UserAccountHelpers.CreateUserWithInventory(scene, userId); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId); + UserAccountHelpers.CreateUserWithInventory(m_scene, userId); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); // Now add the attachment to the original avatar and use that to load a new appearance // TODO: Could also run tests loading from a notecard though this isn't much different for our purposes here @@ -197,13 +195,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests UUID attAssetId = TestHelpers.ParseTail(0x3); string attName = "att"; - UserInventoryHelpers.CreateInventoryItem(scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); + UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); - am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); + m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); - npcModule.SetNPCAppearance(npcId, sp.Appearance, scene); + m_npcMod.SetNPCAppearance(npcId, sp.Appearance, m_scene); - ScenePresence npc = scene.GetScenePresence(npcId); + ScenePresence npc = m_scene.GetScenePresence(npcId); // Check scene presence status Assert.That(npc.HasAttachments(), Is.True); @@ -228,31 +226,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); Vector3 startPos = new Vector3(128, 128, 30); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); - ScenePresence npc = scene.GetScenePresence(npcId); + ScenePresence npc = m_scene.GetScenePresence(npcId); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); // For now, we'll make the scene presence fly to simplify this test, but this needs to change. npc.Flying = true; - scene.Update(); + m_scene.Update(); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); Vector3 targetPos = startPos + new Vector3(0, 10, 0); - npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false); + m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); Assert.That( npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); - scene.Update(); + m_scene.Update(); // We should really check the exact figure. Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); @@ -261,7 +258,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X)); for (int i = 0; i < 10; i++) - scene.Update(); + m_scene.Update(); double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move"); @@ -271,14 +268,14 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests // Try a second movement startPos = npc.AbsolutePosition; targetPos = startPos + new Vector3(10, 0, 0); - npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false); + m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); Assert.That( npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); - scene.Update(); + m_scene.Update(); // We should really check the exact figure. Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X)); @@ -287,7 +284,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); for (int i = 0; i < 10; i++) - scene.Update(); + m_scene.Update(); distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move"); @@ -300,17 +297,16 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); Vector3 startPos = new Vector3(128, 128, 30); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); - ScenePresence npc = scene.GetScenePresence(npcId); - SceneObjectPart part = SceneHelpers.AddSceneObject(scene); + ScenePresence npc = m_scene.GetScenePresence(npcId); + SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); part.SitTargetPosition = new Vector3(0, 0, 1); - npcModule.Sit(npc.UUID, part.UUID, scene); + m_npcMod.Sit(npc.UUID, part.UUID, m_scene); Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId)); Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); @@ -318,7 +314,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests npc.AbsolutePosition, Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); - npcModule.Stand(npc.UUID, scene); + m_npcMod.Stand(npc.UUID, m_scene); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(npc.ParentID, Is.EqualTo(0)); @@ -330,19 +326,18 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // FIXME: To get this to work for now, we are going to place the npc right next to the target so that // the autopilot doesn't trigger Vector3 startPos = new Vector3(1, 1, 1); - INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); + UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); - ScenePresence npc = scene.GetScenePresence(npcId); - SceneObjectPart part = SceneHelpers.AddSceneObject(scene); + ScenePresence npc = m_scene.GetScenePresence(npcId); + SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); - npcModule.Sit(npc.UUID, part.UUID, scene); + m_npcMod.Sit(npc.UUID, part.UUID, m_scene); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); @@ -355,7 +350,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests npc.AbsolutePosition, Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f))); - npcModule.Stand(npc.UUID, scene); + m_npcMod.Stand(npc.UUID, m_scene); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(npc.ParentID, Is.EqualTo(0)); -- cgit v1.1 From 35f2479858df52022bd7eddd1e1e8db02ca4e2b8 Mon Sep 17 00:00:00 2001 From: satguru srivastava Date: Thu, 8 Mar 2012 20:46:22 -0600 Subject: fix for NPC not playing internal animations --- .../Region/OptionalModules/World/NPC/NPCAvatar.cs | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index be0d56e..69c16c7 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -34,13 +34,17 @@ using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.CoreModules.World.Estate; +using log4net; +using System.Reflection; +using System.Xml; namespace OpenSim.Region.OptionalModules.World.NPC { public class NPCAvatar : IClientAPI, INPC { - public bool SenseAsAgent { get; set; } + private static readonly Dictionary m_defaultAnimations = new Dictionary(); + public bool SenseAsAgent { get; set; } private readonly string m_firstname; private readonly string m_lastname; private readonly Vector3 m_startPos; @@ -57,8 +61,16 @@ namespace OpenSim.Region.OptionalModules.World.NPC m_scene = scene; m_ownerID = ownerID; SenseAsAgent = senseAsAgent; + } + static NPCAvatar() + { + InitDefaultAnimations(); + } + + + public IScene Scene { get { return m_scene; } @@ -130,8 +142,31 @@ namespace OpenSim.Region.OptionalModules.World.NPC } + private static void InitDefaultAnimations() + { + using (XmlTextReader reader = new XmlTextReader("data/avataranimations.xml")) + { + XmlDocument doc = new XmlDocument(); + doc.Load(reader); + if (doc.DocumentElement != null) + foreach (XmlNode nod in doc.DocumentElement.ChildNodes) + { + if (nod.Attributes["name"] != null) + { + string name = nod.Attributes["name"].Value.ToLower(); + string id = nod.InnerText; + m_defaultAnimations.Add(name, (UUID)id); + } + } + } + } + public UUID GetDefaultAnimation(string name) { + if (m_defaultAnimations.ContainsKey(name)) + { + return m_defaultAnimations[name]; + } return UUID.Zero; } -- cgit v1.1 From bdc968f1fcd4008e9f2a6099a7d30edb075ca0f1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 9 Mar 2012 23:57:24 +0000 Subject: Factor out common default animations code into SLUtil. LLClientView now makes use of the SLUtil copy via a method rather than each LLClientView loading a separate copy. As per opensim-users mailing list discussion. --- .../Region/OptionalModules/World/NPC/NPCAvatar.cs | 36 ++-------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 69c16c7..24b9e6b 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -42,9 +42,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC { public class NPCAvatar : IClientAPI, INPC { - private static readonly Dictionary m_defaultAnimations = new Dictionary(); - public bool SenseAsAgent { get; set; } + private readonly string m_firstname; private readonly string m_lastname; private readonly Vector3 m_startPos; @@ -61,16 +60,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC m_scene = scene; m_ownerID = ownerID; SenseAsAgent = senseAsAgent; - } - static NPCAvatar() - { - InitDefaultAnimations(); - } - - - public IScene Scene { get { return m_scene; } @@ -142,32 +133,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC } - private static void InitDefaultAnimations() - { - using (XmlTextReader reader = new XmlTextReader("data/avataranimations.xml")) - { - XmlDocument doc = new XmlDocument(); - doc.Load(reader); - if (doc.DocumentElement != null) - foreach (XmlNode nod in doc.DocumentElement.ChildNodes) - { - if (nod.Attributes["name"] != null) - { - string name = nod.Attributes["name"].Value.ToLower(); - string id = nod.InnerText; - m_defaultAnimations.Add(name, (UUID)id); - } - } - } - } - public UUID GetDefaultAnimation(string name) { - if (m_defaultAnimations.ContainsKey(name)) - { - return m_defaultAnimations[name]; - } - return UUID.Zero; + return SLUtil.GetDefaultAvatarAnimation(name); } public Vector3 Position -- cgit v1.1 From 30b2a8c778d02926e038bc62977c4a4c9dbec5ee Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 20 Mar 2012 23:12:21 +0000 Subject: Move frame loop entirely within Scene.Update() for better future performance analysis and stat accuracy. Update() now accepts a frames parameter which can control the number of frames updated. -1 will update until shutdown. The watchdog updating moves above the maintc recalculation for any required sleep since it should be accounted for within the frame. --- .../Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 9a7e9e8..eea0b2e 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -238,7 +238,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests // For now, we'll make the scene presence fly to simplify this test, but this needs to change. npc.Flying = true; - m_scene.Update(); + m_scene.Update(1); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); Vector3 targetPos = startPos + new Vector3(0, 10, 0); @@ -249,7 +249,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That( npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); - m_scene.Update(); + m_scene.Update(1); // We should really check the exact figure. Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); @@ -257,8 +257,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X)); - for (int i = 0; i < 10; i++) - m_scene.Update(); + m_scene.Update(10); double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move"); @@ -275,7 +274,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That( npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); - m_scene.Update(); + m_scene.Update(1); // We should really check the exact figure. Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X)); @@ -283,8 +282,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y)); Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); - for (int i = 0; i < 10; i++) - m_scene.Update(); + m_scene.Update(10); distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move"); -- cgit v1.1 From 1a8769e6eff0eab750a528f27d127637edbd292b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 21 Mar 2012 23:57:39 +0000 Subject: Instead of loading default avatar animations in both SLUtil and AvatarAnimations, load just in AvatarAnimations instead. This lets us remove the dependency of OpenSim.Framework.dll on data/avataranimations.xml, which is not necessary for ROBUST. This commit also takes care of the odd situation where animations are stored and used internally with uppercase names (e.g. "STAND") but scripts refer to them with lowercase names (e.g. "sit"). --- OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 24b9e6b..16ec34f 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -133,11 +133,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC } - public UUID GetDefaultAnimation(string name) - { - return SLUtil.GetDefaultAvatarAnimation(name); - } - public Vector3 Position { get { return m_scene.Entities[m_uuid].AbsolutePosition; } -- cgit v1.1