From 7169acc47e8bb56581bd28c3bd921ca9236ba3c3 Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Tue, 3 Apr 2007 19:12:07 +0000
Subject: * Extended Script API with GetRandomAvatar * The script will now get
a IScriptEntity to it's host object with get/sets * The script gets a
IScriptReadnlyEntity interface to entities other than the host object. * the
test script now follows a random avatar.
---
OpenSim.RegionServer/CAPS/AdminWebFront.cs | 21 ++++---
OpenSim.RegionServer/OpenSim.RegionServer.csproj | 3 +
.../OpenSim.RegionServer.dll.build | 1 +
OpenSim.RegionServer/world/Avatar.cs | 25 +-------
OpenSim.RegionServer/world/Entity.cs | 62 ++++++++++++++++----
OpenSim.RegionServer/world/Primitive.cs | 23 ++++----
OpenSim.RegionServer/world/World.cs | 6 +-
.../world/scripting/IScriptContext.cs | 4 +-
.../world/scripting/IScriptEntity.cs | 19 +++++++
.../world/scripting/IScriptHandler.cs | 66 +++++++++++++++++-----
OpenSim.RegionServer/world/scripting/Script.cs | 3 +-
11 files changed, 159 insertions(+), 74 deletions(-)
create mode 100644 OpenSim.RegionServer/world/scripting/IScriptEntity.cs
(limited to 'OpenSim.RegionServer')
diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
index 43996d0..0d03a57 100644
--- a/OpenSim.RegionServer/CAPS/AdminWebFront.cs
+++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
@@ -9,6 +9,7 @@ using OpenSim.Assets;
using OpenSim.Framework.Inventory;
using libsecondlife;
using OpenSim.RegionServer.world.scripting;
+using Avatar=libsecondlife.Avatar;
namespace OpenSim.CAPS
{
@@ -141,8 +142,6 @@ namespace OpenSim.CAPS
private class TestScript : Script
{
- int toggle = 0;
-
public TestScript()
: base(LLUUID.Random())
{
@@ -151,13 +150,21 @@ namespace OpenSim.CAPS
private void MyOnFrame(IScriptContext context)
{
- toggle = 2 - toggle;
+ LLVector3 pos = context.Entity.Pos;
- LLVector3 pos = context.GetPos();
+ IScriptReadonlyEntity avatar;
+
+ if( context.TryGetRandomAvatar( out avatar ) )
+ {
+ LLVector3 avatarPos = avatar.Pos;
- pos.X += (toggle - 1);
+ float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X))/2;
+ float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y))/2;
- context.MoveTo(pos);
+ LLVector3 newPos = new LLVector3( x, y, pos.Z );
+
+ context.Entity.Pos = newPos;
+ }
}
}
@@ -194,7 +201,7 @@ namespace OpenSim.CAPS
foreach (Entity entity in m_world.Entities.Values)
{
string testScriptLink = "javascript:loadXMLDoc('Admin/AddTestScript/" + entity.uuid.ToString() + "');";
- responseString += String.Format( "
[{0}] \"{1}\" @ {2} add test script", entity.uuid, entity.getName(), entity.position, testScriptLink );
+ responseString += String.Format( "[{0}] \"{1}\" @ {2} add test script", entity.uuid, entity.Name, entity.Pos, testScriptLink );
}
responseString += "";
return responseString;
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
index 73b627e..165b123 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
@@ -187,6 +187,9 @@
Code
+
+ Code
+
Code
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
index bee15fd..47a983b 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
@@ -36,6 +36,7 @@
+
diff --git a/OpenSim.RegionServer/world/Avatar.cs b/OpenSim.RegionServer/world/Avatar.cs
index e1e314a..be47eda 100644
--- a/OpenSim.RegionServer/world/Avatar.cs
+++ b/OpenSim.RegionServer/world/Avatar.cs
@@ -19,7 +19,6 @@ namespace OpenSim.world
public SimClient ControllingClient;
public LLUUID current_anim;
public int anim_seq;
- private PhysicsActor _physActor;
private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
private bool updateflag = false;
private byte movementflag = 0;
@@ -30,7 +29,6 @@ namespace OpenSim.world
private byte[] visualParams;
private AvatarWearable[] Wearables;
private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
- private World m_world;
private ulong m_regionHandle;
private Dictionary m_clientThreads;
private string m_regionName;
@@ -45,8 +43,7 @@ namespace OpenSim.world
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
ControllingClient = TheClient;
localid = 8880000 + (this.m_world._localNumber++);
- position = new LLVector3(100.0f, 100.0f, 30.0f);
- position.Z = m_world.LandMap[(int)position.Y * 256 + (int)position.X] + 1;
+ Pos = new LLVector3(100.0f, 100.0f, m_world.LandMap[(int)Pos.Y * 256 + (int)Pos.X] + 1);
visualParams = new byte[218];
for (int i = 0; i < 218; i++)
{
@@ -209,7 +206,7 @@ namespace OpenSim.world
this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
- libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
+ libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z);
byte[] pb = pos2.GetBytes();
@@ -614,23 +611,7 @@ namespace OpenSim.world
public override void LandRenegerated()
{
- position = new LLVector3(100.0f, 100.0f, 30.0f);
- position.Z = this.m_world.LandMap[(int)position.Y * 256 + (int)position.X] + 50;
- if (this._physActor != null)
- {
- try
- {
- lock (this.m_world.LockPhysicsEngine)
- {
-
- this._physActor.Position = new PhysicsVector(position.X, position.Y, position.Z);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
+ Pos = new LLVector3(100.0f, 100.0f, this.m_world.LandMap[(int)Pos.Y * 256 + (int)Pos.X] + 50);
}
}
diff --git a/OpenSim.RegionServer/world/Entity.cs b/OpenSim.RegionServer/world/Entity.cs
index 567c0b7..424d395 100644
--- a/OpenSim.RegionServer/world/Entity.cs
+++ b/OpenSim.RegionServer/world/Entity.cs
@@ -2,31 +2,78 @@ using System;
using System.Collections.Generic;
using System.Text;
using Axiom.MathLib;
+using OpenSim.Physics.Manager;
using OpenSim.types;
using libsecondlife;
+using OpenSim.RegionServer.world.scripting;
namespace OpenSim.world
{
- public class Entity
+ public abstract class Entity : IScriptReadonlyEntity
{
public libsecondlife.LLUUID uuid;
public uint localid;
- public LLVector3 position;
public LLVector3 velocity;
public Quaternion rotation;
- protected string name;
protected List children;
+ protected string m_name;
+ public virtual string Name
+ {
+ get { return m_name; }
+ }
+
+ private LLVector3 m_pos;
+ protected PhysicsActor _physActor;
+ protected World m_world;
+
+ public LLVector3 Pos
+ {
+ get
+ {
+ if (this._physActor != null)
+ {
+ m_pos.X = _physActor.Position.X;
+ m_pos.Y = _physActor.Position.Y;
+ m_pos.Z = _physActor.Position.Z;
+ }
+
+ return m_pos;
+ }
+ set
+ {
+ if (this._physActor != null)
+ {
+ try
+ {
+ lock (this.m_world.LockPhysicsEngine)
+ {
+
+ this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ m_pos = value;
+ }
+ }
+
+
public Entity()
{
uuid = new libsecondlife.LLUUID();
localid = 0;
- position = new LLVector3();
+ m_pos = new LLVector3();
velocity = new LLVector3();
rotation = new Quaternion();
- name = "(basic entity)";
+ m_name = "(basic entity)";
children = new List();
}
+
public virtual void addForces()
{
foreach (Entity child in children)
@@ -42,11 +89,6 @@ namespace OpenSim.world
}
}
- public virtual string getName()
- {
- return name;
- }
-
public virtual Mesh getMesh()
{
Mesh mesh = new Mesh();
diff --git a/OpenSim.RegionServer/world/Primitive.cs b/OpenSim.RegionServer/world/Primitive.cs
index 156bbfb..8ff66f9 100644
--- a/OpenSim.RegionServer/world/Primitive.cs
+++ b/OpenSim.RegionServer/world/Primitive.cs
@@ -19,13 +19,11 @@ namespace OpenSim.world
protected bool updateFlag = false;
protected bool dirtyFlag = false;
private ObjectUpdatePacket OurPacket;
- private PhysicsActor _physActor;
private bool physicsEnabled = false;
private bool physicstest = false;
private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
private Dictionary m_clientThreads;
private ulong m_regionHandle;
- private World m_world;
private const uint FULL_MASK_PERMISSIONS = 2147483647;
public bool PhysicsEnabled
@@ -130,7 +128,7 @@ namespace OpenSim.world
public void UpdatePosition(LLVector3 pos)
{
- this.position = pos;
+ this.Pos = pos;
if (this._physActor != null) // && this.physicsEnabled)
{
try
@@ -208,7 +206,7 @@ namespace OpenSim.world
if (this.physicstest)
{
- LLVector3 pos = this.position;
+ LLVector3 pos = this.Pos;
pos.Z += 0.0001f;
this.UpdatePosition(pos);
this.physicstest = false;
@@ -226,7 +224,7 @@ namespace OpenSim.world
}
else
{
- lPos = this.position;
+ lPos = this.Pos;
}
byte[] pb = lPos.GetBytes();
Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
@@ -300,7 +298,7 @@ namespace OpenSim.world
this.physicsEnabled = pack.AgentData.UsePhysics;
if (this._physActor.Kinematic == false)
{
- LLVector3 pos = this.position;
+ LLVector3 pos = this.Pos;
this.UpdatePosition(pos);
pos.Z += 0.000001f;
this.UpdatePosition(pos);
@@ -310,7 +308,7 @@ namespace OpenSim.world
{
PhysicsVector vec = this._physActor.Position;
LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z);
- this.position = pos;
+ this.Pos = pos;
this.updateFlag = true;
}
}
@@ -319,7 +317,7 @@ namespace OpenSim.world
public void MakeParent(Primitive prim)
{
this.primData.ParentID = prim.localid;
- this.position -= prim.position;
+ this.Pos -= prim.Pos;
this.dirtyFlag = true;
}
@@ -385,7 +383,7 @@ namespace OpenSim.world
this.newPrimFlag = true;
this.primData.FullID = this.uuid = objupdate.ObjectData[0].FullID;
this.localid = objupdate.ObjectData[0].ID;
- this.primData.Position = this.position = pos1;
+ this.primData.Position = this.Pos = pos1;
this.OurPacket = objupdate;
}
@@ -466,7 +464,7 @@ namespace OpenSim.world
this.uuid = objupdate.ObjectData[0].FullID;
this.localid = objupdate.ObjectData[0].ID;
- this.position = pos1;
+ this.Pos = pos1;
this.OurPacket = objupdate;
if (newprim)
{
@@ -501,7 +499,7 @@ namespace OpenSim.world
}
else
{
- lPos = this.position;
+ lPos = this.Pos;
lRot = this.rotation;
}
byte[] pb = lPos.GetBytes();
@@ -557,10 +555,9 @@ namespace OpenSim.world
{
this.primData.FullID = this.uuid;
this.primData.LocalID = this.localid;
- this.primData.Position = this.position;
+ this.primData.Position = this.Pos;
this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w);
this.m_world.localStorage.StorePrim(this.primData);
}
}
-
}
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs
index 408f68d..c775429 100644
--- a/OpenSim.RegionServer/world/World.cs
+++ b/OpenSim.RegionServer/world/World.cs
@@ -335,7 +335,7 @@ namespace OpenSim.world
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world");
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
NewAvatar.SendRegionHandshake(this);
- PhysicsVector pVec = new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z);
+ PhysicsVector pVec = new PhysicsVector(NewAvatar.Pos.X, NewAvatar.Pos.Y, NewAvatar.Pos.Z);
lock (this.LockPhysicsEngine)
{
NewAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
@@ -348,7 +348,7 @@ namespace OpenSim.world
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim");
Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this);
prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount);
- PhysicsVector pVec = new PhysicsVector(prim.position.X, prim.position.Y, prim.position.Z);
+ PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z);
PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f);
if (OpenSim.world.Avatar.PhysicsEngineFlying)
{
@@ -521,7 +521,7 @@ namespace OpenSim.world
reply.ChatData.Message = inchatpack.ChatData.Message;
reply.ChatData.ChatType = 1;
reply.ChatData.SourceType = 1;
- reply.ChatData.Position = simClient.ClientAvatar.position;
+ reply.ChatData.Position = simClient.ClientAvatar.Pos;
reply.ChatData.FromName = enc.GetBytes(simClient.ClientAvatar.firstname + " " + simClient.ClientAvatar.lastname + "\0");
reply.ChatData.OwnerID = simClient.AgentID;
reply.ChatData.SourceID = simClient.AgentID;
diff --git a/OpenSim.RegionServer/world/scripting/IScriptContext.cs b/OpenSim.RegionServer/world/scripting/IScriptContext.cs
index 80878ef..465c23b 100644
--- a/OpenSim.RegionServer/world/scripting/IScriptContext.cs
+++ b/OpenSim.RegionServer/world/scripting/IScriptContext.cs
@@ -7,7 +7,7 @@ namespace OpenSim.RegionServer.world.scripting
{
public interface IScriptContext
{
- bool MoveTo(LLVector3 newPos);
- LLVector3 GetPos();
+ IScriptEntity Entity { get; }
+ bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
}
}
diff --git a/OpenSim.RegionServer/world/scripting/IScriptEntity.cs b/OpenSim.RegionServer/world/scripting/IScriptEntity.cs
new file mode 100644
index 0000000..2ef16a4
--- /dev/null
+++ b/OpenSim.RegionServer/world/scripting/IScriptEntity.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using libsecondlife;
+
+namespace OpenSim.RegionServer.world.scripting
+{
+ public interface IScriptReadonlyEntity
+ {
+ LLVector3 Pos { get; }
+ string Name { get; }
+ }
+
+ public interface IScriptEntity
+ {
+ LLVector3 Pos { get; set; }
+ string Name { get; }
+ }
+}
diff --git a/OpenSim.RegionServer/world/scripting/IScriptHandler.cs b/OpenSim.RegionServer/world/scripting/IScriptHandler.cs
index 5addb35..15efc49 100644
--- a/OpenSim.RegionServer/world/scripting/IScriptHandler.cs
+++ b/OpenSim.RegionServer/world/scripting/IScriptHandler.cs
@@ -4,18 +4,19 @@ using System.Text;
using libsecondlife;
using OpenSim.Physics.Manager;
using OpenSim.world;
-using Primitive=OpenSim.world.Primitive;
+using Avatar=OpenSim.world.Avatar;
+using Primitive = OpenSim.world.Primitive;
namespace OpenSim.RegionServer.world.scripting
{
- public delegate void ScriptEventHandler( IScriptContext context );
-
- public class ScriptHandler : IScriptContext
+ public delegate void ScriptEventHandler(IScriptContext context);
+
+ public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
{
private World m_world;
private Script m_script;
private Entity m_entity;
-
+
public LLUUID ScriptId
{
get
@@ -23,13 +24,13 @@ namespace OpenSim.RegionServer.world.scripting
return m_script.ScriptId;
}
}
-
+
public void OnFrame()
{
m_script.OnFrame(this);
}
- public ScriptHandler( Script script, Entity entity, World world )
+ public ScriptHandler(Script script, Entity entity, World world)
{
m_script = script;
m_entity = entity;
@@ -38,22 +39,57 @@ namespace OpenSim.RegionServer.world.scripting
#region IScriptContext Members
- bool IScriptContext.MoveTo(LLVector3 newPos)
+ IScriptEntity IScriptContext.Entity
+ {
+ get
+ {
+ return this;
+ }
+ }
+
+ bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
{
- if (m_entity is Primitive)
+ foreach (Entity entity in m_world.Entities.Values )
{
- Primitive prim = m_entity as Primitive;
- // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
- prim.UpdatePosition( newPos );
- return true;
+ if( entity is Avatar )
+ {
+ avatar = entity;
+ return true;
+ }
}
+ avatar = null;
return false;
}
- LLVector3 IScriptContext.GetPos()
+ #endregion
+
+ #region IScriptEntity and IScriptReadonlyEntity Members
+
+ public string Name
+ {
+ get
+ {
+ return m_entity.Name;
+ }
+ }
+
+ public LLVector3 Pos
{
- return m_entity.position;
+ get
+ {
+ return m_entity.Pos;
+ }
+
+ set
+ {
+ if (m_entity is Primitive)
+ {
+ Primitive prim = m_entity as Primitive;
+ // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
+ prim.UpdatePosition( value );
+ }
+ }
}
#endregion
diff --git a/OpenSim.RegionServer/world/scripting/Script.cs b/OpenSim.RegionServer/world/scripting/Script.cs
index 3997b41..48c18ff 100644
--- a/OpenSim.RegionServer/world/scripting/Script.cs
+++ b/OpenSim.RegionServer/world/scripting/Script.cs
@@ -7,8 +7,7 @@ namespace OpenSim.RegionServer.world.scripting
{
public class Script
{
- private LLUUID m_scriptId;
-
+ private LLUUID m_scriptId;
public virtual LLUUID ScriptId
{
get
--
cgit v1.1