aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs2
-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.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Permissions.cs29
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs44
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs27
-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.cs594
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs133
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs592
-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
16 files changed, 1402 insertions, 829 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
index 78bd622..7312799 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
@@ -103,6 +103,8 @@ namespace OpenSim.Region.Framework.Interfaces
103 103
104 void StoreRegionSettings(RegionSettings rs); 104 void StoreRegionSettings(RegionSettings rs);
105 RegionSettings LoadRegionSettings(UUID regionUUID); 105 RegionSettings LoadRegionSettings(UUID regionUUID);
106 RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID);
107 void StoreRegionWindlightSettings(RegionMeta7WindlightData wl);
106 108
107 void Shutdown(); 109 void Shutdown();
108 } 110 }
diff --git a/OpenSim/Region/Framework/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..b04871e 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -849,8 +849,12 @@ namespace OpenSim.Region.Framework.Scenes
849 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) 849 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
850 { 850 {
851 SceneObjectPart part = GetSceneObjectPart(localID); 851 SceneObjectPart part = GetSceneObjectPart(localID);
852 SceneObjectGroup group = part.ParentGroup; 852 SceneObjectGroup group = null;
853 if (group != null) 853 if (part != null)
854 {
855 group = part.ParentGroup;
856 }
857 if (part != null && group != null)
854 { 858 {
855 TaskInventoryItem item = group.GetInventoryItem(localID, itemID); 859 TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
856 if (item == null) 860 if (item == null)
@@ -1577,9 +1581,10 @@ namespace OpenSim.Region.Framework.Scenes
1577 if (remoteClient != null) 1581 if (remoteClient != null)
1578 { 1582 {
1579 permissionToTake = 1583 permissionToTake =
1580 Permissions.CanReturnObject( 1584 Permissions.CanReturnObjects(
1581 grp.UUID, 1585 null,
1582 remoteClient.AgentId); 1586 remoteClient.AgentId,
1587 new List<SceneObjectGroup>() {grp});
1583 permissionToDelete = permissionToTake; 1588 permissionToDelete = permissionToTake;
1584 1589
1585 if (permissionToDelete) 1590 if (permissionToDelete)
@@ -1804,8 +1809,13 @@ namespace OpenSim.Region.Framework.Scenes
1804 } 1809 }
1805 else 1810 else
1806 { 1811 {
1807 item.BasePermissions = objectGroup.GetEffectivePermissions(); 1812 uint ownerPerms = objectGroup.GetEffectivePermissions();
1808 item.CurrentPermissions = objectGroup.GetEffectivePermissions(); 1813 if ((objectGroup.RootPart.OwnerMask & (uint)PermissionMask.Modify) != 0)
1814 ownerPerms |= (uint)PermissionMask.Modify;
1815
1816 item.BasePermissions = ownerPerms;
1817 item.CurrentPermissions = ownerPerms;
1818
1809 item.NextPermissions = objectGroup.RootPart.NextOwnerMask; 1819 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1810 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask; 1820 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
1811 item.GroupPermissions = objectGroup.RootPart.GroupMask; 1821 item.GroupPermissions = objectGroup.RootPart.GroupMask;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
index d1d6b6a..7dab04f 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Region.Framework.Scenes
48 public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene); 48 public delegate bool EditObjectInventoryHandler(UUID objectID, UUID editorID, Scene scene);
49 public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene); 49 public delegate bool MoveObjectHandler(UUID objectID, UUID moverID, Scene scene);
50 public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene); 50 public delegate bool ObjectEntryHandler(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene);
51 public delegate bool ReturnObjectHandler(UUID objectID, UUID returnerID, Scene scene); 51 public delegate bool ReturnObjectsHandler(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene);
52 public delegate bool InstantMessageHandler(UUID user, UUID target, Scene startScene); 52 public delegate bool InstantMessageHandler(UUID user, UUID target, Scene startScene);
53 public delegate bool InventoryTransferHandler(UUID user, UUID target, Scene startScene); 53 public delegate bool InventoryTransferHandler(UUID user, UUID target, Scene startScene);
54 public delegate bool ViewScriptHandler(UUID script, UUID objectID, UUID user, Scene scene); 54 public delegate bool ViewScriptHandler(UUID script, UUID objectID, UUID user, Scene scene);
@@ -81,7 +81,6 @@ namespace OpenSim.Region.Framework.Scenes
81 public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID); 81 public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID);
82 public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID); 82 public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID);
83 public delegate bool TeleportHandler(UUID userID, Scene scene); 83 public delegate bool TeleportHandler(UUID userID, Scene scene);
84 public delegate bool UseObjectReturnHandler(ILandObject landData, uint type, IClientAPI client, List<SceneObjectGroup> retlist, Scene scene);
85 #endregion 84 #endregion
86 85
87 public class ScenePermissions 86 public class ScenePermissions
@@ -107,7 +106,7 @@ namespace OpenSim.Region.Framework.Scenes
107 public event EditObjectInventoryHandler OnEditObjectInventory; 106 public event EditObjectInventoryHandler OnEditObjectInventory;
108 public event MoveObjectHandler OnMoveObject; 107 public event MoveObjectHandler OnMoveObject;
109 public event ObjectEntryHandler OnObjectEntry; 108 public event ObjectEntryHandler OnObjectEntry;
110 public event ReturnObjectHandler OnReturnObject; 109 public event ReturnObjectsHandler OnReturnObjects;
111 public event InstantMessageHandler OnInstantMessage; 110 public event InstantMessageHandler OnInstantMessage;
112 public event InventoryTransferHandler OnInventoryTransfer; 111 public event InventoryTransferHandler OnInventoryTransfer;
113 public event ViewScriptHandler OnViewScript; 112 public event ViewScriptHandler OnViewScript;
@@ -140,7 +139,6 @@ namespace OpenSim.Region.Framework.Scenes
140 public event CopyUserInventoryHandler OnCopyUserInventory; 139 public event CopyUserInventoryHandler OnCopyUserInventory;
141 public event DeleteUserInventoryHandler OnDeleteUserInventory; 140 public event DeleteUserInventoryHandler OnDeleteUserInventory;
142 public event TeleportHandler OnTeleport; 141 public event TeleportHandler OnTeleport;
143 public event UseObjectReturnHandler OnUseObjectReturn;
144 #endregion 142 #endregion
145 143
146 #region Object Permission Checks 144 #region Object Permission Checks
@@ -377,15 +375,15 @@ namespace OpenSim.Region.Framework.Scenes
377 #endregion 375 #endregion
378 376
379 #region RETURN OBJECT 377 #region RETURN OBJECT
380 public bool CanReturnObject(UUID objectID, UUID returnerID) 378 public bool CanReturnObjects(ILandObject land, UUID user, List<SceneObjectGroup> objects)
381 { 379 {
382 ReturnObjectHandler handler = OnReturnObject; 380 ReturnObjectsHandler handler = OnReturnObjects;
383 if (handler != null) 381 if (handler != null)
384 { 382 {
385 Delegate[] list = handler.GetInvocationList(); 383 Delegate[] list = handler.GetInvocationList();
386 foreach (ReturnObjectHandler h in list) 384 foreach (ReturnObjectsHandler h in list)
387 { 385 {
388 if (h(objectID, returnerID, m_scene) == false) 386 if (h(land, user, objects, m_scene) == false)
389 return false; 387 return false;
390 } 388 }
391 } 389 }
@@ -949,20 +947,5 @@ namespace OpenSim.Region.Framework.Scenes
949 } 947 }
950 return true; 948 return true;
951 } 949 }
952
953 public bool CanUseObjectReturn(ILandObject landData, uint type , IClientAPI client, List<SceneObjectGroup> retlist)
954 {
955 UseObjectReturnHandler handler = OnUseObjectReturn;
956 if (handler != null)
957 {
958 Delegate[] list = handler.GetInvocationList();
959 foreach (UseObjectReturnHandler h in list)
960 {
961 if (h(landData, type, client, retlist, m_scene) == false)
962 return false;
963 }
964 }
965 return true;
966 }
967 } 950 }
968} 951}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 7796b8d..fec8aa7 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -539,6 +539,8 @@ namespace OpenSim.Region.Framework.Scenes
539 539
540 // Load region settings 540 // Load region settings
541 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); 541 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID);
542 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(m_regInfo.RegionID);
543
542 if (m_storageManager.EstateDataStore != null) 544 if (m_storageManager.EstateDataStore != null)
543 { 545 {
544 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 546 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID);
@@ -886,6 +888,15 @@ namespace OpenSim.Region.Framework.Scenes
886 /// <param name="seconds">float indicating duration before restart.</param> 888 /// <param name="seconds">float indicating duration before restart.</param>
887 public virtual void Restart(float seconds) 889 public virtual void Restart(float seconds)
888 { 890 {
891 Restart(seconds, true);
892 }
893
894 /// <summary>
895 /// Given float seconds, this will restart the region. showDialog will optionally alert the users.
896 /// </summary>
897 /// <param name="seconds">float indicating duration before restart.</param>
898 public virtual void Restart(float seconds, bool showDialog)
899 {
889 // notifications are done in 15 second increments 900 // 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 901 // 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. 902 // It's a 'Cancel restart' request.
@@ -906,8 +917,11 @@ namespace OpenSim.Region.Framework.Scenes
906 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); 917 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed);
907 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); 918 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes");
908 m_restartTimer.Start(); 919 m_restartTimer.Start();
909 m_dialogModule.SendNotificationToUsersInRegion( 920 if (showDialog)
921 {
922 m_dialogModule.SendNotificationToUsersInRegion(
910 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); 923 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0)));
924 }
911 } 925 }
912 } 926 }
913 927
@@ -1189,16 +1203,16 @@ namespace OpenSim.Region.Framework.Scenes
1189 // Check if any objects have reached their targets 1203 // Check if any objects have reached their targets
1190 CheckAtTargets(); 1204 CheckAtTargets();
1191 1205
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 1206 // Run through all ScenePresences looking for updates
1198 // Presence updates and queued object updates for each presence are sent to clients 1207 // Presence updates and queued object updates for each presence are sent to clients
1199 if (m_frame % m_update_presences == 0) 1208 if (m_frame % m_update_presences == 0)
1200 m_sceneGraph.UpdatePresences(); 1209 m_sceneGraph.UpdatePresences();
1201 1210
1211 // Update SceneObjectGroups that have scheduled themselves for updates
1212 // Objects queue their updates onto all scene presences
1213 if (m_frame % m_update_objects == 0)
1214 m_sceneGraph.UpdateObjectGroups();
1215
1202 int tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1216 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1203 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1217 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1204 m_sceneGraph.UpdatePreparePhysics(); 1218 m_sceneGraph.UpdatePreparePhysics();
@@ -1509,6 +1523,19 @@ namespace OpenSim.Region.Framework.Scenes
1509 public void SaveTerrain() 1523 public void SaveTerrain()
1510 { 1524 {
1511 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1525 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1526 }
1527
1528 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1529 {
1530 m_regInfo.WindlightSettings = wl;
1531 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
1532 m_eventManager.TriggerOnSaveNewWindlightProfile();
1533 }
1534
1535 public void LoadWindlightProfile()
1536 {
1537 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1538 m_eventManager.TriggerOnSaveNewWindlightProfile();
1512 } 1539 }
1513 1540
1514 /// <summary> 1541 /// <summary>
@@ -3450,6 +3477,9 @@ namespace OpenSim.Region.Framework.Scenes
3450 3477
3451 CapsModule.AddCapsHandler(agent.AgentID); 3478 CapsModule.AddCapsHandler(agent.AgentID);
3452 3479
3480 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3481 System.Threading.Thread.Sleep(2000);
3482
3453 if (!agent.child) 3483 if (!agent.child)
3454 { 3484 {
3455 if (TestBorderCross(agent.startpos,Cardinals.E)) 3485 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3508,6 +3538,7 @@ namespace OpenSim.Region.Framework.Scenes
3508 } 3538 }
3509 } 3539 }
3510 // Honor parcel landing type and position. 3540 // Honor parcel landing type and position.
3541 /*
3511 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 3542 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3512 if (land != null) 3543 if (land != null)
3513 { 3544 {
@@ -3516,6 +3547,7 @@ namespace OpenSim.Region.Framework.Scenes
3516 agent.startpos = land.LandData.UserLocation; 3547 agent.startpos = land.LandData.UserLocation;
3517 } 3548 }
3518 } 3549 }
3550 */// This is now handled properly in ScenePresence.MakeRootAgent
3519 } 3551 }
3520 3552
3521 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 3553 m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 2f6a0db..5f84252 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;
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..5951a92 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -106,6 +106,72 @@ namespace OpenSim.Region.Framework.Scenes
106 private bool m_hasGroupChanged = false; 106 private bool m_hasGroupChanged = false;
107 private long timeFirstChanged; 107 private long timeFirstChanged;
108 private long timeLastChanged; 108 private long timeLastChanged;
109 private System.Threading.ReaderWriterLockSlim m_partsLock = new System.Threading.ReaderWriterLockSlim();
110
111 public void lockPartsForRead(bool locked)
112 {
113 if (locked)
114 {
115 if (m_partsLock.RecursiveReadCount > 0)
116 {
117 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.");
118 m_partsLock.ExitReadLock();
119 }
120 if (m_partsLock.RecursiveWriteCount > 0)
121 {
122 m_log.Error("[SceneObjectGroup.m_parts] Recursive read lock requested. This should not happen and means something needs to be fixed.");
123 m_partsLock.ExitWriteLock();
124 }
125
126 while (!m_partsLock.TryEnterReadLock(60000))
127 {
128 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.");
129 if (m_partsLock.IsWriteLockHeld)
130 {
131 m_partsLock = new System.Threading.ReaderWriterLockSlim();
132 }
133 }
134 }
135 else
136 {
137 if (m_partsLock.RecursiveReadCount > 0)
138 {
139 m_partsLock.ExitReadLock();
140 }
141 }
142 }
143 public void lockPartsForWrite(bool locked)
144 {
145 if (locked)
146 {
147 if (m_partsLock.RecursiveReadCount > 0)
148 {
149 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.");
150 m_partsLock.ExitReadLock();
151 }
152 if (m_partsLock.RecursiveWriteCount > 0)
153 {
154 m_log.Error("[SceneObjectGroup.m_parts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
155 m_partsLock.ExitWriteLock();
156 }
157
158 while (!m_partsLock.TryEnterWriteLock(60000))
159 {
160 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.");
161 if (m_partsLock.IsWriteLockHeld)
162 {
163 m_partsLock = new System.Threading.ReaderWriterLockSlim();
164 }
165 }
166 }
167 else
168 {
169 if (m_partsLock.RecursiveWriteCount > 0)
170 {
171 m_partsLock.ExitWriteLock();
172 }
173 }
174 }
109 175
110 public bool HasGroupChanged 176 public bool HasGroupChanged
111 { 177 {
@@ -258,13 +324,16 @@ namespace OpenSim.Region.Framework.Scenes
258 set 324 set
259 { 325 {
260 m_regionHandle = value; 326 m_regionHandle = value;
261 lock (m_parts) 327 lockPartsForRead(true);
262 { 328 {
263 foreach (SceneObjectPart part in m_parts.Values) 329 foreach (SceneObjectPart part in m_parts.Values)
264 { 330 {
331
265 part.RegionHandle = m_regionHandle; 332 part.RegionHandle = m_regionHandle;
333
266 } 334 }
267 } 335 }
336 lockPartsForRead(false);
268 } 337 }
269 } 338 }
270 339
@@ -298,6 +367,9 @@ namespace OpenSim.Region.Framework.Scenes
298 { 367 {
299 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 368 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
300 } 369 }
370
371 lockPartsForRead(true);
372
301 if (RootPart.GetStatusSandbox()) 373 if (RootPart.GetStatusSandbox())
302 { 374 {
303 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) 375 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
@@ -308,14 +380,14 @@ namespace OpenSim.Region.Framework.Scenes
308 return; 380 return;
309 } 381 }
310 } 382 }
311 lock (m_parts) 383
384 foreach (SceneObjectPart part in m_parts.Values)
312 { 385 {
313 foreach (SceneObjectPart part in m_parts.Values) 386 part.GroupPosition = val;
314 {
315 part.GroupPosition = val;
316 }
317 } 387 }
318 388
389 lockPartsForRead(false);
390
319 //if (m_rootPart.PhysActor != null) 391 //if (m_rootPart.PhysActor != null)
320 //{ 392 //{
321 //m_rootPart.PhysActor.Position = 393 //m_rootPart.PhysActor.Position =
@@ -504,13 +576,16 @@ namespace OpenSim.Region.Framework.Scenes
504 576
505 public void SetFromItemID(UUID AssetId) 577 public void SetFromItemID(UUID AssetId)
506 { 578 {
507 lock (m_parts) 579 lockPartsForRead(true);
508 { 580 {
509 foreach (SceneObjectPart part in m_parts.Values) 581 foreach (SceneObjectPart part in m_parts.Values)
510 { 582 {
583
511 part.FromItemID = AssetId; 584 part.FromItemID = AssetId;
585
512 } 586 }
513 } 587 }
588 lockPartsForRead(false);
514 } 589 }
515 590
516 public UUID GetFromItemID() 591 public UUID GetFromItemID()
@@ -579,10 +654,11 @@ namespace OpenSim.Region.Framework.Scenes
579 Vector3 maxScale = Vector3.Zero; 654 Vector3 maxScale = Vector3.Zero;
580 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); 655 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
581 656
582 lock (m_parts) 657 lockPartsForRead(true);
583 { 658 {
584 foreach (SceneObjectPart part in m_parts.Values) 659 foreach (SceneObjectPart part in m_parts.Values)
585 { 660 {
661
586 Vector3 partscale = part.Scale; 662 Vector3 partscale = part.Scale;
587 Vector3 partoffset = part.OffsetPosition; 663 Vector3 partoffset = part.OffsetPosition;
588 664
@@ -593,8 +669,11 @@ namespace OpenSim.Region.Framework.Scenes
593 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X; 669 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; 670 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; 671 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
672
596 } 673 }
597 } 674 }
675 lockPartsForRead(false);
676
598 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; 677 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
599 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; 678 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
600 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; 679 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
@@ -610,10 +689,11 @@ namespace OpenSim.Region.Framework.Scenes
610 689
611 EntityIntersection result = new EntityIntersection(); 690 EntityIntersection result = new EntityIntersection();
612 691
613 lock (m_parts) 692 lockPartsForRead(true);
614 { 693 {
615 foreach (SceneObjectPart part in m_parts.Values) 694 foreach (SceneObjectPart part in m_parts.Values)
616 { 695 {
696
617 // Temporary commented to stop compiler warning 697 // Temporary commented to stop compiler warning
618 //Vector3 partPosition = 698 //Vector3 partPosition =
619 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); 699 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
@@ -641,8 +721,10 @@ namespace OpenSim.Region.Framework.Scenes
641 result.distance = inter.distance; 721 result.distance = inter.distance;
642 } 722 }
643 } 723 }
724
644 } 725 }
645 } 726 }
727 lockPartsForRead(false);
646 return result; 728 return result;
647 } 729 }
648 730
@@ -655,10 +737,11 @@ namespace OpenSim.Region.Framework.Scenes
655 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) 737 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
656 { 738 {
657 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f; 739 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f;
658 lock (m_parts) 740 lockPartsForRead(true);
659 { 741 {
660 foreach (SceneObjectPart part in m_parts.Values) 742 foreach (SceneObjectPart part in m_parts.Values)
661 { 743 {
744
662 Vector3 worldPos = part.GetWorldPosition(); 745 Vector3 worldPos = part.GetWorldPosition();
663 Vector3 offset = worldPos - AbsolutePosition; 746 Vector3 offset = worldPos - AbsolutePosition;
664 Quaternion worldRot; 747 Quaternion worldRot;
@@ -717,6 +800,8 @@ namespace OpenSim.Region.Framework.Scenes
717 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 800 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
718 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 801 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
719 802
803
804
720 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); 805 //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); 806 //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); 807 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
@@ -888,6 +973,7 @@ namespace OpenSim.Region.Framework.Scenes
888 minZ = backBottomLeft.Z; 973 minZ = backBottomLeft.Z;
889 } 974 }
890 } 975 }
976 lockPartsForRead(false);
891 977
892 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); 978 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
893 979
@@ -916,17 +1002,20 @@ namespace OpenSim.Region.Framework.Scenes
916 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1002 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
917 1003
918 // Capture script state while holding the lock 1004 // Capture script state while holding the lock
919 lock (m_parts) 1005 lockPartsForRead(true);
920 { 1006 {
921 foreach (SceneObjectPart part in m_parts.Values) 1007 foreach (SceneObjectPart part in m_parts.Values)
922 { 1008 {
1009
923 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); 1010 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates();
924 foreach (UUID itemid in pstates.Keys) 1011 foreach (UUID itemid in pstates.Keys)
925 { 1012 {
926 states.Add(itemid, pstates[itemid]); 1013 states.Add(itemid, pstates[itemid]);
927 } 1014 }
1015
928 } 1016 }
929 } 1017 }
1018 lockPartsForRead(false);
930 1019
931 if (states.Count > 0) 1020 if (states.Count > 0)
932 { 1021 {
@@ -1094,13 +1183,16 @@ namespace OpenSim.Region.Framework.Scenes
1094 1183
1095 public override void UpdateMovement() 1184 public override void UpdateMovement()
1096 { 1185 {
1097 lock (m_parts) 1186 lockPartsForRead(true);
1098 { 1187 {
1099 foreach (SceneObjectPart part in m_parts.Values) 1188 foreach (SceneObjectPart part in m_parts.Values)
1100 { 1189 {
1190
1101 part.UpdateMovement(); 1191 part.UpdateMovement();
1192
1102 } 1193 }
1103 } 1194 }
1195 lockPartsForRead(false);
1104 } 1196 }
1105 1197
1106 public ushort GetTimeDilation() 1198 public ushort GetTimeDilation()
@@ -1144,7 +1236,7 @@ namespace OpenSim.Region.Framework.Scenes
1144 /// <param name="part"></param> 1236 /// <param name="part"></param>
1145 public void AddPart(SceneObjectPart part) 1237 public void AddPart(SceneObjectPart part)
1146 { 1238 {
1147 lock (m_parts) 1239 lockPartsForWrite(true);
1148 { 1240 {
1149 part.SetParent(this); 1241 part.SetParent(this);
1150 m_parts.Add(part.UUID, part); 1242 m_parts.Add(part.UUID, part);
@@ -1154,6 +1246,7 @@ namespace OpenSim.Region.Framework.Scenes
1154 if (part.LinkNum == 2 && RootPart != null) 1246 if (part.LinkNum == 2 && RootPart != null)
1155 RootPart.LinkNum = 1; 1247 RootPart.LinkNum = 1;
1156 } 1248 }
1249 lockPartsForWrite(false);
1157 } 1250 }
1158 1251
1159 /// <summary> 1252 /// <summary>
@@ -1161,28 +1254,33 @@ namespace OpenSim.Region.Framework.Scenes
1161 /// </summary> 1254 /// </summary>
1162 private void UpdateParentIDs() 1255 private void UpdateParentIDs()
1163 { 1256 {
1164 lock (m_parts) 1257 lockPartsForRead(true);
1165 { 1258 {
1166 foreach (SceneObjectPart part in m_parts.Values) 1259 foreach (SceneObjectPart part in m_parts.Values)
1167 { 1260 {
1261
1168 if (part.UUID != m_rootPart.UUID) 1262 if (part.UUID != m_rootPart.UUID)
1169 { 1263 {
1170 part.ParentID = m_rootPart.LocalId; 1264 part.ParentID = m_rootPart.LocalId;
1171 } 1265 }
1266
1172 } 1267 }
1173 } 1268 }
1269 lockPartsForRead(false);
1174 } 1270 }
1175 1271
1176 public void RegenerateFullIDs() 1272 public void RegenerateFullIDs()
1177 { 1273 {
1178 lock (m_parts) 1274 lockPartsForRead(true);
1179 { 1275 {
1180 foreach (SceneObjectPart part in m_parts.Values) 1276 foreach (SceneObjectPart part in m_parts.Values)
1181 { 1277 {
1278
1182 part.UUID = UUID.Random(); 1279 part.UUID = UUID.Random();
1183 1280
1184 } 1281 }
1185 } 1282 }
1283 lockPartsForRead(false);
1186 } 1284 }
1187 1285
1188 // helper provided for parts. 1286 // helper provided for parts.
@@ -1263,29 +1361,33 @@ namespace OpenSim.Region.Framework.Scenes
1263 1361
1264 DetachFromBackup(); 1362 DetachFromBackup();
1265 1363
1266 lock (m_parts) 1364 lockPartsForRead(true);
1365 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1366 lockPartsForRead(false);
1367
1368 foreach (SceneObjectPart part in values)
1267 { 1369 {
1268 foreach (SceneObjectPart part in m_parts.Values)
1269 {
1270// part.Inventory.RemoveScriptInstances(); 1370// part.Inventory.RemoveScriptInstances();
1271 1371
1272 ScenePresence[] avatars = Scene.GetScenePresences(); 1372 ScenePresence[] avatars = Scene.GetScenePresences();
1273 for (int i = 0; i < avatars.Length; i++) 1373 for (int i = 0; i < avatars.Length; i++)
1374 {
1375 if (avatars[i].ParentID == LocalId)
1274 { 1376 {
1275 if (avatars[i].ParentID == LocalId) 1377 avatars[i].StandUp();
1276 { 1378 }
1277 avatars[i].StandUp();
1278 }
1279 1379
1280 if (!silent) 1380 if (!silent)
1281 { 1381 {
1282 part.UpdateFlag = 0; 1382 part.UpdateFlag = 0;
1283 if (part == m_rootPart) 1383 if (part == m_rootPart)
1284 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1384 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1285 }
1286 } 1385 }
1287 } 1386 }
1387
1288 } 1388 }
1389
1390
1289 } 1391 }
1290 1392
1291 public void AddScriptLPS(int count) 1393 public void AddScriptLPS(int count)
@@ -1310,17 +1412,20 @@ namespace OpenSim.Region.Framework.Scenes
1310 1412
1311 scriptEvents aggregateScriptEvents=0; 1413 scriptEvents aggregateScriptEvents=0;
1312 1414
1313 lock (m_parts) 1415 lockPartsForRead(true);
1314 { 1416 {
1315 foreach (SceneObjectPart part in m_parts.Values) 1417 foreach (SceneObjectPart part in m_parts.Values)
1316 { 1418 {
1419
1317 if (part == null) 1420 if (part == null)
1318 continue; 1421 continue;
1319 if (part != RootPart) 1422 if (part != RootPart)
1320 part.ObjectFlags = objectflagupdate; 1423 part.ObjectFlags = objectflagupdate;
1321 aggregateScriptEvents |= part.AggregateScriptEvents; 1424 aggregateScriptEvents |= part.AggregateScriptEvents;
1425
1322 } 1426 }
1323 } 1427 }
1428 lockPartsForRead(false);
1324 1429
1325 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); 1430 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
1326 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); 1431 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
@@ -1362,42 +1467,52 @@ namespace OpenSim.Region.Framework.Scenes
1362 /// <param name="m_physicalPrim"></param> 1467 /// <param name="m_physicalPrim"></param>
1363 public void ApplyPhysics(bool m_physicalPrim) 1468 public void ApplyPhysics(bool m_physicalPrim)
1364 { 1469 {
1365 lock (m_parts) 1470 lockPartsForRead(true);
1471
1472 if (m_parts.Count > 1)
1366 { 1473 {
1367 if (m_parts.Count > 1) 1474 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1475 lockPartsForRead(false);
1476 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1477 foreach (SceneObjectPart part in values)
1368 { 1478 {
1369 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); 1479
1370 foreach (SceneObjectPart part in m_parts.Values) 1480 if (part.LocalId != m_rootPart.LocalId)
1371 { 1481 {
1372 if (part.LocalId != m_rootPart.LocalId) 1482 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1373 {
1374 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1375 }
1376 } 1483 }
1377 1484
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 } 1485 }
1486 // Hack to get the physics scene geometries in the right spot
1487 ResetChildPrimPhysicsPositions();
1488 }
1489 else
1490 {
1491 lockPartsForRead(false);
1492 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1385 } 1493 }
1386 } 1494 }
1387 1495
1388 public void SetOwnerId(UUID userId) 1496 public void SetOwnerId(UUID userId)
1389 { 1497 {
1390 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1498 ForEachPart(delegate(SceneObjectPart part)
1499 {
1500
1501 part.OwnerID = userId;
1502
1503 });
1391 } 1504 }
1392 1505
1393 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1506 public void ForEachPart(Action<SceneObjectPart> whatToDo)
1394 { 1507 {
1395 lock (m_parts) 1508 lockPartsForRead(true);
1509 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1510 lockPartsForRead(false);
1511 foreach (SceneObjectPart part in values)
1396 { 1512 {
1397 foreach (SceneObjectPart part in m_parts.Values) 1513
1398 { 1514 whatToDo(part);
1399 whatToDo(part); 1515
1400 }
1401 } 1516 }
1402 } 1517 }
1403 1518
@@ -1496,14 +1611,17 @@ namespace OpenSim.Region.Framework.Scenes
1496 { 1611 {
1497 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1612 SendPartFullUpdate(remoteClient, RootPart, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1498 1613
1499 lock (m_parts) 1614 lockPartsForRead(true);
1500 { 1615 {
1501 foreach (SceneObjectPart part in m_parts.Values) 1616 foreach (SceneObjectPart part in m_parts.Values)
1502 { 1617 {
1618
1503 if (part != RootPart) 1619 if (part != RootPart)
1504 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1620 SendPartFullUpdate(remoteClient, part, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
1621
1505 } 1622 }
1506 } 1623 }
1624 lockPartsForRead(false);
1507 } 1625 }
1508 1626
1509 /// <summary> 1627 /// <summary>
@@ -1601,10 +1719,11 @@ namespace OpenSim.Region.Framework.Scenes
1601 1719
1602 List<SceneObjectPart> partList; 1720 List<SceneObjectPart> partList;
1603 1721
1604 lock (m_parts) 1722 lockPartsForRead(true);
1605 { 1723
1606 partList = new List<SceneObjectPart>(m_parts.Values); 1724 partList = new List<SceneObjectPart>(m_parts.Values);
1607 } 1725
1726 lockPartsForRead(false);
1608 1727
1609 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1728 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1610 { 1729 {
@@ -1827,13 +1946,40 @@ namespace OpenSim.Region.Framework.Scenes
1827 } 1946 }
1828 } 1947 }
1829 1948
1949 public void rotLookAt(Quaternion target, float strength, float damping)
1950 {
1951 SceneObjectPart rootpart = m_rootPart;
1952 if (rootpart != null)
1953 {
1954 if (IsAttachment)
1955 {
1956 /*
1957 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
1958 if (avatar != null)
1959 {
1960 Rotate the Av?
1961 } */
1962 }
1963 else
1964 {
1965 if (rootpart.PhysActor != null)
1966 { // APID must be implemented in your physics system for this to function.
1967 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
1968 rootpart.PhysActor.APIDStrength = strength;
1969 rootpart.PhysActor.APIDDamping = damping;
1970 rootpart.PhysActor.APIDActive = true;
1971 }
1972 }
1973 }
1974 }
1975
1830 public void stopLookAt() 1976 public void stopLookAt()
1831 { 1977 {
1832 SceneObjectPart rootpart = m_rootPart; 1978 SceneObjectPart rootpart = m_rootPart;
1833 if (rootpart != null) 1979 if (rootpart != null)
1834 { 1980 {
1835 if (rootpart.PhysActor != null) 1981 if (rootpart.PhysActor != null)
1836 { 1982 { // APID must be implemented in your physics system for this to function.
1837 rootpart.PhysActor.APIDActive = false; 1983 rootpart.PhysActor.APIDActive = false;
1838 } 1984 }
1839 } 1985 }
@@ -1901,10 +2047,11 @@ namespace OpenSim.Region.Framework.Scenes
1901 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2047 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1902 newPart.SetParent(this); 2048 newPart.SetParent(this);
1903 2049
1904 lock (m_parts) 2050 lockPartsForWrite(true);
1905 { 2051 {
1906 m_parts.Add(newPart.UUID, newPart); 2052 m_parts.Add(newPart.UUID, newPart);
1907 } 2053 }
2054 lockPartsForWrite(false);
1908 2055
1909 SetPartAsNonRoot(newPart); 2056 SetPartAsNonRoot(newPart);
1910 2057
@@ -1967,7 +2114,7 @@ namespace OpenSim.Region.Framework.Scenes
1967 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2114 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1968 // return; 2115 // return;
1969 2116
1970 lock (m_parts) 2117 lockPartsForRead(true);
1971 { 2118 {
1972 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2119 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1973 2120
@@ -1987,9 +2134,12 @@ namespace OpenSim.Region.Framework.Scenes
1987 { 2134 {
1988 if (!IsSelected) 2135 if (!IsSelected)
1989 part.UpdateLookAt(); 2136 part.UpdateLookAt();
2137
1990 part.SendScheduledUpdates(); 2138 part.SendScheduledUpdates();
2139
1991 } 2140 }
1992 } 2141 }
2142 lockPartsForRead(false);
1993 } 2143 }
1994 2144
1995 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2145 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -1998,27 +2148,31 @@ namespace OpenSim.Region.Framework.Scenes
1998 2148
1999 RootPart.AddFullUpdateToAvatar(presence); 2149 RootPart.AddFullUpdateToAvatar(presence);
2000 2150
2001 lock (m_parts) 2151 lockPartsForRead(true);
2002 { 2152 {
2003 foreach (SceneObjectPart part in m_parts.Values) 2153 foreach (SceneObjectPart part in m_parts.Values)
2004 { 2154 {
2155
2005 if (part != RootPart) 2156 if (part != RootPart)
2006 part.AddFullUpdateToAvatar(presence); 2157 part.AddFullUpdateToAvatar(presence);
2158
2007 } 2159 }
2008 } 2160 }
2161 lockPartsForRead(false);
2009 } 2162 }
2010 2163
2011 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2164 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
2012 { 2165 {
2013// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2166 lockPartsForRead(true);
2014
2015 lock (m_parts)
2016 { 2167 {
2017 foreach (SceneObjectPart part in m_parts.Values) 2168 foreach (SceneObjectPart part in m_parts.Values)
2018 { 2169 {
2170
2019 part.AddTerseUpdateToAvatar(presence); 2171 part.AddTerseUpdateToAvatar(presence);
2172
2020 } 2173 }
2021 } 2174 }
2175 lockPartsForRead(false);
2022 } 2176 }
2023 2177
2024 /// <summary> 2178 /// <summary>
@@ -2031,14 +2185,17 @@ namespace OpenSim.Region.Framework.Scenes
2031 checkAtTargets(); 2185 checkAtTargets();
2032 RootPart.ScheduleFullUpdate(); 2186 RootPart.ScheduleFullUpdate();
2033 2187
2034 lock (m_parts) 2188 lockPartsForRead(true);
2035 { 2189 {
2036 foreach (SceneObjectPart part in m_parts.Values) 2190 foreach (SceneObjectPart part in m_parts.Values)
2037 { 2191 {
2192
2038 if (part != RootPart) 2193 if (part != RootPart)
2039 part.ScheduleFullUpdate(); 2194 part.ScheduleFullUpdate();
2195
2040 } 2196 }
2041 } 2197 }
2198 lockPartsForRead(false);
2042 } 2199 }
2043 2200
2044 /// <summary> 2201 /// <summary>
@@ -2046,15 +2203,22 @@ namespace OpenSim.Region.Framework.Scenes
2046 /// </summary> 2203 /// </summary>
2047 public void ScheduleGroupForTerseUpdate() 2204 public void ScheduleGroupForTerseUpdate()
2048 { 2205 {
2206<<<<<<< HEAD:OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
2207 lockPartsForRead(true);
2208=======
2049// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2209// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID);
2050 2210
2051 lock (m_parts) 2211 lock (m_parts)
2212>>>>>>> 0.6.9-post-fixes:OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
2052 { 2213 {
2053 foreach (SceneObjectPart part in m_parts.Values) 2214 foreach (SceneObjectPart part in m_parts.Values)
2054 { 2215 {
2216
2055 part.ScheduleTerseUpdate(); 2217 part.ScheduleTerseUpdate();
2218
2056 } 2219 }
2057 } 2220 }
2221 lockPartsForRead(false);
2058 } 2222 }
2059 2223
2060 /// <summary> 2224 /// <summary>
@@ -2069,14 +2233,17 @@ namespace OpenSim.Region.Framework.Scenes
2069 2233
2070 RootPart.SendFullUpdateToAllClients(); 2234 RootPart.SendFullUpdateToAllClients();
2071 2235
2072 lock (m_parts) 2236 lockPartsForRead(true);
2073 { 2237 {
2074 foreach (SceneObjectPart part in m_parts.Values) 2238 foreach (SceneObjectPart part in m_parts.Values)
2075 { 2239 {
2240
2076 if (part != RootPart) 2241 if (part != RootPart)
2077 part.SendFullUpdateToAllClients(); 2242 part.SendFullUpdateToAllClients();
2243
2078 } 2244 }
2079 } 2245 }
2246 lockPartsForRead(false);
2080 } 2247 }
2081 2248
2082 /// <summary> 2249 /// <summary>
@@ -2108,14 +2275,15 @@ namespace OpenSim.Region.Framework.Scenes
2108 { 2275 {
2109 if (IsDeleted) 2276 if (IsDeleted)
2110 return; 2277 return;
2111 2278
2112 lock (m_parts) 2279 lockPartsForRead(true);
2113 { 2280 {
2114 foreach (SceneObjectPart part in m_parts.Values) 2281 foreach (SceneObjectPart part in m_parts.Values)
2115 { 2282 {
2116 part.SendTerseUpdateToAllClients(); 2283 part.SendTerseUpdateToAllClients();
2117 } 2284 }
2118 } 2285 }
2286 lockPartsForRead(false);
2119 } 2287 }
2120 2288
2121 #endregion 2289 #endregion
@@ -2129,16 +2297,18 @@ namespace OpenSim.Region.Framework.Scenes
2129 /// <returns>null if no child part with that linknum or child part</returns> 2297 /// <returns>null if no child part with that linknum or child part</returns>
2130 public SceneObjectPart GetLinkNumPart(int linknum) 2298 public SceneObjectPart GetLinkNumPart(int linknum)
2131 { 2299 {
2132 lock (m_parts) 2300 lockPartsForRead(true);
2133 { 2301 {
2134 foreach (SceneObjectPart part in m_parts.Values) 2302 foreach (SceneObjectPart part in m_parts.Values)
2135 { 2303 {
2136 if (part.LinkNum == linknum) 2304 if (part.LinkNum == linknum)
2137 { 2305 {
2306 lockPartsForRead(false);
2138 return part; 2307 return part;
2139 } 2308 }
2140 } 2309 }
2141 } 2310 }
2311 lockPartsForRead(false);
2142 2312
2143 return null; 2313 return null;
2144 } 2314 }
@@ -2166,17 +2336,19 @@ namespace OpenSim.Region.Framework.Scenes
2166 public SceneObjectPart GetChildPart(uint localID) 2336 public SceneObjectPart GetChildPart(uint localID)
2167 { 2337 {
2168 //m_log.DebugFormat("Entered looking for {0}", localID); 2338 //m_log.DebugFormat("Entered looking for {0}", localID);
2169 lock (m_parts) 2339 lockPartsForRead(true);
2170 { 2340 {
2171 foreach (SceneObjectPart part in m_parts.Values) 2341 foreach (SceneObjectPart part in m_parts.Values)
2172 { 2342 {
2173 //m_log.DebugFormat("Found {0}", part.LocalId); 2343 //m_log.DebugFormat("Found {0}", part.LocalId);
2174 if (part.LocalId == localID) 2344 if (part.LocalId == localID)
2175 { 2345 {
2346 lockPartsForRead(false);
2176 return part; 2347 return part;
2177 } 2348 }
2178 } 2349 }
2179 } 2350 }
2351 lockPartsForRead(false);
2180 2352
2181 return null; 2353 return null;
2182 } 2354 }
@@ -2206,17 +2378,19 @@ namespace OpenSim.Region.Framework.Scenes
2206 public bool HasChildPrim(uint localID) 2378 public bool HasChildPrim(uint localID)
2207 { 2379 {
2208 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2380 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2209 lock (m_parts) 2381 lockPartsForRead(true);
2210 { 2382 {
2211 foreach (SceneObjectPart part in m_parts.Values) 2383 foreach (SceneObjectPart part in m_parts.Values)
2212 { 2384 {
2213 //m_log.DebugFormat("Found {0}", part.LocalId); 2385 //m_log.DebugFormat("Found {0}", part.LocalId);
2214 if (part.LocalId == localID) 2386 if (part.LocalId == localID)
2215 { 2387 {
2388 lockPartsForRead(false);
2216 return true; 2389 return true;
2217 } 2390 }
2218 } 2391 }
2219 } 2392 }
2393 lockPartsForRead(false);
2220 2394
2221 return false; 2395 return false;
2222 } 2396 }
@@ -2266,53 +2440,57 @@ namespace OpenSim.Region.Framework.Scenes
2266 if (m_rootPart.LinkNum == 0) 2440 if (m_rootPart.LinkNum == 0)
2267 m_rootPart.LinkNum = 1; 2441 m_rootPart.LinkNum = 1;
2268 2442
2269 lock (m_parts) 2443 lockPartsForWrite(true);
2270 { 2444
2271 m_parts.Add(linkPart.UUID, linkPart); 2445 m_parts.Add(linkPart.UUID, linkPart);
2446
2447 lockPartsForWrite(false);
2272 2448
2273 // Insert in terms of link numbers, the new links 2449 // Insert in terms of link numbers, the new links
2274 // before the current ones (with the exception of 2450 // before the current ones (with the exception of
2275 // the root prim. Shuffle the old ones up 2451 // the root prim. Shuffle the old ones up
2276 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2452 lockPartsForRead(true);
2453 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2454 {
2455 if (kvp.Value.LinkNum != 1)
2277 { 2456 {
2278 if (kvp.Value.LinkNum != 1) 2457 // Don't update root prim link number
2279 { 2458 kvp.Value.LinkNum += objectGroup.PrimCount;
2280 // Don't update root prim link number
2281 kvp.Value.LinkNum += objectGroup.PrimCount;
2282 }
2283 } 2459 }
2460 }
2461 lockPartsForRead(false);
2284 2462
2285 linkPart.LinkNum = 2; 2463 linkPart.LinkNum = 2;
2286 2464
2287 linkPart.SetParent(this); 2465 linkPart.SetParent(this);
2288 linkPart.AddFlag(PrimFlags.CreateSelected); 2466 linkPart.AddFlag(PrimFlags.CreateSelected);
2289 2467
2290 //if (linkPart.PhysActor != null) 2468 //if (linkPart.PhysActor != null)
2291 //{ 2469 //{
2292 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2470 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2293 2471
2294 //linkPart.PhysActor = null; 2472 //linkPart.PhysActor = null;
2295 //} 2473 //}
2296 2474
2297 //TODO: rest of parts 2475 //TODO: rest of parts
2298 int linkNum = 3; 2476 int linkNum = 3;
2299 foreach (SceneObjectPart part in objectGroup.Children.Values) 2477 foreach (SceneObjectPart part in objectGroup.Children.Values)
2478 {
2479 if (part.UUID != objectGroup.m_rootPart.UUID)
2300 { 2480 {
2301 if (part.UUID != objectGroup.m_rootPart.UUID) 2481 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2302 {
2303 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2304 }
2305 part.ClearUndoState();
2306 } 2482 }
2483 part.ClearUndoState();
2307 } 2484 }
2308 2485
2309 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2486 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2310 objectGroup.m_isDeleted = true; 2487 objectGroup.m_isDeleted = true;
2488
2489 objectGroup.lockPartsForWrite(true);
2311 2490
2312 lock (objectGroup.m_parts) 2491 objectGroup.m_parts.Clear();
2313 { 2492
2314 objectGroup.m_parts.Clear(); 2493 objectGroup.lockPartsForWrite(false);
2315 }
2316 2494
2317 // Can't do this yet since backup still makes use of the root part without any synchronization 2495 // Can't do this yet since backup still makes use of the root part without any synchronization
2318// objectGroup.m_rootPart = null; 2496// objectGroup.m_rootPart = null;
@@ -2382,11 +2560,12 @@ namespace OpenSim.Region.Framework.Scenes
2382 Quaternion worldRot = linkPart.GetWorldRotation(); 2560 Quaternion worldRot = linkPart.GetWorldRotation();
2383 2561
2384 // Remove the part from this object 2562 // Remove the part from this object
2385 lock (m_parts) 2563 lockPartsForWrite(true);
2386 { 2564 {
2387 m_parts.Remove(linkPart.UUID); 2565 m_parts.Remove(linkPart.UUID);
2388 } 2566 }
2389 2567 lockPartsForWrite(false);
2568 lockPartsForRead(true);
2390 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2569 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2391 RootPart.LinkNum = 0; 2570 RootPart.LinkNum = 0;
2392 else 2571 else
@@ -2397,6 +2576,7 @@ namespace OpenSim.Region.Framework.Scenes
2397 p.LinkNum--; 2576 p.LinkNum--;
2398 } 2577 }
2399 } 2578 }
2579 lockPartsForRead(false);
2400 2580
2401 linkPart.ParentID = 0; 2581 linkPart.ParentID = 0;
2402 linkPart.LinkNum = 0; 2582 linkPart.LinkNum = 0;
@@ -2718,9 +2898,12 @@ namespace OpenSim.Region.Framework.Scenes
2718 2898
2719 if (selectionPart != null) 2899 if (selectionPart != null)
2720 { 2900 {
2721 lock (m_parts) 2901 lockPartsForRead(true);
2902 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2903 lockPartsForRead(false);
2904 foreach (SceneObjectPart part in parts)
2722 { 2905 {
2723 foreach (SceneObjectPart part in m_parts.Values) 2906 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2724 { 2907 {
2725 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2908 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2726 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2909 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2730,12 +2913,13 @@ namespace OpenSim.Region.Framework.Scenes
2730 break; 2913 break;
2731 } 2914 }
2732 } 2915 }
2916 }
2733 2917
2734 foreach (SceneObjectPart part in m_parts.Values) 2918 foreach (SceneObjectPart part in parts)
2735 { 2919 {
2736 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2920 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2737 }
2738 } 2921 }
2922
2739 } 2923 }
2740 } 2924 }
2741 2925
@@ -2821,11 +3005,9 @@ namespace OpenSim.Region.Framework.Scenes
2821 scale.Y = m_scene.m_maxNonphys; 3005 scale.Y = m_scene.m_maxNonphys;
2822 if (scale.Z > m_scene.m_maxNonphys) 3006 if (scale.Z > m_scene.m_maxNonphys)
2823 scale.Z = m_scene.m_maxNonphys; 3007 scale.Z = m_scene.m_maxNonphys;
2824
2825 SceneObjectPart part = GetChildPart(localID); 3008 SceneObjectPart part = GetChildPart(localID);
2826 if (part != null) 3009 if (part != null)
2827 { 3010 {
2828 part.Resize(scale);
2829 if (part.PhysActor != null) 3011 if (part.PhysActor != null)
2830 { 3012 {
2831 if (part.PhysActor.IsPhysical) 3013 if (part.PhysActor.IsPhysical)
@@ -2840,7 +3022,7 @@ namespace OpenSim.Region.Framework.Scenes
2840 part.PhysActor.Size = scale; 3022 part.PhysActor.Size = scale;
2841 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 3023 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2842 } 3024 }
2843 //if (part.UUID != m_rootPart.UUID) 3025 part.Resize(scale);
2844 3026
2845 HasGroupChanged = true; 3027 HasGroupChanged = true;
2846 ScheduleGroupForFullUpdate(); 3028 ScheduleGroupForFullUpdate();
@@ -2882,73 +3064,71 @@ namespace OpenSim.Region.Framework.Scenes
2882 float y = (scale.Y / part.Scale.Y); 3064 float y = (scale.Y / part.Scale.Y);
2883 float z = (scale.Z / part.Scale.Z); 3065 float z = (scale.Z / part.Scale.Z);
2884 3066
2885 lock (m_parts) 3067 lockPartsForRead(true);
3068 if (x > 1.0f || y > 1.0f || z > 1.0f)
2886 { 3069 {
2887 if (x > 1.0f || y > 1.0f || z > 1.0f) 3070 foreach (SceneObjectPart obPart in m_parts.Values)
2888 { 3071 {
2889 foreach (SceneObjectPart obPart in m_parts.Values) 3072 if (obPart.UUID != m_rootPart.UUID)
2890 { 3073 {
2891 if (obPart.UUID != m_rootPart.UUID) 3074 obPart.IgnoreUndoUpdate = true;
2892 { 3075 Vector3 oldSize = new Vector3(obPart.Scale);
2893 obPart.IgnoreUndoUpdate = true;
2894 Vector3 oldSize = new Vector3(obPart.Scale);
2895 3076
2896 float f = 1.0f; 3077 float f = 1.0f;
2897 float a = 1.0f; 3078 float a = 1.0f;
2898 3079
2899 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3080 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3081 {
3082 if (oldSize.X*x > m_scene.m_maxPhys)
2900 { 3083 {
2901 if (oldSize.X*x > m_scene.m_maxPhys) 3084 f = m_scene.m_maxPhys / oldSize.X;
2902 { 3085 a = f / x;
2903 f = m_scene.m_maxPhys / oldSize.X; 3086 x *= a;
2904 a = f / x; 3087 y *= a;
2905 x *= a; 3088 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 } 3089 }
2926 else 3090 if (oldSize.Y*y > m_scene.m_maxPhys)
3091 {
3092 f = m_scene.m_maxPhys / oldSize.Y;
3093 a = f / y;
3094 x *= a;
3095 y *= a;
3096 z *= a;
3097 }
3098 if (oldSize.Z*z > m_scene.m_maxPhys)
3099 {
3100 f = m_scene.m_maxPhys / oldSize.Z;
3101 a = f / z;
3102 x *= a;
3103 y *= a;
3104 z *= a;
3105 }
3106 }
3107 else
3108 {
3109 if (oldSize.X*x > m_scene.m_maxNonphys)
2927 { 3110 {
2928 if (oldSize.X*x > m_scene.m_maxNonphys) 3111 f = m_scene.m_maxNonphys / oldSize.X;
2929 { 3112 a = f / x;
2930 f = m_scene.m_maxNonphys / oldSize.X; 3113 x *= a;
2931 a = f / x; 3114 y *= a;
2932 x *= a; 3115 z *= a;
2933 y *= a; 3116 }
2934 z *= a; 3117 if (oldSize.Y*y > m_scene.m_maxNonphys)
2935 } 3118 {
2936 if (oldSize.Y*y > m_scene.m_maxNonphys) 3119 f = m_scene.m_maxNonphys / oldSize.Y;
2937 { 3120 a = f / y;
2938 f = m_scene.m_maxNonphys / oldSize.Y; 3121 x *= a;
2939 a = f / y; 3122 y *= a;
2940 x *= a; 3123 z *= a;
2941 y *= a; 3124 }
2942 z *= a; 3125 if (oldSize.Z*z > m_scene.m_maxNonphys)
2943 } 3126 {
2944 if (oldSize.Z*z > m_scene.m_maxNonphys) 3127 f = m_scene.m_maxNonphys / oldSize.Z;
2945 { 3128 a = f / z;
2946 f = m_scene.m_maxNonphys / oldSize.Z; 3129 x *= a;
2947 a = f / z; 3130 y *= a;
2948 x *= a; 3131 z *= a;
2949 y *= a;
2950 z *= a;
2951 }
2952 } 3132 }
2953 obPart.IgnoreUndoUpdate = false; 3133 obPart.IgnoreUndoUpdate = false;
2954 obPart.StoreUndoState(); 3134 obPart.StoreUndoState();
@@ -2956,6 +3136,7 @@ namespace OpenSim.Region.Framework.Scenes
2956 } 3136 }
2957 } 3137 }
2958 } 3138 }
3139 lockPartsForRead(false);
2959 3140
2960 Vector3 prevScale = part.Scale; 3141 Vector3 prevScale = part.Scale;
2961 prevScale.X *= x; 3142 prevScale.X *= x;
@@ -2963,7 +3144,7 @@ namespace OpenSim.Region.Framework.Scenes
2963 prevScale.Z *= z; 3144 prevScale.Z *= z;
2964 part.Resize(prevScale); 3145 part.Resize(prevScale);
2965 3146
2966 lock (m_parts) 3147 lockPartsForRead(true);
2967 { 3148 {
2968 foreach (SceneObjectPart obPart in m_parts.Values) 3149 foreach (SceneObjectPart obPart in m_parts.Values)
2969 { 3150 {
@@ -2985,6 +3166,7 @@ namespace OpenSim.Region.Framework.Scenes
2985 obPart.StoreUndoState(); 3166 obPart.StoreUndoState();
2986 } 3167 }
2987 } 3168 }
3169 lockPartsForRead(false);
2988 3170
2989 if (part.PhysActor != null) 3171 if (part.PhysActor != null)
2990 { 3172 {
@@ -3087,7 +3269,7 @@ namespace OpenSim.Region.Framework.Scenes
3087 axDiff *= Quaternion.Inverse(partRotation); 3269 axDiff *= Quaternion.Inverse(partRotation);
3088 diff = axDiff; 3270 diff = axDiff;
3089 3271
3090 lock (m_parts) 3272 lockPartsForRead(true);
3091 { 3273 {
3092 foreach (SceneObjectPart obPart in m_parts.Values) 3274 foreach (SceneObjectPart obPart in m_parts.Values)
3093 { 3275 {
@@ -3097,6 +3279,7 @@ namespace OpenSim.Region.Framework.Scenes
3097 } 3279 }
3098 } 3280 }
3099 } 3281 }
3282 lockPartsForRead(false);
3100 3283
3101 AbsolutePosition = newPos; 3284 AbsolutePosition = newPos;
3102 3285
@@ -3230,25 +3413,25 @@ namespace OpenSim.Region.Framework.Scenes
3230 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3413 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3231 } 3414 }
3232 3415
3233 lock (m_parts) 3416 lockPartsForRead(true);
3417
3418 foreach (SceneObjectPart prim in m_parts.Values)
3234 { 3419 {
3235 foreach (SceneObjectPart prim in m_parts.Values) 3420 if (prim.UUID != m_rootPart.UUID)
3236 { 3421 {
3237 if (prim.UUID != m_rootPart.UUID) 3422 prim.IgnoreUndoUpdate = true;
3238 { 3423 Vector3 axPos = prim.OffsetPosition;
3239 prim.IgnoreUndoUpdate = true; 3424 axPos *= oldParentRot;
3240 Vector3 axPos = prim.OffsetPosition; 3425 axPos *= Quaternion.Inverse(axRot);
3241 axPos *= oldParentRot; 3426 prim.OffsetPosition = axPos;
3242 axPos *= Quaternion.Inverse(axRot); 3427 Quaternion primsRot = prim.RotationOffset;
3243 prim.OffsetPosition = axPos; 3428 Quaternion newRot = primsRot * oldParentRot;
3244 Quaternion primsRot = prim.RotationOffset; 3429 newRot *= Quaternion.Inverse(axRot);
3245 Quaternion newRot = primsRot * oldParentRot; 3430 prim.RotationOffset = newRot;
3246 newRot *= Quaternion.Inverse(axRot); 3431 prim.ScheduleTerseUpdate();
3247 prim.RotationOffset = newRot;
3248 prim.ScheduleTerseUpdate();
3249 }
3250 } 3432 }
3251 } 3433 }
3434
3252 foreach (SceneObjectPart childpart in Children.Values) 3435 foreach (SceneObjectPart childpart in Children.Values)
3253 { 3436 {
3254 if (childpart != m_rootPart) 3437 if (childpart != m_rootPart)
@@ -3257,6 +3440,9 @@ namespace OpenSim.Region.Framework.Scenes
3257 childpart.StoreUndoState(); 3440 childpart.StoreUndoState();
3258 } 3441 }
3259 } 3442 }
3443
3444 lockPartsForRead(false);
3445
3260 m_rootPart.ScheduleTerseUpdate(); 3446 m_rootPart.ScheduleTerseUpdate();
3261 } 3447 }
3262 3448
@@ -3378,7 +3564,7 @@ namespace OpenSim.Region.Framework.Scenes
3378 if (atTargets.Count > 0) 3564 if (atTargets.Count > 0)
3379 { 3565 {
3380 uint[] localids = new uint[0]; 3566 uint[] localids = new uint[0];
3381 lock (m_parts) 3567 lockPartsForRead(true);
3382 { 3568 {
3383 localids = new uint[m_parts.Count]; 3569 localids = new uint[m_parts.Count];
3384 int cntr = 0; 3570 int cntr = 0;
@@ -3388,6 +3574,7 @@ namespace OpenSim.Region.Framework.Scenes
3388 cntr++; 3574 cntr++;
3389 } 3575 }
3390 } 3576 }
3577 lockPartsForRead(false);
3391 3578
3392 for (int ctr = 0; ctr < localids.Length; ctr++) 3579 for (int ctr = 0; ctr < localids.Length; ctr++)
3393 { 3580 {
@@ -3406,7 +3593,7 @@ namespace OpenSim.Region.Framework.Scenes
3406 { 3593 {
3407 //trigger not_at_target 3594 //trigger not_at_target
3408 uint[] localids = new uint[0]; 3595 uint[] localids = new uint[0];
3409 lock (m_parts) 3596 lockPartsForRead(true);
3410 { 3597 {
3411 localids = new uint[m_parts.Count]; 3598 localids = new uint[m_parts.Count];
3412 int cntr = 0; 3599 int cntr = 0;
@@ -3416,7 +3603,8 @@ namespace OpenSim.Region.Framework.Scenes
3416 cntr++; 3603 cntr++;
3417 } 3604 }
3418 } 3605 }
3419 3606 lockPartsForRead(false);
3607
3420 for (int ctr = 0; ctr < localids.Length; ctr++) 3608 for (int ctr = 0; ctr < localids.Length; ctr++)
3421 { 3609 {
3422 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3610 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3508,19 +3696,20 @@ namespace OpenSim.Region.Framework.Scenes
3508 public float GetMass() 3696 public float GetMass()
3509 { 3697 {
3510 float retmass = 0f; 3698 float retmass = 0f;
3511 lock (m_parts) 3699 lockPartsForRead(true);
3512 { 3700 {
3513 foreach (SceneObjectPart part in m_parts.Values) 3701 foreach (SceneObjectPart part in m_parts.Values)
3514 { 3702 {
3515 retmass += part.GetMass(); 3703 retmass += part.GetMass();
3516 } 3704 }
3517 } 3705 }
3706 lockPartsForRead(false);
3518 return retmass; 3707 return retmass;
3519 } 3708 }
3520 3709
3521 public void CheckSculptAndLoad() 3710 public void CheckSculptAndLoad()
3522 { 3711 {
3523 lock (m_parts) 3712 lockPartsForRead(true);
3524 { 3713 {
3525 if (!IsDeleted) 3714 if (!IsDeleted)
3526 { 3715 {
@@ -3545,6 +3734,7 @@ namespace OpenSim.Region.Framework.Scenes
3545 } 3734 }
3546 } 3735 }
3547 } 3736 }
3737 lockPartsForRead(false);
3548 } 3738 }
3549 3739
3550 protected void AssetReceived(string id, Object sender, AssetBase asset) 3740 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3565,7 +3755,7 @@ namespace OpenSim.Region.Framework.Scenes
3565 /// <param name="client"></param> 3755 /// <param name="client"></param>
3566 public void SetGroup(UUID GroupID, IClientAPI client) 3756 public void SetGroup(UUID GroupID, IClientAPI client)
3567 { 3757 {
3568 lock (m_parts) 3758 lockPartsForRead(true);
3569 { 3759 {
3570 foreach (SceneObjectPart part in m_parts.Values) 3760 foreach (SceneObjectPart part in m_parts.Values)
3571 { 3761 {
@@ -3575,10 +3765,15 @@ namespace OpenSim.Region.Framework.Scenes
3575 3765
3576 HasGroupChanged = true; 3766 HasGroupChanged = true;
3577 } 3767 }
3768<<<<<<< HEAD:OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
3769 lockPartsForRead(false);
3770 ScheduleGroupForFullUpdate();
3771=======
3578 3772
3579 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3773 // 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. 3774 // for the same object with very different properties. The caller must schedule the update.
3581 //ScheduleGroupForFullUpdate(); 3775 //ScheduleGroupForFullUpdate();
3776>>>>>>> 0.6.9-post-fixes:OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
3582 } 3777 }
3583 3778
3584 public void TriggerScriptChangedEvent(Changed val) 3779 public void TriggerScriptChangedEvent(Changed val)
@@ -3596,11 +3791,12 @@ namespace OpenSim.Region.Framework.Scenes
3596 3791
3597 public void SetAttachmentPoint(byte point) 3792 public void SetAttachmentPoint(byte point)
3598 { 3793 {
3599 lock (m_parts) 3794 lockPartsForRead(true);
3600 { 3795 {
3601 foreach (SceneObjectPart part in m_parts.Values) 3796 foreach (SceneObjectPart part in m_parts.Values)
3602 part.SetAttachmentPoint(point); 3797 part.SetAttachmentPoint(point);
3603 } 3798 }
3799 lockPartsForRead(false);
3604 } 3800 }
3605 3801
3606 #region ISceneObject 3802 #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..5d00917 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -82,7 +82,9 @@ namespace OpenSim.Region.Framework.Scenes
82 /// </value> 82 /// </value>
83 protected internal TaskInventoryDictionary Items 83 protected internal TaskInventoryDictionary Items
84 { 84 {
85 get { return m_items; } 85 get {
86 return m_items;
87 }
86 set 88 set
87 { 89 {
88 m_items = value; 90 m_items = value;
@@ -118,22 +120,25 @@ namespace OpenSim.Region.Framework.Scenes
118 /// <param name="linkNum">Link number for the part</param> 120 /// <param name="linkNum">Link number for the part</param>
119 public void ResetInventoryIDs() 121 public void ResetInventoryIDs()
120 { 122 {
121 lock (Items) 123 m_items.LockItemsForWrite(true);
124
125 if (0 == Items.Count)
122 { 126 {
123 if (0 == Items.Count) 127 m_items.LockItemsForWrite(false);
124 return; 128 return;
129 }
125 130
126 HasInventoryChanged = true; 131 HasInventoryChanged = true;
127 m_part.ParentGroup.HasGroupChanged = true; 132 m_part.ParentGroup.HasGroupChanged = true;
128 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 133 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
129 Items.Clear(); 134 Items.Clear();
130 135
131 foreach (TaskInventoryItem item in items) 136 foreach (TaskInventoryItem item in items)
132 { 137 {
133 item.ResetIDs(m_part.UUID); 138 item.ResetIDs(m_part.UUID);
134 Items.Add(item.ItemID, item); 139 Items.Add(item.ItemID, item);
135 }
136 } 140 }
141 m_items.LockItemsForWrite(false);
137 } 142 }
138 143
139 /// <summary> 144 /// <summary>
@@ -142,25 +147,25 @@ namespace OpenSim.Region.Framework.Scenes
142 /// <param name="ownerId"></param> 147 /// <param name="ownerId"></param>
143 public void ChangeInventoryOwner(UUID ownerId) 148 public void ChangeInventoryOwner(UUID ownerId)
144 { 149 {
145 lock (Items) 150 m_items.LockItemsForWrite(true);
151 if (0 == Items.Count)
146 { 152 {
147 if (0 == Items.Count) 153 m_items.LockItemsForWrite(false);
148 { 154 return;
149 return; 155 }
150 }
151 156
152 HasInventoryChanged = true; 157 HasInventoryChanged = true;
153 m_part.ParentGroup.HasGroupChanged = true; 158 m_part.ParentGroup.HasGroupChanged = true;
154 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 159 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
155 foreach (TaskInventoryItem item in items) 160 foreach (TaskInventoryItem item in items)
161 {
162 if (ownerId != item.OwnerID)
156 { 163 {
157 if (ownerId != item.OwnerID) 164 item.LastOwnerID = item.OwnerID;
158 { 165 item.OwnerID = ownerId;
159 item.LastOwnerID = item.OwnerID;
160 item.OwnerID = ownerId;
161 }
162 } 166 }
163 } 167 }
168 m_items.LockItemsForWrite(false);
164 } 169 }
165 170
166 /// <summary> 171 /// <summary>
@@ -169,24 +174,24 @@ namespace OpenSim.Region.Framework.Scenes
169 /// <param name="groupID"></param> 174 /// <param name="groupID"></param>
170 public void ChangeInventoryGroup(UUID groupID) 175 public void ChangeInventoryGroup(UUID groupID)
171 { 176 {
172 lock (Items) 177 m_items.LockItemsForWrite(true);
178 if (0 == Items.Count)
173 { 179 {
174 if (0 == Items.Count) 180 m_items.LockItemsForWrite(false);
175 { 181 return;
176 return; 182 }
177 }
178 183
179 HasInventoryChanged = true; 184 HasInventoryChanged = true;
180 m_part.ParentGroup.HasGroupChanged = true; 185 m_part.ParentGroup.HasGroupChanged = true;
181 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 186 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
182 foreach (TaskInventoryItem item in items) 187 foreach (TaskInventoryItem item in items)
188 {
189 if (groupID != item.GroupID)
183 { 190 {
184 if (groupID != item.GroupID) 191 item.GroupID = groupID;
185 {
186 item.GroupID = groupID;
187 }
188 } 192 }
189 } 193 }
194 m_items.LockItemsForWrite(false);
190 } 195 }
191 196
192 /// <summary> 197 /// <summary>
@@ -194,14 +199,14 @@ namespace OpenSim.Region.Framework.Scenes
194 /// </summary> 199 /// </summary>
195 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 200 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
196 { 201 {
197 lock (m_items) 202 Items.LockItemsForRead(true);
203 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
204 Items.LockItemsForRead(false);
205 foreach (TaskInventoryItem item in items)
198 { 206 {
199 foreach (TaskInventoryItem item in Items.Values) 207 if ((int)InventoryType.LSL == item.InvType)
200 { 208 {
201 if ((int)InventoryType.LSL == item.InvType) 209 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
202 {
203 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
204 }
205 } 210 }
206 } 211 }
207 } 212 }
@@ -236,16 +241,20 @@ namespace OpenSim.Region.Framework.Scenes
236 /// </param> 241 /// </param>
237 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 242 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
238 { 243 {
239 lock (Items) 244 Items.LockItemsForRead(true);
245 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
246 Items.LockItemsForRead(false);
247
248 foreach (TaskInventoryItem item in items)
240 { 249 {
241 foreach (TaskInventoryItem item in Items.Values) 250 if ((int)InventoryType.LSL == item.InvType)
242 { 251 {
243 if ((int)InventoryType.LSL == item.InvType) 252 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
244 { 253 m_part.RemoveScriptEvents(item.ItemID);
245 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
246 }
247 } 254 }
248 } 255 }
256
257
249 } 258 }
250 259
251 /// <summary> 260 /// <summary>
@@ -270,12 +279,10 @@ namespace OpenSim.Region.Framework.Scenes
270 if (stateSource == 1 && // Prim crossing 279 if (stateSource == 1 && // Prim crossing
271 m_part.ParentGroup.Scene.m_trustBinaries) 280 m_part.ParentGroup.Scene.m_trustBinaries)
272 { 281 {
273 lock (m_items) 282 m_items.LockItemsForWrite(true);
274 { 283 m_items[item.ItemID].PermsMask = 0;
275 m_items[item.ItemID].PermsMask = 0; 284 m_items[item.ItemID].PermsGranter = UUID.Zero;
276 m_items[item.ItemID].PermsGranter = UUID.Zero; 285 m_items.LockItemsForWrite(false);
277 }
278
279 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 286 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
280 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 287 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
281 m_part.ParentGroup.AddActiveScriptCount(1); 288 m_part.ParentGroup.AddActiveScriptCount(1);
@@ -283,36 +290,31 @@ namespace OpenSim.Region.Framework.Scenes
283 return; 290 return;
284 } 291 }
285 292
286 m_part.ParentGroup.Scene.AssetService.Get( 293 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) 294 {
288 { 295 if (null == asset)
289 if (null == asset) 296 {
290 { 297 m_log.ErrorFormat(
291 m_log.ErrorFormat( 298 "[PRIM INVENTORY]: " +
292 "[PRIM INVENTORY]: " + 299 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
293 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 300 item.Name, item.ItemID, m_part.AbsolutePosition,
294 item.Name, item.ItemID, m_part.AbsolutePosition, 301 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
295 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); 302 }
296 } 303 else
297 else 304 {
298 { 305 if (m_part.ParentGroup.m_savedScriptState != null)
299 if (m_part.ParentGroup.m_savedScriptState != null) 306 RestoreSavedScriptState(item.OldItemID, item.ItemID);
300 RestoreSavedScriptState(item.OldItemID, item.ItemID); 307 m_items.LockItemsForWrite(true);
301 308 m_items[item.ItemID].PermsMask = 0;
302 lock (m_items) 309 m_items[item.ItemID].PermsGranter = UUID.Zero;
303 { 310 m_items.LockItemsForWrite(false);
304 m_items[item.ItemID].PermsMask = 0; 311 string script = Utils.BytesToString(asset.Data);
305 m_items[item.ItemID].PermsGranter = UUID.Zero; 312 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
306 } 313 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
307 314 m_part.ParentGroup.AddActiveScriptCount(1);
308 string script = Utils.BytesToString(asset.Data); 315 m_part.ScheduleFullUpdate();
309 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 316 }
310 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 317 });
311 m_part.ParentGroup.AddActiveScriptCount(1);
312 m_part.ScheduleFullUpdate();
313 }
314 }
315 );
316 } 318 }
317 } 319 }
318 320
@@ -379,14 +381,17 @@ namespace OpenSim.Region.Framework.Scenes
379 /// </param> 381 /// </param>
380 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 382 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
381 { 383 {
382 lock (m_items) 384 m_items.LockItemsForRead(true);
385 if (m_items.ContainsKey(itemId))
383 { 386 {
384 if (m_items.ContainsKey(itemId)) 387 if (m_items.ContainsKey(itemId))
385 { 388 {
389 m_items.LockItemsForRead(false);
386 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); 390 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
387 } 391 }
388 else 392 else
389 { 393 {
394 m_items.LockItemsForRead(false);
390 m_log.ErrorFormat( 395 m_log.ErrorFormat(
391 "[PRIM INVENTORY]: " + 396 "[PRIM INVENTORY]: " +
392 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 397 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
@@ -394,6 +399,15 @@ namespace OpenSim.Region.Framework.Scenes
394 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 399 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
395 } 400 }
396 } 401 }
402 else
403 {
404 m_items.LockItemsForRead(false);
405 m_log.ErrorFormat(
406 "[PRIM INVENTORY]: " +
407 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2}",
408 itemId, m_part.Name, m_part.UUID);
409 }
410
397 } 411 }
398 412
399 /// <summary> 413 /// <summary>
@@ -406,15 +420,7 @@ namespace OpenSim.Region.Framework.Scenes
406 /// </param> 420 /// </param>
407 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 421 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
408 { 422 {
409 bool scriptPresent = false; 423 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 { 424 {
419 if (!sceneObjectBeingDeleted) 425 if (!sceneObjectBeingDeleted)
420 m_part.RemoveScriptEvents(itemId); 426 m_part.RemoveScriptEvents(itemId);
@@ -440,11 +446,16 @@ namespace OpenSim.Region.Framework.Scenes
440 /// <returns></returns> 446 /// <returns></returns>
441 private bool InventoryContainsName(string name) 447 private bool InventoryContainsName(string name)
442 { 448 {
443 foreach (TaskInventoryItem item in Items.Values) 449 m_items.LockItemsForRead(true);
450 foreach (TaskInventoryItem item in m_items.Values)
444 { 451 {
445 if (item.Name == name) 452 if (item.Name == name)
453 {
454 m_items.LockItemsForRead(false);
446 return true; 455 return true;
456 }
447 } 457 }
458 m_items.LockItemsForRead(false);
448 return false; 459 return false;
449 } 460 }
450 461
@@ -486,13 +497,9 @@ namespace OpenSim.Region.Framework.Scenes
486 /// <param name="item"></param> 497 /// <param name="item"></param>
487 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 498 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
488 { 499 {
489 List<TaskInventoryItem> il; 500 m_items.LockItemsForRead(true);
490 501 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
491 lock (m_items) 502 m_items.LockItemsForRead(false);
492 {
493 il = new List<TaskInventoryItem>(m_items.Values);
494 }
495
496 foreach (TaskInventoryItem i in il) 503 foreach (TaskInventoryItem i in il)
497 { 504 {
498 if (i.Name == item.Name) 505 if (i.Name == item.Name)
@@ -529,15 +536,14 @@ namespace OpenSim.Region.Framework.Scenes
529 item.ParentPartID = m_part.UUID; 536 item.ParentPartID = m_part.UUID;
530 item.Name = name; 537 item.Name = name;
531 538
532 lock (m_items) 539 m_items.LockItemsForWrite(true);
533 { 540 m_items.Add(item.ItemID, item);
534 m_items.Add(item.ItemID, item); 541 m_items.LockItemsForWrite(false);
535
536 if (allowedDrop) 542 if (allowedDrop)
537 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 543 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
538 else 544 else
539 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 545 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
540 } 546
541 547
542 m_inventorySerial++; 548 m_inventorySerial++;
543 //m_inventorySerial += 2; 549 //m_inventorySerial += 2;
@@ -554,14 +560,13 @@ namespace OpenSim.Region.Framework.Scenes
554 /// <param name="items"></param> 560 /// <param name="items"></param>
555 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 561 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
556 { 562 {
557 lock (m_items) 563 m_items.LockItemsForWrite(true);
564 foreach (TaskInventoryItem item in items)
558 { 565 {
559 foreach (TaskInventoryItem item in items) 566 m_items.Add(item.ItemID, item);
560 { 567 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
561 m_items.Add(item.ItemID, item);
562 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
563 }
564 } 568 }
569 m_items.LockItemsForWrite(false);
565 570
566 m_inventorySerial++; 571 m_inventorySerial++;
567 } 572 }
@@ -574,10 +579,9 @@ namespace OpenSim.Region.Framework.Scenes
574 public TaskInventoryItem GetInventoryItem(UUID itemId) 579 public TaskInventoryItem GetInventoryItem(UUID itemId)
575 { 580 {
576 TaskInventoryItem item; 581 TaskInventoryItem item;
577 582 m_items.LockItemsForRead(true);
578 lock (m_items) 583 m_items.TryGetValue(itemId, out item);
579 m_items.TryGetValue(itemId, out item); 584 m_items.LockItemsForRead(false);
580
581 return item; 585 return item;
582 } 586 }
583 587
@@ -613,46 +617,46 @@ namespace OpenSim.Region.Framework.Scenes
613 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 617 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
614 public bool UpdateInventoryItem(TaskInventoryItem item) 618 public bool UpdateInventoryItem(TaskInventoryItem item)
615 { 619 {
616 lock (m_items) 620 m_items.LockItemsForWrite(true);
621
622 if (m_items.ContainsKey(item.ItemID))
617 { 623 {
618 if (m_items.ContainsKey(item.ItemID)) 624 item.ParentID = m_part.UUID;
625 item.ParentPartID = m_part.UUID;
626 item.Flags = m_items[item.ItemID].Flags;
627 if (item.AssetID == UUID.Zero)
619 { 628 {
620 item.ParentID = m_part.UUID; 629 item.AssetID = m_items[item.ItemID].AssetID;
621 item.ParentPartID = m_part.UUID; 630 }
622 item.Flags = m_items[item.ItemID].Flags; 631 else if ((InventoryType)item.Type == InventoryType.Notecard)
623 if (item.AssetID == UUID.Zero) 632 {
624 { 633 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 634
631 if (presence != null) 635 if (presence != null)
632 { 636 {
633 presence.ControllingClient.SendAgentAlertMessage( 637 presence.ControllingClient.SendAgentAlertMessage(
634 "Notecard saved", false); 638 "Notecard saved", false);
635 }
636 } 639 }
640 }
637 641
638 m_items[item.ItemID] = item; 642 m_items[item.ItemID] = item;
639 m_inventorySerial++; 643 m_inventorySerial++;
640 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 644 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
641
642 HasInventoryChanged = true;
643 m_part.ParentGroup.HasGroupChanged = true;
644 645
645 return true; 646 HasInventoryChanged = true;
646 } 647 m_part.ParentGroup.HasGroupChanged = true;
647 else 648 m_items.LockItemsForWrite(false);
648 { 649 return true;
649 m_log.ErrorFormat( 650 }
650 "[PRIM INVENTORY]: " + 651 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", 652 {
652 item.ItemID, m_part.Name, m_part.UUID, 653 m_log.ErrorFormat(
653 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 654 "[PRIM INVENTORY]: " +
654 } 655 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
656 item.ItemID, m_part.Name, m_part.UUID,
657 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
655 } 658 }
659 m_items.LockItemsForWrite(false);
656 660
657 return false; 661 return false;
658 } 662 }
@@ -665,53 +669,54 @@ namespace OpenSim.Region.Framework.Scenes
665 /// in this prim's inventory.</returns> 669 /// in this prim's inventory.</returns>
666 public int RemoveInventoryItem(UUID itemID) 670 public int RemoveInventoryItem(UUID itemID)
667 { 671 {
668 lock (m_items) 672 m_items.LockItemsForRead(true);
673
674 if (m_items.ContainsKey(itemID))
669 { 675 {
670 if (m_items.ContainsKey(itemID)) 676 int type = m_items[itemID].InvType;
677 m_items.LockItemsForRead(false);
678 if (type == 10) // Script
671 { 679 {
672 int type = m_items[itemID].InvType; 680 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
673 if (type == 10) // Script 681 }
674 { 682 m_items.LockItemsForWrite(true);
675 m_part.RemoveScriptEvents(itemID); 683 m_items.Remove(itemID);
676 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 684 m_items.LockItemsForWrite(false);
677 } 685 m_inventorySerial++;
678 m_items.Remove(itemID); 686 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 687
685 int scriptcount = 0; 688 HasInventoryChanged = true;
686 lock (m_items) 689 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 690
697 if (scriptcount <= 0) 691 int scriptcount = 0;
692 m_items.LockItemsForRead(true);
693 foreach (TaskInventoryItem item in m_items.Values)
694 {
695 if (item.Type == 10)
698 { 696 {
699 m_part.RemFlag(PrimFlags.Scripted); 697 scriptcount++;
700 } 698 }
701
702 m_part.ScheduleFullUpdate();
703
704 return type;
705 } 699 }
706 else 700 m_items.LockItemsForRead(false);
701
702
703 if (scriptcount <= 0)
707 { 704 {
708 m_log.ErrorFormat( 705 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 } 706 }
707
708 m_part.ScheduleFullUpdate();
709
710 return type;
711 }
712 else
713 {
714 m_log.ErrorFormat(
715 "[PRIM INVENTORY]: " +
716 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
717 itemID, m_part.Name, m_part.UUID);
714 } 718 }
719 m_items.LockItemsForWrite(false);
715 720
716 return -1; 721 return -1;
717 } 722 }
@@ -764,52 +769,53 @@ namespace OpenSim.Region.Framework.Scenes
764 // isn't available (such as drag from prim inventory to agent inventory) 769 // isn't available (such as drag from prim inventory to agent inventory)
765 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 770 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
766 771
767 lock (m_items) 772 m_items.LockItemsForRead(true);
773
774 foreach (TaskInventoryItem item in m_items.Values)
768 { 775 {
769 foreach (TaskInventoryItem item in m_items.Values) 776 UUID ownerID = item.OwnerID;
770 { 777 uint everyoneMask = 0;
771 UUID ownerID = item.OwnerID; 778 uint baseMask = item.BasePermissions;
772 uint everyoneMask = 0; 779 uint ownerMask = item.CurrentPermissions;
773 uint baseMask = item.BasePermissions;
774 uint ownerMask = item.CurrentPermissions;
775 780
776 invString.AddItemStart(); 781 invString.AddItemStart();
777 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 782 invString.AddNameValueLine("item_id", item.ItemID.ToString());
778 invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); 783 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
779 784
780 invString.AddPermissionsStart(); 785 invString.AddPermissionsStart();
781 786
782 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 787 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
783 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 788 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
784 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0)); 789 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0));
785 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 790 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
786 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 791 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
787 792
788 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 793 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
789 invString.AddNameValueLine("owner_id", ownerID.ToString()); 794 invString.AddNameValueLine("owner_id", ownerID.ToString());
790 795
791 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 796 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
792 797
793 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 798 invString.AddNameValueLine("group_id", item.GroupID.ToString());
794 invString.AddSectionEnd(); 799 invString.AddSectionEnd();
795 800
796 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 801 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
797 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 802 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
798 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 803 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
799 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 804 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
800 805
801 invString.AddSaleStart(); 806 invString.AddSaleStart();
802 invString.AddNameValueLine("sale_type", "not"); 807 invString.AddNameValueLine("sale_type", "not");
803 invString.AddNameValueLine("sale_price", "0"); 808 invString.AddNameValueLine("sale_price", "0");
804 invString.AddSectionEnd(); 809 invString.AddSectionEnd();
805 810
806 invString.AddNameValueLine("name", item.Name + "|"); 811 invString.AddNameValueLine("name", item.Name + "|");
807 invString.AddNameValueLine("desc", item.Description + "|"); 812 invString.AddNameValueLine("desc", item.Description + "|");
808 813
809 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 814 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
810 invString.AddSectionEnd(); 815 invString.AddSectionEnd();
811 }
812 } 816 }
817 int count = m_items.Count;
818 m_items.LockItemsForRead(false);
813 819
814 fileData = Utils.StringToBytes(invString.BuildString); 820 fileData = Utils.StringToBytes(invString.BuildString);
815 821
@@ -830,10 +836,9 @@ namespace OpenSim.Region.Framework.Scenes
830 { 836 {
831 if (HasInventoryChanged) 837 if (HasInventoryChanged)
832 { 838 {
833 lock (Items) 839 Items.LockItemsForRead(true);
834 { 840 datastore.StorePrimInventory(m_part.UUID, Items.Values);
835 datastore.StorePrimInventory(m_part.UUID, Items.Values); 841 Items.LockItemsForRead(false);
836 }
837 842
838 HasInventoryChanged = false; 843 HasInventoryChanged = false;
839 } 844 }
@@ -902,61 +907,54 @@ namespace OpenSim.Region.Framework.Scenes
902 { 907 {
903 uint mask=0x7fffffff; 908 uint mask=0x7fffffff;
904 909
905 lock (m_items) 910 foreach (TaskInventoryItem item in m_items.Values)
906 { 911 {
907 foreach (TaskInventoryItem item in m_items.Values) 912 if (item.InvType != (int)InventoryType.Object)
908 { 913 {
909 if (item.InvType != (int)InventoryType.Object) 914 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
910 { 915 mask &= ~((uint)PermissionMask.Copy >> 13);
911 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 916 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
912 mask &= ~((uint)PermissionMask.Copy >> 13); 917 mask &= ~((uint)PermissionMask.Transfer >> 13);
913 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 918 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
914 mask &= ~((uint)PermissionMask.Transfer >> 13); 919 mask &= ~((uint)PermissionMask.Modify >> 13);
915 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 920 }
916 mask &= ~((uint)PermissionMask.Modify >> 13); 921 else
917 } 922 {
918 else 923 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
919 { 924 mask &= ~((uint)PermissionMask.Copy >> 13);
920 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 925 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
921 mask &= ~((uint)PermissionMask.Copy >> 13); 926 mask &= ~((uint)PermissionMask.Transfer >> 13);
922 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 927 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
923 mask &= ~((uint)PermissionMask.Transfer >> 13); 928 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 } 929 }
930
931 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
932 mask &= ~(uint)PermissionMask.Copy;
933 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
934 mask &= ~(uint)PermissionMask.Transfer;
935 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
936 mask &= ~(uint)PermissionMask.Modify;
935 } 937 }
936
937 return mask; 938 return mask;
938 } 939 }
939 940
940 public void ApplyNextOwnerPermissions() 941 public void ApplyNextOwnerPermissions()
941 { 942 {
942 lock (m_items) 943 foreach (TaskInventoryItem item in m_items.Values)
943 { 944 {
944 foreach (TaskInventoryItem item in m_items.Values) 945 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
945 { 946 {
946 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 947 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
947 { 948 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
948 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 949 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
949 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 950 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
950 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 951 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
951 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 952 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
952 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 953 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 } 954 }
955 item.CurrentPermissions &= item.NextPermissions;
956 item.BasePermissions &= item.NextPermissions;
957 item.EveryonePermissions &= item.NextPermissions;
960 } 958 }
961 959
962 m_part.TriggerScriptChangedEvent(Changed.OWNER); 960 m_part.TriggerScriptChangedEvent(Changed.OWNER);
@@ -964,29 +962,22 @@ namespace OpenSim.Region.Framework.Scenes
964 962
965 public void ApplyGodPermissions(uint perms) 963 public void ApplyGodPermissions(uint perms)
966 { 964 {
967 lock (m_items) 965 foreach (TaskInventoryItem item in m_items.Values)
968 { 966 {
969 foreach (TaskInventoryItem item in m_items.Values) 967 item.CurrentPermissions = perms;
970 { 968 item.BasePermissions = perms;
971 item.CurrentPermissions = perms;
972 item.BasePermissions = perms;
973 }
974 } 969 }
975 } 970 }
976 971
977 public bool ContainsScripts() 972 public bool ContainsScripts()
978 { 973 {
979 lock (m_items) 974 foreach (TaskInventoryItem item in m_items.Values)
980 { 975 {
981 foreach (TaskInventoryItem item in m_items.Values) 976 if (item.InvType == (int)InventoryType.LSL)
982 { 977 {
983 if (item.InvType == (int)InventoryType.LSL) 978 return true;
984 {
985 return true;
986 }
987 } 979 }
988 } 980 }
989
990 return false; 981 return false;
991 } 982 }
992 983
@@ -994,11 +985,8 @@ namespace OpenSim.Region.Framework.Scenes
994 { 985 {
995 List<UUID> ret = new List<UUID>(); 986 List<UUID> ret = new List<UUID>();
996 987
997 lock (m_items) 988 foreach (TaskInventoryItem item in m_items.Values)
998 { 989 ret.Add(item.ItemID);
999 foreach (TaskInventoryItem item in m_items.Values)
1000 ret.Add(item.ItemID);
1001 }
1002 990
1003 return ret; 991 return ret;
1004 } 992 }
@@ -1011,30 +999,26 @@ namespace OpenSim.Region.Framework.Scenes
1011 if (engines == null) // No engine at all 999 if (engines == null) // No engine at all
1012 return ret; 1000 return ret;
1013 1001
1014 lock (m_items) 1002 foreach (TaskInventoryItem item in m_items.Values)
1015 { 1003 {
1016 foreach (TaskInventoryItem item in m_items.Values) 1004 if (item.InvType == (int)InventoryType.LSL)
1017 { 1005 {
1018 if (item.InvType == (int)InventoryType.LSL) 1006 foreach (IScriptModule e in engines)
1019 { 1007 {
1020 foreach (IScriptModule e in engines) 1008 if (e != null)
1021 { 1009 {
1022 if (e != null) 1010 string n = e.GetXMLState(item.ItemID);
1011 if (n != String.Empty)
1023 { 1012 {
1024 string n = e.GetXMLState(item.ItemID); 1013 if (!ret.ContainsKey(item.ItemID))
1025 if (n != String.Empty) 1014 ret[item.ItemID] = n;
1026 { 1015 break;
1027 if (!ret.ContainsKey(item.ItemID))
1028 ret[item.ItemID] = n;
1029 break;
1030 }
1031 } 1016 }
1032 } 1017 }
1033 } 1018 }
1034 } 1019 }
1035 } 1020 }
1036
1037 return ret; 1021 return ret;
1038 } 1022 }
1039 } 1023 }
1040} \ No newline at end of file 1024}
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;