diff --git a/Flocking.dll b/Flocking.dll deleted file mode 100755 index ff146ba..0000000 Binary files a/Flocking.dll and /dev/null differ diff --git a/Flocking.dll.mdb b/Flocking.dll.mdb deleted file mode 100644 index dcf561b..0000000 Binary files a/Flocking.dll.mdb and /dev/null differ diff --git a/Flocking/Flocking.csproj.user b/Flocking/Flocking.csproj.user deleted file mode 100644 index 6fb9ffe..0000000 --- a/Flocking/Flocking.csproj.user +++ /dev/null @@ -1,12 +0,0 @@ - - - Debug - AnyCPU - /Users/jon/osim/opensim/bin/ - 9.0.21022 - ProjectFiles - 0 - - - - diff --git a/Flocking/Flocking.dll.build b/Flocking/Flocking.dll.build deleted file mode 100644 index 8a170df..0000000 --- a/Flocking/Flocking.dll.build +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Flocking/resources/Flocking.addin.xml b/Flocking/resources/Flocking.addin.xml deleted file mode 100644 index 5e1cfcd..0000000 --- a/Flocking/resources/Flocking.addin.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/Flocking/Boid.cs b/Modules/BoidsModule/Boid.cs similarity index 95% rename from Flocking/Boid.cs rename to Modules/BoidsModule/Boid.cs index f8af296..afa26ea 100644 --- a/Flocking/Boid.cs +++ b/Modules/BoidsModule/Boid.cs @@ -43,7 +43,10 @@ namespace Flocking private FlockingModel m_model; private FlowMap m_flowMap; - + private int m_regionX; + private int m_regionY; + private int m_regionZ; + private float m_regionBorder; /// /// Initializes a new instance of the class. @@ -63,7 +66,11 @@ namespace Flocking m_acc = Vector3.Zero; m_vel = new Vector3 (m_rndnums.Next (-1, 1), m_rndnums.Next (-1, 1), m_rndnums.Next (-1, 1)); m_model = model; - m_flowMap = flowMap; + m_flowMap = flowMap; + m_regionX = m_flowMap.LengthX; + m_regionY = m_flowMap.LengthY; + m_regionZ = m_flowMap.LengthZ; + m_regionBorder = m_flowMap.Border; } public Vector3 Location { @@ -249,11 +256,11 @@ namespace Flocking // try increaing our acceleration // or try decreasing our acceleration // or turn around - coz where we came from was OK - if (m_loc.X < 5 || m_loc.X > 250) - m_vel.X = -m_vel.X; - if (m_loc.Y < 5 || m_loc.Y > 250) + if (m_loc.X < m_regionBorder || m_loc.X > m_regionX - m_regionBorder) + m_vel.X = -m_vel.X; + if (m_loc.Y < m_regionBorder || m_loc.Y > m_regionY - m_regionBorder) m_vel.Y = -m_vel.Y; - if (m_loc.Z < 21 || m_loc.Z > 271 ) + if (m_loc.Z < 21 || m_loc.Z > m_regionZ ) m_vel.Z = -m_vel.Z; } diff --git a/Flocking/FlockingModel.cs b/Modules/BoidsModule/FlockingModel.cs similarity index 96% rename from Flocking/FlockingModel.cs rename to Modules/BoidsModule/FlockingModel.cs index beb0bb0..93fae10 100644 --- a/Flocking/FlockingModel.cs +++ b/Modules/BoidsModule/FlockingModel.cs @@ -38,7 +38,8 @@ namespace Flocking private float m_maxForce; private float m_neighbourDistance; private float m_desiredSeparation; - private float m_tolerance; + private float m_tolerance; + private float m_border; private Random m_rnd = new Random(Environment.TickCount); @@ -53,12 +54,13 @@ namespace Flocking } } - public FlockingModel( float maxSpeed, float maxForce, float neighbourDistance, float desiredSeparation, float tolerance ) { + public FlockingModel( float maxSpeed, float maxForce, float neighbourDistance, float desiredSeparation, float tolerance, float border) { m_maxSpeed = maxSpeed; m_maxForce = maxForce; m_neighbourDistance = neighbourDistance; m_desiredSeparation = desiredSeparation; - m_tolerance = tolerance; + m_tolerance = tolerance; + m_border = border; } void AddBoid (string name) diff --git a/Flocking/FlockingModule.cs b/Modules/BoidsModule/FlockingModule.cs similarity index 74% rename from Flocking/FlockingModule.cs rename to Modules/BoidsModule/FlockingModule.cs index 92c4de2..8e77297 100644 --- a/Flocking/FlockingModule.cs +++ b/Modules/BoidsModule/FlockingModule.cs @@ -36,16 +36,22 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Framework; using OpenSim.Framework.Console; +using Mono.Addins; + +[assembly: Addin("BoidsModule", "0.1")] +[assembly: AddinDependency("OpenSim", "0.5")] namespace Flocking { - public class FlockingModule : INonSharedRegionModule - { - - private static readonly ILog m_log = LogManager.GetLogger (System.Reflection.MethodBase.GetCurrentMethod ().DeclaringType); + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class FlockingModule : INonSharedRegionModule + { + #region Fields + private static readonly ILog m_log = LogManager.GetLogger (System.Reflection.MethodBase.GetCurrentMethod ().DeclaringType); static object m_sync = new object(); - private Scene m_scene; + public string m_name = "BoidsModule"; + private Scene m_scene; private FlockingModel m_model; private FlockingView m_view; private bool m_enabled = false; @@ -60,14 +66,15 @@ namespace Flocking private float m_neighbourDistance; private float m_desiredSeparation; private float m_tolerance; + private float m_borderSize; + private int m_maxHeight; private UUID m_owner; + #endregion - #region IRegionModule Members + #region IRegionModuleBase implementation - - - public void Initialise (IConfigSource source) + public void Initialise (IConfigSource source) { //check if we are in the ini files //if so get some physical constants out of them and pass into the model @@ -81,30 +88,41 @@ namespace Flocking m_neighbourDistance = config.GetFloat("neighbour-dist", 25f); m_desiredSeparation = config.GetFloat("desired-separation", 20f); m_tolerance = config.GetFloat("tolerance", 5f); - - - // we're in the config - so turn on this module - m_enabled = true; + m_borderSize = config.GetFloat("border-size", 5f); + m_maxHeight = config.GetInt("max-height", 256); + m_enabled = config.GetBoolean("enabled", false); } + + if (m_enabled) + { + m_log.InfoFormat("[BOIDS] Enabled on channel {0} with Flock Size {1}", m_chatChannel, m_flockSize); + //m_ready = true; + return; + } } + public void PostInitialise() + { + } + public void AddRegion (Scene scene) { - m_log.Info ("ADDING FLOCKING"); - m_scene = scene; - if (m_enabled) { - //register commands - RegisterCommands (); - - //register handlers - m_scene.EventManager.OnFrame += FlockUpdate; - m_scene.EventManager.OnChatFromClient += SimChatSent; //listen for commands sent from the client + m_scene = scene; + m_log.InfoFormat ("[BOIDS]: Adding {0}", scene.RegionInfo.RegionName); + if (m_enabled) + { + //register commands + RegisterCommands(); - // init module - m_model = new FlockingModel (m_maxSpeed, m_maxForce, m_neighbourDistance, m_desiredSeparation, m_tolerance); - m_view = new FlockingView (m_scene); - m_view.BoidPrim = m_boidPrim; - } + //register handlers + scene.EventManager.OnFrame += FlockUpdate; + scene.EventManager.OnChatFromClient += SimChatSent; //listen for commands sent from the client + + // init module + m_model = new FlockingModel(m_maxSpeed, m_maxForce, m_neighbourDistance, m_desiredSeparation, m_tolerance, m_borderSize); + m_view = new FlockingView(scene); + m_view.BoidPrim = m_boidPrim; + } } public void RegionLoaded (Scene scene) @@ -112,14 +130,14 @@ namespace Flocking if (m_enabled) { //make a flow map for this scene - FlowMap flowMap = new FlowMap(scene ); + FlowMap flowMap = new FlowMap(scene, m_maxHeight, m_borderSize); flowMap.Initialise(); // Generate initial flock values m_model.Initialise (m_flockSize, flowMap); // who is the owner for the flock in this region - m_owner = m_scene.RegionInfo.EstateSettings.EstateOwner; + m_owner = scene.RegionInfo.EstateSettings.EstateOwner; m_view.PostInitialize (m_owner); // Mark Module Ready for duty @@ -130,19 +148,35 @@ namespace Flocking public void RemoveRegion (Scene scene) { if (m_enabled) { - m_scene.EventManager.OnFrame -= FlockUpdate; - m_scene.EventManager.OnChatFromClient -= SimChatSent; + m_ready = false; + scene.EventManager.OnFrame -= FlockUpdate; + scene.EventManager.OnChatFromClient -= SimChatSent; } } + public void Close() + { + if (m_enabled) + { + m_ready = false; + m_scene.EventManager.OnFrame -= FlockUpdate; + m_scene.EventManager.OnChatFromClient -= SimChatSent; + } + } + public string Name { - get { return "FlockingModule"; } + get { return m_name; } } public bool IsSharedModule { get { return false; } } + public Type ReplaceableInterface + { + get { return null; } + } + #endregion #region EventHandlers @@ -234,7 +268,7 @@ namespace Flocking if (inWorld) { IClientAPI ownerAPI = null; if (m_scene.TryGetClient (m_owner, out ownerAPI)) { - ownerAPI.SendBlueBoxMessage (m_owner, "osboids", response); + ownerAPI.SendBlueBoxMessage (m_owner, "Boids", response); } } else { MainConsole.Instance.Output (response); @@ -299,21 +333,6 @@ namespace Flocking #endregion - - - #region IRegionModuleBase Members - - - - public void Close () - { - } - - public Type ReplaceableInterface { - get { return null; } - } - - #endregion } } diff --git a/Flocking/FlockingView.cs b/Modules/BoidsModule/FlockingView.cs similarity index 96% rename from Flocking/FlockingView.cs rename to Modules/BoidsModule/FlockingView.cs index 5db8f33..69efe82 100644 --- a/Flocking/FlockingView.cs +++ b/Modules/BoidsModule/FlockingView.cs @@ -132,9 +132,9 @@ namespace Flocking private SceneObjectGroup MakeDefaultPrim (string name) { PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere (); - shape.Scale = new Vector3 (0.5f, 0.5f, 0.5f); - - SceneObjectGroup prim = new SceneObjectGroup (m_owner, new Vector3 (128f, 128f, 25f), shape); + 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); prim.Name = name; prim.DetachFromBackup (); m_scene.AddNewSceneObject (prim, false); diff --git a/Flocking/FlowMap.cs b/Modules/BoidsModule/FlowMap.cs similarity index 76% rename from Flocking/FlowMap.cs rename to Modules/BoidsModule/FlowMap.cs index b4df130..e08b2c1 100644 --- a/Flocking/FlowMap.cs +++ b/Modules/BoidsModule/FlowMap.cs @@ -33,48 +33,60 @@ namespace Flocking { public class FlowMap { - private Scene m_scene; - private float[,,] m_flowMap = new float[256,256,256]; + private Scene m_scene; + private float[, ,] m_flowMap; + private uint regionX; + private uint regionY; + private uint regionZ; + private float regionBorder; - public FlowMap (Scene scene) + public FlowMap (Scene scene, int maxHeight, float borderSize) { - m_scene = scene; + m_scene = scene; + regionX = m_scene.RegionInfo.RegionSizeX; + regionY = m_scene.RegionInfo.RegionSizeY; + regionZ = (uint)maxHeight; + regionBorder = borderSize; + m_flowMap = new float[regionX, regionY, regionZ]; } public int LengthX { - get {return 256;} + get {return (int)regionX;} } public int LengthY { - get {return 256;} + get {return (int)regionY;} } public int LengthZ { - get {return 256;} - } + get {return (int)regionZ;} + } + public int Border { + get {return (int)regionBorder;} + } public void Initialise() { //fill in the boundaries - for( int x = 0; x < 256; x++ ) { - for( int y = 0; y < 256; y++ ) { + for( int x = 0; x < regionX; x++ ) { + for( int y = 0; y < regionY; y++ ) { m_flowMap[x,y,0] = 100f; - m_flowMap[x,y,255] = 100f; + m_flowMap[x,y, regionZ-1] = 100f; } } - for( int x = 0; x < 256; x++ ) { - for( int z = 0; z < 256; z++ ) { + for( int x = 0; x < regionX; x++ ) { + for( int z = 0; z < regionZ; z++ ) { m_flowMap[x,0,z] = 100f; - m_flowMap[x,255,z] = 100f; + m_flowMap[x,regionY-1,z] = 100f; } } - for( int y = 0; y < 256; y++ ) { - for( int z = 0; z < 256; z++ ) { + for( int y = 0; y < regionY; y++ ) { + for( int z = 0; z < regionZ; z++ ) { m_flowMap[0,y,z] = 100f; - m_flowMap[255,y,z] = 100f; + m_flowMap[regionX-1,y,z] = 100f; } } //fill in the terrain - for( int x = 0; x < 256; x++ ) { - for( int y = 0; y < 256; y++ ) { + for( int x = 0; x < regionX; x++ ) { + for( int y = 0; y < regionY; y++ ) { int zMax = Convert.ToInt32(m_scene.GetGroundHeight( x, y )); for( int z = 1; z < zMax; z++ ) { m_flowMap[x,y,z] = 100f; @@ -127,12 +139,12 @@ namespace Flocking public bool IsOutOfBounds(Vector3 targetPos) { bool retVal = false; - if( targetPos.X < 5f || - targetPos.X > 250f || - targetPos.Y < 5f || - targetPos.Y > 250f || - targetPos.Z < 5f || - targetPos.Z > 250f ) { + if( targetPos.X < regionBorder || + targetPos.X > regionX - regionBorder || + targetPos.Y < regionBorder || + targetPos.Y > regionY - regionBorder || + targetPos.Z < regionBorder || + targetPos.Z > regionZ - regionBorder ) { retVal = true; } @@ -169,7 +181,7 @@ namespace Flocking public bool IsWithinObstacle( int x, int y, int z ) { bool retVal = false; - if( x > LengthX || y > LengthY || z > LengthZ ) { + if( x >= LengthX || y >= LengthY || z >= LengthZ ) { retVal = true; } else if( x < 0 || y < 0 || z < 0 ) { retVal = true; diff --git a/Flocking/Util.cs b/Modules/BoidsModule/Util.cs similarity index 100% rename from Flocking/Util.cs rename to Modules/BoidsModule/Util.cs diff --git a/prebuild.xml b/prebuild.xml index 36e4a8e..3309edb 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1,34 +1,33 @@ - - + + + + + ../../../bin/ + + + + + ../../../bin/ + + - - - - ../../../bin/ - - - - - ../../../bin/ - - - - ../../../bin/ - - - - - - - - - - - - - - - - - + ../../../bin/ + + + + + + + + + + + + + + + + + +