diff options
author | onefang | 2019-05-19 21:24:15 +1000 |
---|---|---|
committer | onefang | 2019-05-19 21:24:15 +1000 |
commit | 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch) | |
tree | a9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/CoreModules/World/Wind | |
parent | Add a build script. (diff) | |
download | opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2 opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz |
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Wind')
3 files changed, 52 insertions, 76 deletions
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs index 6af4050..a2b44df 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs | |||
@@ -50,7 +50,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
50 | private float m_avgDirection = 0.0f; // Average direction of the wind in degrees | 50 | private float m_avgDirection = 0.0f; // Average direction of the wind in degrees |
51 | private float m_varStrength = 5.0f; // Max Strength Variance | 51 | private float m_varStrength = 5.0f; // Max Strength Variance |
52 | private float m_varDirection = 30.0f;// Max Direction Variance | 52 | private float m_varDirection = 30.0f;// Max Direction Variance |
53 | private float m_rateChange = 1.0f; // | 53 | private float m_rateChange = 1.0f; // |
54 | 54 | ||
55 | private Vector2 m_curPredominateWind = new Vector2(); | 55 | private Vector2 m_curPredominateWind = new Vector2(); |
56 | 56 | ||
@@ -70,7 +70,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
70 | 70 | ||
71 | public void Initialise() | 71 | public void Initialise() |
72 | { | 72 | { |
73 | 73 | ||
74 | } | 74 | } |
75 | 75 | ||
76 | #endregion | 76 | #endregion |
@@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | public void WindUpdate(uint frame) | 106 | public bool WindUpdate(uint frame) |
107 | { | 107 | { |
108 | double avgAng = m_avgDirection * (Math.PI/180.0f); | 108 | double avgAng = m_avgDirection * (Math.PI/180.0f); |
109 | double varDir = m_varDirection * (Math.PI/180.0f); | 109 | double varDir = m_varDirection * (Math.PI/180.0f); |
@@ -111,7 +111,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
111 | // Prevailing wind algorithm | 111 | // Prevailing wind algorithm |
112 | // Inspired by Kanker Greenacre | 112 | // Inspired by Kanker Greenacre |
113 | 113 | ||
114 | // TODO: | 114 | // TODO: |
115 | // * This should probably be based on in-world time. | 115 | // * This should probably be based on in-world time. |
116 | // * should probably move all these local variables to class members and constants | 116 | // * should probably move all these local variables to class members and constants |
117 | double time = DateTime.Now.TimeOfDay.Seconds / 86400.0f; | 117 | double time = DateTime.Now.TimeOfDay.Seconds / 86400.0f; |
@@ -125,10 +125,8 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
125 | offset = Math.Sin(theta) * Math.Sin(theta*4) + (Math.Sin(theta*13) / 3); | 125 | offset = Math.Sin(theta) * Math.Sin(theta*4) + (Math.Sin(theta*13) / 3); |
126 | double windSpeed = m_avgStrength + (m_varStrength * offset); | 126 | double windSpeed = m_avgStrength + (m_varStrength * offset); |
127 | 127 | ||
128 | if (windSpeed<0) | 128 | if (windSpeed < 0) |
129 | windSpeed=0; | 129 | windSpeed = -windSpeed; |
130 | |||
131 | |||
132 | 130 | ||
133 | m_curPredominateWind.X = (float)Math.Cos(windDir); | 131 | m_curPredominateWind.X = (float)Math.Cos(windDir); |
134 | m_curPredominateWind.Y = (float)Math.Sin(windDir); | 132 | m_curPredominateWind.Y = (float)Math.Sin(windDir); |
@@ -144,6 +142,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
144 | m_windSpeeds[y * 16 + x] = m_curPredominateWind; | 142 | m_windSpeeds[y * 16 + x] = m_curPredominateWind; |
145 | } | 143 | } |
146 | } | 144 | } |
145 | return true; | ||
147 | } | 146 | } |
148 | 147 | ||
149 | public Vector3 WindSpeed(float fX, float fY, float fZ) | 148 | public Vector3 WindSpeed(float fX, float fY, float fZ) |
@@ -158,9 +157,9 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
158 | 157 | ||
159 | public string Description | 158 | public string Description |
160 | { | 159 | { |
161 | get | 160 | get |
162 | { | 161 | { |
163 | return "Provides a predominate wind direction that can change within configured variances for direction and speed."; | 162 | return "Provides a predominate wind direction that can change within configured variances for direction and speed."; |
164 | } | 163 | } |
165 | } | 164 | } |
166 | 165 | ||
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs index fcb0c10..d2ff7b3 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs | |||
@@ -82,22 +82,23 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins | |||
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | public void WindUpdate(uint frame) | 85 | public bool WindUpdate(uint frame) |
86 | { | 86 | { |
87 | //Make sure our object is valid (we haven't been disposed of yet) | 87 | //Make sure our object is valid (we haven't been disposed of yet) |
88 | if (m_windSpeeds != null) | 88 | if (m_windSpeeds == null) |
89 | return false; | ||
90 | |||
91 | for (int y = 0; y < 16; y++) | ||
89 | { | 92 | { |
90 | for (int y = 0; y < 16; y++) | 93 | for (int x = 0; x < 16; x++) |
91 | { | 94 | { |
92 | for (int x = 0; x < 16; x++) | 95 | m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1 |
93 | { | 96 | m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1 |
94 | m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1 | 97 | m_windSpeeds[y * 16 + x].X *= m_strength; |
95 | m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1 | 98 | m_windSpeeds[y * 16 + x].Y *= m_strength; |
96 | m_windSpeeds[y * 16 + x].X *= m_strength; | ||
97 | m_windSpeeds[y * 16 + x].Y *= m_strength; | ||
98 | } | ||
99 | } | 99 | } |
100 | } | 100 | } |
101 | return true; | ||
101 | } | 102 | } |
102 | 103 | ||
103 | public Vector3 WindSpeed(float fX, float fY, float fZ) | 104 | public Vector3 WindSpeed(float fX, float fY, float fZ) |
diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs index 35014f5..a1fff62 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,7 +98,6 @@ 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 | { |
@@ -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 | } |