Started the process of cleaning up AssetCache and moving most of the code into modules. Have moved TextureRequest handling (from the client) to a module. But even though to start with I just did a little bit of cleaning up of the existing code, it doesn't seem to work as good as the old code so I need to spend more time on it. So for now am committing my changes but with them not in use. So for now all Texture and asset requests are still handled by the old code in AssetCache.

This commit is contained in:
MW
2007-10-29 09:51:23 +00:00
parent 7c6ef95f2f
commit 27f003b683
13 changed files with 360 additions and 100 deletions

View File

@@ -42,6 +42,8 @@ namespace OpenSim.Framework.Communications.Cache
{
public delegate void DownloadComplete(AssetCache.TextureSender sender);
public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
/// <summary>
/// Manages local cache of assets and their sending to viewers.
/// </summary>
@@ -63,6 +65,8 @@ namespace OpenSim.Framework.Communications.Cache
private Dictionary<LLUUID, Dictionary<LLUUID, int>> TimesTextureSent = new Dictionary<LLUUID, Dictionary<LLUUID, int>>();
public Dictionary<LLUUID, AssetRequestsList> RequestLists = new Dictionary<LLUUID, AssetRequestsList>();
private IAssetServer _assetServer;
private Thread _assetCacheThread;
@@ -123,6 +127,46 @@ namespace OpenSim.Framework.Communications.Cache
return asset;
}
public void GetAsset(LLUUID assetID, AssetRequestCallback callback)
{
AssetBase asset = null;
if (this.Textures.ContainsKey(assetID))
{
asset = this.Textures[assetID];
}
else if (this.Assets.ContainsKey(assetID))
{
asset = this.Assets[assetID];
}
if (asset != null)
{
callback(assetID, asset);
}
else
{
NewAssetRequest req = new NewAssetRequest(assetID, callback);
if (this.RequestLists.ContainsKey(assetID))
{
lock (RequestLists)
{
RequestLists[assetID].Requests.Add(req);
}
}
else
{
AssetRequestsList reqList = new AssetRequestsList(assetID);
reqList.Requests.Add(req);
lock (RequestLists)
{
RequestLists.Add(assetID, reqList);
}
}
this._assetServer.FetchAsset(assetID, false);
}
}
public AssetBase GetAsset(LLUUID assetID, bool isTexture)
{
AssetBase asset = GetAsset(assetID);
@@ -135,7 +179,7 @@ namespace OpenSim.Framework.Communications.Cache
public void AddAsset(AssetBase asset)
{
// System.Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated());
//System.Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated());
if (asset.Type == 0)
{
//Console.WriteLine("which is a texture");
@@ -207,26 +251,7 @@ namespace OpenSim.Framework.Communications.Cache
while (true)
{
TextureSender sender = this.QueueTextures.Dequeue();
/* if (TimesTextureSent.ContainsKey(sender.request.RequestUser.AgentId))
{
if (TimesTextureSent[sender.request.RequestUser.AgentId].ContainsKey(sender.request.ImageInfo.FullID))
{
TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID]++;
}
else
{
TimesTextureSent[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID, 1);
}
}
else
{
Dictionary<LLUUID, int> UsersSent = new Dictionary<LLUUID,int>();
TimesTextureSent.Add(sender.request.RequestUser.AgentId, UsersSent );
UsersSent.Add(sender.request.ImageInfo.FullID, 1);
}
if (TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID] < 1000)
{*/
bool finished = sender.SendTexture();
if (finished)
{
@@ -237,11 +262,7 @@ namespace OpenSim.Framework.Communications.Cache
// Console.WriteLine("readding texture");
this.QueueTextures.Enqueue(sender);
}
/* }
else
{
this.TextureSent(sender);
}*/
}
}
@@ -317,6 +338,21 @@ namespace OpenSim.Framework.Communications.Cache
}
}
}
if (RequestLists.ContainsKey(asset.FullID))
{
AssetRequestsList reqList = RequestLists[asset.FullID];
foreach (NewAssetRequest req in reqList.Requests)
{
req.Callback(asset.FullID, asset);
}
lock (RequestLists)
{
RequestLists.Remove(asset.FullID);
reqList.Requests.Clear();
}
}
}
}
@@ -508,17 +544,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset)
{
AssetInfo newAsset = new AssetInfo();
newAsset.Data = new byte[sourceAsset.Data.Length];
Array.Copy(sourceAsset.Data, newAsset.Data, sourceAsset.Data.Length);
newAsset.FullID = LLUUID.Random();
newAsset.Type = sourceAsset.Type;
newAsset.InvType = sourceAsset.InvType;
return (newAsset);
}
#endregion
#region Textures
@@ -529,7 +554,7 @@ namespace OpenSim.Framework.Communications.Cache
/// <param name="imageID"></param>
public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber, int discard)
{
//Console.WriteLine("texture request for " + imageID.ToStringHyphenated() + " packetnumber= " + packetNumber);
// System.Console.WriteLine("texture request for " + imageID.ToStringHyphenated() + " packetnumber= " + packetNumber);
//check to see if texture is in local cache, if not request from asset server
if (!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId))
{
@@ -540,6 +565,7 @@ namespace OpenSim.Framework.Communications.Cache
//Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them");
return;
}*/
if (!this.Textures.ContainsKey(imageID))
{
if (!this.RequestedTextures.ContainsKey(imageID))
@@ -556,7 +582,7 @@ namespace OpenSim.Framework.Communications.Cache
return;
}
//Console.WriteLine("texture already in cache");
// System.Console.WriteLine("texture already in cache");
TextureImage imag = this.Textures[imageID];
AssetRequest req = new AssetRequest();
req.RequestUser = userInfo;
@@ -583,46 +609,9 @@ namespace OpenSim.Framework.Communications.Cache
this.TextureRequests.Add(req);
}
public TextureImage CloneImage(LLUUID newOwner, TextureImage source)
{
TextureImage newImage = new TextureImage();
newImage.Data = new byte[source.Data.Length];
Array.Copy(source.Data, newImage.Data, source.Data.Length);
//newImage.filename = source.filename;
newImage.FullID = LLUUID.Random();
newImage.Name = source.Name;
return (newImage);
}
#endregion
private IAssetServer LoadAssetDll(string dllName)
{
Assembly pluginAssembly = Assembly.LoadFrom(dllName);
IAssetServer server = null;
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (pluginType.IsPublic)
{
if (!pluginType.IsAbstract)
{
Type typeInterface = pluginType.GetInterface("IAssetPlugin", true);
if (typeInterface != null)
{
IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
server = plug.GetAssetServer();
break;
}
typeInterface = null;
}
}
}
pluginAssembly = null;
return server;
}
public class AssetRequest
{
public IClientAPI RequestUser;
@@ -779,4 +768,29 @@ namespace OpenSim.Framework.Communications.Cache
}
}
}
public class AssetRequestsList
{
public LLUUID AssetID;
public List<NewAssetRequest> Requests = new List<NewAssetRequest>();
public AssetRequestsList(LLUUID assetID)
{
AssetID = assetID;
}
}
public class NewAssetRequest
{
public LLUUID AssetID;
public AssetRequestCallback Callback;
public NewAssetRequest(LLUUID assetID, AssetRequestCallback callback)
{
AssetID = assetID;
Callback = callback;
}
}
}

