diff options
author | onefang | 2019-09-11 16:36:50 +1000 |
---|---|---|
committer | onefang | 2019-09-11 16:36:50 +1000 |
commit | 50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch) | |
tree | 52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/CoreModules/World/Wind/WindModule.cs | |
parent | Renamed branch to SledjChisl. (diff) | |
parent | Bump to release flavour, build 0. (diff) | |
download | opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2 opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz |
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Wind/WindModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Wind/WindModule.cs | 92 |
1 files changed, 34 insertions, 58 deletions
diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs index 35014f5..96ba003 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs | |||
@@ -46,11 +46,13 @@ namespace OpenSim.Region.CoreModules | |||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | private uint m_frame = 0; | 48 | private uint m_frame = 0; |
49 | private uint m_frameLastUpdateClientArray = 0; | 49 | private int m_dataVersion = 0; |
50 | // private int m_regionID = 0; | ||
50 | private int m_frameUpdateRate = 150; | 51 | private int m_frameUpdateRate = 150; |
51 | //private Random m_rndnums = new Random(Environment.TickCount); | 52 | //private Random m_rndnums = new Random(Environment.TickCount); |
52 | private Scene m_scene = null; | 53 | private Scene m_scene = null; |
53 | private bool m_ready = false; | 54 | private bool m_ready = false; |
55 | private bool m_inUpdate = false; | ||
54 | 56 | ||
55 | private bool m_enabled = false; | 57 | private bool m_enabled = false; |
56 | private IConfig m_windConfig; | 58 | private IConfig m_windConfig; |
@@ -96,11 +98,10 @@ namespace OpenSim.Region.CoreModules | |||
96 | 98 | ||
97 | m_scene = scene; | 99 | m_scene = scene; |
98 | m_frame = 0; | 100 | m_frame = 0; |
99 | |||
100 | // Register all the Wind Model Plug-ins | 101 | // Register all the Wind Model Plug-ins |
101 | foreach (IWindModelPlugin windPlugin in AddinManager.GetExtensionObjects("/OpenSim/WindModule", false)) | 102 | foreach (IWindModelPlugin windPlugin in AddinManager.GetExtensionObjects("/OpenSim/WindModule", false)) |
102 | { | 103 | { |
103 | m_log.InfoFormat("[WIND] Found Plugin: {0}", windPlugin.Name); | 104 | m_log.DebugFormat("[WIND] Found Plugin: {0}", windPlugin.Name); |
104 | m_availableWindPlugins.Add(windPlugin.Name, windPlugin); | 105 | m_availableWindPlugins.Add(windPlugin.Name, windPlugin); |
105 | } | 106 | } |
106 | 107 | ||
@@ -109,7 +110,7 @@ namespace OpenSim.Region.CoreModules | |||
109 | { | 110 | { |
110 | m_activeWindPlugin = m_availableWindPlugins[m_dWindPluginName]; | 111 | m_activeWindPlugin = m_availableWindPlugins[m_dWindPluginName]; |
111 | 112 | ||
112 | m_log.InfoFormat("[WIND] {0} plugin found, initializing.", m_dWindPluginName); | 113 | m_log.DebugFormat("[WIND] {0} plugin found, initializing.", m_dWindPluginName); |
113 | 114 | ||
114 | if (m_windConfig != null) | 115 | if (m_windConfig != null) |
115 | { | 116 | { |
@@ -118,7 +119,6 @@ namespace OpenSim.Region.CoreModules | |||
118 | } | 119 | } |
119 | } | 120 | } |
120 | 121 | ||
121 | |||
122 | // if the plug-in wasn't found, default to no wind. | 122 | // if the plug-in wasn't found, default to no wind. |
123 | if (m_activeWindPlugin == null) | 123 | if (m_activeWindPlugin == null) |
124 | { | 124 | { |
@@ -154,14 +154,14 @@ namespace OpenSim.Region.CoreModules | |||
154 | 154 | ||
155 | // Register event handlers for when Avatars enter the region, and frame ticks | 155 | // Register event handlers for when Avatars enter the region, and frame ticks |
156 | m_scene.EventManager.OnFrame += WindUpdate; | 156 | m_scene.EventManager.OnFrame += WindUpdate; |
157 | m_scene.EventManager.OnMakeRootAgent += OnAgentEnteredRegion; | ||
158 | 157 | ||
159 | // Register the wind module | 158 | // Register the wind module |
160 | m_scene.RegisterModuleInterface<IWindModule>(this); | 159 | m_scene.RegisterModuleInterface<IWindModule>(this); |
161 | 160 | ||
162 | // Generate initial wind values | 161 | // Generate initial wind values |
163 | GenWindPos(); | 162 | GenWind(); |
164 | 163 | // hopefully this will not be the same for all regions on same instance | |
164 | m_dataVersion = (int)m_scene.AllocateLocalId(); | ||
165 | // Mark Module Ready for duty | 165 | // Mark Module Ready for duty |
166 | m_ready = true; | 166 | m_ready = true; |
167 | } | 167 | } |
@@ -184,7 +184,7 @@ namespace OpenSim.Region.CoreModules | |||
184 | 184 | ||
185 | // Remove our hooks | 185 | // Remove our hooks |
186 | m_scene.EventManager.OnFrame -= WindUpdate; | 186 | m_scene.EventManager.OnFrame -= WindUpdate; |
187 | m_scene.EventManager.OnMakeRootAgent -= OnAgentEnteredRegion; | 187 | // m_scene.EventManager.OnMakeRootAgent -= OnAgentEnteredRegion; |
188 | 188 | ||
189 | } | 189 | } |
190 | 190 | ||
@@ -351,7 +351,7 @@ namespace OpenSim.Region.CoreModules | |||
351 | #region IWindModule Methods | 351 | #region IWindModule Methods |
352 | 352 | ||
353 | /// <summary> | 353 | /// <summary> |
354 | /// Retrieve the wind speed at the given region coordinate. This | 354 | /// Retrieve the wind speed at the given region coordinate. This |
355 | /// implimentation ignores Z. | 355 | /// implimentation ignores Z. |
356 | /// </summary> | 356 | /// </summary> |
357 | /// <param name="x">0...255</param> | 357 | /// <param name="x">0...255</param> |
@@ -396,7 +396,7 @@ namespace OpenSim.Region.CoreModules | |||
396 | 396 | ||
397 | public string WindActiveModelPluginName | 397 | public string WindActiveModelPluginName |
398 | { | 398 | { |
399 | get | 399 | get |
400 | { | 400 | { |
401 | if (m_activeWindPlugin != null) | 401 | if (m_activeWindPlugin != null) |
402 | { | 402 | { |
@@ -416,67 +416,43 @@ namespace OpenSim.Region.CoreModules | |||
416 | /// </summary> | 416 | /// </summary> |
417 | public void WindUpdate() | 417 | public void WindUpdate() |
418 | { | 418 | { |
419 | if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready) | 419 | if ((!m_ready || m_inUpdate || (m_frame++ % m_frameUpdateRate) != 0)) |
420 | { | ||
421 | return; | 420 | return; |
422 | } | ||
423 | |||
424 | GenWindPos(); | ||
425 | |||
426 | SendWindAllClients(); | ||
427 | } | ||
428 | 421 | ||
429 | public void OnAgentEnteredRegion(ScenePresence avatar) | 422 | m_inUpdate = true; |
430 | { | 423 | Util.FireAndForget(delegate |
431 | if (m_ready) | ||
432 | { | 424 | { |
433 | if (m_activeWindPlugin != null) | 425 | try |
434 | { | 426 | { |
435 | // Ask wind plugin to generate a LL wind array to be cached locally | 427 | GenWind(); |
436 | // Try not to update this too often, as it may involve array copies | 428 | m_scene.ForEachClient(delegate(IClientAPI client) |
437 | if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate)) | ||
438 | { | 429 | { |
439 | windSpeeds = m_activeWindPlugin.WindLLClientArray(); | 430 | client.SendWindData(m_dataVersion, windSpeeds); |
440 | m_frameLastUpdateClientArray = m_frame; | 431 | }); |
441 | } | ||
442 | } | ||
443 | |||
444 | avatar.ControllingClient.SendWindData(windSpeeds); | ||
445 | } | ||
446 | } | ||
447 | 432 | ||
448 | private void SendWindAllClients() | 433 | } |
449 | { | 434 | finally |
450 | if (m_ready) | ||
451 | { | ||
452 | if (m_scene.GetRootAgentCount() > 0) | ||
453 | { | 435 | { |
454 | // Ask wind plugin to generate a LL wind array to be cached locally | 436 | m_inUpdate = false; |
455 | // Try not to update this too often, as it may involve array copies | ||
456 | if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate)) | ||
457 | { | ||
458 | windSpeeds = m_activeWindPlugin.WindLLClientArray(); | ||
459 | m_frameLastUpdateClientArray = m_frame; | ||
460 | } | ||
461 | |||
462 | m_scene.ForEachRootClient(delegate(IClientAPI client) | ||
463 | { | ||
464 | client.SendWindData(windSpeeds); | ||
465 | }); | ||
466 | } | 437 | } |
467 | } | 438 | }, |
439 | null, "WindModuleUpdate"); | ||
468 | } | 440 | } |
441 | |||
469 | /// <summary> | 442 | /// <summary> |
470 | /// Calculate the sun's orbital position and its velocity. | 443 | /// Calculate new wind |
444 | /// returns false if no change | ||
471 | /// </summary> | 445 | /// </summary> |
472 | 446 | ||
473 | private void GenWindPos() | 447 | private bool GenWind() |
474 | { | 448 | { |
475 | if (m_activeWindPlugin != null) | 449 | if (m_activeWindPlugin != null && m_activeWindPlugin.WindUpdate(m_frame)) |
476 | { | 450 | { |
477 | // Tell Wind Plugin to update it's wind data | 451 | windSpeeds = m_activeWindPlugin.WindLLClientArray(); |
478 | m_activeWindPlugin.WindUpdate(m_frame); | 452 | m_dataVersion++; |
453 | return true; | ||
479 | } | 454 | } |
455 | return false; | ||
480 | } | 456 | } |
481 | } | 457 | } |
482 | } | 458 | } |