From 5a67940acc17c80c419781fddc9efa0c18ce1f15 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 3 Nov 2011 22:31:31 +0000
Subject: Add click/grab behaviour to pCampbot, which gets bots to randomly
click things.
This can be specified on pCampbot.exe by using g in the list of behaviours for the new -behaviours,-b switch
e.g. -b p,g to get both existing physics and grabbing behaviours.
grabbing is primitive, it attempts grabs on random prims whether they're actually signalled as clickable or not.
behaviour is currently primitive overall, behaviours are just executed in a list
---
.../Tools/pCampBot/Behaviours/GrabbingBehaviour.cs | 56 ++++++++++++++++++++++
.../Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | 2 +-
OpenSim/Tools/pCampBot/BotManager.cs | 16 +++++--
OpenSim/Tools/pCampBot/PhysicsBot.cs | 31 +++++++++++-
OpenSim/Tools/pCampBot/pCampBot.cs | 8 ++--
5 files changed, 105 insertions(+), 8 deletions(-)
create mode 100644 OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs
(limited to 'OpenSim/Tools/pCampBot')
diff --git a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs
new file mode 100644
index 0000000..00313b8
--- /dev/null
+++ b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using OpenMetaverse;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using pCampBot.Interfaces;
+
+namespace pCampBot
+{
+ ///
+ /// Click (grab) on random objects in the scene.
+ ///
+ ///
+ /// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable.
+ ///
+ public class GrabbingBehaviour : IBehaviour
+ {
+ public void Action(PhysicsBot bot)
+ {
+ Dictionary objects = bot.Objects;
+
+ Primitive prim = objects.ElementAt(bot.Random.Next(0, objects.Count)).Value;
+
+ // This appears to be a typical message sent when a viewer user clicks a clickable object
+ bot.Client.Self.Grab(prim.LocalID);
+ bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero);
+ bot.Client.Self.DeGrab(prim.LocalID);
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
index e76c0b3..bd4a7a2 100644
--- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
+++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
@@ -35,7 +35,7 @@ using pCampBot.Interfaces;
namespace pCampBot
{
///
- /// This is a behaviour designed to stress physics by moving and bouncing around bots a whole lot.
+ /// Stress physics by moving and bouncing around bots a whole lot.
///
///
/// TODO: talkarray should be in a separate behaviour.
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 0505c97..dac6e0e 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -120,13 +120,23 @@ namespace pCampBot
string password = cs.GetString("password");
string loginUri = cs.GetString("loginuri");
- // Hardcoded for new
- List behaviours = new List();
- behaviours.Add(new PhysicsBehaviour());
+ HashSet behaviourSwitches = new HashSet();
+ Array.ForEach(
+ cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
for (int i = 0; i < botcount; i++)
{
string lastName = string.Format("{0}_{1}", lastNameStem, i);
+
+ List behaviours = new List();
+
+ // Hard-coded for now
+ if (behaviourSwitches.Contains("p"))
+ behaviours.Add(new PhysicsBehaviour());
+
+ if (behaviourSwitches.Contains("g"))
+ behaviours.Add(new GrabbingBehaviour());
+
startupBot(i, this, behaviours, firstName, lastName, password, loginUri);
}
}
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs
index 05a510a..6e40ca7 100644
--- a/OpenSim/Tools/pCampBot/PhysicsBot.cs
+++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs
@@ -55,9 +55,28 @@ namespace pCampBot
///
/// Behaviours implemented by this bot.
///
+ ///
+ /// Lock this list before manipulating it.
+ ///
public List Behaviours { get; private set; }
///
+ /// Objects that the bot has discovered.
+ ///
+ ///
+ /// Returns a list copy. Inserting new objects manually will have no effect.
+ ///
+ public Dictionary Objects
+ {
+ get
+ {
+ lock (m_objects)
+ return new Dictionary(m_objects);
+ }
+ }
+ private Dictionary m_objects = new Dictionary();
+
+ ///
/// Is this bot connected to the grid?
///
public bool IsConnected { get; private set; }
@@ -125,7 +144,14 @@ namespace pCampBot
private void Action()
{
while (true)
- Behaviours.ForEach(b => b.Action(this));
+ lock (Behaviours)
+ Behaviours.ForEach(
+ b =>
+ {
+ // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType());
+ b.Action(this);
+ }
+ );
}
///
@@ -407,6 +433,9 @@ namespace pCampBot
if (prim != null)
{
+ lock (m_objects)
+ m_objects[prim.ID] = prim;
+
if (prim.Textures != null)
{
if (prim.Textures.DefaultTexture.TextureID != UUID.Zero)
diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs
index cae96e1..4d3b06d 100644
--- a/OpenSim/Tools/pCampBot/pCampBot.cs
+++ b/OpenSim/Tools/pCampBot/pCampBot.cs
@@ -84,12 +84,13 @@ namespace pCampBot
//Set up our nifty config.. thanks to nini
ArgvConfigSource cs = new ArgvConfigSource(args);
- cs.AddSwitch("Startup", "botcount","n");
- cs.AddSwitch("Startup", "loginuri","l");
+ cs.AddSwitch("Startup", "botcount", "n");
+ cs.AddSwitch("Startup", "loginuri", "l");
cs.AddSwitch("Startup", "firstname");
cs.AddSwitch("Startup", "lastname");
cs.AddSwitch("Startup", "password");
- cs.AddSwitch("Startup", "help","h");
+ cs.AddSwitch("Startup", "behaviours", "b");
+ cs.AddSwitch("Startup", "help", "h");
cs.AddSwitch("Startup", "wear");
IConfig ol = cs.Configs["Startup"];
@@ -110,6 +111,7 @@ namespace pCampBot
" -firstname first name for the bots\n" +
" -lastname lastname for the bots. Each lastname will have _ appended, e.g. Ima Bot_0\n" +
" -password password for the bots\n" +
+ " -b, behaviours behaviours for bots. Current options p (physics), g (grab). Comma separated, e.g. p,g. Default is p",
" -wear set appearance folder to load from (default: no)\n" +
" -h, -help show this message"
);
--
cgit v1.1