View File

@@ -136,6 +136,33 @@ namespace OpenSim.Framework.Interfaces
}
}
public class TextureRequestArgs : EventArgs
{
protected LLUUID m_requestedAssetID;
private sbyte m_discardLevel;
private uint m_packetNumber;
public uint PacketNumber
{
get { return m_packetNumber; }
set { m_packetNumber = value; }
}
public sbyte DiscardLevel
{
get { return m_discardLevel; }
set { m_discardLevel = value; }
}
public LLUUID RequestedAssetID
{
get { return m_requestedAssetID; }
set { m_requestedAssetID = value; }
}
}
public delegate void TextureRequest(Object sender, TextureRequestArgs e);
public delegate void ImprovedInstantMessage(LLUUID fromAgentID, LLUUID fromAgentSession, LLUUID toAgentID, LLUUID imSessionID, uint timestamp, string fromAgentName, string message, byte dialog); // Cut down from full list
public delegate void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos);
public delegate void ModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, IClientAPI remoteClient);
@@ -204,6 +231,7 @@ namespace OpenSim.Framework.Interfaces
{
event ImprovedInstantMessage OnInstantMessage;
event ChatFromViewer OnChatFromViewer;
event TextureRequest OnRequestTexture;
event RezObject OnRezObject;
event ModifyTerrain OnModifyTerrain;
event SetAppearance OnSetAppearance;