added ability to change flock size

stable0711
Jon Cundill 2011-07-09 12:35:13 +01:00
parent 57717a3a79
commit 72db5e2cc8
3 changed files with 101 additions and 77 deletions

View File

@ -34,17 +34,39 @@ namespace Flocking
{
private List<Boid> flock = new List<Boid>();
private int m_xRange = 200;
private int m_yRange = 200;
private int m_zRange = 200;
public int Size {
get {return flock.Count;}
set {
if( value < flock.Count ) {
flock.RemoveRange( 0, flock.Count - value );
} else while( value > flock.Count ) {
AddBoid( "boid"+flock.Count);
}
}
}
void AddBoid (string name)
{
Boid boid = new Boid (name, 3.0f, 0.05f);
boid.Location = new Vector3 (m_xRange / 2f, m_yRange / 2f, m_zRange / 2f);
flock.Add (boid);
}
public void Initialise (int num, int xRange, int yRange, int zRange)
{
m_xRange = xRange;
m_yRange = yRange;
m_zRange = zRange;
//TODO: fill in the initial Flock array properly
for (int i = 0; i < num; i++) {
Boid boid = new Boid ("boid"+i, 3.0f, 0.05f);
boid.Location = new Vector3 (xRange / 2f, yRange / 2f, zRange / 2f);
flock.Add (boid);
AddBoid ("boid"+i );
}
}

View File

@ -37,32 +37,25 @@ using OpenSim.Region.Framework.Scenes;
using OpenSim.Framework;
using OpenSim.Framework.Console;
namespace Flocking
{
public class FlockingModule : INonSharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger (System.Reflection.MethodBase.GetCurrentMethod ().DeclaringType);
static object m_sync = new object();
private Scene m_scene;
private FlockingModel m_model;
private FlockingView m_view;
private bool m_enabled = false;
private bool m_ready = false;
private uint m_frame = 0;
private int m_frameUpdateRate = 1;
private int m_chatChannel = 118;
private string m_boidPrim;
private UUID m_owner;
#region IRegionModule Members
@ -122,7 +115,6 @@ namespace Flocking
}
}
public string Name {
get { return "FlockingModule"; }
}
@ -137,8 +129,7 @@ namespace Flocking
public void FlockUpdate ()
{
if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready || !m_enabled)
{
if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready || !m_enabled) {
return;
}
@ -146,9 +137,11 @@ namespace Flocking
// work out where everyone has moved to
// and tell the scene to render the new positions
lock( m_sync ) {
List<Boid > boids = m_model.UpdateFlockPos ();
m_view.Render (boids);
}
}
protected void SimChatSent (Object x, OSChatMessage msg)
{
@ -165,7 +158,7 @@ namespace Flocking
m_log.Info ("got cmd " + cmd);
//stick ui in the args so we know to respond in world
string[] args = ("<ui> " + cmd).Split (" ".ToCharArray ());
string[] args = (cmd + " <ui>").Split (" ".ToCharArray ());
if (cmd.StartsWith ("stop")) {
HandleStopCmd ("flock", args);
@ -194,8 +187,8 @@ namespace Flocking
m_scene.AddCommand (this, "flock-" + cmd, "flock-" + cmd + argStr, help, fn);
}
private void RegisterCommands() {
private void RegisterCommands ()
{
AddCommand ("stop", "", "Stop all Flocking", HandleStopCmd);
AddCommand ("start", "", "Start Flocking", HandleStartCmd);
AddCommand ("size", "num", "Adjust the size of the flock ", HandleSetSizeCmd);
@ -203,20 +196,23 @@ namespace Flocking
AddCommand ("prim", "name", "set the prim used for each boid to that passed in", HandleSetPrimCmd);
}
private bool ShouldHandleCmd() {
private bool ShouldHandleCmd ()
{
return m_scene.ConsoleScene () == m_scene;
}
private bool IsInWorldCmd( ref string [] args ) {
private bool IsInWorldCmd (ref string [] args)
{
bool retVal = false;
if( args.Length > 0 && args[0].Equals("<ui>") ) {
if (args.Length > 0 && args [args.Length - 1].Equals ("<ui>")) {
retVal = true;
}
return retVal;
}
private void ShowResponse(string response, bool inWorld) {
private void ShowResponse (string response, bool inWorld)
{
if (inWorld) {
IClientAPI ownerAPI = null;
if (m_scene.TryGetClient (m_owner, out ownerAPI)) {
@ -248,7 +244,14 @@ namespace Flocking
public void HandleSetSizeCmd (string module, string[] args)
{
if (ShouldHandleCmd ()) {
m_log.Info("set size not implemented yet");
lock( m_sync ) {
//m_enabled = false;
//m_log.Info( args );
int newSize = Convert.ToInt32(args[1]);
m_model.Size = newSize;
m_view.Clear();
//m_enabled = true;
}
}
}
@ -260,13 +263,13 @@ namespace Flocking
}
}
public void HandleSetPrimCmd (string module, string[] args)
{
if (ShouldHandleCmd ()) {
m_log.Info ("set prim not implemented yet");
}
}
#endregion
@ -279,8 +282,6 @@ namespace Flocking
{
}
public Type ReplaceableInterface {
get { return null; }
}

View File

@ -84,7 +84,8 @@ namespace Flocking
}
Quaternion rotation = CalcRotationToEndpoint (sog, sog.AbsolutePosition, boid.Location);
sog.UpdateGroupRotationPR (boid.Location, rotation);
sog.UpdateGroupPosition(boid.Location);
sog.UpdateGroupRotationR (rotation);
}
private static Quaternion CalcRotationToEndpoint (SceneObjectGroup copy, Vector3 sv, Vector3 ev)