Terminate 'nothing' behaviour (and potentially others) by signalling using an event rather than polling connection state every 100ms
This kind of polling is very expensive with many bots/polling threads and appears to be the primary cause of bot falloff from the client end at higher loads. Where inbound packet threads can't run in time due to contention and simulator disconnect timeout occurs.bullet-2.82
parent
f1f935ed95
commit
21176a3a90
|
@ -29,11 +29,12 @@ using OpenMetaverse;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using pCampBot.Interfaces;
|
using pCampBot.Interfaces;
|
||||||
|
|
||||||
namespace pCampBot
|
namespace pCampBot
|
||||||
{
|
{
|
||||||
public class AbstractBehaviour : IBehaviour
|
public abstract class AbstractBehaviour : IBehaviour
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abbreviated name of this behaviour.
|
/// Abbreviated name of this behaviour.
|
||||||
|
@ -44,13 +45,20 @@ namespace pCampBot
|
||||||
|
|
||||||
public Bot Bot { get; protected set; }
|
public Bot Bot { get; protected set; }
|
||||||
|
|
||||||
public virtual void Action() {}
|
public abstract void Action();
|
||||||
|
|
||||||
|
public virtual void Interrupt() {}
|
||||||
|
|
||||||
|
protected AutoResetEvent m_interruptEvent = new AutoResetEvent(false);
|
||||||
|
|
||||||
public virtual void Initialize(Bot bot)
|
public virtual void Initialize(Bot bot)
|
||||||
{
|
{
|
||||||
Bot = bot;
|
Bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Close() {}
|
public virtual void Close()
|
||||||
|
{
|
||||||
|
Interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,5 +43,15 @@ namespace pCampBot
|
||||||
AbbreviatedName = "n";
|
AbbreviatedName = "n";
|
||||||
Name = "None";
|
Name = "None";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Action()
|
||||||
|
{
|
||||||
|
m_interruptEvent.WaitOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Interrupt()
|
||||||
|
{
|
||||||
|
m_interruptEvent.Set();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -82,6 +82,8 @@ namespace pCampBot
|
||||||
{
|
{
|
||||||
if (Bot.ConnectionState == ConnectionState.Connected)
|
if (Bot.ConnectionState == ConnectionState.Connected)
|
||||||
Bot.Client.Self.Jump(false);
|
Bot.Client.Self.Jump(false);
|
||||||
|
|
||||||
|
base.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] readexcuses()
|
private string[] readexcuses()
|
||||||
|
|
|
@ -192,35 +192,34 @@ namespace pCampBot
|
||||||
|
|
||||||
public bool AddBehaviour(IBehaviour behaviour)
|
public bool AddBehaviour(IBehaviour behaviour)
|
||||||
{
|
{
|
||||||
lock (Behaviours)
|
Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours);
|
||||||
{
|
|
||||||
if (!Behaviours.ContainsKey(behaviour.AbbreviatedName))
|
if (!updatedBehaviours.ContainsKey(behaviour.AbbreviatedName))
|
||||||
{
|
{
|
||||||
behaviour.Initialize(this);
|
behaviour.Initialize(this);
|
||||||
Behaviours.Add(behaviour.AbbreviatedName, behaviour);
|
updatedBehaviours.Add(behaviour.AbbreviatedName, behaviour);
|
||||||
|
Behaviours = updatedBehaviours;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RemoveBehaviour(string abbreviatedName)
|
public bool RemoveBehaviour(string abbreviatedName)
|
||||||
{
|
{
|
||||||
lock (Behaviours)
|
Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours);
|
||||||
{
|
|
||||||
IBehaviour behaviour;
|
IBehaviour behaviour;
|
||||||
|
|
||||||
if (!Behaviours.TryGetValue(abbreviatedName, out behaviour))
|
if (!updatedBehaviours.TryGetValue(abbreviatedName, out behaviour))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
behaviour.Close();
|
behaviour.Close();
|
||||||
Behaviours.Remove(abbreviatedName);
|
updatedBehaviours.Remove(abbreviatedName);
|
||||||
|
Behaviours = updatedBehaviours;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateLibOmvClient()
|
private void CreateLibOmvClient()
|
||||||
{
|
{
|
||||||
|
@ -278,8 +277,6 @@ namespace pCampBot
|
||||||
private void Action()
|
private void Action()
|
||||||
{
|
{
|
||||||
while (ConnectionState == ConnectionState.Connected)
|
while (ConnectionState == ConnectionState.Connected)
|
||||||
{
|
|
||||||
lock (Behaviours)
|
|
||||||
{
|
{
|
||||||
foreach (IBehaviour behaviour in Behaviours.Values)
|
foreach (IBehaviour behaviour in Behaviours.Values)
|
||||||
{
|
{
|
||||||
|
@ -290,11 +287,6 @@ namespace pCampBot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: This is a really shitty way of yielding so that behaviours can be added/removed
|
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (Behaviours)
|
|
||||||
foreach (IBehaviour b in Behaviours.Values)
|
foreach (IBehaviour b in Behaviours.Values)
|
||||||
b.Close();
|
b.Close();
|
||||||
}
|
}
|
||||||
|
@ -306,8 +298,8 @@ namespace pCampBot
|
||||||
{
|
{
|
||||||
ConnectionState = ConnectionState.Disconnecting;
|
ConnectionState = ConnectionState.Disconnecting;
|
||||||
|
|
||||||
// if (m_actionThread != null)
|
foreach (IBehaviour behaviour in Behaviours.Values)
|
||||||
// m_actionThread.Abort();
|
behaviour.Interrupt();
|
||||||
|
|
||||||
Client.Network.Logout();
|
Client.Network.Logout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,14 @@ namespace pCampBot.Interfaces
|
||||||
/// <param name="bot"></param>
|
/// <param name="bot"></param>
|
||||||
void Initialize(Bot bot);
|
void Initialize(Bot bot);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interrupt the behaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This should cause the current Action call() to terminate if this is active.
|
||||||
|
/// </remarks>
|
||||||
|
void Interrupt();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Close down this behaviour.
|
/// Close down this behaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue