Whitespace changes and detabified file.

pull/1/head
Kevin Cozens 2018-03-11 15:39:36 -04:00
parent cd72e7b701
commit b72f67be06
1 changed files with 147 additions and 153 deletions

View File

@ -58,31 +58,31 @@ namespace Flocking
private string m_regionConfigDir = "";
private Scene m_scene;
private ICommandConsole m_console;
private FlockingModel m_model;
private FlockingView m_view;
private FlockingModel m_model;
private FlockingView m_view;
private bool m_startup = true;
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_birdPrim;
private int m_flockSize = 50;
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_birdPrim;
private int m_flockSize = 50;
private int m_maxFlockSize = 100;
private float m_maxSpeed;
private float m_maxForce;
private float m_neighbourDistance;
private float m_desiredSeparation;
private float m_tolerance;
private float m_maxSpeed;
private float m_maxForce;
private float m_neighbourDistance;
private float m_desiredSeparation;
private float m_tolerance;
private float m_borderSize;
private int m_maxHeight;
private Vector3 m_shoutPos = new Vector3(128f, 128f, 30f);
private Vector3 m_shoutPos = new Vector3(128f, 128f, 30f);
static object m_sync = new object();
private List<UUID> m_allowedControllers = new List<UUID>();
public IConfigSource m_config;
private UUID m_owner;
private UUID m_owner;
#endregion
#region IRegionModuleBase implementation
@ -92,18 +92,18 @@ namespace Flocking
public bool IsSharedModule { get { return false; } }
public void Initialise (IConfigSource source)
{
{
m_config = source;
}
}
public void AddRegion (Scene scene)
{
public void AddRegion (Scene scene)
{
IConfig cnf;
m_log.InfoFormat("[{0}]: Adding region {1} to this module", m_name, scene.RegionInfo.RegionName);
cnf = m_config.Configs["Startup"];
m_regionConfigDir = cnf.GetString("regionload_regionsdir", Path.Combine(Util.configDir(), "bin/Regions/"));
cnf = m_config.Configs[scene.RegionInfo.RegionName];
if (cnf == null)
@ -205,19 +205,18 @@ namespace Flocking
m_shoutPos = new Vector3(scene.RegionInfo.RegionSizeX / 2f, scene.RegionInfo.RegionSizeY / 2f, 30f);
FlockInitialise();
}
else m_log.InfoFormat("[{0}] Module is disabled in Region {1}", m_name, scene.RegionInfo.RegionName);
}
}
public void RegionLoaded (Scene scene)
{
public void RegionLoaded (Scene scene)
{
if (m_startup)
{
// Mark Module Ready for duty
m_ready = true;
}
}
m_ready = true;
}
}
public void PrimsLoaded(Scene scene)
{
@ -225,18 +224,18 @@ namespace Flocking
ClearPersisted();
}
public void RemoveRegion (Scene scene)
{
public void RemoveRegion (Scene scene)
{
m_log.InfoFormat("[{0}]: Removing region {1} from this module", m_name, scene.RegionInfo.RegionName);
if (m_startup) {
m_view.Clear();
scene.EventManager.OnFrame -= FlockUpdate;
scene.EventManager.OnChatFromClient -= SimChatSent;
scene.EventManager.OnFrame -= FlockUpdate;
scene.EventManager.OnChatFromClient -= SimChatSent;
scene.EventManager.OnChatFromWorld -= SimChatSent;
scene.EventManager.OnPrimsLoaded -= PrimsLoaded;
m_ready = false;
}
}
}
public void Close()
{
@ -250,7 +249,7 @@ namespace Flocking
}
}
#endregion
#endregion
#region Helpers
@ -292,25 +291,25 @@ namespace Flocking
#region EventHandlers
public void FlockUpdate ()
{
{
if (!m_ready || !m_enabled || ((m_frame++ % m_frameUpdateRate) != 0))
{
return;
}
//m_log.InfoFormat("update my birds");
// work out where everyone has moved to
// and tell the scene to render the new positions
lock( m_sync ) {
List<Bird > birds = m_model.UpdateFlockPos ();
m_view.Render (birds);
}
}
protected void SimChatSent (Object x, OSChatMessage msg)
{
if (msg.Channel != m_chatChannel) return; // not for us
return;
}
//m_log.InfoFormat("update my birds");
// work out where everyone has moved to
// and tell the scene to render the new positions
lock( m_sync ) {
List<Bird > birds = m_model.UpdateFlockPos ();
m_view.Render (birds);
}
}
protected void SimChatSent (Object x, OSChatMessage msg)
{
if (msg.Channel != m_chatChannel) return; // not for us
if (m_allowedControllers.Count > 0)
{
bool reject = true;
@ -325,27 +324,27 @@ namespace Flocking
if (reject) return; //not for us
}
// try and parse a valid cmd from this msg
string cmd = msg.Message; //.ToLower ();
//stick ui in the args so we know to respond in world
//bit of a hack - but lets us use CommandDelegate inWorld
string[] args = (cmd + " <ui>").Split (" ".ToCharArray ());
if (cmd.StartsWith ("stop")) {
HandleStopCmd (m_name, args);
} else if (cmd.StartsWith ("start")) {
HandleStartCmd (m_name, args);
// try and parse a valid cmd from this msg
string cmd = msg.Message; //.ToLower ();
//stick ui in the args so we know to respond in world
//bit of a hack - but lets us use CommandDelegate inWorld
string[] args = (cmd + " <ui>").Split (" ".ToCharArray ());
if (cmd.StartsWith ("stop")) {
HandleStopCmd (m_name, args);
} else if (cmd.StartsWith ("start")) {
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 (m_name, args);
} else if (cmd.StartsWith ("stats")) {
HandleShowStatsCmd (m_name, args);
} else if (cmd.StartsWith ("prim")) {
HandleSetPrimCmd (m_name, args);
} else if (cmd.StartsWith ("size")) {
HandleSetSizeCmd (m_name, args);
} else if (cmd.StartsWith ("stats")) {
HandleShowStatsCmd (m_name, args);
} else if (cmd.StartsWith ("prim")) {
HandleSetPrimCmd (m_name, args);
} else if (cmd.StartsWith("speed")) {
HandleSetMaxSpeedCmd(m_name, args);
} else if (cmd.StartsWith("force")) {
@ -356,35 +355,34 @@ namespace Flocking
HandleSetDesiredSeparationCmd(m_name, args);
} else if (cmd.StartsWith("tolerance")) {
HandleSetToleranceCmd(m_name, args);
} else if (cmd.StartsWith ("framerate")) {
HandleSetFrameRateCmd (m_name, args);
}
}
} else if (cmd.StartsWith ("framerate")) {
HandleSetFrameRateCmd (m_name, args);
}
}
#endregion
#region Command Handling
private void AddCommand (string cmd, string args, string help, CommandDelegate fn)
{
string argStr = "";
if (args.Trim ().Length > 0) {
argStr = " <" + args + "> ";
}
#endregion
#region Command Handling
private void AddCommand (string cmd, string args, string help, CommandDelegate fn)
{
string argStr = "";
if (args.Trim ().Length > 0) {
argStr = " <" + args + "> ";
}
m_log.InfoFormat("[{0}]: Adding console command {1} - {2} to region {3}", m_name, "birds-" + cmd + argStr, help, m_scene.RegionInfo.RegionName);
//m_scene.AddCommand (this, "birds-" + cmd, "birds-" + cmd + argStr, help, fn);
m_console.Commands.AddCommand(m_name, false, "birds-" + cmd, "birds-" + cmd + argStr, help, fn);
}
private void RegisterCommands ()
{
AddCommand ("stop", "", "Stop Birds Flocking", HandleStopCmd);
AddCommand ("start", "", "Start Birds Flocking", HandleStartCmd);
private void RegisterCommands ()
{
AddCommand ("stop", "", "Stop Birds Flocking", HandleStopCmd);
AddCommand ("start", "", "Start Birds Flocking", HandleStartCmd);
AddCommand ("enable", "", "Enable Birds Flocking", HandleEnableCmd);
AddCommand ("disable", "", "Disable Birds Flocking", HandleDisableCmd);
AddCommand ("size", "num", "Adjust the size of the flock ", HandleSetSizeCmd);
AddCommand ("prim", "name", "Set the prim used for each bird to that passed in", HandleSetPrimCmd);
AddCommand ("size", "num", "Adjust the size of the flock ", HandleSetSizeCmd);
AddCommand ("prim", "name", "Set the prim used for each bird to that passed in", HandleSetPrimCmd);
AddCommand ("speed", "num", "Set the maximum velocity each bird may achieve", HandleSetMaxSpeedCmd);
AddCommand("force", "num", "Set the maximum force each bird may accelerate", HandleSetMaxForceCmd);
AddCommand("distance", "num", "Set the maximum distance that other birds are to be considered in the same flock as us", HandleSetNeighbourDistanceCmd);
@ -400,7 +398,6 @@ namespace Flocking
if (comms != null)
{
comms.RegisterScriptInvocation(this, "birdsGetStats");
}
}
@ -408,36 +405,36 @@ namespace Flocking
{
return ""; //currently a placeholder
}
private bool ShouldHandleCmd ()
{
private bool ShouldHandleCmd ()
{
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) {
return false;
}
return true;
}
private bool IsInWorldCmd (ref string [] args)
{
if (args.Length > 0 && args [args.Length - 1].Equals ("<ui>")) {
}
private bool IsInWorldCmd (ref string [] args)
{
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 true;
}
return false;
}
private void ShowResponse (string response, bool inWorld)
{
if (inWorld) {
//IClientAPI ownerAPI = null;
//if (m_scene.TryGetClient (m_owner, out ownerAPI)) {
// ownerAPI.SendBlueBoxMessage (m_owner, "Birds", response);
//}
}
private void ShowResponse (string response, bool inWorld)
{
if (inWorld) {
//IClientAPI ownerAPI = null;
//if (m_scene.TryGetClient (m_owner, out ownerAPI)) {
// ownerAPI.SendBlueBoxMessage (m_owner, "Birds", response);
//}
SendSimChat(response, m_chatChannel);
} else {
MainConsole.Instance.Output (response);
}
}
} else {
MainConsole.Instance.Output (response);
}
}
private void SendSimChat(string msg, int channel)
{
@ -463,15 +460,15 @@ namespace Flocking
//m_ready = true;
}
}
public void HandleStopCmd (string module, string[] args)
{
public void HandleStopCmd (string module, string[] args)
{
if (m_enabled && m_ready && ShouldHandleCmd())
{
m_log.InfoFormat("[{0}]: Bird flocking is stopped in region {1}.", m_name, m_scene.RegionInfo.RegionName);
m_enabled = false;
}
}
m_enabled = false;
}
}
public void HandleStartCmd(string module, string[] args)
{
@ -483,36 +480,35 @@ namespace Flocking
}
}
void HandleSetFrameRateCmd (string module, string[] args)
{
void HandleSetFrameRateCmd (string module, string[] args)
{
if (m_ready && ShouldHandleCmd())
{
int frameRate = Convert.ToInt32( args[1] );
m_frameUpdateRate = frameRate;
int frameRate = Convert.ToInt32( args[1] );
m_frameUpdateRate = frameRate;
m_log.InfoFormat("[{0}]: Bird updates set to every {1} frames in region {2}.", m_name, frameRate, m_scene.RegionInfo.RegionName);
}
}
}
}
public void HandleSetSizeCmd (string module, string[] args)
{
public void HandleSetSizeCmd (string module, string[] args)
{
if (m_ready && ShouldHandleCmd())
{
lock( m_sync ) {
int newSize = Convert.ToInt32(args[1]);
lock( m_sync ) {
int newSize = Convert.ToInt32(args[1]);
if (newSize > m_maxFlockSize) newSize = m_maxFlockSize;
m_view.Clear();
m_model.Size = newSize;
m_log.InfoFormat("[{0}]: Bird flock size is set to {1} in region {2}.", m_name, newSize, m_scene.RegionInfo.RegionName);
}
}
}
public void HandleShowStatsCmd (string module, string[] args)
{
}
}
}
public void HandleShowStatsCmd (string module, string[] args)
{
if (m_ready && ShouldHandleCmd())
{
bool inWorld = IsInWorldCmd (ref args);
bool inWorld = IsInWorldCmd (ref args);
int i;
int s=m_model.Size;
UUID primUuid;
@ -560,21 +556,21 @@ namespace Flocking
ShowResponse("birds-prim" + i + " = " + m_name + i + " : " + primUuid.ToString() + " : " + avUuids.Trim(), inWorld);
}
}
}
public void HandleSetPrimCmd (string module, string[] args)
{
}
}
public void HandleSetPrimCmd (string module, string[] args)
{
if (m_ready && ShouldHandleCmd())
{
string primName = args[1];
lock(m_sync) {
m_view.BirdPrim = primName;
string primName = args[1];
lock(m_sync) {
m_view.BirdPrim = primName;
m_log.InfoFormat("[{0}]: Bird prim is set to {1} in region {2}.", m_name, primName, m_scene.RegionInfo.RegionName);
m_view.Clear();
}
}
}
m_view.Clear();
}
}
}
public void HandleSetMaxSpeedCmd(string module, string[] args)
{
@ -641,8 +637,6 @@ namespace Flocking
}
}
#endregion
}
#endregion
}
}