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.cs29
-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.cs66
-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.cs660
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs579
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs11
15 files changed, 1527 insertions, 843 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 712dcc7..be0e985 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -53,8 +53,8 @@ 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 60
@@ -123,17 +123,22 @@ namespace OpenSim.Region.Framework.Scenes.Animation
123 /// </summary> 123 /// </summary>
124 public void TrySetMovementAnimation(string anim) 124 public void TrySetMovementAnimation(string anim)
125 { 125 {
126 //m_log.DebugFormat("Updating movement animation to {0}", anim); 126//Console.WriteLine("Updating movement animation to {0}", anim);
127 127
128 if (!m_scenePresence.IsChildAgent) 128 if (!m_scenePresence.IsChildAgent)
129 { 129 {
130 if (m_animations.TrySetDefaultAnimation( 130 if (m_animations.TrySetDefaultAnimation(
131 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID)) 131 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID))
132 { 132 {
133//Console.WriteLine("TSMA {0} success.", anim);
133 // 16384 is CHANGED_ANIMATION 134 // 16384 is CHANGED_ANIMATION
134 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { 16384 }); 135 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { 16384 });
135 SendAnimPack(); 136 SendAnimPack();
136 } 137 }
138 else
139 {
140//Console.WriteLine("TSMA {0} fail.", anim);
141 }
137 } 142 }
138 } 143 }
139 144
@@ -146,10 +151,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
146 const float PREJUMP_DELAY = 0.25f; 151 const float PREJUMP_DELAY = 0.25f;
147 152
148 #region Inputs 153 #region Inputs
149 if (m_scenePresence.SitGround) 154
150 {
151 return "SIT_GROUND_CONSTRAINED";
152 }
153 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; 155 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
154 PhysicsActor actor = m_scenePresence.PhysicsActor; 156 PhysicsActor actor = m_scenePresence.PhysicsActor;
155 157
@@ -159,11 +161,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
159 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); 161 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
160 162
161 // Check control flags 163 // Check control flags
162 bool heldForward = 164 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)); 165 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; 166 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; 167 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; 168 //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; 169 //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; 170 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
@@ -316,7 +317,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
316 public void UpdateMovementAnimations() 317 public void UpdateMovementAnimations()
317 { 318 {
318 m_movementAnimation = GetMovementAnimation(); 319 m_movementAnimation = GetMovementAnimation();
319 320//Console.WriteLine("UMA got {0}", m_movementAnimation);
320 if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump) 321 if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump)
321 { 322 {
322 // This was the previous behavior before PREJUMP 323 // This was the previous behavior before PREJUMP
@@ -451,4 +452,4 @@ namespace OpenSim.Region.Framework.Scenes.Animation
451 m_scenePresence = null; 452 m_scenePresence = null;
452 } 453 }
453 } 454 }
454} \ No newline at end of file 455}
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 57e1c37..7fb1cd8 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 5b21332..6c57d18 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 {
@@ -849,8 +848,12 @@ namespace OpenSim.Region.Framework.Scenes
849 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) 848 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
850 { 849 {
851 SceneObjectPart part = GetSceneObjectPart(localID); 850 SceneObjectPart part = GetSceneObjectPart(localID);
852 SceneObjectGroup group = part.ParentGroup; 851 SceneObjectGroup group = null;
853 if (group != null) 852 if (part != null)
853 {
854 group = part.ParentGroup;
855 }
856 if (part != null && group != null)
854 { 857 {
855 TaskInventoryItem item = group.GetInventoryItem(localID, itemID); 858 TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
856 if (item == null) 859 if (item == null)
@@ -1577,9 +1580,10 @@ namespace OpenSim.Region.Framework.Scenes
1577 if (remoteClient != null) 1580 if (remoteClient != null)
1578 { 1581 {
1579 permissionToTake = 1582 permissionToTake =
1580 Permissions.CanReturnObject( 1583 Permissions.CanReturnObjects(
1581 grp.UUID, 1584 null,
1582 remoteClient.AgentId); 1585 remoteClient.AgentId,
1586 new List<SceneObjectGroup>() {grp});
1583 permissionToDelete = permissionToTake; 1587 permissionToDelete = permissionToTake;
1584 1588
1585 if (permissionToDelete) 1589 if (permissionToDelete)
@@ -1804,8 +1808,13 @@ namespace OpenSim.Region.Framework.Scenes
1804 } 1808 }
1805 else 1809 else
1806 { 1810 {
1807 item.BasePermissions = objectGroup.GetEffectivePermissions(); 1811 uint ownerPerms = objectGroup.GetEffectivePermissions();
1808 item.CurrentPermissions = objectGroup.GetEffectivePermissions(); 1812 if ((objectGroup.RootPart.OwnerMask & (uint)PermissionMask.Modify) != 0)
1813 ownerPerms |= (uint)PermissionMask.Modify;
1814
1815 item.BasePermissions = ownerPerms;
1816 item.CurrentPermissions = ownerPerms;
1817
1809 item.NextPermissions = objectGroup.RootPart.NextOwnerMask; 1818 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1810 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask; 1819 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
1811 item.GroupPermissions = objectGroup.RootPart.GroupMask; 1820 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 7796b8d..db073e8 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);
@@ -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>
@@ -3450,6 +3491,9 @@ namespace OpenSim.Region.Framework.Scenes
3450 3491
3451 CapsModule.AddCapsHandler(agent.AgentID); 3492 CapsModule.AddCapsHandler(agent.AgentID);
3452 3493
3494 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3495 System.Threading.Thread.Sleep(2000);
3496
3453 if (!agent.child) 3497 if (!agent.child)
3454 { 3498 {
3455 if (TestBorderCross(agent.startpos,Cardinals.E)) 3499 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3508,6 +3552,7 @@ namespace OpenSim.Region.Framework.Scenes
3508 } 3552 }
3509 } 3553 }
3510 // Honor parcel landing type and position. 3554 // Honor parcel landing type and position.
3555 /*
3511 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 3556 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3512 if (land != null) 3557 if (land != null)
3513 { 3558 {
@@ -3516,6 +3561,7 @@ namespace OpenSim.Region.Framework.Scenes
3516 agent.startpos = land.LandData.UserLocation; 3561 agent.startpos = land.LandData.UserLocation;
3517 } 3562 }
3518 } 3563 }
3564 */// This is now handled properly in ScenePresence.MakeRootAgent
3519 } 3565 }
3520 3566
3521 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3567 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
@@ -4331,6 +4377,14 @@ namespace OpenSim.Region.Framework.Scenes
4331 } 4377 }
4332 4378
4333 /// <summary> 4379 /// <summary>
4380 /// Cheaply return the number of avatars in a region (without fetching a list object)
4381 /// </summary>
4382 public int GetRootAgentCount()
4383 {
4384 return m_sceneGraph.GetRootAgentCount();
4385 }
4386
4387 /// <summary>
4334 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents. 4388 /// Return a list of all ScenePresences in this region. This returns child agents as well as root agents.
4335 /// This list is a new object, so it can be iterated over without locking. 4389 /// This list is a new object, so it can be iterated over without locking.
4336 /// </summary> 4390 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 2f6a0db..04626d3 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 d31b45e..bbcb85e 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -222,6 +222,30 @@ namespace OpenSim.Region.Framework.Scenes
222 protected internal bool AddRestoredSceneObject( 222 protected internal bool AddRestoredSceneObject(
223 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted) 223 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
224 { 224 {
225 // KF: Check for out-of-region, move inside and make static.
226 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
227 sceneObject.RootPart.GroupPosition.Y,
228 sceneObject.RootPart.GroupPosition.Z);
229 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 ||
230 npos.X > Constants.RegionSize ||
231 npos.Y > Constants.RegionSize))
232 {
233 if (npos.X < 0.0) npos.X = 1.0f;
234 if (npos.Y < 0.0) npos.Y = 1.0f;
235 if (npos.Z < 0.0) npos.Z = 0.0f;
236 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
237 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
238
239 foreach (SceneObjectPart part in sceneObject.Children.Values)
240 {
241 part.GroupPosition = npos;
242 }
243 sceneObject.RootPart.Velocity = Vector3.Zero;
244 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
245 sceneObject.RootPart.Acceleration = Vector3.Zero;
246 sceneObject.RootPart.Velocity = Vector3.Zero;
247 }
248
225 if (!alreadyPersisted) 249 if (!alreadyPersisted)
226 { 250 {
227 sceneObject.ForceInventoryPersistence(); 251 sceneObject.ForceInventoryPersistence();
@@ -587,6 +611,18 @@ namespace OpenSim.Region.Framework.Scenes
587 if (group.GetFromItemID() == itemID) 611 if (group.GetFromItemID() == itemID)
588 { 612 {
589 m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero); 613 m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero);
614 bool hasScripts = false;
615 foreach (SceneObjectPart part in group.Children.Values)
616 {
617 if (part.Inventory.ContainsScripts())
618 {
619 hasScripts = true;
620 break;
621 }
622 }
623
624 if (hasScripts) // Allow the object to execute the attach(NULL_KEY) event
625 System.Threading.Thread.Sleep(100);
590 group.DetachToInventoryPrep(); 626 group.DetachToInventoryPrep();
591 m_log.Debug("[DETACH]: Saving attachpoint: " + 627 m_log.Debug("[DETACH]: Saving attachpoint: " +
592 ((uint)group.GetAttachmentPoint()).ToString()); 628 ((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 c14b39a..13d1d4e 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
@@ -1496,14 +1653,17 @@ namespace OpenSim.Region.Framework.Scenes
1496 { 1653 {
1497 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1654 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1498 1655
1499 lock (m_parts) 1656 lockPartsForRead(true);
1500 { 1657 {
1501 foreach (SceneObjectPart part in m_parts.Values) 1658 foreach (SceneObjectPart part in m_parts.Values)
1502 { 1659 {
1660
1503 if (part != RootPart) 1661 if (part != RootPart)
1504 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1662 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
1663
1505 } 1664 }
1506 } 1665 }
1666 lockPartsForRead(false);
1507 } 1667 }
1508 1668
1509 /// <summary> 1669 /// <summary>
@@ -1601,10 +1761,11 @@ namespace OpenSim.Region.Framework.Scenes
1601 1761
1602 List<SceneObjectPart> partList; 1762 List<SceneObjectPart> partList;
1603 1763
1604 lock (m_parts) 1764 lockPartsForRead(true);
1605 { 1765
1606 partList = new List<SceneObjectPart>(m_parts.Values); 1766 partList = new List<SceneObjectPart>(m_parts.Values);
1607 } 1767
1768 lockPartsForRead(false);
1608 1769
1609 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1770 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1610 { 1771 {
@@ -1827,13 +1988,40 @@ namespace OpenSim.Region.Framework.Scenes
1827 } 1988 }
1828 } 1989 }
1829 1990
1991 public void rotLookAt(Quaternion target, float strength, float damping)
1992 {
1993 SceneObjectPart rootpart = m_rootPart;
1994 if (rootpart != null)
1995 {
1996 if (IsAttachment)
1997 {
1998 /*
1999 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2000 if (avatar != null)
2001 {
2002 Rotate the Av?
2003 } */
2004 }
2005 else
2006 {
2007 if (rootpart.PhysActor != null)
2008 { // APID must be implemented in your physics system for this to function.
2009 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
2010 rootpart.PhysActor.APIDStrength = strength;
2011 rootpart.PhysActor.APIDDamping = damping;
2012 rootpart.PhysActor.APIDActive = true;
2013 }
2014 }
2015 }
2016 }
2017
1830 public void stopLookAt() 2018 public void stopLookAt()
1831 { 2019 {
1832 SceneObjectPart rootpart = m_rootPart; 2020 SceneObjectPart rootpart = m_rootPart;
1833 if (rootpart != null) 2021 if (rootpart != null)
1834 { 2022 {
1835 if (rootpart.PhysActor != null) 2023 if (rootpart.PhysActor != null)
1836 { 2024 { // APID must be implemented in your physics system for this to function.
1837 rootpart.PhysActor.APIDActive = false; 2025 rootpart.PhysActor.APIDActive = false;
1838 } 2026 }
1839 } 2027 }
@@ -1901,10 +2089,11 @@ namespace OpenSim.Region.Framework.Scenes
1901 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2089 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1902 newPart.SetParent(this); 2090 newPart.SetParent(this);
1903 2091
1904 lock (m_parts) 2092 lockPartsForWrite(true);
1905 { 2093 {
1906 m_parts.Add(newPart.UUID, newPart); 2094 m_parts.Add(newPart.UUID, newPart);
1907 } 2095 }
2096 lockPartsForWrite(false);
1908 2097
1909 SetPartAsNonRoot(newPart); 2098 SetPartAsNonRoot(newPart);
1910 2099
@@ -1967,7 +2156,7 @@ namespace OpenSim.Region.Framework.Scenes
1967 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2156 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1968 // return; 2157 // return;
1969 2158
1970 lock (m_parts) 2159 lockPartsForRead(true);
1971 { 2160 {
1972 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2161 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1973 2162
@@ -1987,9 +2176,12 @@ namespace OpenSim.Region.Framework.Scenes
1987 { 2176 {
1988 if (!IsSelected) 2177 if (!IsSelected)
1989 part.UpdateLookAt(); 2178 part.UpdateLookAt();
2179
1990 part.SendScheduledUpdates(); 2180 part.SendScheduledUpdates();
2181
1991 } 2182 }
1992 } 2183 }
2184 lockPartsForRead(false);
1993 } 2185 }
1994 2186
1995 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2187 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -1998,27 +2190,31 @@ namespace OpenSim.Region.Framework.Scenes
1998 2190
1999 RootPart.AddFullUpdateToAvatar(presence); 2191 RootPart.AddFullUpdateToAvatar(presence);
2000 2192
2001 lock (m_parts) 2193 lockPartsForRead(true);
2002 { 2194 {
2003 foreach (SceneObjectPart part in m_parts.Values) 2195 foreach (SceneObjectPart part in m_parts.Values)
2004 { 2196 {
2197
2005 if (part != RootPart) 2198 if (part != RootPart)
2006 part.AddFullUpdateToAvatar(presence); 2199 part.AddFullUpdateToAvatar(presence);
2200
2007 } 2201 }
2008 } 2202 }
2203 lockPartsForRead(false);
2009 } 2204 }
2010 2205
2011 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2206 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
2012 { 2207 {
2013// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2208 lockPartsForRead(true);
2014
2015 lock (m_parts)
2016 { 2209 {
2017 foreach (SceneObjectPart part in m_parts.Values) 2210 foreach (SceneObjectPart part in m_parts.Values)
2018 { 2211 {
2212
2019 part.AddTerseUpdateToAvatar(presence); 2213 part.AddTerseUpdateToAvatar(presence);
2214
2020 } 2215 }
2021 } 2216 }
2217 lockPartsForRead(false);
2022 } 2218 }
2023 2219
2024 /// <summary> 2220 /// <summary>
@@ -2031,14 +2227,17 @@ namespace OpenSim.Region.Framework.Scenes
2031 checkAtTargets(); 2227 checkAtTargets();
2032 RootPart.ScheduleFullUpdate(); 2228 RootPart.ScheduleFullUpdate();
2033 2229
2034 lock (m_parts) 2230 lockPartsForRead(true);
2035 { 2231 {
2036 foreach (SceneObjectPart part in m_parts.Values) 2232 foreach (SceneObjectPart part in m_parts.Values)
2037 { 2233 {
2234
2038 if (part != RootPart) 2235 if (part != RootPart)
2039 part.ScheduleFullUpdate(); 2236 part.ScheduleFullUpdate();
2237
2040 } 2238 }
2041 } 2239 }
2240 lockPartsForRead(false);
2042 } 2241 }
2043 2242
2044 /// <summary> 2243 /// <summary>
@@ -2046,15 +2245,16 @@ namespace OpenSim.Region.Framework.Scenes
2046 /// </summary> 2245 /// </summary>
2047 public void ScheduleGroupForTerseUpdate() 2246 public void ScheduleGroupForTerseUpdate()
2048 { 2247 {
2049// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2248 lockPartsForRead(true);
2050
2051 lock (m_parts)
2052 { 2249 {
2053 foreach (SceneObjectPart part in m_parts.Values) 2250 foreach (SceneObjectPart part in m_parts.Values)
2054 { 2251 {
2252
2055 part.ScheduleTerseUpdate(); 2253 part.ScheduleTerseUpdate();
2254
2056 } 2255 }
2057 } 2256 }
2257 lockPartsForRead(false);
2058 } 2258 }
2059 2259
2060 /// <summary> 2260 /// <summary>
@@ -2069,14 +2269,17 @@ namespace OpenSim.Region.Framework.Scenes
2069 2269
2070 RootPart.SendFullUpdateToAllClients(); 2270 RootPart.SendFullUpdateToAllClients();
2071 2271
2072 lock (m_parts) 2272 lockPartsForRead(true);
2073 { 2273 {
2074 foreach (SceneObjectPart part in m_parts.Values) 2274 foreach (SceneObjectPart part in m_parts.Values)
2075 { 2275 {
2276
2076 if (part != RootPart) 2277 if (part != RootPart)
2077 part.SendFullUpdateToAllClients(); 2278 part.SendFullUpdateToAllClients();
2279
2078 } 2280 }
2079 } 2281 }
2282 lockPartsForRead(false);
2080 } 2283 }
2081 2284
2082 /// <summary> 2285 /// <summary>
@@ -2108,14 +2311,15 @@ namespace OpenSim.Region.Framework.Scenes
2108 { 2311 {
2109 if (IsDeleted) 2312 if (IsDeleted)
2110 return; 2313 return;
2111 2314
2112 lock (m_parts) 2315 lockPartsForRead(true);
2113 { 2316 {
2114 foreach (SceneObjectPart part in m_parts.Values) 2317 foreach (SceneObjectPart part in m_parts.Values)
2115 { 2318 {
2116 part.SendTerseUpdateToAllClients(); 2319 part.SendTerseUpdateToAllClients();
2117 } 2320 }
2118 } 2321 }
2322 lockPartsForRead(false);
2119 } 2323 }
2120 2324
2121 #endregion 2325 #endregion
@@ -2129,16 +2333,18 @@ namespace OpenSim.Region.Framework.Scenes
2129 /// <returns>null if no child part with that linknum or child part</returns> 2333 /// <returns>null if no child part with that linknum or child part</returns>
2130 public SceneObjectPart GetLinkNumPart(int linknum) 2334 public SceneObjectPart GetLinkNumPart(int linknum)
2131 { 2335 {
2132 lock (m_parts) 2336 lockPartsForRead(true);
2133 { 2337 {
2134 foreach (SceneObjectPart part in m_parts.Values) 2338 foreach (SceneObjectPart part in m_parts.Values)
2135 { 2339 {
2136 if (part.LinkNum == linknum) 2340 if (part.LinkNum == linknum)
2137 { 2341 {
2342 lockPartsForRead(false);
2138 return part; 2343 return part;
2139 } 2344 }
2140 } 2345 }
2141 } 2346 }
2347 lockPartsForRead(false);
2142 2348
2143 return null; 2349 return null;
2144 } 2350 }
@@ -2166,17 +2372,19 @@ namespace OpenSim.Region.Framework.Scenes
2166 public SceneObjectPart GetChildPart(uint localID) 2372 public SceneObjectPart GetChildPart(uint localID)
2167 { 2373 {
2168 //m_log.DebugFormat("Entered looking for {0}", localID); 2374 //m_log.DebugFormat("Entered looking for {0}", localID);
2169 lock (m_parts) 2375 lockPartsForRead(true);
2170 { 2376 {
2171 foreach (SceneObjectPart part in m_parts.Values) 2377 foreach (SceneObjectPart part in m_parts.Values)
2172 { 2378 {
2173 //m_log.DebugFormat("Found {0}", part.LocalId); 2379 //m_log.DebugFormat("Found {0}", part.LocalId);
2174 if (part.LocalId == localID) 2380 if (part.LocalId == localID)
2175 { 2381 {
2382 lockPartsForRead(false);
2176 return part; 2383 return part;
2177 } 2384 }
2178 } 2385 }
2179 } 2386 }
2387 lockPartsForRead(false);
2180 2388
2181 return null; 2389 return null;
2182 } 2390 }
@@ -2206,17 +2414,19 @@ namespace OpenSim.Region.Framework.Scenes
2206 public bool HasChildPrim(uint localID) 2414 public bool HasChildPrim(uint localID)
2207 { 2415 {
2208 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2416 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2209 lock (m_parts) 2417 lockPartsForRead(true);
2210 { 2418 {
2211 foreach (SceneObjectPart part in m_parts.Values) 2419 foreach (SceneObjectPart part in m_parts.Values)
2212 { 2420 {
2213 //m_log.DebugFormat("Found {0}", part.LocalId); 2421 //m_log.DebugFormat("Found {0}", part.LocalId);
2214 if (part.LocalId == localID) 2422 if (part.LocalId == localID)
2215 { 2423 {
2424 lockPartsForRead(false);
2216 return true; 2425 return true;
2217 } 2426 }
2218 } 2427 }
2219 } 2428 }
2429 lockPartsForRead(false);
2220 2430
2221 return false; 2431 return false;
2222 } 2432 }
@@ -2266,53 +2476,57 @@ namespace OpenSim.Region.Framework.Scenes
2266 if (m_rootPart.LinkNum == 0) 2476 if (m_rootPart.LinkNum == 0)
2267 m_rootPart.LinkNum = 1; 2477 m_rootPart.LinkNum = 1;
2268 2478
2269 lock (m_parts) 2479 lockPartsForWrite(true);
2270 { 2480
2271 m_parts.Add(linkPart.UUID, linkPart); 2481 m_parts.Add(linkPart.UUID, linkPart);
2482
2483 lockPartsForWrite(false);
2272 2484
2273 // Insert in terms of link numbers, the new links 2485 // Insert in terms of link numbers, the new links
2274 // before the current ones (with the exception of 2486 // before the current ones (with the exception of
2275 // the root prim. Shuffle the old ones up 2487 // the root prim. Shuffle the old ones up
2276 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2488 lockPartsForRead(true);
2489 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2490 {
2491 if (kvp.Value.LinkNum != 1)
2277 { 2492 {
2278 if (kvp.Value.LinkNum != 1) 2493 // Don't update root prim link number
2279 { 2494 kvp.Value.LinkNum += objectGroup.PrimCount;
2280 // Don't update root prim link number
2281 kvp.Value.LinkNum += objectGroup.PrimCount;
2282 }
2283 } 2495 }
2496 }
2497 lockPartsForRead(false);
2284 2498
2285 linkPart.LinkNum = 2; 2499 linkPart.LinkNum = 2;
2286 2500
2287 linkPart.SetParent(this); 2501 linkPart.SetParent(this);
2288 linkPart.AddFlag(PrimFlags.CreateSelected); 2502 linkPart.AddFlag(PrimFlags.CreateSelected);
2289 2503
2290 //if (linkPart.PhysActor != null) 2504 //if (linkPart.PhysActor != null)
2291 //{ 2505 //{
2292 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2506 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2293 2507
2294 //linkPart.PhysActor = null; 2508 //linkPart.PhysActor = null;
2295 //} 2509 //}
2296 2510
2297 //TODO: rest of parts 2511 //TODO: rest of parts
2298 int linkNum = 3; 2512 int linkNum = 3;
2299 foreach (SceneObjectPart part in objectGroup.Children.Values) 2513 foreach (SceneObjectPart part in objectGroup.Children.Values)
2514 {
2515 if (part.UUID != objectGroup.m_rootPart.UUID)
2300 { 2516 {
2301 if (part.UUID != objectGroup.m_rootPart.UUID) 2517 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2302 {
2303 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2304 }
2305 part.ClearUndoState();
2306 } 2518 }
2519 part.ClearUndoState();
2307 } 2520 }
2308 2521
2309 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2522 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2310 objectGroup.m_isDeleted = true; 2523 objectGroup.m_isDeleted = true;
2524
2525 objectGroup.lockPartsForWrite(true);
2311 2526
2312 lock (objectGroup.m_parts) 2527 objectGroup.m_parts.Clear();
2313 { 2528
2314 objectGroup.m_parts.Clear(); 2529 objectGroup.lockPartsForWrite(false);
2315 }
2316 2530
2317 // Can't do this yet since backup still makes use of the root part without any synchronization 2531 // Can't do this yet since backup still makes use of the root part without any synchronization
2318// objectGroup.m_rootPart = null; 2532// objectGroup.m_rootPart = null;
@@ -2382,11 +2596,12 @@ namespace OpenSim.Region.Framework.Scenes
2382 Quaternion worldRot = linkPart.GetWorldRotation(); 2596 Quaternion worldRot = linkPart.GetWorldRotation();
2383 2597
2384 // Remove the part from this object 2598 // Remove the part from this object
2385 lock (m_parts) 2599 lockPartsForWrite(true);
2386 { 2600 {
2387 m_parts.Remove(linkPart.UUID); 2601 m_parts.Remove(linkPart.UUID);
2388 } 2602 }
2389 2603 lockPartsForWrite(false);
2604 lockPartsForRead(true);
2390 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2605 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2391 RootPart.LinkNum = 0; 2606 RootPart.LinkNum = 0;
2392 else 2607 else
@@ -2397,6 +2612,7 @@ namespace OpenSim.Region.Framework.Scenes
2397 p.LinkNum--; 2612 p.LinkNum--;
2398 } 2613 }
2399 } 2614 }
2615 lockPartsForRead(false);
2400 2616
2401 linkPart.ParentID = 0; 2617 linkPart.ParentID = 0;
2402 linkPart.LinkNum = 0; 2618 linkPart.LinkNum = 0;
@@ -2718,9 +2934,12 @@ namespace OpenSim.Region.Framework.Scenes
2718 2934
2719 if (selectionPart != null) 2935 if (selectionPart != null)
2720 { 2936 {
2721 lock (m_parts) 2937 lockPartsForRead(true);
2938 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2939 lockPartsForRead(false);
2940 foreach (SceneObjectPart part in parts)
2722 { 2941 {
2723 foreach (SceneObjectPart part in m_parts.Values) 2942 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2724 { 2943 {
2725 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2944 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2726 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2945 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2730,12 +2949,13 @@ namespace OpenSim.Region.Framework.Scenes
2730 break; 2949 break;
2731 } 2950 }
2732 } 2951 }
2952 }
2733 2953
2734 foreach (SceneObjectPart part in m_parts.Values) 2954 foreach (SceneObjectPart part in parts)
2735 { 2955 {
2736 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2956 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2737 }
2738 } 2957 }
2958
2739 } 2959 }
2740 } 2960 }
2741 2961
@@ -2821,11 +3041,9 @@ namespace OpenSim.Region.Framework.Scenes
2821 scale.Y = m_scene.m_maxNonphys; 3041 scale.Y = m_scene.m_maxNonphys;
2822 if (scale.Z > m_scene.m_maxNonphys) 3042 if (scale.Z > m_scene.m_maxNonphys)
2823 scale.Z = m_scene.m_maxNonphys; 3043 scale.Z = m_scene.m_maxNonphys;
2824
2825 SceneObjectPart part = GetChildPart(localID); 3044 SceneObjectPart part = GetChildPart(localID);
2826 if (part != null) 3045 if (part != null)
2827 { 3046 {
2828 part.Resize(scale);
2829 if (part.PhysActor != null) 3047 if (part.PhysActor != null)
2830 { 3048 {
2831 if (part.PhysActor.IsPhysical) 3049 if (part.PhysActor.IsPhysical)
@@ -2840,7 +3058,7 @@ namespace OpenSim.Region.Framework.Scenes
2840 part.PhysActor.Size = scale; 3058 part.PhysActor.Size = scale;
2841 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 3059 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2842 } 3060 }
2843 //if (part.UUID != m_rootPart.UUID) 3061 part.Resize(scale);
2844 3062
2845 HasGroupChanged = true; 3063 HasGroupChanged = true;
2846 ScheduleGroupForFullUpdate(); 3064 ScheduleGroupForFullUpdate();
@@ -2882,73 +3100,71 @@ namespace OpenSim.Region.Framework.Scenes
2882 float y = (scale.Y / part.Scale.Y); 3100 float y = (scale.Y / part.Scale.Y);
2883 float z = (scale.Z / part.Scale.Z); 3101 float z = (scale.Z / part.Scale.Z);
2884 3102
2885 lock (m_parts) 3103 lockPartsForRead(true);
3104 if (x > 1.0f || y > 1.0f || z > 1.0f)
2886 { 3105 {
2887 if (x > 1.0f || y > 1.0f || z > 1.0f) 3106 foreach (SceneObjectPart obPart in m_parts.Values)
2888 { 3107 {
2889 foreach (SceneObjectPart obPart in m_parts.Values) 3108 if (obPart.UUID != m_rootPart.UUID)
2890 { 3109 {
2891 if (obPart.UUID != m_rootPart.UUID) 3110 obPart.IgnoreUndoUpdate = true;
2892 { 3111 Vector3 oldSize = new Vector3(obPart.Scale);
2893 obPart.IgnoreUndoUpdate = true;
2894 Vector3 oldSize = new Vector3(obPart.Scale);
2895 3112
2896 float f = 1.0f; 3113 float f = 1.0f;
2897 float a = 1.0f; 3114 float a = 1.0f;
2898 3115
2899 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3116 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3117 {
3118 if (oldSize.X*x > m_scene.m_maxPhys)
2900 { 3119 {
2901 if (oldSize.X*x > m_scene.m_maxPhys) 3120 f = m_scene.m_maxPhys / oldSize.X;
2902 { 3121 a = f / x;
2903 f = m_scene.m_maxPhys / oldSize.X; 3122 x *= a;
2904 a = f / x; 3123 y *= a;
2905 x *= a; 3124 z *= a;
2906 y *= a;
2907 z *= a;
2908 }
2909 if (oldSize.Y*y > m_scene.m_maxPhys)
2910 {
2911 f = m_scene.m_maxPhys / oldSize.Y;
2912 a = f / y;
2913 x *= a;
2914 y *= a;
2915 z *= a;
2916 }
2917 if (oldSize.Z*z > m_scene.m_maxPhys)
2918 {
2919 f = m_scene.m_maxPhys / oldSize.Z;
2920 a = f / z;
2921 x *= a;
2922 y *= a;
2923 z *= a;
2924 }
2925 } 3125 }
2926 else 3126 if (oldSize.Y*y > m_scene.m_maxPhys)
2927 { 3127 {
2928 if (oldSize.X*x > m_scene.m_maxNonphys) 3128 f = m_scene.m_maxPhys / oldSize.Y;
2929 { 3129 a = f / y;
2930 f = m_scene.m_maxNonphys / oldSize.X; 3130 x *= a;
2931 a = f / x; 3131 y *= a;
2932 x *= a; 3132 z *= a;
2933 y *= a; 3133 }
2934 z *= a; 3134 if (oldSize.Z*z > m_scene.m_maxPhys)
2935 } 3135 {
2936 if (oldSize.Y*y > m_scene.m_maxNonphys) 3136 f = m_scene.m_maxPhys / oldSize.Z;
2937 { 3137 a = f / z;
2938 f = m_scene.m_maxNonphys / oldSize.Y; 3138 x *= a;
2939 a = f / y; 3139 y *= a;
2940 x *= a; 3140 z *= a;
2941 y *= a; 3141 }
2942 z *= a; 3142 }
2943 } 3143 else
2944 if (oldSize.Z*z > m_scene.m_maxNonphys) 3144 {
2945 { 3145 if (oldSize.X*x > m_scene.m_maxNonphys)
2946 f = m_scene.m_maxNonphys / oldSize.Z; 3146 {
2947 a = f / z; 3147 f = m_scene.m_maxNonphys / oldSize.X;
2948 x *= a; 3148 a = f / x;
2949 y *= a; 3149 x *= a;
2950 z *= a; 3150 y *= a;
2951 } 3151 z *= a;
3152 }
3153 if (oldSize.Y*y > m_scene.m_maxNonphys)
3154 {
3155 f = m_scene.m_maxNonphys / oldSize.Y;
3156 a = f / y;
3157 x *= a;
3158 y *= a;
3159 z *= a;
3160 }
3161 if (oldSize.Z*z > m_scene.m_maxNonphys)
3162 {
3163 f = m_scene.m_maxNonphys / oldSize.Z;
3164 a = f / z;
3165 x *= a;
3166 y *= a;
3167 z *= a;
2952 } 3168 }
2953 obPart.IgnoreUndoUpdate = false; 3169 obPart.IgnoreUndoUpdate = false;
2954 obPart.StoreUndoState(); 3170 obPart.StoreUndoState();
@@ -2956,6 +3172,7 @@ namespace OpenSim.Region.Framework.Scenes
2956 } 3172 }
2957 } 3173 }
2958 } 3174 }
3175 lockPartsForRead(false);
2959 3176
2960 Vector3 prevScale = part.Scale; 3177 Vector3 prevScale = part.Scale;
2961 prevScale.X *= x; 3178 prevScale.X *= x;
@@ -2963,7 +3180,7 @@ namespace OpenSim.Region.Framework.Scenes
2963 prevScale.Z *= z; 3180 prevScale.Z *= z;
2964 part.Resize(prevScale); 3181 part.Resize(prevScale);
2965 3182
2966 lock (m_parts) 3183 lockPartsForRead(true);
2967 { 3184 {
2968 foreach (SceneObjectPart obPart in m_parts.Values) 3185 foreach (SceneObjectPart obPart in m_parts.Values)
2969 { 3186 {
@@ -2985,6 +3202,7 @@ namespace OpenSim.Region.Framework.Scenes
2985 obPart.StoreUndoState(); 3202 obPart.StoreUndoState();
2986 } 3203 }
2987 } 3204 }
3205 lockPartsForRead(false);
2988 3206
2989 if (part.PhysActor != null) 3207 if (part.PhysActor != null)
2990 { 3208 {
@@ -3087,7 +3305,7 @@ namespace OpenSim.Region.Framework.Scenes
3087 axDiff *= Quaternion.Inverse(partRotation); 3305 axDiff *= Quaternion.Inverse(partRotation);
3088 diff = axDiff; 3306 diff = axDiff;
3089 3307
3090 lock (m_parts) 3308 lockPartsForRead(true);
3091 { 3309 {
3092 foreach (SceneObjectPart obPart in m_parts.Values) 3310 foreach (SceneObjectPart obPart in m_parts.Values)
3093 { 3311 {
@@ -3097,6 +3315,7 @@ namespace OpenSim.Region.Framework.Scenes
3097 } 3315 }
3098 } 3316 }
3099 } 3317 }
3318 lockPartsForRead(false);
3100 3319
3101 AbsolutePosition = newPos; 3320 AbsolutePosition = newPos;
3102 3321
@@ -3230,25 +3449,25 @@ namespace OpenSim.Region.Framework.Scenes
3230 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3449 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3231 } 3450 }
3232 3451
3233 lock (m_parts) 3452 lockPartsForRead(true);
3453
3454 foreach (SceneObjectPart prim in m_parts.Values)
3234 { 3455 {
3235 foreach (SceneObjectPart prim in m_parts.Values) 3456 if (prim.UUID != m_rootPart.UUID)
3236 { 3457 {
3237 if (prim.UUID != m_rootPart.UUID) 3458 prim.IgnoreUndoUpdate = true;
3238 { 3459 Vector3 axPos = prim.OffsetPosition;
3239 prim.IgnoreUndoUpdate = true; 3460 axPos *= oldParentRot;
3240 Vector3 axPos = prim.OffsetPosition; 3461 axPos *= Quaternion.Inverse(axRot);
3241 axPos *= oldParentRot; 3462 prim.OffsetPosition = axPos;
3242 axPos *= Quaternion.Inverse(axRot); 3463 Quaternion primsRot = prim.RotationOffset;
3243 prim.OffsetPosition = axPos; 3464 Quaternion newRot = primsRot * oldParentRot;
3244 Quaternion primsRot = prim.RotationOffset; 3465 newRot *= Quaternion.Inverse(axRot);
3245 Quaternion newRot = primsRot * oldParentRot; 3466 prim.RotationOffset = newRot;
3246 newRot *= Quaternion.Inverse(axRot); 3467 prim.ScheduleTerseUpdate();
3247 prim.RotationOffset = newRot;
3248 prim.ScheduleTerseUpdate();
3249 }
3250 } 3468 }
3251 } 3469 }
3470
3252 foreach (SceneObjectPart childpart in Children.Values) 3471 foreach (SceneObjectPart childpart in Children.Values)
3253 { 3472 {
3254 if (childpart != m_rootPart) 3473 if (childpart != m_rootPart)
@@ -3257,6 +3476,9 @@ namespace OpenSim.Region.Framework.Scenes
3257 childpart.StoreUndoState(); 3476 childpart.StoreUndoState();
3258 } 3477 }
3259 } 3478 }
3479
3480 lockPartsForRead(false);
3481
3260 m_rootPart.ScheduleTerseUpdate(); 3482 m_rootPart.ScheduleTerseUpdate();
3261 } 3483 }
3262 3484
@@ -3378,7 +3600,7 @@ namespace OpenSim.Region.Framework.Scenes
3378 if (atTargets.Count > 0) 3600 if (atTargets.Count > 0)
3379 { 3601 {
3380 uint[] localids = new uint[0]; 3602 uint[] localids = new uint[0];
3381 lock (m_parts) 3603 lockPartsForRead(true);
3382 { 3604 {
3383 localids = new uint[m_parts.Count]; 3605 localids = new uint[m_parts.Count];
3384 int cntr = 0; 3606 int cntr = 0;
@@ -3388,6 +3610,7 @@ namespace OpenSim.Region.Framework.Scenes
3388 cntr++; 3610 cntr++;
3389 } 3611 }
3390 } 3612 }
3613 lockPartsForRead(false);
3391 3614
3392 for (int ctr = 0; ctr < localids.Length; ctr++) 3615 for (int ctr = 0; ctr < localids.Length; ctr++)
3393 { 3616 {
@@ -3406,7 +3629,7 @@ namespace OpenSim.Region.Framework.Scenes
3406 { 3629 {
3407 //trigger not_at_target 3630 //trigger not_at_target
3408 uint[] localids = new uint[0]; 3631 uint[] localids = new uint[0];
3409 lock (m_parts) 3632 lockPartsForRead(true);
3410 { 3633 {
3411 localids = new uint[m_parts.Count]; 3634 localids = new uint[m_parts.Count];
3412 int cntr = 0; 3635 int cntr = 0;
@@ -3416,7 +3639,8 @@ namespace OpenSim.Region.Framework.Scenes
3416 cntr++; 3639 cntr++;
3417 } 3640 }
3418 } 3641 }
3419 3642 lockPartsForRead(false);
3643
3420 for (int ctr = 0; ctr < localids.Length; ctr++) 3644 for (int ctr = 0; ctr < localids.Length; ctr++)
3421 { 3645 {
3422 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3646 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3508,19 +3732,20 @@ namespace OpenSim.Region.Framework.Scenes
3508 public float GetMass() 3732 public float GetMass()
3509 { 3733 {
3510 float retmass = 0f; 3734 float retmass = 0f;
3511 lock (m_parts) 3735 lockPartsForRead(true);
3512 { 3736 {
3513 foreach (SceneObjectPart part in m_parts.Values) 3737 foreach (SceneObjectPart part in m_parts.Values)
3514 { 3738 {
3515 retmass += part.GetMass(); 3739 retmass += part.GetMass();
3516 } 3740 }
3517 } 3741 }
3742 lockPartsForRead(false);
3518 return retmass; 3743 return retmass;
3519 } 3744 }
3520 3745
3521 public void CheckSculptAndLoad() 3746 public void CheckSculptAndLoad()
3522 { 3747 {
3523 lock (m_parts) 3748 lockPartsForRead(true);
3524 { 3749 {
3525 if (!IsDeleted) 3750 if (!IsDeleted)
3526 { 3751 {
@@ -3545,6 +3770,7 @@ namespace OpenSim.Region.Framework.Scenes
3545 } 3770 }
3546 } 3771 }
3547 } 3772 }
3773 lockPartsForRead(false);
3548 } 3774 }
3549 3775
3550 protected void AssetReceived(string id, Object sender, AssetBase asset) 3776 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3565,7 +3791,7 @@ namespace OpenSim.Region.Framework.Scenes
3565 /// <param name="client"></param> 3791 /// <param name="client"></param>
3566 public void SetGroup(UUID GroupID, IClientAPI client) 3792 public void SetGroup(UUID GroupID, IClientAPI client)
3567 { 3793 {
3568 lock (m_parts) 3794 lockPartsForRead(true);
3569 { 3795 {
3570 foreach (SceneObjectPart part in m_parts.Values) 3796 foreach (SceneObjectPart part in m_parts.Values)
3571 { 3797 {
@@ -3575,6 +3801,7 @@ namespace OpenSim.Region.Framework.Scenes
3575 3801
3576 HasGroupChanged = true; 3802 HasGroupChanged = true;
3577 } 3803 }
3804 lockPartsForRead(false);
3578 3805
3579 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3806 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
3580 // for the same object with very different properties. The caller must schedule the update. 3807 // for the same object with very different properties. The caller must schedule the update.
@@ -3596,11 +3823,12 @@ namespace OpenSim.Region.Framework.Scenes
3596 3823
3597 public void SetAttachmentPoint(byte point) 3824 public void SetAttachmentPoint(byte point)
3598 { 3825 {
3599 lock (m_parts) 3826 lockPartsForRead(true);
3600 { 3827 {
3601 foreach (SceneObjectPart part in m_parts.Values) 3828 foreach (SceneObjectPart part in m_parts.Values)
3602 part.SetAttachmentPoint(point); 3829 part.SetAttachmentPoint(point);
3603 } 3830 }
3831 lockPartsForRead(false);
3604 } 3832 }
3605 3833
3606 #region ISceneObject 3834 #region ISceneObject
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index a85a4b3..548a64f 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();
@@ -1937,12 +1948,17 @@ namespace OpenSim.Region.Framework.Scenes
1937 public Vector3 GetWorldPosition() 1948 public Vector3 GetWorldPosition()
1938 { 1949 {
1939 Quaternion parentRot = ParentGroup.RootPart.RotationOffset; 1950 Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
1940
1941 Vector3 axPos = OffsetPosition; 1951 Vector3 axPos = OffsetPosition;
1942
1943 axPos *= parentRot; 1952 axPos *= parentRot;
1944 Vector3 translationOffsetPosition = axPos; 1953 Vector3 translationOffsetPosition = axPos;
1945 return GroupPosition + translationOffsetPosition; 1954 if(_parentID == 0)
1955 {
1956 return GroupPosition;
1957 }
1958 else
1959 {
1960 return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position
1961 }
1946 } 1962 }
1947 1963
1948 /// <summary> 1964 /// <summary>
@@ -1953,7 +1969,7 @@ namespace OpenSim.Region.Framework.Scenes
1953 { 1969 {
1954 Quaternion newRot; 1970 Quaternion newRot;
1955 1971
1956 if (this.LinkNum == 0) 1972 if (this.LinkNum < 2) //KF Single or root prim
1957 { 1973 {
1958 newRot = RotationOffset; 1974 newRot = RotationOffset;
1959 } 1975 }
@@ -2610,17 +2626,18 @@ namespace OpenSim.Region.Framework.Scenes
2610 //Trys to fetch sound id from prim's inventory. 2626 //Trys to fetch sound id from prim's inventory.
2611 //Prim's inventory doesn't support non script items yet 2627 //Prim's inventory doesn't support non script items yet
2612 2628
2613 lock (TaskInventory) 2629 TaskInventory.LockItemsForRead(true);
2630
2631 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2614 { 2632 {
2615 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2633 if (item.Value.Name == sound)
2616 { 2634 {
2617 if (item.Value.Name == sound) 2635 soundID = item.Value.ItemID;
2618 { 2636 break;
2619 soundID = item.Value.ItemID;
2620 break;
2621 }
2622 } 2637 }
2623 } 2638 }
2639
2640 TaskInventory.LockItemsForRead(false);
2624 } 2641 }
2625 2642
2626 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 2643 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
@@ -2688,38 +2705,7 @@ namespace OpenSim.Region.Framework.Scenes
2688 2705
2689 public void RotLookAt(Quaternion target, float strength, float damping) 2706 public void RotLookAt(Quaternion target, float strength, float damping)
2690 { 2707 {
2691 rotLookAt(target, strength, damping); 2708 m_parentGroup.rotLookAt(target, strength, damping); // This calls method in SceneObjectGroup.
2692 }
2693
2694 public void rotLookAt(Quaternion target, float strength, float damping)
2695 {
2696 if (IsAttachment)
2697 {
2698 /*
2699 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2700 if (avatar != null)
2701 {
2702 Rotate the Av?
2703 } */
2704 }
2705 else
2706 {
2707 APIDDamp = damping;
2708 APIDStrength = strength;
2709 APIDTarget = target;
2710 }
2711 }
2712
2713 public void startLookAt(Quaternion rot, float damp, float strength)
2714 {
2715 APIDDamp = damp;
2716 APIDStrength = strength;
2717 APIDTarget = rot;
2718 }
2719
2720 public void stopLookAt()
2721 {
2722 APIDTarget = Quaternion.Identity;
2723 } 2709 }
2724 2710
2725 /// <summary> 2711 /// <summary>
@@ -2927,8 +2913,8 @@ namespace OpenSim.Region.Framework.Scenes
2927 { 2913 {
2928 const float ROTATION_TOLERANCE = 0.01f; 2914 const float ROTATION_TOLERANCE = 0.01f;
2929 const float VELOCITY_TOLERANCE = 0.001f; 2915 const float VELOCITY_TOLERANCE = 0.001f;
2930 const float POSITION_TOLERANCE = 0.05f; 2916 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2931 const int TIME_MS_TOLERANCE = 3000; 2917 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2932 2918
2933 if (m_updateFlag == 1) 2919 if (m_updateFlag == 1)
2934 { 2920 {
@@ -2942,7 +2928,7 @@ namespace OpenSim.Region.Framework.Scenes
2942 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2928 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2943 { 2929 {
2944 AddTerseUpdateToAllAvatars(); 2930 AddTerseUpdateToAllAvatars();
2945 ClearUpdateSchedule(); 2931
2946 2932
2947 // This causes the Scene to 'poll' physical objects every couple of frames 2933 // This causes the Scene to 'poll' physical objects every couple of frames
2948 // bad, so it's been replaced by an event driven method. 2934 // bad, so it's been replaced by an event driven method.
@@ -2960,16 +2946,18 @@ namespace OpenSim.Region.Framework.Scenes
2960 m_lastAngularVelocity = AngularVelocity; 2946 m_lastAngularVelocity = AngularVelocity;
2961 m_lastTerseSent = Environment.TickCount; 2947 m_lastTerseSent = Environment.TickCount;
2962 } 2948 }
2949 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
2950 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
2963 } 2951 }
2964 else 2952 else
2965 { 2953 {
2966 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes 2954 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
2967 { 2955 {
2968 AddFullUpdateToAllAvatars(); 2956 AddFullUpdateToAllAvatars();
2969 ClearUpdateSchedule(); 2957 m_updateFlag = 0; //Same here
2970 } 2958 }
2971 } 2959 }
2972 ClearUpdateSchedule(); 2960 m_updateFlag = 0;
2973 } 2961 }
2974 2962
2975 /// <summary> 2963 /// <summary>
@@ -2996,17 +2984,16 @@ namespace OpenSim.Region.Framework.Scenes
2996 if (!UUID.TryParse(sound, out soundID)) 2984 if (!UUID.TryParse(sound, out soundID))
2997 { 2985 {
2998 // search sound file from inventory 2986 // search sound file from inventory
2999 lock (TaskInventory) 2987 TaskInventory.LockItemsForRead(true);
2988 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3000 { 2989 {
3001 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2990 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3002 { 2991 {
3003 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 2992 soundID = item.Value.ItemID;
3004 { 2993 break;
3005 soundID = item.Value.ItemID;
3006 break;
3007 }
3008 } 2994 }
3009 } 2995 }
2996 TaskInventory.LockItemsForRead(false);
3010 } 2997 }
3011 2998
3012 if (soundID == UUID.Zero) 2999 if (soundID == UUID.Zero)
@@ -3442,7 +3429,7 @@ namespace OpenSim.Region.Framework.Scenes
3442 3429
3443 public void StopLookAt() 3430 public void StopLookAt()
3444 { 3431 {
3445 m_parentGroup.stopLookAt(); 3432 m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup.
3446 3433
3447 m_parentGroup.ScheduleGroupForTerseUpdate(); 3434 m_parentGroup.ScheduleGroupForTerseUpdate();
3448 } 3435 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index a555eae..d03b464 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, GetScriptErrors(item.ItemID));
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, GetScriptErrors(item.ItemID));
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
@@ -379,21 +394,80 @@ namespace OpenSim.Region.Framework.Scenes
379 /// </param> 394 /// </param>
380 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 395 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
381 { 396 {
382 lock (m_items) 397 m_items.LockItemsForRead(true);
398 if (m_items.ContainsKey(itemId))
383 { 399 {
384 if (m_items.ContainsKey(itemId)) 400 if (m_items.ContainsKey(itemId))
385 { 401 {
402 m_items.LockItemsForRead(false);
386 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); 403 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
387 } 404 }
388 else 405 else
389 { 406 {
407 m_items.LockItemsForRead(false);
408 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
409 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
410 StoreScriptError(itemId, msg);
390 m_log.ErrorFormat( 411 m_log.ErrorFormat(
391 "[PRIM INVENTORY]: " + 412 "[PRIM INVENTORY]: " +
392 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 413 "Couldn't start script with ID {0} since it {1}", itemId, msg);
393 itemId, m_part.Name, m_part.UUID,
394 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
395 } 414 }
396 } 415 }
416 else
417 {
418 m_items.LockItemsForRead(false);
419 string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID);
420 StoreScriptError(itemId, msg);
421 m_log.ErrorFormat(
422 "[PRIM INVENTORY]: " +
423 "Couldn't start script with ID {0} since it {1}", itemId, msg);
424 }
425
426 }
427
428 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
429 {
430 ArrayList errors;
431
432 lock (m_scriptErrors)
433 {
434 m_scriptErrors.Remove(itemId);
435 }
436 CreateScriptInstance(itemId, startParam, postOnRez, engine, stateSource);
437 lock (m_scriptErrors)
438 {
439 while (!m_scriptErrors.TryGetValue(itemId, out errors))
440 {
441 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
442 {
443 m_log.ErrorFormat(
444 "[PRIM INVENTORY]: " +
445 "timedout waiting for script {0} errors", itemId);
446 if (!m_scriptErrors.TryGetValue(itemId, out errors))
447 {
448 errors = new ArrayList(1);
449 errors.Add("timedout waiting for errors");
450 }
451 break;
452 }
453 }
454 m_scriptErrors.Remove(itemId);
455 }
456 return errors;
457 }
458 private void StoreScriptErrors(UUID itemId, ArrayList errors)
459 {
460 lock (m_scriptErrors)
461 {
462 m_scriptErrors[itemId] = errors;
463 System.Threading.Monitor.PulseAll(m_scriptErrors);
464 }
465 }
466 private void StoreScriptError(UUID itemId, string message)
467 {
468 ArrayList errors = new ArrayList(1);
469 errors.Add(message);
470 StoreScriptErrors(itemId, errors);
397 } 471 }
398 472
399 /// <summary> 473 /// <summary>
@@ -406,15 +480,7 @@ namespace OpenSim.Region.Framework.Scenes
406 /// </param> 480 /// </param>
407 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 481 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
408 { 482 {
409 bool scriptPresent = false; 483 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 { 484 {
419 if (!sceneObjectBeingDeleted) 485 if (!sceneObjectBeingDeleted)
420 m_part.RemoveScriptEvents(itemId); 486 m_part.RemoveScriptEvents(itemId);
@@ -440,11 +506,16 @@ namespace OpenSim.Region.Framework.Scenes
440 /// <returns></returns> 506 /// <returns></returns>
441 private bool InventoryContainsName(string name) 507 private bool InventoryContainsName(string name)
442 { 508 {
443 foreach (TaskInventoryItem item in Items.Values) 509 m_items.LockItemsForRead(true);
510 foreach (TaskInventoryItem item in m_items.Values)
444 { 511 {
445 if (item.Name == name) 512 if (item.Name == name)
513 {
514 m_items.LockItemsForRead(false);
446 return true; 515 return true;
516 }
447 } 517 }
518 m_items.LockItemsForRead(false);
448 return false; 519 return false;
449 } 520 }
450 521
@@ -486,13 +557,9 @@ namespace OpenSim.Region.Framework.Scenes
486 /// <param name="item"></param> 557 /// <param name="item"></param>
487 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 558 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
488 { 559 {
489 List<TaskInventoryItem> il; 560 m_items.LockItemsForRead(true);
490 561 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
491 lock (m_items) 562 m_items.LockItemsForRead(false);
492 {
493 il = new List<TaskInventoryItem>(m_items.Values);
494 }
495
496 foreach (TaskInventoryItem i in il) 563 foreach (TaskInventoryItem i in il)
497 { 564 {
498 if (i.Name == item.Name) 565 if (i.Name == item.Name)
@@ -529,15 +596,14 @@ namespace OpenSim.Region.Framework.Scenes
529 item.ParentPartID = m_part.UUID; 596 item.ParentPartID = m_part.UUID;
530 item.Name = name; 597 item.Name = name;
531 598
532 lock (m_items) 599 m_items.LockItemsForWrite(true);
533 { 600 m_items.Add(item.ItemID, item);
534 m_items.Add(item.ItemID, item); 601 m_items.LockItemsForWrite(false);
535
536 if (allowedDrop) 602 if (allowedDrop)
537 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 603 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
538 else 604 else
539 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 605 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
540 } 606
541 607
542 m_inventorySerial++; 608 m_inventorySerial++;
543 //m_inventorySerial += 2; 609 //m_inventorySerial += 2;
@@ -554,14 +620,13 @@ namespace OpenSim.Region.Framework.Scenes
554 /// <param name="items"></param> 620 /// <param name="items"></param>
555 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 621 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
556 { 622 {
557 lock (m_items) 623 m_items.LockItemsForWrite(true);
624 foreach (TaskInventoryItem item in items)
558 { 625 {
559 foreach (TaskInventoryItem item in items) 626 m_items.Add(item.ItemID, item);
560 { 627 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
561 m_items.Add(item.ItemID, item);
562 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
563 }
564 } 628 }
629 m_items.LockItemsForWrite(false);
565 630
566 m_inventorySerial++; 631 m_inventorySerial++;
567 } 632 }
@@ -574,10 +639,9 @@ namespace OpenSim.Region.Framework.Scenes
574 public TaskInventoryItem GetInventoryItem(UUID itemId) 639 public TaskInventoryItem GetInventoryItem(UUID itemId)
575 { 640 {
576 TaskInventoryItem item; 641 TaskInventoryItem item;
577 642 m_items.LockItemsForRead(true);
578 lock (m_items) 643 m_items.TryGetValue(itemId, out item);
579 m_items.TryGetValue(itemId, out item); 644 m_items.LockItemsForRead(false);
580
581 return item; 645 return item;
582 } 646 }
583 647
@@ -613,46 +677,46 @@ namespace OpenSim.Region.Framework.Scenes
613 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 677 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
614 public bool UpdateInventoryItem(TaskInventoryItem item) 678 public bool UpdateInventoryItem(TaskInventoryItem item)
615 { 679 {
616 lock (m_items) 680 m_items.LockItemsForWrite(true);
681
682 if (m_items.ContainsKey(item.ItemID))
617 { 683 {
618 if (m_items.ContainsKey(item.ItemID)) 684 item.ParentID = m_part.UUID;
685 item.ParentPartID = m_part.UUID;
686 item.Flags = m_items[item.ItemID].Flags;
687 if (item.AssetID == UUID.Zero)
619 { 688 {
620 item.ParentID = m_part.UUID; 689 item.AssetID = m_items[item.ItemID].AssetID;
621 item.ParentPartID = m_part.UUID; 690 }
622 item.Flags = m_items[item.ItemID].Flags; 691 else if ((InventoryType)item.Type == InventoryType.Notecard)
623 if (item.AssetID == UUID.Zero) 692 {
624 { 693 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 694
631 if (presence != null) 695 if (presence != null)
632 { 696 {
633 presence.ControllingClient.SendAgentAlertMessage( 697 presence.ControllingClient.SendAgentAlertMessage(
634 "Notecard saved", false); 698 "Notecard saved", false);
635 }
636 } 699 }
700 }
637 701
638 m_items[item.ItemID] = item; 702 m_items[item.ItemID] = item;
639 m_inventorySerial++; 703 m_inventorySerial++;
640 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 704 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
641
642 HasInventoryChanged = true;
643 m_part.ParentGroup.HasGroupChanged = true;
644 705
645 return true; 706 HasInventoryChanged = true;
646 } 707 m_part.ParentGroup.HasGroupChanged = true;
647 else 708 m_items.LockItemsForWrite(false);
648 { 709 return true;
649 m_log.ErrorFormat( 710 }
650 "[PRIM INVENTORY]: " + 711 else
651 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 712 {
652 item.ItemID, m_part.Name, m_part.UUID, 713 m_log.ErrorFormat(
653 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 714 "[PRIM INVENTORY]: " +
654 } 715 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
716 item.ItemID, m_part.Name, m_part.UUID,
717 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
655 } 718 }
719 m_items.LockItemsForWrite(false);
656 720
657 return false; 721 return false;
658 } 722 }
@@ -665,53 +729,54 @@ namespace OpenSim.Region.Framework.Scenes
665 /// in this prim's inventory.</returns> 729 /// in this prim's inventory.</returns>
666 public int RemoveInventoryItem(UUID itemID) 730 public int RemoveInventoryItem(UUID itemID)
667 { 731 {
668 lock (m_items) 732 m_items.LockItemsForRead(true);
733
734 if (m_items.ContainsKey(itemID))
669 { 735 {
670 if (m_items.ContainsKey(itemID)) 736 int type = m_items[itemID].InvType;
737 m_items.LockItemsForRead(false);
738 if (type == 10) // Script
671 { 739 {
672 int type = m_items[itemID].InvType; 740 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
673 if (type == 10) // Script 741 }
674 { 742 m_items.LockItemsForWrite(true);
675 m_part.RemoveScriptEvents(itemID); 743 m_items.Remove(itemID);
676 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 744 m_items.LockItemsForWrite(false);
677 } 745 m_inventorySerial++;
678 m_items.Remove(itemID); 746 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
679 m_inventorySerial++;
680 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
681
682 HasInventoryChanged = true;
683 m_part.ParentGroup.HasGroupChanged = true;
684 747
685 int scriptcount = 0; 748 HasInventoryChanged = true;
686 lock (m_items) 749 m_part.ParentGroup.HasGroupChanged = true;
687 {
688 foreach (TaskInventoryItem item in m_items.Values)
689 {
690 if (item.Type == 10)
691 {
692 scriptcount++;
693 }
694 }
695 }
696 750
697 if (scriptcount <= 0) 751 int scriptcount = 0;
752 m_items.LockItemsForRead(true);
753 foreach (TaskInventoryItem item in m_items.Values)
754 {
755 if (item.Type == 10)
698 { 756 {
699 m_part.RemFlag(PrimFlags.Scripted); 757 scriptcount++;
700 } 758 }
701
702 m_part.ScheduleFullUpdate();
703
704 return type;
705 } 759 }
706 else 760 m_items.LockItemsForRead(false);
761
762
763 if (scriptcount <= 0)
707 { 764 {
708 m_log.ErrorFormat( 765 m_part.RemFlag(PrimFlags.Scripted);
709 "[PRIM INVENTORY]: " +
710 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
711 itemID, m_part.Name, m_part.UUID,
712 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
713 } 766 }
767
768 m_part.ScheduleFullUpdate();
769
770 return type;
771 }
772 else
773 {
774 m_log.ErrorFormat(
775 "[PRIM INVENTORY]: " +
776 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
777 itemID, m_part.Name, m_part.UUID);
714 } 778 }
779 m_items.LockItemsForWrite(false);
715 780
716 return -1; 781 return -1;
717 } 782 }
@@ -764,52 +829,53 @@ namespace OpenSim.Region.Framework.Scenes
764 // isn't available (such as drag from prim inventory to agent inventory) 829 // isn't available (such as drag from prim inventory to agent inventory)
765 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 830 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
766 831
767 lock (m_items) 832 m_items.LockItemsForRead(true);
833
834 foreach (TaskInventoryItem item in m_items.Values)
768 { 835 {
769 foreach (TaskInventoryItem item in m_items.Values) 836 UUID ownerID = item.OwnerID;
770 { 837 uint everyoneMask = 0;
771 UUID ownerID = item.OwnerID; 838 uint baseMask = item.BasePermissions;
772 uint everyoneMask = 0; 839 uint ownerMask = item.CurrentPermissions;
773 uint baseMask = item.BasePermissions;
774 uint ownerMask = item.CurrentPermissions;
775 840
776 invString.AddItemStart(); 841 invString.AddItemStart();
777 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 842 invString.AddNameValueLine("item_id", item.ItemID.ToString());
778 invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); 843 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
779 844
780 invString.AddPermissionsStart(); 845 invString.AddPermissionsStart();
781 846
782 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 847 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
783 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 848 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
784 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0)); 849 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0));
785 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 850 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
786 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 851 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
787 852
788 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 853 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
789 invString.AddNameValueLine("owner_id", ownerID.ToString()); 854 invString.AddNameValueLine("owner_id", ownerID.ToString());
790 855
791 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 856 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
792 857
793 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 858 invString.AddNameValueLine("group_id", item.GroupID.ToString());
794 invString.AddSectionEnd(); 859 invString.AddSectionEnd();
795 860
796 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 861 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
797 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 862 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
798 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 863 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
799 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 864 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
800 865
801 invString.AddSaleStart(); 866 invString.AddSaleStart();
802 invString.AddNameValueLine("sale_type", "not"); 867 invString.AddNameValueLine("sale_type", "not");
803 invString.AddNameValueLine("sale_price", "0"); 868 invString.AddNameValueLine("sale_price", "0");
804 invString.AddSectionEnd(); 869 invString.AddSectionEnd();
805 870
806 invString.AddNameValueLine("name", item.Name + "|"); 871 invString.AddNameValueLine("name", item.Name + "|");
807 invString.AddNameValueLine("desc", item.Description + "|"); 872 invString.AddNameValueLine("desc", item.Description + "|");
808 873
809 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 874 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
810 invString.AddSectionEnd(); 875 invString.AddSectionEnd();
811 }
812 } 876 }
877 int count = m_items.Count;
878 m_items.LockItemsForRead(false);
813 879
814 fileData = Utils.StringToBytes(invString.BuildString); 880 fileData = Utils.StringToBytes(invString.BuildString);
815 881
@@ -830,10 +896,9 @@ namespace OpenSim.Region.Framework.Scenes
830 { 896 {
831 if (HasInventoryChanged) 897 if (HasInventoryChanged)
832 { 898 {
833 lock (Items) 899 Items.LockItemsForRead(true);
834 { 900 datastore.StorePrimInventory(m_part.UUID, Items.Values);
835 datastore.StorePrimInventory(m_part.UUID, Items.Values); 901 Items.LockItemsForRead(false);
836 }
837 902
838 HasInventoryChanged = false; 903 HasInventoryChanged = false;
839 } 904 }
@@ -902,61 +967,54 @@ namespace OpenSim.Region.Framework.Scenes
902 { 967 {
903 uint mask=0x7fffffff; 968 uint mask=0x7fffffff;
904 969
905 lock (m_items) 970 foreach (TaskInventoryItem item in m_items.Values)
906 { 971 {
907 foreach (TaskInventoryItem item in m_items.Values) 972 if (item.InvType != (int)InventoryType.Object)
908 { 973 {
909 if (item.InvType != (int)InventoryType.Object) 974 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
910 { 975 mask &= ~((uint)PermissionMask.Copy >> 13);
911 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 976 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
912 mask &= ~((uint)PermissionMask.Copy >> 13); 977 mask &= ~((uint)PermissionMask.Transfer >> 13);
913 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 978 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
914 mask &= ~((uint)PermissionMask.Transfer >> 13); 979 mask &= ~((uint)PermissionMask.Modify >> 13);
915 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 980 }
916 mask &= ~((uint)PermissionMask.Modify >> 13); 981 else
917 } 982 {
918 else 983 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
919 { 984 mask &= ~((uint)PermissionMask.Copy >> 13);
920 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 985 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
921 mask &= ~((uint)PermissionMask.Copy >> 13); 986 mask &= ~((uint)PermissionMask.Transfer >> 13);
922 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 987 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
923 mask &= ~((uint)PermissionMask.Transfer >> 13); 988 mask &= ~((uint)PermissionMask.Modify >> 13);
924 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
925 mask &= ~((uint)PermissionMask.Modify >> 13);
926 }
927
928 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
929 mask &= ~(uint)PermissionMask.Copy;
930 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
931 mask &= ~(uint)PermissionMask.Transfer;
932 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
933 mask &= ~(uint)PermissionMask.Modify;
934 } 989 }
990
991 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
992 mask &= ~(uint)PermissionMask.Copy;
993 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
994 mask &= ~(uint)PermissionMask.Transfer;
995 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
996 mask &= ~(uint)PermissionMask.Modify;
935 } 997 }
936
937 return mask; 998 return mask;
938 } 999 }
939 1000
940 public void ApplyNextOwnerPermissions() 1001 public void ApplyNextOwnerPermissions()
941 { 1002 {
942 lock (m_items) 1003 foreach (TaskInventoryItem item in m_items.Values)
943 { 1004 {
944 foreach (TaskInventoryItem item in m_items.Values) 1005 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
945 { 1006 {
946 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1007 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
947 { 1008 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
948 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1009 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
949 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 1010 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
950 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1011 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
951 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 1012 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
952 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 1013 item.CurrentPermissions |= 8;
953 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
954 item.CurrentPermissions |= 8;
955 }
956 item.CurrentPermissions &= item.NextPermissions;
957 item.BasePermissions &= item.NextPermissions;
958 item.EveryonePermissions &= item.NextPermissions;
959 } 1014 }
1015 item.CurrentPermissions &= item.NextPermissions;
1016 item.BasePermissions &= item.NextPermissions;
1017 item.EveryonePermissions &= item.NextPermissions;
960 } 1018 }
961 1019
962 m_part.TriggerScriptChangedEvent(Changed.OWNER); 1020 m_part.TriggerScriptChangedEvent(Changed.OWNER);
@@ -964,29 +1022,22 @@ namespace OpenSim.Region.Framework.Scenes
964 1022
965 public void ApplyGodPermissions(uint perms) 1023 public void ApplyGodPermissions(uint perms)
966 { 1024 {
967 lock (m_items) 1025 foreach (TaskInventoryItem item in m_items.Values)
968 { 1026 {
969 foreach (TaskInventoryItem item in m_items.Values) 1027 item.CurrentPermissions = perms;
970 { 1028 item.BasePermissions = perms;
971 item.CurrentPermissions = perms;
972 item.BasePermissions = perms;
973 }
974 } 1029 }
975 } 1030 }
976 1031
977 public bool ContainsScripts() 1032 public bool ContainsScripts()
978 { 1033 {
979 lock (m_items) 1034 foreach (TaskInventoryItem item in m_items.Values)
980 { 1035 {
981 foreach (TaskInventoryItem item in m_items.Values) 1036 if (item.InvType == (int)InventoryType.LSL)
982 { 1037 {
983 if (item.InvType == (int)InventoryType.LSL) 1038 return true;
984 {
985 return true;
986 }
987 } 1039 }
988 } 1040 }
989
990 return false; 1041 return false;
991 } 1042 }
992 1043
@@ -994,11 +1045,8 @@ namespace OpenSim.Region.Framework.Scenes
994 { 1045 {
995 List<UUID> ret = new List<UUID>(); 1046 List<UUID> ret = new List<UUID>();
996 1047
997 lock (m_items) 1048 foreach (TaskInventoryItem item in m_items.Values)
998 { 1049 ret.Add(item.ItemID);
999 foreach (TaskInventoryItem item in m_items.Values)
1000 ret.Add(item.ItemID);
1001 }
1002 1050
1003 return ret; 1051 return ret;
1004 } 1052 }
@@ -1011,30 +1059,26 @@ namespace OpenSim.Region.Framework.Scenes
1011 if (engines == null) // No engine at all 1059 if (engines == null) // No engine at all
1012 return ret; 1060 return ret;
1013 1061
1014 lock (m_items) 1062 foreach (TaskInventoryItem item in m_items.Values)
1015 { 1063 {
1016 foreach (TaskInventoryItem item in m_items.Values) 1064 if (item.InvType == (int)InventoryType.LSL)
1017 { 1065 {
1018 if (item.InvType == (int)InventoryType.LSL) 1066 foreach (IScriptModule e in engines)
1019 { 1067 {
1020 foreach (IScriptModule e in engines) 1068 if (e != null)
1021 { 1069 {
1022 if (e != null) 1070 string n = e.GetXMLState(item.ItemID);
1071 if (n != String.Empty)
1023 { 1072 {
1024 string n = e.GetXMLState(item.ItemID); 1073 if (!ret.ContainsKey(item.ItemID))
1025 if (n != String.Empty) 1074 ret[item.ItemID] = n;
1026 { 1075 break;
1027 if (!ret.ContainsKey(item.ItemID))
1028 ret[item.ItemID] = n;
1029 break;
1030 }
1031 } 1076 }
1032 } 1077 }
1033 } 1078 }
1034 } 1079 }
1035 } 1080 }
1036
1037 return ret; 1081 return ret;
1038 } 1082 }
1039 } 1083 }
1040} \ No newline at end of file 1084}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 4973663..2603fe1 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
127 private Vector3 m_lastPosition; 129 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
130 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
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 }
@@ -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
@@ -826,9 +857,24 @@ namespace OpenSim.Region.Framework.Scenes
826 { 857 {
827 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 858 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
828 pos.Y = crossedBorder.BorderLine.Z - 1; 859 pos.Y = crossedBorder.BorderLine.Z - 1;
860 }
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 }
829 } 876 }
830 877
831
832 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) 878 if (pos.X < 0 || pos.Y < 0 || pos.Z < 0)
833 { 879 {
834 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128); 880 Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128);
@@ -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;
991 if (m_physicsActor != null)
992 isFlying = m_physicsActor.Flying;
993 1037
1038 if (m_physicsActor != null)
1039 isFlying = m_physicsActor.Flying;
1040
994 RemoveFromPhysicalScene(); 1041 RemoveFromPhysicalScene();
995 Velocity = Vector3.Zero; 1042 Velocity = Vector3.Zero;
996 AbsolutePosition = pos; 1043 AbsolutePosition = pos;
@@ -1001,7 +1048,8 @@ namespace OpenSim.Region.Framework.Scenes
1001 SetHeight(m_appearance.AvatarHeight); 1048 SetHeight(m_appearance.AvatarHeight);
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 {
@@ -1453,6 +1494,9 @@ namespace OpenSim.Region.Framework.Scenes
1453 // Ignore z component of vector 1494 // Ignore z component of vector
1454 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1495 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1455 LocalVectorToTarget2D.Normalize(); 1496 LocalVectorToTarget2D.Normalize();
1497
1498 //We're not nudging
1499 Nudging = false;
1456 agent_control_v3 += LocalVectorToTarget2D; 1500 agent_control_v3 += LocalVectorToTarget2D;
1457 1501
1458 // update avatar movement flags. the avatar coordinate system is as follows: 1502 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1541,13 +1585,13 @@ namespace OpenSim.Region.Framework.Scenes
1541 // m_log.DebugFormat( 1585 // m_log.DebugFormat(
1542 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1586 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1543 1587
1544 AddNewMovement(agent_control_v3, q); 1588 AddNewMovement(agent_control_v3, q, Nudging);
1545 1589
1546 1590
1547 } 1591 }
1548 } 1592 }
1549 1593
1550 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1594 if (update_movementflag)
1551 Animator.UpdateMovementAnimations(); 1595 Animator.UpdateMovementAnimations();
1552 1596
1553 m_scene.EventManager.TriggerOnClientMovement(this); 1597 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1562,7 +1606,6 @@ namespace OpenSim.Region.Framework.Scenes
1562 m_sitAtAutoTarget = false; 1606 m_sitAtAutoTarget = false;
1563 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1607 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1564 //proxy.PCode = (byte)PCode.ParticleSystem; 1608 //proxy.PCode = (byte)PCode.ParticleSystem;
1565
1566 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1609 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1567 proxyObjectGroup.AttachToScene(m_scene); 1610 proxyObjectGroup.AttachToScene(m_scene);
1568 1611
@@ -1604,7 +1647,7 @@ namespace OpenSim.Region.Framework.Scenes
1604 } 1647 }
1605 m_moveToPositionInProgress = true; 1648 m_moveToPositionInProgress = true;
1606 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1649 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1607 } 1650 }
1608 catch (Exception ex) 1651 catch (Exception ex)
1609 { 1652 {
1610 //Why did I get this error? 1653 //Why did I get this error?
@@ -1626,7 +1669,7 @@ namespace OpenSim.Region.Framework.Scenes
1626 Velocity = Vector3.Zero; 1669 Velocity = Vector3.Zero;
1627 SendFullUpdateToAllClients(); 1670 SendFullUpdateToAllClients();
1628 1671
1629 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1672 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1630 } 1673 }
1631 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1674 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1632 m_requestedSitTargetUUID = UUID.Zero; 1675 m_requestedSitTargetUUID = UUID.Zero;
@@ -1659,55 +1702,84 @@ namespace OpenSim.Region.Framework.Scenes
1659 /// </summary> 1702 /// </summary>
1660 public void StandUp() 1703 public void StandUp()
1661 { 1704 {
1662 if (SitGround)
1663 SitGround = false;
1664
1665 if (m_parentID != 0) 1705 if (m_parentID != 0)
1666 { 1706 {
1667 m_log.Debug("StandupCode Executed");
1668 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1707 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1669 if (part != null) 1708 if (part != null)
1670 { 1709 {
1710 part.TaskInventory.LockItemsForRead(true);
1671 TaskInventoryDictionary taskIDict = part.TaskInventory; 1711 TaskInventoryDictionary taskIDict = part.TaskInventory;
1672 if (taskIDict != null) 1712 if (taskIDict != null)
1673 { 1713 {
1674 lock (taskIDict) 1714 foreach (UUID taskID in taskIDict.Keys)
1675 { 1715 {
1676 foreach (UUID taskID in taskIDict.Keys) 1716 UnRegisterControlEventsToScript(LocalId, taskID);
1677 { 1717 taskIDict[taskID].PermsMask &= ~(
1678 UnRegisterControlEventsToScript(LocalId, taskID); 1718 2048 | //PERMISSION_CONTROL_CAMERA
1679 taskIDict[taskID].PermsMask &= ~( 1719 4); // PERMISSION_TAKE_CONTROLS
1680 2048 | //PERMISSION_CONTROL_CAMERA
1681 4); // PERMISSION_TAKE_CONTROLS
1682 }
1683 } 1720 }
1684
1685 } 1721 }
1722 part.TaskInventory.LockItemsForRead(false);
1686 // Reset sit target. 1723 // Reset sit target.
1687 if (part.GetAvatarOnSitTarget() == UUID) 1724 if (part.GetAvatarOnSitTarget() == UUID)
1688 part.SetAvatarOnSitTarget(UUID.Zero); 1725 part.SetAvatarOnSitTarget(UUID.Zero);
1689
1690 m_parentPosition = part.GetWorldPosition(); 1726 m_parentPosition = part.GetWorldPosition();
1691 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1727 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1692 } 1728 }
1693 1729 // part.GetWorldRotation() is the rotation of the object being sat on
1694 if (m_physicsActor == null) 1730 // Rotation is the sittiing Av's rotation
1695 { 1731
1696 AddToPhysicalScene(false); 1732 Quaternion partRot;
1733// if (part.LinkNum == 1)
1734// { // Root prim of linkset
1735// partRot = part.ParentGroup.RootPart.RotationOffset;
1736// }
1737// else
1738// { // single or child prim
1739
1740// }
1741 if (part == null) //CW: Part may be gone. llDie() for example.
1742 {
1743 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1744 }
1745 else
1746 {
1747 partRot = part.GetWorldRotation();
1697 } 1748 }
1698 1749
1699 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1750 Quaternion partIRot = Quaternion.Inverse(partRot);
1700 m_parentPosition = Vector3.Zero;
1701 1751
1702 m_parentID = 0; 1752 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1753 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1754
1755
1756 if (m_physicsActor == null)
1757 {
1758 AddToPhysicalScene(false);
1759 }
1760 //CW: If the part isn't null then we can set the current position
1761 if (part != null)
1762 {
1763 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + (m_pos * partRot); // + av sit offset!
1764 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1765 part.IsOccupied = false;
1766 }
1767 else
1768 {
1769 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1770 AbsolutePosition = m_lastWorldPosition;
1771 }
1772
1773 m_parentPosition = Vector3.Zero;
1774 m_parentID = 0;
1703 SendFullUpdateToAllClients(); 1775 SendFullUpdateToAllClients();
1704 m_requestedSitTargetID = 0; 1776 m_requestedSitTargetID = 0;
1777
1705 if ((m_physicsActor != null) && (m_avHeight > 0)) 1778 if ((m_physicsActor != null) && (m_avHeight > 0))
1706 { 1779 {
1707 SetHeight(m_avHeight); 1780 SetHeight(m_avHeight);
1708 } 1781 }
1709 } 1782 }
1710
1711 Animator.TrySetMovementAnimation("STAND"); 1783 Animator.TrySetMovementAnimation("STAND");
1712 } 1784 }
1713 1785
@@ -1738,13 +1810,9 @@ namespace OpenSim.Region.Framework.Scenes
1738 Vector3 avSitOffSet = part.SitTargetPosition; 1810 Vector3 avSitOffSet = part.SitTargetPosition;
1739 Quaternion avSitOrientation = part.SitTargetOrientation; 1811 Quaternion avSitOrientation = part.SitTargetOrientation;
1740 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1812 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1741 1813 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1742 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1814 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1743 bool SitTargetisSet = 1815 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 { 1816 {
1749 //switch the target to this prim 1817 //switch the target to this prim
1750 return part; 1818 return part;
@@ -1758,84 +1826,152 @@ namespace OpenSim.Region.Framework.Scenes
1758 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1826 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1759 { 1827 {
1760 bool autopilot = true; 1828 bool autopilot = true;
1829 Vector3 autopilotTarget = new Vector3();
1830 Quaternion sitOrientation = Quaternion.Identity;
1761 Vector3 pos = new Vector3(); 1831 Vector3 pos = new Vector3();
1762 Quaternion sitOrientation = pSitOrientation;
1763 Vector3 cameraEyeOffset = Vector3.Zero; 1832 Vector3 cameraEyeOffset = Vector3.Zero;
1764 Vector3 cameraAtOffset = Vector3.Zero; 1833 Vector3 cameraAtOffset = Vector3.Zero;
1765 bool forceMouselook = false; 1834 bool forceMouselook = false;
1766 1835
1767 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1836 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1768 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1837 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1769 if (part != null) 1838 if (part == null) return;
1770 { 1839
1771 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1840 // 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 1841 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1773 1842
1774 // Is a sit target available? 1843 // part is the prim to sit on
1775 Vector3 avSitOffSet = part.SitTargetPosition; 1844 // offset is the world-ref vector distance from that prim center to the click-spot
1776 Quaternion avSitOrientation = part.SitTargetOrientation; 1845 // UUID is the UUID of the Avatar doing the clicking
1777 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1846
1778 1847 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1779 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1848
1780 bool SitTargetisSet = 1849 // Is a sit target available?
1781 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1850 Vector3 avSitOffSet = part.SitTargetPosition;
1782 ( 1851 Quaternion avSitOrientation = part.SitTargetOrientation;
1783 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1852
1784 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1853 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 1854 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1786 ) 1855 Quaternion partRot;
1787 )); 1856// if (part.LinkNum == 1)
1788 1857// { // Root prim of linkset
1789 if (SitTargetisSet && SitTargetUnOccupied) 1858// partRot = part.ParentGroup.RootPart.RotationOffset;
1790 { 1859// }
1791 part.SetAvatarOnSitTarget(UUID); 1860// else
1792 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1861// { // single or child prim
1793 sitOrientation = avSitOrientation; 1862 partRot = part.GetWorldRotation();
1794 autopilot = false; 1863// }
1795 } 1864 Quaternion partIRot = Quaternion.Inverse(partRot);
1796 1865//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1797 pos = part.AbsolutePosition + offset; 1866 // Sit analysis rewritten by KF 091125
1798 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1867 if (SitTargetisSet) // scipted sit
1799 //{ 1868 {
1800 // offset = pos; 1869 if (!part.IsOccupied)
1801 //autopilot = false; 1870 {
1802 //} 1871//Console.WriteLine("Scripted, unoccupied");
1803 if (m_physicsActor != null) 1872 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1804 { 1873 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 1874 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1806 // We can remove the physicsActor until they stand up. 1875 autopilot = false; // Jump direct to scripted llSitPos()
1807 m_sitAvatarHeight = m_physicsActor.Size.Z; 1876 }
1808 1877 else
1809 if (autopilot) 1878 {
1810 { 1879//Console.WriteLine("Scripted, occupied");
1811 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1880 return;
1812 { 1881 }
1813 autopilot = false; 1882 }
1883 else // Not Scripted
1884 {
1885 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1886 {
1887 // large prim & offset, ignore if other Avs sitting
1888// offset.Z -= 0.05f;
1889 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1890 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1891
1892//Console.WriteLine(" offset ={0}", offset);
1893//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1894//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1895
1896 }
1897 else // small offset
1898 {
1899//Console.WriteLine("Small offset");
1900 if (!part.IsOccupied)
1901 {
1902 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1903 autopilotTarget = part.AbsolutePosition;
1904 }
1905 else return; // occupied small
1906 } // end large/small
1907 } // end Scripted/not
1908 cameraAtOffset = part.GetCameraAtOffset();
1909 cameraEyeOffset = part.GetCameraEyeOffset();
1910 forceMouselook = part.GetForceMouselook();
1911 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1912 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1814 1913
1815 RemoveFromPhysicalScene(); 1914 if (m_physicsActor != null)
1816 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1915 {
1817 } 1916 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1818 } 1917 // We can remove the physicsActor until they stand up.
1819 else 1918 m_sitAvatarHeight = m_physicsActor.Size.Z;
1919 if (autopilot)
1920 { // its not a scripted sit
1921// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1922 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1820 { 1923 {
1924 autopilot = false; // close enough
1925 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1926 Not using the part's position because returning the AV to the last known standing
1927 position is likely to be more friendly, isn't it? */
1821 RemoveFromPhysicalScene(); 1928 RemoveFromPhysicalScene();
1822 } 1929 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1930 } // else the autopilot will get us close
1931 }
1932 else
1933 { // its a scripted sit
1934 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1935 I *am* using the part's position this time because we have no real idea how far away
1936 the avatar is from the sit target. */
1937 RemoveFromPhysicalScene();
1823 } 1938 }
1824
1825 cameraAtOffset = part.GetCameraAtOffset();
1826 cameraEyeOffset = part.GetCameraEyeOffset();
1827 forceMouselook = part.GetForceMouselook();
1828 } 1939 }
1829 1940 else return; // physactor is null!
1830 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 1941
1831 m_requestedSitTargetUUID = targetID; 1942 Vector3 offsetr; // = offset * partIRot;
1943 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
1944 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
1945 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
1946 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
1947 offsetr = offset * partIRot;
1948//
1949 // else
1950 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
1951 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
1952 // (offset * partRot);
1953 // }
1954
1955//Console.WriteLine(" ");
1956//Console.WriteLine("link number ={0}", part.LinkNum);
1957//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
1958//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
1959//Console.WriteLine("Click offst ={0}", offset);
1960//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
1961//Console.WriteLine("offsetr ={0}", offsetr);
1962//Console.WriteLine("Camera At ={0}", cameraAtOffset);
1963//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
1964
1965 ControllingClient.SendSitResponse(part.UUID, offsetr, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
1966 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1832 // This calls HandleAgentSit twice, once from here, and the client calls 1967 // This calls HandleAgentSit twice, once from here, and the client calls
1833 // HandleAgentSit itself after it gets to the location 1968 // HandleAgentSit itself after it gets to the location
1834 // It doesn't get to the location until we've moved them there though 1969 // It doesn't get to the location until we've moved them there though
1835 // which happens in HandleAgentSit :P 1970 // which happens in HandleAgentSit :P
1836 m_autopilotMoving = autopilot; 1971 m_autopilotMoving = autopilot;
1837 m_autoPilotTarget = pos; 1972 m_autoPilotTarget = autopilotTarget;
1838 m_sitAtAutoTarget = autopilot; 1973 m_sitAtAutoTarget = autopilot;
1974 m_initialSitTarget = autopilotTarget;
1839 if (!autopilot) 1975 if (!autopilot)
1840 HandleAgentSit(remoteClient, UUID); 1976 HandleAgentSit(remoteClient, UUID);
1841 } 1977 }
@@ -2130,31 +2266,65 @@ namespace OpenSim.Region.Framework.Scenes
2130 { 2266 {
2131 if (part != null) 2267 if (part != null)
2132 { 2268 {
2269//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2133 if (part.GetAvatarOnSitTarget() == UUID) 2270 if (part.GetAvatarOnSitTarget() == UUID)
2134 { 2271 {
2272//Console.WriteLine("Scripted Sit");
2273 // Scripted sit
2135 Vector3 sitTargetPos = part.SitTargetPosition; 2274 Vector3 sitTargetPos = part.SitTargetPosition;
2136 Quaternion sitTargetOrient = part.SitTargetOrientation; 2275 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); 2276 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2144 m_pos += SIT_TARGET_ADJUSTMENT; 2277 m_pos += SIT_TARGET_ADJUSTMENT;
2145 m_bodyRot = sitTargetOrient; 2278 m_bodyRot = sitTargetOrient;
2146 //Rotation = sitTargetOrient;
2147 m_parentPosition = part.AbsolutePosition; 2279 m_parentPosition = part.AbsolutePosition;
2148 2280 part.IsOccupied = true;
2149 //SendTerseUpdateToAllClients();
2150 } 2281 }
2151 else 2282 else
2152 { 2283 {
2153 m_pos -= part.AbsolutePosition; 2284 // if m_avUnscriptedSitPos is zero then Av sits above center
2285 // Else Av sits at m_avUnscriptedSitPos
2286
2287 // Non-scripted sit by Kitto Flora 21Nov09
2288 // Calculate angle of line from prim to Av
2289 Quaternion partIRot;
2290// if (part.LinkNum == 1)
2291// { // Root prim of linkset
2292// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2293// }
2294// else
2295// { // single or child prim
2296 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2297// }
2298 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2299 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2300 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2301 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2302 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2303 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2304 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2305 // Av sits at world euler <0,0, z>, translated by part rotation
2306 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2307
2154 m_parentPosition = part.AbsolutePosition; 2308 m_parentPosition = part.AbsolutePosition;
2155 } 2309 part.IsOccupied = true;
2310 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2311 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2312 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2313 m_avUnscriptedSitPos; // adds click offset, if any
2314 //Set up raytrace to find top surface of prim
2315 Vector3 size = part.Scale;
2316 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2317 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2318 Vector3 down = new Vector3(0f, 0f, -1f);
2319//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2320 m_scene.PhysicsScene.RaycastWorld(
2321 start, // Vector3 position,
2322 down, // Vector3 direction,
2323 mag, // float length,
2324 SitAltitudeCallback); // retMethod
2325 } // end scripted/not
2156 } 2326 }
2157 else 2327 else // no Av
2158 { 2328 {
2159 return; 2329 return;
2160 } 2330 }
@@ -2166,11 +2336,36 @@ namespace OpenSim.Region.Framework.Scenes
2166 2336
2167 Animator.TrySetMovementAnimation(sitAnimation); 2337 Animator.TrySetMovementAnimation(sitAnimation);
2168 SendFullUpdateToAllClients(); 2338 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 } 2339 }
2340
2341 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2342 {
2343 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2344 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2345 if(hitYN)
2346 {
2347 // m_pos = Av offset from prim center to make look like on center
2348 // m_parentPosition = Actual center pos of prim
2349 // collisionPoint = spot on prim where we want to sit
2350 // collisionPoint.Z = global sit surface height
2351 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2352 Quaternion partIRot;
2353// if (part.LinkNum == 1)
2354/// { // Root prim of linkset
2355// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2356// }
2357// else
2358// { // single or child prim
2359 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2360// }
2361 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2362 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2363//Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2364 m_pos += offset;
2365// ControllingClient.SendClearFollowCamProperties(part.UUID);
2366
2367 }
2368 } // End SitAltitudeCallback KF.
2174 2369
2175 /// <summary> 2370 /// <summary>
2176 /// Event handler for the 'Always run' setting on the client 2371 /// Event handler for the 'Always run' setting on the client
@@ -2200,7 +2395,7 @@ namespace OpenSim.Region.Framework.Scenes
2200 /// </summary> 2395 /// </summary>
2201 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2396 /// <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. 2397 /// <param name="rotation">The direction in which this avatar should now face.
2203 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2398 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2204 { 2399 {
2205 if (m_isChildAgent) 2400 if (m_isChildAgent)
2206 { 2401 {
@@ -2274,7 +2469,7 @@ namespace OpenSim.Region.Framework.Scenes
2274 2469
2275 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2470 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2276 m_forceToApply = direc; 2471 m_forceToApply = direc;
2277 2472 m_isNudging = Nudging;
2278 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2473 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2279 } 2474 }
2280 2475
@@ -2289,7 +2484,7 @@ namespace OpenSim.Region.Framework.Scenes
2289 const float POSITION_TOLERANCE = 0.05f; 2484 const float POSITION_TOLERANCE = 0.05f;
2290 //const int TIME_MS_TOLERANCE = 3000; 2485 //const int TIME_MS_TOLERANCE = 3000;
2291 2486
2292 SendPrimUpdates(); 2487
2293 2488
2294 if (m_newCoarseLocations) 2489 if (m_newCoarseLocations)
2295 { 2490 {
@@ -2325,6 +2520,9 @@ namespace OpenSim.Region.Framework.Scenes
2325 CheckForBorderCrossing(); 2520 CheckForBorderCrossing();
2326 CheckForSignificantMovement(); // sends update to the modules. 2521 CheckForSignificantMovement(); // sends update to the modules.
2327 } 2522 }
2523
2524 //Sending prim updates AFTER the avatar terse updates are sent
2525 SendPrimUpdates();
2328 } 2526 }
2329 2527
2330 #endregion 2528 #endregion
@@ -3225,14 +3423,25 @@ namespace OpenSim.Region.Framework.Scenes
3225 { 3423 {
3226 if (m_forceToApply.HasValue) 3424 if (m_forceToApply.HasValue)
3227 { 3425 {
3228 Vector3 force = m_forceToApply.Value;
3229 3426
3427 Vector3 force = m_forceToApply.Value;
3230 m_updateflag = true; 3428 m_updateflag = true;
3231// movementvector = force;
3232 Velocity = force; 3429 Velocity = force;
3233 3430
3234 m_forceToApply = null; 3431 m_forceToApply = null;
3235 } 3432 }
3433 else
3434 {
3435 if (m_isNudging)
3436 {
3437 Vector3 force = Vector3.Zero;
3438
3439 m_updateflag = true;
3440 Velocity = force;
3441 m_isNudging = false;
3442 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3443 }
3444 }
3236 } 3445 }
3237 3446
3238 public override void SetText(string text, Vector3 color, double alpha) 3447 public override void SetText(string text, Vector3 color, double alpha)
@@ -3283,18 +3492,29 @@ namespace OpenSim.Region.Framework.Scenes
3283 { 3492 {
3284 if (e == null) 3493 if (e == null)
3285 return; 3494 return;
3286 3495
3287 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3496 // 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 3497 // as of this comment the interval is set in AddToPhysicalScene
3290 if (Animator!=null) 3498 if (Animator!=null)
3291 Animator.UpdateMovementAnimations(); 3499 {
3500 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3501 { // else its will lock out other animation changes, like ground sit.
3502 Animator.UpdateMovementAnimations();
3503 m_updateCount--;
3504 }
3505 }
3292 3506
3293 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3507 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3294 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3508 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3295 3509
3296 CollisionPlane = Vector4.UnitW; 3510 CollisionPlane = Vector4.UnitW;
3297 3511
3512 if (m_lastColCount != coldata.Count)
3513 {
3514 m_updateCount = UPDATE_COUNT;
3515 m_lastColCount = coldata.Count;
3516 }
3517
3298 if (coldata.Count != 0 && Animator != null) 3518 if (coldata.Count != 0 && Animator != null)
3299 { 3519 {
3300 switch (Animator.CurrentMovementAnimation) 3520 switch (Animator.CurrentMovementAnimation)
@@ -3931,5 +4151,16 @@ namespace OpenSim.Region.Framework.Scenes
3931 m_reprioritization_called = false; 4151 m_reprioritization_called = false;
3932 } 4152 }
3933 } 4153 }
4154
4155 private Vector3 Quat2Euler(Quaternion rot){
4156 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4157 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4158 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4159 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4160 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4161 return(new Vector3(x,y,z));
4162 }
4163
4164
3934 } 4165 }
3935} 4166}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index e4296ef..1cff0eb 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -76,7 +76,7 @@ namespace OpenSim.Region.Framework.Scenes
76 76
77 foreach (EntityBase e in m_presence.Scene.Entities) 77 foreach (EntityBase e in m_presence.Scene.Entities)
78 { 78 {
79 if (e is SceneObjectGroup) 79 if (e != null && e is SceneObjectGroup)
80 m_pendingObjects.Enqueue((SceneObjectGroup)e); 80 m_pendingObjects.Enqueue((SceneObjectGroup)e);
81 } 81 }
82 } 82 }
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;