From 57717a3a7954ba4f5974a845e377824aeed8d2ef Mon Sep 17 00:00:00 2001 From: Jon Cundill Date: Sat, 9 Jul 2011 11:11:19 +0100 Subject: [PATCH] basic controller structure added --- Flocking/Flocking.pidb | Bin 18380 -> 0 bytes Flocking/FlockingModel.cs | 3 + Flocking/FlockingModule.cs | 150 +++++++++++++++++++++++++++++++++++-- Flocking/FlockingView.cs | 42 +++++++---- 4 files changed, 174 insertions(+), 21 deletions(-) delete mode 100644 Flocking/Flocking.pidb diff --git a/Flocking/Flocking.pidb b/Flocking/Flocking.pidb deleted file mode 100644 index f68b0d9837a1d0c4912a7eaaf24fabe27af947a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18380 zcmeHPO>i8?b>0DX7rP7ofcl}VA4@}0qW-`INl}ypk(5AyARz%H1%Q-nhJgmV4Pc1b znbpiJz@-$KlxSJD6331$J9e(gF|N`nm8u+c$R&s5oMVoz9FwXXgM8ncpPgCkE&-ZU z*(rCSd%NGfe(&|`*WIssdXUjFnaly?zUkOr`JCac_{O58 z27pkSc8uzzQSlvj;IeW(U=+rkTHSD!TOj6~c|&F2R!uK|*{~YQ8&V%M49oPJ5mqMC zm&xV&1`CBu=FKRhrnSg1z;;n#MA$lwwv|$2t-~tHFnYHq)T884wlde%y z>yEoxp0a)AE*TZ&5&IhA-l_ABJ-32>sRq~qaXjf1*vM7HTy4Q}mf7rE)aD4HjwoTn z!p{I6AG4KDHZ{cT)U?C4CxeZ`KyAURC|fir4LAbeo(OBhLGG!pt(jv@X-OS;IVna} z!`~0^3m(v^vM8?bcnQEqBg73Vkzf~bXQWJML9rdl;GvMOEv%VpJtlPwux~|3F)1IA z9TBO^z>hG(-v)k*wFPB!xKv|e#{nLSQ2W=AgXpd@s?8YXl@to;0%eK)8>76IMA>m2 zr9C0arFzxy)huF+Jc`E;BT6W8P&5%sQ?}`w7)xHuw8sEXnKl835hoEj0E0kH-ayQI zPQ$Gz0d9PVpTYB{ZDPW(m&|1%eT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o}dGZ9yztTuyERtt22|PvZ@DSgmK(ehKJSx=i4#PJie!Dr|?w#G}sNa zKYuQMKIKg~_}T{I$V<3(#1~@3Ff)gH_P#f5+NvG(>2_2)2JJ{10?Z-XeRakQ*Fa`= zzotFi)j~pcksm|!d>u)a|Jb8c%71|Tv+_?q@R`Yqs;q|hzClYm>LMlEG9r<4-d1Z+o`+9#>WxQE;NP?~YIb`EV8s$o zXB;&-E;Szs`4PbB9qb!Ox(l4pJ4Z+C0ts2x*En2d+_F2+6KnXH4toN3@jZO^g1h*h zgHO2XD@_kOa|^d?;r8TfKXK3@}Uc*UZ23kbsM6J*GWzryO% U1YjTXV09Zw#A@*NK>=p|54~1Hn*aa+ diff --git a/Flocking/FlockingModel.cs b/Flocking/FlockingModel.cs index 0fe3613..fca6fc2 100644 --- a/Flocking/FlockingModel.cs +++ b/Flocking/FlockingModel.cs @@ -34,6 +34,9 @@ namespace Flocking { private List flock = new List(); + public int Size { + get {return flock.Count;} + } public void Initialise (int num, int xRange, int yRange, int zRange) { diff --git a/Flocking/FlockingModule.cs b/Flocking/FlockingModule.cs index 63a9bfe..cd41722 100644 --- a/Flocking/FlockingModule.cs +++ b/Flocking/FlockingModule.cs @@ -56,6 +56,11 @@ namespace Flocking 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 @@ -64,9 +69,16 @@ namespace Flocking public void Initialise (IConfigSource source) { - //TODO: check if we are in the ini files - //TODO: if so get some physical constants out of them and pass into the model - m_enabled = true; + //check if we are in the ini files + //if so get some physical constants out of them and pass into the model + IConfig config = source.Configs["Boids"]; + if (config != null) { + m_chatChannel = config.GetInt( "chat-channel", 118 ); + m_boidPrim = config.GetString( "boid-prim", "boidPrim" ); + + // we're in the config - so turn on this module + m_enabled = true; + } } public void AddRegion (Scene scene) @@ -74,12 +86,16 @@ namespace Flocking 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 + // init module m_model = new FlockingModel(); m_view = new FlockingView (m_scene); - - m_scene.AddCommand (this, "flocking", "I haz got a Flocking Module", "wotever" , null); } } @@ -88,7 +104,10 @@ namespace Flocking if (m_enabled) { // Generate initial flock values m_model.Initialise( 200, 255, 255, 255); - m_view.PostInitialize(); + + // who is the owner for the flock in this region + m_owner = m_scene.RegionInfo.EstateSettings.EstateOwner; + m_view.PostInitialize(m_owner); // Mark Module Ready for duty m_ready = true; @@ -99,6 +118,7 @@ namespace Flocking { if (m_enabled) { m_scene.EventManager.OnFrame -= FlockUpdate; + m_scene.EventManager.OnChatFromClient -= SimChatSent; } } @@ -117,7 +137,7 @@ namespace Flocking public void FlockUpdate() { - if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready) + if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready || !m_enabled) { return; } @@ -129,10 +149,126 @@ namespace Flocking List boids = m_model.UpdateFlockPos(); m_view.Render(boids); } + + protected void SimChatSent (Object x, OSChatMessage msg) + { + m_log.Info("got msg"); + if (m_scene.ConsoleScene () != m_scene) + return; // not for us + + m_log.Info("got channel" + msg.Channel); + if (msg.Channel != m_chatChannel) + return; // not for us + + // try and parse a valid cmd from this msg + string cmd = msg.Message.ToLower (); + m_log.Info("got cmd " + cmd); + + //stick ui in the args so we know to respond in world + string[] args = (" " + cmd).Split (" ".ToCharArray ()); + + if (cmd.StartsWith ("stop")) { + HandleStopCmd("flock", args); + } else if ( cmd.StartsWith( "start" ) ) { + HandleStartCmd("flock", args); + } else if ( cmd.StartsWith( "size" ) ) { + HandleSetSizeCmd("flock", args); + } else if ( cmd.StartsWith ( "stats" ) ) { + HandleShowStatsCmd("flock", args ); + } else if ( cmd.StartsWith ( "prim" ) ) { + HandleSetPrimCmd("flock", 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_scene.AddCommand (this, "flock-" + cmd, "flock-" + cmd + argStr, help, fn); + } + private void RegisterCommands() { + AddCommand ("stop", "", "Stop all Flocking", HandleStopCmd); + AddCommand ("start", "", "Start Flocking", HandleStartCmd); + AddCommand ("size", "num", "Adjust the size of the flock ", HandleSetSizeCmd); + AddCommand ("stats", "", "show flocking stats", HandleShowStatsCmd); + AddCommand ("prim", "name", "set the prim used for each boid to that passed in", HandleSetPrimCmd); + } + + private bool ShouldHandleCmd() { + return m_scene.ConsoleScene () == m_scene; + } + + private bool IsInWorldCmd( ref string [] args ) { + bool retVal = false; + + if( args.Length > 0 && args[0].Equals("") ) { + retVal = true; + } + return retVal; + } + + private void ShowResponse(string response, bool inWorld) { + if( inWorld ){ + IClientAPI ownerAPI = null; + if( m_scene.TryGetClient( m_owner, out ownerAPI ) ) { + ownerAPI.SendBlueBoxMessage( m_owner,"osboids", response ); + } + } else { + MainConsole.Instance.Output (response); + } + } + + public void HandleStopCmd (string module, string[] args) + { + if( ShouldHandleCmd() ) { + m_log.Info("stop the flocking capability"); + m_enabled = false; + m_view.Clear(); + } + } + + public void HandleStartCmd (string module, string[] args) + { + if( ShouldHandleCmd() ) { + m_log.Info("start the flocking capability"); + m_enabled = true; + FlockUpdate(); + } + } + + public void HandleSetSizeCmd (string module, string[] args) + { + if( ShouldHandleCmd() ) { + m_log.Info("set size not implemented yet"); + } + } + + public void HandleShowStatsCmd (string module, string[] args) + { + if( ShouldHandleCmd() ) { + bool inWorld = IsInWorldCmd( ref args ); + ShowResponse("Num Boids = " + m_model.Size, inWorld ); + } + } + + + public void HandleSetPrimCmd (string module, string[] args) + { + if( ShouldHandleCmd() ) { + m_log.Info("set prim not implemented yet"); + } + } + #endregion + #region IRegionModuleBase Members diff --git a/Flocking/FlockingView.cs b/Flocking/FlockingView.cs index 120dae1..9d4455e 100644 --- a/Flocking/FlockingView.cs +++ b/Flocking/FlockingView.cs @@ -40,43 +40,51 @@ namespace Flocking private UUID m_owner; private Dictionary m_sogMap = new Dictionary (); - + public FlockingView (Scene scene) { m_scene = scene; } - public void PostInitialize () + public void PostInitialize (UUID owner) { - m_owner = m_scene.RegionInfo.EstateSettings.EstateOwner; + m_owner = owner; } + public void Clear () + { + //trash everything we have + foreach (string name in m_sogMap.Keys) + { + RemoveSOGFromScene(name); + } + m_sogMap.Clear(); + } + public void Render (List boids) { foreach (Boid boid in boids) { - SceneObjectGroup sog = DrawBoid (boid); - //sog.ScheduleGroupForTerseUpdate (); + DrawBoid (boid); } } - private SceneObjectGroup DrawBoid (Boid boid) + private void DrawBoid (Boid boid) { SceneObjectPart existing = m_scene.GetSceneObjectPart (boid.Id); - SceneObjectGroup copy; + SceneObjectGroup sog; if (existing == null) { SceneObjectGroup group = findByName ("boidPrim"); - copy = CopyPrim (group, boid.Id); - m_sogMap [boid.Id] = copy; - m_scene.AddNewSceneObject (copy, false); + sog = CopyPrim (group, boid.Id); + m_sogMap [boid.Id] = sog; + m_scene.AddNewSceneObject (sog, false); } else { - copy = existing.ParentGroup; + sog = existing.ParentGroup; } - Quaternion rotation = CalcRotationToEndpoint (copy, copy.AbsolutePosition, boid.Location); - copy.UpdateGroupRotationPR (boid.Location, rotation); - return copy; + Quaternion rotation = CalcRotationToEndpoint (sog, sog.AbsolutePosition, boid.Location); + sog.UpdateGroupRotationPR (boid.Location, rotation); } private static Quaternion CalcRotationToEndpoint (SceneObjectGroup copy, Vector3 sv, Vector3 ev) @@ -138,6 +146,12 @@ namespace Flocking return prim; } + private void RemoveSOGFromScene(string sogName) + { + SceneObjectGroup sog = m_sogMap[sogName]; + m_scene.DeleteSceneObject(sog, false); + + } }