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.cs45
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs24
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs26
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs601
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs133
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs592
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs570
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneViewer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs11
15 files changed, 1339 insertions, 809 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 dc9ae19..37a51d9 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -206,7 +206,11 @@ namespace OpenSim.Region.Framework.Scenes
206 public event OnMakeChildAgentDelegate OnMakeChildAgent; 206 public event OnMakeChildAgentDelegate OnMakeChildAgent;
207 207
208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence); 208 public delegate void OnMakeRootAgentDelegate(ScenePresence presence);
209 public delegate void OnSaveNewWindlightProfileDelegate();
210 public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionMeta7WindlightData wl, UUID user);
209 public event OnMakeRootAgentDelegate OnMakeRootAgent; 211 public event OnMakeRootAgentDelegate OnMakeRootAgent;
212 public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted;
213 public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile;
210 214
211 /// <summary> 215 /// <summary>
212 /// Triggered when an object or attachment enters a scene 216 /// Triggered when an object or attachment enters a scene
@@ -1216,6 +1220,24 @@ namespace OpenSim.Region.Framework.Scenes
1216 } 1220 }
1217 } 1221 }
1218 1222
1223 public void TriggerOnSendNewWindlightProfileTargeted(RegionMeta7WindlightData wl, UUID user)
1224 {
1225 OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted;
1226 if (handlerSendNewWindlightProfileTargeted != null)
1227 {
1228 handlerSendNewWindlightProfileTargeted(wl, user);
1229 }
1230 }
1231
1232 public void TriggerOnSaveNewWindlightProfile()
1233 {
1234 OnSaveNewWindlightProfileDelegate handlerSaveNewWindlightProfile = OnSaveNewWindlightProfile;
1235 if (handlerSaveNewWindlightProfile != null)
1236 {
1237 handlerSaveNewWindlightProfile();
1238 }
1239 }
1240
1219 public void TriggerOnMakeRootAgent(ScenePresence presence) 1241 public void TriggerOnMakeRootAgent(ScenePresence presence)
1220 { 1242 {
1221 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent; 1243 OnMakeRootAgentDelegate handlerMakeRootAgent = OnMakeRootAgent;
@@ -1992,4 +2014,4 @@ namespace OpenSim.Region.Framework.Scenes
1992 } 2014 }
1993 } 2015 }
1994 } 2016 }
1995} \ No newline at end of file 2017}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 41533a1..6ebd048 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 c510dc8..03f1ee2 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -603,6 +603,8 @@ namespace OpenSim.Region.Framework.Scenes
603 603
604 // Load region settings 604 // Load region settings
605 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); 605 m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID);
606 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(m_regInfo.RegionID);
607
606 if (m_storageManager.EstateDataStore != null) 608 if (m_storageManager.EstateDataStore != null)
607 { 609 {
608 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID); 610 m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID);
@@ -981,6 +983,15 @@ namespace OpenSim.Region.Framework.Scenes
981 /// <param name="seconds">float indicating duration before restart.</param> 983 /// <param name="seconds">float indicating duration before restart.</param>
982 public virtual void Restart(float seconds) 984 public virtual void Restart(float seconds)
983 { 985 {
986 Restart(seconds, true);
987 }
988
989 /// <summary>
990 /// Given float seconds, this will restart the region. showDialog will optionally alert the users.
991 /// </summary>
992 /// <param name="seconds">float indicating duration before restart.</param>
993 public virtual void Restart(float seconds, bool showDialog)
994 {
984 // notifications are done in 15 second increments 995 // notifications are done in 15 second increments
985 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request 996 // so .. if the number of seconds is less then 15 seconds, it's not really a restart request
986 // It's a 'Cancel restart' request. 997 // It's a 'Cancel restart' request.
@@ -1001,8 +1012,11 @@ namespace OpenSim.Region.Framework.Scenes
1001 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); 1012 m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed);
1002 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); 1013 m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes");
1003 m_restartTimer.Start(); 1014 m_restartTimer.Start();
1004 m_dialogModule.SendNotificationToUsersInRegion( 1015 if (showDialog)
1016 {
1017 m_dialogModule.SendNotificationToUsersInRegion(
1005 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); 1018 UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0)));
1019 }
1006 } 1020 }
1007 } 1021 }
1008 1022
@@ -1280,16 +1294,16 @@ namespace OpenSim.Region.Framework.Scenes
1280 // Check if any objects have reached their targets 1294 // Check if any objects have reached their targets
1281 CheckAtTargets(); 1295 CheckAtTargets();
1282 1296
1283 // Update SceneObjectGroups that have scheduled themselves for updates
1284 // Objects queue their updates onto all scene presences
1285 if (m_frame % m_update_objects == 0)
1286 m_sceneGraph.UpdateObjectGroups();
1287
1288 // Run through all ScenePresences looking for updates 1297 // Run through all ScenePresences looking for updates
1289 // Presence updates and queued object updates for each presence are sent to clients 1298 // Presence updates and queued object updates for each presence are sent to clients
1290 if (m_frame % m_update_presences == 0) 1299 if (m_frame % m_update_presences == 0)
1291 m_sceneGraph.UpdatePresences(); 1300 m_sceneGraph.UpdatePresences();
1292 1301
1302 // Update SceneObjectGroups that have scheduled themselves for updates
1303 // Objects queue their updates onto all scene presences
1304 if (m_frame % m_update_objects == 0)
1305 m_sceneGraph.UpdateObjectGroups();
1306
1293 int tmpPhysicsMS2 = Util.EnvironmentTickCount(); 1307 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1294 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1308 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1295 m_sceneGraph.UpdatePreparePhysics(); 1309 m_sceneGraph.UpdatePreparePhysics();
@@ -1600,6 +1614,19 @@ namespace OpenSim.Region.Framework.Scenes
1600 public void SaveTerrain() 1614 public void SaveTerrain()
1601 { 1615 {
1602 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1616 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1617 }
1618
1619 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1620 {
1621 m_regInfo.WindlightSettings = wl;
1622 m_storageManager.DataStore.StoreRegionWindlightSettings(wl);
1623 m_eventManager.TriggerOnSaveNewWindlightProfile();
1624 }
1625
1626 public void LoadWindlightProfile()
1627 {
1628 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1629 m_eventManager.TriggerOnSaveNewWindlightProfile();
1603 } 1630 }
1604 1631
1605 /// <summary> 1632 /// <summary>
@@ -3287,6 +3314,9 @@ namespace OpenSim.Region.Framework.Scenes
3287 3314
3288 CapsModule.AddCapsHandler(agent.AgentID); 3315 CapsModule.AddCapsHandler(agent.AgentID);
3289 3316
3317 if ((teleportFlags & ((uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.ViaLandmark | (uint)TeleportFlags.Default)) != 0)
3318 System.Threading.Thread.Sleep(2000);
3319
3290 if (!agent.child) 3320 if (!agent.child)
3291 { 3321 {
3292 if (TestBorderCross(agent.startpos,Cardinals.E)) 3322 if (TestBorderCross(agent.startpos,Cardinals.E))
@@ -3345,6 +3375,8 @@ namespace OpenSim.Region.Framework.Scenes
3345 } 3375 }
3346 } 3376 }
3347 // Honor parcel landing type and position. 3377 // Honor parcel landing type and position.
3378 /*
3379 ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
3348 if (land != null) 3380 if (land != null)
3349 { 3381 {
3350 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) 3382 if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
@@ -3352,6 +3384,7 @@ namespace OpenSim.Region.Framework.Scenes
3352 agent.startpos = land.LandData.UserLocation; 3384 agent.startpos = land.LandData.UserLocation;
3353 } 3385 }
3354 } 3386 }
3387 */// This is now handled properly in ScenePresence.MakeRootAgent
3355 } 3388 }
3356 3389
3357 agent.teleportFlags = teleportFlags; 3390 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 d944834..db70d6a 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 88deedf..d083119 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -106,6 +106,72 @@ namespace OpenSim.Region.Framework.Scenes
106 private bool m_hasGroupChanged = false; 106 private bool m_hasGroupChanged = false;
107 private long timeFirstChanged; 107 private long timeFirstChanged;
108 private long timeLastChanged; 108 private long timeLastChanged;
109 private System.Threading.ReaderWriterLockSlim m_partsLock = new System.Threading.ReaderWriterLockSlim();
110
111 public void lockPartsForRead(bool locked)
112 {
113 if (locked)
114 {
115 if (m_partsLock.RecursiveReadCount > 0)
116 {
117 m_log.Error("[SceneObjectGroup.m_parts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
118 m_partsLock.ExitReadLock();
119 }
120 if (m_partsLock.RecursiveWriteCount > 0)
121 {
122 m_log.Error("[SceneObjectGroup.m_parts] Recursive read lock requested. This should not happen and means something needs to be fixed.");
123 m_partsLock.ExitWriteLock();
124 }
125
126 while (!m_partsLock.TryEnterReadLock(60000))
127 {
128 m_log.Error("[SceneObjectGroup.m_parts] Thread lock detected while trying to aquire READ lock of m_parts in SceneObjectGroup. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
129 if (m_partsLock.IsWriteLockHeld)
130 {
131 m_partsLock = new System.Threading.ReaderWriterLockSlim();
132 }
133 }
134 }
135 else
136 {
137 if (m_partsLock.RecursiveReadCount > 0)
138 {
139 m_partsLock.ExitReadLock();
140 }
141 }
142 }
143 public void lockPartsForWrite(bool locked)
144 {
145 if (locked)
146 {
147 if (m_partsLock.RecursiveReadCount > 0)
148 {
149 m_log.Error("[SceneObjectGroup.m_parts] Recursive write lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
150 m_partsLock.ExitReadLock();
151 }
152 if (m_partsLock.RecursiveWriteCount > 0)
153 {
154 m_log.Error("[SceneObjectGroup.m_parts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
155 m_partsLock.ExitWriteLock();
156 }
157
158 while (!m_partsLock.TryEnterWriteLock(60000))
159 {
160 m_log.Error("[SceneObjectGroup.m_parts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
161 if (m_partsLock.IsWriteLockHeld)
162 {
163 m_partsLock = new System.Threading.ReaderWriterLockSlim();
164 }
165 }
166 }
167 else
168 {
169 if (m_partsLock.RecursiveWriteCount > 0)
170 {
171 m_partsLock.ExitWriteLock();
172 }
173 }
174 }
109 175
110 public bool HasGroupChanged 176 public bool HasGroupChanged
111 { 177 {
@@ -258,13 +324,16 @@ namespace OpenSim.Region.Framework.Scenes
258 set 324 set
259 { 325 {
260 m_regionHandle = value; 326 m_regionHandle = value;
261 lock (m_parts) 327 lockPartsForRead(true);
262 { 328 {
263 foreach (SceneObjectPart part in m_parts.Values) 329 foreach (SceneObjectPart part in m_parts.Values)
264 { 330 {
331
265 part.RegionHandle = m_regionHandle; 332 part.RegionHandle = m_regionHandle;
333
266 } 334 }
267 } 335 }
336 lockPartsForRead(false);
268 } 337 }
269 } 338 }
270 339
@@ -298,6 +367,9 @@ namespace OpenSim.Region.Framework.Scenes
298 { 367 {
299 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 368 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
300 } 369 }
370
371 lockPartsForRead(true);
372
301 if (RootPart.GetStatusSandbox()) 373 if (RootPart.GetStatusSandbox())
302 { 374 {
303 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) 375 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
@@ -305,17 +377,18 @@ namespace OpenSim.Region.Framework.Scenes
305 RootPart.ScriptSetPhysicsStatus(false); 377 RootPart.ScriptSetPhysicsStatus(false);
306 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), 378 Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
307 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); 379 ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
380 lockPartsForRead(false);
308 return; 381 return;
309 } 382 }
310 } 383 }
311 lock (m_parts) 384
385 foreach (SceneObjectPart part in m_parts.Values)
312 { 386 {
313 foreach (SceneObjectPart part in m_parts.Values) 387 part.GroupPosition = val;
314 {
315 part.GroupPosition = val;
316 }
317 } 388 }
318 389
390 lockPartsForRead(false);
391
319 //if (m_rootPart.PhysActor != null) 392 //if (m_rootPart.PhysActor != null)
320 //{ 393 //{
321 //m_rootPart.PhysActor.Position = 394 //m_rootPart.PhysActor.Position =
@@ -504,13 +577,16 @@ namespace OpenSim.Region.Framework.Scenes
504 577
505 public void SetFromItemID(UUID AssetId) 578 public void SetFromItemID(UUID AssetId)
506 { 579 {
507 lock (m_parts) 580 lockPartsForRead(true);
508 { 581 {
509 foreach (SceneObjectPart part in m_parts.Values) 582 foreach (SceneObjectPart part in m_parts.Values)
510 { 583 {
584
511 part.FromItemID = AssetId; 585 part.FromItemID = AssetId;
586
512 } 587 }
513 } 588 }
589 lockPartsForRead(false);
514 } 590 }
515 591
516 public UUID GetFromItemID() 592 public UUID GetFromItemID()
@@ -579,10 +655,11 @@ namespace OpenSim.Region.Framework.Scenes
579 Vector3 maxScale = Vector3.Zero; 655 Vector3 maxScale = Vector3.Zero;
580 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); 656 Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
581 657
582 lock (m_parts) 658 lockPartsForRead(true);
583 { 659 {
584 foreach (SceneObjectPart part in m_parts.Values) 660 foreach (SceneObjectPart part in m_parts.Values)
585 { 661 {
662
586 Vector3 partscale = part.Scale; 663 Vector3 partscale = part.Scale;
587 Vector3 partoffset = part.OffsetPosition; 664 Vector3 partoffset = part.OffsetPosition;
588 665
@@ -593,8 +670,11 @@ namespace OpenSim.Region.Framework.Scenes
593 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X; 670 maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X;
594 maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y; 671 maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y;
595 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z; 672 maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
673
596 } 674 }
597 } 675 }
676 lockPartsForRead(false);
677
598 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; 678 finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
599 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; 679 finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
600 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; 680 finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
@@ -610,10 +690,11 @@ namespace OpenSim.Region.Framework.Scenes
610 690
611 EntityIntersection result = new EntityIntersection(); 691 EntityIntersection result = new EntityIntersection();
612 692
613 lock (m_parts) 693 lockPartsForRead(true);
614 { 694 {
615 foreach (SceneObjectPart part in m_parts.Values) 695 foreach (SceneObjectPart part in m_parts.Values)
616 { 696 {
697
617 // Temporary commented to stop compiler warning 698 // Temporary commented to stop compiler warning
618 //Vector3 partPosition = 699 //Vector3 partPosition =
619 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); 700 // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
@@ -641,8 +722,10 @@ namespace OpenSim.Region.Framework.Scenes
641 result.distance = inter.distance; 722 result.distance = inter.distance;
642 } 723 }
643 } 724 }
725
644 } 726 }
645 } 727 }
728 lockPartsForRead(false);
646 return result; 729 return result;
647 } 730 }
648 731
@@ -655,10 +738,11 @@ namespace OpenSim.Region.Framework.Scenes
655 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) 738 public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
656 { 739 {
657 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f; 740 float maxX = -256f, maxY = -256f, maxZ = -256f, minX = 256f, minY = 256f, minZ = 256f;
658 lock (m_parts) 741 lockPartsForRead(true);
659 { 742 {
660 foreach (SceneObjectPart part in m_parts.Values) 743 foreach (SceneObjectPart part in m_parts.Values)
661 { 744 {
745
662 Vector3 worldPos = part.GetWorldPosition(); 746 Vector3 worldPos = part.GetWorldPosition();
663 Vector3 offset = worldPos - AbsolutePosition; 747 Vector3 offset = worldPos - AbsolutePosition;
664 Quaternion worldRot; 748 Quaternion worldRot;
@@ -717,6 +801,8 @@ namespace OpenSim.Region.Framework.Scenes
717 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 801 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
718 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 802 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
719 803
804
805
720 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); 806 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
721 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z); 807 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
722 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z); 808 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
@@ -888,6 +974,7 @@ namespace OpenSim.Region.Framework.Scenes
888 minZ = backBottomLeft.Z; 974 minZ = backBottomLeft.Z;
889 } 975 }
890 } 976 }
977 lockPartsForRead(false);
891 978
892 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); 979 Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
893 980
@@ -916,17 +1003,20 @@ namespace OpenSim.Region.Framework.Scenes
916 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1003 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
917 1004
918 // Capture script state while holding the lock 1005 // Capture script state while holding the lock
919 lock (m_parts) 1006 lockPartsForRead(true);
920 { 1007 {
921 foreach (SceneObjectPart part in m_parts.Values) 1008 foreach (SceneObjectPart part in m_parts.Values)
922 { 1009 {
1010
923 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); 1011 Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates();
924 foreach (UUID itemid in pstates.Keys) 1012 foreach (UUID itemid in pstates.Keys)
925 { 1013 {
926 states.Add(itemid, pstates[itemid]); 1014 states.Add(itemid, pstates[itemid]);
927 } 1015 }
1016
928 } 1017 }
929 } 1018 }
1019 lockPartsForRead(false);
930 1020
931 if (states.Count > 0) 1021 if (states.Count > 0)
932 { 1022 {
@@ -1094,13 +1184,16 @@ namespace OpenSim.Region.Framework.Scenes
1094 1184
1095 public override void UpdateMovement() 1185 public override void UpdateMovement()
1096 { 1186 {
1097 lock (m_parts) 1187 lockPartsForRead(true);
1098 { 1188 {
1099 foreach (SceneObjectPart part in m_parts.Values) 1189 foreach (SceneObjectPart part in m_parts.Values)
1100 { 1190 {
1191
1101 part.UpdateMovement(); 1192 part.UpdateMovement();
1193
1102 } 1194 }
1103 } 1195 }
1196 lockPartsForRead(false);
1104 } 1197 }
1105 1198
1106 public ushort GetTimeDilation() 1199 public ushort GetTimeDilation()
@@ -1144,7 +1237,7 @@ namespace OpenSim.Region.Framework.Scenes
1144 /// <param name="part"></param> 1237 /// <param name="part"></param>
1145 public void AddPart(SceneObjectPart part) 1238 public void AddPart(SceneObjectPart part)
1146 { 1239 {
1147 lock (m_parts) 1240 lockPartsForWrite(true);
1148 { 1241 {
1149 part.SetParent(this); 1242 part.SetParent(this);
1150 m_parts.Add(part.UUID, part); 1243 m_parts.Add(part.UUID, part);
@@ -1154,6 +1247,7 @@ namespace OpenSim.Region.Framework.Scenes
1154 if (part.LinkNum == 2 && RootPart != null) 1247 if (part.LinkNum == 2 && RootPart != null)
1155 RootPart.LinkNum = 1; 1248 RootPart.LinkNum = 1;
1156 } 1249 }
1250 lockPartsForWrite(false);
1157 } 1251 }
1158 1252
1159 /// <summary> 1253 /// <summary>
@@ -1161,28 +1255,33 @@ namespace OpenSim.Region.Framework.Scenes
1161 /// </summary> 1255 /// </summary>
1162 private void UpdateParentIDs() 1256 private void UpdateParentIDs()
1163 { 1257 {
1164 lock (m_parts) 1258 lockPartsForRead(true);
1165 { 1259 {
1166 foreach (SceneObjectPart part in m_parts.Values) 1260 foreach (SceneObjectPart part in m_parts.Values)
1167 { 1261 {
1262
1168 if (part.UUID != m_rootPart.UUID) 1263 if (part.UUID != m_rootPart.UUID)
1169 { 1264 {
1170 part.ParentID = m_rootPart.LocalId; 1265 part.ParentID = m_rootPart.LocalId;
1171 } 1266 }
1267
1172 } 1268 }
1173 } 1269 }
1270 lockPartsForRead(false);
1174 } 1271 }
1175 1272
1176 public void RegenerateFullIDs() 1273 public void RegenerateFullIDs()
1177 { 1274 {
1178 lock (m_parts) 1275 lockPartsForRead(true);
1179 { 1276 {
1180 foreach (SceneObjectPart part in m_parts.Values) 1277 foreach (SceneObjectPart part in m_parts.Values)
1181 { 1278 {
1279
1182 part.UUID = UUID.Random(); 1280 part.UUID = UUID.Random();
1183 1281
1184 } 1282 }
1185 } 1283 }
1284 lockPartsForRead(false);
1186 } 1285 }
1187 1286
1188 // helper provided for parts. 1287 // helper provided for parts.
@@ -1263,29 +1362,33 @@ namespace OpenSim.Region.Framework.Scenes
1263 1362
1264 DetachFromBackup(); 1363 DetachFromBackup();
1265 1364
1266 lock (m_parts) 1365 lockPartsForRead(true);
1366 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1367 lockPartsForRead(false);
1368
1369 foreach (SceneObjectPart part in values)
1267 { 1370 {
1268 foreach (SceneObjectPart part in m_parts.Values)
1269 {
1270// part.Inventory.RemoveScriptInstances(); 1371// part.Inventory.RemoveScriptInstances();
1271 1372
1272 ScenePresence[] avatars = Scene.GetScenePresences(); 1373 ScenePresence[] avatars = Scene.GetScenePresences();
1273 for (int i = 0; i < avatars.Length; i++) 1374 for (int i = 0; i < avatars.Length; i++)
1375 {
1376 if (avatars[i].ParentID == LocalId)
1274 { 1377 {
1275 if (avatars[i].ParentID == LocalId) 1378 avatars[i].StandUp();
1276 { 1379 }
1277 avatars[i].StandUp();
1278 }
1279 1380
1280 if (!silent) 1381 if (!silent)
1281 { 1382 {
1282 part.UpdateFlag = 0; 1383 part.UpdateFlag = 0;
1283 if (part == m_rootPart) 1384 if (part == m_rootPart)
1284 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId); 1385 avatars[i].ControllingClient.SendKillObject(m_regionHandle, part.LocalId);
1285 }
1286 } 1386 }
1287 } 1387 }
1388
1288 } 1389 }
1390
1391
1289 } 1392 }
1290 1393
1291 public void AddScriptLPS(int count) 1394 public void AddScriptLPS(int count)
@@ -1310,17 +1413,20 @@ namespace OpenSim.Region.Framework.Scenes
1310 1413
1311 scriptEvents aggregateScriptEvents=0; 1414 scriptEvents aggregateScriptEvents=0;
1312 1415
1313 lock (m_parts) 1416 lockPartsForRead(true);
1314 { 1417 {
1315 foreach (SceneObjectPart part in m_parts.Values) 1418 foreach (SceneObjectPart part in m_parts.Values)
1316 { 1419 {
1420
1317 if (part == null) 1421 if (part == null)
1318 continue; 1422 continue;
1319 if (part != RootPart) 1423 if (part != RootPart)
1320 part.ObjectFlags = objectflagupdate; 1424 part.ObjectFlags = objectflagupdate;
1321 aggregateScriptEvents |= part.AggregateScriptEvents; 1425 aggregateScriptEvents |= part.AggregateScriptEvents;
1426
1322 } 1427 }
1323 } 1428 }
1429 lockPartsForRead(false);
1324 1430
1325 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); 1431 m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
1326 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); 1432 m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
@@ -1362,42 +1468,52 @@ namespace OpenSim.Region.Framework.Scenes
1362 /// <param name="m_physicalPrim"></param> 1468 /// <param name="m_physicalPrim"></param>
1363 public void ApplyPhysics(bool m_physicalPrim) 1469 public void ApplyPhysics(bool m_physicalPrim)
1364 { 1470 {
1365 lock (m_parts) 1471 lockPartsForRead(true);
1472
1473 if (m_parts.Count > 1)
1366 { 1474 {
1367 if (m_parts.Count > 1) 1475 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1476 lockPartsForRead(false);
1477 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1478 foreach (SceneObjectPart part in values)
1368 { 1479 {
1369 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); 1480
1370 foreach (SceneObjectPart part in m_parts.Values) 1481 if (part.LocalId != m_rootPart.LocalId)
1371 { 1482 {
1372 if (part.LocalId != m_rootPart.LocalId) 1483 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1373 {
1374 part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim);
1375 }
1376 } 1484 }
1377 1485
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 } 1486 }
1487 // Hack to get the physics scene geometries in the right spot
1488 ResetChildPrimPhysicsPositions();
1489 }
1490 else
1491 {
1492 lockPartsForRead(false);
1493 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim);
1385 } 1494 }
1386 } 1495 }
1387 1496
1388 public void SetOwnerId(UUID userId) 1497 public void SetOwnerId(UUID userId)
1389 { 1498 {
1390 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1499 ForEachPart(delegate(SceneObjectPart part)
1500 {
1501
1502 part.OwnerID = userId;
1503
1504 });
1391 } 1505 }
1392 1506
1393 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1507 public void ForEachPart(Action<SceneObjectPart> whatToDo)
1394 { 1508 {
1395 lock (m_parts) 1509 lockPartsForRead(true);
1510 List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values);
1511 lockPartsForRead(false);
1512 foreach (SceneObjectPart part in values)
1396 { 1513 {
1397 foreach (SceneObjectPart part in m_parts.Values) 1514
1398 { 1515 whatToDo(part);
1399 whatToDo(part); 1516
1400 }
1401 } 1517 }
1402 } 1518 }
1403 1519
@@ -1495,10 +1611,11 @@ namespace OpenSim.Region.Framework.Scenes
1495 RootPart.SendFullUpdate( 1611 RootPart.SendFullUpdate(
1496 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); 1612 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID));
1497 1613
1498 lock (m_parts) 1614 lockPartsForRead(true);
1499 { 1615 {
1500 foreach (SceneObjectPart part in m_parts.Values) 1616 foreach (SceneObjectPart part in m_parts.Values)
1501 { 1617 {
1618
1502 if (part != RootPart) 1619 if (part != RootPart)
1503 part.SendFullUpdate( 1620 part.SendFullUpdate(
1504 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); 1621 remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID));
@@ -1572,10 +1689,11 @@ namespace OpenSim.Region.Framework.Scenes
1572 1689
1573 List<SceneObjectPart> partList; 1690 List<SceneObjectPart> partList;
1574 1691
1575 lock (m_parts) 1692 lockPartsForRead(true);
1576 { 1693
1577 partList = new List<SceneObjectPart>(m_parts.Values); 1694 partList = new List<SceneObjectPart>(m_parts.Values);
1578 } 1695
1696 lockPartsForRead(false);
1579 1697
1580 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1698 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1581 { 1699 {
@@ -1798,13 +1916,40 @@ namespace OpenSim.Region.Framework.Scenes
1798 } 1916 }
1799 } 1917 }
1800 1918
1919 public void rotLookAt(Quaternion target, float strength, float damping)
1920 {
1921 SceneObjectPart rootpart = m_rootPart;
1922 if (rootpart != null)
1923 {
1924 if (IsAttachment)
1925 {
1926 /*
1927 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
1928 if (avatar != null)
1929 {
1930 Rotate the Av?
1931 } */
1932 }
1933 else
1934 {
1935 if (rootpart.PhysActor != null)
1936 { // APID must be implemented in your physics system for this to function.
1937 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
1938 rootpart.PhysActor.APIDStrength = strength;
1939 rootpart.PhysActor.APIDDamping = damping;
1940 rootpart.PhysActor.APIDActive = true;
1941 }
1942 }
1943 }
1944 }
1945
1801 public void stopLookAt() 1946 public void stopLookAt()
1802 { 1947 {
1803 SceneObjectPart rootpart = m_rootPart; 1948 SceneObjectPart rootpart = m_rootPart;
1804 if (rootpart != null) 1949 if (rootpart != null)
1805 { 1950 {
1806 if (rootpart.PhysActor != null) 1951 if (rootpart.PhysActor != null)
1807 { 1952 { // APID must be implemented in your physics system for this to function.
1808 rootpart.PhysActor.APIDActive = false; 1953 rootpart.PhysActor.APIDActive = false;
1809 } 1954 }
1810 } 1955 }
@@ -1872,10 +2017,11 @@ namespace OpenSim.Region.Framework.Scenes
1872 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2017 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
1873 newPart.SetParent(this); 2018 newPart.SetParent(this);
1874 2019
1875 lock (m_parts) 2020 lockPartsForWrite(true);
1876 { 2021 {
1877 m_parts.Add(newPart.UUID, newPart); 2022 m_parts.Add(newPart.UUID, newPart);
1878 } 2023 }
2024 lockPartsForWrite(false);
1879 2025
1880 SetPartAsNonRoot(newPart); 2026 SetPartAsNonRoot(newPart);
1881 2027
@@ -1938,7 +2084,7 @@ namespace OpenSim.Region.Framework.Scenes
1938 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) 2084 //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1939 // return; 2085 // return;
1940 2086
1941 lock (m_parts) 2087 lockPartsForRead(true);
1942 { 2088 {
1943 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 2089 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1944 2090
@@ -1958,9 +2104,12 @@ namespace OpenSim.Region.Framework.Scenes
1958 { 2104 {
1959 if (!IsSelected) 2105 if (!IsSelected)
1960 part.UpdateLookAt(); 2106 part.UpdateLookAt();
2107
1961 part.SendScheduledUpdates(); 2108 part.SendScheduledUpdates();
2109
1962 } 2110 }
1963 } 2111 }
2112 lockPartsForRead(false);
1964 } 2113 }
1965 2114
1966 public void ScheduleFullUpdateToAvatar(ScenePresence presence) 2115 public void ScheduleFullUpdateToAvatar(ScenePresence presence)
@@ -1969,27 +2118,29 @@ namespace OpenSim.Region.Framework.Scenes
1969 2118
1970 RootPart.AddFullUpdateToAvatar(presence); 2119 RootPart.AddFullUpdateToAvatar(presence);
1971 2120
1972 lock (m_parts) 2121 lockPartsForRead(true);
1973 { 2122 {
1974 foreach (SceneObjectPart part in m_parts.Values) 2123 foreach (SceneObjectPart part in m_parts.Values)
1975 { 2124 {
2125
1976 if (part != RootPart) 2126 if (part != RootPart)
1977 part.AddFullUpdateToAvatar(presence); 2127 part.AddFullUpdateToAvatar(presence);
2128
1978 } 2129 }
1979 } 2130 }
2131 lockPartsForRead(false);
1980 } 2132 }
1981 2133
1982 public void ScheduleTerseUpdateToAvatar(ScenePresence presence) 2134 public void ScheduleTerseUpdateToAvatar(ScenePresence presence)
1983 { 2135 {
1984// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); 2136 lockPartsForRead(true);
1985 2137
1986 lock (m_parts) 2138 foreach (SceneObjectPart part in m_parts.Values)
1987 { 2139 {
1988 foreach (SceneObjectPart part in m_parts.Values) 2140 part.AddTerseUpdateToAvatar(presence);
1989 {
1990 part.AddTerseUpdateToAvatar(presence);
1991 }
1992 } 2141 }
2142
2143 lockPartsForRead(false);
1993 } 2144 }
1994 2145
1995 /// <summary> 2146 /// <summary>
@@ -2002,14 +2153,17 @@ namespace OpenSim.Region.Framework.Scenes
2002 checkAtTargets(); 2153 checkAtTargets();
2003 RootPart.ScheduleFullUpdate(); 2154 RootPart.ScheduleFullUpdate();
2004 2155
2005 lock (m_parts) 2156 lockPartsForRead(true);
2006 { 2157 {
2007 foreach (SceneObjectPart part in m_parts.Values) 2158 foreach (SceneObjectPart part in m_parts.Values)
2008 { 2159 {
2160
2009 if (part != RootPart) 2161 if (part != RootPart)
2010 part.ScheduleFullUpdate(); 2162 part.ScheduleFullUpdate();
2163
2011 } 2164 }
2012 } 2165 }
2166 lockPartsForRead(false);
2013 } 2167 }
2014 2168
2015 /// <summary> 2169 /// <summary>
@@ -2017,15 +2171,14 @@ namespace OpenSim.Region.Framework.Scenes
2017 /// </summary> 2171 /// </summary>
2018 public void ScheduleGroupForTerseUpdate() 2172 public void ScheduleGroupForTerseUpdate()
2019 { 2173 {
2020// m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); 2174 lockPartsForRead(true);
2021 2175
2022 lock (m_parts) 2176 foreach (SceneObjectPart part in m_parts.Values)
2023 { 2177 {
2024 foreach (SceneObjectPart part in m_parts.Values) 2178 part.ScheduleTerseUpdate();
2025 {
2026 part.ScheduleTerseUpdate();
2027 }
2028 } 2179 }
2180
2181 lockPartsForRead(false);
2029 } 2182 }
2030 2183
2031 /// <summary> 2184 /// <summary>
@@ -2040,14 +2193,17 @@ namespace OpenSim.Region.Framework.Scenes
2040 2193
2041 RootPart.SendFullUpdateToAllClients(); 2194 RootPart.SendFullUpdateToAllClients();
2042 2195
2043 lock (m_parts) 2196 lockPartsForRead(true);
2044 { 2197 {
2045 foreach (SceneObjectPart part in m_parts.Values) 2198 foreach (SceneObjectPart part in m_parts.Values)
2046 { 2199 {
2200
2047 if (part != RootPart) 2201 if (part != RootPart)
2048 part.SendFullUpdateToAllClients(); 2202 part.SendFullUpdateToAllClients();
2203
2049 } 2204 }
2050 } 2205 }
2206 lockPartsForRead(false);
2051 } 2207 }
2052 2208
2053 /// <summary> 2209 /// <summary>
@@ -2079,14 +2235,15 @@ namespace OpenSim.Region.Framework.Scenes
2079 { 2235 {
2080 if (IsDeleted) 2236 if (IsDeleted)
2081 return; 2237 return;
2082 2238
2083 lock (m_parts) 2239 lockPartsForRead(true);
2084 { 2240 {
2085 foreach (SceneObjectPart part in m_parts.Values) 2241 foreach (SceneObjectPart part in m_parts.Values)
2086 { 2242 {
2087 part.SendTerseUpdateToAllClients(); 2243 part.SendTerseUpdateToAllClients();
2088 } 2244 }
2089 } 2245 }
2246 lockPartsForRead(false);
2090 } 2247 }
2091 2248
2092 #endregion 2249 #endregion
@@ -2100,16 +2257,18 @@ namespace OpenSim.Region.Framework.Scenes
2100 /// <returns>null if no child part with that linknum or child part</returns> 2257 /// <returns>null if no child part with that linknum or child part</returns>
2101 public SceneObjectPart GetLinkNumPart(int linknum) 2258 public SceneObjectPart GetLinkNumPart(int linknum)
2102 { 2259 {
2103 lock (m_parts) 2260 lockPartsForRead(true);
2104 { 2261 {
2105 foreach (SceneObjectPart part in m_parts.Values) 2262 foreach (SceneObjectPart part in m_parts.Values)
2106 { 2263 {
2107 if (part.LinkNum == linknum) 2264 if (part.LinkNum == linknum)
2108 { 2265 {
2266 lockPartsForRead(false);
2109 return part; 2267 return part;
2110 } 2268 }
2111 } 2269 }
2112 } 2270 }
2271 lockPartsForRead(false);
2113 2272
2114 return null; 2273 return null;
2115 } 2274 }
@@ -2137,17 +2296,19 @@ namespace OpenSim.Region.Framework.Scenes
2137 public SceneObjectPart GetChildPart(uint localID) 2296 public SceneObjectPart GetChildPart(uint localID)
2138 { 2297 {
2139 //m_log.DebugFormat("Entered looking for {0}", localID); 2298 //m_log.DebugFormat("Entered looking for {0}", localID);
2140 lock (m_parts) 2299 lockPartsForRead(true);
2141 { 2300 {
2142 foreach (SceneObjectPart part in m_parts.Values) 2301 foreach (SceneObjectPart part in m_parts.Values)
2143 { 2302 {
2144 //m_log.DebugFormat("Found {0}", part.LocalId); 2303 //m_log.DebugFormat("Found {0}", part.LocalId);
2145 if (part.LocalId == localID) 2304 if (part.LocalId == localID)
2146 { 2305 {
2306 lockPartsForRead(false);
2147 return part; 2307 return part;
2148 } 2308 }
2149 } 2309 }
2150 } 2310 }
2311 lockPartsForRead(false);
2151 2312
2152 return null; 2313 return null;
2153 } 2314 }
@@ -2177,17 +2338,19 @@ namespace OpenSim.Region.Framework.Scenes
2177 public bool HasChildPrim(uint localID) 2338 public bool HasChildPrim(uint localID)
2178 { 2339 {
2179 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); 2340 //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID);
2180 lock (m_parts) 2341 lockPartsForRead(true);
2181 { 2342 {
2182 foreach (SceneObjectPart part in m_parts.Values) 2343 foreach (SceneObjectPart part in m_parts.Values)
2183 { 2344 {
2184 //m_log.DebugFormat("Found {0}", part.LocalId); 2345 //m_log.DebugFormat("Found {0}", part.LocalId);
2185 if (part.LocalId == localID) 2346 if (part.LocalId == localID)
2186 { 2347 {
2348 lockPartsForRead(false);
2187 return true; 2349 return true;
2188 } 2350 }
2189 } 2351 }
2190 } 2352 }
2353 lockPartsForRead(false);
2191 2354
2192 return false; 2355 return false;
2193 } 2356 }
@@ -2237,53 +2400,57 @@ namespace OpenSim.Region.Framework.Scenes
2237 if (m_rootPart.LinkNum == 0) 2400 if (m_rootPart.LinkNum == 0)
2238 m_rootPart.LinkNum = 1; 2401 m_rootPart.LinkNum = 1;
2239 2402
2240 lock (m_parts) 2403 lockPartsForWrite(true);
2241 { 2404
2242 m_parts.Add(linkPart.UUID, linkPart); 2405 m_parts.Add(linkPart.UUID, linkPart);
2406
2407 lockPartsForWrite(false);
2243 2408
2244 // Insert in terms of link numbers, the new links 2409 // Insert in terms of link numbers, the new links
2245 // before the current ones (with the exception of 2410 // before the current ones (with the exception of
2246 // the root prim. Shuffle the old ones up 2411 // the root prim. Shuffle the old ones up
2247 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) 2412 lockPartsForRead(true);
2413 foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts)
2414 {
2415 if (kvp.Value.LinkNum != 1)
2248 { 2416 {
2249 if (kvp.Value.LinkNum != 1) 2417 // Don't update root prim link number
2250 { 2418 kvp.Value.LinkNum += objectGroup.PrimCount;
2251 // Don't update root prim link number
2252 kvp.Value.LinkNum += objectGroup.PrimCount;
2253 }
2254 } 2419 }
2420 }
2421 lockPartsForRead(false);
2255 2422
2256 linkPart.LinkNum = 2; 2423 linkPart.LinkNum = 2;
2257 2424
2258 linkPart.SetParent(this); 2425 linkPart.SetParent(this);
2259 linkPart.AddFlag(PrimFlags.CreateSelected); 2426 linkPart.AddFlag(PrimFlags.CreateSelected);
2260 2427
2261 //if (linkPart.PhysActor != null) 2428 //if (linkPart.PhysActor != null)
2262 //{ 2429 //{
2263 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); 2430 // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
2264 2431
2265 //linkPart.PhysActor = null; 2432 //linkPart.PhysActor = null;
2266 //} 2433 //}
2267 2434
2268 //TODO: rest of parts 2435 //TODO: rest of parts
2269 int linkNum = 3; 2436 int linkNum = 3;
2270 foreach (SceneObjectPart part in objectGroup.Children.Values) 2437 foreach (SceneObjectPart part in objectGroup.Children.Values)
2438 {
2439 if (part.UUID != objectGroup.m_rootPart.UUID)
2271 { 2440 {
2272 if (part.UUID != objectGroup.m_rootPart.UUID) 2441 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2273 {
2274 LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
2275 }
2276 part.ClearUndoState();
2277 } 2442 }
2443 part.ClearUndoState();
2278 } 2444 }
2279 2445
2280 m_scene.UnlinkSceneObject(objectGroup.UUID, true); 2446 m_scene.UnlinkSceneObject(objectGroup.UUID, true);
2281 objectGroup.m_isDeleted = true; 2447 objectGroup.m_isDeleted = true;
2448
2449 objectGroup.lockPartsForWrite(true);
2282 2450
2283 lock (objectGroup.m_parts) 2451 objectGroup.m_parts.Clear();
2284 { 2452
2285 objectGroup.m_parts.Clear(); 2453 objectGroup.lockPartsForWrite(false);
2286 }
2287 2454
2288 // Can't do this yet since backup still makes use of the root part without any synchronization 2455 // Can't do this yet since backup still makes use of the root part without any synchronization
2289// objectGroup.m_rootPart = null; 2456// objectGroup.m_rootPart = null;
@@ -2353,11 +2520,12 @@ namespace OpenSim.Region.Framework.Scenes
2353 Quaternion worldRot = linkPart.GetWorldRotation(); 2520 Quaternion worldRot = linkPart.GetWorldRotation();
2354 2521
2355 // Remove the part from this object 2522 // Remove the part from this object
2356 lock (m_parts) 2523 lockPartsForWrite(true);
2357 { 2524 {
2358 m_parts.Remove(linkPart.UUID); 2525 m_parts.Remove(linkPart.UUID);
2359 } 2526 }
2360 2527 lockPartsForWrite(false);
2528 lockPartsForRead(true);
2361 if (m_parts.Count == 1 && RootPart != null) //Single prim is left 2529 if (m_parts.Count == 1 && RootPart != null) //Single prim is left
2362 RootPart.LinkNum = 0; 2530 RootPart.LinkNum = 0;
2363 else 2531 else
@@ -2368,6 +2536,7 @@ namespace OpenSim.Region.Framework.Scenes
2368 p.LinkNum--; 2536 p.LinkNum--;
2369 } 2537 }
2370 } 2538 }
2539 lockPartsForRead(false);
2371 2540
2372 linkPart.ParentID = 0; 2541 linkPart.ParentID = 0;
2373 linkPart.LinkNum = 0; 2542 linkPart.LinkNum = 0;
@@ -2689,9 +2858,12 @@ namespace OpenSim.Region.Framework.Scenes
2689 2858
2690 if (selectionPart != null) 2859 if (selectionPart != null)
2691 { 2860 {
2692 lock (m_parts) 2861 lockPartsForRead(true);
2862 List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values);
2863 lockPartsForRead(false);
2864 foreach (SceneObjectPart part in parts)
2693 { 2865 {
2694 foreach (SceneObjectPart part in m_parts.Values) 2866 if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
2695 { 2867 {
2696 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || 2868 if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax ||
2697 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || 2869 part.Scale.Y > m_scene.RegionInfo.PhysPrimMax ||
@@ -2701,12 +2873,13 @@ namespace OpenSim.Region.Framework.Scenes
2701 break; 2873 break;
2702 } 2874 }
2703 } 2875 }
2876 }
2704 2877
2705 foreach (SceneObjectPart part in m_parts.Values) 2878 foreach (SceneObjectPart part in parts)
2706 { 2879 {
2707 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); 2880 part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
2708 }
2709 } 2881 }
2882
2710 } 2883 }
2711 } 2884 }
2712 2885
@@ -2792,11 +2965,9 @@ namespace OpenSim.Region.Framework.Scenes
2792 scale.Y = m_scene.m_maxNonphys; 2965 scale.Y = m_scene.m_maxNonphys;
2793 if (scale.Z > m_scene.m_maxNonphys) 2966 if (scale.Z > m_scene.m_maxNonphys)
2794 scale.Z = m_scene.m_maxNonphys; 2967 scale.Z = m_scene.m_maxNonphys;
2795
2796 SceneObjectPart part = GetChildPart(localID); 2968 SceneObjectPart part = GetChildPart(localID);
2797 if (part != null) 2969 if (part != null)
2798 { 2970 {
2799 part.Resize(scale);
2800 if (part.PhysActor != null) 2971 if (part.PhysActor != null)
2801 { 2972 {
2802 if (part.PhysActor.IsPhysical) 2973 if (part.PhysActor.IsPhysical)
@@ -2811,7 +2982,7 @@ namespace OpenSim.Region.Framework.Scenes
2811 part.PhysActor.Size = scale; 2982 part.PhysActor.Size = scale;
2812 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); 2983 m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
2813 } 2984 }
2814 //if (part.UUID != m_rootPart.UUID) 2985 part.Resize(scale);
2815 2986
2816 HasGroupChanged = true; 2987 HasGroupChanged = true;
2817 ScheduleGroupForFullUpdate(); 2988 ScheduleGroupForFullUpdate();
@@ -2853,73 +3024,71 @@ namespace OpenSim.Region.Framework.Scenes
2853 float y = (scale.Y / part.Scale.Y); 3024 float y = (scale.Y / part.Scale.Y);
2854 float z = (scale.Z / part.Scale.Z); 3025 float z = (scale.Z / part.Scale.Z);
2855 3026
2856 lock (m_parts) 3027 lockPartsForRead(true);
3028 if (x > 1.0f || y > 1.0f || z > 1.0f)
2857 { 3029 {
2858 if (x > 1.0f || y > 1.0f || z > 1.0f) 3030 foreach (SceneObjectPart obPart in m_parts.Values)
2859 { 3031 {
2860 foreach (SceneObjectPart obPart in m_parts.Values) 3032 if (obPart.UUID != m_rootPart.UUID)
2861 { 3033 {
2862 if (obPart.UUID != m_rootPart.UUID) 3034 Vector3 oldSize = new Vector3(obPart.Scale);
2863 { 3035 obPart.IgnoreUndoUpdate = true;
2864 obPart.IgnoreUndoUpdate = true;
2865 Vector3 oldSize = new Vector3(obPart.Scale);
2866 3036
2867 float f = 1.0f; 3037 float f = 1.0f;
2868 float a = 1.0f; 3038 float a = 1.0f;
2869 3039
2870 if (part.PhysActor != null && part.PhysActor.IsPhysical) 3040 if (part.PhysActor != null && part.PhysActor.IsPhysical)
3041 {
3042 if (oldSize.X*x > m_scene.m_maxPhys)
2871 { 3043 {
2872 if (oldSize.X*x > m_scene.m_maxPhys) 3044 f = m_scene.m_maxPhys / oldSize.X;
2873 { 3045 a = f / x;
2874 f = m_scene.m_maxPhys / oldSize.X; 3046 x *= a;
2875 a = f / x; 3047 y *= a;
2876 x *= a; 3048 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 } 3049 }
2897 else 3050 if (oldSize.Y*y > m_scene.m_maxPhys)
3051 {
3052 f = m_scene.m_maxPhys / oldSize.Y;
3053 a = f / y;
3054 x *= a;
3055 y *= a;
3056 z *= a;
3057 }
3058 if (oldSize.Z*z > m_scene.m_maxPhys)
3059 {
3060 f = m_scene.m_maxPhys / oldSize.Z;
3061 a = f / z;
3062 x *= a;
3063 y *= a;
3064 z *= a;
3065 }
3066 }
3067 else
3068 {
3069 if (oldSize.X*x > m_scene.m_maxNonphys)
3070 {
3071 f = m_scene.m_maxNonphys / oldSize.X;
3072 a = f / x;
3073 x *= a;
3074 y *= a;
3075 z *= a;
3076 }
3077 if (oldSize.Y*y > m_scene.m_maxNonphys)
2898 { 3078 {
2899 if (oldSize.X*x > m_scene.m_maxNonphys) 3079 f = m_scene.m_maxNonphys / oldSize.Y;
2900 { 3080 a = f / y;
2901 f = m_scene.m_maxNonphys / oldSize.X; 3081 x *= a;
2902 a = f / x; 3082 y *= a;
2903 x *= a; 3083 z *= a;
2904 y *= a; 3084 }
2905 z *= a; 3085 if (oldSize.Z*z > m_scene.m_maxNonphys)
2906 } 3086 {
2907 if (oldSize.Y*y > m_scene.m_maxNonphys) 3087 f = m_scene.m_maxNonphys / oldSize.Z;
2908 { 3088 a = f / z;
2909 f = m_scene.m_maxNonphys / oldSize.Y; 3089 x *= a;
2910 a = f / y; 3090 y *= a;
2911 x *= a; 3091 z *= a;
2912 y *= a;
2913 z *= a;
2914 }
2915 if (oldSize.Z*z > m_scene.m_maxNonphys)
2916 {
2917 f = m_scene.m_maxNonphys / oldSize.Z;
2918 a = f / z;
2919 x *= a;
2920 y *= a;
2921 z *= a;
2922 }
2923 } 3092 }
2924 obPart.IgnoreUndoUpdate = false; 3093 obPart.IgnoreUndoUpdate = false;
2925 obPart.StoreUndoState(); 3094 obPart.StoreUndoState();
@@ -2927,6 +3096,7 @@ namespace OpenSim.Region.Framework.Scenes
2927 } 3096 }
2928 } 3097 }
2929 } 3098 }
3099 lockPartsForRead(false);
2930 3100
2931 Vector3 prevScale = part.Scale; 3101 Vector3 prevScale = part.Scale;
2932 prevScale.X *= x; 3102 prevScale.X *= x;
@@ -2934,7 +3104,7 @@ namespace OpenSim.Region.Framework.Scenes
2934 prevScale.Z *= z; 3104 prevScale.Z *= z;
2935 part.Resize(prevScale); 3105 part.Resize(prevScale);
2936 3106
2937 lock (m_parts) 3107 lockPartsForRead(true);
2938 { 3108 {
2939 foreach (SceneObjectPart obPart in m_parts.Values) 3109 foreach (SceneObjectPart obPart in m_parts.Values)
2940 { 3110 {
@@ -2956,6 +3126,7 @@ namespace OpenSim.Region.Framework.Scenes
2956 obPart.StoreUndoState(); 3126 obPart.StoreUndoState();
2957 } 3127 }
2958 } 3128 }
3129 lockPartsForRead(false);
2959 3130
2960 if (part.PhysActor != null) 3131 if (part.PhysActor != null)
2961 { 3132 {
@@ -3058,7 +3229,7 @@ namespace OpenSim.Region.Framework.Scenes
3058 axDiff *= Quaternion.Inverse(partRotation); 3229 axDiff *= Quaternion.Inverse(partRotation);
3059 diff = axDiff; 3230 diff = axDiff;
3060 3231
3061 lock (m_parts) 3232 lockPartsForRead(true);
3062 { 3233 {
3063 foreach (SceneObjectPart obPart in m_parts.Values) 3234 foreach (SceneObjectPart obPart in m_parts.Values)
3064 { 3235 {
@@ -3068,6 +3239,7 @@ namespace OpenSim.Region.Framework.Scenes
3068 } 3239 }
3069 } 3240 }
3070 } 3241 }
3242 lockPartsForRead(false);
3071 3243
3072 AbsolutePosition = newPos; 3244 AbsolutePosition = newPos;
3073 3245
@@ -3201,25 +3373,25 @@ namespace OpenSim.Region.Framework.Scenes
3201 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); 3373 m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
3202 } 3374 }
3203 3375
3204 lock (m_parts) 3376 lockPartsForRead(true);
3377
3378 foreach (SceneObjectPart prim in m_parts.Values)
3205 { 3379 {
3206 foreach (SceneObjectPart prim in m_parts.Values) 3380 if (prim.UUID != m_rootPart.UUID)
3207 { 3381 {
3208 if (prim.UUID != m_rootPart.UUID) 3382 prim.IgnoreUndoUpdate = true;
3209 { 3383 Vector3 axPos = prim.OffsetPosition;
3210 prim.IgnoreUndoUpdate = true; 3384 axPos *= oldParentRot;
3211 Vector3 axPos = prim.OffsetPosition; 3385 axPos *= Quaternion.Inverse(axRot);
3212 axPos *= oldParentRot; 3386 prim.OffsetPosition = axPos;
3213 axPos *= Quaternion.Inverse(axRot); 3387 Quaternion primsRot = prim.RotationOffset;
3214 prim.OffsetPosition = axPos; 3388 Quaternion newRot = primsRot * oldParentRot;
3215 Quaternion primsRot = prim.RotationOffset; 3389 newRot *= Quaternion.Inverse(axRot);
3216 Quaternion newRot = primsRot * oldParentRot; 3390 prim.RotationOffset = newRot;
3217 newRot *= Quaternion.Inverse(axRot); 3391 prim.ScheduleTerseUpdate();
3218 prim.RotationOffset = newRot;
3219 prim.ScheduleTerseUpdate();
3220 }
3221 } 3392 }
3222 } 3393 }
3394
3223 foreach (SceneObjectPart childpart in Children.Values) 3395 foreach (SceneObjectPart childpart in Children.Values)
3224 { 3396 {
3225 if (childpart != m_rootPart) 3397 if (childpart != m_rootPart)
@@ -3228,6 +3400,9 @@ namespace OpenSim.Region.Framework.Scenes
3228 childpart.StoreUndoState(); 3400 childpart.StoreUndoState();
3229 } 3401 }
3230 } 3402 }
3403
3404 lockPartsForRead(false);
3405
3231 m_rootPart.ScheduleTerseUpdate(); 3406 m_rootPart.ScheduleTerseUpdate();
3232 } 3407 }
3233 3408
@@ -3349,7 +3524,7 @@ namespace OpenSim.Region.Framework.Scenes
3349 if (atTargets.Count > 0) 3524 if (atTargets.Count > 0)
3350 { 3525 {
3351 uint[] localids = new uint[0]; 3526 uint[] localids = new uint[0];
3352 lock (m_parts) 3527 lockPartsForRead(true);
3353 { 3528 {
3354 localids = new uint[m_parts.Count]; 3529 localids = new uint[m_parts.Count];
3355 int cntr = 0; 3530 int cntr = 0;
@@ -3359,6 +3534,7 @@ namespace OpenSim.Region.Framework.Scenes
3359 cntr++; 3534 cntr++;
3360 } 3535 }
3361 } 3536 }
3537 lockPartsForRead(false);
3362 3538
3363 for (int ctr = 0; ctr < localids.Length; ctr++) 3539 for (int ctr = 0; ctr < localids.Length; ctr++)
3364 { 3540 {
@@ -3377,7 +3553,7 @@ namespace OpenSim.Region.Framework.Scenes
3377 { 3553 {
3378 //trigger not_at_target 3554 //trigger not_at_target
3379 uint[] localids = new uint[0]; 3555 uint[] localids = new uint[0];
3380 lock (m_parts) 3556 lockPartsForRead(true);
3381 { 3557 {
3382 localids = new uint[m_parts.Count]; 3558 localids = new uint[m_parts.Count];
3383 int cntr = 0; 3559 int cntr = 0;
@@ -3387,7 +3563,8 @@ namespace OpenSim.Region.Framework.Scenes
3387 cntr++; 3563 cntr++;
3388 } 3564 }
3389 } 3565 }
3390 3566 lockPartsForRead(false);
3567
3391 for (int ctr = 0; ctr < localids.Length; ctr++) 3568 for (int ctr = 0; ctr < localids.Length; ctr++)
3392 { 3569 {
3393 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); 3570 m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
@@ -3479,19 +3656,20 @@ namespace OpenSim.Region.Framework.Scenes
3479 public float GetMass() 3656 public float GetMass()
3480 { 3657 {
3481 float retmass = 0f; 3658 float retmass = 0f;
3482 lock (m_parts) 3659 lockPartsForRead(true);
3483 { 3660 {
3484 foreach (SceneObjectPart part in m_parts.Values) 3661 foreach (SceneObjectPart part in m_parts.Values)
3485 { 3662 {
3486 retmass += part.GetMass(); 3663 retmass += part.GetMass();
3487 } 3664 }
3488 } 3665 }
3666 lockPartsForRead(false);
3489 return retmass; 3667 return retmass;
3490 } 3668 }
3491 3669
3492 public void CheckSculptAndLoad() 3670 public void CheckSculptAndLoad()
3493 { 3671 {
3494 lock (m_parts) 3672 lockPartsForRead(true);
3495 { 3673 {
3496 if (!IsDeleted) 3674 if (!IsDeleted)
3497 { 3675 {
@@ -3516,6 +3694,7 @@ namespace OpenSim.Region.Framework.Scenes
3516 } 3694 }
3517 } 3695 }
3518 } 3696 }
3697 lockPartsForRead(false);
3519 } 3698 }
3520 3699
3521 protected void AssetReceived(string id, Object sender, AssetBase asset) 3700 protected void AssetReceived(string id, Object sender, AssetBase asset)
@@ -3536,7 +3715,7 @@ namespace OpenSim.Region.Framework.Scenes
3536 /// <param name="client"></param> 3715 /// <param name="client"></param>
3537 public void SetGroup(UUID GroupID, IClientAPI client) 3716 public void SetGroup(UUID GroupID, IClientAPI client)
3538 { 3717 {
3539 lock (m_parts) 3718 lockPartsForRead(true);
3540 { 3719 {
3541 foreach (SceneObjectPart part in m_parts.Values) 3720 foreach (SceneObjectPart part in m_parts.Values)
3542 { 3721 {
@@ -3546,6 +3725,7 @@ namespace OpenSim.Region.Framework.Scenes
3546 3725
3547 HasGroupChanged = true; 3726 HasGroupChanged = true;
3548 } 3727 }
3728 lockPartsForRead(false);
3549 3729
3550 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 3730 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
3551 // for the same object with very different properties. The caller must schedule the update. 3731 // for the same object with very different properties. The caller must schedule the update.
@@ -3567,11 +3747,12 @@ namespace OpenSim.Region.Framework.Scenes
3567 3747
3568 public void SetAttachmentPoint(byte point) 3748 public void SetAttachmentPoint(byte point)
3569 { 3749 {
3570 lock (m_parts) 3750 lockPartsForRead(true);
3571 { 3751 {
3572 foreach (SceneObjectPart part in m_parts.Values) 3752 foreach (SceneObjectPart part in m_parts.Values)
3573 part.SetAttachmentPoint(point); 3753 part.SetAttachmentPoint(point);
3574 } 3754 }
3755 lockPartsForRead(false);
3575 } 3756 }
3576 3757
3577 #region ISceneObject 3758 #region ISceneObject
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index a2b98b9..48e34ee 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -147,7 +147,7 @@ namespace OpenSim.Region.Framework.Scenes
147 147
148 // TODO: This needs to be persisted in next XML version update! 148 // TODO: This needs to be persisted in next XML version update!
149 [XmlIgnore] 149 [XmlIgnore]
150 public readonly int[] PayPrice = {-2,-2,-2,-2,-2}; 150 public int[] PayPrice = {-2,-2,-2,-2,-2};
151 [XmlIgnore] 151 [XmlIgnore]
152 public PhysicsActor PhysActor; 152 public PhysicsActor PhysActor;
153 153
@@ -274,6 +274,7 @@ namespace OpenSim.Region.Framework.Scenes
274 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 274 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
275 private Vector3 m_sitTargetPosition; 275 private Vector3 m_sitTargetPosition;
276 private string m_sitAnimation = "SIT"; 276 private string m_sitAnimation = "SIT";
277 private bool m_occupied; // KF if any av is sitting on this prim
277 private string m_text = String.Empty; 278 private string m_text = String.Empty;
278 private string m_touchName = String.Empty; 279 private string m_touchName = String.Empty;
279 private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5); 280 private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5);
@@ -452,12 +453,16 @@ namespace OpenSim.Region.Framework.Scenes
452 } 453 }
453 454
454 /// <value> 455 /// <value>
455 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 456 /// Get the inventory list
456 /// </value> 457 /// </value>
457 public TaskInventoryDictionary TaskInventory 458 public TaskInventoryDictionary TaskInventory
458 { 459 {
459 get { return m_inventory.Items; } 460 get {
460 set { m_inventory.Items = value; } 461 return m_inventory.Items;
462 }
463 set {
464 m_inventory.Items = value;
465 }
461 } 466 }
462 467
463 public uint ObjectFlags 468 public uint ObjectFlags
@@ -586,14 +591,12 @@ namespace OpenSim.Region.Framework.Scenes
586 set { m_LoopSoundSlavePrims = value; } 591 set { m_LoopSoundSlavePrims = value; }
587 } 592 }
588 593
589 [XmlIgnore]
590 public Byte[] TextureAnimation 594 public Byte[] TextureAnimation
591 { 595 {
592 get { return m_TextureAnimation; } 596 get { return m_TextureAnimation; }
593 set { m_TextureAnimation = value; } 597 set { m_TextureAnimation = value; }
594 } 598 }
595 599
596 [XmlIgnore]
597 public Byte[] ParticleSystem 600 public Byte[] ParticleSystem
598 { 601 {
599 get { return m_particleSystem; } 602 get { return m_particleSystem; }
@@ -647,7 +650,6 @@ namespace OpenSim.Region.Framework.Scenes
647 set 650 set
648 { 651 {
649 m_groupPosition = value; 652 m_groupPosition = value;
650
651 PhysicsActor actor = PhysActor; 653 PhysicsActor actor = PhysActor;
652 if (actor != null) 654 if (actor != null)
653 { 655 {
@@ -816,7 +818,16 @@ namespace OpenSim.Region.Framework.Scenes
816 /// <summary></summary> 818 /// <summary></summary>
817 public Vector3 Acceleration 819 public Vector3 Acceleration
818 { 820 {
819 get { return m_acceleration; } 821 get
822 {
823 PhysicsActor actor = PhysActor;
824 if (actor != null)
825 {
826 m_acceleration = actor.Acceleration;
827 }
828 return m_acceleration;
829 }
830
820 set { m_acceleration = value; } 831 set { m_acceleration = value; }
821 } 832 }
822 833
@@ -960,7 +971,8 @@ namespace OpenSim.Region.Framework.Scenes
960 if (IsAttachment) 971 if (IsAttachment)
961 return GroupPosition; 972 return GroupPosition;
962 973
963 return m_offsetPosition + m_groupPosition; } 974// return m_offsetPosition + m_groupPosition; }
975 return m_groupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset) ; } //KF: Rotation was ignored!
964 } 976 }
965 977
966 public SceneObjectGroup ParentGroup 978 public SceneObjectGroup ParentGroup
@@ -1112,6 +1124,13 @@ namespace OpenSim.Region.Framework.Scenes
1112 get { return _flags; } 1124 get { return _flags; }
1113 set { _flags = value; } 1125 set { _flags = value; }
1114 } 1126 }
1127
1128 [XmlIgnore]
1129 public bool IsOccupied // KF If an av is sittingon this prim
1130 {
1131 get { return m_occupied; }
1132 set { m_occupied = value; }
1133 }
1115 1134
1116 [XmlIgnore] 1135 [XmlIgnore]
1117 public UUID SitTargetAvatar 1136 public UUID SitTargetAvatar
@@ -1187,14 +1206,6 @@ namespace OpenSim.Region.Framework.Scenes
1187 } 1206 }
1188 } 1207 }
1189 1208
1190 /// <summary>
1191 /// Clear all pending updates of parts to clients
1192 /// </summary>
1193 private void ClearUpdateSchedule()
1194 {
1195 m_updateFlag = 0;
1196 }
1197
1198 private void SendObjectPropertiesToClient(UUID AgentID) 1209 private void SendObjectPropertiesToClient(UUID AgentID)
1199 { 1210 {
1200 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); 1211 ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences();
@@ -1937,12 +1948,17 @@ namespace OpenSim.Region.Framework.Scenes
1937 public Vector3 GetWorldPosition() 1948 public Vector3 GetWorldPosition()
1938 { 1949 {
1939 Quaternion parentRot = ParentGroup.RootPart.RotationOffset; 1950 Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
1940
1941 Vector3 axPos = OffsetPosition; 1951 Vector3 axPos = OffsetPosition;
1942
1943 axPos *= parentRot; 1952 axPos *= parentRot;
1944 Vector3 translationOffsetPosition = axPos; 1953 Vector3 translationOffsetPosition = axPos;
1945 return GroupPosition + translationOffsetPosition; 1954 if(_parentID == 0)
1955 {
1956 return GroupPosition;
1957 }
1958 else
1959 {
1960 return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position
1961 }
1946 } 1962 }
1947 1963
1948 /// <summary> 1964 /// <summary>
@@ -1953,7 +1969,7 @@ namespace OpenSim.Region.Framework.Scenes
1953 { 1969 {
1954 Quaternion newRot; 1970 Quaternion newRot;
1955 1971
1956 if (this.LinkNum == 0) 1972 if (this.LinkNum < 2) //KF Single or root prim
1957 { 1973 {
1958 newRot = RotationOffset; 1974 newRot = RotationOffset;
1959 } 1975 }
@@ -2611,17 +2627,18 @@ namespace OpenSim.Region.Framework.Scenes
2611 //Trys to fetch sound id from prim's inventory. 2627 //Trys to fetch sound id from prim's inventory.
2612 //Prim's inventory doesn't support non script items yet 2628 //Prim's inventory doesn't support non script items yet
2613 2629
2614 lock (TaskInventory) 2630 TaskInventory.LockItemsForRead(true);
2631
2632 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2615 { 2633 {
2616 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2634 if (item.Value.Name == sound)
2617 { 2635 {
2618 if (item.Value.Name == sound) 2636 soundID = item.Value.ItemID;
2619 { 2637 break;
2620 soundID = item.Value.ItemID;
2621 break;
2622 }
2623 } 2638 }
2624 } 2639 }
2640
2641 TaskInventory.LockItemsForRead(false);
2625 } 2642 }
2626 2643
2627 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars(); 2644 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
@@ -2689,38 +2706,7 @@ namespace OpenSim.Region.Framework.Scenes
2689 2706
2690 public void RotLookAt(Quaternion target, float strength, float damping) 2707 public void RotLookAt(Quaternion target, float strength, float damping)
2691 { 2708 {
2692 rotLookAt(target, strength, damping); 2709 m_parentGroup.rotLookAt(target, strength, damping); // This calls method in SceneObjectGroup.
2693 }
2694
2695 public void rotLookAt(Quaternion target, float strength, float damping)
2696 {
2697 if (IsAttachment)
2698 {
2699 /*
2700 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
2701 if (avatar != null)
2702 {
2703 Rotate the Av?
2704 } */
2705 }
2706 else
2707 {
2708 APIDDamp = damping;
2709 APIDStrength = strength;
2710 APIDTarget = target;
2711 }
2712 }
2713
2714 public void startLookAt(Quaternion rot, float damp, float strength)
2715 {
2716 APIDDamp = damp;
2717 APIDStrength = strength;
2718 APIDTarget = rot;
2719 }
2720
2721 public void stopLookAt()
2722 {
2723 APIDTarget = Quaternion.Identity;
2724 } 2710 }
2725 2711
2726 /// <summary> 2712 /// <summary>
@@ -2955,8 +2941,8 @@ namespace OpenSim.Region.Framework.Scenes
2955 { 2941 {
2956 const float ROTATION_TOLERANCE = 0.01f; 2942 const float ROTATION_TOLERANCE = 0.01f;
2957 const float VELOCITY_TOLERANCE = 0.001f; 2943 const float VELOCITY_TOLERANCE = 0.001f;
2958 const float POSITION_TOLERANCE = 0.05f; 2944 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2959 const int TIME_MS_TOLERANCE = 3000; 2945 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2960 2946
2961 if (m_updateFlag == 1) 2947 if (m_updateFlag == 1)
2962 { 2948 {
@@ -2970,7 +2956,7 @@ namespace OpenSim.Region.Framework.Scenes
2970 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) 2956 Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
2971 { 2957 {
2972 AddTerseUpdateToAllAvatars(); 2958 AddTerseUpdateToAllAvatars();
2973 ClearUpdateSchedule(); 2959
2974 2960
2975 // This causes the Scene to 'poll' physical objects every couple of frames 2961 // This causes the Scene to 'poll' physical objects every couple of frames
2976 // bad, so it's been replaced by an event driven method. 2962 // bad, so it's been replaced by an event driven method.
@@ -2988,16 +2974,18 @@ namespace OpenSim.Region.Framework.Scenes
2988 m_lastAngularVelocity = AngularVelocity; 2974 m_lastAngularVelocity = AngularVelocity;
2989 m_lastTerseSent = Environment.TickCount; 2975 m_lastTerseSent = Environment.TickCount;
2990 } 2976 }
2977 //Moved this outside of the if clause so updates don't get blocked.. *sigh*
2978 m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams*
2991 } 2979 }
2992 else 2980 else
2993 { 2981 {
2994 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes 2982 if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
2995 { 2983 {
2996 AddFullUpdateToAllAvatars(); 2984 AddFullUpdateToAllAvatars();
2997 ClearUpdateSchedule(); 2985 m_updateFlag = 0; //Same here
2998 } 2986 }
2999 } 2987 }
3000 ClearUpdateSchedule(); 2988 m_updateFlag = 0;
3001 } 2989 }
3002 2990
3003 /// <summary> 2991 /// <summary>
@@ -3024,17 +3012,16 @@ namespace OpenSim.Region.Framework.Scenes
3024 if (!UUID.TryParse(sound, out soundID)) 3012 if (!UUID.TryParse(sound, out soundID))
3025 { 3013 {
3026 // search sound file from inventory 3014 // search sound file from inventory
3027 lock (TaskInventory) 3015 TaskInventory.LockItemsForRead(true);
3016 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
3028 { 3017 {
3029 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3018 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
3030 { 3019 {
3031 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3020 soundID = item.Value.ItemID;
3032 { 3021 break;
3033 soundID = item.Value.ItemID;
3034 break;
3035 }
3036 } 3022 }
3037 } 3023 }
3024 TaskInventory.LockItemsForRead(false);
3038 } 3025 }
3039 3026
3040 if (soundID == UUID.Zero) 3027 if (soundID == UUID.Zero)
@@ -3470,7 +3457,7 @@ namespace OpenSim.Region.Framework.Scenes
3470 3457
3471 public void StopLookAt() 3458 public void StopLookAt()
3472 { 3459 {
3473 m_parentGroup.stopLookAt(); 3460 m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup.
3474 3461
3475 m_parentGroup.ScheduleGroupForTerseUpdate(); 3462 m_parentGroup.ScheduleGroupForTerseUpdate();
3476 } 3463 }
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 6f16ff3..24179a9 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes
73// { 73// {
74// m_log.Debug("[ScenePresence] Destructor called"); 74// m_log.Debug("[ScenePresence] Destructor called");
75// } 75// }
76 76
77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 77 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
78 78
79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 79 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
@@ -89,7 +89,9 @@ namespace OpenSim.Region.Framework.Scenes
89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 89 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
90 /// issue #1716 90 /// issue #1716
91 /// </summary> 91 /// </summary>
92 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); 92// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f);
93 // Value revised by KF 091121 by comparison with SL.
94 private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f);
93 95
94 public UUID currentParcelUUID = UUID.Zero; 96 public UUID currentParcelUUID = UUID.Zero;
95 97
@@ -123,8 +125,11 @@ namespace OpenSim.Region.Framework.Scenes
123 public Vector3 lastKnownAllowedPosition; 125 public Vector3 lastKnownAllowedPosition;
124 public bool sentMessageAboutRestrictedParcelFlyingDown; 126 public bool sentMessageAboutRestrictedParcelFlyingDown;
125 public Vector4 CollisionPlane = Vector4.UnitW; 127 public Vector4 CollisionPlane = Vector4.UnitW;
126 128
127 private Vector3 m_lastPosition; 129 private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation
130 private Vector3 m_avUnscriptedSitPos; // for non-scripted prims
131 private Vector3 m_lastPosition;
132 private Vector3 m_lastWorldPosition;
128 private Quaternion m_lastRotation; 133 private Quaternion m_lastRotation;
129 private Vector3 m_lastVelocity; 134 private Vector3 m_lastVelocity;
130 //private int m_lastTerseSent; 135 //private int m_lastTerseSent;
@@ -134,7 +139,6 @@ namespace OpenSim.Region.Framework.Scenes
134 private Vector3? m_forceToApply; 139 private Vector3? m_forceToApply;
135 private uint m_requestedSitTargetID; 140 private uint m_requestedSitTargetID;
136 private UUID m_requestedSitTargetUUID; 141 private UUID m_requestedSitTargetUUID;
137 public bool SitGround = false;
138 142
139 private SendCourseLocationsMethod m_sendCourseLocationsMethod; 143 private SendCourseLocationsMethod m_sendCourseLocationsMethod;
140 144
@@ -157,7 +161,6 @@ namespace OpenSim.Region.Framework.Scenes
157 private int m_perfMonMS; 161 private int m_perfMonMS;
158 162
159 private bool m_setAlwaysRun; 163 private bool m_setAlwaysRun;
160
161 private bool m_forceFly; 164 private bool m_forceFly;
162 private bool m_flyDisabled; 165 private bool m_flyDisabled;
163 166
@@ -183,7 +186,8 @@ namespace OpenSim.Region.Framework.Scenes
183 protected RegionInfo m_regionInfo; 186 protected RegionInfo m_regionInfo;
184 protected ulong crossingFromRegion; 187 protected ulong crossingFromRegion;
185 188
186 private readonly Vector3[] Dir_Vectors = new Vector3[9]; 189 private readonly Vector3[] Dir_Vectors = new Vector3[11];
190 private bool m_isNudging = false;
187 191
188 // Position of agent's camera in world (region cordinates) 192 // Position of agent's camera in world (region cordinates)
189 protected Vector3 m_CameraCenter; 193 protected Vector3 m_CameraCenter;
@@ -208,6 +212,7 @@ namespace OpenSim.Region.Framework.Scenes
208 private bool m_autopilotMoving; 212 private bool m_autopilotMoving;
209 private Vector3 m_autoPilotTarget; 213 private Vector3 m_autoPilotTarget;
210 private bool m_sitAtAutoTarget; 214 private bool m_sitAtAutoTarget;
215 private Vector3 m_initialSitTarget; //KF: First estimate of where to sit
211 216
212 private string m_nextSitAnimation = String.Empty; 217 private string m_nextSitAnimation = String.Empty;
213 218
@@ -218,6 +223,9 @@ namespace OpenSim.Region.Framework.Scenes
218 private bool m_followCamAuto; 223 private bool m_followCamAuto;
219 224
220 private int m_movementUpdateCount; 225 private int m_movementUpdateCount;
226 private int m_lastColCount = -1; //KF: Look for Collision chnages
227 private int m_updateCount = 0; //KF: Update Anims for a while
228 private static readonly int UPDATE_COUNT = 10; // how many frames to update for
221 229
222 private const int NumMovementsBetweenRayCast = 5; 230 private const int NumMovementsBetweenRayCast = 5;
223 231
@@ -246,7 +254,9 @@ namespace OpenSim.Region.Framework.Scenes
246 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, 254 DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
247 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, 255 DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
248 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, 256 DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS,
249 DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, 257 DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG,
258 DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS,
259 DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG,
250 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 260 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
251 } 261 }
252 262
@@ -693,10 +703,7 @@ namespace OpenSim.Region.Framework.Scenes
693 m_reprioritization_timer.AutoReset = false; 703 m_reprioritization_timer.AutoReset = false;
694 704
695 AdjustKnownSeeds(); 705 AdjustKnownSeeds();
696
697 // TODO: I think, this won't send anything, as we are still a child here...
698 Animator.TrySetMovementAnimation("STAND"); 706 Animator.TrySetMovementAnimation("STAND");
699
700 // we created a new ScenePresence (a new child agent) in a fresh region. 707 // we created a new ScenePresence (a new child agent) in a fresh region.
701 // Request info about all the (root) agents in this region 708 // Request info about all the (root) agents in this region
702 // Note: This won't send data *to* other clients in that region (children don't send) 709 // Note: This won't send data *to* other clients in that region (children don't send)
@@ -752,25 +759,47 @@ namespace OpenSim.Region.Framework.Scenes
752 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT 759 Dir_Vectors[3] = -Vector3.UnitY; //RIGHT
753 Dir_Vectors[4] = Vector3.UnitZ; //UP 760 Dir_Vectors[4] = Vector3.UnitZ; //UP
754 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN 761 Dir_Vectors[5] = -Vector3.UnitZ; //DOWN
755 Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge 762 Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE
756 Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD 763 Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE
757 Dir_Vectors[7] = -Vector3.UnitX; //BACK 764 Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE
765 Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE
766 Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge
758 } 767 }
759 768
760 private Vector3[] GetWalkDirectionVectors() 769 private Vector3[] GetWalkDirectionVectors()
761 { 770 {
762 Vector3[] vector = new Vector3[9]; 771 Vector3[] vector = new Vector3[11];
763 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD 772 vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD
764 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK 773 vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK
765 vector[2] = Vector3.UnitY; //LEFT 774 vector[2] = Vector3.UnitY; //LEFT
766 vector[3] = -Vector3.UnitY; //RIGHT 775 vector[3] = -Vector3.UnitY; //RIGHT
767 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP 776 vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP
768 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN 777 vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN
769 vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge 778 vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE
770 vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge 779 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE
771 vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge 780 vector[8] = Vector3.UnitY; //LEFT_NUDGE
781 vector[9] = -Vector3.UnitY; //RIGHT_NUDGE
782 vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE
772 return vector; 783 return vector;
773 } 784 }
785
786 private bool[] GetDirectionIsNudge()
787 {
788 bool[] isNudge = new bool[11];
789 isNudge[0] = false; //FORWARD
790 isNudge[1] = false; //BACK
791 isNudge[2] = false; //LEFT
792 isNudge[3] = false; //RIGHT
793 isNudge[4] = false; //UP
794 isNudge[5] = false; //DOWN
795 isNudge[6] = true; //FORWARD_NUDGE
796 isNudge[7] = true; //BACK_NUDGE
797 isNudge[8] = true; //LEFT_NUDGE
798 isNudge[9] = true; //RIGHT_NUDGE
799 isNudge[10] = true; //DOWN_Nudge
800 return isNudge;
801 }
802
774 803
775 #endregion 804 #endregion
776 805
@@ -839,6 +868,22 @@ namespace OpenSim.Region.Framework.Scenes
839 { 868 {
840 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 869 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
841 pos.Y = crossedBorder.BorderLine.Z - 1; 870 pos.Y = crossedBorder.BorderLine.Z - 1;
871 }
872
873 //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet.
874 //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent,
875 //they'll bypass the landing point. But I can't think of any decent way of fixing this.
876 if (KnownChildRegionHandles.Count == 0)
877 {
878 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
879 if (land != null)
880 {
881 //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni.
882 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)
883 {
884 pos = land.LandData.UserLocation;
885 }
886 }
842 } 887 }
843 888
844 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 889 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
@@ -975,9 +1020,10 @@ namespace OpenSim.Region.Framework.Scenes
975 public void Teleport(Vector3 pos) 1020 public void Teleport(Vector3 pos)
976 { 1021 {
977 bool isFlying = false; 1022 bool isFlying = false;
978 if (m_physicsActor != null)
979 isFlying = m_physicsActor.Flying;
980 1023
1024 if (m_physicsActor != null)
1025 isFlying = m_physicsActor.Flying;
1026
981 RemoveFromPhysicalScene(); 1027 RemoveFromPhysicalScene();
982 Velocity = Vector3.Zero; 1028 Velocity = Vector3.Zero;
983 AbsolutePosition = pos; 1029 AbsolutePosition = pos;
@@ -988,7 +1034,8 @@ namespace OpenSim.Region.Framework.Scenes
988 SetHeight(m_appearance.AvatarHeight); 1034 SetHeight(m_appearance.AvatarHeight);
989 } 1035 }
990 1036
991 SendTerseUpdateToAllClients(); 1037 SendTerseUpdateToAllClients();
1038
992 } 1039 }
993 1040
994 public void TeleportWithMomentum(Vector3 pos) 1041 public void TeleportWithMomentum(Vector3 pos)
@@ -1033,7 +1080,9 @@ namespace OpenSim.Region.Framework.Scenes
1033 { 1080 {
1034 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); 1081 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
1035 } 1082 }
1036 1083
1084 m_updateCount = UPDATE_COUNT; //KF: Trigger Anim updates to catch falling anim.
1085
1037 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, 1086 ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
1038 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient))); 1087 AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
1039 } 1088 }
@@ -1284,7 +1333,6 @@ namespace OpenSim.Region.Framework.Scenes
1284 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); 1333 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback);
1285 } 1334 }
1286 } 1335 }
1287
1288 lock (scriptedcontrols) 1336 lock (scriptedcontrols)
1289 { 1337 {
1290 if (scriptedcontrols.Count > 0) 1338 if (scriptedcontrols.Count > 0)
@@ -1299,12 +1347,8 @@ namespace OpenSim.Region.Framework.Scenes
1299 1347
1300 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1348 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1301 { 1349 {
1302 // TODO: This doesn't prevent the user from walking yet. 1350 m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick.
1303 // Setting parent ID would fix this, if we knew what value 1351 Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1304 // to use. Or we could add a m_isSitting variable.
1305 //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
1306 SitGround = true;
1307
1308 } 1352 }
1309 1353
1310 // In the future, these values might need to go global. 1354 // In the future, these values might need to go global.
@@ -1354,6 +1398,11 @@ namespace OpenSim.Region.Framework.Scenes
1354 update_rotation = true; 1398 update_rotation = true;
1355 } 1399 }
1356 1400
1401 //guilty until proven innocent..
1402 bool Nudging = true;
1403 //Basically, if there is at least one non-nudge control then we don't need
1404 //to worry about stopping the avatar
1405
1357 if (m_parentID == 0) 1406 if (m_parentID == 0)
1358 { 1407 {
1359 bool bAllowUpdateMoveToPosition = false; 1408 bool bAllowUpdateMoveToPosition = false;
@@ -1368,9 +1417,12 @@ namespace OpenSim.Region.Framework.Scenes
1368 else 1417 else
1369 dirVectors = Dir_Vectors; 1418 dirVectors = Dir_Vectors;
1370 1419
1371 // The fact that m_movementflag is a byte needs to be fixed 1420 bool[] isNudge = GetDirectionIsNudge();
1372 // it really should be a uint 1421
1373 uint nudgehack = 250; 1422
1423
1424
1425
1374 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) 1426 foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS)
1375 { 1427 {
1376 if (((uint)flags & (uint)DCF) != 0) 1428 if (((uint)flags & (uint)DCF) != 0)
@@ -1380,40 +1432,28 @@ namespace OpenSim.Region.Framework.Scenes
1380 try 1432 try
1381 { 1433 {
1382 agent_control_v3 += dirVectors[i]; 1434 agent_control_v3 += dirVectors[i];
1383 //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); 1435 if (isNudge[i] == false)
1436 {
1437 Nudging = false;
1438 }
1384 } 1439 }
1385 catch (IndexOutOfRangeException) 1440 catch (IndexOutOfRangeException)
1386 { 1441 {
1387 // Why did I get this? 1442 // Why did I get this?
1388 } 1443 }
1389 1444
1390 if ((m_movementflag & (byte)(uint)DCF) == 0) 1445 if ((m_movementflag & (uint)DCF) == 0)
1391 { 1446 {
1392 if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1393 {
1394 m_movementflag |= (byte)nudgehack;
1395 }
1396 m_movementflag += (byte)(uint)DCF; 1447 m_movementflag += (byte)(uint)DCF;
1397 update_movementflag = true; 1448 update_movementflag = true;
1398 } 1449 }
1399 } 1450 }
1400 else 1451 else
1401 { 1452 {
1402 if ((m_movementflag & (byte)(uint)DCF) != 0 || 1453 if ((m_movementflag & (uint)DCF) != 0)
1403 ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1404 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1405 ) // This or is for Nudge forward
1406 { 1454 {
1407 m_movementflag -= ((byte)(uint)DCF); 1455 m_movementflag -= (byte)(uint)DCF;
1408
1409 update_movementflag = true; 1456 update_movementflag = true;
1410 /*
1411 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1412 && ((m_movementflag & (byte)nudgehack) == nudgehack))
1413 {
1414 m_log.Debug("Removed Hack flag");
1415 }
1416 */
1417 } 1457 }
1418 else 1458 else
1419 { 1459 {
@@ -1457,6 +1497,9 @@ namespace OpenSim.Region.Framework.Scenes
1457 // Ignore z component of vector 1497 // Ignore z component of vector
1458 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1498 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1459 LocalVectorToTarget2D.Normalize(); 1499 LocalVectorToTarget2D.Normalize();
1500
1501 //We're not nudging
1502 Nudging = false;
1460 agent_control_v3 += LocalVectorToTarget2D; 1503 agent_control_v3 += LocalVectorToTarget2D;
1461 1504
1462 // update avatar movement flags. the avatar coordinate system is as follows: 1505 // update avatar movement flags. the avatar coordinate system is as follows:
@@ -1545,13 +1588,13 @@ namespace OpenSim.Region.Framework.Scenes
1545 // m_log.DebugFormat( 1588 // m_log.DebugFormat(
1546 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1589 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1547 1590
1548 AddNewMovement(agent_control_v3, q); 1591 AddNewMovement(agent_control_v3, q, Nudging);
1549 1592
1550 1593
1551 } 1594 }
1552 } 1595 }
1553 1596
1554 if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) 1597 if (update_movementflag)
1555 Animator.UpdateMovementAnimations(); 1598 Animator.UpdateMovementAnimations();
1556 1599
1557 m_scene.EventManager.TriggerOnClientMovement(this); 1600 m_scene.EventManager.TriggerOnClientMovement(this);
@@ -1566,7 +1609,6 @@ namespace OpenSim.Region.Framework.Scenes
1566 m_sitAtAutoTarget = false; 1609 m_sitAtAutoTarget = false;
1567 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; 1610 PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
1568 //proxy.PCode = (byte)PCode.ParticleSystem; 1611 //proxy.PCode = (byte)PCode.ParticleSystem;
1569
1570 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); 1612 proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
1571 proxyObjectGroup.AttachToScene(m_scene); 1613 proxyObjectGroup.AttachToScene(m_scene);
1572 1614
@@ -1608,7 +1650,7 @@ namespace OpenSim.Region.Framework.Scenes
1608 } 1650 }
1609 m_moveToPositionInProgress = true; 1651 m_moveToPositionInProgress = true;
1610 m_moveToPositionTarget = new Vector3(locx, locy, locz); 1652 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1611 } 1653 }
1612 catch (Exception ex) 1654 catch (Exception ex)
1613 { 1655 {
1614 //Why did I get this error? 1656 //Why did I get this error?
@@ -1630,7 +1672,7 @@ namespace OpenSim.Region.Framework.Scenes
1630 Velocity = Vector3.Zero; 1672 Velocity = Vector3.Zero;
1631 SendFullUpdateToAllClients(); 1673 SendFullUpdateToAllClients();
1632 1674
1633 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1675 HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ??
1634 } 1676 }
1635 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); 1677 //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
1636 m_requestedSitTargetUUID = UUID.Zero; 1678 m_requestedSitTargetUUID = UUID.Zero;
@@ -1663,55 +1705,84 @@ namespace OpenSim.Region.Framework.Scenes
1663 /// </summary> 1705 /// </summary>
1664 public void StandUp() 1706 public void StandUp()
1665 { 1707 {
1666 if (SitGround)
1667 SitGround = false;
1668
1669 if (m_parentID != 0) 1708 if (m_parentID != 0)
1670 { 1709 {
1671 m_log.Debug("StandupCode Executed");
1672 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); 1710 SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
1673 if (part != null) 1711 if (part != null)
1674 { 1712 {
1713 part.TaskInventory.LockItemsForRead(true);
1675 TaskInventoryDictionary taskIDict = part.TaskInventory; 1714 TaskInventoryDictionary taskIDict = part.TaskInventory;
1676 if (taskIDict != null) 1715 if (taskIDict != null)
1677 { 1716 {
1678 lock (taskIDict) 1717 foreach (UUID taskID in taskIDict.Keys)
1679 { 1718 {
1680 foreach (UUID taskID in taskIDict.Keys) 1719 UnRegisterControlEventsToScript(LocalId, taskID);
1681 { 1720 taskIDict[taskID].PermsMask &= ~(
1682 UnRegisterControlEventsToScript(LocalId, taskID); 1721 2048 | //PERMISSION_CONTROL_CAMERA
1683 taskIDict[taskID].PermsMask &= ~( 1722 4); // PERMISSION_TAKE_CONTROLS
1684 2048 | //PERMISSION_CONTROL_CAMERA
1685 4); // PERMISSION_TAKE_CONTROLS
1686 }
1687 } 1723 }
1688
1689 } 1724 }
1725 part.TaskInventory.LockItemsForRead(false);
1690 // Reset sit target. 1726 // Reset sit target.
1691 if (part.GetAvatarOnSitTarget() == UUID) 1727 if (part.GetAvatarOnSitTarget() == UUID)
1692 part.SetAvatarOnSitTarget(UUID.Zero); 1728 part.SetAvatarOnSitTarget(UUID.Zero);
1693
1694 m_parentPosition = part.GetWorldPosition(); 1729 m_parentPosition = part.GetWorldPosition();
1695 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1730 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1696 } 1731 }
1697 1732 // part.GetWorldRotation() is the rotation of the object being sat on
1698 if (m_physicsActor == null) 1733 // Rotation is the sittiing Av's rotation
1699 { 1734
1700 AddToPhysicalScene(false); 1735 Quaternion partRot;
1736// if (part.LinkNum == 1)
1737// { // Root prim of linkset
1738// partRot = part.ParentGroup.RootPart.RotationOffset;
1739// }
1740// else
1741// { // single or child prim
1742
1743// }
1744 if (part == null) //CW: Part may be gone. llDie() for example.
1745 {
1746 partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
1747 }
1748 else
1749 {
1750 partRot = part.GetWorldRotation();
1701 } 1751 }
1702 1752
1703 m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); 1753 Quaternion partIRot = Quaternion.Inverse(partRot);
1704 m_parentPosition = Vector3.Zero;
1705 1754
1706 m_parentID = 0; 1755 Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av
1756 Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av
1757
1758
1759 if (m_physicsActor == null)
1760 {
1761 AddToPhysicalScene(false);
1762 }
1763 //CW: If the part isn't null then we can set the current position
1764 if (part != null)
1765 {
1766 Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + (m_pos * partRot); // + av sit offset!
1767 AbsolutePosition = avWorldStandUp; //KF: Fix stand up.
1768 part.IsOccupied = false;
1769 }
1770 else
1771 {
1772 //CW: Since the part doesn't exist, a coarse standup position isn't an issue
1773 AbsolutePosition = m_lastWorldPosition;
1774 }
1775
1776 m_parentPosition = Vector3.Zero;
1777 m_parentID = 0;
1707 SendFullUpdateToAllClients(); 1778 SendFullUpdateToAllClients();
1708 m_requestedSitTargetID = 0; 1779 m_requestedSitTargetID = 0;
1780
1709 if ((m_physicsActor != null) && (m_avHeight > 0)) 1781 if ((m_physicsActor != null) && (m_avHeight > 0))
1710 { 1782 {
1711 SetHeight(m_avHeight); 1783 SetHeight(m_avHeight);
1712 } 1784 }
1713 } 1785 }
1714
1715 Animator.TrySetMovementAnimation("STAND"); 1786 Animator.TrySetMovementAnimation("STAND");
1716 } 1787 }
1717 1788
@@ -1742,13 +1813,9 @@ namespace OpenSim.Region.Framework.Scenes
1742 Vector3 avSitOffSet = part.SitTargetPosition; 1813 Vector3 avSitOffSet = part.SitTargetPosition;
1743 Quaternion avSitOrientation = part.SitTargetOrientation; 1814 Quaternion avSitOrientation = part.SitTargetOrientation;
1744 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1815 UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
1745 1816 bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero);
1746 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1817 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1747 bool SitTargetisSet = 1818 if (SitTargetisSet && !SitTargetOccupied)
1748 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
1749 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
1750
1751 if (SitTargetisSet && SitTargetUnOccupied)
1752 { 1819 {
1753 //switch the target to this prim 1820 //switch the target to this prim
1754 return part; 1821 return part;
@@ -1762,84 +1829,152 @@ namespace OpenSim.Region.Framework.Scenes
1762 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) 1829 private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation)
1763 { 1830 {
1764 bool autopilot = true; 1831 bool autopilot = true;
1832 Vector3 autopilotTarget = new Vector3();
1833 Quaternion sitOrientation = Quaternion.Identity;
1765 Vector3 pos = new Vector3(); 1834 Vector3 pos = new Vector3();
1766 Quaternion sitOrientation = pSitOrientation;
1767 Vector3 cameraEyeOffset = Vector3.Zero; 1835 Vector3 cameraEyeOffset = Vector3.Zero;
1768 Vector3 cameraAtOffset = Vector3.Zero; 1836 Vector3 cameraAtOffset = Vector3.Zero;
1769 bool forceMouselook = false; 1837 bool forceMouselook = false;
1770 1838
1771 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); 1839 //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
1772 SceneObjectPart part = FindNextAvailableSitTarget(targetID); 1840 SceneObjectPart part = FindNextAvailableSitTarget(targetID);
1773 if (part != null) 1841 if (part == null) return;
1774 { 1842
1775 // TODO: determine position to sit at based on scene geometry; don't trust offset from client 1843 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
1776 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 1844 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1777 1845
1778 // Is a sit target available? 1846 // part is the prim to sit on
1779 Vector3 avSitOffSet = part.SitTargetPosition; 1847 // offset is the world-ref vector distance from that prim center to the click-spot
1780 Quaternion avSitOrientation = part.SitTargetOrientation; 1848 // UUID is the UUID of the Avatar doing the clicking
1781 UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); 1849
1782 1850 m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation
1783 bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); 1851
1784 bool SitTargetisSet = 1852 // Is a sit target available?
1785 (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && 1853 Vector3 avSitOffSet = part.SitTargetPosition;
1786 ( 1854 Quaternion avSitOrientation = part.SitTargetOrientation;
1787 avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion 1855
1788 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point 1856 bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored.
1789 || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion 1857 // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation());
1790 ) 1858 Quaternion partRot;
1791 )); 1859// if (part.LinkNum == 1)
1792 1860// { // Root prim of linkset
1793 if (SitTargetisSet && SitTargetUnOccupied) 1861// partRot = part.ParentGroup.RootPart.RotationOffset;
1794 { 1862// }
1795 part.SetAvatarOnSitTarget(UUID); 1863// else
1796 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); 1864// { // single or child prim
1797 sitOrientation = avSitOrientation; 1865 partRot = part.GetWorldRotation();
1798 autopilot = false; 1866// }
1799 } 1867 Quaternion partIRot = Quaternion.Inverse(partRot);
1800 1868//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet);
1801 pos = part.AbsolutePosition + offset; 1869 // Sit analysis rewritten by KF 091125
1802 //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) 1870 if (SitTargetisSet) // scipted sit
1803 //{ 1871 {
1804 // offset = pos; 1872 if (!part.IsOccupied)
1805 //autopilot = false; 1873 {
1806 //} 1874//Console.WriteLine("Scripted, unoccupied");
1807 if (m_physicsActor != null) 1875 part.SetAvatarOnSitTarget(UUID); // set that Av will be on it
1808 { 1876 offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one
1809 // If we're not using the client autopilot, we're immediately warping the avatar to the location 1877 sitOrientation = avSitOrientation; // Change rotatione to the scripted one
1810 // We can remove the physicsActor until they stand up. 1878 autopilot = false; // Jump direct to scripted llSitPos()
1811 m_sitAvatarHeight = m_physicsActor.Size.Z; 1879 }
1812 1880 else
1813 if (autopilot) 1881 {
1814 { 1882//Console.WriteLine("Scripted, occupied");
1815 if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) 1883 return;
1816 { 1884 }
1817 autopilot = false; 1885 }
1886 else // Not Scripted
1887 {
1888 if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) )
1889 {
1890 // large prim & offset, ignore if other Avs sitting
1891// offset.Z -= 0.05f;
1892 m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked
1893 autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point
1894
1895//Console.WriteLine(" offset ={0}", offset);
1896//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos);
1897//Console.WriteLine(" autopilotTarget={0}", autopilotTarget);
1898
1899 }
1900 else // small offset
1901 {
1902//Console.WriteLine("Small offset");
1903 if (!part.IsOccupied)
1904 {
1905 m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center
1906 autopilotTarget = part.AbsolutePosition;
1907 }
1908 else return; // occupied small
1909 } // end large/small
1910 } // end Scripted/not
1911 cameraAtOffset = part.GetCameraAtOffset();
1912 cameraEyeOffset = part.GetCameraEyeOffset();
1913 forceMouselook = part.GetForceMouselook();
1914 if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); //
1915 if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); //
1818 1916
1819 RemoveFromPhysicalScene(); 1917 if (m_physicsActor != null)
1820 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 1918 {
1821 } 1919 // If we're not using the client autopilot, we're immediately warping the avatar to the location
1822 } 1920 // We can remove the physicsActor until they stand up.
1823 else 1921 m_sitAvatarHeight = m_physicsActor.Size.Z;
1922 if (autopilot)
1923 { // its not a scripted sit
1924// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5)
1925 if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) )
1824 { 1926 {
1927 autopilot = false; // close enough
1928 m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1929 Not using the part's position because returning the AV to the last known standing
1930 position is likely to be more friendly, isn't it? */
1825 RemoveFromPhysicalScene(); 1931 RemoveFromPhysicalScene();
1826 } 1932 AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target
1933 } // else the autopilot will get us close
1934 }
1935 else
1936 { // its a scripted sit
1937 m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup.
1938 I *am* using the part's position this time because we have no real idea how far away
1939 the avatar is from the sit target. */
1940 RemoveFromPhysicalScene();
1827 } 1941 }
1828
1829 cameraAtOffset = part.GetCameraAtOffset();
1830 cameraEyeOffset = part.GetCameraEyeOffset();
1831 forceMouselook = part.GetForceMouselook();
1832 } 1942 }
1833 1943 else return; // physactor is null!
1834 ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); 1944
1835 m_requestedSitTargetUUID = targetID; 1945 Vector3 offsetr; // = offset * partIRot;
1946 // KF: In a linkset, offsetr needs to be relative to the group root! 091208
1947 // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot);
1948 // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error.
1949 // { // Single, or Root prim of linkset, target is ClickOffset * RootRot
1950 offsetr = offset * partIRot;
1951//
1952 // else
1953 // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot)
1954 // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) +
1955 // (offset * partRot);
1956 // }
1957
1958//Console.WriteLine(" ");
1959//Console.WriteLine("link number ={0}", part.LinkNum);
1960//Console.WriteLine("Prim offset ={0}", part.OffsetPosition );
1961//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset);
1962//Console.WriteLine("Click offst ={0}", offset);
1963//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation());
1964//Console.WriteLine("offsetr ={0}", offsetr);
1965//Console.WriteLine("Camera At ={0}", cameraAtOffset);
1966//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset);
1967
1968 ControllingClient.SendSitResponse(part.UUID, offsetr, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
1969 m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target
1836 // This calls HandleAgentSit twice, once from here, and the client calls 1970 // This calls HandleAgentSit twice, once from here, and the client calls
1837 // HandleAgentSit itself after it gets to the location 1971 // HandleAgentSit itself after it gets to the location
1838 // It doesn't get to the location until we've moved them there though 1972 // It doesn't get to the location until we've moved them there though
1839 // which happens in HandleAgentSit :P 1973 // which happens in HandleAgentSit :P
1840 m_autopilotMoving = autopilot; 1974 m_autopilotMoving = autopilot;
1841 m_autoPilotTarget = pos; 1975 m_autoPilotTarget = autopilotTarget;
1842 m_sitAtAutoTarget = autopilot; 1976 m_sitAtAutoTarget = autopilot;
1977 m_initialSitTarget = autopilotTarget;
1843 if (!autopilot) 1978 if (!autopilot)
1844 HandleAgentSit(remoteClient, UUID); 1979 HandleAgentSit(remoteClient, UUID);
1845 } 1980 }
@@ -2134,31 +2269,65 @@ namespace OpenSim.Region.Framework.Scenes
2134 { 2269 {
2135 if (part != null) 2270 if (part != null)
2136 { 2271 {
2272//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation());
2137 if (part.GetAvatarOnSitTarget() == UUID) 2273 if (part.GetAvatarOnSitTarget() == UUID)
2138 { 2274 {
2275//Console.WriteLine("Scripted Sit");
2276 // Scripted sit
2139 Vector3 sitTargetPos = part.SitTargetPosition; 2277 Vector3 sitTargetPos = part.SitTargetPosition;
2140 Quaternion sitTargetOrient = part.SitTargetOrientation; 2278 Quaternion sitTargetOrient = part.SitTargetOrientation;
2141
2142 //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
2143 //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
2144
2145 //Quaternion result = (sitTargetOrient * vq) * nq;
2146
2147 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); 2279 m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
2148 m_pos += SIT_TARGET_ADJUSTMENT; 2280 m_pos += SIT_TARGET_ADJUSTMENT;
2149 m_bodyRot = sitTargetOrient; 2281 m_bodyRot = sitTargetOrient;
2150 //Rotation = sitTargetOrient;
2151 m_parentPosition = part.AbsolutePosition; 2282 m_parentPosition = part.AbsolutePosition;
2152 2283 part.IsOccupied = true;
2153 //SendTerseUpdateToAllClients();
2154 } 2284 }
2155 else 2285 else
2156 { 2286 {
2157 m_pos -= part.AbsolutePosition; 2287 // if m_avUnscriptedSitPos is zero then Av sits above center
2288 // Else Av sits at m_avUnscriptedSitPos
2289
2290 // Non-scripted sit by Kitto Flora 21Nov09
2291 // Calculate angle of line from prim to Av
2292 Quaternion partIRot;
2293// if (part.LinkNum == 1)
2294// { // Root prim of linkset
2295// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2296// }
2297// else
2298// { // single or child prim
2299 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2300// }
2301 Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos;
2302 float y_diff = (m_avInitialPos.Y - sitTargetPos.Y);
2303 float x_diff = ( m_avInitialPos.X - sitTargetPos.X);
2304 if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0
2305 if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0
2306 float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff);
2307 // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'.
2308 // Av sits at world euler <0,0, z>, translated by part rotation
2309 m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click
2310
2158 m_parentPosition = part.AbsolutePosition; 2311 m_parentPosition = part.AbsolutePosition;
2159 } 2312 part.IsOccupied = true;
2313 m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation
2314 (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center
2315 (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) +
2316 m_avUnscriptedSitPos; // adds click offset, if any
2317 //Set up raytrace to find top surface of prim
2318 Vector3 size = part.Scale;
2319 float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z));
2320 Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag);
2321 Vector3 down = new Vector3(0f, 0f, -1f);
2322//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag);
2323 m_scene.PhysicsScene.RaycastWorld(
2324 start, // Vector3 position,
2325 down, // Vector3 direction,
2326 mag, // float length,
2327 SitAltitudeCallback); // retMethod
2328 } // end scripted/not
2160 } 2329 }
2161 else 2330 else // no Av
2162 { 2331 {
2163 return; 2332 return;
2164 } 2333 }
@@ -2170,11 +2339,36 @@ namespace OpenSim.Region.Framework.Scenes
2170 2339
2171 Animator.TrySetMovementAnimation(sitAnimation); 2340 Animator.TrySetMovementAnimation(sitAnimation);
2172 SendFullUpdateToAllClients(); 2341 SendFullUpdateToAllClients();
2173 // This may seem stupid, but Our Full updates don't send avatar rotation :P
2174 // So we're also sending a terse update (which has avatar rotation)
2175 // [Update] We do now.
2176 //SendTerseUpdateToAllClients();
2177 } 2342 }
2343
2344 public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal)
2345 {
2346 // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer
2347 // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height.
2348 if(hitYN)
2349 {
2350 // m_pos = Av offset from prim center to make look like on center
2351 // m_parentPosition = Actual center pos of prim
2352 // collisionPoint = spot on prim where we want to sit
2353 // collisionPoint.Z = global sit surface height
2354 SceneObjectPart part = m_scene.GetSceneObjectPart(localid);
2355 Quaternion partIRot;
2356// if (part.LinkNum == 1)
2357/// { // Root prim of linkset
2358// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset);
2359// }
2360// else
2361// { // single or child prim
2362 partIRot = Quaternion.Inverse(part.GetWorldRotation());
2363// }
2364 float offZ = collisionPoint.Z - m_initialSitTarget.Z;
2365 Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction
2366//Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset);
2367 m_pos += offset;
2368// ControllingClient.SendClearFollowCamProperties(part.UUID);
2369
2370 }
2371 } // End SitAltitudeCallback KF.
2178 2372
2179 /// <summary> 2373 /// <summary>
2180 /// Event handler for the 'Always run' setting on the client 2374 /// Event handler for the 'Always run' setting on the client
@@ -2204,7 +2398,7 @@ namespace OpenSim.Region.Framework.Scenes
2204 /// </summary> 2398 /// </summary>
2205 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2399 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2206 /// <param name="rotation">The direction in which this avatar should now face. 2400 /// <param name="rotation">The direction in which this avatar should now face.
2207 public void AddNewMovement(Vector3 vec, Quaternion rotation) 2401 public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging)
2208 { 2402 {
2209 if (m_isChildAgent) 2403 if (m_isChildAgent)
2210 { 2404 {
@@ -2281,7 +2475,7 @@ namespace OpenSim.Region.Framework.Scenes
2281 2475
2282 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2476 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2283 m_forceToApply = direc; 2477 m_forceToApply = direc;
2284 2478 m_isNudging = Nudging;
2285 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2479 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2286 } 2480 }
2287 2481
@@ -2296,7 +2490,7 @@ namespace OpenSim.Region.Framework.Scenes
2296 const float POSITION_TOLERANCE = 0.05f; 2490 const float POSITION_TOLERANCE = 0.05f;
2297 //const int TIME_MS_TOLERANCE = 3000; 2491 //const int TIME_MS_TOLERANCE = 3000;
2298 2492
2299 SendPrimUpdates(); 2493
2300 2494
2301 if (m_newCoarseLocations) 2495 if (m_newCoarseLocations)
2302 { 2496 {
@@ -2332,6 +2526,9 @@ namespace OpenSim.Region.Framework.Scenes
2332 CheckForBorderCrossing(); 2526 CheckForBorderCrossing();
2333 CheckForSignificantMovement(); // sends update to the modules. 2527 CheckForSignificantMovement(); // sends update to the modules.
2334 } 2528 }
2529
2530 //Sending prim updates AFTER the avatar terse updates are sent
2531 SendPrimUpdates();
2335 } 2532 }
2336 2533
2337 #endregion 2534 #endregion
@@ -3239,14 +3436,25 @@ namespace OpenSim.Region.Framework.Scenes
3239 { 3436 {
3240 if (m_forceToApply.HasValue) 3437 if (m_forceToApply.HasValue)
3241 { 3438 {
3242 Vector3 force = m_forceToApply.Value;
3243 3439
3440 Vector3 force = m_forceToApply.Value;
3244 m_updateflag = true; 3441 m_updateflag = true;
3245// movementvector = force;
3246 Velocity = force; 3442 Velocity = force;
3247 3443
3248 m_forceToApply = null; 3444 m_forceToApply = null;
3249 } 3445 }
3446 else
3447 {
3448 if (m_isNudging)
3449 {
3450 Vector3 force = Vector3.Zero;
3451
3452 m_updateflag = true;
3453 Velocity = force;
3454 m_isNudging = false;
3455 m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
3456 }
3457 }
3250 } 3458 }
3251 3459
3252 public override void SetText(string text, Vector3 color, double alpha) 3460 public override void SetText(string text, Vector3 color, double alpha)
@@ -3297,18 +3505,29 @@ namespace OpenSim.Region.Framework.Scenes
3297 { 3505 {
3298 if (e == null) 3506 if (e == null)
3299 return; 3507 return;
3300 3508
3301 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3509 // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3302 // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents(
3303 // as of this comment the interval is set in AddToPhysicalScene 3510 // as of this comment the interval is set in AddToPhysicalScene
3304 if (Animator!=null) 3511 if (Animator!=null)
3305 Animator.UpdateMovementAnimations(); 3512 {
3513 if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper,
3514 { // else its will lock out other animation changes, like ground sit.
3515 Animator.UpdateMovementAnimations();
3516 m_updateCount--;
3517 }
3518 }
3306 3519
3307 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3520 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3308 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3521 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3309 3522
3310 CollisionPlane = Vector4.UnitW; 3523 CollisionPlane = Vector4.UnitW;
3311 3524
3525 if (m_lastColCount != coldata.Count)
3526 {
3527 m_updateCount = UPDATE_COUNT;
3528 m_lastColCount = coldata.Count;
3529 }
3530
3312 if (coldata.Count != 0 && Animator != null) 3531 if (coldata.Count != 0 && Animator != null)
3313 { 3532 {
3314 switch (Animator.CurrentMovementAnimation) 3533 switch (Animator.CurrentMovementAnimation)
@@ -3915,5 +4134,16 @@ namespace OpenSim.Region.Framework.Scenes
3915 m_reprioritization_called = false; 4134 m_reprioritization_called = false;
3916 } 4135 }
3917 } 4136 }
4137
4138 private Vector3 Quat2Euler(Quaternion rot){
4139 float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) ,
4140 (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z)));
4141 float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W)));
4142 float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) ,
4143 (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z)));
4144 return(new Vector3(x,y,z));
4145 }
4146
4147
3918 } 4148 }
3919} 4149}
diff --git a/OpenSim/Region/Framework/Scenes/SceneViewer.cs b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
index c6cf4cc..4ba4fab 100644
--- a/OpenSim/Region/Framework/Scenes/SceneViewer.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneViewer.cs
@@ -75,7 +75,7 @@ namespace OpenSim.Region.Framework.Scenes
75 75
76 foreach (EntityBase e in m_presence.Scene.Entities) 76 foreach (EntityBase e in m_presence.Scene.Entities)
77 { 77 {
78 if (e is SceneObjectGroup) 78 if (e != null && e is SceneObjectGroup)
79 m_pendingObjects.Enqueue((SceneObjectGroup)e); 79 m_pendingObjects.Enqueue((SceneObjectGroup)e);
80 } 80 }
81 } 81 }
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
index c77220c..68035ca 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -101,7 +101,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests
101 { 101 {
102 throw new NotImplementedException(); 102 throw new NotImplementedException();
103 } 103 }
104 104 public RegionMeta7WindlightData LoadRegionWindlightSettings(UUID regionUUID)
105 {
106 //This connector doesn't support the windlight module yet
107 //Return default LL windlight settings
108 return new RegionMeta7WindlightData();
109 }
110 public void StoreRegionWindlightSettings(RegionMeta7WindlightData wl)
111 {
112 //This connector doesn't support the windlight module yet
113 }
105 public RegionSettings LoadRegionSettings(UUID regionUUID) 114 public RegionSettings LoadRegionSettings(UUID regionUUID)
106 { 115 {
107 return null; 116 return null;