Mantis#1496. Thank you kindly, Melanie for a patch that:

Adds full implementation of all llDetected* functions for sensors, 
collisions and touches. Adds changed(CHANGED_REGION_RESTART) event 
to allow restarting of eye-candy functionality not currently 
persisted with the prim.
0.6.0-stable
Charles Krinke 2008-06-07 22:37:48 +00:00
parent 6ce9a8ecdd
commit 0e5f2b3293
5 changed files with 283 additions and 106 deletions

View File

@ -324,6 +324,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.AsyncCommandPlugins
{ {
detect[idx] = new XDetectParams(); detect[idx] = new XDetectParams();
detect[idx].Key=(LLUUID)(SensedObjects.Data[idx]); detect[idx].Key=(LLUUID)(SensedObjects.Data[idx]);
detect[idx].Populate(m_CmdManager.m_ScriptEngine.World);
} }
m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,

View File

@ -26,6 +26,8 @@
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic;
using libsecondlife; using libsecondlife;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney; using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney;
@ -55,6 +57,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target; myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target;
myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target; myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target;
myScriptEngine.World.EventManager.OnScriptControlEvent += control; myScriptEngine.World.EventManager.OnScriptControlEvent += control;
myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start;
myScriptEngine.World.EventManager.OnScriptColliding += collision;
myScriptEngine.World.EventManager.OnScriptCollidingEnd += collision_end;
IMoneyModule money=myScriptEngine.World.RequestModuleInterface<IMoneyModule>(); IMoneyModule money=myScriptEngine.World.RequestModuleInterface<IMoneyModule>();
if (money != null) if (money != null)
{ {
@ -81,6 +86,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
XDetectParams[] det = new XDetectParams[1]; XDetectParams[] det = new XDetectParams[1];
det[0] = new XDetectParams(); det[0] = new XDetectParams();
det[0].Key = remoteClient.AgentId; det[0].Key = remoteClient.AgentId;
det[0].Populate(myScriptEngine.World);
SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart( SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(
localID); localID);
@ -103,6 +109,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
XDetectParams[] det = new XDetectParams[1]; XDetectParams[] det = new XDetectParams[1];
det[0] = new XDetectParams(); det[0] = new XDetectParams();
det[0].Key = remoteClient.AgentId; det[0].Key = remoteClient.AgentId;
det[0].Populate(myScriptEngine.World);
det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X, det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X,
offsetPos.Y, offsetPos.Y,
offsetPos.Z); offsetPos.Z);
@ -127,6 +134,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
XDetectParams[] det = new XDetectParams[1]; XDetectParams[] det = new XDetectParams[1];
det[0] = new XDetectParams(); det[0] = new XDetectParams();
det[0].Key = remoteClient.AgentId; det[0].Key = remoteClient.AgentId;
det[0].Populate(myScriptEngine.World);
SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart( SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(
localID); localID);
@ -162,45 +170,60 @@ namespace OpenSim.Region.ScriptEngine.XEngine
new XDetectParams[0])); new XDetectParams[0]));
} }
public void collision_start(uint localID, LLUUID itemID, public void collision_start(uint localID, ColliderArgs col)
IClientAPI remoteClient)
{ {
// Add to queue for all scripts in ObjectID object // Add to queue for all scripts in ObjectID object
XDetectParams[] det = new XDetectParams[1]; List<XDetectParams> det = new List<XDetectParams>();
det[0] = new XDetectParams();
det[0].Key = remoteClient.AgentId; foreach (DetectedObject detobj in col.Colliders)
{
XDetectParams d = new XDetectParams();
d.Key =detobj.keyUUID;
d.Populate(myScriptEngine.World);
det.Add(d);
}
myScriptEngine.PostObjectEvent(localID, new XEventParams( myScriptEngine.PostObjectEvent(localID, new XEventParams(
"collision_start", "collision_start",
new Object[] { new LSL_Types.LSLInteger(1) }, new Object[] { new LSL_Types.LSLInteger(1) },
det)); det.ToArray()));
} }
public void collision(uint localID, LLUUID itemID, public void collision(uint localID, ColliderArgs col)
IClientAPI remoteClient)
{ {
// Add to queue for all scripts in ObjectID object // Add to queue for all scripts in ObjectID object
XDetectParams[] det = new XDetectParams[1]; List<XDetectParams> det = new List<XDetectParams>();
det[0] = new XDetectParams();
det[0].Key = remoteClient.AgentId; foreach (DetectedObject detobj in col.Colliders)
{
XDetectParams d = new XDetectParams();
d.Key =detobj.keyUUID;
d.Populate(myScriptEngine.World);
det.Add(d);
}
myScriptEngine.PostObjectEvent(localID, new XEventParams( myScriptEngine.PostObjectEvent(localID, new XEventParams(
"collision", new Object[] { new LSL_Types.LSLInteger(1) }, "collision", new Object[] { new LSL_Types.LSLInteger(1) },
det)); det.ToArray()));
} }
public void collision_end(uint localID, LLUUID itemID, public void collision_end(uint localID, ColliderArgs col)
IClientAPI remoteClient)
{ {
// Add to queue for all scripts in ObjectID object // Add to queue for all scripts in ObjectID object
XDetectParams[] det = new XDetectParams[1]; List<XDetectParams> det = new List<XDetectParams>();
det[0] = new XDetectParams();
det[0].Key = remoteClient.AgentId; foreach (DetectedObject detobj in col.Colliders)
{
XDetectParams d = new XDetectParams();
d.Key =detobj.keyUUID;
d.Populate(myScriptEngine.World);
det.Add(d);
}
myScriptEngine.PostObjectEvent(localID, new XEventParams( myScriptEngine.PostObjectEvent(localID, new XEventParams(
"collision_end", "collision_end",
new Object[] { new LSL_Types.LSLInteger(1) }, new Object[] { new LSL_Types.LSLInteger(1) },
det)); det.ToArray()));
} }
public void land_collision_start(uint localID, LLUUID itemID) public void land_collision_start(uint localID, LLUUID itemID)

