From c2863df49d3bd1f4f7c2f4c17d897d9f66b36b26 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 17 Jan 2008 02:23:48 +0000 Subject: * Added and implemented the LSL changed event. * An example changed event syntax is at: http://opensimulator.org/wiki/Changed_Event_Example * You can use this to trigger actions in your script if someone sits on your object_rez * You can use this to figure out all of the CHANGED_ constants except for CHANGED_REGION, CHANGED_TELEPORT, and CHANGED_ALLOW_DROP --- OpenSim/Region/Environment/Scenes/Scene.cs | 7 +++ OpenSim/Region/Environment/Scenes/SceneEvents.cs | 8 +++ .../Scenes/SceneObjectPart.Inventory.cs | 6 ++- .../Region/Environment/Scenes/SceneObjectPart.cs | 59 ++++++++++++++++++++-- .../Common/ScriptEngineBase/EventManager.cs | 7 +++ 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 449e1d2..3a0e1b9 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1249,6 +1249,7 @@ namespace OpenSim.Region.Environment.Scenes return avatar; } + protected void GetAvatarAppearance(IClientAPI client, out AvatarAppearance appearance) { if (m_AvatarFactory == null || @@ -2190,6 +2191,12 @@ namespace OpenSim.Region.Environment.Scenes scriptEngine.InitializeEngine(this, logger); } + public void TriggerObjectChanged(uint localID, uint change) + { + + m_eventManager.TriggerOnScriptChangedEvent(localID, change); + } + #endregion #region InnerScene wrapper methods diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs index 739f86d..4e9a258 100644 --- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs +++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs @@ -125,7 +125,15 @@ namespace OpenSim.Region.Environment.Scenes public event NewGridInstantMessage OnGridInstantMessageToGroupsModule; + public delegate void ScriptChangedEvent(uint localID, uint change); + + public event ScriptChangedEvent OnScriptChangedEvent; + public void TriggerOnScriptChangedEvent(uint localID, uint change) + { + if (OnScriptChangedEvent != null) + OnScriptChangedEvent(localID,change); + } public void TriggerOnClientMovement(ScenePresence avatar) { diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs index be2ddae..1a9e6c4 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs @@ -203,6 +203,7 @@ namespace OpenSim.Region.Environment.Scenes lock (m_taskInventory) { m_taskInventory.Add(item.ItemID, item); + TriggerScriptChangedEvent(Changed.INVENTORY); } m_inventorySerial++; @@ -220,6 +221,7 @@ namespace OpenSim.Region.Environment.Scenes foreach (TaskInventoryItem item in items) { m_taskInventory.Add(item.ItemID, item); + TriggerScriptChangedEvent(Changed.INVENTORY); } } @@ -265,7 +267,8 @@ namespace OpenSim.Region.Environment.Scenes { m_taskInventory[item.ItemID] = item; m_inventorySerial++; - + TriggerScriptChangedEvent(Changed.INVENTORY); + return true; } else @@ -295,6 +298,7 @@ namespace OpenSim.Region.Environment.Scenes int type = m_taskInventory[itemID].InvType; m_taskInventory.Remove(itemID); m_inventorySerial++; + TriggerScriptChangedEvent(Changed.INVENTORY); return type; } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 7866739..0cb4ae7 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -42,6 +42,23 @@ using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Environment.Scenes { + // I don't really know where to put this except here. + // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants + + [Flags] + public enum Changed : uint + { + INVENTORY = 1, + COLOR = 2, + SHAPE = 4, + SCALE = 8, + TEXTURE = 16, + LINK = 32, + ALLOWED_DROP = 64, + OWNER = 128 + } + + public partial class SceneObjectPart : IScriptHost { private const PermissionMask OBJFULL_MASK_GENERAL = @@ -94,7 +111,7 @@ namespace OpenSim.Region.Environment.Scenes private byte m_updateFlag; #region Properties - + public LLUUID CreatorID; public LLUUID ObjectCreator @@ -160,7 +177,7 @@ namespace OpenSim.Region.Environment.Scenes /// A Linked Child Prim objects position in world public LLVector3 GetWorldPosition() { - + Quaternion parentRot = new Quaternion( ParentGroup.RootPart.RotationOffset.W, ParentGroup.RootPart.RotationOffset.X, @@ -186,6 +203,7 @@ namespace OpenSim.Region.Environment.Scenes /// public LLQuaternion GetWorldRotation() { + Quaternion newRot; if (this.LinkNum == 0) @@ -277,6 +295,7 @@ namespace OpenSim.Region.Environment.Scenes { // Hack to get the child prim to update world positions in the physics engine ParentGroup.ResetChildPrimPhysicsPositions(); + } catch (System.NullReferenceException) { @@ -427,6 +446,8 @@ namespace OpenSim.Region.Environment.Scenes set { m_color = value; + TriggerScriptChangedEvent(Changed.COLOR); + /* ScheduleFullUpdate() need not be called b/c after * setting the color, the text will be set, so then * ScheduleFullUpdate() will be called. */ @@ -477,7 +498,12 @@ namespace OpenSim.Region.Environment.Scenes public int LinkNum { get { return m_linkNum; } - set { m_linkNum = value; } + set + { + m_linkNum = value; + TriggerScriptChangedEvent(Changed.LINK); + + } } private byte m_clickAction = 0; @@ -494,16 +520,35 @@ namespace OpenSim.Region.Environment.Scenes protected PrimitiveBaseShape m_shape; + public void TriggerScriptChangedEvent(Changed val) + { + if (m_parentGroup != null) + { + if (m_parentGroup.Scene != null) + m_parentGroup.Scene.TriggerObjectChanged(LocalID, (uint)val); + } + + } + public PrimitiveBaseShape Shape { get { return m_shape; } - set { m_shape = value; } + set + { + + m_shape = value; + TriggerScriptChangedEvent(Changed.SHAPE); + } } public LLVector3 Scale { - set { m_shape.Scale = value; } get { return m_shape.Scale; } + set + { + m_shape.Scale = value; + TriggerScriptChangedEvent(Changed.SCALE); + } } public bool Stopped @@ -692,6 +737,8 @@ namespace OpenSim.Region.Environment.Scenes { BaseMask = NextOwnerMask; OwnerMask = NextOwnerMask; + TriggerScriptChangedEvent(Changed.OWNER); + } public void ApplySanePermissions() @@ -918,6 +965,7 @@ namespace OpenSim.Region.Environment.Scenes public void SetAvatarOnSitTarget(LLUUID avatarID) { m_SitTargetAvatar = avatarID; + TriggerScriptChangedEvent(Changed.LINK); } public LLUUID GetAvatarOnSitTarget() @@ -1328,6 +1376,7 @@ namespace OpenSim.Region.Environment.Scenes public void UpdateTextureEntry(byte[] textureEntry) { m_shape.TextureEntry = textureEntry; + TriggerScriptChangedEvent(Changed.TEXTURE); ScheduleFullUpdate(); } diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs index 0a8f7ea..a32a132 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs @@ -68,10 +68,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase myScriptEngine.World.EventManager.OnObjectGrab += touch_start; myScriptEngine.World.EventManager.OnRezScript += OnRezScript; myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript; + myScriptEngine.World.EventManager.OnScriptChangedEvent += changed; // TODO: HOOK ALL EVENTS UP TO SERVER! } } + public void changed(uint localID, uint change) + { + // Add to queue for all scripts in localID, Object pass change. + myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID,"changed", new object[] {(int) change}); + } + public void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient) { // Add to queue for all scripts in ObjectID object -- cgit v1.1