aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs29
-rw-r--r--OpenSim/Region/Framework/Scenes/EntityManager.cs79
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs45
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs26
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs601
-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.cs580
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs11
14 files changed, 1346 insertions, 810 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 7307662..fd7d44f 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 dc9ae19..37a51d9 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -206,7 +206,11 @@ namespace OpenSim.Region.Framework.Scenes
206 public event OnMakeChildAgentDelegate OnMakeChildAgent; 206 public event OnMakeChildAgentDelegate OnMakeChildAgent;
207 207
208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence); 208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence);
209 public delegate void OnSaveNewWindlightProfileDelegate();
210 public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionMeta7WindlightData wl, UUID user);
209 public event OnMakeRootAgentDelegate OnMakeRootAgent; 211 public event OnMakeRootAgentDelegate OnMakeRootAgent;
212 public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted;
213 public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile;
210 214
211 /// <summary> 215 /// <summary>
212 /// Triggered when an object or attachment enters a scene 216 /// Triggered when an object or attachment enters a scene
@@ -1216,6 +1220,24 @@ namespace OpenSim.Region.Framework.Scenes
1216 } 1220 }
1217 } 1221 }
1218 1222
1223 public void TriggerOnSendNewWindlightProfileTargeted(RegionMeta7WindlightData wl, UUID user)
1224 {
1225 OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted;
1226 if (handlerSendNewWindlightProfileTargeted != null)
1227 {
1228 handlerSendNewWindlightProfileTargeted(wl, user);
1229 }
1230 }
1231
1232 public void TriggerOnSaveNewWindlightProfile()
1233 {
1234 OnSaveNewWindlightProfileDelegate handlerSaveNewWindlightProfile = OnSaveNewWindlightProfile;
1235 if (handlerSaveNewWindlightProfile != null)
1236 {
1237 handlerSaveNewWindlightProfile();
1238 }
1239 }
1240
1219 public void TriggerOnMakeRootAgent(ScenePresence presence) 1241 public void TriggerOnMakeRootAgent(ScenePresence presence)
1220 { 1242 {
1221 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent; 1243 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent;
@@ -1992,4 +2014,4 @@ namespace OpenSim.Region.Framework.Scenes
1992 } 2014 }
1993 } 2015 }
1994 } 2016 }
1995} \ No newline at end of file 2017}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 31c0be1..1875c48 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -782,8 +782,12 @@ namespace OpenSim.Region.Framework.Scenes
782 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) 782 public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
783 { 783 {
784 SceneObjectPart part = GetSceneObjectPart(localID); 784 SceneObjectPart part = GetSceneObjectPart(localID);
785 SceneObjectGroup group = part.ParentGroup; 785 SceneObjectGroup group = null;
786 if (group != null) 786 if (part != null)
787 {
788 group = part.ParentGroup;
789 }
790 if (part != null && group != null)
787 { 791 {
788 TaskInventoryItem item = group.GetInventoryItem(localID, itemID); 792 TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
789 if (item == null) 793 if (item == null)
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 0085df3..2b6f80b 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -602,6 +602,8 @@ namespace OpenSim.Region.Framework.Scenes
602 602
603 // Load region settings 603 // Load region settings
604 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); 604 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID);
605 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(m_regInfo.RegionID);
606
605 if (m_storageManager.EstateDataStore != null) 607 if (m_storageManager.EstateDataStore != null)
606 { 608 {
607 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false); 609 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false);
@@ -1016,6 +1018,15 @@ namespace OpenSim.Region.Framework.Scenes
1016 /// <param name="seconds">float indicating duration before restart.</param> 1018 /// <param name="seconds">float indicating duration before restart.</param>
1017 public virtual void Restart(float seconds) 1019 public virtual void Restart(float seconds)
1018 { 1020 {
1021 Restart(seconds, true);
1022 }
1023
1024 /// <summary>
1025 /// Given float seconds, this will restart the region. showDialog will optionally alert the users.
1026 /// </summary>
1027 /// <param name="seconds">float indicating duration before restart.</param>
1028 public virtual void Restart(float seconds, bool showDialog)
1029 {
1019 // notifications are done in 15 second increments 1030 // notifications are done in 15 second increments
1020 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request 1031 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request
1021 // It's a 'Cancel restart' request. 1032 // It's a 'Cancel restart' request.
@@ -1036,8 +1047,11 @@ namespace OpenSim.Region.Framework.Scenes
1036 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); 1047 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed);
1037 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); 1048 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes");
1038 m_restartTimer.Start(); 1049 m_restartTimer.Start();
1039 m_dialogModule.SendNotificationToUsersInRegion( 1050 if (showDialog)
1051 {
1052 m_dialogModule.SendNotificationToUsersInRegion(
1040 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); 1053 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0)));
1054 }
1041 } 1055 }
1042 } 1056 }
1043 1057
@@ -1393,16 +1407,16 @@ namespace OpenSim.Region.Framework.Scenes
1393 // Check if any objects have reached their targets 1407 // Check if any objects have reached their targets
1394 CheckAtTargets(); 1408 CheckAtTargets();
1395 1409
1396 // Update SceneObjectGroups that have scheduled themselves for updates
1397 // Objects queue their updates onto all scene presences
1398 if (m_frame % m_update_objects == 0)
1399 m_sceneGraph.UpdateObjectGroups();
1400
1401 // Run through all ScenePresences looking for updates 1410 // Run through all ScenePresences looking for updates
1402 // Presence updates and queued object updates for each presence are sent to clients 1411 // Presence updates and queued object updates for each presence are sent to clients
1403 if (m_frame % m_update_presences == 0) 1412 if (m_frame % m_update_presences == 0)
1404 m_sceneGraph.UpdatePresences(); 1413 m_sceneGraph.UpdatePresences();
1405 1414
1415 // Update SceneObjectGroups that have scheduled themselves for updates
1416 // Objects queue their updates onto all scene presences
1417 if (m_frame % m_update_objects == 0)
1418 m_sceneGraph.UpdateObjectGroups();
1419
1406 int tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1420 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1407 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1421 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1408 m_sceneGraph.UpdatePreparePhysics(); 1422 m_sceneGraph.UpdatePreparePhysics();
@@ -1713,6 +1727,19 @@ namespace OpenSim.Region.Framework.Scenes
1713 public void SaveTerrain() 1727 public void SaveTerrain()
1714 { 1728 {
1715 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1729 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1730 }
1731
1732 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1733 {
1734 m_regInfo.WindlightSettings = wl;
1735 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
1736 m_eventManager.TriggerOnSaveNewWindlightProfile();
1737 }
1738
1739 public void LoadWindlightProfile()
1740 {
1741 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1742 m_eventManager.TriggerOnSaveNewWindlightProfile();
1716 } 1743 }
1717 1744
1718 /// <summary> 1745 /// <summary>
@@ -3400,6 +3427,9 @@ namespace OpenSim.Region.Framework.Scenes
3400 3427
3401 CapsModule.AddCapsHandler(agent.AgentID); 3428 CapsModule.AddCapsHandler(agent.AgentID);
3402 3429
3430 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3431 System.Threading.Thread.Sleep(2000);
3432
3403 if (!agent.child) 3433 if (!agent.child)
3404 { 3434 {
3405 if (TestBorderCross(agent.startpos,Cardinals.E)) 3435 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3458,6 +3488,8 @@ namespace OpenSim.Region.Framework.Scenes
3458 } 3488 }
3459 } 3489 }
3460 // Honor parcel landing type and position. 3490 // Honor parcel landing type and position.
3491 /*
3492 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3461 if (land != null) 3493 if (land != null)
3462 { 3494 {
3463 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3495 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3465,6 +3497,7 @@ namespace OpenSim.Region.Framework.Scenes
3465 agent.startpos = land.LandData.UserLocation; 3497 agent.startpos = land.LandData.UserLocation;
3466 } 3498 }
3467 } 3499 }
3500 */// This is now handled properly in ScenePresence.MakeRootAgent
3468 } 3501 }
3469 3502
3470 agent.teleportFlags = teleportFlags; 3503 agent.teleportFlags = teleportFlags;
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index bd8ccce..9d0e6f4 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -300,7 +300,7 @@ namespace OpenSim.Region.Framework.Scenes
300 d); 300 d);
301 } 301 }
302 } 302 }
303 303
304 public List<GridRegion> RequestNamedRegions(string name, int maxNumber) 304 public List<GridRegion> RequestNamedRegions(string name, int maxNumber)
305 { 305 {
306 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); 306 return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber);
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 23a4ee9..3a1962c 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -225,6 +225,30 @@ namespace OpenSim.Region.Framework.Scenes
225 protected internal bool AddRestoredSceneObject( 225 protected internal bool AddRestoredSceneObject(
226 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted) 226 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
227 { 227 {
228 // KF: Check for out-of-region, move inside and make static.
229 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
230 sceneObject.RootPart.GroupPosition.Y,
231 sceneObject.RootPart.GroupPosition.Z);
232 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 ||
233 npos.X > Constants.RegionSize ||
234 npos.Y > Constants.RegionSize))
235 {
236 if (npos.X < 0.0) npos.X = 1.0f;
237 if (npos.Y < 0.0) npos.Y = 1.0f;
238 if (npos.Z < 0.0) npos.Z = 0.0f;
239 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
240 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
241
242 foreach (SceneObjectPart part in sceneObject.Children.Values)
243 {
244 part.GroupPosition = npos;
245 }
246 sceneObject.RootPart.Velocity = Vector3.Zero;
247 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
248 sceneObject.RootPart.Acceleration = Vector3.Zero;
249 sceneObject.RootPart.Velocity = Vector3.Zero;
250 }
251
228 if (!alreadyPersisted) 252 if (!alreadyPersisted)
229 { 253 {
230 sceneObject.ForceInventoryPersistence(); 254 sceneObject.ForceInventoryPersistence();
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 8aefd50..3895d93 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)
@@ -305,17 +377,18 @@ namespace OpenSim.Region.Framework.Scenes
305 RootPart.ScriptSetPhysicsStatus(false); 377 RootPart.ScriptSetPhysicsStatus(false);
306 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), 378 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
307 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); 379 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
380 lockPartsForRead(false);
308 return; 381 return;
309 } 382 }
310 } 383 }
311 lock (m_parts) 384
385 foreach (SceneObjectPart part in m_parts.Values)
312 { 386 {
313 foreach (SceneObjectPart part in m_parts.Values) 387 part.GroupPosition = val;
314 {
315 part.GroupPosition = val;
316 }
317 } 388 }
318 389
390 lockPartsForRead(false);
391
319 //if (m_rootPart.PhysActor != null) 392 //if (m_rootPart.PhysActor != null)
320 //{ 393 //{
321 //m_rootPart.PhysActor.Position = 394 //m_rootPart.PhysActor.Position =
@@ -504,13 +577,16 @@ namespace OpenSim.Region.Framework.Scenes
504 577
505 public void SetFromItemID(UUID AssetId) 578 public void SetFromItemID(UUID AssetId)
506 { 579 {
507 lock (m_parts) 580 lockPartsForRead(true);
508 { 581 {
509 foreach (SceneObjectPart part in m_parts.Values) 582 foreach (SceneObjectPart part in m_parts.Values)
510 { 583 {
584
511 part.FromItemID = AssetId; 585 part.FromItemID = AssetId;
586
512 } 587 }
513 } 588 }
589 lockPartsForRead(false);
514 } 590 }
515 591
516 public UUID GetFromItemID() 592 public UUID GetFromItemID()
@@ -579,10 +655,11 @@ namespace OpenSim.Region.Framework.Scenes
579 Vector3 maxScale = Vector3.Zero; 655 Vector3 maxScale = Vector3.Zero;
580 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); 656 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
581 657
582 lock (m_parts) 658 lockPartsForRead(true);
583 { 659 {
584 foreach (SceneObjectPart part in m_parts.Values) 660 foreach (SceneObjectPart part in m_parts.Values)
585 { 661 {
662
586 Vector3 partscale = part.Scale; 663 Vector3 partscale = part.Scale;
587 Vector3 partoffset = part.OffsetPosition; 664 Vector3 partoffset = part.OffsetPosition;
588 665
@@ -593,8 +670,11 @@ namespace OpenSim.Region.Framework.Scenes
593 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X; 670 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; 671 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; 672 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
673
596 } 674 }
597 } 675 }
676 lockPartsForRead(false);
677
598 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; 678 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
599 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; 679 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
600 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; 680 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
@@ -610,10 +690,11 @@ namespace OpenSim.Region.Framework.Scenes
610 690
611 EntityIntersection result = new EntityIntersection(); 691 EntityIntersection result = new EntityIntersection();
612 692
613 lock (m_parts) 693 lockPartsForRead(true);
614 { 694 {
615 foreach (SceneObjectPart part in m_parts.Values) 695 foreach (SceneObjectPart part in m_parts.Values)
616 { 696 {
697
617 // Temporary commented to stop compiler warning 698 // Temporary commented to stop compiler warning
618 //Vector3 partPosition = 699 //Vector3 partPosition =
619 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); 700 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
@@ -641,8 +722,10 @@ namespace OpenSim.Region.Framework.Scenes
641 result.distance = inter.distance; 722 result.distance = inter.distance;
642 } 723 }
643 } 724 }
725
644 } 726 }
645 } 727 }
728 lockPartsForRead(false);
646 return result; 729 return result;
647 } 730 }
648 731
@@ -655,10 +738,11 @@ namespace OpenSim.Region.Framework.Scenes
655 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) 738 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
656 { 739 {
657 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f; 740 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f;
658 lock (m_parts) 741 lockPartsForRead(true);
659 { 742 {
660 foreach (SceneObjectPart part in m_parts.Values) 743 foreach (SceneObjectPart part in m_parts.Values)
661 { 744 {
745
662 Vector3 worldPos = part.GetWorldPosition(); 746 Vector3 worldPos = part.GetWorldPosition();
663 Vector3 offset = worldPos - AbsolutePosition; 747 Vector3 offset = worldPos - AbsolutePosition;
664 Quaternion worldRot; 748 Quaternion worldRot;
@@ -717,6 +801,8 @@ namespace OpenSim.Region.Framework.Scenes
717 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 801 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
718 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 802 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
719 803
804
805
720 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); 806 //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); 807 //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); 808 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
@@ -888,6 +974,7 @@ namespace OpenSim.Region.Framework.Scenes
888 minZ = backBottomLeft.Z; 974 minZ = backBottomLeft.Z;
889 } 975 }
890 } 976 }
977 lockPartsForRead(false);
891 978
892 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); 979 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
893 980
@@ -916,17 +1003,20 @@ namespace OpenSim.Region.Framework.Scenes
916 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1003 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
917 1004
918 // Capture script state while holding the lock 1005 // Capture script state while holding the lock
919 lock (m_parts) 1006 lockPartsForRead(true);
920 { 1007 {
921 foreach (SceneObjectPart part in m_parts.Values) 1008 foreach (SceneObjectPart part in m_parts.Values)
922 { 1009 {
1010
923 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); 1011 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates();
924 foreach (UUID itemid in pstates.Keys) 1012 foreach (UUID itemid in pstates.Keys)
925 { 1013 {
926 states.Add(itemid, pstates[itemid]); 1014 states.Add(itemid, pstates[itemid]);
927 } 1015 }
1016
928 } 1017 }
929 } 1018 }
1019 lockPartsForRead(false);
930 1020
931 if (states.Count > 0) 1021 if (states.Count > 0)
932 { 1022 {
@@ -1094,13 +1184,16 @@ namespace OpenSim.Region.Framework.Scenes
1094 1184
1095 public override void UpdateMovement() 1185 public override void UpdateMovement()
1096 { 1186 {
1097 lock (m_parts) 1187 lockPartsForRead(true);
1098 { 1188 {
1099 foreach (SceneObjectPart part in m_parts.Values) 1189 foreach (SceneObjectPart part in m_parts.Values)
1100 { 1190 {
1191
1101 part.UpdateMovement(); 1192 part.UpdateMovement();
1193
1102 } 1194 }
1103 } 1195 }
1196 lockPartsForRead(false);
1104 } 1197 }
1105 1198
1106 public ushort GetTimeDilation() 1199 public ushort GetTimeDilation()
@@ -1144,7 +1237,7 @@ namespace OpenSim.Region.Framework.Scenes
1144 /// <param name="part"></param> 1237 /// <param name="part"></param>
1145 public void AddPart(SceneObjectPart part) 1238 public void AddPart(SceneObjectPart part)
1146 { 1239 {
1147 lock (m_parts) 1240 lockPartsForWrite(true);
1148 { 1241 {
1149 part.SetParent(this); 1242 part.SetParent(this);
1150 m_parts.Add(part.UUID, part); 1243 m_parts.Add(part.UUID, part);
@@ -1154,6 +1247,7 @@ namespace OpenSim.Region.Framework.Scenes
1154 if (part.LinkNum == 2 && RootPart != null) 1247 if (part.LinkNum == 2 && RootPart != null)
1155 RootPart.LinkNum = 1; 1248 RootPart.LinkNum = 1;
1156 } 1249 }
1250 lockPartsForWrite(false);
1157 } 1251 }
1158 1252
1159 /// <summary> 1253 /// <summary>
@@ -1161,28 +1255,33 @@ namespace OpenSim.Region.Framework.Scenes
1161 /// </summary> 1255 /// </summary>
1162 private void UpdateParentIDs() 1256 private void UpdateParentIDs()
1163 { 1257 {
1164 lock (m_parts) 1258 lockPartsForRead(true);
1165 { 1259 {
1166 foreach (SceneObjectPart part in m_parts.Values) 1260 foreach (SceneObjectPart part in m_parts.Values)
1167 { 1261 {
1262
1168 if (part.UUID != m_rootPart.UUID) 1263 if (part.UUID != m_rootPart.UUID)
1169 { 1264 {
1170 part.ParentID = m_rootPart.LocalId; 1265 part.ParentID = m_rootPart.LocalId;
1171 } 1266 }
1267
1172 } 1268 }
1173 } 1269 }
1270 lockPartsForRead(false);
1174 } 1271 }
1175 1272
1176 public void RegenerateFullIDs() 1273 public void RegenerateFullIDs()
1177 { 1274 {
1178 lock (m_parts) 1275 lockPartsForRead(true);
1179 { 1276 {
1180 foreach (SceneObjectPart part in m_parts.Values) 1277 foreach (SceneObjectPart part in m_parts.Values)
1181 { 1278 {
1279
1182 part.UUID = UUID.Random(); 1280 part.UUID = UUID.Random();
1183 1281
1184 } 1282 }
1185 } 1283 }
1284 lockPartsForRead(false);
1186 } 1285 }
1187 1286
1188 // helper provided for parts. 1287 // helper provided for parts.
@@ -1263,27 +1362,33 @@ namespace OpenSim.Region.Framework.Scenes
1263 1362
1264 DetachFromBackup(); 1363 DetachFromBackup();
1265 1364
1266 lock (m_parts) 1365 lockPartsForRead(true);
1366 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1367 lockPartsForRead(false);
1368
1369 foreach (SceneObjectPart part in values)
1267 { 1370 {
1268 foreach (SceneObjectPart part in m_parts.Values)
1269 {
1270// part.Inventory.RemoveScriptInstances(); 1371// part.Inventory.RemoveScriptInstances();
1271 Scene.ForEachScenePresence(delegate(ScenePresence avatar) 1372
1373 List<ScenePresence> avatars = Scene.GetScenePresences();
1374 for (int i = 0; i < avatars.Count; i++)
1375 {
1376 if (avatars[i].ParentID == LocalId)
1272 { 1377 {
1273 if (avatar.ParentID == LocalId) 1378 avatars[i].StandUp();
1274 { 1379 }
1275 avatar.StandUp();
1276 }
1277 1380
1278 if (!silent) 1381 if (!silent)
1279 { 1382 {
1280 part.UpdateFlag = 0; 1383 part.UpdateFlag = 0;
1281 if (part == m_rootPart) 1384 if (part == m_rootPart)
1282 avatar.ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1385 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1283 } 1386 }
1284 });
1285 } 1387 }
1388
1286 } 1389 }
1390
1391
1287 } 1392 }
1288 1393
1289 public void AddScriptLPS(int count) 1394 public void AddScriptLPS(int count)
@@ -1308,17 +1413,20 @@ namespace OpenSim.Region.Framework.Scenes
1308 1413
1309 scriptEvents aggregateScriptEvents=0; 1414 scriptEvents aggregateScriptEvents=0;
1310 1415
1311 lock (m_parts) 1416 lockPartsForRead(true);
1312 { 1417 {
1313 foreach (SceneObjectPart part in m_parts.Values) 1418 foreach (SceneObjectPart part in m_parts.Values)
1314 { 1419 {
1420
1315 if (part == null) 1421 if (part == null)
1316 continue; 1422 continue;
1317 if (part != RootPart) 1423 if (part != RootPart)
1318 part.ObjectFlags = objectflagupdate; 1424 part.ObjectFlags = objectflagupdate;
1319 aggregateScriptEvents |= part.AggregateScriptEvents; 1425 aggregateScriptEvents |= part.AggregateScriptEvents;
1426
1320 } 1427 }
1321 } 1428 }
1429 lockPartsForRead(false);
1322 1430
1323 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); 1431 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
1324 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); 1432 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
@@ -1360,42 +1468,52 @@ namespace OpenSim.Region.Framework.Scenes
1360 /// <param name="m_physicalPrim"></param> 1468 /// <param name="m_physicalPrim"></param>
1361 public void ApplyPhysics(bool m_physicalPrim) 1469 public void ApplyPhysics(bool m_physicalPrim)
1362 { 1470 {
1363 lock (m_parts) 1471 lockPartsForRead(true);
1472
1473 if (m_parts.Count > 1)
1364 { 1474 {
1365 if (m_parts.Count > 1) 1475 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1476 lockPartsForRead(false);
1477 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1478 foreach (SceneObjectPart part in values)
1366 { 1479 {
1367 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); 1480
1368 foreach (SceneObjectPart part in m_parts.Values) 1481 if (part.LocalId != m_rootPart.LocalId)
1369 { 1482 {
1370 if (part.LocalId != m_rootPart.LocalId) 1483 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1371 {
1372 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1373 }
1374 } 1484 }
1375 1485
1376 // Hack to get the physics scene geometries in the right spot
1377 ResetChildPrimPhysicsPositions();
1378 }
1379 else
1380 {
1381 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1382 } 1486 }
1487 // Hack to get the physics scene geometries in the right spot
1488 ResetChildPrimPhysicsPositions();
1489 }
1490 else
1491 {
1492 lockPartsForRead(false);
1493 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1383 } 1494 }
1384 } 1495 }
1385 1496
1386 public void SetOwnerId(UUID userId) 1497 public void SetOwnerId(UUID userId)
1387 { 1498 {
1388 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1499 ForEachPart(delegate(SceneObjectPart part)
1500 {
1501
1502 part.OwnerID = userId;
1503
1504 });
1389 } 1505 }
1390 1506
1391 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1507 public void ForEachPart(Action<SceneObjectPart> whatToDo)
1392 { 1508 {
1393 lock (m_parts) 1509 lockPartsForRead(true);
1510 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1511 lockPartsForRead(false);
1512 foreach (SceneObjectPart part in values)
1394 { 1513 {
1395 foreach (SceneObjectPart part in m_parts.Values) 1514
1396 { 1515 whatToDo(part);
1397 whatToDo(part); 1516
1398 }
1399 } 1517 }
1400 } 1518 }
1401 1519
@@ -1493,10 +1611,11 @@ namespace OpenSim.Region.Framework.Scenes
1493 RootPart.SendFullUpdate( 1611 RootPart.SendFullUpdate(
1494 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1612 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1495 1613
1496 lock (m_parts) 1614 lockPartsForRead(true);
1497 { 1615 {
1498 foreach (SceneObjectPart part in m_parts.Values) 1616 foreach (SceneObjectPart part in m_parts.Values)
1499 { 1617 {
1618
1500 if (part != RootPart) 1619 if (part != RootPart)
1501 part.SendFullUpdate( 1620 part.SendFullUpdate(
1502 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1621 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
@@ -1570,10 +1689,11 @@ namespace OpenSim.Region.Framework.Scenes
1570 1689
1571 List<SceneObjectPart> partList; 1690 List<SceneObjectPart> partList;
1572 1691
1573 lock (m_parts) 1692 lockPartsForRead(true);
1574 { 1693
1575 partList = new List<SceneObjectPart>(m_parts.Values); 1694 partList = new List<SceneObjectPart>(m_parts.Values);
1576 } 1695
1696 lockPartsForRead(false);
1577 1697
1578 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1698 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1579 { 1699 {
@@ -1796,13 +1916,40 @@ namespace OpenSim.Region.Framework.Scenes
1796 } 1916 }
1797 } 1917 }
1798 1918
1919 public void rotLookAt(Quaternion target, float strength, float damping)
1920 {
1921 SceneObjectPart rootpart = m_rootPart;
1922 if (rootpart != null)
1923 {
1924 if (IsAttachment)
1925 {
1926 /*
1927 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
1928 if (avatar != null)
1929 {
1930 Rotate the Av?
1931 } */
1932 }
1933 else
1934 {
1935 if (rootpart.PhysActor != null)
1936 { // APID must be implemented in your physics system for this to function.
1937 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
1938 rootpart.PhysActor.APIDStrength = strength;
1939 rootpart.PhysActor.APIDDamping = damping;
1940 rootpart.PhysActor.APIDActive = true;
1941 }
1942 }
1943 }
1944 }
1945
1799 public void stopLookAt() 1946 public void stopLookAt()
1800 { 1947 {
1801 SceneObjectPart rootpart = m_rootPart; 1948 SceneObjectPart rootpart = m_rootPart;
1802 if (rootpart != null) 1949 if (rootpart != null)
1803 { 1950 {
1804 if (rootpart.PhysActor != null) 1951 if (rootpart.PhysActor != null)
1805 { 1952 { // APID must be implemented in your physics system for this to function.
1806 rootpart.PhysActor.APIDActive = false; 1953 rootpart.PhysActor.APIDActive = false;
1807 } 1954 }
1808 } 1955 }
@@ -1870,10 +2017,11 @@ namespace OpenSim.Region.Framework.Scenes
1870 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2017 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1871 newPart.SetParent(this); 2018 newPart.SetParent(this);
1872 2019
1873 lock (m_parts) 2020 lockPartsForWrite(true);
1874 { 2021 {
1875 m_parts.Add(newPart.UUID, newPart); 2022 m_parts.Add(newPart.UUID, newPart);
1876 } 2023 }
2024 lockPartsForWrite(false);
1877 2025
1878 SetPartAsNonRoot(newPart); 2026 SetPartAsNonRoot(newPart);
1879 2027
@@ -1936,7 +2084,7 @@ namespace OpenSim.Region.Framework.Scenes
1936 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2084 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1937 // return; 2085 // return;
1938 2086
1939 lock (m_parts) 2087 lockPartsForRead(true);
1940 { 2088 {
1941 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2089 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1942 2090
@@ -1956,9 +2104,12 @@ namespace OpenSim.Region.Framework.Scenes
1956 { 2104 {
1957 if (!IsSelected) 2105 if (!IsSelected)
1958 part.UpdateLookAt(); 2106 part.UpdateLookAt();
2107
1959 part.SendScheduledUpdates(); 2108 part.SendScheduledUpdates();
2109
1960 } 2110 }
1961 } 2111 }
2112 lockPartsForRead(false);
1962 } 2113 }
1963 2114
1964 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2115 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -1967,27 +2118,29 @@ namespace OpenSim.Region.Framework.Scenes
1967 2118
1968 RootPart.AddFullUpdateToAvatar(presence); 2119 RootPart.AddFullUpdateToAvatar(presence);
1969 2120
1970 lock (m_parts) 2121 lockPartsForRead(true);
1971 { 2122 {
1972 foreach (SceneObjectPart part in m_parts.Values) 2123 foreach (SceneObjectPart part in m_parts.Values)
1973 { 2124 {
2125
1974 if (part != RootPart) 2126 if (part != RootPart)
1975 part.AddFullUpdateToAvatar(presence); 2127 part.AddFullUpdateToAvatar(presence);
2128
1976 } 2129 }
1977 } 2130 }
2131 lockPartsForRead(false);
1978 } 2132 }
1979 2133
1980 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2134 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
1981 { 2135 {
1982// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2136 lockPartsForRead(true);
1983 2137
1984 lock (m_parts) 2138 foreach (SceneObjectPart part in m_parts.Values)
1985 { 2139 {
1986 foreach (SceneObjectPart part in m_parts.Values) 2140 part.AddTerseUpdateToAvatar(presence);
1987 {
1988 part.AddTerseUpdateToAvatar(presence);
1989 }
1990 } 2141 }
2142
2143 lockPartsForRead(false);
1991 } 2144 }
1992 2145
1993 /// <summary> 2146 /// <summary>
@@ -2000,14 +2153,17 @@ namespace OpenSim.Region.Framework.Scenes
2000 checkAtTargets(); 2153 checkAtTargets();
2001 RootPart.ScheduleFullUpdate(); 2154 RootPart.ScheduleFullUpdate();
2002 2155
2003 lock (m_parts) 2156 lockPartsForRead(true);
2004 { 2157 {
2005 foreach (SceneObjectPart part in m_parts.Values) 2158 foreach (SceneObjectPart part in m_parts.Values)
2006 { 2159 {
2160
2007 if (part != RootPart) 2161 if (part != RootPart)
2008 part.ScheduleFullUpdate(); 2162 part.ScheduleFullUpdate();
2163
2009 } 2164 }
2010 } 2165 }
2166 lockPartsForRead(false);
2011 } 2167 }
2012 2168
2013 /// <summary> 2169 /// <summary>
@@ -2015,15 +2171,14 @@ namespace OpenSim.Region.Framework.Scenes
2015 /// </summary> 2171 /// </summary>
2016 public void ScheduleGroupForTerseUpdate() 2172 public void ScheduleGroupForTerseUpdate()
2017 { 2173 {
2018// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2174 lockPartsForRead(true);
2019 2175
2020 lock (m_parts) 2176 foreach (SceneObjectPart part in m_parts.Values)
2021 { 2177 {
2022 foreach (SceneObjectPart part in m_parts.Values) 2178 part.ScheduleTerseUpdate();
2023 {
2024 part.ScheduleTerseUpdate();
2025 }
2026 } 2179 }
2180
2181 lockPartsForRead(false);
2027 } 2182 }
2028 2183
2029 /// <summary> 2184 /// <summary>
@@ -2038,14 +2193,17 @@ namespace OpenSim.Region.Framework.Scenes
2038 2193
2039 RootPart.SendFullUpdateToAllClients(); 2194 RootPart.SendFullUpdateToAllClients();
2040 2195
2041 lock (m_parts) 2196 lockPartsForRead(true);
2042 { 2197 {
2043 foreach (SceneObjectPart part in m_parts.Values) 2198 foreach (SceneObjectPart part in m_parts.Values)
2044 { 2199 {
2200
2045 if (part != RootPart) 2201 if (part != RootPart)
2046 part.SendFullUpdateToAllClients(); 2202 part.SendFullUpdateToAllClients();
2203
2047 } 2204 }
2048 } 2205 }
2206 lockPartsForRead(false);
2049 } 2207 }
2050 2208
2051 /// <summary> 2209 /// <summary>
@@ -2077,14 +2235,15 @@ namespace OpenSim.Region.Framework.Scenes
2077 { 2235 {
2078 if (IsDeleted) 2236 if (IsDeleted)
2079 return; 2237 return;
2080 2238
2081 lock (m_parts) 2239 lockPartsForRead(true);
2082 { 2240 {
2083 foreach (SceneObjectPart part in m_parts.Values) 2241 foreach (SceneObjectPart part in m_parts.Values)
2084 { 2242 {
2085 part.SendTerseUpdateToAllClients(); 2243 part.SendTerseUpdateToAllClients();
2086 } 2244 }
2087 } 2245 }
2246 lockPartsForRead(false);
2088 } 2247 }
2089 2248
2090 #endregion 2249 #endregion
@@ -2098,16 +2257,18 @@ namespace OpenSim.Region.Framework.Scenes
2098 /// <returns>null if no child part with that linknum or child part</returns> 2257 /// <returns>null if no child part with that linknum or child part</returns>
2099 public SceneObjectPart GetLinkNumPart(int linknum) 2258 public SceneObjectPart GetLinkNumPart(int linknum)
2100 { 2259 {
2101 lock (m_parts) 2260 lockPartsForRead(true);
2102 { 2261 {
2103 foreach (SceneObjectPart part in m_parts.Values) 2262 foreach (SceneObjectPart part in m_parts.Values)
2104 { 2263 {
2105 if (part.LinkNum == linknum) 2264 if (part.LinkNum == linknum)
2106 { 2265 {
2266 lockPartsForRead(false);
2107 return part; 2267 return part;
2108 } 2268 }
2109 } 2269 }
2110 } 2270 }
2271 lockPartsForRead(false);
2111 2272
2112 return null; 2273 return null;
2113 } 2274 }
@@ -2135,17 +2296,19 @@ namespace OpenSim.Region.Framework.Scenes
2135 public SceneObjectPart GetChildPart(uint localID) 2296 public SceneObjectPart GetChildPart(uint localID)
2136 { 2297 {
2137 //m_log.DebugFormat("Entered looking for {0}", localID); 2298 //m_log.DebugFormat("Entered looking for {0}", localID);
2138 lock (m_parts) 2299 lockPartsForRead(true);
2139 { 2300 {
2140 foreach (SceneObjectPart part in m_parts.Values) 2301 foreach (SceneObjectPart part in m_parts.Values)
2141 { 2302 {
2142 //m_log.DebugFormat("Found {0}", part.LocalId); 2303 //m_log.DebugFormat("Found {0}", part.LocalId);
2143 if (part.LocalId == localID) 2304 if (part.LocalId == localID)
2144 { 2305 {
2306 lockPartsForRead(false);
2145 return part; 2307 return part;
2146 } 2308 }
2147 } 2309 }
2148 } 2310 }
2311 lockPartsForRead(false);
2149 2312
2150 return null; 2313 return null;
2151 } 2314 }
@@ -2175,17 +2338,19 @@ namespace OpenSim.Region.Framework.Scenes
2175 public bool HasChildPrim(uint localID) 2338 public bool HasChildPrim(uint localID)
2176 { 2339 {
2177 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2340 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2178 lock (m_parts) 2341 lockPartsForRead(true);
2179 { 2342 {
2180 foreach (SceneObjectPart part in m_parts.Values) 2343 foreach (SceneObjectPart part in m_parts.Values)
2181 { 2344 {
2182 //m_log.DebugFormat("Found {0}", part.LocalId); 2345 //m_log.DebugFormat("Found {0}", part.LocalId);
2183 if (part.LocalId == localID) 2346 if (part.LocalId == localID)
2184 { 2347 {
2348 lockPartsForRead(false);
2185 return true; 2349 return true;
2186 } 2350 }
2187 } 2351 }
2188 } 2352 }
2353 lockPartsForRead(false);
2189 2354
2190 return false; 2355 return false;
2191 } 2356 }
@@ -2235,53 +2400,57 @@ namespace OpenSim.Region.Framework.Scenes
2235 if (m_rootPart.LinkNum == 0) 2400 if (m_rootPart.LinkNum == 0)
2236 m_rootPart.LinkNum = 1; 2401 m_rootPart.LinkNum = 1;
2237 2402
2238 lock (m_parts) 2403 lockPartsForWrite(true);
2239 { 2404
2240 m_parts.Add(linkPart.UUID, linkPart); 2405 m_parts.Add(linkPart.UUID, linkPart);
2406
2407 lockPartsForWrite(false);
2241 2408
2242 // Insert in terms of link numbers, the new links 2409 // Insert in terms of link numbers, the new links
2243 // before the current ones (with the exception of 2410 // before the current ones (with the exception of
2244 // the root prim. Shuffle the old ones up 2411 // the root prim. Shuffle the old ones up
2245 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2412 lockPartsForRead(true);
2413 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2414 {
2415 if (kvp.Value.LinkNum != 1)
2246 { 2416 {
2247 if (kvp.Value.LinkNum != 1) 2417 // Don't update root prim link number
2248 { 2418 kvp.Value.LinkNum += objectGroup.PrimCount;
2249 // Don't update root prim link number
2250 kvp.Value.LinkNum += objectGroup.PrimCount;
2251 }
2252 } 2419 }
2420 }
2421 lockPartsForRead(false);
2253 2422
2254 linkPart.LinkNum = 2; 2423 linkPart.LinkNum = 2;
2255 2424
2256 linkPart.SetParent(this); 2425 linkPart.SetParent(this);
2257 linkPart.AddFlag(PrimFlags.CreateSelected); 2426 linkPart.AddFlag(PrimFlags.CreateSelected);
2258 2427
2259 //if (linkPart.PhysActor != null) 2428 //if (linkPart.PhysActor != null)
2260 //{ 2429 //{
2261 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2430 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2262 2431
2263 //linkPart.PhysActor = null; 2432 //linkPart.PhysActor = null;
2264 //} 2433 //}
2265 2434
2266 //TODO: rest of parts 2435 //TODO: rest of parts
2267 int linkNum = 3; 2436 int linkNum = 3;
2268 foreach (SceneObjectPart part in objectGroup.Children.Values) 2437 foreach (SceneObjectPart part in objectGroup.Children.Values)
2438 {
2439 if (part.UUID != objectGroup.m_rootPart.UUID)
2269 { 2440 {
2270 if (part.UUID != objectGroup.m_rootPart.UUID) 2441 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2271 {
2272 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2273 }
2274 part.ClearUndoState();
2275 } 2442 }
2443 part.ClearUndoState();
2276 } 2444 }
2277 2445
2278 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2446 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2279 objectGroup.m_isDeleted = true; 2447 objectGroup.m_isDeleted = true;
2448
2449 objectGroup.lockPartsForWrite(true);
2280 2450
2281 lock (objectGroup.m_parts) 2451 objectGroup.m_parts.Clear();
2282 { 2452
2283 objectGroup.m_parts.Clear(); 2453 objectGroup.lockPartsForWrite(false);
2284 }
2285 2454
2286 // Can't do this yet since backup still makes use of the root part without any synchronization 2455 // Can't do this yet since backup still makes use of the root part without any synchronization
2287// objectGroup.m_rootPart = null; 2456// objectGroup.m_rootPart = null;
@@ -2351,11 +2520,12 @@ namespace OpenSim.Region.Framework.Scenes
2351 Quaternion worldRot = linkPart.GetWorldRotation(); 2520 Quaternion worldRot = linkPart.GetWorldRotation();
2352 2521
2353 // Remove the part from this object 2522 // Remove the part from this object
2354 lock (m_parts) 2523 lockPartsForWrite(true);
2355 { 2524 {
2356 m_parts.Remove(linkPart.UUID); 2525 m_parts.Remove(linkPart.UUID);
2357 } 2526 }
2358 2527 lockPartsForWrite(false);
2528 lockPartsForRead(true);
2359 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2529 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2360 RootPart.LinkNum = 0; 2530 RootPart.LinkNum = 0;
2361 else 2531 else
@@ -2366,6 +2536,7 @@ namespace OpenSim.Region.Framework.Scenes
2366 p.LinkNum--; 2536 p.LinkNum--;
2367 } 2537 }
2368 } 2538 }
2539 lockPartsForRead(false);
2369 2540
2370 linkPart.ParentID = 0; 2541 linkPart.ParentID = 0;
2371 linkPart.LinkNum = 0; 2542 linkPart.LinkNum = 0;
@@ -2687,9 +2858,12 @@ namespace OpenSim.Region.Framework.Scenes
2687 2858
2688 if (selectionPart != null) 2859 if (selectionPart != null)
2689 { 2860 {
2690 lock (m_parts) 2861 lockPartsForRead(true);
2862 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2863 lockPartsForRead(false);
2864 foreach (SceneObjectPart part in parts)
2691 { 2865 {
2692 foreach (SceneObjectPart part in m_parts.Values) 2866 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2693 { 2867 {
2694 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2868 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2695 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2869 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2699,12 +2873,13 @@ namespace OpenSim.Region.Framework.Scenes
2699 break; 2873 break;
2700 } 2874 }
2701 } 2875 }
2876 }
2702 2877
2703 foreach (SceneObjectPart part in m_parts.Values) 2878 foreach (SceneObjectPart part in parts)
2704 { 2879 {
2705 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2880 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2706 }
2707 } 2881 }
2882
2708 } 2883 }
2709 } 2884 }
2710 2885
@@ -2790,11 +2965,9 @@ namespace OpenSim.Region.Framework.Scenes
2790 scale.Y = m_scene.m_maxNonphys; 2965 scale.Y = m_scene.m_maxNonphys;
2791 if (scale.Z > m_scene.m_maxNonphys) 2966 if (scale.Z > m_scene.m_maxNonphys)
2792 scale.Z = m_scene.m_maxNonphys; 2967 scale.Z = m_scene.m_maxNonphys;
2793
2794 SceneObjectPart part = GetChildPart(localID); 2968 SceneObjectPart part = GetChildPart(localID);
2795 if (part != null) 2969 if (part != null)
2796 { 2970 {
2797 part.Resize(scale);
2798 if (part.PhysActor != null) 2971 if (part.PhysActor != null)
2799 { 2972 {
2800 if (part.PhysActor.IsPhysical) 2973 if (part.PhysActor.IsPhysical)
@@ -2809,7 +2982,7 @@ namespace OpenSim.Region.Framework.Scenes
2809 part.PhysActor.Size = scale; 2982 part.PhysActor.Size = scale;
2810 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 2983 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2811 } 2984 }
2812 //if (part.UUID != m_rootPart.UUID) 2985 part.Resize(scale);
2813 2986
2814 HasGroupChanged = true; 2987 HasGroupChanged = true;
2815 ScheduleGroupForFullUpdate(); 2988 ScheduleGroupForFullUpdate();
@@ -2851,73 +3024,71 @@ namespace OpenSim.Region.Framework.Scenes
2851 float y = (scale.Y / part.Scale.Y); 3024 float y = (scale.Y / part.Scale.Y);
2852 float z = (scale.Z / part.Scale.Z); 3025 float z = (scale.Z / part.Scale.Z);
2853 3026
2854 lock (m_parts) 3027 lockPartsForRead(true);
3028 if (x > 1.0f || y > 1.0f || z > 1.0f)
2855 { 3029 {
2856 if (x > 1.0f || y > 1.0f || z > 1.0f) 3030 foreach (SceneObjectPart obPart in m_parts.Values)
2857 { 3031 {
2858 foreach (SceneObjectPart obPart in m_parts.Values) 3032 if (obPart.UUID != m_rootPart.UUID)
2859 { 3033 {
2860 if (obPart.UUID != m_rootPart.UUID) 3034 Vector3 oldSize = new Vector3(obPart.Scale);
2861 { 3035 obPart.IgnoreUndoUpdate = true;
2862 obPart.IgnoreUndoUpdate = true;
2863 Vector3 oldSize = new Vector3(obPart.Scale);
2864 3036
2865 float f = 1.0f; 3037 float f = 1.0f;
2866 float a = 1.0f; 3038 float a = 1.0f;
2867 3039
2868 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3040 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3041 {
3042 if (oldSize.X*x > m_scene.m_maxPhys)
2869 { 3043 {
2870 if (oldSize.X*x > m_scene.m_maxPhys) 3044 f = m_scene.m_maxPhys / oldSize.X;
2871 { 3045 a = f / x;
2872 f = m_scene.m_maxPhys / oldSize.X; 3046 x *= a;
2873 a = f / x; 3047 y *= a;
2874 x *= a; 3048 z *= a;
2875 y *= a;
2876 z *= a;
2877 }
2878 if (oldSize.Y*y > m_scene.m_maxPhys)
2879 {
2880 f = m_scene.m_maxPhys / oldSize.Y;
2881 a = f / y;
2882 x *= a;
2883 y *= a;
2884 z *= a;
2885 }
2886 if (oldSize.Z*z > m_scene.m_maxPhys)
2887 {
2888 f = m_scene.m_maxPhys / oldSize.Z;
2889 a = f / z;
2890 x *= a;
2891 y *= a;
2892 z *= a;
2893 }
2894 } 3049 }
2895 else 3050 if (oldSize.Y*y > m_scene.m_maxPhys)
3051 {
3052 f = m_scene.m_maxPhys / oldSize.Y;
3053 a = f / y;
3054 x *= a;
3055 y *= a;
3056 z *= a;
3057 }
3058 if (oldSize.Z*z > m_scene.m_maxPhys)
3059 {
3060 f = m_scene.m_maxPhys / oldSize.Z;
3061 a = f / z;
3062 x *= a;
3063 y *= a;
3064 z *= a;
3065 }
3066 }
3067 else
3068 {
3069 if (oldSize.X*x > m_scene.m_maxNonphys)
3070 {
3071 f = m_scene.m_maxNonphys / oldSize.X;
3072 a = f / x;
3073 x *= a;
3074 y *= a;
3075 z *= a;
3076 }
3077 if (oldSize.Y*y > m_scene.m_maxNonphys)
2896 { 3078 {
2897 if (oldSize.X*x > m_scene.m_maxNonphys) 3079 f = m_scene.m_maxNonphys / oldSize.Y;
2898 { 3080 a = f / y;
2899 f = m_scene.m_maxNonphys / oldSize.X; 3081 x *= a;
2900 a = f / x; 3082 y *= a;
2901 x *= a; 3083 z *= a;
2902 y *= a; 3084 }
2903 z *= a; 3085 if (oldSize.Z*z > m_scene.m_maxNonphys)
2904 } 3086 {
2905 if (oldSize.Y*y > m_scene.m_maxNonphys) 3087 f = m_scene.m_maxNonphys / oldSize.Z;
2906 { 3088 a = f / z;
2907 f = m_scene.m_maxNonphys / oldSize.Y; 3089 x *= a;
2908 a = f / y; 3090 y *= a;
2909 x *= a; 3091 z *= a;
2910 y *= a;
2911 z *= a;
2912 }
2913 if (oldSize.Z*z > m_scene.m_maxNonphys)
2914 {
2915 f = m_scene.m_maxNonphys / oldSize.Z;
2916 a = f / z;
2917 x *= a;
2918 y *= a;
2919 z *= a;
2920 }
2921 } 3092 }
2922 obPart.IgnoreUndoUpdate = false; 3093 obPart.IgnoreUndoUpdate = false;
2923 obPart.StoreUndoState(); 3094 obPart.StoreUndoState();
@@ -2925,6 +3096,7 @@ namespace OpenSim.Region.Framework.Scenes
2925 } 3096 }
2926 } 3097 }
2927 } 3098 }
3099 lockPartsForRead(false);
2928 3100
2929 Vector3 prevScale = part.Scale; 3101 Vector3 prevScale = part.Scale;
2930 prevScale.X *= x; 3102 prevScale.X *= x;
@@ -2932,7 +3104,7 @@ namespace OpenSim.Region.Framework.Scenes
2932 prevScale.Z *= z; 3104 prevScale.Z *= z;
2933 part.Resize(prevScale); 3105 part.Resize(prevScale);
2934 3106
2935 lock (m_parts) 3107 lockPartsForRead(true);
2936 { 3108 {
2937 foreach (SceneObjectPart obPart in m_parts.Values) 3109 foreach (SceneObjectPart obPart in m_parts.Values)
2938 { 3110 {
@@ -2954,6 +3126,7 @@ namespace OpenSim.Region.Framework.Scenes
2954 obPart.StoreUndoState(); 3126 obPart.StoreUndoState();
2955 } 3127 }
2956 } 3128 }
3129 lockPartsForRead(false);
2957 3130
2958 if (part.PhysActor != null) 3131 if (part.PhysActor != null)
2959 { 3132 {
@@ -3056,7 +3229,7 @@ namespace OpenSim.Region.Framework.Scenes
3056 axDiff *= Quaternion.Inverse(partRotation); 3229 axDiff *= Quaternion.Inverse(partRotation);
3057 diff = axDiff; 3230 diff = axDiff;
3058 3231
3059 lock (m_parts) 3232 lockPartsForRead(true);
3060 { 3233 {
3061 foreach (SceneObjectPart obPart in m_parts.Values) 3234 foreach (SceneObjectPart obPart in m_parts.Values)
3062 { 3235 {
@@ -3066,6 +3239,7 @@ namespace OpenSim.Region.Framework.Scenes
3066 } 3239 }
3067 } 3240 }
3068 } 3241 }
3242 lockPartsForRead(false);
3069 3243
3070 AbsolutePosition = newPos; 3244 AbsolutePosition = newPos;
3071 3245
@@ -3199,25 +3373,25 @@ namespace OpenSim.Region.Framework.Scenes
3199 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3373 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3200 } 3374 }
3201 3375
3202 lock (m_parts) 3376 lockPartsForRead(true);
3377
3378 foreach (SceneObjectPart prim in m_parts.Values)
3203 { 3379 {
3204 foreach (SceneObjectPart prim in m_parts.Values) 3380 if (prim.UUID != m_rootPart.UUID)
3205 { 3381 {
3206 if (prim.UUID != m_rootPart.UUID) 3382 prim.IgnoreUndoUpdate = true;
3207 { 3383 Vector3 axPos = prim.OffsetPosition;
3208 prim.IgnoreUndoUpdate = true; 3384 axPos *= oldParentRot;
3209 Vector3 axPos = prim.OffsetPosition; 3385 axPos *= Quaternion.Inverse(axRot);
3210 axPos *= oldParentRot; 3386 prim.OffsetPosition = axPos;
3211 axPos *= Quaternion.Inverse(axRot); 3387 Quaternion primsRot = prim.RotationOffset;
3212 prim.OffsetPosition = axPos; 3388 Quaternion newRot = primsRot * oldParentRot;
3213 Quaternion primsRot = prim.RotationOffset; 3389 newRot *= Quaternion.Inverse(axRot);
3214 Quaternion newRot = primsRot * oldParentRot; 3390 prim.RotationOffset = newRot;
3215 newRot *= Quaternion.Inverse(axRot); 3391 prim.ScheduleTerseUpdate();
3216 prim.RotationOffset = newRot;
3217 prim.ScheduleTerseUpdate();
3218 }
3219 } 3392 }
3220 } 3393 }
3394
3221 foreach (SceneObjectPart childpart in Children.Values) 3395 foreach (SceneObjectPart childpart in Children.Values)
3222 { 3396 {
3223 if (childpart != m_rootPart) 3397 if (childpart != m_rootPart)
@@ -3226,6 +3400,9 @@ namespace OpenSim.Region.Framework.Scenes
3226 childpart.StoreUndoState(); 3400 childpart.StoreUndoState();
3227 } 3401 }
3228 } 3402 }
3403
3404 lockPartsForRead(false);
3405
3229 m_rootPart.ScheduleTerseUpdate(); 3406 m_rootPart.ScheduleTerseUpdate();
3230 } 3407 }
3231 3408
@@ -3347,7 +3524,7 @@ namespace OpenSim.Region.Framework.Scenes
3347 if (atTargets.Count > 0) 3524 if (atTargets.Count > 0)
3348 { 3525 {
3349 uint[] localids = new uint[0]; 3526 uint[] localids = new uint[0];
3350 lock (m_parts) 3527 lockPartsForRead(true);
3351 { 3528 {
3352 localids = new uint[m_parts.Count]; 3529 localids = new uint[m_parts.Count];
3353 int cntr = 0; 3530 int cntr = 0;
@@ -3357,6 +3534,7 @@ namespace OpenSim.Region.Framework.Scenes
3357 cntr++; 3534 cntr++;
3358 } 3535 }
3359 } 3536 }
3537 lockPartsForRead(false);
3360 3538
3361 for (int ctr = 0; ctr < localids.Length; ctr++) 3539 for (int ctr = 0; ctr < localids.Length; ctr++)
3362 { 3540 {
@@ -3375,7 +3553,7 @@ namespace OpenSim.Region.Framework.Scenes
3375 { 3553 {
3376 //trigger not_at_target 3554 //trigger not_at_target
3377 uint[] localids = new uint[0]; 3555 uint[] localids = new uint[0];
3378 lock (m_parts) 3556 lockPartsForRead(true);
3379 { 3557 {
3380 localids = new uint[m_parts.Count]; 3558 localids = new uint[m_parts.Count];
3381 int cntr = 0; 3559 int cntr = 0;
@@ -3385,7 +3563,8 @@ namespace OpenSim.Region.Framework.Scenes
3385 cntr++; 3563 cntr++;
3386 } 3564 }
3387 } 3565 }
3388 3566 lockPartsForRead(false);
3567
3389 for (int ctr = 0; ctr < localids.Length; ctr++) 3568 for (int ctr = 0; ctr < localids.Length; ctr++)
3390 { 3569 {
3391 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3570 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3477,19 +3656,20 @@ namespace OpenSim.Region.Framework.Scenes
3477 public float GetMass() 3656 public float GetMass()
3478 { 3657 {
3479 float retmass = 0f; 3658 float retmass = 0f;
3480 lock (m_parts) 3659 lockPartsForRead(true);
3481 { 3660 {
3482 foreach (SceneObjectPart part in m_parts.Values) 3661 foreach (SceneObjectPart part in m_parts.Values)
3483 { 3662 {
3484 retmass += part.GetMass(); 3663 retmass += part.GetMass();
3485 } 3664 }
3486 } 3665 }
3666 lockPartsForRead(false);
3487 return retmass; 3667 return retmass;
3488 } 3668 }
3489 3669
3490 public void CheckSculptAndLoad() 3670 public void CheckSculptAndLoad()
3491 { 3671 {
3492 lock (m_parts) 3672 lockPartsForRead(true);
3493 { 3673 {
3494 if (!IsDeleted) 3674 if (!IsDeleted)
3495 { 3675 {
@@ -3514,6 +3694,7 @@ namespace OpenSim.Region.Framework.Scenes
3514 } 3694 }
3515 } 3695 }
3516 } 3696 }
3697 lockPartsForRead(false);
3517 } 3698 }
3518 3699
3519 protected void AssetReceived(string id, Object sender, AssetBase asset) 3700 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3534,7 +3715,7 @@ namespace OpenSim.Region.Framework.Scenes
3534 /// <param name="client"></param> 3715 /// <param name="client"></param>
3535 public void SetGroup(UUID GroupID, IClientAPI client) 3716 public void SetGroup(UUID GroupID, IClientAPI client)
3536 { 3717 {
3537 lock (m_parts) 3718 lockPartsForRead(true);
3538 { 3719 {
3539 foreach (SceneObjectPart part in m_parts.Values) 3720 foreach (SceneObjectPart part in m_parts.Values)
3540 { 3721 {
@@ -3544,6 +3725,7 @@ namespace OpenSim.Region.Framework.Scenes
3544 3725
3545 HasGroupChanged = true; 3726 HasGroupChanged = true;
3546 } 3727 }
3728 lockPartsForRead(false);
3547 3729
3548 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3730 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
3549 // for the same object with very different properties. The caller must schedule the update. 3731 // for the same object with very different properties. The caller must schedule the update.
@@ -3565,11 +3747,12 @@ namespace OpenSim.Region.Framework.Scenes
3565 3747
3566 public void SetAttachmentPoint(byte point) 3748 public void SetAttachmentPoint(byte point)
3567 { 3749 {
3568 lock (m_parts) 3750 lockPartsForRead(true);
3569 { 3751 {
3570 foreach (SceneObjectPart part in m_parts.Values) 3752 foreach (SceneObjectPart part in m_parts.Values)
3571 part.SetAttachmentPoint(point); 3753 part.SetAttachmentPoint(point);
3572 } 3754 }
3755 lockPartsForRead(false);
3573 } 3756 }
3574 3757
3575 #region ISceneObject 3758 #region ISceneObject
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 46eadee..4b2641c 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 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) 1211 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
@@ -1934,12 +1945,17 @@ namespace OpenSim.Region.Framework.Scenes
1934 public Vector3 GetWorldPosition() 1945 public Vector3 GetWorldPosition()
1935 { 1946 {
1936 Quaternion parentRot = ParentGroup.RootPart.RotationOffset; 1947 Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
1937
1938 Vector3 axPos = OffsetPosition; 1948 Vector3 axPos = OffsetPosition;
1939
1940 axPos *= parentRot; 1949 axPos *= parentRot;
1941 Vector3 translationOffsetPosition = axPos; 1950 Vector3 translationOffsetPosition = axPos;
1942 return GroupPosition + translationOffsetPosition; 1951 if(_parentID == 0)
1952 {
1953 return GroupPosition;
1954 }
1955 else
1956 {
1957 return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position
1958 }
1943 } 1959 }
1944 1960
1945 /// <summary> 1961 /// <summary>
@@ -1950,7 +1966,7 @@ namespace OpenSim.Region.Framework.Scenes
1950 { 1966 {
1951 Quaternion newRot; 1967 Quaternion newRot;
1952 1968
1953 if (this.LinkNum == 0) 1969 if (this.LinkNum < 2) //KF Single or root prim
1954 { 1970 {
1955 newRot = RotationOffset; 1971 newRot = RotationOffset;
1956 } 1972 }
@@ -2596,17 +2612,18 @@ namespace OpenSim.Region.Framework.Scenes
2596 //Trys to fetch sound id from prim's inventory. 2612 //Trys to fetch sound id from prim's inventory.
2597 //Prim's inventory doesn't support non script items yet 2613 //Prim's inventory doesn't support non script items yet
2598 2614
2599 lock (TaskInventory) 2615 TaskInventory.LockItemsForRead(true);
2616
2617 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2600 { 2618 {
2601 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2619 if (item.Value.Name == sound)
2602 { 2620 {
2603 if (item.Value.Name == sound) 2621 soundID = item.Value.ItemID;
2604 { 2622 break;
2605 soundID = item.Value.ItemID;
2606 break;
2607 }
2608 } 2623 }
2609 } 2624 }
2625
2626 TaskInventory.LockItemsForRead(false);
2610 } 2627 }
2611 2628
2612 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp) 2629 m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
@@ -2675,38 +2692,7 @@ namespace OpenSim.Region.Framework.Scenes
2675 2692
2676 public void RotLookAt(Quaternion target, float strength, float damping) 2693 public void RotLookAt(Quaternion target, float strength, float damping)
2677 { 2694 {
2678 rotLookAt(target, strength, damping); 2695 m_parentGroup.rotLookAt(target, strength, damping); // This calls method in SceneObjectGroup.
2679 }
2680
2681 public void rotLookAt(Quaternion target, float strength, float damping)
2682 {
2683 if (IsAttachment)
2684 {
2685 /*
2686 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2687 if (avatar != null)
2688 {
2689 Rotate the Av?
2690 } */
2691 }
2692 else
2693 {
2694 APIDDamp = damping;
2695 APIDStrength = strength;
2696 APIDTarget = target;
2697 }
2698 }
2699
2700 public void startLookAt(Quaternion rot, float damp, float strength)
2701 {
2702 APIDDamp = damp;
2703 APIDStrength = strength;
2704 APIDTarget = rot;
2705 }
2706
2707 public void stopLookAt()
2708 {
2709 APIDTarget = Quaternion.Identity;
2710 } 2696 }
2711 2697
2712 /// <summary> 2698 /// <summary>
@@ -2939,8 +2925,8 @@ namespace OpenSim.Region.Framework.Scenes
2939 { 2925 {
2940 const float ROTATION_TOLERANCE = 0.01f; 2926 const float ROTATION_TOLERANCE = 0.01f;
2941 const float VELOCITY_TOLERANCE = 0.001f; 2927 const float VELOCITY_TOLERANCE = 0.001f;
2942 const float POSITION_TOLERANCE = 0.05f; 2928 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2943 const int TIME_MS_TOLERANCE = 3000; 2929 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2944 2930
2945 if (m_updateFlag == 1) 2931 if (m_updateFlag == 1)
2946 { 2932 {
@@ -2954,7 +2940,7 @@ namespace OpenSim.Region.Framework.Scenes
2954 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2940 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2955 { 2941 {
2956 AddTerseUpdateToAllAvatars(); 2942 AddTerseUpdateToAllAvatars();
2957 ClearUpdateSchedule(); 2943
2958 2944
2959 // This causes the Scene to 'poll' physical objects every couple of frames 2945 // This causes the Scene to 'poll' physical objects every couple of frames
2960 // bad, so it's been replaced by an event driven method. 2946 // bad, so it's been replaced by an event driven method.
@@ -2972,16 +2958,18 @@ namespace OpenSim.Region.Framework.Scenes
2972 m_lastAngularVelocity = AngularVelocity; 2958 m_lastAngularVelocity = AngularVelocity;
2973 m_lastTerseSent = Environment.TickCount; 2959 m_lastTerseSent = Environment.TickCount;
2974 } 2960 }
2961 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
2962 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
2975 } 2963 }
2976 else 2964 else
2977 { 2965 {
2978 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes 2966 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
2979 { 2967 {
2980 AddFullUpdateToAllAvatars(); 2968 AddFullUpdateToAllAvatars();
2981 ClearUpdateSchedule(); 2969 m_updateFlag = 0; //Same here
2982 } 2970 }
2983 } 2971 }
2984 ClearUpdateSchedule(); 2972 m_updateFlag = 0;
2985 } 2973 }
2986 2974
2987 /// <summary> 2975 /// <summary>
@@ -3008,17 +2996,16 @@ namespace OpenSim.Region.Framework.Scenes
3008 if (!UUID.TryParse(sound, out soundID)) 2996 if (!UUID.TryParse(sound, out soundID))
3009 { 2997 {
3010 // search sound file from inventory 2998 // search sound file from inventory
3011 lock (TaskInventory) 2999 TaskInventory.LockItemsForRead(true);
3000 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3012 { 3001 {
3013 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3002 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3014 { 3003 {
3015 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3004 soundID = item.Value.ItemID;
3016 { 3005 break;
3017 soundID = item.Value.ItemID;
3018 break;
3019 }
3020 } 3006 }
3021 } 3007 }
3008 TaskInventory.LockItemsForRead(false);
3022 } 3009 }
3023 3010
3024 if (soundID == UUID.Zero) 3011 if (soundID == UUID.Zero)
@@ -3453,7 +3440,7 @@ namespace OpenSim.Region.Framework.Scenes
3453 3440
3454 public void StopLookAt() 3441 public void StopLookAt()
3455 { 3442 {
3456 m_parentGroup.stopLookAt(); 3443 m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup.
3457 3444
3458 m_parentGroup.ScheduleGroupForTerseUpdate(); 3445 m_parentGroup.ScheduleGroupForTerseUpdate();
3459 } 3446 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 77bf6fe..836622d 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -81,7 +81,9 @@ namespace OpenSim.Region.Framework.Scenes
81 /// </value> 81 /// </value>
82 protected internal TaskInventoryDictionary Items 82 protected internal TaskInventoryDictionary Items
83 { 83 {
84 get { return m_items; } 84 get {
85 return m_items;
86 }
85 set 87 set
86 { 88 {
87 m_items = value; 89 m_items = value;
@@ -117,22 +119,25 @@ namespace OpenSim.Region.Framework.Scenes
117 /// <param name="linkNum">Link number for the part</param> 119 /// <param name="linkNum">Link number for the part</param>
118 public void ResetInventoryIDs() 120 public void ResetInventoryIDs()
119 { 121 {
120 lock (Items) 122 m_items.LockItemsForWrite(true);
123
124 if (0 == Items.Count)
121 { 125 {
122 if (0 == Items.Count) 126 m_items.LockItemsForWrite(false);
123 return; 127 return;
128 }
124 129
125 HasInventoryChanged = true; 130 HasInventoryChanged = true;
126 m_part.ParentGroup.HasGroupChanged = true; 131 m_part.ParentGroup.HasGroupChanged = true;
127 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 132 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
128 Items.Clear(); 133 Items.Clear();
129 134
130 foreach (TaskInventoryItem item in items) 135 foreach (TaskInventoryItem item in items)
131 { 136 {
132 item.ResetIDs(m_part.UUID); 137 item.ResetIDs(m_part.UUID);
133 Items.Add(item.ItemID, item); 138 Items.Add(item.ItemID, item);
134 }
135 } 139 }
140 m_items.LockItemsForWrite(false);
136 } 141 }
137 142
138 /// <summary> 143 /// <summary>
@@ -141,25 +146,25 @@ namespace OpenSim.Region.Framework.Scenes
141 /// <param name="ownerId"></param> 146 /// <param name="ownerId"></param>
142 public void ChangeInventoryOwner(UUID ownerId) 147 public void ChangeInventoryOwner(UUID ownerId)
143 { 148 {
144 lock (Items) 149 m_items.LockItemsForWrite(true);
150 if (0 == Items.Count)
145 { 151 {
146 if (0 == Items.Count) 152 m_items.LockItemsForWrite(false);
147 { 153 return;
148 return; 154 }
149 }
150 155
151 HasInventoryChanged = true; 156 HasInventoryChanged = true;
152 m_part.ParentGroup.HasGroupChanged = true; 157 m_part.ParentGroup.HasGroupChanged = true;
153 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 158 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
154 foreach (TaskInventoryItem item in items) 159 foreach (TaskInventoryItem item in items)
160 {
161 if (ownerId != item.OwnerID)
155 { 162 {
156 if (ownerId != item.OwnerID) 163 item.LastOwnerID = item.OwnerID;
157 { 164 item.OwnerID = ownerId;
158 item.LastOwnerID = item.OwnerID;
159 item.OwnerID = ownerId;
160 }
161 } 165 }
162 } 166 }
167 m_items.LockItemsForWrite(false);
163 } 168 }
164 169
165 /// <summary> 170 /// <summary>
@@ -168,24 +173,24 @@ namespace OpenSim.Region.Framework.Scenes
168 /// <param name="groupID"></param> 173 /// <param name="groupID"></param>
169 public void ChangeInventoryGroup(UUID groupID) 174 public void ChangeInventoryGroup(UUID groupID)
170 { 175 {
171 lock (Items) 176 m_items.LockItemsForWrite(true);
177 if (0 == Items.Count)
172 { 178 {
173 if (0 == Items.Count) 179 m_items.LockItemsForWrite(false);
174 { 180 return;
175 return; 181 }
176 }
177 182
178 HasInventoryChanged = true; 183 HasInventoryChanged = true;
179 m_part.ParentGroup.HasGroupChanged = true; 184 m_part.ParentGroup.HasGroupChanged = true;
180 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 185 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
181 foreach (TaskInventoryItem item in items) 186 foreach (TaskInventoryItem item in items)
187 {
188 if (groupID != item.GroupID)
182 { 189 {
183 if (groupID != item.GroupID) 190 item.GroupID = groupID;
184 {
185 item.GroupID = groupID;
186 }
187 } 191 }
188 } 192 }
193 m_items.LockItemsForWrite(false);
189 } 194 }
190 195
191 /// <summary> 196 /// <summary>
@@ -193,14 +198,14 @@ namespace OpenSim.Region.Framework.Scenes
193 /// </summary> 198 /// </summary>
194 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 199 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
195 { 200 {
196 lock (m_items) 201 Items.LockItemsForRead(true);
202 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
203 Items.LockItemsForRead(false);
204 foreach (TaskInventoryItem item in items)
197 { 205 {
198 foreach (TaskInventoryItem item in Items.Values) 206 if ((int)InventoryType.LSL == item.InvType)
199 { 207 {
200 if ((int)InventoryType.LSL == item.InvType) 208 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
201 {
202 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
203 }
204 } 209 }
205 } 210 }
206 } 211 }
@@ -235,16 +240,20 @@ namespace OpenSim.Region.Framework.Scenes
235 /// </param> 240 /// </param>
236 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 241 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
237 { 242 {
238 lock (Items) 243 Items.LockItemsForRead(true);
244 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
245 Items.LockItemsForRead(false);
246
247 foreach (TaskInventoryItem item in items)
239 { 248 {
240 foreach (TaskInventoryItem item in Items.Values) 249 if ((int)InventoryType.LSL == item.InvType)
241 { 250 {
242 if ((int)InventoryType.LSL == item.InvType) 251 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
243 { 252 m_part.RemoveScriptEvents(item.ItemID);
244 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
245 }
246 } 253 }
247 } 254 }
255
256
248 } 257 }
249 258
250 /// <summary> 259 /// <summary>
@@ -269,12 +278,10 @@ namespace OpenSim.Region.Framework.Scenes
269 if (stateSource == 1 && // Prim crossing 278 if (stateSource == 1 && // Prim crossing
270 m_part.ParentGroup.Scene.m_trustBinaries) 279 m_part.ParentGroup.Scene.m_trustBinaries)
271 { 280 {
272 lock (m_items) 281 m_items.LockItemsForWrite(true);
273 { 282 m_items[item.ItemID].PermsMask = 0;
274 m_items[item.ItemID].PermsMask = 0; 283 m_items[item.ItemID].PermsGranter = UUID.Zero;
275 m_items[item.ItemID].PermsGranter = UUID.Zero; 284 m_items.LockItemsForWrite(false);
276 }
277
278 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 285 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
279 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 286 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
280 m_part.ParentGroup.AddActiveScriptCount(1); 287 m_part.ParentGroup.AddActiveScriptCount(1);
@@ -282,36 +289,31 @@ namespace OpenSim.Region.Framework.Scenes
282 return; 289 return;
283 } 290 }
284 291
285 m_part.ParentGroup.Scene.AssetService.Get( 292 m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset)
286 item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset) 293 {
287 { 294 if (null == asset)
288 if (null == asset) 295 {
289 { 296 m_log.ErrorFormat(
290 m_log.ErrorFormat( 297 "[PRIM INVENTORY]: " +
291 "[PRIM INVENTORY]: " + 298 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
292 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 299 item.Name, item.ItemID, m_part.AbsolutePosition,
293 item.Name, item.ItemID, m_part.AbsolutePosition, 300 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
294 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); 301 }
295 } 302 else
296 else 303 {
297 { 304 if (m_part.ParentGroup.m_savedScriptState != null)
298 if (m_part.ParentGroup.m_savedScriptState != null) 305 RestoreSavedScriptState(item.OldItemID, item.ItemID);
299 RestoreSavedScriptState(item.OldItemID, item.ItemID); 306 m_items.LockItemsForWrite(true);
300 307 m_items[item.ItemID].PermsMask = 0;
301 lock (m_items) 308 m_items[item.ItemID].PermsGranter = UUID.Zero;
302 { 309 m_items.LockItemsForWrite(false);
303 m_items[item.ItemID].PermsMask = 0; 310 string script = Utils.BytesToString(asset.Data);
304 m_items[item.ItemID].PermsGranter = UUID.Zero; 311 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
305 } 312 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
306 313 m_part.ParentGroup.AddActiveScriptCount(1);
307 string script = Utils.BytesToString(asset.Data); 314 m_part.ScheduleFullUpdate();
308 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 315 }
309 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 316 });
310 m_part.ParentGroup.AddActiveScriptCount(1);
311 m_part.ScheduleFullUpdate();
312 }
313 }
314 );
315 } 317 }
316 } 318 }
317 319
@@ -378,14 +380,17 @@ namespace OpenSim.Region.Framework.Scenes
378 /// </param> 380 /// </param>
379 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 381 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
380 { 382 {
381 lock (m_items) 383 m_items.LockItemsForRead(true);
384 if (m_items.ContainsKey(itemId))
382 { 385 {
383 if (m_items.ContainsKey(itemId)) 386 if (m_items.ContainsKey(itemId))
384 { 387 {
388 m_items.LockItemsForRead(false);
385 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); 389 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
386 } 390 }
387 else 391 else
388 { 392 {
393 m_items.LockItemsForRead(false);
389 m_log.ErrorFormat( 394 m_log.ErrorFormat(
390 "[PRIM INVENTORY]: " + 395 "[PRIM INVENTORY]: " +
391 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 396 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
@@ -393,6 +398,15 @@ namespace OpenSim.Region.Framework.Scenes
393 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 398 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
394 } 399 }
395 } 400 }
401 else
402 {
403 m_items.LockItemsForRead(false);
404 m_log.ErrorFormat(
405 "[PRIM INVENTORY]: " +
406 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2}",
407 itemId, m_part.Name, m_part.UUID);
408 }
409
396 } 410 }
397 411
398 /// <summary> 412 /// <summary>
@@ -405,15 +419,7 @@ namespace OpenSim.Region.Framework.Scenes
405 /// </param> 419 /// </param>
406 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 420 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
407 { 421 {
408 bool scriptPresent = false; 422 if (m_items.ContainsKey(itemId))
409
410 lock (m_items)
411 {
412 if (m_items.ContainsKey(itemId))
413 scriptPresent = true;
414 }
415
416 if (scriptPresent)
417 { 423 {
418 if (!sceneObjectBeingDeleted) 424 if (!sceneObjectBeingDeleted)
419 m_part.RemoveScriptEvents(itemId); 425 m_part.RemoveScriptEvents(itemId);
@@ -439,11 +445,16 @@ namespace OpenSim.Region.Framework.Scenes
439 /// <returns></returns> 445 /// <returns></returns>
440 private bool InventoryContainsName(string name) 446 private bool InventoryContainsName(string name)
441 { 447 {
442 foreach (TaskInventoryItem item in Items.Values) 448 m_items.LockItemsForRead(true);
449 foreach (TaskInventoryItem item in m_items.Values)
443 { 450 {
444 if (item.Name == name) 451 if (item.Name == name)
452 {
453 m_items.LockItemsForRead(false);
445 return true; 454 return true;
455 }
446 } 456 }
457 m_items.LockItemsForRead(false);
447 return false; 458 return false;
448 } 459 }
449 460
@@ -485,13 +496,9 @@ namespace OpenSim.Region.Framework.Scenes
485 /// <param name="item"></param> 496 /// <param name="item"></param>
486 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 497 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
487 { 498 {
488 List<TaskInventoryItem> il; 499 m_items.LockItemsForRead(true);
489 500 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
490 lock (m_items) 501 m_items.LockItemsForRead(false);
491 {
492 il = new List<TaskInventoryItem>(m_items.Values);
493 }
494
495 foreach (TaskInventoryItem i in il) 502 foreach (TaskInventoryItem i in il)
496 { 503 {
497 if (i.Name == item.Name) 504 if (i.Name == item.Name)
@@ -528,15 +535,14 @@ namespace OpenSim.Region.Framework.Scenes
528 item.ParentPartID = m_part.UUID; 535 item.ParentPartID = m_part.UUID;
529 item.Name = name; 536 item.Name = name;
530 537
531 lock (m_items) 538 m_items.LockItemsForWrite(true);
532 { 539 m_items.Add(item.ItemID, item);
533 m_items.Add(item.ItemID, item); 540 m_items.LockItemsForWrite(false);
534
535 if (allowedDrop) 541 if (allowedDrop)
536 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 542 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
537 else 543 else
538 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 544 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
539 } 545
540 546
541 m_inventorySerial++; 547 m_inventorySerial++;
542 //m_inventorySerial += 2; 548 //m_inventorySerial += 2;
@@ -553,14 +559,13 @@ namespace OpenSim.Region.Framework.Scenes
553 /// <param name="items"></param> 559 /// <param name="items"></param>
554 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 560 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
555 { 561 {
556 lock (m_items) 562 m_items.LockItemsForWrite(true);
563 foreach (TaskInventoryItem item in items)
557 { 564 {
558 foreach (TaskInventoryItem item in items) 565 m_items.Add(item.ItemID, item);
559 { 566 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
560 m_items.Add(item.ItemID, item);
561 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
562 }
563 } 567 }
568 m_items.LockItemsForWrite(false);
564 569
565 m_inventorySerial++; 570 m_inventorySerial++;
566 } 571 }
@@ -573,10 +578,9 @@ namespace OpenSim.Region.Framework.Scenes
573 public TaskInventoryItem GetInventoryItem(UUID itemId) 578 public TaskInventoryItem GetInventoryItem(UUID itemId)
574 { 579 {
575 TaskInventoryItem item; 580 TaskInventoryItem item;
576 581 m_items.LockItemsForRead(true);
577 lock (m_items) 582 m_items.TryGetValue(itemId, out item);
578 m_items.TryGetValue(itemId, out item); 583 m_items.LockItemsForRead(false);
579
580 return item; 584 return item;
581 } 585 }
582 586
@@ -612,45 +616,45 @@ namespace OpenSim.Region.Framework.Scenes
612 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 616 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
613 public bool UpdateInventoryItem(TaskInventoryItem item) 617 public bool UpdateInventoryItem(TaskInventoryItem item)
614 { 618 {
615 lock (m_items) 619 m_items.LockItemsForWrite(true);
620
621 if (m_items.ContainsKey(item.ItemID))
616 { 622 {
617 if (m_items.ContainsKey(item.ItemID)) 623 item.ParentID = m_part.UUID;
624 item.ParentPartID = m_part.UUID;
625 item.Flags = m_items[item.ItemID].Flags;
626 if (item.AssetID == UUID.Zero)
618 { 627 {
619 item.ParentID = m_part.UUID; 628 item.AssetID = m_items[item.ItemID].AssetID;
620 item.ParentPartID = m_part.UUID;
621 item.Flags = m_items[item.ItemID].Flags;
622 if (item.AssetID == UUID.Zero)
623 {
624 item.AssetID = m_items[item.ItemID].AssetID;
625 }
626 else if ((InventoryType)item.Type == InventoryType.Notecard)
627 {
628 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
629
630 if (presence != null)
631 {
632 presence.ControllingClient.SendAgentAlertMessage(
633 "Notecard saved", false);
634 }
635 }
636
637 m_items[item.ItemID] = item;
638 m_inventorySerial++;
639 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
640 HasInventoryChanged = true;
641 m_part.ParentGroup.HasGroupChanged = true;
642
643 return true;
644 } 629 }
645 else 630 else if ((InventoryType)item.Type == InventoryType.Notecard)
646 { 631 {
647 m_log.ErrorFormat( 632 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
648 "[PRIM INVENTORY]: " + 633
649 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 634 if (presence != null)
650 item.ItemID, m_part.Name, m_part.UUID, 635 {
651 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 636 presence.ControllingClient.SendAgentAlertMessage(
637 "Notecard saved", false);
638 }
652 } 639 }
640
641 m_items[item.ItemID] = item;
642 m_inventorySerial++;
643 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
644 HasInventoryChanged = true;
645 m_part.ParentGroup.HasGroupChanged = true;
646 m_items.LockItemsForWrite(false);
647 return true;
648 }
649 else
650 {
651 m_log.ErrorFormat(
652 "[PRIM INVENTORY]: " +
653 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
654 item.ItemID, m_part.Name, m_part.UUID,
655 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
653 } 656 }
657 m_items.LockItemsForWrite(false);
654 658
655 return false; 659 return false;
656 } 660 }
@@ -663,53 +667,54 @@ namespace OpenSim.Region.Framework.Scenes
663 /// in this prim's inventory.</returns> 667 /// in this prim's inventory.</returns>
664 public int RemoveInventoryItem(UUID itemID) 668 public int RemoveInventoryItem(UUID itemID)
665 { 669 {
666 lock (m_items) 670 m_items.LockItemsForRead(true);
671
672 if (m_items.ContainsKey(itemID))
667 { 673 {
668 if (m_items.ContainsKey(itemID)) 674 int type = m_items[itemID].InvType;
675 m_items.LockItemsForRead(false);
676 if (type == 10) // Script
669 { 677 {
670 int type = m_items[itemID].InvType; 678 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
671 if (type == 10) // Script 679 }
672 { 680 m_items.LockItemsForWrite(true);
673 m_part.RemoveScriptEvents(itemID); 681 m_items.Remove(itemID);
674 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 682 m_items.LockItemsForWrite(false);
675 } 683 m_inventorySerial++;
676 m_items.Remove(itemID); 684 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
677 m_inventorySerial++;
678 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
679
680 HasInventoryChanged = true;
681 m_part.ParentGroup.HasGroupChanged = true;
682 685
683 int scriptcount = 0; 686 HasInventoryChanged = true;
684 lock (m_items) 687 m_part.ParentGroup.HasGroupChanged = true;
685 {
686 foreach (TaskInventoryItem item in m_items.Values)
687 {
688 if (item.Type == 10)
689 {
690 scriptcount++;
691 }
692 }
693 }
694 688
695 if (scriptcount <= 0) 689 int scriptcount = 0;
690 m_items.LockItemsForRead(true);
691 foreach (TaskInventoryItem item in m_items.Values)
692 {
693 if (item.Type == 10)
696 { 694 {
697 m_part.RemFlag(PrimFlags.Scripted); 695 scriptcount++;
698 } 696 }
699
700 m_part.ScheduleFullUpdate();
701
702 return type;
703 } 697 }
704 else 698 m_items.LockItemsForRead(false);
699
700
701 if (scriptcount <= 0)
705 { 702 {
706 m_log.ErrorFormat( 703 m_part.RemFlag(PrimFlags.Scripted);
707 "[PRIM INVENTORY]: " +
708 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
709 itemID, m_part.Name, m_part.UUID,
710 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
711 } 704 }
705
706 m_part.ScheduleFullUpdate();
707
708 return type;
709 }
710 else
711 {
712 m_log.ErrorFormat(
713 "[PRIM INVENTORY]: " +
714 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
715 itemID, m_part.Name, m_part.UUID);
712 } 716 }
717 m_items.LockItemsForWrite(false);
713 718
714 return -1; 719 return -1;
715 } 720 }
@@ -762,52 +767,53 @@ namespace OpenSim.Region.Framework.Scenes
762 // isn't available (such as drag from prim inventory to agent inventory) 767 // isn't available (such as drag from prim inventory to agent inventory)
763 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 768 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
764 769
765 lock (m_items) 770 m_items.LockItemsForRead(true);
771
772 foreach (TaskInventoryItem item in m_items.Values)
766 { 773 {
767 foreach (TaskInventoryItem item in m_items.Values) 774 UUID ownerID = item.OwnerID;
768 { 775 uint everyoneMask = 0;
769 UUID ownerID = item.OwnerID; 776 uint baseMask = item.BasePermissions;
770 uint everyoneMask = 0; 777 uint ownerMask = item.CurrentPermissions;
771 uint baseMask = item.BasePermissions;
772 uint ownerMask = item.CurrentPermissions;
773 778
774 invString.AddItemStart(); 779 invString.AddItemStart();
775 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 780 invString.AddNameValueLine("item_id", item.ItemID.ToString());
776 invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); 781 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
777 782
778 invString.AddPermissionsStart(); 783 invString.AddPermissionsStart();
779 784
780 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 785 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
781 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 786 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
782 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0)); 787 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0));
783 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 788 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
784 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 789 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
785 790
786 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 791 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
787 invString.AddNameValueLine("owner_id", ownerID.ToString()); 792 invString.AddNameValueLine("owner_id", ownerID.ToString());
788 793
789 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 794 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
790 795
791 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 796 invString.AddNameValueLine("group_id", item.GroupID.ToString());
792 invString.AddSectionEnd(); 797 invString.AddSectionEnd();
793 798
794 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 799 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
795 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 800 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
796 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 801 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
797 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 802 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
798 803
799 invString.AddSaleStart(); 804 invString.AddSaleStart();
800 invString.AddNameValueLine("sale_type", "not"); 805 invString.AddNameValueLine("sale_type", "not");
801 invString.AddNameValueLine("sale_price", "0"); 806 invString.AddNameValueLine("sale_price", "0");
802 invString.AddSectionEnd(); 807 invString.AddSectionEnd();
803 808
804 invString.AddNameValueLine("name", item.Name + "|"); 809 invString.AddNameValueLine("name", item.Name + "|");
805 invString.AddNameValueLine("desc", item.Description + "|"); 810 invString.AddNameValueLine("desc", item.Description + "|");
806 811
807 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 812 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
808 invString.AddSectionEnd(); 813 invString.AddSectionEnd();
809 }
810 } 814 }
815 int count = m_items.Count;
816 m_items.LockItemsForRead(false);
811 817
812 fileData = Utils.StringToBytes(invString.BuildString); 818 fileData = Utils.StringToBytes(invString.BuildString);
813 819
@@ -828,10 +834,9 @@ namespace OpenSim.Region.Framework.Scenes
828 { 834 {
829 if (HasInventoryChanged) 835 if (HasInventoryChanged)
830 { 836 {
831 lock (Items) 837 Items.LockItemsForRead(true);
832 { 838 datastore.StorePrimInventory(m_part.UUID, Items.Values);
833 datastore.StorePrimInventory(m_part.UUID, Items.Values); 839 Items.LockItemsForRead(false);
834 }
835 840
836 HasInventoryChanged = false; 841 HasInventoryChanged = false;
837 } 842 }
@@ -900,61 +905,54 @@ namespace OpenSim.Region.Framework.Scenes
900 { 905 {
901 uint mask=0x7fffffff; 906 uint mask=0x7fffffff;
902 907
903 lock (m_items) 908 foreach (TaskInventoryItem item in m_items.Values)
904 { 909 {
905 foreach (TaskInventoryItem item in m_items.Values) 910 if (item.InvType != (int)InventoryType.Object)
906 { 911 {
907 if (item.InvType != (int)InventoryType.Object) 912 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
908 { 913 mask &= ~((uint)PermissionMask.Copy >> 13);
909 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 914 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
910 mask &= ~((uint)PermissionMask.Copy >> 13); 915 mask &= ~((uint)PermissionMask.Transfer >> 13);
911 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 916 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
912 mask &= ~((uint)PermissionMask.Transfer >> 13); 917 mask &= ~((uint)PermissionMask.Modify >> 13);
913 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 918 }
914 mask &= ~((uint)PermissionMask.Modify >> 13); 919 else
915 } 920 {
916 else 921 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
917 { 922 mask &= ~((uint)PermissionMask.Copy >> 13);
918 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 923 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
919 mask &= ~((uint)PermissionMask.Copy >> 13); 924 mask &= ~((uint)PermissionMask.Transfer >> 13);
920 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 925 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
921 mask &= ~((uint)PermissionMask.Transfer >> 13); 926 mask &= ~((uint)PermissionMask.Modify >> 13);
922 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
923 mask &= ~((uint)PermissionMask.Modify >> 13);
924 }
925
926 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
927 mask &= ~(uint)PermissionMask.Copy;
928 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
929 mask &= ~(uint)PermissionMask.Transfer;
930 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
931 mask &= ~(uint)PermissionMask.Modify;
932 } 927 }
928
929 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
930 mask &= ~(uint)PermissionMask.Copy;
931 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
932 mask &= ~(uint)PermissionMask.Transfer;
933 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
934 mask &= ~(uint)PermissionMask.Modify;
933 } 935 }
934
935 return mask; 936 return mask;
936 } 937 }
937 938
938 public void ApplyNextOwnerPermissions() 939 public void ApplyNextOwnerPermissions()
939 { 940 {
940 lock (m_items) 941 foreach (TaskInventoryItem item in m_items.Values)
941 { 942 {
942 foreach (TaskInventoryItem item in m_items.Values) 943 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
943 { 944 {
944 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 945 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
945 { 946 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
946 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 947 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
947 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 948 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
948 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 949 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
949 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 950 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
950 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 951 item.CurrentPermissions |= 8;
951 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
952 item.CurrentPermissions |= 8;
953 }
954 item.CurrentPermissions &= item.NextPermissions;
955 item.BasePermissions &= item.NextPermissions;
956 item.EveryonePermissions &= item.NextPermissions;
957 } 952 }
953 item.CurrentPermissions &= item.NextPermissions;
954 item.BasePermissions &= item.NextPermissions;
955 item.EveryonePermissions &= item.NextPermissions;
958 } 956 }
959 957
960 m_part.TriggerScriptChangedEvent(Changed.OWNER); 958 m_part.TriggerScriptChangedEvent(Changed.OWNER);
@@ -962,29 +960,22 @@ namespace OpenSim.Region.Framework.Scenes
962 960
963 public void ApplyGodPermissions(uint perms) 961 public void ApplyGodPermissions(uint perms)
964 { 962 {
965 lock (m_items) 963 foreach (TaskInventoryItem item in m_items.Values)
966 { 964 {
967 foreach (TaskInventoryItem item in m_items.Values) 965 item.CurrentPermissions = perms;
968 { 966 item.BasePermissions = perms;
969 item.CurrentPermissions = perms;
970 item.BasePermissions = perms;
971 }
972 } 967 }
973 } 968 }
974 969
975 public bool ContainsScripts() 970 public bool ContainsScripts()
976 { 971 {
977 lock (m_items) 972 foreach (TaskInventoryItem item in m_items.Values)
978 { 973 {
979 foreach (TaskInventoryItem item in m_items.Values) 974 if (item.InvType == (int)InventoryType.LSL)
980 { 975 {
981 if (item.InvType == (int)InventoryType.LSL) 976 return true;
982 {
983 return true;
984 }
985 } 977 }
986 } 978 }
987
988 return false; 979 return false;
989 } 980 }
990 981
@@ -992,11 +983,8 @@ namespace OpenSim.Region.Framework.Scenes
992 { 983 {
993 List<UUID> ret = new List<UUID>(); 984 List<UUID> ret = new List<UUID>();
994 985
995 lock (m_items) 986 foreach (TaskInventoryItem item in m_items.Values)
996 { 987 ret.Add(item.ItemID);
997 foreach (TaskInventoryItem item in m_items.Values)
998 ret.Add(item.ItemID);
999 }
1000 988
1001 return ret; 989 return ret;
1002 } 990 }
@@ -1009,30 +997,26 @@ namespace OpenSim.Region.Framework.Scenes
1009 if (engines == null) // No engine at all 997 if (engines == null) // No engine at all
1010 return ret; 998 return ret;
1011 999
1012 lock (m_items) 1000 foreach (TaskInventoryItem item in m_items.Values)
1013 { 1001 {
1014 foreach (TaskInventoryItem item in m_items.Values) 1002 if (item.InvType == (int)InventoryType.LSL)
1015 { 1003 {
1016 if (item.InvType == (int)InventoryType.LSL) 1004 foreach (IScriptModule e in engines)
1017 { 1005 {
1018 foreach (IScriptModule e in engines) 1006 if (e != null)
1019 { 1007 {
1020 if (e != null) 1008 string n = e.GetXMLState(item.ItemID);
1009 if (n != String.Empty)
1021 { 1010 {
1022 string n = e.GetXMLState(item.ItemID); 1011 if (!ret.ContainsKey(item.ItemID))
1023 if (n != String.Empty) 1012 ret[item.ItemID] = n;
1024 { 1013 break;
1025 if (!ret.ContainsKey(item.ItemID))
1026 ret[item.ItemID] = n;
1027 break;
1028 }
1029 } 1014 }
1030 } 1015 }
1031 } 1016 }
1032 } 1017 }
1033 } 1018 }
1034
1035 return ret; 1019 return ret;
1036 } 1020 }
1037 } 1021 }
1038} \ No newline at end of file 1022}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index b5f6217..5c54616 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
@@ -157,7 +161,6 @@ namespace OpenSim.Region.Framework.Scenes
157 private int m_perfMonMS; 161 private int m_perfMonMS;
158 162
159 private bool m_setAlwaysRun; 163 private bool m_setAlwaysRun;
160
161 private bool m_forceFly; 164 private bool m_forceFly;
162 private bool m_flyDisabled; 165 private bool m_flyDisabled;
163 166
@@ -183,7 +186,8 @@ namespace OpenSim.Region.Framework.Scenes
183 protected RegionInfo m_regionInfo; 186 protected RegionInfo m_regionInfo;
184 protected ulong crossingFromRegion; 187 protected ulong crossingFromRegion;
185 188
186 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 189 private readonly Vector3[] Dir_Vectors = new Vector3[11];
190 private bool m_isNudging = false;
187 191
188 // Position of agent's camera in world (region cordinates) 192 // Position of agent's camera in world (region cordinates)
189 protected Vector3 m_CameraCenter; 193 protected Vector3 m_CameraCenter;
@@ -208,6 +212,7 @@ namespace OpenSim.Region.Framework.Scenes
208 private bool m_autopilotMoving; 212 private bool m_autopilotMoving;
209 private Vector3 m_autoPilotTarget; 213 private Vector3 m_autoPilotTarget;
210 private bool m_sitAtAutoTarget; 214 private bool m_sitAtAutoTarget;
215 private Vector3 m_initialSitTarget; //KF: First estimate of where to sit
211 216
212 private string m_nextSitAnimation = String.Empty; 217 private string m_nextSitAnimation = String.Empty;
213 218
@@ -218,6 +223,9 @@ namespace OpenSim.Region.Framework.Scenes
218 private bool m_followCamAuto; 223 private bool m_followCamAuto;
219 224
220 private int m_movementUpdateCount; 225 private int m_movementUpdateCount;
226 private int m_lastColCount = -1; //KF: Look for Collision chnages
227 private int m_updateCount = 0; //KF: Update Anims for a while
228 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
221 229
222 private const int NumMovementsBetweenRayCast = 5; 230 private const int NumMovementsBetweenRayCast = 5;
223 231
@@ -246,7 +254,9 @@ namespace OpenSim.Region.Framework.Scenes
246 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 254 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
247 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 255 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
248 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 256 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
249 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 257 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
258 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
259 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
250 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 260 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
251 } 261 }
252 262
@@ -453,7 +463,8 @@ namespace OpenSim.Region.Framework.Scenes
453 get 463 get
454 { 464 {
455 PhysicsActor actor = m_physicsActor; 465 PhysicsActor actor = m_physicsActor;
456 if (actor != null) 466// if (actor != null)
467 if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting!
457 m_pos = actor.Position; 468 m_pos = actor.Position;
458 469
459 return m_parentPosition + m_pos; 470 return m_parentPosition + m_pos;
@@ -474,7 +485,8 @@ namespace OpenSim.Region.Framework.Scenes
474 } 485 }
475 } 486 }
476 487
477 m_pos = value; 488 if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting!
489 m_pos = value;
478 m_parentPosition = Vector3.Zero; 490 m_parentPosition = Vector3.Zero;
479 } 491 }
480 } 492 }
@@ -693,10 +705,7 @@ namespace OpenSim.Region.Framework.Scenes
693 m_reprioritization_timer.AutoReset = false; 705 m_reprioritization_timer.AutoReset = false;
694 706
695 AdjustKnownSeeds(); 707 AdjustKnownSeeds();
696
697 // TODO: I think, this won't send anything, as we are still a child here...
698 Animator.TrySetMovementAnimation("STAND"); 708 Animator.TrySetMovementAnimation("STAND");
699
700 // we created a new ScenePresence (a new child agent) in a fresh region. 709 // we created a new ScenePresence (a new child agent) in a fresh region.
701 // Request info about all the (root) agents in this region 710 // Request info about all the (root) agents in this region
702 // Note: This won't send data *to* other clients in that region (children don't send) 711 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -752,25 +761,47 @@ namespace OpenSim.Region.Framework.Scenes
752 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 761 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
753 Dir_Vectors[4] = Vector3.UnitZ; //UP 762 Dir_Vectors[4] = Vector3.UnitZ; //UP
754 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 763 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
755 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 764 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
756 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 765 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
757 Dir_Vectors[7] = -Vector3.UnitX; //BACK 766 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
767 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
768 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
758 } 769 }
759 770
760 private Vector3[] GetWalkDirectionVectors() 771 private Vector3[] GetWalkDirectionVectors()
761 { 772 {
762 Vector3[] vector = new Vector3[9]; 773 Vector3[] vector = new Vector3[11];
763 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 774 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
764 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 775 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
765 vector[2] = Vector3.UnitY; //LEFT 776 vector[2] = Vector3.UnitY; //LEFT
766 vector[3] = -Vector3.UnitY; //RIGHT 777 vector[3] = -Vector3.UnitY; //RIGHT
767 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 778 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
768 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 779 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
769 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 780 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
770 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 781 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
771 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 782 vector[8] = Vector3.UnitY; //LEFT_NUDGE
783 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
784 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
772 return vector; 785 return vector;
773 } 786 }
787
788 private bool[] GetDirectionIsNudge()
789 {
790 bool[] isNudge = new bool[11];
791 isNudge[0] = false; //FORWARD
792 isNudge[1] = false; //BACK
793 isNudge[2] = false; //LEFT
794 isNudge[3] = false; //RIGHT
795 isNudge[4] = false; //UP
796 isNudge[5] = false; //DOWN
797 isNudge[6] = true; //FORWARD_NUDGE
798 isNudge[7] = true; //BACK_NUDGE
799 isNudge[8] = true; //LEFT_NUDGE
800 isNudge[9] = true; //RIGHT_NUDGE
801 isNudge[10] = true; //DOWN_Nudge
802 return isNudge;
803 }
804
774 805
775 #endregion 806 #endregion
776 807
@@ -839,6 +870,22 @@ namespace OpenSim.Region.Framework.Scenes
839 { 870 {
840 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 871 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
841 pos.Y = crossedBorder.BorderLine.Z - 1; 872 pos.Y = crossedBorder.BorderLine.Z - 1;
873 }
874
875 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
876 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
877 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
878 if (KnownChildRegionHandles.Count == 0)
879 {
880 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
881 if (land != null)
882 {
883 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
884 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && m_userLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid)
885 {
886 pos = land.LandData.UserLocation;
887 }
888 }
842 } 889 }
843 890
844 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 891 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
@@ -972,9 +1019,10 @@ namespace OpenSim.Region.Framework.Scenes
972 public void Teleport(Vector3 pos) 1019 public void Teleport(Vector3 pos)
973 { 1020 {
974 bool isFlying = false; 1021 bool isFlying = false;
975 if (m_physicsActor != null)
976 isFlying = m_physicsActor.Flying;
977 1022
1023 if (m_physicsActor != null)
1024 isFlying = m_physicsActor.Flying;
1025
978 RemoveFromPhysicalScene(); 1026 RemoveFromPhysicalScene();
979 Velocity = Vector3.Zero; 1027 Velocity = Vector3.Zero;
980 AbsolutePosition = pos; 1028 AbsolutePosition = pos;
@@ -985,7 +1033,8 @@ namespace OpenSim.Region.Framework.Scenes
985 SetHeight(m_appearance.AvatarHeight); 1033 SetHeight(m_appearance.AvatarHeight);
986 } 1034 }
987 1035
988 SendTerseUpdateToAllClients(); 1036 SendTerseUpdateToAllClients();
1037
989 } 1038 }
990 1039
991 public void TeleportWithMomentum(Vector3 pos) 1040 public void TeleportWithMomentum(Vector3 pos)
@@ -1030,7 +1079,9 @@ namespace OpenSim.Region.Framework.Scenes
1030 { 1079 {
1031 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); 1080 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
1032 } 1081 }
1033 1082
1083 m_updateCount = UPDATE_COUNT; //KF: Trigger Anim updates to catch falling anim.
1084
1034 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 1085 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
1035 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient))); 1086 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
1036 } 1087 }
@@ -1215,6 +1266,7 @@ namespace OpenSim.Region.Framework.Scenes
1215 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); 1266 m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902");
1216 1267
1217 m_pos = m_LastFinitePos; 1268 m_pos = m_LastFinitePos;
1269
1218 if (!m_pos.IsFinite()) 1270 if (!m_pos.IsFinite())
1219 { 1271 {
1220 m_pos.X = 127f; 1272 m_pos.X = 127f;
@@ -1281,7 +1333,6 @@ namespace OpenSim.Region.Framework.Scenes
1281 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1333 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1282 } 1334 }
1283 } 1335 }
1284
1285 lock (scriptedcontrols) 1336 lock (scriptedcontrols)
1286 { 1337 {
1287 if (scriptedcontrols.Count > 0) 1338 if (scriptedcontrols.Count > 0)
@@ -1296,12 +1347,8 @@ namespace OpenSim.Region.Framework.Scenes
1296 1347
1297 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1348 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1298 { 1349 {
1299 // TODO: This doesn't prevent the user from walking yet. 1350 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1300 // Setting parent ID would fix this, if we knew what value 1351 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1301 // to use. Or we could add a m_isSitting variable.
1302 //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1303 SitGround = true;
1304
1305 } 1352 }
1306 1353
1307 // In the future, these values might need to go global. 1354 // In the future, these values might need to go global.
@@ -1351,6 +1398,11 @@ namespace OpenSim.Region.Framework.Scenes
1351 update_rotation = true; 1398 update_rotation = true;
1352 } 1399 }
1353 1400
1401 //guilty until proven innocent..
1402 bool Nudging = true;
1403 //Basically, if there is at least one non-nudge control then we don't need
1404 //to worry about stopping the avatar
1405
1354 if (m_parentID == 0) 1406 if (m_parentID == 0)
1355 { 1407 {
1356 bool bAllowUpdateMoveToPosition = false; 1408 bool bAllowUpdateMoveToPosition = false;
@@ -1365,9 +1417,12 @@ namespace OpenSim.Region.Framework.Scenes
1365 else 1417 else
1366 dirVectors = Dir_Vectors; 1418 dirVectors = Dir_Vectors;
1367 1419
1368 // The fact that m_movementflag is a byte needs to be fixed 1420 bool[] isNudge = GetDirectionIsNudge();
1369 // it really should be a uint 1421
1370 uint nudgehack = 250; 1422
1423
1424
1425
1371 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1426 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1372 { 1427 {
1373 if (((uint)flags & (uint)DCF) != 0) 1428 if (((uint)flags & (uint)DCF) != 0)
@@ -1377,40 +1432,28 @@ namespace OpenSim.Region.Framework.Scenes
1377 try 1432 try
1378 { 1433 {
1379 agent_control_v3 += dirVectors[i]; 1434 agent_control_v3 += dirVectors[i];
1380 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1435 if (isNudge[i] == false)
1436 {
1437 Nudging = false;
1438 }
1381 } 1439 }
1382 catch (IndexOutOfRangeException) 1440 catch (IndexOutOfRangeException)
1383 { 1441 {
1384 // Why did I get this? 1442 // Why did I get this?
1385 } 1443 }
1386 1444
1387 if ((m_movementflag & (byte)(uint)DCF) == 0) 1445 if ((m_movementflag & (uint)DCF) == 0)
1388 { 1446 {
1389 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1390 {
1391 m_movementflag |= (byte)nudgehack;
1392 }
1393 m_movementflag += (byte)(uint)DCF; 1447 m_movementflag += (byte)(uint)DCF;
1394 update_movementflag = true; 1448 update_movementflag = true;
1395 } 1449 }
1396 } 1450 }
1397 else 1451 else
1398 { 1452 {
1399 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1453 if ((m_movementflag & (uint)DCF) != 0)
1400 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1401 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1402 ) // This or is for Nudge forward
1403 { 1454 {
1404 m_movementflag -= ((byte)(uint)DCF); 1455 m_movementflag -= (byte)(uint)DCF;
1405
1406 update_movementflag = true; 1456 update_movementflag = true;
1407 /*
1408 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1409 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1410 {
1411 m_log.Debug("Removed Hack flag");
1412 }
1413 */
1414 } 1457 }
1415 else 1458 else
1416 { 1459 {
@@ -1454,6 +1497,9 @@ namespace OpenSim.Region.Framework.Scenes
1454 // Ignore z component of vector 1497 // Ignore z component of vector
1455 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1498 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1456 LocalVectorToTarget2D.Normalize(); 1499 LocalVectorToTarget2D.Normalize();
1500
1501 //We're not nudging
1502 Nudging = false;
1457 agent_control_v3 += LocalVectorToTarget2D; 1503 agent_control_v3 += LocalVectorToTarget2D;
1458 1504
1459 // update avatar movement flags. the avatar coordinate system is as follows: 1505 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1542,13 +1588,13 @@ namespace OpenSim.Region.Framework.Scenes
1542 // m_log.DebugFormat( 1588 // m_log.DebugFormat(
1543 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1589 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1544 1590
1545 AddNewMovement(agent_control_v3, q); 1591 AddNewMovement(agent_control_v3, q, Nudging);
1546 1592
1547 1593
1548 } 1594 }
1549 } 1595 }
1550 1596
1551 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1597 if (update_movementflag)
1552 Animator.UpdateMovementAnimations(); 1598 Animator.UpdateMovementAnimations();
1553 1599
1554 m_scene.EventManager.TriggerOnClientMovement(this); 1600 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1563,7 +1609,6 @@ namespace OpenSim.Region.Framework.Scenes
1563 m_sitAtAutoTarget = false; 1609 m_sitAtAutoTarget = false;
1564 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1610 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1565 //proxy.PCode = (byte)PCode.ParticleSystem; 1611 //proxy.PCode = (byte)PCode.ParticleSystem;
1566
1567 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1612 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1568 proxyObjectGroup.AttachToScene(m_scene); 1613 proxyObjectGroup.AttachToScene(m_scene);
1569 1614
@@ -1605,7 +1650,7 @@ namespace OpenSim.Region.Framework.Scenes
1605 } 1650 }
1606 m_moveToPositionInProgress = true; 1651 m_moveToPositionInProgress = true;
1607 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1652 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1608 } 1653 }
1609 catch (Exception ex) 1654 catch (Exception ex)
1610 { 1655 {
1611 //Why did I get this error? 1656 //Why did I get this error?
@@ -1627,7 +1672,7 @@ namespace OpenSim.Region.Framework.Scenes
1627 Velocity = Vector3.Zero; 1672 Velocity = Vector3.Zero;
1628 SendFullUpdateToAllClients(); 1673 SendFullUpdateToAllClients();
1629 1674
1630 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1675 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1631 } 1676 }
1632 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1677 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1633 m_requestedSitTargetUUID = UUID.Zero; 1678 m_requestedSitTargetUUID = UUID.Zero;
@@ -1660,55 +1705,84 @@ namespace OpenSim.Region.Framework.Scenes
1660 /// </summary> 1705 /// </summary>
1661 public void StandUp() 1706 public void StandUp()
1662 { 1707 {
1663 if (SitGround)
1664 SitGround = false;
1665
1666 if (m_parentID != 0) 1708 if (m_parentID != 0)
1667 { 1709 {
1668 m_log.Debug("StandupCode Executed");
1669 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1710 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1670 if (part != null) 1711 if (part != null)
1671 { 1712 {
1713 part.TaskInventory.LockItemsForRead(true);
1672 TaskInventoryDictionary taskIDict = part.TaskInventory; 1714 TaskInventoryDictionary taskIDict = part.TaskInventory;
1673 if (taskIDict != null) 1715 if (taskIDict != null)
1674 { 1716 {
1675 lock (taskIDict) 1717 foreach (UUID taskID in taskIDict.Keys)
1676 { 1718 {
1677 foreach (UUID taskID in taskIDict.Keys) 1719 UnRegisterControlEventsToScript(LocalId, taskID);
1678 { 1720 taskIDict[taskID].PermsMask &= ~(
1679 UnRegisterControlEventsToScript(LocalId, taskID); 1721 2048 | //PERMISSION_CONTROL_CAMERA
1680 taskIDict[taskID].PermsMask &= ~( 1722 4); // PERMISSION_TAKE_CONTROLS
1681 2048 | //PERMISSION_CONTROL_CAMERA
1682 4); // PERMISSION_TAKE_CONTROLS
1683 }
1684 } 1723 }
1685
1686 } 1724 }
1725 part.TaskInventory.LockItemsForRead(false);
1687 // Reset sit target. 1726 // Reset sit target.
1688 if (part.GetAvatarOnSitTarget() == UUID) 1727 if (part.GetAvatarOnSitTarget() == UUID)
1689 part.SetAvatarOnSitTarget(UUID.Zero); 1728 part.SetAvatarOnSitTarget(UUID.Zero);
1690
1691 m_parentPosition = part.GetWorldPosition(); 1729 m_parentPosition = part.GetWorldPosition();
1692 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1730 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1693 } 1731 }
1694 1732 // part.GetWorldRotation() is the rotation of the object being sat on
1695 if (m_physicsActor == null) 1733 // Rotation is the sittiing Av's rotation
1696 { 1734
1697 AddToPhysicalScene(false); 1735 Quaternion partRot;
1736// if (part.LinkNum == 1)
1737// { // Root prim of linkset
1738// partRot = part.ParentGroup.RootPart.RotationOffset;
1739// }
1740// else
1741// { // single or child prim
1742
1743// }
1744 if (part == null) //CW: Part may be gone. llDie() for example.
1745 {
1746 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1747 }
1748 else
1749 {
1750 partRot = part.GetWorldRotation();
1698 } 1751 }
1699 1752
1700 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1753 Quaternion partIRot = Quaternion.Inverse(partRot);
1701 m_parentPosition = Vector3.Zero; 1754
1755 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1756 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1702 1757
1703 m_parentID = 0; 1758
1759 if (m_physicsActor == null)
1760 {
1761 AddToPhysicalScene(false);
1762 }
1763 //CW: If the part isn't null then we can set the current position
1764 if (part != null)
1765 {
1766 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + (m_pos * partRot); // + av sit offset!
1767 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1768 part.IsOccupied = false;
1769 }
1770 else
1771 {
1772 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1773 AbsolutePosition = m_lastWorldPosition;
1774 }
1775
1776 m_parentPosition = Vector3.Zero;
1777 m_parentID = 0;
1704 SendFullUpdateToAllClients(); 1778 SendFullUpdateToAllClients();
1705 m_requestedSitTargetID = 0; 1779 m_requestedSitTargetID = 0;
1780
1706 if ((m_physicsActor != null) && (m_avHeight > 0)) 1781 if ((m_physicsActor != null) && (m_avHeight > 0))
1707 { 1782 {
1708 SetHeight(m_avHeight); 1783 SetHeight(m_avHeight);
1709 } 1784 }
1710 } 1785 }
1711
1712 Animator.TrySetMovementAnimation("STAND"); 1786 Animator.TrySetMovementAnimation("STAND");
1713 } 1787 }
1714 1788
@@ -1739,13 +1813,9 @@ namespace OpenSim.Region.Framework.Scenes
1739 Vector3 avSitOffSet = part.SitTargetPosition; 1813 Vector3 avSitOffSet = part.SitTargetPosition;
1740 Quaternion avSitOrientation = part.SitTargetOrientation; 1814 Quaternion avSitOrientation = part.SitTargetOrientation;
1741 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1815 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1742 1816 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1743 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1817 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1744 bool SitTargetisSet = 1818 if (SitTargetisSet && !SitTargetOccupied)
1745 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1746 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1747
1748 if (SitTargetisSet && SitTargetUnOccupied)
1749 { 1819 {
1750 //switch the target to this prim 1820 //switch the target to this prim
1751 return part; 1821 return part;
@@ -1759,84 +1829,153 @@ namespace OpenSim.Region.Framework.Scenes
1759 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1829 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1760 { 1830 {
1761 bool autopilot = true; 1831 bool autopilot = true;
1832 Vector3 autopilotTarget = new Vector3();
1833 Quaternion sitOrientation = Quaternion.Identity;
1762 Vector3 pos = new Vector3(); 1834 Vector3 pos = new Vector3();
1763 Quaternion sitOrientation = pSitOrientation;
1764 Vector3 cameraEyeOffset = Vector3.Zero; 1835 Vector3 cameraEyeOffset = Vector3.Zero;
1765 Vector3 cameraAtOffset = Vector3.Zero; 1836 Vector3 cameraAtOffset = Vector3.Zero;
1766 bool forceMouselook = false; 1837 bool forceMouselook = false;
1767 1838
1768 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1839 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1769 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1840 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1770 if (part != null) 1841 if (part == null) return;
1771 { 1842
1772 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1843 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1773 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1844 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1774 1845
1775 // Is a sit target available? 1846 // part is the prim to sit on
1776 Vector3 avSitOffSet = part.SitTargetPosition; 1847 // offset is the world-ref vector distance from that prim center to the click-spot
1777 Quaternion avSitOrientation = part.SitTargetOrientation; 1848 // UUID is the UUID of the Avatar doing the clicking
1778 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1849
1779 1850 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1780 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1851
1781 bool SitTargetisSet = 1852 // Is a sit target available?
1782 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1853 Vector3 avSitOffSet = part.SitTargetPosition;
1783 ( 1854 Quaternion avSitOrientation = part.SitTargetOrientation;
1784 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1855
1785 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1856 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1786 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1857 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1787 ) 1858 Quaternion partRot;
1788 )); 1859// if (part.LinkNum == 1)
1789 1860// { // Root prim of linkset
1790 if (SitTargetisSet && SitTargetUnOccupied) 1861// partRot = part.ParentGroup.RootPart.RotationOffset;
1791 { 1862// }
1792 part.SetAvatarOnSitTarget(UUID); 1863// else
1793 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1864// { // single or child prim
1794 sitOrientation = avSitOrientation; 1865 partRot = part.GetWorldRotation();
1795 autopilot = false; 1866// }
1796 } 1867 Quaternion partIRot = Quaternion.Inverse(partRot);
1797 1868//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1798 pos = part.AbsolutePosition + offset; 1869 // Sit analysis rewritten by KF 091125
1799 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1870 if (SitTargetisSet) // scipted sit
1800 //{ 1871 {
1801 // offset = pos; 1872 if (!part.IsOccupied)
1802 //autopilot = false; 1873 {
1803 //} 1874//Console.WriteLine("Scripted, unoccupied");
1804 if (m_physicsActor != null) 1875 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1805 { 1876 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1806 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1877 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1807 // We can remove the physicsActor until they stand up. 1878 autopilot = false; // Jump direct to scripted llSitPos()
1808 m_sitAvatarHeight = m_physicsActor.Size.Z; 1879 }
1809 1880 else
1810 if (autopilot) 1881 {
1811 { 1882//Console.WriteLine("Scripted, occupied");
1812 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1883 return;
1813 { 1884 }
1814 autopilot = false; 1885 }
1886 else // Not Scripted
1887 {
1888 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1889 {
1890 // large prim & offset, ignore if other Avs sitting
1891// offset.Z -= 0.05f;
1892 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1893 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1894
1895//Console.WriteLine(" offset ={0}", offset);
1896//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1897//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1898
1899 }
1900 else // small offset
1901 {
1902//Console.WriteLine("Small offset");
1903 if (!part.IsOccupied)
1904 {
1905 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1906 autopilotTarget = part.AbsolutePosition;
1907//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget);
1908 }
1909 else return; // occupied small
1910 } // end large/small
1911 } // end Scripted/not
1912 cameraAtOffset = part.GetCameraAtOffset();
1913 cameraEyeOffset = part.GetCameraEyeOffset();
1914 forceMouselook = part.GetForceMouselook();
1915 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1916 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1815 1917
1816 RemoveFromPhysicalScene(); 1918 if (m_physicsActor != null)
1817 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1919 {
1818 } 1920 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1819 } 1921 // We can remove the physicsActor until they stand up.
1820 else 1922 m_sitAvatarHeight = m_physicsActor.Size.Z;
1923 if (autopilot)
1924 { // its not a scripted sit
1925// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1926 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1821 { 1927 {
1928 autopilot = false; // close enough
1929 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1930 Not using the part's position because returning the AV to the last known standing
1931 position is likely to be more friendly, isn't it? */
1822 RemoveFromPhysicalScene(); 1932 RemoveFromPhysicalScene();
1823 } 1933 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1934 } // else the autopilot will get us close
1935 }
1936 else
1937 { // its a scripted sit
1938 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1939 I *am* using the part's position this time because we have no real idea how far away
1940 the avatar is from the sit target. */
1941 RemoveFromPhysicalScene();
1824 } 1942 }
1825
1826 cameraAtOffset = part.GetCameraAtOffset();
1827 cameraEyeOffset = part.GetCameraEyeOffset();
1828 forceMouselook = part.GetForceMouselook();
1829 } 1943 }
1830 1944 else return; // physactor is null!
1831 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 1945
1832 m_requestedSitTargetUUID = targetID; 1946 Vector3 offsetr; // = offset * partIRot;
1947 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
1948 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
1949 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
1950 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
1951 offsetr = offset * partIRot;
1952//
1953 // else
1954 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
1955 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
1956 // (offset * partRot);
1957 // }
1958
1959//Console.WriteLine(" ");
1960//Console.WriteLine("link number ={0}", part.LinkNum);
1961//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
1962//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
1963//Console.WriteLine("Click offst ={0}", offset);
1964//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
1965//Console.WriteLine("offsetr ={0}", offsetr);
1966//Console.WriteLine("Camera At ={0}", cameraAtOffset);
1967//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
1968
1969 ControllingClient.SendSitResponse(part.UUID, offsetr, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
1970 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1833 // This calls HandleAgentSit twice, once from here, and the client calls 1971 // This calls HandleAgentSit twice, once from here, and the client calls
1834 // HandleAgentSit itself after it gets to the location 1972 // HandleAgentSit itself after it gets to the location
1835 // It doesn't get to the location until we've moved them there though 1973 // It doesn't get to the location until we've moved them there though
1836 // which happens in HandleAgentSit :P 1974 // which happens in HandleAgentSit :P
1837 m_autopilotMoving = autopilot; 1975 m_autopilotMoving = autopilot;
1838 m_autoPilotTarget = pos; 1976 m_autoPilotTarget = autopilotTarget;
1839 m_sitAtAutoTarget = autopilot; 1977 m_sitAtAutoTarget = autopilot;
1978 m_initialSitTarget = autopilotTarget;
1840 if (!autopilot) 1979 if (!autopilot)
1841 HandleAgentSit(remoteClient, UUID); 1980 HandleAgentSit(remoteClient, UUID);
1842 } 1981 }
@@ -2131,31 +2270,66 @@ namespace OpenSim.Region.Framework.Scenes
2131 { 2270 {
2132 if (part != null) 2271 if (part != null)
2133 { 2272 {
2273//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2134 if (part.GetAvatarOnSitTarget() == UUID) 2274 if (part.GetAvatarOnSitTarget() == UUID)
2135 { 2275 {
2276//Console.WriteLine("Scripted Sit");
2277 // Scripted sit
2136 Vector3 sitTargetPos = part.SitTargetPosition; 2278 Vector3 sitTargetPos = part.SitTargetPosition;
2137 Quaternion sitTargetOrient = part.SitTargetOrientation; 2279 Quaternion sitTargetOrient = part.SitTargetOrientation;
2138
2139 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2140 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2141
2142 //Quaternion result = (sitTargetOrient * vq) * nq;
2143
2144 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2280 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2145 m_pos += SIT_TARGET_ADJUSTMENT; 2281 m_pos += SIT_TARGET_ADJUSTMENT;
2146 m_bodyRot = sitTargetOrient; 2282 m_bodyRot = sitTargetOrient;
2147 //Rotation = sitTargetOrient;
2148 m_parentPosition = part.AbsolutePosition; 2283 m_parentPosition = part.AbsolutePosition;
2149 2284 part.IsOccupied = true;
2150 //SendTerseUpdateToAllClients(); 2285Console.WriteLine("Scripted Sit ofset {0}", m_pos);
2151 } 2286 }
2152 else 2287 else
2153 { 2288 {
2154 m_pos -= part.AbsolutePosition; 2289 // if m_avUnscriptedSitPos is zero then Av sits above center
2290 // Else Av sits at m_avUnscriptedSitPos
2291
2292 // Non-scripted sit by Kitto Flora 21Nov09
2293 // Calculate angle of line from prim to Av
2294 Quaternion partIRot;
2295// if (part.LinkNum == 1)
2296// { // Root prim of linkset
2297// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2298// }
2299// else
2300// { // single or child prim
2301 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2302// }
2303 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2304 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2305 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2306 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2307 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2308 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2309 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2310 // Av sits at world euler <0,0, z>, translated by part rotation
2311 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2312
2155 m_parentPosition = part.AbsolutePosition; 2313 m_parentPosition = part.AbsolutePosition;
2156 } 2314 part.IsOccupied = true;
2315 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2316 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2317 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2318 m_avUnscriptedSitPos; // adds click offset, if any
2319 //Set up raytrace to find top surface of prim
2320 Vector3 size = part.Scale;
2321 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2322 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2323 Vector3 down = new Vector3(0f, 0f, -1f);
2324//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2325 m_scene.PhysicsScene.RaycastWorld(
2326 start, // Vector3 position,
2327 down, // Vector3 direction,
2328 mag, // float length,
2329 SitAltitudeCallback); // retMethod
2330 } // end scripted/not
2157 } 2331 }
2158 else 2332 else // no Av
2159 { 2333 {
2160 return; 2334 return;
2161 } 2335 }
@@ -2167,11 +2341,36 @@ namespace OpenSim.Region.Framework.Scenes
2167 2341
2168 Animator.TrySetMovementAnimation(sitAnimation); 2342 Animator.TrySetMovementAnimation(sitAnimation);
2169 SendFullUpdateToAllClients(); 2343 SendFullUpdateToAllClients();
2170 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2171 // So we're also sending a terse update (which has avatar rotation)
2172 // [Update] We do now.
2173 //SendTerseUpdateToAllClients();
2174 } 2344 }
2345
2346 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2347 {
2348 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2349 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2350 if(hitYN)
2351 {
2352 // m_pos = Av offset from prim center to make look like on center
2353 // m_parentPosition = Actual center pos of prim
2354 // collisionPoint = spot on prim where we want to sit
2355 // collisionPoint.Z = global sit surface height
2356 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2357 Quaternion partIRot;
2358// if (part.LinkNum == 1)
2359/// { // Root prim of linkset
2360// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2361// }
2362// else
2363// { // single or child prim
2364 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2365// }
2366 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2367 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2368//Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2369 m_pos += offset;
2370// ControllingClient.SendClearFollowCamProperties(part.UUID);
2371
2372 }
2373 } // End SitAltitudeCallback KF.
2175 2374
2176 /// <summary> 2375 /// <summary>
2177 /// Event handler for the 'Always run' setting on the client 2376 /// Event handler for the 'Always run' setting on the client
@@ -2201,7 +2400,7 @@ namespace OpenSim.Region.Framework.Scenes
2201 /// </summary> 2400 /// </summary>
2202 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2401 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2203 /// <param name="rotation">The direction in which this avatar should now face. 2402 /// <param name="rotation">The direction in which this avatar should now face.
2204 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2403 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2205 { 2404 {
2206 if (m_isChildAgent) 2405 if (m_isChildAgent)
2207 { 2406 {
@@ -2278,7 +2477,7 @@ namespace OpenSim.Region.Framework.Scenes
2278 2477
2279 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2478 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2280 m_forceToApply = direc; 2479 m_forceToApply = direc;
2281 2480 m_isNudging = Nudging;
2282 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2481 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2283 } 2482 }
2284 2483
@@ -2293,7 +2492,7 @@ namespace OpenSim.Region.Framework.Scenes
2293 const float POSITION_TOLERANCE = 0.05f; 2492 const float POSITION_TOLERANCE = 0.05f;
2294 //const int TIME_MS_TOLERANCE = 3000; 2493 //const int TIME_MS_TOLERANCE = 3000;
2295 2494
2296 SendPrimUpdates(); 2495
2297 2496
2298 if (m_newCoarseLocations) 2497 if (m_newCoarseLocations)
2299 { 2498 {
@@ -2329,6 +2528,9 @@ namespace OpenSim.Region.Framework.Scenes
2329 CheckForBorderCrossing(); 2528 CheckForBorderCrossing();
2330 CheckForSignificantMovement(); // sends update to the modules. 2529 CheckForSignificantMovement(); // sends update to the modules.
2331 } 2530 }
2531
2532 //Sending prim updates AFTER the avatar terse updates are sent
2533 SendPrimUpdates();
2332 } 2534 }
2333 2535
2334 #endregion 2536 #endregion
@@ -3145,6 +3347,7 @@ namespace OpenSim.Region.Framework.Scenes
3145 m_callbackURI = cAgent.CallbackURI; 3347 m_callbackURI = cAgent.CallbackURI;
3146 3348
3147 m_pos = cAgent.Position; 3349 m_pos = cAgent.Position;
3350
3148 m_velocity = cAgent.Velocity; 3351 m_velocity = cAgent.Velocity;
3149 m_CameraCenter = cAgent.Center; 3352 m_CameraCenter = cAgent.Center;
3150 //m_avHeight = cAgent.Size.Z; 3353 //m_avHeight = cAgent.Size.Z;
@@ -3233,14 +3436,25 @@ namespace OpenSim.Region.Framework.Scenes
3233 { 3436 {
3234 if (m_forceToApply.HasValue) 3437 if (m_forceToApply.HasValue)
3235 { 3438 {
3236 Vector3 force = m_forceToApply.Value;
3237 3439
3440 Vector3 force = m_forceToApply.Value;
3238 m_updateflag = true; 3441 m_updateflag = true;
3239// movementvector = force;
3240 Velocity = force; 3442 Velocity = force;
3241 3443
3242 m_forceToApply = null; 3444 m_forceToApply = null;
3243 } 3445 }
3446 else
3447 {
3448 if (m_isNudging)
3449 {
3450 Vector3 force = Vector3.Zero;
3451
3452 m_updateflag = true;
3453 Velocity = force;
3454 m_isNudging = false;
3455 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3456 }
3457 }
3244 } 3458 }
3245 3459
3246 public override void SetText(string text, Vector3 color, double alpha) 3460 public override void SetText(string text, Vector3 color, double alpha)
@@ -3291,18 +3505,29 @@ namespace OpenSim.Region.Framework.Scenes
3291 { 3505 {
3292 if (e == null) 3506 if (e == null)
3293 return; 3507 return;
3294 3508
3295 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3509 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3296 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3297 // as of this comment the interval is set in AddToPhysicalScene 3510 // as of this comment the interval is set in AddToPhysicalScene
3298 if (Animator!=null) 3511 if (Animator!=null)
3299 Animator.UpdateMovementAnimations(); 3512 {
3513 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3514 { // else its will lock out other animation changes, like ground sit.
3515 Animator.UpdateMovementAnimations();
3516 m_updateCount--;
3517 }
3518 }
3300 3519
3301 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3520 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3302 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3521 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3303 3522
3304 CollisionPlane = Vector4.UnitW; 3523 CollisionPlane = Vector4.UnitW;
3305 3524
3525 if (m_lastColCount != coldata.Count)
3526 {
3527 m_updateCount = UPDATE_COUNT;
3528 m_lastColCount = coldata.Count;
3529 }
3530
3306 if (coldata.Count != 0 && Animator != null) 3531 if (coldata.Count != 0 && Animator != null)
3307 { 3532 {
3308 switch (Animator.CurrentMovementAnimation) 3533 switch (Animator.CurrentMovementAnimation)
@@ -3909,5 +4134,16 @@ namespace OpenSim.Region.Framework.Scenes
3909 m_reprioritization_called = false; 4134 m_reprioritization_called = false;
3910 } 4135 }
3911 } 4136 }
4137
4138 private Vector3 Quat2Euler(Quaternion rot){
4139 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4140 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4141 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4142 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4143 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4144 return(new Vector3(x,y,z));
4145 }
4146
4147
3912 } 4148 }
3913} 4149}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index c6cf4cc..4ba4fab 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -75,7 +75,7 @@ namespace OpenSim.Region.Framework.Scenes
75 75
76 foreach (EntityBase e in m_presence.Scene.Entities) 76 foreach (EntityBase e in m_presence.Scene.Entities)
77 { 77 {
78 if (e is SceneObjectGroup) 78 if (e != null && e is SceneObjectGroup)
79 m_pendingObjects.Enqueue((SceneObjectGroup)e); 79 m_pendingObjects.Enqueue((SceneObjectGroup)e);
80 } 80 }
81 } 81 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
index c77220c..68035ca 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;