* Added TryGetAvatar to SceneManager

* Refactored some names for clarity
afrisby
lbsa71 2007-09-20 05:02:44 +00:00
parent 604b786d89
commit 4ce0c0794a
4 changed files with 489 additions and 458 deletions

View File

@ -377,19 +377,19 @@ namespace OpenSim
switch (command) switch (command)
{ {
case "set-time": case "set-time":
m_localScenes.SetTimePhase(Convert.ToInt32(cmdparams[0])); m_localScenes.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
break; break;
case "force-update": case "force-update":
Console.WriteLine("Updating all clients"); Console.WriteLine("Updating all clients");
m_localScenes.ForceClientUpdate(); m_localScenes.ForceCurrentSceneClientUpdate();
break; break;
case "edit-scale": case "edit-scale":
if (cmdparams.Length == 4) if (cmdparams.Length == 4)
{ {
m_localScenes.HandleEditCommand(cmdparams); m_localScenes.HandleEditCommandOnCurrentScene(cmdparams);
} }
break; break;
@ -427,34 +427,34 @@ namespace OpenSim
case "save-xml": case "save-xml":
if (cmdparams.Length > 0) if (cmdparams.Length > 0)
{ {
m_localScenes.SavePrimsToXml(cmdparams[0]); m_localScenes.SaveCurrentSceneToXml(cmdparams[0]);
} }
else else
{ {
m_localScenes.SavePrimsToXml(DEFAULT_PRIM_BACKUP_FILENAME); m_localScenes.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
} }
break; break;
case "load-xml": case "load-xml":
if (cmdparams.Length > 0) if (cmdparams.Length > 0)
{ {
m_localScenes.LoadPrimsFromXml(cmdparams[0]); m_localScenes.LoadCurrentSceneFromXml(cmdparams[0]);
} }
else else
{ {
m_localScenes.LoadPrimsFromXml(DEFAULT_PRIM_BACKUP_FILENAME); m_localScenes.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME);
} }
break; break;
case "terrain": case "terrain":
if (!m_localScenes.RunTerrainCmd(cmdparams, ref result)) if (!m_localScenes.RunTerrainCmdOnCurrentScene(cmdparams, ref result))
{ {
m_log.Error(result); m_log.Error(result);
} }
break; break;
case "script": case "script":
m_localScenes.SendCommandToScripts(cmdparams); m_localScenes.SendCommandToCurrentSceneScripts(cmdparams);
break; break;
case "command-script": case "command-script":
@ -468,16 +468,16 @@ namespace OpenSim
// Treats each user as a super-admin when disabled // Treats each user as a super-admin when disabled
bool permissions = Convert.ToBoolean(cmdparams[0]); bool permissions = Convert.ToBoolean(cmdparams[0]);
m_localScenes.BypassPermissions(!permissions); m_localScenes.SetBypassPermissionsOnCurrentScene(!permissions);
break; break;
case "backup": case "backup":
m_localScenes.Backup(); m_localScenes.BackupCurrentScene();
break; break;
case "alert": case "alert":
m_localScenes.HandleAlertCommand(cmdparams); m_localScenes.HandleAlertCommandOnCurrentScene(cmdparams);
break; break;
case "create": case "create":
@ -497,7 +497,7 @@ namespace OpenSim
{ {
string regionName = this.CombineParams(cmdparams, 0); string regionName = this.CombineParams(cmdparams, 0);
if (m_localScenes.TrySetCurrentRegion(regionName)) if (m_localScenes.TrySetCurrentScene(regionName))
{ {
} }
@ -535,7 +535,7 @@ namespace OpenSim
int newDebug; int newDebug;
if (int.TryParse(args[1], out newDebug)) if (int.TryParse(args[1], out newDebug))
{ {
m_localScenes.DebugPacket(m_log, newDebug); m_localScenes.SetDebugPacketOnCurrentScene(m_log, newDebug);
} }
else else
{ {
@ -568,7 +568,7 @@ namespace OpenSim
case "users": case "users":
m_log.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP", "World")); m_log.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP", "World"));
List<ScenePresence> avatars = m_localScenes.GetAvatars(); List<ScenePresence> avatars = m_localScenes.GetCurrentSceneAvatars();
foreach (ScenePresence avatar in avatars) foreach (ScenePresence avatar in avatars)
{ {

View File

@ -48,7 +48,7 @@ using OpenSim.Region.Environment.Scenes.Scripting;
using OpenSim.Region.Environment.Types; using OpenSim.Region.Environment.Types;
using OpenSim.Region.Physics.Manager; using OpenSim.Region.Physics.Manager;
using OpenSim.Region.Terrain; using OpenSim.Region.Terrain;
using Timer=System.Timers.Timer; using Timer = System.Timers.Timer;
namespace OpenSim.Region.Environment.Scenes namespace OpenSim.Region.Environment.Scenes
{ {
@ -195,7 +195,7 @@ namespace OpenSim.Region.Environment.Scenes
Prims = new Dictionary<LLUUID, SceneObjectGroup>(); Prims = new Dictionary<LLUUID, SceneObjectGroup>();
MainLog.Instance.Verbose("Creating LandMap"); MainLog.Instance.Verbose("Creating LandMap");
Terrain = new TerrainEngine((int) RegionInfo.RegionLocX, (int) RegionInfo.RegionLocY); Terrain = new TerrainEngine((int)RegionInfo.RegionLocX, (int)RegionInfo.RegionLocY);
ScenePresence.LoadAnims(); ScenePresence.LoadAnims();
@ -254,7 +254,7 @@ namespace OpenSim.Region.Environment.Scenes
if (phyScene.IsThreaded) if (phyScene.IsThreaded)
{ {
phyScene.GetResults(); phyScene.GetResults();
/// no engines implement this, and what does it have to do with threading? possible DEAD CODE /// no engines implement this, and what does it have to do with threading? possible DEAD CODE
} }
List<EntityBase> moveEntities = new List<EntityBase>(Entities.Values); List<EntityBase> moveEntities = new List<EntityBase>(Entities.Values);
@ -313,7 +313,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
for (int y = 0; y < 16; y++) for (int y = 0; y < 16; y++)
{ {
if (Terrain.Tainted(x*16, y*16)) if (Terrain.Tainted(x * 16, y * 16))
{ {
SendLayerData(x, y, presence.ControllingClient, SendLayerData(x, y, presence.ControllingClient,
terData); terData);
@ -526,7 +526,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
AddEntityFromStorage(prim); AddEntityFromStorage(prim);
SceneObjectPart rootPart = prim.GetChildPart(prim.UUID); SceneObjectPart rootPart = prim.GetChildPart(prim.UUID);
if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
rootPart.PhysActor = phyScene.AddPrim( rootPart.PhysActor = phyScene.AddPrim(
new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
rootPart.AbsolutePosition.Z), rootPart.AbsolutePosition.Z),
@ -570,10 +570,10 @@ namespace OpenSim.Region.Environment.Scenes
// if grass or tree, make phantom // if grass or tree, make phantom
if ((rootPart.Shape.PCode == 95) || (rootPart.Shape.PCode == 255)) if ((rootPart.Shape.PCode == 95) || (rootPart.Shape.PCode == 255))
{ {
rootPart.ObjectFlags += (uint) LLObject.ObjectFlags.Phantom; rootPart.ObjectFlags += (uint)LLObject.ObjectFlags.Phantom;
} }
// if not phantom, add to physics // if not phantom, add to physics
if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
rootPart.PhysActor = rootPart.PhysActor =
phyScene.AddPrim(new PhysicsVector(pos.X, pos.Y, pos.Z), phyScene.AddPrim(new PhysicsVector(pos.X, pos.Y, pos.Z),
new PhysicsVector(shape.Scale.X, shape.Scale.Y, shape.Scale.Z), new PhysicsVector(shape.Scale.X, shape.Scale.Y, shape.Scale.Z),
@ -587,9 +587,9 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (obj is SceneObjectGroup) if (obj is SceneObjectGroup)
{ {
if (((SceneObjectGroup) obj).LocalId == localID) if (((SceneObjectGroup)obj).LocalId == localID)
{ {
RemoveEntity((SceneObjectGroup) obj); RemoveEntity((SceneObjectGroup)obj);
return; return;
} }
} }
@ -657,7 +657,7 @@ namespace OpenSim.Region.Environment.Scenes
AddEntity(obj); AddEntity(obj);
SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
rootPart.PhysActor = phyScene.AddPrim( rootPart.PhysActor = phyScene.AddPrim(
new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
rootPart.AbsolutePosition.Z), rootPart.AbsolutePosition.Z),
@ -683,7 +683,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
stream.WriteLine(((SceneObjectGroup) ent).ToXmlString()); stream.WriteLine(((SceneObjectGroup)ent).ToXmlString());
primCount++; primCount++;
} }
} }
@ -793,7 +793,7 @@ namespace OpenSim.Region.Environment.Scenes
MainLog.Instance.Verbose(RegionInfo.RegionName + ": Creating new root agent."); MainLog.Instance.Verbose(RegionInfo.RegionName + ": Creating new root agent.");
MainLog.Instance.Verbose(RegionInfo.RegionName + ": Adding Physical agent."); MainLog.Instance.Verbose(RegionInfo.RegionName + ": Adding Physical agent.");
newAvatar.AddToPhysicalScene( ); newAvatar.AddToPhysicalScene();
} }
lock (Entities) lock (Entities)
@ -835,14 +835,14 @@ namespace OpenSim.Region.Environment.Scenes
ForEachScenePresence( ForEachScenePresence(
delegate(ScenePresence presence) delegate(ScenePresence presence)
{
presence.CoarseLocationChange(avatar);
presence.ControllingClient.SendKillObject(avatar.RegionHandle, avatar.LocalId);
if (presence.PhysActor != null)
{ {
presence.CoarseLocationChange(avatar); phyScene.RemoveAvatar(presence.PhysActor);
presence.ControllingClient.SendKillObject(avatar.RegionHandle, avatar.LocalId); }
if (presence.PhysActor != null) });
{
phyScene.RemoveAvatar(presence.PhysActor);
}
});
lock (Avatars) lock (Avatars)
{ {
@ -968,7 +968,7 @@ namespace OpenSim.Region.Environment.Scenes
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
// ((SceneObjectGroup)ent).SendFullUpdateToClient(client); // ((SceneObjectGroup)ent).SendFullUpdateToClient(client);
((SceneObjectGroup) ent).ScheduleFullUpdateToAvatar(presence); ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence);
} }
} }
} }
@ -1157,17 +1157,17 @@ namespace OpenSim.Region.Environment.Scenes
public void RegisterModuleInterface<M>(M mod) public void RegisterModuleInterface<M>(M mod)
{ {
if (!ModuleInterfaces.ContainsKey(typeof (M))) if (!ModuleInterfaces.ContainsKey(typeof(M)))
{ {
ModuleInterfaces.Add(typeof (M), mod); ModuleInterfaces.Add(typeof(M), mod);
} }
} }
public T RequestModuleInterface<T>() public T RequestModuleInterface<T>()
{ {
if (ModuleInterfaces.ContainsKey(typeof (T))) if (ModuleInterfaces.ContainsKey(typeof(T)))
{ {
return (T) ModuleInterfaces[typeof (T)]; return (T)ModuleInterfaces[typeof(T)];
} }
else else
{ {
@ -1257,7 +1257,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
((SceneObjectGroup) ent).ScheduleGroupForFullUpdate(); ((SceneObjectGroup)ent).ScheduleGroupForFullUpdate();
} }
} }
} }
@ -1269,7 +1269,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
SceneObjectPart part = ((SceneObjectGroup) ent).GetChildPart(((SceneObjectGroup) ent).UUID); SceneObjectPart part = ((SceneObjectGroup)ent).GetChildPart(((SceneObjectGroup)ent).UUID);
if (part != null) if (part != null)
{ {
if (part.Name == cmmdparams[0]) if (part.Name == cmmdparams[0])
@ -1357,10 +1357,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID); hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false) if (hasPrim != false)
{ {
return ((SceneObjectGroup) ent).GetPartsFullID(localID); return ((SceneObjectGroup)ent).GetPartsFullID(localID);
} }
} }
} }
@ -1374,10 +1374,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID); hasPrim = ((SceneObjectGroup)ent).HasChildPrim(localID);
if (hasPrim != false) if (hasPrim != false)
{ {
return ((SceneObjectGroup) ent).GetChildPart(localID); return ((SceneObjectGroup)ent).GetChildPart(localID);
} }
} }
} }
@ -1391,14 +1391,30 @@ namespace OpenSim.Region.Environment.Scenes
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
hasPrim = ((SceneObjectGroup) ent).HasChildPrim(fullID); hasPrim = ((SceneObjectGroup)ent).HasChildPrim(fullID);
if (hasPrim != false) if (hasPrim != false)
{ {
return ((SceneObjectGroup) ent).GetChildPart(fullID); return ((SceneObjectGroup)ent).GetChildPart(fullID);
} }
} }
} }
return null; return null;
} }
internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar)
{
ScenePresence presence;
if (Avatars.TryGetValue(avatarId, out presence))
{
if (!presence.childAgent)
{
avatar = presence;
return true;
}
}
avatar = null;
return false;
}
} }
} }

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Framework.Types; using OpenSim.Framework.Types;
using libsecondlife;
namespace OpenSim.Region.Environment.Scenes namespace OpenSim.Region.Environment.Scenes
{ {
@ -15,7 +16,7 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_currentScene; } get { return m_currentScene; }
} }
private Scene CurrentOrFirstScene public Scene CurrentOrFirstScene
{ {
get get
{ {
@ -48,17 +49,17 @@ namespace OpenSim.Region.Environment.Scenes
m_localScenes.Add(scene); m_localScenes.Add(scene);
} }
public void SavePrimsToXml(string filename) public void SaveCurrentSceneToXml(string filename)
{ {
CurrentOrFirstScene.SavePrimsToXml(filename); CurrentOrFirstScene.SavePrimsToXml(filename);
} }
public void LoadPrimsFromXml(string filename) public void LoadCurrentSceneFromXml(string filename)
{ {
CurrentOrFirstScene.LoadPrimsFromXml(filename); CurrentOrFirstScene.LoadPrimsFromXml(filename);
} }
public bool RunTerrainCmd(string[] cmdparams, ref string result) public bool RunTerrainCmdOnCurrentScene(string[] cmdparams, ref string result)
{ {
if (m_currentScene == null) if (m_currentScene == null)
{ {
@ -79,17 +80,17 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public void SendCommandToScripts(string[] cmdparams) public void SendCommandToCurrentSceneScripts(string[] cmdparams)
{ {
ForEach(delegate(Scene scene) { scene.SendCommandToScripts(cmdparams); }); ForEachCurrentScene(delegate(Scene scene) { scene.SendCommandToScripts(cmdparams); });
} }
public void BypassPermissions(bool bypassPermissions) public void SetBypassPermissionsOnCurrentScene(bool bypassPermissions)
{ {
ForEach(delegate(Scene scene) { scene.PermissionsMngr.BypassPermissions = bypassPermissions; }); ForEachCurrentScene(delegate(Scene scene) { scene.PermissionsMngr.BypassPermissions = bypassPermissions; });
} }
private void ForEach(Action<Scene> func) private void ForEachCurrentScene(Action<Scene> func)
{ {
if (m_currentScene == null) if (m_currentScene == null)
{ {
@ -101,17 +102,17 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public void Backup() public void BackupCurrentScene()
{ {
ForEach(delegate(Scene scene) { scene.Backup(); }); ForEachCurrentScene(delegate(Scene scene) { scene.Backup(); });
} }
public void HandleAlertCommand(string[] cmdparams) public void HandleAlertCommandOnCurrentScene(string[] cmdparams)
{ {
ForEach(delegate(Scene scene) { scene.HandleAlertCommand(cmdparams); }); ForEachCurrentScene(delegate(Scene scene) { scene.HandleAlertCommand(cmdparams); });
} }
public bool TrySetCurrentRegion(string regionName) public bool TrySetCurrentScene(string regionName)
{ {
if ((String.Compare(regionName, "root") == 0) || (String.Compare(regionName, "..") == 0)) if ((String.Compare(regionName, "root") == 0) || (String.Compare(regionName, "..") == 0))
{ {
@ -135,9 +136,9 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
public void DebugPacket(LogBase log, int newDebug) public void SetDebugPacketOnCurrentScene(LogBase log, int newDebug)
{ {
ForEach(delegate(Scene scene) ForEachCurrentScene(delegate(Scene scene)
{ {
foreach (EntityBase entity in scene.Entities.Values) foreach (EntityBase entity in scene.Entities.Values)
{ {
@ -157,11 +158,11 @@ namespace OpenSim.Region.Environment.Scenes
}); });
} }
public List<ScenePresence> GetAvatars() public List<ScenePresence> GetCurrentSceneAvatars()
{ {
List<ScenePresence> avatars = new List<ScenePresence>(); List<ScenePresence> avatars = new List<ScenePresence>();
ForEach(delegate(Scene scene) ForEachCurrentScene(delegate(Scene scene)
{ {
foreach (EntityBase entity in scene.Entities.Values) foreach (EntityBase entity in scene.Entities.Values)
{ {
@ -192,9 +193,9 @@ namespace OpenSim.Region.Environment.Scenes
return null; return null;
} }
public void SetTimePhase(int timePhase) public void SetCurrentSceneTimePhase(int timePhase)
{ {
ForEach(delegate(Scene scene) ForEachCurrentScene(delegate(Scene scene)
{ {
scene.SetTimePhase( scene.SetTimePhase(
timePhase) timePhase)
@ -203,14 +204,28 @@ namespace OpenSim.Region.Environment.Scenes
} }
public void ForceClientUpdate() public void ForceCurrentSceneClientUpdate()
{ {
ForEach(delegate(Scene scene) { scene.ForceClientUpdate(); }); ForEachCurrentScene(delegate(Scene scene) { scene.ForceClientUpdate(); });
} }
public void HandleEditCommand(string[] cmdparams) public void HandleEditCommandOnCurrentScene(string[] cmdparams)
{ {
ForEach(delegate(Scene scene) { scene.HandleEditCommand(cmdparams); }); ForEachCurrentScene(delegate(Scene scene) { scene.HandleEditCommand(cmdparams); });
}
public bool TryGetAvatar( LLUUID avatarId, out ScenePresence avatar )
{
foreach (Scene scene in m_localScenes)
{
if( scene.TryGetAvatar( avatarId, out avatar ))
{
return true;
}
}
avatar = null;
return false;
} }
} }
} }