View File

@ -550,113 +550,55 @@ namespace OpenSim.Region.ScriptEngine.XEngine
public string llDetectedName(int number) public string llDetectedName(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
LLUUID sensedUUID = m_ScriptEngine.GetDetectID(m_itemID, number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (sensedUUID != LLUUID.Zero) if (d == null)
return resolveName(sensedUUID); return String.Empty;
return String.Empty; return d.Name;
}
public LLUUID uuidDetectedKey(int number)
{
return m_ScriptEngine.GetDetectID(m_itemID, number);
}
public EntityBase entityDetectedKey(int number)
{
LLUUID sensedUUID = m_ScriptEngine.GetDetectID(m_itemID, number);
if (sensedUUID != LLUUID.Zero)
{
EntityBase SensedObject = null;
lock (World.Entities)
{
World.Entities.TryGetValue(sensedUUID, out SensedObject);
}
return SensedObject;
}
return null;
} }
public string llDetectedKey(int number) public string llDetectedKey(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
LLUUID SensedUUID = uuidDetectedKey(number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (SensedUUID == LLUUID.Zero) if (d == null)
return String.Empty; return String.Empty;
return d.Key.ToString();
return SensedUUID.ToString();
} }
public string llDetectedOwner(int number) public string llDetectedOwner(int number)
{ {
// returns UUID of owner of object detected
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
EntityBase SensedObject = entityDetectedKey(number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (SensedObject == null) if (d == null)
return String.Empty; return String.Empty;
LLUUID SensedUUID = uuidDetectedKey(number); return d.Owner.ToString();
if (World.GetScenePresence(SensedUUID) == null) }
{
// sensed object is not an avatar
// so get the owner of the sensed object
SceneObjectPart SOP = World.GetSceneObjectPart(SensedUUID);
if (SOP != null)
{
return SOP.ObjectOwner.ToString();
}
}
else
{
// sensed object is an avatar, and so must be its own owner
return SensedUUID.ToString();
}
return String.Empty;
}
public LSL_Types.LSLInteger llDetectedType(int number) public LSL_Types.LSLInteger llDetectedType(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
EntityBase SensedObject = entityDetectedKey(number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (SensedObject == null) if (d == null)
return 0; return 0;
int mask = 0; return new LSL_Types.LSLInteger(d.Type);
LLUUID SensedUUID = uuidDetectedKey(number);
LSL_Types.Vector3 ZeroVector = new LSL_Types.Vector3(0, 0, 0);
if (World.GetScenePresence(SensedUUID) != null)
mask |= 0x01; // actor
if (SensedObject.Velocity.Equals(ZeroVector))
mask |= 0x04; // passive non-moving
else
mask |= 0x02; // active moving
if (SensedObject is IScript)
mask |= 0x08; // Scripted. It COULD have one hidden ...
return mask;
} }
public LSL_Types.Vector3 llDetectedPos(int number) public LSL_Types.Vector3 llDetectedPos(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
EntityBase SensedObject = entityDetectedKey(number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (SensedObject == null) if (d == null)
return new LSL_Types.Vector3(0, 0, 0); return new LSL_Types.Vector3();
return d.Position;
return new LSL_Types.Vector3(SensedObject.AbsolutePosition.X,SensedObject.AbsolutePosition.Y,SensedObject.AbsolutePosition.Z);
} }
public LSL_Types.Vector3 llDetectedVel(int number) public LSL_Types.Vector3 llDetectedVel(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
EntityBase SensedObject = entityDetectedKey(number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (SensedObject == null) if (d == null)
return new LSL_Types.Vector3(0, 0, 0); return new LSL_Types.Vector3();
return d.Velocity;
return new LSL_Types.Vector3(SensedObject.Velocity.X, SensedObject.Velocity.Y, SensedObject.Velocity.Z);
// return new LSL_Types.Vector3();
} }
public LSL_Types.Vector3 llDetectedGrab(int number) public LSL_Types.Vector3 llDetectedGrab(int number)
@ -672,18 +614,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine
public LSL_Types.Quaternion llDetectedRot(int number) public LSL_Types.Quaternion llDetectedRot(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
EntityBase SensedObject = entityDetectedKey(number); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
if (SensedObject == null) if (d == null)
return new LSL_Types.Quaternion(); return new LSL_Types.Quaternion();
return d.Rotation;
return new LSL_Types.Quaternion(SensedObject.Rotation.x, SensedObject.Rotation.y, SensedObject.Rotation.z, SensedObject.Rotation.w);
} }
public LSL_Types.LSLInteger llDetectedGroup(int number) public LSL_Types.LSLInteger llDetectedGroup(int number)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
NotImplemented("llDetectedGroup"); XDetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
return 0; if (d == null)
return new LSL_Types.LSLInteger(0);
if(m_host.GroupID == d.Group)
return new LSL_Types.LSLInteger(1);
return new LSL_Types.LSLInteger(0);
} }
public LSL_Types.LSLInteger llDetectedLinkNumber(int number) public LSL_Types.LSLInteger llDetectedLinkNumber(int number)

