From 3f3cefc2ae676de8dd687dd32e2ade31f6721028 Mon Sep 17 00:00:00 2001 From: Jak Daniels Date: Sat, 3 Jan 2015 21:34:16 +0000 Subject: [PATCH] Added new commands to alter flock dynamics in realtime. Updated README.md --- Module/BirdsModule/FlockingModel.cs | 15 +++-- Module/BirdsModule/FlockingModule.cs | 92 ++++++++++++++++++++++++++-- README.md | 40 ++++++++---- 3 files changed, 123 insertions(+), 24 deletions(-) diff --git a/Module/BirdsModule/FlockingModel.cs b/Module/BirdsModule/FlockingModel.cs index 1a05488..84158d2 100644 --- a/Module/BirdsModule/FlockingModel.cs +++ b/Module/BirdsModule/FlockingModel.cs @@ -89,23 +89,28 @@ namespace Flocking } public float MaxSpeed { - get {return m_maxSpeed;} + get {return m_maxSpeed;} + set { m_maxSpeed = value; } } public float MaxForce { - get {return m_maxForce;} + get {return m_maxForce;} + set { m_maxForce = value; } } public float NeighbourDistance { - get {return m_neighbourDistance;} + get {return m_neighbourDistance;} + set { m_neighbourDistance = value; } } public float DesiredSeparation { - get {return m_desiredSeparation;} + get {return m_desiredSeparation;} + set { m_desiredSeparation = value; } } public float Tolerance { - get {return m_tolerance;} + get {return m_tolerance;} + set { m_tolerance = value; } } diff --git a/Module/BirdsModule/FlockingModule.cs b/Module/BirdsModule/FlockingModule.cs index 02b059c..93fbd8f 100644 --- a/Module/BirdsModule/FlockingModule.cs +++ b/Module/BirdsModule/FlockingModule.cs @@ -264,7 +264,17 @@ namespace Flocking } else if (cmd.StartsWith ("stats")) { HandleShowStatsCmd (m_name, args); } else if (cmd.StartsWith ("prim")) { - HandleSetPrimCmd (m_name, args); + HandleSetPrimCmd (m_name, args); + } else if (cmd.StartsWith("speed")) { + HandleSetMaxSpeedCmd(m_name, args); + } else if (cmd.StartsWith("force")) { + HandleSetMaxForceCmd(m_name, args); + } else if (cmd.StartsWith("distance")) { + HandleSetNeighbourDistanceCmd(m_name, args); + } else if (cmd.StartsWith("separation")) { + HandleSetDesiredSeparationCmd(m_name, args); + } else if (cmd.StartsWith("tolerance")) { + HandleSetToleranceCmd(m_name, args); } else if (cmd.StartsWith ("framerate")) { HandleSetFrameRateCmd (m_name, args); } @@ -293,10 +303,15 @@ namespace Flocking AddCommand ("enable", "", "Enable Birds Flocking", HandleEnableCmd); AddCommand ("disable", "", "Disable Birds Flocking", HandleDisableCmd); 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 bird to that passed in", HandleSetPrimCmd); - AddCommand ("framerate", "num", "[debugging] only update birds every frames", HandleSetFrameRateCmd); - } + AddCommand ("stats", "", "Show flocking stats", HandleShowStatsCmd); + 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); + AddCommand("separation", "num", "How far away from other birds we would like to stay", HandleSetDesiredSeparationCmd); + AddCommand("tolerance", "num", "How close to the edges of things can we get without being worried", HandleSetToleranceCmd); + AddCommand("framerate", "num", "[debugging] only update birds every frames", HandleSetFrameRateCmd); + } private bool ShouldHandleCmd () { @@ -407,7 +422,72 @@ namespace Flocking m_view.Clear(); } } - } + } + + public void HandleSetMaxSpeedCmd(string module, string[] args) + { + if (ShouldHandleCmd()) + { + float maxSpeed = (float)Convert.ToDecimal(args[1]); + lock (m_sync) + { + m_model.MaxSpeed = maxSpeed; + m_log.InfoFormat("[{0}]: Birds maximum speed is set to {1} in region {2}.", m_name, maxSpeed, m_scene.RegionInfo.RegionName); + } + } + } + + public void HandleSetMaxForceCmd(string module, string[] args) + { + if (ShouldHandleCmd()) + { + float maxForce = (float)Convert.ToDecimal(args[1]); + lock (m_sync) + { + m_model.MaxForce = maxForce; + m_log.InfoFormat("[{0}]: Birds maximum force is set to {1} in region {2}.", m_name, maxForce, m_scene.RegionInfo.RegionName); + } + } + } + + public void HandleSetNeighbourDistanceCmd(string module, string[] args) + { + if (ShouldHandleCmd()) + { + float neighbourDistance = (float)Convert.ToDecimal(args[1]); + lock (m_sync) + { + m_model.NeighbourDistance = neighbourDistance; + m_log.InfoFormat("[{0}]: Birds neighbour distance is set to {1} in region {2}.", m_name, neighbourDistance, m_scene.RegionInfo.RegionName); + } + } + } + + public void HandleSetDesiredSeparationCmd(string module, string[] args) + { + if (ShouldHandleCmd()) + { + float desiredSeparation = (float)Convert.ToDecimal(args[1]); + lock (m_sync) + { + m_model.DesiredSeparation = desiredSeparation; + m_log.InfoFormat("[{0}]: Birds desired separation is set to {1} in region {2}.", m_name, desiredSeparation, m_scene.RegionInfo.RegionName); + } + } + } + + public void HandleSetToleranceCmd(string module, string[] args) + { + if (ShouldHandleCmd()) + { + float tolerance = (float)Convert.ToDecimal(args[1]); + lock (m_sync) + { + m_model.Tolerance = tolerance; + m_log.InfoFormat("[{0}]: Birds tolerance is set to {1} in region {2}.", m_name, tolerance, m_scene.RegionInfo.RegionName); + } + } + } #endregion diff --git a/README.md b/README.md index d73de75..6b5db44 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ provided which should be edited and copied to the correct place above. Here is an example config: -;; Set the Birds settings per named region + ;; Set the Birds settings per named region [Test Region 1] @@ -51,7 +51,8 @@ Here is an example config: Various runtime commands control the flocking module behaviour - described below. These can either be invoked -from the Console or in world by directing them to a chat channel. You can specify which channel to use in the .ini: +from the Console or in world by directing them to a chat channel either from the client's Local Chat or via a script. +You can specify which channel to use in the .ini: BirdsChatChannel = 118 the chat channel to listen for Bird commands on @@ -59,18 +60,31 @@ from the Console or in world by directing them to a chat channel. You can specif Runtime Commands -The following commands, which can either be issued on the Console, or via a chat channel in-world, control the behaviour -of the flock at runtime +The following commands, which can be issued on the Console or via in-world chat or scripted chat on the BirdsChatChannel +to control the birds at runtime: - birds-stop or /118 stop ;stop all birds flocking - birds-start or /118 start ;start all birds flocking - birds-enable or /118 enable ;enable the flocking simulation if disabled - birds-disable or /118 disable ;stop all birds and remove them from the scene - birds-size or /118 size ;change the size of the flock - birds-prim or /118 prim ;change the bird prim to one already rezzed in the scene - birds-framerate or /118 framerate ;only update the flock positions every frames - ;only really useful for photography and debugging bird - ;behaviour + birds-stop or /118 stop ;stop all birds flocking + birds-start or /118 start ;start all birds flocking + birds-enable or /118 enable ;enable the flocking simulation if disabled + birds-disable or /118 disable ;stop all birds and remove them from the scene + birds-prim or /118 prim ;change the bird prim to a prim already rezzed in the scene + birds-stats or /118 stats ;show some statistics (needs work) + birds-framerate or /118 framerate ;only update the flock positions every frames + ;only really useful for photography and debugging bird + ;behaviour + + +These commands are great for playing with the flock dynamics in real time: + + birds-size or /118 size ;change the size of the flock + birds-speed or /118 speed ;change the maximum velocity each bird may achieve + birds-force or /118 force ;change the maximum force each bird may accelerate + birds-distance or /118 distance ;change the maximum distance that other birds are to be considered in the same flock as us + birds-separation or /118 separation ;sets how far away from other birds we would like to stay + birds-tolerance or /118 tolerance ;sets how close to the edges of things can we get without being worried + +Of course if distance is less than separation then the birds will never flock. The other way around and they will always +eventually form one or more flocks. Bird prims