Major refactor and added support for varregions (first cut)

pull/1/merge
Jak Daniels 2014-07-17 17:43:21 +01:00
parent d7c5242aa9
commit 184fa20e2c
12 changed files with 157 additions and 204 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +0,0 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ReferencePath>/Users/jon/osim/opensim/bin/</ReferencePath>
<LastOpenVersion>9.0.21022</LastOpenVersion>
<ProjectView>ProjectFiles</ProjectView>
<ProjectTrust>0</ProjectTrust>
</PropertyGroup>
<PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
</Project>

View File

@ -1,61 +0,0 @@
<?xml version="1.0" ?>
<project name="Flocking" default="build">
<target name="build">
<echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
<mkdir dir="${project::get-base-directory()}/${build.dir}" />
<copy todir="${project::get-base-directory()}/${build.dir}" flatten="true">
<fileset basedir="${project::get-base-directory()}">
</fileset>
</copy>
<copy todir="${project::get-base-directory()}/${build.dir}">
<fileset basedir=".">
</fileset>
</copy>
<csc target="library" debug="${build.debug}" platform="${build.platform}" unsafe="False" warnaserror="False" define="TRACE;DEBUG" nostdlib="False" main="" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll" noconfig="true">
<resources prefix="Flocking" dynamicprefix="true" >
<include name="Resources/Flocking.addin.xml" />
</resources>
<sources failonempty="true">
<include name="Boid.cs" />
<include name="FlockingModel.cs" />
<include name="FlockingModule.cs" />
<include name="FlockingView.cs" />
<include name="FlowMap.cs" />
<include name="Util.cs" />
</sources>
<references basedir="${project::get-base-directory()}">
<lib>
<include name="${project::get-base-directory()}" />
<include name="${project::get-base-directory()}/../../../bin" />
</lib>
<include name="../../../bin/log4net.dll"/>
<include name="../../../bin/Nini.dll"/>
<include name="../../../bin/OpenMetaverse.dll"/>
<include name="../../../bin/OpenMetaverseTypes.dll"/>
<include name="../../../bin/OpenSim.Framework.dll"/>
<include name="../../../bin/OpenSim.Framework.Communications.dll"/>
<include name="../../../bin/OpenSim.Framework.Console.dll"/>
<include name="../../../bin/OpenSim.Region.Framework.dll"/>
<include name="System.dll" />
<include name="System.Drawing.dll" />
<include name="System.Xml.dll" />
</references>
</csc>
<echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../../bin/" />
<mkdir dir="${project::get-base-directory()}/../../../bin/"/>
<copy todir="${project::get-base-directory()}/../../../bin/">
<fileset basedir="${project::get-base-directory()}/${build.dir}/" >
<include name="*.dll"/>
<include name="*.exe"/>
<include name="*.mdb" if='${build.debug}'/>
<include name="*.pdb" if='${build.debug}'/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${bin.dir}" failonerror="false" />
<delete dir="${obj.dir}" failonerror="false" />
</target>
<target name="doc" description="Creates documentation.">
</target>
</project>

View File

@ -1,13 +0,0 @@
<Addin id="Flocking" version="0.1">
<Runtime>
<Import assembly="Flocking.dll"/>
</Runtime>
<Dependencies>
<Addin id="OpenSim" version="0.5" />
</Dependencies>
<Extension path = "/OpenSim/RegionModules">
<RegionModule id="Flocking" type="Flocking.FlockingModule" />
</Extension>
</Addin>

View File

@ -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;
/// <summary>
/// Initializes a new instance of the <see cref="Flocking.Boid"/> class.
@ -64,6 +67,10 @@ namespace Flocking
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_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)
if (m_loc.X < m_regionBorder || m_loc.X > m_regionX - m_regionBorder)
m_vel.X = -m_vel.X;
if (m_loc.Y < 5 || m_loc.Y > 250)
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;
}

View File

@ -39,6 +39,7 @@ namespace Flocking
private float m_neighbourDistance;
private float m_desiredSeparation;
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_border = border;
}
void AddBoid (string name)

View File

@ -36,15 +36,21 @@ 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
{
[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();
public string m_name = "BoidsModule";
private Scene m_scene;
private FlockingModel m_model;
private FlockingView m_view;
@ -60,12 +66,13 @@ 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)
{
@ -81,28 +88,39 @@ 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) {
m_log.InfoFormat ("[BOIDS]: Adding {0}", scene.RegionInfo.RegionName);
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
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_view = new FlockingView (m_scene);
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;
}
}
@ -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_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
}
}

View File

@ -134,7 +134,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 (128f, 128f, 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);

View File

@ -34,47 +34,59 @@ namespace Flocking
public class FlowMap
{
private Scene m_scene;
private float[,,] m_flowMap = new float[256,256,256];
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;
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;

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Core osboids Project -->
<Project frameworkVersion="v3_5" name="Flocking" path="addon-modules/osboids/Flocking/" type="Library">
<?xml version="1.0" ?>
<Project frameworkVersion="v3_5" name="OpenSimBoids.Modules" path="addon-modules/OpenSimBoids/Modules" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../bin/</OutputPath>
@ -14,21 +12,22 @@
</Configuration>
<ReferencePath>../../../bin/</ReferencePath>
<Reference name="log4net" path="../../../bin/" />
<Reference name="System"/>
<Reference name="System.Drawing" />
<Reference name="System.Xml"/>
<Reference name="Nini" path="../../../bin/" />
<Reference name="System.Net"/>
<Reference name="OpenMetaverse"/>
<Reference name="OpenMetaverseTypes"/>
<Reference name="OpenMetaverse.StructuredData"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Region.Framework"/>
<Reference name="Nini"/>
<Reference name="log4net"/>
<Reference name="Mono.Addins"/>
<Reference name="OpenSim.Framework" path="../../../bin/" />
<Reference name="OpenSim.Framework.Communications" path="../../../bin/" />
<Reference name="OpenSim.Region.Framework" path="../../../bin/" />
<Reference name="OpenSim.Framework.Console" path="../../../bin/" />
<Reference name="OpenMetaverseTypes" path="../../../bin/" />
<Reference name="OpenMetaverse" path="../../../bin/" />
<Files>
<Match pattern="*.cs" recurse="true"/>
<Match pattern="*.addin.xml" path="Resources" buildAction="EmbeddedResource" recurse="true"/>
<Files>
<Match pattern="*.cs" recurse="true">
</Match>
</Files>
</Project>