Fix removeing object from scene and using existing objects

pull/1/merge
Jak Daniels 2014-12-31 21:12:20 +00:00
parent ca41de0286
commit 80dfa5a0d6
2 changed files with 43 additions and 50 deletions

View File

@ -220,17 +220,21 @@ namespace Flocking
string[] args = (cmd + " <ui>").Split (" ".ToCharArray ()); string[] args = (cmd + " <ui>").Split (" ".ToCharArray ());
if (cmd.StartsWith ("stop")) { if (cmd.StartsWith ("stop")) {
HandleStopCmd ("flock", args); HandleStopCmd (m_name, args);
} else if (cmd.StartsWith ("start")) { } else if (cmd.StartsWith ("start")) {
HandleStartCmd ("flock", args); HandleStartCmd (m_name, args);
} else if (cmd.StartsWith("enable")) {
HandleEnableCmd(m_name, args);
} else if (cmd.StartsWith("disable")) {
HandleDisableCmd(m_name, args);
} else if (cmd.StartsWith ("size")) { } else if (cmd.StartsWith ("size")) {
HandleSetSizeCmd ("flock", args); HandleSetSizeCmd (m_name, args);
} else if (cmd.StartsWith ("stats")) { } else if (cmd.StartsWith ("stats")) {
HandleShowStatsCmd ("flock", args); HandleShowStatsCmd (m_name, args);
} else if (cmd.StartsWith ("prim")) { } else if (cmd.StartsWith ("prim")) {
HandleSetPrimCmd ("flock", args); HandleSetPrimCmd (m_name, args);
} else if (cmd.StartsWith ("framerate")) { } else if (cmd.StartsWith ("framerate")) {
HandleSetFrameRateCmd ("flock", args); HandleSetFrameRateCmd (m_name, args);
} }
} }
@ -264,24 +268,19 @@ namespace Flocking
private bool ShouldHandleCmd () private bool ShouldHandleCmd ()
{ {
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) {
{
m_log.InfoFormat("[{0}]: Command Ignored!", m_name);
return false; return false;
} else {
m_log.InfoFormat("[{0}]: Command Executed!", m_name);
return true;
} }
} return true;
}
private bool IsInWorldCmd (ref string [] args) private bool IsInWorldCmd (ref string [] args)
{ {
bool retVal = false; if (args.Length > 0 && args [args.Length - 1].Equals ("<ui>")) {
m_log.InfoFormat("[{0}]: Inworld command detected in region {1}", m_name, m_scene.RegionInfo.RegionName);
if (args.Length > 0 && args [args.Length - 1].Equals ("<ui>")) { return true;
retVal = true; }
} return false;
return retVal;
} }
private void ShowResponse (string response, bool inWorld) private void ShowResponse (string response, bool inWorld)
@ -311,7 +310,6 @@ namespace Flocking
if (!m_ready && ShouldHandleCmd()) if (!m_ready && ShouldHandleCmd())
{ {
m_log.InfoFormat("[{0}]: Bird flocking is enabled.", m_name); m_log.InfoFormat("[{0}]: Bird flocking is enabled.", m_name);
FlockInitialise();
m_enabled = true; m_enabled = true;
m_ready = true; m_ready = true;
} }

View File

