First part of Scene refactoring:

Started the move of some of the methods from scene into a inner class (currently called InnerScene.cs), the idea being that the code related to the 3d scene (primitive/entities/Avatars etc) will be in this inner class, then what is now Scene.cs will be left as a kind of wrapper class around it. And once the spilt is complete can be renamed to something like RegionInstance (or any name that sounds good and ids it as the Region layer class that "has" a scene). 
Added SceneCommunicationService which at the moment is a kind of high level wrapper around commsManager. The idea being that it has a higher level API for the Region/Scene to send messages to the other regions on the grid. a Example of the API is that instead of having sendXmessage methods, it has more functional level method like PassAvatarToNeighbour. Hopefully this will allow more freedom to do changes in communications that doesn't break other things.
afrisby
MW 2007-11-03 19:14:22 +00:00
parent add6fb9722
commit dabbdec2cd
9 changed files with 1084 additions and 769 deletions

View File

@ -370,8 +370,9 @@ namespace OpenSim
protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager, protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
AgentCircuitManager circuitManager) AgentCircuitManager circuitManager)
{ {
SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
return return
new Scene(regionInfo, circuitManager, m_commsManager, m_assetCache, storageManager, m_httpServer, new Scene(regionInfo, circuitManager, m_commsManager, sceneGridService, m_assetCache, storageManager, m_httpServer,
m_moduleLoader, m_dumpAssetsToFile); m_moduleLoader, m_dumpAssetsToFile);
} }

View File

@ -0,0 +1,657 @@
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
using libsecondlife.Packets;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.Environment.Types;
using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Environment.Scenes
{
public class InnerScene
{
public Dictionary<LLUUID, ScenePresence> ScenePresences;
public Dictionary<LLUUID, SceneObjectGroup> SceneObjects;
public Dictionary<LLUUID, EntityBase> Entities;
public BasicQuadTreeNode QuadTree;
protected RegionInfo m_regInfo;
protected Scene m_parentScene;
public PhysicsScene PhyScene;
private PermissionManager PermissionsMngr;
public InnerScene(Scene parent, RegionInfo regInfo, PermissionManager permissionsMngr)
{
m_parentScene = parent;
m_regInfo = regInfo;
PermissionsMngr = permissionsMngr;
QuadTree = new BasicQuadTreeNode(null, "/0/", 0, 0, 256, 256);
QuadTree.Subdivide();
QuadTree.Subdivide();
}
public void Close()
{
ScenePresences.Clear();
SceneObjects.Clear();
Entities.Clear();
}
public void AddEntityFromStorage(SceneObjectGroup sceneObject)
{
sceneObject.RegionHandle = m_regInfo.RegionHandle;
sceneObject.SetScene(m_parentScene);
foreach (SceneObjectPart part in sceneObject.Children.Values)
{
part.LocalID = m_parentScene.PrimIDAllocate();
}
sceneObject.UpdateParentIDs();
AddEntity(sceneObject);
}
public void AddEntity(SceneObjectGroup sceneObject)
{
if (!Entities.ContainsKey(sceneObject.UUID))
{
// QuadTree.AddObject(sceneObject);
Entities.Add(sceneObject.UUID, sceneObject);
}
}
public void RemovePrim(uint localID, LLUUID avatar_deleter)
{
foreach (EntityBase obj in Entities.Values)
{
if (obj is SceneObjectGroup)
{
if (((SceneObjectGroup)obj).LocalId == localID)
{
m_parentScene.RemoveEntity((SceneObjectGroup)obj);
return;
}
}
}
}
public ScenePresence CreateAndAddScenePresence(IClientAPI client, bool child, AvatarWearable[] wearables, byte[] visualParams)
{
ScenePresence newAvatar = null;
newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, visualParams, wearables);
newAvatar.IsChildAgent = child;
if (child)
{
MainLog.Instance.Verbose("SCENE", m_regInfo.RegionName + ": Creating new child agent.");
}
else
{
//newAvatar.OnSignificantClientMovement += m_LandManager.handleSignificantClientMovement;
MainLog.Instance.Verbose("SCENE", m_regInfo.RegionName + ": Creating new root agent.");
MainLog.Instance.Verbose("SCENE", m_regInfo.RegionName + ": Adding Physical agent.");
newAvatar.AddToPhysicalScene();
}
lock (Entities)
{
if (!Entities.ContainsKey(client.AgentId))
{
Entities.Add(client.AgentId, newAvatar);
}
else
{
Entities[client.AgentId] = newAvatar;
}
}
lock (ScenePresences)
{
if (ScenePresences.ContainsKey(client.AgentId))
{
ScenePresences[client.AgentId] = newAvatar;
}
else
{
ScenePresences.Add(client.AgentId, newAvatar);
}
}
return newAvatar;
}
/// <summary>
/// Request a List of all m_scenePresences in this World
/// </summary>
/// <returns></returns>
public List<ScenePresence> GetScenePresences()
{
List<ScenePresence> result = new List<ScenePresence>(ScenePresences.Values);
return result;
}
public List<ScenePresence> GetAvatars()
{
List<ScenePresence> result =
GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
return result;
}
/// <summary>
/// Request a filtered list of m_scenePresences in this World
/// </summary>
/// <returns></returns>
public List<ScenePresence> GetScenePresences(FilterAvatarList filter)
{
List<ScenePresence> result = new List<ScenePresence>();
foreach (ScenePresence avatar in ScenePresences.Values)
{
if (filter(avatar))
{
result.Add(avatar);
}
}
return result;
}
/// <summary>
/// Request a Avatar by UUID
/// </summary>
/// <param name="avatarID"></param>
/// <returns></returns>
public ScenePresence GetScenePresence(LLUUID avatarID)
{
if (ScenePresences.ContainsKey(avatarID))
{
return ScenePresences[avatarID];
}
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;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
return ((SceneObjectGroup)ent).GetChildPart(localID);
}
}
}
return null;
}
public SceneObjectPart GetSceneObjectPart(LLUUID fullID)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(fullID);
if (hasPrim != false)
{
return ((SceneObjectGroup)ent).GetChildPart(fullID);
}
}
}
return null;
}
internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar)
{
ScenePresence presence;
if (ScenePresences.TryGetValue(avatarId, out presence))
{
if (!presence.IsChildAgent)
{
avatar = presence;
return true;
}
}
avatar = null;
return false;
}
internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
{
foreach (ScenePresence presence in ScenePresences.Values)
{
if (!presence.IsChildAgent)
{
string name = presence.ControllingClient.FirstName + " " + presence.ControllingClient.LastName;
if (String.Compare(avatarName, name, true) == 0)
{
avatar = presence;
return true;
}
}
}
avatar = null;
return false;
}
internal void ForEachClient(Action<IClientAPI> action)
{
foreach (ScenePresence presence in ScenePresences.Values)
{
action(presence.ControllingClient);
}
}
#region Client Event handlers
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="scale"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).Resize(scale, localID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="rot"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateSingleRotation(rot, localID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="rot"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateGroupRotation(rot);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="pos"></param>
/// <param name="rot"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateGroupRotation(pos, rot);
break;
}
}
}
}
public void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateSinglePosition(pos, localID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="pos"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateGroupPosition(pos);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="texture"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateTextureEntry(localID, texture);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="packet"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
{
bool hasprim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasprim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasprim != false)
{
((SceneObjectGroup)ent).UpdatePrimFlags(localID, (ushort)packet.Type, true, packet.ToBytes());
}
}
}
//System.Console.WriteLine("Got primupdate packet: " + packet.UsePhysics.ToString());
}
public void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
{
if (PermissionsMngr.CanEditObject(remoteClient.AgentId, objectID))
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(objectID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).GrabMovement(offset, pos, remoteClient);
break;
}
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="primLocalID"></param>
/// <param name="description"></param>
public void PrimName(uint primLocalID, string name)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).SetPartName(name, primLocalID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="primLocalID"></param>
/// <param name="description"></param>
public void PrimDescription(uint primLocalID, string description)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).SetPartDescription(description, primLocalID);
break;
}
}
}
}
public void UpdateExtraParam(uint primLocalID, ushort type, bool inUse, byte[] data)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateExtraParam(primLocalID, type, inUse, data);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="primLocalID"></param>
/// <param name="shapeBlock"></param>
public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateShape(shapeBlock, primLocalID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="parentPrim"></param>
/// <param name="childPrims"></param>
public void LinkObjects(uint parentPrim, List<uint> childPrims)
{
SceneObjectGroup parenPrim = null;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup)ent).LocalId == parentPrim)
{
parenPrim = (SceneObjectGroup)ent;
break;
}
}
}
List<SceneObjectGroup> children = new List<SceneObjectGroup>();
if (parenPrim != null)
{
for (int i = 0; i < childPrims.Count; i++)
{
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup)ent).LocalId == childPrims[i])
{
children.Add((SceneObjectGroup)ent);
}
}
}
}
}
foreach (SceneObjectGroup sceneObj in children)
{
parenPrim.LinkToGroup(sceneObj);
}
}
/// <summary>
///
/// </summary>
/// <param name="originalPrim"></param>
/// <param name="offset"></param>
/// <param name="flags"></param>
public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags)
{
SceneObjectGroup originPrim = null;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup)ent).LocalId == originalPrim)
{
originPrim = (SceneObjectGroup)ent;
break;
}
}
}
if (originPrim != null)
{
SceneObjectGroup copy = originPrim.Copy();
copy.AbsolutePosition = copy.AbsolutePosition + offset;
Entities.Add(copy.UUID, copy);
copy.ScheduleGroupForFullUpdate();
}
else
{
MainLog.Instance.Warn("client", "Attempted to duplicate nonexistant prim");
}
}
#endregion
}
}

