Stop individual bots attempting to download the same asset more than once

remove-scene-viewer
Justin Clark-Casey (justincc) 2011-10-31 22:52:49 +00:00
parent 0c6509098a
commit d366a08ebb
1 changed files with 36 additions and 14 deletions

View File

@ -56,6 +56,11 @@ namespace pCampBot
public event AnEvent OnConnected; public event AnEvent OnConnected;
public event AnEvent OnDisconnected; public event AnEvent OnDisconnected;
/// <summary>
/// Track the assets we have and have not received so we don't endlessly repeat requests.
/// </summary>
public Dictionary<UUID, bool> AssetsReceived { get; private set; }
protected Timer m_action; // Action Timer protected Timer m_action; // Action Timer
protected List<uint> objectIDs = new List<uint>(); protected List<uint> objectIDs = new List<uint>();
@ -86,6 +91,8 @@ namespace pCampBot
startupConfig = bsconfig; startupConfig = bsconfig;
readconfig(); readconfig();
talkarray = readexcuses(); talkarray = readexcuses();
AssetsReceived = new Dictionary<UUID, bool>();
} }
//We do our actions here. This is where one would //We do our actions here. This is where one would
@ -164,7 +171,7 @@ namespace pCampBot
client.Network.SimConnected += this.Network_SimConnected; client.Network.SimConnected += this.Network_SimConnected;
client.Network.Disconnected += this.Network_OnDisconnected; client.Network.Disconnected += this.Network_OnDisconnected;
client.Objects.ObjectUpdate += Objects_NewPrim; client.Objects.ObjectUpdate += Objects_NewPrim;
//client.Assets.OnAssetReceived += Asset_ReceivedCallback;
if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
{ {
if (OnConnected != null) if (OnConnected != null)
@ -393,40 +400,55 @@ namespace pCampBot
{ {
if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) if (prim.Textures.DefaultTexture.TextureID != UUID.Zero)
{ {
client.Assets.RequestImage(prim.Textures.DefaultTexture.TextureID, ImageType.Normal, Asset_TextureCallback_Texture); GetTexture(prim.Textures.DefaultTexture.TextureID);
} }
for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) for (int i = 0; i < prim.Textures.FaceTextures.Length; i++)
{ {
if (prim.Textures.FaceTextures[i] != null) UUID textureID = prim.Textures.FaceTextures[i].TextureID;
if (textureID != null && textureID != UUID.Zero)
{ {
if (prim.Textures.FaceTextures[i].TextureID != UUID.Zero) GetTexture(textureID);
{
client.Assets.RequestImage(prim.Textures.FaceTextures[i].TextureID, ImageType.Normal, Asset_TextureCallback_Texture);
}
} }
} }
} }
if (prim.Sculpt.SculptTexture != UUID.Zero) if (prim.Sculpt.SculptTexture != UUID.Zero)
{ {
client.Assets.RequestImage(prim.Sculpt.SculptTexture, ImageType.Normal, Asset_TextureCallback_Texture); GetTexture(prim.Sculpt.SculptTexture);
} }
} }
} }
private void GetTexture(UUID textureID)
{
lock (AssetsReceived)
{
// Don't request assets more than once.
if (AssetsReceived.ContainsKey(textureID))
return;
AssetsReceived[textureID] = false;
client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
}
}
public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
{ {
//TODO: Implement texture saving and applying //TODO: Implement texture saving and applying
} }
public void Asset_ReceivedCallback(AssetDownload transfer,Asset asset) public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset)
{ {
if (wear == "save") lock (AssetsReceived)
{ AssetsReceived[asset.AssetID] = true;
SaveAsset((AssetWearable) asset);
} // if (wear == "save")
// {
// SaveAsset((AssetWearable) asset);
// }
} }
public string[] readexcuses() public string[] readexcuses()