Some more refactoring

afrisby
MW 2007-11-04 22:22:53 +00:00
parent 1467720f60
commit d56ed8fe9c
9 changed files with 268 additions and 196 deletions

View File

@ -34,5 +34,6 @@ namespace OpenSim.Framework.Communications
bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData); bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData);
bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying); bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying);
bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId); bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId);
void TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID);
} }
} }

View File

@ -35,7 +35,6 @@ namespace OpenSim.Framework
void RemoveClient(LLUUID agentID); void RemoveClient(LLUUID agentID);
RegionInfo RegionInfo { get; } RegionInfo RegionInfo { get; }
object SyncRoot { get; }
uint NextLocalId { get; } uint NextLocalId { get; }
ClientManager ClientManager { get; } ClientManager ClientManager { get; }

View File

@ -178,6 +178,14 @@ namespace OpenSim.Region.Communications.Local
return false; return false;
} }
public void TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
{
if (m_regionListeners.ContainsKey(regionHandle))
{
// m_regionListeners[regionHandle].TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
}
}
public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId) public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId)
{ {
if (m_regionListeners.ContainsKey(regionHandle)) if (m_regionListeners.ContainsKey(regionHandle))

View File

@ -472,6 +472,11 @@ namespace OpenSim.Region.Communications.OGS1
} }
} }
public void TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
{
}
public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId) public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId)
{ {
return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId); return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId);

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using libsecondlife; using libsecondlife;
@ -12,6 +12,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
public class InnerScene public class InnerScene
{ {
#region Fields
public Dictionary<LLUUID, ScenePresence> ScenePresences; public Dictionary<LLUUID, ScenePresence> ScenePresences;
public Dictionary<LLUUID, SceneObjectGroup> SceneObjects; public Dictionary<LLUUID, SceneObjectGroup> SceneObjects;
public Dictionary<LLUUID, EntityBase> Entities; public Dictionary<LLUUID, EntityBase> Entities;
@ -19,11 +20,13 @@ namespace OpenSim.Region.Environment.Scenes
public BasicQuadTreeNode QuadTree; public BasicQuadTreeNode QuadTree;
protected RegionInfo m_regInfo; protected RegionInfo m_regInfo;
protected Scene m_parentScene; protected Scene m_parentScene;
public PhysicsScene PhyScene; protected PermissionManager PermissionsMngr;
private PermissionManager PermissionsMngr; internal object m_syncRoot = new object();
public PhysicsScene PhyScene;
#endregion
public InnerScene(Scene parent, RegionInfo regInfo, PermissionManager permissionsMngr) public InnerScene(Scene parent, RegionInfo regInfo, PermissionManager permissionsMngr)
{ {
@ -42,6 +45,51 @@ namespace OpenSim.Region.Environment.Scenes
Entities.Clear(); 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<EntityBase> updateEntities = new List<EntityBase>(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<EntityBase> moveEntities = new List<EntityBase>(Entities.Values);
foreach (EntityBase entity in moveEntities)
{
entity.UpdateMovement();
}
}
#endregion
#region Entity Methods
public void AddEntityFromStorage(SceneObjectGroup sceneObject) public void AddEntityFromStorage(SceneObjectGroup sceneObject)
{ {
sceneObject.RegionHandle = m_regInfo.RegionHandle; sceneObject.RegionHandle = m_regInfo.RegionHandle;
@ -122,6 +170,9 @@ namespace OpenSim.Region.Environment.Scenes
return newAvatar; return newAvatar;
} }
#endregion
#region Get Methods
/// <summary> /// <summary>
/// Request a List of all m_scenePresences in this World /// Request a List of all m_scenePresences in this World
@ -175,35 +226,6 @@ namespace OpenSim.Region.Environment.Scenes
return null; 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) public SceneObjectPart GetSceneObjectPart(uint localID)
{ {
bool hasPrim = false; bool hasPrim = false;
@ -274,6 +296,37 @@ namespace OpenSim.Region.Environment.Scenes
return false; 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<IClientAPI> action) internal void ForEachClient(Action<IClientAPI> action)
{ {
@ -282,6 +335,7 @@ namespace OpenSim.Region.Environment.Scenes
action(presence.ControllingClient); action(presence.ControllingClient);
} }
} }
#endregion
#region Client Event handlers #region Client Event handlers
/// <summary> /// <summary>
@ -307,7 +361,6 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -395,7 +448,6 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -653,3 +705,4 @@ namespace OpenSim.Region.Environment.Scenes
#endregion #endregion
} }
} }

View File