@ -29,23 +29,23 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using log4net; using log4net;
namespace Flocking namespace Flocking
{ {
public class FlockingView public class FlockingView
{ {
private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene; private Scene m_scene;
private UUID m_owner; private UUID m_owner;
private String m_name; private String m_name;
private String m_birdPrim; private String m_birdPrim;
private Dictionary<string, SceneObjectGroup> m_sogMap = new Dictionary<string, SceneObjectGroup> (); private Dictionary<string, SceneObjectGroup> m_sogMap = new Dictionary<string, SceneObjectGroup> ();
public FlockingView (String moduleName, Scene scene) public FlockingView (String moduleName, Scene scene)
{ {
m_name = moduleName; m_name = moduleName;
m_scene = scene; m_scene = scene;
} }
@ -63,11 +63,13 @@ namespace Flocking
{ {
//trash everything we have //trash everything we have
foreach (string name in m_sogMap.Keys) foreach (string name in m_sogMap.Keys)
{ {
m_log.InfoFormat("[{0}]: Removing prim {1} from region {2}", m_name, name, m_scene.RegionInfo.RegionName); m_log.InfoFormat("[{0}]: Removing prim {1} from region {2}", m_name, name, m_scene.RegionInfo.RegionName);
RemoveSOGFromScene(name); SceneObjectGroup sog = m_sogMap[name];
m_scene.DeleteSceneObject(sog, false);
} }
m_sogMap.Clear(); m_sogMap.Clear();
m_scene.ForceClientUpdate();
} }
public void Render (List<Bird> birds) public void Render (List<Bird> birds)
@ -82,31 +84,32 @@ namespace Flocking
SceneObjectPart existing = m_scene.GetSceneObjectPart (bird.Id); SceneObjectPart existing = m_scene.GetSceneObjectPart (bird.Id);
SceneObjectGroup sog; SceneObjectGroup sog;
SceneObjectPart rootPart; SceneObjectPart rootPart;
if (existing == null) { if (existing == null) {
SceneObjectGroup group = findByName (m_birdPrim); SceneObjectGroup group = findByName (m_birdPrim);
sog = CopyPrim (group, bird.Id); sog = CopyPrim (group, bird.Id);
rootPart = sog.RootPart; rootPart = sog.RootPart;
//set prim to phantom //set prim to phantom
sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false); sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false);
m_sogMap [bird.Id] = sog; m_sogMap [bird.Id] = sog;
m_log.InfoFormat("[{0}]: Adding prim {1} from region {2}", m_name, bird.Id, m_scene.RegionInfo.RegionName); m_log.InfoFormat("[{0}]: Adding prim {1} from region {2}", m_name, bird.Id, m_scene.RegionInfo.RegionName);
m_scene.AddNewSceneObject (sog, false); m_scene.AddNewSceneObject (sog, false);
} else { } else {
sog = existing.ParentGroup; sog = existing.ParentGroup;
rootPart = sog.RootPart; m_sogMap[bird.Id] = sog;
//set prim to phantom rootPart = sog.RootPart;
//set prim to phantom
sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false); sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false);
} }
Quaternion rotation = CalcRotationToEndpoint (sog, sog.AbsolutePosition, bird.Location); Quaternion rotation = CalcRotationToEndpoint (sog, sog.AbsolutePosition, bird.Location);
sog.UpdateGroupRotationPR( bird.Location, rotation); sog.UpdateGroupRotationPR( bird.Location, rotation);
// Fire script on_rez // Fire script on_rez
sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1); sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1);
rootPart.ParentGroup.ResumeScripts(); rootPart.ParentGroup.ResumeScripts();
rootPart.ScheduleFullUpdate(); rootPart.ScheduleFullUpdate();
} }
@ -125,7 +128,7 @@ namespace Flocking
private SceneObjectGroup CopyPrim (SceneObjectGroup prim, string name) private SceneObjectGroup CopyPrim (SceneObjectGroup prim, string name)
{ {
SceneObjectGroup copy = prim.Copy (true); SceneObjectGroup copy = prim.Copy (true);
copy.Name = name; copy.Name = name;
copy.DetachFromBackup (); copy.DetachFromBackup ();
return copy; return copy;
@ -154,7 +157,7 @@ namespace Flocking
PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere (); PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere ();
shape.Scale = new Vector3 (0.5f, 0.5f, 0.5f); shape.Scale = new Vector3 (0.5f, 0.5f, 0.5f);
SceneObjectGroup prim = new SceneObjectGroup(m_owner, new Vector3((float)m_scene.RegionInfo.RegionSizeX / 2, (float)m_scene.RegionInfo.RegionSizeY / 2, 25f), shape); SceneObjectGroup prim = new SceneObjectGroup(m_owner, new Vector3((float)m_scene.RegionInfo.RegionSizeX / 2, (float)m_scene.RegionInfo.RegionSizeY / 2, 25f), shape);
prim.Name = name; prim.Name = name;
prim.DetachFromBackup (); prim.DetachFromBackup ();
m_scene.AddNewSceneObject (prim, false); m_scene.AddNewSceneObject (prim, false);
@ -162,14 +165,6 @@ namespace Flocking
return prim; return prim;
} }
private void RemoveSOGFromScene(string sogName)
{
SceneObjectGroup sog = m_sogMap[sogName];
m_scene.DeleteSceneObject(sog, false);
}
} }
} }