mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 00:46:02 +08:00
DANGER... changed bakedtextures caching. Assuming grid baking is cache
only, reduced number of accesses to it. TESTING
This commit is contained in:
@@ -96,9 +96,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
s.EventManager.OnRemovePresence -= DeRegisterPresence;
|
||||
m_BakedTextureModule = null;
|
||||
m_scene = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void RegionLoaded(Scene s)
|
||||
{
|
||||
@@ -110,44 +108,58 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
|
||||
private void DeRegisterPresence(UUID agentId)
|
||||
{
|
||||
ScenePresence presence = null;
|
||||
if (m_scene.TryGetScenePresence(agentId, out presence))
|
||||
// ScenePresence presence = null;
|
||||
// if (m_scene.TryGetScenePresence(agentId, out presence))
|
||||
{
|
||||
presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings;
|
||||
// presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void RegisterNewPresence(ScenePresence presence)
|
||||
{
|
||||
presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings;
|
||||
|
||||
// presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings;
|
||||
}
|
||||
|
||||
private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems)
|
||||
{
|
||||
int maxCacheitemsLoop = cacheItems.Length;
|
||||
if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES)
|
||||
{
|
||||
maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES;
|
||||
m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES);
|
||||
}
|
||||
/* not in use. work done in AvatarFactoryModule ValidateBakedTextureCache() and UpdateBakedTextureCache()
|
||||
private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems)
|
||||
{
|
||||
// if cacheItems.Length > 0 viewer is giving us current textures information.
|
||||
// baked ones should had been uploaded and in assets cache as local itens
|
||||
|
||||
m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
|
||||
if (cacheItems.Length > 0)
|
||||
{
|
||||
m_log.Debug("[Cacheitems]: " + cacheItems.Length);
|
||||
for (int iter = 0; iter < maxCacheitemsLoop; iter++)
|
||||
{
|
||||
m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
|
||||
cacheItems[iter].TextureID);
|
||||
}
|
||||
|
||||
ScenePresence p = null;
|
||||
if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p))
|
||||
{
|
||||
|
||||
if (cacheItems.Length == 0)
|
||||
return; // no textures information, nothing to do
|
||||
|
||||
ScenePresence p = null;
|
||||
if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out p))
|
||||
return; // what are we doing if there is no presence to cache for?
|
||||
|
||||
if (p.IsDeleted)
|
||||
return; // does this really work?
|
||||
|
||||
int maxCacheitemsLoop = cacheItems.Length;
|
||||
if (maxCacheitemsLoop > 20)
|
||||
{
|
||||
maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES;
|
||||
m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES);
|
||||
}
|
||||
|
||||
m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
|
||||
|
||||
|
||||
// some nice debug
|
||||
m_log.Debug("[Cacheitems]: " + cacheItems.Length);
|
||||
for (int iter = 0; iter < maxCacheitemsLoop; iter++)
|
||||
{
|
||||
m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
|
||||
cacheItems[iter].TextureID);
|
||||
}
|
||||
|
||||
// p.Appearance.WearableCacheItems is in memory primary cashID to textures mapper
|
||||
|
||||
WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems;
|
||||
|
||||
if (existingitems == null)
|
||||
{
|
||||
if (m_BakedTextureModule != null)
|
||||
@@ -161,38 +173,22 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
p.Appearance.WearableCacheItems = savedcache;
|
||||
p.Appearance.WearableCacheItemsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* The following Catch types DO NOT WORK with m_BakedTextureModule.Get
|
||||
* it jumps to the General Packet Exception Handler if you don't catch Exception!
|
||||
*
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
cacheItems = null;
|
||||
}
|
||||
catch (WebException)
|
||||
{
|
||||
cacheItems = null;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
cacheItems = null;
|
||||
} */
|
||||
catch (Exception)
|
||||
{
|
||||
// The service logs a sufficient error message.
|
||||
// The service logs a sufficient error message.
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (savedcache != null)
|
||||
existingitems = savedcache;
|
||||
}
|
||||
}
|
||||
|
||||
// Existing items null means it's a fully new appearance
|
||||
if (existingitems == null)
|
||||
{
|
||||
|
||||
for (int i = 0; i < maxCacheitemsLoop; i++)
|
||||
{
|
||||
if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
|
||||
@@ -205,7 +201,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
AppearanceManager.DEFAULT_AVATAR_TEXTURE;
|
||||
continue;
|
||||
}
|
||||
cacheItems[i].TextureID =face.TextureID;
|
||||
cacheItems[i].TextureID = face.TextureID;
|
||||
if (m_scene.AssetService != null)
|
||||
cacheItems[i].TextureAsset =
|
||||
m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString());
|
||||
@@ -214,15 +210,10 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
{
|
||||
m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
{
|
||||
// for each uploaded baked texture
|
||||
{
|
||||
for (int i = 0; i < maxCacheitemsLoop; i++)
|
||||
{
|
||||
if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
|
||||
@@ -253,27 +244,24 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.Appearance.WearableCacheItems = cacheItems;
|
||||
|
||||
|
||||
if (m_BakedTextureModule != null)
|
||||
{
|
||||
m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems);
|
||||
p.Appearance.WearableCacheItemsDirty = true;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
p.Appearance.WearableCacheItemsDirty = false;
|
||||
|
||||
for (int iter = 0; iter < maxCacheitemsLoop; iter++)
|
||||
{
|
||||
m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
|
||||
cacheItems[iter].TextureID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int iter = 0; iter < maxCacheitemsLoop; iter++)
|
||||
{
|
||||
m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
|
||||
cacheItems[iter].TextureID);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3684,6 +3684,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
avp.Sender.IsTrial = false;
|
||||
avp.Sender.ID = agentID;
|
||||
avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0];
|
||||
|
||||
// this need be use in future
|
||||
// avp.AppearanceData[0].AppearanceVersion = 0;
|
||||
// avp.AppearanceData[0].CofVersion = 0;
|
||||
|
||||
//m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString());
|
||||
OutPacket(avp, ThrottleOutPacketType.Task);
|
||||
}
|
||||
@@ -12006,8 +12011,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
|
||||
|
||||
if (cachedtex.AgentData.SessionID != SessionId)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
|
||||
// TODO: don't create new blocks if recycling an old packet
|
||||
cachedresp.AgentData.AgentID = AgentId;
|
||||
@@ -12022,23 +12026,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
//WearableCacheItem[] items = fac.GetCachedItems(AgentId);
|
||||
|
||||
IAssetService cache = m_scene.AssetService;
|
||||
IBakedTextureModule bakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
|
||||
//bakedTextureModule = null;
|
||||
int maxWearablesLoop = cachedtex.WearableData.Length;
|
||||
if (maxWearablesLoop > AvatarWearable.MAX_WEARABLES)
|
||||
maxWearablesLoop = AvatarWearable.MAX_WEARABLES;
|
||||
|
||||
// if (bakedTextureModule != null && cache != null)
|
||||
int cacheHits = 0;
|
||||
|
||||
if (cache != null)
|
||||
{
|
||||
// We need to make sure the asset stored in the bake is available on this server also by it's assetid before we map it to a Cacheid
|
||||
|
||||
WearableCacheItem[] cacheItems = null;
|
||||
|
||||
ScenePresence p = m_scene.GetScenePresence(AgentId);
|
||||
if (p.Appearance != null)
|
||||
|
||||
if (p!= null && p.Appearance != null)
|
||||
{
|
||||
if (p.Appearance.WearableCacheItems == null || p.Appearance.WearableCacheItemsDirty)
|
||||
/* we should only check bakedTextureModule at login or when appearance changes
|
||||
if (p.Appearance.WearableCacheItems == null) // currently with a caching only bakemodule Appearance.Wearables.dirty as no use
|
||||
{
|
||||
IBakedTextureModule bakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
|
||||
if (bakedTextureModule != null)
|
||||
{
|
||||
m_log.Debug("[ HandleAgentTextureCached] bakedTextureModule");
|
||||
@@ -12047,23 +12055,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
cacheItems = bakedTextureModule.Get(AgentId);
|
||||
p.Appearance.WearableCacheItems = cacheItems;
|
||||
p.Appearance.WearableCacheItemsDirty = false;
|
||||
|
||||
if (cacheItems != null)
|
||||
{
|
||||
foreach (WearableCacheItem item in cacheItems)
|
||||
{
|
||||
if (item.TextureAsset != null)
|
||||
{
|
||||
item.TextureAsset.Temporary = true;
|
||||
item.TextureAsset.Local = true;
|
||||
cache.Store(item.TextureAsset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The following Catch types DO NOT WORK, it jumps to the General Packet Exception Handler if you don't catch Exception!
|
||||
*
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
cacheItems = null;
|
||||
}
|
||||
catch (WebException)
|
||||
{
|
||||
cacheItems = null;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
cacheItems = null;
|
||||
} */
|
||||
catch (Exception)
|
||||
{
|
||||
cacheItems = null;
|
||||
@@ -12075,36 +12081,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
{
|
||||
cacheItems = p.Appearance.WearableCacheItems;
|
||||
}
|
||||
*/
|
||||
cacheItems = p.Appearance.WearableCacheItems;
|
||||
}
|
||||
|
||||
if (cache != null && cacheItems != null)
|
||||
{
|
||||
foreach (WearableCacheItem item in cacheItems)
|
||||
{
|
||||
|
||||
if (cache.GetCached(item.TextureID.ToString()) == null)
|
||||
{
|
||||
item.TextureAsset.Temporary = true;
|
||||
cache.Store(item.TextureAsset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cacheItems != null)
|
||||
{
|
||||
|
||||
for (int i = 0; i < maxWearablesLoop; i++)
|
||||
{
|
||||
WearableCacheItem item =
|
||||
WearableCacheItem.SearchTextureIndex(cachedtex.WearableData[i].TextureIndex,cacheItems);
|
||||
int idx = cachedtex.WearableData[i].TextureIndex;
|
||||
|
||||
cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
|
||||
cachedresp.WearableData[i].TextureIndex= cachedtex.WearableData[i].TextureIndex;
|
||||
cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
|
||||
cachedresp.WearableData[i].HostName = new byte[0];
|
||||
if (item != null && cachedtex.WearableData[i].ID == item.CacheId)
|
||||
if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId)
|
||||
{
|
||||
|
||||
cachedresp.WearableData[i].TextureID = item.TextureID;
|
||||
cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID;
|
||||
cacheHits++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -12124,36 +12117,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else // no cache
|
||||
{
|
||||
if (cache == null)
|
||||
for (int i = 0; i < maxWearablesLoop; i++)
|
||||
{
|
||||
for (int i = 0; i < maxWearablesLoop; i++)
|
||||
{
|
||||
cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
|
||||
cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
|
||||
cachedresp.WearableData[i].TextureID = UUID.Zero;
|
||||
//UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
|
||||
cachedresp.WearableData[i].HostName = new byte[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < maxWearablesLoop; i++)
|
||||
{
|
||||
cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
|
||||
cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
|
||||
|
||||
if (cache.GetCached(cachedresp.WearableData[i].TextureID.ToString()) == null)
|
||||
cachedresp.WearableData[i].TextureID = UUID.Zero;
|
||||
//UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
|
||||
// else
|
||||
// cachedresp.WearableData[i].TextureID = UUID.Zero;
|
||||
// UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
|
||||
cachedresp.WearableData[i].HostName = new byte[0];
|
||||
}
|
||||
cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
|
||||
cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
|
||||
cachedresp.WearableData[i].TextureID = UUID.Zero;
|
||||
cachedresp.WearableData[i].HostName = new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
m_log.DebugFormat("texture cached: hits {0}", cacheHits);
|
||||
|
||||
cachedresp.Header.Zerocoded = true;
|
||||
OutPacket(cachedresp, ThrottleOutPacketType.Task);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user