Make bots share a cache so that asset downloads attempts are only made once instead of once for each bot

remove-scene-viewer
Justin Clark-Casey (justincc) 2011-10-31 23:22:55 +00:00
parent 210868a832
commit b951c7fb1e
2 changed files with 24 additions and 20 deletions

View File

@ -53,13 +53,20 @@ namespace pCampBot
protected bool m_verbose = true;
protected Random somthing = new Random(Environment.TickCount);
protected int numbots = 0;
private IConfig Config;
public IConfig Config { get; private set; }
/// <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; }
/// <summary>
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
/// </summary>
public BotManager()
{
AssetsReceived = new Dictionary<UUID, bool>();
m_console = CreateConsole();
MainConsole.Instance = m_console;
@ -113,7 +120,7 @@ namespace pCampBot
for (int i = 0; i < botcount; i++)
{
string lastName = string.Format("{0}_{1}", lastNameStem, i);
startupBot(i, cs, firstName, lastName, password, loginUri);
startupBot(i, this, firstName, lastName, password, loginUri);
}
}
@ -146,9 +153,9 @@ namespace pCampBot
/// <param name="lastName">Last name</param>
/// <param name="password">Password</param>
/// <param name="loginUri">Login URI</param>
public void startupBot(int pos, IConfig cs, string firstName, string lastName, string password, string loginUri)
public void startupBot(int pos, BotManager bm, string firstName, string lastName, string password, string loginUri)
{
PhysicsBot pb = new PhysicsBot(cs, firstName, lastName, password, loginUri);
PhysicsBot pb = new PhysicsBot(bm, firstName, lastName, password, loginUri);
pb.OnConnected += handlebotEvent;
pb.OnDisconnected += handlebotEvent;

View File

@ -47,7 +47,9 @@ namespace pCampBot
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
public IConfig startupConfig; // bot config, passed from BotManager
public BotManager BotManager { get; private set; }
private IConfig startupConfig; // bot config, passed from BotManager
public string FirstName { get; private set; }
public string LastName { get; private set; }
@ -60,11 +62,6 @@ namespace pCampBot
public event AnEvent OnConnected;
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 List<uint> objectIDs = new List<uint>();
@ -80,23 +77,23 @@ namespace pCampBot
/// <summary>
/// Constructor
/// </summary>
/// <param name="bsconfig"></param>
/// <param name="bm"></param>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <param name="password"></param>
/// <param name="loginUri"></param>
public PhysicsBot(IConfig bsconfig, string firstName, string lastName, string password, string loginUri)
public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri)
{
FirstName = firstName;
LastName = lastName;
Name = string.Format("{0} {1}", FirstName, LastName);
Password = password;
LoginUri = loginUri;
startupConfig = bsconfig;
BotManager = bm;
startupConfig = bm.Config;
readconfig();
talkarray = readexcuses();
AssetsReceived = new Dictionary<UUID, bool>();
}
//We do our actions here. This is where one would
@ -428,13 +425,13 @@ namespace pCampBot
private void GetTexture(UUID textureID)
{
lock (AssetsReceived)
lock (BotManager.AssetsReceived)
{
// Don't request assets more than once.
if (AssetsReceived.ContainsKey(textureID))
if (BotManager.AssetsReceived.ContainsKey(textureID))
return;
AssetsReceived[textureID] = false;
BotManager.AssetsReceived[textureID] = false;
client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
}
}
@ -447,8 +444,8 @@ namespace pCampBot
public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset)
{
lock (AssetsReceived)
AssetsReceived[asset.AssetID] = true;
lock (BotManager.AssetsReceived)
BotManager.AssetsReceived[asset.AssetID] = true;
// if (wear == "save")
// {