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