Only launch a prims script(s) when adding the prim, not on every update.

Rename Bird prims to OpenSimBirdsN where N is 0-birdcount.
pull/1/merge
Jak Daniels 2015-01-02 15:11:06 +00:00
parent c487d9b945
commit 45fd724e56
2 changed files with 13 additions and 15 deletions

View File

@ -40,7 +40,7 @@ namespace Flocking
private float m_neighbourDistance; private float m_neighbourDistance;
private float m_desiredSeparation; private float m_desiredSeparation;
private float m_tolerance; private float m_tolerance;
private float m_border; private float m_border;
private string m_name; private string m_name;
private Random m_rnd = new Random(Environment.TickCount); private Random m_rnd = new Random(Environment.TickCount);
@ -56,7 +56,7 @@ namespace Flocking
} }
} }
public FlockingModel(string moduleName, float maxSpeed, float maxForce, float neighbourDistance, float desiredSeparation, float tolerance, float border) { public FlockingModel(string moduleName, float maxSpeed, float maxForce, float neighbourDistance, float desiredSeparation, float tolerance, float border) {
m_name = moduleName; m_name = moduleName;
m_maxSpeed = maxSpeed; m_maxSpeed = maxSpeed;
m_maxForce = maxForce; m_maxForce = maxForce;
@ -111,7 +111,7 @@ namespace Flocking
{ {
m_flowMap = flowMap; m_flowMap = flowMap;
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
AddBird ("Bird"+i ); AddBird (m_name + i );
} }
} }

View File

@ -87,31 +87,29 @@ namespace Flocking
SceneObjectGroup sog; SceneObjectGroup sog;
SceneObjectPart rootPart; SceneObjectPart rootPart;
if (existing == null) { if (existing == null) {
SceneObjectGroup group = findByName (m_birdPrim); m_log.InfoFormat("[{0}]: Adding prim {1} from region {2}", m_name, bird.Id, m_scene.RegionInfo.RegionName);
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_scene.AddNewSceneObject (sog, false);
m_scene.AddNewSceneObject (sog, false); // Fire script on_rez
sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1);
rootPart.ParentGroup.ResumeScripts();
rootPart.ScheduleFullUpdate();
} else { } else {
sog = existing.ParentGroup; sog = existing.ParentGroup;
m_sogMap[bird.Id] = sog; m_sogMap[bird.Id] = sog;
//m_log.InfoFormat("[{0}]: Reusing prim {1} from region {2}", m_name, bird.Id, m_scene.RegionInfo.RegionName); //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);
} }
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
sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1);
rootPart.ParentGroup.ResumeScripts();
rootPart.ScheduleFullUpdate();
} }
private static Quaternion CalcRotationToEndpoint (SceneObjectGroup copy, Vector3 sv, Vector3 ev) private static Quaternion CalcRotationToEndpoint (SceneObjectGroup copy, Vector3 sv, Vector3 ev)