move wind generation out of heartbeat to a pool job. Use that to send to all clients and not one per client

0.9.0-post-fixes
UbitUmarov 2016-09-23 12:32:40 +01:00
parent 7201352074
commit 984cb38583
4 changed files with 57 additions and 60 deletions

View File

@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins
}
}
public void WindUpdate(uint frame)
public bool WindUpdate(uint frame)
{
double avgAng = m_avgDirection * (Math.PI/180.0f);
double varDir = m_varDirection * (Math.PI/180.0f);
@ -125,10 +125,8 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins
offset = Math.Sin(theta) * Math.Sin(theta*4) + (Math.Sin(theta*13) / 3);
double windSpeed = m_avgStrength + (m_varStrength * offset);
if (windSpeed<0)
windSpeed=0;
if (windSpeed < 0)
windSpeed = -windSpeed;
m_curPredominateWind.X = (float)Math.Cos(windDir);
m_curPredominateWind.Y = (float)Math.Sin(windDir);
@ -144,6 +142,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins
m_windSpeeds[y * 16 + x] = m_curPredominateWind;
}
}
return true;
}
public Vector3 WindSpeed(float fX, float fY, float fZ)

View File

@ -82,22 +82,23 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins
}
}
public void WindUpdate(uint frame)
public bool WindUpdate(uint frame)
{
//Make sure our object is valid (we haven't been disposed of yet)
if (m_windSpeeds != null)
if (m_windSpeeds == null)
return false;
for (int y = 0; y < 16; y++)
{
for (int y = 0; y < 16; y++)
for (int x = 0; x < 16; x++)
{
for (int x = 0; x < 16; x++)
{
m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
m_windSpeeds[y * 16 + x].X *= m_strength;
m_windSpeeds[y * 16 + x].Y *= m_strength;
}
m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
m_windSpeeds[y * 16 + x].X *= m_strength;
m_windSpeeds[y * 16 + x].Y *= m_strength;
}
}
return true;
}
public Vector3 WindSpeed(float fX, float fY, float fZ)

View File

@ -51,6 +51,7 @@ namespace OpenSim.Region.CoreModules
//private Random m_rndnums = new Random(Environment.TickCount);
private Scene m_scene = null;
private bool m_ready = false;
private bool m_inUpdate = false;
private bool m_enabled = false;
private IConfig m_windConfig;
@ -160,7 +161,7 @@ namespace OpenSim.Region.CoreModules
m_scene.RegisterModuleInterface<IWindModule>(this);
// Generate initial wind values
GenWindPos();
GenWind();
// Mark Module Ready for duty
m_ready = true;
@ -416,67 +417,63 @@ namespace OpenSim.Region.CoreModules
/// </summary>
public void WindUpdate()
{
if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready)
{
if ((!m_ready || m_inUpdate || (m_frame++ % m_frameUpdateRate) != 0))
return;
}
GenWindPos();
m_inUpdate = true;
Util.FireAndForget(delegate
{
try
{
if(GenWind())
windSpeeds = m_activeWindPlugin.WindLLClientArray();
SendWindAllClients();
m_scene.ForEachRootClient(delegate(IClientAPI client)
{
client.SendWindData(windSpeeds);
});
}
finally
{
m_inUpdate = false;
}
},
null, "WindModuleUpdate");
}
/*
public void OnAgentEnteredRegion(ScenePresence avatar)
{
if (m_ready)
{
if (m_activeWindPlugin != null)
{
// Ask wind plugin to generate a LL wind array to be cached locally
// Try not to update this too often, as it may involve array copies
if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate))
{
windSpeeds = m_activeWindPlugin.WindLLClientArray();
m_frameLastUpdateClientArray = m_frame;
}
}
avatar.ControllingClient.SendWindData(windSpeeds);
}
}
*/
private void SendWindAllClients()
{
if (m_ready)
{
if (m_scene.GetRootAgentCount() > 0)
{
// Ask wind plugin to generate a LL wind array to be cached locally
// Try not to update this too often, as it may involve array copies
if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate))
{
windSpeeds = m_activeWindPlugin.WindLLClientArray();
m_frameLastUpdateClientArray = m_frame;
}
if (!m_ready || m_scene.GetRootAgentCount() == 0)
return;
m_scene.ForEachRootClient(delegate(IClientAPI client)
{
client.SendWindData(windSpeeds);
});
}
// Ask wind plugin to generate a LL wind array to be cached locally
// Try not to update this too often, as it may involve array copies
if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate))
{
windSpeeds = m_activeWindPlugin.WindLLClientArray();
m_frameLastUpdateClientArray = m_frame;
}
m_scene.ForEachRootClient(delegate(IClientAPI client)
{
client.SendWindData(windSpeeds);
});
}
*/
/// <summary>
/// Calculate the sun's orbital position and its velocity.
/// Calculate new wind
/// returns false if no change
/// </summary>
private void GenWindPos()
private bool GenWind()
{
if (m_activeWindPlugin != null)
{
// Tell Wind Plugin to update it's wind data
m_activeWindPlugin.WindUpdate(m_frame);
return m_activeWindPlugin.WindUpdate(m_frame);
}
return false;
}
}
}

View File

@ -53,7 +53,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <summary>
/// Update wind.
/// </summary>
void WindUpdate(uint frame);
bool WindUpdate(uint frame);
/// <summary>
/// Returns the wind vector at the given local region coordinates.