diff options
Diffstat (limited to 'OpenSim/Tools')
-rw-r--r-- | OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs | 14 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Behaviours/NoneBehaviour.cs | 10 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | 2 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Bot.cs | 58 | ||||
-rw-r--r-- | OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs | 8 |
5 files changed, 56 insertions, 36 deletions
diff --git a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs index 9bc8512..c1ba36b 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs | |||
@@ -29,11 +29,12 @@ using OpenMetaverse; | |||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Linq; | 31 | using System.Linq; |
32 | using System.Threading; | ||
32 | using pCampBot.Interfaces; | 33 | using pCampBot.Interfaces; |
33 | 34 | ||
34 | namespace pCampBot | 35 | namespace pCampBot |
35 | { | 36 | { |
36 | public class AbstractBehaviour : IBehaviour | 37 | public abstract class AbstractBehaviour : IBehaviour |
37 | { | 38 | { |
38 | /// <summary> | 39 | /// <summary> |
39 | /// Abbreviated name of this behaviour. | 40 | /// Abbreviated name of this behaviour. |
@@ -44,13 +45,20 @@ namespace pCampBot | |||
44 | 45 | ||
45 | public Bot Bot { get; protected set; } | 46 | public Bot Bot { get; protected set; } |
46 | 47 | ||
47 | public virtual void Action() {} | 48 | public abstract void Action(); |
49 | |||
50 | public virtual void Interrupt() {} | ||
51 | |||
52 | protected AutoResetEvent m_interruptEvent = new AutoResetEvent(false); | ||
48 | 53 | ||
49 | public virtual void Initialize(Bot bot) | 54 | public virtual void Initialize(Bot bot) |
50 | { | 55 | { |
51 | Bot = bot; | 56 | Bot = bot; |
52 | } | 57 | } |
53 | 58 | ||
54 | public virtual void Close() {} | 59 | public virtual void Close() |
60 | { | ||
61 | Interrupt(); | ||
62 | } | ||
55 | } | 63 | } |
56 | } | 64 | } |
diff --git a/OpenSim/Tools/pCampBot/Behaviours/NoneBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/NoneBehaviour.cs index 9a3075c..4a7237c 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/NoneBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/NoneBehaviour.cs | |||
@@ -43,5 +43,15 @@ namespace pCampBot | |||
43 | AbbreviatedName = "n"; | 43 | AbbreviatedName = "n"; |
44 | Name = "None"; | 44 | Name = "None"; |
45 | } | 45 | } |
46 | |||
47 | public override void Action() | ||
48 | { | ||
49 | m_interruptEvent.WaitOne(); | ||
50 | } | ||
51 | |||
52 | public override void Interrupt() | ||
53 | { | ||
54 | m_interruptEvent.Set(); | ||
55 | } | ||
46 | } | 56 | } |
47 | } \ No newline at end of file | 57 | } \ No newline at end of file |
diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs index 6fd2b7c..98ab931 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | |||
@@ -82,6 +82,8 @@ namespace pCampBot | |||
82 | { | 82 | { |
83 | if (Bot.ConnectionState == ConnectionState.Connected) | 83 | if (Bot.ConnectionState == ConnectionState.Connected) |
84 | Bot.Client.Self.Jump(false); | 84 | Bot.Client.Self.Jump(false); |
85 | |||
86 | base.Close(); | ||
85 | } | 87 | } |
86 | 88 | ||
87 | private string[] readexcuses() | 89 | private string[] readexcuses() |
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index bd5eb81..fd9ae3f 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs | |||
@@ -192,15 +192,15 @@ namespace pCampBot | |||
192 | 192 | ||
193 | public bool AddBehaviour(IBehaviour behaviour) | 193 | public bool AddBehaviour(IBehaviour behaviour) |
194 | { | 194 | { |
195 | lock (Behaviours) | 195 | Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours); |
196 | { | ||
197 | if (!Behaviours.ContainsKey(behaviour.AbbreviatedName)) | ||
198 | { | ||
199 | behaviour.Initialize(this); | ||
200 | Behaviours.Add(behaviour.AbbreviatedName, behaviour); | ||
201 | 196 | ||
202 | return true; | 197 | if (!updatedBehaviours.ContainsKey(behaviour.AbbreviatedName)) |
203 | } | 198 | { |
199 | behaviour.Initialize(this); | ||
200 | updatedBehaviours.Add(behaviour.AbbreviatedName, behaviour); | ||
201 | Behaviours = updatedBehaviours; | ||
202 | |||
203 | return true; | ||
204 | } | 204 | } |
205 | 205 | ||
206 | return false; | 206 | return false; |
@@ -208,18 +208,17 @@ namespace pCampBot | |||
208 | 208 | ||
209 | public bool RemoveBehaviour(string abbreviatedName) | 209 | public bool RemoveBehaviour(string abbreviatedName) |
210 | { | 210 | { |
211 | lock (Behaviours) | 211 | Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours); |
212 | { | 212 | IBehaviour behaviour; |
213 | IBehaviour behaviour; | ||
214 | 213 | ||
215 | if (!Behaviours.TryGetValue(abbreviatedName, out behaviour)) | 214 | if (!updatedBehaviours.TryGetValue(abbreviatedName, out behaviour)) |
216 | return false; | 215 | return false; |
217 | 216 | ||
218 | behaviour.Close(); | 217 | behaviour.Close(); |
219 | Behaviours.Remove(abbreviatedName); | 218 | updatedBehaviours.Remove(abbreviatedName); |
219 | Behaviours = updatedBehaviours; | ||
220 | 220 | ||
221 | return true; | 221 | return true; |
222 | } | ||
223 | } | 222 | } |
224 | 223 | ||
225 | private void CreateLibOmvClient() | 224 | private void CreateLibOmvClient() |
@@ -279,24 +278,17 @@ namespace pCampBot | |||
279 | { | 278 | { |
280 | while (ConnectionState == ConnectionState.Connected) | 279 | while (ConnectionState == ConnectionState.Connected) |
281 | { | 280 | { |
282 | lock (Behaviours) | 281 | foreach (IBehaviour behaviour in Behaviours.Values) |
283 | { | 282 | { |
284 | foreach (IBehaviour behaviour in Behaviours.Values) | ||
285 | { | ||
286 | // Thread.Sleep(Random.Next(3000, 10000)); | 283 | // Thread.Sleep(Random.Next(3000, 10000)); |
287 | 284 | ||
288 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); | 285 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); |
289 | behaviour.Action(); | 286 | behaviour.Action(); |
290 | } | ||
291 | } | 287 | } |
292 | |||
293 | // XXX: This is a really shitty way of yielding so that behaviours can be added/removed | ||
294 | Thread.Sleep(100); | ||
295 | } | 288 | } |
296 | 289 | ||
297 | lock (Behaviours) | 290 | foreach (IBehaviour b in Behaviours.Values) |
298 | foreach (IBehaviour b in Behaviours.Values) | 291 | b.Close(); |
299 | b.Close(); | ||
300 | } | 292 | } |
301 | 293 | ||
302 | /// <summary> | 294 | /// <summary> |
@@ -305,9 +297,9 @@ namespace pCampBot | |||
305 | public void Disconnect() | 297 | public void Disconnect() |
306 | { | 298 | { |
307 | ConnectionState = ConnectionState.Disconnecting; | 299 | ConnectionState = ConnectionState.Disconnecting; |
308 | 300 | ||
309 | // if (m_actionThread != null) | 301 | foreach (IBehaviour behaviour in Behaviours.Values) |
310 | // m_actionThread.Abort(); | 302 | behaviour.Interrupt(); |
311 | 303 | ||
312 | Client.Network.Logout(); | 304 | Client.Network.Logout(); |
313 | } | 305 | } |
diff --git a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs index 0ed4825..660c630 100644 --- a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs | |||
@@ -51,6 +51,14 @@ namespace pCampBot.Interfaces | |||
51 | void Initialize(Bot bot); | 51 | void Initialize(Bot bot); |
52 | 52 | ||
53 | /// <summary> | 53 | /// <summary> |
54 | /// Interrupt the behaviour. | ||
55 | /// </summary> | ||
56 | /// <remarks> | ||
57 | /// This should cause the current Action call() to terminate if this is active. | ||
58 | /// </remarks> | ||
59 | void Interrupt(); | ||
60 | |||
61 | /// <summary> | ||
54 | /// Close down this behaviour. | 62 | /// Close down this behaviour. |
55 | /// </summary> | 63 | /// </summary> |
56 | /// <remarks> | 64 | /// <remarks> |