@ -75,6 +75,7 @@ namespace OpenSim.Region.Environment.Scenes
public CommunicationsManager CommsManager; public CommunicationsManager CommsManager;
// protected XferManager xferManager; // protected XferManager xferManager;
protected SceneCommunicationService m_sceneGridService; protected SceneCommunicationService m_sceneGridService;
protected SceneXmlLoader m_sceneXmlLoader;
protected Dictionary<LLUUID, Caps> m_capsHandlers = new Dictionary<LLUUID, Caps>(); protected Dictionary<LLUUID, Caps> m_capsHandlers = new Dictionary<LLUUID, Caps>();
protected BaseHttpServer httpListener; protected BaseHttpServer httpListener;
@ -140,6 +141,11 @@ namespace OpenSim.Region.Environment.Scenes
get { return (m_innerScene.PhyScene); } get { return (m_innerScene.PhyScene); }
} }
public object SyncRoot
{
get { return m_innerScene.m_syncRoot; }
}
public EstateManager EstateManager public EstateManager EstateManager
{ {
get { return m_estateManager; } get { return m_estateManager; }
@ -207,7 +213,8 @@ namespace OpenSim.Region.Environment.Scenes
m_eventManager = new EventManager(); m_eventManager = new EventManager();
m_permissionManager = new PermissionManager(this); 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_eventManager.OnParcelPrimCountAdd +=
m_LandManager.addPrimToLandPrimCounts; m_LandManager.addPrimToLandPrimCounts;
@ -292,18 +299,18 @@ namespace OpenSim.Region.Environment.Scenes
m_frame = 0; m_frame = 0;
if (m_frame%m_update_physics == 0) if (m_frame%m_update_physics == 0)
UpdatePreparePhysics(); m_innerScene.UpdatePreparePhysics();
if (m_frame%m_update_entitymovement == 0) if (m_frame%m_update_entitymovement == 0)
UpdateEntityMovement(); m_innerScene.UpdateEntityMovement();
if (m_frame%m_update_physics == 0) if (m_frame%m_update_physics == 0)
UpdatePhysics( m_innerScene.UpdatePhysics(
Math.Max(SinceLastFrame.TotalSeconds, m_timespan) Math.Max(SinceLastFrame.TotalSeconds, m_timespan)
); );
if (m_frame%m_update_entities == 0) if (m_frame%m_update_entities == 0)
UpdateEntities(); m_innerScene.UpdateEntities();
if (m_frame%m_update_events == 0) if (m_frame%m_update_events == 0)
UpdateEvents(); 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() private void UpdateInWorldTime()
{ {
m_timeUpdateCount++; m_timeUpdateCount++;
@ -388,7 +381,7 @@ namespace OpenSim.Region.Environment.Scenes
lock (Terrain.heightmap) lock (Terrain.heightmap)
{ {
lock (m_syncRoot) lock (SyncRoot)
{ {
phyScene.SetTerrain(Terrain.GetHeights1D()); phyScene.SetTerrain(Terrain.GetHeights1D());
} }
@ -427,34 +420,6 @@ namespace OpenSim.Region.Environment.Scenes
m_eventManager.TriggerOnFrame(); m_eventManager.TriggerOnFrame();
} }
private void UpdateEntities()
{
List<EntityBase> updateEntities = new List<EntityBase>(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<EntityBase> moveEntities = new List<EntityBase>(Entities.Values);
foreach (EntityBase entity in moveEntities)
{
entity.UpdateMovement();
}
}
/// <summary> /// <summary>
/// Perform delegate action on all clients subscribing to updates from this region. /// Perform delegate action on all clients subscribing to updates from this region.
/// </summary> /// </summary>
@ -655,120 +620,22 @@ namespace OpenSim.Region.Environment.Scenes
public void LoadPrimsFromXml(string fileName) public void LoadPrimsFromXml(string fileName)
{ {
XmlDocument doc = new XmlDocument(); m_sceneXmlLoader.LoadPrimsFromXml(fileName);
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");
}
} }
public void SavePrimsToXml(string fileName) public void SavePrimsToXml(string fileName)
{ {
FileStream file = new FileStream(fileName, FileMode.Create); m_sceneXmlLoader.SavePrimsToXml(fileName);
StreamWriter stream = new StreamWriter(file);
int primCount = 0;
stream.WriteLine("<scene>\n");
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup) ent).ToXmlString());
primCount++;
}
}
stream.WriteLine("</scene>\n");
stream.Close();
file.Close();
} }
public void LoadPrimsFromXml2(string fileName) public void LoadPrimsFromXml2(string fileName)
{ {
XmlDocument doc = new XmlDocument(); m_sceneXmlLoader.LoadPrimsFromXml2(fileName);
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);
} }
public void SavePrimsToXml2(string fileName) public void SavePrimsToXml2(string fileName)
{ {
FileStream file = new FileStream(fileName, FileMode.Create); m_sceneXmlLoader.SavePrimsToXml2(fileName);
StreamWriter stream = new StreamWriter(file);
int primCount = 0;
stream.WriteLine("<scene>\n");
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup) ent).ToXmlString2());
primCount++;
}
}
stream.WriteLine("</scene>\n");
stream.Close();
file.Close();
} }
#endregion #endregion

View File

@ -45,7 +45,6 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_clientManager; } get { return m_clientManager; }
} }
// public Dictionary<LLUUID, EntityBase> Entities;
protected ulong m_regionHandle; protected ulong m_regionHandle;
protected string m_regionName; protected string m_regionName;
protected RegionInfo m_regInfo; protected RegionInfo m_regInfo;
@ -66,7 +65,6 @@ namespace OpenSim.Region.Environment.Scenes
protected string m_datastore; protected string m_datastore;
protected object m_syncRoot = new object();
private uint m_nextLocalId = 8880000; private uint m_nextLocalId = 8880000;
private AssetCache m_assetCache; private AssetCache m_assetCache;
@ -132,11 +130,6 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_regInfo; } get { return m_regInfo; }
} }
public object SyncRoot
{
get { return m_syncRoot; }
}
public uint NextLocalId public uint NextLocalId
{ {
get { return m_nextLocalId++; } get { return m_nextLocalId++; }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Text; using System.Text;
@ -204,9 +204,10 @@ namespace OpenSim.Region.Environment.Scenes
return m_commsProvider.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying); 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.");
} }
} }
} }

View File

@ -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("<scene>\n");
foreach (EntityBase ent in m_innerScene.Entities.Values)
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup)ent).ToXmlString());
primCount++;
}
}
stream.WriteLine("</scene>\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("<scene>\n");
foreach (EntityBase ent in m_innerScene.Entities.Values)
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2());
primCount++;
}
}
stream.WriteLine("</scene>\n");
stream.Close();
file.Close();
}
}
}