cache wind compressed data so cpu burning compression is only done after a change. Not happy with version scheme for several regions on same instance, but should be ok for now
parent
a6df626868
commit
8d7f10e36b
|
@ -1395,6 +1395,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
|||
Util.FireAndForget(DoSendCloudData, cloudDensity, "LLClientView.SendCloudData");
|
||||
}
|
||||
|
||||
// wind caching
|
||||
private static int lastWindVersion = 0;
|
||||
private static List<LayerDataPacket> lastWindPackets = new List<LayerDataPacket>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send wind layer information to the client.
|
||||
/// </summary>
|
||||
|
@ -1403,22 +1408,41 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
|||
public virtual void SendWindData(int version, Vector2[] windSpeeds)
|
||||
{
|
||||
// Vector2[] windSpeeds = (Vector2[])o;
|
||||
TerrainPatch[] patches = new TerrainPatch[2];
|
||||
patches[0] = new TerrainPatch { Data = new float[16 * 16] };
|
||||
patches[1] = new TerrainPatch { Data = new float[16 * 16] };
|
||||
|
||||
for (int x = 0; x < 16 * 16; x++)
|
||||
bool isNewData;
|
||||
lock(lastWindPackets)
|
||||
isNewData = lastWindVersion != version;
|
||||
|
||||
if(isNewData)
|
||||
{
|
||||
patches[0].Data[x] = windSpeeds[x].X;
|
||||
patches[1].Data[x] = windSpeeds[x].Y;
|
||||
TerrainPatch[] patches = new TerrainPatch[2];
|
||||
patches[0] = new TerrainPatch { Data = new float[16 * 16] };
|
||||
patches[1] = new TerrainPatch { Data = new float[16 * 16] };
|
||||
|
||||
for (int x = 0; x < 16 * 16; x++)
|
||||
{
|
||||
patches[0].Data[x] = windSpeeds[x].X;
|
||||
patches[1].Data[x] = windSpeeds[x].Y;
|
||||
}
|
||||
|
||||
// neither we or viewers have extended wind
|
||||
byte layerType = (byte)TerrainPatch.LayerType.Wind;
|
||||
|
||||
LayerDataPacket layerpack =
|
||||
OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(
|
||||
patches, layerType);
|
||||
layerpack.Header.Zerocoded = true;
|
||||
lock(lastWindPackets)
|
||||
{
|
||||
lastWindPackets.Clear();
|
||||
lastWindPackets.Add(layerpack);
|
||||
lastWindVersion = version;
|
||||
}
|
||||
}
|
||||
|
||||
// neither we or viewers have extended wind
|
||||
byte layerType = (byte)TerrainPatch.LayerType.Wind;
|
||||
|
||||
LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(patches, layerType);
|
||||
layerpack.Header.Zerocoded = true;
|
||||
OutPacket(layerpack, ThrottleOutPacketType.Wind);
|
||||
lock(lastWindPackets)
|
||||
foreach(LayerDataPacket pkt in lastWindPackets)
|
||||
OutPacket(pkt, ThrottleOutPacketType.Wind);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -46,7 +46,8 @@ namespace OpenSim.Region.CoreModules
|
|||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private uint m_frame = 0;
|
||||
private uint m_frameLastUpdateClientArray = 0;
|
||||
private int m_dataVersion = 0;
|
||||
private int m_regionID = 0;
|
||||
private int m_frameUpdateRate = 150;
|
||||
//private Random m_rndnums = new Random(Environment.TickCount);
|
||||
private Scene m_scene = null;
|
||||
|
@ -97,7 +98,6 @@ namespace OpenSim.Region.CoreModules
|
|||
|
||||
m_scene = scene;
|
||||
m_frame = 0;
|
||||
|
||||
// Register all the Wind Model Plug-ins
|
||||
foreach (IWindModelPlugin windPlugin in AddinManager.GetExtensionObjects("/OpenSim/WindModule", false))
|
||||
{
|
||||
|
@ -119,7 +119,6 @@ namespace OpenSim.Region.CoreModules
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// if the plug-in wasn't found, default to no wind.
|
||||
if (m_activeWindPlugin == null)
|
||||
{
|
||||
|
@ -155,14 +154,14 @@ namespace OpenSim.Region.CoreModules
|
|||
|
||||
// Register event handlers for when Avatars enter the region, and frame ticks
|
||||
m_scene.EventManager.OnFrame += WindUpdate;
|
||||
// m_scene.EventManager.OnMakeRootAgent += OnAgentEnteredRegion;
|
||||
|
||||
// Register the wind module
|
||||
m_scene.RegisterModuleInterface<IWindModule>(this);
|
||||
|
||||
// Generate initial wind values
|
||||
GenWind();
|
||||
|
||||
// hopefully this will not be the same for all regions on same instance
|
||||
m_dataVersion = (int)m_scene.AllocateLocalId();
|
||||
// Mark Module Ready for duty
|
||||
m_ready = true;
|
||||
}
|
||||
|
@ -425,13 +424,11 @@ namespace OpenSim.Region.CoreModules
|
|||
{
|
||||
try
|
||||
{
|
||||
if(GenWind())
|
||||
windSpeeds = m_activeWindPlugin.WindLLClientArray();
|
||||
|
||||
m_scene.ForEachRootClient(delegate(IClientAPI client)
|
||||
{
|
||||
client.SendWindData(0, windSpeeds);
|
||||
});
|
||||
GenWind();
|
||||
m_scene.ForEachRootClient(delegate(IClientAPI client)
|
||||
{
|
||||
client.SendWindData(m_dataVersion, windSpeeds);
|
||||
});
|
||||
|
||||
}
|
||||
finally
|
||||
|
@ -441,26 +438,7 @@ namespace OpenSim.Region.CoreModules
|
|||
},
|
||||
null, "WindModuleUpdate");
|
||||
}
|
||||
/*
|
||||
private void SendWindAllClients()
|
||||
{
|
||||
if (!m_ready || m_scene.GetRootAgentCount() == 0)
|
||||
return;
|
||||
|
||||
// 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 new wind
|
||||
/// returns false if no change
|
||||
|
@ -468,10 +446,11 @@ namespace OpenSim.Region.CoreModules
|
|||
|
||||
private bool GenWind()
|
||||
{
|
||||
if (m_activeWindPlugin != null)
|
||||
if (m_activeWindPlugin != null && m_activeWindPlugin.WindUpdate(m_frame))
|
||||
{
|
||||
// Tell Wind Plugin to update it's wind data
|
||||
return m_activeWindPlugin.WindUpdate(m_frame);
|
||||
windSpeeds = m_activeWindPlugin.WindLLClientArray();
|
||||
m_dataVersion++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue