aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEntityInventory.cs4
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs2
-rw-r--r--OpenSim/Region/Framework/Interfaces/ISnmpModule.cs27
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs28
-rw-r--r--OpenSim/Region/Framework/Scenes/EntityManager.cs79
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs27
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Permissions.cs29
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs68
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs29
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs36
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs26
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs640
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs133
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs727
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs593
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs11
18 files changed, 1632 insertions, 853 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
index f58904f..16ca3f9 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
@@ -73,8 +73,6 @@ namespace OpenSim.Region.Framework.Interfaces
73 /// </summary> 73 /// </summary>
74 void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource); 74 void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource);
75 75
76 ArrayList GetScriptErrors(UUID itemID);
77
78 /// <summary> 76 /// <summary>
79 /// Stop all the scripts in this entity. 77 /// Stop all the scripts in this entity.
80 /// </summary> 78 /// </summary>
@@ -104,6 +102,8 @@ namespace OpenSim.Region.Framework.Interfaces
104 /// <param name="stateSource"></param> 102 /// <param name="stateSource"></param>
105 void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource); 103 void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
106 104
105 ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
106
107 /// <summary> 107 /// <summary>
108 /// Stop a script which is in this prim's inventory. 108 /// Stop a script which is in this prim's inventory.
109 /// </summary> 109 /// </summary>
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
index 78bd622..7312799 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
@@ -103,6 +103,8 @@ namespace OpenSim.Region.Framework.Interfaces
103 103
104 void StoreRegionSettings(RegionSettings rs); 104 void StoreRegionSettings(RegionSettings rs);
105 RegionSettings LoadRegionSettings(UUID regionUUID); 105 RegionSettings LoadRegionSettings(UUID regionUUID);
106 RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID);
107 void StoreRegionWindlightSettings(RegionMeta7WindlightData wl);
106 108
107 void Shutdown(); 109 void Shutdown();
108 } 110 }
diff --git a/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs b/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs
new file mode 100644
index 0000000..e01f649
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/ISnmpModule.cs
@@ -0,0 +1,27 @@
1///////////////////////////////////////////////////////////////////
2//
3// (c) Careminster LImited, Melanie Thielker and the Meta7 Team
4//
5// This file is not open source. All rights reserved
6// Mod 2
7
8using OpenSim.Region.Framework.Scenes;
9
10public interface ISnmpModule
11{
12 void Trap(int code, string Message, Scene scene);
13 void Critical(string Message, Scene scene);
14 void Warning(string Message, Scene scene);
15 void Major(string Message, Scene scene);
16 void ColdStart(int step , Scene scene);
17 void Shutdown(int step , Scene scene);
18 //
19 // Node Start/stop events
20 //
21 void LinkUp(Scene scene);
22 void LinkDown(Scene scene);
23 void BootInfo(string data, Scene scene);
24 void trapDebug(string Module,string data, Scene scene);
25 void trapXMRE(int data, string Message, Scene scene);
26
27}
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 712dcc7..b43caf2 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -53,10 +53,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation
53 { 53 {
54 get { return m_movementAnimation; } 54 get { return m_movementAnimation; }
55 } 55 }
56 protected string m_movementAnimation = "DEFAULT"; 56 // protected string m_movementAnimation = "DEFAULT"; //KF: 'DEFAULT' does not exist!
57 57 protected string m_movementAnimation = "CROUCH"; //KF: CROUCH ensures reliable Av Anim. init.
58 private int m_animTickFall; 58 private int m_animTickFall;
59 private int m_animTickJump; 59// private int m_animTickJump;
60 public int m_animTickJump; // ScenePresence has to see this to control +Z force
60 61
61 /// <value> 62 /// <value>
62 /// The scene presence that this animator applies to 63 /// The scene presence that this animator applies to
@@ -123,8 +124,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation
123 /// </summary> 124 /// </summary>
124 public void TrySetMovementAnimation(string anim) 125 public void TrySetMovementAnimation(string anim)
125 { 126 {
126 //m_log.DebugFormat("Updating movement animation to {0}", anim);
127
128 if (!m_scenePresence.IsChildAgent) 127 if (!m_scenePresence.IsChildAgent)
129 { 128 {
130 if (m_animations.TrySetDefaultAnimation( 129 if (m_animations.TrySetDefaultAnimation(
@@ -146,10 +145,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
146 const float PREJUMP_DELAY = 0.25f; 145 const float PREJUMP_DELAY = 0.25f;
147 146
148 #region Inputs 147 #region Inputs
149 if (m_scenePresence.SitGround) 148
150 {
151 return "SIT_GROUND_CONSTRAINED";
152 }
153 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; 149 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
154 PhysicsActor actor = m_scenePresence.PhysicsActor; 150 PhysicsActor actor = m_scenePresence.PhysicsActor;
155 151
@@ -159,11 +155,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
159 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); 155 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
160 156
161 // Check control flags 157 // Check control flags
162 bool heldForward = 158 bool heldForward = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS);
163 (((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) || ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS)); 159 bool heldBack = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG);
164 bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG; 160 bool heldLeft = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS);
165 bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS; 161 bool heldRight = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG);
166 bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG;
167 //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; 162 //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
168 //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; 163 //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
169 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; 164 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
@@ -266,7 +261,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
266 m_animTickJump = Environment.TickCount; 261 m_animTickJump = Environment.TickCount;
267 return "PREJUMP"; 262 return "PREJUMP";
268 } 263 }
269 else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f) 264 else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 800.0f)
270 { 265 {
271 // Start actual jump 266 // Start actual jump
272 if (m_animTickJump == -1) 267 if (m_animTickJump == -1)
@@ -316,7 +311,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation
316 public void UpdateMovementAnimations() 311 public void UpdateMovementAnimations()
317 { 312 {
318 m_movementAnimation = GetMovementAnimation(); 313 m_movementAnimation = GetMovementAnimation();
319
320 if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump) 314 if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump)
321 { 315 {
322 // This was the previous behavior before PREJUMP 316 // This was the previous behavior before PREJUMP
@@ -451,4 +445,4 @@ namespace OpenSim.Region.Framework.Scenes.Animation
451 m_scenePresence = null; 445 m_scenePresence = null;
452 } 446 }
453 } 447 }
454} \ No newline at end of file 448}
diff --git a/OpenSim/Region/Framework/Scenes/EntityManager.cs b/OpenSim/Region/Framework/Scenes/EntityManager.cs
index 099fcce..c246e32 100644
--- a/OpenSim/Region/Framework/Scenes/EntityManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EntityManager.cs
@@ -40,7 +40,7 @@ namespace OpenSim.Region.Framework.Scenes
40 private readonly Dictionary<UUID,EntityBase> m_eb_uuid = new Dictionary<UUID, EntityBase>(); 40 private readonly Dictionary<UUID,EntityBase> m_eb_uuid = new Dictionary<UUID, EntityBase>();
41 private readonly Dictionary<uint, EntityBase> m_eb_localID = new Dictionary<uint, EntityBase>(); 41 private readonly Dictionary<uint, EntityBase> m_eb_localID = new Dictionary<uint, EntityBase>();
42 //private readonly Dictionary<UUID, ScenePresence> m_pres_uuid = new Dictionary<UUID, ScenePresence>(); 42 //private readonly Dictionary<UUID, ScenePresence> m_pres_uuid = new Dictionary<UUID, ScenePresence>();
43 private readonly Object m_lock = new Object(); 43 private System.Threading.ReaderWriterLockSlim m_lock = new System.Threading.ReaderWriterLockSlim();
44 44
45 [Obsolete("Use Add() instead.")] 45 [Obsolete("Use Add() instead.")]
46 public void Add(UUID id, EntityBase eb) 46 public void Add(UUID id, EntityBase eb)
@@ -50,7 +50,8 @@ namespace OpenSim.Region.Framework.Scenes
50 50
51 public void Add(EntityBase entity) 51 public void Add(EntityBase entity)
52 { 52 {
53 lock (m_lock) 53 m_lock.EnterWriteLock();
54 try
54 { 55 {
55 try 56 try
56 { 57 {
@@ -62,11 +63,16 @@ namespace OpenSim.Region.Framework.Scenes
62 m_log.ErrorFormat("Add Entity failed: {0}", e.Message); 63 m_log.ErrorFormat("Add Entity failed: {0}", e.Message);
63 } 64 }
64 } 65 }
66 finally
67 {
68 m_lock.ExitWriteLock();
69 }
65 } 70 }
66 71
67 public void InsertOrReplace(EntityBase entity) 72 public void InsertOrReplace(EntityBase entity)
68 { 73 {
69 lock (m_lock) 74 m_lock.EnterWriteLock();
75 try
70 { 76 {
71 try 77 try
72 { 78 {
@@ -78,15 +84,24 @@ namespace OpenSim.Region.Framework.Scenes
78 m_log.ErrorFormat("Insert or Replace Entity failed: {0}", e.Message); 84 m_log.ErrorFormat("Insert or Replace Entity failed: {0}", e.Message);
79 } 85 }
80 } 86 }
87 finally
88 {
89 m_lock.ExitWriteLock();
90 }
81 } 91 }
82 92
83 public void Clear() 93 public void Clear()
84 { 94 {
85 lock (m_lock) 95 m_lock.EnterWriteLock();
96 try
86 { 97 {
87 m_eb_uuid.Clear(); 98 m_eb_uuid.Clear();
88 m_eb_localID.Clear(); 99 m_eb_localID.Clear();
89 } 100 }
101 finally
102 {
103 m_lock.ExitWriteLock();
104 }
90 } 105 }
91 106
92 public int Count 107 public int Count
@@ -123,7 +138,8 @@ namespace OpenSim.Region.Framework.Scenes
123 138
124 public bool Remove(uint localID) 139 public bool Remove(uint localID)
125 { 140 {
126 lock (m_lock) 141 m_lock.EnterWriteLock();
142 try
127 { 143 {
128 try 144 try
129 { 145 {
@@ -141,11 +157,16 @@ namespace OpenSim.Region.Framework.Scenes
141 return false; 157 return false;
142 } 158 }
143 } 159 }
160 finally
161 {
162 m_lock.ExitWriteLock();
163 }
144 } 164 }
145 165
146 public bool Remove(UUID id) 166 public bool Remove(UUID id)
147 { 167 {
148 lock (m_lock) 168 m_lock.EnterWriteLock();
169 try
149 { 170 {
150 try 171 try
151 { 172 {
@@ -163,13 +184,18 @@ namespace OpenSim.Region.Framework.Scenes
163 return false; 184 return false;
164 } 185 }
165 } 186 }
187 finally
188 {
189 m_lock.ExitWriteLock();
190 }
166 } 191 }
167 192
168 public List<EntityBase> GetAllByType<T>() 193 public List<EntityBase> GetAllByType<T>()
169 { 194 {
170 List<EntityBase> tmp = new List<EntityBase>(); 195 List<EntityBase> tmp = new List<EntityBase>();
171 196
172 lock (m_lock) 197 m_lock.EnterReadLock();
198 try
173 { 199 {
174 try 200 try
175 { 201 {
@@ -187,23 +213,33 @@ namespace OpenSim.Region.Framework.Scenes
187 tmp = null; 213 tmp = null;
188 } 214 }
189 } 215 }
216 finally
217 {
218 m_lock.ExitReadLock();
219 }
190 220
191 return tmp; 221 return tmp;
192 } 222 }
193 223
194 public List<EntityBase> GetEntities() 224 public List<EntityBase> GetEntities()
195 { 225 {
196 lock (m_lock) 226 m_lock.EnterReadLock();
227 try
197 { 228 {
198 return new List<EntityBase>(m_eb_uuid.Values); 229 return new List<EntityBase>(m_eb_uuid.Values);
199 } 230 }
231 finally
232 {
233 m_lock.ExitReadLock();
234 }
200 } 235 }
201 236
202 public EntityBase this[UUID id] 237 public EntityBase this[UUID id]
203 { 238 {
204 get 239 get
205 { 240 {
206 lock (m_lock) 241 m_lock.EnterReadLock();
242 try
207 { 243 {
208 EntityBase entity; 244 EntityBase entity;
209 if (m_eb_uuid.TryGetValue(id, out entity)) 245 if (m_eb_uuid.TryGetValue(id, out entity))
@@ -211,6 +247,10 @@ namespace OpenSim.Region.Framework.Scenes
211 else 247 else
212 return null; 248 return null;
213 } 249 }
250 finally
251 {
252 m_lock.ExitReadLock();
253 }
214 } 254 }
215 set 255 set
216 { 256 {
@@ -222,7 +262,8 @@ namespace OpenSim.Region.Framework.Scenes
222 { 262 {
223 get 263 get
224 { 264 {
225 lock (m_lock) 265 m_lock.EnterReadLock();
266 try
226 { 267 {
227 EntityBase entity; 268 EntityBase entity;
228 if (m_eb_localID.TryGetValue(localID, out entity)) 269 if (m_eb_localID.TryGetValue(localID, out entity))
@@ -230,6 +271,10 @@ namespace OpenSim.Region.Framework.Scenes
230 else 271 else
231 return null; 272 return null;
232 } 273 }
274 finally
275 {
276 m_lock.ExitReadLock();
277 }
233 } 278 }
234 set 279 set
235 { 280 {
@@ -239,18 +284,28 @@ namespace OpenSim.Region.Framework.Scenes
239 284
240 public bool TryGetValue(UUID key, out EntityBase obj) 285 public bool TryGetValue(UUID key, out EntityBase obj)
241 { 286 {
242 lock (m_lock) 287 m_lock.EnterReadLock();
288 try
243 { 289 {
244 return m_eb_uuid.TryGetValue(key, out obj); 290 return m_eb_uuid.TryGetValue(key, out obj);
245 } 291 }
292 finally
293 {
294 m_lock.ExitReadLock();
295 }
246 } 296 }
247 297
248 public bool TryGetValue(uint key, out EntityBase obj) 298 public bool TryGetValue(uint key, out EntityBase obj)
249 { 299 {
250 lock (m_lock) 300 m_lock.EnterReadLock();
301 try
251 { 302 {
252 return m_eb_localID.TryGetValue(key, out obj); 303 return m_eb_localID.TryGetValue(key, out obj);
253 } 304 }
305 finally
306 {
307 m_lock.ExitReadLock();
308 }
254 } 309 }
255 310
256 /// <summary> 311 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 4365ece..8d2ec0f 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -203,7 +203,11 @@ namespace OpenSim.Region.Framework.Scenes
203 public event OnMakeChildAgentDelegate OnMakeChildAgent; 203 public event OnMakeChildAgentDelegate OnMakeChildAgent;
204 204
205 public delegate void OnMakeRootAgentDelegate(ScenePresence presence); 205 public delegate void OnMakeRootAgentDelegate(ScenePresence presence);
206 public delegate void OnSaveNewWindlightProfileDelegate();
207 public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionMeta7WindlightData wl, UUID user);
206 public event OnMakeRootAgentDelegate OnMakeRootAgent; 208 public event OnMakeRootAgentDelegate OnMakeRootAgent;
209 public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted;
210 public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile;
207 211
208 /// <summary> 212 /// <summary>
209 /// Triggered when an object or attachment enters a scene 213 /// Triggered when an object or attachment enters a scene
@@ -1191,6 +1195,24 @@ namespace OpenSim.Region.Framework.Scenes
1191 } 1195 }
1192 } 1196 }
1193 1197
1198 public void TriggerOnSendNewWindlightProfileTargeted(RegionMeta7WindlightData wl, UUID user)
1199 {
1200 OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted;
1201 if (handlerSendNewWindlightProfileTargeted != null)
1202 {
1203 handlerSendNewWindlightProfileTargeted(wl, user);
1204 }
1205 }
1206
1207 public void TriggerOnSaveNewWindlightProfile()
1208 {
1209 OnSaveNewWindlightProfileDelegate handlerSaveNewWindlightProfile = OnSaveNewWindlightProfile;
1210 if (handlerSaveNewWindlightProfile != null)
1211 {
1212 handlerSaveNewWindlightProfile();
1213 }
1214 }
1215
1194 public void TriggerOnMakeRootAgent(ScenePresence presence) 1216 public void TriggerOnMakeRootAgent(ScenePresence presence)
1195 { 1217 {
1196 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent; 1218 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent;
@@ -1967,4 +1989,4 @@ namespace OpenSim.Region.Framework.Scenes
1967 } 1989 }
1968 } 1990 }
1969 } 1991 }
1970} \ No newline at end of file 1992}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 79b3cfd..2aad4f0 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -271,8 +271,7 @@ namespace OpenSim.Region.Framework.Scenes
271 { 271 {
272 // Needs to determine which engine was running it and use that 272 // Needs to determine which engine was running it and use that
273 // 273 //
274 part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0); 274 errors = part.Inventory.CreateScriptInstanceEr(item.ItemID, 0, false, DefaultScriptEngine, 0);
275 errors = part.Inventory.GetScriptErrors(item.ItemID);
276 } 275 }
277 else 276 else
278 { 277 {
@@ -850,8 +849,12 @@ namespace OpenSim.Region.Framework.Scenes
850 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) 849 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
851 { 850 {
852 SceneObjectPart part = GetSceneObjectPart(localID); 851 SceneObjectPart part = GetSceneObjectPart(localID);
853 SceneObjectGroup group = part.ParentGroup; 852 SceneObjectGroup group = null;
854 if (group != null) 853 if (part != null)
854 {
855 group = part.ParentGroup;
856 }
857 if (part != null && group != null)
855 { 858 {
856 TaskInventoryItem item = group.GetInventoryItem(localID, itemID); 859 TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
857 if (item == null) 860 if (item == null)
@@ -1579,9 +1582,10 @@ namespace OpenSim.Region.Framework.Scenes
1579 if (remoteClient != null) 1582 if (remoteClient != null)
1580 { 1583 {
1581 permissionToTake = 1584 permissionToTake =
1582 Permissions.CanReturnObject( 1585 Permissions.CanReturnObjects(
1583 grp.UUID, 1586 null,
1584 remoteClient.AgentId); 1587 remoteClient.AgentId,
1588 new List<SceneObjectGroup>() {grp});
1585 permissionToDelete = permissionToTake; 1589 permissionToDelete = permissionToTake;
1586 1590
1587 if (permissionToDelete) 1591 if (permissionToDelete)
@@ -1806,8 +1810,13 @@ namespace OpenSim.Region.Framework.Scenes
1806 } 1810 }
1807 else 1811 else
1808 { 1812 {
1809 item.BasePermissions = objectGroup.GetEffectivePermissions(); 1813 uint ownerPerms = objectGroup.GetEffectivePermissions();
1810 item.CurrentPermissions = objectGroup.GetEffectivePermissions(); 1814 if ((objectGroup.RootPart.OwnerMask & (uint)PermissionMask.Modify) != 0)
1815 ownerPerms |= (uint)PermissionMask.Modify;
1816
1817 item.BasePermissions = ownerPerms;
1818 item.CurrentPermissions = ownerPerms;
1819
1811 item.NextPermissions = objectGroup.RootPart.NextOwnerMask; 1820 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1812 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask; 1821 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
1813 item.GroupPermissions = objectGroup.RootPart.GroupMask; 1822 item.GroupPermissions = objectGroup.RootPart.GroupMask;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
index d1d6b6a..7dab04f 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Region.Framework.Scenes
48 public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene); 48 public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene);
49 public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene); 49 public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene);
50 public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene); 50 public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene);
51 public delegate bool ReturnObjectHandler(UUID objectID, UUID returnerID, Scene scene); 51 public delegate bool ReturnObjectsHandler(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene);
52 public delegate bool InstantMessageHandler(UUID user, UUID target, Scene startScene); 52 public delegate bool InstantMessageHandler(UUID user, UUID target, Scene startScene);
53 public delegate bool InventoryTransferHandler(UUID user, UUID target, Scene startScene); 53 public delegate bool InventoryTransferHandler(UUID user, UUID target, Scene startScene);
54 public delegate bool ViewScriptHandler(UUID script, UUID objectID, UUID user, Scene scene); 54 public delegate bool ViewScriptHandler(UUID script, UUID objectID, UUID user, Scene scene);
@@ -81,7 +81,6 @@ namespace OpenSim.Region.Framework.Scenes
81 public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID); 81 public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID);
82 public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID); 82 public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID);
83 public delegate bool TeleportHandler(UUID userID, Scene scene); 83 public delegate bool TeleportHandler(UUID userID, Scene scene);
84 public delegate bool UseObjectReturnHandler(ILandObject landData, uint type, IClientAPI client, List<SceneObjectGroup> retlist, Scene scene);
85 #endregion 84 #endregion
86 85
87 public class ScenePermissions 86 public class ScenePermissions
@@ -107,7 +106,7 @@ namespace OpenSim.Region.Framework.Scenes
107 public event EditObjectInventoryHandler OnEditObjectInventory; 106 public event EditObjectInventoryHandler OnEditObjectInventory;
108 public event MoveObjectHandler OnMoveObject; 107 public event MoveObjectHandler OnMoveObject;
109 public event ObjectEntryHandler OnObjectEntry; 108 public event ObjectEntryHandler OnObjectEntry;
110 public event ReturnObjectHandler OnReturnObject; 109 public event ReturnObjectsHandler OnReturnObjects;
111 public event InstantMessageHandler OnInstantMessage; 110 public event InstantMessageHandler OnInstantMessage;
112 public event InventoryTransferHandler OnInventoryTransfer; 111 public event InventoryTransferHandler OnInventoryTransfer;
113 public event ViewScriptHandler OnViewScript; 112 public event ViewScriptHandler OnViewScript;
@@ -140,7 +139,6 @@ namespace OpenSim.Region.Framework.Scenes
140 public event CopyUserInventoryHandler OnCopyUserInventory; 139 public event CopyUserInventoryHandler OnCopyUserInventory;
141 public event DeleteUserInventoryHandler OnDeleteUserInventory; 140 public event DeleteUserInventoryHandler OnDeleteUserInventory;
142 public event TeleportHandler OnTeleport; 141 public event TeleportHandler OnTeleport;
143 public event UseObjectReturnHandler OnUseObjectReturn;
144 #endregion 142 #endregion
145 143
146 #region Object Permission Checks 144 #region Object Permission Checks
@@ -377,15 +375,15 @@ namespace OpenSim.Region.Framework.Scenes
377 #endregion 375 #endregion
378 376
379 #region RETURN OBJECT 377 #region RETURN OBJECT
380 public bool CanReturnObject(UUID objectID, UUID returnerID) 378 public bool CanReturnObjects(ILandObject land, UUID user, List<SceneObjectGroup> objects)
381 { 379 {
382 ReturnObjectHandler handler = OnReturnObject; 380 ReturnObjectsHandler handler = OnReturnObjects;
383 if (handler != null) 381 if (handler != null)
384 { 382 {
385 Delegate[] list = handler.GetInvocationList(); 383 Delegate[] list = handler.GetInvocationList();
386 foreach (ReturnObjectHandler h in list) 384 foreach (ReturnObjectsHandler h in list)
387 { 385 {
388 if (h(objectID, returnerID, m_scene) == false) 386 if (h(land, user, objects, m_scene) == false)
389 return false; 387 return false;
390 } 388 }
391 } 389 }
@@ -949,20 +947,5 @@ namespace OpenSim.Region.Framework.Scenes
949 } 947 }
950 return true; 948 return true;
951 } 949 }
952
953 public bool CanUseObjectReturn(ILandObject landData, uint type , IClientAPI client, List<SceneObjectGroup> retlist)
954 {
955 UseObjectReturnHandler handler = OnUseObjectReturn;
956 if (handler != null)
957 {
958 Delegate[] list = handler.GetInvocationList();
959 foreach (UseObjectReturnHandler h in list)
960 {
961 if (h(landData, type, client, retlist, m_scene) == false)
962 return false;
963 }
964 }
965 return true;
966 }
967 } 950 }
968} 951}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 62ee574..8e860fb 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -159,6 +159,20 @@ namespace OpenSim.Region.Framework.Scenes
159 159
160 public IXfer XferManager; 160 public IXfer XferManager;
161 161
162 protected ISnmpModule m_snmpService = null;
163 public ISnmpModule SnmpService
164 {
165 get
166 {
167 if (m_snmpService == null)
168 {
169 m_snmpService = RequestModuleInterface<ISnmpModule>();
170 }
171
172 return m_snmpService;
173 }
174 }
175
162 protected IAssetService m_AssetService; 176 protected IAssetService m_AssetService;
163 protected IAuthorizationService m_AuthorizationService; 177 protected IAuthorizationService m_AuthorizationService;
164 178
@@ -540,6 +554,8 @@ namespace OpenSim.Region.Framework.Scenes
540 554
541 // Load region settings 555 // Load region settings
542 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); 556 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID);
557 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(m_regInfo.RegionID);
558
543 if (m_storageManager.EstateDataStore != null) 559 if (m_storageManager.EstateDataStore != null)
544 { 560 {
545 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 561 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID);
@@ -598,7 +614,7 @@ namespace OpenSim.Region.Framework.Scenes
598 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 614 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
599 // TODO: Change default to true once the feature is supported 615 // TODO: Change default to true once the feature is supported
600 m_usePreJump = startupConfig.GetBoolean("enableprejump", false); 616 m_usePreJump = startupConfig.GetBoolean("enableprejump", false);
601 617 m_usePreJump = true; // Above line fails!?
602 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 618 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
603 if (RegionInfo.NonphysPrimMax > 0) 619 if (RegionInfo.NonphysPrimMax > 0)
604 { 620 {
@@ -887,6 +903,15 @@ namespace OpenSim.Region.Framework.Scenes
887 /// <param name="seconds">float indicating duration before restart.</param> 903 /// <param name="seconds">float indicating duration before restart.</param>
888 public virtual void Restart(float seconds) 904 public virtual void Restart(float seconds)
889 { 905 {
906 Restart(seconds, true);
907 }
908
909 /// <summary>
910 /// Given float seconds, this will restart the region. showDialog will optionally alert the users.
911 /// </summary>
912 /// <param name="seconds">float indicating duration before restart.</param>
913 public virtual void Restart(float seconds, bool showDialog)
914 {
890 // notifications are done in 15 second increments 915 // notifications are done in 15 second increments
891 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request 916 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request
892 // It's a 'Cancel restart' request. 917 // It's a 'Cancel restart' request.
@@ -907,8 +932,11 @@ namespace OpenSim.Region.Framework.Scenes
907 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); 932 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed);
908 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); 933 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes");
909 m_restartTimer.Start(); 934 m_restartTimer.Start();
910 m_dialogModule.SendNotificationToUsersInRegion( 935 if (showDialog)
936 {
937 m_dialogModule.SendNotificationToUsersInRegion(
911 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); 938 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0)));
939 }
912 } 940 }
913 } 941 }
914 942
@@ -1190,16 +1218,16 @@ namespace OpenSim.Region.Framework.Scenes
1190 // Check if any objects have reached their targets 1218 // Check if any objects have reached their targets
1191 CheckAtTargets(); 1219 CheckAtTargets();
1192 1220
1193 // Update SceneObjectGroups that have scheduled themselves for updates
1194 // Objects queue their updates onto all scene presences
1195 if (m_frame % m_update_objects == 0)
1196 m_sceneGraph.UpdateObjectGroups();
1197
1198 // Run through all ScenePresences looking for updates 1221 // Run through all ScenePresences looking for updates
1199 // Presence updates and queued object updates for each presence are sent to clients 1222 // Presence updates and queued object updates for each presence are sent to clients
1200 if (m_frame % m_update_presences == 0) 1223 if (m_frame % m_update_presences == 0)
1201 m_sceneGraph.UpdatePresences(); 1224 m_sceneGraph.UpdatePresences();
1202 1225
1226 // Update SceneObjectGroups that have scheduled themselves for updates
1227 // Objects queue their updates onto all scene presences
1228 if (m_frame % m_update_objects == 0)
1229 m_sceneGraph.UpdateObjectGroups();
1230
1203 int tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1231 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1204 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1232 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1205 m_sceneGraph.UpdatePreparePhysics(); 1233 m_sceneGraph.UpdatePreparePhysics();
@@ -1512,6 +1540,19 @@ namespace OpenSim.Region.Framework.Scenes
1512 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1540 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1513 } 1541 }
1514 1542
1543 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1544 {
1545 m_regInfo.WindlightSettings = wl;
1546 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
1547 m_eventManager.TriggerOnSaveNewWindlightProfile();
1548 }
1549
1550 public void LoadWindlightProfile()
1551 {
1552 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1553 m_eventManager.TriggerOnSaveNewWindlightProfile();
1554 }
1555
1515 /// <summary> 1556 /// <summary>
1516 /// Loads the World heightmap 1557 /// Loads the World heightmap
1517 /// </summary> 1558 /// </summary>
@@ -3488,6 +3529,9 @@ namespace OpenSim.Region.Framework.Scenes
3488 3529
3489 CapsModule.AddCapsHandler(agent.AgentID); 3530 CapsModule.AddCapsHandler(agent.AgentID);
3490 3531
3532 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3533 System.Threading.Thread.Sleep(2000);
3534
3491 if (!agent.child) 3535 if (!agent.child)
3492 { 3536 {
3493 if (TestBorderCross(agent.startpos,Cardinals.E)) 3537 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3546,6 +3590,7 @@ namespace OpenSim.Region.Framework.Scenes
3546 } 3590 }
3547 } 3591 }
3548 // Honor parcel landing type and position. 3592 // Honor parcel landing type and position.
3593 /*
3549 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 3594 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3550 if (land != null) 3595 if (land != null)
3551 { 3596 {
@@ -3554,6 +3599,7 @@ namespace OpenSim.Region.Framework.Scenes
3554 agent.startpos = land.LandData.UserLocation; 3599 agent.startpos = land.LandData.UserLocation;
3555 } 3600 }
3556 } 3601 }
3602 */// This is now handled properly in ScenePresence.MakeRootAgent
3557 } 3603 }
3558 3604
3559 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3605 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
@@ -4369,6 +4415,14 @@ namespace OpenSim.Region.Framework.Scenes
4369 } 4415 }
4370 4416
4371 /// <summary> 4417 /// <summary>
4418 /// Cheaply return the number of avatars in a region (without fetching a list object)
4419 /// </summary>
4420 public int GetRootAgentCount()
4421 {
4422 return m_sceneGraph.GetRootAgentCount();
4423 }
4424
4425 /// <summary>
4372 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents. 4426 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents.
4373 /// This list is a new object, so it can be iterated over without locking. 4427 /// This list is a new object, so it can be iterated over without locking.
4374 /// </summary> 4428 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 67fa13d..1ba1953 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -711,6 +711,33 @@ namespace OpenSim.Region.Framework.Scenes
711 position = emergencyPos; 711 position = emergencyPos;
712 } 712 }
713 713
714 Vector3 currentPos = avatar.AbsolutePosition;
715 ILandObject srcLand = m_scene.LandChannel.GetLandObject(currentPos.X, currentPos.Y);
716 ILandObject destLand = m_scene.LandChannel.GetLandObject(position.X, position.Y);
717 if (srcLand != null && destLand != null && (teleportFlags & (uint)TeleportFlags.ViaLure) == 0 && (teleportFlags & (uint)TeleportFlags.ViaGodlikeLure) == 0)
718 {
719 if (srcLand.LandData.LocalID == destLand.LandData.LocalID)
720 {
721 //TPing within the same parcel. If the landing point is restricted, block the TP.
722 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
723 if (destLand.LandData.LandingType == (byte)1 && destLand.LandData.UserLocation != Vector3.Zero && avatar.GodLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar.UUID) && destLand.LandData.OwnerID != avatar.UUID)
724 {
725 //Disabling this behaviour for now pending review. ~CasperW
726
727 //avatar.ControllingClient.SendAgentAlertMessage("Can't TP to the destination; landing point set.", false);
728 //position = currentPos;
729 }
730 }
731 else
732 {
733 //Tping to a different parcel. Respect the landing point on the destination parcel.
734 if (destLand.LandData.LandingType == (byte)1 && destLand.LandData.UserLocation != Vector3.Zero && avatar.GodLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar.UUID) && destLand.LandData.OwnerID != avatar.UUID)
735 {
736 position = destLand.LandData.UserLocation;
737 }
738 }
739 }
740
714 // TODO: Get proper AVG Height 741 // TODO: Get proper AVG Height
715 float localAVHeight = 1.56f; 742 float localAVHeight = 1.56f;
716 float posZLimit = 22; 743 float posZLimit = 22;
@@ -1005,7 +1032,7 @@ namespace OpenSim.Region.Framework.Scenes
1005 1032
1006 public bool WaitForCallback(UUID id) 1033 public bool WaitForCallback(UUID id)
1007 { 1034 {
1008 int count = 200; 1035 int count = 400;
1009 while (m_agentsInTransit.Contains(id) && count-- > 0) 1036 while (m_agentsInTransit.Contains(id) && count-- > 0)
1010 { 1037 {
1011 //m_log.Debug(" >>> Waiting... " + count); 1038 //m_log.Debug(" >>> Waiting... " + count);
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index bdab696..5a1922a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -226,6 +226,30 @@ namespace OpenSim.Region.Framework.Scenes
226 protected internal bool AddRestoredSceneObject( 226 protected internal bool AddRestoredSceneObject(
227 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) 227 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
228 { 228 {
229 // KF: Check for out-of-region, move inside and make static.
230 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
231 sceneObject.RootPart.GroupPosition.Y,
232 sceneObject.RootPart.GroupPosition.Z);
233 if (!(((sceneObject.RootPart.Shape.PCode == (byte)PCode.Prim) && (sceneObject.RootPart.Shape.State != 0))) && (npos.X < 0.0 || npos.Y < 0.0 || npos.Z < 0.0 ||
234 npos.X > Constants.RegionSize ||
235 npos.Y > Constants.RegionSize))
236 {
237 if (npos.X < 0.0) npos.X = 1.0f;
238 if (npos.Y < 0.0) npos.Y = 1.0f;
239 if (npos.Z < 0.0) npos.Z = 0.0f;
240 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
241 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
242
243 foreach (SceneObjectPart part in sceneObject.Children.Values)
244 {
245 part.GroupPosition = npos;
246 }
247 sceneObject.RootPart.Velocity = Vector3.Zero;
248 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
249 sceneObject.RootPart.Acceleration = Vector3.Zero;
250 sceneObject.RootPart.Velocity = Vector3.Zero;
251 }
252
229 if (!alreadyPersisted) 253 if (!alreadyPersisted)
230 { 254 {
231 sceneObject.ForceInventoryPersistence(); 255 sceneObject.ForceInventoryPersistence();
@@ -611,6 +635,18 @@ namespace OpenSim.Region.Framework.Scenes
611 if (group.GetFromItemID() == itemID) 635 if (group.GetFromItemID() == itemID)
612 { 636 {
613 m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero); 637 m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero);
638 bool hasScripts = false;
639 foreach (SceneObjectPart part in group.Children.Values)
640 {
641 if (part.Inventory.ContainsScripts())
642 {
643 hasScripts = true;
644 break;
645 }
646 }
647
648 if (hasScripts) // Allow the object to execute the attach(NULL_KEY) event
649 System.Threading.Thread.Sleep(100);
614 group.DetachToInventoryPrep(); 650 group.DetachToInventoryPrep();
615 m_log.Debug("[DETACH]: Saving attachpoint: " + 651 m_log.Debug("[DETACH]: Saving attachpoint: " +
616 ((uint)group.GetAttachmentPoint()).ToString()); 652 ((uint)group.GetAttachmentPoint()).ToString());
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
index 4034744..8b65445 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs
@@ -46,12 +46,12 @@ namespace OpenSim.Region.Framework.Scenes
46 /// </summary> 46 /// </summary>
47 public void ForceInventoryPersistence() 47 public void ForceInventoryPersistence()
48 { 48 {
49 lock (m_parts) 49 lockPartsForRead(true);
50 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
51 lockPartsForRead(false);
52 foreach (SceneObjectPart part in values)
50 { 53 {
51 foreach (SceneObjectPart part in m_parts.Values) 54 part.Inventory.ForceInventoryPersistence();
52 {
53 part.Inventory.ForceInventoryPersistence();
54 }
55 } 55 }
56 } 56 }
57 57
@@ -74,19 +74,17 @@ namespace OpenSim.Region.Framework.Scenes
74 /// <summary> 74 /// <summary>
75 /// Stop the scripts contained in all the prims in this group 75 /// Stop the scripts contained in all the prims in this group
76 /// </summary> 76 /// </summary>
77 /// <param name="sceneObjectBeingDeleted">
78 /// Should be true if these scripts are being removed because the scene
79 /// object is being deleted. This will prevent spurious updates to the client.
80 /// </param>
81 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 77 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
82 { 78 {
83 lock (m_parts) 79 lockPartsForRead(true);
80 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
81 lockPartsForRead(false);
82
83 foreach (SceneObjectPart part in values)
84 { 84 {
85 foreach (SceneObjectPart part in m_parts.Values) 85 part.Inventory.RemoveScriptInstances(sceneObjectBeingDeleted);
86 {
87 part.Inventory.RemoveScriptInstances(sceneObjectBeingDeleted);
88 }
89 } 86 }
87
90 } 88 }
91 89
92 /// <summary> 90 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index aa41354..54b27b2 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -104,8 +104,78 @@ namespace OpenSim.Region.Framework.Scenes
104 /// since the group's last persistent backup 104 /// since the group's last persistent backup
105 /// </summary> 105 /// </summary>
106 private bool m_hasGroupChanged = false; 106 private bool m_hasGroupChanged = false;
107 private long timeFirstChanged; 107 private long timeFirstChanged = 0;
108 private long timeLastChanged; 108 private long timeLastChanged = 0;
109 private long m_maxPersistTime = 0;
110 private long m_minPersistTime = 0;
111 private Random m_rand;
112
113 private System.Threading.ReaderWriterLockSlim m_partsLock = new System.Threading.ReaderWriterLockSlim();
114
115 public void lockPartsForRead(bool locked)
116 {
117 if (locked)
118 {
119 if (m_partsLock.RecursiveReadCount > 0)
120 {
121 m_log.Error("[SceneObjectGroup.m_parts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
122 m_partsLock.ExitReadLock();
123 }
124 if (m_partsLock.RecursiveWriteCount > 0)
125 {
126 m_log.Error("[SceneObjectGroup.m_parts] Recursive read lock requested. This should not happen and means something needs to be fixed.");
127 m_partsLock.ExitWriteLock();
128 }
129
130 while (!m_partsLock.TryEnterReadLock(60000))
131 {
132 m_log.Error("[SceneObjectGroup.m_parts] Thread lock detected while trying to aquire READ lock of m_parts in SceneObjectGroup. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
133 if (m_partsLock.IsWriteLockHeld)
134 {
135 m_partsLock = new System.Threading.ReaderWriterLockSlim();
136 }
137 }
138 }
139 else
140 {
141 if (m_partsLock.RecursiveReadCount > 0)
142 {
143 m_partsLock.ExitReadLock();
144 }
145 }
146 }
147 public void lockPartsForWrite(bool locked)
148 {
149 if (locked)
150 {
151 if (m_partsLock.RecursiveReadCount > 0)
152 {
153 m_log.Error("[SceneObjectGroup.m_parts] Recursive write lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
154 m_partsLock.ExitReadLock();
155 }
156 if (m_partsLock.RecursiveWriteCount > 0)
157 {
158 m_log.Error("[SceneObjectGroup.m_parts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
159 m_partsLock.ExitWriteLock();
160 }
161
162 while (!m_partsLock.TryEnterWriteLock(60000))
163 {
164 m_log.Error("[SceneObjectGroup.m_parts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
165 if (m_partsLock.IsWriteLockHeld)
166 {
167 m_partsLock = new System.Threading.ReaderWriterLockSlim();
168 }
169 }
170 }
171 else
172 {
173 if (m_partsLock.RecursiveWriteCount > 0)
174 {
175 m_partsLock.ExitWriteLock();
176 }
177 }
178 }
109 179
110 public bool HasGroupChanged 180 public bool HasGroupChanged
111 { 181 {
@@ -116,6 +186,32 @@ namespace OpenSim.Region.Framework.Scenes
116 timeLastChanged = DateTime.Now.Ticks; 186 timeLastChanged = DateTime.Now.Ticks;
117 if (!m_hasGroupChanged) 187 if (!m_hasGroupChanged)
118 timeFirstChanged = DateTime.Now.Ticks; 188 timeFirstChanged = DateTime.Now.Ticks;
189 if (m_rootPart != null && m_rootPart.UUID != null && m_scene != null)
190 {
191 if (m_rand == null)
192 {
193 byte[] val = new byte[16];
194 m_rootPart.UUID.ToBytes(val, 0);
195 m_rand = new Random(BitConverter.ToInt32(val, 0));
196 }
197
198 if (m_scene.GetRootAgentCount() == 0)
199 {
200 //If the region is empty, this change has been made by an automated process
201 //and thus we delay the persist time by a random amount between 1.5 and 2.5.
202
203 float factor = 1.5f + (float)(m_rand.NextDouble());
204 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor);
205 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor);
206 }
207 else
208 {
209 //If the region is not empty, we want to obey the minimum and maximum persist times
210 //but add a random factor so we stagger the object persistance a little
211 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
212 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
213 }
214 }
119 } 215 }
120 m_hasGroupChanged = value; 216 m_hasGroupChanged = value;
121 } 217 }
@@ -131,8 +227,19 @@ namespace OpenSim.Region.Framework.Scenes
131 return false; 227 return false;
132 if (m_scene.ShuttingDown) 228 if (m_scene.ShuttingDown)
133 return true; 229 return true;
230
231 if (m_minPersistTime == 0 || m_maxPersistTime == 0)
232 {
233 m_maxPersistTime = m_scene.m_persistAfter;
234 m_minPersistTime = m_scene.m_dontPersistBefore;
235 }
236
134 long currentTime = DateTime.Now.Ticks; 237 long currentTime = DateTime.Now.Ticks;
135 if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) 238
239 if (timeLastChanged == 0) timeLastChanged = currentTime;
240 if (timeFirstChanged == 0) timeFirstChanged = currentTime;
241
242 if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
136 return true; 243 return true;
137 return false; 244 return false;
138 } 245 }
@@ -258,13 +365,16 @@ namespace OpenSim.Region.Framework.Scenes
258 set 365 set
259 { 366 {
260 m_regionHandle = value; 367 m_regionHandle = value;
261 lock (m_parts) 368 lockPartsForRead(true);
262 { 369 {
263 foreach (SceneObjectPart part in m_parts.Values) 370 foreach (SceneObjectPart part in m_parts.Values)
264 { 371 {
372
265 part.RegionHandle = m_regionHandle; 373 part.RegionHandle = m_regionHandle;
374
266 } 375 }
267 } 376 }
377 lockPartsForRead(false);
268 } 378 }
269 } 379 }
270 380
@@ -298,6 +408,9 @@ namespace OpenSim.Region.Framework.Scenes
298 { 408 {
299 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 409 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
300 } 410 }
411
412 lockPartsForRead(true);
413
301 if (RootPart.GetStatusSandbox()) 414 if (RootPart.GetStatusSandbox())
302 { 415 {
303 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) 416 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
@@ -308,14 +421,14 @@ namespace OpenSim.Region.Framework.Scenes
308 return; 421 return;
309 } 422 }
310 } 423 }
311 lock (m_parts) 424
425 foreach (SceneObjectPart part in m_parts.Values)
312 { 426 {
313 foreach (SceneObjectPart part in m_parts.Values) 427 part.GroupPosition = val;
314 {
315 part.GroupPosition = val;
316 }
317 } 428 }
318 429
430 lockPartsForRead(false);
431
319 //if (m_rootPart.PhysActor != null) 432 //if (m_rootPart.PhysActor != null)
320 //{ 433 //{
321 //m_rootPart.PhysActor.Position = 434 //m_rootPart.PhysActor.Position =
@@ -457,6 +570,7 @@ namespace OpenSim.Region.Framework.Scenes
457 /// </summary> 570 /// </summary>
458 public SceneObjectGroup() 571 public SceneObjectGroup()
459 { 572 {
573
460 } 574 }
461 575
462 /// <summary> 576 /// <summary>
@@ -473,7 +587,7 @@ namespace OpenSim.Region.Framework.Scenes
473 /// Constructor. This object is added to the scene later via AttachToScene() 587 /// Constructor. This object is added to the scene later via AttachToScene()
474 /// </summary> 588 /// </summary>
475 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) 589 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
476 { 590 {
477 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); 591 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
478 } 592 }
479 593
@@ -504,13 +618,16 @@ namespace OpenSim.Region.Framework.Scenes
504 618
505 public void SetFromItemID(UUID AssetId) 619 public void SetFromItemID(UUID AssetId)
506 { 620 {
507 lock (m_parts) 621 lockPartsForRead(true);
508 { 622 {
509 foreach (SceneObjectPart part in m_parts.Values) 623 foreach (SceneObjectPart part in m_parts.Values)
510 { 624 {
625
511 part.FromItemID = AssetId; 626 part.FromItemID = AssetId;
627
512 } 628 }
513 } 629 }
630 lockPartsForRead(false);
514 } 631 }
515 632
516 public UUID GetFromItemID() 633 public UUID GetFromItemID()
@@ -579,10 +696,11 @@ namespace OpenSim.Region.Framework.Scenes
579 Vector3 maxScale = Vector3.Zero; 696 Vector3 maxScale = Vector3.Zero;
580 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); 697 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
581 698
582 lock (m_parts) 699 lockPartsForRead(true);
583 { 700 {
584 foreach (SceneObjectPart part in m_parts.Values) 701 foreach (SceneObjectPart part in m_parts.Values)
585 { 702 {
703
586 Vector3 partscale = part.Scale; 704 Vector3 partscale = part.Scale;
587 Vector3 partoffset = part.OffsetPosition; 705 Vector3 partoffset = part.OffsetPosition;
588 706
@@ -593,8 +711,11 @@ namespace OpenSim.Region.Framework.Scenes
593 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X; 711 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X;
594 maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y; 712 maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y;
595 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z; 713 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
714
596 } 715 }
597 } 716 }
717 lockPartsForRead(false);
718
598 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; 719 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
599 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; 720 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
600 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; 721 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
@@ -610,10 +731,11 @@ namespace OpenSim.Region.Framework.Scenes
610 731
611 EntityIntersection result = new EntityIntersection(); 732 EntityIntersection result = new EntityIntersection();
612 733
613 lock (m_parts) 734 lockPartsForRead(true);
614 { 735 {
615 foreach (SceneObjectPart part in m_parts.Values) 736 foreach (SceneObjectPart part in m_parts.Values)
616 { 737 {
738
617 // Temporary commented to stop compiler warning 739 // Temporary commented to stop compiler warning
618 //Vector3 partPosition = 740 //Vector3 partPosition =
619 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); 741 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
@@ -641,8 +763,10 @@ namespace OpenSim.Region.Framework.Scenes
641 result.distance = inter.distance; 763 result.distance = inter.distance;
642 } 764 }
643 } 765 }
766
644 } 767 }
645 } 768 }
769 lockPartsForRead(false);
646 return result; 770 return result;
647 } 771 }
648 772
@@ -655,10 +779,11 @@ namespace OpenSim.Region.Framework.Scenes
655 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) 779 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
656 { 780 {
657 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f; 781 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f;
658 lock (m_parts) 782 lockPartsForRead(true);
659 { 783 {
660 foreach (SceneObjectPart part in m_parts.Values) 784 foreach (SceneObjectPart part in m_parts.Values)
661 { 785 {
786
662 Vector3 worldPos = part.GetWorldPosition(); 787 Vector3 worldPos = part.GetWorldPosition();
663 Vector3 offset = worldPos - AbsolutePosition; 788 Vector3 offset = worldPos - AbsolutePosition;
664 Quaternion worldRot; 789 Quaternion worldRot;
@@ -717,6 +842,8 @@ namespace OpenSim.Region.Framework.Scenes
717 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 842 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
718 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 843 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
719 844
845
846
720 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); 847 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
721 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z); 848 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
722 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z); 849 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
@@ -888,6 +1015,7 @@ namespace OpenSim.Region.Framework.Scenes
888 minZ = backBottomLeft.Z; 1015 minZ = backBottomLeft.Z;
889 } 1016 }
890 } 1017 }
1018 lockPartsForRead(false);
891 1019
892 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); 1020 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
893 1021
@@ -916,17 +1044,20 @@ namespace OpenSim.Region.Framework.Scenes
916 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1044 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
917 1045
918 // Capture script state while holding the lock 1046 // Capture script state while holding the lock
919 lock (m_parts) 1047 lockPartsForRead(true);
920 { 1048 {
921 foreach (SceneObjectPart part in m_parts.Values) 1049 foreach (SceneObjectPart part in m_parts.Values)
922 { 1050 {
1051
923 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); 1052 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates();
924 foreach (UUID itemid in pstates.Keys) 1053 foreach (UUID itemid in pstates.Keys)
925 { 1054 {
926 states.Add(itemid, pstates[itemid]); 1055 states.Add(itemid, pstates[itemid]);
927 } 1056 }
1057
928 } 1058 }
929 } 1059 }
1060 lockPartsForRead(false);
930 1061
931 if (states.Count > 0) 1062 if (states.Count > 0)
932 { 1063 {
@@ -1094,13 +1225,16 @@ namespace OpenSim.Region.Framework.Scenes
1094 1225
1095 public override void UpdateMovement() 1226 public override void UpdateMovement()
1096 { 1227 {
1097 lock (m_parts) 1228 lockPartsForRead(true);
1098 { 1229 {
1099 foreach (SceneObjectPart part in m_parts.Values) 1230 foreach (SceneObjectPart part in m_parts.Values)
1100 { 1231 {
1232
1101 part.UpdateMovement(); 1233 part.UpdateMovement();
1234
1102 } 1235 }
1103 } 1236 }
1237 lockPartsForRead(false);
1104 } 1238 }
1105 1239
1106 public ushort GetTimeDilation() 1240 public ushort GetTimeDilation()
@@ -1144,7 +1278,7 @@ namespace OpenSim.Region.Framework.Scenes
1144 /// <param name="part"></param> 1278 /// <param name="part"></param>
1145 public void AddPart(SceneObjectPart part) 1279 public void AddPart(SceneObjectPart part)
1146 { 1280 {
1147 lock (m_parts) 1281 lockPartsForWrite(true);
1148 { 1282 {
1149 part.SetParent(this); 1283 part.SetParent(this);
1150 m_parts.Add(part.UUID, part); 1284 m_parts.Add(part.UUID, part);
@@ -1154,6 +1288,7 @@ namespace OpenSim.Region.Framework.Scenes
1154 if (part.LinkNum == 2 && RootPart != null) 1288 if (part.LinkNum == 2 && RootPart != null)
1155 RootPart.LinkNum = 1; 1289 RootPart.LinkNum = 1;
1156 } 1290 }
1291 lockPartsForWrite(false);
1157 } 1292 }
1158 1293
1159 /// <summary> 1294 /// <summary>
@@ -1161,28 +1296,33 @@ namespace OpenSim.Region.Framework.Scenes
1161 /// </summary> 1296 /// </summary>
1162 private void UpdateParentIDs() 1297 private void UpdateParentIDs()
1163 { 1298 {
1164 lock (m_parts) 1299 lockPartsForRead(true);
1165 { 1300 {
1166 foreach (SceneObjectPart part in m_parts.Values) 1301 foreach (SceneObjectPart part in m_parts.Values)
1167 { 1302 {
1303
1168 if (part.UUID != m_rootPart.UUID) 1304 if (part.UUID != m_rootPart.UUID)
1169 { 1305 {
1170 part.ParentID = m_rootPart.LocalId; 1306 part.ParentID = m_rootPart.LocalId;
1171 } 1307 }
1308
1172 } 1309 }
1173 } 1310 }
1311 lockPartsForRead(false);
1174 } 1312 }
1175 1313
1176 public void RegenerateFullIDs() 1314 public void RegenerateFullIDs()
1177 { 1315 {
1178 lock (m_parts) 1316 lockPartsForRead(true);
1179 { 1317 {
1180 foreach (SceneObjectPart part in m_parts.Values) 1318 foreach (SceneObjectPart part in m_parts.Values)
1181 { 1319 {
1320
1182 part.UUID = UUID.Random(); 1321 part.UUID = UUID.Random();
1183 1322
1184 } 1323 }
1185 } 1324 }
1325 lockPartsForRead(false);
1186 } 1326 }
1187 1327
1188 // helper provided for parts. 1328 // helper provided for parts.
@@ -1263,29 +1403,33 @@ namespace OpenSim.Region.Framework.Scenes
1263 1403
1264 DetachFromBackup(); 1404 DetachFromBackup();
1265 1405
1266 lock (m_parts) 1406 lockPartsForRead(true);
1407 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1408 lockPartsForRead(false);
1409
1410 foreach (SceneObjectPart part in values)
1267 { 1411 {
1268 foreach (SceneObjectPart part in m_parts.Values)
1269 {
1270// part.Inventory.RemoveScriptInstances(); 1412// part.Inventory.RemoveScriptInstances();
1271 1413
1272 ScenePresence[] avatars = Scene.GetScenePresences(); 1414 ScenePresence[] avatars = Scene.GetScenePresences();
1273 for (int i = 0; i < avatars.Length; i++) 1415 for (int i = 0; i < avatars.Length; i++)
1416 {
1417 if (avatars[i].ParentID == LocalId)
1274 { 1418 {
1275 if (avatars[i].ParentID == LocalId) 1419 avatars[i].StandUp();
1276 { 1420 }
1277 avatars[i].StandUp();
1278 }
1279 1421
1280 if (!silent) 1422 if (!silent)
1281 { 1423 {
1282 part.UpdateFlag = 0; 1424 part.UpdateFlag = 0;
1283 if (part == m_rootPart) 1425 if (part == m_rootPart)
1284 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1426 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1285 }
1286 } 1427 }
1287 } 1428 }
1429
1288 } 1430 }
1431
1432
1289 } 1433 }
1290 1434
1291 public void AddScriptLPS(int count) 1435 public void AddScriptLPS(int count)
@@ -1310,17 +1454,20 @@ namespace OpenSim.Region.Framework.Scenes
1310 1454
1311 scriptEvents aggregateScriptEvents=0; 1455 scriptEvents aggregateScriptEvents=0;
1312 1456
1313 lock (m_parts) 1457 lockPartsForRead(true);
1314 { 1458 {
1315 foreach (SceneObjectPart part in m_parts.Values) 1459 foreach (SceneObjectPart part in m_parts.Values)
1316 { 1460 {
1461
1317 if (part == null) 1462 if (part == null)
1318 continue; 1463 continue;
1319 if (part != RootPart) 1464 if (part != RootPart)
1320 part.ObjectFlags = objectflagupdate; 1465 part.ObjectFlags = objectflagupdate;
1321 aggregateScriptEvents |= part.AggregateScriptEvents; 1466 aggregateScriptEvents |= part.AggregateScriptEvents;
1467
1322 } 1468 }
1323 } 1469 }
1470 lockPartsForRead(false);
1324 1471
1325 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); 1472 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
1326 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); 1473 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
@@ -1362,42 +1509,52 @@ namespace OpenSim.Region.Framework.Scenes
1362 /// <param name="m_physicalPrim"></param> 1509 /// <param name="m_physicalPrim"></param>
1363 public void ApplyPhysics(bool m_physicalPrim) 1510 public void ApplyPhysics(bool m_physicalPrim)
1364 { 1511 {
1365 lock (m_parts) 1512 lockPartsForRead(true);
1513
1514 if (m_parts.Count > 1)
1366 { 1515 {
1367 if (m_parts.Count > 1) 1516 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1517 lockPartsForRead(false);
1518 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1519 foreach (SceneObjectPart part in values)
1368 { 1520 {
1369 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); 1521
1370 foreach (SceneObjectPart part in m_parts.Values) 1522 if (part.LocalId != m_rootPart.LocalId)
1371 { 1523 {
1372 if (part.LocalId != m_rootPart.LocalId) 1524 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1373 {
1374 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1375 }
1376 } 1525 }
1377 1526
1378 // Hack to get the physics scene geometries in the right spot
1379 ResetChildPrimPhysicsPositions();
1380 }
1381 else
1382 {
1383 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1384 } 1527 }
1528 // Hack to get the physics scene geometries in the right spot
1529 ResetChildPrimPhysicsPositions();
1530 }
1531 else
1532 {
1533 lockPartsForRead(false);
1534 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1385 } 1535 }
1386 } 1536 }
1387 1537
1388 public void SetOwnerId(UUID userId) 1538 public void SetOwnerId(UUID userId)
1389 { 1539 {
1390 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1540 ForEachPart(delegate(SceneObjectPart part)
1541 {
1542
1543 part.OwnerID = userId;
1544
1545 });
1391 } 1546 }
1392 1547
1393 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1548 public void ForEachPart(Action<SceneObjectPart> whatToDo)
1394 { 1549 {
1395 lock (m_parts) 1550 lockPartsForRead(true);
1551 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1552 lockPartsForRead(false);
1553 foreach (SceneObjectPart part in values)
1396 { 1554 {
1397 foreach (SceneObjectPart part in m_parts.Values) 1555
1398 { 1556 whatToDo(part);
1399 whatToDo(part); 1557
1400 }
1401 } 1558 }
1402 } 1559 }
1403 1560
@@ -1500,14 +1657,17 @@ namespace OpenSim.Region.Framework.Scenes
1500 1657
1501 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1658 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1502 1659
1503 lock (m_parts) 1660 lockPartsForRead(true);
1504 { 1661 {
1505 foreach (SceneObjectPart part in m_parts.Values) 1662 foreach (SceneObjectPart part in m_parts.Values)
1506 { 1663 {
1664
1507 if (part != RootPart) 1665 if (part != RootPart)
1508 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1666 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
1667
1509 } 1668 }
1510 } 1669 }
1670 lockPartsForRead(false);
1511 } 1671 }
1512 1672
1513 /// <summary> 1673 /// <summary>
@@ -1606,10 +1766,11 @@ namespace OpenSim.Region.Framework.Scenes
1606 1766
1607 List<SceneObjectPart> partList; 1767 List<SceneObjectPart> partList;
1608 1768
1609 lock (m_parts) 1769 lockPartsForRead(true);
1610 { 1770
1611 partList = new List<SceneObjectPart>(m_parts.Values); 1771 partList = new List<SceneObjectPart>(m_parts.Values);
1612 } 1772
1773 lockPartsForRead(false);
1613 1774
1614 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1775 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1615 { 1776 {
@@ -1832,13 +1993,40 @@ namespace OpenSim.Region.Framework.Scenes
1832 } 1993 }
1833 } 1994 }
1834 1995
1996 public void rotLookAt(Quaternion target, float strength, float damping)
1997 {
1998 SceneObjectPart rootpart = m_rootPart;
1999 if (rootpart != null)
2000 {
2001 if (IsAttachment)
2002 {
2003 /*
2004 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2005 if (avatar != null)
2006 {
2007 Rotate the Av?
2008 } */
2009 }
2010 else
2011 {
2012 if (rootpart.PhysActor != null)
2013 { // APID must be implemented in your physics system for this to function.
2014 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
2015 rootpart.PhysActor.APIDStrength = strength;
2016 rootpart.PhysActor.APIDDamping = damping;
2017 rootpart.PhysActor.APIDActive = true;
2018 }
2019 }
2020 }
2021 }
2022
1835 public void stopLookAt() 2023 public void stopLookAt()
1836 { 2024 {
1837 SceneObjectPart rootpart = m_rootPart; 2025 SceneObjectPart rootpart = m_rootPart;
1838 if (rootpart != null) 2026 if (rootpart != null)
1839 { 2027 {
1840 if (rootpart.PhysActor != null) 2028 if (rootpart.PhysActor != null)
1841 { 2029 { // APID must be implemented in your physics system for this to function.
1842 rootpart.PhysActor.APIDActive = false; 2030 rootpart.PhysActor.APIDActive = false;
1843 } 2031 }
1844 } 2032 }
@@ -1906,10 +2094,11 @@ namespace OpenSim.Region.Framework.Scenes
1906 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2094 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1907 newPart.SetParent(this); 2095 newPart.SetParent(this);
1908 2096
1909 lock (m_parts) 2097 lockPartsForWrite(true);
1910 { 2098 {
1911 m_parts.Add(newPart.UUID, newPart); 2099 m_parts.Add(newPart.UUID, newPart);
1912 } 2100 }
2101 lockPartsForWrite(false);
1913 2102
1914 SetPartAsNonRoot(newPart); 2103 SetPartAsNonRoot(newPart);
1915 2104
@@ -1972,7 +2161,7 @@ namespace OpenSim.Region.Framework.Scenes
1972 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2161 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1973 // return; 2162 // return;
1974 2163
1975 lock (m_parts) 2164 lockPartsForRead(true);
1976 { 2165 {
1977 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2166 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1978 2167
@@ -1992,9 +2181,12 @@ namespace OpenSim.Region.Framework.Scenes
1992 { 2181 {
1993 if (!IsSelected) 2182 if (!IsSelected)
1994 part.UpdateLookAt(); 2183 part.UpdateLookAt();
2184
1995 part.SendScheduledUpdates(); 2185 part.SendScheduledUpdates();
2186
1996 } 2187 }
1997 } 2188 }
2189 lockPartsForRead(false);
1998 } 2190 }
1999 2191
2000 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2192 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -2004,27 +2196,31 @@ namespace OpenSim.Region.Framework.Scenes
2004 2196
2005 RootPart.AddFullUpdateToAvatar(presence); 2197 RootPart.AddFullUpdateToAvatar(presence);
2006 2198
2007 lock (m_parts) 2199 lockPartsForRead(true);
2008 { 2200 {
2009 foreach (SceneObjectPart part in m_parts.Values) 2201 foreach (SceneObjectPart part in m_parts.Values)
2010 { 2202 {
2203
2011 if (part != RootPart) 2204 if (part != RootPart)
2012 part.AddFullUpdateToAvatar(presence); 2205 part.AddFullUpdateToAvatar(presence);
2206
2013 } 2207 }
2014 } 2208 }
2209 lockPartsForRead(false);
2015 } 2210 }
2016 2211
2017 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2212 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
2018 { 2213 {
2019// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2214 lockPartsForRead(true);
2020
2021 lock (m_parts)
2022 { 2215 {
2023 foreach (SceneObjectPart part in m_parts.Values) 2216 foreach (SceneObjectPart part in m_parts.Values)
2024 { 2217 {
2218
2025 part.AddTerseUpdateToAvatar(presence); 2219 part.AddTerseUpdateToAvatar(presence);
2220
2026 } 2221 }
2027 } 2222 }
2223 lockPartsForRead(false);
2028 } 2224 }
2029 2225
2030 /// <summary> 2226 /// <summary>
@@ -2038,14 +2234,17 @@ namespace OpenSim.Region.Framework.Scenes
2038 checkAtTargets(); 2234 checkAtTargets();
2039 RootPart.ScheduleFullUpdate(); 2235 RootPart.ScheduleFullUpdate();
2040 2236
2041 lock (m_parts) 2237 lockPartsForRead(true);
2042 { 2238 {
2043 foreach (SceneObjectPart part in m_parts.Values) 2239 foreach (SceneObjectPart part in m_parts.Values)
2044 { 2240 {
2241
2045 if (part != RootPart) 2242 if (part != RootPart)
2046 part.ScheduleFullUpdate(); 2243 part.ScheduleFullUpdate();
2244
2047 } 2245 }
2048 } 2246 }
2247 lockPartsForRead(false);
2049 } 2248 }
2050 2249
2051 /// <summary> 2250 /// <summary>
@@ -2053,15 +2252,16 @@ namespace OpenSim.Region.Framework.Scenes
2053 /// </summary> 2252 /// </summary>
2054 public void ScheduleGroupForTerseUpdate() 2253 public void ScheduleGroupForTerseUpdate()
2055 { 2254 {
2056// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2255 lockPartsForRead(true);
2057
2058 lock (m_parts)
2059 { 2256 {
2060 foreach (SceneObjectPart part in m_parts.Values) 2257 foreach (SceneObjectPart part in m_parts.Values)
2061 { 2258 {
2259
2062 part.ScheduleTerseUpdate(); 2260 part.ScheduleTerseUpdate();
2261
2063 } 2262 }
2064 } 2263 }
2264 lockPartsForRead(false);
2065 } 2265 }
2066 2266
2067 /// <summary> 2267 /// <summary>
@@ -2076,14 +2276,17 @@ namespace OpenSim.Region.Framework.Scenes
2076 2276
2077 RootPart.SendFullUpdateToAllClients(); 2277 RootPart.SendFullUpdateToAllClients();
2078 2278
2079 lock (m_parts) 2279 lockPartsForRead(true);
2080 { 2280 {
2081 foreach (SceneObjectPart part in m_parts.Values) 2281 foreach (SceneObjectPart part in m_parts.Values)
2082 { 2282 {
2283
2083 if (part != RootPart) 2284 if (part != RootPart)
2084 part.SendFullUpdateToAllClients(); 2285 part.SendFullUpdateToAllClients();
2286
2085 } 2287 }
2086 } 2288 }
2289 lockPartsForRead(false);
2087 } 2290 }
2088 2291
2089 /// <summary> 2292 /// <summary>
@@ -2115,14 +2318,15 @@ namespace OpenSim.Region.Framework.Scenes
2115 { 2318 {
2116 if (IsDeleted) 2319 if (IsDeleted)
2117 return; 2320 return;
2118 2321
2119 lock (m_parts) 2322 lockPartsForRead(true);
2120 { 2323 {
2121 foreach (SceneObjectPart part in m_parts.Values) 2324 foreach (SceneObjectPart part in m_parts.Values)
2122 { 2325 {
2123 part.SendTerseUpdateToAllClients(); 2326 part.SendTerseUpdateToAllClients();
2124 } 2327 }
2125 } 2328 }
2329 lockPartsForRead(false);
2126 } 2330 }
2127 2331
2128 #endregion 2332 #endregion
@@ -2136,16 +2340,18 @@ namespace OpenSim.Region.Framework.Scenes
2136 /// <returns>null if no child part with that linknum or child part</returns> 2340 /// <returns>null if no child part with that linknum or child part</returns>
2137 public SceneObjectPart GetLinkNumPart(int linknum) 2341 public SceneObjectPart GetLinkNumPart(int linknum)
2138 { 2342 {
2139 lock (m_parts) 2343 lockPartsForRead(true);
2140 { 2344 {
2141 foreach (SceneObjectPart part in m_parts.Values) 2345 foreach (SceneObjectPart part in m_parts.Values)
2142 { 2346 {
2143 if (part.LinkNum == linknum) 2347 if (part.LinkNum == linknum)
2144 { 2348 {
2349 lockPartsForRead(false);
2145 return part; 2350 return part;
2146 } 2351 }
2147 } 2352 }
2148 } 2353 }
2354 lockPartsForRead(false);
2149 2355
2150 return null; 2356 return null;
2151 } 2357 }
@@ -2173,17 +2379,19 @@ namespace OpenSim.Region.Framework.Scenes
2173 public SceneObjectPart GetChildPart(uint localID) 2379 public SceneObjectPart GetChildPart(uint localID)
2174 { 2380 {
2175 //m_log.DebugFormat("Entered looking for {0}", localID); 2381 //m_log.DebugFormat("Entered looking for {0}", localID);
2176 lock (m_parts) 2382 lockPartsForRead(true);
2177 { 2383 {
2178 foreach (SceneObjectPart part in m_parts.Values) 2384 foreach (SceneObjectPart part in m_parts.Values)
2179 { 2385 {
2180 //m_log.DebugFormat("Found {0}", part.LocalId); 2386 //m_log.DebugFormat("Found {0}", part.LocalId);
2181 if (part.LocalId == localID) 2387 if (part.LocalId == localID)
2182 { 2388 {
2389 lockPartsForRead(false);
2183 return part; 2390 return part;
2184 } 2391 }
2185 } 2392 }
2186 } 2393 }
2394 lockPartsForRead(false);
2187 2395
2188 return null; 2396 return null;
2189 } 2397 }
@@ -2213,17 +2421,19 @@ namespace OpenSim.Region.Framework.Scenes
2213 public bool HasChildPrim(uint localID) 2421 public bool HasChildPrim(uint localID)
2214 { 2422 {
2215 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2423 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2216 lock (m_parts) 2424 lockPartsForRead(true);
2217 { 2425 {
2218 foreach (SceneObjectPart part in m_parts.Values) 2426 foreach (SceneObjectPart part in m_parts.Values)
2219 { 2427 {
2220 //m_log.DebugFormat("Found {0}", part.LocalId); 2428 //m_log.DebugFormat("Found {0}", part.LocalId);
2221 if (part.LocalId == localID) 2429 if (part.LocalId == localID)
2222 { 2430 {
2431 lockPartsForRead(false);
2223 return true; 2432 return true;
2224 } 2433 }
2225 } 2434 }
2226 } 2435 }
2436 lockPartsForRead(false);
2227 2437
2228 return false; 2438 return false;
2229 } 2439 }
@@ -2273,53 +2483,57 @@ namespace OpenSim.Region.Framework.Scenes
2273 if (m_rootPart.LinkNum == 0) 2483 if (m_rootPart.LinkNum == 0)
2274 m_rootPart.LinkNum = 1; 2484 m_rootPart.LinkNum = 1;
2275 2485
2276 lock (m_parts) 2486 lockPartsForWrite(true);
2277 { 2487
2278 m_parts.Add(linkPart.UUID, linkPart); 2488 m_parts.Add(linkPart.UUID, linkPart);
2489
2490 lockPartsForWrite(false);
2279 2491
2280 // Insert in terms of link numbers, the new links 2492 // Insert in terms of link numbers, the new links
2281 // before the current ones (with the exception of 2493 // before the current ones (with the exception of
2282 // the root prim. Shuffle the old ones up 2494 // the root prim. Shuffle the old ones up
2283 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2495 lockPartsForRead(true);
2496 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2497 {
2498 if (kvp.Value.LinkNum != 1)
2284 { 2499 {
2285 if (kvp.Value.LinkNum != 1) 2500 // Don't update root prim link number
2286 { 2501 kvp.Value.LinkNum += objectGroup.PrimCount;
2287 // Don't update root prim link number
2288 kvp.Value.LinkNum += objectGroup.PrimCount;
2289 }
2290 } 2502 }
2503 }
2504 lockPartsForRead(false);
2291 2505
2292 linkPart.LinkNum = 2; 2506 linkPart.LinkNum = 2;
2293 2507
2294 linkPart.SetParent(this); 2508 linkPart.SetParent(this);
2295 linkPart.AddFlag(PrimFlags.CreateSelected); 2509 linkPart.AddFlag(PrimFlags.CreateSelected);
2296 2510
2297 //if (linkPart.PhysActor != null) 2511 //if (linkPart.PhysActor != null)
2298 //{ 2512 //{
2299 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2513 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2300 2514
2301 //linkPart.PhysActor = null; 2515 //linkPart.PhysActor = null;
2302 //} 2516 //}
2303 2517
2304 //TODO: rest of parts 2518 //TODO: rest of parts
2305 int linkNum = 3; 2519 int linkNum = 3;
2306 foreach (SceneObjectPart part in objectGroup.Children.Values) 2520 foreach (SceneObjectPart part in objectGroup.Children.Values)
2521 {
2522 if (part.UUID != objectGroup.m_rootPart.UUID)
2307 { 2523 {
2308 if (part.UUID != objectGroup.m_rootPart.UUID) 2524 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2309 {
2310 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2311 }
2312 part.ClearUndoState();
2313 } 2525 }
2526 part.ClearUndoState();
2314 } 2527 }
2315 2528
2316 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2529 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2317 objectGroup.m_isDeleted = true; 2530 objectGroup.m_isDeleted = true;
2531
2532 objectGroup.lockPartsForWrite(true);
2318 2533
2319 lock (objectGroup.m_parts) 2534 objectGroup.m_parts.Clear();
2320 { 2535
2321 objectGroup.m_parts.Clear(); 2536 objectGroup.lockPartsForWrite(false);
2322 }
2323 2537
2324 // Can't do this yet since backup still makes use of the root part without any synchronization 2538 // Can't do this yet since backup still makes use of the root part without any synchronization
2325// objectGroup.m_rootPart = null; 2539// objectGroup.m_rootPart = null;
@@ -2389,11 +2603,12 @@ namespace OpenSim.Region.Framework.Scenes
2389 Quaternion worldRot = linkPart.GetWorldRotation(); 2603 Quaternion worldRot = linkPart.GetWorldRotation();
2390 2604
2391 // Remove the part from this object 2605 // Remove the part from this object
2392 lock (m_parts) 2606 lockPartsForWrite(true);
2393 { 2607 {
2394 m_parts.Remove(linkPart.UUID); 2608 m_parts.Remove(linkPart.UUID);
2395 } 2609 }
2396 2610 lockPartsForWrite(false);
2611 lockPartsForRead(true);
2397 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2612 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2398 RootPart.LinkNum = 0; 2613 RootPart.LinkNum = 0;
2399 else 2614 else
@@ -2404,6 +2619,7 @@ namespace OpenSim.Region.Framework.Scenes
2404 p.LinkNum--; 2619 p.LinkNum--;
2405 } 2620 }
2406 } 2621 }
2622 lockPartsForRead(false);
2407 2623
2408 linkPart.ParentID = 0; 2624 linkPart.ParentID = 0;
2409 linkPart.LinkNum = 0; 2625 linkPart.LinkNum = 0;
@@ -2725,9 +2941,12 @@ namespace OpenSim.Region.Framework.Scenes
2725 2941
2726 if (selectionPart != null) 2942 if (selectionPart != null)
2727 { 2943 {
2728 lock (m_parts) 2944 lockPartsForRead(true);
2945 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2946 lockPartsForRead(false);
2947 foreach (SceneObjectPart part in parts)
2729 { 2948 {
2730 foreach (SceneObjectPart part in m_parts.Values) 2949 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2731 { 2950 {
2732 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2951 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2733 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2952 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2737,12 +2956,13 @@ namespace OpenSim.Region.Framework.Scenes
2737 break; 2956 break;
2738 } 2957 }
2739 } 2958 }
2959 }
2740 2960
2741 foreach (SceneObjectPart part in m_parts.Values) 2961 foreach (SceneObjectPart part in parts)
2742 { 2962 {
2743 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2963 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2744 }
2745 } 2964 }
2965
2746 } 2966 }
2747 } 2967 }
2748 2968
@@ -2828,11 +3048,9 @@ namespace OpenSim.Region.Framework.Scenes
2828 scale.Y = m_scene.m_maxNonphys; 3048 scale.Y = m_scene.m_maxNonphys;
2829 if (scale.Z > m_scene.m_maxNonphys) 3049 if (scale.Z > m_scene.m_maxNonphys)
2830 scale.Z = m_scene.m_maxNonphys; 3050 scale.Z = m_scene.m_maxNonphys;
2831
2832 SceneObjectPart part = GetChildPart(localID); 3051 SceneObjectPart part = GetChildPart(localID);
2833 if (part != null) 3052 if (part != null)
2834 { 3053 {
2835 part.Resize(scale);
2836 if (part.PhysActor != null) 3054 if (part.PhysActor != null)
2837 { 3055 {
2838 if (part.PhysActor.IsPhysical) 3056 if (part.PhysActor.IsPhysical)
@@ -2847,7 +3065,7 @@ namespace OpenSim.Region.Framework.Scenes
2847 part.PhysActor.Size = scale; 3065 part.PhysActor.Size = scale;
2848 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 3066 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2849 } 3067 }
2850 //if (part.UUID != m_rootPart.UUID) 3068 part.Resize(scale);
2851 3069
2852 HasGroupChanged = true; 3070 HasGroupChanged = true;
2853 ScheduleGroupForFullUpdate(); 3071 ScheduleGroupForFullUpdate();
@@ -2889,73 +3107,71 @@ namespace OpenSim.Region.Framework.Scenes
2889 float y = (scale.Y / part.Scale.Y); 3107 float y = (scale.Y / part.Scale.Y);
2890 float z = (scale.Z / part.Scale.Z); 3108 float z = (scale.Z / part.Scale.Z);
2891 3109
2892 lock (m_parts) 3110 lockPartsForRead(true);
3111 if (x > 1.0f || y > 1.0f || z > 1.0f)
2893 { 3112 {
2894 if (x > 1.0f || y > 1.0f || z > 1.0f) 3113 foreach (SceneObjectPart obPart in m_parts.Values)
2895 { 3114 {
2896 foreach (SceneObjectPart obPart in m_parts.Values) 3115 if (obPart.UUID != m_rootPart.UUID)
2897 { 3116 {
2898 if (obPart.UUID != m_rootPart.UUID) 3117 obPart.IgnoreUndoUpdate = true;
2899 { 3118 Vector3 oldSize = new Vector3(obPart.Scale);
2900 obPart.IgnoreUndoUpdate = true;
2901 Vector3 oldSize = new Vector3(obPart.Scale);
2902 3119
2903 float f = 1.0f; 3120 float f = 1.0f;
2904 float a = 1.0f; 3121 float a = 1.0f;
2905 3122
2906 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3123 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3124 {
3125 if (oldSize.X*x > m_scene.m_maxPhys)
2907 { 3126 {
2908 if (oldSize.X*x > m_scene.m_maxPhys) 3127 f = m_scene.m_maxPhys / oldSize.X;
2909 { 3128 a = f / x;
2910 f = m_scene.m_maxPhys / oldSize.X; 3129 x *= a;
2911 a = f / x; 3130 y *= a;
2912 x *= a; 3131 z *= a;
2913 y *= a;
2914 z *= a;
2915 }
2916 if (oldSize.Y*y > m_scene.m_maxPhys)
2917 {
2918 f = m_scene.m_maxPhys / oldSize.Y;
2919 a = f / y;
2920 x *= a;
2921 y *= a;
2922 z *= a;
2923 }
2924 if (oldSize.Z*z > m_scene.m_maxPhys)
2925 {
2926 f = m_scene.m_maxPhys / oldSize.Z;
2927 a = f / z;
2928 x *= a;
2929 y *= a;
2930 z *= a;
2931 }
2932 } 3132 }
2933 else 3133 if (oldSize.Y*y > m_scene.m_maxPhys)
2934 { 3134 {
2935 if (oldSize.X*x > m_scene.m_maxNonphys) 3135 f = m_scene.m_maxPhys / oldSize.Y;
2936 { 3136 a = f / y;
2937 f = m_scene.m_maxNonphys / oldSize.X; 3137 x *= a;
2938 a = f / x; 3138 y *= a;
2939 x *= a; 3139 z *= a;
2940 y *= a; 3140 }
2941 z *= a; 3141 if (oldSize.Z*z > m_scene.m_maxPhys)
2942 } 3142 {
2943 if (oldSize.Y*y > m_scene.m_maxNonphys) 3143 f = m_scene.m_maxPhys / oldSize.Z;
2944 { 3144 a = f / z;
2945 f = m_scene.m_maxNonphys / oldSize.Y; 3145 x *= a;
2946 a = f / y; 3146 y *= a;
2947 x *= a; 3147 z *= a;
2948 y *= a; 3148 }
2949 z *= a; 3149 }
2950 } 3150 else
2951 if (oldSize.Z*z > m_scene.m_maxNonphys) 3151 {
2952 { 3152 if (oldSize.X*x > m_scene.m_maxNonphys)
2953 f = m_scene.m_maxNonphys / oldSize.Z; 3153 {
2954 a = f / z; 3154 f = m_scene.m_maxNonphys / oldSize.X;
2955 x *= a; 3155 a = f / x;
2956 y *= a; 3156 x *= a;
2957 z *= a; 3157 y *= a;
2958 } 3158 z *= a;
3159 }
3160 if (oldSize.Y*y > m_scene.m_maxNonphys)
3161 {
3162 f = m_scene.m_maxNonphys / oldSize.Y;
3163 a = f / y;
3164 x *= a;
3165 y *= a;
3166 z *= a;
3167 }
3168 if (oldSize.Z*z > m_scene.m_maxNonphys)
3169 {
3170 f = m_scene.m_maxNonphys / oldSize.Z;
3171 a = f / z;
3172 x *= a;
3173 y *= a;
3174 z *= a;
2959 } 3175 }
2960 obPart.IgnoreUndoUpdate = false; 3176 obPart.IgnoreUndoUpdate = false;
2961 obPart.StoreUndoState(); 3177 obPart.StoreUndoState();
@@ -2963,6 +3179,7 @@ namespace OpenSim.Region.Framework.Scenes
2963 } 3179 }
2964 } 3180 }
2965 } 3181 }
3182 lockPartsForRead(false);
2966 3183
2967 Vector3 prevScale = part.Scale; 3184 Vector3 prevScale = part.Scale;
2968 prevScale.X *= x; 3185 prevScale.X *= x;
@@ -2970,7 +3187,7 @@ namespace OpenSim.Region.Framework.Scenes
2970 prevScale.Z *= z; 3187 prevScale.Z *= z;
2971 part.Resize(prevScale); 3188 part.Resize(prevScale);
2972 3189
2973 lock (m_parts) 3190 lockPartsForRead(true);
2974 { 3191 {
2975 foreach (SceneObjectPart obPart in m_parts.Values) 3192 foreach (SceneObjectPart obPart in m_parts.Values)
2976 { 3193 {
@@ -2992,6 +3209,7 @@ namespace OpenSim.Region.Framework.Scenes
2992 obPart.StoreUndoState(); 3209 obPart.StoreUndoState();
2993 } 3210 }
2994 } 3211 }
3212 lockPartsForRead(false);
2995 3213
2996 if (part.PhysActor != null) 3214 if (part.PhysActor != null)
2997 { 3215 {
@@ -3094,7 +3312,7 @@ namespace OpenSim.Region.Framework.Scenes
3094 axDiff *= Quaternion.Inverse(partRotation); 3312 axDiff *= Quaternion.Inverse(partRotation);
3095 diff = axDiff; 3313 diff = axDiff;
3096 3314
3097 lock (m_parts) 3315 lockPartsForRead(true);
3098 { 3316 {
3099 foreach (SceneObjectPart obPart in m_parts.Values) 3317 foreach (SceneObjectPart obPart in m_parts.Values)
3100 { 3318 {
@@ -3104,6 +3322,7 @@ namespace OpenSim.Region.Framework.Scenes
3104 } 3322 }
3105 } 3323 }
3106 } 3324 }
3325 lockPartsForRead(false);
3107 3326
3108 AbsolutePosition = newPos; 3327 AbsolutePosition = newPos;
3109 3328
@@ -3237,25 +3456,25 @@ namespace OpenSim.Region.Framework.Scenes
3237 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3456 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3238 } 3457 }
3239 3458
3240 lock (m_parts) 3459 lockPartsForRead(true);
3460
3461 foreach (SceneObjectPart prim in m_parts.Values)
3241 { 3462 {
3242 foreach (SceneObjectPart prim in m_parts.Values) 3463 if (prim.UUID != m_rootPart.UUID)
3243 { 3464 {
3244 if (prim.UUID != m_rootPart.UUID) 3465 prim.IgnoreUndoUpdate = true;
3245 { 3466 Vector3 axPos = prim.OffsetPosition;
3246 prim.IgnoreUndoUpdate = true; 3467 axPos *= oldParentRot;
3247 Vector3 axPos = prim.OffsetPosition; 3468 axPos *= Quaternion.Inverse(axRot);
3248 axPos *= oldParentRot; 3469 prim.OffsetPosition = axPos;
3249 axPos *= Quaternion.Inverse(axRot); 3470 Quaternion primsRot = prim.RotationOffset;
3250 prim.OffsetPosition = axPos; 3471 Quaternion newRot = primsRot * oldParentRot;
3251 Quaternion primsRot = prim.RotationOffset; 3472 newRot *= Quaternion.Inverse(axRot);
3252 Quaternion newRot = primsRot * oldParentRot; 3473 prim.RotationOffset = newRot;
3253 newRot *= Quaternion.Inverse(axRot); 3474 prim.ScheduleTerseUpdate();
3254 prim.RotationOffset = newRot;
3255 prim.ScheduleTerseUpdate();
3256 }
3257 } 3475 }
3258 } 3476 }
3477
3259 foreach (SceneObjectPart childpart in Children.Values) 3478 foreach (SceneObjectPart childpart in Children.Values)
3260 { 3479 {
3261 if (childpart != m_rootPart) 3480 if (childpart != m_rootPart)
@@ -3264,6 +3483,9 @@ namespace OpenSim.Region.Framework.Scenes
3264 childpart.StoreUndoState(); 3483 childpart.StoreUndoState();
3265 } 3484 }
3266 } 3485 }
3486
3487 lockPartsForRead(false);
3488
3267 m_rootPart.ScheduleTerseUpdate(); 3489 m_rootPart.ScheduleTerseUpdate();
3268 } 3490 }
3269 3491
@@ -3385,7 +3607,7 @@ namespace OpenSim.Region.Framework.Scenes
3385 if (atTargets.Count > 0) 3607 if (atTargets.Count > 0)
3386 { 3608 {
3387 uint[] localids = new uint[0]; 3609 uint[] localids = new uint[0];
3388 lock (m_parts) 3610 lockPartsForRead(true);
3389 { 3611 {
3390 localids = new uint[m_parts.Count]; 3612 localids = new uint[m_parts.Count];
3391 int cntr = 0; 3613 int cntr = 0;
@@ -3395,6 +3617,7 @@ namespace OpenSim.Region.Framework.Scenes
3395 cntr++; 3617 cntr++;
3396 } 3618 }
3397 } 3619 }
3620 lockPartsForRead(false);
3398 3621
3399 for (int ctr = 0; ctr < localids.Length; ctr++) 3622 for (int ctr = 0; ctr < localids.Length; ctr++)
3400 { 3623 {
@@ -3413,7 +3636,7 @@ namespace OpenSim.Region.Framework.Scenes
3413 { 3636 {
3414 //trigger not_at_target 3637 //trigger not_at_target
3415 uint[] localids = new uint[0]; 3638 uint[] localids = new uint[0];
3416 lock (m_parts) 3639 lockPartsForRead(true);
3417 { 3640 {
3418 localids = new uint[m_parts.Count]; 3641 localids = new uint[m_parts.Count];
3419 int cntr = 0; 3642 int cntr = 0;
@@ -3423,7 +3646,8 @@ namespace OpenSim.Region.Framework.Scenes
3423 cntr++; 3646 cntr++;
3424 } 3647 }
3425 } 3648 }
3426 3649 lockPartsForRead(false);
3650
3427 for (int ctr = 0; ctr < localids.Length; ctr++) 3651 for (int ctr = 0; ctr < localids.Length; ctr++)
3428 { 3652 {
3429 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3653 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3515,19 +3739,20 @@ namespace OpenSim.Region.Framework.Scenes
3515 public float GetMass() 3739 public float GetMass()
3516 { 3740 {
3517 float retmass = 0f; 3741 float retmass = 0f;
3518 lock (m_parts) 3742 lockPartsForRead(true);
3519 { 3743 {
3520 foreach (SceneObjectPart part in m_parts.Values) 3744 foreach (SceneObjectPart part in m_parts.Values)
3521 { 3745 {
3522 retmass += part.GetMass(); 3746 retmass += part.GetMass();
3523 } 3747 }
3524 } 3748 }
3749 lockPartsForRead(false);
3525 return retmass; 3750 return retmass;
3526 } 3751 }
3527 3752
3528 public void CheckSculptAndLoad() 3753 public void CheckSculptAndLoad()
3529 { 3754 {
3530 lock (m_parts) 3755 lockPartsForRead(true);
3531 { 3756 {
3532 if (!IsDeleted) 3757 if (!IsDeleted)
3533 { 3758 {
@@ -3552,6 +3777,7 @@ namespace OpenSim.Region.Framework.Scenes
3552 } 3777 }
3553 } 3778 }
3554 } 3779 }
3780 lockPartsForRead(false);
3555 } 3781 }
3556 3782
3557 protected void AssetReceived(string id, Object sender, AssetBase asset) 3783 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3572,7 +3798,7 @@ namespace OpenSim.Region.Framework.Scenes
3572 /// <param name="client"></param> 3798 /// <param name="client"></param>
3573 public void SetGroup(UUID GroupID, IClientAPI client) 3799 public void SetGroup(UUID GroupID, IClientAPI client)
3574 { 3800 {
3575 lock (m_parts) 3801 lockPartsForRead(true);
3576 { 3802 {
3577 foreach (SceneObjectPart part in m_parts.Values) 3803 foreach (SceneObjectPart part in m_parts.Values)
3578 { 3804 {
@@ -3582,6 +3808,7 @@ namespace OpenSim.Region.Framework.Scenes
3582 3808
3583 HasGroupChanged = true; 3809 HasGroupChanged = true;
3584 } 3810 }
3811 lockPartsForRead(false);
3585 3812
3586 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3813 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
3587 // for the same object with very different properties. The caller must schedule the update. 3814 // for the same object with very different properties. The caller must schedule the update.
@@ -3603,11 +3830,12 @@ namespace OpenSim.Region.Framework.Scenes
3603 3830
3604 public void SetAttachmentPoint(byte point) 3831 public void SetAttachmentPoint(byte point)
3605 { 3832 {
3606 lock (m_parts) 3833 lockPartsForRead(true);
3607 { 3834 {
3608 foreach (SceneObjectPart part in m_parts.Values) 3835 foreach (SceneObjectPart part in m_parts.Values)
3609 part.SetAttachmentPoint(point); 3836 part.SetAttachmentPoint(point);
3610 } 3837 }
3838 lockPartsForRead(false);
3611 } 3839 }
3612 3840
3613 #region ISceneObject 3841 #region ISceneObject
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 19ff288..9862785 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -147,7 +147,7 @@ namespace OpenSim.Region.Framework.Scenes
147 147
148 // TODO: This needs to be persisted in next XML version update! 148 // TODO: This needs to be persisted in next XML version update!
149 [XmlIgnore] 149 [XmlIgnore]
150 public readonly int[] PayPrice = {-2,-2,-2,-2,-2}; 150 public int[] PayPrice = {-2,-2,-2,-2,-2};
151 [XmlIgnore] 151 [XmlIgnore]
152 public PhysicsActor PhysActor; 152 public PhysicsActor PhysActor;
153 153
@@ -274,6 +274,7 @@ namespace OpenSim.Region.Framework.Scenes
274 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 274 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
275 private Vector3 m_sitTargetPosition; 275 private Vector3 m_sitTargetPosition;
276 private string m_sitAnimation = "SIT"; 276 private string m_sitAnimation = "SIT";
277 private bool m_occupied; // KF if any av is sitting on this prim
277 private string m_text = String.Empty; 278 private string m_text = String.Empty;
278 private string m_touchName = String.Empty; 279 private string m_touchName = String.Empty;
279 private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5); 280 private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5);
@@ -452,12 +453,16 @@ namespace OpenSim.Region.Framework.Scenes
452 } 453 }
453 454
454 /// <value> 455 /// <value>
455 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 456 /// Get the inventory list
456 /// </value> 457 /// </value>
457 public TaskInventoryDictionary TaskInventory 458 public TaskInventoryDictionary TaskInventory
458 { 459 {
459 get { return m_inventory.Items; } 460 get {
460 set { m_inventory.Items = value; } 461 return m_inventory.Items;
462 }
463 set {
464 m_inventory.Items = value;
465 }
461 } 466 }
462 467
463 public uint ObjectFlags 468 public uint ObjectFlags
@@ -586,14 +591,12 @@ namespace OpenSim.Region.Framework.Scenes
586 set { m_LoopSoundSlavePrims = value; } 591 set { m_LoopSoundSlavePrims = value; }
587 } 592 }
588 593
589 [XmlIgnore]
590 public Byte[] TextureAnimation 594 public Byte[] TextureAnimation
591 { 595 {
592 get { return m_TextureAnimation; } 596 get { return m_TextureAnimation; }
593 set { m_TextureAnimation = value; } 597 set { m_TextureAnimation = value; }
594 } 598 }
595 599
596 [XmlIgnore]
597 public Byte[] ParticleSystem 600 public Byte[] ParticleSystem
598 { 601 {
599 get { return m_particleSystem; } 602 get { return m_particleSystem; }
@@ -647,7 +650,6 @@ namespace OpenSim.Region.Framework.Scenes
647 set 650 set
648 { 651 {
649 m_groupPosition = value; 652 m_groupPosition = value;
650
651 PhysicsActor actor = PhysActor; 653 PhysicsActor actor = PhysActor;
652 if (actor != null) 654 if (actor != null)
653 { 655 {
@@ -816,7 +818,16 @@ namespace OpenSim.Region.Framework.Scenes
816 /// <summary></summary> 818 /// <summary></summary>
817 public Vector3 Acceleration 819 public Vector3 Acceleration
818 { 820 {
819 get { return m_acceleration; } 821 get
822 {
823 PhysicsActor actor = PhysActor;
824 if (actor != null)
825 {
826 m_acceleration = actor.Acceleration;
827 }
828 return m_acceleration;
829 }
830
820 set { m_acceleration = value; } 831 set { m_acceleration = value; }
821 } 832 }
822 833
@@ -960,7 +971,8 @@ namespace OpenSim.Region.Framework.Scenes
960 if (IsAttachment) 971 if (IsAttachment)
961 return GroupPosition; 972 return GroupPosition;
962 973
963 return m_offsetPosition + m_groupPosition; } 974// return m_offsetPosition + m_groupPosition; }
975 return m_groupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset) ; } //KF: Rotation was ignored!
964 } 976 }
965 977
966 public SceneObjectGroup ParentGroup 978 public SceneObjectGroup ParentGroup
@@ -1112,6 +1124,13 @@ namespace OpenSim.Region.Framework.Scenes
1112 get { return _flags; } 1124 get { return _flags; }
1113 set { _flags = value; } 1125 set { _flags = value; }
1114 } 1126 }
1127
1128 [XmlIgnore]
1129 public bool IsOccupied // KF If an av is sittingon this prim
1130 {
1131 get { return m_occupied; }
1132 set { m_occupied = value; }
1133 }
1115 1134
1116 [XmlIgnore] 1135 [XmlIgnore]
1117 public UUID SitTargetAvatar 1136 public UUID SitTargetAvatar
@@ -1187,14 +1206,6 @@ namespace OpenSim.Region.Framework.Scenes
1187 } 1206 }
1188 } 1207 }
1189 1208
1190 /// <summary>
1191 /// Clear all pending updates of parts to clients
1192 /// </summary>
1193 private void ClearUpdateSchedule()
1194 {
1195 m_updateFlag = 0;
1196 }
1197
1198 private void SendObjectPropertiesToClient(UUID AgentID) 1209 private void SendObjectPropertiesToClient(UUID AgentID)
1199 { 1210 {
1200 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 1211 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences();
@@ -1939,12 +1950,17 @@ namespace OpenSim.Region.Framework.Scenes
1939 public Vector3 GetWorldPosition() 1950 public Vector3 GetWorldPosition()
1940 { 1951 {
1941 Quaternion parentRot = ParentGroup.RootPart.RotationOffset; 1952 Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
1942
1943 Vector3 axPos = OffsetPosition; 1953 Vector3 axPos = OffsetPosition;
1944
1945 axPos *= parentRot; 1954 axPos *= parentRot;
1946 Vector3 translationOffsetPosition = axPos; 1955 Vector3 translationOffsetPosition = axPos;
1947 return GroupPosition + translationOffsetPosition; 1956 if(_parentID == 0)
1957 {
1958 return GroupPosition;
1959 }
1960 else
1961 {
1962 return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position
1963 }
1948 } 1964 }
1949 1965
1950 /// <summary> 1966 /// <summary>
@@ -1955,7 +1971,7 @@ namespace OpenSim.Region.Framework.Scenes
1955 { 1971 {
1956 Quaternion newRot; 1972 Quaternion newRot;
1957 1973
1958 if (this.LinkNum == 0) 1974 if (this.LinkNum < 2) //KF Single or root prim
1959 { 1975 {
1960 newRot = RotationOffset; 1976 newRot = RotationOffset;
1961 } 1977 }
@@ -2612,17 +2628,18 @@ namespace OpenSim.Region.Framework.Scenes
2612 //Trys to fetch sound id from prim's inventory. 2628 //Trys to fetch sound id from prim's inventory.
2613 //Prim's inventory doesn't support non script items yet 2629 //Prim's inventory doesn't support non script items yet
2614 2630
2615 lock (TaskInventory) 2631 TaskInventory.LockItemsForRead(true);
2632
2633 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2616 { 2634 {
2617 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2635 if (item.Value.Name == sound)
2618 { 2636 {
2619 if (item.Value.Name == sound) 2637 soundID = item.Value.ItemID;
2620 { 2638 break;
2621 soundID = item.Value.ItemID;
2622 break;
2623 }
2624 } 2639 }
2625 } 2640 }
2641
2642 TaskInventory.LockItemsForRead(false);
2626 } 2643 }
2627 2644
2628 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 2645 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
@@ -2690,38 +2707,7 @@ namespace OpenSim.Region.Framework.Scenes
2690 2707
2691 public void RotLookAt(Quaternion target, float strength, float damping) 2708 public void RotLookAt(Quaternion target, float strength, float damping)
2692 { 2709 {
2693 rotLookAt(target, strength, damping); 2710 m_parentGroup.rotLookAt(target, strength, damping); // This calls method in SceneObjectGroup.
2694 }
2695
2696 public void rotLookAt(Quaternion target, float strength, float damping)
2697 {
2698 if (IsAttachment)
2699 {
2700 /*
2701 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2702 if (avatar != null)
2703 {
2704 Rotate the Av?
2705 } */
2706 }
2707 else
2708 {
2709 APIDDamp = damping;
2710 APIDStrength = strength;
2711 APIDTarget = target;
2712 }
2713 }
2714
2715 public void startLookAt(Quaternion rot, float damp, float strength)
2716 {
2717 APIDDamp = damp;
2718 APIDStrength = strength;
2719 APIDTarget = rot;
2720 }
2721
2722 public void stopLookAt()
2723 {
2724 APIDTarget = Quaternion.Identity;
2725 } 2711 }
2726 2712
2727 /// <summary> 2713 /// <summary>
@@ -2959,8 +2945,8 @@ namespace OpenSim.Region.Framework.Scenes
2959 { 2945 {
2960 const float ROTATION_TOLERANCE = 0.01f; 2946 const float ROTATION_TOLERANCE = 0.01f;
2961 const float VELOCITY_TOLERANCE = 0.001f; 2947 const float VELOCITY_TOLERANCE = 0.001f;
2962 const float POSITION_TOLERANCE = 0.05f; 2948 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2963 const int TIME_MS_TOLERANCE = 3000; 2949 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2964 2950
2965 if (m_updateFlag == 1) 2951 if (m_updateFlag == 1)
2966 { 2952 {
@@ -2974,7 +2960,7 @@ namespace OpenSim.Region.Framework.Scenes
2974 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2960 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2975 { 2961 {
2976 AddTerseUpdateToAllAvatars(); 2962 AddTerseUpdateToAllAvatars();
2977 ClearUpdateSchedule(); 2963
2978 2964
2979 // This causes the Scene to 'poll' physical objects every couple of frames 2965 // This causes the Scene to 'poll' physical objects every couple of frames
2980 // bad, so it's been replaced by an event driven method. 2966 // bad, so it's been replaced by an event driven method.
@@ -2992,6 +2978,8 @@ namespace OpenSim.Region.Framework.Scenes
2992 m_lastAngularVelocity = AngularVelocity; 2978 m_lastAngularVelocity = AngularVelocity;
2993 m_lastTerseSent = Environment.TickCount; 2979 m_lastTerseSent = Environment.TickCount;
2994 } 2980 }
2981 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
2982 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
2995 } 2983 }
2996 else 2984 else
2997 { 2985 {
@@ -3001,10 +2989,10 @@ namespace OpenSim.Region.Framework.Scenes
3001// m_log.DebugFormat("[SOP]: Sending scheduled full update for {0} {1}", Name, LocalId); 2989// m_log.DebugFormat("[SOP]: Sending scheduled full update for {0} {1}", Name, LocalId);
3002 2990
3003 AddFullUpdateToAllAvatars(); 2991 AddFullUpdateToAllAvatars();
3004 ClearUpdateSchedule(); 2992 m_updateFlag = 0; //Same here
3005 } 2993 }
3006 } 2994 }
3007 ClearUpdateSchedule(); 2995 m_updateFlag = 0;
3008 } 2996 }
3009 2997
3010 /// <summary> 2998 /// <summary>
@@ -3031,17 +3019,16 @@ namespace OpenSim.Region.Framework.Scenes
3031 if (!UUID.TryParse(sound, out soundID)) 3019 if (!UUID.TryParse(sound, out soundID))
3032 { 3020 {
3033 // search sound file from inventory 3021 // search sound file from inventory
3034 lock (TaskInventory) 3022 TaskInventory.LockItemsForRead(true);
3023 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3035 { 3024 {
3036 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3025 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3037 { 3026 {
3038 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3027 soundID = item.Value.ItemID;
3039 { 3028 break;
3040 soundID = item.Value.ItemID;
3041 break;
3042 }
3043 } 3029 }
3044 } 3030 }
3031 TaskInventory.LockItemsForRead(false);
3045 } 3032 }
3046 3033
3047 if (soundID == UUID.Zero) 3034 if (soundID == UUID.Zero)
@@ -3477,7 +3464,7 @@ namespace OpenSim.Region.Framework.Scenes
3477 3464
3478 public void StopLookAt() 3465 public void StopLookAt()
3479 { 3466 {
3480 m_parentGroup.stopLookAt(); 3467 m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup.
3481 3468
3482 m_parentGroup.ScheduleGroupForTerseUpdate(); 3469 m_parentGroup.ScheduleGroupForTerseUpdate();
3483 } 3470 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 256e3b0..9b16281 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -47,6 +47,8 @@ namespace OpenSim.Region.Framework.Scenes
47 47
48 private string m_inventoryFileName = String.Empty; 48 private string m_inventoryFileName = String.Empty;
49 private int m_inventoryFileNameSerial = 0; 49 private int m_inventoryFileNameSerial = 0;
50
51 private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>();
50 52
51 /// <value> 53 /// <value>
52 /// The part to which the inventory belongs. 54 /// The part to which the inventory belongs.
@@ -83,7 +85,9 @@ namespace OpenSim.Region.Framework.Scenes
83 /// </value> 85 /// </value>
84 protected internal TaskInventoryDictionary Items 86 protected internal TaskInventoryDictionary Items
85 { 87 {
86 get { return m_items; } 88 get {
89 return m_items;
90 }
87 set 91 set
88 { 92 {
89 m_items = value; 93 m_items = value;
@@ -119,22 +123,25 @@ namespace OpenSim.Region.Framework.Scenes
119 /// <param name="linkNum">Link number for the part</param> 123 /// <param name="linkNum">Link number for the part</param>
120 public void ResetInventoryIDs() 124 public void ResetInventoryIDs()
121 { 125 {
122 lock (Items) 126 m_items.LockItemsForWrite(true);
127
128 if (0 == Items.Count)
123 { 129 {
124 if (0 == Items.Count) 130 m_items.LockItemsForWrite(false);
125 return; 131 return;
132 }
126 133
127 HasInventoryChanged = true; 134 HasInventoryChanged = true;
128 m_part.ParentGroup.HasGroupChanged = true; 135 m_part.ParentGroup.HasGroupChanged = true;
129 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 136 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
130 Items.Clear(); 137 Items.Clear();
131 138
132 foreach (TaskInventoryItem item in items) 139 foreach (TaskInventoryItem item in items)
133 { 140 {
134 item.ResetIDs(m_part.UUID); 141 item.ResetIDs(m_part.UUID);
135 Items.Add(item.ItemID, item); 142 Items.Add(item.ItemID, item);
136 }
137 } 143 }
144 m_items.LockItemsForWrite(false);
138 } 145 }
139 146
140 /// <summary> 147 /// <summary>
@@ -143,25 +150,25 @@ namespace OpenSim.Region.Framework.Scenes
143 /// <param name="ownerId"></param> 150 /// <param name="ownerId"></param>
144 public void ChangeInventoryOwner(UUID ownerId) 151 public void ChangeInventoryOwner(UUID ownerId)
145 { 152 {
146 lock (Items) 153 m_items.LockItemsForWrite(true);
154 if (0 == Items.Count)
147 { 155 {
148 if (0 == Items.Count) 156 m_items.LockItemsForWrite(false);
149 { 157 return;
150 return; 158 }
151 }
152 159
153 HasInventoryChanged = true; 160 HasInventoryChanged = true;
154 m_part.ParentGroup.HasGroupChanged = true; 161 m_part.ParentGroup.HasGroupChanged = true;
155 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 162 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
156 foreach (TaskInventoryItem item in items) 163 foreach (TaskInventoryItem item in items)
164 {
165 if (ownerId != item.OwnerID)
157 { 166 {
158 if (ownerId != item.OwnerID) 167 item.LastOwnerID = item.OwnerID;
159 { 168 item.OwnerID = ownerId;
160 item.LastOwnerID = item.OwnerID;
161 item.OwnerID = ownerId;
162 }
163 } 169 }
164 } 170 }
171 m_items.LockItemsForWrite(false);
165 } 172 }
166 173
167 /// <summary> 174 /// <summary>
@@ -170,24 +177,24 @@ namespace OpenSim.Region.Framework.Scenes
170 /// <param name="groupID"></param> 177 /// <param name="groupID"></param>
171 public void ChangeInventoryGroup(UUID groupID) 178 public void ChangeInventoryGroup(UUID groupID)
172 { 179 {
173 lock (Items) 180 m_items.LockItemsForWrite(true);
181 if (0 == Items.Count)
174 { 182 {
175 if (0 == Items.Count) 183 m_items.LockItemsForWrite(false);
176 { 184 return;
177 return; 185 }
178 }
179 186
180 HasInventoryChanged = true; 187 HasInventoryChanged = true;
181 m_part.ParentGroup.HasGroupChanged = true; 188 m_part.ParentGroup.HasGroupChanged = true;
182 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 189 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
183 foreach (TaskInventoryItem item in items) 190 foreach (TaskInventoryItem item in items)
191 {
192 if (groupID != item.GroupID)
184 { 193 {
185 if (groupID != item.GroupID) 194 item.GroupID = groupID;
186 {
187 item.GroupID = groupID;
188 }
189 } 195 }
190 } 196 }
197 m_items.LockItemsForWrite(false);
191 } 198 }
192 199
193 /// <summary> 200 /// <summary>
@@ -195,10 +202,14 @@ namespace OpenSim.Region.Framework.Scenes
195 /// </summary> 202 /// </summary>
196 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 203 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
197 { 204 {
198 lock (m_items) 205 Items.LockItemsForRead(true);
206 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
207 Items.LockItemsForRead(false);
208 foreach (TaskInventoryItem item in items)
199 { 209 {
200 foreach (TaskInventoryItem item in Items.Values) 210 if ((int)InventoryType.LSL == item.InvType)
201 { 211 {
212 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
202 if ((int)InventoryType.LSL == item.InvType) 213 if ((int)InventoryType.LSL == item.InvType)
203 { 214 {
204 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 215 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
@@ -208,7 +219,7 @@ namespace OpenSim.Region.Framework.Scenes
208 } 219 }
209 } 220 }
210 221
211 public ArrayList GetScriptErrors(UUID itemID) 222 private ArrayList GetScriptErrors(UUID itemID)
212 { 223 {
213 ArrayList ret = new ArrayList(); 224 ArrayList ret = new ArrayList();
214 225
@@ -238,16 +249,20 @@ namespace OpenSim.Region.Framework.Scenes
238 /// </param> 249 /// </param>
239 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 250 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
240 { 251 {
241 lock (Items) 252 Items.LockItemsForRead(true);
253 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
254 Items.LockItemsForRead(false);
255
256 foreach (TaskInventoryItem item in items)
242 { 257 {
243 foreach (TaskInventoryItem item in Items.Values) 258 if ((int)InventoryType.LSL == item.InvType)
244 { 259 {
245 if ((int)InventoryType.LSL == item.InvType) 260 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
246 { 261 m_part.RemoveScriptEvents(item.ItemID);
247 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
248 }
249 } 262 }
250 } 263 }
264
265
251 } 266 }
252 267
253 /// <summary> 268 /// <summary>
@@ -263,7 +278,10 @@ namespace OpenSim.Region.Framework.Scenes
263 // item.Name, item.ItemID, m_part.Name, m_part.UUID); 278 // item.Name, item.ItemID, m_part.Name, m_part.UUID);
264 279
265 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 280 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
281 {
282 StoreScriptError(item.ItemID, "no permission");
266 return; 283 return;
284 }
267 285
268 m_part.AddFlag(PrimFlags.Scripted); 286 m_part.AddFlag(PrimFlags.Scripted);
269 287
@@ -272,49 +290,50 @@ namespace OpenSim.Region.Framework.Scenes
272 if (stateSource == 1 && // Prim crossing 290 if (stateSource == 1 && // Prim crossing
273 m_part.ParentGroup.Scene.m_trustBinaries) 291 m_part.ParentGroup.Scene.m_trustBinaries)
274 { 292 {
275 lock (m_items) 293 m_items.LockItemsForWrite(true);
276 { 294 m_items[item.ItemID].PermsMask = 0;
277 m_items[item.ItemID].PermsMask = 0; 295 m_items[item.ItemID].PermsGranter = UUID.Zero;
278 m_items[item.ItemID].PermsGranter = UUID.Zero; 296 m_items.LockItemsForWrite(false);
279 }
280
281 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 297 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
282 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 298 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
299 StoreScriptErrors(item.ItemID, null);
283 m_part.ParentGroup.AddActiveScriptCount(1); 300 m_part.ParentGroup.AddActiveScriptCount(1);
284 m_part.ScheduleFullUpdate(); 301 m_part.ScheduleFullUpdate();
285 return; 302 return;
286 } 303 }
287 304
288 m_part.ParentGroup.Scene.AssetService.Get( 305 m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset)
289 item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset) 306 {
290 { 307 if (null == asset)
291 if (null == asset) 308 {
292 { 309 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
293 m_log.ErrorFormat( 310 StoreScriptError(item.ItemID, msg);
294 "[PRIM INVENTORY]: " + 311 m_log.ErrorFormat(
295 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 312 "[PRIM INVENTORY]: " +
296 item.Name, item.ItemID, m_part.AbsolutePosition, 313 "Couldn't start script {0}, {1} at {2} in {3} since {4}",
297 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); 314 item.Name, item.ItemID, m_part.AbsolutePosition,
298 } 315 m_part.ParentGroup.Scene.RegionInfo.RegionName, msg);
299 else 316 }
300 { 317 else
301 lock (m_items) 318 {
302 { 319 if (m_part.ParentGroup.m_savedScriptState != null)
303 if (m_part.ParentGroup.m_savedScriptState != null) 320 RestoreSavedScriptState(item.OldItemID, item.ItemID);
304 RestoreSavedScriptState(item.OldItemID, item.ItemID); 321 m_items.LockItemsForWrite(true);
305 322 m_items[item.ItemID].PermsMask = 0;
306 m_items[item.ItemID].PermsMask = 0; 323 m_items[item.ItemID].PermsGranter = UUID.Zero;
307 m_items[item.ItemID].PermsGranter = UUID.Zero; 324 m_items.LockItemsForWrite(false);
308 325 string script = Utils.BytesToString(asset.Data);
309 string script = Utils.BytesToString(asset.Data); 326 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
310 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 327 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
311 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 328 StoreScriptErrors(item.ItemID, null);
312 m_part.ParentGroup.AddActiveScriptCount(1); 329 m_part.ParentGroup.AddActiveScriptCount(1);
313 m_part.ScheduleFullUpdate(); 330 m_part.ScheduleFullUpdate();
314 } 331 }
315 } 332 });
316 } 333 }
317 ); 334 else
335 {
336 StoreScriptError(item.ItemID, "scripts disabled");
318 } 337 }
319 } 338 }
320 339
@@ -375,27 +394,145 @@ namespace OpenSim.Region.Framework.Scenes
375 394
376 /// <summary> 395 /// <summary>
377 /// Start a script which is in this prim's inventory. 396 /// Start a script which is in this prim's inventory.
397 /// Some processing may occur in the background, but this routine returns asap.
378 /// </summary> 398 /// </summary>
379 /// <param name="itemId"> 399 /// <param name="itemId">
380 /// A <see cref="UUID"/> 400 /// A <see cref="UUID"/>
381 /// </param> 401 /// </param>
382 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 402 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
383 { 403 {
384 lock (m_items) 404 lock (m_scriptErrors)
405 {
406 // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion
407 m_scriptErrors.Remove(itemId);
408 }
409 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
410 }
411
412 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
413 {
414 m_items.LockItemsForRead(true);
415 if (m_items.ContainsKey(itemId))
385 { 416 {
386 if (m_items.ContainsKey(itemId)) 417 if (m_items.ContainsKey(itemId))
387 { 418 {
419 m_items.LockItemsForRead(false);
388 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); 420 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
389 } 421 }
390 else 422 else
391 { 423 {
424 m_items.LockItemsForRead(false);
425 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
426 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
427 StoreScriptError(itemId, msg);
392 m_log.ErrorFormat( 428 m_log.ErrorFormat(
393 "[PRIM INVENTORY]: " + 429 "[PRIM INVENTORY]: " +
394 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 430 "Couldn't start script with ID {0} since it {1}", itemId, msg);
395 itemId, m_part.Name, m_part.UUID, 431 }
396 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 432 }
433 else
434 {
435 m_items.LockItemsForRead(false);
436 string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID);
437 StoreScriptError(itemId, msg);
438 m_log.ErrorFormat(
439 "[PRIM INVENTORY]: " +
440 "Couldn't start script with ID {0} since it {1}", itemId, msg);
441 }
442
443 }
444
445 /// <summary>
446 /// Start a script which is in this prim's inventory and return any compilation error messages.
447 /// </summary>
448 /// <param name="itemId">
449 /// A <see cref="UUID"/>
450 /// </param>
451 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
452 {
453 ArrayList errors;
454
455 // Indicate to CreateScriptInstanceInternal() we want it to
456 // post any compilation/loading error messages
457 lock (m_scriptErrors)
458 {
459 m_scriptErrors[itemId] = null;
460 }
461
462 // Perform compilation/loading
463 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
464
465 // Wait for and retrieve any errors
466 lock (m_scriptErrors)
467 {
468 while ((errors = m_scriptErrors[itemId]) == null)
469 {
470 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
471 {
472 m_log.ErrorFormat(
473 "[PRIM INVENTORY]: " +
474 "timedout waiting for script {0} errors", itemId);
475 errors = m_scriptErrors[itemId];
476 if (errors == null)
477 {
478 errors = new ArrayList(1);
479 errors.Add("timedout waiting for errors");
480 }
481 break;
482 }
397 } 483 }
484 m_scriptErrors.Remove(itemId);
398 } 485 }
486 return errors;
487 }
488
489 // Signal to CreateScriptInstanceEr() that compilation/loading is complete
490 private void StoreScriptErrors(UUID itemId, ArrayList errors)
491 {
492 lock (m_scriptErrors)
493 {
494 // If compilation/loading initiated via CreateScriptInstance(),
495 // it does not want the errors, so just get out
496 if (!m_scriptErrors.ContainsKey(itemId))
497 {
498 return;
499 }
500
501 // Initiated via CreateScriptInstanceEr(), if we know what the
502 // errors are, save them and wake CreateScriptInstanceEr().
503 if (errors != null)
504 {
505 m_scriptErrors[itemId] = errors;
506 System.Threading.Monitor.PulseAll(m_scriptErrors);
507 return;
508 }
509 }
510
511 // Initiated via CreateScriptInstanceEr() but we don't know what
512 // the errors are yet, so retrieve them from the script engine.
513 // This may involve some waiting internal to GetScriptErrors().
514 errors = GetScriptErrors(itemId);
515
516 // Get a default non-null value to indicate success.
517 if (errors == null)
518 {
519 errors = new ArrayList();
520 }
521
522 // Post to CreateScriptInstanceEr() and wake it up
523 lock (m_scriptErrors)
524 {
525 m_scriptErrors[itemId] = errors;
526 System.Threading.Monitor.PulseAll(m_scriptErrors);
527 }
528 }
529
530 // Like StoreScriptErrors(), but just posts a single string message
531 private void StoreScriptError(UUID itemId, string message)
532 {
533 ArrayList errors = new ArrayList(1);
534 errors.Add(message);
535 StoreScriptErrors(itemId, errors);
399 } 536 }
400 537
401 /// <summary> 538 /// <summary>
@@ -408,15 +545,7 @@ namespace OpenSim.Region.Framework.Scenes
408 /// </param> 545 /// </param>
409 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 546 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
410 { 547 {
411 bool scriptPresent = false; 548 if (m_items.ContainsKey(itemId))
412
413 lock (m_items)
414 {
415 if (m_items.ContainsKey(itemId))
416 scriptPresent = true;
417 }
418
419 if (scriptPresent)
420 { 549 {
421 if (!sceneObjectBeingDeleted) 550 if (!sceneObjectBeingDeleted)
422 m_part.RemoveScriptEvents(itemId); 551 m_part.RemoveScriptEvents(itemId);
@@ -442,11 +571,16 @@ namespace OpenSim.Region.Framework.Scenes
442 /// <returns></returns> 571 /// <returns></returns>
443 private bool InventoryContainsName(string name) 572 private bool InventoryContainsName(string name)
444 { 573 {
445 foreach (TaskInventoryItem item in Items.Values) 574 m_items.LockItemsForRead(true);
575 foreach (TaskInventoryItem item in m_items.Values)
446 { 576 {
447 if (item.Name == name) 577 if (item.Name == name)
578 {
579 m_items.LockItemsForRead(false);
448 return true; 580 return true;
581 }
449 } 582 }
583 m_items.LockItemsForRead(false);
450 return false; 584 return false;
451 } 585 }
452 586
@@ -488,13 +622,9 @@ namespace OpenSim.Region.Framework.Scenes
488 /// <param name="item"></param> 622 /// <param name="item"></param>
489 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 623 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
490 { 624 {
491 List<TaskInventoryItem> il; 625 m_items.LockItemsForRead(true);
492 626 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
493 lock (m_items) 627 m_items.LockItemsForRead(false);
494 {
495 il = new List<TaskInventoryItem>(m_items.Values);
496 }
497
498 foreach (TaskInventoryItem i in il) 628 foreach (TaskInventoryItem i in il)
499 { 629 {
500 if (i.Name == item.Name) 630 if (i.Name == item.Name)
@@ -532,15 +662,14 @@ namespace OpenSim.Region.Framework.Scenes
532 item.Name = name; 662 item.Name = name;
533 item.GroupID = m_part.GroupID; 663 item.GroupID = m_part.GroupID;
534 664
535 lock (m_items) 665 m_items.LockItemsForWrite(true);
536 { 666 m_items.Add(item.ItemID, item);
537 m_items.Add(item.ItemID, item); 667 m_items.LockItemsForWrite(false);
538
539 if (allowedDrop) 668 if (allowedDrop)
540 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 669 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
541 else 670 else
542 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 671 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
543 } 672
544 673
545 m_inventorySerial++; 674 m_inventorySerial++;
546 //m_inventorySerial += 2; 675 //m_inventorySerial += 2;
@@ -557,14 +686,13 @@ namespace OpenSim.Region.Framework.Scenes
557 /// <param name="items"></param> 686 /// <param name="items"></param>
558 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 687 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
559 { 688 {
560 lock (m_items) 689 m_items.LockItemsForWrite(true);
690 foreach (TaskInventoryItem item in items)
561 { 691 {
562 foreach (TaskInventoryItem item in items) 692 m_items.Add(item.ItemID, item);
563 { 693 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
564 m_items.Add(item.ItemID, item);
565 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
566 }
567 } 694 }
695 m_items.LockItemsForWrite(false);
568 696
569 m_inventorySerial++; 697 m_inventorySerial++;
570 } 698 }
@@ -577,10 +705,9 @@ namespace OpenSim.Region.Framework.Scenes
577 public TaskInventoryItem GetInventoryItem(UUID itemId) 705 public TaskInventoryItem GetInventoryItem(UUID itemId)
578 { 706 {
579 TaskInventoryItem item; 707 TaskInventoryItem item;
580 708 m_items.LockItemsForRead(true);
581 lock (m_items) 709 m_items.TryGetValue(itemId, out item);
582 m_items.TryGetValue(itemId, out item); 710 m_items.LockItemsForRead(false);
583
584 return item; 711 return item;
585 } 712 }
586 713
@@ -616,51 +743,51 @@ namespace OpenSim.Region.Framework.Scenes
616 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 743 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
617 public bool UpdateInventoryItem(TaskInventoryItem item) 744 public bool UpdateInventoryItem(TaskInventoryItem item)
618 { 745 {
619 lock (m_items) 746 m_items.LockItemsForWrite(true);
747
748 if (m_items.ContainsKey(item.ItemID))
620 { 749 {
621 if (m_items.ContainsKey(item.ItemID)) 750 item.ParentID = m_part.UUID;
751 item.ParentPartID = m_part.UUID;
752 item.Flags = m_items[item.ItemID].Flags;
753 // If group permissions have been set on, check that the groupID is up to date in case it has
754 // changed since permissions were last set.
755 if (item.GroupPermissions != (uint)PermissionMask.None)
756 item.GroupID = m_part.GroupID;
757
758 if (item.AssetID == UUID.Zero)
622 { 759 {
623 item.ParentID = m_part.UUID; 760 item.AssetID = m_items[item.ItemID].AssetID;
624 item.ParentPartID = m_part.UUID; 761 }
625 item.Flags = m_items[item.ItemID].Flags; 762 else if ((InventoryType)item.Type == InventoryType.Notecard)
626 763 {
627 // If group permissions have been set on, check that the groupID is up to date in case it has 764 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
628 // changed since permissions were last set.
629 if (item.GroupPermissions != (uint)PermissionMask.None)
630 item.GroupID = m_part.GroupID;
631
632 if (item.AssetID == UUID.Zero)
633 {
634 item.AssetID = m_items[item.ItemID].AssetID;
635 }
636 else if ((InventoryType)item.Type == InventoryType.Notecard)
637 {
638 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
639 765
640 if (presence != null) 766 if (presence != null)
641 { 767 {
642 presence.ControllingClient.SendAgentAlertMessage( 768 presence.ControllingClient.SendAgentAlertMessage(
643 "Notecard saved", false); 769 "Notecard saved", false);
644 }
645 } 770 }
771 }
646 772
647 m_items[item.ItemID] = item; 773 m_items[item.ItemID] = item;
648 m_inventorySerial++; 774 m_inventorySerial++;
649 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 775 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
650 HasInventoryChanged = true;
651 m_part.ParentGroup.HasGroupChanged = true;
652 776
653 return true; 777 HasInventoryChanged = true;
654 } 778 m_part.ParentGroup.HasGroupChanged = true;
655 else 779 m_items.LockItemsForWrite(false);
656 { 780 return true;
657 m_log.ErrorFormat(
658 "[PRIM INVENTORY]: " +
659 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
660 item.ItemID, m_part.Name, m_part.UUID,
661 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
662 }
663 } 781 }
782 else
783 {
784 m_log.ErrorFormat(
785 "[PRIM INVENTORY]: " +
786 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
787 item.ItemID, m_part.Name, m_part.UUID,
788 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
789 }
790 m_items.LockItemsForWrite(false);
664 791
665 return false; 792 return false;
666 } 793 }
@@ -673,53 +800,54 @@ namespace OpenSim.Region.Framework.Scenes
673 /// in this prim's inventory.</returns> 800 /// in this prim's inventory.</returns>
674 public int RemoveInventoryItem(UUID itemID) 801 public int RemoveInventoryItem(UUID itemID)
675 { 802 {
676 lock (m_items) 803 m_items.LockItemsForRead(true);
804
805 if (m_items.ContainsKey(itemID))
677 { 806 {
678 if (m_items.ContainsKey(itemID)) 807 int type = m_items[itemID].InvType;
808 m_items.LockItemsForRead(false);
809 if (type == 10) // Script
679 { 810 {
680 int type = m_items[itemID].InvType; 811 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
681 if (type == 10) // Script 812 }
682 { 813 m_items.LockItemsForWrite(true);
683 m_part.RemoveScriptEvents(itemID); 814 m_items.Remove(itemID);
684 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 815 m_items.LockItemsForWrite(false);
685 } 816 m_inventorySerial++;
686 m_items.Remove(itemID); 817 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
687 m_inventorySerial++;
688 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
689
690 HasInventoryChanged = true;
691 m_part.ParentGroup.HasGroupChanged = true;
692 818
693 int scriptcount = 0; 819 HasInventoryChanged = true;
694 lock (m_items) 820 m_part.ParentGroup.HasGroupChanged = true;
695 {
696 foreach (TaskInventoryItem item in m_items.Values)
697 {
698 if (item.Type == 10)
699 {
700 scriptcount++;
701 }
702 }
703 }
704 821
705 if (scriptcount <= 0) 822 int scriptcount = 0;
823 m_items.LockItemsForRead(true);
824 foreach (TaskInventoryItem item in m_items.Values)
825 {
826 if (item.Type == 10)
706 { 827 {
707 m_part.RemFlag(PrimFlags.Scripted); 828 scriptcount++;
708 } 829 }
709
710 m_part.ScheduleFullUpdate();
711
712 return type;
713 } 830 }
714 else 831 m_items.LockItemsForRead(false);
832
833
834 if (scriptcount <= 0)
715 { 835 {
716 m_log.ErrorFormat( 836 m_part.RemFlag(PrimFlags.Scripted);
717 "[PRIM INVENTORY]: " +
718 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
719 itemID, m_part.Name, m_part.UUID,
720 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
721 } 837 }
838
839 m_part.ScheduleFullUpdate();
840
841 return type;
842 }
843 else
844 {
845 m_log.ErrorFormat(
846 "[PRIM INVENTORY]: " +
847 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
848 itemID, m_part.Name, m_part.UUID);
722 } 849 }
850 m_items.LockItemsForWrite(false);
723 851
724 return -1; 852 return -1;
725 } 853 }
@@ -772,53 +900,54 @@ namespace OpenSim.Region.Framework.Scenes
772 // isn't available (such as drag from prim inventory to agent inventory) 900 // isn't available (such as drag from prim inventory to agent inventory)
773 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 901 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
774 902
775 lock (m_items) 903 m_items.LockItemsForRead(true);
904
905 foreach (TaskInventoryItem item in m_items.Values)
776 { 906 {
777 foreach (TaskInventoryItem item in m_items.Values) 907 UUID ownerID = item.OwnerID;
778 { 908 uint everyoneMask = 0;
779 UUID ownerID = item.OwnerID; 909 uint baseMask = item.BasePermissions;
780 uint everyoneMask = 0; 910 uint ownerMask = item.CurrentPermissions;
781 uint baseMask = item.BasePermissions; 911 uint groupMask = item.GroupPermissions;
782 uint ownerMask = item.CurrentPermissions;
783 uint groupMask = item.GroupPermissions;
784 912
785 invString.AddItemStart(); 913 invString.AddItemStart();
786 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 914 invString.AddNameValueLine("item_id", item.ItemID.ToString());
787 invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); 915 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
788 916
789 invString.AddPermissionsStart(); 917 invString.AddPermissionsStart();
790 918
791 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 919 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
792 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 920 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
793 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); 921 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
794 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 922 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
795 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 923 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
796 924
797 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 925 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
798 invString.AddNameValueLine("owner_id", ownerID.ToString()); 926 invString.AddNameValueLine("owner_id", ownerID.ToString());
799 927
800 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 928 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
801 929
802 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 930 invString.AddNameValueLine("group_id", item.GroupID.ToString());
803 invString.AddSectionEnd(); 931 invString.AddSectionEnd();
804 932
805 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 933 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
806 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 934 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
807 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 935 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
808 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 936 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
809 937
810 invString.AddSaleStart(); 938 invString.AddSaleStart();
811 invString.AddNameValueLine("sale_type", "not"); 939 invString.AddNameValueLine("sale_type", "not");
812 invString.AddNameValueLine("sale_price", "0"); 940 invString.AddNameValueLine("sale_price", "0");
813 invString.AddSectionEnd(); 941 invString.AddSectionEnd();
814 942
815 invString.AddNameValueLine("name", item.Name + "|"); 943 invString.AddNameValueLine("name", item.Name + "|");
816 invString.AddNameValueLine("desc", item.Description + "|"); 944 invString.AddNameValueLine("desc", item.Description + "|");
817 945
818 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 946 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
819 invString.AddSectionEnd(); 947 invString.AddSectionEnd();
820 }
821 } 948 }
949 int count = m_items.Count;
950 m_items.LockItemsForRead(false);
822 951
823 fileData = Utils.StringToBytes(invString.BuildString); 952 fileData = Utils.StringToBytes(invString.BuildString);
824 953
@@ -839,10 +968,9 @@ namespace OpenSim.Region.Framework.Scenes
839 { 968 {
840 if (HasInventoryChanged) 969 if (HasInventoryChanged)
841 { 970 {
842 lock (Items) 971 Items.LockItemsForRead(true);
843 { 972 datastore.StorePrimInventory(m_part.UUID, Items.Values);
844 datastore.StorePrimInventory(m_part.UUID, Items.Values); 973 Items.LockItemsForRead(false);
845 }
846 974
847 HasInventoryChanged = false; 975 HasInventoryChanged = false;
848 } 976 }
@@ -911,61 +1039,54 @@ namespace OpenSim.Region.Framework.Scenes
911 { 1039 {
912 uint mask=0x7fffffff; 1040 uint mask=0x7fffffff;
913 1041
914 lock (m_items) 1042 foreach (TaskInventoryItem item in m_items.Values)
915 { 1043 {
916 foreach (TaskInventoryItem item in m_items.Values) 1044 if (item.InvType != (int)InventoryType.Object)
917 { 1045 {
918 if (item.InvType != (int)InventoryType.Object) 1046 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
919 { 1047 mask &= ~((uint)PermissionMask.Copy >> 13);
920 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1048 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
921 mask &= ~((uint)PermissionMask.Copy >> 13); 1049 mask &= ~((uint)PermissionMask.Transfer >> 13);
922 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1050 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
923 mask &= ~((uint)PermissionMask.Transfer >> 13); 1051 mask &= ~((uint)PermissionMask.Modify >> 13);
924 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1052 }
925 mask &= ~((uint)PermissionMask.Modify >> 13); 1053 else
926 } 1054 {
927 else 1055 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
928 { 1056 mask &= ~((uint)PermissionMask.Copy >> 13);
929 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1057 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
930 mask &= ~((uint)PermissionMask.Copy >> 13); 1058 mask &= ~((uint)PermissionMask.Transfer >> 13);
931 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1059 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
932 mask &= ~((uint)PermissionMask.Transfer >> 13); 1060 mask &= ~((uint)PermissionMask.Modify >> 13);
933 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
934 mask &= ~((uint)PermissionMask.Modify >> 13);
935 }
936
937 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
938 mask &= ~(uint)PermissionMask.Copy;
939 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
940 mask &= ~(uint)PermissionMask.Transfer;
941 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
942 mask &= ~(uint)PermissionMask.Modify;
943 } 1061 }
1062
1063 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1064 mask &= ~(uint)PermissionMask.Copy;
1065 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1066 mask &= ~(uint)PermissionMask.Transfer;
1067 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1068 mask &= ~(uint)PermissionMask.Modify;
944 } 1069 }
945
946 return mask; 1070 return mask;
947 } 1071 }
948 1072
949 public void ApplyNextOwnerPermissions() 1073 public void ApplyNextOwnerPermissions()
950 { 1074 {
951 lock (m_items) 1075 foreach (TaskInventoryItem item in m_items.Values)
952 { 1076 {
953 foreach (TaskInventoryItem item in m_items.Values) 1077 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
954 { 1078 {
955 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1079 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
956 { 1080 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
957 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1081 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
958 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 1082 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
959 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1083 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
960 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 1084 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
961 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 1085 item.CurrentPermissions |= 8;
962 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
963 item.CurrentPermissions |= 8;
964 }
965 item.CurrentPermissions &= item.NextPermissions;
966 item.BasePermissions &= item.NextPermissions;
967 item.EveryonePermissions &= item.NextPermissions;
968 } 1086 }
1087 item.CurrentPermissions &= item.NextPermissions;
1088 item.BasePermissions &= item.NextPermissions;
1089 item.EveryonePermissions &= item.NextPermissions;
969 } 1090 }
970 1091
971 m_part.TriggerScriptChangedEvent(Changed.OWNER); 1092 m_part.TriggerScriptChangedEvent(Changed.OWNER);
@@ -973,29 +1094,22 @@ namespace OpenSim.Region.Framework.Scenes
973 1094
974 public void ApplyGodPermissions(uint perms) 1095 public void ApplyGodPermissions(uint perms)
975 { 1096 {
976 lock (m_items) 1097 foreach (TaskInventoryItem item in m_items.Values)
977 { 1098 {
978 foreach (TaskInventoryItem item in m_items.Values) 1099 item.CurrentPermissions = perms;
979 { 1100 item.BasePermissions = perms;
980 item.CurrentPermissions = perms;
981 item.BasePermissions = perms;
982 }
983 } 1101 }
984 } 1102 }
985 1103
986 public bool ContainsScripts() 1104 public bool ContainsScripts()
987 { 1105 {
988 lock (m_items) 1106 foreach (TaskInventoryItem item in m_items.Values)
989 { 1107 {
990 foreach (TaskInventoryItem item in m_items.Values) 1108 if (item.InvType == (int)InventoryType.LSL)
991 { 1109 {
992 if (item.InvType == (int)InventoryType.LSL) 1110 return true;
993 {
994 return true;
995 }
996 } 1111 }
997 } 1112 }
998
999 return false; 1113 return false;
1000 } 1114 }
1001 1115
@@ -1003,11 +1117,8 @@ namespace OpenSim.Region.Framework.Scenes
1003 { 1117 {
1004 List<UUID> ret = new List<UUID>(); 1118 List<UUID> ret = new List<UUID>();
1005 1119
1006 lock (m_items) 1120 foreach (TaskInventoryItem item in m_items.Values)
1007 { 1121 ret.Add(item.ItemID);
1008 foreach (TaskInventoryItem item in m_items.Values)
1009 ret.Add(item.ItemID);
1010 }
1011 1122
1012 return ret; 1123 return ret;
1013 } 1124 }
@@ -1020,30 +1131,26 @@ namespace OpenSim.Region.Framework.Scenes
1020 if (engines == null) // No engine at all 1131 if (engines == null) // No engine at all
1021 return ret; 1132 return ret;
1022 1133
1023 lock (m_items) 1134 foreach (TaskInventoryItem item in m_items.Values)
1024 { 1135 {
1025 foreach (TaskInventoryItem item in m_items.Values) 1136 if (item.InvType == (int)InventoryType.LSL)
1026 { 1137 {
1027 if (item.InvType == (int)InventoryType.LSL) 1138 foreach (IScriptModule e in engines)
1028 { 1139 {
1029 foreach (IScriptModule e in engines) 1140 if (e != null)
1030 { 1141 {
1031 if (e != null) 1142 string n = e.GetXMLState(item.ItemID);
1143 if (n != String.Empty)
1032 { 1144 {
1033 string n = e.GetXMLState(item.ItemID); 1145 if (!ret.ContainsKey(item.ItemID))
1034 if (n != String.Empty) 1146 ret[item.ItemID] = n;
1035 { 1147 break;
1036 if (!ret.ContainsKey(item.ItemID))
1037 ret[item.ItemID] = n;
1038 break;
1039 }
1040 } 1148 }
1041 } 1149 }
1042 } 1150 }
1043 } 1151 }
1044 } 1152 }
1045
1046 return ret; 1153 return ret;
1047 } 1154 }
1048 } 1155 }
1049} \ No newline at end of file 1156}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 8a633b5..a187844 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
73// { 73// {
74// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
75// } 75// }
76 76
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78 78
79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -89,7 +89,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 90 /// issue #1716
91 /// </summary> 91 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 // Value revised by KF 091121 by comparison with SL.
94 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 95
94 public UUID currentParcelUUID = UUID.Zero; 96 public UUID currentParcelUUID = UUID.Zero;
95 97
@@ -123,8 +125,11 @@ namespace OpenSim.Region.Framework.Scenes
123 public Vector3 lastKnownAllowedPosition; 125 public Vector3 lastKnownAllowedPosition;
124 public bool sentMessageAboutRestrictedParcelFlyingDown; 126 public bool sentMessageAboutRestrictedParcelFlyingDown;
125 public Vector4 CollisionPlane = Vector4.UnitW; 127 public Vector4 CollisionPlane = Vector4.UnitW;
126 128
129 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
130 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
127 private Vector3 m_lastPosition; 131 private Vector3 m_lastPosition;
132 private Vector3 m_lastWorldPosition;
128 private Quaternion m_lastRotation; 133 private Quaternion m_lastRotation;
129 private Vector3 m_lastVelocity; 134 private Vector3 m_lastVelocity;
130 //private int m_lastTerseSent; 135 //private int m_lastTerseSent;
@@ -134,7 +139,6 @@ namespace OpenSim.Region.Framework.Scenes
134 private Vector3? m_forceToApply; 139 private Vector3? m_forceToApply;
135 private uint m_requestedSitTargetID; 140 private uint m_requestedSitTargetID;
136 private UUID m_requestedSitTargetUUID; 141 private UUID m_requestedSitTargetUUID;
137 public bool SitGround = false;
138 142
139 private SendCourseLocationsMethod m_sendCourseLocationsMethod; 143 private SendCourseLocationsMethod m_sendCourseLocationsMethod;
140 144
@@ -156,7 +160,6 @@ namespace OpenSim.Region.Framework.Scenes
156 private int m_perfMonMS; 160 private int m_perfMonMS;
157 161
158 private bool m_setAlwaysRun; 162 private bool m_setAlwaysRun;
159
160 private bool m_forceFly; 163 private bool m_forceFly;
161 private bool m_flyDisabled; 164 private bool m_flyDisabled;
162 165
@@ -182,7 +185,8 @@ namespace OpenSim.Region.Framework.Scenes
182 protected RegionInfo m_regionInfo; 185 protected RegionInfo m_regionInfo;
183 protected ulong crossingFromRegion; 186 protected ulong crossingFromRegion;
184 187
185 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 188 private readonly Vector3[] Dir_Vectors = new Vector3[11];
189 private bool m_isNudging = false;
186 190
187 // Position of agent's camera in world (region cordinates) 191 // Position of agent's camera in world (region cordinates)
188 protected Vector3 m_CameraCenter; 192 protected Vector3 m_CameraCenter;
@@ -207,6 +211,7 @@ namespace OpenSim.Region.Framework.Scenes
207 private bool m_autopilotMoving; 211 private bool m_autopilotMoving;
208 private Vector3 m_autoPilotTarget; 212 private Vector3 m_autoPilotTarget;
209 private bool m_sitAtAutoTarget; 213 private bool m_sitAtAutoTarget;
214 private Vector3 m_initialSitTarget; //KF: First estimate of where to sit
210 215
211 private string m_nextSitAnimation = String.Empty; 216 private string m_nextSitAnimation = String.Empty;
212 217
@@ -217,6 +222,9 @@ namespace OpenSim.Region.Framework.Scenes
217 private bool m_followCamAuto; 222 private bool m_followCamAuto;
218 223
219 private int m_movementUpdateCount; 224 private int m_movementUpdateCount;
225 private int m_lastColCount = -1; //KF: Look for Collision chnages
226 private int m_updateCount = 0; //KF: Update Anims for a while
227 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
220 228
221 private const int NumMovementsBetweenRayCast = 5; 229 private const int NumMovementsBetweenRayCast = 5;
222 230
@@ -245,7 +253,9 @@ namespace OpenSim.Region.Framework.Scenes
245 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 253 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
246 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 254 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
247 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 255 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
248 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 256 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
257 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
258 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
249 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 259 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
250 } 260 }
251 261
@@ -445,8 +455,9 @@ namespace OpenSim.Region.Framework.Scenes
445 get 455 get
446 { 456 {
447 PhysicsActor actor = m_physicsActor; 457 PhysicsActor actor = m_physicsActor;
448 if (actor != null) 458// if (actor != null)
449 m_pos = actor.Position; 459 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
460 m_pos = actor.Position;
450 461
451 return m_parentPosition + m_pos; 462 return m_parentPosition + m_pos;
452 } 463 }
@@ -466,7 +477,8 @@ namespace OpenSim.Region.Framework.Scenes
466 } 477 }
467 } 478 }
468 479
469 m_pos = value; 480 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
481 m_pos = value;
470 m_parentPosition = Vector3.Zero; 482 m_parentPosition = Vector3.Zero;
471 } 483 }
472 } 484 }
@@ -653,7 +665,7 @@ namespace OpenSim.Region.Framework.Scenes
653 CreateSceneViewer(); 665 CreateSceneViewer();
654 m_animator = new ScenePresenceAnimator(this); 666 m_animator = new ScenePresenceAnimator(this);
655 } 667 }
656 668
657 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() 669 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
658 { 670 {
659 m_rootRegionHandle = reginfo.RegionHandle; 671 m_rootRegionHandle = reginfo.RegionHandle;
@@ -680,10 +692,7 @@ namespace OpenSim.Region.Framework.Scenes
680 m_reprioritization_timer.AutoReset = false; 692 m_reprioritization_timer.AutoReset = false;
681 693
682 AdjustKnownSeeds(); 694 AdjustKnownSeeds();
683
684 // TODO: I think, this won't send anything, as we are still a child here...
685 Animator.TrySetMovementAnimation("STAND"); 695 Animator.TrySetMovementAnimation("STAND");
686
687 // we created a new ScenePresence (a new child agent) in a fresh region. 696 // we created a new ScenePresence (a new child agent) in a fresh region.
688 // Request info about all the (root) agents in this region 697 // Request info about all the (root) agents in this region
689 // Note: This won't send data *to* other clients in that region (children don't send) 698 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -739,25 +748,47 @@ namespace OpenSim.Region.Framework.Scenes
739 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 748 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
740 Dir_Vectors[4] = Vector3.UnitZ; //UP 749 Dir_Vectors[4] = Vector3.UnitZ; //UP
741 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 750 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
742 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 751 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
743 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 752 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
744 Dir_Vectors[7] = -Vector3.UnitX; //BACK 753 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
754 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
755 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
745 } 756 }
746 757
747 private Vector3[] GetWalkDirectionVectors() 758 private Vector3[] GetWalkDirectionVectors()
748 { 759 {
749 Vector3[] vector = new Vector3[9]; 760 Vector3[] vector = new Vector3[11];
750 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 761 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
751 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 762 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
752 vector[2] = Vector3.UnitY; //LEFT 763 vector[2] = Vector3.UnitY; //LEFT
753 vector[3] = -Vector3.UnitY; //RIGHT 764 vector[3] = -Vector3.UnitY; //RIGHT
754 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 765 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
755 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 766 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
756 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 767 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
757 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 768 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
758 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 769 vector[8] = Vector3.UnitY; //LEFT_NUDGE
770 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
771 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
759 return vector; 772 return vector;
760 } 773 }
774
775 private bool[] GetDirectionIsNudge()
776 {
777 bool[] isNudge = new bool[11];
778 isNudge[0] = false; //FORWARD
779 isNudge[1] = false; //BACK
780 isNudge[2] = false; //LEFT
781 isNudge[3] = false; //RIGHT
782 isNudge[4] = false; //UP
783 isNudge[5] = false; //DOWN
784 isNudge[6] = true; //FORWARD_NUDGE
785 isNudge[7] = true; //BACK_NUDGE
786 isNudge[8] = true; //LEFT_NUDGE
787 isNudge[9] = true; //RIGHT_NUDGE
788 isNudge[10] = true; //DOWN_Nudge
789 return isNudge;
790 }
791
761 792
762 #endregion 793 #endregion
763 794
@@ -828,6 +859,21 @@ namespace OpenSim.Region.Framework.Scenes
828 pos.Y = crossedBorder.BorderLine.Z - 1; 859 pos.Y = crossedBorder.BorderLine.Z - 1;
829 } 860 }
830 861
862 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
863 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
864 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
865 if (KnownChildRegionHandles.Count == 0)
866 {
867 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
868 if (land != null)
869 {
870 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
871 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && m_godlevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid)
872 {
873 pos = land.LandData.UserLocation;
874 }
875 }
876 }
831 877
832 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) 878 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
833 { 879 {
@@ -988,9 +1034,10 @@ namespace OpenSim.Region.Framework.Scenes
988 public void Teleport(Vector3 pos) 1034 public void Teleport(Vector3 pos)
989 { 1035 {
990 bool isFlying = false; 1036 bool isFlying = false;
1037
991 if (m_physicsActor != null) 1038 if (m_physicsActor != null)
992 isFlying = m_physicsActor.Flying; 1039 isFlying = m_physicsActor.Flying;
993 1040
994 RemoveFromPhysicalScene(); 1041 RemoveFromPhysicalScene();
995 Velocity = Vector3.Zero; 1042 Velocity = Vector3.Zero;
996 AbsolutePosition = pos; 1043 AbsolutePosition = pos;
@@ -1002,6 +1049,7 @@ namespace OpenSim.Region.Framework.Scenes
1002 } 1049 }
1003 1050
1004 SendTerseUpdateToAllClients(); 1051 SendTerseUpdateToAllClients();
1052
1005 } 1053 }
1006 1054
1007 public void TeleportWithMomentum(Vector3 pos) 1055 public void TeleportWithMomentum(Vector3 pos)
@@ -1046,7 +1094,9 @@ namespace OpenSim.Region.Framework.Scenes
1046 { 1094 {
1047 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); 1095 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
1048 } 1096 }
1049 1097
1098 m_updateCount = UPDATE_COUNT; //KF: Trigger Anim updates to catch falling anim.
1099
1050 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 1100 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
1051 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient))); 1101 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
1052 } 1102 }
@@ -1280,7 +1330,6 @@ namespace OpenSim.Region.Framework.Scenes
1280 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1330 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1281 } 1331 }
1282 } 1332 }
1283
1284 lock (scriptedcontrols) 1333 lock (scriptedcontrols)
1285 { 1334 {
1286 if (scriptedcontrols.Count > 0) 1335 if (scriptedcontrols.Count > 0)
@@ -1295,12 +1344,8 @@ namespace OpenSim.Region.Framework.Scenes
1295 1344
1296 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1345 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1297 { 1346 {
1298 // TODO: This doesn't prevent the user from walking yet. 1347 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1299 // Setting parent ID would fix this, if we knew what value 1348 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1300 // to use. Or we could add a m_isSitting variable.
1301 //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1302 SitGround = true;
1303
1304 } 1349 }
1305 1350
1306 // In the future, these values might need to go global. 1351 // In the future, these values might need to go global.
@@ -1350,6 +1395,11 @@ namespace OpenSim.Region.Framework.Scenes
1350 update_rotation = true; 1395 update_rotation = true;
1351 } 1396 }
1352 1397
1398 //guilty until proven innocent..
1399 bool Nudging = true;
1400 //Basically, if there is at least one non-nudge control then we don't need
1401 //to worry about stopping the avatar
1402
1353 if (m_parentID == 0) 1403 if (m_parentID == 0)
1354 { 1404 {
1355 bool bAllowUpdateMoveToPosition = false; 1405 bool bAllowUpdateMoveToPosition = false;
@@ -1364,9 +1414,12 @@ namespace OpenSim.Region.Framework.Scenes
1364 else 1414 else
1365 dirVectors = Dir_Vectors; 1415 dirVectors = Dir_Vectors;
1366 1416
1367 // The fact that m_movementflag is a byte needs to be fixed 1417 bool[] isNudge = GetDirectionIsNudge();
1368 // it really should be a uint 1418
1369 uint nudgehack = 250; 1419
1420
1421
1422
1370 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1423 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1371 { 1424 {
1372 if (((uint)flags & (uint)DCF) != 0) 1425 if (((uint)flags & (uint)DCF) != 0)
@@ -1376,40 +1429,28 @@ namespace OpenSim.Region.Framework.Scenes
1376 try 1429 try
1377 { 1430 {
1378 agent_control_v3 += dirVectors[i]; 1431 agent_control_v3 += dirVectors[i];
1379 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1432 if (isNudge[i] == false)
1433 {
1434 Nudging = false;
1435 }
1380 } 1436 }
1381 catch (IndexOutOfRangeException) 1437 catch (IndexOutOfRangeException)
1382 { 1438 {
1383 // Why did I get this? 1439 // Why did I get this?
1384 } 1440 }
1385 1441
1386 if ((m_movementflag & (byte)(uint)DCF) == 0) 1442 if ((m_movementflag & (uint)DCF) == 0)
1387 { 1443 {
1388 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1389 {
1390 m_movementflag |= (byte)nudgehack;
1391 }
1392 m_movementflag += (byte)(uint)DCF; 1444 m_movementflag += (byte)(uint)DCF;
1393 update_movementflag = true; 1445 update_movementflag = true;
1394 } 1446 }
1395 } 1447 }
1396 else 1448 else
1397 { 1449 {
1398 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1450 if ((m_movementflag & (uint)DCF) != 0)
1399 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1400 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1401 ) // This or is for Nudge forward
1402 { 1451 {
1403 m_movementflag -= ((byte)(uint)DCF); 1452 m_movementflag -= (byte)(uint)DCF;
1404
1405 update_movementflag = true; 1453 update_movementflag = true;
1406 /*
1407 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1408 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1409 {
1410 m_log.Debug("Removed Hack flag");
1411 }
1412 */
1413 } 1454 }
1414 else 1455 else
1415 { 1456 {
@@ -1418,7 +1459,6 @@ namespace OpenSim.Region.Framework.Scenes
1418 } 1459 }
1419 i++; 1460 i++;
1420 } 1461 }
1421
1422 //Paupaw:Do Proper PID for Autopilot here 1462 //Paupaw:Do Proper PID for Autopilot here
1423 if (bResetMoveToPosition) 1463 if (bResetMoveToPosition)
1424 { 1464 {
@@ -1453,6 +1493,9 @@ namespace OpenSim.Region.Framework.Scenes
1453 // Ignore z component of vector 1493 // Ignore z component of vector
1454 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1494 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1455 LocalVectorToTarget2D.Normalize(); 1495 LocalVectorToTarget2D.Normalize();
1496
1497 //We're not nudging
1498 Nudging = false;
1456 agent_control_v3 += LocalVectorToTarget2D; 1499 agent_control_v3 += LocalVectorToTarget2D;
1457 1500
1458 // update avatar movement flags. the avatar coordinate system is as follows: 1501 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1541,13 +1584,13 @@ namespace OpenSim.Region.Framework.Scenes
1541 // m_log.DebugFormat( 1584 // m_log.DebugFormat(
1542 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1585 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1543 1586
1544 AddNewMovement(agent_control_v3, q); 1587 AddNewMovement(agent_control_v3, q, Nudging);
1545 1588
1546 1589
1547 } 1590 }
1548 } 1591 }
1549 1592
1550 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1593 if (update_movementflag)
1551 Animator.UpdateMovementAnimations(); 1594 Animator.UpdateMovementAnimations();
1552 1595
1553 m_scene.EventManager.TriggerOnClientMovement(this); 1596 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1562,7 +1605,6 @@ namespace OpenSim.Region.Framework.Scenes
1562 m_sitAtAutoTarget = false; 1605 m_sitAtAutoTarget = false;
1563 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1606 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1564 //proxy.PCode = (byte)PCode.ParticleSystem; 1607 //proxy.PCode = (byte)PCode.ParticleSystem;
1565
1566 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1608 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1567 proxyObjectGroup.AttachToScene(m_scene); 1609 proxyObjectGroup.AttachToScene(m_scene);
1568 1610
@@ -1604,7 +1646,7 @@ namespace OpenSim.Region.Framework.Scenes
1604 } 1646 }
1605 m_moveToPositionInProgress = true; 1647 m_moveToPositionInProgress = true;
1606 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1648 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1607 } 1649 }
1608 catch (Exception ex) 1650 catch (Exception ex)
1609 { 1651 {
1610 //Why did I get this error? 1652 //Why did I get this error?
@@ -1626,7 +1668,7 @@ namespace OpenSim.Region.Framework.Scenes
1626 Velocity = Vector3.Zero; 1668 Velocity = Vector3.Zero;
1627 SendFullUpdateToAllClients(); 1669 SendFullUpdateToAllClients();
1628 1670
1629 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1671 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1630 } 1672 }
1631 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1673 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1632 m_requestedSitTargetUUID = UUID.Zero; 1674 m_requestedSitTargetUUID = UUID.Zero;
@@ -1659,55 +1701,84 @@ namespace OpenSim.Region.Framework.Scenes
1659 /// </summary> 1701 /// </summary>
1660 public void StandUp() 1702 public void StandUp()
1661 { 1703 {
1662 if (SitGround)
1663 SitGround = false;
1664
1665 if (m_parentID != 0) 1704 if (m_parentID != 0)
1666 { 1705 {
1667 m_log.Debug("StandupCode Executed");
1668 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1706 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1669 if (part != null) 1707 if (part != null)
1670 { 1708 {
1709 part.TaskInventory.LockItemsForRead(true);
1671 TaskInventoryDictionary taskIDict = part.TaskInventory; 1710 TaskInventoryDictionary taskIDict = part.TaskInventory;
1672 if (taskIDict != null) 1711 if (taskIDict != null)
1673 { 1712 {
1674 lock (taskIDict) 1713 foreach (UUID taskID in taskIDict.Keys)
1675 { 1714 {
1676 foreach (UUID taskID in taskIDict.Keys) 1715 UnRegisterControlEventsToScript(LocalId, taskID);
1677 { 1716 taskIDict[taskID].PermsMask &= ~(
1678 UnRegisterControlEventsToScript(LocalId, taskID); 1717 2048 | //PERMISSION_CONTROL_CAMERA
1679 taskIDict[taskID].PermsMask &= ~( 1718 4); // PERMISSION_TAKE_CONTROLS
1680 2048 | //PERMISSION_CONTROL_CAMERA
1681 4); // PERMISSION_TAKE_CONTROLS
1682 }
1683 } 1719 }
1684
1685 } 1720 }
1721 part.TaskInventory.LockItemsForRead(false);
1686 // Reset sit target. 1722 // Reset sit target.
1687 if (part.GetAvatarOnSitTarget() == UUID) 1723 if (part.GetAvatarOnSitTarget() == UUID)
1688 part.SetAvatarOnSitTarget(UUID.Zero); 1724 part.SetAvatarOnSitTarget(UUID.Zero);
1689
1690 m_parentPosition = part.GetWorldPosition(); 1725 m_parentPosition = part.GetWorldPosition();
1691 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1726 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1692 } 1727 }
1728 // part.GetWorldRotation() is the rotation of the object being sat on
1729 // Rotation is the sittiing Av's rotation
1730
1731 Quaternion partRot;
1732// if (part.LinkNum == 1)
1733// { // Root prim of linkset
1734// partRot = part.ParentGroup.RootPart.RotationOffset;
1735// }
1736// else
1737// { // single or child prim
1738
1739// }
1740 if (part == null) //CW: Part may be gone. llDie() for example.
1741 {
1742 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1743 }
1744 else
1745 {
1746 partRot = part.GetWorldRotation();
1747 }
1748
1749 Quaternion partIRot = Quaternion.Inverse(partRot);
1750
1751 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1752 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1693 1753
1754
1694 if (m_physicsActor == null) 1755 if (m_physicsActor == null)
1695 { 1756 {
1696 AddToPhysicalScene(false); 1757 AddToPhysicalScene(false);
1697 } 1758 }
1698 1759 //CW: If the part isn't null then we can set the current position
1699 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1760 if (part != null)
1700 m_parentPosition = Vector3.Zero; 1761 {
1701 1762 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + (m_pos * partRot); // + av sit offset!
1702 m_parentID = 0; 1763 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1764 part.IsOccupied = false;
1765 }
1766 else
1767 {
1768 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1769 AbsolutePosition = m_lastWorldPosition;
1770 }
1771
1772 m_parentPosition = Vector3.Zero;
1773 m_parentID = 0;
1703 SendFullUpdateToAllClients(); 1774 SendFullUpdateToAllClients();
1704 m_requestedSitTargetID = 0; 1775 m_requestedSitTargetID = 0;
1776
1705 if ((m_physicsActor != null) && (m_avHeight > 0)) 1777 if ((m_physicsActor != null) && (m_avHeight > 0))
1706 { 1778 {
1707 SetHeight(m_avHeight); 1779 SetHeight(m_avHeight);
1708 } 1780 }
1709 } 1781 }
1710
1711 Animator.TrySetMovementAnimation("STAND"); 1782 Animator.TrySetMovementAnimation("STAND");
1712 } 1783 }
1713 1784
@@ -1738,13 +1809,9 @@ namespace OpenSim.Region.Framework.Scenes
1738 Vector3 avSitOffSet = part.SitTargetPosition; 1809 Vector3 avSitOffSet = part.SitTargetPosition;
1739 Quaternion avSitOrientation = part.SitTargetOrientation; 1810 Quaternion avSitOrientation = part.SitTargetOrientation;
1740 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1811 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1741 1812 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1742 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1813 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1743 bool SitTargetisSet = 1814 if (SitTargetisSet && !SitTargetOccupied)
1744 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1745 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1746
1747 if (SitTargetisSet && SitTargetUnOccupied)
1748 { 1815 {
1749 //switch the target to this prim 1816 //switch the target to this prim
1750 return part; 1817 return part;
@@ -1758,84 +1825,152 @@ namespace OpenSim.Region.Framework.Scenes
1758 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1825 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1759 { 1826 {
1760 bool autopilot = true; 1827 bool autopilot = true;
1828 Vector3 autopilotTarget = new Vector3();
1829 Quaternion sitOrientation = Quaternion.Identity;
1761 Vector3 pos = new Vector3(); 1830 Vector3 pos = new Vector3();
1762 Quaternion sitOrientation = pSitOrientation;
1763 Vector3 cameraEyeOffset = Vector3.Zero; 1831 Vector3 cameraEyeOffset = Vector3.Zero;
1764 Vector3 cameraAtOffset = Vector3.Zero; 1832 Vector3 cameraAtOffset = Vector3.Zero;
1765 bool forceMouselook = false; 1833 bool forceMouselook = false;
1766 1834
1767 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1835 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1768 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1836 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1769 if (part != null) 1837 if (part == null) return;
1770 { 1838
1771 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1839 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1772 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1840 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1773 1841
1774 // Is a sit target available? 1842 // part is the prim to sit on
1775 Vector3 avSitOffSet = part.SitTargetPosition; 1843 // offset is the world-ref vector distance from that prim center to the click-spot
1776 Quaternion avSitOrientation = part.SitTargetOrientation; 1844 // UUID is the UUID of the Avatar doing the clicking
1777 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1845
1778 1846 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1779 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1847
1780 bool SitTargetisSet = 1848 // Is a sit target available?
1781 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1849 Vector3 avSitOffSet = part.SitTargetPosition;
1782 ( 1850 Quaternion avSitOrientation = part.SitTargetOrientation;
1783 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1851
1784 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1852 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1785 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1853 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1786 ) 1854 Quaternion partRot;
1787 )); 1855// if (part.LinkNum == 1)
1788 1856// { // Root prim of linkset
1789 if (SitTargetisSet && SitTargetUnOccupied) 1857// partRot = part.ParentGroup.RootPart.RotationOffset;
1790 { 1858// }
1791 part.SetAvatarOnSitTarget(UUID); 1859// else
1792 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1860// { // single or child prim
1793 sitOrientation = avSitOrientation; 1861 partRot = part.GetWorldRotation();
1794 autopilot = false; 1862// }
1795 } 1863 Quaternion partIRot = Quaternion.Inverse(partRot);
1796 1864//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1797 pos = part.AbsolutePosition + offset; 1865 // Sit analysis rewritten by KF 091125
1798 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1866 if (SitTargetisSet) // scipted sit
1799 //{ 1867 {
1800 // offset = pos; 1868 if (!part.IsOccupied)
1801 //autopilot = false; 1869 {
1802 //} 1870//Console.WriteLine("Scripted, unoccupied");
1803 if (m_physicsActor != null) 1871 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1804 { 1872 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1805 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1873 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1806 // We can remove the physicsActor until they stand up. 1874 autopilot = false; // Jump direct to scripted llSitPos()
1807 m_sitAvatarHeight = m_physicsActor.Size.Z; 1875 }
1808 1876 else
1809 if (autopilot) 1877 {
1810 { 1878//Console.WriteLine("Scripted, occupied");
1811 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1879 return;
1812 { 1880 }
1813 autopilot = false; 1881 }
1882 else // Not Scripted
1883 {
1884 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1885 {
1886 // large prim & offset, ignore if other Avs sitting
1887// offset.Z -= 0.05f;
1888 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1889 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1890
1891//Console.WriteLine(" offset ={0}", offset);
1892//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1893//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1894
1895 }
1896 else // small offset
1897 {
1898//Console.WriteLine("Small offset");
1899 if (!part.IsOccupied)
1900 {
1901 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1902 autopilotTarget = part.AbsolutePosition;
1903 }
1904 else return; // occupied small
1905 } // end large/small
1906 } // end Scripted/not
1907 cameraAtOffset = part.GetCameraAtOffset();
1908 cameraEyeOffset = part.GetCameraEyeOffset();
1909 forceMouselook = part.GetForceMouselook();
1910 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1911 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1814 1912
1815 RemoveFromPhysicalScene(); 1913 if (m_physicsActor != null)
1816 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1914 {
1817 } 1915 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1818 } 1916 // We can remove the physicsActor until they stand up.
1819 else 1917 m_sitAvatarHeight = m_physicsActor.Size.Z;
1918 if (autopilot)
1919 { // its not a scripted sit
1920// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1921 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1820 { 1922 {
1923 autopilot = false; // close enough
1924 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1925 Not using the part's position because returning the AV to the last known standing
1926 position is likely to be more friendly, isn't it? */
1821 RemoveFromPhysicalScene(); 1927 RemoveFromPhysicalScene();
1822 } 1928 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1929 } // else the autopilot will get us close
1930 }
1931 else
1932 { // its a scripted sit
1933 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1934 I *am* using the part's position this time because we have no real idea how far away
1935 the avatar is from the sit target. */
1936 RemoveFromPhysicalScene();
1823 } 1937 }
1824
1825 cameraAtOffset = part.GetCameraAtOffset();
1826 cameraEyeOffset = part.GetCameraEyeOffset();
1827 forceMouselook = part.GetForceMouselook();
1828 } 1938 }
1829 1939 else return; // physactor is null!
1830 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 1940
1831 m_requestedSitTargetUUID = targetID; 1941 Vector3 offsetr; // = offset * partIRot;
1942 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
1943 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
1944 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
1945 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
1946 offsetr = offset * partIRot;
1947//
1948 // else
1949 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
1950 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
1951 // (offset * partRot);
1952 // }
1953
1954//Console.WriteLine(" ");
1955//Console.WriteLine("link number ={0}", part.LinkNum);
1956//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
1957//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
1958//Console.WriteLine("Click offst ={0}", offset);
1959//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
1960//Console.WriteLine("offsetr ={0}", offsetr);
1961//Console.WriteLine("Camera At ={0}", cameraAtOffset);
1962//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
1963
1964 ControllingClient.SendSitResponse(part.UUID, offsetr, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
1965 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1832 // This calls HandleAgentSit twice, once from here, and the client calls 1966 // This calls HandleAgentSit twice, once from here, and the client calls
1833 // HandleAgentSit itself after it gets to the location 1967 // HandleAgentSit itself after it gets to the location
1834 // It doesn't get to the location until we've moved them there though 1968 // It doesn't get to the location until we've moved them there though
1835 // which happens in HandleAgentSit :P 1969 // which happens in HandleAgentSit :P
1836 m_autopilotMoving = autopilot; 1970 m_autopilotMoving = autopilot;
1837 m_autoPilotTarget = pos; 1971 m_autoPilotTarget = autopilotTarget;
1838 m_sitAtAutoTarget = autopilot; 1972 m_sitAtAutoTarget = autopilot;
1973 m_initialSitTarget = autopilotTarget;
1839 if (!autopilot) 1974 if (!autopilot)
1840 HandleAgentSit(remoteClient, UUID); 1975 HandleAgentSit(remoteClient, UUID);
1841 } 1976 }
@@ -2130,31 +2265,65 @@ namespace OpenSim.Region.Framework.Scenes
2130 { 2265 {
2131 if (part != null) 2266 if (part != null)
2132 { 2267 {
2268//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2133 if (part.GetAvatarOnSitTarget() == UUID) 2269 if (part.GetAvatarOnSitTarget() == UUID)
2134 { 2270 {
2271//Console.WriteLine("Scripted Sit");
2272 // Scripted sit
2135 Vector3 sitTargetPos = part.SitTargetPosition; 2273 Vector3 sitTargetPos = part.SitTargetPosition;
2136 Quaternion sitTargetOrient = part.SitTargetOrientation; 2274 Quaternion sitTargetOrient = part.SitTargetOrientation;
2137
2138 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2139 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2140
2141 //Quaternion result = (sitTargetOrient * vq) * nq;
2142
2143 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2275 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2144 m_pos += SIT_TARGET_ADJUSTMENT; 2276 m_pos += SIT_TARGET_ADJUSTMENT;
2145 m_bodyRot = sitTargetOrient; 2277 m_bodyRot = sitTargetOrient;
2146 //Rotation = sitTargetOrient;
2147 m_parentPosition = part.AbsolutePosition; 2278 m_parentPosition = part.AbsolutePosition;
2148 2279 part.IsOccupied = true;
2149 //SendTerseUpdateToAllClients();
2150 } 2280 }
2151 else 2281 else
2152 { 2282 {
2153 m_pos -= part.AbsolutePosition; 2283 // if m_avUnscriptedSitPos is zero then Av sits above center
2284 // Else Av sits at m_avUnscriptedSitPos
2285
2286 // Non-scripted sit by Kitto Flora 21Nov09
2287 // Calculate angle of line from prim to Av
2288 Quaternion partIRot;
2289// if (part.LinkNum == 1)
2290// { // Root prim of linkset
2291// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2292// }
2293// else
2294// { // single or child prim
2295 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2296// }
2297 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2298 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2299 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2300 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2301 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2302 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2303 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2304 // Av sits at world euler <0,0, z>, translated by part rotation
2305 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2306
2154 m_parentPosition = part.AbsolutePosition; 2307 m_parentPosition = part.AbsolutePosition;
2155 } 2308 part.IsOccupied = true;
2309 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2310 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2311 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2312 m_avUnscriptedSitPos; // adds click offset, if any
2313 //Set up raytrace to find top surface of prim
2314 Vector3 size = part.Scale;
2315 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2316 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2317 Vector3 down = new Vector3(0f, 0f, -1f);
2318//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2319 m_scene.PhysicsScene.RaycastWorld(
2320 start, // Vector3 position,
2321 down, // Vector3 direction,
2322 mag, // float length,
2323 SitAltitudeCallback); // retMethod
2324 } // end scripted/not
2156 } 2325 }
2157 else 2326 else // no Av
2158 { 2327 {
2159 return; 2328 return;
2160 } 2329 }
@@ -2166,11 +2335,39 @@ namespace OpenSim.Region.Framework.Scenes
2166 2335
2167 Animator.TrySetMovementAnimation(sitAnimation); 2336 Animator.TrySetMovementAnimation(sitAnimation);
2168 SendFullUpdateToAllClients(); 2337 SendFullUpdateToAllClients();
2169 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2170 // So we're also sending a terse update (which has avatar rotation)
2171 // [Update] We do now.
2172 //SendTerseUpdateToAllClients();
2173 } 2338 }
2339
2340 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2341 {
2342 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2343 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2344 if(hitYN)
2345 {
2346 // m_pos = Av offset from prim center to make look like on center
2347 // m_parentPosition = Actual center pos of prim
2348 // collisionPoint = spot on prim where we want to sit
2349 // collisionPoint.Z = global sit surface height
2350 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2351 Quaternion partIRot;
2352// if (part.LinkNum == 1)
2353/// { // Root prim of linkset
2354// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2355// }
2356// else
2357// { // single or child prim
2358 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2359// }
2360 if (m_initialSitTarget != null)
2361 {
2362 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2363 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2364 //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2365 m_pos += offset;
2366 // ControllingClient.SendClearFollowCamProperties(part.UUID);
2367 }
2368
2369 }
2370 } // End SitAltitudeCallback KF.
2174 2371
2175 /// <summary> 2372 /// <summary>
2176 /// Event handler for the 'Always run' setting on the client 2373 /// Event handler for the 'Always run' setting on the client
@@ -2200,7 +2397,7 @@ namespace OpenSim.Region.Framework.Scenes
2200 /// </summary> 2397 /// </summary>
2201 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2398 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2202 /// <param name="rotation">The direction in which this avatar should now face. 2399 /// <param name="rotation">The direction in which this avatar should now face.
2203 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2400 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2204 { 2401 {
2205 if (m_isChildAgent) 2402 if (m_isChildAgent)
2206 { 2403 {
@@ -2238,10 +2435,11 @@ namespace OpenSim.Region.Framework.Scenes
2238 Rotation = rotation; 2435 Rotation = rotation;
2239 Vector3 direc = vec * rotation; 2436 Vector3 direc = vec * rotation;
2240 direc.Normalize(); 2437 direc.Normalize();
2438 PhysicsActor actor = m_physicsActor;
2439 if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up.
2241 2440
2242 direc *= 0.03f * 128f * m_speedModifier; 2441 direc *= 0.03f * 128f * m_speedModifier;
2243 2442
2244 PhysicsActor actor = m_physicsActor;
2245 if (actor != null) 2443 if (actor != null)
2246 { 2444 {
2247 if (actor.Flying) 2445 if (actor.Flying)
@@ -2263,18 +2461,25 @@ namespace OpenSim.Region.Framework.Scenes
2263 { 2461 {
2264 if (direc.Z > 2.0f) 2462 if (direc.Z > 2.0f)
2265 { 2463 {
2266 direc.Z *= 3.0f; 2464 if(m_animator.m_animTickJump == -1)
2267 2465 {
2268 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2466 direc.Z *= 3.0f; // jump
2269 Animator.TrySetMovementAnimation("PREJUMP"); 2467 }
2270 Animator.TrySetMovementAnimation("JUMP"); 2468 else
2469 {
2470 direc.Z *= 0.1f; // prejump
2471 }
2472 /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
2473 Animator.TrySetMovementAnimation("PREJUMP");
2474 Animator.TrySetMovementAnimation("JUMP");
2475 */
2271 } 2476 }
2272 } 2477 }
2273 } 2478 }
2274 2479
2275 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2480 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2276 m_forceToApply = direc; 2481 m_forceToApply = direc;
2277 2482 m_isNudging = Nudging;
2278 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2483 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2279 } 2484 }
2280 2485
@@ -2289,7 +2494,7 @@ namespace OpenSim.Region.Framework.Scenes
2289 const float POSITION_TOLERANCE = 0.05f; 2494 const float POSITION_TOLERANCE = 0.05f;
2290 //const int TIME_MS_TOLERANCE = 3000; 2495 //const int TIME_MS_TOLERANCE = 3000;
2291 2496
2292 SendPrimUpdates(); 2497
2293 2498
2294 if (m_newCoarseLocations) 2499 if (m_newCoarseLocations)
2295 { 2500 {
@@ -2325,6 +2530,9 @@ namespace OpenSim.Region.Framework.Scenes
2325 CheckForBorderCrossing(); 2530 CheckForBorderCrossing();
2326 CheckForSignificantMovement(); // sends update to the modules. 2531 CheckForSignificantMovement(); // sends update to the modules.
2327 } 2532 }
2533
2534 //Sending prim updates AFTER the avatar terse updates are sent
2535 SendPrimUpdates();
2328 } 2536 }
2329 2537
2330 #endregion 2538 #endregion
@@ -3225,14 +3433,25 @@ namespace OpenSim.Region.Framework.Scenes
3225 { 3433 {
3226 if (m_forceToApply.HasValue) 3434 if (m_forceToApply.HasValue)
3227 { 3435 {
3228 Vector3 force = m_forceToApply.Value;
3229 3436
3437 Vector3 force = m_forceToApply.Value;
3230 m_updateflag = true; 3438 m_updateflag = true;
3231// movementvector = force;
3232 Velocity = force; 3439 Velocity = force;
3233 3440
3234 m_forceToApply = null; 3441 m_forceToApply = null;
3235 } 3442 }
3443 else
3444 {
3445 if (m_isNudging)
3446 {
3447 Vector3 force = Vector3.Zero;
3448
3449 m_updateflag = true;
3450 Velocity = force;
3451 m_isNudging = false;
3452 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3453 }
3454 }
3236 } 3455 }
3237 3456
3238 public override void SetText(string text, Vector3 color, double alpha) 3457 public override void SetText(string text, Vector3 color, double alpha)
@@ -3283,18 +3502,29 @@ namespace OpenSim.Region.Framework.Scenes
3283 { 3502 {
3284 if (e == null) 3503 if (e == null)
3285 return; 3504 return;
3286 3505
3287 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3506 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3288 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3289 // as of this comment the interval is set in AddToPhysicalScene 3507 // as of this comment the interval is set in AddToPhysicalScene
3290 if (Animator!=null) 3508 if (Animator!=null)
3291 Animator.UpdateMovementAnimations(); 3509 {
3510 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3511 { // else its will lock out other animation changes, like ground sit.
3512 Animator.UpdateMovementAnimations();
3513 m_updateCount--;
3514 }
3515 }
3292 3516
3293 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3517 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3294 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3518 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3295 3519
3296 CollisionPlane = Vector4.UnitW; 3520 CollisionPlane = Vector4.UnitW;
3297 3521
3522 if (m_lastColCount != coldata.Count)
3523 {
3524 m_updateCount = UPDATE_COUNT;
3525 m_lastColCount = coldata.Count;
3526 }
3527
3298 if (coldata.Count != 0 && Animator != null) 3528 if (coldata.Count != 0 && Animator != null)
3299 { 3529 {
3300 switch (Animator.CurrentMovementAnimation) 3530 switch (Animator.CurrentMovementAnimation)
@@ -3933,5 +4163,16 @@ namespace OpenSim.Region.Framework.Scenes
3933 m_reprioritization_called = false; 4163 m_reprioritization_called = false;
3934 } 4164 }
3935 } 4165 }
4166
4167 private Vector3 Quat2Euler(Quaternion rot){
4168 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4169 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4170 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4171 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4172 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4173 return(new Vector3(x,y,z));
4174 }
4175
4176
3936 } 4177 }
3937} 4178}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index 23663dd..9799872 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -82,7 +82,7 @@ namespace OpenSim.Region.Framework.Scenes
82 82
83 foreach (EntityBase e in m_presence.Scene.Entities) 83 foreach (EntityBase e in m_presence.Scene.Entities)
84 { 84 {
85 if (e is SceneObjectGroup) 85 if (e != null && e is SceneObjectGroup)
86 m_pendingObjects.Enqueue((SceneObjectGroup)e); 86 m_pendingObjects.Enqueue((SceneObjectGroup)e);
87 } 87 }
88 } 88 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
index 8a27b7b..5abbb82 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -101,7 +101,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests
101 { 101 {
102 throw new NotImplementedException(); 102 throw new NotImplementedException();
103 } 103 }
104 104 public RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID)
105 {
106 //This connector doesn't support the windlight module yet
107 //Return default LL windlight settings
108 return new RegionMeta7WindlightData();
109 }
110 public void StoreRegionWindlightSettings(RegionMeta7WindlightData wl)
111 {
112 //This connector doesn't support the windlight module yet
113 }
105 public RegionSettings LoadRegionSettings(UUID regionUUID) 114 public RegionSettings LoadRegionSettings(UUID regionUUID)
106 { 115 {
107 return null; 116 return null;