From d56ed8fe9c6428a4ac3288190be303b5813b0b91 Mon Sep 17 00:00:00 2001 From: MW Date: Sun, 4 Nov 2007 22:22:53 +0000 Subject: Some more refactoring --- OpenSim/Region/Environment/Scenes/InnerScene.cs | 123 ++++++++++----- OpenSim/Region/Environment/Scenes/Scene.cs | 167 +++------------------ OpenSim/Region/Environment/Scenes/SceneBase.cs | 7 - .../Scenes/SceneCommunicationService.cs | 7 +- .../Region/Environment/Scenes/SceneXmlLoader.cs | 145 ++++++++++++++++++ 5 files changed, 254 insertions(+), 195 deletions(-) create mode 100644 OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs index 3195991..f775e22 100644 --- a/OpenSim/Region/Environment/Scenes/InnerScene.cs +++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using libsecondlife; @@ -12,6 +12,7 @@ namespace OpenSim.Region.Environment.Scenes { public class InnerScene { + #region Fields public Dictionary ScenePresences; public Dictionary SceneObjects; public Dictionary Entities; @@ -19,11 +20,13 @@ namespace OpenSim.Region.Environment.Scenes public BasicQuadTreeNode QuadTree; protected RegionInfo m_regInfo; - protected Scene m_parentScene; - public PhysicsScene PhyScene; + protected PermissionManager PermissionsMngr; + + internal object m_syncRoot = new object(); - private PermissionManager PermissionsMngr; + public PhysicsScene PhyScene; + #endregion public InnerScene(Scene parent, RegionInfo regInfo, PermissionManager permissionsMngr) { @@ -42,6 +45,51 @@ namespace OpenSim.Region.Environment.Scenes Entities.Clear(); } + #region Update Methods + internal void UpdatePreparePhysics() + { + // If we are using a threaded physics engine + // grab the latest scene from the engine before + // trying to process it. + + // PhysX does this (runs in the background). + + if (PhyScene.IsThreaded) + { + PhyScene.GetResults(); + } + } + + internal void UpdateEntities() + { + List updateEntities = new List(Entities.Values); + + foreach (EntityBase entity in updateEntities) + { + entity.Update(); + } + } + + internal void UpdatePhysics(double elapsed) + { + lock (m_syncRoot) + { + PhyScene.Simulate((float)elapsed); + } + } + + internal void UpdateEntityMovement() + { + List moveEntities = new List(Entities.Values); + + foreach (EntityBase entity in moveEntities) + { + entity.UpdateMovement(); + } + } + #endregion + + #region Entity Methods public void AddEntityFromStorage(SceneObjectGroup sceneObject) { sceneObject.RegionHandle = m_regInfo.RegionHandle; @@ -122,6 +170,9 @@ namespace OpenSim.Region.Environment.Scenes return newAvatar; } + #endregion + + #region Get Methods /// /// Request a List of all m_scenePresences in this World @@ -175,35 +226,6 @@ namespace OpenSim.Region.Environment.Scenes return null; } - - public LLUUID ConvertLocalIDToFullID(uint localID) - { - bool hasPrim = false; - foreach (EntityBase ent in Entities.Values) - { - if (ent is SceneObjectGroup) - { - hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID); - if (hasPrim != false) - { - return ((SceneObjectGroup)ent).GetPartsFullID(localID); - } - } - } - return LLUUID.Zero; - } - - public void SendAllSceneObjectsToClient(ScenePresence presence) - { - foreach (EntityBase ent in Entities.Values) - { - if (ent is SceneObjectGroup) - { - ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence); - } - } - } - public SceneObjectPart GetSceneObjectPart(uint localID) { bool hasPrim = false; @@ -274,6 +296,37 @@ namespace OpenSim.Region.Environment.Scenes return false; } + #endregion + + #region Other Methods + + public LLUUID ConvertLocalIDToFullID(uint localID) + { + bool hasPrim = false; + foreach (EntityBase ent in Entities.Values) + { + if (ent is SceneObjectGroup) + { + hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID); + if (hasPrim != false) + { + return ((SceneObjectGroup)ent).GetPartsFullID(localID); + } + } + } + return LLUUID.Zero; + } + + public void SendAllSceneObjectsToClient(ScenePresence presence) + { + foreach (EntityBase ent in Entities.Values) + { + if (ent is SceneObjectGroup) + { + ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence); + } + } + } internal void ForEachClient(Action action) { @@ -282,6 +335,7 @@ namespace OpenSim.Region.Environment.Scenes action(presence.ControllingClient); } } + #endregion #region Client Event handlers /// @@ -307,7 +361,6 @@ namespace OpenSim.Region.Environment.Scenes } } - /// /// /// @@ -395,7 +448,6 @@ namespace OpenSim.Region.Environment.Scenes } } - /// /// /// @@ -653,3 +705,4 @@ namespace OpenSim.Region.Environment.Scenes #endregion } } + diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 49d2268..8262478 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -75,6 +75,7 @@ namespace OpenSim.Region.Environment.Scenes public CommunicationsManager CommsManager; // protected XferManager xferManager; protected SceneCommunicationService m_sceneGridService; + protected SceneXmlLoader m_sceneXmlLoader; protected Dictionary m_capsHandlers = new Dictionary(); protected BaseHttpServer httpListener; @@ -140,6 +141,11 @@ namespace OpenSim.Region.Environment.Scenes get { return (m_innerScene.PhyScene); } } + public object SyncRoot + { + get { return m_innerScene.m_syncRoot; } + } + public EstateManager EstateManager { get { return m_estateManager; } @@ -207,7 +213,8 @@ namespace OpenSim.Region.Environment.Scenes m_eventManager = new EventManager(); m_permissionManager = new PermissionManager(this); - m_innerScene = new InnerScene(this, regInfo, m_permissionManager); + m_innerScene = new InnerScene(this, m_regInfo, m_permissionManager); + m_sceneXmlLoader = new SceneXmlLoader(this, m_innerScene, m_regInfo); m_eventManager.OnParcelPrimCountAdd += m_LandManager.addPrimToLandPrimCounts; @@ -292,18 +299,18 @@ namespace OpenSim.Region.Environment.Scenes m_frame = 0; if (m_frame%m_update_physics == 0) - UpdatePreparePhysics(); + m_innerScene.UpdatePreparePhysics(); if (m_frame%m_update_entitymovement == 0) - UpdateEntityMovement(); + m_innerScene.UpdateEntityMovement(); if (m_frame%m_update_physics == 0) - UpdatePhysics( + m_innerScene.UpdatePhysics( Math.Max(SinceLastFrame.TotalSeconds, m_timespan) ); if (m_frame%m_update_entities == 0) - UpdateEntities(); + m_innerScene.UpdateEntities(); if (m_frame%m_update_events == 0) UpdateEvents(); @@ -337,20 +344,6 @@ namespace OpenSim.Region.Environment.Scenes } } - private void UpdatePreparePhysics() - { - // If we are using a threaded physics engine - // grab the latest scene from the engine before - // trying to process it. - - // PhysX does this (runs in the background). - - if (phyScene.IsThreaded) - { - phyScene.GetResults(); - } - } - private void UpdateInWorldTime() { m_timeUpdateCount++; @@ -388,7 +381,7 @@ namespace OpenSim.Region.Environment.Scenes lock (Terrain.heightmap) { - lock (m_syncRoot) + lock (SyncRoot) { phyScene.SetTerrain(Terrain.GetHeights1D()); } @@ -427,34 +420,6 @@ namespace OpenSim.Region.Environment.Scenes m_eventManager.TriggerOnFrame(); } - private void UpdateEntities() - { - List updateEntities = new List(Entities.Values); - - foreach (EntityBase entity in updateEntities) - { - entity.Update(); - } - } - - private void UpdatePhysics(double elapsed) - { - lock (m_syncRoot) - { - phyScene.Simulate((float) elapsed); - } - } - - private void UpdateEntityMovement() - { - List moveEntities = new List(Entities.Values); - - foreach (EntityBase entity in moveEntities) - { - entity.UpdateMovement(); - } - } - /// /// Perform delegate action on all clients subscribing to updates from this region. /// @@ -655,120 +620,22 @@ namespace OpenSim.Region.Environment.Scenes public void LoadPrimsFromXml(string fileName) { - XmlDocument doc = new XmlDocument(); - XmlNode rootNode; - int primCount = 0; - if (fileName.StartsWith("http:") || File.Exists(fileName)) - { - XmlTextReader reader = new XmlTextReader(fileName); - reader.WhitespaceHandling = WhitespaceHandling.None; - doc.Load(reader); - reader.Close(); - rootNode = doc.FirstChild; - foreach (XmlNode aPrimNode in rootNode.ChildNodes) - { - SceneObjectGroup obj = new SceneObjectGroup(this, - m_regionHandle, aPrimNode.OuterXml); - //if we want this to be a import method then we need new uuids for the object to avoid any clashes - //obj.RegenerateFullIDs(); - AddEntity(obj); - - SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); - bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0); - if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) - rootPart.PhysActor = phyScene.AddPrimShape( - rootPart.Name, - rootPart.Shape, - new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, - rootPart.AbsolutePosition.Z), - new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), - new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, - rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); - primCount++; - } - } - else - { - throw new Exception("Could not open file " + fileName + " for reading"); - } + m_sceneXmlLoader.LoadPrimsFromXml(fileName); } public void SavePrimsToXml(string fileName) { - FileStream file = new FileStream(fileName, FileMode.Create); - StreamWriter stream = new StreamWriter(file); - int primCount = 0; - stream.WriteLine("\n"); - foreach (EntityBase ent in Entities.Values) - { - if (ent is SceneObjectGroup) - { - stream.WriteLine(((SceneObjectGroup) ent).ToXmlString()); - primCount++; - } - } - stream.WriteLine("\n"); - stream.Close(); - file.Close(); + m_sceneXmlLoader.SavePrimsToXml(fileName); } public void LoadPrimsFromXml2(string fileName) { - XmlDocument doc = new XmlDocument(); - XmlNode rootNode; - if (fileName.StartsWith("http:") || File.Exists(fileName)) - { - XmlTextReader reader = new XmlTextReader(fileName); - reader.WhitespaceHandling = WhitespaceHandling.None; - doc.Load(reader); - reader.Close(); - rootNode = doc.FirstChild; - foreach (XmlNode aPrimNode in rootNode.ChildNodes) - { - CreatePrimFromXml(aPrimNode.OuterXml); - } - } - else - { - throw new Exception("Could not open file " + fileName + " for reading"); - } - } - - public void CreatePrimFromXml(string xmlData) - { - SceneObjectGroup obj = new SceneObjectGroup(xmlData); - AddEntityFromStorage(obj); - - SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); - bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0); - if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) - rootPart.PhysActor = phyScene.AddPrimShape( - rootPart.Name, - rootPart.Shape, - new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, - rootPart.AbsolutePosition.Z), - new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), - new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, - rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); + m_sceneXmlLoader.LoadPrimsFromXml2(fileName); } public void SavePrimsToXml2(string fileName) { - FileStream file = new FileStream(fileName, FileMode.Create); - StreamWriter stream = new StreamWriter(file); - int primCount = 0; - stream.WriteLine("\n"); - foreach (EntityBase ent in Entities.Values) - { - if (ent is SceneObjectGroup) - { - stream.WriteLine(((SceneObjectGroup) ent).ToXmlString2()); - primCount++; - } - } - stream.WriteLine("\n"); - stream.Close(); - file.Close(); + m_sceneXmlLoader.SavePrimsToXml2(fileName); } #endregion diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index b0ec352..ace1788 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs @@ -45,7 +45,6 @@ namespace OpenSim.Region.Environment.Scenes get { return m_clientManager; } } - // public Dictionary Entities; protected ulong m_regionHandle; protected string m_regionName; protected RegionInfo m_regInfo; @@ -66,7 +65,6 @@ namespace OpenSim.Region.Environment.Scenes protected string m_datastore; - protected object m_syncRoot = new object(); private uint m_nextLocalId = 8880000; private AssetCache m_assetCache; @@ -132,11 +130,6 @@ namespace OpenSim.Region.Environment.Scenes get { return m_regInfo; } } - public object SyncRoot - { - get { return m_syncRoot; } - } - public uint NextLocalId { get { return m_nextLocalId++; } diff --git a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs index e67d413..fe8414d 100644 --- a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Net; using System.Text; @@ -204,9 +204,10 @@ namespace OpenSim.Region.Environment.Scenes return m_commsProvider.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying); } - public void CloseAgentConnection(ScenePresence presence) + public void CloseChildAgentConnections(ScenePresence presence) { - throw new Exception("The method or operation is not implemented."); + } } } + diff --git a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs new file mode 100644 index 0000000..1176e13 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using System.IO; +using libsecondlife; +using Axiom.Math; +using OpenSim.Framework; +using OpenSim.Region.Physics.Manager; + +namespace OpenSim.Region.Environment.Scenes +{ + public class SceneXmlLoader //Most likely can move to a module + { + protected InnerScene m_innerScene; + protected RegionInfo m_regInfo; + protected Scene m_parentScene; + + public SceneXmlLoader(Scene parentScene, InnerScene innerScene, RegionInfo regionInfo) + { + m_parentScene = parentScene; + m_innerScene = innerScene; + m_regInfo = regionInfo; + } + + public void LoadPrimsFromXml(string fileName) + { + XmlDocument doc = new XmlDocument(); + XmlNode rootNode; + int primCount = 0; + if (fileName.StartsWith("http:") || File.Exists(fileName)) + { + XmlTextReader reader = new XmlTextReader(fileName); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + rootNode = doc.FirstChild; + foreach (XmlNode aPrimNode in rootNode.ChildNodes) + { + SceneObjectGroup obj = new SceneObjectGroup(m_parentScene, + m_regInfo.RegionHandle, aPrimNode.OuterXml); + //if we want this to be a import method then we need new uuids for the object to avoid any clashes + //obj.RegenerateFullIDs(); + m_innerScene.AddEntity(obj); + + SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); + bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0); + if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) + rootPart.PhysActor = m_innerScene.PhyScene.AddPrimShape( + rootPart.Name, + rootPart.Shape, + new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, + rootPart.AbsolutePosition.Z), + new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), + new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, + rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); + primCount++; + } + } + else + { + throw new Exception("Could not open file " + fileName + " for reading"); + } + } + + public void SavePrimsToXml(string fileName) + { + FileStream file = new FileStream(fileName, FileMode.Create); + StreamWriter stream = new StreamWriter(file); + int primCount = 0; + stream.WriteLine("\n"); + foreach (EntityBase ent in m_innerScene.Entities.Values) + { + if (ent is SceneObjectGroup) + { + stream.WriteLine(((SceneObjectGroup)ent).ToXmlString()); + primCount++; + } + } + stream.WriteLine("\n"); + stream.Close(); + file.Close(); + } + + public void LoadPrimsFromXml2(string fileName) + { + XmlDocument doc = new XmlDocument(); + XmlNode rootNode; + if (fileName.StartsWith("http:") || File.Exists(fileName)) + { + XmlTextReader reader = new XmlTextReader(fileName); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + rootNode = doc.FirstChild; + foreach (XmlNode aPrimNode in rootNode.ChildNodes) + { + CreatePrimFromXml(aPrimNode.OuterXml); + } + } + else + { + throw new Exception("Could not open file " + fileName + " for reading"); + } + } + + public void CreatePrimFromXml(string xmlData) + { + SceneObjectGroup obj = new SceneObjectGroup(xmlData); + m_innerScene.AddEntityFromStorage(obj); + + SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); + bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0); + if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) + rootPart.PhysActor = m_innerScene.PhyScene.AddPrimShape( + rootPart.Name, + rootPart.Shape, + new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, + rootPart.AbsolutePosition.Z), + new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), + new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, + rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); + } + + public void SavePrimsToXml2(string fileName) + { + FileStream file = new FileStream(fileName, FileMode.Create); + StreamWriter stream = new StreamWriter(file); + int primCount = 0; + stream.WriteLine("\n"); + foreach (EntityBase ent in m_innerScene.Entities.Values) + { + if (ent is SceneObjectGroup) + { + stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2()); + primCount++; + } + } + stream.WriteLine("\n"); + stream.Close(); + file.Close(); + } + + } +} -- cgit v1.1