View File

@ -2080,6 +2080,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Script
public const int CHANGED_LINK = 32; public const int CHANGED_LINK = 32;
public const int CHANGED_ALLOWED_DROP = 64; public const int CHANGED_ALLOWED_DROP = 64;
public const int CHANGED_OWNER = 128; public const int CHANGED_OWNER = 128;
public const int CHANGED_REGION_RESTART = 256;
public const int TYPE_INVALID = 0; public const int TYPE_INVALID = 0;
public const int TYPE_INTEGER = 1; public const int TYPE_INTEGER = 1;
public const int TYPE_double = 2; public const int TYPE_double = 2;

View File

@ -388,7 +388,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
part.UUID, itemID, assetID, assembly, part.UUID, itemID, assetID, assembly,
m_AppDomains[appDomain], m_AppDomains[appDomain],
part.ParentGroup.RootPart.Name, part.ParentGroup.RootPart.Name,
item.Name); item.Name, XScriptInstance.StateSource.NewRez);
m_log.DebugFormat("[XEngine] Loaded script {0}.{1}", m_log.DebugFormat("[XEngine] Loaded script {0}.{1}",
part.ParentGroup.RootPart.Name, item.Name); part.ParentGroup.RootPart.Name, item.Name);
@ -673,9 +673,97 @@ namespace OpenSim.Region.ScriptEngine.XEngine
public class XDetectParams public class XDetectParams
{ {
public XDetectParams()
{
Key = LLUUID.Zero;
OffsetPos = new LSL_Types.Vector3();
LinkNum = 0;
Group = LLUUID.Zero;
Name = String.Empty;
Owner = LLUUID.Zero;
Position = new LSL_Types.Vector3();
Rotation = new LSL_Types.Quaternion();
Type = 0;
Velocity = new LSL_Types.Vector3();
}
public LLUUID Key; public LLUUID Key;
public LSL_Types.Vector3 OffsetPos; public LSL_Types.Vector3 OffsetPos;
public int LinkNum; public int LinkNum;
public LLUUID Group;
public string Name;
public LLUUID Owner;
public LSL_Types.Vector3 Position;
public LSL_Types.Quaternion Rotation;
public int Type;
public LSL_Types.Vector3 Velocity;
public void Populate(Scene scene)
{
SceneObjectPart part = scene.GetSceneObjectPart(Key);
if(part == null) // Avatar, maybe?
{
ScenePresence presence = scene.GetScenePresence(Key);
if(presence == null)
return;
Name = presence.Firstname + " " + presence.Lastname;
Owner = Key;
Position = new LSL_Types.Vector3(
presence.AbsolutePosition.X,
presence.AbsolutePosition.X,
presence.AbsolutePosition.Z);
Rotation = new LSL_Types.Quaternion(
presence.Rotation.x,
presence.Rotation.y,
presence.Rotation.z,
presence.Rotation.w);
Velocity = new LSL_Types.Vector3(
presence.Velocity.X,
presence.Velocity.X,
presence.Velocity.Z);
Type = 0x01; // Avatar
if(presence.Velocity != LLVector3.Zero)
Type |= 0x02; // Active
Group = presence.ControllingClient.ActiveGroupId;
return;
}
part=part.ParentGroup.RootPart; // We detect objects only
LinkNum = 0; // Not relevant
Group = part.GroupID;
Name = part.Name;
Owner = part.OwnerID;
if(part.Velocity == LLVector3.Zero)
Type = 0x04; // Passive
else
Type = 0x02; // Passive
foreach (SceneObjectPart p in part.ParentGroup.Children.Values)
{
if(part.ContainsScripts())
{
Type |= 0x08; // Scripted
break;
}
}
Position = new LSL_Types.Vector3(part.AbsolutePosition.X,
part.AbsolutePosition.Y,
part.AbsolutePosition.Z);
LLQuaternion wr = part.GetWorldRotation();
Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
Velocity = new LSL_Types.Vector3(part.Velocity.X,
part.Velocity.Y,
part.Velocity.Z);
}
} }
public class XEventParams public class XEventParams
@ -715,6 +803,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
private string m_ScriptName; private string m_ScriptName;
private string m_Assembly; private string m_Assembly;
public enum StateSource
{
NewRez = 0,
PrimCrossing = 1,
AttachmentCrossing = 2
}
// Script state // Script state
private string m_State="default"; private string m_State="default";
@ -786,7 +881,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
public XScriptInstance(XEngine engine, uint localID, LLUUID objectID, public XScriptInstance(XEngine engine, uint localID, LLUUID objectID,
LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom, LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom,
string primName, string scriptName) string primName, string scriptName, StateSource stateSource)
{ {
m_Engine = engine; m_Engine = engine;
@ -874,6 +969,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
m_RunEvents = false; m_RunEvents = false;
Start(); Start();
} }
// we get new rez events on sim restart, too
// but if there is state, then we fire the change
// event
if(stateSource == StateSource.NewRez)
PostEvent(new XEventParams("changed",
new Object[] {256}, new XDetectParams[0]));
} }
} }
else else
@ -1286,6 +1388,47 @@ namespace OpenSim.Region.ScriptEngine.XEngine
XmlAttribute pos = xmldoc.CreateAttribute("", "pos", ""); XmlAttribute pos = xmldoc.CreateAttribute("", "pos", "");
pos.Value = det.OffsetPos.ToString(); pos.Value = det.OffsetPos.ToString();
objectElem.Attributes.Append(pos); objectElem.Attributes.Append(pos);
XmlAttribute d_linkNum = xmldoc.CreateAttribute("",
"linkNum", "");
d_linkNum.Value = det.LinkNum.ToString();
objectElem.Attributes.Append(d_linkNum);
XmlAttribute d_group = xmldoc.CreateAttribute("",
"group", "");
d_group.Value = det.Group.ToString();
objectElem.Attributes.Append(d_group);
XmlAttribute d_name = xmldoc.CreateAttribute("",
"name", "");
d_name.Value = det.Name.ToString();
objectElem.Attributes.Append(d_name);
XmlAttribute d_owner = xmldoc.CreateAttribute("",
"owner", "");
d_owner.Value = det.Owner.ToString();
objectElem.Attributes.Append(d_owner);
XmlAttribute d_position = xmldoc.CreateAttribute("",
"position", "");
d_position.Value = det.Position.ToString();
objectElem.Attributes.Append(d_position);
XmlAttribute d_rotation = xmldoc.CreateAttribute("",
"rotation", "");
d_rotation.Value = det.Rotation.ToString();
objectElem.Attributes.Append(d_rotation);
XmlAttribute d_type = xmldoc.CreateAttribute("",
"type", "");
d_type.Value = det.Type.ToString();
objectElem.Attributes.Append(d_type);
XmlAttribute d_velocity = xmldoc.CreateAttribute("",
"velocity", "");
d_velocity.Value = det.Velocity.ToString();
objectElem.Attributes.Append(d_velocity);
objectElem.AppendChild( objectElem.AppendChild(
xmldoc.CreateTextNode(det.Key.ToString())); xmldoc.CreateTextNode(det.Key.ToString()));
@ -1385,6 +1528,62 @@ namespace OpenSim.Region.ScriptEngine.XEngine
"pos").Value; "pos").Value;
LSL_Types.Vector3 v = LSL_Types.Vector3 v =
new LSL_Types.Vector3(vect); new LSL_Types.Vector3(vect);
int d_linkNum=0;
LLUUID d_group = LLUUID.Zero;
string d_name = String.Empty;
LLUUID d_owner = LLUUID.Zero;
LSL_Types.Vector3 d_position =
new LSL_Types.Vector3();
LSL_Types.Quaternion d_rotation =
new LSL_Types.Quaternion();
int d_type = 0;
LSL_Types.Vector3 d_velocity =
new LSL_Types.Vector3();
try
{
string tmp;
tmp = det.Attributes.GetNamedItem(
"linkNum").Value;
int.TryParse(tmp, out d_linkNum);
tmp = det.Attributes.GetNamedItem(
"group").Value;
LLUUID.TryParse(tmp, out d_group);
d_name = det.Attributes.GetNamedItem(
"name").Value;
tmp = det.Attributes.GetNamedItem(
"owner").Value;
LLUUID.TryParse(tmp, out d_owner);
tmp = det.Attributes.GetNamedItem(
"position").Value;
d_position =
new LSL_Types.Vector3(tmp);
tmp = det.Attributes.GetNamedItem(
"rotation").Value;
d_rotation =
new LSL_Types.Quaternion(tmp);
tmp = det.Attributes.GetNamedItem(
"type").Value;
int.TryParse(tmp, out d_type);
tmp = det.Attributes.GetNamedItem(
"velocity").Value;
d_velocity =
new LSL_Types.Vector3(tmp);
}
catch (Exception) // Old version XML
{
}
LLUUID uuid = new LLUUID(); LLUUID uuid = new LLUUID();
LLUUID.TryParse(det.InnerText, LLUUID.TryParse(det.InnerText,
out uuid); out uuid);
@ -1392,6 +1591,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
XDetectParams d = new XDetectParams(); XDetectParams d = new XDetectParams();
d.Key = uuid; d.Key = uuid;
d.OffsetPos = v; d.OffsetPos = v;
d.LinkNum = d_linkNum;
d.Group = d_group;
d.Name = d_name;
d.Owner = d_owner;
d.Position = d_position;
d.Rotation = d_rotation;
d.Type = d_type;
d.Velocity = d_velocity;
detected.Add(d); detected.Add(d);
} }