View File

@ -89,129 +89,6 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// <summary>
///
/// </summary>
/// <param name="originalPrim"></param>
/// <param name="offset"></param>
/// <param name="flags"></param>
public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags)
{
SceneObjectGroup originPrim = null;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup) ent).LocalId == originalPrim)
{
originPrim = (SceneObjectGroup) ent;
break;
}
}
}
if (originPrim != null)
{
SceneObjectGroup copy = originPrim.Copy();
copy.AbsolutePosition = copy.AbsolutePosition + offset;
Entities.Add(copy.UUID, copy);
copy.ScheduleGroupForFullUpdate();
/* List<ScenePresence> avatars = this.GetScenePresences();
for (int i = 0; i < avatars.Count; i++)
{
// copy.SendAllChildPrimsToClient(avatars[i].ControllingClient);
}*/
}
else
{
MainLog.Instance.Warn("client", "Attempted to duplicate nonexistant prim");
}
}
/// <summary>
///
/// </summary>
/// <param name="parentPrim"></param>
/// <param name="childPrims"></param>
public void LinkObjects(uint parentPrim, List<uint> childPrims)
{
SceneObjectGroup parenPrim = null;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup) ent).LocalId == parentPrim)
{
parenPrim = (SceneObjectGroup) ent;
break;
}
}
}
List<SceneObjectGroup> children = new List<SceneObjectGroup>();
if (parenPrim != null)
{
for (int i = 0; i < childPrims.Count; i++)
{
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup) ent).LocalId == childPrims[i])
{
children.Add((SceneObjectGroup) ent);
}
}
}
}
}
foreach (SceneObjectGroup sceneObj in children)
{
parenPrim.LinkToGroup(sceneObj);
}
}
/// <summary>
///
/// </summary>
/// <param name="primLocalID"></param>
/// <param name="shapeBlock"></param>
public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateShape(shapeBlock, primLocalID);
break;
}
}
}
}
public void UpdateExtraParam(uint primLocalID, ushort type, bool inUse, byte[] data)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateExtraParam(primLocalID, type, inUse, data);
break;
}
}
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -255,250 +132,6 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// <summary>
///
/// </summary>
/// <param name="primLocalID"></param>
/// <param name="description"></param>
public void PrimDescription(uint primLocalID, string description)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).SetPartDescription(description, primLocalID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="primLocalID"></param>
/// <param name="description"></param>
public void PrimName(uint primLocalID, string name)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).SetPartName(name, primLocalID);
break;
}
}
}
}
public void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
{
if (PermissionsMngr.CanEditObject(remoteClient.AgentId, objectID))
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(objectID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).GrabMovement(offset, pos, remoteClient);
break;
}
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="packet"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
{
bool hasprim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasprim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasprim != false)
{
((SceneObjectGroup) ent).UpdatePrimFlags(localID, (ushort) packet.Type, true, packet.ToBytes());
}
}
}
//System.Console.WriteLine("Got primupdate packet: " + packet.UsePhysics.ToString());
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="texture"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateTextureEntry(localID, texture);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="pos"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateGroupPosition(pos);
break;
}
}
}
}
public void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateSinglePosition(pos, localID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="pos"></param>
/// <param name="rot"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateGroupRotation(pos, rot);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="rot"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateGroupRotation(rot);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="rot"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).UpdateSingleRotation(rot, localID);
break;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="localID"></param>
/// <param name="scale"></param>
/// <param name="remoteClient"></param>
public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
{
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup) ent).Resize(scale, localID);
break;
}
}
}
}
public void StartAnimation(LLUUID animID, int seq, LLUUID agentId) public void StartAnimation(LLUUID animID, int seq, LLUUID agentId)
{ {
Broadcast(delegate(IClientAPI client) { client.SendAnimation(animID, seq, agentId); }); Broadcast(delegate(IClientAPI client) { client.SendAnimation(animID, seq, agentId); });

View File

@ -51,13 +51,14 @@ using Timer=System.Timers.Timer;
namespace OpenSim.Region.Environment.Scenes namespace OpenSim.Region.Environment.Scenes
{ {
public delegate bool FilterAvatarList(ScenePresence avatar);
public partial class Scene : SceneBase public partial class Scene : SceneBase
{ {
public delegate bool FilterAvatarList(ScenePresence avatar); #region Fields
protected Timer m_heartbeatTimer = new Timer(); protected Timer m_heartbeatTimer = new Timer();
protected Dictionary<LLUUID, ScenePresence> m_scenePresences;
protected Dictionary<LLUUID, SceneObjectGroup> m_sceneObjects; public InnerScene m_innerScene;
private Random Rand = new Random(); private Random Rand = new Random();
private uint _primCount = 702000; private uint _primCount = 702000;
@ -66,16 +67,14 @@ namespace OpenSim.Region.Environment.Scenes
private int m_timePhase = 24; private int m_timePhase = 24;
private int m_timeUpdateCount; private int m_timeUpdateCount;
public BasicQuadTreeNode QuadTree;
private readonly Mutex updateLock; private readonly Mutex updateLock;
protected ModuleLoader m_moduleLoader; protected ModuleLoader m_moduleLoader;
protected StorageManager storageManager; protected StorageManager storageManager;
protected AgentCircuitManager authenticateHandler; protected AgentCircuitManager authenticateHandler;
protected RegionCommsListener regionCommsHost;
public CommunicationsManager commsManager; public CommunicationsManager commsManager;
// protected XferManager xferManager; // protected XferManager xferManager;
protected SceneCommunicationService m_sceneGridService;
protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>(); protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
protected BaseHttpServer httpListener; protected BaseHttpServer httpListener;
@ -111,6 +110,7 @@ namespace OpenSim.Region.Environment.Scenes
private int m_update_terrain = 50; private int m_update_terrain = 50;
private int m_update_land = 1; private int m_update_land = 1;
private int m_update_avatars = 1; private int m_update_avatars = 1;
#endregion
#region Properties #region Properties
@ -128,12 +128,16 @@ namespace OpenSim.Region.Environment.Scenes
private readonly EstateManager m_estateManager; private readonly EstateManager m_estateManager;
private PhysicsScene phyScene; private PhysicsScene phyScene
{
set { m_innerScene.PhyScene = value; }
get { return (m_innerScene.PhyScene); }
}
public PhysicsScene PhysScene public PhysicsScene PhysScene
{ {
set { phyScene = value; } set { m_innerScene.PhyScene = value; }
get { return (phyScene); } get { return (m_innerScene.PhyScene); }
} }
public EstateManager EstateManager public EstateManager EstateManager
@ -148,21 +152,39 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_permissionManager; } get { return m_permissionManager; }
} }
public Dictionary<LLUUID, SceneObjectGroup> Objects
{
get { return m_sceneObjects; }
}
public int TimePhase public int TimePhase
{ {
get { return m_timePhase; } get { return m_timePhase; }
} }
public Dictionary<LLUUID, SceneObjectGroup> Objects
{
get { return m_innerScene.SceneObjects; }
}
protected Dictionary<LLUUID, ScenePresence> m_scenePresences
{
get { return m_innerScene.ScenePresences; }
set { m_innerScene.ScenePresences = value; }
}
protected Dictionary<LLUUID, SceneObjectGroup> m_sceneObjects
{
get { return m_innerScene.SceneObjects; }
set { m_innerScene.SceneObjects = value; }
}
public Dictionary<LLUUID, EntityBase> Entities
{
get { return m_innerScene.Entities; }
set { m_innerScene.Entities = value; }
}
#endregion #endregion
#region Constructors #region Constructors
public Scene(RegionInfo regInfo, AgentCircuitManager authen, CommunicationsManager commsMan, public Scene(RegionInfo regInfo, AgentCircuitManager authen, CommunicationsManager commsMan, SceneCommunicationService sceneGridService,
AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer, AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer,
ModuleLoader moduleLoader, bool dumpAssetsToFile) ModuleLoader moduleLoader, bool dumpAssetsToFile)
{ {
@ -171,6 +193,7 @@ namespace OpenSim.Region.Environment.Scenes
m_moduleLoader = moduleLoader; m_moduleLoader = moduleLoader;
authenticateHandler = authen; authenticateHandler = authen;
commsManager = commsMan; commsManager = commsMan;
m_sceneGridService = sceneGridService;
storageManager = storeManager; storageManager = storeManager;
assetCache = assetCach; assetCache = assetCach;
m_regInfo = regInfo; m_regInfo = regInfo;
@ -184,15 +207,13 @@ 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_eventManager.OnParcelPrimCountAdd += m_eventManager.OnParcelPrimCountAdd +=
m_LandManager.addPrimToLandPrimCounts; m_LandManager.addPrimToLandPrimCounts;
m_eventManager.OnPermissionError += SendPermissionAlert; m_eventManager.OnPermissionError += SendPermissionAlert;
QuadTree = new BasicQuadTreeNode(null, "/0/", 0, 0, 256, 256);
QuadTree.Subdivide();
QuadTree.Subdivide();
MainLog.Instance.Verbose("Creating new entitities instance"); MainLog.Instance.Verbose("Creating new entitities instance");
Entities = new Dictionary<LLUUID, EntityBase>(); Entities = new Dictionary<LLUUID, EntityBase>();
m_scenePresences = new Dictionary<LLUUID, ScenePresence>(); m_scenePresences = new Dictionary<LLUUID, ScenePresence>();
@ -209,6 +230,26 @@ namespace OpenSim.Region.Environment.Scenes
#endregion #endregion
#region Startup / Close Methods
public override void Close()
{
m_heartbeatTimer.Close();
m_innerScene.Close();
m_sceneGridService.Close();
base.Close();
}
/// <summary>
///
/// </summary>
public void StartTimer()
{
m_heartbeatTimer.Enabled = true;
m_heartbeatTimer.Interval = (int)(m_timespan * 1000);
m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
}
public void SetModuleInterfaces() public void SetModuleInterfaces()
{ {
m_simChatModule = RequestModuleInterface<ISimChat>(); m_simChatModule = RequestModuleInterface<ISimChat>();
@ -218,25 +259,8 @@ namespace OpenSim.Region.Environment.Scenes
XferManager = RequestModuleInterface<IXfer>(); XferManager = RequestModuleInterface<IXfer>();
} }
#region Script Handling Methods
public void SendCommandToPlugins(string[] args)
{
m_eventManager.TriggerOnPluginConsole(args);
}
#endregion #endregion
/// <summary>
///
/// </summary>
public void StartTimer()
{
m_heartbeatTimer.Enabled = true;
m_heartbeatTimer.Interval = (int) (m_timespan*1000);
m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
}
#region Update Methods #region Update Methods
/// <summary> /// <summary>
@ -597,38 +621,17 @@ namespace OpenSim.Region.Environment.Scenes
public void RemovePrim(uint localID, LLUUID avatar_deleter) public void RemovePrim(uint localID, LLUUID avatar_deleter)
{ {
foreach (EntityBase obj in Entities.Values) m_innerScene.RemovePrim(localID, avatar_deleter);
{
if (obj is SceneObjectGroup)
{
if (((SceneObjectGroup) obj).LocalId == localID)
{
RemoveEntity((SceneObjectGroup) obj);
return;
}
}
}
} }
public void AddEntityFromStorage(SceneObjectGroup sceneObject) public void AddEntityFromStorage(SceneObjectGroup sceneObject)
{ {
sceneObject.RegionHandle = m_regionHandle; m_innerScene.AddEntityFromStorage(sceneObject);
sceneObject.SetScene(this);
foreach (SceneObjectPart part in sceneObject.Children.Values)
{
part.LocalID = PrimIDAllocate();
}
sceneObject.UpdateParentIDs();
AddEntity(sceneObject);
} }
public void AddEntity(SceneObjectGroup sceneObject) public void AddEntity(SceneObjectGroup sceneObject)
{ {
if (!Entities.ContainsKey(sceneObject.UUID)) m_innerScene.AddEntity(sceneObject);
{
// QuadTree.AddObject(sceneObject);
Entities.Add(sceneObject.UUID, sceneObject);
}
} }
public void RemoveEntity(SceneObjectGroup sceneObject) public void RemoveEntity(SceneObjectGroup sceneObject)
@ -797,31 +800,30 @@ namespace OpenSim.Region.Environment.Scenes
client.OnRegionHandShakeReply += SendLayerData; client.OnRegionHandShakeReply += SendLayerData;
//remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims); //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
client.OnModifyTerrain += ModifyTerrain; client.OnModifyTerrain += ModifyTerrain;
//client.OnChatFromViewer += SimChat; // client.OnRequestWearables += InformClientOfNeighbours;
client.OnRequestWearables += InformClientOfNeighbours;
client.OnAddPrim += AddNewPrim; client.OnAddPrim += AddNewPrim;
client.OnUpdatePrimGroupPosition += UpdatePrimPosition; client.OnUpdatePrimGroupPosition += m_innerScene.UpdatePrimPosition;
client.OnUpdatePrimSinglePosition += UpdatePrimSinglePosition; client.OnUpdatePrimSinglePosition += m_innerScene.UpdatePrimSinglePosition;
client.OnUpdatePrimGroupRotation += UpdatePrimRotation; client.OnUpdatePrimGroupRotation += m_innerScene.UpdatePrimRotation;
client.OnUpdatePrimGroupMouseRotation += UpdatePrimRotation; client.OnUpdatePrimGroupMouseRotation += m_innerScene.UpdatePrimRotation;
client.OnUpdatePrimSingleRotation += UpdatePrimSingleRotation; client.OnUpdatePrimSingleRotation += m_innerScene.UpdatePrimSingleRotation;
client.OnUpdatePrimScale += UpdatePrimScale; client.OnUpdatePrimScale += m_innerScene.UpdatePrimScale;
client.OnUpdateExtraParams += UpdateExtraParam; client.OnUpdateExtraParams += m_innerScene.UpdateExtraParam;
client.OnUpdatePrimShape += UpdatePrimShape; client.OnUpdatePrimShape += m_innerScene.UpdatePrimShape;
client.OnRequestMapBlocks += RequestMapBlocks; client.OnRequestMapBlocks += RequestMapBlocks;
client.OnUpdatePrimTexture += UpdatePrimTexture; client.OnUpdatePrimTexture += m_innerScene.UpdatePrimTexture;
client.OnTeleportLocationRequest += RequestTeleportLocation; client.OnTeleportLocationRequest += RequestTeleportLocation;
client.OnObjectSelect += SelectPrim; client.OnObjectSelect += SelectPrim;
client.OnObjectDeselect += DeselectPrim; client.OnObjectDeselect += DeselectPrim;
client.OnGrabUpdate += MoveObject; client.OnGrabUpdate += m_innerScene.MoveObject;
client.OnDeRezObject += DeRezObject; client.OnDeRezObject += DeRezObject;
client.OnRezObject += RezObject; client.OnRezObject += RezObject;
client.OnNameFromUUIDRequest += commsManager.HandleUUIDNameRequest; client.OnNameFromUUIDRequest += commsManager.HandleUUIDNameRequest;
client.OnObjectDescription += PrimDescription; client.OnObjectDescription += m_innerScene.PrimDescription;
client.OnObjectName += PrimName; client.OnObjectName += m_innerScene.PrimName;
client.OnLinkObjects += LinkObjects; client.OnLinkObjects += m_innerScene.LinkObjects;
client.OnObjectDuplicate += DuplicateObject; client.OnObjectDuplicate += m_innerScene.DuplicateObject;
client.OnUpdatePrimFlags += UpdatePrimFlags; client.OnUpdatePrimFlags += m_innerScene.UpdatePrimFlags;
client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_LandManager.handleParcelPropertiesRequest); client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_LandManager.handleParcelPropertiesRequest);
client.OnParcelDivideRequest += new ParcelDivideRequest(m_LandManager.handleParcelDivideRequest); client.OnParcelDivideRequest += new ParcelDivideRequest(m_LandManager.handleParcelDivideRequest);
@ -845,8 +847,6 @@ namespace OpenSim.Region.Environment.Scenes
client.OnRezScript += RezScript; client.OnRezScript += RezScript;
client.OnRemoveTaskItem += RemoveTaskInventory; client.OnRemoveTaskItem += RemoveTaskInventory;
// client.OnRequestAvatarProperties += RequestAvatarProperty;
client.OnGrabObject += ProcessObjectGrab; client.OnGrabObject += ProcessObjectGrab;
EventManager.TriggerOnNewClient(client); EventManager.TriggerOnNewClient(client);
@ -865,44 +865,11 @@ namespace OpenSim.Region.Environment.Scenes
AvatarFactoryModule.GetDefaultAvatarAppearance(out wearables, out visualParams); AvatarFactoryModule.GetDefaultAvatarAppearance(out wearables, out visualParams);
} }
newAvatar = new ScenePresence(client, this, m_regInfo, visualParams, wearables); newAvatar = m_innerScene.CreateAndAddScenePresence(client, child, wearables, visualParams);
newAvatar.IsChildAgent = child;
if (child) if (!newAvatar.IsChildAgent)
{
MainLog.Instance.Verbose("SCENE", RegionInfo.RegionName + ": Creating new child agent.");
}
else
{ {
newAvatar.OnSignificantClientMovement += m_LandManager.handleSignificantClientMovement; newAvatar.OnSignificantClientMovement += m_LandManager.handleSignificantClientMovement;
MainLog.Instance.Verbose("SCENE", RegionInfo.RegionName + ": Creating new root agent.");
MainLog.Instance.Verbose("SCENE", RegionInfo.RegionName + ": Adding Physical agent.");
newAvatar.AddToPhysicalScene();
}
lock (Entities)
{
if (!Entities.ContainsKey(client.AgentId))
{
Entities.Add(client.AgentId, newAvatar);
}
else
{
Entities[client.AgentId] = newAvatar;
}
}
lock (m_scenePresences)
{
if (m_scenePresences.ContainsKey(client.AgentId))
{
m_scenePresences[client.AgentId] = newAvatar;
}
else
{
m_scenePresences.Add(client.AgentId, newAvatar);
}
} }
return newAvatar; return newAvatar;
@ -942,87 +909,13 @@ namespace OpenSim.Region.Environment.Scenes
return; return;
} }
public void NotifyMyCoarseLocationChange()
{
ForEachScenePresence(delegate(ScenePresence presence) { presence.CoarseLocationChange(); });
}
#endregion #endregion
#region Request m_scenePresences List Methods #region Entities
//The idea is to have a group of method that return a list of avatars meeting some requirement
// ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
/// <summary>
/// Request a List of all m_scenePresences in this World
/// </summary>
/// <returns></returns>
public List<ScenePresence> GetScenePresences()
{
List<ScenePresence> result = new List<ScenePresence>(m_scenePresences.Values);
return result;
}
public List<ScenePresence> GetAvatars()
{
List<ScenePresence> result =
GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
return result;
}
/// <summary>
/// Request a filtered list of m_scenePresences in this World
/// </summary>
/// <returns></returns>
public List<ScenePresence> GetScenePresences(FilterAvatarList filter)
{
List<ScenePresence> result = new List<ScenePresence>();
foreach (ScenePresence avatar in m_scenePresences.Values)
{
if (filter(avatar))
{
result.Add(avatar);
}
}
return result;
}
/// <summary>
/// Request a Avatar by UUID
/// </summary>
/// <param name="avatarID"></param>
/// <returns></returns>
public ScenePresence GetScenePresence(LLUUID avatarID)
{
if (m_scenePresences.ContainsKey(avatarID))
{
return m_scenePresences[avatarID];
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="action"></param>
public void ForEachScenePresence(Action<ScenePresence> action)
{
foreach (ScenePresence presence in m_scenePresences.Values)
{
action(presence);
}
}
public void ForEachObject(Action<SceneObjectGroup> action)
{
foreach (SceneObjectGroup presence in m_sceneObjects.Values)
{
action(presence);
}
}
#endregion
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -1044,36 +937,18 @@ namespace OpenSim.Region.Environment.Scenes
Broadcast(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); }); Broadcast(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); });
} }
public void NotifyMyCoarseLocationChange() #endregion
{
ForEachScenePresence(delegate(ScenePresence presence) { presence.CoarseLocationChange(); });
}
public void SendAllSceneObjectsToClient(ScenePresence presence) #region RegionComms
{
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
// ((SceneObjectGroup)ent).SendFullUpdateToClient(client);
((SceneObjectGroup) ent).ScheduleFullUpdateToAvatar(presence);
}
}
}
#region RegionCommsHost
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public void RegisterRegionWithComms() public void RegisterRegionWithComms()
{ {
regionCommsHost = commsManager.GridService.RegisterRegion(m_regInfo); m_sceneGridService.RegisterRegion(m_regInfo);
if (regionCommsHost != null) m_sceneGridService.OnExpectUser += NewUserConnection;
{ m_sceneGridService.OnAvatarCrossingIntoRegion += AgentCrossing;
regionCommsHost.OnExpectUser += NewUserConnection;
regionCommsHost.OnAvatarCrossingIntoRegion += AgentCrossing;
}
} }
/// <summary> /// <summary>
@ -1083,27 +958,23 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="agent"></param> /// <param name="agent"></param>
public void NewUserConnection(ulong regionHandle, AgentCircuitData agent) public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
{ {
// Console.WriteLine("Scene.cs - add new user connection");
//should just check that its meant for this region
if (regionHandle == m_regInfo.RegionHandle) if (regionHandle == m_regInfo.RegionHandle)
{ {
if (agent.CapsPath != "") if (agent.CapsPath != "")
{ {
//Console.WriteLine("new user, so creating caps handler for it");
Caps cap = Caps cap =
new Caps(commsManager.AssetCache, httpListener, m_regInfo.ExternalHostName, httpListener.Port, new Caps(commsManager.AssetCache, httpListener, m_regInfo.ExternalHostName, httpListener.Port,
agent.CapsPath, agent.AgentID, m_dumpAssetsToFile); agent.CapsPath, agent.AgentID, m_dumpAssetsToFile);
Util.SetCapsURL(agent.AgentID, Util.SetCapsURL(agent.AgentID, "http://" + m_regInfo.ExternalHostName + ":" + httpListener.Port.ToString() +
"http://" + m_regInfo.ExternalHostName + ":" + httpListener.Port.ToString() +
"/CAPS/" + agent.CapsPath + "0000/"); "/CAPS/" + agent.CapsPath + "0000/");
cap.RegisterHandlers(); cap.RegisterHandlers();
cap.AddNewInventoryItem = AddInventoryItem; cap.AddNewInventoryItem = AddInventoryItem;
cap.ItemUpdatedCall = CapsUpdateInventoryItemAsset; cap.ItemUpdatedCall = CapsUpdateInventoryItemAsset;
if (capsHandlers.ContainsKey(agent.AgentID)) if (capsHandlers.ContainsKey(agent.AgentID))
{ {
MainLog.Instance.Warn("client", "Adding duplicate CAPS entry for user " + //MainLog.Instance.Warn("client", "Adding duplicate CAPS entry for user " +
agent.AgentID.ToStringHyphenated()); // agent.AgentID.ToStringHyphenated());
capsHandlers[agent.AgentID] = cap; capsHandlers[agent.AgentID] = cap;
} }
else else
@ -1126,61 +997,13 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
private delegate void InformClientOfNeighbourDelegate(
IClientAPI remoteClient, AgentCircuitData a, ulong regionHandle, IPEndPoint endPoint);
private void InformClientOfNeighbourCompleted(IAsyncResult iar)
{
InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate) iar.AsyncState;
icon.EndInvoke(iar);
}
/// <summary>
/// Async compnent for informing client of which neighbours exists
/// </summary>
/// <remarks>
/// This needs to run asynchronesously, as a network timeout may block the thread for a long while
/// </remarks>
/// <param name="remoteClient"></param>
/// <param name="a"></param>
/// <param name="regionHandle"></param>
/// <param name="endPoint"></param>
private void InformClientOfNeighbourAsync(IClientAPI remoteClient, AgentCircuitData a, ulong regionHandle,
IPEndPoint endPoint)
{
MainLog.Instance.Notice("INTERGRID", "Starting to inform client about neighbours");
bool regionAccepted = commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, a);
if (regionAccepted)
remoteClient.InformClientOfNeighbour(regionHandle, endPoint);
MainLog.Instance.Notice("INTERGRID", "Completed inform client about neighbours");
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public void InformClientOfNeighbours(IClientAPI remoteClient) public void InformClientOfNeighbours(ScenePresence presence)
{ {
List<SimpleRegionInfo> neighbours = m_sceneGridService.InformClientOfNeighbours(presence);
commsManager.GridService.RequestNeighbours(m_regInfo.RegionLocX, m_regInfo.RegionLocY);
if (neighbours != null)
{
for (int i = 0; i < neighbours.Count; i++)
{
AgentCircuitData agent = remoteClient.RequestClientInfo();
agent.BaseFolder = LLUUID.Zero;
agent.InventoryFolder = LLUUID.Zero;
agent.startpos = new LLVector3(128, 128, 70);
agent.child = true;
InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
d.BeginInvoke(remoteClient, agent, neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint,
InformClientOfNeighbourCompleted,
d);
}
}
} }
/// <summary> /// <summary>
@ -1190,7 +1013,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <returns></returns> /// <returns></returns>
public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle) public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
{ {
return commsManager.GridService.RequestNeighbourInfo(regionHandle); return m_sceneGridService.RequestNeighbouringRegionInfo(regionHandle);
} }
/// <summary> /// <summary>
@ -1202,9 +1025,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="maxY"></param> /// <param name="maxY"></param>
public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY) public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
{ {
List<MapBlockData> mapBlocks; m_sceneGridService.RequestMapBlocks(remoteClient, minX, minY, maxX, maxX);
mapBlocks = commsManager.GridService.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
remoteClient.SendMapBlock(mapBlocks);
} }
/// <summary> /// <summary>
@ -1218,34 +1039,9 @@ namespace OpenSim.Region.Environment.Scenes
public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position,
LLVector3 lookAt, uint flags) LLVector3 lookAt, uint flags)
{ {
if (regionHandle == m_regionHandle) if (m_scenePresences.ContainsKey(remoteClient.AgentId))
{ {
if (m_scenePresences.ContainsKey(remoteClient.AgentId)) m_sceneGridService.RequestTeleportLocation(m_scenePresences[remoteClient.AgentId], regionHandle, position, lookAt, flags);
{
remoteClient.SendTeleportLocationStart();
remoteClient.SendLocalTeleport(position, lookAt, flags);
m_scenePresences[remoteClient.AgentId].Teleport(position);
}
}
else
{
RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle);
if (reg != null)
{
remoteClient.SendTeleportLocationStart();
AgentCircuitData agent = remoteClient.RequestClientInfo();
agent.BaseFolder = LLUUID.Zero;
agent.InventoryFolder = LLUUID.Zero;
// agent.startpos = new LLVector3(128, 128, 70);
agent.startpos = position;
agent.child = true;
m_scenePresences[remoteClient.AgentId].Close();
commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position, false);
AgentCircuitData circuitdata = remoteClient.RequestClientInfo();
string capsPath = Util.GetCapsURL(remoteClient.AgentId);
remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4), capsPath);
}
} }
} }
@ -1257,19 +1053,12 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="position"></param> /// <param name="position"></param>
public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying) public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying)
{ {
return commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying); return m_sceneGridService.InformNeighbourOfCrossing(regionhandle, agentID, position, isFlying);
}
public void performParcelPrimCountUpdate()
{
m_LandManager.resetAllLandPrimCounts();
m_eventManager.TriggerParcelPrimCountUpdate();
m_LandManager.finalizeLandPrimCountUpdate();
m_LandManager.landPrimCountTainted = false;
} }
#endregion #endregion
#region Module Methods
public void AddModule(string name, IRegionModule module) public void AddModule(string name, IRegionModule module)
{ {
if (!Modules.ContainsKey(name)) if (!Modules.ContainsKey(name))
@ -1297,7 +1086,9 @@ namespace OpenSim.Region.Environment.Scenes
return default(T); return default(T);
} }
} }
#endregion
#region Other Methods
public void SetTimePhase(int phase) public void SetTimePhase(int phase)
{ {
m_timePhase = phase; m_timePhase = phase;
@ -1313,6 +1104,26 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public LLUUID MakeHttpRequest(string url, string type, string body)
{
if (m_httpRequestModule != null)
{
return m_httpRequestModule.MakeHttpRequest(url, type, body);
}
return LLUUID.Zero;
}
public void performParcelPrimCountUpdate()
{
m_LandManager.resetAllLandPrimCounts();
m_eventManager.TriggerParcelPrimCountUpdate();
m_LandManager.finalizeLandPrimCountUpdate();
m_LandManager.landPrimCountTainted = false;
}
#endregion
#region Console Commands
#region Alert Methods #region Alert Methods
private void SendPermissionAlert(LLUUID user, string reason) private void SendPermissionAlert(LLUUID user, string reason)
@ -1444,15 +1255,17 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public LLUUID MakeHttpRequest(string url, string type, string body) #endregion
#region Script Handling Methods
public void SendCommandToPlugins(string[] args)
{ {
if (m_httpRequestModule != null) m_eventManager.TriggerOnPluginConsole(args);
{
return m_httpRequestModule.MakeHttpRequest(url, type, body);
}
return LLUUID.Zero;
} }
#endregion
#region Script Engine #region Script Engine
private List<ScriptEngineInterface> ScriptEngines = new List<ScriptEngineInterface>(); private List<ScriptEngineInterface> ScriptEngines = new List<ScriptEngineInterface>();
@ -1467,106 +1280,100 @@ namespace OpenSim.Region.Environment.Scenes
#endregion #endregion
#region InnerScene wrapper methods
public LLUUID ConvertLocalIDToFullID(uint localID) public LLUUID ConvertLocalIDToFullID(uint localID)
{ {
bool hasPrim = false; return m_innerScene.ConvertLocalIDToFullID(localID);
foreach (EntityBase ent in Entities.Values) }
public void SendAllSceneObjectsToClient(ScenePresence presence)
{
m_innerScene.SendAllSceneObjectsToClient(presence);
}
//The idea is to have a group of method that return a list of avatars meeting some requirement
// ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
public List<ScenePresence> GetAvatars()
{
return m_innerScene.GetAvatars();
}
/// <summary>
/// Request a List of all m_scenePresences in this World
/// </summary>
/// <returns></returns>
public List<ScenePresence> GetScenePresences()
{
return m_innerScene.GetScenePresences();
}
/// <summary>
/// Request a filtered list of m_scenePresences in this World
/// </summary>
/// <returns></returns>
public List<ScenePresence> GetScenePresences(FilterAvatarList filter)
{
return m_innerScene.GetScenePresences(filter);
}
/// <summary>
/// Request a Avatar by UUID
/// </summary>
/// <param name="avatarID"></param>
/// <returns></returns>
public ScenePresence GetScenePresence(LLUUID avatarID)
{
return m_innerScene.GetScenePresence(avatarID);
}
/// <summary>
///
/// </summary>
/// <param name="action"></param>
public void ForEachScenePresence(Action<ScenePresence> action)
{
foreach (ScenePresence presence in m_scenePresences.Values)
{ {
if (ent is SceneObjectGroup) action(presence);
{ }
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID); }
if (hasPrim != false)
{ public void ForEachObject(Action<SceneObjectGroup> action)
return ((SceneObjectGroup) ent).GetPartsFullID(localID); {
} foreach (SceneObjectGroup presence in m_sceneObjects.Values)
} {
action(presence);
} }
return LLUUID.Zero;
} }
public SceneObjectPart GetSceneObjectPart(uint localID) public SceneObjectPart GetSceneObjectPart(uint localID)
{ {
bool hasPrim = false; return m_innerScene.GetSceneObjectPart(localID);
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
return ((SceneObjectGroup) ent).GetChildPart(localID);
}
}
}
return null;
} }
public SceneObjectPart GetSceneObjectPart(LLUUID fullID) public SceneObjectPart GetSceneObjectPart(LLUUID fullID)
{ {
bool hasPrim = false; return m_innerScene.GetSceneObjectPart(fullID);
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(fullID);
if (hasPrim != false)
{
return ((SceneObjectGroup) ent).GetChildPart(fullID);
}
}
}
return null;
} }
internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar) internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar)
{ {
ScenePresence presence; return m_innerScene.TryGetAvatar(avatarId, out avatar);
if (m_scenePresences.TryGetValue(avatarId, out presence))
{
if (!presence.IsChildAgent)
{
avatar = presence;
return true;
}
}
avatar = null;
return false;
} }
public override void Close()
{
m_heartbeatTimer.Close();
base.Close();
}
internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
{ {
foreach (ScenePresence presence in m_scenePresences.Values) return m_innerScene.TryGetAvatarByName(avatarName, out avatar);
{
if (!presence.IsChildAgent)
{
string name = presence.ControllingClient.FirstName + " " + presence.ControllingClient.LastName;
if (String.Compare(avatarName, name, true) == 0)
{
avatar = presence;
return true;
}
}
}
avatar = null;
return false;
} }
internal void ForEachClient(Action<IClientAPI> action) internal void ForEachClient(Action<IClientAPI> action)
{ {
foreach (ScenePresence presence in m_scenePresences.Values) m_innerScene.ForEachClient(action);
{
action(presence.ControllingClient);
}
} }
#endregion
} }
} }

