aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-01-14 23:19:47 +0000
committerJustin Clark-Casey (justincc)2013-01-14 23:19:47 +0000
commit7978b349bd400d14b7ecd4f8274af1921f435fee (patch)
treec27a0a48b2437f2ffe64c4a25ca7df477a47d19f
parentImplement a workaround solution for saving manual script state changes by the... (diff)
downloadopensim-SC-7978b349bd400d14b7ecd4f8274af1921f435fee.zip
opensim-SC-7978b349bd400d14b7ecd4f8274af1921f435fee.tar.gz
opensim-SC-7978b349bd400d14b7ecd4f8274af1921f435fee.tar.bz2
opensim-SC-7978b349bd400d14b7ecd4f8274af1921f435fee.tar.xz
refactor: Simplify ScriptInstance by retaining reference to SceneObjectPart instead of sometimes but not always looking it up.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs127
1 files changed, 55 insertions, 72 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 01a5e34..f172216 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -157,19 +157,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
157 157
158 public UUID AppDomain { get; set; } 158 public UUID AppDomain { get; set; }
159 159
160 /// <summary>
161 /// Scene part in which this script instance is contained.
162 /// </summary>
163 public SceneObjectPart Part { get; private set; }
164
160 public string PrimName { get; private set; } 165 public string PrimName { get; private set; }
161 166
162 public string ScriptName { get; private set; } 167 public string ScriptName { get; private set; }
163 168
164 public UUID ItemID { get; private set; } 169 public UUID ItemID { get; private set; }
165 170
166 public UUID ObjectID { get; private set; } 171 public UUID ObjectID { get { return Part.UUID; } }
167 172
168 public uint LocalID { get; private set; } 173 public uint LocalID { get { return Part.LocalId; } }
169 174
170 public UUID RootObjectID { get; private set; } 175 public UUID RootObjectID { get { return Part.ParentGroup.UUID; } }
171 176
172 public uint RootLocalID { get; private set; } 177 public uint RootLocalID { get { return Part.ParentGroup.LocalId; } }
173 178
174 public UUID AssetID { get; private set; } 179 public UUID AssetID { get; private set; }
175 180
@@ -214,10 +219,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
214 EventQueue = new Queue(32); 219 EventQueue = new Queue(32);
215 220
216 Engine = engine; 221 Engine = engine;
217 LocalID = part.LocalId; 222 Part = part;
218 ObjectID = part.UUID;
219 RootLocalID = part.ParentGroup.LocalId;
220 RootObjectID = part.ParentGroup.UUID;
221 ItemID = itemID; 223 ItemID = itemID;
222 AssetID = assetID; 224 AssetID = assetID;
223 PrimName = primName; 225 PrimName = primName;
@@ -227,17 +229,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
227 m_MaxScriptQueue = maxScriptQueue; 229 m_MaxScriptQueue = maxScriptQueue;
228 m_stateSource = stateSource; 230 m_stateSource = stateSource;
229 m_postOnRez = postOnRez; 231 m_postOnRez = postOnRez;
230 m_AttachedAvatar = part.ParentGroup.AttachedAvatar; 232 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar;
231 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; 233 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID;
232 234
233 if (part != null) 235 lock (Part.TaskInventory)
234 { 236 {
235 lock (part.TaskInventory) 237 if (Part.TaskInventory.ContainsKey(ItemID))
236 { 238 {
237 if (part.TaskInventory.ContainsKey(ItemID)) 239 ScriptTask = Part.TaskInventory[ItemID];
238 {
239 ScriptTask = part.TaskInventory[ItemID];
240 }
241 } 240 }
242 } 241 }
243 242
@@ -322,7 +321,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
322 321
323// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName); 322// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName);
324 323
325 part.SetScriptEvents(ItemID, 324 Part.SetScriptEvents(ItemID,
326 (int)m_Script.GetStateEventFlags(State)); 325 (int)m_Script.GetStateEventFlags(State));
327 326
328 if (!Running) 327 if (!Running)
@@ -418,33 +417,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
418 PostEvent(new EventParams("attach", 417 PostEvent(new EventParams("attach",
419 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 418 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
420 } 419 }
421
422 } 420 }
423 } 421 }
424 422
425 private void ReleaseControls() 423 private void ReleaseControls()
426 { 424 {
427 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); 425 int permsMask;
428 426 UUID permsGranter;
429 if (part != null) 427 lock (Part.TaskInventory)
430 { 428 {
431 int permsMask; 429 if (!Part.TaskInventory.ContainsKey(ItemID))
432 UUID permsGranter; 430 return;
433 lock (part.TaskInventory)
434 {
435 if (!part.TaskInventory.ContainsKey(ItemID))
436 return;
437 431
438 permsGranter = part.TaskInventory[ItemID].PermsGranter; 432 permsGranter = Part.TaskInventory[ItemID].PermsGranter;
439 permsMask = part.TaskInventory[ItemID].PermsMask; 433 permsMask = Part.TaskInventory[ItemID].PermsMask;
440 } 434 }
441 435
442 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 436 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
443 { 437 {
444 ScenePresence presence = Engine.World.GetScenePresence(permsGranter); 438 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
445 if (presence != null) 439 if (presence != null)
446 presence.UnRegisterControlEventsToScript(LocalID, ItemID); 440 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
447 }
448 } 441 }
449 } 442 }
450 443
@@ -706,19 +699,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
706 m_CollisionInQueue = false; 699 m_CollisionInQueue = false;
707 } 700 }
708 701
709 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
710
711 if (DebugLevel >= 2) 702 if (DebugLevel >= 2)
712 m_log.DebugFormat( 703 m_log.DebugFormat(
713 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 704 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
714 data.EventName, 705 data.EventName,
715 ScriptName, 706 ScriptName,
716 part.Name, 707 Part.Name,
717 part.LocalId, 708 Part.LocalId,
718 part.ParentGroup.Name, 709 Part.ParentGroup.Name,
719 part.ParentGroup.UUID, 710 Part.ParentGroup.UUID,
720 part.AbsolutePosition, 711 Part.AbsolutePosition,
721 part.ParentGroup.Scene.Name); 712 Part.ParentGroup.Scene.Name);
722 713
723 m_DetectParams = data.DetectParams; 714 m_DetectParams = data.DetectParams;
724 715
@@ -731,21 +722,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
731 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 722 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
732 State, 723 State,
733 ScriptName, 724 ScriptName,
734 part.Name, 725 Part.Name,
735 part.LocalId, 726 Part.LocalId,
736 part.ParentGroup.Name, 727 Part.ParentGroup.Name,
737 part.ParentGroup.UUID, 728 Part.ParentGroup.UUID,
738 part.AbsolutePosition, 729 Part.AbsolutePosition,
739 part.ParentGroup.Scene.Name); 730 Part.ParentGroup.Scene.Name);
740 731
741 AsyncCommandManager.RemoveScript(Engine, 732 AsyncCommandManager.RemoveScript(Engine,
742 LocalID, ItemID); 733 LocalID, ItemID);
743 734
744 if (part != null) 735 Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
745 {
746 part.SetScriptEvents(ItemID,
747 (int)m_Script.GetStateEventFlags(State));
748 }
749 } 736 }
750 else 737 else
751 { 738 {
@@ -804,17 +791,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
804 text = text.Substring(0, 1000); 791 text = text.Substring(0, 1000);
805 Engine.World.SimChat(Utils.StringToBytes(text), 792 Engine.World.SimChat(Utils.StringToBytes(text),
806 ChatTypeEnum.DebugChannel, 2147483647, 793 ChatTypeEnum.DebugChannel, 2147483647,
807 part.AbsolutePosition, 794 Part.AbsolutePosition,
808 part.Name, part.UUID, false); 795 Part.Name, Part.UUID, false);
809 796
810 797
811 m_log.DebugFormat( 798 m_log.DebugFormat(
812 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", 799 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}",
813 ScriptName, 800 ScriptName,
814 PrimName, 801 PrimName,
815 part.UUID, 802 Part.UUID,
816 part.AbsolutePosition, 803 Part.AbsolutePosition,
817 part.ParentGroup.Scene.Name, 804 Part.ParentGroup.Scene.Name,
818 text.Replace("\n", "\\n"), 805 text.Replace("\n", "\\n"),
819 e.InnerException); 806 e.InnerException);
820 } 807 }
@@ -834,14 +821,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
834 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) 821 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
835 { 822 {
836 m_InSelfDelete = true; 823 m_InSelfDelete = true;
837 if (part != null) 824 Engine.World.DeleteSceneObject(Part.ParentGroup, false);
838 Engine.World.DeleteSceneObject(part.ParentGroup, false);
839 } 825 }
840 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) 826 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
841 { 827 {
842 m_InSelfDelete = true; 828 m_InSelfDelete = true;
843 if (part != null) 829 Part.Inventory.RemoveInventoryItem(ItemID);
844 part.Inventory.RemoveInventoryItem(ItemID);
845 } 830 }
846 } 831 }
847 } 832 }
@@ -888,15 +873,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
888 ReleaseControls(); 873 ReleaseControls();
889 874
890 Stop(timeout); 875 Stop(timeout);
891 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); 876 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
892 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 877 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
893 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
894 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 878 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
895 EventQueue.Clear(); 879 EventQueue.Clear();
896 m_Script.ResetVars(); 880 m_Script.ResetVars();
897 State = "default"; 881 State = "default";
898 882
899 part.SetScriptEvents(ItemID, 883 Part.SetScriptEvents(ItemID,
900 (int)m_Script.GetStateEventFlags(State)); 884 (int)m_Script.GetStateEventFlags(State));
901 if (running) 885 if (running)
902 Start(); 886 Start();
@@ -913,16 +897,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
913 ReleaseControls(); 897 ReleaseControls();
914 898
915 m_Script.ResetVars(); 899 m_Script.ResetVars();
916 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); 900 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
917 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 901 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
918 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
919 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 902 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
920 903
921 EventQueue.Clear(); 904 EventQueue.Clear();
922 m_Script.ResetVars(); 905 m_Script.ResetVars();
923 State = "default"; 906 State = "default";
924 907
925 part.SetScriptEvents(ItemID, 908 Part.SetScriptEvents(ItemID,
926 (int)m_Script.GetStateEventFlags(State)); 909 (int)m_Script.GetStateEventFlags(State));
927 910
928 if (m_CurrentEvent != "state_entry") 911 if (m_CurrentEvent != "state_entry")