aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-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/Scene.Inventory.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs34
-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.cs602
-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
12 files changed, 1301 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/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 fc915a3..1f604c5 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,7 +1727,7 @@ 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);
1716 } 1730 }
1717 1731
1718 public void StoreWindlightProfile(RegionLightShareData wl) 1732 public void StoreWindlightProfile(RegionLightShareData wl)
1719 { 1733 {
@@ -3413,6 +3427,9 @@ namespace OpenSim.Region.Framework.Scenes
3413 3427
3414 CapsModule.AddCapsHandler(agent.AgentID); 3428 CapsModule.AddCapsHandler(agent.AgentID);
3415 3429
3430 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3431 System.Threading.Thread.Sleep(2000);
3432
3416 if (!agent.child) 3433 if (!agent.child)
3417 { 3434 {
3418 if (TestBorderCross(agent.startpos,Cardinals.E)) 3435 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3471,6 +3488,8 @@ namespace OpenSim.Region.Framework.Scenes
3471 } 3488 }
3472 } 3489 }
3473 // 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);
3474 if (land != null) 3493 if (land != null)
3475 { 3494 {
3476 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3495 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3478,6 +3497,7 @@ namespace OpenSim.Region.Framework.Scenes
3478 agent.startpos = land.LandData.UserLocation; 3497 agent.startpos = land.LandData.UserLocation;
3479 } 3498 }
3480 } 3499 }
3500 */// This is now handled properly in ScenePresence.MakeRootAgent
3481 } 3501 }
3482 3502
3483 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..7ed29a5 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,32 @@ 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 Scene.ForEachScenePresence(delegate (ScenePresence sp)
1374 {
1375 if (sp.ParentID == LocalId)
1272 { 1376 {
1273 if (avatar.ParentID == LocalId) 1377 sp.StandUp();
1274 { 1378 }
1275 avatar.StandUp();
1276 }
1277 1379
1278 if (!silent) 1380 if (!silent)
1279 { 1381 {
1280 part.UpdateFlag = 0; 1382 part.UpdateFlag = 0;
1281 if (part == m_rootPart) 1383 if (part == m_rootPart)
1282 avatar.ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1384 sp.ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1283 } 1385 }
1284 }); 1386 });
1285 } 1387
1286 } 1388 }
1389
1390
1287 } 1391 }
1288 1392
1289 public void AddScriptLPS(int count) 1393 public void AddScriptLPS(int count)
@@ -1308,17 +1412,20 @@ namespace OpenSim.Region.Framework.Scenes
1308 1412
1309 scriptEvents aggregateScriptEvents=0; 1413 scriptEvents aggregateScriptEvents=0;
1310 1414
1311 lock (m_parts) 1415 lockPartsForRead(true);
1312 { 1416 {
1313 foreach (SceneObjectPart part in m_parts.Values) 1417 foreach (SceneObjectPart part in m_parts.Values)
1314 { 1418 {
1419
1315 if (part == null) 1420 if (part == null)
1316 continue; 1421 continue;
1317 if (part != RootPart) 1422 if (part != RootPart)
1318 part.ObjectFlags = objectflagupdate; 1423 part.ObjectFlags = objectflagupdate;
1319 aggregateScriptEvents |= part.AggregateScriptEvents; 1424 aggregateScriptEvents |= part.AggregateScriptEvents;
1425
1320 } 1426 }
1321 } 1427 }
1428 lockPartsForRead(false);
1322 1429
1323 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); 1430 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
1324 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); 1431 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
@@ -1360,42 +1467,52 @@ namespace OpenSim.Region.Framework.Scenes
1360 /// <param name="m_physicalPrim"></param> 1467 /// <param name="m_physicalPrim"></param>
1361 public void ApplyPhysics(bool m_physicalPrim) 1468 public void ApplyPhysics(bool m_physicalPrim)
1362 { 1469 {
1363 lock (m_parts) 1470 lockPartsForRead(true);
1471
1472 if (m_parts.Count > 1)
1364 { 1473 {
1365 if (m_parts.Count > 1) 1474 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1475 lockPartsForRead(false);
1476 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1477 foreach (SceneObjectPart part in values)
1366 { 1478 {
1367 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); 1479
1368 foreach (SceneObjectPart part in m_parts.Values) 1480 if (part.LocalId != m_rootPart.LocalId)
1369 { 1481 {
1370 if (part.LocalId != m_rootPart.LocalId) 1482 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1371 {
1372 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1373 }
1374 } 1483 }
1375 1484
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 } 1485 }
1486 // Hack to get the physics scene geometries in the right spot
1487 ResetChildPrimPhysicsPositions();
1488 }
1489 else
1490 {
1491 lockPartsForRead(false);
1492 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1383 } 1493 }
1384 } 1494 }
1385 1495
1386 public void SetOwnerId(UUID userId) 1496 public void SetOwnerId(UUID userId)
1387 { 1497 {
1388 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1498 ForEachPart(delegate(SceneObjectPart part)
1499 {
1500
1501 part.OwnerID = userId;
1502
1503 });
1389 } 1504 }
1390 1505
1391 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1506 public void ForEachPart(Action<SceneObjectPart> whatToDo)
1392 { 1507 {
1393 lock (m_parts) 1508 lockPartsForRead(true);
1509 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1510 lockPartsForRead(false);
1511 foreach (SceneObjectPart part in values)
1394 { 1512 {
1395 foreach (SceneObjectPart part in m_parts.Values) 1513
1396 { 1514 whatToDo(part);
1397 whatToDo(part); 1515
1398 }
1399 } 1516 }
1400 } 1517 }
1401 1518
@@ -1493,10 +1610,11 @@ namespace OpenSim.Region.Framework.Scenes
1493 RootPart.SendFullUpdate( 1610 RootPart.SendFullUpdate(
1494 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1611 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1495 1612
1496 lock (m_parts) 1613 lockPartsForRead(true);
1497 { 1614 {
1498 foreach (SceneObjectPart part in m_parts.Values) 1615 foreach (SceneObjectPart part in m_parts.Values)
1499 { 1616 {
1617
1500 if (part != RootPart) 1618 if (part != RootPart)
1501 part.SendFullUpdate( 1619 part.SendFullUpdate(
1502 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1620 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
@@ -1570,10 +1688,11 @@ namespace OpenSim.Region.Framework.Scenes
1570 1688
1571 List<SceneObjectPart> partList; 1689 List<SceneObjectPart> partList;
1572 1690
1573 lock (m_parts) 1691 lockPartsForRead(true);
1574 { 1692
1575 partList = new List<SceneObjectPart>(m_parts.Values); 1693 partList = new List<SceneObjectPart>(m_parts.Values);
1576 } 1694
1695 lockPartsForRead(false);
1577 1696
1578 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1697 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1579 { 1698 {
@@ -1796,13 +1915,40 @@ namespace OpenSim.Region.Framework.Scenes
1796 } 1915 }
1797 } 1916 }
1798 1917
1918 public void rotLookAt(Quaternion target, float strength, float damping)
1919 {
1920 SceneObjectPart rootpart = m_rootPart;
1921 if (rootpart != null)
1922 {
1923 if (IsAttachment)
1924 {
1925 /*
1926 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
1927 if (avatar != null)
1928 {
1929 Rotate the Av?
1930 } */
1931 }
1932 else
1933 {
1934 if (rootpart.PhysActor != null)
1935 { // APID must be implemented in your physics system for this to function.
1936 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
1937 rootpart.PhysActor.APIDStrength = strength;
1938 rootpart.PhysActor.APIDDamping = damping;
1939 rootpart.PhysActor.APIDActive = true;
1940 }
1941 }
1942 }
1943 }
1944
1799 public void stopLookAt() 1945 public void stopLookAt()
1800 { 1946 {
1801 SceneObjectPart rootpart = m_rootPart; 1947 SceneObjectPart rootpart = m_rootPart;
1802 if (rootpart != null) 1948 if (rootpart != null)
1803 { 1949 {
1804 if (rootpart.PhysActor != null) 1950 if (rootpart.PhysActor != null)
1805 { 1951 { // APID must be implemented in your physics system for this to function.
1806 rootpart.PhysActor.APIDActive = false; 1952 rootpart.PhysActor.APIDActive = false;
1807 } 1953 }
1808 } 1954 }
@@ -1870,10 +2016,11 @@ namespace OpenSim.Region.Framework.Scenes
1870 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2016 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1871 newPart.SetParent(this); 2017 newPart.SetParent(this);
1872 2018
1873 lock (m_parts) 2019 lockPartsForWrite(true);
1874 { 2020 {
1875 m_parts.Add(newPart.UUID, newPart); 2021 m_parts.Add(newPart.UUID, newPart);
1876 } 2022 }
2023 lockPartsForWrite(false);
1877 2024
1878 SetPartAsNonRoot(newPart); 2025 SetPartAsNonRoot(newPart);
1879 2026
@@ -1936,7 +2083,7 @@ namespace OpenSim.Region.Framework.Scenes
1936 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2083 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1937 // return; 2084 // return;
1938 2085
1939 lock (m_parts) 2086 lockPartsForRead(true);
1940 { 2087 {
1941 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2088 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1942 2089
@@ -1956,9 +2103,12 @@ namespace OpenSim.Region.Framework.Scenes
1956 { 2103 {
1957 if (!IsSelected) 2104 if (!IsSelected)
1958 part.UpdateLookAt(); 2105 part.UpdateLookAt();
2106
1959 part.SendScheduledUpdates(); 2107 part.SendScheduledUpdates();
2108
1960 } 2109 }
1961 } 2110 }
2111 lockPartsForRead(false);
1962 } 2112 }
1963 2113
1964 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2114 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -1967,27 +2117,29 @@ namespace OpenSim.Region.Framework.Scenes
1967 2117
1968 RootPart.AddFullUpdateToAvatar(presence); 2118 RootPart.AddFullUpdateToAvatar(presence);
1969 2119
1970 lock (m_parts) 2120 lockPartsForRead(true);
1971 { 2121 {
1972 foreach (SceneObjectPart part in m_parts.Values) 2122 foreach (SceneObjectPart part in m_parts.Values)
1973 { 2123 {
2124
1974 if (part != RootPart) 2125 if (part != RootPart)
1975 part.AddFullUpdateToAvatar(presence); 2126 part.AddFullUpdateToAvatar(presence);
2127
1976 } 2128 }
1977 } 2129 }
2130 lockPartsForRead(false);
1978 } 2131 }
1979 2132
1980 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2133 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
1981 { 2134 {
1982// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2135 lockPartsForRead(true);
1983 2136
1984 lock (m_parts) 2137 foreach (SceneObjectPart part in m_parts.Values)
1985 { 2138 {
1986 foreach (SceneObjectPart part in m_parts.Values) 2139 part.AddTerseUpdateToAvatar(presence);
1987 {
1988 part.AddTerseUpdateToAvatar(presence);
1989 }
1990 } 2140 }
2141
2142 lockPartsForRead(false);
1991 } 2143 }
1992 2144
1993 /// <summary> 2145 /// <summary>
@@ -2000,14 +2152,17 @@ namespace OpenSim.Region.Framework.Scenes
2000 checkAtTargets(); 2152 checkAtTargets();
2001 RootPart.ScheduleFullUpdate(); 2153 RootPart.ScheduleFullUpdate();
2002 2154
2003 lock (m_parts) 2155 lockPartsForRead(true);
2004 { 2156 {
2005 foreach (SceneObjectPart part in m_parts.Values) 2157 foreach (SceneObjectPart part in m_parts.Values)
2006 { 2158 {
2159
2007 if (part != RootPart) 2160 if (part != RootPart)
2008 part.ScheduleFullUpdate(); 2161 part.ScheduleFullUpdate();
2162
2009 } 2163 }
2010 } 2164 }
2165 lockPartsForRead(false);
2011 } 2166 }
2012 2167
2013 /// <summary> 2168 /// <summary>
@@ -2015,15 +2170,14 @@ namespace OpenSim.Region.Framework.Scenes
2015 /// </summary> 2170 /// </summary>
2016 public void ScheduleGroupForTerseUpdate() 2171 public void ScheduleGroupForTerseUpdate()
2017 { 2172 {
2018// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2173 lockPartsForRead(true);
2019 2174
2020 lock (m_parts) 2175 foreach (SceneObjectPart part in m_parts.Values)
2021 { 2176 {
2022 foreach (SceneObjectPart part in m_parts.Values) 2177 part.ScheduleTerseUpdate();
2023 {
2024 part.ScheduleTerseUpdate();
2025 }
2026 } 2178 }
2179
2180 lockPartsForRead(false);
2027 } 2181 }
2028 2182
2029 /// <summary> 2183 /// <summary>
@@ -2038,14 +2192,17 @@ namespace OpenSim.Region.Framework.Scenes
2038 2192
2039 RootPart.SendFullUpdateToAllClients(); 2193 RootPart.SendFullUpdateToAllClients();
2040 2194
2041 lock (m_parts) 2195 lockPartsForRead(true);
2042 { 2196 {
2043 foreach (SceneObjectPart part in m_parts.Values) 2197 foreach (SceneObjectPart part in m_parts.Values)
2044 { 2198 {
2199
2045 if (part != RootPart) 2200 if (part != RootPart)
2046 part.SendFullUpdateToAllClients(); 2201 part.SendFullUpdateToAllClients();
2202
2047 } 2203 }
2048 } 2204 }
2205 lockPartsForRead(false);
2049 } 2206 }
2050 2207
2051 /// <summary> 2208 /// <summary>
@@ -2077,14 +2234,15 @@ namespace OpenSim.Region.Framework.Scenes
2077 { 2234 {
2078 if (IsDeleted) 2235 if (IsDeleted)
2079 return; 2236 return;
2080 2237
2081 lock (m_parts) 2238 lockPartsForRead(true);
2082 { 2239 {
2083 foreach (SceneObjectPart part in m_parts.Values) 2240 foreach (SceneObjectPart part in m_parts.Values)
2084 { 2241 {
2085 part.SendTerseUpdateToAllClients(); 2242 part.SendTerseUpdateToAllClients();
2086 } 2243 }
2087 } 2244 }
2245 lockPartsForRead(false);
2088 } 2246 }
2089 2247
2090 #endregion 2248 #endregion
@@ -2098,16 +2256,18 @@ namespace OpenSim.Region.Framework.Scenes
2098 /// <returns>null if no child part with that linknum or child part</returns> 2256 /// <returns>null if no child part with that linknum or child part</returns>
2099 public SceneObjectPart GetLinkNumPart(int linknum) 2257 public SceneObjectPart GetLinkNumPart(int linknum)
2100 { 2258 {
2101 lock (m_parts) 2259 lockPartsForRead(true);
2102 { 2260 {
2103 foreach (SceneObjectPart part in m_parts.Values) 2261 foreach (SceneObjectPart part in m_parts.Values)
2104 { 2262 {
2105 if (part.LinkNum == linknum) 2263 if (part.LinkNum == linknum)
2106 { 2264 {
2265 lockPartsForRead(false);
2107 return part; 2266 return part;
2108 } 2267 }
2109 } 2268 }
2110 } 2269 }
2270 lockPartsForRead(false);
2111 2271
2112 return null; 2272 return null;
2113 } 2273 }
@@ -2135,17 +2295,19 @@ namespace OpenSim.Region.Framework.Scenes
2135 public SceneObjectPart GetChildPart(uint localID) 2295 public SceneObjectPart GetChildPart(uint localID)
2136 { 2296 {
2137 //m_log.DebugFormat("Entered looking for {0}", localID); 2297 //m_log.DebugFormat("Entered looking for {0}", localID);
2138 lock (m_parts) 2298 lockPartsForRead(true);
2139 { 2299 {
2140 foreach (SceneObjectPart part in m_parts.Values) 2300 foreach (SceneObjectPart part in m_parts.Values)
2141 { 2301 {
2142 //m_log.DebugFormat("Found {0}", part.LocalId); 2302 //m_log.DebugFormat("Found {0}", part.LocalId);
2143 if (part.LocalId == localID) 2303 if (part.LocalId == localID)
2144 { 2304 {
2305 lockPartsForRead(false);
2145 return part; 2306 return part;
2146 } 2307 }
2147 } 2308 }
2148 } 2309 }
2310 lockPartsForRead(false);
2149 2311
2150 return null; 2312 return null;
2151 } 2313 }
@@ -2175,17 +2337,19 @@ namespace OpenSim.Region.Framework.Scenes
2175 public bool HasChildPrim(uint localID) 2337 public bool HasChildPrim(uint localID)
2176 { 2338 {
2177 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2339 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2178 lock (m_parts) 2340 lockPartsForRead(true);
2179 { 2341 {
2180 foreach (SceneObjectPart part in m_parts.Values) 2342 foreach (SceneObjectPart part in m_parts.Values)
2181 { 2343 {
2182 //m_log.DebugFormat("Found {0}", part.LocalId); 2344 //m_log.DebugFormat("Found {0}", part.LocalId);
2183 if (part.LocalId == localID) 2345 if (part.LocalId == localID)
2184 { 2346 {
2347 lockPartsForRead(false);
2185 return true; 2348 return true;
2186 } 2349 }
2187 } 2350 }
2188 } 2351 }
2352 lockPartsForRead(false);
2189 2353
2190 return false; 2354 return false;
2191 } 2355 }
@@ -2235,53 +2399,57 @@ namespace OpenSim.Region.Framework.Scenes
2235 if (m_rootPart.LinkNum == 0) 2399 if (m_rootPart.LinkNum == 0)
2236 m_rootPart.LinkNum = 1; 2400 m_rootPart.LinkNum = 1;
2237 2401
2238 lock (m_parts) 2402 lockPartsForWrite(true);
2239 { 2403
2240 m_parts.Add(linkPart.UUID, linkPart); 2404 m_parts.Add(linkPart.UUID, linkPart);
2405
2406 lockPartsForWrite(false);
2241 2407
2242 // Insert in terms of link numbers, the new links 2408 // Insert in terms of link numbers, the new links
2243 // before the current ones (with the exception of 2409 // before the current ones (with the exception of
2244 // the root prim. Shuffle the old ones up 2410 // the root prim. Shuffle the old ones up
2245 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2411 lockPartsForRead(true);
2412 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2413 {
2414 if (kvp.Value.LinkNum != 1)
2246 { 2415 {
2247 if (kvp.Value.LinkNum != 1) 2416 // Don't update root prim link number
2248 { 2417 kvp.Value.LinkNum += objectGroup.PrimCount;
2249 // Don't update root prim link number
2250 kvp.Value.LinkNum += objectGroup.PrimCount;
2251 }
2252 } 2418 }
2419 }
2420 lockPartsForRead(false);
2253 2421
2254 linkPart.LinkNum = 2; 2422 linkPart.LinkNum = 2;
2255 2423
2256 linkPart.SetParent(this); 2424 linkPart.SetParent(this);
2257 linkPart.AddFlag(PrimFlags.CreateSelected); 2425 linkPart.AddFlag(PrimFlags.CreateSelected);
2258 2426
2259 //if (linkPart.PhysActor != null) 2427 //if (linkPart.PhysActor != null)
2260 //{ 2428 //{
2261 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2429 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2262 2430
2263 //linkPart.PhysActor = null; 2431 //linkPart.PhysActor = null;
2264 //} 2432 //}
2265 2433
2266 //TODO: rest of parts 2434 //TODO: rest of parts
2267 int linkNum = 3; 2435 int linkNum = 3;
2268 foreach (SceneObjectPart part in objectGroup.Children.Values) 2436 foreach (SceneObjectPart part in objectGroup.Children.Values)
2437 {
2438 if (part.UUID != objectGroup.m_rootPart.UUID)
2269 { 2439 {
2270 if (part.UUID != objectGroup.m_rootPart.UUID) 2440 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2271 {
2272 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2273 }
2274 part.ClearUndoState();
2275 } 2441 }
2442 part.ClearUndoState();
2276 } 2443 }
2277 2444
2278 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2445 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2279 objectGroup.m_isDeleted = true; 2446 objectGroup.m_isDeleted = true;
2447
2448 objectGroup.lockPartsForWrite(true);
2280 2449
2281 lock (objectGroup.m_parts) 2450 objectGroup.m_parts.Clear();
2282 { 2451
2283 objectGroup.m_parts.Clear(); 2452 objectGroup.lockPartsForWrite(false);
2284 }
2285 2453
2286 // Can't do this yet since backup still makes use of the root part without any synchronization 2454 // Can't do this yet since backup still makes use of the root part without any synchronization
2287// objectGroup.m_rootPart = null; 2455// objectGroup.m_rootPart = null;
@@ -2351,11 +2519,12 @@ namespace OpenSim.Region.Framework.Scenes
2351 Quaternion worldRot = linkPart.GetWorldRotation(); 2519 Quaternion worldRot = linkPart.GetWorldRotation();
2352 2520
2353 // Remove the part from this object 2521 // Remove the part from this object
2354 lock (m_parts) 2522 lockPartsForWrite(true);
2355 { 2523 {
2356 m_parts.Remove(linkPart.UUID); 2524 m_parts.Remove(linkPart.UUID);
2357 } 2525 }
2358 2526 lockPartsForWrite(false);
2527 lockPartsForRead(true);
2359 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2528 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2360 RootPart.LinkNum = 0; 2529 RootPart.LinkNum = 0;
2361 else 2530 else
@@ -2366,6 +2535,7 @@ namespace OpenSim.Region.Framework.Scenes
2366 p.LinkNum--; 2535 p.LinkNum--;
2367 } 2536 }
2368 } 2537 }
2538 lockPartsForRead(false);
2369 2539
2370 linkPart.ParentID = 0; 2540 linkPart.ParentID = 0;
2371 linkPart.LinkNum = 0; 2541 linkPart.LinkNum = 0;
@@ -2687,9 +2857,12 @@ namespace OpenSim.Region.Framework.Scenes
2687 2857
2688 if (selectionPart != null) 2858 if (selectionPart != null)
2689 { 2859 {
2690 lock (m_parts) 2860 lockPartsForRead(true);
2861 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2862 lockPartsForRead(false);
2863 foreach (SceneObjectPart part in parts)
2691 { 2864 {
2692 foreach (SceneObjectPart part in m_parts.Values) 2865 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2693 { 2866 {
2694 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2867 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2695 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2868 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2699,12 +2872,13 @@ namespace OpenSim.Region.Framework.Scenes
2699 break; 2872 break;
2700 } 2873 }
2701 } 2874 }
2875 }
2702 2876
2703 foreach (SceneObjectPart part in m_parts.Values) 2877 foreach (SceneObjectPart part in parts)
2704 { 2878 {
2705 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2879 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2706 }
2707 } 2880 }
2881
2708 } 2882 }
2709 } 2883 }
2710 2884
@@ -2790,11 +2964,9 @@ namespace OpenSim.Region.Framework.Scenes
2790 scale.Y = m_scene.m_maxNonphys; 2964 scale.Y = m_scene.m_maxNonphys;
2791 if (scale.Z > m_scene.m_maxNonphys) 2965 if (scale.Z > m_scene.m_maxNonphys)
2792 scale.Z = m_scene.m_maxNonphys; 2966 scale.Z = m_scene.m_maxNonphys;
2793
2794 SceneObjectPart part = GetChildPart(localID); 2967 SceneObjectPart part = GetChildPart(localID);
2795 if (part != null) 2968 if (part != null)
2796 { 2969 {
2797 part.Resize(scale);
2798 if (part.PhysActor != null) 2970 if (part.PhysActor != null)
2799 { 2971 {
2800 if (part.PhysActor.IsPhysical) 2972 if (part.PhysActor.IsPhysical)
@@ -2809,7 +2981,7 @@ namespace OpenSim.Region.Framework.Scenes
2809 part.PhysActor.Size = scale; 2981 part.PhysActor.Size = scale;
2810 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 2982 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2811 } 2983 }
2812 //if (part.UUID != m_rootPart.UUID) 2984 part.Resize(scale);
2813 2985
2814 HasGroupChanged = true; 2986 HasGroupChanged = true;
2815 ScheduleGroupForFullUpdate(); 2987 ScheduleGroupForFullUpdate();
@@ -2851,73 +3023,71 @@ namespace OpenSim.Region.Framework.Scenes
2851 float y = (scale.Y / part.Scale.Y); 3023 float y = (scale.Y / part.Scale.Y);
2852 float z = (scale.Z / part.Scale.Z); 3024 float z = (scale.Z / part.Scale.Z);
2853 3025
2854 lock (m_parts) 3026 lockPartsForRead(true);
3027 if (x > 1.0f || y > 1.0f || z > 1.0f)
2855 { 3028 {
2856 if (x > 1.0f || y > 1.0f || z > 1.0f) 3029 foreach (SceneObjectPart obPart in m_parts.Values)
2857 { 3030 {
2858 foreach (SceneObjectPart obPart in m_parts.Values) 3031 if (obPart.UUID != m_rootPart.UUID)
2859 { 3032 {
2860 if (obPart.UUID != m_rootPart.UUID) 3033 Vector3 oldSize = new Vector3(obPart.Scale);
2861 { 3034 obPart.IgnoreUndoUpdate = true;
2862 obPart.IgnoreUndoUpdate = true;
2863 Vector3 oldSize = new Vector3(obPart.Scale);
2864 3035
2865 float f = 1.0f; 3036 float f = 1.0f;
2866 float a = 1.0f; 3037 float a = 1.0f;
2867 3038
2868 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3039 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3040 {
3041 if (oldSize.X*x > m_scene.m_maxPhys)
2869 { 3042 {
2870 if (oldSize.X*x > m_scene.m_maxPhys) 3043 f = m_scene.m_maxPhys / oldSize.X;
2871 { 3044 a = f / x;
2872 f = m_scene.m_maxPhys / oldSize.X; 3045 x *= a;
2873 a = f / x; 3046 y *= a;
2874 x *= a; 3047 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 } 3048 }
2895 else 3049 if (oldSize.Y*y > m_scene.m_maxPhys)
3050 {
3051 f = m_scene.m_maxPhys / oldSize.Y;
3052 a = f / y;
3053 x *= a;
3054 y *= a;
3055 z *= a;
3056 }
3057 if (oldSize.Z*z > m_scene.m_maxPhys)
3058 {
3059 f = m_scene.m_maxPhys / oldSize.Z;
3060 a = f / z;
3061 x *= a;
3062 y *= a;
3063 z *= a;
3064 }
3065 }
3066 else
3067 {
3068 if (oldSize.X*x > m_scene.m_maxNonphys)
3069 {
3070 f = m_scene.m_maxNonphys / oldSize.X;
3071 a = f / x;
3072 x *= a;
3073 y *= a;
3074 z *= a;
3075 }
3076 if (oldSize.Y*y > m_scene.m_maxNonphys)
2896 { 3077 {
2897 if (oldSize.X*x > m_scene.m_maxNonphys) 3078 f = m_scene.m_maxNonphys / oldSize.Y;
2898 { 3079 a = f / y;
2899 f = m_scene.m_maxNonphys / oldSize.X; 3080 x *= a;
2900 a = f / x; 3081 y *= a;
2901 x *= a; 3082 z *= a;
2902 y *= a; 3083 }
2903 z *= a; 3084 if (oldSize.Z*z > m_scene.m_maxNonphys)
2904 } 3085 {
2905 if (oldSize.Y*y > m_scene.m_maxNonphys) 3086 f = m_scene.m_maxNonphys / oldSize.Z;
2906 { 3087 a = f / z;
2907 f = m_scene.m_maxNonphys / oldSize.Y; 3088 x *= a;
2908 a = f / y; 3089 y *= a;
2909 x *= a; 3090 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 } 3091 }
2922 obPart.IgnoreUndoUpdate = false; 3092 obPart.IgnoreUndoUpdate = false;
2923 obPart.StoreUndoState(); 3093 obPart.StoreUndoState();
@@ -2925,6 +3095,7 @@ namespace OpenSim.Region.Framework.Scenes
2925 } 3095 }
2926 } 3096 }
2927 } 3097 }
3098 lockPartsForRead(false);
2928 3099
2929 Vector3 prevScale = part.Scale; 3100 Vector3 prevScale = part.Scale;
2930 prevScale.X *= x; 3101 prevScale.X *= x;
@@ -2932,7 +3103,7 @@ namespace OpenSim.Region.Framework.Scenes
2932 prevScale.Z *= z; 3103 prevScale.Z *= z;
2933 part.Resize(prevScale); 3104 part.Resize(prevScale);
2934 3105
2935 lock (m_parts) 3106 lockPartsForRead(true);
2936 { 3107 {
2937 foreach (SceneObjectPart obPart in m_parts.Values) 3108 foreach (SceneObjectPart obPart in m_parts.Values)
2938 { 3109 {
@@ -2954,6 +3125,7 @@ namespace OpenSim.Region.Framework.Scenes
2954 obPart.StoreUndoState(); 3125 obPart.StoreUndoState();
2955 } 3126 }
2956 } 3127 }
3128 lockPartsForRead(false);
2957 3129
2958 if (part.PhysActor != null) 3130 if (part.PhysActor != null)
2959 { 3131 {
@@ -3056,7 +3228,7 @@ namespace OpenSim.Region.Framework.Scenes
3056 axDiff *= Quaternion.Inverse(partRotation); 3228 axDiff *= Quaternion.Inverse(partRotation);
3057 diff = axDiff; 3229 diff = axDiff;
3058 3230
3059 lock (m_parts) 3231 lockPartsForRead(true);
3060 { 3232 {
3061 foreach (SceneObjectPart obPart in m_parts.Values) 3233 foreach (SceneObjectPart obPart in m_parts.Values)
3062 { 3234 {
@@ -3066,6 +3238,7 @@ namespace OpenSim.Region.Framework.Scenes
3066 } 3238 }
3067 } 3239 }
3068 } 3240 }
3241 lockPartsForRead(false);
3069 3242
3070 AbsolutePosition = newPos; 3243 AbsolutePosition = newPos;
3071 3244
@@ -3199,25 +3372,25 @@ namespace OpenSim.Region.Framework.Scenes
3199 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3372 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3200 } 3373 }
3201 3374
3202 lock (m_parts) 3375 lockPartsForRead(true);
3376
3377 foreach (SceneObjectPart prim in m_parts.Values)
3203 { 3378 {
3204 foreach (SceneObjectPart prim in m_parts.Values) 3379 if (prim.UUID != m_rootPart.UUID)
3205 { 3380 {
3206 if (prim.UUID != m_rootPart.UUID) 3381 prim.IgnoreUndoUpdate = true;
3207 { 3382 Vector3 axPos = prim.OffsetPosition;
3208 prim.IgnoreUndoUpdate = true; 3383 axPos *= oldParentRot;
3209 Vector3 axPos = prim.OffsetPosition; 3384 axPos *= Quaternion.Inverse(axRot);
3210 axPos *= oldParentRot; 3385 prim.OffsetPosition = axPos;
3211 axPos *= Quaternion.Inverse(axRot); 3386 Quaternion primsRot = prim.RotationOffset;
3212 prim.OffsetPosition = axPos; 3387 Quaternion newRot = primsRot * oldParentRot;
3213 Quaternion primsRot = prim.RotationOffset; 3388 newRot *= Quaternion.Inverse(axRot);
3214 Quaternion newRot = primsRot * oldParentRot; 3389 prim.RotationOffset = newRot;
3215 newRot *= Quaternion.Inverse(axRot); 3390 prim.ScheduleTerseUpdate();
3216 prim.RotationOffset = newRot;
3217 prim.ScheduleTerseUpdate();
3218 }
3219 } 3391 }
3220 } 3392 }
3393
3221 foreach (SceneObjectPart childpart in Children.Values) 3394 foreach (SceneObjectPart childpart in Children.Values)
3222 { 3395 {
3223 if (childpart != m_rootPart) 3396 if (childpart != m_rootPart)
@@ -3226,6 +3399,9 @@ namespace OpenSim.Region.Framework.Scenes
3226 childpart.StoreUndoState(); 3399 childpart.StoreUndoState();
3227 } 3400 }
3228 } 3401 }
3402
3403 lockPartsForRead(false);
3404
3229 m_rootPart.ScheduleTerseUpdate(); 3405 m_rootPart.ScheduleTerseUpdate();
3230 } 3406 }
3231 3407
@@ -3347,7 +3523,7 @@ namespace OpenSim.Region.Framework.Scenes
3347 if (atTargets.Count > 0) 3523 if (atTargets.Count > 0)
3348 { 3524 {
3349 uint[] localids = new uint[0]; 3525 uint[] localids = new uint[0];
3350 lock (m_parts) 3526 lockPartsForRead(true);
3351 { 3527 {
3352 localids = new uint[m_parts.Count]; 3528 localids = new uint[m_parts.Count];
3353 int cntr = 0; 3529 int cntr = 0;
@@ -3357,6 +3533,7 @@ namespace OpenSim.Region.Framework.Scenes
3357 cntr++; 3533 cntr++;
3358 } 3534 }
3359 } 3535 }
3536 lockPartsForRead(false);
3360 3537
3361 for (int ctr = 0; ctr < localids.Length; ctr++) 3538 for (int ctr = 0; ctr < localids.Length; ctr++)
3362 { 3539 {
@@ -3375,7 +3552,7 @@ namespace OpenSim.Region.Framework.Scenes
3375 { 3552 {
3376 //trigger not_at_target 3553 //trigger not_at_target
3377 uint[] localids = new uint[0]; 3554 uint[] localids = new uint[0];
3378 lock (m_parts) 3555 lockPartsForRead(true);
3379 { 3556 {
3380 localids = new uint[m_parts.Count]; 3557 localids = new uint[m_parts.Count];
3381 int cntr = 0; 3558 int cntr = 0;
@@ -3385,7 +3562,8 @@ namespace OpenSim.Region.Framework.Scenes
3385 cntr++; 3562 cntr++;
3386 } 3563 }
3387 } 3564 }
3388 3565 lockPartsForRead(false);
3566
3389 for (int ctr = 0; ctr < localids.Length; ctr++) 3567 for (int ctr = 0; ctr < localids.Length; ctr++)
3390 { 3568 {
3391 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3569 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3477,19 +3655,20 @@ namespace OpenSim.Region.Framework.Scenes
3477 public float GetMass() 3655 public float GetMass()
3478 { 3656 {
3479 float retmass = 0f; 3657 float retmass = 0f;
3480 lock (m_parts) 3658 lockPartsForRead(true);
3481 { 3659 {
3482 foreach (SceneObjectPart part in m_parts.Values) 3660 foreach (SceneObjectPart part in m_parts.Values)
3483 { 3661 {
3484 retmass += part.GetMass(); 3662 retmass += part.GetMass();
3485 } 3663 }
3486 } 3664 }
3665 lockPartsForRead(false);
3487 return retmass; 3666 return retmass;
3488 } 3667 }
3489 3668
3490 public void CheckSculptAndLoad() 3669 public void CheckSculptAndLoad()
3491 { 3670 {
3492 lock (m_parts) 3671 lockPartsForRead(true);
3493 { 3672 {
3494 if (!IsDeleted) 3673 if (!IsDeleted)
3495 { 3674 {
@@ -3514,6 +3693,7 @@ namespace OpenSim.Region.Framework.Scenes
3514 } 3693 }
3515 } 3694 }
3516 } 3695 }
3696 lockPartsForRead(false);
3517 } 3697 }
3518 3698
3519 protected void AssetReceived(string id, Object sender, AssetBase asset) 3699 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3534,7 +3714,7 @@ namespace OpenSim.Region.Framework.Scenes
3534 /// <param name="client"></param> 3714 /// <param name="client"></param>
3535 public void SetGroup(UUID GroupID, IClientAPI client) 3715 public void SetGroup(UUID GroupID, IClientAPI client)
3536 { 3716 {
3537 lock (m_parts) 3717 lockPartsForRead(true);
3538 { 3718 {
3539 foreach (SceneObjectPart part in m_parts.Values) 3719 foreach (SceneObjectPart part in m_parts.Values)
3540 { 3720 {
@@ -3544,6 +3724,7 @@ namespace OpenSim.Region.Framework.Scenes
3544 3724
3545 HasGroupChanged = true; 3725 HasGroupChanged = true;
3546 } 3726 }
3727 lockPartsForRead(false);
3547 3728
3548 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3729 // 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. 3730 // for the same object with very different properties. The caller must schedule the update.
@@ -3565,11 +3746,12 @@ namespace OpenSim.Region.Framework.Scenes
3565 3746
3566 public void SetAttachmentPoint(byte point) 3747 public void SetAttachmentPoint(byte point)
3567 { 3748 {
3568 lock (m_parts) 3749 lockPartsForRead(true);
3569 { 3750 {
3570 foreach (SceneObjectPart part in m_parts.Values) 3751 foreach (SceneObjectPart part in m_parts.Values)
3571 part.SetAttachmentPoint(point); 3752 part.SetAttachmentPoint(point);
3572 } 3753 }
3754 lockPartsForRead(false);
3573 } 3755 }
3574 3756
3575 #region ISceneObject 3757 #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 }