View File

@ -37,6 +37,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
public abstract class SceneBase : IScene public abstract class SceneBase : IScene
{ {
#region Fields
private readonly ClientManager m_clientManager = new ClientManager(); private readonly ClientManager m_clientManager = new ClientManager();
public ClientManager ClientManager public ClientManager ClientManager
@ -44,7 +45,7 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_clientManager; } get { return m_clientManager; }
} }
public Dictionary<LLUUID, EntityBase> Entities; // 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;
@ -69,6 +70,8 @@ namespace OpenSim.Region.Environment.Scenes
private uint m_nextLocalId = 8880000; private uint m_nextLocalId = 8880000;
protected AssetCache assetCache; protected AssetCache assetCache;
#endregion
#region Update Methods #region Update Methods
/// <summary> /// <summary>

View File

@ -0,0 +1,212 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Communications;
namespace OpenSim.Region.Environment.Scenes
{
public class SceneCommunicationService //one instance per region
{
protected CommunicationsManager m_commsProvider;
protected RegionInfo m_regionInfo;
protected RegionCommsListener regionCommsHost;
public event AgentCrossing OnAvatarCrossingIntoRegion;
public event ExpectUserDelegate OnExpectUser;
public SceneCommunicationService(CommunicationsManager commsMan)
{
m_commsProvider = commsMan;
}
public void RegisterRegion(RegionInfo regionInfos)
{
m_regionInfo = regionInfos;
regionCommsHost = m_commsProvider.GridService.RegisterRegion(m_regionInfo);
if (regionCommsHost != null)
{
regionCommsHost.OnExpectUser += NewUserConnection;
regionCommsHost.OnAvatarCrossingIntoRegion += AgentCrossing;
}
}
public void Close()
{
regionCommsHost.OnExpectUser -= NewUserConnection;
regionCommsHost.OnAvatarCrossingIntoRegion -= AgentCrossing;
//regionCommsHost.RemoveRegion(m_regionInfo); //TODO add to method to commsManager
regionCommsHost = null;
}
#region CommsManager Event handlers
/// <summary>
///
/// </summary>
/// <param name="regionHandle"></param>
/// <param name="agent"></param>
public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
{
if (OnExpectUser != null)
{
OnExpectUser(regionHandle, agent);
}
}
public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
{
if (OnAvatarCrossingIntoRegion != null)
{
OnAvatarCrossingIntoRegion(regionHandle, agentID, position, isFlying);
}
}
#endregion
#region Inform Client of Neighbours
private delegate void InformClientOfNeighbourDelegate(
ScenePresence avatar, AgentCircuitData a, ulong regionHandle, IPEndPoint endPoint);
private void InformClientOfNeighbourCompleted(IAsyncResult iar)
{
InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate)iar.AsyncState;
icon.EndInvoke(iar);
}
/// <summary>
/// Async compnent for informing client of which neighbours exists
/// </summary>
/// <remarks>
/// This needs to run asynchronesously, as a network timeout may block the thread for a long while
/// </remarks>
/// <param name="remoteClient"></param>
/// <param name="a"></param>
/// <param name="regionHandle"></param>
/// <param name="endPoint"></param>
private void InformClientOfNeighbourAsync(ScenePresence avatar, AgentCircuitData a, ulong regionHandle,
IPEndPoint endPoint)
{
MainLog.Instance.Notice("INTERGRID", "Starting to inform client about neighbours");
bool regionAccepted = m_commsProvider.InterRegion.InformRegionOfChildAgent(regionHandle, a);
if (regionAccepted)
{
avatar.ControllingClient.InformClientOfNeighbour(regionHandle, endPoint);
avatar.AddNeighbourRegion(regionHandle);
MainLog.Instance.Notice("INTERGRID", "Completed inform client about neighbours");
}
}
/// <summary>
///
/// </summary>
public void InformClientOfNeighbours(ScenePresence avatar)
{
List<SimpleRegionInfo> neighbours =
m_commsProvider.GridService.RequestNeighbours(m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
if (neighbours != null)
{
for (int i = 0; i < neighbours.Count; i++)
{
AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
agent.BaseFolder = LLUUID.Zero;
agent.InventoryFolder = LLUUID.Zero;
agent.startpos = new LLVector3(128, 128, 70);
agent.child = true;
InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
d.BeginInvoke(avatar, agent, neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint,
InformClientOfNeighbourCompleted,
d);
}
}
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="regionHandle"></param>
/// <returns></returns>
public virtual RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
{
return m_commsProvider.GridService.RequestNeighbourInfo(regionHandle);
}
/// <summary>
///
/// </summary>
/// <param name="minX"></param>
/// <param name="minY"></param>
/// <param name="maxX"></param>
/// <param name="maxY"></param>
public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
{
List<MapBlockData> mapBlocks;
mapBlocks = m_commsProvider.GridService.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
remoteClient.SendMapBlock(mapBlocks);
}
/// <summary>
///
/// </summary>
/// <param name="remoteClient"></param>
/// <param name="RegionHandle"></param>
/// <param name="position"></param>
/// <param name="lookAt"></param>
/// <param name="flags"></param>
public virtual void RequestTeleportLocation(ScenePresence avatar, ulong regionHandle, LLVector3 position,
LLVector3 lookAt, uint flags)
{
if (regionHandle == m_regionInfo.RegionHandle)
{
avatar.ControllingClient.SendTeleportLocationStart();
avatar.ControllingClient.SendLocalTeleport(position, lookAt, flags);
avatar.Teleport(position);
}
else
{
RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle);
if (reg != null)
{
avatar.ControllingClient.SendTeleportLocationStart();
AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
agent.BaseFolder = LLUUID.Zero;
agent.InventoryFolder = LLUUID.Zero;
agent.startpos = position;
agent.child = true;
avatar.Close();
m_commsProvider.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
m_commsProvider.InterRegion.ExpectAvatarCrossing(regionHandle, avatar.ControllingClient.AgentId, position, false);
AgentCircuitData circuitdata = avatar.ControllingClient.RequestClientInfo();
string capsPath = Util.GetCapsURL(avatar.ControllingClient.AgentId);
avatar.ControllingClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4), capsPath);
avatar.MakeChildAgent();
}
}
}
/// <summary>
///
/// </summary>
/// <param name="regionhandle"></param>
/// <param name="agentID"></param>
/// <param name="position"></param>
public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying)
{
return m_commsProvider.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying);
}
public void CloseAgentConnection(ScenePresence presence)
{
throw new Exception("The method or operation is not implemented.");
}
}
}

