aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-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.cs718
-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
15 files changed, 1595 insertions, 848 deletions
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 aa724c5..4019c12 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)
@@ -1578,9 +1581,10 @@ namespace OpenSim.Region.Framework.Scenes
1578 if (remoteClient != null) 1581 if (remoteClient != null)
1579 { 1582 {
1580 permissionToTake = 1583 permissionToTake =
1581 Permissions.CanReturnObject( 1584 Permissions.CanReturnObjects(
1582 grp.UUID, 1585 null,
1583 remoteClient.AgentId); 1586 remoteClient.AgentId,
1587 new List<SceneObjectGroup>() {grp});
1584 permissionToDelete = permissionToTake; 1588 permissionToDelete = permissionToTake;
1585 1589
1586 if (permissionToDelete) 1590 if (permissionToDelete)
@@ -1805,8 +1809,13 @@ namespace OpenSim.Region.Framework.Scenes
1805 } 1809 }
1806 else 1810 else
1807 { 1811 {
1808 item.BasePermissions = objectGroup.GetEffectivePermissions(); 1812 uint ownerPerms = objectGroup.GetEffectivePermissions();
1809 item.CurrentPermissions = objectGroup.GetEffectivePermissions(); 1813 if ((objectGroup.RootPart.OwnerMask & (uint)PermissionMask.Modify) != 0)
1814 ownerPerms |= (uint)PermissionMask.Modify;
1815
1816 item.BasePermissions = ownerPerms;
1817 item.CurrentPermissions = ownerPerms;
1818
1810 item.NextPermissions = objectGroup.RootPart.NextOwnerMask; 1819 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1811 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask; 1820 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
1812 item.GroupPermissions = objectGroup.RootPart.GroupMask; 1821 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 f8ca047..a3c5a03 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -158,6 +158,20 @@ namespace OpenSim.Region.Framework.Scenes
158 158
159 public IXfer XferManager; 159 public IXfer XferManager;
160 160
161 protected ISnmpModule m_snmpService = null;
162 public ISnmpModule SnmpService
163 {
164 get
165 {
166 if (m_snmpService == null)
167 {
168 m_snmpService = RequestModuleInterface<ISnmpModule>();
169 }
170
171 return m_snmpService;
172 }
173 }
174
161 protected IAssetService m_AssetService; 175 protected IAssetService m_AssetService;
162 protected IAuthorizationService m_AuthorizationService; 176 protected IAuthorizationService m_AuthorizationService;
163 177
@@ -539,6 +553,8 @@ namespace OpenSim.Region.Framework.Scenes
539 553
540 // Load region settings 554 // Load region settings
541 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); 555 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID);
556 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(m_regInfo.RegionID);
557
542 if (m_storageManager.EstateDataStore != null) 558 if (m_storageManager.EstateDataStore != null)
543 { 559 {
544 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 560 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID);
@@ -597,7 +613,7 @@ namespace OpenSim.Region.Framework.Scenes
597 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); 613 m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false);
598 // TODO: Change default to true once the feature is supported 614 // TODO: Change default to true once the feature is supported
599 m_usePreJump = startupConfig.GetBoolean("enableprejump", false); 615 m_usePreJump = startupConfig.GetBoolean("enableprejump", false);
600 616 m_usePreJump = true; // Above line fails!?
601 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); 617 m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys);
602 if (RegionInfo.NonphysPrimMax > 0) 618 if (RegionInfo.NonphysPrimMax > 0)
603 { 619 {
@@ -886,6 +902,15 @@ namespace OpenSim.Region.Framework.Scenes
886 /// <param name="seconds">float indicating duration before restart.</param> 902 /// <param name="seconds">float indicating duration before restart.</param>
887 public virtual void Restart(float seconds) 903 public virtual void Restart(float seconds)
888 { 904 {
905 Restart(seconds, true);
906 }
907
908 /// <summary>
909 /// Given float seconds, this will restart the region. showDialog will optionally alert the users.
910 /// </summary>
911 /// <param name="seconds">float indicating duration before restart.</param>
912 public virtual void Restart(float seconds, bool showDialog)
913 {
889 // notifications are done in 15 second increments 914 // notifications are done in 15 second increments
890 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request 915 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request
891 // It's a 'Cancel restart' request. 916 // It's a 'Cancel restart' request.
@@ -906,8 +931,11 @@ namespace OpenSim.Region.Framework.Scenes
906 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); 931 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed);
907 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); 932 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes");
908 m_restartTimer.Start(); 933 m_restartTimer.Start();
909 m_dialogModule.SendNotificationToUsersInRegion( 934 if (showDialog)
935 {
936 m_dialogModule.SendNotificationToUsersInRegion(
910 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); 937 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0)));
938 }
911 } 939 }
912 } 940 }
913 941
@@ -1189,16 +1217,16 @@ namespace OpenSim.Region.Framework.Scenes
1189 // Check if any objects have reached their targets 1217 // Check if any objects have reached their targets
1190 CheckAtTargets(); 1218 CheckAtTargets();
1191 1219
1192 // Update SceneObjectGroups that have scheduled themselves for updates
1193 // Objects queue their updates onto all scene presences
1194 if (m_frame % m_update_objects == 0)
1195 m_sceneGraph.UpdateObjectGroups();
1196
1197 // Run through all ScenePresences looking for updates 1220 // Run through all ScenePresences looking for updates
1198 // Presence updates and queued object updates for each presence are sent to clients 1221 // Presence updates and queued object updates for each presence are sent to clients
1199 if (m_frame % m_update_presences == 0) 1222 if (m_frame % m_update_presences == 0)
1200 m_sceneGraph.UpdatePresences(); 1223 m_sceneGraph.UpdatePresences();
1201 1224
1225 // Update SceneObjectGroups that have scheduled themselves for updates
1226 // Objects queue their updates onto all scene presences
1227 if (m_frame % m_update_objects == 0)
1228 m_sceneGraph.UpdateObjectGroups();
1229
1202 int tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1230 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1203 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1231 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1204 m_sceneGraph.UpdatePreparePhysics(); 1232 m_sceneGraph.UpdatePreparePhysics();
@@ -1511,6 +1539,19 @@ namespace OpenSim.Region.Framework.Scenes
1511 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1539 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1512 } 1540 }
1513 1541
1542 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1543 {
1544 m_regInfo.WindlightSettings = wl;
1545 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
1546 m_eventManager.TriggerOnSaveNewWindlightProfile();
1547 }
1548
1549 public void LoadWindlightProfile()
1550 {
1551 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1552 m_eventManager.TriggerOnSaveNewWindlightProfile();
1553 }
1554
1514 /// <summary> 1555 /// <summary>
1515 /// Loads the World heightmap 1556 /// Loads the World heightmap
1516 /// </summary> 1557 /// </summary>
@@ -3485,6 +3526,9 @@ namespace OpenSim.Region.Framework.Scenes
3485 3526
3486 CapsModule.AddCapsHandler(agent.AgentID); 3527 CapsModule.AddCapsHandler(agent.AgentID);
3487 3528
3529 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3530 System.Threading.Thread.Sleep(2000);
3531
3488 if (!agent.child) 3532 if (!agent.child)
3489 { 3533 {
3490 if (TestBorderCross(agent.startpos,Cardinals.E)) 3534 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3543,6 +3587,7 @@ namespace OpenSim.Region.Framework.Scenes
3543 } 3587 }
3544 } 3588 }
3545 // Honor parcel landing type and position. 3589 // Honor parcel landing type and position.
3590 /*
3546 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 3591 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3547 if (land != null) 3592 if (land != null)
3548 { 3593 {
@@ -3551,6 +3596,7 @@ namespace OpenSim.Region.Framework.Scenes
3551 agent.startpos = land.LandData.UserLocation; 3596 agent.startpos = land.LandData.UserLocation;
3552 } 3597 }
3553 } 3598 }
3599 */// This is now handled properly in ScenePresence.MakeRootAgent
3554 } 3600 }
3555 3601
3556 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3602 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
@@ -4366,6 +4412,14 @@ namespace OpenSim.Region.Framework.Scenes
4366 } 4412 }
4367 4413
4368 /// <summary> 4414 /// <summary>
4415 /// Cheaply return the number of avatars in a region (without fetching a list object)
4416 /// </summary>
4417 public int GetRootAgentCount()
4418 {
4419 return m_sceneGraph.GetRootAgentCount();
4420 }
4421
4422 /// <summary>
4369 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents. 4423 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents.
4370 /// This list is a new object, so it can be iterated over without locking. 4424 /// This list is a new object, so it can be iterated over without locking.
4371 /// </summary> 4425 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 50feb17..9153069 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 fa3c5eb..fb01140 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 71354b4..8b58b3e 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 ba3fde7..318357d 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 ffbb427..3a101cc 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>
@@ -2942,8 +2928,8 @@ namespace OpenSim.Region.Framework.Scenes
2942 { 2928 {
2943 const float ROTATION_TOLERANCE = 0.01f; 2929 const float ROTATION_TOLERANCE = 0.01f;
2944 const float VELOCITY_TOLERANCE = 0.001f; 2930 const float VELOCITY_TOLERANCE = 0.001f;
2945 const float POSITION_TOLERANCE = 0.05f; 2931 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2946 const int TIME_MS_TOLERANCE = 3000; 2932 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2947 2933
2948 if (m_updateFlag == 1) 2934 if (m_updateFlag == 1)
2949 { 2935 {
@@ -2957,7 +2943,7 @@ namespace OpenSim.Region.Framework.Scenes
2957 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2943 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2958 { 2944 {
2959 AddTerseUpdateToAllAvatars(); 2945 AddTerseUpdateToAllAvatars();
2960 ClearUpdateSchedule(); 2946
2961 2947
2962 // This causes the Scene to 'poll' physical objects every couple of frames 2948 // This causes the Scene to 'poll' physical objects every couple of frames
2963 // bad, so it's been replaced by an event driven method. 2949 // bad, so it's been replaced by an event driven method.
@@ -2975,6 +2961,8 @@ namespace OpenSim.Region.Framework.Scenes
2975 m_lastAngularVelocity = AngularVelocity; 2961 m_lastAngularVelocity = AngularVelocity;
2976 m_lastTerseSent = Environment.TickCount; 2962 m_lastTerseSent = Environment.TickCount;
2977 } 2963 }
2964 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
2965 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
2978 } 2966 }
2979 else 2967 else
2980 { 2968 {
@@ -2984,10 +2972,10 @@ namespace OpenSim.Region.Framework.Scenes
2984 m_log.DebugFormat("[SOP]: Sending scheduled full update for {0} {1}", Name, LocalId); 2972 m_log.DebugFormat("[SOP]: Sending scheduled full update for {0} {1}", Name, LocalId);
2985 2973
2986 AddFullUpdateToAllAvatars(); 2974 AddFullUpdateToAllAvatars();
2987 ClearUpdateSchedule(); 2975 m_updateFlag = 0; //Same here
2988 } 2976 }
2989 } 2977 }
2990 ClearUpdateSchedule(); 2978 m_updateFlag = 0;
2991 } 2979 }
2992 2980
2993 /// <summary> 2981 /// <summary>
@@ -3014,17 +3002,16 @@ namespace OpenSim.Region.Framework.Scenes
3014 if (!UUID.TryParse(sound, out soundID)) 3002 if (!UUID.TryParse(sound, out soundID))
3015 { 3003 {
3016 // search sound file from inventory 3004 // search sound file from inventory
3017 lock (TaskInventory) 3005 TaskInventory.LockItemsForRead(true);
3006 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3018 { 3007 {
3019 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3008 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3020 { 3009 {
3021 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3010 soundID = item.Value.ItemID;
3022 { 3011 break;
3023 soundID = item.Value.ItemID;
3024 break;
3025 }
3026 } 3012 }
3027 } 3013 }
3014 TaskInventory.LockItemsForRead(false);
3028 } 3015 }
3029 3016
3030 if (soundID == UUID.Zero) 3017 if (soundID == UUID.Zero)
@@ -3460,7 +3447,7 @@ namespace OpenSim.Region.Framework.Scenes
3460 3447
3461 public void StopLookAt() 3448 public void StopLookAt()
3462 { 3449 {
3463 m_parentGroup.stopLookAt(); 3450 m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup.
3464 3451
3465 m_parentGroup.ScheduleGroupForTerseUpdate(); 3452 m_parentGroup.ScheduleGroupForTerseUpdate();
3466 } 3453 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 21ca1de..a2fceb7 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -46,6 +46,8 @@ namespace OpenSim.Region.Framework.Scenes
46 46
47 private string m_inventoryFileName = String.Empty; 47 private string m_inventoryFileName = String.Empty;
48 private int m_inventoryFileNameSerial = 0; 48 private int m_inventoryFileNameSerial = 0;
49
50 private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>();
49 51
50 /// <value> 52 /// <value>
51 /// The part to which the inventory belongs. 53 /// The part to which the inventory belongs.
@@ -82,7 +84,9 @@ namespace OpenSim.Region.Framework.Scenes
82 /// </value> 84 /// </value>
83 protected internal TaskInventoryDictionary Items 85 protected internal TaskInventoryDictionary Items
84 { 86 {
85 get { return m_items; } 87 get {
88 return m_items;
89 }
86 set 90 set
87 { 91 {
88 m_items = value; 92 m_items = value;
@@ -118,22 +122,25 @@ namespace OpenSim.Region.Framework.Scenes
118 /// <param name="linkNum">Link number for the part</param> 122 /// <param name="linkNum">Link number for the part</param>
119 public void ResetInventoryIDs() 123 public void ResetInventoryIDs()
120 { 124 {
121 lock (Items) 125 m_items.LockItemsForWrite(true);
126
127 if (0 == Items.Count)
122 { 128 {
123 if (0 == Items.Count) 129 m_items.LockItemsForWrite(false);
124 return; 130 return;
131 }
125 132
126 HasInventoryChanged = true; 133 HasInventoryChanged = true;
127 m_part.ParentGroup.HasGroupChanged = true; 134 m_part.ParentGroup.HasGroupChanged = true;
128 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 135 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
129 Items.Clear(); 136 Items.Clear();
130 137
131 foreach (TaskInventoryItem item in items) 138 foreach (TaskInventoryItem item in items)
132 { 139 {
133 item.ResetIDs(m_part.UUID); 140 item.ResetIDs(m_part.UUID);
134 Items.Add(item.ItemID, item); 141 Items.Add(item.ItemID, item);
135 }
136 } 142 }
143 m_items.LockItemsForWrite(false);
137 } 144 }
138 145
139 /// <summary> 146 /// <summary>
@@ -142,25 +149,25 @@ namespace OpenSim.Region.Framework.Scenes
142 /// <param name="ownerId"></param> 149 /// <param name="ownerId"></param>
143 public void ChangeInventoryOwner(UUID ownerId) 150 public void ChangeInventoryOwner(UUID ownerId)
144 { 151 {
145 lock (Items) 152 m_items.LockItemsForWrite(true);
153 if (0 == Items.Count)
146 { 154 {
147 if (0 == Items.Count) 155 m_items.LockItemsForWrite(false);
148 { 156 return;
149 return; 157 }
150 }
151 158
152 HasInventoryChanged = true; 159 HasInventoryChanged = true;
153 m_part.ParentGroup.HasGroupChanged = true; 160 m_part.ParentGroup.HasGroupChanged = true;
154 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 161 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
155 foreach (TaskInventoryItem item in items) 162 foreach (TaskInventoryItem item in items)
163 {
164 if (ownerId != item.OwnerID)
156 { 165 {
157 if (ownerId != item.OwnerID) 166 item.LastOwnerID = item.OwnerID;
158 { 167 item.OwnerID = ownerId;
159 item.LastOwnerID = item.OwnerID;
160 item.OwnerID = ownerId;
161 }
162 } 168 }
163 } 169 }
170 m_items.LockItemsForWrite(false);
164 } 171 }
165 172
166 /// <summary> 173 /// <summary>
@@ -169,24 +176,24 @@ namespace OpenSim.Region.Framework.Scenes
169 /// <param name="groupID"></param> 176 /// <param name="groupID"></param>
170 public void ChangeInventoryGroup(UUID groupID) 177 public void ChangeInventoryGroup(UUID groupID)
171 { 178 {
172 lock (Items) 179 m_items.LockItemsForWrite(true);
180 if (0 == Items.Count)
173 { 181 {
174 if (0 == Items.Count) 182 m_items.LockItemsForWrite(false);
175 { 183 return;
176 return; 184 }
177 }
178 185
179 HasInventoryChanged = true; 186 HasInventoryChanged = true;
180 m_part.ParentGroup.HasGroupChanged = true; 187 m_part.ParentGroup.HasGroupChanged = true;
181 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 188 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
182 foreach (TaskInventoryItem item in items) 189 foreach (TaskInventoryItem item in items)
190 {
191 if (groupID != item.GroupID)
183 { 192 {
184 if (groupID != item.GroupID) 193 item.GroupID = groupID;
185 {
186 item.GroupID = groupID;
187 }
188 } 194 }
189 } 195 }
196 m_items.LockItemsForWrite(false);
190 } 197 }
191 198
192 /// <summary> 199 /// <summary>
@@ -194,19 +201,19 @@ namespace OpenSim.Region.Framework.Scenes
194 /// </summary> 201 /// </summary>
195 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 202 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
196 { 203 {
197 lock (m_items) 204 Items.LockItemsForRead(true);
205 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
206 Items.LockItemsForRead(false);
207 foreach (TaskInventoryItem item in items)
198 { 208 {
199 foreach (TaskInventoryItem item in Items.Values) 209 if ((int)InventoryType.LSL == item.InvType)
200 { 210 {
201 if ((int)InventoryType.LSL == item.InvType) 211 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
202 {
203 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
204 }
205 } 212 }
206 } 213 }
207 } 214 }
208 215
209 public ArrayList GetScriptErrors(UUID itemID) 216 private ArrayList GetScriptErrors(UUID itemID)
210 { 217 {
211 ArrayList ret = new ArrayList(); 218 ArrayList ret = new ArrayList();
212 219
@@ -236,16 +243,20 @@ namespace OpenSim.Region.Framework.Scenes
236 /// </param> 243 /// </param>
237 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 244 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
238 { 245 {
239 lock (Items) 246 Items.LockItemsForRead(true);
247 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
248 Items.LockItemsForRead(false);
249
250 foreach (TaskInventoryItem item in items)
240 { 251 {
241 foreach (TaskInventoryItem item in Items.Values) 252 if ((int)InventoryType.LSL == item.InvType)
242 { 253 {
243 if ((int)InventoryType.LSL == item.InvType) 254 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
244 { 255 m_part.RemoveScriptEvents(item.ItemID);
245 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
246 }
247 } 256 }
248 } 257 }
258
259
249 } 260 }
250 261
251 /// <summary> 262 /// <summary>
@@ -261,7 +272,10 @@ namespace OpenSim.Region.Framework.Scenes
261 // item.Name, item.ItemID, Name, UUID); 272 // item.Name, item.ItemID, Name, UUID);
262 273
263 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 274 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
275 {
276 StoreScriptError(item.ItemID, "no permission");
264 return; 277 return;
278 }
265 279
266 m_part.AddFlag(PrimFlags.Scripted); 280 m_part.AddFlag(PrimFlags.Scripted);
267 281
@@ -270,49 +284,50 @@ namespace OpenSim.Region.Framework.Scenes
270 if (stateSource == 1 && // Prim crossing 284 if (stateSource == 1 && // Prim crossing
271 m_part.ParentGroup.Scene.m_trustBinaries) 285 m_part.ParentGroup.Scene.m_trustBinaries)
272 { 286 {
273 lock (m_items) 287 m_items.LockItemsForWrite(true);
274 { 288 m_items[item.ItemID].PermsMask = 0;
275 m_items[item.ItemID].PermsMask = 0; 289 m_items[item.ItemID].PermsGranter = UUID.Zero;
276 m_items[item.ItemID].PermsGranter = UUID.Zero; 290 m_items.LockItemsForWrite(false);
277 }
278
279 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 291 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
280 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 292 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
293 StoreScriptErrors(item.ItemID, null);
281 m_part.ParentGroup.AddActiveScriptCount(1); 294 m_part.ParentGroup.AddActiveScriptCount(1);
282 m_part.ScheduleFullUpdate(); 295 m_part.ScheduleFullUpdate();
283 return; 296 return;
284 } 297 }
285 298
286 m_part.ParentGroup.Scene.AssetService.Get( 299 m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset)
287 item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset) 300 {
288 { 301 if (null == asset)
289 if (null == asset) 302 {
290 { 303 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
291 m_log.ErrorFormat( 304 StoreScriptError(item.ItemID, msg);
292 "[PRIM INVENTORY]: " + 305 m_log.ErrorFormat(
293 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 306 "[PRIM INVENTORY]: " +
294 item.Name, item.ItemID, m_part.AbsolutePosition, 307 "Couldn't start script {0}, {1} at {2} in {3} since {4}",
295 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); 308 item.Name, item.ItemID, m_part.AbsolutePosition,
296 } 309 m_part.ParentGroup.Scene.RegionInfo.RegionName, msg);
297 else 310 }
298 { 311 else
299 if (m_part.ParentGroup.m_savedScriptState != null) 312 {
300 RestoreSavedScriptState(item.OldItemID, item.ItemID); 313 if (m_part.ParentGroup.m_savedScriptState != null)
301 314 RestoreSavedScriptState(item.OldItemID, item.ItemID);
302 lock (m_items) 315 m_items.LockItemsForWrite(true);
303 { 316 m_items[item.ItemID].PermsMask = 0;
304 m_items[item.ItemID].PermsMask = 0; 317 m_items[item.ItemID].PermsGranter = UUID.Zero;
305 m_items[item.ItemID].PermsGranter = UUID.Zero; 318 m_items.LockItemsForWrite(false);
306 } 319 string script = Utils.BytesToString(asset.Data);
307 320 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
308 string script = Utils.BytesToString(asset.Data); 321 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
309 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 322 StoreScriptErrors(item.ItemID, null);
310 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 323 m_part.ParentGroup.AddActiveScriptCount(1);
311 m_part.ParentGroup.AddActiveScriptCount(1); 324 m_part.ScheduleFullUpdate();
312 m_part.ScheduleFullUpdate(); 325 }
313 } 326 });
314 } 327 }
315 ); 328 else
329 {
330 StoreScriptError(item.ItemID, "scripts disabled");
316 } 331 }
317 } 332 }
318 333
@@ -373,27 +388,145 @@ namespace OpenSim.Region.Framework.Scenes
373 388
374 /// <summary> 389 /// <summary>
375 /// Start a script which is in this prim's inventory. 390 /// Start a script which is in this prim's inventory.
391 /// Some processing may occur in the background, but this routine returns asap.
376 /// </summary> 392 /// </summary>
377 /// <param name="itemId"> 393 /// <param name="itemId">
378 /// A <see cref="UUID"/> 394 /// A <see cref="UUID"/>
379 /// </param> 395 /// </param>
380 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 396 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
381 { 397 {
382 lock (m_items) 398 lock (m_scriptErrors)
399 {
400 // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion
401 m_scriptErrors.Remove(itemId);
402 }
403 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
404 }
405
406 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
407 {
408 m_items.LockItemsForRead(true);
409 if (m_items.ContainsKey(itemId))
383 { 410 {
384 if (m_items.ContainsKey(itemId)) 411 if (m_items.ContainsKey(itemId))
385 { 412 {
413 m_items.LockItemsForRead(false);
386 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); 414 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
387 } 415 }
388 else 416 else
389 { 417 {
418 m_items.LockItemsForRead(false);
419 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
420 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
421 StoreScriptError(itemId, msg);
390 m_log.ErrorFormat( 422 m_log.ErrorFormat(
391 "[PRIM INVENTORY]: " + 423 "[PRIM INVENTORY]: " +
392 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 424 "Couldn't start script with ID {0} since it {1}", itemId, msg);
393 itemId, m_part.Name, m_part.UUID, 425 }
394 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 426 }
427 else
428 {
429 m_items.LockItemsForRead(false);
430 string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID);
431 StoreScriptError(itemId, msg);
432 m_log.ErrorFormat(
433 "[PRIM INVENTORY]: " +
434 "Couldn't start script with ID {0} since it {1}", itemId, msg);
435 }
436
437 }
438
439 /// <summary>
440 /// Start a script which is in this prim's inventory and return any compilation error messages.
441 /// </summary>
442 /// <param name="itemId">
443 /// A <see cref="UUID"/>
444 /// </param>
445 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
446 {
447 ArrayList errors;
448
449 // Indicate to CreateScriptInstanceInternal() we want it to
450 // post any compilation/loading error messages
451 lock (m_scriptErrors)
452 {
453 m_scriptErrors[itemId] = null;
454 }
455
456 // Perform compilation/loading
457 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
458
459 // Wait for and retrieve any errors
460 lock (m_scriptErrors)
461 {
462 while ((errors = m_scriptErrors[itemId]) == null)
463 {
464 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
465 {
466 m_log.ErrorFormat(
467 "[PRIM INVENTORY]: " +
468 "timedout waiting for script {0} errors", itemId);
469 errors = m_scriptErrors[itemId];
470 if (errors == null)
471 {
472 errors = new ArrayList(1);
473 errors.Add("timedout waiting for errors");
474 }
475 break;
476 }
395 } 477 }
478 m_scriptErrors.Remove(itemId);
396 } 479 }
480 return errors;
481 }
482
483 // Signal to CreateScriptInstanceEr() that compilation/loading is complete
484 private void StoreScriptErrors(UUID itemId, ArrayList errors)
485 {
486 lock (m_scriptErrors)
487 {
488 // If compilation/loading initiated via CreateScriptInstance(),
489 // it does not want the errors, so just get out
490 if (!m_scriptErrors.ContainsKey(itemId))
491 {
492 return;
493 }
494
495 // Initiated via CreateScriptInstanceEr(), if we know what the
496 // errors are, save them and wake CreateScriptInstanceEr().
497 if (errors != null)
498 {
499 m_scriptErrors[itemId] = errors;
500 System.Threading.Monitor.PulseAll(m_scriptErrors);
501 return;
502 }
503 }
504
505 // Initiated via CreateScriptInstanceEr() but we don't know what
506 // the errors are yet, so retrieve them from the script engine.
507 // This may involve some waiting internal to GetScriptErrors().
508 errors = GetScriptErrors(itemId);
509
510 // Get a default non-null value to indicate success.
511 if (errors == null)
512 {
513 errors = new ArrayList();
514 }
515
516 // Post to CreateScriptInstanceEr() and wake it up
517 lock (m_scriptErrors)
518 {
519 m_scriptErrors[itemId] = errors;
520 System.Threading.Monitor.PulseAll(m_scriptErrors);
521 }
522 }
523
524 // Like StoreScriptErrors(), but just posts a single string message
525 private void StoreScriptError(UUID itemId, string message)
526 {
527 ArrayList errors = new ArrayList(1);
528 errors.Add(message);
529 StoreScriptErrors(itemId, errors);
397 } 530 }
398 531
399 /// <summary> 532 /// <summary>
@@ -406,15 +539,7 @@ namespace OpenSim.Region.Framework.Scenes
406 /// </param> 539 /// </param>
407 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 540 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
408 { 541 {
409 bool scriptPresent = false; 542 if (m_items.ContainsKey(itemId))
410
411 lock (m_items)
412 {
413 if (m_items.ContainsKey(itemId))
414 scriptPresent = true;
415 }
416
417 if (scriptPresent)
418 { 543 {
419 if (!sceneObjectBeingDeleted) 544 if (!sceneObjectBeingDeleted)
420 m_part.RemoveScriptEvents(itemId); 545 m_part.RemoveScriptEvents(itemId);
@@ -440,11 +565,16 @@ namespace OpenSim.Region.Framework.Scenes
440 /// <returns></returns> 565 /// <returns></returns>
441 private bool InventoryContainsName(string name) 566 private bool InventoryContainsName(string name)
442 { 567 {
443 foreach (TaskInventoryItem item in Items.Values) 568 m_items.LockItemsForRead(true);
569 foreach (TaskInventoryItem item in m_items.Values)
444 { 570 {
445 if (item.Name == name) 571 if (item.Name == name)
572 {
573 m_items.LockItemsForRead(false);
446 return true; 574 return true;
575 }
447 } 576 }
577 m_items.LockItemsForRead(false);
448 return false; 578 return false;
449 } 579 }
450 580
@@ -486,13 +616,9 @@ namespace OpenSim.Region.Framework.Scenes
486 /// <param name="item"></param> 616 /// <param name="item"></param>
487 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 617 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
488 { 618 {
489 List<TaskInventoryItem> il; 619 m_items.LockItemsForRead(true);
490 620 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
491 lock (m_items) 621 m_items.LockItemsForRead(false);
492 {
493 il = new List<TaskInventoryItem>(m_items.Values);
494 }
495
496 foreach (TaskInventoryItem i in il) 622 foreach (TaskInventoryItem i in il)
497 { 623 {
498 if (i.Name == item.Name) 624 if (i.Name == item.Name)
@@ -529,15 +655,14 @@ namespace OpenSim.Region.Framework.Scenes
529 item.ParentPartID = m_part.UUID; 655 item.ParentPartID = m_part.UUID;
530 item.Name = name; 656 item.Name = name;
531 657
532 lock (m_items) 658 m_items.LockItemsForWrite(true);
533 { 659 m_items.Add(item.ItemID, item);
534 m_items.Add(item.ItemID, item); 660 m_items.LockItemsForWrite(false);
535
536 if (allowedDrop) 661 if (allowedDrop)
537 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 662 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
538 else 663 else
539 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 664 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
540 } 665
541 666
542 m_inventorySerial++; 667 m_inventorySerial++;
543 //m_inventorySerial += 2; 668 //m_inventorySerial += 2;
@@ -554,14 +679,13 @@ namespace OpenSim.Region.Framework.Scenes
554 /// <param name="items"></param> 679 /// <param name="items"></param>
555 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 680 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
556 { 681 {
557 lock (m_items) 682 m_items.LockItemsForWrite(true);
683 foreach (TaskInventoryItem item in items)
558 { 684 {
559 foreach (TaskInventoryItem item in items) 685 m_items.Add(item.ItemID, item);
560 { 686 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
561 m_items.Add(item.ItemID, item);
562 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
563 }
564 } 687 }
688 m_items.LockItemsForWrite(false);
565 689
566 m_inventorySerial++; 690 m_inventorySerial++;
567 } 691 }
@@ -574,10 +698,9 @@ namespace OpenSim.Region.Framework.Scenes
574 public TaskInventoryItem GetInventoryItem(UUID itemId) 698 public TaskInventoryItem GetInventoryItem(UUID itemId)
575 { 699 {
576 TaskInventoryItem item; 700 TaskInventoryItem item;
577 701 m_items.LockItemsForRead(true);
578 lock (m_items) 702 m_items.TryGetValue(itemId, out item);
579 m_items.TryGetValue(itemId, out item); 703 m_items.LockItemsForRead(false);
580
581 return item; 704 return item;
582 } 705 }
583 706
@@ -613,45 +736,46 @@ namespace OpenSim.Region.Framework.Scenes
613 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 736 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
614 public bool UpdateInventoryItem(TaskInventoryItem item) 737 public bool UpdateInventoryItem(TaskInventoryItem item)
615 { 738 {
616 lock (m_items) 739 m_items.LockItemsForWrite(true);
740
741 if (m_items.ContainsKey(item.ItemID))
617 { 742 {
618 if (m_items.ContainsKey(item.ItemID)) 743 item.ParentID = m_part.UUID;
744 item.ParentPartID = m_part.UUID;
745 item.Flags = m_items[item.ItemID].Flags;
746 if (item.AssetID == UUID.Zero)
619 { 747 {
620 item.ParentID = m_part.UUID; 748 item.AssetID = m_items[item.ItemID].AssetID;
621 item.ParentPartID = m_part.UUID; 749 }
622 item.Flags = m_items[item.ItemID].Flags; 750 else if ((InventoryType)item.Type == InventoryType.Notecard)
623 if (item.AssetID == UUID.Zero) 751 {
624 { 752 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
625 item.AssetID = m_items[item.ItemID].AssetID;
626 }
627 else if ((InventoryType)item.Type == InventoryType.Notecard)
628 {
629 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
630 753
631 if (presence != null) 754 if (presence != null)
632 { 755 {
633 presence.ControllingClient.SendAgentAlertMessage( 756 presence.ControllingClient.SendAgentAlertMessage(
634 "Notecard saved", false); 757 "Notecard saved", false);
635 }
636 } 758 }
759 }
637 760
638 m_items[item.ItemID] = item; 761 m_items[item.ItemID] = item;
639 m_inventorySerial++; 762 m_inventorySerial++;
640 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 763 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
641 HasInventoryChanged = true;
642 m_part.ParentGroup.HasGroupChanged = true;
643 764
644 return true; 765 HasInventoryChanged = true;
645 } 766 m_part.ParentGroup.HasGroupChanged = true;
646 else 767 m_items.LockItemsForWrite(false);
647 { 768 return true;
648 m_log.ErrorFormat(
649 "[PRIM INVENTORY]: " +
650 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
651 item.ItemID, m_part.Name, m_part.UUID,
652 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
653 }
654 } 769 }
770 else
771 {
772 m_log.ErrorFormat(
773 "[PRIM INVENTORY]: " +
774 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
775 item.ItemID, m_part.Name, m_part.UUID,
776 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
777 }
778 m_items.LockItemsForWrite(false);
655 779
656 return false; 780 return false;
657 } 781 }
@@ -664,53 +788,54 @@ namespace OpenSim.Region.Framework.Scenes
664 /// in this prim's inventory.</returns> 788 /// in this prim's inventory.</returns>
665 public int RemoveInventoryItem(UUID itemID) 789 public int RemoveInventoryItem(UUID itemID)
666 { 790 {
667 lock (m_items) 791 m_items.LockItemsForRead(true);
792
793 if (m_items.ContainsKey(itemID))
668 { 794 {
669 if (m_items.ContainsKey(itemID)) 795 int type = m_items[itemID].InvType;
796 m_items.LockItemsForRead(false);
797 if (type == 10) // Script
670 { 798 {
671 int type = m_items[itemID].InvType; 799 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
672 if (type == 10) // Script 800 }
673 { 801 m_items.LockItemsForWrite(true);
674 m_part.RemoveScriptEvents(itemID); 802 m_items.Remove(itemID);
675 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 803 m_items.LockItemsForWrite(false);
676 } 804 m_inventorySerial++;
677 m_items.Remove(itemID); 805 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
678 m_inventorySerial++;
679 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
680
681 HasInventoryChanged = true;
682 m_part.ParentGroup.HasGroupChanged = true;
683 806
684 int scriptcount = 0; 807 HasInventoryChanged = true;
685 lock (m_items) 808 m_part.ParentGroup.HasGroupChanged = true;
686 {
687 foreach (TaskInventoryItem item in m_items.Values)
688 {
689 if (item.Type == 10)
690 {
691 scriptcount++;
692 }
693 }
694 }
695 809
696 if (scriptcount <= 0) 810 int scriptcount = 0;
811 m_items.LockItemsForRead(true);
812 foreach (TaskInventoryItem item in m_items.Values)
813 {
814 if (item.Type == 10)
697 { 815 {
698 m_part.RemFlag(PrimFlags.Scripted); 816 scriptcount++;
699 } 817 }
700
701 m_part.ScheduleFullUpdate();
702
703 return type;
704 } 818 }
705 else 819 m_items.LockItemsForRead(false);
820
821
822 if (scriptcount <= 0)
706 { 823 {
707 m_log.ErrorFormat( 824 m_part.RemFlag(PrimFlags.Scripted);
708 "[PRIM INVENTORY]: " +
709 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
710 itemID, m_part.Name, m_part.UUID,
711 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
712 } 825 }
826
827 m_part.ScheduleFullUpdate();
828
829 return type;
830 }
831 else
832 {
833 m_log.ErrorFormat(
834 "[PRIM INVENTORY]: " +
835 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
836 itemID, m_part.Name, m_part.UUID);
713 } 837 }
838 m_items.LockItemsForWrite(false);
714 839
715 return -1; 840 return -1;
716 } 841 }
@@ -763,52 +888,53 @@ namespace OpenSim.Region.Framework.Scenes
763 // isn't available (such as drag from prim inventory to agent inventory) 888 // isn't available (such as drag from prim inventory to agent inventory)
764 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 889 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
765 890
766 lock (m_items) 891 m_items.LockItemsForRead(true);
892
893 foreach (TaskInventoryItem item in m_items.Values)
767 { 894 {
768 foreach (TaskInventoryItem item in m_items.Values) 895 UUID ownerID = item.OwnerID;
769 { 896 uint everyoneMask = 0;
770 UUID ownerID = item.OwnerID; 897 uint baseMask = item.BasePermissions;
771 uint everyoneMask = 0; 898 uint ownerMask = item.CurrentPermissions;
772 uint baseMask = item.BasePermissions;
773 uint ownerMask = item.CurrentPermissions;
774 899
775 invString.AddItemStart(); 900 invString.AddItemStart();
776 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 901 invString.AddNameValueLine("item_id", item.ItemID.ToString());
777 invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); 902 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
778 903
779 invString.AddPermissionsStart(); 904 invString.AddPermissionsStart();
780 905
781 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 906 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
782 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 907 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
783 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0)); 908 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0));
784 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 909 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
785 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 910 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
786 911
787 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 912 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
788 invString.AddNameValueLine("owner_id", ownerID.ToString()); 913 invString.AddNameValueLine("owner_id", ownerID.ToString());
789 914
790 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 915 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
791 916
792 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 917 invString.AddNameValueLine("group_id", item.GroupID.ToString());
793 invString.AddSectionEnd(); 918 invString.AddSectionEnd();
794 919
795 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 920 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
796 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 921 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
797 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 922 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
798 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 923 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
799 924
800 invString.AddSaleStart(); 925 invString.AddSaleStart();
801 invString.AddNameValueLine("sale_type", "not"); 926 invString.AddNameValueLine("sale_type", "not");
802 invString.AddNameValueLine("sale_price", "0"); 927 invString.AddNameValueLine("sale_price", "0");
803 invString.AddSectionEnd(); 928 invString.AddSectionEnd();
804 929
805 invString.AddNameValueLine("name", item.Name + "|"); 930 invString.AddNameValueLine("name", item.Name + "|");
806 invString.AddNameValueLine("desc", item.Description + "|"); 931 invString.AddNameValueLine("desc", item.Description + "|");
807 932
808 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 933 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
809 invString.AddSectionEnd(); 934 invString.AddSectionEnd();
810 }
811 } 935 }
936 int count = m_items.Count;
937 m_items.LockItemsForRead(false);
812 938
813 fileData = Utils.StringToBytes(invString.BuildString); 939 fileData = Utils.StringToBytes(invString.BuildString);
814 940
@@ -829,10 +955,9 @@ namespace OpenSim.Region.Framework.Scenes
829 { 955 {
830 if (HasInventoryChanged) 956 if (HasInventoryChanged)
831 { 957 {
832 lock (Items) 958 Items.LockItemsForRead(true);
833 { 959 datastore.StorePrimInventory(m_part.UUID, Items.Values);
834 datastore.StorePrimInventory(m_part.UUID, Items.Values); 960 Items.LockItemsForRead(false);
835 }
836 961
837 HasInventoryChanged = false; 962 HasInventoryChanged = false;
838 } 963 }
@@ -901,61 +1026,54 @@ namespace OpenSim.Region.Framework.Scenes
901 { 1026 {
902 uint mask=0x7fffffff; 1027 uint mask=0x7fffffff;
903 1028
904 lock (m_items) 1029 foreach (TaskInventoryItem item in m_items.Values)
905 { 1030 {
906 foreach (TaskInventoryItem item in m_items.Values) 1031 if (item.InvType != (int)InventoryType.Object)
907 { 1032 {
908 if (item.InvType != (int)InventoryType.Object) 1033 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
909 { 1034 mask &= ~((uint)PermissionMask.Copy >> 13);
910 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1035 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
911 mask &= ~((uint)PermissionMask.Copy >> 13); 1036 mask &= ~((uint)PermissionMask.Transfer >> 13);
912 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1037 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
913 mask &= ~((uint)PermissionMask.Transfer >> 13); 1038 mask &= ~((uint)PermissionMask.Modify >> 13);
914 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1039 }
915 mask &= ~((uint)PermissionMask.Modify >> 13); 1040 else
916 } 1041 {
917 else 1042 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
918 { 1043 mask &= ~((uint)PermissionMask.Copy >> 13);
919 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1044 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
920 mask &= ~((uint)PermissionMask.Copy >> 13); 1045 mask &= ~((uint)PermissionMask.Transfer >> 13);
921 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1046 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
922 mask &= ~((uint)PermissionMask.Transfer >> 13); 1047 mask &= ~((uint)PermissionMask.Modify >> 13);
923 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
924 mask &= ~((uint)PermissionMask.Modify >> 13);
925 }
926
927 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
928 mask &= ~(uint)PermissionMask.Copy;
929 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
930 mask &= ~(uint)PermissionMask.Transfer;
931 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
932 mask &= ~(uint)PermissionMask.Modify;
933 } 1048 }
1049
1050 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1051 mask &= ~(uint)PermissionMask.Copy;
1052 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1053 mask &= ~(uint)PermissionMask.Transfer;
1054 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1055 mask &= ~(uint)PermissionMask.Modify;
934 } 1056 }
935
936 return mask; 1057 return mask;
937 } 1058 }
938 1059
939 public void ApplyNextOwnerPermissions() 1060 public void ApplyNextOwnerPermissions()
940 { 1061 {
941 lock (m_items) 1062 foreach (TaskInventoryItem item in m_items.Values)
942 { 1063 {
943 foreach (TaskInventoryItem item in m_items.Values) 1064 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
944 { 1065 {
945 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1066 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
946 { 1067 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
947 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1068 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
948 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 1069 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
949 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1070 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
950 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 1071 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
951 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 1072 item.CurrentPermissions |= 8;
952 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
953 item.CurrentPermissions |= 8;
954 }
955 item.CurrentPermissions &= item.NextPermissions;
956 item.BasePermissions &= item.NextPermissions;
957 item.EveryonePermissions &= item.NextPermissions;
958 } 1073 }
1074 item.CurrentPermissions &= item.NextPermissions;
1075 item.BasePermissions &= item.NextPermissions;
1076 item.EveryonePermissions &= item.NextPermissions;
959 } 1077 }
960 1078
961 m_part.TriggerScriptChangedEvent(Changed.OWNER); 1079 m_part.TriggerScriptChangedEvent(Changed.OWNER);
@@ -963,29 +1081,22 @@ namespace OpenSim.Region.Framework.Scenes
963 1081
964 public void ApplyGodPermissions(uint perms) 1082 public void ApplyGodPermissions(uint perms)
965 { 1083 {
966 lock (m_items) 1084 foreach (TaskInventoryItem item in m_items.Values)
967 { 1085 {
968 foreach (TaskInventoryItem item in m_items.Values) 1086 item.CurrentPermissions = perms;
969 { 1087 item.BasePermissions = perms;
970 item.CurrentPermissions = perms;
971 item.BasePermissions = perms;
972 }
973 } 1088 }
974 } 1089 }
975 1090
976 public bool ContainsScripts() 1091 public bool ContainsScripts()
977 { 1092 {
978 lock (m_items) 1093 foreach (TaskInventoryItem item in m_items.Values)
979 { 1094 {
980 foreach (TaskInventoryItem item in m_items.Values) 1095 if (item.InvType == (int)InventoryType.LSL)
981 { 1096 {
982 if (item.InvType == (int)InventoryType.LSL) 1097 return true;
983 {
984 return true;
985 }
986 } 1098 }
987 } 1099 }
988
989 return false; 1100 return false;
990 } 1101 }
991 1102
@@ -993,11 +1104,8 @@ namespace OpenSim.Region.Framework.Scenes
993 { 1104 {
994 List<UUID> ret = new List<UUID>(); 1105 List<UUID> ret = new List<UUID>();
995 1106
996 lock (m_items) 1107 foreach (TaskInventoryItem item in m_items.Values)
997 { 1108 ret.Add(item.ItemID);
998 foreach (TaskInventoryItem item in m_items.Values)
999 ret.Add(item.ItemID);
1000 }
1001 1109
1002 return ret; 1110 return ret;
1003 } 1111 }
@@ -1010,30 +1118,26 @@ namespace OpenSim.Region.Framework.Scenes
1010 if (engines == null) // No engine at all 1118 if (engines == null) // No engine at all
1011 return ret; 1119 return ret;
1012 1120
1013 lock (m_items) 1121 foreach (TaskInventoryItem item in m_items.Values)
1014 { 1122 {
1015 foreach (TaskInventoryItem item in m_items.Values) 1123 if (item.InvType == (int)InventoryType.LSL)
1016 { 1124 {
1017 if (item.InvType == (int)InventoryType.LSL) 1125 foreach (IScriptModule e in engines)
1018 { 1126 {
1019 foreach (IScriptModule e in engines) 1127 if (e != null)
1020 { 1128 {
1021 if (e != null) 1129 string n = e.GetXMLState(item.ItemID);
1130 if (n != String.Empty)
1022 { 1131 {
1023 string n = e.GetXMLState(item.ItemID); 1132 if (!ret.ContainsKey(item.ItemID))
1024 if (n != String.Empty) 1133 ret[item.ItemID] = n;
1025 { 1134 break;
1026 if (!ret.ContainsKey(item.ItemID))
1027 ret[item.ItemID] = n;
1028 break;
1029 }
1030 } 1135 }
1031 } 1136 }
1032 } 1137 }
1033 } 1138 }
1034 } 1139 }
1035
1036 return ret; 1140 return ret;
1037 } 1141 }
1038 } 1142 }
1039} \ No newline at end of file 1143}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 4973663..68acabe 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);
1693 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
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)
@@ -3931,5 +4161,16 @@ namespace OpenSim.Region.Framework.Scenes
3931 m_reprioritization_called = false; 4161 m_reprioritization_called = false;
3932 } 4162 }
3933 } 4163 }
4164
4165 private Vector3 Quat2Euler(Quaternion rot){
4166 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4167 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4168 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4169 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4170 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4171 return(new Vector3(x,y,z));
4172 }
4173
4174
3934 } 4175 }
3935} 4176}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index 6f2bef9..f88605b 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;