Fix removeing object from scene and using existing objects
parent
ca41de0286
commit
80dfa5a0d6
|
@ -220,17 +220,21 @@ namespace Flocking
|
|||
string[] args = (cmd + " <ui>").Split (" ".ToCharArray ());
|
||||
|
||||
if (cmd.StartsWith ("stop")) {
|
||||
HandleStopCmd ("flock", args);
|
||||
HandleStopCmd (m_name, args);
|
||||
} 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")) {
|
||||
HandleSetSizeCmd ("flock", args);
|
||||
HandleSetSizeCmd (m_name, args);
|
||||
} else if (cmd.StartsWith ("stats")) {
|
||||
HandleShowStatsCmd ("flock", args);
|
||||
HandleShowStatsCmd (m_name, args);
|
||||
} else if (cmd.StartsWith ("prim")) {
|
||||
HandleSetPrimCmd ("flock", args);
|
||||
HandleSetPrimCmd (m_name, args);
|
||||
} else if (cmd.StartsWith ("framerate")) {
|
||||
HandleSetFrameRateCmd ("flock", args);
|
||||
HandleSetFrameRateCmd (m_name, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -264,24 +268,19 @@ namespace Flocking
|
|||
|
||||
private bool ShouldHandleCmd ()
|
||||
{
|
||||
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
|
||||
{
|
||||
m_log.InfoFormat("[{0}]: Command Ignored!", m_name);
|
||||
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) {
|
||||
return false;
|
||||
} else {
|
||||
m_log.InfoFormat("[{0}]: Command Executed!", m_name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsInWorldCmd (ref string [] args)
|
||||
{
|
||||
bool retVal = false;
|
||||
|
||||
if (args.Length > 0 && args [args.Length - 1].Equals ("<ui>")) {
|
||||
retVal = true;
|
||||
}
|
||||
return retVal;
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ShowResponse (string response, bool inWorld)
|
||||
|
@ -311,7 +310,6 @@ namespace Flocking
|
|||
if (!m_ready && ShouldHandleCmd())
|
||||
{
|
||||
m_log.InfoFormat("[{0}]: Bird flocking is enabled.", m_name);
|
||||
FlockInitialise();
|
||||
m_enabled = true;
|
||||
m_ready = true;
|
||||
}
|
||||
|
|
|
@ -29,23 +29,23 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using log4net;
|
||||
|
||||
namespace Flocking
|
||||
{
|
||||
public class FlockingView
|
||||
{
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private Scene m_scene;
|
||||
private UUID m_owner;
|
||||
private UUID m_owner;
|
||||
private String m_name;
|
||||
private String m_birdPrim;
|
||||
|
||||
private Dictionary<string, SceneObjectGroup> m_sogMap = new Dictionary<string, SceneObjectGroup> ();
|
||||
|
||||
public FlockingView (String moduleName, Scene scene)
|
||||
{
|
||||
{
|
||||
m_name = moduleName;
|
||||
m_scene = scene;
|
||||
}
|
||||
|
@ -63,11 +63,13 @@ namespace Flocking
|
|||
{
|
||||
//trash everything we have
|
||||
foreach (string name in m_sogMap.Keys)
|
||||
{
|
||||
m_log.InfoFormat("[{0}]: Removing prim {1} from region {2}", m_name, name, m_scene.RegionInfo.RegionName);
|
||||
RemoveSOGFromScene(name);
|
||||
{
|
||||
m_log.InfoFormat("[{0}]: Removing prim {1} from region {2}", m_name, name, m_scene.RegionInfo.RegionName);
|
||||
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)
|
||||
|
@ -82,31 +84,32 @@ namespace Flocking
|
|||
SceneObjectPart existing = m_scene.GetSceneObjectPart (bird.Id);
|
||||
|
||||
|
||||
SceneObjectGroup sog;
|
||||
SceneObjectGroup sog;
|
||||
SceneObjectPart rootPart;
|
||||
|
||||
if (existing == null) {
|
||||
SceneObjectGroup group = findByName (m_birdPrim);
|
||||
sog = CopyPrim (group, bird.Id);
|
||||
rootPart = sog.RootPart;
|
||||
//set prim to phantom
|
||||
sog = CopyPrim (group, bird.Id);
|
||||
rootPart = sog.RootPart;
|
||||
//set prim to phantom
|
||||
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_scene.AddNewSceneObject (sog, false);
|
||||
} else {
|
||||
sog = existing.ParentGroup;
|
||||
rootPart = sog.RootPart;
|
||||
//set prim to phantom
|
||||
m_sogMap[bird.Id] = sog;
|
||||
rootPart = sog.RootPart;
|
||||
//set prim to phantom
|
||||
sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false);
|
||||
}
|
||||
|
||||
Quaternion rotation = CalcRotationToEndpoint (sog, sog.AbsolutePosition, bird.Location);
|
||||
sog.UpdateGroupRotationPR( bird.Location, rotation);
|
||||
|
||||
// Fire script on_rez
|
||||
sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1);
|
||||
rootPart.ParentGroup.ResumeScripts();
|
||||
sog.UpdateGroupRotationPR( bird.Location, rotation);
|
||||
|
||||
// Fire script on_rez
|
||||
sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1);
|
||||
rootPart.ParentGroup.ResumeScripts();
|
||||
rootPart.ScheduleFullUpdate();
|
||||
}
|
||||
|
||||
|
@ -125,7 +128,7 @@ namespace Flocking
|
|||
|
||||
private SceneObjectGroup CopyPrim (SceneObjectGroup prim, string name)
|
||||
{
|
||||
SceneObjectGroup copy = prim.Copy (true);
|
||||
SceneObjectGroup copy = prim.Copy (true);
|
||||
copy.Name = name;
|
||||
copy.DetachFromBackup ();
|
||||
return copy;
|
||||
|
@ -154,7 +157,7 @@ namespace Flocking
|
|||
PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere ();
|
||||
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.DetachFromBackup ();
|
||||
m_scene.AddNewSceneObject (prim, false);
|
||||
|
@ -162,14 +165,6 @@ namespace Flocking
|
|||
return prim;
|
||||
}
|
||||
|
||||
private void RemoveSOGFromScene(string sogName)
|
||||
{
|
||||
SceneObjectGroup sog = m_sogMap[sogName];
|
||||
m_scene.DeleteSceneObject(sog, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue