diff options
author | UbitUmarov | 2016-09-23 12:32:40 +0100 |
---|---|---|
committer | UbitUmarov | 2016-09-23 12:32:40 +0100 |
commit | 984cb385831e6613fade75046d352a2f68f3ae2b (patch) | |
tree | 042f22c7d97f456fbdbab84ba81f41f063abe821 /OpenSim/Region/CoreModules | |
parent | bug fix: add a missing return; add some error messages (diff) | |
download | opensim-SC-984cb385831e6613fade75046d352a2f68f3ae2b.zip opensim-SC-984cb385831e6613fade75046d352a2f68f3ae2b.tar.gz opensim-SC-984cb385831e6613fade75046d352a2f68f3ae2b.tar.bz2 opensim-SC-984cb385831e6613fade75046d352a2f68f3ae2b.tar.xz |
move wind generation out of heartbeat to a pool job. Use that to send to all clients and not one per client
Diffstat (limited to 'OpenSim/Region/CoreModules')
3 files changed, 55 insertions, 58 deletions
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs index 6af4050..65691fe 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs | |||
@@ -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); |
@@ -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) |
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 2f401bf..9f13d90 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs | |||
@@ -51,6 +51,7 @@ namespace OpenSim.Region.CoreModules | |||
51 | //private Random m_rndnums = new Random(Environment.TickCount); | 51 | //private Random m_rndnums = new Random(Environment.TickCount); |
52 | private Scene m_scene = null; | 52 | private Scene m_scene = null; |
53 | private bool m_ready = false; | 53 | private bool m_ready = false; |
54 | private bool m_inUpdate = false; | ||
54 | 55 | ||
55 | private bool m_enabled = false; | 56 | private bool m_enabled = false; |
56 | private IConfig m_windConfig; | 57 | private IConfig m_windConfig; |
@@ -160,7 +161,7 @@ namespace OpenSim.Region.CoreModules | |||
160 | m_scene.RegisterModuleInterface<IWindModule>(this); | 161 | m_scene.RegisterModuleInterface<IWindModule>(this); |
161 | 162 | ||
162 | // Generate initial wind values | 163 | // Generate initial wind values |
163 | GenWindPos(); | 164 | GenWind(); |
164 | 165 | ||
165 | // Mark Module Ready for duty | 166 | // Mark Module Ready for duty |
166 | m_ready = true; | 167 | m_ready = true; |
@@ -416,67 +417,63 @@ namespace OpenSim.Region.CoreModules | |||
416 | /// </summary> | 417 | /// </summary> |
417 | public void WindUpdate() | 418 | public void WindUpdate() |
418 | { | 419 | { |
419 | if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready) | 420 | if ((!m_ready || m_inUpdate || (m_frame++ % m_frameUpdateRate) != 0)) |
420 | { | ||
421 | return; | 421 | return; |
422 | } | ||
423 | 422 | ||
424 | GenWindPos(); | 423 | m_inUpdate = true; |
425 | 424 | Util.FireAndForget(delegate | |
426 | SendWindAllClients(); | ||
427 | } | ||
428 | /* | ||
429 | public void OnAgentEnteredRegion(ScenePresence avatar) | ||
430 | { | ||
431 | if (m_ready) | ||
432 | { | 425 | { |
433 | if (m_activeWindPlugin != null) | 426 | try |
434 | { | 427 | { |
435 | // Ask wind plugin to generate a LL wind array to be cached locally | 428 | if(GenWind()) |
436 | // Try not to update this too often, as it may involve array copies | 429 | windSpeeds = m_activeWindPlugin.WindLLClientArray(); |
437 | if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate)) | ||
438 | { | ||
439 | windSpeeds = m_activeWindPlugin.WindLLClientArray(); | ||
440 | m_frameLastUpdateClientArray = m_frame; | ||
441 | } | ||
442 | } | ||
443 | 430 | ||
444 | avatar.ControllingClient.SendWindData(windSpeeds); | 431 | m_scene.ForEachRootClient(delegate(IClientAPI client) |
445 | } | 432 | { |
433 | client.SendWindData(windSpeeds); | ||
434 | }); | ||
435 | |||
436 | } | ||
437 | finally | ||
438 | { | ||
439 | m_inUpdate = false; | ||
440 | } | ||
441 | }, | ||
442 | null, "WindModuleUpdate"); | ||
446 | } | 443 | } |
447 | */ | 444 | /* |
448 | private void SendWindAllClients() | 445 | private void SendWindAllClients() |
449 | { | 446 | { |
450 | if (m_ready) | 447 | if (!m_ready || m_scene.GetRootAgentCount() == 0) |
451 | { | 448 | return; |
452 | if (m_scene.GetRootAgentCount() > 0) | ||
453 | { | ||
454 | // Ask wind plugin to generate a LL wind array to be cached locally | ||
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 | 449 | ||
462 | m_scene.ForEachRootClient(delegate(IClientAPI client) | 450 | // Ask wind plugin to generate a LL wind array to be cached locally |
463 | { | 451 | // Try not to update this too often, as it may involve array copies |
464 | client.SendWindData(windSpeeds); | 452 | if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate)) |
465 | }); | 453 | { |
466 | } | 454 | windSpeeds = m_activeWindPlugin.WindLLClientArray(); |
455 | m_frameLastUpdateClientArray = m_frame; | ||
467 | } | 456 | } |
457 | |||
458 | m_scene.ForEachRootClient(delegate(IClientAPI client) | ||
459 | { | ||
460 | client.SendWindData(windSpeeds); | ||
461 | }); | ||
468 | } | 462 | } |
463 | */ | ||
469 | /// <summary> | 464 | /// <summary> |
470 | /// Calculate the sun's orbital position and its velocity. | 465 | /// Calculate new wind |
466 | /// returns false if no change | ||
471 | /// </summary> | 467 | /// </summary> |
472 | 468 | ||
473 | private void GenWindPos() | 469 | private bool GenWind() |
474 | { | 470 | { |
475 | if (m_activeWindPlugin != null) | 471 | if (m_activeWindPlugin != null) |
476 | { | 472 | { |
477 | // Tell Wind Plugin to update it's wind data | 473 | // Tell Wind Plugin to update it's wind data |
478 | m_activeWindPlugin.WindUpdate(m_frame); | 474 | return m_activeWindPlugin.WindUpdate(m_frame); |
479 | } | 475 | } |
476 | return false; | ||
480 | } | 477 | } |
481 | } | 478 | } |
482 | } | 479 | } |