refactored some duplicate SceneObjectGroup searching code in Scene

afrisby
Jeff Ames 2007-11-07 02:42:18 +00:00
parent c0010e4940
commit f86a65f14b
2 changed files with 98 additions and 236 deletions

View File

@ -226,37 +226,47 @@ namespace OpenSim.Region.Environment.Scenes
return null; return null;
} }
public SceneObjectPart GetSceneObjectPart(uint localID) private SceneObjectGroup GetGroupByPrim(uint localID)
{ {
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in Entities.Values)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID); if (((SceneObjectGroup)ent).HasChildPrim(localID))
if (hasPrim != false) return (SceneObjectGroup)ent;
{
return ((SceneObjectGroup)ent).GetChildPart(localID);
}
} }
} }
return null; return null;
} }
public SceneObjectPart GetSceneObjectPart(LLUUID fullID) private SceneObjectGroup GetGroupByPrim(LLUUID fullID)
{ {
bool hasPrim = false;
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in Entities.Values)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(fullID); if (((SceneObjectGroup)ent).HasChildPrim(fullID))
if (hasPrim != false) return (SceneObjectGroup)ent;
}
}
return null;
}
public SceneObjectPart GetSceneObjectPart(uint localID)
{ {
return ((SceneObjectGroup)ent).GetChildPart(fullID); SceneObjectGroup group = GetGroupByPrim(localID);
} if (group != null)
} return group.GetChildPart(localID);
else
return null;
} }
public SceneObjectPart GetSceneObjectPart(LLUUID fullID)
{
SceneObjectGroup group = GetGroupByPrim(fullID);
if (group != null)
return group.GetChildPart(fullID);
else
return null; return null;
} }
@ -302,18 +312,10 @@ namespace OpenSim.Region.Environment.Scenes
public LLUUID ConvertLocalIDToFullID(uint localID) public LLUUID ConvertLocalIDToFullID(uint localID)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ return group.GetPartsFullID(localID);
if (ent is SceneObjectGroup) else
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
return ((SceneObjectGroup)ent).GetPartsFullID(localID);
}
}
}
return LLUUID.Zero; return LLUUID.Zero;
} }
@ -346,19 +348,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient) public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.Resize(scale, localID);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).Resize(scale, localID);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -369,19 +361,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient) public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateSingleRotation(rot, localID);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateSingleRotation(rot, localID);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -392,19 +374,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient) public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateGroupRotation(rot);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateGroupRotation(rot);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -416,36 +388,16 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient) public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateGroupRotation(pos, rot);
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) public void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateSinglePosition(pos, localID);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateSinglePosition(pos, localID);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -456,19 +408,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient) public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateGroupPosition(pos);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateGroupPosition(pos);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -479,19 +421,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient) public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateTextureEntry(localID, texture);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateTextureEntry(localID, texture);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -502,19 +434,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient) public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
{ {
bool hasprim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdatePrimFlags(localID, (ushort)packet.Type, true, packet.ToBytes());
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()); //System.Console.WriteLine("Got primupdate packet: " + packet.UsePhysics.ToString());
} }
@ -522,19 +444,9 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (PermissionsMngr.CanEditObject(remoteClient.AgentId, objectID)) if (PermissionsMngr.CanEditObject(remoteClient.AgentId, objectID))
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(objectID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.GrabMovement(offset, pos, remoteClient);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(objectID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).GrabMovement(offset, pos, remoteClient);
break;
}
}
}
} }
} }
@ -545,19 +457,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="description"></param> /// <param name="description"></param>
public void PrimName(uint primLocalID, string name) public void PrimName(uint primLocalID, string name)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(primLocalID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.SetPartName(name, primLocalID);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).SetPartName(name, primLocalID);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -567,36 +469,16 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="description"></param> /// <param name="description"></param>
public void PrimDescription(uint primLocalID, string description) public void PrimDescription(uint primLocalID, string description)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(primLocalID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.SetPartDescription(description, primLocalID);
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) public void UpdateExtraParam(uint primLocalID, ushort type, bool inUse, byte[] data)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(primLocalID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateExtraParam(primLocalID, type, inUse, data);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateExtraParam(primLocalID, type, inUse, data);
break;
}
}
}
} }
/// <summary> /// <summary>
@ -606,19 +488,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="shapeBlock"></param> /// <param name="shapeBlock"></param>
public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock) public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(primLocalID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ group.UpdateShape(shapeBlock, primLocalID);
if (ent is SceneObjectGroup)
{
hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
((SceneObjectGroup)ent).UpdateShape(shapeBlock, primLocalID);
break;
}
}
}
} }
/// <summary> /// <summary>

View File

@ -217,6 +217,19 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
private SceneObjectGroup GetGroupByPrim(uint localID)
{
foreach (EntityBase ent in Entities.Values)
{
if (ent is SceneObjectGroup)
{
if (((SceneObjectGroup)ent).HasChildPrim(localID))
return (SceneObjectGroup)ent;
}
}
return null;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -224,23 +237,15 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="primLocalID"></param> /// <param name="primLocalID"></param>
public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID) public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(primLocalID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ {
if (ent is SceneObjectGroup) bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
{
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(primLocalID);
if (hasPrim != false)
{
bool fileChange = ((SceneObjectGroup) ent).GetPartInventoryFileName(remoteClient, primLocalID);
if (fileChange) if (fileChange)
{ {
if (XferManager != null) if (XferManager != null)
{ {
((SceneObjectGroup) ent).RequestInventoryFile(primLocalID, XferManager); group.RequestInventoryFile(primLocalID, XferManager);
}
}
break;
} }
} }
} }
@ -248,24 +253,17 @@ namespace OpenSim.Region.Environment.Scenes
public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID) public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ {
if (ent is SceneObjectGroup) int type = group.RemoveInventoryItem(remoteClient, localID, itemID);
{ group.GetProperites(remoteClient);
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
if (hasPrim != false)
{
int type = ((SceneObjectGroup) ent).RemoveInventoryItem(remoteClient, localID, itemID);
((SceneObjectGroup) ent).GetProperites(remoteClient);
if (type == 10) if (type == 10)
{ {
EventManager.TriggerRemoveScript(localID, itemID); EventManager.TriggerRemoveScript(localID, itemID);
} }
} }
} }
}
}
public void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID) public void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID)
{ {
@ -307,20 +305,12 @@ namespace OpenSim.Region.Environment.Scenes
if (rezzed) if (rezzed)
{ {
bool hasPrim = false; SceneObjectGroup group = GetGroupByPrim(localID);
foreach (EntityBase ent in Entities.Values) if (group != null)
{ {
if (ent is SceneObjectGroup) // TODO: do we care about the value of this bool?
{ bool added = group.AddInventoryItem(remoteClient, localID, item, copyID);
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID); group.GetProperites(remoteClient);
if (hasPrim != false)
{
bool added =
((SceneObjectGroup) ent).AddInventoryItem(remoteClient, localID, item,
copyID);
((SceneObjectGroup) ent).GetProperites(remoteClient);
}
}
} }
} }
} }