From e12baa5eb33882fc1d4c6aa0886037e00d726e2e Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 5 Jun 2008 13:24:59 +0000 Subject: * This sends collision events to the script engine. * Unfortunately, there's some kludges with the Async manager and the llDetected functions that I have yet to decipher... so llDetected functions don't work with collision events at the moment.... --- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 55 +++++++++++++- .../Common/ScriptEngineBase/EventManager.cs | 85 ++++++++++++++++++++-- .../Common/ScriptEngineBase/EventQueueManager.cs | 3 +- .../ScriptEngine/Common/ScriptServerInterfaces.cs | 9 ++- 4 files changed, 137 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Common') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 663ac0c..4c58e36 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -562,6 +562,25 @@ namespace OpenSim.Region.ScriptEngine.Common return resolveName(SensedUUID); } } + else + { + ScriptManager sm; + IScript script = null; + + if ((sm = m_ScriptEngine.m_ScriptManager) != null) + { + if (sm.Scripts.ContainsKey(m_localID)) + { + if ((script = sm.GetScript(m_localID, m_itemID)) != null) + { + if (script.llDetectParams._bool.Length > number && script.llDetectParams._bool[number]) + { + return script.llDetectParams._string[number]; + } + } + } + } + } return String.Empty; } @@ -587,9 +606,12 @@ namespace OpenSim.Region.ScriptEngine.Common { if ((script = sm.GetScript(m_localID, m_itemID)) != null) { - if (script.llDetectParams._key[0]) + if (script.llDetectParams._bool.Length > number && script.llDetectParams._bool[number]) { - return new LLUUID(script.llDetectParams._key[0]); + LLUUID returnUUID = LLUUID.Zero; + Helpers.TryParse(script.llDetectParams._key[number], out returnUUID); + + return returnUUID; } } } @@ -614,6 +636,35 @@ namespace OpenSim.Region.ScriptEngine.Common return SensedObject; } } + else + { + ScriptManager sm; + IScript script = null; + + if ((sm = m_ScriptEngine.m_ScriptManager) != null) + { + if (sm.Scripts.ContainsKey(m_localID)) + { + if ((script = sm.GetScript(m_localID, m_itemID)) != null) + { + if (script.llDetectParams._key[number]) + { + EntityBase SensedObject = null; + LLUUID SensedUUID = LLUUID.Zero; + Helpers.TryParse(script.llDetectParams._key.ToString(), out SensedUUID); + if (SensedUUID == LLUUID.Zero) + return null; + lock (World.Entities) + { + World.Entities.TryGetValue(SensedUUID, out SensedObject); + } + return SensedObject; + + } + } + } + } + } return null; } diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs index 5ef4a6b..ae84f65 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs @@ -26,9 +26,12 @@ */ using System; +using System.Collections.Generic; using libsecondlife; using OpenSim.Framework; using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney; +using OpenSim.Region.Environment; +using OpenSim.Region; using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Interfaces; @@ -74,6 +77,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target; myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target; myScriptEngine.World.EventManager.OnScriptControlEvent += control; + myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start; + myScriptEngine.World.EventManager.OnScriptColliding += collision; + myScriptEngine.World.EventManager.OnScriptCollidingEnd += collision_end; // TODO: HOOK ALL EVENTS UP TO SERVER! IMoneyModule money=myScriptEngine.World.RequestModuleInterface(); @@ -171,19 +177,82 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "touch_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) }); } - public void collision_start(uint localID, LLUUID itemID) + public void collision_start(uint localID, ColliderArgs col) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_start", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) }); + EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); + detstruct._string = new string[col.Colliders.Count]; + detstruct._Quaternion = new LSL_Types.Quaternion[col.Colliders.Count]; + detstruct._int = new int[col.Colliders.Count]; + detstruct._key = new LSL_Types.key[col.Colliders.Count]; + detstruct._Vector3 = new LSL_Types.Vector3[col.Colliders.Count]; + detstruct._Vector32 = new LSL_Types.Vector3[col.Colliders.Count]; + detstruct._bool = new bool[col.Colliders.Count]; + + int i = 0; + foreach (DetectedObject detobj in col.Colliders) + { + detstruct._key[i] = new LSL_Types.key(detobj.keyUUID.ToString()); + detstruct._Quaternion[i] = new LSL_Types.Quaternion(detobj.rotQuat.X, detobj.rotQuat.Y, detobj.rotQuat.Z, detobj.rotQuat.W); + detstruct._string[i] = detobj.nameStr; + detstruct._int[i] = detobj.colliderType; + detstruct._Vector3[i] = new LSL_Types.Vector3(detobj.posVector.X, detobj.posVector.Y, detobj.posVector.Z); + detstruct._Vector32[i] = new LSL_Types.Vector3(detobj.velVector.X, detobj.velVector.Y, detobj.velVector.Z); + detstruct._bool[i] = true; // Apparently the script engine uses this to see if this is a valid entry... + i++; + } + + myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "collision_start", detstruct, new object[] { new LSL_Types.LSLInteger(col.Colliders.Count) }); } - public void collision(uint localID, LLUUID itemID) + public void collision(uint localID, ColliderArgs col) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) }); + EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); + detstruct._string = new string[col.Colliders.Count]; + detstruct._Quaternion = new LSL_Types.Quaternion[col.Colliders.Count]; + detstruct._int = new int[col.Colliders.Count]; + detstruct._key = new LSL_Types.key[col.Colliders.Count]; + detstruct._Vector3 = new LSL_Types.Vector3[col.Colliders.Count]; + detstruct._Vector32 = new LSL_Types.Vector3[col.Colliders.Count]; + detstruct._bool = new bool[col.Colliders.Count]; + + int i = 0; + foreach (DetectedObject detobj in col.Colliders) + { + detstruct._key[i] = new LSL_Types.key(detobj.keyUUID.ToString()); + detstruct._Quaternion[i] = new LSL_Types.Quaternion(detobj.rotQuat.X, detobj.rotQuat.Y, detobj.rotQuat.Z, detobj.rotQuat.W); + detstruct._string[i] = detobj.nameStr; + detstruct._int[i] = detobj.colliderType; + detstruct._Vector3[i] = new LSL_Types.Vector3(detobj.posVector.X, detobj.posVector.Y, detobj.posVector.Z); + detstruct._Vector32[i] = new LSL_Types.Vector3(detobj.velVector.X, detobj.velVector.Y, detobj.velVector.Z); + detstruct._bool[i] = true; // Apparently the script engine uses this to see if this is a valid entry... i++; + } + myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "collision", detstruct, new object[] { new LSL_Types.LSLInteger(col.Colliders.Count) }); } - public void collision_end(uint localID, LLUUID itemID) + public void collision_end(uint localID, ColliderArgs col) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) }); + EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); + detstruct._string = new string[col.Colliders.Count]; + detstruct._Quaternion = new LSL_Types.Quaternion[col.Colliders.Count]; + detstruct._int = new int[col.Colliders.Count]; + detstruct._key = new LSL_Types.key[col.Colliders.Count]; + detstruct._Vector3 = new LSL_Types.Vector3[col.Colliders.Count]; + detstruct._Vector32 = new LSL_Types.Vector3[col.Colliders.Count]; + detstruct._bool = new bool[col.Colliders.Count]; + + int i = 0; + foreach (DetectedObject detobj in col.Colliders) + { + detstruct._key[i] = new LSL_Types.key(detobj.keyUUID.ToString()); + detstruct._Quaternion[i] = new LSL_Types.Quaternion(detobj.rotQuat.X, detobj.rotQuat.Y, detobj.rotQuat.Z, detobj.rotQuat.W); + detstruct._string[i] = detobj.nameStr; + detstruct._int[i] = detobj.colliderType; + detstruct._Vector3[i] = new LSL_Types.Vector3(detobj.posVector.X, detobj.posVector.Y, detobj.posVector.Z); + detstruct._Vector32[i] = new LSL_Types.Vector3(detobj.velVector.X, detobj.velVector.Y, detobj.velVector.Z); + detstruct._bool[i] = true; // Apparently the script engine uses this to see if this is a valid entry... + i++; + } + myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "collision_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(col.Colliders.Count) }); } public void land_collision_start(uint localID, LLUUID itemID) @@ -191,9 +260,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "land_collision_start", EventQueueManager.llDetectNull); } - public void land_collision(uint localID, LLUUID itemID) + public void land_collision(uint localID, ColliderArgs col) { - myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "land_collision", EventQueueManager.llDetectNull); + myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "land_collision", EventQueueManager.llDetectNull); } public void land_collision_end(uint localID, LLUUID itemID) diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs index 7cbbd4f..c6eebf1 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs @@ -155,7 +155,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase // should be fixed to something better :) public LSL_Types.key[] _key; public LSL_Types.Quaternion[] _Quaternion; - public LSL_Types.Vector3[] _Vector3; + public LSL_Types.Vector3[] _Vector3; // Pos + public LSL_Types.Vector3[] _Vector32; // Vel public bool[] _bool; public int[] _int; public string[] _string; diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptServerInterfaces.cs b/OpenSim/Region/ScriptEngine/Common/ScriptServerInterfaces.cs index be42539..59f828d 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptServerInterfaces.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptServerInterfaces.cs @@ -31,6 +31,7 @@ using OpenSim.Framework; using OpenSim.Region.Environment.Scenes; using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase; + namespace OpenSim.Region.ScriptEngine.Common { public class ScriptServerInterfaces @@ -43,11 +44,11 @@ namespace OpenSim.Region.ScriptEngine.Common void state_exit(uint localID); void touch(uint localID, LLUUID itemID); void touch_end(uint localID, LLUUID itemID); - void collision_start(uint localID, LLUUID itemID); - void collision(uint localID, LLUUID itemID); - void collision_end(uint localID, LLUUID itemID); + void collision_start(uint localID, ColliderArgs col); + void collision(uint localID, ColliderArgs col); + void collision_end(uint localID, ColliderArgs col); void land_collision_start(uint localID, LLUUID itemID); - void land_collision(uint localID, LLUUID itemID); + void land_collision(uint localID, ColliderArgs col); void land_collision_end(uint localID, LLUUID itemID); void timer(uint localID, LLUUID itemID); void listen(uint localID, LLUUID itemID); -- cgit v1.1