ObjectsAvatars and ObjectsPrimitives are now ConcurrentDictionary to avoid a rather nasty locking bottleneck.
This commit is contained in:
@@ -43,18 +43,14 @@ namespace OpenMetaverse.TestClient
|
||||
{
|
||||
lock (Client.Network.Simulators)
|
||||
{
|
||||
foreach (var sim in Client.Network.Simulators)
|
||||
foreach (var target in Client.Network.Simulators
|
||||
.Select(sim => sim.ObjectsAvatars
|
||||
.FirstOrDefault(avatar => avatar.Value.Name == name))
|
||||
.Where(target => target.Value != null))
|
||||
{
|
||||
Avatar target = sim.ObjectsAvatars.Find(
|
||||
avatar => avatar.Name == name
|
||||
);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
targetLocalID = target.LocalID;
|
||||
Active = true;
|
||||
return true;
|
||||
}
|
||||
targetLocalID = target.Value.LocalID;
|
||||
Active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,30 +16,28 @@ namespace OpenMetaverse.TestClient
|
||||
Primitive closest = null;
|
||||
double closestDistance = double.MaxValue;
|
||||
|
||||
Client.Network.CurrentSim.ObjectsPrimitives.ForEach(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
float distance = Vector3.Distance(Client.Self.SimPosition, prim.Position);
|
||||
|
||||
if (closest == null || distance < closestDistance)
|
||||
{
|
||||
closest = prim;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (closest != null)
|
||||
foreach (var kvp in Client.Network.CurrentSim.ObjectsPrimitives)
|
||||
{
|
||||
Client.Self.RequestSit(closest.ID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
if (kvp.Value == null) { continue; }
|
||||
|
||||
return "Sat on " + closest.ID + " (" + closest.LocalID + "). Distance: " + closestDistance;
|
||||
var prim = kvp.Value;
|
||||
var distance = Vector3.Distance(Client.Self.SimPosition, prim.Position);
|
||||
if (closest == null || distance < closestDistance)
|
||||
{
|
||||
closest = prim;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (closest == null)
|
||||
{
|
||||
return "Couldn't find a nearby prim to sit on";
|
||||
}
|
||||
}
|
||||
Client.Self.RequestSit(closest.ID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
|
||||
return $"Sat on {closest.ID} ({closest.LocalID}). Distance: {closestDistance}";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenMetaverse.TestClient
|
||||
{
|
||||
public class SitOnCommand : Command
|
||||
@@ -14,16 +16,13 @@ namespace OpenMetaverse.TestClient
|
||||
if (args.Length != 1)
|
||||
return "Usage: siton UUID";
|
||||
|
||||
UUID target;
|
||||
|
||||
if (UUID.TryParse(args[0], out target))
|
||||
if (UUID.TryParse(args[0], out var target))
|
||||
{
|
||||
Primitive targetPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(
|
||||
prim => prim.ID == target
|
||||
);
|
||||
var kvp = Client.Network.CurrentSim.ObjectsPrimitives.FirstOrDefault(prim => prim.Value.ID == target);
|
||||
|
||||
if (targetPrim != null)
|
||||
if (kvp.Value != null)
|
||||
{
|
||||
var targetPrim = kvp.Value;
|
||||
Client.Self.RequestSit(targetPrim.ID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
return "Requested to sit on prim " + targetPrim.ID +
|
||||
|
||||
Reference in New Issue
Block a user