From 74ef1ed36f234d93aa3d58b1602344bcb3e00d6e Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 19:36:39 +0100 Subject: [PATCH 01/12] add prim item and test asset save in save oar unit test --- .../Serialization/TarArchiveWriter.cs | 7 +++- .../World/Archiver/AssetsRequest.cs | 2 +- .../World/Archiver/Tests/ArchiverTests.cs | 32 +++++++++++++++++-- .../Scenes/Tests/UuidGathererTests.cs | 3 +- .../Region/Framework/Scenes/UuidGatherer.cs | 8 +++-- OpenSim/Tests/Common/Setup/AssetHelpers.cs | 14 ++++++-- 6 files changed, 55 insertions(+), 11 deletions(-) diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index 0bd639ff3a..fca909f2d8 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -28,7 +28,9 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text; +using log4net; namespace OpenSim.Framework.Serialization { @@ -37,7 +39,7 @@ namespace OpenSim.Framework.Serialization /// public class TarArchiveWriter { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); @@ -148,6 +150,9 @@ namespace OpenSim.Framework.Serialization /// protected void WriteEntry(string filePath, byte[] data, char fileType) { +// m_log.DebugFormat( +// "[TAR ARCHIVE WRITER]: Data for {0} is {1} bytes", filePath, (null == data ? "null" : data.Length.ToString())); + byte[] header = new byte[512]; // file path field (100) diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs index 4215f97343..a1451ce705 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs @@ -239,7 +239,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver if (asset != null) { -// m_log.DebugFormat("[ARCHIVER]: Recording asset {0} as found", id); +// m_log.DebugFormat("[ARCHIVER]: Writing asset {0}", id); m_foundAssetUuids.Add(asset.FullID); m_assetsArchiver.WriteAsset(asset); } diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index 624dc22044..f3e5458dce 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs @@ -33,8 +33,8 @@ using log4net.Config; using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using OpenMetaverse; +using OpenMetaverse.Assets; using OpenSim.Framework; - using OpenSim.Framework.Serialization; using OpenSim.Framework.Serialization.External; using OpenSim.Region.CoreModules.World.Serialiser; @@ -44,6 +44,9 @@ using OpenSim.Region.Framework.Scenes.Serialization; using OpenSim.Tests.Common; using OpenSim.Tests.Common.Mock; using OpenSim.Tests.Common.Setup; +using ArchiveConstants = OpenSim.Framework.Serialization.ArchiveConstants; +using TarArchiveReader = OpenSim.Framework.Serialization.TarArchiveReader; +using TarArchiveWriter = OpenSim.Framework.Serialization.TarArchiveWriter; namespace OpenSim.Region.CoreModules.World.Archiver.Tests { @@ -55,6 +58,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests protected TestScene m_scene; protected ArchiverModule m_archiverModule; + + protected TaskInventoryItem m_soundItem; [SetUp] public void SetUp() @@ -127,7 +132,19 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests m_scene.AddNewSceneObject(new SceneObjectGroup(part1), false); SceneObjectPart part2 = CreateSceneObjectPart2(); - m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false); + + AssetNotecard nc = new AssetNotecard("Hello World!"); + UUID ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000"); + UUID ncItemUuid = new UUID("00000000-0000-0000-1100-000000000000"); + AssetBase ncAsset + = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero); + m_scene.AssetService.Store(ncAsset); + SceneObjectGroup sog2 = new SceneObjectGroup(part2); + TaskInventoryItem ncItem + = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid }; + part2.Inventory.AddInventoryItem(ncItem, true); + + m_scene.AddNewSceneObject(sog2, false); MemoryStream archiveWriteStream = new MemoryStream(); m_scene.EventManager.OnOarFileSaved += SaveCompleted; @@ -151,8 +168,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests TarArchiveReader tar = new TarArchiveReader(archiveReadStream); bool gotControlFile = false; + bool gotNcAssetFile = false; bool gotObject1File = false; bool gotObject2File = false; + + string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt"); string expectedObject1FileName = string.Format( "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", part1.Name, @@ -173,6 +193,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests { gotControlFile = true; } + else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) + { + string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length); + + Assert.That(fileName, Is.EqualTo(expectedNcAssetFileName)); + gotNcAssetFile = true; + } else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) { string fileName = filePath.Remove(0, ArchiveConstants.OBJECTS_PATH.Length); @@ -191,6 +218,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests } Assert.That(gotControlFile, Is.True, "No control file in archive"); + Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive"); Assert.That(gotObject1File, Is.True, "No object1 file in archive"); Assert.That(gotObject2File, Is.True, "No object2 file in archive"); diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs index 8b80ebe3dc..5e6124b4f9 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs @@ -58,7 +58,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelper.InMethod(); UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); - AssetBase corruptAsset = AssetHelpers.CreateAsset(corruptAssetUuid, "CORRUPT ASSET", UUID.Zero); + AssetBase corruptAsset + = AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, "CORRUPT ASSET", UUID.Zero); m_assetService.Store(corruptAsset); IDictionary foundAssetUuids = new Dictionary(); diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 0ec3cc3c73..e3965ce978 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -123,8 +123,8 @@ namespace OpenSim.Region.Framework.Scenes foreach (SceneObjectPart part in sceneObject.GetParts()) { - //m_log.DebugFormat( - // "[ARCHIVER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID); +// m_log.DebugFormat( +// "[ARCHIVER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID); try { @@ -155,7 +155,9 @@ namespace OpenSim.Region.Framework.Scenes // Now analyze this prim's inventory items to preserve all the uuids that they reference foreach (TaskInventoryItem tii in taskDictionary.Values) { - //m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type); +// m_log.DebugFormat( +// "[ARCHIVER]: Analysing item {0} asset type {1} in {2} {3}", +// tii.Name, tii.Type, part.Name, part.UUID); if (!assetUuids.ContainsKey(tii.AssetID)) GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); diff --git a/OpenSim/Tests/Common/Setup/AssetHelpers.cs b/OpenSim/Tests/Common/Setup/AssetHelpers.cs index 1fc3cb5455..1beafcf764 100644 --- a/OpenSim/Tests/Common/Setup/AssetHelpers.cs +++ b/OpenSim/Tests/Common/Setup/AssetHelpers.cs @@ -38,12 +38,20 @@ namespace OpenSim.Tests.Common /// /// Create an asset from the given data /// - public static AssetBase CreateAsset(UUID assetUuid, string data, UUID creatorID) + public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID) { - AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)AssetType.Object, creatorID.ToString()); - asset.Data = Encoding.ASCII.GetBytes(data); + AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString()); + asset.Data = data; return asset; } + + /// + /// Create an asset from the given data + /// + public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string data, UUID creatorID) + { + return CreateAsset(assetUuid, assetType, Encoding.ASCII.GetBytes(data), creatorID); + } /// /// Create an asset from the given scene object From 682efe94635943fbfadc19204d77602fd30b3861 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 19:41:00 +0100 Subject: [PATCH 02/12] minor: refactor CreateAsset to eliminate dupe code --- OpenSim/Tests/Common/Setup/AssetHelpers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OpenSim/Tests/Common/Setup/AssetHelpers.cs b/OpenSim/Tests/Common/Setup/AssetHelpers.cs index 1beafcf764..6dc993f069 100644 --- a/OpenSim/Tests/Common/Setup/AssetHelpers.cs +++ b/OpenSim/Tests/Common/Setup/AssetHelpers.cs @@ -61,9 +61,11 @@ namespace OpenSim.Tests.Common /// public static AssetBase CreateAsset(UUID assetUuid, SceneObjectGroup sog) { - AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)AssetType.Object, sog.OwnerID.ToString()); - asset.Data = Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(sog)); - return asset; + return CreateAsset( + assetUuid, + AssetType.Object, + Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(sog)), + sog.OwnerID); } } } From 721c1085da22229f4d40529dd2738a2cf62a91b7 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 20:43:11 +0100 Subject: [PATCH 03/12] make oar object filename/pathname creation a helper method reused in both tests and oar code reduction in checking is outweighed by greater test clarity --- .../Serialization/ArchiveConstants.cs | 33 ++++++++++ .../World/Archiver/ArchiveHelpers.cs | 64 +++++++++++++++++++ .../World/Archiver/ArchiveReadRequest.cs | 1 - .../Archiver/ArchiveWriteRequestExecution.cs | 11 +--- .../World/Archiver/Tests/ArchiverTests.cs | 37 +++-------- 5 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 1cd80db24d..475a9de0cb 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using OpenMetaverse; @@ -85,6 +86,11 @@ namespace OpenSim.Framework.Serialization /// public const string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; + /// + /// Template used for creating filenames in OpenSim Archives. + /// + public const string OAR_OBJECT_FILENAME_TEMPLATE = "{0}_{1:000}-{2:000}-{3:000}__{4}.xml"; + /// /// Extensions used for asset types in the archive /// @@ -139,5 +145,32 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; } + + /// + /// Create the filename used to store an object in an OpenSim Archive. + /// + /// + /// + /// + /// + public static string CreateOarObjectFilename(string objectName, UUID uuid, Vector3 pos) + { + return string.Format( + OAR_OBJECT_FILENAME_TEMPLATE, objectName, + Math.Round(pos.X), Math.Round(pos.Y), Math.Round(pos.Z), + uuid); + } + + /// + /// Create the path used to store an object in an OpenSim Archives. + /// + /// + /// + /// + /// + public static string CreateOarObjectPath(string objectName, UUID uuid, Vector3 pos) + { + return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); + } } } diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs new file mode 100644 index 0000000000..880bd7cdd4 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs @@ -0,0 +1,64 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using OpenMetaverse; +using OpenSim.Framework.Serialization; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.CoreModules.World.Archiver +{ + /// + /// Helper methods for archive manipulation + /// + /// This is a separate class from ArchiveConstants because we need to bring in very OpenSim specific classes. + public static class ArchiveHelpers + { + /// + /// Create the filename used for objects in OpenSim Archives. + /// + /// + /// + /// + /// + public static string CreateObjectFilename(SceneObjectGroup sog) + { + return ArchiveConstants.CreateOarObjectFilename(sog.Name, sog.UUID, sog.AbsolutePosition); + } + + /// + /// Create the path used to store an object in an OpenSim Archive. + /// + /// + /// + /// + /// + public static string CreateObjectPath(SceneObjectGroup sog) + { + return ArchiveConstants.CreateOarObjectPath(sog.Name, sog.UUID, sog.AbsolutePosition); + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index c52f029c39..8d62fe1668 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -38,7 +38,6 @@ using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Serialization; using OpenSim.Framework.Serialization.External; - using OpenSim.Region.CoreModules.World.Terrain; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs index 9fc6ec47c2..586d98e322 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs @@ -145,17 +145,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver { //m_log.DebugFormat("[ARCHIVER]: Saving {0} {1}, {2}", entity.Name, entity.UUID, entity.GetType()); - Vector3 position = sceneObject.AbsolutePosition; - string serializedObject = m_serialiser.SerializeGroupToXml2(sceneObject); - string filename - = string.Format( - "{0}{1}_{2:000}-{3:000}-{4:000}__{5}.xml", - ArchiveConstants.OBJECTS_PATH, sceneObject.Name, - Math.Round(position.X), Math.Round(position.Y), Math.Round(position.Z), - sceneObject.UUID); - - m_archiveWriter.WriteFile(filename, serializedObject); + m_archiveWriter.WriteFile(ArchiveHelpers.CreateObjectPath(sceneObject), serializedObject); } m_log.InfoFormat("[ARCHIVER]: Added scene objects to archive."); diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index f3e5458dce..4d04af16e7 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections.Generic; using System.IO; using System.Reflection; using System.Threading; @@ -129,7 +130,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests //log4net.Config.XmlConfigurator.Configure(); SceneObjectPart part1 = CreateSceneObjectPart1(); - m_scene.AddNewSceneObject(new SceneObjectGroup(part1), false); + SceneObjectGroup sog1 = new SceneObjectGroup(part1); + m_scene.AddNewSceneObject(sog1, false); SceneObjectPart part2 = CreateSceneObjectPart2(); @@ -169,20 +171,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests bool gotControlFile = false; bool gotNcAssetFile = false; - bool gotObject1File = false; - bool gotObject2File = false; string expectedNcAssetFileName = string.Format("{0}_{1}", ncAssetUuid, "notecard.txt"); - string expectedObject1FileName = string.Format( - "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", - part1.Name, - Math.Round(part1.GroupPosition.X), Math.Round(part1.GroupPosition.Y), Math.Round(part1.GroupPosition.Z), - part1.UUID); - string expectedObject2FileName = string.Format( - "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", - part2.Name, - Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z), - part2.UUID); + + List foundPaths = new List(); + List expectedPaths = new List(); + expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog1)); + expectedPaths.Add(ArchiveHelpers.CreateObjectPath(sog2)); string filePath; TarArchiveReader.TarEntryType tarEntryType; @@ -202,25 +197,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests } else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) { - string fileName = filePath.Remove(0, ArchiveConstants.OBJECTS_PATH.Length); - - if (fileName.StartsWith(part1.Name)) - { - Assert.That(fileName, Is.EqualTo(expectedObject1FileName)); - gotObject1File = true; - } - else if (fileName.StartsWith(part2.Name)) - { - Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); - gotObject2File = true; - } + foundPaths.Add(filePath); } } Assert.That(gotControlFile, Is.True, "No control file in archive"); Assert.That(gotNcAssetFile, Is.True, "No notecard asset file in archive"); - Assert.That(gotObject1File, Is.True, "No object1 file in archive"); - Assert.That(gotObject2File, Is.True, "No object2 file in archive"); + Assert.That(foundPaths, Is.EquivalentTo(expectedPaths)); // TODO: Test presence of more files and contents of files. } From 2b5b2f4e60737f0a2197ff32cad4314a78671525 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 21 May 2010 21:02:26 +0100 Subject: [PATCH 04/12] Add a new priority scheme that works like FrontBack, but completely deprioritizes static prims, creating a hierarchy as follows: 0 == own avatar < other avatars < pysical prims < static prims For a child agent, simply acts like FrontBack --- .../Region/Framework/Scenes/Prioritizer.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs index e6a464206e..1eb0c286e8 100644 --- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs +++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs @@ -4,6 +4,7 @@ using log4net; using Nini.Config; using OpenSim.Framework; using OpenMetaverse; +using OpenSim.Region.Physics.Manager; /* * Steps to add a new prioritization policy: @@ -25,6 +26,7 @@ namespace OpenSim.Region.Framework.Scenes Distance = 1, SimpleAngularDistance = 2, FrontBack = 3, + BestAvatarResponsiveness = 4, } public class Prioritizer @@ -50,6 +52,8 @@ namespace OpenSim.Region.Framework.Scenes return GetPriorityByDistance(client, entity); // TODO: Reimplement SimpleAngularDistance case UpdatePrioritizationSchemes.FrontBack: return GetPriorityByFrontBack(client, entity); + case UpdatePrioritizationSchemes.BestAvatarResponsiveness: + return GetPriorityByBestAvatarResponsiveness(client, entity); default: throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); } @@ -130,5 +134,58 @@ namespace OpenSim.Region.Framework.Scenes return double.NaN; } + + private double GetPriorityByBestAvatarResponsiveness(IClientAPI client, ISceneEntity entity) + { + ScenePresence presence = m_scene.GetScenePresence(client.AgentId); + if (presence != null) + { + // If this is an update for our own avatar give it the highest priority + if (presence == entity) + return 0.0; + + // Use group position for child prims + Vector3 entityPos = entity.AbsolutePosition; + if (entity is SceneObjectPart) + entityPos = m_scene.GetGroupByPrim(entity.LocalId).AbsolutePosition; + else + entityPos = entity.AbsolutePosition; + + if (!presence.IsChildAgent) + { + if (entity is ScenePresence) + return 1.0; + + // Root agent. Use distance from camera and a priority decrease for objects behind us + Vector3 camPosition = presence.CameraPosition; + Vector3 camAtAxis = presence.CameraAtAxis; + + // Distance + double priority = Vector3.DistanceSquared(camPosition, entityPos); + + // Plane equation + float d = -Vector3.Dot(camPosition, camAtAxis); + float p = Vector3.Dot(camAtAxis, entityPos) + d; + if (p < 0.0f) priority *= 2.0; + + if (entity is SceneObjectPart) + { + PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor; + if (physActor == null || !physActor.IsPhysical) + priority+=100; + } + return priority; + } + else + { + // Child agent. Use the normal distance method + Vector3 presencePos = presence.AbsolutePosition; + + return Vector3.DistanceSquared(presencePos, entityPos); + } + } + + return double.NaN; + } } } From f83acf533b708d7963c5dd1238709898a969c96c Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 21:22:53 +0100 Subject: [PATCH 05/12] Fix a problem where SceneGraph.AddSceneObject() would return false on successfully adding an object rather than true, in defiance of its method documentation This meant that the returns were inconsistent - false would be returned both for various scene object failure conditions (e.g. root part was null) and if the object was successfully added. --- .../World/Archiver/ArchiveReadRequest.cs | 1 - OpenSim/Region/Framework/Scenes/SceneGraph.cs | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index 8d62fe1668..f97ae5f791 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -243,7 +243,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver // to the same scene (when this is possible). sceneObject.ResetIDs(); - foreach (SceneObjectPart part in sceneObject.Children.Values) { if (!ResolveUserUuid(part.CreatorID)) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index ef13c9834a..bb570e74dc 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -278,7 +278,7 @@ namespace OpenSim.Region.Framework.Scenes if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero) return false; - bool alreadyExisted = false; + bool newlyAdded = false; if (m_parentScene.m_clampPrimSize) { @@ -305,7 +305,12 @@ namespace OpenSim.Region.Framework.Scenes lock (sceneObject) { if (!Entities.ContainsKey(sceneObject.UUID)) - { + { +// m_log.DebugFormat( +// "[SCENE GRAPH]: Adding object {0} {1} to region {2}", +// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); + + newlyAdded = true; Entities.Add(sceneObject); m_numPrim += sceneObject.Children.Count; @@ -326,13 +331,15 @@ namespace OpenSim.Region.Framework.Scenes } } } - else - { - alreadyExisted = true; - } +// else +// { +// m_log.WarnFormat( +// "[SCENE GRAPH]: Scene object {0} {1} was already in region {2} on add request", +// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); +// } } - return alreadyExisted; + return newlyAdded; } /// From 8d968249ec02808db18b0d96d94383a7e2b05b03 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 21:38:47 +0100 Subject: [PATCH 06/12] extend TestAddSceneObject() to check Scene.AddNewSceneObject() return boolean improve test to retrieve object by known uuid rather than dynamically assigned local id --- .../Scenes/Tests/SceneObjectBasicTests.cs | 16 +++++++++++++--- OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs | 2 -- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs index 78f2ae3aa1..4fe4a6a6ad 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs @@ -55,12 +55,22 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelper.InMethod(); Scene scene = SceneSetupHelpers.SetupScene(); - SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene); - SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId); + + string objName = "obj1"; + UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); + + SceneObjectPart part + = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) + { Name = objName, UUID = objUuid }; + + Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part), false), Is.True); + + SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid); //m_log.Debug("retrievedPart : {0}", retrievedPart); // If the parts have the same UUID then we will consider them as one and the same - Assert.That(retrievedPart.UUID, Is.EqualTo(part.UUID)); + Assert.That(retrievedPart.Name, Is.EqualTo(objName)); + Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid)); } /// diff --git a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs index ef8ea50e64..91cf323fcb 100644 --- a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs +++ b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs @@ -32,7 +32,6 @@ using Nini.Config; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Communications; - using OpenSim.Framework.Console; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; @@ -115,7 +114,6 @@ namespace OpenSim.Tests.Common.Setup return SetupScene(name, id, x, y,""); } - /// /// Set up a scene. If it's more then one scene, use the same CommunicationsManager to link regions /// or a different, to get a brand new scene with new shared region modules. From 76135eec5bfcd31357f8e698538747eb72fb8233 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 21:46:41 +0100 Subject: [PATCH 07/12] add test to make sure that adding an object where one already exists in the scene with that uuid fails --- .../Scenes/Tests/SceneObjectBasicTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs index 4fe4a6a6ad..39f8acf982 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs @@ -72,6 +72,40 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(retrievedPart.Name, Is.EqualTo(objName)); Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid)); } + + [Test] + /// + /// It shouldn't be possible to add a scene object if one with that uuid already exists in the scene. + /// + public void TestAddExistingSceneObjectUuid() + { + TestHelper.InMethod(); + + Scene scene = SceneSetupHelpers.SetupScene(); + + string obj1Name = "Alfred"; + string obj2Name = "Betty"; + UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); + + SceneObjectPart part1 + = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) + { Name = obj1Name, UUID = objUuid }; + + Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True); + + SceneObjectPart part2 + = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) + { Name = obj2Name, UUID = objUuid }; + + Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part2), false), Is.False); + + SceneObjectPart retrievedPart = scene.GetSceneObjectPart(objUuid); + + //m_log.Debug("retrievedPart : {0}", retrievedPart); + // If the parts have the same UUID then we will consider them as one and the same + Assert.That(retrievedPart.Name, Is.EqualTo(obj1Name)); + Assert.That(retrievedPart.UUID, Is.EqualTo(objUuid)); + } /// /// Test deleting an object from a scene. From 4b518e0288386d37c2e13a9b3de6edcd5ed04412 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 21:48:47 +0100 Subject: [PATCH 08/12] minor: remove LongRunning test designator from TestAddSceneObject() since it isn't, really --- OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs index 39f8acf982..4baa22c0fb 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectBasicTests.cs @@ -49,7 +49,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests /// /// Test adding an object to a scene. /// - [Test, LongRunning] + [Test] public void TestAddSceneObject() { TestHelper.InMethod(); From 93ef65c69055157e0b7d51e544abe5a1035f40f0 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 21 May 2010 13:55:36 -0700 Subject: [PATCH 09/12] * Moving all of the prioritization/reprioritization code into a new file Prioritizer.cs * Simplified the interest management code to make it easier to add new policies. Prioritization and reprioritization share code paths now * Improved the distance and front back policies to always give your avatar the highest priority --- .../Client/MXP/ClientStack/MXPClientView.cs | 2 +- .../ClientStack/SirikataClientView.cs | 2 +- .../VWoHTTP/ClientStack/VWHClientView.cs | 2 +- OpenSim/Framework/IClientAPI.cs | 21 ++- OpenSim/Framework/ISceneEntity.cs | 1 + .../ClientStack/LindenUDP/LLClientView.cs | 46 +++---- .../Examples/SimpleModule/MyNpcCharacter.cs | 2 +- OpenSim/Region/Framework/Scenes/EntityBase.cs | 3 +- .../Region/Framework/Scenes/Prioritizer.cs | 122 ++++++++++++++++++ OpenSim/Region/Framework/Scenes/Scene.cs | 96 +++++++------- .../Framework/Scenes/SceneObjectGroup.cs | 101 +-------------- .../Region/Framework/Scenes/ScenePresence.cs | 118 +---------------- .../Server/IRCClientView.cs | 2 +- .../OptionalModules/World/NPC/NPCAvatar.cs | 2 +- OpenSim/Tests/Common/Mock/TestClient.cs | 2 +- 15 files changed, 207 insertions(+), 315 deletions(-) create mode 100644 OpenSim/Region/Framework/Scenes/Prioritizer.cs diff --git a/OpenSim/Client/MXP/ClientStack/MXPClientView.cs b/OpenSim/Client/MXP/ClientStack/MXPClientView.cs index a62d8974a9..3e926587c2 100644 --- a/OpenSim/Client/MXP/ClientStack/MXPClientView.cs +++ b/OpenSim/Client/MXP/ClientStack/MXPClientView.cs @@ -1065,7 +1065,7 @@ namespace OpenSim.Client.MXP.ClientStack throw new System.NotImplementedException(); } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { } diff --git a/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs b/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs index d1f098892b..c293480e76 100644 --- a/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs +++ b/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs @@ -609,7 +609,7 @@ namespace OpenSim.Client.Sirikata.ClientStack throw new System.NotImplementedException(); } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { throw new System.NotImplementedException(); } diff --git a/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs b/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs index c0da3263c2..51026abf80 100644 --- a/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs +++ b/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs @@ -615,7 +615,7 @@ namespace OpenSim.Client.VWoHTTP.ClientStack throw new System.NotImplementedException(); } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { throw new System.NotImplementedException(); } diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 00681cf80d..f51bf71f5d 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -458,8 +458,6 @@ namespace OpenSim.Framework public delegate void PlacesQuery(UUID QueryID, UUID TransactionID, string QueryText, uint QueryFlags, byte Category, string SimName, IClientAPI client); public delegate void AgentFOV(IClientAPI client, float verticalAngle); - - public delegate double UpdatePriorityHandler(UpdatePriorityData data); public delegate void MuteListEntryUpdate(IClientAPI client, UUID MuteID, string Name, int Flags,UUID AgentID); @@ -571,17 +569,16 @@ namespace OpenSim.Framework public float dwell; } - public struct UpdatePriorityData { - private double m_priority; - private uint m_localID; + public class EntityUpdate + { + public ISceneEntity Entity; + public PrimUpdateFlags Flags; - public UpdatePriorityData(double priority, uint localID) { - this.m_priority = priority; - this.m_localID = localID; + public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags) + { + Entity = entity; + Flags = flags; } - - public double priority { get { return this.m_priority; } } - public uint localID { get { return this.m_localID; } } } /// @@ -1024,7 +1021,7 @@ namespace OpenSim.Framework void SendAvatarDataImmediate(ISceneEntity avatar); void SendPrimUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags); - void ReprioritizeUpdates(UpdatePriorityHandler handler); + void ReprioritizeUpdates(); void FlushPrimUpdates(); void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List items, diff --git a/OpenSim/Framework/ISceneEntity.cs b/OpenSim/Framework/ISceneEntity.cs index fa3c514667..5ac364f994 100644 --- a/OpenSim/Framework/ISceneEntity.cs +++ b/OpenSim/Framework/ISceneEntity.cs @@ -33,5 +33,6 @@ namespace OpenSim.Framework { UUID UUID { get; } uint LocalId { get; } + Vector3 AbsolutePosition { get; } } } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index c8a542b360..9eb35fa67b 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -50,18 +50,6 @@ using Nini.Config; namespace OpenSim.Region.ClientStack.LindenUDP { - public class EntityUpdate - { - public ISceneEntity Entity; - public PrimUpdateFlags Flags; - - public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags) - { - Entity = entity; - Flags = flags; - } - } - public delegate bool PacketMethod(IClientAPI simClient, Packet packet); /// @@ -325,6 +313,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private int m_cachedTextureSerial; private PriorityQueue m_entityUpdates; + private Prioritizer m_prioritizer; /// /// List used in construction of data blocks for an object update packet. This is to stop us having to @@ -462,6 +451,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_propertiesPacketTimer = new Timer(100); m_propertiesPacketTimer.Elapsed += ProcessObjectPropertiesPacket; + m_prioritizer = new Prioritizer(m_scene); + RegisterLocalPacketHandlers(); } @@ -3457,14 +3448,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// public void SendPrimUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags) { - double priority; - - if (entity is SceneObjectPart) - priority = ((SceneObjectPart)entity).ParentGroup.GetUpdatePriority(this); - else if (entity is ScenePresence) - priority = ((ScenePresence)entity).GetUpdatePriority(this); - else - priority = 0.0d; + double priority = m_prioritizer.GetUpdatePriority(this, entity); lock (m_entityUpdates.SyncRoot) m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags), entity.LocalId); @@ -3613,19 +3597,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion Packet Sending } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { //m_log.Debug("[CLIENT]: Reprioritizing prim updates for " + m_firstName + " " + m_lastName); - PriorityQueue.UpdatePriorityHandler update_priority_handler = - delegate(ref double priority, uint local_id) - { - priority = handler(new UpdatePriorityData(priority, local_id)); - return priority != double.NaN; - }; - lock (m_entityUpdates.SyncRoot) - m_entityUpdates.Reprioritize(update_priority_handler); + m_entityUpdates.Reprioritize(UpdatePriorityHandler); + } + + private bool UpdatePriorityHandler(ref double priority, uint localID) + { + EntityBase entity; + if (m_scene.Entities.TryGetValue(localID, out entity)) + { + priority = m_prioritizer.GetUpdatePriority(this, entity); + } + + return priority != double.NaN; } public void FlushPrimUpdates() diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs index aac47d19a3..967438fcf5 100644 --- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs @@ -548,7 +548,7 @@ namespace OpenSim.Region.Examples.SimpleModule { } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { } diff --git a/OpenSim/Region/Framework/Scenes/EntityBase.cs b/OpenSim/Region/Framework/Scenes/EntityBase.cs index 1c76c546e5..4e25c468c0 100644 --- a/OpenSim/Region/Framework/Scenes/EntityBase.cs +++ b/OpenSim/Region/Framework/Scenes/EntityBase.cs @@ -28,11 +28,12 @@ using System; using System.Runtime.Serialization; using System.Security.Permissions; +using OpenSim.Framework; using OpenMetaverse; namespace OpenSim.Region.Framework.Scenes { - public abstract class EntityBase + public abstract class EntityBase : ISceneEntity { /// /// The scene to which this entity belongs diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs new file mode 100644 index 0000000000..af250143dd --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using log4net; +using Nini.Config; +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.Framework.Scenes +{ + public enum UpdatePrioritizationSchemes + { + Time = 0, + Distance = 1, + SimpleAngularDistance = 2, + FrontBack = 3, + } + + public class Prioritizer + { + private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; + + public Prioritizer(Scene scene) + { + m_scene = scene; + } + + public double GetUpdatePriority(IClientAPI client, ISceneEntity entity) + { + switch (m_scene.UpdatePrioritizationScheme) + { + case UpdatePrioritizationSchemes.Time: + return GetPriorityByTime(); + case UpdatePrioritizationSchemes.Distance: + return GetPriorityByDistance(client, entity); + case UpdatePrioritizationSchemes.SimpleAngularDistance: + return GetPriorityByDistance(client, entity); + case UpdatePrioritizationSchemes.FrontBack: + return GetPriorityByFrontBack(client, entity); + default: + throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); + } + } + + private double GetPriorityByTime() + { + return DateTime.UtcNow.ToOADate(); + } + + private double GetPriorityByDistance(IClientAPI client, ISceneEntity entity) + { + ScenePresence presence = m_scene.GetScenePresence(client.AgentId); + if (presence != null) + { + // If this is an update for our own avatar give it the highest priority + if (presence == entity) + return 0.0; + + // Use the camera position for local agents and avatar position for remote agents + Vector3 presencePos = (presence.IsChildAgent) ? + presence.AbsolutePosition : + presence.CameraPosition; + + // Use group position for child prims + Vector3 entityPos; + if (entity is SceneObjectPart) + entityPos = m_scene.GetGroupByPrim(entity.LocalId).AbsolutePosition; + else + entityPos = entity.AbsolutePosition; + + return Vector3.DistanceSquared(presencePos, entityPos); + } + + return double.NaN; + } + + private double GetPriorityByFrontBack(IClientAPI client, ISceneEntity entity) + { + ScenePresence presence = m_scene.GetScenePresence(client.AgentId); + if (presence != null) + { + // If this is an update for our own avatar give it the highest priority + if (presence == entity) + return 0.0; + + // Use group position for child prims + Vector3 entityPos = entity.AbsolutePosition; + if (entity is SceneObjectPart) + entityPos = m_scene.GetGroupByPrim(entity.LocalId).AbsolutePosition; + else + entityPos = entity.AbsolutePosition; + + if (!presence.IsChildAgent) + { + // Root agent. Use distance from camera and a priority decrease for objects behind us + Vector3 camPosition = presence.CameraPosition; + Vector3 camAtAxis = presence.CameraAtAxis; + + // Distance + double priority = Vector3.DistanceSquared(camPosition, entityPos); + + // Plane equation + float d = -Vector3.Dot(camPosition, camAtAxis); + float p = Vector3.Dot(camAtAxis, entityPos) + d; + if (p < 0.0f) priority *= 2.0; + + return priority; + } + else + { + // Child agent. Use the normal distance method + Vector3 presencePos = presence.AbsolutePosition; + + return Vector3.DistanceSquared(presencePos, entityPos); + } + } + + return double.NaN; + } + } +} diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index de8ecc2713..f35dffca32 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -58,13 +58,6 @@ namespace OpenSim.Region.Framework.Scenes public partial class Scene : SceneBase { - public enum UpdatePrioritizationSchemes { - Time = 0, - Distance = 1, - SimpleAngularDistance = 2, - FrontBack = 3, - } - public delegate void SynchronizeSceneHandler(Scene scene); public SynchronizeSceneHandler SynchronizeScene = null; @@ -388,12 +381,6 @@ namespace OpenSim.Region.Framework.Scenes private int m_lastUpdate; private bool m_firstHeartbeat = true; - private UpdatePrioritizationSchemes m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time; - private bool m_reprioritization_enabled = true; - private double m_reprioritization_interval = 5000.0; - private double m_root_reprioritization_distance = 10.0; - private double m_child_reprioritization_distance = 20.0; - private object m_deleting_scene_object = new object(); // the minimum time that must elapse before a changed object will be considered for persisted @@ -401,15 +388,21 @@ namespace OpenSim.Region.Framework.Scenes // the maximum time that must elapse before a changed object will be considered for persisted public long m_persistAfter = DEFAULT_MAX_TIME_FOR_PERSISTENCE * 10000000L; + private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time; + private bool m_reprioritizationEnabled = true; + private double m_reprioritizationInterval = 5000.0; + private double m_rootReprioritizationDistance = 10.0; + private double m_childReprioritizationDistance = 20.0; + #endregion #region Properties - public UpdatePrioritizationSchemes UpdatePrioritizationScheme { get { return this.m_update_prioritization_scheme; } } - public bool IsReprioritizationEnabled { get { return m_reprioritization_enabled; } } - public double ReprioritizationInterval { get { return m_reprioritization_interval; } } - public double RootReprioritizationDistance { get { return m_root_reprioritization_distance; } } - public double ChildReprioritizationDistance { get { return m_child_reprioritization_distance; } } + public UpdatePrioritizationSchemes UpdatePrioritizationScheme { get { return m_priorityScheme; } } + public bool IsReprioritizationEnabled { get { return m_reprioritizationEnabled; } } + public double ReprioritizationInterval { get { return m_reprioritizationInterval; } } + public double RootReprioritizationDistance { get { return m_rootReprioritizationDistance; } } + public double ChildReprioritizationDistance { get { return m_childReprioritizationDistance; } } public AgentCircuitManager AuthenticateHandler { @@ -611,6 +604,8 @@ namespace OpenSim.Region.Framework.Scenes m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); m_asyncSceneObjectDeleter.Enabled = true; + #region Region Settings + // Load region settings m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); if (m_storageManager.EstateDataStore != null) @@ -657,6 +652,8 @@ namespace OpenSim.Region.Framework.Scenes } } + #endregion Region Settings + MainConsole.Instance.Commands.AddCommand("region", false, "reload estate", "reload estate", "Reload the estate data", HandleReloadEstate); @@ -701,6 +698,8 @@ namespace OpenSim.Region.Framework.Scenes m_simulatorVersion = simulatorVersion + " (" + Util.GetRuntimeInformation() + ")"; + #region Region Config + try { // Region config overrides global config @@ -754,38 +753,6 @@ namespace OpenSim.Region.Framework.Scenes m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); - IConfig interest_management_config = m_config.Configs["InterestManagement"]; - if (interest_management_config != null) - { - string update_prioritization_scheme = interest_management_config.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower(); - switch (update_prioritization_scheme) - { - case "time": - m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time; - break; - case "distance": - m_update_prioritization_scheme = UpdatePrioritizationSchemes.Distance; - break; - case "simpleangulardistance": - m_update_prioritization_scheme = UpdatePrioritizationSchemes.SimpleAngularDistance; - break; - case "frontback": - m_update_prioritization_scheme = UpdatePrioritizationSchemes.FrontBack; - break; - default: - m_log.Warn("[SCENE]: UpdatePrioritizationScheme was not recognized, setting to default settomg of Time"); - m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time; - break; - } - - m_reprioritization_enabled = interest_management_config.GetBoolean("ReprioritizationEnabled", true); - m_reprioritization_interval = interest_management_config.GetDouble("ReprioritizationInterval", 5000.0); - m_root_reprioritization_distance = interest_management_config.GetDouble("RootReprioritizationDistance", 10.0); - m_child_reprioritization_distance = interest_management_config.GetDouble("ChildReprioritizationDistance", 20.0); - } - - m_log.Info("[SCENE]: Using the " + m_update_prioritization_scheme + " prioritization scheme"); - #region BinaryStats try @@ -822,6 +789,35 @@ namespace OpenSim.Region.Framework.Scenes { m_log.Warn("[SCENE]: Failed to load StartupConfig"); } + + #endregion Region Config + + #region Interest Management + + IConfig interestConfig = m_config.Configs["InterestManagement"]; + if (interestConfig != null) + { + string update_prioritization_scheme = interestConfig.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower(); + + try + { + m_priorityScheme = (UpdatePrioritizationSchemes)Enum.Parse(typeof(UpdatePrioritizationSchemes), update_prioritization_scheme, true); + } + catch (Exception) + { + m_log.Warn("[PRIORITIZER]: UpdatePrioritizationScheme was not recognized, setting to default prioritizer Time"); + m_priorityScheme = UpdatePrioritizationSchemes.Time; + } + + m_reprioritizationEnabled = interestConfig.GetBoolean("ReprioritizationEnabled", true); + m_reprioritizationInterval = interestConfig.GetDouble("ReprioritizationInterval", 5000.0); + m_rootReprioritizationDistance = interestConfig.GetDouble("RootReprioritizationDistance", 10.0); + m_childReprioritizationDistance = interestConfig.GetDouble("ChildReprioritizationDistance", 20.0); + } + + m_log.Info("[SCENE]: Using the " + m_priorityScheme + " prioritization scheme"); + + #endregion Interest Management } /// diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 8aefd50977..4453bebec8 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -3602,106 +3602,7 @@ namespace OpenSim.Region.Framework.Scenes SetFromItemID(uuid); } - #endregion - public double GetUpdatePriority(IClientAPI client) - { - switch (Scene.UpdatePrioritizationScheme) - { - case Scene.UpdatePrioritizationSchemes.Time: - return GetPriorityByTime(); - case Scene.UpdatePrioritizationSchemes.Distance: - return GetPriorityByDistance(client); - case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: - return GetPriorityBySimpleAngularDistance(client); - case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: - return GetPriorityByFrontBack(client); - default: - throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); - } - } - - private double GetPriorityByTime() - { - return DateTime.Now.ToOADate(); - } - - private double GetPriorityByDistance(IClientAPI client) - { - ScenePresence presence = Scene.GetScenePresence(client.AgentId); - if (presence != null) - { - return GetPriorityByDistance((presence.IsChildAgent) ? - presence.AbsolutePosition : presence.CameraPosition); - } - return double.NaN; - } - - private double GetPriorityBySimpleAngularDistance(IClientAPI client) - { - ScenePresence presence = Scene.GetScenePresence(client.AgentId); - if (presence != null) - { - return GetPriorityBySimpleAngularDistance((presence.IsChildAgent) ? - presence.AbsolutePosition : presence.CameraPosition); - } - return double.NaN; - } - - private double GetPriorityByFrontBack(IClientAPI client) - { - ScenePresence presence = Scene.GetScenePresence(client.AgentId); - if (presence != null) - { - return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis); - } - return double.NaN; - } - - public double GetPriorityByDistance(Vector3 position) - { - return Vector3.Distance(AbsolutePosition, position); - } - - public double GetPriorityBySimpleAngularDistance(Vector3 position) - { - double distance = Vector3.Distance(position, AbsolutePosition); - if (distance >= double.Epsilon) - { - float height; - Vector3 box = GetAxisAlignedBoundingBox(out height); - - double angle = box.X / distance; - double max = angle; - - angle = box.Y / distance; - if (max < angle) - max = angle; - - angle = box.Z / distance; - if (max < angle) - max = angle; - - return -max; - } - else - return double.MinValue; - } - - public double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis) - { - // Distance - double priority = Vector3.Distance(camPosition, AbsolutePosition); - - // Scale - //priority -= GroupScale().Length(); - - // Plane equation - float d = -Vector3.Dot(camPosition, camAtAxis); - float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d; - if (p < 0.0f) priority *= 2.0f; - - return priority; - } + #endregion } } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index ee0eb07265..2ce1b6800d 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -3777,123 +3777,9 @@ namespace OpenSim.Region.Framework.Scenes } } - public double GetUpdatePriority(IClientAPI client) - { - switch (Scene.UpdatePrioritizationScheme) - { - case Scene.UpdatePrioritizationSchemes.Time: - return GetPriorityByTime(); - case Scene.UpdatePrioritizationSchemes.Distance: - return GetPriorityByDistance(client); - case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: - return GetPriorityByDistance(client); - case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: - return GetPriorityByFrontBack(client); - default: - throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); - } - } - - private double GetPriorityByTime() - { - return DateTime.Now.ToOADate(); - } - - private double GetPriorityByDistance(IClientAPI client) - { - ScenePresence presence = Scene.GetScenePresence(client.AgentId); - if (presence != null) - { - return GetPriorityByDistance((presence.IsChildAgent) ? - presence.AbsolutePosition : presence.CameraPosition); - } - return double.NaN; - } - - private double GetPriorityByFrontBack(IClientAPI client) - { - ScenePresence presence = Scene.GetScenePresence(client.AgentId); - if (presence != null) - { - return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis); - } - return double.NaN; - } - - private double GetPriorityByDistance(Vector3 position) - { - return Vector3.Distance(AbsolutePosition, position); - } - - private double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis) - { - // Distance - double priority = Vector3.Distance(camPosition, AbsolutePosition); - - // Plane equation - float d = -Vector3.Dot(camPosition, camAtAxis); - float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d; - if (p < 0.0f) priority *= 2.0f; - - return priority; - } - - private double GetSOGUpdatePriority(SceneObjectGroup sog) - { - switch (Scene.UpdatePrioritizationScheme) - { - case Scene.UpdatePrioritizationSchemes.Time: - throw new InvalidOperationException("UpdatePrioritizationScheme for time not supported for reprioritization"); - case Scene.UpdatePrioritizationSchemes.Distance: - return sog.GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); - case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: - return sog.GetPriorityBySimpleAngularDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); - case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: - return sog.GetPriorityByFrontBack(CameraPosition, CameraAtAxis); - default: - throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); - } - } - - private double UpdatePriority(UpdatePriorityData data) - { - EntityBase entity; - SceneObjectGroup group; - - if (Scene.Entities.TryGetValue(data.localID, out entity)) - { - group = entity as SceneObjectGroup; - if (group != null) - return GetSOGUpdatePriority(group); - - ScenePresence presence = entity as ScenePresence; - if (presence == null) - throw new InvalidOperationException("entity found is neither SceneObjectGroup nor ScenePresence"); - switch (Scene.UpdatePrioritizationScheme) - { - case Scene.UpdatePrioritizationSchemes.Time: - throw new InvalidOperationException("UpdatePrioritization for time not supported for reprioritization"); - case Scene.UpdatePrioritizationSchemes.Distance: - case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: - return GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); - case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack: - return GetPriorityByFrontBack(CameraPosition, CameraAtAxis); - default: - throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); - } - } - else - { - group = Scene.GetGroupByPrim(data.localID); - if (group != null) - return GetSOGUpdatePriority(group); - } - return double.NaN; - } - private void ReprioritizeUpdates() { - if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != Scene.UpdatePrioritizationSchemes.Time) + if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != UpdatePrioritizationSchemes.Time) { lock (m_reprioritization_timer) { @@ -3907,7 +3793,7 @@ namespace OpenSim.Region.Framework.Scenes private void Reprioritize(object sender, ElapsedEventArgs e) { - m_controllingClient.ReprioritizeUpdates(UpdatePriority); + m_controllingClient.ReprioritizeUpdates(); lock (m_reprioritization_timer) { diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 84faac0e00..27de529e22 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -1065,7 +1065,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { } diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 906669187c..d2279c735e 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -638,7 +638,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC { } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { } diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index edb76428b4..6b0efe920e 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -641,7 +641,7 @@ namespace OpenSim.Tests.Common.Mock { } - public void ReprioritizeUpdates(UpdatePriorityHandler handler) + public void ReprioritizeUpdates() { } From 5287c5f7fbd75ddb36f18a8692adb38cd824aaee Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 21 May 2010 21:57:56 +0100 Subject: [PATCH 10/12] rearrange SceneGraph.AddSceneObject() to return earlier if an object with that uuid is already in the scene this means that we don't perform pointless work --- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 110 +++++++++--------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index bb570e74dc..e923a92566 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -278,68 +278,64 @@ namespace OpenSim.Region.Framework.Scenes if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero) return false; - bool newlyAdded = false; - - if (m_parentScene.m_clampPrimSize) - { - foreach (SceneObjectPart part in sceneObject.Children.Values) - { - Vector3 scale = part.Shape.Scale; - - if (scale.X > m_parentScene.m_maxNonphys) - scale.X = m_parentScene.m_maxNonphys; - if (scale.Y > m_parentScene.m_maxNonphys) - scale.Y = m_parentScene.m_maxNonphys; - if (scale.Z > m_parentScene.m_maxNonphys) - scale.Z = m_parentScene.m_maxNonphys; - - part.Shape.Scale = scale; - } - } - - sceneObject.AttachToScene(m_parentScene); - - if (sendClientUpdates) - sceneObject.ScheduleGroupForFullUpdate(); - lock (sceneObject) - { - if (!Entities.ContainsKey(sceneObject.UUID)) - { -// m_log.DebugFormat( -// "[SCENE GRAPH]: Adding object {0} {1} to region {2}", -// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); - - newlyAdded = true; - Entities.Add(sceneObject); - m_numPrim += sceneObject.Children.Count; - - if (attachToBackup) - sceneObject.AttachToBackup(); - - if (OnObjectCreate != null) - OnObjectCreate(sceneObject); - - lock (m_dictionary_lock) - { - SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject; - SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject; - foreach (SceneObjectPart part in sceneObject.Children.Values) - { - SceneObjectGroupsByFullID[part.UUID] = sceneObject; - SceneObjectGroupsByLocalID[part.LocalId] = sceneObject; - } - } - } -// else -// { + { + if (Entities.ContainsKey(sceneObject.UUID)) + { // m_log.WarnFormat( // "[SCENE GRAPH]: Scene object {0} {1} was already in region {2} on add request", -// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); -// } +// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); + return false; + } + +// m_log.DebugFormat( +// "[SCENE GRAPH]: Adding object {0} {1} to region {2}", +// sceneObject.Name, sceneObject.UUID, m_parentScene.RegionInfo.RegionName); + + if (m_parentScene.m_clampPrimSize) + { + foreach (SceneObjectPart part in sceneObject.Children.Values) + { + Vector3 scale = part.Shape.Scale; + + if (scale.X > m_parentScene.m_maxNonphys) + scale.X = m_parentScene.m_maxNonphys; + if (scale.Y > m_parentScene.m_maxNonphys) + scale.Y = m_parentScene.m_maxNonphys; + if (scale.Z > m_parentScene.m_maxNonphys) + scale.Z = m_parentScene.m_maxNonphys; + + part.Shape.Scale = scale; + } + } + + sceneObject.AttachToScene(m_parentScene); + + if (sendClientUpdates) + sceneObject.ScheduleGroupForFullUpdate(); + + Entities.Add(sceneObject); + m_numPrim += sceneObject.Children.Count; + + if (attachToBackup) + sceneObject.AttachToBackup(); + + if (OnObjectCreate != null) + OnObjectCreate(sceneObject); + + lock (m_dictionary_lock) + { + SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject; + SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject; + foreach (SceneObjectPart part in sceneObject.Children.Values) + { + SceneObjectGroupsByFullID[part.UUID] = sceneObject; + SceneObjectGroupsByLocalID[part.LocalId] = sceneObject; + } + } } - return newlyAdded; + return true; } /// From abd5d1f7470ba07b784c6dbad4cdcdeaedc58d37 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 21 May 2010 14:04:10 -0700 Subject: [PATCH 11/12] * Added code comments to Prioritizer.cs that document how to add a new update priority policy --- OpenSim/Region/Framework/Scenes/Prioritizer.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs index af250143dd..e6a464206e 100644 --- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs +++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs @@ -5,6 +5,18 @@ using Nini.Config; using OpenSim.Framework; using OpenMetaverse; +/* + * Steps to add a new prioritization policy: + * + * - Add a new value to the UpdatePrioritizationSchemes enum. + * - Specify this new value in the [InterestManagement] section of your + * OpenSim.ini. The name in the config file must match the enum value name + * (although it is not case sensitive). + * - Write a new GetPriorityBy*() method in this class. + * - Add a new entry to the switch statement in GetUpdatePriority() that calls + * your method. + */ + namespace OpenSim.Region.Framework.Scenes { public enum UpdatePrioritizationSchemes @@ -35,7 +47,7 @@ namespace OpenSim.Region.Framework.Scenes case UpdatePrioritizationSchemes.Distance: return GetPriorityByDistance(client, entity); case UpdatePrioritizationSchemes.SimpleAngularDistance: - return GetPriorityByDistance(client, entity); + return GetPriorityByDistance(client, entity); // TODO: Reimplement SimpleAngularDistance case UpdatePrioritizationSchemes.FrontBack: return GetPriorityByFrontBack(client, entity); default: From d0eecf03986b1b1bd7458123a2deed522587b6dc Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 21 May 2010 14:17:03 -0700 Subject: [PATCH 12/12] Added a sanity check before using m_config in the Scene constructor --- OpenSim/Region/Framework/Scenes/Scene.cs | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index f35dffca32..46fbcd3832 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -794,25 +794,28 @@ namespace OpenSim.Region.Framework.Scenes #region Interest Management - IConfig interestConfig = m_config.Configs["InterestManagement"]; - if (interestConfig != null) + if (m_config != null) { - string update_prioritization_scheme = interestConfig.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower(); - - try + IConfig interestConfig = m_config.Configs["InterestManagement"]; + if (interestConfig != null) { - m_priorityScheme = (UpdatePrioritizationSchemes)Enum.Parse(typeof(UpdatePrioritizationSchemes), update_prioritization_scheme, true); - } - catch (Exception) - { - m_log.Warn("[PRIORITIZER]: UpdatePrioritizationScheme was not recognized, setting to default prioritizer Time"); - m_priorityScheme = UpdatePrioritizationSchemes.Time; - } + string update_prioritization_scheme = interestConfig.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower(); - m_reprioritizationEnabled = interestConfig.GetBoolean("ReprioritizationEnabled", true); - m_reprioritizationInterval = interestConfig.GetDouble("ReprioritizationInterval", 5000.0); - m_rootReprioritizationDistance = interestConfig.GetDouble("RootReprioritizationDistance", 10.0); - m_childReprioritizationDistance = interestConfig.GetDouble("ChildReprioritizationDistance", 20.0); + try + { + m_priorityScheme = (UpdatePrioritizationSchemes)Enum.Parse(typeof(UpdatePrioritizationSchemes), update_prioritization_scheme, true); + } + catch (Exception) + { + m_log.Warn("[PRIORITIZER]: UpdatePrioritizationScheme was not recognized, setting to default prioritizer Time"); + m_priorityScheme = UpdatePrioritizationSchemes.Time; + } + + m_reprioritizationEnabled = interestConfig.GetBoolean("ReprioritizationEnabled", true); + m_reprioritizationInterval = interestConfig.GetDouble("ReprioritizationInterval", 5000.0); + m_rootReprioritizationDistance = interestConfig.GetDouble("RootReprioritizationDistance", 10.0); + m_childReprioritizationDistance = interestConfig.GetDouble("ChildReprioritizationDistance", 20.0); + } } m_log.Info("[SCENE]: Using the " + m_priorityScheme + " prioritization scheme");