View File

@ -260,6 +260,7 @@ namespace OpenSim.Region.Environment.Scenes
public SceneObjectGroup ParentGroup public SceneObjectGroup ParentGroup
{ {
get { return m_parentGroup; } get { return m_parentGroup; }
} }
#region Constructors #region Constructors

View File

@ -42,10 +42,10 @@ namespace SimpleApp
{ {
private List<ScenePresence> m_avatars; private List<ScenePresence> m_avatars;
public MyWorld(RegionInfo regionInfo, AgentCircuitManager authen, CommunicationsManager commsMan, public MyWorld(RegionInfo regionInfo, AgentCircuitManager authen, CommunicationsManager commsMan, SceneCommunicationService sceneGridService,
AssetCache assetCach, StorageManager storeMan, BaseHttpServer httpServer, AssetCache assetCach, StorageManager storeMan, BaseHttpServer httpServer,
ModuleLoader moduleLoader) ModuleLoader moduleLoader)
: base(regionInfo, authen, commsMan, assetCach, storeMan, httpServer, moduleLoader, false) : base(regionInfo, authen, commsMan, sceneGridService, assetCach, storeMan, httpServer, moduleLoader, false)
{ {
m_avatars = new List<Avatar>(); m_avatars = new List<Avatar>();
} }

View File

@ -169,8 +169,9 @@ namespace SimpleApp
protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager, protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
AgentCircuitManager circuitManager) AgentCircuitManager circuitManager)
{ {
SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
return return
new MyWorld(regionInfo, circuitManager, m_commsManager, m_assetCache, storageManager, m_httpServer, new MyWorld(regionInfo, circuitManager, m_commsManager, sceneGridService, m_assetCache, storageManager, m_httpServer,
new ModuleLoader(m_log, m_config)); new ModuleLoader(m_log, m_config));
} }