Module is started by default, and can run without a config, but will not be enabled. Module can be specifically disabled in a region with BirdsModuleStartup = True/False

pull/1/merge
Jak Daniels 2015-10-16 15:00:55 +01:00
parent 3dcb5d0b1c
commit d356b62176
1 changed files with 53 additions and 45 deletions

View File

@ -60,6 +60,7 @@ namespace Flocking
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_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;
@ -128,10 +129,11 @@ namespace Flocking
} }
} }
m_enabled = cnf.GetBoolean("BirdsEnabled", false); m_startup = cnf.GetBoolean("BirdsModuleStartup", true);
if (m_enabled) if (m_startup)
{ {
m_enabled = cnf.GetBoolean("BirdsEnabled", false);
m_chatChannel = cnf.GetInt("BirdsChatChannel", 118); m_chatChannel = cnf.GetInt("BirdsChatChannel", 118);
m_birdPrim = cnf.GetString("BirdsPrim", "birdPrim"); m_birdPrim = cnf.GetString("BirdsPrim", "birdPrim");
m_flockSize = cnf.GetInt("BirdsFlockSize", 50); m_flockSize = cnf.GetInt("BirdsFlockSize", 50);
@ -145,7 +147,7 @@ namespace Flocking
m_maxHeight = cnf.GetInt("BirdsMaxHeight", 256); m_maxHeight = cnf.GetInt("BirdsMaxHeight", 256);
m_frameUpdateRate = cnf.GetInt("BirdsUpdateEveryNFrames", 1); m_frameUpdateRate = cnf.GetInt("BirdsUpdateEveryNFrames", 1);
m_log.InfoFormat("[{0}] Enabled on channel {1} with Flock Size {2}", m_name, m_chatChannel, m_flockSize); m_log.InfoFormat("[{0}] Module is {1} listening for commands on channel {2} with Flock Size {3}", m_name, m_enabled?"enabled and":"disabled, but", m_chatChannel, m_flockSize);
m_scene = scene; m_scene = scene;
m_console = MainConsole.Instance; m_console = MainConsole.Instance;
@ -173,7 +175,7 @@ namespace Flocking
public void RegionLoaded (Scene scene) public void RegionLoaded (Scene scene)
{ {
if (m_enabled) if (m_startup)
{ {
// Mark Module Ready for duty // Mark Module Ready for duty
m_ready = true; m_ready = true;
@ -189,24 +191,25 @@ namespace Flocking
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_enabled) { if (m_startup) {
m_view.Clear(); m_view.Clear();
m_ready = false;
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;
} }
} }
public void Close() public void Close()
{ {
if (m_enabled) if (m_startup)
{ {
m_ready = false;
m_scene.EventManager.OnFrame -= FlockUpdate; m_scene.EventManager.OnFrame -= FlockUpdate;
m_scene.EventManager.OnChatFromClient -= SimChatSent; m_scene.EventManager.OnChatFromClient -= SimChatSent;
m_scene.EventManager.OnChatFromWorld -= SimChatSent; m_scene.EventManager.OnChatFromWorld -= SimChatSent;
m_scene.EventManager.OnPrimsLoaded -= PrimsLoaded;
m_ready = false;
} }
} }
@ -253,7 +256,8 @@ namespace Flocking
public void FlockUpdate () public void FlockUpdate ()
{ {
if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready || !m_enabled) { if (!m_ready || !m_enabled || ((m_frame++ % m_frameUpdateRate) != 0))
{
return; return;
} }
@ -396,18 +400,18 @@ namespace Flocking
if (m_ready && ShouldHandleCmd ()) { if (m_ready && ShouldHandleCmd ()) {
m_log.InfoFormat("[{0}]: Bird flocking is disabled in region {1}.", m_name, m_scene.RegionInfo.RegionName); m_log.InfoFormat("[{0}]: Bird flocking is disabled in region {1}.", m_name, m_scene.RegionInfo.RegionName);
m_enabled = false; m_enabled = false;
m_ready = false; //m_ready = false;
m_view.Clear(); m_view.Clear();
} }
} }
public void HandleEnableCmd(string module, string[] args) public void HandleEnableCmd(string module, string[] args)
{ {
if (!m_ready && ShouldHandleCmd()) if (m_ready && ShouldHandleCmd())
{ {
m_log.InfoFormat("[{0}]: Bird flocking is enabled in region {1}.", m_name, m_scene.RegionInfo.RegionName); m_log.InfoFormat("[{0}]: Bird flocking is enabled in region {1}.", m_name, m_scene.RegionInfo.RegionName);
m_enabled = true; m_enabled = true;
m_ready = true; //m_ready = true;
} }
} }
@ -432,7 +436,8 @@ namespace Flocking
void HandleSetFrameRateCmd (string module, string[] args) void HandleSetFrameRateCmd (string module, string[] args)
{ {
if (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);
@ -441,7 +446,8 @@ namespace Flocking
public void HandleSetSizeCmd (string module, string[] args) public void HandleSetSizeCmd (string module, string[] args)
{ {
if (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;
@ -455,7 +461,8 @@ namespace Flocking
public void HandleShowStatsCmd (string module, string[] args) public void HandleShowStatsCmd (string module, string[] args)
{ {
if (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;
@ -509,7 +516,8 @@ namespace Flocking
public void HandleSetPrimCmd (string module, string[] args) public void HandleSetPrimCmd (string module, string[] args)
{ {
if (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;
@ -521,7 +529,7 @@ namespace Flocking
public void HandleSetMaxSpeedCmd(string module, string[] args) public void HandleSetMaxSpeedCmd(string module, string[] args)
{ {
if (ShouldHandleCmd()) if (m_ready && ShouldHandleCmd())
{ {
float maxSpeed = (float)Convert.ToDecimal(args[1]); float maxSpeed = (float)Convert.ToDecimal(args[1]);
lock (m_sync) lock (m_sync)
@ -534,7 +542,7 @@ namespace Flocking
public void HandleSetMaxForceCmd(string module, string[] args) public void HandleSetMaxForceCmd(string module, string[] args)
{ {
if (ShouldHandleCmd()) if (m_ready && ShouldHandleCmd())
{ {
float maxForce = (float)Convert.ToDecimal(args[1]); float maxForce = (float)Convert.ToDecimal(args[1]);
lock (m_sync) lock (m_sync)
@ -547,7 +555,7 @@ namespace Flocking
public void HandleSetNeighbourDistanceCmd(string module, string[] args) public void HandleSetNeighbourDistanceCmd(string module, string[] args)
{ {
if (ShouldHandleCmd()) if (m_ready && ShouldHandleCmd())
{ {
float neighbourDistance = (float)Convert.ToDecimal(args[1]); float neighbourDistance = (float)Convert.ToDecimal(args[1]);
lock (m_sync) lock (m_sync)
@ -560,7 +568,7 @@ namespace Flocking
public void HandleSetDesiredSeparationCmd(string module, string[] args) public void HandleSetDesiredSeparationCmd(string module, string[] args)
{ {
if (ShouldHandleCmd()) if (m_ready && ShouldHandleCmd())
{ {
float desiredSeparation = (float)Convert.ToDecimal(args[1]); float desiredSeparation = (float)Convert.ToDecimal(args[1]);
lock (m_sync) lock (m_sync)
@ -573,7 +581,7 @@ namespace Flocking
public void HandleSetToleranceCmd(string module, string[] args) public void HandleSetToleranceCmd(string module, string[] args)
{ {
if (ShouldHandleCmd()) if (m_ready && ShouldHandleCmd())
{ {
float tolerance = (float)Convert.ToDecimal(args[1]); float tolerance = (float)Convert.ToDecimal(args[1]);
lock (m_sync) lock (m_sync)