aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs29
-rw-r--r--OpenSim/Region/Framework/Scenes/EntityManager.cs79
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs44
-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.cs547
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs103
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs592
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs570
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs11
15 files changed, 1301 insertions, 762 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
index 78bd622..7312799 100644
--- a/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/IRegionDataStore.cs
@@ -103,6 +103,8 @@ namespace OpenSim.Region.Framework.Interfaces
103 103
104 void StoreRegionSettings(RegionSettings rs); 104 void StoreRegionSettings(RegionSettings rs);
105 RegionSettings LoadRegionSettings(UUID regionUUID); 105 RegionSettings LoadRegionSettings(UUID regionUUID);
106 RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID);
107 void StoreRegionWindlightSettings(RegionMeta7WindlightData wl);
106 108
107 void Shutdown(); 109 void Shutdown();
108 } 110 }
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 7307662..fd7d44f 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -53,8 +53,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
53 { 53 {
54 get { return m_movementAnimation; } 54 get { return m_movementAnimation; }
55 } 55 }
56 protected string m_movementAnimation = "DEFAULT"; 56 // protected string m_movementAnimation = "DEFAULT"; //KF: 'DEFAULT' does not exist!
57 57 protected string m_movementAnimation = "CROUCH"; //KF: CROUCH ensures reliable Av Anim. init.
58 private int m_animTickFall; 58 private int m_animTickFall;
59 private int m_animTickJump; 59 private int m_animTickJump;
60 60
@@ -123,17 +123,22 @@ namespace OpenSim.Region.Framework.Scenes.Animation
123 /// </summary> 123 /// </summary>
124 public void TrySetMovementAnimation(string anim) 124 public void TrySetMovementAnimation(string anim)
125 { 125 {
126 //m_log.DebugFormat("Updating movement animation to {0}", anim); 126//Console.WriteLine("Updating movement animation to {0}", anim);
127 127
128 if (!m_scenePresence.IsChildAgent) 128 if (!m_scenePresence.IsChildAgent)
129 { 129 {
130 if (m_animations.TrySetDefaultAnimation( 130 if (m_animations.TrySetDefaultAnimation(
131 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID)) 131 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID))
132 { 132 {
133//Console.WriteLine("TSMA {0} success.", anim);
133 // 16384 is CHANGED_ANIMATION 134 // 16384 is CHANGED_ANIMATION
134 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { 16384 }); 135 m_scenePresence.SendScriptEventToAttachments("changed", new Object[] { 16384 });
135 SendAnimPack(); 136 SendAnimPack();
136 } 137 }
138 else
139 {
140//Console.WriteLine("TSMA {0} fail.", anim);
141 }
137 } 142 }
138 } 143 }
139 144
@@ -146,10 +151,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
146 const float PREJUMP_DELAY = 0.25f; 151 const float PREJUMP_DELAY = 0.25f;
147 152
148 #region Inputs 153 #region Inputs
149 if (m_scenePresence.SitGround) 154
150 {
151 return "SIT_GROUND_CONSTRAINED";
152 }
153 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; 155 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
154 PhysicsActor actor = m_scenePresence.PhysicsActor; 156 PhysicsActor actor = m_scenePresence.PhysicsActor;
155 157
@@ -159,11 +161,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
159 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); 161 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
160 162
161 // Check control flags 163 // Check control flags
162 bool heldForward = 164 bool heldForward = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS);
163 (((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) || ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS)); 165 bool heldBack = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG);
164 bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG; 166 bool heldLeft = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS);
165 bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS; 167 bool heldRight = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG);
166 bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG;
167 //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; 168 //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
168 //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; 169 //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
169 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; 170 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
@@ -316,7 +317,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
316 public void UpdateMovementAnimations() 317 public void UpdateMovementAnimations()
317 { 318 {
318 m_movementAnimation = GetMovementAnimation(); 319 m_movementAnimation = GetMovementAnimation();
319 320//Console.WriteLine("UMA got {0}", m_movementAnimation);
320 if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump) 321 if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump)
321 { 322 {
322 // This was the previous behavior before PREJUMP 323 // This was the previous behavior before PREJUMP
@@ -451,4 +452,4 @@ namespace OpenSim.Region.Framework.Scenes.Animation
451 m_scenePresence = null; 452 m_scenePresence = null;
452 } 453 }
453 } 454 }
454} \ No newline at end of file 455}
diff --git a/OpenSim/Region/Framework/Scenes/EntityManager.cs b/OpenSim/Region/Framework/Scenes/EntityManager.cs
index 099fcce..c246e32 100644
--- a/OpenSim/Region/Framework/Scenes/EntityManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EntityManager.cs
@@ -40,7 +40,7 @@ namespace OpenSim.Region.Framework.Scenes
40 private readonly Dictionary<UUID,EntityBase> m_eb_uuid = new Dictionary<UUID, EntityBase>(); 40 private readonly Dictionary<UUID,EntityBase> m_eb_uuid = new Dictionary<UUID, EntityBase>();
41 private readonly Dictionary<uint, EntityBase> m_eb_localID = new Dictionary<uint, EntityBase>(); 41 private readonly Dictionary<uint, EntityBase> m_eb_localID = new Dictionary<uint, EntityBase>();
42 //private readonly Dictionary<UUID, ScenePresence> m_pres_uuid = new Dictionary<UUID, ScenePresence>(); 42 //private readonly Dictionary<UUID, ScenePresence> m_pres_uuid = new Dictionary<UUID, ScenePresence>();
43 private readonly Object m_lock = new Object(); 43 private System.Threading.ReaderWriterLockSlim m_lock = new System.Threading.ReaderWriterLockSlim();
44 44
45 [Obsolete("Use Add() instead.")] 45 [Obsolete("Use Add() instead.")]
46 public void Add(UUID id, EntityBase eb) 46 public void Add(UUID id, EntityBase eb)
@@ -50,7 +50,8 @@ namespace OpenSim.Region.Framework.Scenes
50 50
51 public void Add(EntityBase entity) 51 public void Add(EntityBase entity)
52 { 52 {
53 lock (m_lock) 53 m_lock.EnterWriteLock();
54 try
54 { 55 {
55 try 56 try
56 { 57 {
@@ -62,11 +63,16 @@ namespace OpenSim.Region.Framework.Scenes
62 m_log.ErrorFormat("Add Entity failed: {0}", e.Message); 63 m_log.ErrorFormat("Add Entity failed: {0}", e.Message);
63 } 64 }
64 } 65 }
66 finally
67 {
68 m_lock.ExitWriteLock();
69 }
65 } 70 }
66 71
67 public void InsertOrReplace(EntityBase entity) 72 public void InsertOrReplace(EntityBase entity)
68 { 73 {
69 lock (m_lock) 74 m_lock.EnterWriteLock();
75 try
70 { 76 {
71 try 77 try
72 { 78 {
@@ -78,15 +84,24 @@ namespace OpenSim.Region.Framework.Scenes
78 m_log.ErrorFormat("Insert or Replace Entity failed: {0}", e.Message); 84 m_log.ErrorFormat("Insert or Replace Entity failed: {0}", e.Message);
79 } 85 }
80 } 86 }
87 finally
88 {
89 m_lock.ExitWriteLock();
90 }
81 } 91 }
82 92
83 public void Clear() 93 public void Clear()
84 { 94 {
85 lock (m_lock) 95 m_lock.EnterWriteLock();
96 try
86 { 97 {
87 m_eb_uuid.Clear(); 98 m_eb_uuid.Clear();
88 m_eb_localID.Clear(); 99 m_eb_localID.Clear();
89 } 100 }
101 finally
102 {
103 m_lock.ExitWriteLock();
104 }
90 } 105 }
91 106
92 public int Count 107 public int Count
@@ -123,7 +138,8 @@ namespace OpenSim.Region.Framework.Scenes
123 138
124 public bool Remove(uint localID) 139 public bool Remove(uint localID)
125 { 140 {
126 lock (m_lock) 141 m_lock.EnterWriteLock();
142 try
127 { 143 {
128 try 144 try
129 { 145 {
@@ -141,11 +157,16 @@ namespace OpenSim.Region.Framework.Scenes
141 return false; 157 return false;
142 } 158 }
143 } 159 }
160 finally
161 {
162 m_lock.ExitWriteLock();
163 }
144 } 164 }
145 165
146 public bool Remove(UUID id) 166 public bool Remove(UUID id)
147 { 167 {
148 lock (m_lock) 168 m_lock.EnterWriteLock();
169 try
149 { 170 {
150 try 171 try
151 { 172 {
@@ -163,13 +184,18 @@ namespace OpenSim.Region.Framework.Scenes
163 return false; 184 return false;
164 } 185 }
165 } 186 }
187 finally
188 {
189 m_lock.ExitWriteLock();
190 }
166 } 191 }
167 192
168 public List<EntityBase> GetAllByType<T>() 193 public List<EntityBase> GetAllByType<T>()
169 { 194 {
170 List<EntityBase> tmp = new List<EntityBase>(); 195 List<EntityBase> tmp = new List<EntityBase>();
171 196
172 lock (m_lock) 197 m_lock.EnterReadLock();
198 try
173 { 199 {
174 try 200 try
175 { 201 {
@@ -187,23 +213,33 @@ namespace OpenSim.Region.Framework.Scenes
187 tmp = null; 213 tmp = null;
188 } 214 }
189 } 215 }
216 finally
217 {
218 m_lock.ExitReadLock();
219 }
190 220
191 return tmp; 221 return tmp;
192 } 222 }
193 223
194 public List<EntityBase> GetEntities() 224 public List<EntityBase> GetEntities()
195 { 225 {
196 lock (m_lock) 226 m_lock.EnterReadLock();
227 try
197 { 228 {
198 return new List<EntityBase>(m_eb_uuid.Values); 229 return new List<EntityBase>(m_eb_uuid.Values);
199 } 230 }
231 finally
232 {
233 m_lock.ExitReadLock();
234 }
200 } 235 }
201 236
202 public EntityBase this[UUID id] 237 public EntityBase this[UUID id]
203 { 238 {
204 get 239 get
205 { 240 {
206 lock (m_lock) 241 m_lock.EnterReadLock();
242 try
207 { 243 {
208 EntityBase entity; 244 EntityBase entity;
209 if (m_eb_uuid.TryGetValue(id, out entity)) 245 if (m_eb_uuid.TryGetValue(id, out entity))
@@ -211,6 +247,10 @@ namespace OpenSim.Region.Framework.Scenes
211 else 247 else
212 return null; 248 return null;
213 } 249 }
250 finally
251 {
252 m_lock.ExitReadLock();
253 }
214 } 254 }
215 set 255 set
216 { 256 {
@@ -222,7 +262,8 @@ namespace OpenSim.Region.Framework.Scenes
222 { 262 {
223 get 263 get
224 { 264 {
225 lock (m_lock) 265 m_lock.EnterReadLock();
266 try
226 { 267 {
227 EntityBase entity; 268 EntityBase entity;
228 if (m_eb_localID.TryGetValue(localID, out entity)) 269 if (m_eb_localID.TryGetValue(localID, out entity))
@@ -230,6 +271,10 @@ namespace OpenSim.Region.Framework.Scenes
230 else 271 else
231 return null; 272 return null;
232 } 273 }
274 finally
275 {
276 m_lock.ExitReadLock();
277 }
233 } 278 }
234 set 279 set
235 { 280 {
@@ -239,18 +284,28 @@ namespace OpenSim.Region.Framework.Scenes
239 284
240 public bool TryGetValue(UUID key, out EntityBase obj) 285 public bool TryGetValue(UUID key, out EntityBase obj)
241 { 286 {
242 lock (m_lock) 287 m_lock.EnterReadLock();
288 try
243 { 289 {
244 return m_eb_uuid.TryGetValue(key, out obj); 290 return m_eb_uuid.TryGetValue(key, out obj);
245 } 291 }
292 finally
293 {
294 m_lock.ExitReadLock();
295 }
246 } 296 }
247 297
248 public bool TryGetValue(uint key, out EntityBase obj) 298 public bool TryGetValue(uint key, out EntityBase obj)
249 { 299 {
250 lock (m_lock) 300 m_lock.EnterReadLock();
301 try
251 { 302 {
252 return m_eb_localID.TryGetValue(key, out obj); 303 return m_eb_localID.TryGetValue(key, out obj);
253 } 304 }
305 finally
306 {
307 m_lock.ExitReadLock();
308 }
254 } 309 }
255 310
256 /// <summary> 311 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index f0d346f..1650946 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -206,7 +206,11 @@ namespace OpenSim.Region.Framework.Scenes
206 public event OnMakeChildAgentDelegate OnMakeChildAgent; 206 public event OnMakeChildAgentDelegate OnMakeChildAgent;
207 207
208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence); 208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence);
209 public delegate void OnSaveNewWindlightProfileDelegate();
210 public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionMeta7WindlightData wl, UUID user);
209 public event OnMakeRootAgentDelegate OnMakeRootAgent; 211 public event OnMakeRootAgentDelegate OnMakeRootAgent;
212 public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted;
213 public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile;
210 214
211 /// <summary> 215 /// <summary>
212 /// Triggered when an object or attachment enters a scene 216 /// Triggered when an object or attachment enters a scene
@@ -1216,6 +1220,24 @@ namespace OpenSim.Region.Framework.Scenes
1216 } 1220 }
1217 } 1221 }
1218 1222
1223 public void TriggerOnSendNewWindlightProfileTargeted(RegionMeta7WindlightData wl, UUID user)
1224 {
1225 OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted;
1226 if (handlerSendNewWindlightProfileTargeted != null)
1227 {
1228 handlerSendNewWindlightProfileTargeted(wl, user);
1229 }
1230 }
1231
1232 public void TriggerOnSaveNewWindlightProfile()
1233 {
1234 OnSaveNewWindlightProfileDelegate handlerSaveNewWindlightProfile = OnSaveNewWindlightProfile;
1235 if (handlerSaveNewWindlightProfile != null)
1236 {
1237 handlerSaveNewWindlightProfile();
1238 }
1239 }
1240
1219 public void TriggerOnMakeRootAgent(ScenePresence presence) 1241 public void TriggerOnMakeRootAgent(ScenePresence presence)
1220 { 1242 {
1221 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent; 1243 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent;
@@ -1992,4 +2014,4 @@ namespace OpenSim.Region.Framework.Scenes
1992 } 2014 }
1993 } 2015 }
1994 } 2016 }
1995} \ No newline at end of file 2017}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index dad0efd..eb51019 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 30c69a8..388bc99 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); 609 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID);
@@ -980,6 +982,15 @@ namespace OpenSim.Region.Framework.Scenes
980 /// <param name="seconds">float indicating duration before restart.</param> 982 /// <param name="seconds">float indicating duration before restart.</param>
981 public virtual void Restart(float seconds) 983 public virtual void Restart(float seconds)
982 { 984 {
985 Restart(seconds, true);
986 }
987
988 /// <summary>
989 /// Given float seconds, this will restart the region. showDialog will optionally alert the users.
990 /// </summary>
991 /// <param name="seconds">float indicating duration before restart.</param>
992 public virtual void Restart(float seconds, bool showDialog)
993 {
983 // notifications are done in 15 second increments 994 // notifications are done in 15 second increments
984 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request 995 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request
985 // It's a 'Cancel restart' request. 996 // It's a 'Cancel restart' request.
@@ -1000,8 +1011,11 @@ namespace OpenSim.Region.Framework.Scenes
1000 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); 1011 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed);
1001 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); 1012 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes");
1002 m_restartTimer.Start(); 1013 m_restartTimer.Start();
1003 m_dialogModule.SendNotificationToUsersInRegion( 1014 if (showDialog)
1015 {
1016 m_dialogModule.SendNotificationToUsersInRegion(
1004 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); 1017 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0)));
1018 }
1005 } 1019 }
1006 } 1020 }
1007 1021
@@ -1279,16 +1293,16 @@ namespace OpenSim.Region.Framework.Scenes
1279 // Check if any objects have reached their targets 1293 // Check if any objects have reached their targets
1280 CheckAtTargets(); 1294 CheckAtTargets();
1281 1295
1282 // Update SceneObjectGroups that have scheduled themselves for updates
1283 // Objects queue their updates onto all scene presences
1284 if (m_frame % m_update_objects == 0)
1285 m_sceneGraph.UpdateObjectGroups();
1286
1287 // Run through all ScenePresences looking for updates 1296 // Run through all ScenePresences looking for updates
1288 // Presence updates and queued object updates for each presence are sent to clients 1297 // Presence updates and queued object updates for each presence are sent to clients
1289 if (m_frame % m_update_presences == 0) 1298 if (m_frame % m_update_presences == 0)
1290 m_sceneGraph.UpdatePresences(); 1299 m_sceneGraph.UpdatePresences();
1291 1300
1301 // Update SceneObjectGroups that have scheduled themselves for updates
1302 // Objects queue their updates onto all scene presences
1303 if (m_frame % m_update_objects == 0)
1304 m_sceneGraph.UpdateObjectGroups();
1305
1292 int tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1306 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1293 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1307 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1294 m_sceneGraph.UpdatePreparePhysics(); 1308 m_sceneGraph.UpdatePreparePhysics();
@@ -1599,6 +1613,19 @@ namespace OpenSim.Region.Framework.Scenes
1599 public void SaveTerrain() 1613 public void SaveTerrain()
1600 { 1614 {
1601 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1615 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1616 }
1617
1618 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1619 {
1620 m_regInfo.WindlightSettings = wl;
1621 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
1622 m_eventManager.TriggerOnSaveNewWindlightProfile();
1623 }
1624
1625 public void LoadWindlightProfile()
1626 {
1627 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1628 m_eventManager.TriggerOnSaveNewWindlightProfile();
1602 } 1629 }
1603 1630
1604 /// <summary> 1631 /// <summary>
@@ -3271,6 +3298,9 @@ namespace OpenSim.Region.Framework.Scenes
3271 3298
3272 CapsModule.AddCapsHandler(agent.AgentID); 3299 CapsModule.AddCapsHandler(agent.AgentID);
3273 3300
3301 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3302 System.Threading.Thread.Sleep(2000);
3303
3274 if (!agent.child) 3304 if (!agent.child)
3275 { 3305 {
3276 if (TestBorderCross(agent.startpos,Cardinals.E)) 3306 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3329,6 +3359,7 @@ namespace OpenSim.Region.Framework.Scenes
3329 } 3359 }
3330 } 3360 }
3331 // Honor parcel landing type and position. 3361 // Honor parcel landing type and position.
3362 /*
3332 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 3363 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3333 if (land != null) 3364 if (land != null)
3334 { 3365 {
@@ -3337,6 +3368,7 @@ namespace OpenSim.Region.Framework.Scenes
3337 agent.startpos = land.LandData.UserLocation; 3368 agent.startpos = land.LandData.UserLocation;
3338 } 3369 }
3339 } 3370 }
3371 */// This is now handled properly in ScenePresence.MakeRootAgent
3340 } 3372 }
3341 3373
3342 agent.teleportFlags = teleportFlags; 3374 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 380722d..4e41b07 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -223,6 +223,30 @@ namespace OpenSim.Region.Framework.Scenes
223 protected internal bool AddRestoredSceneObject( 223 protected internal bool AddRestoredSceneObject(
224 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted) 224 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
225 { 225 {
226 // KF: Check for out-of-region, move inside and make static.
227 Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X,
228 sceneObject.RootPart.GroupPosition.Y,
229 sceneObject.RootPart.GroupPosition.Z);
230 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 ||
231 npos.X > Constants.RegionSize ||
232 npos.Y > Constants.RegionSize))
233 {
234 if (npos.X < 0.0) npos.X = 1.0f;
235 if (npos.Y < 0.0) npos.Y = 1.0f;
236 if (npos.Z < 0.0) npos.Z = 0.0f;
237 if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f;
238 if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f;
239
240 foreach (SceneObjectPart part in sceneObject.Children.Values)
241 {
242 part.GroupPosition = npos;
243 }
244 sceneObject.RootPart.Velocity = Vector3.Zero;
245 sceneObject.RootPart.AngularVelocity = Vector3.Zero;
246 sceneObject.RootPart.Acceleration = Vector3.Zero;
247 sceneObject.RootPart.Velocity = Vector3.Zero;
248 }
249
226 if (!alreadyPersisted) 250 if (!alreadyPersisted)
227 { 251 {
228 sceneObject.ForceInventoryPersistence(); 252 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 37b4fd6..8c5a9a6 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,16 +377,15 @@ 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
312 { 385 foreach (SceneObjectPart part in m_parts.Values)
313 foreach (SceneObjectPart part in m_parts.Values) 386 part.GroupPosition = val;
314 { 387
315 part.GroupPosition = val; 388 lockPartsForRead(false);
316 }
317 }
318 389
319 //if (m_rootPart.PhysActor != null) 390 //if (m_rootPart.PhysActor != null)
320 //{ 391 //{
@@ -504,13 +575,16 @@ namespace OpenSim.Region.Framework.Scenes
504 575
505 public void SetFromItemID(UUID AssetId) 576 public void SetFromItemID(UUID AssetId)
506 { 577 {
507 lock (m_parts) 578 lockPartsForRead(true);
508 { 579 {
509 foreach (SceneObjectPart part in m_parts.Values) 580 foreach (SceneObjectPart part in m_parts.Values)
510 { 581 {
582
511 part.FromItemID = AssetId; 583 part.FromItemID = AssetId;
584
512 } 585 }
513 } 586 }
587 lockPartsForRead(false);
514 } 588 }
515 589
516 public UUID GetFromItemID() 590 public UUID GetFromItemID()
@@ -579,10 +653,11 @@ namespace OpenSim.Region.Framework.Scenes
579 Vector3 maxScale = Vector3.Zero; 653 Vector3 maxScale = Vector3.Zero;
580 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); 654 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
581 655
582 lock (m_parts) 656 lockPartsForRead(true);
583 { 657 {
584 foreach (SceneObjectPart part in m_parts.Values) 658 foreach (SceneObjectPart part in m_parts.Values)
585 { 659 {
660
586 Vector3 partscale = part.Scale; 661 Vector3 partscale = part.Scale;
587 Vector3 partoffset = part.OffsetPosition; 662 Vector3 partoffset = part.OffsetPosition;
588 663
@@ -593,8 +668,11 @@ namespace OpenSim.Region.Framework.Scenes
593 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X; 668 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; 669 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; 670 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
671
596 } 672 }
597 } 673 }
674 lockPartsForRead(false);
675
598 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; 676 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
599 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; 677 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
600 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; 678 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
@@ -610,10 +688,11 @@ namespace OpenSim.Region.Framework.Scenes
610 688
611 EntityIntersection result = new EntityIntersection(); 689 EntityIntersection result = new EntityIntersection();
612 690
613 lock (m_parts) 691 lockPartsForRead(true);
614 { 692 {
615 foreach (SceneObjectPart part in m_parts.Values) 693 foreach (SceneObjectPart part in m_parts.Values)
616 { 694 {
695
617 // Temporary commented to stop compiler warning 696 // Temporary commented to stop compiler warning
618 //Vector3 partPosition = 697 //Vector3 partPosition =
619 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); 698 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
@@ -641,8 +720,10 @@ namespace OpenSim.Region.Framework.Scenes
641 result.distance = inter.distance; 720 result.distance = inter.distance;
642 } 721 }
643 } 722 }
723
644 } 724 }
645 } 725 }
726 lockPartsForRead(false);
646 return result; 727 return result;
647 } 728 }
648 729
@@ -655,10 +736,11 @@ namespace OpenSim.Region.Framework.Scenes
655 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) 736 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
656 { 737 {
657 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f; 738 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f;
658 lock (m_parts) 739 lockPartsForRead(true);
659 { 740 {
660 foreach (SceneObjectPart part in m_parts.Values) 741 foreach (SceneObjectPart part in m_parts.Values)
661 { 742 {
743
662 Vector3 worldPos = part.GetWorldPosition(); 744 Vector3 worldPos = part.GetWorldPosition();
663 Vector3 offset = worldPos - AbsolutePosition; 745 Vector3 offset = worldPos - AbsolutePosition;
664 Quaternion worldRot; 746 Quaternion worldRot;
@@ -717,6 +799,8 @@ namespace OpenSim.Region.Framework.Scenes
717 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 799 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
718 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 800 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
719 801
802
803
720 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); 804 //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); 805 //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); 806 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
@@ -888,6 +972,7 @@ namespace OpenSim.Region.Framework.Scenes
888 minZ = backBottomLeft.Z; 972 minZ = backBottomLeft.Z;
889 } 973 }
890 } 974 }
975 lockPartsForRead(false);
891 976
892 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); 977 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
893 978
@@ -916,17 +1001,20 @@ namespace OpenSim.Region.Framework.Scenes
916 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1001 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
917 1002
918 // Capture script state while holding the lock 1003 // Capture script state while holding the lock
919 lock (m_parts) 1004 lockPartsForRead(true);
920 { 1005 {
921 foreach (SceneObjectPart part in m_parts.Values) 1006 foreach (SceneObjectPart part in m_parts.Values)
922 { 1007 {
1008
923 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); 1009 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates();
924 foreach (UUID itemid in pstates.Keys) 1010 foreach (UUID itemid in pstates.Keys)
925 { 1011 {
926 states.Add(itemid, pstates[itemid]); 1012 states.Add(itemid, pstates[itemid]);
927 } 1013 }
1014
928 } 1015 }
929 } 1016 }
1017 lockPartsForRead(false);
930 1018
931 if (states.Count > 0) 1019 if (states.Count > 0)
932 { 1020 {
@@ -1094,13 +1182,16 @@ namespace OpenSim.Region.Framework.Scenes
1094 1182
1095 public override void UpdateMovement() 1183 public override void UpdateMovement()
1096 { 1184 {
1097 lock (m_parts) 1185 lockPartsForRead(true);
1098 { 1186 {
1099 foreach (SceneObjectPart part in m_parts.Values) 1187 foreach (SceneObjectPart part in m_parts.Values)
1100 { 1188 {
1189
1101 part.UpdateMovement(); 1190 part.UpdateMovement();
1191
1102 } 1192 }
1103 } 1193 }
1194 lockPartsForRead(false);
1104 } 1195 }
1105 1196
1106 public ushort GetTimeDilation() 1197 public ushort GetTimeDilation()
@@ -1144,7 +1235,7 @@ namespace OpenSim.Region.Framework.Scenes
1144 /// <param name="part"></param> 1235 /// <param name="part"></param>
1145 public void AddPart(SceneObjectPart part) 1236 public void AddPart(SceneObjectPart part)
1146 { 1237 {
1147 lock (m_parts) 1238 lockPartsForWrite(true);
1148 { 1239 {
1149 part.SetParent(this); 1240 part.SetParent(this);
1150 m_parts.Add(part.UUID, part); 1241 m_parts.Add(part.UUID, part);
@@ -1154,6 +1245,7 @@ namespace OpenSim.Region.Framework.Scenes
1154 if (part.LinkNum == 2 && RootPart != null) 1245 if (part.LinkNum == 2 && RootPart != null)
1155 RootPart.LinkNum = 1; 1246 RootPart.LinkNum = 1;
1156 } 1247 }
1248 lockPartsForWrite(false);
1157 } 1249 }
1158 1250
1159 /// <summary> 1251 /// <summary>
@@ -1161,28 +1253,33 @@ namespace OpenSim.Region.Framework.Scenes
1161 /// </summary> 1253 /// </summary>
1162 private void UpdateParentIDs() 1254 private void UpdateParentIDs()
1163 { 1255 {
1164 lock (m_parts) 1256 lockPartsForRead(true);
1165 { 1257 {
1166 foreach (SceneObjectPart part in m_parts.Values) 1258 foreach (SceneObjectPart part in m_parts.Values)
1167 { 1259 {
1260
1168 if (part.UUID != m_rootPart.UUID) 1261 if (part.UUID != m_rootPart.UUID)
1169 { 1262 {
1170 part.ParentID = m_rootPart.LocalId; 1263 part.ParentID = m_rootPart.LocalId;
1171 } 1264 }
1265
1172 } 1266 }
1173 } 1267 }
1268 lockPartsForRead(false);
1174 } 1269 }
1175 1270
1176 public void RegenerateFullIDs() 1271 public void RegenerateFullIDs()
1177 { 1272 {
1178 lock (m_parts) 1273 lockPartsForRead(true);
1179 { 1274 {
1180 foreach (SceneObjectPart part in m_parts.Values) 1275 foreach (SceneObjectPart part in m_parts.Values)
1181 { 1276 {
1277
1182 part.UUID = UUID.Random(); 1278 part.UUID = UUID.Random();
1183 1279
1184 } 1280 }
1185 } 1281 }
1282 lockPartsForRead(false);
1186 } 1283 }
1187 1284
1188 // helper provided for parts. 1285 // helper provided for parts.
@@ -1263,29 +1360,33 @@ namespace OpenSim.Region.Framework.Scenes
1263 1360
1264 DetachFromBackup(); 1361 DetachFromBackup();
1265 1362
1266 lock (m_parts) 1363 lockPartsForRead(true);
1364 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1365 lockPartsForRead(false);
1366
1367 foreach (SceneObjectPart part in values)
1267 { 1368 {
1268 foreach (SceneObjectPart part in m_parts.Values)
1269 {
1270// part.Inventory.RemoveScriptInstances(); 1369// part.Inventory.RemoveScriptInstances();
1271 1370
1272 ScenePresence[] avatars = Scene.GetScenePresences(); 1371 ScenePresence[] avatars = Scene.GetScenePresences();
1273 for (int i = 0; i < avatars.Length; i++) 1372 for (int i = 0; i < avatars.Length; i++)
1373 {
1374 if (avatars[i].ParentID == LocalId)
1274 { 1375 {
1275 if (avatars[i].ParentID == LocalId) 1376 avatars[i].StandUp();
1276 { 1377 }
1277 avatars[i].StandUp();
1278 }
1279 1378
1280 if (!silent) 1379 if (!silent)
1281 { 1380 {
1282 part.UpdateFlag = 0; 1381 part.UpdateFlag = 0;
1283 if (part == m_rootPart) 1382 if (part == m_rootPart)
1284 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1383 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1285 }
1286 } 1384 }
1287 } 1385 }
1386
1288 } 1387 }
1388
1389
1289 } 1390 }
1290 1391
1291 public void AddScriptLPS(int count) 1392 public void AddScriptLPS(int count)
@@ -1310,17 +1411,20 @@ namespace OpenSim.Region.Framework.Scenes
1310 1411
1311 scriptEvents aggregateScriptEvents=0; 1412 scriptEvents aggregateScriptEvents=0;
1312 1413
1313 lock (m_parts) 1414 lockPartsForRead(true);
1314 { 1415 {
1315 foreach (SceneObjectPart part in m_parts.Values) 1416 foreach (SceneObjectPart part in m_parts.Values)
1316 { 1417 {
1418
1317 if (part == null) 1419 if (part == null)
1318 continue; 1420 continue;
1319 if (part != RootPart) 1421 if (part != RootPart)
1320 part.ObjectFlags = objectflagupdate; 1422 part.ObjectFlags = objectflagupdate;
1321 aggregateScriptEvents |= part.AggregateScriptEvents; 1423 aggregateScriptEvents |= part.AggregateScriptEvents;
1424
1322 } 1425 }
1323 } 1426 }
1427 lockPartsForRead(false);
1324 1428
1325 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); 1429 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
1326 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); 1430 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
@@ -1362,42 +1466,52 @@ namespace OpenSim.Region.Framework.Scenes
1362 /// <param name="m_physicalPrim"></param> 1466 /// <param name="m_physicalPrim"></param>
1363 public void ApplyPhysics(bool m_physicalPrim) 1467 public void ApplyPhysics(bool m_physicalPrim)
1364 { 1468 {
1365 lock (m_parts) 1469 lockPartsForRead(true);
1470
1471 if (m_parts.Count > 1)
1366 { 1472 {
1367 if (m_parts.Count > 1) 1473 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1474 lockPartsForRead(false);
1475 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1476 foreach (SceneObjectPart part in values)
1368 { 1477 {
1369 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); 1478
1370 foreach (SceneObjectPart part in m_parts.Values) 1479 if (part.LocalId != m_rootPart.LocalId)
1371 { 1480 {
1372 if (part.LocalId != m_rootPart.LocalId) 1481 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1373 {
1374 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1375 }
1376 } 1482 }
1377 1483
1378 // Hack to get the physics scene geometries in the right spot
1379 ResetChildPrimPhysicsPositions();
1380 }
1381 else
1382 {
1383 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1384 } 1484 }
1485 // Hack to get the physics scene geometries in the right spot
1486 ResetChildPrimPhysicsPositions();
1487 }
1488 else
1489 {
1490 lockPartsForRead(false);
1491 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1385 } 1492 }
1386 } 1493 }
1387 1494
1388 public void SetOwnerId(UUID userId) 1495 public void SetOwnerId(UUID userId)
1389 { 1496 {
1390 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1497 ForEachPart(delegate(SceneObjectPart part)
1498 {
1499
1500 part.OwnerID = userId;
1501
1502 });
1391 } 1503 }
1392 1504
1393 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1505 public void ForEachPart(Action<SceneObjectPart> whatToDo)
1394 { 1506 {
1395 lock (m_parts) 1507 lockPartsForRead(true);
1508 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1509 lockPartsForRead(false);
1510 foreach (SceneObjectPart part in values)
1396 { 1511 {
1397 foreach (SceneObjectPart part in m_parts.Values) 1512
1398 { 1513 whatToDo(part);
1399 whatToDo(part); 1514
1400 }
1401 } 1515 }
1402 } 1516 }
1403 1517
@@ -1495,10 +1609,11 @@ namespace OpenSim.Region.Framework.Scenes
1495 RootPart.SendFullUpdate( 1609 RootPart.SendFullUpdate(
1496 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1610 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1497 1611
1498 lock (m_parts) 1612 lockPartsForRead(true);
1499 { 1613 {
1500 foreach (SceneObjectPart part in m_parts.Values) 1614 foreach (SceneObjectPart part in m_parts.Values)
1501 { 1615 {
1616
1502 if (part != RootPart) 1617 if (part != RootPart)
1503 part.SendFullUpdate( 1618 part.SendFullUpdate(
1504 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1619 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
@@ -1572,10 +1687,11 @@ namespace OpenSim.Region.Framework.Scenes
1572 1687
1573 List<SceneObjectPart> partList; 1688 List<SceneObjectPart> partList;
1574 1689
1575 lock (m_parts) 1690 lockPartsForRead(true);
1576 { 1691
1577 partList = new List<SceneObjectPart>(m_parts.Values); 1692 partList = new List<SceneObjectPart>(m_parts.Values);
1578 } 1693
1694 lockPartsForRead(false);
1579 1695
1580 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1696 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1581 { 1697 {
@@ -1872,10 +1988,11 @@ namespace OpenSim.Region.Framework.Scenes
1872 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 1988 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1873 newPart.SetParent(this); 1989 newPart.SetParent(this);
1874 1990
1875 lock (m_parts) 1991 lockPartsForWrite(true);
1876 { 1992 {
1877 m_parts.Add(newPart.UUID, newPart); 1993 m_parts.Add(newPart.UUID, newPart);
1878 } 1994 }
1995 lockPartsForWrite(false);
1879 1996
1880 SetPartAsNonRoot(newPart); 1997 SetPartAsNonRoot(newPart);
1881 1998
@@ -1938,7 +2055,7 @@ namespace OpenSim.Region.Framework.Scenes
1938 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2055 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1939 // return; 2056 // return;
1940 2057
1941 lock (m_parts) 2058 lockPartsForRead(true);
1942 { 2059 {
1943 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2060 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1944 2061
@@ -1958,9 +2075,12 @@ namespace OpenSim.Region.Framework.Scenes
1958 { 2075 {
1959 if (!IsSelected) 2076 if (!IsSelected)
1960 part.UpdateLookAt(); 2077 part.UpdateLookAt();
2078
1961 part.SendScheduledUpdates(); 2079 part.SendScheduledUpdates();
2080
1962 } 2081 }
1963 } 2082 }
2083 lockPartsForRead(false);
1964 } 2084 }
1965 2085
1966 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2086 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -1969,27 +2089,29 @@ namespace OpenSim.Region.Framework.Scenes
1969 2089
1970 RootPart.AddFullUpdateToAvatar(presence); 2090 RootPart.AddFullUpdateToAvatar(presence);
1971 2091
1972 lock (m_parts) 2092 lockPartsForRead(true);
1973 { 2093 {
1974 foreach (SceneObjectPart part in m_parts.Values) 2094 foreach (SceneObjectPart part in m_parts.Values)
1975 { 2095 {
2096
1976 if (part != RootPart) 2097 if (part != RootPart)
1977 part.AddFullUpdateToAvatar(presence); 2098 part.AddFullUpdateToAvatar(presence);
2099
1978 } 2100 }
1979 } 2101 }
2102 lockPartsForRead(false);
1980 } 2103 }
1981 2104
1982 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2105 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
1983 { 2106 {
1984// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2107 lockPartsForRead(true);
1985 2108
1986 lock (m_parts) 2109 foreach (SceneObjectPart part in m_parts.Values)
1987 { 2110 {
1988 foreach (SceneObjectPart part in m_parts.Values) 2111 part.AddTerseUpdateToAvatar(presence);
1989 {
1990 part.AddTerseUpdateToAvatar(presence);
1991 }
1992 } 2112 }
2113
2114 lockPartsForRead(false);
1993 } 2115 }
1994 2116
1995 /// <summary> 2117 /// <summary>
@@ -2002,14 +2124,17 @@ namespace OpenSim.Region.Framework.Scenes
2002 checkAtTargets(); 2124 checkAtTargets();
2003 RootPart.ScheduleFullUpdate(); 2125 RootPart.ScheduleFullUpdate();
2004 2126
2005 lock (m_parts) 2127 lockPartsForRead(true);
2006 { 2128 {
2007 foreach (SceneObjectPart part in m_parts.Values) 2129 foreach (SceneObjectPart part in m_parts.Values)
2008 { 2130 {
2131
2009 if (part != RootPart) 2132 if (part != RootPart)
2010 part.ScheduleFullUpdate(); 2133 part.ScheduleFullUpdate();
2134
2011 } 2135 }
2012 } 2136 }
2137 lockPartsForRead(false);
2013 } 2138 }
2014 2139
2015 /// <summary> 2140 /// <summary>
@@ -2017,15 +2142,14 @@ namespace OpenSim.Region.Framework.Scenes
2017 /// </summary> 2142 /// </summary>
2018 public void ScheduleGroupForTerseUpdate() 2143 public void ScheduleGroupForTerseUpdate()
2019 { 2144 {
2020// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2145 lockPartsForRead(true);
2021 2146
2022 lock (m_parts) 2147 foreach (SceneObjectPart part in m_parts.Values)
2023 { 2148 {
2024 foreach (SceneObjectPart part in m_parts.Values) 2149 part.ScheduleTerseUpdate();
2025 {
2026 part.ScheduleTerseUpdate();
2027 }
2028 } 2150 }
2151
2152 lockPartsForRead(false);
2029 } 2153 }
2030 2154
2031 /// <summary> 2155 /// <summary>
@@ -2040,14 +2164,17 @@ namespace OpenSim.Region.Framework.Scenes
2040 2164
2041 RootPart.SendFullUpdateToAllClients(); 2165 RootPart.SendFullUpdateToAllClients();
2042 2166
2043 lock (m_parts) 2167 lockPartsForRead(true);
2044 { 2168 {
2045 foreach (SceneObjectPart part in m_parts.Values) 2169 foreach (SceneObjectPart part in m_parts.Values)
2046 { 2170 {
2171
2047 if (part != RootPart) 2172 if (part != RootPart)
2048 part.SendFullUpdateToAllClients(); 2173 part.SendFullUpdateToAllClients();
2174
2049 } 2175 }
2050 } 2176 }
2177 lockPartsForRead(false);
2051 } 2178 }
2052 2179
2053 /// <summary> 2180 /// <summary>
@@ -2079,14 +2206,15 @@ namespace OpenSim.Region.Framework.Scenes
2079 { 2206 {
2080 if (IsDeleted) 2207 if (IsDeleted)
2081 return; 2208 return;
2082 2209
2083 lock (m_parts) 2210 lockPartsForRead(true);
2084 { 2211 {
2085 foreach (SceneObjectPart part in m_parts.Values) 2212 foreach (SceneObjectPart part in m_parts.Values)
2086 { 2213 {
2087 part.SendTerseUpdateToAllClients(); 2214 part.SendTerseUpdateToAllClients();
2088 } 2215 }
2089 } 2216 }
2217 lockPartsForRead(false);
2090 } 2218 }
2091 2219
2092 #endregion 2220 #endregion
@@ -2100,16 +2228,18 @@ namespace OpenSim.Region.Framework.Scenes
2100 /// <returns>null if no child part with that linknum or child part</returns> 2228 /// <returns>null if no child part with that linknum or child part</returns>
2101 public SceneObjectPart GetLinkNumPart(int linknum) 2229 public SceneObjectPart GetLinkNumPart(int linknum)
2102 { 2230 {
2103 lock (m_parts) 2231 lockPartsForRead(true);
2104 { 2232 {
2105 foreach (SceneObjectPart part in m_parts.Values) 2233 foreach (SceneObjectPart part in m_parts.Values)
2106 { 2234 {
2107 if (part.LinkNum == linknum) 2235 if (part.LinkNum == linknum)
2108 { 2236 {
2237 lockPartsForRead(false);
2109 return part; 2238 return part;
2110 } 2239 }
2111 } 2240 }
2112 } 2241 }
2242 lockPartsForRead(false);
2113 2243
2114 return null; 2244 return null;
2115 } 2245 }
@@ -2137,17 +2267,19 @@ namespace OpenSim.Region.Framework.Scenes
2137 public SceneObjectPart GetChildPart(uint localID) 2267 public SceneObjectPart GetChildPart(uint localID)
2138 { 2268 {
2139 //m_log.DebugFormat("Entered looking for {0}", localID); 2269 //m_log.DebugFormat("Entered looking for {0}", localID);
2140 lock (m_parts) 2270 lockPartsForRead(true);
2141 { 2271 {
2142 foreach (SceneObjectPart part in m_parts.Values) 2272 foreach (SceneObjectPart part in m_parts.Values)
2143 { 2273 {
2144 //m_log.DebugFormat("Found {0}", part.LocalId); 2274 //m_log.DebugFormat("Found {0}", part.LocalId);
2145 if (part.LocalId == localID) 2275 if (part.LocalId == localID)
2146 { 2276 {
2277 lockPartsForRead(false);
2147 return part; 2278 return part;
2148 } 2279 }
2149 } 2280 }
2150 } 2281 }
2282 lockPartsForRead(false);
2151 2283
2152 return null; 2284 return null;
2153 } 2285 }
@@ -2177,17 +2309,19 @@ namespace OpenSim.Region.Framework.Scenes
2177 public bool HasChildPrim(uint localID) 2309 public bool HasChildPrim(uint localID)
2178 { 2310 {
2179 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2311 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2180 lock (m_parts) 2312 lockPartsForRead(true);
2181 { 2313 {
2182 foreach (SceneObjectPart part in m_parts.Values) 2314 foreach (SceneObjectPart part in m_parts.Values)
2183 { 2315 {
2184 //m_log.DebugFormat("Found {0}", part.LocalId); 2316 //m_log.DebugFormat("Found {0}", part.LocalId);
2185 if (part.LocalId == localID) 2317 if (part.LocalId == localID)
2186 { 2318 {
2319 lockPartsForRead(false);
2187 return true; 2320 return true;
2188 } 2321 }
2189 } 2322 }
2190 } 2323 }
2324 lockPartsForRead(false);
2191 2325
2192 return false; 2326 return false;
2193 } 2327 }
@@ -2237,53 +2371,57 @@ namespace OpenSim.Region.Framework.Scenes
2237 if (m_rootPart.LinkNum == 0) 2371 if (m_rootPart.LinkNum == 0)
2238 m_rootPart.LinkNum = 1; 2372 m_rootPart.LinkNum = 1;
2239 2373
2240 lock (m_parts) 2374 lockPartsForWrite(true);
2241 { 2375
2242 m_parts.Add(linkPart.UUID, linkPart); 2376 m_parts.Add(linkPart.UUID, linkPart);
2377
2378 lockPartsForWrite(false);
2243 2379
2244 // Insert in terms of link numbers, the new links 2380 // Insert in terms of link numbers, the new links
2245 // before the current ones (with the exception of 2381 // before the current ones (with the exception of
2246 // the root prim. Shuffle the old ones up 2382 // the root prim. Shuffle the old ones up
2247 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2383 lockPartsForRead(true);
2384 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2385 {
2386 if (kvp.Value.LinkNum != 1)
2248 { 2387 {
2249 if (kvp.Value.LinkNum != 1) 2388 // Don't update root prim link number
2250 { 2389 kvp.Value.LinkNum += objectGroup.PrimCount;
2251 // Don't update root prim link number
2252 kvp.Value.LinkNum += objectGroup.PrimCount;
2253 }
2254 } 2390 }
2391 }
2392 lockPartsForRead(false);
2255 2393
2256 linkPart.LinkNum = 2; 2394 linkPart.LinkNum = 2;
2257 2395
2258 linkPart.SetParent(this); 2396 linkPart.SetParent(this);
2259 linkPart.AddFlag(PrimFlags.CreateSelected); 2397 linkPart.AddFlag(PrimFlags.CreateSelected);
2260 2398
2261 //if (linkPart.PhysActor != null) 2399 //if (linkPart.PhysActor != null)
2262 //{ 2400 //{
2263 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2401 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2264 2402
2265 //linkPart.PhysActor = null; 2403 //linkPart.PhysActor = null;
2266 //} 2404 //}
2267 2405
2268 //TODO: rest of parts 2406 //TODO: rest of parts
2269 int linkNum = 3; 2407 int linkNum = 3;
2270 foreach (SceneObjectPart part in objectGroup.Children.Values) 2408 foreach (SceneObjectPart part in objectGroup.Children.Values)
2409 {
2410 if (part.UUID != objectGroup.m_rootPart.UUID)
2271 { 2411 {
2272 if (part.UUID != objectGroup.m_rootPart.UUID) 2412 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2273 {
2274 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2275 }
2276 part.ClearUndoState();
2277 } 2413 }
2414 part.ClearUndoState();
2278 } 2415 }
2279 2416
2280 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2417 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2281 objectGroup.m_isDeleted = true; 2418 objectGroup.m_isDeleted = true;
2419
2420 objectGroup.lockPartsForWrite(true);
2282 2421
2283 lock (objectGroup.m_parts) 2422 objectGroup.m_parts.Clear();
2284 { 2423
2285 objectGroup.m_parts.Clear(); 2424 objectGroup.lockPartsForWrite(false);
2286 }
2287 2425
2288 // Can't do this yet since backup still makes use of the root part without any synchronization 2426 // Can't do this yet since backup still makes use of the root part without any synchronization
2289// objectGroup.m_rootPart = null; 2427// objectGroup.m_rootPart = null;
@@ -2353,11 +2491,12 @@ namespace OpenSim.Region.Framework.Scenes
2353 Quaternion worldRot = linkPart.GetWorldRotation(); 2491 Quaternion worldRot = linkPart.GetWorldRotation();
2354 2492
2355 // Remove the part from this object 2493 // Remove the part from this object
2356 lock (m_parts) 2494 lockPartsForWrite(true);
2357 { 2495 {
2358 m_parts.Remove(linkPart.UUID); 2496 m_parts.Remove(linkPart.UUID);
2359 } 2497 }
2360 2498 lockPartsForWrite(false);
2499 lockPartsForRead(true);
2361 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2500 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2362 RootPart.LinkNum = 0; 2501 RootPart.LinkNum = 0;
2363 else 2502 else
@@ -2368,6 +2507,7 @@ namespace OpenSim.Region.Framework.Scenes
2368 p.LinkNum--; 2507 p.LinkNum--;
2369 } 2508 }
2370 } 2509 }
2510 lockPartsForRead(false);
2371 2511
2372 linkPart.ParentID = 0; 2512 linkPart.ParentID = 0;
2373 linkPart.LinkNum = 0; 2513 linkPart.LinkNum = 0;
@@ -2689,9 +2829,12 @@ namespace OpenSim.Region.Framework.Scenes
2689 2829
2690 if (selectionPart != null) 2830 if (selectionPart != null)
2691 { 2831 {
2692 lock (m_parts) 2832 lockPartsForRead(true);
2833 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2834 lockPartsForRead(false);
2835 foreach (SceneObjectPart part in parts)
2693 { 2836 {
2694 foreach (SceneObjectPart part in m_parts.Values) 2837 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2695 { 2838 {
2696 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2839 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2697 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2840 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2701,12 +2844,13 @@ namespace OpenSim.Region.Framework.Scenes
2701 break; 2844 break;
2702 } 2845 }
2703 } 2846 }
2847 }
2704 2848
2705 foreach (SceneObjectPart part in m_parts.Values) 2849 foreach (SceneObjectPart part in parts)
2706 { 2850 {
2707 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2851 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2708 }
2709 } 2852 }
2853
2710 } 2854 }
2711 } 2855 }
2712 2856
@@ -2792,11 +2936,9 @@ namespace OpenSim.Region.Framework.Scenes
2792 scale.Y = m_scene.m_maxNonphys; 2936 scale.Y = m_scene.m_maxNonphys;
2793 if (scale.Z > m_scene.m_maxNonphys) 2937 if (scale.Z > m_scene.m_maxNonphys)
2794 scale.Z = m_scene.m_maxNonphys; 2938 scale.Z = m_scene.m_maxNonphys;
2795
2796 SceneObjectPart part = GetChildPart(localID); 2939 SceneObjectPart part = GetChildPart(localID);
2797 if (part != null) 2940 if (part != null)
2798 { 2941 {
2799 part.Resize(scale);
2800 if (part.PhysActor != null) 2942 if (part.PhysActor != null)
2801 { 2943 {
2802 if (part.PhysActor.IsPhysical) 2944 if (part.PhysActor.IsPhysical)
@@ -2811,7 +2953,7 @@ namespace OpenSim.Region.Framework.Scenes
2811 part.PhysActor.Size = scale; 2953 part.PhysActor.Size = scale;
2812 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 2954 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2813 } 2955 }
2814 //if (part.UUID != m_rootPart.UUID) 2956 part.Resize(scale);
2815 2957
2816 HasGroupChanged = true; 2958 HasGroupChanged = true;
2817 ScheduleGroupForFullUpdate(); 2959 ScheduleGroupForFullUpdate();
@@ -2853,73 +2995,71 @@ namespace OpenSim.Region.Framework.Scenes
2853 float y = (scale.Y / part.Scale.Y); 2995 float y = (scale.Y / part.Scale.Y);
2854 float z = (scale.Z / part.Scale.Z); 2996 float z = (scale.Z / part.Scale.Z);
2855 2997
2856 lock (m_parts) 2998 lockPartsForRead(true);
2999 if (x > 1.0f || y > 1.0f || z > 1.0f)
2857 { 3000 {
2858 if (x > 1.0f || y > 1.0f || z > 1.0f) 3001 foreach (SceneObjectPart obPart in m_parts.Values)
2859 { 3002 {
2860 foreach (SceneObjectPart obPart in m_parts.Values) 3003 if (obPart.UUID != m_rootPart.UUID)
2861 { 3004 {
2862 if (obPart.UUID != m_rootPart.UUID) 3005 Vector3 oldSize = new Vector3(obPart.Scale);
2863 { 3006 obPart.IgnoreUndoUpdate = true;
2864 obPart.IgnoreUndoUpdate = true;
2865 Vector3 oldSize = new Vector3(obPart.Scale);
2866 3007
2867 float f = 1.0f; 3008 float f = 1.0f;
2868 float a = 1.0f; 3009 float a = 1.0f;
2869 3010
2870 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3011 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3012 {
3013 if (oldSize.X*x > m_scene.m_maxPhys)
2871 { 3014 {
2872 if (oldSize.X*x > m_scene.m_maxPhys) 3015 f = m_scene.m_maxPhys / oldSize.X;
2873 { 3016 a = f / x;
2874 f = m_scene.m_maxPhys / oldSize.X; 3017 x *= a;
2875 a = f / x; 3018 y *= a;
2876 x *= a; 3019 z *= a;
2877 y *= a;
2878 z *= a;
2879 }
2880 if (oldSize.Y*y > m_scene.m_maxPhys)
2881 {
2882 f = m_scene.m_maxPhys / oldSize.Y;
2883 a = f / y;
2884 x *= a;
2885 y *= a;
2886 z *= a;
2887 }
2888 if (oldSize.Z*z > m_scene.m_maxPhys)
2889 {
2890 f = m_scene.m_maxPhys / oldSize.Z;
2891 a = f / z;
2892 x *= a;
2893 y *= a;
2894 z *= a;
2895 }
2896 } 3020 }
2897 else 3021 if (oldSize.Y*y > m_scene.m_maxPhys)
3022 {
3023 f = m_scene.m_maxPhys / oldSize.Y;
3024 a = f / y;
3025 x *= a;
3026 y *= a;
3027 z *= a;
3028 }
3029 if (oldSize.Z*z > m_scene.m_maxPhys)
3030 {
3031 f = m_scene.m_maxPhys / oldSize.Z;
3032 a = f / z;
3033 x *= a;
3034 y *= a;
3035 z *= a;
3036 }
3037 }
3038 else
3039 {
3040 if (oldSize.X*x > m_scene.m_maxNonphys)
2898 { 3041 {
2899 if (oldSize.X*x > m_scene.m_maxNonphys) 3042 f = m_scene.m_maxNonphys / oldSize.X;
2900 { 3043 a = f / x;
2901 f = m_scene.m_maxNonphys / oldSize.X; 3044 x *= a;
2902 a = f / x; 3045 y *= a;
2903 x *= a; 3046 z *= a;
2904 y *= a; 3047 }
2905 z *= a; 3048 if (oldSize.Y*y > m_scene.m_maxNonphys)
2906 } 3049 {
2907 if (oldSize.Y*y > m_scene.m_maxNonphys) 3050 f = m_scene.m_maxNonphys / oldSize.Y;
2908 { 3051 a = f / y;
2909 f = m_scene.m_maxNonphys / oldSize.Y; 3052 x *= a;
2910 a = f / y; 3053 y *= a;
2911 x *= a; 3054 z *= a;
2912 y *= a; 3055 }
2913 z *= a; 3056 if (oldSize.Z*z > m_scene.m_maxNonphys)
2914 } 3057 {
2915 if (oldSize.Z*z > m_scene.m_maxNonphys) 3058 f = m_scene.m_maxNonphys / oldSize.Z;
2916 { 3059 a = f / z;
2917 f = m_scene.m_maxNonphys / oldSize.Z; 3060 x *= a;
2918 a = f / z; 3061 y *= a;
2919 x *= a; 3062 z *= a;
2920 y *= a;
2921 z *= a;
2922 }
2923 } 3063 }
2924 obPart.IgnoreUndoUpdate = false; 3064 obPart.IgnoreUndoUpdate = false;
2925 obPart.StoreUndoState(); 3065 obPart.StoreUndoState();
@@ -2927,6 +3067,7 @@ namespace OpenSim.Region.Framework.Scenes
2927 } 3067 }
2928 } 3068 }
2929 } 3069 }
3070 lockPartsForRead(false);
2930 3071
2931 Vector3 prevScale = part.Scale; 3072 Vector3 prevScale = part.Scale;
2932 prevScale.X *= x; 3073 prevScale.X *= x;
@@ -2934,7 +3075,7 @@ namespace OpenSim.Region.Framework.Scenes
2934 prevScale.Z *= z; 3075 prevScale.Z *= z;
2935 part.Resize(prevScale); 3076 part.Resize(prevScale);
2936 3077
2937 lock (m_parts) 3078 lockPartsForRead(true);
2938 { 3079 {
2939 foreach (SceneObjectPart obPart in m_parts.Values) 3080 foreach (SceneObjectPart obPart in m_parts.Values)
2940 { 3081 {
@@ -2956,6 +3097,7 @@ namespace OpenSim.Region.Framework.Scenes
2956 obPart.StoreUndoState(); 3097 obPart.StoreUndoState();
2957 } 3098 }
2958 } 3099 }
3100 lockPartsForRead(false);
2959 3101
2960 if (part.PhysActor != null) 3102 if (part.PhysActor != null)
2961 { 3103 {
@@ -3058,7 +3200,7 @@ namespace OpenSim.Region.Framework.Scenes
3058 axDiff *= Quaternion.Inverse(partRotation); 3200 axDiff *= Quaternion.Inverse(partRotation);
3059 diff = axDiff; 3201 diff = axDiff;
3060 3202
3061 lock (m_parts) 3203 lockPartsForRead(true);
3062 { 3204 {
3063 foreach (SceneObjectPart obPart in m_parts.Values) 3205 foreach (SceneObjectPart obPart in m_parts.Values)
3064 { 3206 {
@@ -3068,6 +3210,7 @@ namespace OpenSim.Region.Framework.Scenes
3068 } 3210 }
3069 } 3211 }
3070 } 3212 }
3213 lockPartsForRead(false);
3071 3214
3072 AbsolutePosition = newPos; 3215 AbsolutePosition = newPos;
3073 3216
@@ -3201,7 +3344,7 @@ namespace OpenSim.Region.Framework.Scenes
3201 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3344 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3202 } 3345 }
3203 3346
3204 lock (m_parts) 3347 lockPartsForRead(true);
3205 { 3348 {
3206 foreach (SceneObjectPart prim in m_parts.Values) 3349 foreach (SceneObjectPart prim in m_parts.Values)
3207 { 3350 {
@@ -3220,6 +3363,7 @@ namespace OpenSim.Region.Framework.Scenes
3220 } 3363 }
3221 } 3364 }
3222 } 3365 }
3366
3223 foreach (SceneObjectPart childpart in Children.Values) 3367 foreach (SceneObjectPart childpart in Children.Values)
3224 { 3368 {
3225 if (childpart != m_rootPart) 3369 if (childpart != m_rootPart)
@@ -3228,6 +3372,9 @@ namespace OpenSim.Region.Framework.Scenes
3228 childpart.StoreUndoState(); 3372 childpart.StoreUndoState();
3229 } 3373 }
3230 } 3374 }
3375
3376 lockPartsForRead(false);
3377
3231 m_rootPart.ScheduleTerseUpdate(); 3378 m_rootPart.ScheduleTerseUpdate();
3232 } 3379 }
3233 3380
@@ -3349,7 +3496,7 @@ namespace OpenSim.Region.Framework.Scenes
3349 if (atTargets.Count > 0) 3496 if (atTargets.Count > 0)
3350 { 3497 {
3351 uint[] localids = new uint[0]; 3498 uint[] localids = new uint[0];
3352 lock (m_parts) 3499 lockPartsForRead(true);
3353 { 3500 {
3354 localids = new uint[m_parts.Count]; 3501 localids = new uint[m_parts.Count];
3355 int cntr = 0; 3502 int cntr = 0;
@@ -3359,6 +3506,7 @@ namespace OpenSim.Region.Framework.Scenes
3359 cntr++; 3506 cntr++;
3360 } 3507 }
3361 } 3508 }
3509 lockPartsForRead(false);
3362 3510
3363 for (int ctr = 0; ctr < localids.Length; ctr++) 3511 for (int ctr = 0; ctr < localids.Length; ctr++)
3364 { 3512 {
@@ -3377,7 +3525,7 @@ namespace OpenSim.Region.Framework.Scenes
3377 { 3525 {
3378 //trigger not_at_target 3526 //trigger not_at_target
3379 uint[] localids = new uint[0]; 3527 uint[] localids = new uint[0];
3380 lock (m_parts) 3528 lockPartsForRead(true);
3381 { 3529 {
3382 localids = new uint[m_parts.Count]; 3530 localids = new uint[m_parts.Count];
3383 int cntr = 0; 3531 int cntr = 0;
@@ -3387,7 +3535,8 @@ namespace OpenSim.Region.Framework.Scenes
3387 cntr++; 3535 cntr++;
3388 } 3536 }
3389 } 3537 }
3390 3538 lockPartsForRead(false);
3539
3391 for (int ctr = 0; ctr < localids.Length; ctr++) 3540 for (int ctr = 0; ctr < localids.Length; ctr++)
3392 { 3541 {
3393 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3542 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3479,19 +3628,20 @@ namespace OpenSim.Region.Framework.Scenes
3479 public float GetMass() 3628 public float GetMass()
3480 { 3629 {
3481 float retmass = 0f; 3630 float retmass = 0f;
3482 lock (m_parts) 3631 lockPartsForRead(true);
3483 { 3632 {
3484 foreach (SceneObjectPart part in m_parts.Values) 3633 foreach (SceneObjectPart part in m_parts.Values)
3485 { 3634 {
3486 retmass += part.GetMass(); 3635 retmass += part.GetMass();
3487 } 3636 }
3488 } 3637 }
3638 lockPartsForRead(false);
3489 return retmass; 3639 return retmass;
3490 } 3640 }
3491 3641
3492 public void CheckSculptAndLoad() 3642 public void CheckSculptAndLoad()
3493 { 3643 {
3494 lock (m_parts) 3644 lockPartsForRead(true);
3495 { 3645 {
3496 if (!IsDeleted) 3646 if (!IsDeleted)
3497 { 3647 {
@@ -3516,6 +3666,7 @@ namespace OpenSim.Region.Framework.Scenes
3516 } 3666 }
3517 } 3667 }
3518 } 3668 }
3669 lockPartsForRead(false);
3519 } 3670 }
3520 3671
3521 protected void AssetReceived(string id, Object sender, AssetBase asset) 3672 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3536,7 +3687,7 @@ namespace OpenSim.Region.Framework.Scenes
3536 /// <param name="client"></param> 3687 /// <param name="client"></param>
3537 public void SetGroup(UUID GroupID, IClientAPI client) 3688 public void SetGroup(UUID GroupID, IClientAPI client)
3538 { 3689 {
3539 lock (m_parts) 3690 lockPartsForRead(true);
3540 { 3691 {
3541 foreach (SceneObjectPart part in m_parts.Values) 3692 foreach (SceneObjectPart part in m_parts.Values)
3542 { 3693 {
@@ -3546,6 +3697,7 @@ namespace OpenSim.Region.Framework.Scenes
3546 3697
3547 HasGroupChanged = true; 3698 HasGroupChanged = true;
3548 } 3699 }
3700 lockPartsForRead(false);
3549 3701
3550 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3702 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
3551 // for the same object with very different properties. The caller must schedule the update. 3703 // for the same object with very different properties. The caller must schedule the update.
@@ -3567,11 +3719,12 @@ namespace OpenSim.Region.Framework.Scenes
3567 3719
3568 public void SetAttachmentPoint(byte point) 3720 public void SetAttachmentPoint(byte point)
3569 { 3721 {
3570 lock (m_parts) 3722 lockPartsForRead(true);
3571 { 3723 {
3572 foreach (SceneObjectPart part in m_parts.Values) 3724 foreach (SceneObjectPart part in m_parts.Values)
3573 part.SetAttachmentPoint(point); 3725 part.SetAttachmentPoint(point);
3574 } 3726 }
3727 lockPartsForRead(false);
3575 } 3728 }
3576 3729
3577 #region ISceneObject 3730 #region ISceneObject
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 4729382..e0d0fe1 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 {
@@ -960,7 +962,8 @@ namespace OpenSim.Region.Framework.Scenes
960 if (IsAttachment) 962 if (IsAttachment)
961 return GroupPosition; 963 return GroupPosition;
962 964
963 return m_offsetPosition + m_groupPosition; } 965// return m_offsetPosition + m_groupPosition; }
966 return m_groupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset) ; } //KF: Rotation was ignored!
964 } 967 }
965 968
966 public SceneObjectGroup ParentGroup 969 public SceneObjectGroup ParentGroup
@@ -1112,6 +1115,13 @@ namespace OpenSim.Region.Framework.Scenes
1112 get { return _flags; } 1115 get { return _flags; }
1113 set { _flags = value; } 1116 set { _flags = value; }
1114 } 1117 }
1118
1119 [XmlIgnore]
1120 public bool IsOccupied // KF If an av is sittingon this prim
1121 {
1122 get { return m_occupied; }
1123 set { m_occupied = value; }
1124 }
1115 1125
1116 [XmlIgnore] 1126 [XmlIgnore]
1117 public UUID SitTargetAvatar 1127 public UUID SitTargetAvatar
@@ -1187,14 +1197,6 @@ namespace OpenSim.Region.Framework.Scenes
1187 } 1197 }
1188 } 1198 }
1189 1199
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) 1200 private void SendObjectPropertiesToClient(UUID AgentID)
1199 { 1201 {
1200 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 1202 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences();
@@ -1937,12 +1939,17 @@ namespace OpenSim.Region.Framework.Scenes
1937 public Vector3 GetWorldPosition() 1939 public Vector3 GetWorldPosition()
1938 { 1940 {
1939 Quaternion parentRot = ParentGroup.RootPart.RotationOffset; 1941 Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
1940
1941 Vector3 axPos = OffsetPosition; 1942 Vector3 axPos = OffsetPosition;
1942
1943 axPos *= parentRot; 1943 axPos *= parentRot;
1944 Vector3 translationOffsetPosition = axPos; 1944 Vector3 translationOffsetPosition = axPos;
1945 return GroupPosition + translationOffsetPosition; 1945 if(_parentID == 0)
1946 {
1947 return GroupPosition;
1948 }
1949 else
1950 {
1951 return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position
1952 }
1946 } 1953 }
1947 1954
1948 /// <summary> 1955 /// <summary>
@@ -1953,7 +1960,7 @@ namespace OpenSim.Region.Framework.Scenes
1953 { 1960 {
1954 Quaternion newRot; 1961 Quaternion newRot;
1955 1962
1956 if (this.LinkNum == 0) 1963 if (this.LinkNum < 2) //KF Single or root prim
1957 { 1964 {
1958 newRot = RotationOffset; 1965 newRot = RotationOffset;
1959 } 1966 }
@@ -2610,17 +2617,18 @@ namespace OpenSim.Region.Framework.Scenes
2610 //Trys to fetch sound id from prim's inventory. 2617 //Trys to fetch sound id from prim's inventory.
2611 //Prim's inventory doesn't support non script items yet 2618 //Prim's inventory doesn't support non script items yet
2612 2619
2613 lock (TaskInventory) 2620 TaskInventory.LockItemsForRead(true);
2621
2622 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2614 { 2623 {
2615 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2624 if (item.Value.Name == sound)
2616 { 2625 {
2617 if (item.Value.Name == sound) 2626 soundID = item.Value.ItemID;
2618 { 2627 break;
2619 soundID = item.Value.ItemID;
2620 break;
2621 }
2622 } 2628 }
2623 } 2629 }
2630
2631 TaskInventory.LockItemsForRead(false);
2624 } 2632 }
2625 2633
2626 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 2634 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
@@ -2954,8 +2962,8 @@ namespace OpenSim.Region.Framework.Scenes
2954 { 2962 {
2955 const float ROTATION_TOLERANCE = 0.01f; 2963 const float ROTATION_TOLERANCE = 0.01f;
2956 const float VELOCITY_TOLERANCE = 0.001f; 2964 const float VELOCITY_TOLERANCE = 0.001f;
2957 const float POSITION_TOLERANCE = 0.05f; 2965 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2958 const int TIME_MS_TOLERANCE = 3000; 2966 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2959 2967
2960 if (m_updateFlag == 1) 2968 if (m_updateFlag == 1)
2961 { 2969 {
@@ -2969,7 +2977,7 @@ namespace OpenSim.Region.Framework.Scenes
2969 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2977 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2970 { 2978 {
2971 AddTerseUpdateToAllAvatars(); 2979 AddTerseUpdateToAllAvatars();
2972 ClearUpdateSchedule(); 2980
2973 2981
2974 // This causes the Scene to 'poll' physical objects every couple of frames 2982 // This causes the Scene to 'poll' physical objects every couple of frames
2975 // bad, so it's been replaced by an event driven method. 2983 // bad, so it's been replaced by an event driven method.
@@ -2987,16 +2995,18 @@ namespace OpenSim.Region.Framework.Scenes
2987 m_lastAngularVelocity = AngularVelocity; 2995 m_lastAngularVelocity = AngularVelocity;
2988 m_lastTerseSent = Environment.TickCount; 2996 m_lastTerseSent = Environment.TickCount;
2989 } 2997 }
2998 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
2999 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
2990 } 3000 }
2991 else 3001 else
2992 { 3002 {
2993 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes 3003 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
2994 { 3004 {
2995 AddFullUpdateToAllAvatars(); 3005 AddFullUpdateToAllAvatars();
2996 ClearUpdateSchedule(); 3006 m_updateFlag = 0; //Same here
2997 } 3007 }
2998 } 3008 }
2999 ClearUpdateSchedule(); 3009 m_updateFlag = 0;
3000 } 3010 }
3001 3011
3002 /// <summary> 3012 /// <summary>
@@ -3023,17 +3033,16 @@ namespace OpenSim.Region.Framework.Scenes
3023 if (!UUID.TryParse(sound, out soundID)) 3033 if (!UUID.TryParse(sound, out soundID))
3024 { 3034 {
3025 // search sound file from inventory 3035 // search sound file from inventory
3026 lock (TaskInventory) 3036 TaskInventory.LockItemsForRead(true);
3037 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3027 { 3038 {
3028 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3039 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3029 { 3040 {
3030 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3041 soundID = item.Value.ItemID;
3031 { 3042 break;
3032 soundID = item.Value.ItemID;
3033 break;
3034 }
3035 } 3043 }
3036 } 3044 }
3045 TaskInventory.LockItemsForRead(false);
3037 } 3046 }
3038 3047
3039 if (soundID == UUID.Zero) 3048 if (soundID == UUID.Zero)
@@ -3216,6 +3225,22 @@ namespace OpenSim.Region.Framework.Scenes
3216 PhysActor.VehicleRotationParam(param, rotation); 3225 PhysActor.VehicleRotationParam(param, rotation);
3217 } 3226 }
3218 } 3227 }
3228
3229 public void SetVehicleFlags(int flags)
3230 {
3231 if (PhysActor != null)
3232 {
3233 PhysActor.VehicleFlagsSet(flags);
3234 }
3235 }
3236
3237 public void RemoveVehicleFlags(int flags)
3238 {
3239 if (PhysActor != null)
3240 {
3241 PhysActor.VehicleFlagsRemove(flags);
3242 }
3243 }
3219 3244
3220 /// <summary> 3245 /// <summary>
3221 /// Set the color of prim faces 3246 /// Set the color of prim faces
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 4256be9..93e66e0 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
73// { 73// {
74// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
75// } 75// }
76 76
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78 78
79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -89,7 +89,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 90 /// issue #1716
91 /// </summary> 91 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 // Value revised by KF 091121 by comparison with SL.
94 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 95
94 public UUID currentParcelUUID = UUID.Zero; 96 public UUID currentParcelUUID = UUID.Zero;
95 97
@@ -123,8 +125,11 @@ namespace OpenSim.Region.Framework.Scenes
123 public Vector3 lastKnownAllowedPosition; 125 public Vector3 lastKnownAllowedPosition;
124 public bool sentMessageAboutRestrictedParcelFlyingDown; 126 public bool sentMessageAboutRestrictedParcelFlyingDown;
125 public Vector4 CollisionPlane = Vector4.UnitW; 127 public Vector4 CollisionPlane = Vector4.UnitW;
126 128
127 private Vector3 m_lastPosition; 129 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
130 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
131 private Vector3 m_lastPosition;
132 private Vector3 m_lastWorldPosition;
128 private Quaternion m_lastRotation; 133 private Quaternion m_lastRotation;
129 private Vector3 m_lastVelocity; 134 private Vector3 m_lastVelocity;
130 //private int m_lastTerseSent; 135 //private int m_lastTerseSent;
@@ -134,7 +139,6 @@ namespace OpenSim.Region.Framework.Scenes
134 private Vector3? m_forceToApply; 139 private Vector3? m_forceToApply;
135 private uint m_requestedSitTargetID; 140 private uint m_requestedSitTargetID;
136 private UUID m_requestedSitTargetUUID; 141 private UUID m_requestedSitTargetUUID;
137 public bool SitGround = false;
138 142
139 private SendCourseLocationsMethod m_sendCourseLocationsMethod; 143 private SendCourseLocationsMethod m_sendCourseLocationsMethod;
140 144
@@ -156,7 +160,6 @@ namespace OpenSim.Region.Framework.Scenes
156 private int m_perfMonMS; 160 private int m_perfMonMS;
157 161
158 private bool m_setAlwaysRun; 162 private bool m_setAlwaysRun;
159
160 private bool m_forceFly; 163 private bool m_forceFly;
161 private bool m_flyDisabled; 164 private bool m_flyDisabled;
162 165
@@ -182,7 +185,8 @@ namespace OpenSim.Region.Framework.Scenes
182 protected RegionInfo m_regionInfo; 185 protected RegionInfo m_regionInfo;
183 protected ulong crossingFromRegion; 186 protected ulong crossingFromRegion;
184 187
185 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 188 private readonly Vector3[] Dir_Vectors = new Vector3[11];
189 private bool m_isNudging = false;
186 190
187 // Position of agent's camera in world (region cordinates) 191 // Position of agent's camera in world (region cordinates)
188 protected Vector3 m_CameraCenter; 192 protected Vector3 m_CameraCenter;
@@ -207,6 +211,7 @@ namespace OpenSim.Region.Framework.Scenes
207 private bool m_autopilotMoving; 211 private bool m_autopilotMoving;
208 private Vector3 m_autoPilotTarget; 212 private Vector3 m_autoPilotTarget;
209 private bool m_sitAtAutoTarget; 213 private bool m_sitAtAutoTarget;
214 private Vector3 m_initialSitTarget; //KF: First estimate of where to sit
210 215
211 private string m_nextSitAnimation = String.Empty; 216 private string m_nextSitAnimation = String.Empty;
212 217
@@ -217,6 +222,9 @@ namespace OpenSim.Region.Framework.Scenes
217 private bool m_followCamAuto; 222 private bool m_followCamAuto;
218 223
219 private int m_movementUpdateCount; 224 private int m_movementUpdateCount;
225 private int m_lastColCount = -1; //KF: Look for Collision chnages
226 private int m_updateCount = 0; //KF: Update Anims for a while
227 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
220 228
221 private const int NumMovementsBetweenRayCast = 5; 229 private const int NumMovementsBetweenRayCast = 5;
222 230
@@ -245,7 +253,9 @@ namespace OpenSim.Region.Framework.Scenes
245 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 253 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
246 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 254 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
247 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 255 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
248 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 256 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
257 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
258 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
249 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 259 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
250 } 260 }
251 261
@@ -682,10 +692,7 @@ namespace OpenSim.Region.Framework.Scenes
682 m_reprioritization_timer.AutoReset = false; 692 m_reprioritization_timer.AutoReset = false;
683 693
684 AdjustKnownSeeds(); 694 AdjustKnownSeeds();
685
686 // TODO: I think, this won't send anything, as we are still a child here...
687 Animator.TrySetMovementAnimation("STAND"); 695 Animator.TrySetMovementAnimation("STAND");
688
689 // we created a new ScenePresence (a new child agent) in a fresh region. 696 // we created a new ScenePresence (a new child agent) in a fresh region.
690 // Request info about all the (root) agents in this region 697 // Request info about all the (root) agents in this region
691 // Note: This won't send data *to* other clients in that region (children don't send) 698 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -741,25 +748,47 @@ namespace OpenSim.Region.Framework.Scenes
741 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 748 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
742 Dir_Vectors[4] = Vector3.UnitZ; //UP 749 Dir_Vectors[4] = Vector3.UnitZ; //UP
743 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 750 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
744 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 751 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
745 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 752 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
746 Dir_Vectors[7] = -Vector3.UnitX; //BACK 753 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
754 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
755 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
747 } 756 }
748 757
749 private Vector3[] GetWalkDirectionVectors() 758 private Vector3[] GetWalkDirectionVectors()
750 { 759 {
751 Vector3[] vector = new Vector3[9]; 760 Vector3[] vector = new Vector3[11];
752 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 761 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
753 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 762 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
754 vector[2] = Vector3.UnitY; //LEFT 763 vector[2] = Vector3.UnitY; //LEFT
755 vector[3] = -Vector3.UnitY; //RIGHT 764 vector[3] = -Vector3.UnitY; //RIGHT
756 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 765 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
757 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 766 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
758 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 767 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
759 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 768 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
760 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 769 vector[8] = Vector3.UnitY; //LEFT_NUDGE
770 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
771 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
761 return vector; 772 return vector;
762 } 773 }
774
775 private bool[] GetDirectionIsNudge()
776 {
777 bool[] isNudge = new bool[11];
778 isNudge[0] = false; //FORWARD
779 isNudge[1] = false; //BACK
780 isNudge[2] = false; //LEFT
781 isNudge[3] = false; //RIGHT
782 isNudge[4] = false; //UP
783 isNudge[5] = false; //DOWN
784 isNudge[6] = true; //FORWARD_NUDGE
785 isNudge[7] = true; //BACK_NUDGE
786 isNudge[8] = true; //LEFT_NUDGE
787 isNudge[9] = true; //RIGHT_NUDGE
788 isNudge[10] = true; //DOWN_Nudge
789 return isNudge;
790 }
791
763 792
764 #endregion 793 #endregion
765 794
@@ -828,6 +857,22 @@ namespace OpenSim.Region.Framework.Scenes
828 { 857 {
829 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 858 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
830 pos.Y = crossedBorder.BorderLine.Z - 1; 859 pos.Y = crossedBorder.BorderLine.Z - 1;
860 }
861
862 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
863 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
864 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
865 if (KnownChildRegionHandles.Count == 0)
866 {
867 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
868 if (land != null)
869 {
870 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
871 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && m_godlevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid)
872 {
873 pos = land.LandData.UserLocation;
874 }
875 }
831 } 876 }
832 877
833 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 878 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
@@ -964,9 +1009,10 @@ namespace OpenSim.Region.Framework.Scenes
964 public void Teleport(Vector3 pos) 1009 public void Teleport(Vector3 pos)
965 { 1010 {
966 bool isFlying = false; 1011 bool isFlying = false;
967 if (m_physicsActor != null)
968 isFlying = m_physicsActor.Flying;
969 1012
1013 if (m_physicsActor != null)
1014 isFlying = m_physicsActor.Flying;
1015
970 RemoveFromPhysicalScene(); 1016 RemoveFromPhysicalScene();
971 Velocity = Vector3.Zero; 1017 Velocity = Vector3.Zero;
972 AbsolutePosition = pos; 1018 AbsolutePosition = pos;
@@ -977,7 +1023,8 @@ namespace OpenSim.Region.Framework.Scenes
977 SetHeight(m_appearance.AvatarHeight); 1023 SetHeight(m_appearance.AvatarHeight);
978 } 1024 }
979 1025
980 SendTerseUpdateToAllClients(); 1026 SendTerseUpdateToAllClients();
1027
981 } 1028 }
982 1029
983 public void TeleportWithMomentum(Vector3 pos) 1030 public void TeleportWithMomentum(Vector3 pos)
@@ -1022,7 +1069,9 @@ namespace OpenSim.Region.Framework.Scenes
1022 { 1069 {
1023 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); 1070 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
1024 } 1071 }
1025 1072
1073 m_updateCount = UPDATE_COUNT; //KF: Trigger Anim updates to catch falling anim.
1074
1026 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 1075 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
1027 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient))); 1076 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
1028 } 1077 }
@@ -1273,7 +1322,6 @@ namespace OpenSim.Region.Framework.Scenes
1273 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1322 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1274 } 1323 }
1275 } 1324 }
1276
1277 lock (scriptedcontrols) 1325 lock (scriptedcontrols)
1278 { 1326 {
1279 if (scriptedcontrols.Count > 0) 1327 if (scriptedcontrols.Count > 0)
@@ -1288,12 +1336,8 @@ namespace OpenSim.Region.Framework.Scenes
1288 1336
1289 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1337 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1290 { 1338 {
1291 // TODO: This doesn't prevent the user from walking yet. 1339 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1292 // Setting parent ID would fix this, if we knew what value 1340 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1293 // to use. Or we could add a m_isSitting variable.
1294 //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1295 SitGround = true;
1296
1297 } 1341 }
1298 1342
1299 // In the future, these values might need to go global. 1343 // In the future, these values might need to go global.
@@ -1343,6 +1387,11 @@ namespace OpenSim.Region.Framework.Scenes
1343 update_rotation = true; 1387 update_rotation = true;
1344 } 1388 }
1345 1389
1390 //guilty until proven innocent..
1391 bool Nudging = true;
1392 //Basically, if there is at least one non-nudge control then we don't need
1393 //to worry about stopping the avatar
1394
1346 if (m_parentID == 0) 1395 if (m_parentID == 0)
1347 { 1396 {
1348 bool bAllowUpdateMoveToPosition = false; 1397 bool bAllowUpdateMoveToPosition = false;
@@ -1357,9 +1406,12 @@ namespace OpenSim.Region.Framework.Scenes
1357 else 1406 else
1358 dirVectors = Dir_Vectors; 1407 dirVectors = Dir_Vectors;
1359 1408
1360 // The fact that m_movementflag is a byte needs to be fixed 1409 bool[] isNudge = GetDirectionIsNudge();
1361 // it really should be a uint 1410
1362 uint nudgehack = 250; 1411
1412
1413
1414
1363 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1415 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1364 { 1416 {
1365 if (((uint)flags & (uint)DCF) != 0) 1417 if (((uint)flags & (uint)DCF) != 0)
@@ -1369,40 +1421,28 @@ namespace OpenSim.Region.Framework.Scenes
1369 try 1421 try
1370 { 1422 {
1371 agent_control_v3 += dirVectors[i]; 1423 agent_control_v3 += dirVectors[i];
1372 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1424 if (isNudge[i] == false)
1425 {
1426 Nudging = false;
1427 }
1373 } 1428 }
1374 catch (IndexOutOfRangeException) 1429 catch (IndexOutOfRangeException)
1375 { 1430 {
1376 // Why did I get this? 1431 // Why did I get this?
1377 } 1432 }
1378 1433
1379 if ((m_movementflag & (byte)(uint)DCF) == 0) 1434 if ((m_movementflag & (uint)DCF) == 0)
1380 { 1435 {
1381 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1382 {
1383 m_movementflag |= (byte)nudgehack;
1384 }
1385 m_movementflag += (byte)(uint)DCF; 1436 m_movementflag += (byte)(uint)DCF;
1386 update_movementflag = true; 1437 update_movementflag = true;
1387 } 1438 }
1388 } 1439 }
1389 else 1440 else
1390 { 1441 {
1391 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1442 if ((m_movementflag & (uint)DCF) != 0)
1392 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1393 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1394 ) // This or is for Nudge forward
1395 { 1443 {
1396 m_movementflag -= ((byte)(uint)DCF); 1444 m_movementflag -= (byte)(uint)DCF;
1397
1398 update_movementflag = true; 1445 update_movementflag = true;
1399 /*
1400 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1401 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1402 {
1403 m_log.Debug("Removed Hack flag");
1404 }
1405 */
1406 } 1446 }
1407 else 1447 else
1408 { 1448 {
@@ -1446,6 +1486,9 @@ namespace OpenSim.Region.Framework.Scenes
1446 // Ignore z component of vector 1486 // Ignore z component of vector
1447 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1487 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1448 LocalVectorToTarget2D.Normalize(); 1488 LocalVectorToTarget2D.Normalize();
1489
1490 //We're not nudging
1491 Nudging = false;
1449 agent_control_v3 += LocalVectorToTarget2D; 1492 agent_control_v3 += LocalVectorToTarget2D;
1450 1493
1451 // update avatar movement flags. the avatar coordinate system is as follows: 1494 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1534,13 +1577,13 @@ namespace OpenSim.Region.Framework.Scenes
1534 // m_log.DebugFormat( 1577 // m_log.DebugFormat(
1535 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1578 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1536 1579
1537 AddNewMovement(agent_control_v3, q); 1580 AddNewMovement(agent_control_v3, q, Nudging);
1538 1581
1539 1582
1540 } 1583 }
1541 } 1584 }
1542 1585
1543 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1586 if (update_movementflag)
1544 Animator.UpdateMovementAnimations(); 1587 Animator.UpdateMovementAnimations();
1545 1588
1546 m_scene.EventManager.TriggerOnClientMovement(this); 1589 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1555,7 +1598,6 @@ namespace OpenSim.Region.Framework.Scenes
1555 m_sitAtAutoTarget = false; 1598 m_sitAtAutoTarget = false;
1556 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1599 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1557 //proxy.PCode = (byte)PCode.ParticleSystem; 1600 //proxy.PCode = (byte)PCode.ParticleSystem;
1558
1559 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1601 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1560 proxyObjectGroup.AttachToScene(m_scene); 1602 proxyObjectGroup.AttachToScene(m_scene);
1561 1603
@@ -1597,7 +1639,7 @@ namespace OpenSim.Region.Framework.Scenes
1597 } 1639 }
1598 m_moveToPositionInProgress = true; 1640 m_moveToPositionInProgress = true;
1599 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1641 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1600 } 1642 }
1601 catch (Exception ex) 1643 catch (Exception ex)
1602 { 1644 {
1603 //Why did I get this error? 1645 //Why did I get this error?
@@ -1619,7 +1661,7 @@ namespace OpenSim.Region.Framework.Scenes
1619 Velocity = Vector3.Zero; 1661 Velocity = Vector3.Zero;
1620 SendFullUpdateToAllClients(); 1662 SendFullUpdateToAllClients();
1621 1663
1622 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1664 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1623 } 1665 }
1624 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1666 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1625 m_requestedSitTargetUUID = UUID.Zero; 1667 m_requestedSitTargetUUID = UUID.Zero;
@@ -1652,55 +1694,84 @@ namespace OpenSim.Region.Framework.Scenes
1652 /// </summary> 1694 /// </summary>
1653 public void StandUp() 1695 public void StandUp()
1654 { 1696 {
1655 if (SitGround)
1656 SitGround = false;
1657
1658 if (m_parentID != 0) 1697 if (m_parentID != 0)
1659 { 1698 {
1660 m_log.Debug("StandupCode Executed");
1661 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1699 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1662 if (part != null) 1700 if (part != null)
1663 { 1701 {
1702 part.TaskInventory.LockItemsForRead(true);
1664 TaskInventoryDictionary taskIDict = part.TaskInventory; 1703 TaskInventoryDictionary taskIDict = part.TaskInventory;
1665 if (taskIDict != null) 1704 if (taskIDict != null)
1666 { 1705 {
1667 lock (taskIDict) 1706 foreach (UUID taskID in taskIDict.Keys)
1668 { 1707 {
1669 foreach (UUID taskID in taskIDict.Keys) 1708 UnRegisterControlEventsToScript(LocalId, taskID);
1670 { 1709 taskIDict[taskID].PermsMask &= ~(
1671 UnRegisterControlEventsToScript(LocalId, taskID); 1710 2048 | //PERMISSION_CONTROL_CAMERA
1672 taskIDict[taskID].PermsMask &= ~( 1711 4); // PERMISSION_TAKE_CONTROLS
1673 2048 | //PERMISSION_CONTROL_CAMERA
1674 4); // PERMISSION_TAKE_CONTROLS
1675 }
1676 } 1712 }
1677
1678 } 1713 }
1714 part.TaskInventory.LockItemsForRead(false);
1679 // Reset sit target. 1715 // Reset sit target.
1680 if (part.GetAvatarOnSitTarget() == UUID) 1716 if (part.GetAvatarOnSitTarget() == UUID)
1681 part.SetAvatarOnSitTarget(UUID.Zero); 1717 part.SetAvatarOnSitTarget(UUID.Zero);
1682
1683 m_parentPosition = part.GetWorldPosition(); 1718 m_parentPosition = part.GetWorldPosition();
1684 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1719 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1685 } 1720 }
1686 1721 // part.GetWorldRotation() is the rotation of the object being sat on
1687 if (m_physicsActor == null) 1722 // Rotation is the sittiing Av's rotation
1688 { 1723
1689 AddToPhysicalScene(false); 1724 Quaternion partRot;
1725// if (part.LinkNum == 1)
1726// { // Root prim of linkset
1727// partRot = part.ParentGroup.RootPart.RotationOffset;
1728// }
1729// else
1730// { // single or child prim
1731
1732// }
1733 if (part == null) //CW: Part may be gone. llDie() for example.
1734 {
1735 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1736 }
1737 else
1738 {
1739 partRot = part.GetWorldRotation();
1690 } 1740 }
1691 1741
1692 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1742 Quaternion partIRot = Quaternion.Inverse(partRot);
1693 m_parentPosition = Vector3.Zero;
1694 1743
1695 m_parentID = 0; 1744 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1745 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1746
1747
1748 if (m_physicsActor == null)
1749 {
1750 AddToPhysicalScene(false);
1751 }
1752 //CW: If the part isn't null then we can set the current position
1753 if (part != null)
1754 {
1755 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + (m_pos * partRot); // + av sit offset!
1756 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1757 part.IsOccupied = false;
1758 }
1759 else
1760 {
1761 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1762 AbsolutePosition = m_lastWorldPosition;
1763 }
1764
1765 m_parentPosition = Vector3.Zero;
1766 m_parentID = 0;
1696 SendFullUpdateToAllClients(); 1767 SendFullUpdateToAllClients();
1697 m_requestedSitTargetID = 0; 1768 m_requestedSitTargetID = 0;
1769
1698 if ((m_physicsActor != null) && (m_avHeight > 0)) 1770 if ((m_physicsActor != null) && (m_avHeight > 0))
1699 { 1771 {
1700 SetHeight(m_avHeight); 1772 SetHeight(m_avHeight);
1701 } 1773 }
1702 } 1774 }
1703
1704 Animator.TrySetMovementAnimation("STAND"); 1775 Animator.TrySetMovementAnimation("STAND");
1705 } 1776 }
1706 1777
@@ -1731,13 +1802,9 @@ namespace OpenSim.Region.Framework.Scenes
1731 Vector3 avSitOffSet = part.SitTargetPosition; 1802 Vector3 avSitOffSet = part.SitTargetPosition;
1732 Quaternion avSitOrientation = part.SitTargetOrientation; 1803 Quaternion avSitOrientation = part.SitTargetOrientation;
1733 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1804 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1734 1805 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1735 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1806 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1736 bool SitTargetisSet = 1807 if (SitTargetisSet && !SitTargetOccupied)
1737 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1738 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1739
1740 if (SitTargetisSet && SitTargetUnOccupied)
1741 { 1808 {
1742 //switch the target to this prim 1809 //switch the target to this prim
1743 return part; 1810 return part;
@@ -1751,84 +1818,152 @@ namespace OpenSim.Region.Framework.Scenes
1751 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1818 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1752 { 1819 {
1753 bool autopilot = true; 1820 bool autopilot = true;
1821 Vector3 autopilotTarget = new Vector3();
1822 Quaternion sitOrientation = Quaternion.Identity;
1754 Vector3 pos = new Vector3(); 1823 Vector3 pos = new Vector3();
1755 Quaternion sitOrientation = pSitOrientation;
1756 Vector3 cameraEyeOffset = Vector3.Zero; 1824 Vector3 cameraEyeOffset = Vector3.Zero;
1757 Vector3 cameraAtOffset = Vector3.Zero; 1825 Vector3 cameraAtOffset = Vector3.Zero;
1758 bool forceMouselook = false; 1826 bool forceMouselook = false;
1759 1827
1760 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1828 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1761 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1829 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1762 if (part != null) 1830 if (part == null) return;
1763 { 1831
1764 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1832 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1765 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1833 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1766 1834
1767 // Is a sit target available? 1835 // part is the prim to sit on
1768 Vector3 avSitOffSet = part.SitTargetPosition; 1836 // offset is the world-ref vector distance from that prim center to the click-spot
1769 Quaternion avSitOrientation = part.SitTargetOrientation; 1837 // UUID is the UUID of the Avatar doing the clicking
1770 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1838
1771 1839 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1772 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1840
1773 bool SitTargetisSet = 1841 // Is a sit target available?
1774 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1842 Vector3 avSitOffSet = part.SitTargetPosition;
1775 ( 1843 Quaternion avSitOrientation = part.SitTargetOrientation;
1776 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1844
1777 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1845 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1778 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1846 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1779 ) 1847 Quaternion partRot;
1780 )); 1848// if (part.LinkNum == 1)
1781 1849// { // Root prim of linkset
1782 if (SitTargetisSet && SitTargetUnOccupied) 1850// partRot = part.ParentGroup.RootPart.RotationOffset;
1783 { 1851// }
1784 part.SetAvatarOnSitTarget(UUID); 1852// else
1785 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1853// { // single or child prim
1786 sitOrientation = avSitOrientation; 1854 partRot = part.GetWorldRotation();
1787 autopilot = false; 1855// }
1788 } 1856 Quaternion partIRot = Quaternion.Inverse(partRot);
1789 1857//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1790 pos = part.AbsolutePosition + offset; 1858 // Sit analysis rewritten by KF 091125
1791 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1859 if (SitTargetisSet) // scipted sit
1792 //{ 1860 {
1793 // offset = pos; 1861 if (!part.IsOccupied)
1794 //autopilot = false; 1862 {
1795 //} 1863//Console.WriteLine("Scripted, unoccupied");
1796 if (m_physicsActor != null) 1864 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1797 { 1865 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1798 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1866 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1799 // We can remove the physicsActor until they stand up. 1867 autopilot = false; // Jump direct to scripted llSitPos()
1800 m_sitAvatarHeight = m_physicsActor.Size.Z; 1868 }
1801 1869 else
1802 if (autopilot) 1870 {
1803 { 1871//Console.WriteLine("Scripted, occupied");
1804 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1872 return;
1805 { 1873 }
1806 autopilot = false; 1874 }
1875 else // Not Scripted
1876 {
1877 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1878 {
1879 // large prim & offset, ignore if other Avs sitting
1880// offset.Z -= 0.05f;
1881 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1882 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1883
1884//Console.WriteLine(" offset ={0}", offset);
1885//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1886//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1887
1888 }
1889 else // small offset
1890 {
1891//Console.WriteLine("Small offset");
1892 if (!part.IsOccupied)
1893 {
1894 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1895 autopilotTarget = part.AbsolutePosition;
1896 }
1897 else return; // occupied small
1898 } // end large/small
1899 } // end Scripted/not
1900 cameraAtOffset = part.GetCameraAtOffset();
1901 cameraEyeOffset = part.GetCameraEyeOffset();
1902 forceMouselook = part.GetForceMouselook();
1903 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1904 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1807 1905
1808 RemoveFromPhysicalScene(); 1906 if (m_physicsActor != null)
1809 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1907 {
1810 } 1908 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1811 } 1909 // We can remove the physicsActor until they stand up.
1812 else 1910 m_sitAvatarHeight = m_physicsActor.Size.Z;
1911 if (autopilot)
1912 { // its not a scripted sit
1913// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1914 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1813 { 1915 {
1916 autopilot = false; // close enough
1917 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1918 Not using the part's position because returning the AV to the last known standing
1919 position is likely to be more friendly, isn't it? */
1814 RemoveFromPhysicalScene(); 1920 RemoveFromPhysicalScene();
1815 } 1921 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1922 } // else the autopilot will get us close
1923 }
1924 else
1925 { // its a scripted sit
1926 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1927 I *am* using the part's position this time because we have no real idea how far away
1928 the avatar is from the sit target. */
1929 RemoveFromPhysicalScene();
1816 } 1930 }
1817
1818 cameraAtOffset = part.GetCameraAtOffset();
1819 cameraEyeOffset = part.GetCameraEyeOffset();
1820 forceMouselook = part.GetForceMouselook();
1821 } 1931 }
1822 1932 else return; // physactor is null!
1823 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 1933
1824 m_requestedSitTargetUUID = targetID; 1934 Vector3 offsetr; // = offset * partIRot;
1935 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
1936 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
1937 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
1938 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
1939 offsetr = offset * partIRot;
1940//
1941 // else
1942 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
1943 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
1944 // (offset * partRot);
1945 // }
1946
1947//Console.WriteLine(" ");
1948//Console.WriteLine("link number ={0}", part.LinkNum);
1949//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
1950//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
1951//Console.WriteLine("Click offst ={0}", offset);
1952//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
1953//Console.WriteLine("offsetr ={0}", offsetr);
1954//Console.WriteLine("Camera At ={0}", cameraAtOffset);
1955//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
1956
1957 ControllingClient.SendSitResponse(part.UUID, offsetr, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
1958 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1825 // This calls HandleAgentSit twice, once from here, and the client calls 1959 // This calls HandleAgentSit twice, once from here, and the client calls
1826 // HandleAgentSit itself after it gets to the location 1960 // HandleAgentSit itself after it gets to the location
1827 // It doesn't get to the location until we've moved them there though 1961 // It doesn't get to the location until we've moved them there though
1828 // which happens in HandleAgentSit :P 1962 // which happens in HandleAgentSit :P
1829 m_autopilotMoving = autopilot; 1963 m_autopilotMoving = autopilot;
1830 m_autoPilotTarget = pos; 1964 m_autoPilotTarget = autopilotTarget;
1831 m_sitAtAutoTarget = autopilot; 1965 m_sitAtAutoTarget = autopilot;
1966 m_initialSitTarget = autopilotTarget;
1832 if (!autopilot) 1967 if (!autopilot)
1833 HandleAgentSit(remoteClient, UUID); 1968 HandleAgentSit(remoteClient, UUID);
1834 } 1969 }
@@ -2123,31 +2258,65 @@ namespace OpenSim.Region.Framework.Scenes
2123 { 2258 {
2124 if (part != null) 2259 if (part != null)
2125 { 2260 {
2261//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2126 if (part.GetAvatarOnSitTarget() == UUID) 2262 if (part.GetAvatarOnSitTarget() == UUID)
2127 { 2263 {
2264//Console.WriteLine("Scripted Sit");
2265 // Scripted sit
2128 Vector3 sitTargetPos = part.SitTargetPosition; 2266 Vector3 sitTargetPos = part.SitTargetPosition;
2129 Quaternion sitTargetOrient = part.SitTargetOrientation; 2267 Quaternion sitTargetOrient = part.SitTargetOrientation;
2130
2131 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2132 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2133
2134 //Quaternion result = (sitTargetOrient * vq) * nq;
2135
2136 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2268 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2137 m_pos += SIT_TARGET_ADJUSTMENT; 2269 m_pos += SIT_TARGET_ADJUSTMENT;
2138 m_bodyRot = sitTargetOrient; 2270 m_bodyRot = sitTargetOrient;
2139 //Rotation = sitTargetOrient;
2140 m_parentPosition = part.AbsolutePosition; 2271 m_parentPosition = part.AbsolutePosition;
2141 2272 part.IsOccupied = true;
2142 //SendTerseUpdateToAllClients();
2143 } 2273 }
2144 else 2274 else
2145 { 2275 {
2146 m_pos -= part.AbsolutePosition; 2276 // if m_avUnscriptedSitPos is zero then Av sits above center
2277 // Else Av sits at m_avUnscriptedSitPos
2278
2279 // Non-scripted sit by Kitto Flora 21Nov09
2280 // Calculate angle of line from prim to Av
2281 Quaternion partIRot;
2282// if (part.LinkNum == 1)
2283// { // Root prim of linkset
2284// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2285// }
2286// else
2287// { // single or child prim
2288 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2289// }
2290 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2291 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2292 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2293 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2294 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2295 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2296 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2297 // Av sits at world euler <0,0, z>, translated by part rotation
2298 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2299
2147 m_parentPosition = part.AbsolutePosition; 2300 m_parentPosition = part.AbsolutePosition;
2148 } 2301 part.IsOccupied = true;
2302 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2303 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2304 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2305 m_avUnscriptedSitPos; // adds click offset, if any
2306 //Set up raytrace to find top surface of prim
2307 Vector3 size = part.Scale;
2308 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2309 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2310 Vector3 down = new Vector3(0f, 0f, -1f);
2311//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2312 m_scene.PhysicsScene.RaycastWorld(
2313 start, // Vector3 position,
2314 down, // Vector3 direction,
2315 mag, // float length,
2316 SitAltitudeCallback); // retMethod
2317 } // end scripted/not
2149 } 2318 }
2150 else 2319 else // no Av
2151 { 2320 {
2152 return; 2321 return;
2153 } 2322 }
@@ -2159,11 +2328,36 @@ namespace OpenSim.Region.Framework.Scenes
2159 2328
2160 Animator.TrySetMovementAnimation(sitAnimation); 2329 Animator.TrySetMovementAnimation(sitAnimation);
2161 SendFullUpdateToAllClients(); 2330 SendFullUpdateToAllClients();
2162 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2163 // So we're also sending a terse update (which has avatar rotation)
2164 // [Update] We do now.
2165 //SendTerseUpdateToAllClients();
2166 } 2331 }
2332
2333 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2334 {
2335 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2336 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2337 if(hitYN)
2338 {
2339 // m_pos = Av offset from prim center to make look like on center
2340 // m_parentPosition = Actual center pos of prim
2341 // collisionPoint = spot on prim where we want to sit
2342 // collisionPoint.Z = global sit surface height
2343 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2344 Quaternion partIRot;
2345// if (part.LinkNum == 1)
2346/// { // Root prim of linkset
2347// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2348// }
2349// else
2350// { // single or child prim
2351 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2352// }
2353 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2354 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2355//Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2356 m_pos += offset;
2357// ControllingClient.SendClearFollowCamProperties(part.UUID);
2358
2359 }
2360 } // End SitAltitudeCallback KF.
2167 2361
2168 /// <summary> 2362 /// <summary>
2169 /// Event handler for the 'Always run' setting on the client 2363 /// Event handler for the 'Always run' setting on the client
@@ -2193,7 +2387,7 @@ namespace OpenSim.Region.Framework.Scenes
2193 /// </summary> 2387 /// </summary>
2194 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2388 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2195 /// <param name="rotation">The direction in which this avatar should now face. 2389 /// <param name="rotation">The direction in which this avatar should now face.
2196 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2390 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2197 { 2391 {
2198 if (m_isChildAgent) 2392 if (m_isChildAgent)
2199 { 2393 {
@@ -2270,7 +2464,7 @@ namespace OpenSim.Region.Framework.Scenes
2270 2464
2271 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2465 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2272 m_forceToApply = direc; 2466 m_forceToApply = direc;
2273 2467 m_isNudging = Nudging;
2274 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2468 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2275 } 2469 }
2276 2470
@@ -2285,7 +2479,7 @@ namespace OpenSim.Region.Framework.Scenes
2285 const float POSITION_TOLERANCE = 0.05f; 2479 const float POSITION_TOLERANCE = 0.05f;
2286 //const int TIME_MS_TOLERANCE = 3000; 2480 //const int TIME_MS_TOLERANCE = 3000;
2287 2481
2288 SendPrimUpdates(); 2482
2289 2483
2290 if (m_newCoarseLocations) 2484 if (m_newCoarseLocations)
2291 { 2485 {
@@ -2321,6 +2515,9 @@ namespace OpenSim.Region.Framework.Scenes
2321 CheckForBorderCrossing(); 2515 CheckForBorderCrossing();
2322 CheckForSignificantMovement(); // sends update to the modules. 2516 CheckForSignificantMovement(); // sends update to the modules.
2323 } 2517 }
2518
2519 //Sending prim updates AFTER the avatar terse updates are sent
2520 SendPrimUpdates();
2324 } 2521 }
2325 2522
2326 #endregion 2523 #endregion
@@ -3228,14 +3425,25 @@ namespace OpenSim.Region.Framework.Scenes
3228 { 3425 {
3229 if (m_forceToApply.HasValue) 3426 if (m_forceToApply.HasValue)
3230 { 3427 {
3231 Vector3 force = m_forceToApply.Value;
3232 3428
3429 Vector3 force = m_forceToApply.Value;
3233 m_updateflag = true; 3430 m_updateflag = true;
3234// movementvector = force;
3235 Velocity = force; 3431 Velocity = force;
3236 3432
3237 m_forceToApply = null; 3433 m_forceToApply = null;
3238 } 3434 }
3435 else
3436 {
3437 if (m_isNudging)
3438 {
3439 Vector3 force = Vector3.Zero;
3440
3441 m_updateflag = true;
3442 Velocity = force;
3443 m_isNudging = false;
3444 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3445 }
3446 }
3239 } 3447 }
3240 3448
3241 public override void SetText(string text, Vector3 color, double alpha) 3449 public override void SetText(string text, Vector3 color, double alpha)
@@ -3286,18 +3494,29 @@ namespace OpenSim.Region.Framework.Scenes
3286 { 3494 {
3287 if (e == null) 3495 if (e == null)
3288 return; 3496 return;
3289 3497
3290 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3498 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3291 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3292 // as of this comment the interval is set in AddToPhysicalScene 3499 // as of this comment the interval is set in AddToPhysicalScene
3293 if (Animator!=null) 3500 if (Animator!=null)
3294 Animator.UpdateMovementAnimations(); 3501 {
3502 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3503 { // else its will lock out other animation changes, like ground sit.
3504 Animator.UpdateMovementAnimations();
3505 m_updateCount--;
3506 }
3507 }
3295 3508
3296 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3509 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3297 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3510 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3298 3511
3299 CollisionPlane = Vector4.UnitW; 3512 CollisionPlane = Vector4.UnitW;
3300 3513
3514 if (m_lastColCount != coldata.Count)
3515 {
3516 m_updateCount = UPDATE_COUNT;
3517 m_lastColCount = coldata.Count;
3518 }
3519
3301 if (coldata.Count != 0 && Animator != null) 3520 if (coldata.Count != 0 && Animator != null)
3302 { 3521 {
3303 switch (Animator.CurrentMovementAnimation) 3522 switch (Animator.CurrentMovementAnimation)
@@ -3904,5 +4123,16 @@ namespace OpenSim.Region.Framework.Scenes
3904 m_reprioritization_called = false; 4123 m_reprioritization_called = false;
3905 } 4124 }
3906 } 4125 }
4126
4127 private Vector3 Quat2Euler(Quaternion rot){
4128 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4129 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4130 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4131 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4132 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4133 return(new Vector3(x,y,z));
4134 }
4135
4136
3907 } 4137 }
3908} 4138}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index c6cf4cc..4ba4fab 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -75,7 +75,7 @@ namespace OpenSim.Region.Framework.Scenes
75 75
76 foreach (EntityBase e in m_presence.Scene.Entities) 76 foreach (EntityBase e in m_presence.Scene.Entities)
77 { 77 {
78 if (e is SceneObjectGroup) 78 if (e != null && e is SceneObjectGroup)
79 m_pendingObjects.Enqueue((SceneObjectGroup)e); 79 m_pendingObjects.Enqueue((SceneObjectGroup)e);
80 } 80 }
81 } 81 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
index c77220c..68035ca 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -101,7 +101,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests
101 { 101 {
102 throw new NotImplementedException(); 102 throw new NotImplementedException();
103 } 103 }
104 104 public RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID)
105 {
106 //This connector doesn't support the windlight module yet
107 //Return default LL windlight settings
108 return new RegionMeta7WindlightData();
109 }
110 public void StoreRegionWindlightSettings(RegionMeta7WindlightData wl)
111 {
112 //This connector doesn't support the windlight module yet
113 }
105 public RegionSettings LoadRegionSettings(UUID regionUUID) 114 public RegionSettings LoadRegionSettings(UUID regionUUID)
106 { 115 {
107 return null; 116 return null;