From b951c7fb1e5a284a9bf95054cb168e64ebfe717d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 23:22:55 +0000 Subject: Make bots share a cache so that asset downloads attempts are only made once instead of once for each bot --- OpenSim/Tools/pCampBot/BotManager.cs | 15 +++++++++++---- OpenSim/Tools/pCampBot/PhysicsBot.cs | 29 +++++++++++++---------------- 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'OpenSim/Tools') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index a4b7f16..03bb820 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -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; } + + /// + /// Track the assets we have and have not received so we don't endlessly repeat requests. + /// + public Dictionary AssetsReceived { get; private set; } /// /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data /// public BotManager() { + AssetsReceived = new Dictionary(); + 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 /// Last name /// Password /// Login URI - 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; diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 0c399e3..2070bfd 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -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; - /// - /// Track the assets we have and have not received so we don't endlessly repeat requests. - /// - public Dictionary AssetsReceived { get; private set; } - protected Timer m_action; // Action Timer protected List objectIDs = new List(); @@ -80,23 +77,23 @@ namespace pCampBot /// /// Constructor /// - /// + /// /// /// /// /// - 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(); } //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") // { -- cgit v1.1