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