diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | 26 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/EntityManager.cs | 79 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/EventManager.cs | 24 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Prioritizer.cs | 15 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 67 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.cs | 142 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs | 10 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneGraph.cs | 134 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs | 26 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | 1062 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 277 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | 550 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 8099 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | 4 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/UndoState.cs | 168 |
15 files changed, 6136 insertions, 4547 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs index a90e0f3..b847d87 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | |||
@@ -53,10 +53,11 @@ 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 | public int m_animTickJump; // ScenePresence has to see this to control +Z force | ||
60 | 61 | ||
61 | /// <value> | 62 | /// <value> |
62 | /// The scene presence that this animator applies to | 63 | /// The scene presence that this animator applies to |
@@ -123,8 +124,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
123 | /// </summary> | 124 | /// </summary> |
124 | public void TrySetMovementAnimation(string anim) | 125 | public void TrySetMovementAnimation(string anim) |
125 | { | 126 | { |
126 | //m_log.DebugFormat("Updating movement animation to {0}", anim); | ||
127 | |||
128 | if (!m_scenePresence.IsChildAgent) | 127 | if (!m_scenePresence.IsChildAgent) |
129 | { | 128 | { |
130 | if (m_animations.TrySetDefaultAnimation( | 129 | if (m_animations.TrySetDefaultAnimation( |
@@ -146,10 +145,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
146 | const float PREJUMP_DELAY = 0.25f; | 145 | const float PREJUMP_DELAY = 0.25f; |
147 | 146 | ||
148 | #region Inputs | 147 | #region Inputs |
149 | if (m_scenePresence.SitGround) | 148 | |
150 | { | ||
151 | return "SIT_GROUND_CONSTRAINED"; | ||
152 | } | ||
153 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; | 149 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; |
154 | PhysicsActor actor = m_scenePresence.PhysicsActor; | 150 | PhysicsActor actor = m_scenePresence.PhysicsActor; |
155 | 151 | ||
@@ -159,11 +155,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
159 | Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); | 155 | Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); |
160 | 156 | ||
161 | // Check control flags | 157 | // Check control flags |
162 | bool heldForward = | 158 | 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)); | 159 | 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; | 160 | 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; | 161 | 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; | 162 | //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; | 163 | //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; | 164 | bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; |
@@ -266,7 +261,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
266 | m_animTickJump = Environment.TickCount; | 261 | m_animTickJump = Environment.TickCount; |
267 | return "PREJUMP"; | 262 | return "PREJUMP"; |
268 | } | 263 | } |
269 | else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f) | 264 | else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 800.0f) |
270 | { | 265 | { |
271 | // Start actual jump | 266 | // Start actual jump |
272 | if (m_animTickJump == -1) | 267 | if (m_animTickJump == -1) |
@@ -316,7 +311,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
316 | public void UpdateMovementAnimations() | 311 | public void UpdateMovementAnimations() |
317 | { | 312 | { |
318 | m_movementAnimation = GetMovementAnimation(); | 313 | m_movementAnimation = GetMovementAnimation(); |
319 | |||
320 | if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump) | 314 | if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump) |
321 | { | 315 | { |
322 | // This was the previous behavior before PREJUMP | 316 | // This was the previous behavior before PREJUMP |
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 0ae3146..52e6e92 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs | |||
@@ -55,8 +55,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
55 | 55 | ||
56 | public delegate void OnTerrainTickDelegate(); | 56 | public delegate void OnTerrainTickDelegate(); |
57 | 57 | ||
58 | public delegate void OnTerrainUpdateDelegate(); | ||
59 | |||
58 | public event OnTerrainTickDelegate OnTerrainTick; | 60 | public event OnTerrainTickDelegate OnTerrainTick; |
59 | 61 | ||
62 | public event OnTerrainUpdateDelegate OnTerrainUpdate; | ||
63 | |||
60 | public delegate void OnBackupDelegate(IRegionDataStore datastore, bool forceBackup); | 64 | public delegate void OnBackupDelegate(IRegionDataStore datastore, bool forceBackup); |
61 | 65 | ||
62 | public event OnBackupDelegate OnBackup; | 66 | public event OnBackupDelegate OnBackup; |
@@ -744,6 +748,26 @@ namespace OpenSim.Region.Framework.Scenes | |||
744 | } | 748 | } |
745 | } | 749 | } |
746 | } | 750 | } |
751 | public void TriggerTerrainUpdate() | ||
752 | { | ||
753 | OnTerrainUpdateDelegate handlerTerrainUpdate = OnTerrainUpdate; | ||
754 | if (handlerTerrainUpdate != null) | ||
755 | { | ||
756 | foreach (OnTerrainUpdateDelegate d in handlerTerrainUpdate.GetInvocationList()) | ||
757 | { | ||
758 | try | ||
759 | { | ||
760 | d(); | ||
761 | } | ||
762 | catch (Exception e) | ||
763 | { | ||
764 | m_log.ErrorFormat( | ||
765 | "[EVENT MANAGER]: Delegate for TriggerTerrainUpdate failed - continuing. {0} {1}", | ||
766 | e.Message, e.StackTrace); | ||
767 | } | ||
768 | } | ||
769 | } | ||
770 | } | ||
747 | 771 | ||
748 | public void TriggerTerrainTick() | 772 | public void TriggerTerrainTick() |
749 | { | 773 | { |
diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs index de3c360..8cd0160 100644 --- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs +++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs | |||
@@ -211,12 +211,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
211 | 211 | ||
212 | if (entity is SceneObjectPart) | 212 | if (entity is SceneObjectPart) |
213 | { | 213 | { |
214 | PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor; | ||
215 | if (physActor == null || !physActor.IsPhysical) | ||
216 | priority += 100; | ||
217 | |||
218 | if (((SceneObjectPart)entity).ParentGroup.RootPart.IsAttachment) | 214 | if (((SceneObjectPart)entity).ParentGroup.RootPart.IsAttachment) |
215 | { | ||
219 | priority = 1.0; | 216 | priority = 1.0; |
217 | } | ||
218 | else | ||
219 | { | ||
220 | PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor; | ||
221 | if (physActor == null || !physActor.IsPhysical) | ||
222 | priority += 100; | ||
223 | } | ||
224 | |||
225 | if (((SceneObjectPart)entity).ParentGroup.RootPart != (SceneObjectPart)entity) | ||
226 | priority +=1; | ||
220 | } | 227 | } |
221 | return priority; | 228 | return priority; |
222 | } | 229 | } |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 01edf51..17159b4 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | |||
@@ -94,6 +94,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
94 | 94 | ||
95 | public void AddInventoryItem(UUID AgentID, InventoryItemBase item) | 95 | public void AddInventoryItem(UUID AgentID, InventoryItemBase item) |
96 | { | 96 | { |
97 | InventoryFolderBase folder; | ||
98 | |||
99 | if (item.Folder == UUID.Zero) | ||
100 | { | ||
101 | folder = InventoryService.GetFolderForType(AgentID, (AssetType)item.AssetType); | ||
102 | if (folder == null) | ||
103 | { | ||
104 | folder = InventoryService.GetRootFolder(AgentID); | ||
105 | |||
106 | if (folder == null) | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | item.Folder = folder.ID; | ||
111 | } | ||
112 | |||
97 | if (InventoryService.AddItem(item)) | 113 | if (InventoryService.AddItem(item)) |
98 | { | 114 | { |
99 | int userlevel = 0; | 115 | int userlevel = 0; |
@@ -214,8 +230,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
214 | { | 230 | { |
215 | // Needs to determine which engine was running it and use that | 231 | // Needs to determine which engine was running it and use that |
216 | // | 232 | // |
217 | part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0); | 233 | errors = part.Inventory.CreateScriptInstanceEr(item.ItemID, 0, false, DefaultScriptEngine, 0); |
218 | errors = part.Inventory.GetScriptErrors(item.ItemID); | ||
219 | } | 234 | } |
220 | else | 235 | else |
221 | { | 236 | { |
@@ -633,6 +648,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
633 | return; | 648 | return; |
634 | } | 649 | } |
635 | 650 | ||
651 | if (newName == null) newName = item.Name; | ||
652 | |||
636 | AssetBase asset = AssetService.Get(item.AssetID.ToString()); | 653 | AssetBase asset = AssetService.Get(item.AssetID.ToString()); |
637 | 654 | ||
638 | if (asset != null) | 655 | if (asset != null) |
@@ -680,6 +697,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
680 | } | 697 | } |
681 | 698 | ||
682 | /// <summary> | 699 | /// <summary> |
700 | /// Move an item within the agent's inventory, and leave a copy (used in making a new outfit) | ||
701 | /// </summary> | ||
702 | public void MoveInventoryItemsLeaveCopy(IClientAPI remoteClient, List<InventoryItemBase> items, UUID destfolder) | ||
703 | { | ||
704 | List<InventoryItemBase> moveitems = new List<InventoryItemBase>(); | ||
705 | foreach (InventoryItemBase b in items) | ||
706 | { | ||
707 | CopyInventoryItem(remoteClient, 0, remoteClient.AgentId, b.ID, b.Folder, null); | ||
708 | InventoryItemBase n = InventoryService.GetItem(b); | ||
709 | n.Folder = destfolder; | ||
710 | moveitems.Add(n); | ||
711 | remoteClient.SendInventoryItemCreateUpdate(n, 0); | ||
712 | } | ||
713 | |||
714 | MoveInventoryItem(remoteClient, moveitems); | ||
715 | } | ||
716 | |||
717 | /// <summary> | ||
683 | /// Move an item within the agent's inventory. | 718 | /// Move an item within the agent's inventory. |
684 | /// </summary> | 719 | /// </summary> |
685 | /// <param name="remoteClient"></param> | 720 | /// <param name="remoteClient"></param> |
@@ -913,8 +948,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
913 | public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) | 948 | public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID) |
914 | { | 949 | { |
915 | SceneObjectPart part = GetSceneObjectPart(localID); | 950 | SceneObjectPart part = GetSceneObjectPart(localID); |
916 | SceneObjectGroup group = part.ParentGroup; | 951 | SceneObjectGroup group = null; |
917 | if (group != null) | 952 | if (part != null) |
953 | { | ||
954 | group = part.ParentGroup; | ||
955 | } | ||
956 | if (part != null && group != null) | ||
918 | { | 957 | { |
919 | if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)) | 958 | if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)) |
920 | return; | 959 | return; |
@@ -1489,7 +1528,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1489 | return; | 1528 | return; |
1490 | 1529 | ||
1491 | AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, | 1530 | AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, |
1492 | Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"), | 1531 | Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n\n touch_start(integer num)\n {\n }\n}"), |
1493 | remoteClient.AgentId); | 1532 | remoteClient.AgentId); |
1494 | AssetService.Store(asset); | 1533 | AssetService.Store(asset); |
1495 | 1534 | ||
@@ -1684,11 +1723,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
1684 | // Invalid id | 1723 | // Invalid id |
1685 | SceneObjectPart part = GetSceneObjectPart(localID); | 1724 | SceneObjectPart part = GetSceneObjectPart(localID); |
1686 | if (part == null) | 1725 | if (part == null) |
1726 | { | ||
1727 | //Client still thinks the object exists, kill it | ||
1728 | SendKillObject(localID); | ||
1687 | continue; | 1729 | continue; |
1730 | } | ||
1688 | 1731 | ||
1689 | // Already deleted by someone else | 1732 | // Already deleted by someone else |
1690 | if (part.ParentGroup == null || part.ParentGroup.IsDeleted) | 1733 | if (part.ParentGroup == null || part.ParentGroup.IsDeleted) |
1734 | { | ||
1735 | //Client still thinks the object exists, kill it | ||
1736 | SendKillObject(localID); | ||
1691 | continue; | 1737 | continue; |
1738 | } | ||
1692 | 1739 | ||
1693 | // Can't delete child prims | 1740 | // Can't delete child prims |
1694 | if (part != part.ParentGroup.RootPart) | 1741 | if (part != part.ParentGroup.RootPart) |
@@ -1715,15 +1762,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1715 | } | 1762 | } |
1716 | else | 1763 | else |
1717 | { | 1764 | { |
1718 | if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId)) | 1765 | if (action == DeRezAction.TakeCopy) |
1766 | { | ||
1767 | if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId)) | ||
1768 | permissionToTakeCopy = false; | ||
1769 | } | ||
1770 | else | ||
1771 | { | ||
1719 | permissionToTakeCopy = false; | 1772 | permissionToTakeCopy = false; |
1773 | } | ||
1720 | if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId)) | 1774 | if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId)) |
1721 | permissionToTake = false; | 1775 | permissionToTake = false; |
1722 | 1776 | ||
1723 | if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId)) | 1777 | if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId)) |
1724 | permissionToDelete = false; | 1778 | permissionToDelete = false; |
1725 | } | 1779 | } |
1726 | |||
1727 | } | 1780 | } |
1728 | 1781 | ||
1729 | // Handle god perms | 1782 | // Handle god perms |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index dcd7f3d..6c17be8 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -137,6 +137,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
137 | protected SceneCommunicationService m_sceneGridService; | 137 | protected SceneCommunicationService m_sceneGridService; |
138 | public bool LoginsDisabled = true; | 138 | public bool LoginsDisabled = true; |
139 | public bool LoadingPrims = false; | 139 | public bool LoadingPrims = false; |
140 | public bool CombineRegions = false; | ||
140 | 141 | ||
141 | public new float TimeDilation | 142 | public new float TimeDilation |
142 | { | 143 | { |
@@ -150,6 +151,20 @@ namespace OpenSim.Region.Framework.Scenes | |||
150 | 151 | ||
151 | public IXfer XferManager; | 152 | public IXfer XferManager; |
152 | 153 | ||
154 | protected ISnmpModule m_snmpService = null; | ||
155 | public ISnmpModule SnmpService | ||
156 | { | ||
157 | get | ||
158 | { | ||
159 | if (m_snmpService == null) | ||
160 | { | ||
161 | m_snmpService = RequestModuleInterface<ISnmpModule>(); | ||
162 | } | ||
163 | |||
164 | return m_snmpService; | ||
165 | } | ||
166 | } | ||
167 | |||
153 | protected IAssetService m_AssetService; | 168 | protected IAssetService m_AssetService; |
154 | protected IAuthorizationService m_AuthorizationService; | 169 | protected IAuthorizationService m_AuthorizationService; |
155 | 170 | ||
@@ -608,6 +623,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
608 | 623 | ||
609 | // Load region settings | 624 | // Load region settings |
610 | m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); | 625 | m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); |
626 | m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(m_regInfo.RegionID); | ||
627 | |||
611 | if (m_storageManager.EstateDataStore != null) | 628 | if (m_storageManager.EstateDataStore != null) |
612 | { | 629 | { |
613 | m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false); | 630 | m_regInfo.EstateSettings = m_storageManager.EstateDataStore.LoadEstateSettings(m_regInfo.RegionID, false); |
@@ -710,7 +727,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
710 | m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); | 727 | m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); |
711 | // TODO: Change default to true once the feature is supported | 728 | // TODO: Change default to true once the feature is supported |
712 | m_usePreJump = startupConfig.GetBoolean("enableprejump", false); | 729 | m_usePreJump = startupConfig.GetBoolean("enableprejump", false); |
713 | 730 | m_usePreJump = true; // Above line fails!? | |
714 | m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); | 731 | m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); |
715 | if (RegionInfo.NonphysPrimMax > 0) | 732 | if (RegionInfo.NonphysPrimMax > 0) |
716 | { | 733 | { |
@@ -752,6 +769,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
752 | } | 769 | } |
753 | 770 | ||
754 | m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); | 771 | m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); |
772 | CombineRegions = startupConfig.GetBoolean("CombineContiguousRegions", false); | ||
755 | 773 | ||
756 | #region BinaryStats | 774 | #region BinaryStats |
757 | 775 | ||
@@ -1024,6 +1042,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
1024 | /// <param name="seconds">float indicating duration before restart.</param> | 1042 | /// <param name="seconds">float indicating duration before restart.</param> |
1025 | public virtual void Restart(float seconds) | 1043 | public virtual void Restart(float seconds) |
1026 | { | 1044 | { |
1045 | Restart(seconds, true); | ||
1046 | } | ||
1047 | |||
1048 | /// <summary> | ||
1049 | /// Given float seconds, this will restart the region. showDialog will optionally alert the users. | ||
1050 | /// </summary> | ||
1051 | /// <param name="seconds">float indicating duration before restart.</param> | ||
1052 | public virtual void Restart(float seconds, bool showDialog) | ||
1053 | { | ||
1027 | // notifications are done in 15 second increments | 1054 | // notifications are done in 15 second increments |
1028 | // so .. if the number of seconds is less then 15 seconds, it's not really a restart request | 1055 | // so .. if the number of seconds is less then 15 seconds, it's not really a restart request |
1029 | // It's a 'Cancel restart' request. | 1056 | // It's a 'Cancel restart' request. |
@@ -1044,8 +1071,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1044 | m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); | 1071 | m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); |
1045 | m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); | 1072 | m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); |
1046 | m_restartTimer.Start(); | 1073 | m_restartTimer.Start(); |
1047 | m_dialogModule.SendNotificationToUsersInRegion( | 1074 | if (showDialog) |
1075 | { | ||
1076 | m_dialogModule.SendNotificationToUsersInRegion( | ||
1048 | UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); | 1077 | UUID.Random(), String.Empty, RegionInfo.RegionName + String.Format(": Restarting in {0} Minutes", (int)(seconds / 60.0))); |
1078 | } | ||
1049 | } | 1079 | } |
1050 | } | 1080 | } |
1051 | 1081 | ||
@@ -1403,16 +1433,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
1403 | // Check if any objects have reached their targets | 1433 | // Check if any objects have reached their targets |
1404 | CheckAtTargets(); | 1434 | CheckAtTargets(); |
1405 | 1435 | ||
1406 | // Update SceneObjectGroups that have scheduled themselves for updates | ||
1407 | // Objects queue their updates onto all scene presences | ||
1408 | if (m_frame % m_update_objects == 0) | ||
1409 | m_sceneGraph.UpdateObjectGroups(); | ||
1410 | |||
1411 | // Run through all ScenePresences looking for updates | 1436 | // Run through all ScenePresences looking for updates |
1412 | // Presence updates and queued object updates for each presence are sent to clients | 1437 | // Presence updates and queued object updates for each presence are sent to clients |
1413 | if (m_frame % m_update_presences == 0) | 1438 | if (m_frame % m_update_presences == 0) |
1414 | m_sceneGraph.UpdatePresences(); | 1439 | m_sceneGraph.UpdatePresences(); |
1415 | 1440 | ||
1441 | // Update SceneObjectGroups that have scheduled themselves for updates | ||
1442 | // Objects queue their updates onto all scene presences | ||
1443 | if (m_frame % m_update_objects == 0) | ||
1444 | m_sceneGraph.UpdateObjectGroups(); | ||
1445 | |||
1416 | if (m_frame % m_update_coarse_locations == 0) | 1446 | if (m_frame % m_update_coarse_locations == 0) |
1417 | { | 1447 | { |
1418 | List<Vector3> coarseLocations; | 1448 | List<Vector3> coarseLocations; |
@@ -1741,6 +1771,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1741 | public void StoreWindlightProfile(RegionLightShareData wl) | 1771 | public void StoreWindlightProfile(RegionLightShareData wl) |
1742 | { | 1772 | { |
1743 | m_regInfo.WindlightSettings = wl; | 1773 | m_regInfo.WindlightSettings = wl; |
1774 | wl.Save(); | ||
1744 | m_storageManager.DataStore.StoreRegionWindlightSettings(wl); | 1775 | m_storageManager.DataStore.StoreRegionWindlightSettings(wl); |
1745 | m_eventManager.TriggerOnSaveNewWindlightProfile(); | 1776 | m_eventManager.TriggerOnSaveNewWindlightProfile(); |
1746 | } | 1777 | } |
@@ -1923,14 +1954,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
1923 | /// <returns></returns> | 1954 | /// <returns></returns> |
1924 | public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) | 1955 | public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot, byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly, Vector3 scale, bool FaceCenter) |
1925 | { | 1956 | { |
1957 | |||
1958 | float wheight = (float)RegionInfo.RegionSettings.WaterHeight; | ||
1959 | Vector3 wpos = Vector3.Zero; | ||
1960 | // Check for water surface intersection from above | ||
1961 | if ( (RayStart.Z > wheight) && (RayEnd.Z < wheight) ) | ||
1962 | { | ||
1963 | float ratio = (RayStart.Z - wheight) / (RayStart.Z - RayEnd.Z); | ||
1964 | wpos.X = RayStart.X - (ratio * (RayStart.X - RayEnd.X)); | ||
1965 | wpos.Y = RayStart.Y - (ratio * (RayStart.Y - RayEnd.Y)); | ||
1966 | wpos.Z = wheight; | ||
1967 | } | ||
1968 | |||
1926 | Vector3 pos = Vector3.Zero; | 1969 | Vector3 pos = Vector3.Zero; |
1927 | if (RayEndIsIntersection == (byte)1) | 1970 | if (RayEndIsIntersection == (byte)1) |
1928 | { | 1971 | { |
1929 | pos = RayEnd; | 1972 | pos = RayEnd; |
1930 | return pos; | ||
1931 | } | 1973 | } |
1932 | 1974 | else if (RayTargetID != UUID.Zero) | |
1933 | if (RayTargetID != UUID.Zero) | ||
1934 | { | 1975 | { |
1935 | SceneObjectPart target = GetSceneObjectPart(RayTargetID); | 1976 | SceneObjectPart target = GetSceneObjectPart(RayTargetID); |
1936 | 1977 | ||
@@ -1952,7 +1993,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1952 | EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); | 1993 | EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); |
1953 | 1994 | ||
1954 | // Un-comment out the following line to Get Raytrace results printed to the console. | 1995 | // Un-comment out the following line to Get Raytrace results printed to the console. |
1955 | // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); | 1996 | // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); |
1956 | float ScaleOffset = 0.5f; | 1997 | float ScaleOffset = 0.5f; |
1957 | 1998 | ||
1958 | // If we hit something | 1999 | // If we hit something |
@@ -1975,13 +2016,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1975 | //pos.Z -= 0.25F; | 2016 | //pos.Z -= 0.25F; |
1976 | 2017 | ||
1977 | } | 2018 | } |
1978 | |||
1979 | return pos; | ||
1980 | } | 2019 | } |
1981 | else | 2020 | else |
1982 | { | 2021 | { |
1983 | // We don't have a target here, so we're going to raytrace all the objects in the scene. | 2022 | // We don't have a target here, so we're going to raytrace all the objects in the scene. |
1984 | |||
1985 | EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); | 2023 | EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false); |
1986 | 2024 | ||
1987 | // Un-comment the following line to print the raytrace results to the console. | 2025 | // Un-comment the following line to print the raytrace results to the console. |
@@ -1990,13 +2028,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
1990 | if (ei.HitTF) | 2028 | if (ei.HitTF) |
1991 | { | 2029 | { |
1992 | pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); | 2030 | pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); |
1993 | } else | 2031 | } |
2032 | else | ||
1994 | { | 2033 | { |
1995 | // fall back to our stupid functionality | 2034 | // fall back to our stupid functionality |
1996 | pos = RayEnd; | 2035 | pos = RayEnd; |
1997 | } | 2036 | } |
1998 | |||
1999 | return pos; | ||
2000 | } | 2037 | } |
2001 | } | 2038 | } |
2002 | else | 2039 | else |
@@ -2007,8 +2044,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2007 | //increase height so its above the ground. | 2044 | //increase height so its above the ground. |
2008 | //should be getting the normal of the ground at the rez point and using that? | 2045 | //should be getting the normal of the ground at the rez point and using that? |
2009 | pos.Z += scale.Z / 2f; | 2046 | pos.Z += scale.Z / 2f; |
2010 | return pos; | 2047 | // return pos; |
2011 | } | 2048 | } |
2049 | |||
2050 | // check against posible water intercept | ||
2051 | if (wpos.Z > pos.Z) pos = wpos; | ||
2052 | return pos; | ||
2012 | } | 2053 | } |
2013 | 2054 | ||
2014 | 2055 | ||
@@ -2141,13 +2182,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
2141 | public bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates) | 2182 | public bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates) |
2142 | { | 2183 | { |
2143 | return m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, sendClientUpdates); | 2184 | return m_sceneGraph.AddNewSceneObject(sceneObject, attachToBackup, sendClientUpdates); |
2144 | } | 2185 | } |
2145 | 2186 | ||
2146 | /// <summary> | 2187 | /// <summary> |
2147 | /// Delete every object from the scene. This does not include attachments worn by avatars. | 2188 | /// Delete every object from the scene. This does not include attachments worn by avatars. |
2148 | /// </summary> | 2189 | /// </summary> |
2149 | public void DeleteAllSceneObjects() | 2190 | public void DeleteAllSceneObjects() |
2150 | { | 2191 | { |
2192 | DeleteAllSceneObjects(false); | ||
2193 | } | ||
2194 | |||
2195 | /// <summary> | ||
2196 | /// Delete every object from the scene. This does not include attachments worn by avatars. | ||
2197 | /// </summary> | ||
2198 | public void DeleteAllSceneObjects(bool exceptNoCopy) | ||
2199 | { | ||
2200 | List<SceneObjectGroup> toReturn = new List<SceneObjectGroup>(); | ||
2151 | lock (Entities) | 2201 | lock (Entities) |
2152 | { | 2202 | { |
2153 | ICollection<EntityBase> entities = new List<EntityBase>(Entities); | 2203 | ICollection<EntityBase> entities = new List<EntityBase>(Entities); |
@@ -2157,11 +2207,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
2157 | if (e is SceneObjectGroup) | 2207 | if (e is SceneObjectGroup) |
2158 | { | 2208 | { |
2159 | SceneObjectGroup sog = (SceneObjectGroup)e; | 2209 | SceneObjectGroup sog = (SceneObjectGroup)e; |
2160 | if (!sog.IsAttachment) | 2210 | if (sog != null && !sog.IsAttachment) |
2161 | DeleteSceneObject((SceneObjectGroup)e, false); | 2211 | { |
2212 | if (!exceptNoCopy || ((sog.GetEffectivePermissions() & (uint)PermissionMask.Copy) != 0)) | ||
2213 | { | ||
2214 | DeleteSceneObject((SceneObjectGroup)e, false); | ||
2215 | } | ||
2216 | else | ||
2217 | { | ||
2218 | toReturn.Add((SceneObjectGroup)e); | ||
2219 | } | ||
2220 | } | ||
2162 | } | 2221 | } |
2163 | } | 2222 | } |
2164 | } | 2223 | } |
2224 | if (toReturn.Count > 0) | ||
2225 | { | ||
2226 | returnObjects(toReturn.ToArray(), UUID.Zero); | ||
2227 | } | ||
2165 | } | 2228 | } |
2166 | 2229 | ||
2167 | /// <summary> | 2230 | /// <summary> |
@@ -2861,6 +2924,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2861 | client.OnFetchInventory += HandleFetchInventory; | 2924 | client.OnFetchInventory += HandleFetchInventory; |
2862 | client.OnUpdateInventoryItem += UpdateInventoryItemAsset; | 2925 | client.OnUpdateInventoryItem += UpdateInventoryItemAsset; |
2863 | client.OnCopyInventoryItem += CopyInventoryItem; | 2926 | client.OnCopyInventoryItem += CopyInventoryItem; |
2927 | client.OnMoveItemsAndLeaveCopy += MoveInventoryItemsLeaveCopy; | ||
2864 | client.OnMoveInventoryItem += MoveInventoryItem; | 2928 | client.OnMoveInventoryItem += MoveInventoryItem; |
2865 | client.OnRemoveInventoryItem += RemoveInventoryItem; | 2929 | client.OnRemoveInventoryItem += RemoveInventoryItem; |
2866 | client.OnRemoveInventoryFolder += RemoveInventoryFolder; | 2930 | client.OnRemoveInventoryFolder += RemoveInventoryFolder; |
@@ -3148,6 +3212,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
3148 | /// <param name="flags"></param> | 3212 | /// <param name="flags"></param> |
3149 | public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) | 3213 | public virtual void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags) |
3150 | { | 3214 | { |
3215 | //Add half the avatar's height so that the user doesn't fall through prims | ||
3216 | ScenePresence presence; | ||
3217 | if (TryGetScenePresence(remoteClient.AgentId, out presence)) | ||
3218 | { | ||
3219 | if (presence.Appearance != null) | ||
3220 | { | ||
3221 | position.Z = position.Z + (presence.Appearance.AvatarHeight / 2); | ||
3222 | } | ||
3223 | } | ||
3224 | |||
3151 | if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) | 3225 | if (GridUserService != null && GridUserService.SetHome(remoteClient.AgentId.ToString(), RegionInfo.RegionID, position, lookAt)) |
3152 | // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. | 3226 | // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot. |
3153 | m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); | 3227 | m_dialogModule.SendAlertToUser(remoteClient, "Home position set."); |
@@ -3535,6 +3609,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3535 | } | 3609 | } |
3536 | } | 3610 | } |
3537 | // Honor parcel landing type and position. | 3611 | // Honor parcel landing type and position. |
3612 | /* | ||
3613 | ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); | ||
3538 | if (land != null) | 3614 | if (land != null) |
3539 | { | 3615 | { |
3540 | if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) | 3616 | if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero) |
@@ -3542,6 +3618,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3542 | agent.startpos = land.LandData.UserLocation; | 3618 | agent.startpos = land.LandData.UserLocation; |
3543 | } | 3619 | } |
3544 | } | 3620 | } |
3621 | */// This is now handled properly in ScenePresence.MakeRootAgent | ||
3545 | } | 3622 | } |
3546 | 3623 | ||
3547 | return true; | 3624 | return true; |
@@ -3904,12 +3981,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
3904 | return false; | 3981 | return false; |
3905 | } | 3982 | } |
3906 | 3983 | ||
3984 | public bool IncomingCloseAgent(UUID agentID) | ||
3985 | { | ||
3986 | return IncomingCloseAgent(agentID, false); | ||
3987 | } | ||
3988 | |||
3989 | public bool IncomingCloseChildAgent(UUID agentID) | ||
3990 | { | ||
3991 | return IncomingCloseAgent(agentID, true); | ||
3992 | } | ||
3993 | |||
3907 | /// <summary> | 3994 | /// <summary> |
3908 | /// Tell a single agent to disconnect from the region. | 3995 | /// Tell a single agent to disconnect from the region. |
3909 | /// </summary> | 3996 | /// </summary> |
3910 | /// <param name="regionHandle"></param> | ||
3911 | /// <param name="agentID"></param> | 3997 | /// <param name="agentID"></param> |
3912 | public bool IncomingCloseAgent(UUID agentID) | 3998 | /// <param name="childOnly"></param> |
3999 | public bool IncomingCloseAgent(UUID agentID, bool childOnly) | ||
3913 | { | 4000 | { |
3914 | //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); | 4001 | //m_log.DebugFormat("[SCENE]: Processing incoming close agent for {0}", agentID); |
3915 | 4002 | ||
@@ -3921,7 +4008,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3921 | { | 4008 | { |
3922 | m_sceneGraph.removeUserCount(false); | 4009 | m_sceneGraph.removeUserCount(false); |
3923 | } | 4010 | } |
3924 | else | 4011 | else if (!childOnly) |
3925 | { | 4012 | { |
3926 | m_sceneGraph.removeUserCount(true); | 4013 | m_sceneGraph.removeUserCount(true); |
3927 | } | 4014 | } |
@@ -3937,9 +4024,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3937 | } | 4024 | } |
3938 | else | 4025 | else |
3939 | presence.ControllingClient.SendShutdownConnectionNotice(); | 4026 | presence.ControllingClient.SendShutdownConnectionNotice(); |
4027 | presence.ControllingClient.Close(false); | ||
4028 | } | ||
4029 | else if (!childOnly) | ||
4030 | { | ||
4031 | presence.ControllingClient.Close(true); | ||
3940 | } | 4032 | } |
3941 | |||
3942 | presence.ControllingClient.Close(); | ||
3943 | return true; | 4033 | return true; |
3944 | } | 4034 | } |
3945 | 4035 | ||
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs index c675322..59e4037 100644 --- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs | |||
@@ -168,7 +168,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
168 | 168 | ||
169 | if (neighbour != null) | 169 | if (neighbour != null) |
170 | { | 170 | { |
171 | m_log.DebugFormat("[INTERGRID]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize); | 171 | // m_log.DebugFormat("[INTERGRID]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize); |
172 | m_scene.EventManager.TriggerOnRegionUp(neighbour); | 172 | m_scene.EventManager.TriggerOnRegionUp(neighbour); |
173 | } | 173 | } |
174 | else | 174 | else |
@@ -183,7 +183,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
183 | //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName); | 183 | //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName); |
184 | 184 | ||
185 | List<GridRegion> neighbours = m_scene.GridService.GetNeighbours(m_scene.RegionInfo.ScopeID, m_scene.RegionInfo.RegionID); | 185 | List<GridRegion> neighbours = m_scene.GridService.GetNeighbours(m_scene.RegionInfo.ScopeID, m_scene.RegionInfo.RegionID); |
186 | m_log.DebugFormat("[INTERGRID]: Informing {0} neighbours that this region is up", neighbours.Count); | 186 | //m_log.DebugFormat("[INTERGRID]: Informing {0} neighbours that this region is up", neighbours.Count); |
187 | foreach (GridRegion n in neighbours) | 187 | foreach (GridRegion n in neighbours) |
188 | { | 188 | { |
189 | InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync; | 189 | InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync; |
@@ -267,14 +267,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
267 | protected void SendCloseChildAgentAsync(UUID agentID, ulong regionHandle) | 267 | protected void SendCloseChildAgentAsync(UUID agentID, ulong regionHandle) |
268 | { | 268 | { |
269 | 269 | ||
270 | m_log.Debug("[INTERGRID]: Sending close agent to " + regionHandle); | 270 | //m_log.Debug("[INTERGRID]: Sending close agent to " + regionHandle); |
271 | // let's do our best, but there's not much we can do if the neighbour doesn't accept. | 271 | // let's do our best, but there's not much we can do if the neighbour doesn't accept. |
272 | 272 | ||
273 | //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); | 273 | //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); |
274 | uint x = 0, y = 0; | 274 | uint x = 0, y = 0; |
275 | Utils.LongToUInts(regionHandle, out x, out y); | 275 | Utils.LongToUInts(regionHandle, out x, out y); |
276 | GridRegion destination = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | 276 | GridRegion destination = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); |
277 | m_scene.SimulationService.CloseAgent(destination, agentID); | 277 | m_scene.SimulationService.CloseChildAgent(destination, agentID); |
278 | } | 278 | } |
279 | 279 | ||
280 | private void SendCloseChildAgentCompleted(IAsyncResult iar) | 280 | private void SendCloseChildAgentCompleted(IAsyncResult iar) |
@@ -293,7 +293,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
293 | d); | 293 | d); |
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | public List<GridRegion> RequestNamedRegions(string name, int maxNumber) | 297 | public List<GridRegion> RequestNamedRegions(string name, int maxNumber) |
298 | { | 298 | { |
299 | return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); | 299 | 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 9f38a99..5acc227 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs | |||
@@ -43,6 +43,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
43 | 43 | ||
44 | public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone); | 44 | public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone); |
45 | 45 | ||
46 | public delegate void AttachToBackupDelegate(SceneObjectGroup sog); | ||
47 | |||
48 | public delegate void DetachFromBackupDelegate(SceneObjectGroup sog); | ||
49 | |||
50 | public delegate void ChangedBackupDelegate(SceneObjectGroup sog); | ||
51 | |||
46 | public delegate void ObjectCreateDelegate(EntityBase obj); | 52 | public delegate void ObjectCreateDelegate(EntityBase obj); |
47 | 53 | ||
48 | public delegate void ObjectDeleteDelegate(EntityBase obj); | 54 | public delegate void ObjectDeleteDelegate(EntityBase obj); |
@@ -61,6 +67,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
61 | private PhysicsCrash handlerPhysicsCrash = null; | 67 | private PhysicsCrash handlerPhysicsCrash = null; |
62 | 68 | ||
63 | public event ObjectDuplicateDelegate OnObjectDuplicate; | 69 | public event ObjectDuplicateDelegate OnObjectDuplicate; |
70 | public event AttachToBackupDelegate OnAttachToBackup; | ||
71 | public event DetachFromBackupDelegate OnDetachFromBackup; | ||
72 | public event ChangedBackupDelegate OnChangeBackup; | ||
64 | public event ObjectCreateDelegate OnObjectCreate; | 73 | public event ObjectCreateDelegate OnObjectCreate; |
65 | public event ObjectDeleteDelegate OnObjectRemove; | 74 | public event ObjectDeleteDelegate OnObjectRemove; |
66 | 75 | ||
@@ -68,7 +77,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
68 | 77 | ||
69 | #region Fields | 78 | #region Fields |
70 | 79 | ||
71 | protected object m_presenceLock = new object(); | 80 | protected OpenMetaverse.ReaderWriterLockSlim m_scenePresencesLock = new OpenMetaverse.ReaderWriterLockSlim(); |
72 | protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>(); | 81 | protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>(); |
73 | protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>(); | 82 | protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>(); |
74 | 83 | ||
@@ -128,13 +137,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
128 | 137 | ||
129 | protected internal void Close() | 138 | protected internal void Close() |
130 | { | 139 | { |
131 | lock (m_presenceLock) | 140 | m_scenePresencesLock.EnterWriteLock(); |
141 | try | ||
132 | { | 142 | { |
133 | Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); | 143 | Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(); |
134 | List<ScenePresence> newlist = new List<ScenePresence>(); | 144 | List<ScenePresence> newlist = new List<ScenePresence>(); |
135 | m_scenePresenceMap = newmap; | 145 | m_scenePresenceMap = newmap; |
136 | m_scenePresenceArray = newlist; | 146 | m_scenePresenceArray = newlist; |
137 | } | 147 | } |
148 | finally | ||
149 | { | ||
150 | m_scenePresencesLock.ExitWriteLock(); | ||
151 | } | ||
138 | 152 | ||
139 | lock (m_dictionary_lock) | 153 | lock (m_dictionary_lock) |
140 | { | 154 | { |
@@ -264,6 +278,33 @@ namespace OpenSim.Region.Framework.Scenes | |||
264 | protected internal bool AddRestoredSceneObject( | 278 | protected internal bool AddRestoredSceneObject( |
265 | SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) | 279 | SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates) |
266 | { | 280 | { |
281 | if (!m_parentScene.CombineRegions) | ||
282 | { | ||
283 | // KF: Check for out-of-region, move inside and make static. | ||
284 | Vector3 npos = new Vector3(sceneObject.RootPart.GroupPosition.X, | ||
285 | sceneObject.RootPart.GroupPosition.Y, | ||
286 | sceneObject.RootPart.GroupPosition.Z); | ||
287 | 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 || | ||
288 | npos.X > Constants.RegionSize || | ||
289 | npos.Y > Constants.RegionSize)) | ||
290 | { | ||
291 | if (npos.X < 0.0) npos.X = 1.0f; | ||
292 | if (npos.Y < 0.0) npos.Y = 1.0f; | ||
293 | if (npos.Z < 0.0) npos.Z = 0.0f; | ||
294 | if (npos.X > Constants.RegionSize) npos.X = Constants.RegionSize - 1.0f; | ||
295 | if (npos.Y > Constants.RegionSize) npos.Y = Constants.RegionSize - 1.0f; | ||
296 | |||
297 | foreach (SceneObjectPart part in sceneObject.Children.Values) | ||
298 | { | ||
299 | part.GroupPosition = npos; | ||
300 | } | ||
301 | sceneObject.RootPart.Velocity = Vector3.Zero; | ||
302 | sceneObject.RootPart.AngularVelocity = Vector3.Zero; | ||
303 | sceneObject.RootPart.Acceleration = Vector3.Zero; | ||
304 | sceneObject.RootPart.Velocity = Vector3.Zero; | ||
305 | } | ||
306 | } | ||
307 | |||
267 | if (!alreadyPersisted) | 308 | if (!alreadyPersisted) |
268 | { | 309 | { |
269 | sceneObject.ForceInventoryPersistence(); | 310 | sceneObject.ForceInventoryPersistence(); |
@@ -354,10 +395,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
354 | m_numPrim += sceneObject.Children.Count; | 395 | m_numPrim += sceneObject.Children.Count; |
355 | 396 | ||
356 | if (attachToBackup) | 397 | if (attachToBackup) |
398 | { | ||
357 | sceneObject.AttachToBackup(); | 399 | sceneObject.AttachToBackup(); |
400 | } | ||
358 | 401 | ||
359 | if (OnObjectCreate != null) | 402 | if (OnObjectCreate != null) |
403 | { | ||
360 | OnObjectCreate(sceneObject); | 404 | OnObjectCreate(sceneObject); |
405 | } | ||
361 | 406 | ||
362 | lock (m_dictionary_lock) | 407 | lock (m_dictionary_lock) |
363 | { | 408 | { |
@@ -424,6 +469,30 @@ namespace OpenSim.Region.Framework.Scenes | |||
424 | } | 469 | } |
425 | } | 470 | } |
426 | 471 | ||
472 | public void FireAttachToBackup(SceneObjectGroup obj) | ||
473 | { | ||
474 | if (OnAttachToBackup != null) | ||
475 | { | ||
476 | OnAttachToBackup(obj); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | public void FireDetachFromBackup(SceneObjectGroup obj) | ||
481 | { | ||
482 | if (OnDetachFromBackup != null) | ||
483 | { | ||
484 | OnDetachFromBackup(obj); | ||
485 | } | ||
486 | } | ||
487 | |||
488 | public void FireChangeBackup(SceneObjectGroup obj) | ||
489 | { | ||
490 | if (OnChangeBackup != null) | ||
491 | { | ||
492 | OnChangeBackup(obj); | ||
493 | } | ||
494 | } | ||
495 | |||
427 | /// <summary> | 496 | /// <summary> |
428 | /// Process all pending updates | 497 | /// Process all pending updates |
429 | /// </summary> | 498 | /// </summary> |
@@ -560,7 +629,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
560 | 629 | ||
561 | Entities[presence.UUID] = presence; | 630 | Entities[presence.UUID] = presence; |
562 | 631 | ||
563 | lock (m_presenceLock) | 632 | m_scenePresencesLock.EnterWriteLock(); |
633 | try | ||
564 | { | 634 | { |
565 | Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); | 635 | Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); |
566 | List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); | 636 | List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); |
@@ -584,6 +654,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
584 | m_scenePresenceMap = newmap; | 654 | m_scenePresenceMap = newmap; |
585 | m_scenePresenceArray = newlist; | 655 | m_scenePresenceArray = newlist; |
586 | } | 656 | } |
657 | finally | ||
658 | { | ||
659 | m_scenePresencesLock.ExitWriteLock(); | ||
660 | } | ||
587 | } | 661 | } |
588 | 662 | ||
589 | /// <summary> | 663 | /// <summary> |
@@ -598,7 +672,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
598 | agentID); | 672 | agentID); |
599 | } | 673 | } |
600 | 674 | ||
601 | lock (m_presenceLock) | 675 | m_scenePresencesLock.EnterWriteLock(); |
676 | try | ||
602 | { | 677 | { |
603 | Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); | 678 | Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); |
604 | List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); | 679 | List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); |
@@ -620,6 +695,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
620 | m_log.WarnFormat("[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); | 695 | m_log.WarnFormat("[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); |
621 | } | 696 | } |
622 | } | 697 | } |
698 | finally | ||
699 | { | ||
700 | m_scenePresencesLock.ExitWriteLock(); | ||
701 | } | ||
623 | } | 702 | } |
624 | 703 | ||
625 | protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) | 704 | protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F) |
@@ -1497,10 +1576,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
1497 | /// <param name="childPrims"></param> | 1576 | /// <param name="childPrims"></param> |
1498 | protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children) | 1577 | protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children) |
1499 | { | 1578 | { |
1579 | SceneObjectGroup parentGroup = root.ParentGroup; | ||
1580 | if (parentGroup == null) return; | ||
1500 | Monitor.Enter(m_updateLock); | 1581 | Monitor.Enter(m_updateLock); |
1582 | |||
1501 | try | 1583 | try |
1502 | { | 1584 | { |
1503 | SceneObjectGroup parentGroup = root.ParentGroup; | 1585 | parentGroup.areUpdatesSuspended = true; |
1504 | 1586 | ||
1505 | List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); | 1587 | List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>(); |
1506 | if (parentGroup != null) | 1588 | if (parentGroup != null) |
@@ -1539,12 +1621,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
1539 | // occur on link to invoke this elsewhere (such as object selection) | 1621 | // occur on link to invoke this elsewhere (such as object selection) |
1540 | parentGroup.RootPart.CreateSelected = true; | 1622 | parentGroup.RootPart.CreateSelected = true; |
1541 | parentGroup.TriggerScriptChangedEvent(Changed.LINK); | 1623 | parentGroup.TriggerScriptChangedEvent(Changed.LINK); |
1542 | parentGroup.HasGroupChanged = true; | ||
1543 | parentGroup.ScheduleGroupForFullUpdate(); | ||
1544 | |||
1545 | } | 1624 | } |
1546 | finally | 1625 | finally |
1547 | { | 1626 | { |
1627 | parentGroup.areUpdatesSuspended = false; | ||
1628 | parentGroup.HasGroupChanged = true; | ||
1629 | parentGroup.ScheduleGroupForFullUpdate(); | ||
1548 | Monitor.Exit(m_updateLock); | 1630 | Monitor.Exit(m_updateLock); |
1549 | } | 1631 | } |
1550 | } | 1632 | } |
@@ -1581,11 +1663,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
1581 | } | 1663 | } |
1582 | } | 1664 | } |
1583 | 1665 | ||
1584 | foreach (SceneObjectPart child in childParts) | 1666 | if (childParts.Count > 0) |
1585 | { | 1667 | { |
1586 | // Unlink all child parts from their groups | 1668 | try |
1587 | // | 1669 | { |
1588 | child.ParentGroup.DelinkFromGroup(child, true); | 1670 | childParts[0].ParentGroup.areUpdatesSuspended = true; |
1671 | foreach (SceneObjectPart child in childParts) | ||
1672 | { | ||
1673 | // Unlink all child parts from their groups | ||
1674 | // | ||
1675 | child.ParentGroup.DelinkFromGroup(child, true); | ||
1676 | } | ||
1677 | } | ||
1678 | finally | ||
1679 | { | ||
1680 | childParts[0].ParentGroup.areUpdatesSuspended = false; | ||
1681 | } | ||
1589 | } | 1682 | } |
1590 | 1683 | ||
1591 | foreach (SceneObjectPart root in rootParts) | 1684 | foreach (SceneObjectPart root in rootParts) |
@@ -1609,10 +1702,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1609 | if (numChildren > 1) | 1702 | if (numChildren > 1) |
1610 | sendEventsToRemainder = false; | 1703 | sendEventsToRemainder = false; |
1611 | 1704 | ||
1612 | foreach (SceneObjectPart p in newSet) | 1705 | if (newSet.Count > 0) |
1613 | { | 1706 | { |
1614 | if (p != group.RootPart) | 1707 | try |
1615 | group.DelinkFromGroup(p, sendEventsToRemainder); | 1708 | { |
1709 | newSet[0].ParentGroup.areUpdatesSuspended = true; | ||
1710 | foreach (SceneObjectPart p in newSet) | ||
1711 | { | ||
1712 | if (p != group.RootPart) | ||
1713 | group.DelinkFromGroup(p, sendEventsToRemainder); | ||
1714 | } | ||
1715 | } | ||
1716 | finally | ||
1717 | { | ||
1718 | newSet[0].ParentGroup.areUpdatesSuspended = false; | ||
1719 | } | ||
1616 | } | 1720 | } |
1617 | 1721 | ||
1618 | // If there is more than one prim remaining, we | 1722 | // If there is more than one prim remaining, we |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs index 9a01a28..abb4de6 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 a2c3c07..3c3f4b7 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | |||
@@ -104,8 +104,104 @@ namespace OpenSim.Region.Framework.Scenes | |||
104 | /// since the group's last persistent backup | 104 | /// since the group's last persistent backup |
105 | /// </summary> | 105 | /// </summary> |
106 | private bool m_hasGroupChanged = false; | 106 | private bool m_hasGroupChanged = false; |
107 | private long timeFirstChanged; | 107 | private long timeFirstChanged = 0; |
108 | private long timeLastChanged; | 108 | private long timeLastChanged = 0; |
109 | private long m_maxPersistTime = 0; | ||
110 | private long m_minPersistTime = 0; | ||
111 | private Random m_rand; | ||
112 | private bool m_suspendUpdates; | ||
113 | private System.Threading.ReaderWriterLockSlim m_partsLock = new System.Threading.ReaderWriterLockSlim(); | ||
114 | private List<ScenePresence> m_linkedAvatars = new List<ScenePresence>(); | ||
115 | |||
116 | public bool areUpdatesSuspended | ||
117 | { | ||
118 | get | ||
119 | { | ||
120 | return m_suspendUpdates; | ||
121 | } | ||
122 | set | ||
123 | { | ||
124 | m_suspendUpdates = value; | ||
125 | if (!value) | ||
126 | { | ||
127 | QueueForUpdateCheck(); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | public void lockPartsForRead(bool locked) | ||
133 | { | ||
134 | if (locked) | ||
135 | { | ||
136 | if (m_partsLock.RecursiveReadCount > 0) | ||
137 | { | ||
138 | 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."); | ||
139 | try | ||
140 | { | ||
141 | m_partsLock.ExitReadLock(); | ||
142 | } | ||
143 | catch { } // Ignore errors, to allow resync | ||
144 | } | ||
145 | if (m_partsLock.RecursiveWriteCount > 0) | ||
146 | { | ||
147 | m_log.Error("[SceneObjectGroup.m_parts] Recursive read lock requested (write lock exists on this thread). This should not happen and means something needs to be fixed."); | ||
148 | try | ||
149 | { | ||
150 | m_partsLock.ExitWriteLock(); | ||
151 | } | ||
152 | catch { } | ||
153 | |||
154 | } | ||
155 | |||
156 | while (!m_partsLock.TryEnterReadLock(60000)) | ||
157 | { | ||
158 | 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."); | ||
159 | if (m_partsLock.IsWriteLockHeld) | ||
160 | { | ||
161 | m_partsLock = new System.Threading.ReaderWriterLockSlim(); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | if (m_partsLock.RecursiveReadCount > 0) | ||
168 | { | ||
169 | m_partsLock.ExitReadLock(); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | public void lockPartsForWrite(bool locked) | ||
174 | { | ||
175 | if (locked) | ||
176 | { | ||
177 | if (m_partsLock.RecursiveReadCount > 0) | ||
178 | { | ||
179 | 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."); | ||
180 | m_partsLock.ExitReadLock(); | ||
181 | } | ||
182 | if (m_partsLock.RecursiveWriteCount > 0) | ||
183 | { | ||
184 | m_log.Error("[SceneObjectGroup.m_parts] Recursive write lock requested. This should not happen and means something needs to be fixed."); | ||
185 | m_partsLock.ExitWriteLock(); | ||
186 | } | ||
187 | |||
188 | while (!m_partsLock.TryEnterWriteLock(60000)) | ||
189 | { | ||
190 | 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."); | ||
191 | if (m_partsLock.IsWriteLockHeld) | ||
192 | { | ||
193 | m_partsLock = new System.Threading.ReaderWriterLockSlim(); | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | if (m_partsLock.RecursiveWriteCount > 0) | ||
200 | { | ||
201 | m_partsLock.ExitWriteLock(); | ||
202 | } | ||
203 | } | ||
204 | } | ||
109 | 205 | ||
110 | public bool HasGroupChanged | 206 | public bool HasGroupChanged |
111 | { | 207 | { |
@@ -113,9 +209,39 @@ namespace OpenSim.Region.Framework.Scenes | |||
113 | { | 209 | { |
114 | if (value) | 210 | if (value) |
115 | { | 211 | { |
212 | if (m_isBackedUp) | ||
213 | { | ||
214 | m_scene.SceneGraph.FireChangeBackup(this); | ||
215 | } | ||
116 | timeLastChanged = DateTime.Now.Ticks; | 216 | timeLastChanged = DateTime.Now.Ticks; |
117 | if (!m_hasGroupChanged) | 217 | if (!m_hasGroupChanged) |
118 | timeFirstChanged = DateTime.Now.Ticks; | 218 | timeFirstChanged = DateTime.Now.Ticks; |
219 | if (m_rootPart != null && m_rootPart.UUID != null && m_scene != null) | ||
220 | { | ||
221 | if (m_rand == null) | ||
222 | { | ||
223 | byte[] val = new byte[16]; | ||
224 | m_rootPart.UUID.ToBytes(val, 0); | ||
225 | m_rand = new Random(BitConverter.ToInt32(val, 0)); | ||
226 | } | ||
227 | |||
228 | if (m_scene.GetRootAgentCount() == 0) | ||
229 | { | ||
230 | //If the region is empty, this change has been made by an automated process | ||
231 | //and thus we delay the persist time by a random amount between 1.5 and 2.5. | ||
232 | |||
233 | float factor = 1.5f + (float)(m_rand.NextDouble()); | ||
234 | m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor); | ||
235 | m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor); | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | //If the region is not empty, we want to obey the minimum and maximum persist times | ||
240 | //but add a random factor so we stagger the object persistance a little | ||
241 | m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5 | ||
242 | m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0 | ||
243 | } | ||
244 | } | ||
119 | } | 245 | } |
120 | m_hasGroupChanged = value; | 246 | m_hasGroupChanged = value; |
121 | } | 247 | } |
@@ -131,8 +257,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
131 | return false; | 257 | return false; |
132 | if (m_scene.ShuttingDown) | 258 | if (m_scene.ShuttingDown) |
133 | return true; | 259 | return true; |
260 | |||
261 | if (m_minPersistTime == 0 || m_maxPersistTime == 0) | ||
262 | { | ||
263 | m_maxPersistTime = m_scene.m_persistAfter; | ||
264 | m_minPersistTime = m_scene.m_dontPersistBefore; | ||
265 | } | ||
266 | |||
134 | long currentTime = DateTime.Now.Ticks; | 267 | long currentTime = DateTime.Now.Ticks; |
135 | if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) | 268 | |
269 | if (timeLastChanged == 0) timeLastChanged = currentTime; | ||
270 | if (timeFirstChanged == 0) timeFirstChanged = currentTime; | ||
271 | |||
272 | if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime) | ||
136 | return true; | 273 | return true; |
137 | return false; | 274 | return false; |
138 | } | 275 | } |
@@ -180,8 +317,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
180 | private bool m_scriptListens_notAtTarget = false; | 317 | private bool m_scriptListens_notAtTarget = false; |
181 | 318 | ||
182 | private bool m_scriptListens_atRotTarget = false; | 319 | private bool m_scriptListens_atRotTarget = false; |
183 | private bool m_scriptListens_notAtRotTarget = false; | 320 | private bool m_scriptListens_notAtRotTarget = false; |
184 | 321 | public bool m_dupeInProgress = false; | |
185 | internal Dictionary<UUID, string> m_savedScriptState = null; | 322 | internal Dictionary<UUID, string> m_savedScriptState = null; |
186 | 323 | ||
187 | #region Properties | 324 | #region Properties |
@@ -221,7 +358,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
221 | public virtual Quaternion Rotation | 358 | public virtual Quaternion Rotation |
222 | { | 359 | { |
223 | get { return m_rotation; } | 360 | get { return m_rotation; } |
224 | set { m_rotation = value; } | 361 | set { |
362 | lockPartsForRead(true); | ||
363 | try | ||
364 | { | ||
365 | foreach(SceneObjectPart p in m_parts.Values) | ||
366 | { | ||
367 | p.StoreUndoState(UndoType.STATE_GROUP_ROTATION); | ||
368 | } | ||
369 | } | ||
370 | finally | ||
371 | { | ||
372 | lockPartsForRead(false); | ||
373 | } | ||
374 | m_rotation = value; | ||
375 | } | ||
225 | } | 376 | } |
226 | 377 | ||
227 | public Quaternion GroupRotation | 378 | public Quaternion GroupRotation |
@@ -258,13 +409,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
258 | set | 409 | set |
259 | { | 410 | { |
260 | m_regionHandle = value; | 411 | m_regionHandle = value; |
261 | lock (m_parts) | 412 | lockPartsForRead(true); |
262 | { | 413 | { |
263 | foreach (SceneObjectPart part in m_parts.Values) | 414 | foreach (SceneObjectPart part in m_parts.Values) |
264 | { | 415 | { |
416 | |||
265 | part.RegionHandle = m_regionHandle; | 417 | part.RegionHandle = m_regionHandle; |
418 | |||
266 | } | 419 | } |
267 | } | 420 | } |
421 | lockPartsForRead(false); | ||
268 | } | 422 | } |
269 | } | 423 | } |
270 | 424 | ||
@@ -298,6 +452,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
298 | { | 452 | { |
299 | m_scene.CrossPrimGroupIntoNewRegion(val, this, true); | 453 | m_scene.CrossPrimGroupIntoNewRegion(val, this, true); |
300 | } | 454 | } |
455 | |||
456 | lockPartsForRead(true); | ||
457 | foreach (SceneObjectPart part in m_parts.Values) | ||
458 | { | ||
459 | part.IgnoreUndoUpdate = true; | ||
460 | } | ||
301 | if (RootPart.GetStatusSandbox()) | 461 | if (RootPart.GetStatusSandbox()) |
302 | { | 462 | { |
303 | if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) | 463 | if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) |
@@ -305,15 +465,31 @@ namespace OpenSim.Region.Framework.Scenes | |||
305 | RootPart.ScriptSetPhysicsStatus(false); | 465 | RootPart.ScriptSetPhysicsStatus(false); |
306 | Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), | 466 | Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"), |
307 | ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); | 467 | ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false); |
468 | lockPartsForRead(false); | ||
308 | return; | 469 | return; |
309 | } | 470 | } |
310 | } | 471 | } |
311 | lock (m_parts) | 472 | List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values); |
473 | lockPartsForRead(false); | ||
474 | foreach (SceneObjectPart part in parts) | ||
312 | { | 475 | { |
313 | foreach (SceneObjectPart part in m_parts.Values) | 476 | part.IgnoreUndoUpdate = false; |
314 | { | 477 | part.StoreUndoState(UndoType.STATE_GROUP_POSITION); |
315 | part.GroupPosition = val; | 478 | part.GroupPosition = val; |
479 | if (!m_dupeInProgress) | ||
480 | { | ||
481 | part.TriggerScriptChangedEvent(Changed.POSITION); | ||
316 | } | 482 | } |
483 | } | ||
484 | if (!m_dupeInProgress) | ||
485 | { | ||
486 | foreach (ScenePresence av in m_linkedAvatars) | ||
487 | { | ||
488 | Vector3 offset = m_parts[av.LinkedPrim].GetWorldPosition() - av.ParentPosition; | ||
489 | av.AbsolutePosition += offset; | ||
490 | av.ParentPosition = m_parts[av.LinkedPrim].GetWorldPosition(); //ParentPosition gets cleared by AbsolutePosition | ||
491 | av.SendFullUpdateToAllClients(); | ||
492 | } | ||
317 | } | 493 | } |
318 | 494 | ||
319 | //if (m_rootPart.PhysActor != null) | 495 | //if (m_rootPart.PhysActor != null) |
@@ -457,6 +633,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
457 | /// </summary> | 633 | /// </summary> |
458 | public SceneObjectGroup() | 634 | public SceneObjectGroup() |
459 | { | 635 | { |
636 | |||
460 | } | 637 | } |
461 | 638 | ||
462 | /// <summary> | 639 | /// <summary> |
@@ -473,7 +650,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
473 | /// Constructor. This object is added to the scene later via AttachToScene() | 650 | /// Constructor. This object is added to the scene later via AttachToScene() |
474 | /// </summary> | 651 | /// </summary> |
475 | public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) | 652 | public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) |
476 | { | 653 | { |
477 | SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); | 654 | SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); |
478 | } | 655 | } |
479 | 656 | ||
@@ -504,13 +681,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
504 | 681 | ||
505 | public void SetFromItemID(UUID AssetId) | 682 | public void SetFromItemID(UUID AssetId) |
506 | { | 683 | { |
507 | lock (m_parts) | 684 | lockPartsForRead(true); |
508 | { | 685 | { |
509 | foreach (SceneObjectPart part in m_parts.Values) | 686 | foreach (SceneObjectPart part in m_parts.Values) |
510 | { | 687 | { |
688 | |||
511 | part.FromItemID = AssetId; | 689 | part.FromItemID = AssetId; |
690 | |||
512 | } | 691 | } |
513 | } | 692 | } |
693 | lockPartsForRead(false); | ||
514 | } | 694 | } |
515 | 695 | ||
516 | public UUID GetFromItemID() | 696 | public UUID GetFromItemID() |
@@ -523,6 +703,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
523 | /// </summary> | 703 | /// </summary> |
524 | public virtual void AttachToBackup() | 704 | public virtual void AttachToBackup() |
525 | { | 705 | { |
706 | if (IsAttachment) return; | ||
707 | m_scene.SceneGraph.FireAttachToBackup(this); | ||
708 | |||
526 | if (InSceneBackup) | 709 | if (InSceneBackup) |
527 | { | 710 | { |
528 | //m_log.DebugFormat( | 711 | //m_log.DebugFormat( |
@@ -579,7 +762,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
579 | Vector3 maxScale = Vector3.Zero; | 762 | Vector3 maxScale = Vector3.Zero; |
580 | Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); | 763 | Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f); |
581 | 764 | ||
582 | lock (m_parts) | 765 | lockPartsForRead(true); |
583 | { | 766 | { |
584 | foreach (SceneObjectPart part in m_parts.Values) | 767 | foreach (SceneObjectPart part in m_parts.Values) |
585 | { | 768 | { |
@@ -593,8 +776,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
593 | maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X; | 776 | 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; | 777 | 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; | 778 | maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z; |
779 | |||
596 | } | 780 | } |
597 | } | 781 | } |
782 | lockPartsForRead(false); | ||
783 | |||
598 | finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; | 784 | finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X; |
599 | finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; | 785 | finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y; |
600 | finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; | 786 | finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z; |
@@ -610,10 +796,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
610 | 796 | ||
611 | EntityIntersection result = new EntityIntersection(); | 797 | EntityIntersection result = new EntityIntersection(); |
612 | 798 | ||
613 | lock (m_parts) | 799 | lockPartsForRead(true); |
614 | { | 800 | { |
615 | foreach (SceneObjectPart part in m_parts.Values) | 801 | foreach (SceneObjectPart part in m_parts.Values) |
616 | { | 802 | { |
803 | |||
617 | // Temporary commented to stop compiler warning | 804 | // Temporary commented to stop compiler warning |
618 | //Vector3 partPosition = | 805 | //Vector3 partPosition = |
619 | // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); | 806 | // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); |
@@ -641,8 +828,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
641 | result.distance = inter.distance; | 828 | result.distance = inter.distance; |
642 | } | 829 | } |
643 | } | 830 | } |
831 | |||
644 | } | 832 | } |
645 | } | 833 | } |
834 | lockPartsForRead(false); | ||
646 | return result; | 835 | return result; |
647 | } | 836 | } |
648 | 837 | ||
@@ -661,10 +850,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
661 | minY = 256f; | 850 | minY = 256f; |
662 | minZ = 8192f; | 851 | minZ = 8192f; |
663 | 852 | ||
664 | lock(m_parts); | 853 | lockPartsForRead(true); |
665 | { | 854 | { |
666 | foreach (SceneObjectPart part in m_parts.Values) | 855 | foreach (SceneObjectPart part in m_parts.Values) |
667 | { | 856 | { |
857 | |||
668 | Vector3 worldPos = part.GetWorldPosition(); | 858 | Vector3 worldPos = part.GetWorldPosition(); |
669 | Vector3 offset = worldPos - AbsolutePosition; | 859 | Vector3 offset = worldPos - AbsolutePosition; |
670 | Quaternion worldRot; | 860 | Quaternion worldRot; |
@@ -723,6 +913,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
723 | backBottomRight.Y = orig.Y + (part.Scale.Y / 2); | 913 | backBottomRight.Y = orig.Y + (part.Scale.Y / 2); |
724 | backBottomRight.Z = orig.Z - (part.Scale.Z / 2); | 914 | backBottomRight.Z = orig.Z - (part.Scale.Z / 2); |
725 | 915 | ||
916 | |||
917 | |||
726 | //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); | 918 | //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); |
727 | //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z); | 919 | //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z); |
728 | //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z); | 920 | //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z); |
@@ -894,6 +1086,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
894 | minZ = backBottomLeft.Z; | 1086 | minZ = backBottomLeft.Z; |
895 | } | 1087 | } |
896 | } | 1088 | } |
1089 | lockPartsForRead(false); | ||
897 | } | 1090 | } |
898 | 1091 | ||
899 | public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) | 1092 | public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) |
@@ -929,21 +1122,29 @@ namespace OpenSim.Region.Framework.Scenes | |||
929 | 1122 | ||
930 | public void SaveScriptedState(XmlTextWriter writer) | 1123 | public void SaveScriptedState(XmlTextWriter writer) |
931 | { | 1124 | { |
1125 | SaveScriptedState(writer, false); | ||
1126 | } | ||
1127 | |||
1128 | public void SaveScriptedState(XmlTextWriter writer, bool oldIDs) | ||
1129 | { | ||
932 | XmlDocument doc = new XmlDocument(); | 1130 | XmlDocument doc = new XmlDocument(); |
933 | Dictionary<UUID,string> states = new Dictionary<UUID,string>(); | 1131 | Dictionary<UUID,string> states = new Dictionary<UUID,string>(); |
934 | 1132 | ||
935 | // Capture script state while holding the lock | 1133 | // Capture script state while holding the lock |
936 | lock (m_parts) | 1134 | lockPartsForRead(true); |
937 | { | 1135 | { |
938 | foreach (SceneObjectPart part in m_parts.Values) | 1136 | foreach (SceneObjectPart part in m_parts.Values) |
939 | { | 1137 | { |
940 | Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(); | 1138 | |
1139 | Dictionary<UUID,string> pstates = part.Inventory.GetScriptStates(oldIDs); | ||
941 | foreach (UUID itemid in pstates.Keys) | 1140 | foreach (UUID itemid in pstates.Keys) |
942 | { | 1141 | { |
943 | states.Add(itemid, pstates[itemid]); | 1142 | states.Add(itemid, pstates[itemid]); |
944 | } | 1143 | } |
1144 | |||
945 | } | 1145 | } |
946 | } | 1146 | } |
1147 | lockPartsForRead(false); | ||
947 | 1148 | ||
948 | if (states.Count > 0) | 1149 | if (states.Count > 0) |
949 | { | 1150 | { |
@@ -962,6 +1163,47 @@ namespace OpenSim.Region.Framework.Scenes | |||
962 | } | 1163 | } |
963 | 1164 | ||
964 | /// <summary> | 1165 | /// <summary> |
1166 | /// Add the avatar to this linkset (avatar is sat). | ||
1167 | /// </summary> | ||
1168 | /// <param name="agentID"></param> | ||
1169 | public void AddAvatar(UUID agentID) | ||
1170 | { | ||
1171 | ScenePresence presence; | ||
1172 | if (m_scene.TryGetScenePresence(agentID, out presence)) | ||
1173 | { | ||
1174 | if (!m_linkedAvatars.Contains(presence)) | ||
1175 | { | ||
1176 | m_linkedAvatars.Add(presence); | ||
1177 | } | ||
1178 | } | ||
1179 | } | ||
1180 | |||
1181 | /// <summary> | ||
1182 | /// Delete the avatar from this linkset (avatar is unsat). | ||
1183 | /// </summary> | ||
1184 | /// <param name="agentID"></param> | ||
1185 | public void DeleteAvatar(UUID agentID) | ||
1186 | { | ||
1187 | ScenePresence presence; | ||
1188 | if (m_scene.TryGetScenePresence(agentID, out presence)) | ||
1189 | { | ||
1190 | if (m_linkedAvatars.Contains(presence)) | ||
1191 | { | ||
1192 | m_linkedAvatars.Remove(presence); | ||
1193 | } | ||
1194 | } | ||
1195 | } | ||
1196 | |||
1197 | /// <summary> | ||
1198 | /// Returns the list of linked presences (avatars sat on this group) | ||
1199 | /// </summary> | ||
1200 | /// <param name="agentID"></param> | ||
1201 | public List<ScenePresence> GetLinkedAvatars() | ||
1202 | { | ||
1203 | return m_linkedAvatars; | ||
1204 | } | ||
1205 | |||
1206 | /// <summary> | ||
965 | /// Attach this scene object to the given avatar. | 1207 | /// Attach this scene object to the given avatar. |
966 | /// </summary> | 1208 | /// </summary> |
967 | /// <param name="agentID"></param> | 1209 | /// <param name="agentID"></param> |
@@ -1112,13 +1354,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
1112 | 1354 | ||
1113 | public override void UpdateMovement() | 1355 | public override void UpdateMovement() |
1114 | { | 1356 | { |
1115 | lock (m_parts) | 1357 | lockPartsForRead(true); |
1116 | { | 1358 | { |
1117 | foreach (SceneObjectPart part in m_parts.Values) | 1359 | foreach (SceneObjectPart part in m_parts.Values) |
1118 | { | 1360 | { |
1361 | |||
1119 | part.UpdateMovement(); | 1362 | part.UpdateMovement(); |
1363 | |||
1120 | } | 1364 | } |
1121 | } | 1365 | } |
1366 | lockPartsForRead(false); | ||
1122 | } | 1367 | } |
1123 | 1368 | ||
1124 | public ushort GetTimeDilation() | 1369 | public ushort GetTimeDilation() |
@@ -1162,7 +1407,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1162 | /// <param name="part"></param> | 1407 | /// <param name="part"></param> |
1163 | public void AddPart(SceneObjectPart part) | 1408 | public void AddPart(SceneObjectPart part) |
1164 | { | 1409 | { |
1165 | lock (m_parts) | 1410 | lockPartsForWrite(true); |
1166 | { | 1411 | { |
1167 | part.SetParent(this); | 1412 | part.SetParent(this); |
1168 | m_parts.Add(part.UUID, part); | 1413 | m_parts.Add(part.UUID, part); |
@@ -1172,6 +1417,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1172 | if (part.LinkNum == 2 && RootPart != null) | 1417 | if (part.LinkNum == 2 && RootPart != null) |
1173 | RootPart.LinkNum = 1; | 1418 | RootPart.LinkNum = 1; |
1174 | } | 1419 | } |
1420 | lockPartsForWrite(false); | ||
1175 | } | 1421 | } |
1176 | 1422 | ||
1177 | /// <summary> | 1423 | /// <summary> |
@@ -1179,28 +1425,33 @@ namespace OpenSim.Region.Framework.Scenes | |||
1179 | /// </summary> | 1425 | /// </summary> |
1180 | private void UpdateParentIDs() | 1426 | private void UpdateParentIDs() |
1181 | { | 1427 | { |
1182 | lock (m_parts) | 1428 | lockPartsForRead(true); |
1183 | { | 1429 | { |
1184 | foreach (SceneObjectPart part in m_parts.Values) | 1430 | foreach (SceneObjectPart part in m_parts.Values) |
1185 | { | 1431 | { |
1432 | |||
1186 | if (part.UUID != m_rootPart.UUID) | 1433 | if (part.UUID != m_rootPart.UUID) |
1187 | { | 1434 | { |
1188 | part.ParentID = m_rootPart.LocalId; | 1435 | part.ParentID = m_rootPart.LocalId; |
1189 | } | 1436 | } |
1437 | |||
1190 | } | 1438 | } |
1191 | } | 1439 | } |
1440 | lockPartsForRead(false); | ||
1192 | } | 1441 | } |
1193 | 1442 | ||
1194 | public void RegenerateFullIDs() | 1443 | public void RegenerateFullIDs() |
1195 | { | 1444 | { |
1196 | lock (m_parts) | 1445 | lockPartsForRead(true); |
1197 | { | 1446 | { |
1198 | foreach (SceneObjectPart part in m_parts.Values) | 1447 | foreach (SceneObjectPart part in m_parts.Values) |
1199 | { | 1448 | { |
1449 | |||
1200 | part.UUID = UUID.Random(); | 1450 | part.UUID = UUID.Random(); |
1201 | 1451 | ||
1202 | } | 1452 | } |
1203 | } | 1453 | } |
1454 | lockPartsForRead(false); | ||
1204 | } | 1455 | } |
1205 | 1456 | ||
1206 | // helper provided for parts. | 1457 | // helper provided for parts. |
@@ -1261,7 +1512,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1261 | 1512 | ||
1262 | public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient) | 1513 | public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient) |
1263 | { | 1514 | { |
1264 | part.StoreUndoState(); | 1515 | part.StoreUndoState(UndoType.STATE_PRIM_ALL); |
1265 | part.OnGrab(offsetPos, remoteClient); | 1516 | part.OnGrab(offsetPos, remoteClient); |
1266 | } | 1517 | } |
1267 | 1518 | ||
@@ -1281,27 +1532,32 @@ namespace OpenSim.Region.Framework.Scenes | |||
1281 | 1532 | ||
1282 | DetachFromBackup(); | 1533 | DetachFromBackup(); |
1283 | 1534 | ||
1284 | lock (m_parts) | 1535 | lockPartsForRead(true); |
1536 | List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values); | ||
1537 | lockPartsForRead(false); | ||
1538 | |||
1539 | foreach (SceneObjectPart part in values) | ||
1285 | { | 1540 | { |
1286 | foreach (SceneObjectPart part in m_parts.Values) | ||
1287 | { | ||
1288 | // part.Inventory.RemoveScriptInstances(); | 1541 | // part.Inventory.RemoveScriptInstances(); |
1289 | Scene.ForEachScenePresence(delegate(ScenePresence avatar) | 1542 | |
1543 | Scene.ForEachScenePresence(delegate (ScenePresence sp) | ||
1544 | { | ||
1545 | if (sp.ParentID == LocalId) | ||
1290 | { | 1546 | { |
1291 | if (avatar.ParentID == LocalId) | 1547 | sp.StandUp(); |
1292 | { | 1548 | } |
1293 | avatar.StandUp(); | ||
1294 | } | ||
1295 | 1549 | ||
1296 | if (!silent) | 1550 | if (!silent) |
1297 | { | 1551 | { |
1298 | part.UpdateFlag = 0; | 1552 | part.UpdateFlag = 0; |
1299 | if (part == m_rootPart) | 1553 | if (part == m_rootPart) |
1300 | avatar.ControllingClient.SendKillObject(m_regionHandle, part.LocalId); | 1554 | sp.ControllingClient.SendKillObject(m_regionHandle, part.LocalId); |
1301 | } | 1555 | } |
1302 | }); | 1556 | }); |
1303 | } | 1557 | |
1304 | } | 1558 | } |
1559 | |||
1560 | |||
1305 | } | 1561 | } |
1306 | 1562 | ||
1307 | public void AddScriptLPS(int count) | 1563 | public void AddScriptLPS(int count) |
@@ -1326,17 +1582,20 @@ namespace OpenSim.Region.Framework.Scenes | |||
1326 | 1582 | ||
1327 | scriptEvents aggregateScriptEvents=0; | 1583 | scriptEvents aggregateScriptEvents=0; |
1328 | 1584 | ||
1329 | lock (m_parts) | 1585 | lockPartsForRead(true); |
1330 | { | 1586 | { |
1331 | foreach (SceneObjectPart part in m_parts.Values) | 1587 | foreach (SceneObjectPart part in m_parts.Values) |
1332 | { | 1588 | { |
1589 | |||
1333 | if (part == null) | 1590 | if (part == null) |
1334 | continue; | 1591 | continue; |
1335 | if (part != RootPart) | 1592 | if (part != RootPart) |
1336 | part.ObjectFlags = objectflagupdate; | 1593 | part.ObjectFlags = objectflagupdate; |
1337 | aggregateScriptEvents |= part.AggregateScriptEvents; | 1594 | aggregateScriptEvents |= part.AggregateScriptEvents; |
1595 | |||
1338 | } | 1596 | } |
1339 | } | 1597 | } |
1598 | lockPartsForRead(false); | ||
1340 | 1599 | ||
1341 | m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); | 1600 | m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0); |
1342 | m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); | 1601 | m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0); |
@@ -1378,42 +1637,52 @@ namespace OpenSim.Region.Framework.Scenes | |||
1378 | /// <param name="m_physicalPrim"></param> | 1637 | /// <param name="m_physicalPrim"></param> |
1379 | public void ApplyPhysics(bool m_physicalPrim) | 1638 | public void ApplyPhysics(bool m_physicalPrim) |
1380 | { | 1639 | { |
1381 | lock (m_parts) | 1640 | lockPartsForRead(true); |
1641 | |||
1642 | if (m_parts.Count > 1) | ||
1382 | { | 1643 | { |
1383 | if (m_parts.Count > 1) | 1644 | List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values); |
1645 | lockPartsForRead(false); | ||
1646 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); | ||
1647 | foreach (SceneObjectPart part in values) | ||
1384 | { | 1648 | { |
1385 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); | 1649 | |
1386 | foreach (SceneObjectPart part in m_parts.Values) | 1650 | if (part.LocalId != m_rootPart.LocalId) |
1387 | { | 1651 | { |
1388 | if (part.LocalId != m_rootPart.LocalId) | 1652 | part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim); |
1389 | { | ||
1390 | part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, m_physicalPrim); | ||
1391 | } | ||
1392 | } | 1653 | } |
1393 | 1654 | ||
1394 | // Hack to get the physics scene geometries in the right spot | ||
1395 | ResetChildPrimPhysicsPositions(); | ||
1396 | } | ||
1397 | else | ||
1398 | { | ||
1399 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); | ||
1400 | } | 1655 | } |
1656 | // Hack to get the physics scene geometries in the right spot | ||
1657 | ResetChildPrimPhysicsPositions(); | ||
1658 | } | ||
1659 | else | ||
1660 | { | ||
1661 | lockPartsForRead(false); | ||
1662 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, m_physicalPrim); | ||
1401 | } | 1663 | } |
1402 | } | 1664 | } |
1403 | 1665 | ||
1404 | public void SetOwnerId(UUID userId) | 1666 | public void SetOwnerId(UUID userId) |
1405 | { | 1667 | { |
1406 | ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); | 1668 | ForEachPart(delegate(SceneObjectPart part) |
1669 | { | ||
1670 | |||
1671 | part.OwnerID = userId; | ||
1672 | |||
1673 | }); | ||
1407 | } | 1674 | } |
1408 | 1675 | ||
1409 | public void ForEachPart(Action<SceneObjectPart> whatToDo) | 1676 | public void ForEachPart(Action<SceneObjectPart> whatToDo) |
1410 | { | 1677 | { |
1411 | lock (m_parts) | 1678 | lockPartsForRead(true); |
1679 | List<SceneObjectPart> values = new List<SceneObjectPart>(m_parts.Values); | ||
1680 | lockPartsForRead(false); | ||
1681 | foreach (SceneObjectPart part in values) | ||
1412 | { | 1682 | { |
1413 | foreach (SceneObjectPart part in m_parts.Values) | 1683 | |
1414 | { | 1684 | whatToDo(part); |
1415 | whatToDo(part); | 1685 | |
1416 | } | ||
1417 | } | 1686 | } |
1418 | } | 1687 | } |
1419 | 1688 | ||
@@ -1436,7 +1705,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1436 | 1705 | ||
1437 | try | 1706 | try |
1438 | { | 1707 | { |
1439 | if (!m_scene.ShuttingDown) // if shutting down then there will be nothing to handle the return so leave till next restart | 1708 | if (!m_scene.ShuttingDown || // if shutting down then there will be nothing to handle the return so leave till next restart |
1709 | m_scene.LoginsDisabled || // We're starting up or doing maintenance, don't mess with things | ||
1710 | m_scene.LoadingPrims) // Land may not be valid yet | ||
1711 | |||
1440 | { | 1712 | { |
1441 | ILandObject parcel = m_scene.LandChannel.GetLandObject( | 1713 | ILandObject parcel = m_scene.LandChannel.GetLandObject( |
1442 | m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); | 1714 | m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); |
@@ -1468,9 +1740,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
1468 | // don't backup while it's selected or you're asking for changes mid stream. | 1740 | // don't backup while it's selected or you're asking for changes mid stream. |
1469 | if ((isTimeToPersist()) || (forcedBackup)) | 1741 | if ((isTimeToPersist()) || (forcedBackup)) |
1470 | { | 1742 | { |
1471 | m_log.DebugFormat( | 1743 | // m_log.DebugFormat( |
1472 | "[SCENE]: Storing {0}, {1} in {2}", | 1744 | // "[SCENE]: Storing {0}, {1} in {2}", |
1473 | Name, UUID, m_scene.RegionInfo.RegionName); | 1745 | // Name, UUID, m_scene.RegionInfo.RegionName); |
1474 | 1746 | ||
1475 | SceneObjectGroup backup_group = Copy(false); | 1747 | SceneObjectGroup backup_group = Copy(false); |
1476 | backup_group.RootPart.Velocity = RootPart.Velocity; | 1748 | backup_group.RootPart.Velocity = RootPart.Velocity; |
@@ -1512,15 +1784,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
1512 | RootPart.SendFullUpdate( | 1784 | RootPart.SendFullUpdate( |
1513 | remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); | 1785 | remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, RootPart.UUID)); |
1514 | 1786 | ||
1515 | lock (m_parts) | 1787 | lockPartsForRead(true); |
1516 | { | 1788 | { |
1517 | foreach (SceneObjectPart part in m_parts.Values) | 1789 | foreach (SceneObjectPart part in m_parts.Values) |
1518 | { | 1790 | { |
1791 | |||
1519 | if (part != RootPart) | 1792 | if (part != RootPart) |
1520 | part.SendFullUpdate( | 1793 | part.SendFullUpdate( |
1521 | remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); | 1794 | remoteClient, m_scene.Permissions.GenerateClientFlags(remoteClient.AgentId, part.UUID)); |
1522 | } | 1795 | } |
1523 | } | 1796 | } |
1797 | lockPartsForRead(false); | ||
1524 | } | 1798 | } |
1525 | 1799 | ||
1526 | #region Copying | 1800 | #region Copying |
@@ -1531,87 +1805,96 @@ namespace OpenSim.Region.Framework.Scenes | |||
1531 | /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param> | 1805 | /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param> |
1532 | /// <returns></returns> | 1806 | /// <returns></returns> |
1533 | public SceneObjectGroup Copy(bool userExposed) | 1807 | public SceneObjectGroup Copy(bool userExposed) |
1534 | { | 1808 | { |
1535 | SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone(); | 1809 | SceneObjectGroup dupe; |
1536 | dupe.m_isBackedUp = false; | 1810 | try |
1537 | dupe.m_parts = new Dictionary<UUID, SceneObjectPart>(); | 1811 | { |
1538 | 1812 | m_dupeInProgress = true; | |
1539 | // Warning, The following code related to previousAttachmentStatus is needed so that clones of | 1813 | dupe = (SceneObjectGroup)MemberwiseClone(); |
1540 | // attachments do not bordercross while they're being duplicated. This is hacktastic! | 1814 | dupe.m_isBackedUp = false; |
1541 | // Normally, setting AbsolutePosition will bordercross a prim if it's outside the region! | 1815 | dupe.m_parts = new Dictionary<UUID, SceneObjectPart>(); |
1542 | // unless IsAttachment is true!, so to prevent border crossing, we save it's attachment state | 1816 | |
1543 | // (which should be false anyway) set it as an Attachment and then set it's Absolute Position, | 1817 | // Warning, The following code related to previousAttachmentStatus is needed so that clones of |
1544 | // then restore it's attachment state | 1818 | // attachments do not bordercross while they're being duplicated. This is hacktastic! |
1545 | 1819 | // Normally, setting AbsolutePosition will bordercross a prim if it's outside the region! | |
1546 | // This is only necessary when userExposed is false! | 1820 | // unless IsAttachment is true!, so to prevent border crossing, we save it's attachment state |
1547 | 1821 | // (which should be false anyway) set it as an Attachment and then set it's Absolute Position, | |
1548 | bool previousAttachmentStatus = dupe.RootPart.IsAttachment; | 1822 | // then restore it's attachment state |
1549 | 1823 | ||
1550 | if (!userExposed) | 1824 | // This is only necessary when userExposed is false! |
1551 | dupe.RootPart.IsAttachment = true; | 1825 | |
1552 | 1826 | bool previousAttachmentStatus = dupe.RootPart.IsAttachment; | |
1553 | dupe.AbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z); | 1827 | |
1554 | 1828 | if (!userExposed) | |
1555 | if (!userExposed) | 1829 | dupe.RootPart.IsAttachment = true; |
1556 | { | 1830 | |
1557 | dupe.RootPart.IsAttachment = previousAttachmentStatus; | 1831 | dupe.AbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z); |
1558 | } | 1832 | |
1559 | 1833 | if (!userExposed) | |
1560 | dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed); | 1834 | { |
1561 | dupe.m_rootPart.LinkNum = m_rootPart.LinkNum; | 1835 | dupe.RootPart.IsAttachment = previousAttachmentStatus; |
1562 | 1836 | } | |
1563 | if (userExposed) | 1837 | |
1564 | dupe.m_rootPart.TrimPermissions(); | 1838 | dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed); |
1565 | 1839 | dupe.m_rootPart.LinkNum = m_rootPart.LinkNum; | |
1566 | /// may need to create a new Physics actor. | 1840 | |
1567 | if (dupe.RootPart.PhysActor != null && userExposed) | 1841 | if (userExposed) |
1568 | { | 1842 | dupe.m_rootPart.TrimPermissions(); |
1569 | PrimitiveBaseShape pbs = dupe.RootPart.Shape; | 1843 | |
1570 | 1844 | /// may need to create a new Physics actor. | |
1571 | dupe.RootPart.PhysActor = m_scene.PhysicsScene.AddPrimShape( | 1845 | if (dupe.RootPart.PhysActor != null && userExposed) |
1572 | dupe.RootPart.Name, | 1846 | { |
1573 | pbs, | 1847 | PrimitiveBaseShape pbs = dupe.RootPart.Shape; |
1574 | dupe.RootPart.AbsolutePosition, | 1848 | |
1575 | dupe.RootPart.Scale, | 1849 | dupe.RootPart.PhysActor = m_scene.PhysicsScene.AddPrimShape( |
1576 | dupe.RootPart.RotationOffset, | 1850 | dupe.RootPart.Name, |
1577 | dupe.RootPart.PhysActor.IsPhysical); | 1851 | pbs, |
1578 | 1852 | dupe.RootPart.AbsolutePosition, | |
1579 | dupe.RootPart.PhysActor.LocalID = dupe.RootPart.LocalId; | 1853 | dupe.RootPart.Scale, |
1580 | dupe.RootPart.DoPhysicsPropertyUpdate(dupe.RootPart.PhysActor.IsPhysical, true); | 1854 | dupe.RootPart.RotationOffset, |
1581 | } | 1855 | dupe.RootPart.PhysActor.IsPhysical); |
1582 | 1856 | ||
1583 | List<SceneObjectPart> partList; | 1857 | dupe.RootPart.PhysActor.LocalID = dupe.RootPart.LocalId; |
1584 | 1858 | dupe.RootPart.DoPhysicsPropertyUpdate(dupe.RootPart.PhysActor.IsPhysical, true); | |
1585 | lock (m_parts) | 1859 | } |
1586 | { | 1860 | |
1587 | partList = new List<SceneObjectPart>(m_parts.Values); | 1861 | List<SceneObjectPart> partList; |
1588 | } | 1862 | |
1589 | 1863 | lockPartsForRead(true); | |
1590 | partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) | 1864 | |
1591 | { | 1865 | partList = new List<SceneObjectPart>(m_parts.Values); |
1592 | return p1.LinkNum.CompareTo(p2.LinkNum); | 1866 | |
1593 | } | 1867 | lockPartsForRead(false); |
1594 | ); | 1868 | |
1595 | 1869 | partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) | |
1596 | foreach (SceneObjectPart part in partList) | 1870 | { |
1597 | { | 1871 | return p1.LinkNum.CompareTo(p2.LinkNum); |
1598 | if (part.UUID != m_rootPart.UUID) | 1872 | } |
1599 | { | 1873 | ); |
1600 | SceneObjectPart newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed); | 1874 | |
1601 | 1875 | foreach (SceneObjectPart part in partList) | |
1602 | newPart.LinkNum = part.LinkNum; | 1876 | { |
1603 | } | 1877 | if (part.UUID != m_rootPart.UUID) |
1604 | } | 1878 | { |
1605 | 1879 | SceneObjectPart newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed); | |
1606 | if (userExposed) | 1880 | |
1607 | { | 1881 | newPart.LinkNum = part.LinkNum; |
1608 | dupe.UpdateParentIDs(); | 1882 | } |
1609 | dupe.HasGroupChanged = true; | 1883 | } |
1610 | dupe.AttachToBackup(); | 1884 | |
1611 | 1885 | if (userExposed) | |
1612 | ScheduleGroupForFullUpdate(); | 1886 | { |
1887 | dupe.UpdateParentIDs(); | ||
1888 | dupe.HasGroupChanged = true; | ||
1889 | dupe.AttachToBackup(); | ||
1890 | |||
1891 | ScheduleGroupForFullUpdate(); | ||
1892 | } | ||
1893 | } | ||
1894 | finally | ||
1895 | { | ||
1896 | m_dupeInProgress = false; | ||
1613 | } | 1897 | } |
1614 | |||
1615 | return dupe; | 1898 | return dupe; |
1616 | } | 1899 | } |
1617 | 1900 | ||
@@ -1802,13 +2085,40 @@ namespace OpenSim.Region.Framework.Scenes | |||
1802 | } | 2085 | } |
1803 | } | 2086 | } |
1804 | 2087 | ||
2088 | public void rotLookAt(Quaternion target, float strength, float damping) | ||
2089 | { | ||
2090 | SceneObjectPart rootpart = m_rootPart; | ||
2091 | if (rootpart != null) | ||
2092 | { | ||
2093 | if (IsAttachment) | ||
2094 | { | ||
2095 | /* | ||
2096 | ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar); | ||
2097 | if (avatar != null) | ||
2098 | { | ||
2099 | Rotate the Av? | ||
2100 | } */ | ||
2101 | } | ||
2102 | else | ||
2103 | { | ||
2104 | if (rootpart.PhysActor != null) | ||
2105 | { // APID must be implemented in your physics system for this to function. | ||
2106 | rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W); | ||
2107 | rootpart.PhysActor.APIDStrength = strength; | ||
2108 | rootpart.PhysActor.APIDDamping = damping; | ||
2109 | rootpart.PhysActor.APIDActive = true; | ||
2110 | } | ||
2111 | } | ||
2112 | } | ||
2113 | } | ||
2114 | |||
1805 | public void stopLookAt() | 2115 | public void stopLookAt() |
1806 | { | 2116 | { |
1807 | SceneObjectPart rootpart = m_rootPart; | 2117 | SceneObjectPart rootpart = m_rootPart; |
1808 | if (rootpart != null) | 2118 | if (rootpart != null) |
1809 | { | 2119 | { |
1810 | if (rootpart.PhysActor != null) | 2120 | if (rootpart.PhysActor != null) |
1811 | { | 2121 | { // APID must be implemented in your physics system for this to function. |
1812 | rootpart.PhysActor.APIDActive = false; | 2122 | rootpart.PhysActor.APIDActive = false; |
1813 | } | 2123 | } |
1814 | } | 2124 | } |
@@ -1876,10 +2186,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1876 | SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); | 2186 | SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); |
1877 | newPart.SetParent(this); | 2187 | newPart.SetParent(this); |
1878 | 2188 | ||
1879 | lock (m_parts) | 2189 | lockPartsForWrite(true); |
1880 | { | 2190 | { |
1881 | m_parts.Add(newPart.UUID, newPart); | 2191 | m_parts.Add(newPart.UUID, newPart); |
1882 | } | 2192 | } |
2193 | lockPartsForWrite(false); | ||
1883 | 2194 | ||
1884 | SetPartAsNonRoot(newPart); | 2195 | SetPartAsNonRoot(newPart); |
1885 | 2196 | ||
@@ -1942,7 +2253,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1942 | //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) | 2253 | //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) |
1943 | // return; | 2254 | // return; |
1944 | 2255 | ||
1945 | lock (m_parts) | 2256 | lockPartsForRead(true); |
1946 | { | 2257 | { |
1947 | bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); | 2258 | bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); |
1948 | 2259 | ||
@@ -1962,9 +2273,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
1962 | { | 2273 | { |
1963 | if (!IsSelected) | 2274 | if (!IsSelected) |
1964 | part.UpdateLookAt(); | 2275 | part.UpdateLookAt(); |
2276 | |||
1965 | part.SendScheduledUpdates(); | 2277 | part.SendScheduledUpdates(); |
2278 | |||
1966 | } | 2279 | } |
1967 | } | 2280 | } |
2281 | lockPartsForRead(false); | ||
1968 | } | 2282 | } |
1969 | 2283 | ||
1970 | public void ScheduleFullUpdateToAvatar(ScenePresence presence) | 2284 | public void ScheduleFullUpdateToAvatar(ScenePresence presence) |
@@ -1973,27 +2287,29 @@ namespace OpenSim.Region.Framework.Scenes | |||
1973 | 2287 | ||
1974 | RootPart.AddFullUpdateToAvatar(presence); | 2288 | RootPart.AddFullUpdateToAvatar(presence); |
1975 | 2289 | ||
1976 | lock (m_parts) | 2290 | lockPartsForRead(true); |
1977 | { | 2291 | { |
1978 | foreach (SceneObjectPart part in m_parts.Values) | 2292 | foreach (SceneObjectPart part in m_parts.Values) |
1979 | { | 2293 | { |
2294 | |||
1980 | if (part != RootPart) | 2295 | if (part != RootPart) |
1981 | part.AddFullUpdateToAvatar(presence); | 2296 | part.AddFullUpdateToAvatar(presence); |
2297 | |||
1982 | } | 2298 | } |
1983 | } | 2299 | } |
2300 | lockPartsForRead(false); | ||
1984 | } | 2301 | } |
1985 | 2302 | ||
1986 | public void ScheduleTerseUpdateToAvatar(ScenePresence presence) | 2303 | public void ScheduleTerseUpdateToAvatar(ScenePresence presence) |
1987 | { | 2304 | { |
1988 | // m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1} just to avatar {2}", Name, UUID, presence.Name); | 2305 | lockPartsForRead(true); |
1989 | 2306 | ||
1990 | lock (m_parts) | 2307 | foreach (SceneObjectPart part in m_parts.Values) |
1991 | { | 2308 | { |
1992 | foreach (SceneObjectPart part in m_parts.Values) | 2309 | part.AddTerseUpdateToAvatar(presence); |
1993 | { | ||
1994 | part.AddTerseUpdateToAvatar(presence); | ||
1995 | } | ||
1996 | } | 2310 | } |
2311 | |||
2312 | lockPartsForRead(false); | ||
1997 | } | 2313 | } |
1998 | 2314 | ||
1999 | /// <summary> | 2315 | /// <summary> |
@@ -2007,14 +2323,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
2007 | checkAtTargets(); | 2323 | checkAtTargets(); |
2008 | RootPart.ScheduleFullUpdate(); | 2324 | RootPart.ScheduleFullUpdate(); |
2009 | 2325 | ||
2010 | lock (m_parts) | 2326 | lockPartsForRead(true); |
2011 | { | 2327 | { |
2012 | foreach (SceneObjectPart part in m_parts.Values) | 2328 | foreach (SceneObjectPart part in m_parts.Values) |
2013 | { | 2329 | { |
2330 | |||
2014 | if (part != RootPart) | 2331 | if (part != RootPart) |
2015 | part.ScheduleFullUpdate(); | 2332 | part.ScheduleFullUpdate(); |
2333 | |||
2016 | } | 2334 | } |
2017 | } | 2335 | } |
2336 | lockPartsForRead(false); | ||
2018 | } | 2337 | } |
2019 | 2338 | ||
2020 | /// <summary> | 2339 | /// <summary> |
@@ -2022,37 +2341,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
2022 | /// </summary> | 2341 | /// </summary> |
2023 | public void ScheduleGroupForTerseUpdate() | 2342 | public void ScheduleGroupForTerseUpdate() |
2024 | { | 2343 | { |
2025 | // m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID); | 2344 | lockPartsForRead(true); |
2026 | 2345 | foreach (SceneObjectPart part in m_parts.Values) | |
2027 | lock (m_parts) | ||
2028 | { | 2346 | { |
2029 | foreach (SceneObjectPart part in m_parts.Values) | 2347 | part.ScheduleTerseUpdate(); |
2030 | { | ||
2031 | part.ScheduleTerseUpdate(); | ||
2032 | } | ||
2033 | } | 2348 | } |
2349 | |||
2350 | lockPartsForRead(false); | ||
2034 | } | 2351 | } |
2035 | 2352 | ||
2036 | /// <summary> | 2353 | /// <summary> |
2037 | /// Immediately send a full update for this scene object. | 2354 | /// Immediately send a full update for this scene object. |
2038 | /// </summary> | 2355 | /// </summary> |
2039 | public void SendGroupFullUpdate() | 2356 | public void SendGroupFullUpdate() |
2040 | { | 2357 | { |
2041 | if (IsDeleted) | 2358 | if (IsDeleted) |
2042 | return; | 2359 | return; |
2043 | 2360 | ||
2044 | // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); | 2361 | // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); |
2045 | 2362 | ||
2046 | RootPart.SendFullUpdateToAllClients(); | 2363 | RootPart.SendFullUpdateToAllClients(); |
2047 | 2364 | ||
2048 | lock (m_parts) | 2365 | lockPartsForRead(true); |
2049 | { | 2366 | { |
2050 | foreach (SceneObjectPart part in m_parts.Values) | 2367 | foreach (SceneObjectPart part in m_parts.Values) |
2051 | { | 2368 | { |
2369 | |||
2052 | if (part != RootPart) | 2370 | if (part != RootPart) |
2053 | part.SendFullUpdateToAllClients(); | 2371 | part.SendFullUpdateToAllClients(); |
2372 | |||
2054 | } | 2373 | } |
2055 | } | 2374 | } |
2375 | lockPartsForRead(false); | ||
2056 | } | 2376 | } |
2057 | 2377 | ||
2058 | /// <summary> | 2378 | /// <summary> |
@@ -2084,14 +2404,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
2084 | { | 2404 | { |
2085 | if (IsDeleted) | 2405 | if (IsDeleted) |
2086 | return; | 2406 | return; |
2087 | 2407 | ||
2088 | lock (m_parts) | 2408 | lockPartsForRead(true); |
2089 | { | 2409 | { |
2090 | foreach (SceneObjectPart part in m_parts.Values) | 2410 | foreach (SceneObjectPart part in m_parts.Values) |
2091 | { | 2411 | { |
2092 | part.SendTerseUpdateToAllClients(); | 2412 | part.SendTerseUpdateToAllClients(); |
2093 | } | 2413 | } |
2094 | } | 2414 | } |
2415 | lockPartsForRead(false); | ||
2095 | } | 2416 | } |
2096 | 2417 | ||
2097 | #endregion | 2418 | #endregion |
@@ -2105,16 +2426,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
2105 | /// <returns>null if no child part with that linknum or child part</returns> | 2426 | /// <returns>null if no child part with that linknum or child part</returns> |
2106 | public SceneObjectPart GetLinkNumPart(int linknum) | 2427 | public SceneObjectPart GetLinkNumPart(int linknum) |
2107 | { | 2428 | { |
2108 | lock (m_parts) | 2429 | lockPartsForRead(true); |
2109 | { | 2430 | { |
2110 | foreach (SceneObjectPart part in m_parts.Values) | 2431 | foreach (SceneObjectPart part in m_parts.Values) |
2111 | { | 2432 | { |
2112 | if (part.LinkNum == linknum) | 2433 | if (part.LinkNum == linknum) |
2113 | { | 2434 | { |
2435 | lockPartsForRead(false); | ||
2114 | return part; | 2436 | return part; |
2115 | } | 2437 | } |
2116 | } | 2438 | } |
2117 | } | 2439 | } |
2440 | lockPartsForRead(false); | ||
2118 | 2441 | ||
2119 | return null; | 2442 | return null; |
2120 | } | 2443 | } |
@@ -2142,17 +2465,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
2142 | public SceneObjectPart GetChildPart(uint localID) | 2465 | public SceneObjectPart GetChildPart(uint localID) |
2143 | { | 2466 | { |
2144 | //m_log.DebugFormat("Entered looking for {0}", localID); | 2467 | //m_log.DebugFormat("Entered looking for {0}", localID); |
2145 | lock (m_parts) | 2468 | lockPartsForRead(true); |
2146 | { | 2469 | { |
2147 | foreach (SceneObjectPart part in m_parts.Values) | 2470 | foreach (SceneObjectPart part in m_parts.Values) |
2148 | { | 2471 | { |
2149 | //m_log.DebugFormat("Found {0}", part.LocalId); | 2472 | //m_log.DebugFormat("Found {0}", part.LocalId); |
2150 | if (part.LocalId == localID) | 2473 | if (part.LocalId == localID) |
2151 | { | 2474 | { |
2475 | lockPartsForRead(false); | ||
2152 | return part; | 2476 | return part; |
2153 | } | 2477 | } |
2154 | } | 2478 | } |
2155 | } | 2479 | } |
2480 | lockPartsForRead(false); | ||
2156 | 2481 | ||
2157 | return null; | 2482 | return null; |
2158 | } | 2483 | } |
@@ -2182,17 +2507,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
2182 | public bool HasChildPrim(uint localID) | 2507 | public bool HasChildPrim(uint localID) |
2183 | { | 2508 | { |
2184 | //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); | 2509 | //m_log.DebugFormat("Entered HasChildPrim looking for {0}", localID); |
2185 | lock (m_parts) | 2510 | lockPartsForRead(true); |
2186 | { | 2511 | { |
2187 | foreach (SceneObjectPart part in m_parts.Values) | 2512 | foreach (SceneObjectPart part in m_parts.Values) |
2188 | { | 2513 | { |
2189 | //m_log.DebugFormat("Found {0}", part.LocalId); | 2514 | //m_log.DebugFormat("Found {0}", part.LocalId); |
2190 | if (part.LocalId == localID) | 2515 | if (part.LocalId == localID) |
2191 | { | 2516 | { |
2517 | lockPartsForRead(false); | ||
2192 | return true; | 2518 | return true; |
2193 | } | 2519 | } |
2194 | } | 2520 | } |
2195 | } | 2521 | } |
2522 | lockPartsForRead(false); | ||
2196 | 2523 | ||
2197 | return false; | 2524 | return false; |
2198 | } | 2525 | } |
@@ -2242,53 +2569,57 @@ namespace OpenSim.Region.Framework.Scenes | |||
2242 | if (m_rootPart.LinkNum == 0) | 2569 | if (m_rootPart.LinkNum == 0) |
2243 | m_rootPart.LinkNum = 1; | 2570 | m_rootPart.LinkNum = 1; |
2244 | 2571 | ||
2245 | lock (m_parts) | 2572 | lockPartsForWrite(true); |
2246 | { | 2573 | |
2247 | m_parts.Add(linkPart.UUID, linkPart); | 2574 | m_parts.Add(linkPart.UUID, linkPart); |
2575 | |||
2576 | lockPartsForWrite(false); | ||
2248 | 2577 | ||
2249 | // Insert in terms of link numbers, the new links | 2578 | // Insert in terms of link numbers, the new links |
2250 | // before the current ones (with the exception of | 2579 | // before the current ones (with the exception of |
2251 | // the root prim. Shuffle the old ones up | 2580 | // the root prim. Shuffle the old ones up |
2252 | foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) | 2581 | lockPartsForRead(true); |
2582 | foreach (KeyValuePair<UUID, SceneObjectPart> kvp in m_parts) | ||
2583 | { | ||
2584 | if (kvp.Value.LinkNum != 1) | ||
2253 | { | 2585 | { |
2254 | if (kvp.Value.LinkNum != 1) | 2586 | // Don't update root prim link number |
2255 | { | 2587 | kvp.Value.LinkNum += objectGroup.PrimCount; |
2256 | // Don't update root prim link number | ||
2257 | kvp.Value.LinkNum += objectGroup.PrimCount; | ||
2258 | } | ||
2259 | } | 2588 | } |
2589 | } | ||
2590 | lockPartsForRead(false); | ||
2260 | 2591 | ||
2261 | linkPart.LinkNum = 2; | 2592 | linkPart.LinkNum = 2; |
2262 | 2593 | ||
2263 | linkPart.SetParent(this); | 2594 | linkPart.SetParent(this); |
2264 | linkPart.CreateSelected = true; | 2595 | linkPart.CreateSelected = true; |
2265 | 2596 | ||
2266 | //if (linkPart.PhysActor != null) | 2597 | //if (linkPart.PhysActor != null) |
2267 | //{ | 2598 | //{ |
2268 | // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); | 2599 | // m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); |
2269 | 2600 | ||
2270 | //linkPart.PhysActor = null; | 2601 | //linkPart.PhysActor = null; |
2271 | //} | 2602 | //} |
2272 | 2603 | ||
2273 | //TODO: rest of parts | 2604 | //TODO: rest of parts |
2274 | int linkNum = 3; | 2605 | int linkNum = 3; |
2275 | foreach (SceneObjectPart part in objectGroup.Children.Values) | 2606 | foreach (SceneObjectPart part in objectGroup.Children.Values) |
2607 | { | ||
2608 | if (part.UUID != objectGroup.m_rootPart.UUID) | ||
2276 | { | 2609 | { |
2277 | if (part.UUID != objectGroup.m_rootPart.UUID) | 2610 | LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++); |
2278 | { | ||
2279 | LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++); | ||
2280 | } | ||
2281 | part.ClearUndoState(); | ||
2282 | } | 2611 | } |
2612 | part.ClearUndoState(); | ||
2283 | } | 2613 | } |
2284 | 2614 | ||
2285 | m_scene.UnlinkSceneObject(objectGroup.UUID, true); | 2615 | m_scene.UnlinkSceneObject(objectGroup.UUID, true); |
2286 | objectGroup.m_isDeleted = true; | 2616 | objectGroup.m_isDeleted = true; |
2617 | |||
2618 | objectGroup.lockPartsForWrite(true); | ||
2287 | 2619 | ||
2288 | lock (objectGroup.m_parts) | 2620 | objectGroup.m_parts.Clear(); |
2289 | { | 2621 | |
2290 | objectGroup.m_parts.Clear(); | 2622 | objectGroup.lockPartsForWrite(false); |
2291 | } | ||
2292 | 2623 | ||
2293 | // Can't do this yet since backup still makes use of the root part without any synchronization | 2624 | // Can't do this yet since backup still makes use of the root part without any synchronization |
2294 | // objectGroup.m_rootPart = null; | 2625 | // objectGroup.m_rootPart = null; |
@@ -2358,11 +2689,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2358 | Quaternion worldRot = linkPart.GetWorldRotation(); | 2689 | Quaternion worldRot = linkPart.GetWorldRotation(); |
2359 | 2690 | ||
2360 | // Remove the part from this object | 2691 | // Remove the part from this object |
2361 | lock (m_parts) | 2692 | lockPartsForWrite(true); |
2362 | { | 2693 | { |
2363 | m_parts.Remove(linkPart.UUID); | 2694 | m_parts.Remove(linkPart.UUID); |
2364 | } | 2695 | } |
2365 | 2696 | lockPartsForWrite(false); | |
2697 | lockPartsForRead(true); | ||
2366 | if (m_parts.Count == 1 && RootPart != null) //Single prim is left | 2698 | if (m_parts.Count == 1 && RootPart != null) //Single prim is left |
2367 | RootPart.LinkNum = 0; | 2699 | RootPart.LinkNum = 0; |
2368 | else | 2700 | else |
@@ -2373,6 +2705,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2373 | p.LinkNum--; | 2705 | p.LinkNum--; |
2374 | } | 2706 | } |
2375 | } | 2707 | } |
2708 | lockPartsForRead(false); | ||
2376 | 2709 | ||
2377 | linkPart.ParentID = 0; | 2710 | linkPart.ParentID = 0; |
2378 | linkPart.LinkNum = 0; | 2711 | linkPart.LinkNum = 0; |
@@ -2416,6 +2749,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2416 | /// <param name="objectGroup"></param> | 2749 | /// <param name="objectGroup"></param> |
2417 | public virtual void DetachFromBackup() | 2750 | public virtual void DetachFromBackup() |
2418 | { | 2751 | { |
2752 | m_scene.SceneGraph.FireDetachFromBackup(this); | ||
2753 | |||
2419 | if (m_isBackedUp) | 2754 | if (m_isBackedUp) |
2420 | m_scene.EventManager.OnBackup -= ProcessBackup; | 2755 | m_scene.EventManager.OnBackup -= ProcessBackup; |
2421 | 2756 | ||
@@ -2694,9 +3029,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2694 | 3029 | ||
2695 | if (selectionPart != null) | 3030 | if (selectionPart != null) |
2696 | { | 3031 | { |
2697 | lock (m_parts) | 3032 | lockPartsForRead(true); |
3033 | List<SceneObjectPart> parts = new List<SceneObjectPart>(m_parts.Values); | ||
3034 | lockPartsForRead(false); | ||
3035 | foreach (SceneObjectPart part in parts) | ||
2698 | { | 3036 | { |
2699 | foreach (SceneObjectPart part in m_parts.Values) | 3037 | if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0) |
2700 | { | 3038 | { |
2701 | if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || | 3039 | if (part.Scale.X > m_scene.RegionInfo.PhysPrimMax || |
2702 | part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || | 3040 | part.Scale.Y > m_scene.RegionInfo.PhysPrimMax || |
@@ -2706,12 +3044,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
2706 | break; | 3044 | break; |
2707 | } | 3045 | } |
2708 | } | 3046 | } |
3047 | } | ||
2709 | 3048 | ||
2710 | foreach (SceneObjectPart part in m_parts.Values) | 3049 | foreach (SceneObjectPart part in parts) |
2711 | { | 3050 | { |
2712 | part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); | 3051 | part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect); |
2713 | } | ||
2714 | } | 3052 | } |
3053 | |||
2715 | } | 3054 | } |
2716 | } | 3055 | } |
2717 | 3056 | ||
@@ -2724,6 +3063,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
2724 | } | 3063 | } |
2725 | } | 3064 | } |
2726 | 3065 | ||
3066 | |||
3067 | |||
3068 | /// <summary> | ||
3069 | /// Gets the number of parts | ||
3070 | /// </summary> | ||
3071 | /// <returns></returns> | ||
3072 | public int GetPartCount() | ||
3073 | { | ||
3074 | return Children.Count; | ||
3075 | } | ||
3076 | |||
2727 | /// <summary> | 3077 | /// <summary> |
2728 | /// Get the parts of this scene object | 3078 | /// Get the parts of this scene object |
2729 | /// </summary> | 3079 | /// </summary> |
@@ -2797,11 +3147,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
2797 | scale.Y = m_scene.m_maxNonphys; | 3147 | scale.Y = m_scene.m_maxNonphys; |
2798 | if (scale.Z > m_scene.m_maxNonphys) | 3148 | if (scale.Z > m_scene.m_maxNonphys) |
2799 | scale.Z = m_scene.m_maxNonphys; | 3149 | scale.Z = m_scene.m_maxNonphys; |
2800 | |||
2801 | SceneObjectPart part = GetChildPart(localID); | 3150 | SceneObjectPart part = GetChildPart(localID); |
2802 | if (part != null) | 3151 | if (part != null) |
2803 | { | 3152 | { |
2804 | part.Resize(scale); | ||
2805 | if (part.PhysActor != null) | 3153 | if (part.PhysActor != null) |
2806 | { | 3154 | { |
2807 | if (part.PhysActor.IsPhysical) | 3155 | if (part.PhysActor.IsPhysical) |
@@ -2816,7 +3164,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2816 | part.PhysActor.Size = scale; | 3164 | part.PhysActor.Size = scale; |
2817 | m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); | 3165 | m_scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor); |
2818 | } | 3166 | } |
2819 | //if (part.UUID != m_rootPart.UUID) | 3167 | part.Resize(scale); |
2820 | 3168 | ||
2821 | HasGroupChanged = true; | 3169 | HasGroupChanged = true; |
2822 | ScheduleGroupForFullUpdate(); | 3170 | ScheduleGroupForFullUpdate(); |
@@ -2838,7 +3186,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2838 | SceneObjectPart part = GetChildPart(localID); | 3186 | SceneObjectPart part = GetChildPart(localID); |
2839 | if (part != null) | 3187 | if (part != null) |
2840 | { | 3188 | { |
2841 | part.IgnoreUndoUpdate = true; | ||
2842 | if (scale.X > m_scene.m_maxNonphys) | 3189 | if (scale.X > m_scene.m_maxNonphys) |
2843 | scale.X = m_scene.m_maxNonphys; | 3190 | scale.X = m_scene.m_maxNonphys; |
2844 | if (scale.Y > m_scene.m_maxNonphys) | 3191 | if (scale.Y > m_scene.m_maxNonphys) |
@@ -2858,94 +3205,100 @@ namespace OpenSim.Region.Framework.Scenes | |||
2858 | float y = (scale.Y / part.Scale.Y); | 3205 | float y = (scale.Y / part.Scale.Y); |
2859 | float z = (scale.Z / part.Scale.Z); | 3206 | float z = (scale.Z / part.Scale.Z); |
2860 | 3207 | ||
2861 | lock (m_parts) | 3208 | lockPartsForRead(true); |
3209 | if (x > 1.0f || y > 1.0f || z > 1.0f) | ||
2862 | { | 3210 | { |
2863 | if (x > 1.0f || y > 1.0f || z > 1.0f) | 3211 | foreach (SceneObjectPart obPart in m_parts.Values) |
2864 | { | 3212 | { |
2865 | foreach (SceneObjectPart obPart in m_parts.Values) | 3213 | if (obPart.UUID != m_rootPart.UUID) |
2866 | { | 3214 | { |
2867 | if (obPart.UUID != m_rootPart.UUID) | 3215 | Vector3 oldSize = new Vector3(obPart.Scale); |
2868 | { | 3216 | obPart.IgnoreUndoUpdate = true; |
2869 | obPart.IgnoreUndoUpdate = true; | ||
2870 | Vector3 oldSize = new Vector3(obPart.Scale); | ||
2871 | 3217 | ||
2872 | float f = 1.0f; | 3218 | float f = 1.0f; |
2873 | float a = 1.0f; | 3219 | float a = 1.0f; |
2874 | 3220 | ||
2875 | if (part.PhysActor != null && part.PhysActor.IsPhysical) | 3221 | if (part.PhysActor != null && part.PhysActor.IsPhysical) |
3222 | { | ||
3223 | if (oldSize.X*x > m_scene.m_maxPhys) | ||
2876 | { | 3224 | { |
2877 | if (oldSize.X*x > m_scene.m_maxPhys) | 3225 | f = m_scene.m_maxPhys / oldSize.X; |
2878 | { | 3226 | a = f / x; |
2879 | f = m_scene.m_maxPhys / oldSize.X; | 3227 | x *= a; |
2880 | a = f / x; | 3228 | y *= a; |
2881 | x *= a; | 3229 | z *= a; |
2882 | y *= a; | ||
2883 | z *= a; | ||
2884 | } | ||
2885 | if (oldSize.Y*y > m_scene.m_maxPhys) | ||
2886 | { | ||
2887 | f = m_scene.m_maxPhys / oldSize.Y; | ||
2888 | a = f / y; | ||
2889 | x *= a; | ||
2890 | y *= a; | ||
2891 | z *= a; | ||
2892 | } | ||
2893 | if (oldSize.Z*z > m_scene.m_maxPhys) | ||
2894 | { | ||
2895 | f = m_scene.m_maxPhys / oldSize.Z; | ||
2896 | a = f / z; | ||
2897 | x *= a; | ||
2898 | y *= a; | ||
2899 | z *= a; | ||
2900 | } | ||
2901 | } | 3230 | } |
2902 | else | 3231 | if (oldSize.Y*y > m_scene.m_maxPhys) |
3232 | { | ||
3233 | f = m_scene.m_maxPhys / oldSize.Y; | ||
3234 | a = f / y; | ||
3235 | x *= a; | ||
3236 | y *= a; | ||
3237 | z *= a; | ||
3238 | } | ||
3239 | if (oldSize.Z*z > m_scene.m_maxPhys) | ||
3240 | { | ||
3241 | f = m_scene.m_maxPhys / oldSize.Z; | ||
3242 | a = f / z; | ||
3243 | x *= a; | ||
3244 | y *= a; | ||
3245 | z *= a; | ||
3246 | } | ||
3247 | } | ||
3248 | else | ||
3249 | { | ||
3250 | if (oldSize.X*x > m_scene.m_maxNonphys) | ||
3251 | { | ||
3252 | f = m_scene.m_maxNonphys / oldSize.X; | ||
3253 | a = f / x; | ||
3254 | x *= a; | ||
3255 | y *= a; | ||
3256 | z *= a; | ||
3257 | } | ||
3258 | if (oldSize.Y*y > m_scene.m_maxNonphys) | ||
3259 | { | ||
3260 | f = m_scene.m_maxNonphys / oldSize.Y; | ||
3261 | a = f / y; | ||
3262 | x *= a; | ||
3263 | y *= a; | ||
3264 | z *= a; | ||
3265 | } | ||
3266 | if (oldSize.Z*z > m_scene.m_maxNonphys) | ||
2903 | { | 3267 | { |
2904 | if (oldSize.X*x > m_scene.m_maxNonphys) | 3268 | f = m_scene.m_maxNonphys / oldSize.Z; |
2905 | { | 3269 | a = f / z; |
2906 | f = m_scene.m_maxNonphys / oldSize.X; | 3270 | x *= a; |
2907 | a = f / x; | 3271 | y *= a; |
2908 | x *= a; | 3272 | z *= a; |
2909 | y *= a; | ||
2910 | z *= a; | ||
2911 | } | ||
2912 | if (oldSize.Y*y > m_scene.m_maxNonphys) | ||
2913 | { | ||
2914 | f = m_scene.m_maxNonphys / oldSize.Y; | ||
2915 | a = f / y; | ||
2916 | x *= a; | ||
2917 | y *= a; | ||
2918 | z *= a; | ||
2919 | } | ||
2920 | if (oldSize.Z*z > m_scene.m_maxNonphys) | ||
2921 | { | ||
2922 | f = m_scene.m_maxNonphys / oldSize.Z; | ||
2923 | a = f / z; | ||
2924 | x *= a; | ||
2925 | y *= a; | ||
2926 | z *= a; | ||
2927 | } | ||
2928 | } | 3273 | } |
2929 | obPart.IgnoreUndoUpdate = false; | 3274 | |
2930 | obPart.StoreUndoState(); | ||
2931 | } | 3275 | } |
2932 | } | 3276 | } |
2933 | } | 3277 | } |
2934 | } | 3278 | } |
3279 | lockPartsForRead(false); | ||
2935 | 3280 | ||
2936 | Vector3 prevScale = part.Scale; | 3281 | Vector3 prevScale = part.Scale; |
2937 | prevScale.X *= x; | 3282 | prevScale.X *= x; |
2938 | prevScale.Y *= y; | 3283 | prevScale.Y *= y; |
2939 | prevScale.Z *= z; | 3284 | prevScale.Z *= z;; |
3285 | |||
3286 | part.IgnoreUndoUpdate = false; | ||
3287 | part.StoreUndoState(UndoType.STATE_GROUP_SCALE); | ||
3288 | part.IgnoreUndoUpdate = true; | ||
2940 | part.Resize(prevScale); | 3289 | part.Resize(prevScale); |
3290 | part.IgnoreUndoUpdate = false; | ||
2941 | 3291 | ||
2942 | lock (m_parts) | 3292 | lockPartsForRead(true); |
2943 | { | 3293 | { |
2944 | foreach (SceneObjectPart obPart in m_parts.Values) | 3294 | foreach (SceneObjectPart obPart in m_parts.Values) |
2945 | { | 3295 | { |
2946 | obPart.IgnoreUndoUpdate = true; | ||
2947 | if (obPart.UUID != m_rootPart.UUID) | 3296 | if (obPart.UUID != m_rootPart.UUID) |
2948 | { | 3297 | { |
3298 | obPart.IgnoreUndoUpdate = false; | ||
3299 | obPart.StoreUndoState(UndoType.STATE_GROUP_SCALE); | ||
3300 | obPart.IgnoreUndoUpdate = true; | ||
3301 | |||
2949 | Vector3 currentpos = new Vector3(obPart.OffsetPosition); | 3302 | Vector3 currentpos = new Vector3(obPart.OffsetPosition); |
2950 | currentpos.X *= x; | 3303 | currentpos.X *= x; |
2951 | currentpos.Y *= y; | 3304 | currentpos.Y *= y; |
@@ -2958,9 +3311,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
2958 | obPart.UpdateOffSet(currentpos); | 3311 | obPart.UpdateOffSet(currentpos); |
2959 | } | 3312 | } |
2960 | obPart.IgnoreUndoUpdate = false; | 3313 | obPart.IgnoreUndoUpdate = false; |
2961 | obPart.StoreUndoState(); | ||
2962 | } | 3314 | } |
2963 | } | 3315 | } |
3316 | lockPartsForRead(false); | ||
2964 | 3317 | ||
2965 | if (part.PhysActor != null) | 3318 | if (part.PhysActor != null) |
2966 | { | 3319 | { |
@@ -2969,7 +3322,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2969 | } | 3322 | } |
2970 | 3323 | ||
2971 | part.IgnoreUndoUpdate = false; | 3324 | part.IgnoreUndoUpdate = false; |
2972 | part.StoreUndoState(); | ||
2973 | HasGroupChanged = true; | 3325 | HasGroupChanged = true; |
2974 | ScheduleGroupForTerseUpdate(); | 3326 | ScheduleGroupForTerseUpdate(); |
2975 | } | 3327 | } |
@@ -2985,14 +3337,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
2985 | /// <param name="pos"></param> | 3337 | /// <param name="pos"></param> |
2986 | public void UpdateGroupPosition(Vector3 pos) | 3338 | public void UpdateGroupPosition(Vector3 pos) |
2987 | { | 3339 | { |
2988 | foreach (SceneObjectPart part in Children.Values) | ||
2989 | { | ||
2990 | part.StoreUndoState(); | ||
2991 | } | ||
2992 | if (m_scene.EventManager.TriggerGroupMove(UUID, pos)) | 3340 | if (m_scene.EventManager.TriggerGroupMove(UUID, pos)) |
2993 | { | 3341 | { |
2994 | if (IsAttachment) | 3342 | if (IsAttachment) |
2995 | { | 3343 | { |
3344 | m_rootPart.StoreUndoState(UndoType.STATE_GROUP_POSITION); | ||
2996 | m_rootPart.AttachedPos = pos; | 3345 | m_rootPart.AttachedPos = pos; |
2997 | } | 3346 | } |
2998 | if (RootPart.GetStatusSandbox()) | 3347 | if (RootPart.GetStatusSandbox()) |
@@ -3025,7 +3374,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3025 | SceneObjectPart part = GetChildPart(localID); | 3374 | SceneObjectPart part = GetChildPart(localID); |
3026 | foreach (SceneObjectPart parts in Children.Values) | 3375 | foreach (SceneObjectPart parts in Children.Values) |
3027 | { | 3376 | { |
3028 | parts.StoreUndoState(); | 3377 | parts.StoreUndoState(UndoType.STATE_PRIM_POSITION); |
3029 | } | 3378 | } |
3030 | if (part != null) | 3379 | if (part != null) |
3031 | { | 3380 | { |
@@ -3050,7 +3399,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3050 | { | 3399 | { |
3051 | foreach (SceneObjectPart part in Children.Values) | 3400 | foreach (SceneObjectPart part in Children.Values) |
3052 | { | 3401 | { |
3053 | part.StoreUndoState(); | 3402 | part.StoreUndoState(UndoType.STATE_PRIM_POSITION); |
3054 | } | 3403 | } |
3055 | Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z); | 3404 | Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z); |
3056 | Vector3 oldPos = | 3405 | Vector3 oldPos = |
@@ -3063,7 +3412,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3063 | axDiff *= Quaternion.Inverse(partRotation); | 3412 | axDiff *= Quaternion.Inverse(partRotation); |
3064 | diff = axDiff; | 3413 | diff = axDiff; |
3065 | 3414 | ||
3066 | lock (m_parts) | 3415 | lockPartsForRead(true); |
3067 | { | 3416 | { |
3068 | foreach (SceneObjectPart obPart in m_parts.Values) | 3417 | foreach (SceneObjectPart obPart in m_parts.Values) |
3069 | { | 3418 | { |
@@ -3073,11 +3422,29 @@ namespace OpenSim.Region.Framework.Scenes | |||
3073 | } | 3422 | } |
3074 | } | 3423 | } |
3075 | } | 3424 | } |
3425 | lockPartsForRead(false); | ||
3076 | 3426 | ||
3077 | AbsolutePosition = newPos; | 3427 | //We have to set undoing here because otherwise an undo state will be saved |
3428 | if (!m_rootPart.Undoing) | ||
3429 | { | ||
3430 | m_rootPart.Undoing = true; | ||
3431 | AbsolutePosition = newPos; | ||
3432 | m_rootPart.Undoing = false; | ||
3433 | } | ||
3434 | else | ||
3435 | { | ||
3436 | AbsolutePosition = newPos; | ||
3437 | } | ||
3078 | 3438 | ||
3079 | HasGroupChanged = true; | 3439 | HasGroupChanged = true; |
3080 | ScheduleGroupForTerseUpdate(); | 3440 | if (m_rootPart.Undoing) |
3441 | { | ||
3442 | ScheduleGroupForFullUpdate(); | ||
3443 | } | ||
3444 | else | ||
3445 | { | ||
3446 | ScheduleGroupForTerseUpdate(); | ||
3447 | } | ||
3081 | } | 3448 | } |
3082 | 3449 | ||
3083 | public void OffsetForNewRegion(Vector3 offset) | 3450 | public void OffsetForNewRegion(Vector3 offset) |
@@ -3097,7 +3464,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3097 | { | 3464 | { |
3098 | foreach (SceneObjectPart parts in Children.Values) | 3465 | foreach (SceneObjectPart parts in Children.Values) |
3099 | { | 3466 | { |
3100 | parts.StoreUndoState(); | 3467 | parts.StoreUndoState(UndoType.STATE_GROUP_ROTATION); |
3101 | } | 3468 | } |
3102 | m_rootPart.UpdateRotation(rot); | 3469 | m_rootPart.UpdateRotation(rot); |
3103 | 3470 | ||
@@ -3121,7 +3488,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3121 | { | 3488 | { |
3122 | foreach (SceneObjectPart parts in Children.Values) | 3489 | foreach (SceneObjectPart parts in Children.Values) |
3123 | { | 3490 | { |
3124 | parts.StoreUndoState(); | 3491 | parts.StoreUndoState(UndoType.STATE_GROUP_ROTATION); |
3125 | } | 3492 | } |
3126 | m_rootPart.UpdateRotation(rot); | 3493 | m_rootPart.UpdateRotation(rot); |
3127 | 3494 | ||
@@ -3148,7 +3515,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3148 | SceneObjectPart part = GetChildPart(localID); | 3515 | SceneObjectPart part = GetChildPart(localID); |
3149 | foreach (SceneObjectPart parts in Children.Values) | 3516 | foreach (SceneObjectPart parts in Children.Values) |
3150 | { | 3517 | { |
3151 | parts.StoreUndoState(); | 3518 | parts.StoreUndoState(UndoType.STATE_PRIM_ROTATION); |
3152 | } | 3519 | } |
3153 | if (part != null) | 3520 | if (part != null) |
3154 | { | 3521 | { |
@@ -3176,15 +3543,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
3176 | if (part.UUID == m_rootPart.UUID) | 3543 | if (part.UUID == m_rootPart.UUID) |
3177 | { | 3544 | { |
3178 | UpdateRootRotation(rot); | 3545 | UpdateRootRotation(rot); |
3179 | AbsolutePosition = pos; | 3546 | if (!m_rootPart.Undoing) |
3547 | { | ||
3548 | m_rootPart.Undoing = true; | ||
3549 | AbsolutePosition = pos; | ||
3550 | m_rootPart.Undoing = false; | ||
3551 | } | ||
3552 | else | ||
3553 | { | ||
3554 | AbsolutePosition = pos; | ||
3555 | } | ||
3180 | } | 3556 | } |
3181 | else | 3557 | else |
3182 | { | 3558 | { |
3559 | part.StoreUndoState(UndoType.STATE_PRIM_ROTATION); | ||
3183 | part.IgnoreUndoUpdate = true; | 3560 | part.IgnoreUndoUpdate = true; |
3184 | part.UpdateRotation(rot); | 3561 | part.UpdateRotation(rot); |
3185 | part.OffsetPosition = pos; | 3562 | part.OffsetPosition = pos; |
3186 | part.IgnoreUndoUpdate = false; | 3563 | part.IgnoreUndoUpdate = false; |
3187 | part.StoreUndoState(); | ||
3188 | } | 3564 | } |
3189 | } | 3565 | } |
3190 | } | 3566 | } |
@@ -3198,7 +3574,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
3198 | Quaternion axRot = rot; | 3574 | Quaternion axRot = rot; |
3199 | Quaternion oldParentRot = m_rootPart.RotationOffset; | 3575 | Quaternion oldParentRot = m_rootPart.RotationOffset; |
3200 | 3576 | ||
3201 | m_rootPart.StoreUndoState(); | 3577 | m_rootPart.StoreUndoState(UndoType.STATE_PRIM_ROTATION); |
3578 | bool cancelUndo = false; | ||
3579 | if (!m_rootPart.Undoing) | ||
3580 | { | ||
3581 | m_rootPart.Undoing = true; | ||
3582 | cancelUndo = true; | ||
3583 | } | ||
3202 | m_rootPart.UpdateRotation(rot); | 3584 | m_rootPart.UpdateRotation(rot); |
3203 | if (m_rootPart.PhysActor != null) | 3585 | if (m_rootPart.PhysActor != null) |
3204 | { | 3586 | { |
@@ -3206,33 +3588,31 @@ namespace OpenSim.Region.Framework.Scenes | |||
3206 | m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); | 3588 | m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor); |
3207 | } | 3589 | } |
3208 | 3590 | ||
3209 | lock (m_parts) | 3591 | lockPartsForRead(true); |
3592 | |||
3593 | foreach (SceneObjectPart prim in m_parts.Values) | ||
3210 | { | 3594 | { |
3211 | foreach (SceneObjectPart prim in m_parts.Values) | 3595 | if (prim.UUID != m_rootPart.UUID) |
3212 | { | 3596 | { |
3213 | if (prim.UUID != m_rootPart.UUID) | 3597 | prim.IgnoreUndoUpdate = true; |
3214 | { | 3598 | Vector3 axPos = prim.OffsetPosition; |
3215 | prim.IgnoreUndoUpdate = true; | 3599 | axPos *= oldParentRot; |
3216 | Vector3 axPos = prim.OffsetPosition; | 3600 | axPos *= Quaternion.Inverse(axRot); |
3217 | axPos *= oldParentRot; | 3601 | prim.OffsetPosition = axPos; |
3218 | axPos *= Quaternion.Inverse(axRot); | 3602 | Quaternion primsRot = prim.RotationOffset; |
3219 | prim.OffsetPosition = axPos; | 3603 | Quaternion newRot = primsRot * oldParentRot; |
3220 | Quaternion primsRot = prim.RotationOffset; | 3604 | newRot *= Quaternion.Inverse(axRot); |
3221 | Quaternion newRot = primsRot * oldParentRot; | 3605 | prim.RotationOffset = newRot; |
3222 | newRot *= Quaternion.Inverse(axRot); | 3606 | prim.ScheduleTerseUpdate(); |
3223 | prim.RotationOffset = newRot; | 3607 | prim.IgnoreUndoUpdate = false; |
3224 | prim.ScheduleTerseUpdate(); | ||
3225 | } | ||
3226 | } | 3608 | } |
3227 | } | 3609 | } |
3228 | foreach (SceneObjectPart childpart in Children.Values) | 3610 | if (cancelUndo == true) |
3229 | { | 3611 | { |
3230 | if (childpart != m_rootPart) | 3612 | m_rootPart.Undoing = false; |
3231 | { | ||
3232 | childpart.IgnoreUndoUpdate = false; | ||
3233 | childpart.StoreUndoState(); | ||
3234 | } | ||
3235 | } | 3613 | } |
3614 | lockPartsForRead(false); | ||
3615 | |||
3236 | m_rootPart.ScheduleTerseUpdate(); | 3616 | m_rootPart.ScheduleTerseUpdate(); |
3237 | } | 3617 | } |
3238 | 3618 | ||
@@ -3354,7 +3734,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3354 | if (atTargets.Count > 0) | 3734 | if (atTargets.Count > 0) |
3355 | { | 3735 | { |
3356 | uint[] localids = new uint[0]; | 3736 | uint[] localids = new uint[0]; |
3357 | lock (m_parts) | 3737 | lockPartsForRead(true); |
3358 | { | 3738 | { |
3359 | localids = new uint[m_parts.Count]; | 3739 | localids = new uint[m_parts.Count]; |
3360 | int cntr = 0; | 3740 | int cntr = 0; |
@@ -3364,6 +3744,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3364 | cntr++; | 3744 | cntr++; |
3365 | } | 3745 | } |
3366 | } | 3746 | } |
3747 | lockPartsForRead(false); | ||
3367 | 3748 | ||
3368 | for (int ctr = 0; ctr < localids.Length; ctr++) | 3749 | for (int ctr = 0; ctr < localids.Length; ctr++) |
3369 | { | 3750 | { |
@@ -3382,7 +3763,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3382 | { | 3763 | { |
3383 | //trigger not_at_target | 3764 | //trigger not_at_target |
3384 | uint[] localids = new uint[0]; | 3765 | uint[] localids = new uint[0]; |
3385 | lock (m_parts) | 3766 | lockPartsForRead(true); |
3386 | { | 3767 | { |
3387 | localids = new uint[m_parts.Count]; | 3768 | localids = new uint[m_parts.Count]; |
3388 | int cntr = 0; | 3769 | int cntr = 0; |
@@ -3392,7 +3773,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3392 | cntr++; | 3773 | cntr++; |
3393 | } | 3774 | } |
3394 | } | 3775 | } |
3395 | 3776 | lockPartsForRead(false); | |
3777 | |||
3396 | for (int ctr = 0; ctr < localids.Length; ctr++) | 3778 | for (int ctr = 0; ctr < localids.Length; ctr++) |
3397 | { | 3779 | { |
3398 | m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); | 3780 | m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]); |
@@ -3433,7 +3815,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3433 | if (atRotTargets.Count > 0) | 3815 | if (atRotTargets.Count > 0) |
3434 | { | 3816 | { |
3435 | uint[] localids = new uint[0]; | 3817 | uint[] localids = new uint[0]; |
3436 | lock (m_parts) | 3818 | lockPartsForRead(true); |
3819 | try | ||
3437 | { | 3820 | { |
3438 | localids = new uint[m_parts.Count]; | 3821 | localids = new uint[m_parts.Count]; |
3439 | int cntr = 0; | 3822 | int cntr = 0; |
@@ -3443,6 +3826,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
3443 | cntr++; | 3826 | cntr++; |
3444 | } | 3827 | } |
3445 | } | 3828 | } |
3829 | finally | ||
3830 | { | ||
3831 | lockPartsForRead(false); | ||
3832 | } | ||
3446 | 3833 | ||
3447 | for (int ctr = 0; ctr < localids.Length; ctr++) | 3834 | for (int ctr = 0; ctr < localids.Length; ctr++) |
3448 | { | 3835 | { |
@@ -3461,7 +3848,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3461 | { | 3848 | { |
3462 | //trigger not_at_target | 3849 | //trigger not_at_target |
3463 | uint[] localids = new uint[0]; | 3850 | uint[] localids = new uint[0]; |
3464 | lock (m_parts) | 3851 | lockPartsForRead(true); |
3852 | try | ||
3465 | { | 3853 | { |
3466 | localids = new uint[m_parts.Count]; | 3854 | localids = new uint[m_parts.Count]; |
3467 | int cntr = 0; | 3855 | int cntr = 0; |
@@ -3471,6 +3859,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
3471 | cntr++; | 3859 | cntr++; |
3472 | } | 3860 | } |
3473 | } | 3861 | } |
3862 | finally | ||
3863 | { | ||
3864 | lockPartsForRead(false); | ||
3865 | } | ||
3474 | 3866 | ||
3475 | for (int ctr = 0; ctr < localids.Length; ctr++) | 3867 | for (int ctr = 0; ctr < localids.Length; ctr++) |
3476 | { | 3868 | { |
@@ -3484,19 +3876,20 @@ namespace OpenSim.Region.Framework.Scenes | |||
3484 | public float GetMass() | 3876 | public float GetMass() |
3485 | { | 3877 | { |
3486 | float retmass = 0f; | 3878 | float retmass = 0f; |
3487 | lock (m_parts) | 3879 | lockPartsForRead(true); |
3488 | { | 3880 | { |
3489 | foreach (SceneObjectPart part in m_parts.Values) | 3881 | foreach (SceneObjectPart part in m_parts.Values) |
3490 | { | 3882 | { |
3491 | retmass += part.GetMass(); | 3883 | retmass += part.GetMass(); |
3492 | } | 3884 | } |
3493 | } | 3885 | } |
3886 | lockPartsForRead(false); | ||
3494 | return retmass; | 3887 | return retmass; |
3495 | } | 3888 | } |
3496 | 3889 | ||
3497 | public void CheckSculptAndLoad() | 3890 | public void CheckSculptAndLoad() |
3498 | { | 3891 | { |
3499 | lock (m_parts) | 3892 | lockPartsForRead(true); |
3500 | { | 3893 | { |
3501 | if (!IsDeleted) | 3894 | if (!IsDeleted) |
3502 | { | 3895 | { |
@@ -3521,6 +3914,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3521 | } | 3914 | } |
3522 | } | 3915 | } |
3523 | } | 3916 | } |
3917 | lockPartsForRead(false); | ||
3524 | } | 3918 | } |
3525 | 3919 | ||
3526 | protected void AssetReceived(string id, Object sender, AssetBase asset) | 3920 | protected void AssetReceived(string id, Object sender, AssetBase asset) |
@@ -3541,7 +3935,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3541 | /// <param name="client"></param> | 3935 | /// <param name="client"></param> |
3542 | public void SetGroup(UUID GroupID, IClientAPI client) | 3936 | public void SetGroup(UUID GroupID, IClientAPI client) |
3543 | { | 3937 | { |
3544 | lock (m_parts) | 3938 | lockPartsForRead(true); |
3545 | { | 3939 | { |
3546 | foreach (SceneObjectPart part in m_parts.Values) | 3940 | foreach (SceneObjectPart part in m_parts.Values) |
3547 | { | 3941 | { |
@@ -3551,6 +3945,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3551 | 3945 | ||
3552 | HasGroupChanged = true; | 3946 | HasGroupChanged = true; |
3553 | } | 3947 | } |
3948 | lockPartsForRead(false); | ||
3554 | 3949 | ||
3555 | // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled | 3950 | // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled |
3556 | // for the same object with very different properties. The caller must schedule the update. | 3951 | // for the same object with very different properties. The caller must schedule the update. |
@@ -3572,11 +3967,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3572 | 3967 | ||
3573 | public void SetAttachmentPoint(byte point) | 3968 | public void SetAttachmentPoint(byte point) |
3574 | { | 3969 | { |
3575 | lock (m_parts) | 3970 | lockPartsForRead(true); |
3576 | { | 3971 | { |
3577 | foreach (SceneObjectPart part in m_parts.Values) | 3972 | foreach (SceneObjectPart part in m_parts.Values) |
3578 | part.SetAttachmentPoint(point); | 3973 | part.SetAttachmentPoint(point); |
3579 | } | 3974 | } |
3975 | lockPartsForRead(false); | ||
3580 | } | 3976 | } |
3581 | 3977 | ||
3582 | #region ISceneObject | 3978 | #region ISceneObject |
@@ -3610,6 +4006,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
3610 | SetFromItemID(uuid); | 4006 | SetFromItemID(uuid); |
3611 | } | 4007 | } |
3612 | 4008 | ||
4009 | public void ResetOwnerChangeFlag() | ||
4010 | { | ||
4011 | ForEachPart(delegate(SceneObjectPart part) | ||
4012 | { | ||
4013 | part.ResetOwnerChangeFlag(); | ||
4014 | }); | ||
4015 | } | ||
4016 | |||
3613 | #endregion | 4017 | #endregion |
3614 | } | 4018 | } |
3615 | } | 4019 | } |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 0c35eec..77581af 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | |||
@@ -60,7 +60,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
60 | TELEPORT = 512, | 60 | TELEPORT = 512, |
61 | REGION_RESTART = 1024, | 61 | REGION_RESTART = 1024, |
62 | MEDIA = 2048, | 62 | MEDIA = 2048, |
63 | ANIMATION = 16384 | 63 | ANIMATION = 16384, |
64 | POSITION = 32768 | ||
64 | } | 65 | } |
65 | 66 | ||
66 | // I don't really know where to put this except here. | 67 | // I don't really know where to put this except here. |
@@ -149,7 +150,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
149 | 150 | ||
150 | // TODO: This needs to be persisted in next XML version update! | 151 | // TODO: This needs to be persisted in next XML version update! |
151 | [XmlIgnore] | 152 | [XmlIgnore] |
152 | public readonly int[] PayPrice = {-2,-2,-2,-2,-2}; | 153 | public int[] PayPrice = {-2,-2,-2,-2,-2}; |
153 | [XmlIgnore] | 154 | [XmlIgnore] |
154 | public PhysicsActor PhysActor; | 155 | public PhysicsActor PhysActor; |
155 | 156 | ||
@@ -184,6 +185,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
184 | [XmlIgnore] | 185 | [XmlIgnore] |
185 | public UUID FromFolderID; | 186 | public UUID FromFolderID; |
186 | 187 | ||
188 | // The following two are to hold the attachment data | ||
189 | // while an object is inworld | ||
190 | [XmlIgnore] | ||
191 | public byte AttachPoint = 0; | ||
192 | |||
193 | [XmlIgnore] | ||
194 | public Vector3 AttachOffset = Vector3.Zero; | ||
195 | |||
187 | [XmlIgnore] | 196 | [XmlIgnore] |
188 | public int STATUS_ROTATE_X; | 197 | public int STATUS_ROTATE_X; |
189 | 198 | ||
@@ -279,6 +288,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
279 | private Quaternion m_sitTargetOrientation = Quaternion.Identity; | 288 | private Quaternion m_sitTargetOrientation = Quaternion.Identity; |
280 | private Vector3 m_sitTargetPosition; | 289 | private Vector3 m_sitTargetPosition; |
281 | private string m_sitAnimation = "SIT"; | 290 | private string m_sitAnimation = "SIT"; |
291 | private bool m_occupied; // KF if any av is sitting on this prim | ||
282 | private string m_text = String.Empty; | 292 | private string m_text = String.Empty; |
283 | private string m_touchName = String.Empty; | 293 | private string m_touchName = String.Empty; |
284 | private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5); | 294 | private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5); |
@@ -367,7 +377,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
367 | UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, | 377 | UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, |
368 | Quaternion rotationOffset, Vector3 offsetPosition) | 378 | Quaternion rotationOffset, Vector3 offsetPosition) |
369 | { | 379 | { |
370 | m_name = "Primitive"; | 380 | m_name = "Object"; |
371 | 381 | ||
372 | Rezzed = DateTime.UtcNow; | 382 | Rezzed = DateTime.UtcNow; |
373 | _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed); | 383 | _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed); |
@@ -463,12 +473,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
463 | } | 473 | } |
464 | 474 | ||
465 | /// <value> | 475 | /// <value> |
466 | /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes | 476 | /// Get the inventory list |
467 | /// </value> | 477 | /// </value> |
468 | public TaskInventoryDictionary TaskInventory | 478 | public TaskInventoryDictionary TaskInventory |
469 | { | 479 | { |
470 | get { return m_inventory.Items; } | 480 | get { |
471 | set { m_inventory.Items = value; } | 481 | return m_inventory.Items; |
482 | } | ||
483 | set { | ||
484 | m_inventory.Items = value; | ||
485 | } | ||
472 | } | 486 | } |
473 | 487 | ||
474 | public uint ObjectFlags | 488 | public uint ObjectFlags |
@@ -597,14 +611,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
597 | set { m_LoopSoundSlavePrims = value; } | 611 | set { m_LoopSoundSlavePrims = value; } |
598 | } | 612 | } |
599 | 613 | ||
600 | [XmlIgnore] | ||
601 | public Byte[] TextureAnimation | 614 | public Byte[] TextureAnimation |
602 | { | 615 | { |
603 | get { return m_TextureAnimation; } | 616 | get { return m_TextureAnimation; } |
604 | set { m_TextureAnimation = value; } | 617 | set { m_TextureAnimation = value; } |
605 | } | 618 | } |
606 | 619 | ||
607 | [XmlIgnore] | ||
608 | public Byte[] ParticleSystem | 620 | public Byte[] ParticleSystem |
609 | { | 621 | { |
610 | get { return m_particleSystem; } | 622 | get { return m_particleSystem; } |
@@ -658,7 +670,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
658 | set | 670 | set |
659 | { | 671 | { |
660 | m_groupPosition = value; | 672 | m_groupPosition = value; |
661 | |||
662 | PhysicsActor actor = PhysActor; | 673 | PhysicsActor actor = PhysActor; |
663 | if (actor != null) | 674 | if (actor != null) |
664 | { | 675 | { |
@@ -678,25 +689,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
678 | 689 | ||
679 | // Tell the physics engines that this prim changed. | 690 | // Tell the physics engines that this prim changed. |
680 | m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); | 691 | m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); |
692 | |||
681 | } | 693 | } |
682 | catch (Exception e) | 694 | catch (Exception e) |
683 | { | 695 | { |
684 | m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message); | 696 | m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message); |
685 | } | 697 | } |
686 | } | 698 | } |
687 | |||
688 | // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too | ||
689 | if (m_sitTargetAvatar != UUID.Zero) | ||
690 | { | ||
691 | if (m_parentGroup != null) // TODO can there be a SOP without a SOG? | ||
692 | { | ||
693 | ScenePresence avatar; | ||
694 | if (m_parentGroup.Scene.TryGetScenePresence(m_sitTargetAvatar, out avatar)) | ||
695 | { | ||
696 | avatar.ParentPosition = GetWorldPosition(); | ||
697 | } | ||
698 | } | ||
699 | } | ||
700 | } | 699 | } |
701 | } | 700 | } |
702 | 701 | ||
@@ -705,7 +704,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
705 | get { return m_offsetPosition; } | 704 | get { return m_offsetPosition; } |
706 | set | 705 | set |
707 | { | 706 | { |
708 | StoreUndoState(); | 707 | Vector3 oldpos = m_offsetPosition; |
708 | StoreUndoState(UndoType.STATE_PRIM_POSITION); | ||
709 | m_offsetPosition = value; | 709 | m_offsetPosition = value; |
710 | 710 | ||
711 | if (ParentGroup != null && !ParentGroup.IsDeleted) | 711 | if (ParentGroup != null && !ParentGroup.IsDeleted) |
@@ -718,8 +718,23 @@ namespace OpenSim.Region.Framework.Scenes | |||
718 | 718 | ||
719 | // Tell the physics engines that this prim changed. | 719 | // Tell the physics engines that this prim changed. |
720 | m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); | 720 | m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); |
721 | } | ||
722 | |||
723 | if (!m_parentGroup.m_dupeInProgress) | ||
724 | { | ||
725 | List<ScenePresence> avs = ParentGroup.GetLinkedAvatars(); | ||
726 | foreach (ScenePresence av in avs) | ||
727 | { | ||
728 | if (av.LinkedPrim == m_uuid) | ||
729 | { | ||
730 | Vector3 offset = (m_offsetPosition - oldpos); | ||
731 | av.OffsetPosition += offset; | ||
732 | av.SendFullUpdateToAllClients(); | ||
733 | } | ||
734 | } | ||
721 | } | 735 | } |
722 | } | 736 | } |
737 | TriggerScriptChangedEvent(Changed.POSITION); | ||
723 | } | 738 | } |
724 | } | 739 | } |
725 | 740 | ||
@@ -761,7 +776,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
761 | 776 | ||
762 | set | 777 | set |
763 | { | 778 | { |
764 | StoreUndoState(); | 779 | StoreUndoState(UndoType.STATE_PRIM_ROTATION); |
765 | m_rotationOffset = value; | 780 | m_rotationOffset = value; |
766 | 781 | ||
767 | PhysicsActor actor = PhysActor; | 782 | PhysicsActor actor = PhysActor; |
@@ -845,7 +860,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
845 | /// <summary></summary> | 860 | /// <summary></summary> |
846 | public Vector3 Acceleration | 861 | public Vector3 Acceleration |
847 | { | 862 | { |
848 | get { return m_acceleration; } | 863 | get |
864 | { | ||
865 | PhysicsActor actor = PhysActor; | ||
866 | if (actor != null) | ||
867 | { | ||
868 | m_acceleration = actor.Acceleration; | ||
869 | } | ||
870 | return m_acceleration; | ||
871 | } | ||
872 | |||
849 | set { m_acceleration = value; } | 873 | set { m_acceleration = value; } |
850 | } | 874 | } |
851 | 875 | ||
@@ -950,7 +974,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
950 | get { return m_shape.Scale; } | 974 | get { return m_shape.Scale; } |
951 | set | 975 | set |
952 | { | 976 | { |
953 | StoreUndoState(); | 977 | StoreUndoState(UndoType.STATE_PRIM_SCALE); |
954 | if (m_shape != null) | 978 | if (m_shape != null) |
955 | { | 979 | { |
956 | m_shape.Scale = value; | 980 | m_shape.Scale = value; |
@@ -1016,7 +1040,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
1016 | if (IsAttachment) | 1040 | if (IsAttachment) |
1017 | return GroupPosition; | 1041 | return GroupPosition; |
1018 | 1042 | ||
1019 | return m_offsetPosition + m_groupPosition; } | 1043 | // return m_offsetPosition + m_groupPosition; } |
1044 | return m_groupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset) ; } //KF: Rotation was ignored! | ||
1020 | } | 1045 | } |
1021 | 1046 | ||
1022 | public SceneObjectGroup ParentGroup | 1047 | public SceneObjectGroup ParentGroup |
@@ -1171,6 +1196,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
1171 | get { return _flags; } | 1196 | get { return _flags; } |
1172 | set { _flags = value; } | 1197 | set { _flags = value; } |
1173 | } | 1198 | } |
1199 | |||
1200 | [XmlIgnore] | ||
1201 | public bool IsOccupied // KF If an av is sittingon this prim | ||
1202 | { | ||
1203 | get { return m_occupied; } | ||
1204 | set { m_occupied = value; } | ||
1205 | } | ||
1174 | 1206 | ||
1175 | [XmlIgnore] | 1207 | [XmlIgnore] |
1176 | public UUID SitTargetAvatar | 1208 | public UUID SitTargetAvatar |
@@ -1246,14 +1278,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
1246 | } | 1278 | } |
1247 | } | 1279 | } |
1248 | 1280 | ||
1249 | /// <summary> | ||
1250 | /// Clear all pending updates of parts to clients | ||
1251 | /// </summary> | ||
1252 | private void ClearUpdateSchedule() | ||
1253 | { | ||
1254 | m_updateFlag = 0; | ||
1255 | } | ||
1256 | |||
1257 | private void SendObjectPropertiesToClient(UUID AgentID) | 1281 | private void SendObjectPropertiesToClient(UUID AgentID) |
1258 | { | 1282 | { |
1259 | m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) | 1283 | m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) |
@@ -1504,14 +1528,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1504 | // or flexible | 1528 | // or flexible |
1505 | if (!isPhantom && !IsAttachment && !(Shape.PathCurve == (byte) Extrusion.Flexible)) | 1529 | if (!isPhantom && !IsAttachment && !(Shape.PathCurve == (byte) Extrusion.Flexible)) |
1506 | { | 1530 | { |
1507 | PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( | 1531 | try |
1508 | Name, | 1532 | { |
1509 | Shape, | 1533 | PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( |
1510 | AbsolutePosition, | 1534 | Name, |
1511 | Scale, | 1535 | Shape, |
1512 | RotationOffset, | 1536 | AbsolutePosition, |
1513 | RigidBody); | 1537 | Scale, |
1514 | 1538 | RotationOffset, | |
1539 | RigidBody); | ||
1540 | } | ||
1541 | catch | ||
1542 | { | ||
1543 | m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid); | ||
1544 | PhysActor = null; | ||
1545 | } | ||
1515 | // Basic Physics returns null.. joy joy joy. | 1546 | // Basic Physics returns null.. joy joy joy. |
1516 | if (PhysActor != null) | 1547 | if (PhysActor != null) |
1517 | { | 1548 | { |
@@ -1539,7 +1570,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1539 | { | 1570 | { |
1540 | m_redo.Clear(); | 1571 | m_redo.Clear(); |
1541 | } | 1572 | } |
1542 | StoreUndoState(); | 1573 | StoreUndoState(UndoType.STATE_ALL); |
1543 | } | 1574 | } |
1544 | 1575 | ||
1545 | public byte ConvertScriptUintToByte(uint indata) | 1576 | public byte ConvertScriptUintToByte(uint indata) |
@@ -1651,7 +1682,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1651 | PrimitiveBaseShape shape = PrimitiveBaseShape.Create(); | 1682 | PrimitiveBaseShape shape = PrimitiveBaseShape.Create(); |
1652 | part.Shape = shape; | 1683 | part.Shape = shape; |
1653 | 1684 | ||
1654 | part.Name = "Primitive"; | 1685 | part.Name = "Object"; |
1655 | part._ownerID = UUID.Random(); | 1686 | part._ownerID = UUID.Random(); |
1656 | 1687 | ||
1657 | return part; | 1688 | return part; |
@@ -1774,7 +1805,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1774 | // which stops client-side interpolation of deactivated joint proxy objects. | 1805 | // which stops client-side interpolation of deactivated joint proxy objects. |
1775 | } | 1806 | } |
1776 | 1807 | ||
1777 | if (!UsePhysics && !isNew) | 1808 | if (!UsePhysics) |
1778 | { | 1809 | { |
1779 | // reset velocity to 0 on physics switch-off. Without that, the client thinks the | 1810 | // reset velocity to 0 on physics switch-off. Without that, the client thinks the |
1780 | // prim still has velocity and continues to interpolate its position along the old | 1811 | // prim still has velocity and continues to interpolate its position along the old |
@@ -2009,12 +2040,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
2009 | public Vector3 GetWorldPosition() | 2040 | public Vector3 GetWorldPosition() |
2010 | { | 2041 | { |
2011 | Quaternion parentRot = ParentGroup.RootPart.RotationOffset; | 2042 | Quaternion parentRot = ParentGroup.RootPart.RotationOffset; |
2012 | |||
2013 | Vector3 axPos = OffsetPosition; | 2043 | Vector3 axPos = OffsetPosition; |
2014 | |||
2015 | axPos *= parentRot; | 2044 | axPos *= parentRot; |
2016 | Vector3 translationOffsetPosition = axPos; | 2045 | Vector3 translationOffsetPosition = axPos; |
2017 | return GroupPosition + translationOffsetPosition; | 2046 | if(_parentID == 0) |
2047 | { | ||
2048 | return GroupPosition; | ||
2049 | } | ||
2050 | else | ||
2051 | { | ||
2052 | return ParentGroup.AbsolutePosition + translationOffsetPosition; //KF: Fix child prim position | ||
2053 | } | ||
2018 | } | 2054 | } |
2019 | 2055 | ||
2020 | /// <summary> | 2056 | /// <summary> |
@@ -2025,7 +2061,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2025 | { | 2061 | { |
2026 | Quaternion newRot; | 2062 | Quaternion newRot; |
2027 | 2063 | ||
2028 | if (this.LinkNum == 0) | 2064 | if (this.LinkNum < 2) //KF Single or root prim |
2029 | { | 2065 | { |
2030 | newRot = RotationOffset; | 2066 | newRot = RotationOffset; |
2031 | } | 2067 | } |
@@ -2671,17 +2707,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
2671 | //Trys to fetch sound id from prim's inventory. | 2707 | //Trys to fetch sound id from prim's inventory. |
2672 | //Prim's inventory doesn't support non script items yet | 2708 | //Prim's inventory doesn't support non script items yet |
2673 | 2709 | ||
2674 | lock (TaskInventory) | 2710 | TaskInventory.LockItemsForRead(true); |
2711 | |||
2712 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) | ||
2675 | { | 2713 | { |
2676 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) | 2714 | if (item.Value.Name == sound) |
2677 | { | 2715 | { |
2678 | if (item.Value.Name == sound) | 2716 | soundID = item.Value.ItemID; |
2679 | { | 2717 | break; |
2680 | soundID = item.Value.ItemID; | ||
2681 | break; | ||
2682 | } | ||
2683 | } | 2718 | } |
2684 | } | 2719 | } |
2720 | |||
2721 | TaskInventory.LockItemsForRead(false); | ||
2685 | } | 2722 | } |
2686 | 2723 | ||
2687 | m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp) | 2724 | m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp) |
@@ -2741,7 +2778,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2741 | /// <param name="scale"></param> | 2778 | /// <param name="scale"></param> |
2742 | public void Resize(Vector3 scale) | 2779 | public void Resize(Vector3 scale) |
2743 | { | 2780 | { |
2744 | StoreUndoState(); | 2781 | StoreUndoState(UndoType.STATE_PRIM_SCALE); |
2745 | m_shape.Scale = scale; | 2782 | m_shape.Scale = scale; |
2746 | 2783 | ||
2747 | ParentGroup.HasGroupChanged = true; | 2784 | ParentGroup.HasGroupChanged = true; |
@@ -2750,38 +2787,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2750 | 2787 | ||
2751 | public void RotLookAt(Quaternion target, float strength, float damping) | 2788 | public void RotLookAt(Quaternion target, float strength, float damping) |
2752 | { | 2789 | { |
2753 | rotLookAt(target, strength, damping); | 2790 | m_parentGroup.rotLookAt(target, strength, damping); // This calls method in SceneObjectGroup. |
2754 | } | ||
2755 | |||
2756 | public void rotLookAt(Quaternion target, float strength, float damping) | ||
2757 | { | ||
2758 | if (IsAttachment) | ||
2759 | { | ||
2760 | /* | ||
2761 | ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar); | ||
2762 | if (avatar != null) | ||
2763 | { | ||
2764 | Rotate the Av? | ||
2765 | } */ | ||
2766 | } | ||
2767 | else | ||
2768 | { | ||
2769 | APIDDamp = damping; | ||
2770 | APIDStrength = strength; | ||
2771 | APIDTarget = target; | ||
2772 | } | ||
2773 | } | ||
2774 | |||
2775 | public void startLookAt(Quaternion rot, float damp, float strength) | ||
2776 | { | ||
2777 | APIDDamp = damp; | ||
2778 | APIDStrength = strength; | ||
2779 | APIDTarget = rot; | ||
2780 | } | ||
2781 | |||
2782 | public void stopLookAt() | ||
2783 | { | ||
2784 | APIDTarget = Quaternion.Identity; | ||
2785 | } | 2791 | } |
2786 | 2792 | ||
2787 | /// <summary> | 2793 | /// <summary> |
@@ -2793,7 +2799,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
2793 | 2799 | ||
2794 | if (m_parentGroup != null) | 2800 | if (m_parentGroup != null) |
2795 | { | 2801 | { |
2796 | m_parentGroup.QueueForUpdateCheck(); | 2802 | if (!m_parentGroup.areUpdatesSuspended) |
2803 | { | ||
2804 | m_parentGroup.QueueForUpdateCheck(); | ||
2805 | } | ||
2797 | } | 2806 | } |
2798 | 2807 | ||
2799 | int timeNow = Util.UnixTimeSinceEpoch(); | 2808 | int timeNow = Util.UnixTimeSinceEpoch(); |
@@ -3010,8 +3019,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3010 | { | 3019 | { |
3011 | const float ROTATION_TOLERANCE = 0.01f; | 3020 | const float ROTATION_TOLERANCE = 0.01f; |
3012 | const float VELOCITY_TOLERANCE = 0.001f; | 3021 | const float VELOCITY_TOLERANCE = 0.001f; |
3013 | const float POSITION_TOLERANCE = 0.05f; | 3022 | const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary |
3014 | const int TIME_MS_TOLERANCE = 3000; | 3023 | const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds. |
3015 | 3024 | ||
3016 | if (m_updateFlag == 1) | 3025 | if (m_updateFlag == 1) |
3017 | { | 3026 | { |
@@ -3025,7 +3034,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3025 | Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) | 3034 | Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) |
3026 | { | 3035 | { |
3027 | AddTerseUpdateToAllAvatars(); | 3036 | AddTerseUpdateToAllAvatars(); |
3028 | ClearUpdateSchedule(); | 3037 | |
3029 | 3038 | ||
3030 | // This causes the Scene to 'poll' physical objects every couple of frames | 3039 | // This causes the Scene to 'poll' physical objects every couple of frames |
3031 | // bad, so it's been replaced by an event driven method. | 3040 | // bad, so it's been replaced by an event driven method. |
@@ -3043,16 +3052,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
3043 | m_lastAngularVelocity = AngularVelocity; | 3052 | m_lastAngularVelocity = AngularVelocity; |
3044 | m_lastTerseSent = Environment.TickCount; | 3053 | m_lastTerseSent = Environment.TickCount; |
3045 | } | 3054 | } |
3055 | //Moved this outside of the if clause so updates don't get blocked.. *sigh* | ||
3056 | m_updateFlag = 0; //Why were we calling a function to do this? Inefficient! *screams* | ||
3046 | } | 3057 | } |
3047 | else | 3058 | else |
3048 | { | 3059 | { |
3049 | if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes | 3060 | if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes |
3050 | { | 3061 | { |
3051 | AddFullUpdateToAllAvatars(); | 3062 | AddFullUpdateToAllAvatars(); |
3052 | ClearUpdateSchedule(); | 3063 | m_updateFlag = 0; //Same here |
3053 | } | 3064 | } |
3054 | } | 3065 | } |
3055 | ClearUpdateSchedule(); | 3066 | m_updateFlag = 0; |
3056 | } | 3067 | } |
3057 | 3068 | ||
3058 | /// <summary> | 3069 | /// <summary> |
@@ -3072,6 +3083,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
3072 | UUID ownerID = _ownerID; | 3083 | UUID ownerID = _ownerID; |
3073 | UUID objectID = UUID; | 3084 | UUID objectID = UUID; |
3074 | UUID parentID = GetRootPartUUID(); | 3085 | UUID parentID = GetRootPartUUID(); |
3086 | |||
3087 | if (ParentGroup.IsAttachment && ParentGroup.RootPart.Shape.State > 30) | ||
3088 | { | ||
3089 | // Use the avatar as the parent for HUDs, since the prims | ||
3090 | // are not sent to other avatars | ||
3091 | objectID = _ownerID; | ||
3092 | parentID = _ownerID; | ||
3093 | } | ||
3094 | |||
3075 | UUID soundID = UUID.Zero; | 3095 | UUID soundID = UUID.Zero; |
3076 | Vector3 position = AbsolutePosition; // region local | 3096 | Vector3 position = AbsolutePosition; // region local |
3077 | ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle; | 3097 | ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle; |
@@ -3079,17 +3099,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
3079 | if (!UUID.TryParse(sound, out soundID)) | 3099 | if (!UUID.TryParse(sound, out soundID)) |
3080 | { | 3100 | { |
3081 | // search sound file from inventory | 3101 | // search sound file from inventory |
3082 | lock (TaskInventory) | 3102 | TaskInventory.LockItemsForRead(true); |
3103 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) | ||
3083 | { | 3104 | { |
3084 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) | 3105 | if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) |
3085 | { | 3106 | { |
3086 | if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) | 3107 | soundID = item.Value.ItemID; |
3087 | { | 3108 | break; |
3088 | soundID = item.Value.ItemID; | ||
3089 | break; | ||
3090 | } | ||
3091 | } | 3109 | } |
3092 | } | 3110 | } |
3111 | TaskInventory.LockItemsForRead(false); | ||
3093 | } | 3112 | } |
3094 | 3113 | ||
3095 | if (soundID == UUID.Zero) | 3114 | if (soundID == UUID.Zero) |
@@ -3524,7 +3543,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3524 | 3543 | ||
3525 | public void StopLookAt() | 3544 | public void StopLookAt() |
3526 | { | 3545 | { |
3527 | m_parentGroup.stopLookAt(); | 3546 | m_parentGroup.stopLookAt(); // This calls method in SceneObjectGroup. |
3528 | 3547 | ||
3529 | m_parentGroup.ScheduleGroupForTerseUpdate(); | 3548 | m_parentGroup.ScheduleGroupForTerseUpdate(); |
3530 | } | 3549 | } |
@@ -3551,10 +3570,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
3551 | m_parentGroup.ScheduleGroupForTerseUpdate(); | 3570 | m_parentGroup.ScheduleGroupForTerseUpdate(); |
3552 | //m_parentGroup.ScheduleGroupForFullUpdate(); | 3571 | //m_parentGroup.ScheduleGroupForFullUpdate(); |
3553 | } | 3572 | } |
3554 | 3573 | public void StoreUndoState(UndoType type) | |
3555 | public void StoreUndoState() | ||
3556 | { | 3574 | { |
3557 | if (!Undoing) | 3575 | if (!Undoing && (m_parentGroup == null || m_parentGroup.RootPart == null || !m_parentGroup.RootPart.Undoing)) |
3558 | { | 3576 | { |
3559 | if (!IgnoreUndoUpdate) | 3577 | if (!IgnoreUndoUpdate) |
3560 | { | 3578 | { |
@@ -3565,17 +3583,25 @@ namespace OpenSim.Region.Framework.Scenes | |||
3565 | if (m_undo.Count > 0) | 3583 | if (m_undo.Count > 0) |
3566 | { | 3584 | { |
3567 | UndoState last = m_undo.Peek(); | 3585 | UndoState last = m_undo.Peek(); |
3568 | if (last != null) | 3586 | |
3569 | { | ||
3570 | if (last.Compare(this)) | ||
3571 | return; | ||
3572 | } | ||
3573 | } | 3587 | } |
3574 | 3588 | ||
3575 | if (m_parentGroup.GetSceneMaxUndo() > 0) | 3589 | if (m_parentGroup.GetSceneMaxUndo() > 0) |
3576 | { | 3590 | { |
3577 | UndoState nUndo = new UndoState(this); | 3591 | UndoState lastUndo = m_undo.Peek(); |
3592 | |||
3593 | UndoState nUndo = new UndoState(this, type); | ||
3578 | 3594 | ||
3595 | if (lastUndo != null) | ||
3596 | { | ||
3597 | TimeSpan ts = DateTime.Now.Subtract(lastUndo.LastUpdated); | ||
3598 | if (ts.TotalMilliseconds < 500) | ||
3599 | { | ||
3600 | //Delete the last entry since it was less than 500 milliseconds ago | ||
3601 | nUndo.Merge(lastUndo); | ||
3602 | m_undo.Pop(); | ||
3603 | } | ||
3604 | } | ||
3579 | m_undo.Push(nUndo); | 3605 | m_undo.Push(nUndo); |
3580 | } | 3606 | } |
3581 | 3607 | ||
@@ -4052,11 +4078,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
4052 | if (m_undo.Count > 0) | 4078 | if (m_undo.Count > 0) |
4053 | { | 4079 | { |
4054 | UndoState nUndo = null; | 4080 | UndoState nUndo = null; |
4081 | UndoState goback = m_undo.Pop(); | ||
4055 | if (m_parentGroup.GetSceneMaxUndo() > 0) | 4082 | if (m_parentGroup.GetSceneMaxUndo() > 0) |
4056 | { | 4083 | { |
4057 | nUndo = new UndoState(this); | 4084 | nUndo = new UndoState(this, goback.Type); |
4058 | } | 4085 | } |
4059 | UndoState goback = m_undo.Pop(); | 4086 | |
4087 | |||
4060 | if (goback != null) | 4088 | if (goback != null) |
4061 | { | 4089 | { |
4062 | goback.PlaybackState(this); | 4090 | goback.PlaybackState(this); |
@@ -4071,13 +4099,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
4071 | { | 4099 | { |
4072 | lock (m_redo) | 4100 | lock (m_redo) |
4073 | { | 4101 | { |
4102 | UndoState gofwd = m_redo.Pop(); | ||
4074 | if (m_parentGroup.GetSceneMaxUndo() > 0) | 4103 | if (m_parentGroup.GetSceneMaxUndo() > 0) |
4075 | { | 4104 | { |
4076 | UndoState nUndo = new UndoState(this); | 4105 | UndoState nUndo = new UndoState(this, gofwd.Type); |
4077 | 4106 | ||
4078 | m_undo.Push(nUndo); | 4107 | m_undo.Push(nUndo); |
4079 | } | 4108 | } |
4080 | UndoState gofwd = m_redo.Pop(); | ||
4081 | if (gofwd != null) | 4109 | if (gofwd != null) |
4082 | gofwd.PlayfwdState(this); | 4110 | gofwd.PlayfwdState(this); |
4083 | } | 4111 | } |
@@ -4525,8 +4553,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
4525 | { | 4553 | { |
4526 | m_shape.TextureEntry = textureEntry; | 4554 | m_shape.TextureEntry = textureEntry; |
4527 | TriggerScriptChangedEvent(Changed.TEXTURE); | 4555 | TriggerScriptChangedEvent(Changed.TEXTURE); |
4528 | 4556 | m_updateFlag = 1; | |
4529 | ParentGroup.HasGroupChanged = true; | 4557 | ParentGroup.HasGroupChanged = true; |
4558 | |||
4530 | //This is madness.. | 4559 | //This is madness.. |
4531 | //ParentGroup.ScheduleGroupForFullUpdate(); | 4560 | //ParentGroup.ScheduleGroupForFullUpdate(); |
4532 | //This is sparta | 4561 | //This is sparta |
@@ -4771,5 +4800,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
4771 | Color color = Color; | 4800 | Color color = Color; |
4772 | return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); | 4801 | return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); |
4773 | } | 4802 | } |
4803 | |||
4804 | public void ResetOwnerChangeFlag() | ||
4805 | { | ||
4806 | List<UUID> inv = Inventory.GetInventoryList(); | ||
4807 | |||
4808 | foreach (UUID itemID in inv) | ||
4809 | { | ||
4810 | TaskInventoryItem item = Inventory.GetInventoryItem(itemID); | ||
4811 | item.OwnerChanged = false; | ||
4812 | Inventory.UpdateInventoryItem(item); | ||
4813 | } | ||
4814 | } | ||
4774 | } | 4815 | } |
4775 | } | 4816 | } |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 4ae53a2..8b4f0ed 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | |||
@@ -46,6 +46,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
46 | 46 | ||
47 | private string m_inventoryFileName = String.Empty; | 47 | private string m_inventoryFileName = String.Empty; |
48 | private int m_inventoryFileNameSerial = 0; | 48 | private int m_inventoryFileNameSerial = 0; |
49 | |||
50 | private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>(); | ||
49 | 51 | ||
50 | /// <value> | 52 | /// <value> |
51 | /// The part to which the inventory belongs. | 53 | /// The part to which the inventory belongs. |
@@ -82,7 +84,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
82 | /// </value> | 84 | /// </value> |
83 | protected internal TaskInventoryDictionary Items | 85 | protected internal TaskInventoryDictionary Items |
84 | { | 86 | { |
85 | get { return m_items; } | 87 | get { |
88 | return m_items; | ||
89 | } | ||
86 | set | 90 | set |
87 | { | 91 | { |
88 | m_items = value; | 92 | m_items = value; |
@@ -118,22 +122,25 @@ namespace OpenSim.Region.Framework.Scenes | |||
118 | /// <param name="linkNum">Link number for the part</param> | 122 | /// <param name="linkNum">Link number for the part</param> |
119 | public void ResetInventoryIDs() | 123 | public void ResetInventoryIDs() |
120 | { | 124 | { |
121 | lock (m_items) | 125 | m_items.LockItemsForWrite(true); |
126 | |||
127 | if (0 == Items.Count) | ||
122 | { | 128 | { |
123 | if (0 == m_items.Count) | 129 | m_items.LockItemsForWrite(false); |
124 | return; | 130 | return; |
131 | } | ||
125 | 132 | ||
126 | HasInventoryChanged = true; | 133 | HasInventoryChanged = true; |
127 | m_part.ParentGroup.HasGroupChanged = true; | 134 | m_part.ParentGroup.HasGroupChanged = true; |
128 | IList<TaskInventoryItem> items = GetInventoryItems(); | 135 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); |
129 | m_items.Clear(); | 136 | Items.Clear(); |
130 | 137 | ||
131 | foreach (TaskInventoryItem item in items) | 138 | foreach (TaskInventoryItem item in items) |
132 | { | 139 | { |
133 | item.ResetIDs(m_part.UUID); | 140 | item.ResetIDs(m_part.UUID); |
134 | m_items.Add(item.ItemID, item); | 141 | Items.Add(item.ItemID, item); |
135 | } | ||
136 | } | 142 | } |
143 | m_items.LockItemsForWrite(false); | ||
137 | } | 144 | } |
138 | 145 | ||
139 | /// <summary> | 146 | /// <summary> |
@@ -142,12 +149,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
142 | /// <param name="ownerId"></param> | 149 | /// <param name="ownerId"></param> |
143 | public void ChangeInventoryOwner(UUID ownerId) | 150 | public void ChangeInventoryOwner(UUID ownerId) |
144 | { | 151 | { |
145 | lock (Items) | 152 | m_items.LockItemsForWrite(true); |
153 | if (0 == Items.Count) | ||
146 | { | 154 | { |
147 | if (0 == Items.Count) | 155 | m_items.LockItemsForWrite(false); |
148 | { | 156 | return; |
149 | return; | ||
150 | } | ||
151 | } | 157 | } |
152 | 158 | ||
153 | HasInventoryChanged = true; | 159 | HasInventoryChanged = true; |
@@ -161,6 +167,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
161 | item.OwnerID = ownerId; | 167 | item.OwnerID = ownerId; |
162 | } | 168 | } |
163 | } | 169 | } |
170 | m_items.LockItemsForWrite(false); | ||
164 | } | 171 | } |
165 | 172 | ||
166 | /// <summary> | 173 | /// <summary> |
@@ -169,22 +176,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
169 | /// <param name="groupID"></param> | 176 | /// <param name="groupID"></param> |
170 | public void ChangeInventoryGroup(UUID groupID) | 177 | public void ChangeInventoryGroup(UUID groupID) |
171 | { | 178 | { |
172 | lock (Items) | 179 | m_items.LockItemsForWrite(true); |
180 | if (0 == Items.Count) | ||
173 | { | 181 | { |
174 | if (0 == Items.Count) | 182 | m_items.LockItemsForWrite(false); |
175 | { | 183 | return; |
176 | return; | ||
177 | } | ||
178 | } | 184 | } |
179 | 185 | ||
180 | HasInventoryChanged = true; | 186 | HasInventoryChanged = true; |
181 | m_part.ParentGroup.HasGroupChanged = true; | 187 | m_part.ParentGroup.HasGroupChanged = true; |
182 | List<TaskInventoryItem> items = GetInventoryItems(); | 188 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); |
183 | foreach (TaskInventoryItem item in items) | 189 | foreach (TaskInventoryItem item in items) |
184 | { | 190 | { |
185 | if (groupID != item.GroupID) | 191 | if (groupID != item.GroupID) |
192 | { | ||
186 | item.GroupID = groupID; | 193 | item.GroupID = groupID; |
194 | } | ||
187 | } | 195 | } |
196 | m_items.LockItemsForWrite(false); | ||
188 | } | 197 | } |
189 | 198 | ||
190 | /// <summary> | 199 | /// <summary> |
@@ -192,9 +201,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
192 | /// </summary> | 201 | /// </summary> |
193 | public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) | 202 | public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) |
194 | { | 203 | { |
195 | List<TaskInventoryItem> scripts = GetInventoryScripts(); | 204 | Items.LockItemsForRead(true); |
196 | foreach (TaskInventoryItem item in scripts) | 205 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); |
197 | CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); | 206 | Items.LockItemsForRead(false); |
207 | foreach (TaskInventoryItem item in items) | ||
208 | { | ||
209 | if ((int)InventoryType.LSL == item.InvType) | ||
210 | CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); | ||
211 | } | ||
198 | } | 212 | } |
199 | 213 | ||
200 | public ArrayList GetScriptErrors(UUID itemID) | 214 | public ArrayList GetScriptErrors(UUID itemID) |
@@ -227,9 +241,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
227 | /// </param> | 241 | /// </param> |
228 | public void RemoveScriptInstances(bool sceneObjectBeingDeleted) | 242 | public void RemoveScriptInstances(bool sceneObjectBeingDeleted) |
229 | { | 243 | { |
230 | List<TaskInventoryItem> scripts = GetInventoryScripts(); | 244 | Items.LockItemsForRead(true); |
231 | foreach (TaskInventoryItem item in scripts) | 245 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); |
232 | RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); | 246 | Items.LockItemsForRead(false); |
247 | |||
248 | foreach (TaskInventoryItem item in items) | ||
249 | { | ||
250 | if ((int)InventoryType.LSL == item.InvType) | ||
251 | { | ||
252 | RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); | ||
253 | m_part.RemoveScriptEvents(item.ItemID); | ||
254 | } | ||
255 | } | ||
233 | } | 256 | } |
234 | 257 | ||
235 | /// <summary> | 258 | /// <summary> |
@@ -245,7 +268,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
245 | // item.Name, item.ItemID, Name, UUID); | 268 | // item.Name, item.ItemID, Name, UUID); |
246 | 269 | ||
247 | if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) | 270 | if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) |
271 | { | ||
272 | StoreScriptError(item.ItemID, "no permission"); | ||
248 | return; | 273 | return; |
274 | } | ||
249 | 275 | ||
250 | m_part.AddFlag(PrimFlags.Scripted); | 276 | m_part.AddFlag(PrimFlags.Scripted); |
251 | 277 | ||
@@ -254,14 +280,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
254 | if (stateSource == 1 && // Prim crossing | 280 | if (stateSource == 1 && // Prim crossing |
255 | m_part.ParentGroup.Scene.m_trustBinaries) | 281 | m_part.ParentGroup.Scene.m_trustBinaries) |
256 | { | 282 | { |
257 | lock (m_items) | 283 | m_items.LockItemsForWrite(true); |
258 | { | 284 | m_items[item.ItemID].PermsMask = 0; |
259 | m_items[item.ItemID].PermsMask = 0; | 285 | m_items[item.ItemID].PermsGranter = UUID.Zero; |
260 | m_items[item.ItemID].PermsGranter = UUID.Zero; | 286 | m_items.LockItemsForWrite(false); |
261 | } | ||
262 | |||
263 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( | 287 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( |
264 | m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); | 288 | m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); |
289 | StoreScriptErrors(item.ItemID, null); | ||
265 | m_part.ParentGroup.AddActiveScriptCount(1); | 290 | m_part.ParentGroup.AddActiveScriptCount(1); |
266 | m_part.ScheduleFullUpdate(); | 291 | m_part.ScheduleFullUpdate(); |
267 | return; | 292 | return; |
@@ -270,6 +295,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
270 | AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); | 295 | AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); |
271 | if (null == asset) | 296 | if (null == asset) |
272 | { | 297 | { |
298 | string msg = String.Format("asset ID {0} could not be found", item.AssetID); | ||
299 | StoreScriptError(item.ItemID, msg); | ||
273 | m_log.ErrorFormat( | 300 | m_log.ErrorFormat( |
274 | "[PRIM INVENTORY]: " + | 301 | "[PRIM INVENTORY]: " + |
275 | "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", | 302 | "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", |
@@ -281,15 +308,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
281 | if (m_part.ParentGroup.m_savedScriptState != null) | 308 | if (m_part.ParentGroup.m_savedScriptState != null) |
282 | RestoreSavedScriptState(item.OldItemID, item.ItemID); | 309 | RestoreSavedScriptState(item.OldItemID, item.ItemID); |
283 | 310 | ||
284 | lock (m_items) | 311 | m_items.LockItemsForWrite(true); |
285 | { | 312 | |
286 | m_items[item.ItemID].PermsMask = 0; | 313 | m_items[item.ItemID].PermsMask = 0; |
287 | m_items[item.ItemID].PermsGranter = UUID.Zero; | 314 | m_items[item.ItemID].PermsGranter = UUID.Zero; |
288 | } | 315 | |
316 | m_items.LockItemsForWrite(false); | ||
289 | 317 | ||
290 | string script = Utils.BytesToString(asset.Data); | 318 | string script = Utils.BytesToString(asset.Data); |
291 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( | 319 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( |
292 | m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); | 320 | m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); |
321 | StoreScriptErrors(item.ItemID, null); | ||
293 | m_part.ParentGroup.AddActiveScriptCount(1); | 322 | m_part.ParentGroup.AddActiveScriptCount(1); |
294 | m_part.ScheduleFullUpdate(); | 323 | m_part.ScheduleFullUpdate(); |
295 | } | 324 | } |
@@ -353,21 +382,145 @@ namespace OpenSim.Region.Framework.Scenes | |||
353 | 382 | ||
354 | /// <summary> | 383 | /// <summary> |
355 | /// Start a script which is in this prim's inventory. | 384 | /// Start a script which is in this prim's inventory. |
385 | /// Some processing may occur in the background, but this routine returns asap. | ||
356 | /// </summary> | 386 | /// </summary> |
357 | /// <param name="itemId"> | 387 | /// <param name="itemId"> |
358 | /// A <see cref="UUID"/> | 388 | /// A <see cref="UUID"/> |
359 | /// </param> | 389 | /// </param> |
360 | public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | 390 | public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) |
361 | { | 391 | { |
362 | TaskInventoryItem item = GetInventoryItem(itemId); | 392 | lock (m_scriptErrors) |
363 | if (item != null) | 393 | { |
364 | CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); | 394 | // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion |
395 | m_scriptErrors.Remove(itemId); | ||
396 | } | ||
397 | CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); | ||
398 | } | ||
399 | |||
400 | private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | ||
401 | { | ||
402 | m_items.LockItemsForRead(true); | ||
403 | if (m_items.ContainsKey(itemId)) | ||
404 | { | ||
405 | if (m_items.ContainsKey(itemId)) | ||
406 | { | ||
407 | m_items.LockItemsForRead(false); | ||
408 | CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); | ||
409 | } | ||
410 | else | ||
411 | { | ||
412 | m_items.LockItemsForRead(false); | ||
413 | string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID, | ||
414 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | ||
415 | StoreScriptError(itemId, msg); | ||
416 | m_log.ErrorFormat( | ||
417 | "[PRIM INVENTORY]: " + | ||
418 | "Couldn't start script with ID {0} since it {1}", itemId, msg); | ||
419 | } | ||
420 | } | ||
365 | else | 421 | else |
422 | { | ||
423 | m_items.LockItemsForRead(false); | ||
424 | string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID); | ||
425 | StoreScriptError(itemId, msg); | ||
366 | m_log.ErrorFormat( | 426 | m_log.ErrorFormat( |
367 | "[PRIM INVENTORY]: " + | 427 | "[PRIM INVENTORY]: " + |
368 | "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", | 428 | "Couldn't start script with ID {0} since it {1}", itemId, msg); |
369 | itemId, m_part.Name, m_part.UUID, | 429 | } |
370 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 430 | |
431 | } | ||
432 | |||
433 | /// <summary> | ||
434 | /// Start a script which is in this prim's inventory and return any compilation error messages. | ||
435 | /// </summary> | ||
436 | /// <param name="itemId"> | ||
437 | /// A <see cref="UUID"/> | ||
438 | /// </param> | ||
439 | public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | ||
440 | { | ||
441 | ArrayList errors; | ||
442 | |||
443 | // Indicate to CreateScriptInstanceInternal() we want it to | ||
444 | // post any compilation/loading error messages | ||
445 | lock (m_scriptErrors) | ||
446 | { | ||
447 | m_scriptErrors[itemId] = null; | ||
448 | } | ||
449 | |||
450 | // Perform compilation/loading | ||
451 | CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); | ||
452 | |||
453 | // Wait for and retrieve any errors | ||
454 | lock (m_scriptErrors) | ||
455 | { | ||
456 | while ((errors = m_scriptErrors[itemId]) == null) | ||
457 | { | ||
458 | if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000)) | ||
459 | { | ||
460 | m_log.ErrorFormat( | ||
461 | "[PRIM INVENTORY]: " + | ||
462 | "timedout waiting for script {0} errors", itemId); | ||
463 | errors = m_scriptErrors[itemId]; | ||
464 | if (errors == null) | ||
465 | { | ||
466 | errors = new ArrayList(1); | ||
467 | errors.Add("timedout waiting for errors"); | ||
468 | } | ||
469 | break; | ||
470 | } | ||
471 | } | ||
472 | m_scriptErrors.Remove(itemId); | ||
473 | } | ||
474 | return errors; | ||
475 | } | ||
476 | |||
477 | // Signal to CreateScriptInstanceEr() that compilation/loading is complete | ||
478 | private void StoreScriptErrors(UUID itemId, ArrayList errors) | ||
479 | { | ||
480 | lock (m_scriptErrors) | ||
481 | { | ||
482 | // If compilation/loading initiated via CreateScriptInstance(), | ||
483 | // it does not want the errors, so just get out | ||
484 | if (!m_scriptErrors.ContainsKey(itemId)) | ||
485 | { | ||
486 | return; | ||
487 | } | ||
488 | |||
489 | // Initiated via CreateScriptInstanceEr(), if we know what the | ||
490 | // errors are, save them and wake CreateScriptInstanceEr(). | ||
491 | if (errors != null) | ||
492 | { | ||
493 | m_scriptErrors[itemId] = errors; | ||
494 | System.Threading.Monitor.PulseAll(m_scriptErrors); | ||
495 | return; | ||
496 | } | ||
497 | } | ||
498 | |||
499 | // Initiated via CreateScriptInstanceEr() but we don't know what | ||
500 | // the errors are yet, so retrieve them from the script engine. | ||
501 | // This may involve some waiting internal to GetScriptErrors(). | ||
502 | errors = GetScriptErrors(itemId); | ||
503 | |||
504 | // Get a default non-null value to indicate success. | ||
505 | if (errors == null) | ||
506 | { | ||
507 | errors = new ArrayList(); | ||
508 | } | ||
509 | |||
510 | // Post to CreateScriptInstanceEr() and wake it up | ||
511 | lock (m_scriptErrors) | ||
512 | { | ||
513 | m_scriptErrors[itemId] = errors; | ||
514 | System.Threading.Monitor.PulseAll(m_scriptErrors); | ||
515 | } | ||
516 | } | ||
517 | |||
518 | // Like StoreScriptErrors(), but just posts a single string message | ||
519 | private void StoreScriptError(UUID itemId, string message) | ||
520 | { | ||
521 | ArrayList errors = new ArrayList(1); | ||
522 | errors.Add(message); | ||
523 | StoreScriptErrors(itemId, errors); | ||
371 | } | 524 | } |
372 | 525 | ||
373 | /// <summary> | 526 | /// <summary> |
@@ -380,15 +533,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
380 | /// </param> | 533 | /// </param> |
381 | public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) | 534 | public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) |
382 | { | 535 | { |
383 | bool scriptPresent = false; | 536 | if (m_items.ContainsKey(itemId)) |
384 | |||
385 | lock (m_items) | ||
386 | { | ||
387 | if (m_items.ContainsKey(itemId)) | ||
388 | scriptPresent = true; | ||
389 | } | ||
390 | |||
391 | if (scriptPresent) | ||
392 | { | 537 | { |
393 | if (!sceneObjectBeingDeleted) | 538 | if (!sceneObjectBeingDeleted) |
394 | m_part.RemoveScriptEvents(itemId); | 539 | m_part.RemoveScriptEvents(itemId); |
@@ -413,14 +558,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
413 | /// <returns></returns> | 558 | /// <returns></returns> |
414 | private bool InventoryContainsName(string name) | 559 | private bool InventoryContainsName(string name) |
415 | { | 560 | { |
416 | lock (m_items) | 561 | m_items.LockItemsForRead(true); |
562 | foreach (TaskInventoryItem item in m_items.Values) | ||
417 | { | 563 | { |
418 | foreach (TaskInventoryItem item in m_items.Values) | 564 | if (item.Name == name) |
419 | { | 565 | { |
420 | if (item.Name == name) | 566 | m_items.LockItemsForRead(false); |
421 | return true; | 567 | return true; |
422 | } | 568 | } |
423 | } | 569 | } |
570 | m_items.LockItemsForRead(false); | ||
424 | return false; | 571 | return false; |
425 | } | 572 | } |
426 | 573 | ||
@@ -462,8 +609,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
462 | /// <param name="item"></param> | 609 | /// <param name="item"></param> |
463 | public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) | 610 | public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) |
464 | { | 611 | { |
465 | List<TaskInventoryItem> il = GetInventoryItems(); | 612 | m_items.LockItemsForRead(true); |
466 | 613 | List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values); | |
614 | m_items.LockItemsForRead(false); | ||
467 | foreach (TaskInventoryItem i in il) | 615 | foreach (TaskInventoryItem i in il) |
468 | { | 616 | { |
469 | if (i.Name == item.Name) | 617 | if (i.Name == item.Name) |
@@ -501,14 +649,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
501 | item.Name = name; | 649 | item.Name = name; |
502 | item.GroupID = m_part.GroupID; | 650 | item.GroupID = m_part.GroupID; |
503 | 651 | ||
504 | lock (m_items) | 652 | m_items.LockItemsForWrite(true); |
505 | m_items.Add(item.ItemID, item); | 653 | m_items.Add(item.ItemID, item); |
506 | 654 | m_items.LockItemsForWrite(false); | |
507 | if (allowedDrop) | 655 | if (allowedDrop) |
508 | m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); | 656 | m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); |
509 | else | 657 | else |
510 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 658 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
511 | 659 | ||
512 | m_inventorySerial++; | 660 | m_inventorySerial++; |
513 | //m_inventorySerial += 2; | 661 | //m_inventorySerial += 2; |
514 | HasInventoryChanged = true; | 662 | HasInventoryChanged = true; |
@@ -524,15 +672,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
524 | /// <param name="items"></param> | 672 | /// <param name="items"></param> |
525 | public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) | 673 | public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) |
526 | { | 674 | { |
527 | lock (m_items) | 675 | m_items.LockItemsForWrite(true); |
676 | foreach (TaskInventoryItem item in items) | ||
528 | { | 677 | { |
529 | foreach (TaskInventoryItem item in items) | 678 | m_items.Add(item.ItemID, item); |
530 | { | 679 | // m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
531 | m_items.Add(item.ItemID, item); | ||
532 | // m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | ||
533 | } | ||
534 | m_inventorySerial++; | ||
535 | } | 680 | } |
681 | m_items.LockItemsForWrite(false); | ||
682 | |||
683 | m_inventorySerial++; | ||
536 | } | 684 | } |
537 | 685 | ||
538 | /// <summary> | 686 | /// <summary> |
@@ -543,10 +691,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
543 | public TaskInventoryItem GetInventoryItem(UUID itemId) | 691 | public TaskInventoryItem GetInventoryItem(UUID itemId) |
544 | { | 692 | { |
545 | TaskInventoryItem item; | 693 | TaskInventoryItem item; |
546 | 694 | m_items.LockItemsForRead(true); | |
547 | lock (m_items) | 695 | m_items.TryGetValue(itemId, out item); |
548 | m_items.TryGetValue(itemId, out item); | 696 | m_items.LockItemsForRead(false); |
549 | |||
550 | return item; | 697 | return item; |
551 | } | 698 | } |
552 | 699 | ||
@@ -562,15 +709,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
562 | { | 709 | { |
563 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(); | 710 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(); |
564 | 711 | ||
565 | lock (m_items) | 712 | m_items.LockItemsForRead(true); |
713 | |||
714 | foreach (TaskInventoryItem item in m_items.Values) | ||
566 | { | 715 | { |
567 | foreach (TaskInventoryItem item in m_items.Values) | 716 | if (item.Name == name) |
568 | { | 717 | items.Add(item); |
569 | if (item.Name == name) | ||
570 | items.Add(item); | ||
571 | } | ||
572 | } | 718 | } |
573 | 719 | ||
720 | m_items.LockItemsForRead(false); | ||
721 | |||
574 | return items; | 722 | return items; |
575 | } | 723 | } |
576 | 724 | ||
@@ -587,8 +735,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
587 | 735 | ||
588 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents) | 736 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents) |
589 | { | 737 | { |
590 | TaskInventoryItem it = GetInventoryItem(item.ItemID); | 738 | m_items.LockItemsForWrite(true); |
591 | if (it != null) | 739 | |
740 | if (m_items.ContainsKey(item.ItemID)) | ||
592 | { | 741 | { |
593 | item.ParentID = m_part.UUID; | 742 | item.ParentID = m_part.UUID; |
594 | item.ParentPartID = m_part.UUID; | 743 | item.ParentPartID = m_part.UUID; |
@@ -600,19 +749,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
600 | item.GroupID = m_part.GroupID; | 749 | item.GroupID = m_part.GroupID; |
601 | 750 | ||
602 | if (item.AssetID == UUID.Zero) | 751 | if (item.AssetID == UUID.Zero) |
603 | item.AssetID = it.AssetID; | 752 | item.AssetID = m_items[item.ItemID].AssetID; |
604 | |||
605 | lock (m_items) | ||
606 | { | ||
607 | m_items[item.ItemID] = item; | ||
608 | m_inventorySerial++; | ||
609 | } | ||
610 | 753 | ||
754 | m_items[item.ItemID] = item; | ||
755 | m_inventorySerial++; | ||
611 | if (fireScriptEvents) | 756 | if (fireScriptEvents) |
612 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 757 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
613 | |||
614 | HasInventoryChanged = true; | 758 | HasInventoryChanged = true; |
615 | m_part.ParentGroup.HasGroupChanged = true; | 759 | m_part.ParentGroup.HasGroupChanged = true; |
760 | m_items.LockItemsForWrite(false); | ||
616 | return true; | 761 | return true; |
617 | } | 762 | } |
618 | else | 763 | else |
@@ -623,8 +768,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
623 | item.ItemID, m_part.Name, m_part.UUID, | 768 | item.ItemID, m_part.Name, m_part.UUID, |
624 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 769 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
625 | } | 770 | } |
626 | return false; | 771 | m_items.LockItemsForWrite(false); |
627 | 772 | ||
773 | return false; | ||
628 | } | 774 | } |
629 | 775 | ||
630 | /// <summary> | 776 | /// <summary> |
@@ -635,37 +781,53 @@ namespace OpenSim.Region.Framework.Scenes | |||
635 | /// in this prim's inventory.</returns> | 781 | /// in this prim's inventory.</returns> |
636 | public int RemoveInventoryItem(UUID itemID) | 782 | public int RemoveInventoryItem(UUID itemID) |
637 | { | 783 | { |
638 | TaskInventoryItem item = GetInventoryItem(itemID); | 784 | m_items.LockItemsForRead(true); |
639 | if (item != null) | 785 | |
786 | if (m_items.ContainsKey(itemID)) | ||
640 | { | 787 | { |
641 | int type = m_items[itemID].InvType; | 788 | int type = m_items[itemID].InvType; |
789 | m_items.LockItemsForRead(false); | ||
642 | if (type == 10) // Script | 790 | if (type == 10) // Script |
643 | { | 791 | { |
644 | m_part.RemoveScriptEvents(itemID); | ||
645 | m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); | 792 | m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); |
646 | } | 793 | } |
794 | m_items.LockItemsForWrite(true); | ||
647 | m_items.Remove(itemID); | 795 | m_items.Remove(itemID); |
796 | m_items.LockItemsForWrite(false); | ||
648 | m_inventorySerial++; | 797 | m_inventorySerial++; |
649 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 798 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
650 | 799 | ||
651 | HasInventoryChanged = true; | 800 | HasInventoryChanged = true; |
652 | m_part.ParentGroup.HasGroupChanged = true; | 801 | m_part.ParentGroup.HasGroupChanged = true; |
653 | 802 | ||
654 | if (!ContainsScripts()) | 803 | int scriptcount = 0; |
804 | m_items.LockItemsForRead(true); | ||
805 | foreach (TaskInventoryItem item in m_items.Values) | ||
806 | { | ||
807 | if (item.Type == 10) | ||
808 | { | ||
809 | scriptcount++; | ||
810 | } | ||
811 | } | ||
812 | m_items.LockItemsForRead(false); | ||
813 | |||
814 | |||
815 | if (scriptcount <= 0) | ||
816 | { | ||
655 | m_part.RemFlag(PrimFlags.Scripted); | 817 | m_part.RemFlag(PrimFlags.Scripted); |
818 | } | ||
656 | 819 | ||
657 | m_part.ScheduleFullUpdate(); | 820 | m_part.ScheduleFullUpdate(); |
658 | 821 | ||
659 | return type; | 822 | return type; |
660 | |||
661 | } | 823 | } |
662 | else | 824 | else |
663 | { | 825 | { |
826 | m_items.LockItemsForRead(false); | ||
664 | m_log.ErrorFormat( | 827 | m_log.ErrorFormat( |
665 | "[PRIM INVENTORY]: " + | 828 | "[PRIM INVENTORY]: " + |
666 | "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", | 829 | "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory", |
667 | itemID, m_part.Name, m_part.UUID, | 830 | itemID, m_part.Name, m_part.UUID); |
668 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | ||
669 | } | 831 | } |
670 | 832 | ||
671 | return -1; | 833 | return -1; |
@@ -719,8 +881,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
719 | // isn't available (such as drag from prim inventory to agent inventory) | 881 | // isn't available (such as drag from prim inventory to agent inventory) |
720 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); | 882 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); |
721 | 883 | ||
722 | List<TaskInventoryItem> items = GetInventoryItems(); | 884 | m_items.LockItemsForRead(true); |
723 | foreach (TaskInventoryItem item in items) | 885 | |
886 | foreach (TaskInventoryItem item in m_items.Values) | ||
724 | { | 887 | { |
725 | UUID ownerID = item.OwnerID; | 888 | UUID ownerID = item.OwnerID; |
726 | uint everyoneMask = 0; | 889 | uint everyoneMask = 0; |
@@ -764,6 +927,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
764 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | 927 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); |
765 | invString.AddSectionEnd(); | 928 | invString.AddSectionEnd(); |
766 | } | 929 | } |
930 | int count = m_items.Count; | ||
931 | m_items.LockItemsForRead(false); | ||
767 | 932 | ||
768 | fileData = Utils.StringToBytes(invString.BuildString); | 933 | fileData = Utils.StringToBytes(invString.BuildString); |
769 | 934 | ||
@@ -784,10 +949,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
784 | { | 949 | { |
785 | if (HasInventoryChanged) | 950 | if (HasInventoryChanged) |
786 | { | 951 | { |
787 | HasInventoryChanged = false; | 952 | Items.LockItemsForRead(true); |
788 | List<TaskInventoryItem> items = GetInventoryItems(); | 953 | datastore.StorePrimInventory(m_part.UUID, Items.Values); |
789 | datastore.StorePrimInventory(m_part.UUID, items); | 954 | Items.LockItemsForRead(false); |
790 | 955 | ||
956 | HasInventoryChanged = false; | ||
791 | } | 957 | } |
792 | } | 958 | } |
793 | 959 | ||
@@ -854,89 +1020,75 @@ namespace OpenSim.Region.Framework.Scenes | |||
854 | { | 1020 | { |
855 | uint mask=0x7fffffff; | 1021 | uint mask=0x7fffffff; |
856 | 1022 | ||
857 | lock (m_items) | 1023 | foreach (TaskInventoryItem item in m_items.Values) |
858 | { | 1024 | { |
859 | foreach (TaskInventoryItem item in m_items.Values) | 1025 | if (item.InvType != (int)InventoryType.Object) |
860 | { | 1026 | { |
861 | if (item.InvType != (int)InventoryType.Object) | 1027 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) |
862 | { | 1028 | mask &= ~((uint)PermissionMask.Copy >> 13); |
863 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) | 1029 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) |
864 | mask &= ~((uint)PermissionMask.Copy >> 13); | 1030 | mask &= ~((uint)PermissionMask.Transfer >> 13); |
865 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | 1031 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) |
866 | mask &= ~((uint)PermissionMask.Transfer >> 13); | 1032 | mask &= ~((uint)PermissionMask.Modify >> 13); |
867 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | ||
868 | mask &= ~((uint)PermissionMask.Modify >> 13); | ||
869 | } | ||
870 | else | ||
871 | { | ||
872 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) | ||
873 | mask &= ~((uint)PermissionMask.Copy >> 13); | ||
874 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) | ||
875 | mask &= ~((uint)PermissionMask.Transfer >> 13); | ||
876 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) | ||
877 | mask &= ~((uint)PermissionMask.Modify >> 13); | ||
878 | } | ||
879 | |||
880 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
881 | mask &= ~(uint)PermissionMask.Copy; | ||
882 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
883 | mask &= ~(uint)PermissionMask.Transfer; | ||
884 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
885 | mask &= ~(uint)PermissionMask.Modify; | ||
886 | } | 1033 | } |
1034 | else | ||
1035 | { | ||
1036 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) | ||
1037 | mask &= ~((uint)PermissionMask.Copy >> 13); | ||
1038 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) | ||
1039 | mask &= ~((uint)PermissionMask.Transfer >> 13); | ||
1040 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) | ||
1041 | mask &= ~((uint)PermissionMask.Modify >> 13); | ||
1042 | } | ||
1043 | |||
1044 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
1045 | mask &= ~(uint)PermissionMask.Copy; | ||
1046 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1047 | mask &= ~(uint)PermissionMask.Transfer; | ||
1048 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
1049 | mask &= ~(uint)PermissionMask.Modify; | ||
887 | } | 1050 | } |
888 | |||
889 | return mask; | 1051 | return mask; |
890 | } | 1052 | } |
891 | 1053 | ||
892 | public void ApplyNextOwnerPermissions() | 1054 | public void ApplyNextOwnerPermissions() |
893 | { | 1055 | { |
894 | lock (m_items) | 1056 | foreach (TaskInventoryItem item in m_items.Values) |
895 | { | 1057 | { |
896 | foreach (TaskInventoryItem item in m_items.Values) | 1058 | if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) |
897 | { | 1059 | { |
898 | if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) | 1060 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
899 | { | 1061 | item.CurrentPermissions &= ~(uint)PermissionMask.Copy; |
900 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) | 1062 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
901 | item.CurrentPermissions &= ~(uint)PermissionMask.Copy; | 1063 | item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; |
902 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) | 1064 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
903 | item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; | 1065 | item.CurrentPermissions &= ~(uint)PermissionMask.Modify; |
904 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) | ||
905 | item.CurrentPermissions &= ~(uint)PermissionMask.Modify; | ||
906 | } | ||
907 | item.CurrentPermissions &= item.NextPermissions; | ||
908 | item.BasePermissions &= item.NextPermissions; | ||
909 | item.EveryonePermissions &= item.NextPermissions; | ||
910 | item.OwnerChanged = true; | ||
911 | } | 1066 | } |
1067 | item.OwnerChanged = true; | ||
1068 | item.CurrentPermissions &= item.NextPermissions; | ||
1069 | item.BasePermissions &= item.NextPermissions; | ||
1070 | item.EveryonePermissions &= item.NextPermissions; | ||
912 | } | 1071 | } |
913 | } | 1072 | } |
914 | 1073 | ||
915 | public void ApplyGodPermissions(uint perms) | 1074 | public void ApplyGodPermissions(uint perms) |
916 | { | 1075 | { |
917 | lock (m_items) | 1076 | foreach (TaskInventoryItem item in m_items.Values) |
918 | { | 1077 | { |
919 | foreach (TaskInventoryItem item in m_items.Values) | 1078 | item.CurrentPermissions = perms; |
920 | { | 1079 | item.BasePermissions = perms; |
921 | item.CurrentPermissions = perms; | ||
922 | item.BasePermissions = perms; | ||
923 | } | ||
924 | } | 1080 | } |
925 | } | 1081 | } |
926 | 1082 | ||
927 | public bool ContainsScripts() | 1083 | public bool ContainsScripts() |
928 | { | 1084 | { |
929 | lock (m_items) | 1085 | foreach (TaskInventoryItem item in m_items.Values) |
930 | { | 1086 | { |
931 | foreach (TaskInventoryItem item in m_items.Values) | 1087 | if (item.InvType == (int)InventoryType.LSL) |
932 | { | 1088 | { |
933 | if (item.InvType == (int)InventoryType.LSL) | 1089 | return true; |
934 | { | ||
935 | return true; | ||
936 | } | ||
937 | } | 1090 | } |
938 | } | 1091 | } |
939 | |||
940 | return false; | 1092 | return false; |
941 | } | 1093 | } |
942 | 1094 | ||
@@ -944,11 +1096,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
944 | { | 1096 | { |
945 | List<UUID> ret = new List<UUID>(); | 1097 | List<UUID> ret = new List<UUID>(); |
946 | 1098 | ||
947 | lock (m_items) | 1099 | foreach (TaskInventoryItem item in m_items.Values) |
948 | { | 1100 | ret.Add(item.ItemID); |
949 | foreach (TaskInventoryItem item in m_items.Values) | ||
950 | ret.Add(item.ItemID); | ||
951 | } | ||
952 | 1101 | ||
953 | return ret; | 1102 | return ret; |
954 | } | 1103 | } |
@@ -979,31 +1128,44 @@ namespace OpenSim.Region.Framework.Scenes | |||
979 | 1128 | ||
980 | public Dictionary<UUID, string> GetScriptStates() | 1129 | public Dictionary<UUID, string> GetScriptStates() |
981 | { | 1130 | { |
1131 | return GetScriptStates(false); | ||
1132 | } | ||
1133 | |||
1134 | public Dictionary<UUID, string> GetScriptStates(bool oldIDs) | ||
1135 | { | ||
982 | IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>(); | 1136 | IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>(); |
983 | 1137 | ||
984 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); | 1138 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); |
985 | if (engines == null) // No engine at all | 1139 | if (engines == null) // No engine at all |
986 | return ret; | 1140 | return ret; |
987 | 1141 | ||
988 | List<TaskInventoryItem> scripts = GetInventoryScripts(); | 1142 | foreach (TaskInventoryItem item in m_items.Values) |
989 | |||
990 | foreach (TaskInventoryItem item in scripts) | ||
991 | { | 1143 | { |
992 | foreach (IScriptModule e in engines) | 1144 | if (item.InvType == (int)InventoryType.LSL) |
993 | { | 1145 | { |
994 | if (e != null) | 1146 | foreach (IScriptModule e in engines) |
995 | { | 1147 | { |
996 | string n = e.GetXMLState(item.ItemID); | 1148 | if (e != null) |
997 | if (n != String.Empty) | ||
998 | { | 1149 | { |
999 | if (!ret.ContainsKey(item.ItemID)) | 1150 | string n = e.GetXMLState(item.ItemID); |
1000 | ret[item.ItemID] = n; | 1151 | if (n != String.Empty) |
1001 | break; | 1152 | { |
1153 | if (oldIDs) | ||
1154 | { | ||
1155 | if (!ret.ContainsKey(item.OldItemID)) | ||
1156 | ret[item.OldItemID] = n; | ||
1157 | } | ||
1158 | else | ||
1159 | { | ||
1160 | if (!ret.ContainsKey(item.ItemID)) | ||
1161 | ret[item.ItemID] = n; | ||
1162 | } | ||
1163 | break; | ||
1164 | } | ||
1002 | } | 1165 | } |
1003 | } | 1166 | } |
1004 | } | 1167 | } |
1005 | } | 1168 | } |
1006 | |||
1007 | return ret; | 1169 | return ret; |
1008 | } | 1170 | } |
1009 | 1171 | ||
@@ -1013,21 +1175,27 @@ namespace OpenSim.Region.Framework.Scenes | |||
1013 | if (engines == null) | 1175 | if (engines == null) |
1014 | return; | 1176 | return; |
1015 | 1177 | ||
1016 | List<TaskInventoryItem> scripts = GetInventoryScripts(); | ||
1017 | 1178 | ||
1018 | foreach (TaskInventoryItem item in scripts) | 1179 | Items.LockItemsForRead(true); |
1180 | |||
1181 | foreach (TaskInventoryItem item in m_items.Values) | ||
1019 | { | 1182 | { |
1020 | foreach (IScriptModule engine in engines) | 1183 | if (item.InvType == (int)InventoryType.LSL) |
1021 | { | 1184 | { |
1022 | if (engine != null) | 1185 | foreach (IScriptModule engine in engines) |
1023 | { | 1186 | { |
1024 | if (item.OwnerChanged) | 1187 | if (engine != null) |
1025 | engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER }); | 1188 | { |
1026 | item.OwnerChanged = false; | 1189 | if (item.OwnerChanged) |
1027 | engine.ResumeScript(item.ItemID); | 1190 | engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER }); |
1191 | item.OwnerChanged = false; | ||
1192 | engine.ResumeScript(item.ItemID); | ||
1193 | } | ||
1028 | } | 1194 | } |
1029 | } | 1195 | } |
1030 | } | 1196 | } |
1197 | |||
1198 | Items.LockItemsForRead(false); | ||
1031 | } | 1199 | } |
1032 | 1200 | ||
1033 | } | 1201 | } |
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 4c17615..fc8e0d7 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -1,3767 +1,4332 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSimulator Project nor the | 12 | * * Neither the name of the OpenSimulator Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Xml; |
30 | using System.Reflection; | 30 | using System.Collections.Generic; |
31 | using System.Timers; | 31 | using System.Reflection; |
32 | using OpenMetaverse; | 32 | using System.Timers; |
33 | using log4net; | 33 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 34 | using log4net; |
35 | using OpenSim.Framework.Client; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Framework.Client; |
37 | using OpenSim.Region.Framework.Scenes.Animation; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes.Types; | 38 | using OpenSim.Region.Framework.Scenes.Animation; |
39 | using OpenSim.Region.Physics.Manager; | 39 | using OpenSim.Region.Framework.Scenes.Types; |
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 40 | using OpenSim.Region.Physics.Manager; |
41 | using OpenSim.Services.Interfaces; | 41 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
42 | 42 | using OpenSim.Services.Interfaces; | |
43 | namespace OpenSim.Region.Framework.Scenes | 43 | |
44 | { | 44 | namespace OpenSim.Region.Framework.Scenes |
45 | enum ScriptControlled : uint | 45 | { |
46 | { | 46 | enum ScriptControlled : uint |
47 | CONTROL_ZERO = 0, | 47 | { |
48 | CONTROL_FWD = 1, | 48 | CONTROL_ZERO = 0, |
49 | CONTROL_BACK = 2, | 49 | CONTROL_FWD = 1, |
50 | CONTROL_LEFT = 4, | 50 | CONTROL_BACK = 2, |
51 | CONTROL_RIGHT = 8, | 51 | CONTROL_LEFT = 4, |
52 | CONTROL_UP = 16, | 52 | CONTROL_RIGHT = 8, |
53 | CONTROL_DOWN = 32, | 53 | CONTROL_UP = 16, |
54 | CONTROL_ROT_LEFT = 256, | 54 | CONTROL_DOWN = 32, |
55 | CONTROL_ROT_RIGHT = 512, | 55 | CONTROL_ROT_LEFT = 256, |
56 | CONTROL_LBUTTON = 268435456, | 56 | CONTROL_ROT_RIGHT = 512, |
57 | CONTROL_ML_LBUTTON = 1073741824 | 57 | CONTROL_LBUTTON = 268435456, |
58 | } | 58 | CONTROL_ML_LBUTTON = 1073741824 |
59 | 59 | } | |
60 | struct ScriptControllers | 60 | |
61 | { | 61 | struct ScriptControllers |
62 | public UUID itemID; | 62 | { |
63 | public ScriptControlled ignoreControls; | 63 | public UUID itemID; |
64 | public ScriptControlled eventControls; | 64 | public ScriptControlled ignoreControls; |
65 | } | 65 | public ScriptControlled eventControls; |
66 | 66 | } | |
67 | public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence, List<Vector3> coarseLocations, List<UUID> avatarUUIDs); | 67 | |
68 | 68 | public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence, List<Vector3> coarseLocations, List<UUID> avatarUUIDs); | |
69 | public class ScenePresence : EntityBase, ISceneEntity | 69 | |
70 | { | 70 | public class ScenePresence : EntityBase, ISceneEntity |
71 | // ~ScenePresence() | 71 | { |
72 | // { | 72 | // ~ScenePresence() |
73 | // m_log.Debug("[ScenePresence] Destructor called"); | 73 | // { |
74 | // } | 74 | // m_log.Debug("[ScenePresence] Destructor called"); |
75 | 75 | // } | |
76 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 76 | |
77 | 77 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | |
78 | private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; | 78 | |
79 | // private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); | 79 | private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; |
80 | private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); | 80 | // private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); |
81 | private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); | 81 | private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); |
82 | 82 | private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); | |
83 | /// <summary> | 83 | |
84 | /// Experimentally determined "fudge factor" to make sit-target positions | 84 | /// <summary> |
85 | /// the same as in SecondLife. Fudge factor was tested for 36 different | 85 | /// Experimentally determined "fudge factor" to make sit-target positions |
86 | /// test cases including prims of type box, sphere, cylinder, and torus, | 86 | /// the same as in SecondLife. Fudge factor was tested for 36 different |
87 | /// with varying parameters for sit target location, prim size, prim | 87 | /// test cases including prims of type box, sphere, cylinder, and torus, |
88 | /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis | 88 | /// with varying parameters for sit target location, prim size, prim |
89 | /// issue #1716 | 89 | /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis |
90 | /// </summary> | 90 | /// issue #1716 |
91 | private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); | 91 | /// </summary> |
92 | 92 | // private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); | |
93 | public UUID currentParcelUUID = UUID.Zero; | 93 | // Value revised by KF 091121 by comparison with SL. |
94 | 94 | private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); | |
95 | private ISceneViewer m_sceneViewer; | 95 | |
96 | 96 | public UUID currentParcelUUID = UUID.Zero; | |
97 | /// <value> | 97 | |
98 | /// The animator for this avatar | 98 | private ISceneViewer m_sceneViewer; |
99 | /// </value> | 99 | |
100 | public ScenePresenceAnimator Animator | 100 | /// <value> |
101 | { | 101 | /// The animator for this avatar |
102 | get { return m_animator; } | 102 | /// </value> |
103 | } | 103 | public ScenePresenceAnimator Animator |
104 | protected ScenePresenceAnimator m_animator; | 104 | { |
105 | 105 | get { return m_animator; } | |
106 | /// <value> | 106 | } |
107 | /// The scene objects attached to this avatar. Do not change this list directly - use methods such as | 107 | protected ScenePresenceAnimator m_animator; |
108 | /// AddAttachment() and RemoveAttachment(). Lock this list when performing any read operations upon it. | 108 | |
109 | /// </value> | 109 | /// <value> |
110 | public List<SceneObjectGroup> Attachments | 110 | /// The scene objects attached to this avatar. Do not change this list directly - use methods such as |
111 | { | 111 | /// AddAttachment() and RemoveAttachment(). Lock this list when performing any read operations upon it. |
112 | get { return m_attachments; } | 112 | /// </value> |
113 | } | 113 | public List<SceneObjectGroup> Attachments |
114 | protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); | 114 | { |
115 | 115 | get { return m_attachments; } | |
116 | private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); | 116 | } |
117 | private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; | 117 | protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); |
118 | private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; | 118 | |
119 | private bool MouseDown = false; | 119 | private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); |
120 | private SceneObjectGroup proxyObjectGroup; | 120 | private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; |
121 | //private SceneObjectPart proxyObjectPart = null; | 121 | private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; |
122 | public Vector3 lastKnownAllowedPosition; | 122 | private bool MouseDown = false; |
123 | public bool sentMessageAboutRestrictedParcelFlyingDown; | 123 | private SceneObjectGroup proxyObjectGroup; |
124 | public Vector4 CollisionPlane = Vector4.UnitW; | 124 | //private SceneObjectPart proxyObjectPart = null; |
125 | 125 | public Vector3 lastKnownAllowedPosition; | |
126 | private Vector3 m_lastPosition; | 126 | public bool sentMessageAboutRestrictedParcelFlyingDown; |
127 | private Quaternion m_lastRotation; | 127 | public Vector4 CollisionPlane = Vector4.UnitW; |
128 | private Vector3 m_lastVelocity; | 128 | |
129 | //private int m_lastTerseSent; | 129 | private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation |
130 | 130 | private Vector3 m_avUnscriptedSitPos; // for non-scripted prims | |
131 | private bool m_updateflag; | 131 | private Vector3 m_lastPosition; |
132 | private byte m_movementflag; | 132 | private Vector3 m_lastWorldPosition; |
133 | private Vector3? m_forceToApply; | 133 | private Quaternion m_lastRotation; |
134 | private uint m_requestedSitTargetID; | 134 | private Vector3 m_lastVelocity; |
135 | private UUID m_requestedSitTargetUUID; | 135 | //private int m_lastTerseSent; |
136 | public bool SitGround = false; | 136 | |
137 | 137 | private bool m_updateflag; | |
138 | private SendCourseLocationsMethod m_sendCourseLocationsMethod; | 138 | private byte m_movementflag; |
139 | 139 | private Vector3? m_forceToApply; | |
140 | private bool m_startAnimationSet; | 140 | private uint m_requestedSitTargetID; |
141 | 141 | private UUID m_requestedSitTargetUUID; | |
142 | //private Vector3 m_requestedSitOffset = new Vector3(); | 142 | public bool SitGround = false; |
143 | 143 | ||
144 | private Vector3 m_LastFinitePos; | 144 | private SendCourseLocationsMethod m_sendCourseLocationsMethod; |
145 | 145 | ||
146 | private float m_sitAvatarHeight = 2.0f; | 146 | private bool m_startAnimationSet; |
147 | 147 | ||
148 | private int m_godLevel; | 148 | //private Vector3 m_requestedSitOffset = new Vector3(); |
149 | private int m_userLevel; | 149 | |
150 | 150 | private Vector3 m_LastFinitePos; | |
151 | private bool m_invulnerable = true; | 151 | |
152 | 152 | private float m_sitAvatarHeight = 2.0f; | |
153 | private Vector3 m_lastChildAgentUpdatePosition; | 153 | |
154 | private Vector3 m_lastChildAgentUpdateCamPosition; | 154 | private int m_godLevel; |
155 | 155 | private int m_userLevel; | |
156 | private int m_perfMonMS; | 156 | |
157 | 157 | private bool m_invulnerable = true; | |
158 | private bool m_setAlwaysRun; | 158 | |
159 | 159 | private Vector3 m_lastChildAgentUpdatePosition; | |
160 | private bool m_forceFly; | 160 | private Vector3 m_lastChildAgentUpdateCamPosition; |
161 | private bool m_flyDisabled; | 161 | |
162 | 162 | private int m_perfMonMS; | |
163 | private float m_speedModifier = 1.0f; | 163 | |
164 | 164 | private bool m_setAlwaysRun; | |
165 | private Quaternion m_bodyRot= Quaternion.Identity; | 165 | private bool m_forceFly; |
166 | 166 | private bool m_flyDisabled; | |
167 | private Quaternion m_bodyRotPrevious = Quaternion.Identity; | 167 | |
168 | 168 | private float m_speedModifier = 1.0f; | |
169 | private const int LAND_VELOCITYMAG_MAX = 12; | 169 | |
170 | 170 | private Quaternion m_bodyRot= Quaternion.Identity; | |
171 | public bool IsRestrictedToRegion; | 171 | |
172 | 172 | private Quaternion m_bodyRotPrevious = Quaternion.Identity; | |
173 | public string JID = String.Empty; | 173 | |
174 | 174 | private const int LAND_VELOCITYMAG_MAX = 12; | |
175 | private float m_health = 100f; | 175 | |
176 | 176 | public bool IsRestrictedToRegion; | |
177 | // Default AV Height | 177 | |
178 | private float m_avHeight = 127.0f; | 178 | public string JID = String.Empty; |
179 | 179 | ||
180 | protected RegionInfo m_regionInfo; | 180 | private float m_health = 100f; |
181 | protected ulong crossingFromRegion; | 181 | |
182 | 182 | // Default AV Height | |
183 | private readonly Vector3[] Dir_Vectors = new Vector3[9]; | 183 | private float m_avHeight = 127.0f; |
184 | 184 | ||
185 | // Position of agent's camera in world (region cordinates) | 185 | protected RegionInfo m_regionInfo; |
186 | protected Vector3 m_CameraCenter; | 186 | protected ulong crossingFromRegion; |
187 | protected Vector3 m_lastCameraCenter; | 187 | |
188 | 188 | private readonly Vector3[] Dir_Vectors = new Vector3[11]; | |
189 | protected Timer m_reprioritization_timer; | 189 | private bool m_isNudging = false; |
190 | protected bool m_reprioritizing; | 190 | |
191 | protected bool m_reprioritization_called; | 191 | // Position of agent's camera in world (region cordinates) |
192 | 192 | protected Vector3 m_CameraCenter; | |
193 | // Use these three vectors to figure out what the agent is looking at | 193 | protected Vector3 m_lastCameraCenter; |
194 | // Convert it to a Matrix and/or Quaternion | 194 | |
195 | protected Vector3 m_CameraAtAxis; | 195 | protected Timer m_reprioritization_timer; |
196 | protected Vector3 m_CameraLeftAxis; | 196 | protected bool m_reprioritizing; |
197 | protected Vector3 m_CameraUpAxis; | 197 | protected bool m_reprioritization_called; |
198 | private AgentManager.ControlFlags m_AgentControlFlags; | 198 | |
199 | private Quaternion m_headrotation = Quaternion.Identity; | 199 | // Use these three vectors to figure out what the agent is looking at |
200 | private byte m_state; | 200 | // Convert it to a Matrix and/or Quaternion |
201 | 201 | protected Vector3 m_CameraAtAxis; | |
202 | //Reuse the Vector3 instead of creating a new one on the UpdateMovement method | 202 | protected Vector3 m_CameraLeftAxis; |
203 | // private Vector3 movementvector; | 203 | protected Vector3 m_CameraUpAxis; |
204 | 204 | private AgentManager.ControlFlags m_AgentControlFlags; | |
205 | private bool m_autopilotMoving; | 205 | private Quaternion m_headrotation = Quaternion.Identity; |
206 | private Vector3 m_autoPilotTarget; | 206 | private byte m_state; |
207 | private bool m_sitAtAutoTarget; | 207 | |
208 | 208 | //Reuse the Vector3 instead of creating a new one on the UpdateMovement method | |
209 | private string m_nextSitAnimation = String.Empty; | 209 | // private Vector3 movementvector; |
210 | 210 | ||
211 | //PauPaw:Proper PID Controler for autopilot************ | 211 | private bool m_autopilotMoving; |
212 | private bool m_moveToPositionInProgress; | 212 | private Vector3 m_autoPilotTarget; |
213 | private Vector3 m_moveToPositionTarget; | 213 | private bool m_sitAtAutoTarget; |
214 | 214 | private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit | |
215 | private bool m_followCamAuto; | 215 | |
216 | 216 | private string m_nextSitAnimation = String.Empty; | |
217 | private int m_movementUpdateCount; | 217 | |
218 | private const int NumMovementsBetweenRayCast = 5; | 218 | //PauPaw:Proper PID Controler for autopilot************ |
219 | 219 | private bool m_moveToPositionInProgress; | |
220 | private bool CameraConstraintActive; | 220 | private Vector3 m_moveToPositionTarget; |
221 | //private int m_moveToPositionStateStatus; | 221 | private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); |
222 | //***************************************************** | 222 | |
223 | 223 | private bool m_followCamAuto; | |
224 | // Agent's Draw distance. | 224 | |
225 | protected float m_DrawDistance; | 225 | private int m_movementUpdateCount; |
226 | 226 | private int m_lastColCount = -1; //KF: Look for Collision chnages | |
227 | protected AvatarAppearance m_appearance; | 227 | private int m_updateCount = 0; //KF: Update Anims for a while |
228 | 228 | private static readonly int UPDATE_COUNT = 10; // how many frames to update for | |
229 | // neighbouring regions we have enabled a child agent in | 229 | private const int NumMovementsBetweenRayCast = 5; |
230 | // holds the seed cap for the child agent in that region | 230 | private List<uint> m_lastColliders = new List<uint>(); |
231 | private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>(); | 231 | |
232 | 232 | private bool CameraConstraintActive; | |
233 | /// <summary> | 233 | //private int m_moveToPositionStateStatus; |
234 | /// Implemented Control Flags | 234 | //***************************************************** |
235 | /// </summary> | 235 | |
236 | private enum Dir_ControlFlags | 236 | // Agent's Draw distance. |
237 | { | 237 | protected float m_DrawDistance; |
238 | DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, | 238 | |
239 | DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, | 239 | protected AvatarAppearance m_appearance; |
240 | DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, | 240 | |
241 | DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, | 241 | // neighbouring regions we have enabled a child agent in |
242 | DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, | 242 | // holds the seed cap for the child agent in that region |
243 | DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, | 243 | private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>(); |
244 | DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, | 244 | |
245 | DIR_CONTROL_FLAG_BACKWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, | 245 | /// <summary> |
246 | DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG | 246 | /// Implemented Control Flags |
247 | } | 247 | /// </summary> |
248 | 248 | private enum Dir_ControlFlags | |
249 | /// <summary> | 249 | { |
250 | /// Position at which a significant movement was made | 250 | DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, |
251 | /// </summary> | 251 | DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, |
252 | private Vector3 posLastSignificantMove; | 252 | DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, |
253 | 253 | DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, | |
254 | // For teleports and crossings callbacks | 254 | DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, |
255 | string m_callbackURI; | 255 | DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, |
256 | UUID m_originRegionID; | 256 | DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, |
257 | 257 | DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, | |
258 | ulong m_rootRegionHandle; | 258 | DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS, |
259 | 259 | DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG, | |
260 | /// <value> | 260 | DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG |
261 | /// Script engines present in the scene | 261 | } |
262 | /// </value> | 262 | |
263 | private IScriptModule[] m_scriptEngines; | 263 | /// <summary> |
264 | 264 | /// Position at which a significant movement was made | |
265 | #region Properties | 265 | /// </summary> |
266 | 266 | private Vector3 posLastSignificantMove; | |
267 | /// <summary> | 267 | |
268 | /// Physical scene representation of this Avatar. | 268 | // For teleports and crossings callbacks |
269 | /// </summary> | 269 | string m_callbackURI; |
270 | public PhysicsActor PhysicsActor | 270 | UUID m_originRegionID; |
271 | { | 271 | |
272 | set { m_physicsActor = value; } | 272 | ulong m_rootRegionHandle; |
273 | get { return m_physicsActor; } | 273 | |
274 | } | 274 | /// <value> |
275 | 275 | /// Script engines present in the scene | |
276 | public byte MovementFlag | 276 | /// </value> |
277 | { | 277 | private IScriptModule[] m_scriptEngines; |
278 | set { m_movementflag = value; } | 278 | |
279 | get { return m_movementflag; } | 279 | #region Properties |
280 | } | 280 | |
281 | 281 | /// <summary> | |
282 | public bool Updated | 282 | /// Physical scene representation of this Avatar. |
283 | { | 283 | /// </summary> |
284 | set { m_updateflag = value; } | 284 | public PhysicsActor PhysicsActor |
285 | get { return m_updateflag; } | 285 | { |
286 | } | 286 | set { m_physicsActor = value; } |
287 | 287 | get { return m_physicsActor; } | |
288 | public bool Invulnerable | 288 | } |
289 | { | 289 | |
290 | set { m_invulnerable = value; } | 290 | public byte MovementFlag |
291 | get { return m_invulnerable; } | 291 | { |
292 | } | 292 | set { m_movementflag = value; } |
293 | 293 | get { return m_movementflag; } | |
294 | public int UserLevel | 294 | } |
295 | { | 295 | |
296 | get { return m_userLevel; } | 296 | public bool Updated |
297 | } | 297 | { |
298 | 298 | set { m_updateflag = value; } | |
299 | public int GodLevel | 299 | get { return m_updateflag; } |
300 | { | 300 | } |
301 | get { return m_godLevel; } | 301 | |
302 | } | 302 | public bool Invulnerable |
303 | 303 | { | |
304 | public ulong RegionHandle | 304 | set { m_invulnerable = value; } |
305 | { | 305 | get { return m_invulnerable; } |
306 | get { return m_rootRegionHandle; } | 306 | } |
307 | } | 307 | |
308 | 308 | public int UserLevel | |
309 | public Vector3 CameraPosition | 309 | { |
310 | { | 310 | get { return m_userLevel; } |
311 | get { return m_CameraCenter; } | 311 | } |
312 | } | 312 | |
313 | 313 | public int GodLevel | |
314 | public Quaternion CameraRotation | 314 | { |
315 | { | 315 | get { return m_godLevel; } |
316 | get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } | 316 | } |
317 | } | 317 | |
318 | 318 | public ulong RegionHandle | |
319 | public Vector3 CameraAtAxis | 319 | { |
320 | { | 320 | get { return m_rootRegionHandle; } |
321 | get { return m_CameraAtAxis; } | 321 | } |
322 | } | 322 | |
323 | 323 | public Vector3 CameraPosition | |
324 | public Vector3 CameraLeftAxis | 324 | { |
325 | { | 325 | get { return m_CameraCenter; } |
326 | get { return m_CameraLeftAxis; } | 326 | } |
327 | } | 327 | |
328 | 328 | public Quaternion CameraRotation | |
329 | public Vector3 CameraUpAxis | 329 | { |
330 | { | 330 | get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } |
331 | get { return m_CameraUpAxis; } | 331 | } |
332 | } | 332 | |
333 | 333 | public Vector3 CameraAtAxis | |
334 | public Vector3 Lookat | 334 | { |
335 | { | 335 | get { return m_CameraAtAxis; } |
336 | get | 336 | } |
337 | { | 337 | |
338 | Vector3 a = new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0); | 338 | public Vector3 CameraLeftAxis |
339 | 339 | { | |
340 | if (a == Vector3.Zero) | 340 | get { return m_CameraLeftAxis; } |
341 | return a; | 341 | } |
342 | 342 | ||
343 | return Util.GetNormalizedVector(a); | 343 | public Vector3 CameraUpAxis |
344 | } | 344 | { |
345 | } | 345 | get { return m_CameraUpAxis; } |
346 | 346 | } | |
347 | private readonly string m_firstname; | 347 | |
348 | 348 | public Vector3 Lookat | |
349 | public string Firstname | 349 | { |
350 | { | 350 | get |
351 | get { return m_firstname; } | 351 | { |
352 | } | 352 | Vector3 a = new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0); |
353 | 353 | ||
354 | private readonly string m_lastname; | 354 | if (a == Vector3.Zero) |
355 | 355 | return a; | |
356 | public string Lastname | 356 | |
357 | { | 357 | return Util.GetNormalizedVector(a); |
358 | get { return m_lastname; } | 358 | } |
359 | } | 359 | } |
360 | 360 | ||
361 | private string m_grouptitle; | 361 | private readonly string m_firstname; |
362 | 362 | ||
363 | public string Grouptitle | 363 | public string Firstname |
364 | { | 364 | { |
365 | get { return m_grouptitle; } | 365 | get { return m_firstname; } |
366 | set { m_grouptitle = value; } | 366 | } |
367 | } | 367 | |
368 | 368 | private readonly string m_lastname; | |
369 | public float DrawDistance | 369 | |
370 | { | 370 | public string Lastname |
371 | get { return m_DrawDistance; } | 371 | { |
372 | } | 372 | get { return m_lastname; } |
373 | 373 | } | |
374 | protected bool m_allowMovement = true; | 374 | |
375 | 375 | private string m_grouptitle; | |
376 | public bool AllowMovement | 376 | |
377 | { | 377 | public string Grouptitle |
378 | get { return m_allowMovement; } | 378 | { |
379 | set { m_allowMovement = value; } | 379 | get { return m_grouptitle; } |
380 | } | 380 | set { m_grouptitle = value; } |
381 | 381 | } | |
382 | public bool SetAlwaysRun | 382 | |
383 | { | 383 | public float DrawDistance |
384 | get | 384 | { |
385 | { | 385 | get { return m_DrawDistance; } |
386 | if (PhysicsActor != null) | 386 | } |
387 | { | 387 | |
388 | return PhysicsActor.SetAlwaysRun; | 388 | protected bool m_allowMovement = true; |
389 | } | 389 | |
390 | else | 390 | public bool AllowMovement |
391 | { | 391 | { |
392 | return m_setAlwaysRun; | 392 | get { return m_allowMovement; } |
393 | } | 393 | set { m_allowMovement = value; } |
394 | } | 394 | } |
395 | set | 395 | |
396 | { | 396 | public bool SetAlwaysRun |
397 | m_setAlwaysRun = value; | 397 | { |
398 | if (PhysicsActor != null) | 398 | get |
399 | { | 399 | { |
400 | PhysicsActor.SetAlwaysRun = value; | 400 | if (PhysicsActor != null) |
401 | } | 401 | { |
402 | } | 402 | return PhysicsActor.SetAlwaysRun; |
403 | } | 403 | } |
404 | 404 | else | |
405 | public byte State | 405 | { |
406 | { | 406 | return m_setAlwaysRun; |
407 | get { return m_state; } | 407 | } |
408 | set { m_state = value; } | 408 | } |
409 | } | 409 | set |
410 | 410 | { | |
411 | public uint AgentControlFlags | 411 | m_setAlwaysRun = value; |
412 | { | 412 | if (PhysicsActor != null) |
413 | get { return (uint)m_AgentControlFlags; } | 413 | { |
414 | set { m_AgentControlFlags = (AgentManager.ControlFlags)value; } | 414 | PhysicsActor.SetAlwaysRun = value; |
415 | } | 415 | } |
416 | 416 | } | |
417 | /// <summary> | 417 | } |
418 | /// This works out to be the ClientView object associated with this avatar, or it's client connection manager | 418 | |
419 | /// </summary> | 419 | public byte State |
420 | private IClientAPI m_controllingClient; | 420 | { |
421 | 421 | get { return m_state; } | |
422 | protected PhysicsActor m_physicsActor; | 422 | set { m_state = value; } |
423 | 423 | } | |
424 | /// <value> | 424 | |
425 | /// The client controlling this presence | 425 | public uint AgentControlFlags |
426 | /// </value> | 426 | { |
427 | public IClientAPI ControllingClient | 427 | get { return (uint)m_AgentControlFlags; } |
428 | { | 428 | set { m_AgentControlFlags = (AgentManager.ControlFlags)value; } |
429 | get { return m_controllingClient; } | 429 | } |
430 | } | 430 | |
431 | 431 | /// <summary> | |
432 | public IClientCore ClientView | 432 | /// This works out to be the ClientView object associated with this avatar, or it's client connection manager |
433 | { | 433 | /// </summary> |
434 | get { return (IClientCore) m_controllingClient; } | 434 | private IClientAPI m_controllingClient; |
435 | } | 435 | |
436 | 436 | protected PhysicsActor m_physicsActor; | |
437 | protected Vector3 m_parentPosition; | 437 | |
438 | public Vector3 ParentPosition | 438 | /// <value> |
439 | { | 439 | /// The client controlling this presence |
440 | get { return m_parentPosition; } | 440 | /// </value> |
441 | set { m_parentPosition = value; } | 441 | public IClientAPI ControllingClient |
442 | } | 442 | { |
443 | 443 | get { return m_controllingClient; } | |
444 | /// <summary> | 444 | } |
445 | /// Position of this avatar relative to the region the avatar is in | 445 | |
446 | /// </summary> | 446 | public IClientCore ClientView |
447 | public override Vector3 AbsolutePosition | 447 | { |
448 | { | 448 | get { return (IClientCore) m_controllingClient; } |
449 | get | 449 | } |
450 | { | 450 | |
451 | PhysicsActor actor = m_physicsActor; | 451 | protected Vector3 m_parentPosition; |
452 | if (actor != null) | 452 | public Vector3 ParentPosition |
453 | m_pos = actor.Position; | 453 | { |
454 | 454 | get { return m_parentPosition; } | |
455 | return m_parentPosition + m_pos; | 455 | set { m_parentPosition = value; } |
456 | } | 456 | } |
457 | set | 457 | |
458 | { | 458 | /// <summary> |
459 | PhysicsActor actor = m_physicsActor; | 459 | /// Position of this avatar relative to the region the avatar is in |
460 | if (actor != null) | 460 | /// </summary> |
461 | { | 461 | public override Vector3 AbsolutePosition |
462 | try | 462 | { |
463 | { | 463 | get |
464 | lock (m_scene.SyncRoot) | 464 | { |
465 | m_physicsActor.Position = value; | 465 | PhysicsActor actor = m_physicsActor; |
466 | } | 466 | // if (actor != null) |
467 | catch (Exception e) | 467 | if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting! |
468 | { | 468 | m_pos = actor.Position; |
469 | m_log.Error("[SCENEPRESENCE]: ABSOLUTE POSITION " + e.Message); | 469 | |
470 | } | 470 | // If we're sitting, we need to update our position |
471 | } | 471 | if (m_parentID != 0) |
472 | 472 | { | |
473 | m_pos = value; | 473 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); |
474 | m_parentPosition = Vector3.Zero; | 474 | if (part != null) |
475 | } | 475 | m_parentPosition = part.AbsolutePosition; |
476 | } | 476 | } |
477 | 477 | ||
478 | public Vector3 OffsetPosition | 478 | return m_parentPosition + m_pos; |
479 | { | 479 | } |
480 | get { return m_pos; } | 480 | set |
481 | set { m_pos = value; } | 481 | { |
482 | } | 482 | PhysicsActor actor = m_physicsActor; |
483 | 483 | if (actor != null) | |
484 | /// <summary> | 484 | { |
485 | /// Current velocity of the avatar. | 485 | try |
486 | /// </summary> | 486 | { |
487 | public override Vector3 Velocity | 487 | lock (m_scene.SyncRoot) |
488 | { | 488 | m_physicsActor.Position = value; |
489 | get | 489 | } |
490 | { | 490 | catch (Exception e) |
491 | PhysicsActor actor = m_physicsActor; | 491 | { |
492 | if (actor != null) | 492 | m_log.Error("[SCENEPRESENCE]: ABSOLUTE POSITION " + e.Message); |
493 | m_velocity = actor.Velocity; | 493 | } |
494 | 494 | } | |
495 | return m_velocity; | 495 | |
496 | } | 496 | if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting! |
497 | set | 497 | m_pos = value; |
498 | { | 498 | m_parentPosition = Vector3.Zero; |
499 | PhysicsActor actor = m_physicsActor; | 499 | } |
500 | if (actor != null) | 500 | } |
501 | { | 501 | |
502 | try | 502 | public Vector3 OffsetPosition |
503 | { | 503 | { |
504 | lock (m_scene.SyncRoot) | 504 | get { return m_pos; } |
505 | actor.Velocity = value; | 505 | set { m_pos = value; } |
506 | } | 506 | } |
507 | catch (Exception e) | 507 | |
508 | { | 508 | /// <summary> |
509 | m_log.Error("[SCENEPRESENCE]: VELOCITY " + e.Message); | 509 | /// Current velocity of the avatar. |
510 | } | 510 | /// </summary> |
511 | } | 511 | public override Vector3 Velocity |
512 | 512 | { | |
513 | m_velocity = value; | 513 | get |
514 | } | 514 | { |
515 | } | 515 | PhysicsActor actor = m_physicsActor; |
516 | 516 | if (actor != null) | |
517 | public Quaternion Rotation | 517 | m_velocity = actor.Velocity; |
518 | { | 518 | |
519 | get { return m_bodyRot; } | 519 | return m_velocity; |
520 | set { m_bodyRot = value; } | 520 | } |
521 | } | 521 | set |
522 | 522 | { | |
523 | public Quaternion PreviousRotation | 523 | PhysicsActor actor = m_physicsActor; |
524 | { | 524 | if (actor != null) |
525 | get { return m_bodyRotPrevious; } | 525 | { |
526 | set { m_bodyRotPrevious = value; } | 526 | try |
527 | } | 527 | { |
528 | 528 | lock (m_scene.SyncRoot) | |
529 | /// <summary> | 529 | actor.Velocity = value; |
530 | /// If this is true, agent doesn't have a representation in this scene. | 530 | } |
531 | /// this is an agent 'looking into' this scene from a nearby scene(region) | 531 | catch (Exception e) |
532 | /// | 532 | { |
533 | /// if False, this agent has a representation in this scene | 533 | m_log.Error("[SCENEPRESENCE]: VELOCITY " + e.Message); |
534 | /// </summary> | 534 | } |
535 | private bool m_isChildAgent = true; | 535 | } |
536 | 536 | ||
537 | public bool IsChildAgent | 537 | m_velocity = value; |
538 | { | 538 | } |
539 | get { return m_isChildAgent; } | 539 | } |
540 | set { m_isChildAgent = value; } | 540 | |
541 | } | 541 | public Quaternion OffsetRotation |
542 | 542 | { | |
543 | private uint m_parentID; | 543 | get { return m_offsetRotation; } |
544 | 544 | set { m_offsetRotation = value; } | |
545 | public uint ParentID | 545 | } |
546 | { | 546 | |
547 | get { return m_parentID; } | 547 | public Quaternion Rotation |
548 | set { m_parentID = value; } | 548 | { |
549 | } | 549 | get { |
550 | public float Health | 550 | if (m_parentID != 0) |
551 | { | 551 | { |
552 | get { return m_health; } | 552 | if (m_offsetRotation != null) |
553 | set { m_health = value; } | 553 | { |
554 | } | 554 | return m_offsetRotation; |
555 | 555 | } | |
556 | /// <summary> | 556 | else |
557 | /// These are the region handles known by the avatar. | 557 | { |
558 | /// </summary> | 558 | return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); |
559 | public List<ulong> KnownChildRegionHandles | 559 | } |
560 | { | 560 | |
561 | get | 561 | } |
562 | { | 562 | else |
563 | if (m_knownChildRegions.Count == 0) | 563 | { |
564 | return new List<ulong>(); | 564 | return m_bodyRot; |
565 | else | 565 | } |
566 | return new List<ulong>(m_knownChildRegions.Keys); | 566 | } |
567 | } | 567 | set { |
568 | } | 568 | m_bodyRot = value; |
569 | 569 | if (m_parentID != 0) | |
570 | public Dictionary<ulong, string> KnownRegions | 570 | { |
571 | { | 571 | m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); |
572 | get { return m_knownChildRegions; } | 572 | } |
573 | set | 573 | } |
574 | { | 574 | } |
575 | m_knownChildRegions = value; | 575 | |
576 | } | 576 | public Quaternion PreviousRotation |
577 | } | 577 | { |
578 | 578 | get { return m_bodyRotPrevious; } | |
579 | public ISceneViewer SceneViewer | 579 | set { m_bodyRotPrevious = value; } |
580 | { | 580 | } |
581 | get { return m_sceneViewer; } | 581 | |
582 | } | 582 | /// <summary> |
583 | 583 | /// If this is true, agent doesn't have a representation in this scene. | |
584 | public void AdjustKnownSeeds() | 584 | /// this is an agent 'looking into' this scene from a nearby scene(region) |
585 | { | 585 | /// |
586 | Dictionary<ulong, string> seeds; | 586 | /// if False, this agent has a representation in this scene |
587 | 587 | /// </summary> | |
588 | if (Scene.CapsModule != null) | 588 | private bool m_isChildAgent = true; |
589 | seeds = Scene.CapsModule.GetChildrenSeeds(UUID); | 589 | |
590 | else | 590 | public bool IsChildAgent |
591 | seeds = new Dictionary<ulong, string>(); | 591 | { |
592 | 592 | get { return m_isChildAgent; } | |
593 | List<ulong> old = new List<ulong>(); | 593 | set { m_isChildAgent = value; } |
594 | foreach (ulong handle in seeds.Keys) | 594 | } |
595 | { | 595 | |
596 | uint x, y; | 596 | private uint m_parentID; |
597 | Utils.LongToUInts(handle, out x, out y); | 597 | |
598 | x = x / Constants.RegionSize; | 598 | |
599 | y = y / Constants.RegionSize; | 599 | private UUID m_linkedPrim; |
600 | if (Util.IsOutsideView(x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) | 600 | |
601 | { | 601 | public uint ParentID |
602 | old.Add(handle); | 602 | { |
603 | } | 603 | get { return m_parentID; } |
604 | } | 604 | set { m_parentID = value; } |
605 | DropOldNeighbours(old); | 605 | } |
606 | 606 | ||
607 | if (Scene.CapsModule != null) | 607 | public UUID LinkedPrim |
608 | Scene.CapsModule.SetChildrenSeed(UUID, seeds); | 608 | { |
609 | 609 | get { return m_linkedPrim; } | |
610 | KnownRegions = seeds; | 610 | set { m_linkedPrim = value; } |
611 | //m_log.Debug(" ++++++++++AFTER+++++++++++++ "); | 611 | } |
612 | //DumpKnownRegions(); | 612 | |
613 | } | 613 | public float Health |
614 | 614 | { | |
615 | public void DumpKnownRegions() | 615 | get { return m_health; } |
616 | { | 616 | set { m_health = value; } |
617 | m_log.Info("================ KnownRegions "+Scene.RegionInfo.RegionName+" ================"); | 617 | } |
618 | foreach (KeyValuePair<ulong, string> kvp in KnownRegions) | 618 | |
619 | { | 619 | /// <summary> |
620 | uint x, y; | 620 | /// These are the region handles known by the avatar. |
621 | Utils.LongToUInts(kvp.Key, out x, out y); | 621 | /// </summary> |
622 | x = x / Constants.RegionSize; | 622 | public List<ulong> KnownChildRegionHandles |
623 | y = y / Constants.RegionSize; | 623 | { |
624 | m_log.Info(" >> "+x+", "+y+": "+kvp.Value); | 624 | get |
625 | } | 625 | { |
626 | } | 626 | if (m_knownChildRegions.Count == 0) |
627 | 627 | return new List<ulong>(); | |
628 | private bool m_inTransit; | 628 | else |
629 | private bool m_mouseLook; | 629 | return new List<ulong>(m_knownChildRegions.Keys); |
630 | private bool m_leftButtonDown; | 630 | } |
631 | 631 | } | |
632 | public bool IsInTransit | 632 | |
633 | { | 633 | public Dictionary<ulong, string> KnownRegions |
634 | get { return m_inTransit; } | 634 | { |
635 | set { m_inTransit = value; } | 635 | get { return m_knownChildRegions; } |
636 | } | 636 | set |
637 | 637 | { | |
638 | public float SpeedModifier | 638 | m_knownChildRegions = value; |
639 | { | 639 | } |
640 | get { return m_speedModifier; } | 640 | } |
641 | set { m_speedModifier = value; } | 641 | |
642 | } | 642 | public ISceneViewer SceneViewer |
643 | 643 | { | |
644 | public bool ForceFly | 644 | get { return m_sceneViewer; } |
645 | { | 645 | } |
646 | get { return m_forceFly; } | 646 | |
647 | set { m_forceFly = value; } | 647 | public void AdjustKnownSeeds() |
648 | } | 648 | { |
649 | 649 | Dictionary<ulong, string> seeds; | |
650 | public bool FlyDisabled | 650 | |
651 | { | 651 | if (Scene.CapsModule != null) |
652 | get { return m_flyDisabled; } | 652 | seeds = Scene.CapsModule.GetChildrenSeeds(UUID); |
653 | set { m_flyDisabled = value; } | 653 | else |
654 | } | 654 | seeds = new Dictionary<ulong, string>(); |
655 | 655 | ||
656 | public string Viewer | 656 | List<ulong> old = new List<ulong>(); |
657 | { | 657 | foreach (ulong handle in seeds.Keys) |
658 | get { return m_scene.AuthenticateHandler.GetAgentCircuitData(ControllingClient.CircuitCode).Viewer; } | 658 | { |
659 | } | 659 | uint x, y; |
660 | 660 | Utils.LongToUInts(handle, out x, out y); | |
661 | #endregion | 661 | x = x / Constants.RegionSize; |
662 | 662 | y = y / Constants.RegionSize; | |
663 | #region Constructor(s) | 663 | if (Util.IsOutsideView(x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) |
664 | 664 | { | |
665 | public ScenePresence() | 665 | old.Add(handle); |
666 | { | 666 | } |
667 | m_sendCourseLocationsMethod = SendCoarseLocationsDefault; | 667 | } |
668 | CreateSceneViewer(); | 668 | DropOldNeighbours(old); |
669 | m_animator = new ScenePresenceAnimator(this); | 669 | |
670 | } | 670 | if (Scene.CapsModule != null) |
671 | 671 | Scene.CapsModule.SetChildrenSeed(UUID, seeds); | |
672 | private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() | 672 | |
673 | { | 673 | KnownRegions = seeds; |
674 | m_rootRegionHandle = reginfo.RegionHandle; | 674 | //m_log.Debug(" ++++++++++AFTER+++++++++++++ "); |
675 | m_controllingClient = client; | 675 | //DumpKnownRegions(); |
676 | m_firstname = m_controllingClient.FirstName; | 676 | } |
677 | m_lastname = m_controllingClient.LastName; | 677 | |
678 | m_name = String.Format("{0} {1}", m_firstname, m_lastname); | 678 | public void DumpKnownRegions() |
679 | m_scene = world; | 679 | { |
680 | m_uuid = client.AgentId; | 680 | m_log.Info("================ KnownRegions "+Scene.RegionInfo.RegionName+" ================"); |
681 | m_regionInfo = reginfo; | 681 | foreach (KeyValuePair<ulong, string> kvp in KnownRegions) |
682 | m_localId = m_scene.AllocateLocalId(); | 682 | { |
683 | 683 | uint x, y; | |
684 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); | 684 | Utils.LongToUInts(kvp.Key, out x, out y); |
685 | 685 | x = x / Constants.RegionSize; | |
686 | if (account != null) | 686 | y = y / Constants.RegionSize; |
687 | m_userLevel = account.UserLevel; | 687 | m_log.Info(" >> "+x+", "+y+": "+kvp.Value); |
688 | 688 | } | |
689 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); | 689 | } |
690 | if (gm != null) | 690 | |
691 | m_grouptitle = gm.GetGroupTitle(m_uuid); | 691 | private bool m_inTransit; |
692 | 692 | private bool m_mouseLook; | |
693 | m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); | 693 | private bool m_leftButtonDown; |
694 | 694 | ||
695 | AbsolutePosition = posLastSignificantMove = m_CameraCenter = | 695 | public bool IsInTransit |
696 | m_lastCameraCenter = m_controllingClient.StartPos; | 696 | { |
697 | 697 | get { return m_inTransit; } | |
698 | m_reprioritization_timer = new Timer(world.ReprioritizationInterval); | 698 | set { m_inTransit = value; } |
699 | m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize); | 699 | } |
700 | m_reprioritization_timer.AutoReset = false; | 700 | |
701 | 701 | public float SpeedModifier | |
702 | AdjustKnownSeeds(); | 702 | { |
703 | 703 | get { return m_speedModifier; } | |
704 | // TODO: I think, this won't send anything, as we are still a child here... | 704 | set { m_speedModifier = value; } |
705 | Animator.TrySetMovementAnimation("STAND"); | 705 | } |
706 | 706 | ||
707 | // we created a new ScenePresence (a new child agent) in a fresh region. | 707 | public bool ForceFly |
708 | // Request info about all the (root) agents in this region | 708 | { |
709 | // Note: This won't send data *to* other clients in that region (children don't send) | 709 | get { return m_forceFly; } |
710 | SendInitialFullUpdateToAllClients(); | 710 | set { m_forceFly = value; } |
711 | 711 | } | |
712 | RegisterToEvents(); | 712 | |
713 | SetDirectionVectors(); | 713 | public bool FlyDisabled |
714 | } | 714 | { |
715 | 715 | get { return m_flyDisabled; } | |
716 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, | 716 | set { m_flyDisabled = value; } |
717 | AvatarWearable[] wearables) | 717 | } |
718 | : this(client, world, reginfo) | 718 | |
719 | { | 719 | public string Viewer |
720 | m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); | 720 | { |
721 | } | 721 | get { return m_scene.AuthenticateHandler.GetAgentCircuitData(ControllingClient.CircuitCode).Viewer; } |
722 | 722 | } | |
723 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) | 723 | |
724 | : this(client, world, reginfo) | 724 | #endregion |
725 | { | 725 | |
726 | m_appearance = appearance; | 726 | #region Constructor(s) |
727 | } | 727 | |
728 | 728 | public ScenePresence() | |
729 | private void CreateSceneViewer() | 729 | { |
730 | { | 730 | m_sendCourseLocationsMethod = SendCoarseLocationsDefault; |
731 | m_sceneViewer = new SceneViewer(this); | 731 | CreateSceneViewer(); |
732 | } | 732 | m_animator = new ScenePresenceAnimator(this); |
733 | 733 | } | |
734 | public void RegisterToEvents() | 734 | |
735 | { | 735 | private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() |
736 | m_controllingClient.OnRequestWearables += SendWearables; | 736 | { |
737 | m_controllingClient.OnSetAppearance += SetAppearance; | 737 | m_rootRegionHandle = reginfo.RegionHandle; |
738 | m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; | 738 | m_controllingClient = client; |
739 | //m_controllingClient.OnCompleteMovementToRegion += SendInitialData; | 739 | m_firstname = m_controllingClient.FirstName; |
740 | m_controllingClient.OnAgentUpdate += HandleAgentUpdate; | 740 | m_lastname = m_controllingClient.LastName; |
741 | m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit; | 741 | m_name = String.Format("{0} {1}", m_firstname, m_lastname); |
742 | m_controllingClient.OnAgentSit += HandleAgentSit; | 742 | m_scene = world; |
743 | m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; | 743 | m_uuid = client.AgentId; |
744 | m_controllingClient.OnStartAnim += HandleStartAnim; | 744 | m_regionInfo = reginfo; |
745 | m_controllingClient.OnStopAnim += HandleStopAnim; | 745 | m_localId = m_scene.AllocateLocalId(); |
746 | m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; | 746 | |
747 | m_controllingClient.OnAutoPilotGo += DoAutoPilot; | 747 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); |
748 | m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition); | 748 | |
749 | 749 | if (account != null) | |
750 | // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); | 750 | m_userLevel = account.UserLevel; |
751 | // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); | 751 | |
752 | } | 752 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); |
753 | 753 | if (gm != null) | |
754 | private void SetDirectionVectors() | 754 | m_grouptitle = gm.GetGroupTitle(m_uuid); |
755 | { | 755 | |
756 | Dir_Vectors[0] = Vector3.UnitX; //FORWARD | 756 | m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); |
757 | Dir_Vectors[1] = -Vector3.UnitX; //BACK | 757 | |
758 | Dir_Vectors[2] = Vector3.UnitY; //LEFT | 758 | AbsolutePosition = posLastSignificantMove = m_CameraCenter = |
759 | Dir_Vectors[3] = -Vector3.UnitY; //RIGHT | 759 | m_lastCameraCenter = m_controllingClient.StartPos; |
760 | Dir_Vectors[4] = Vector3.UnitZ; //UP | 760 | |
761 | Dir_Vectors[5] = -Vector3.UnitZ; //DOWN | 761 | m_reprioritization_timer = new Timer(world.ReprioritizationInterval); |
762 | Dir_Vectors[8] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge | 762 | m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize); |
763 | Dir_Vectors[6] = Vector3.UnitX*2; //FORWARD | 763 | m_reprioritization_timer.AutoReset = false; |
764 | Dir_Vectors[7] = -Vector3.UnitX; //BACK | 764 | |
765 | } | 765 | AdjustKnownSeeds(); |
766 | 766 | Animator.TrySetMovementAnimation("STAND"); | |
767 | private Vector3[] GetWalkDirectionVectors() | 767 | // we created a new ScenePresence (a new child agent) in a fresh region. |
768 | { | 768 | // Request info about all the (root) agents in this region |
769 | Vector3[] vector = new Vector3[9]; | 769 | // Note: This won't send data *to* other clients in that region (children don't send) |
770 | vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD | 770 | SendInitialFullUpdateToAllClients(); |
771 | vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK | 771 | RegisterToEvents(); |
772 | vector[2] = Vector3.UnitY; //LEFT | 772 | if (m_controllingClient != null) |
773 | vector[3] = -Vector3.UnitY; //RIGHT | 773 | { |
774 | vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP | 774 | m_controllingClient.ProcessPendingPackets(); |
775 | vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN | 775 | } |
776 | vector[8] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_Nudge | 776 | SetDirectionVectors(); |
777 | vector[6] = (new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z) * 2); //FORWARD Nudge | 777 | } |
778 | vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK Nudge | 778 | |
779 | return vector; | 779 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, |
780 | } | 780 | AvatarWearable[] wearables) |
781 | 781 | : this(client, world, reginfo) | |
782 | #endregion | 782 | { |
783 | 783 | m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); | |
784 | public uint GenerateClientFlags(UUID ObjectID) | 784 | } |
785 | { | 785 | |
786 | return m_scene.Permissions.GenerateClientFlags(m_uuid, ObjectID); | 786 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) |
787 | } | 787 | : this(client, world, reginfo) |
788 | 788 | { | |
789 | /// <summary> | 789 | m_appearance = appearance; |
790 | /// Send updates to the client about prims which have been placed on the update queue. We don't | 790 | } |
791 | /// necessarily send updates for all the parts on the queue, e.g. if an updates with a more recent | 791 | |
792 | /// timestamp has already been sent. | 792 | private void CreateSceneViewer() |
793 | /// </summary> | 793 | { |
794 | public void SendPrimUpdates() | 794 | m_sceneViewer = new SceneViewer(this); |
795 | { | 795 | } |
796 | m_perfMonMS = Util.EnvironmentTickCount(); | 796 | |
797 | 797 | public void RegisterToEvents() | |
798 | m_sceneViewer.SendPrimUpdates(); | 798 | { |
799 | 799 | m_controllingClient.OnRequestWearables += SendWearables; | |
800 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 800 | m_controllingClient.OnSetAppearance += SetAppearance; |
801 | } | 801 | m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; |
802 | 802 | //m_controllingClient.OnCompleteMovementToRegion += SendInitialData; | |
803 | #region Status Methods | 803 | m_controllingClient.OnAgentUpdate += HandleAgentUpdate; |
804 | 804 | m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit; | |
805 | /// <summary> | 805 | m_controllingClient.OnAgentSit += HandleAgentSit; |
806 | /// This turns a child agent, into a root agent | 806 | m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; |
807 | /// This is called when an agent teleports into a region, or if an | 807 | m_controllingClient.OnStartAnim += HandleStartAnim; |
808 | /// agent crosses into this region from a neighbor over the border | 808 | m_controllingClient.OnStopAnim += HandleStopAnim; |
809 | /// </summary> | 809 | m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; |
810 | public void MakeRootAgent(Vector3 pos, bool isFlying) | 810 | m_controllingClient.OnAutoPilotGo += DoAutoPilot; |
811 | { | 811 | m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition); |
812 | m_log.DebugFormat( | 812 | |
813 | "[SCENE]: Upgrading child to root agent for {0} in {1}", | 813 | // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); |
814 | Name, m_scene.RegionInfo.RegionName); | 814 | // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); |
815 | 815 | } | |
816 | //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); | 816 | |
817 | 817 | private void SetDirectionVectors() | |
818 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); | 818 | { |
819 | if (gm != null) | 819 | Dir_Vectors[0] = Vector3.UnitX; //FORWARD |
820 | m_grouptitle = gm.GetGroupTitle(m_uuid); | 820 | Dir_Vectors[1] = -Vector3.UnitX; //BACK |
821 | 821 | Dir_Vectors[2] = Vector3.UnitY; //LEFT | |
822 | m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; | 822 | Dir_Vectors[3] = -Vector3.UnitY; //RIGHT |
823 | 823 | Dir_Vectors[4] = Vector3.UnitZ; //UP | |
824 | m_scene.SetRootAgentScene(m_uuid); | 824 | Dir_Vectors[5] = -Vector3.UnitZ; //DOWN |
825 | 825 | Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE | |
826 | // Moved this from SendInitialData to ensure that m_appearance is initialized | 826 | Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE |
827 | // before the inventory is processed in MakeRootAgent. This fixes a race condition | 827 | Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE |
828 | // related to the handling of attachments | 828 | Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE |
829 | //m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); | 829 | Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge |
830 | if (m_scene.TestBorderCross(pos, Cardinals.E)) | 830 | } |
831 | { | 831 | |
832 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); | 832 | private Vector3[] GetWalkDirectionVectors() |
833 | pos.X = crossedBorder.BorderLine.Z - 1; | 833 | { |
834 | } | 834 | Vector3[] vector = new Vector3[11]; |
835 | 835 | vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD | |
836 | if (m_scene.TestBorderCross(pos, Cardinals.N)) | 836 | vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK |
837 | { | 837 | vector[2] = Vector3.UnitY; //LEFT |
838 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); | 838 | vector[3] = -Vector3.UnitY; //RIGHT |
839 | pos.Y = crossedBorder.BorderLine.Z - 1; | 839 | vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP |
840 | } | 840 | vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN |
841 | 841 | vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE | |
842 | if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) | 842 | vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE |
843 | { | 843 | vector[8] = Vector3.UnitY; //LEFT_NUDGE |
844 | m_log.WarnFormat( | 844 | vector[9] = -Vector3.UnitY; //RIGHT_NUDGE |
845 | "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", | 845 | vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE |
846 | pos, Name, UUID); | 846 | return vector; |
847 | 847 | } | |
848 | if (pos.X < 0f) pos.X = 0f; | 848 | |
849 | if (pos.Y < 0f) pos.Y = 0f; | 849 | private bool[] GetDirectionIsNudge() |
850 | if (pos.Z < 0f) pos.Z = 0f; | 850 | { |
851 | } | 851 | bool[] isNudge = new bool[11]; |
852 | 852 | isNudge[0] = false; //FORWARD | |
853 | float localAVHeight = 1.56f; | 853 | isNudge[1] = false; //BACK |
854 | if (m_avHeight != 127.0f) | 854 | isNudge[2] = false; //LEFT |
855 | { | 855 | isNudge[3] = false; //RIGHT |
856 | localAVHeight = m_avHeight; | 856 | isNudge[4] = false; //UP |
857 | } | 857 | isNudge[5] = false; //DOWN |
858 | 858 | isNudge[6] = true; //FORWARD_NUDGE | |
859 | float posZLimit = 0; | 859 | isNudge[7] = true; //BACK_NUDGE |
860 | 860 | isNudge[8] = true; //LEFT_NUDGE | |
861 | if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) | 861 | isNudge[9] = true; //RIGHT_NUDGE |
862 | posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; | 862 | isNudge[10] = true; //DOWN_Nudge |
863 | 863 | return isNudge; | |
864 | float newPosZ = posZLimit + localAVHeight / 2; | 864 | } |
865 | if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) | 865 | |
866 | { | 866 | |
867 | pos.Z = newPosZ; | 867 | #endregion |
868 | } | 868 | |
869 | AbsolutePosition = pos; | 869 | public uint GenerateClientFlags(UUID ObjectID) |
870 | 870 | { | |
871 | AddToPhysicalScene(isFlying); | 871 | return m_scene.Permissions.GenerateClientFlags(m_uuid, ObjectID); |
872 | 872 | } | |
873 | if (m_forceFly) | 873 | |
874 | { | 874 | /// <summary> |
875 | m_physicsActor.Flying = true; | 875 | /// Send updates to the client about prims which have been placed on the update queue. We don't |
876 | } | 876 | /// necessarily send updates for all the parts on the queue, e.g. if an updates with a more recent |
877 | else if (m_flyDisabled) | 877 | /// timestamp has already been sent. |
878 | { | 878 | /// </summary> |
879 | m_physicsActor.Flying = false; | 879 | public void SendPrimUpdates() |
880 | } | 880 | { |
881 | 881 | m_perfMonMS = Util.EnvironmentTickCount(); | |
882 | if (m_appearance != null) | 882 | |
883 | { | 883 | m_sceneViewer.SendPrimUpdates(); |
884 | if (m_appearance.AvatarHeight > 0) | 884 | |
885 | SetHeight(m_appearance.AvatarHeight); | 885 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
886 | } | 886 | } |
887 | else | 887 | |
888 | { | 888 | #region Status Methods |
889 | m_log.ErrorFormat("[SCENE PRESENCE]: null appearance in MakeRoot in {0}", Scene.RegionInfo.RegionName); | 889 | |
890 | // emergency; this really shouldn't happen | 890 | /// <summary> |
891 | m_appearance = new AvatarAppearance(UUID); | 891 | /// This turns a child agent, into a root agent |
892 | } | 892 | /// This is called when an agent teleports into a region, or if an |
893 | 893 | /// agent crosses into this region from a neighbor over the border | |
894 | // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying | 894 | /// </summary> |
895 | // avatar to return to the standing position in mid-air. On login it looks like this is being sent | 895 | public void MakeRootAgent(Vector3 pos, bool isFlying) |
896 | // elsewhere anyway | 896 | { |
897 | // Animator.SendAnimPack(); | 897 | m_log.DebugFormat( |
898 | 898 | "[SCENE]: Upgrading child to root agent for {0} in {1}", | |
899 | m_scene.SwapRootAgentCount(false); | 899 | Name, m_scene.RegionInfo.RegionName); |
900 | 900 | ||
901 | //CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); | 901 | //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); |
902 | //if (userInfo != null) | 902 | |
903 | // userInfo.FetchInventory(); | 903 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); |
904 | //else | 904 | if (gm != null) |
905 | // m_log.ErrorFormat("[SCENE]: Could not find user info for {0} when making it a root agent", m_uuid); | 905 | m_grouptitle = gm.GetGroupTitle(m_uuid); |
906 | 906 | ||
907 | // On the next prim update, all objects will be sent | 907 | m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; |
908 | // | 908 | m_scene.SetRootAgentScene(m_uuid); |
909 | m_sceneViewer.Reset(); | 909 | |
910 | 910 | // Moved this from SendInitialData to ensure that m_appearance is initialized | |
911 | m_isChildAgent = false; | 911 | // before the inventory is processed in MakeRootAgent. This fixes a race condition |
912 | 912 | // related to the handling of attachments | |
913 | // send the animations of the other presences to me | 913 | //m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); |
914 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) | 914 | if (m_scene.TestBorderCross(pos, Cardinals.E)) |
915 | { | 915 | { |
916 | if (presence != this) | 916 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); |
917 | presence.Animator.SendAnimPackToClient(ControllingClient); | 917 | pos.X = crossedBorder.BorderLine.Z - 1; |
918 | }); | 918 | } |
919 | 919 | ||
920 | m_scene.EventManager.TriggerOnMakeRootAgent(this); | 920 | if (m_scene.TestBorderCross(pos, Cardinals.N)) |
921 | } | 921 | { |
922 | 922 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); | |
923 | /// <summary> | 923 | pos.Y = crossedBorder.BorderLine.Z - 1; |
924 | /// This turns a root agent into a child agent | 924 | } |
925 | /// when an agent departs this region for a neighbor, this gets called. | 925 | |
926 | /// | 926 | //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet. |
927 | /// It doesn't get called for a teleport. Reason being, an agent that | 927 | //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent, |
928 | /// teleports out may not end up anywhere near this region | 928 | //they'll bypass the landing point. But I can't think of any decent way of fixing this. |
929 | /// </summary> | 929 | if (KnownChildRegionHandles.Count == 0) |
930 | public void MakeChildAgent() | 930 | { |
931 | { | 931 | ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y); |
932 | // It looks like m_animator is set to null somewhere, and MakeChild | 932 | if (land != null) |
933 | // is called after that. Probably in aborted teleports. | 933 | { |
934 | if (m_animator == null) | 934 | //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni. |
935 | m_animator = new ScenePresenceAnimator(this); | 935 | if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && UserLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid) |
936 | else | 936 | { |
937 | Animator.ResetAnimations(); | 937 | pos = land.LandData.UserLocation; |
938 | 938 | } | |
939 | // m_log.DebugFormat( | 939 | } |
940 | // "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", | 940 | } |
941 | // Name, UUID, m_scene.RegionInfo.RegionName); | 941 | |
942 | 942 | if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) | |
943 | // Don't zero out the velocity since this can cause problems when an avatar is making a region crossing, | 943 | { |
944 | // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated. | 944 | Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128); |
945 | //Velocity = new Vector3(0, 0, 0); | 945 | |
946 | 946 | if (pos.X < 0) | |
947 | m_isChildAgent = true; | 947 | { |
948 | m_scene.SwapRootAgentCount(true); | 948 | emergencyPos.X = (int)Constants.RegionSize + pos.X; |
949 | RemoveFromPhysicalScene(); | 949 | if (!(pos.Y < 0)) |
950 | 950 | emergencyPos.Y = pos.Y; | |
951 | // FIXME: Set m_rootRegionHandle to the region handle of the scene this agent is moving into | 951 | if (!(pos.Z < 0)) |
952 | 952 | emergencyPos.Z = pos.Z; | |
953 | m_scene.EventManager.TriggerOnMakeChildAgent(this); | 953 | } |
954 | } | 954 | if (pos.Y < 0) |
955 | 955 | { | |
956 | /// <summary> | 956 | emergencyPos.Y = (int)Constants.RegionSize + pos.Y; |
957 | /// Removes physics plugin scene representation of this agent if it exists. | 957 | if (!(pos.X < 0)) |
958 | /// </summary> | 958 | emergencyPos.X = pos.X; |
959 | private void RemoveFromPhysicalScene() | 959 | if (!(pos.Z < 0)) |
960 | { | 960 | emergencyPos.Z = pos.Z; |
961 | if (PhysicsActor != null) | 961 | } |
962 | { | 962 | if (pos.Z < 0) |
963 | m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; | 963 | { |
964 | m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; | 964 | emergencyPos.Z = 128; |
965 | m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); | 965 | if (!(pos.Y < 0)) |
966 | m_physicsActor.UnSubscribeEvents(); | 966 | emergencyPos.Y = pos.Y; |
967 | m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; | 967 | if (!(pos.X < 0)) |
968 | PhysicsActor = null; | 968 | emergencyPos.X = pos.X; |
969 | } | 969 | } |
970 | } | 970 | } |
971 | 971 | ||
972 | /// <summary> | 972 | if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) |
973 | /// | 973 | { |
974 | /// </summary> | 974 | m_log.WarnFormat( |
975 | /// <param name="pos"></param> | 975 | "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", |
976 | public void Teleport(Vector3 pos) | 976 | pos, Name, UUID); |
977 | { | 977 | |
978 | bool isFlying = false; | 978 | if (pos.X < 0f) pos.X = 0f; |
979 | if (m_physicsActor != null) | 979 | if (pos.Y < 0f) pos.Y = 0f; |
980 | isFlying = m_physicsActor.Flying; | 980 | if (pos.Z < 0f) pos.Z = 0f; |
981 | 981 | } | |
982 | RemoveFromPhysicalScene(); | 982 | |
983 | Velocity = Vector3.Zero; | 983 | float localAVHeight = 1.56f; |
984 | AbsolutePosition = pos; | 984 | if (m_avHeight != 127.0f) |
985 | AddToPhysicalScene(isFlying); | 985 | { |
986 | if (m_appearance != null) | 986 | localAVHeight = m_avHeight; |
987 | { | 987 | } |
988 | if (m_appearance.AvatarHeight > 0) | 988 | |
989 | SetHeight(m_appearance.AvatarHeight); | 989 | float posZLimit = 0; |
990 | } | 990 | |
991 | 991 | if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) | |
992 | SendTerseUpdateToAllClients(); | 992 | posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; |
993 | } | 993 | |
994 | 994 | float newPosZ = posZLimit + localAVHeight / 2; | |
995 | public void TeleportWithMomentum(Vector3 pos) | 995 | if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) |
996 | { | 996 | { |
997 | bool isFlying = false; | 997 | pos.Z = newPosZ; |
998 | if (m_physicsActor != null) | 998 | } |
999 | isFlying = m_physicsActor.Flying; | 999 | AbsolutePosition = pos; |
1000 | 1000 | ||
1001 | RemoveFromPhysicalScene(); | 1001 | AddToPhysicalScene(isFlying); |
1002 | AbsolutePosition = pos; | 1002 | |
1003 | AddToPhysicalScene(isFlying); | 1003 | if (m_forceFly) |
1004 | if (m_appearance != null) | 1004 | { |
1005 | { | 1005 | m_physicsActor.Flying = true; |
1006 | if (m_appearance.AvatarHeight > 0) | 1006 | } |
1007 | SetHeight(m_appearance.AvatarHeight); | 1007 | else if (m_flyDisabled) |
1008 | } | 1008 | { |
1009 | 1009 | m_physicsActor.Flying = false; | |
1010 | SendTerseUpdateToAllClients(); | 1010 | } |
1011 | } | 1011 | |
1012 | 1012 | if (m_appearance != null) | |
1013 | /// <summary> | 1013 | { |
1014 | /// | 1014 | if (m_appearance.AvatarHeight > 0) |
1015 | /// </summary> | 1015 | SetHeight(m_appearance.AvatarHeight); |
1016 | public void StopMovement() | 1016 | } |
1017 | { | 1017 | else |
1018 | } | 1018 | { |
1019 | 1019 | m_log.ErrorFormat("[SCENE PRESENCE]: null appearance in MakeRoot in {0}", Scene.RegionInfo.RegionName); | |
1020 | public void StopFlying() | 1020 | // emergency; this really shouldn't happen |
1021 | { | 1021 | m_appearance = new AvatarAppearance(UUID); |
1022 | ControllingClient.StopFlying(this); | 1022 | } |
1023 | } | 1023 | |
1024 | 1024 | // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying | |
1025 | public void AddNeighbourRegion(ulong regionHandle, string cap) | 1025 | // avatar to return to the standing position in mid-air. On login it looks like this is being sent |
1026 | { | 1026 | // elsewhere anyway |
1027 | lock (m_knownChildRegions) | 1027 | // Animator.SendAnimPack(); |
1028 | { | 1028 | |
1029 | if (!m_knownChildRegions.ContainsKey(regionHandle)) | 1029 | m_scene.SwapRootAgentCount(false); |
1030 | { | 1030 | |
1031 | uint x, y; | 1031 | //CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); |
1032 | Utils.LongToUInts(regionHandle, out x, out y); | 1032 | //if (userInfo != null) |
1033 | m_knownChildRegions.Add(regionHandle, cap); | 1033 | // userInfo.FetchInventory(); |
1034 | } | 1034 | //else |
1035 | } | 1035 | // m_log.ErrorFormat("[SCENE]: Could not find user info for {0} when making it a root agent", m_uuid); |
1036 | } | 1036 | |
1037 | 1037 | // On the next prim update, all objects will be sent | |
1038 | public void RemoveNeighbourRegion(ulong regionHandle) | 1038 | // |
1039 | { | 1039 | m_sceneViewer.Reset(); |
1040 | lock (m_knownChildRegions) | 1040 | |
1041 | { | 1041 | m_isChildAgent = false; |
1042 | if (m_knownChildRegions.ContainsKey(regionHandle)) | 1042 | |
1043 | { | 1043 | // send the animations of the other presences to me |
1044 | m_knownChildRegions.Remove(regionHandle); | 1044 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) |
1045 | //m_log.Debug(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count); | 1045 | { |
1046 | } | 1046 | if (presence != this) |
1047 | } | 1047 | presence.Animator.SendAnimPackToClient(ControllingClient); |
1048 | } | 1048 | }); |
1049 | 1049 | ||
1050 | public void DropOldNeighbours(List<ulong> oldRegions) | 1050 | m_scene.EventManager.TriggerOnMakeRootAgent(this); |
1051 | { | 1051 | } |
1052 | foreach (ulong handle in oldRegions) | 1052 | |
1053 | { | 1053 | /// <summary> |
1054 | RemoveNeighbourRegion(handle); | 1054 | /// This turns a root agent into a child agent |
1055 | Scene.CapsModule.DropChildSeed(UUID, handle); | 1055 | /// when an agent departs this region for a neighbor, this gets called. |
1056 | } | 1056 | /// |
1057 | } | 1057 | /// It doesn't get called for a teleport. Reason being, an agent that |
1058 | 1058 | /// teleports out may not end up anywhere near this region | |
1059 | public List<ulong> GetKnownRegionList() | 1059 | /// </summary> |
1060 | { | 1060 | public void MakeChildAgent() |
1061 | return new List<ulong>(m_knownChildRegions.Keys); | 1061 | { |
1062 | } | 1062 | // It looks like m_animator is set to null somewhere, and MakeChild |
1063 | 1063 | // is called after that. Probably in aborted teleports. | |
1064 | #endregion | 1064 | if (m_animator == null) |
1065 | 1065 | m_animator = new ScenePresenceAnimator(this); | |
1066 | #region Event Handlers | 1066 | else |
1067 | 1067 | Animator.ResetAnimations(); | |
1068 | /// <summary> | 1068 | |
1069 | /// Sets avatar height in the phyiscs plugin | 1069 | // m_log.DebugFormat( |
1070 | /// </summary> | 1070 | // "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", |
1071 | internal void SetHeight(float height) | 1071 | // Name, UUID, m_scene.RegionInfo.RegionName); |
1072 | { | 1072 | |
1073 | m_avHeight = height; | 1073 | // Don't zero out the velocity since this can cause problems when an avatar is making a region crossing, |
1074 | if (PhysicsActor != null && !IsChildAgent) | 1074 | // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated. |
1075 | { | 1075 | //Velocity = new Vector3(0, 0, 0); |
1076 | Vector3 SetSize = new Vector3(0.45f, 0.6f, m_avHeight); | 1076 | |
1077 | PhysicsActor.Size = SetSize; | 1077 | m_isChildAgent = true; |
1078 | } | 1078 | m_scene.SwapRootAgentCount(true); |
1079 | } | 1079 | RemoveFromPhysicalScene(); |
1080 | 1080 | ||
1081 | /// <summary> | 1081 | // FIXME: Set m_rootRegionHandle to the region handle of the scene this agent is moving into |
1082 | /// Complete Avatar's movement into the region. | 1082 | |
1083 | /// This is called upon a very important packet sent from the client, | 1083 | m_scene.EventManager.TriggerOnMakeChildAgent(this); |
1084 | /// so it's client-controlled. Never call this method directly. | 1084 | } |
1085 | /// </summary> | 1085 | |
1086 | public void CompleteMovement(IClientAPI client) | 1086 | /// <summary> |
1087 | { | 1087 | /// Removes physics plugin scene representation of this agent if it exists. |
1088 | //m_log.Debug("[SCENE PRESENCE]: CompleteMovement"); | 1088 | /// </summary> |
1089 | 1089 | private void RemoveFromPhysicalScene() | |
1090 | Vector3 look = Velocity; | 1090 | { |
1091 | if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) | 1091 | if (PhysicsActor != null) |
1092 | { | 1092 | { |
1093 | look = new Vector3(0.99f, 0.042f, 0); | 1093 | m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; |
1094 | } | 1094 | m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; |
1095 | 1095 | m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); | |
1096 | // Prevent teleporting to an underground location | 1096 | m_physicsActor.UnSubscribeEvents(); |
1097 | // (may crash client otherwise) | 1097 | m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; |
1098 | // | 1098 | PhysicsActor = null; |
1099 | Vector3 pos = AbsolutePosition; | 1099 | } |
1100 | float ground = m_scene.GetGroundHeight(pos.X, pos.Y); | 1100 | } |
1101 | if (pos.Z < ground + 1.5f) | 1101 | |
1102 | { | 1102 | /// <summary> |
1103 | pos.Z = ground + 1.5f; | 1103 | /// |
1104 | AbsolutePosition = pos; | 1104 | /// </summary> |
1105 | } | 1105 | /// <param name="pos"></param> |
1106 | 1106 | public void Teleport(Vector3 pos) | |
1107 | m_isChildAgent = false; | 1107 | { |
1108 | bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); | 1108 | bool isFlying = false; |
1109 | MakeRootAgent(AbsolutePosition, m_flying); | 1109 | |
1110 | 1110 | if (m_physicsActor != null) | |
1111 | if ((m_callbackURI != null) && !m_callbackURI.Equals("")) | 1111 | isFlying = m_physicsActor.Flying; |
1112 | { | 1112 | |
1113 | m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); | 1113 | RemoveFromPhysicalScene(); |
1114 | Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI); | 1114 | Velocity = Vector3.Zero; |
1115 | m_callbackURI = null; | 1115 | AbsolutePosition = pos; |
1116 | } | 1116 | AddToPhysicalScene(isFlying); |
1117 | 1117 | if (m_appearance != null) | |
1118 | //m_log.DebugFormat("Completed movement"); | 1118 | { |
1119 | 1119 | if (m_appearance.AvatarHeight > 0) | |
1120 | m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); | 1120 | SetHeight(m_appearance.AvatarHeight); |
1121 | SendInitialData(); | 1121 | } |
1122 | 1122 | ||
1123 | // Create child agents in neighbouring regions | 1123 | SendTerseUpdateToAllClients(); |
1124 | if (!m_isChildAgent) | 1124 | |
1125 | { | 1125 | } |
1126 | IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); | 1126 | |
1127 | if (m_agentTransfer != null) | 1127 | public void TeleportWithMomentum(Vector3 pos) |
1128 | m_agentTransfer.EnableChildAgents(this); | 1128 | { |
1129 | else | 1129 | bool isFlying = false; |
1130 | m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active"); | 1130 | if (m_physicsActor != null) |
1131 | 1131 | isFlying = m_physicsActor.Flying; | |
1132 | IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); | 1132 | |
1133 | if (friendsModule != null) | 1133 | RemoveFromPhysicalScene(); |
1134 | friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); | 1134 | AbsolutePosition = pos; |
1135 | } | 1135 | AddToPhysicalScene(isFlying); |
1136 | 1136 | if (m_appearance != null) | |
1137 | } | 1137 | { |
1138 | 1138 | if (m_appearance.AvatarHeight > 0) | |
1139 | /// <summary> | 1139 | SetHeight(m_appearance.AvatarHeight); |
1140 | /// Callback for the Camera view block check. Gets called with the results of the camera view block test | 1140 | } |
1141 | /// hitYN is true when there's something in the way. | 1141 | |
1142 | /// </summary> | 1142 | SendTerseUpdateToAllClients(); |
1143 | /// <param name="hitYN"></param> | 1143 | } |
1144 | /// <param name="collisionPoint"></param> | 1144 | |
1145 | /// <param name="localid"></param> | 1145 | /// <summary> |
1146 | /// <param name="distance"></param> | 1146 | /// |
1147 | public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) | 1147 | /// </summary> |
1148 | { | 1148 | public void StopMovement() |
1149 | const float POSITION_TOLERANCE = 0.02f; | 1149 | { |
1150 | const float VELOCITY_TOLERANCE = 0.02f; | 1150 | } |
1151 | const float ROTATION_TOLERANCE = 0.02f; | 1151 | |
1152 | 1152 | public void StopFlying() | |
1153 | if (m_followCamAuto) | 1153 | { |
1154 | { | 1154 | ControllingClient.StopFlying(this); |
1155 | if (hitYN) | 1155 | } |
1156 | { | 1156 | |
1157 | CameraConstraintActive = true; | 1157 | public void AddNeighbourRegion(ulong regionHandle, string cap) |
1158 | //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); | 1158 | { |
1159 | 1159 | lock (m_knownChildRegions) | |
1160 | Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); | 1160 | { |
1161 | ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); | 1161 | if (!m_knownChildRegions.ContainsKey(regionHandle)) |
1162 | } | 1162 | { |
1163 | else | 1163 | uint x, y; |
1164 | { | 1164 | Utils.LongToUInts(regionHandle, out x, out y); |
1165 | if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || | 1165 | m_knownChildRegions.Add(regionHandle, cap); |
1166 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || | 1166 | } |
1167 | !m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) | 1167 | } |
1168 | { | 1168 | } |
1169 | if (CameraConstraintActive) | 1169 | |
1170 | { | 1170 | public void RemoveNeighbourRegion(ulong regionHandle) |
1171 | ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); | 1171 | { |
1172 | CameraConstraintActive = false; | 1172 | lock (m_knownChildRegions) |
1173 | } | 1173 | { |
1174 | } | 1174 | if (m_knownChildRegions.ContainsKey(regionHandle)) |
1175 | } | 1175 | { |
1176 | } | 1176 | m_knownChildRegions.Remove(regionHandle); |
1177 | } | 1177 | //m_log.Debug(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count); |
1178 | 1178 | } | |
1179 | /// <summary> | 1179 | } |
1180 | /// This is the event handler for client movement. If a client is moving, this event is triggering. | 1180 | } |
1181 | /// </summary> | 1181 | |
1182 | public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) | 1182 | public void DropOldNeighbours(List<ulong> oldRegions) |
1183 | { | 1183 | { |
1184 | //if (m_isChildAgent) | 1184 | foreach (ulong handle in oldRegions) |
1185 | //{ | 1185 | { |
1186 | // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); | 1186 | RemoveNeighbourRegion(handle); |
1187 | // return; | 1187 | Scene.CapsModule.DropChildSeed(UUID, handle); |
1188 | //} | 1188 | } |
1189 | 1189 | } | |
1190 | m_perfMonMS = Util.EnvironmentTickCount(); | 1190 | |
1191 | 1191 | public List<ulong> GetKnownRegionList() | |
1192 | ++m_movementUpdateCount; | 1192 | { |
1193 | if (m_movementUpdateCount < 1) | 1193 | return new List<ulong>(m_knownChildRegions.Keys); |
1194 | m_movementUpdateCount = 1; | 1194 | } |
1195 | 1195 | ||
1196 | #region Sanity Checking | 1196 | #endregion |
1197 | 1197 | ||
1198 | // This is irritating. Really. | 1198 | #region Event Handlers |
1199 | if (!AbsolutePosition.IsFinite()) | 1199 | |
1200 | { | 1200 | /// <summary> |
1201 | RemoveFromPhysicalScene(); | 1201 | /// Sets avatar height in the phyiscs plugin |
1202 | m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); | 1202 | /// </summary> |
1203 | 1203 | internal void SetHeight(float height) | |
1204 | m_pos = m_LastFinitePos; | 1204 | { |
1205 | if (!m_pos.IsFinite()) | 1205 | m_avHeight = height; |
1206 | { | 1206 | if (PhysicsActor != null && !IsChildAgent) |
1207 | m_pos.X = 127f; | 1207 | { |
1208 | m_pos.Y = 127f; | 1208 | Vector3 SetSize = new Vector3(0.45f, 0.6f, m_avHeight); |
1209 | m_pos.Z = 127f; | 1209 | PhysicsActor.Size = SetSize; |
1210 | m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999903"); | 1210 | } |
1211 | } | 1211 | } |
1212 | 1212 | ||
1213 | AddToPhysicalScene(false); | 1213 | /// <summary> |
1214 | } | 1214 | /// Complete Avatar's movement into the region. |
1215 | else | 1215 | /// This is called upon a very important packet sent from the client, |
1216 | { | 1216 | /// so it's client-controlled. Never call this method directly. |
1217 | m_LastFinitePos = m_pos; | 1217 | /// </summary> |
1218 | } | 1218 | public void CompleteMovement(IClientAPI client) |
1219 | 1219 | { | |
1220 | #endregion Sanity Checking | 1220 | //m_log.Debug("[SCENE PRESENCE]: CompleteMovement"); |
1221 | 1221 | ||
1222 | #region Inputs | 1222 | Vector3 look = Velocity; |
1223 | 1223 | if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) | |
1224 | AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; | 1224 | { |
1225 | Quaternion bodyRotation = agentData.BodyRotation; | 1225 | look = new Vector3(0.99f, 0.042f, 0); |
1226 | 1226 | } | |
1227 | // Camera location in world. We'll need to raytrace | 1227 | |
1228 | // from this location from time to time. | 1228 | // Prevent teleporting to an underground location |
1229 | m_CameraCenter = agentData.CameraCenter; | 1229 | // (may crash client otherwise) |
1230 | if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance) | 1230 | // |
1231 | { | 1231 | Vector3 pos = AbsolutePosition; |
1232 | ReprioritizeUpdates(); | 1232 | float ground = m_scene.GetGroundHeight(pos.X, pos.Y); |
1233 | m_lastCameraCenter = m_CameraCenter; | 1233 | if (pos.Z < ground + 1.5f) |
1234 | } | 1234 | { |
1235 | 1235 | pos.Z = ground + 1.5f; | |
1236 | // Use these three vectors to figure out what the agent is looking at | 1236 | AbsolutePosition = pos; |
1237 | // Convert it to a Matrix and/or Quaternion | 1237 | } |
1238 | m_CameraAtAxis = agentData.CameraAtAxis; | 1238 | m_isChildAgent = false; |
1239 | m_CameraLeftAxis = agentData.CameraLeftAxis; | 1239 | bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); |
1240 | m_CameraUpAxis = agentData.CameraUpAxis; | 1240 | MakeRootAgent(AbsolutePosition, m_flying); |
1241 | 1241 | ||
1242 | // The Agent's Draw distance setting | 1242 | if ((m_callbackURI != null) && !m_callbackURI.Equals("")) |
1243 | m_DrawDistance = agentData.Far; | 1243 | { |
1244 | 1244 | m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); | |
1245 | // Check if Client has camera in 'follow cam' or 'build' mode. | 1245 | Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI); |
1246 | Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); | 1246 | m_callbackURI = null; |
1247 | 1247 | } | |
1248 | m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) | 1248 | |
1249 | && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; | 1249 | //m_log.DebugFormat("Completed movement"); |
1250 | 1250 | ||
1251 | m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; | 1251 | m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); |
1252 | m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; | 1252 | SendInitialData(); |
1253 | 1253 | ||
1254 | #endregion Inputs | 1254 | // Create child agents in neighbouring regions |
1255 | 1255 | if (!m_isChildAgent) | |
1256 | if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) | 1256 | { |
1257 | { | 1257 | IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); |
1258 | StandUp(); | 1258 | if (m_agentTransfer != null) |
1259 | } | 1259 | m_agentTransfer.EnableChildAgents(this); |
1260 | 1260 | else | |
1261 | //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); | 1261 | m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active"); |
1262 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view | 1262 | |
1263 | if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) | 1263 | IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); |
1264 | { | 1264 | if (friendsModule != null) |
1265 | if (m_followCamAuto) | 1265 | friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); |
1266 | { | 1266 | } |
1267 | Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; | 1267 | |
1268 | m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); | 1268 | } |
1269 | } | 1269 | |
1270 | } | 1270 | /// <summary> |
1271 | 1271 | /// Callback for the Camera view block check. Gets called with the results of the camera view block test | |
1272 | lock (scriptedcontrols) | 1272 | /// hitYN is true when there's something in the way. |
1273 | { | 1273 | /// </summary> |
1274 | if (scriptedcontrols.Count > 0) | 1274 | /// <param name="hitYN"></param> |
1275 | { | 1275 | /// <param name="collisionPoint"></param> |
1276 | SendControlToScripts((uint)flags); | 1276 | /// <param name="localid"></param> |
1277 | flags = RemoveIgnoredControls(flags, IgnoredControls); | 1277 | /// <param name="distance"></param> |
1278 | } | 1278 | public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) |
1279 | } | 1279 | { |
1280 | 1280 | const float POSITION_TOLERANCE = 0.02f; | |
1281 | if (m_autopilotMoving) | 1281 | const float VELOCITY_TOLERANCE = 0.02f; |
1282 | CheckAtSitTarget(); | 1282 | const float ROTATION_TOLERANCE = 0.02f; |
1283 | 1283 | ||
1284 | if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) | 1284 | if (m_followCamAuto) |
1285 | { | 1285 | { |
1286 | // TODO: This doesn't prevent the user from walking yet. | 1286 | if (hitYN) |
1287 | // Setting parent ID would fix this, if we knew what value | 1287 | { |
1288 | // to use. Or we could add a m_isSitting variable. | 1288 | CameraConstraintActive = true; |
1289 | //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); | 1289 | //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); |
1290 | SitGround = true; | 1290 | |
1291 | } | 1291 | Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); |
1292 | 1292 | ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); | |
1293 | // In the future, these values might need to go global. | 1293 | } |
1294 | // Here's where you get them. | 1294 | else |
1295 | m_AgentControlFlags = flags; | 1295 | { |
1296 | m_headrotation = agentData.HeadRotation; | 1296 | if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || |
1297 | m_state = agentData.State; | 1297 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || |
1298 | 1298 | !m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) | |
1299 | PhysicsActor actor = PhysicsActor; | 1299 | { |
1300 | if (actor == null) | 1300 | if (CameraConstraintActive) |
1301 | { | 1301 | { |
1302 | return; | 1302 | ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); |
1303 | } | 1303 | CameraConstraintActive = false; |
1304 | 1304 | } | |
1305 | bool update_movementflag = false; | 1305 | } |
1306 | 1306 | } | |
1307 | if (m_allowMovement && !SitGround) | 1307 | } |
1308 | { | 1308 | } |
1309 | if (agentData.UseClientAgentPosition) | 1309 | |
1310 | { | 1310 | /// <summary> |
1311 | m_moveToPositionInProgress = (agentData.ClientAgentPosition - AbsolutePosition).Length() > 0.2f; | 1311 | /// This is the event handler for client movement. If a client is moving, this event is triggering. |
1312 | m_moveToPositionTarget = agentData.ClientAgentPosition; | 1312 | /// </summary> |
1313 | } | 1313 | public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) |
1314 | 1314 | { | |
1315 | int i = 0; | 1315 | //if (m_isChildAgent) |
1316 | 1316 | //{ | |
1317 | bool update_rotation = false; | 1317 | // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); |
1318 | bool DCFlagKeyPressed = false; | 1318 | // return; |
1319 | Vector3 agent_control_v3 = Vector3.Zero; | 1319 | //} |
1320 | Quaternion q = bodyRotation; | 1320 | |
1321 | 1321 | m_perfMonMS = Util.EnvironmentTickCount(); | |
1322 | bool oldflying = PhysicsActor.Flying; | 1322 | |
1323 | 1323 | ++m_movementUpdateCount; | |
1324 | if (m_forceFly) | 1324 | if (m_movementUpdateCount < 1) |
1325 | actor.Flying = true; | 1325 | m_movementUpdateCount = 1; |
1326 | else if (m_flyDisabled) | 1326 | |
1327 | actor.Flying = false; | 1327 | #region Sanity Checking |
1328 | else | 1328 | |
1329 | actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); | 1329 | // This is irritating. Really. |
1330 | 1330 | if (!AbsolutePosition.IsFinite()) | |
1331 | if (actor.Flying != oldflying) | 1331 | { |
1332 | update_movementflag = true; | 1332 | RemoveFromPhysicalScene(); |
1333 | 1333 | m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); | |
1334 | if (q != m_bodyRot) | 1334 | |
1335 | { | 1335 | m_pos = m_LastFinitePos; |
1336 | m_bodyRot = q; | 1336 | |
1337 | update_rotation = true; | 1337 | if (!m_pos.IsFinite()) |
1338 | } | 1338 | { |
1339 | 1339 | m_pos.X = 127f; | |
1340 | if (m_parentID == 0) | 1340 | m_pos.Y = 127f; |
1341 | { | 1341 | m_pos.Z = 127f; |
1342 | bool bAllowUpdateMoveToPosition = false; | 1342 | m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999903"); |
1343 | bool bResetMoveToPosition = false; | 1343 | } |
1344 | 1344 | ||
1345 | Vector3[] dirVectors; | 1345 | AddToPhysicalScene(false); |
1346 | 1346 | } | |
1347 | // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying | 1347 | else |
1348 | // this prevents 'jumping' in inappropriate situations. | 1348 | { |
1349 | if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying)) | 1349 | m_LastFinitePos = m_pos; |
1350 | dirVectors = GetWalkDirectionVectors(); | 1350 | } |
1351 | else | 1351 | |
1352 | dirVectors = Dir_Vectors; | 1352 | #endregion Sanity Checking |
1353 | 1353 | ||
1354 | // The fact that m_movementflag is a byte needs to be fixed | 1354 | #region Inputs |
1355 | // it really should be a uint | 1355 | |
1356 | uint nudgehack = 250; | 1356 | AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; |
1357 | foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) | 1357 | Quaternion bodyRotation = agentData.BodyRotation; |
1358 | { | 1358 | |
1359 | if (((uint)flags & (uint)DCF) != 0) | 1359 | // Camera location in world. We'll need to raytrace |
1360 | { | 1360 | // from this location from time to time. |
1361 | bResetMoveToPosition = true; | 1361 | m_CameraCenter = agentData.CameraCenter; |
1362 | DCFlagKeyPressed = true; | 1362 | if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance) |
1363 | try | 1363 | { |
1364 | { | 1364 | ReprioritizeUpdates(); |
1365 | agent_control_v3 += dirVectors[i]; | 1365 | m_lastCameraCenter = m_CameraCenter; |
1366 | //m_log.DebugFormat("[Motion]: {0}, {1}",i, dirVectors[i]); | 1366 | } |
1367 | } | 1367 | |
1368 | catch (IndexOutOfRangeException) | 1368 | // Use these three vectors to figure out what the agent is looking at |
1369 | { | 1369 | // Convert it to a Matrix and/or Quaternion |
1370 | // Why did I get this? | 1370 | m_CameraAtAxis = agentData.CameraAtAxis; |
1371 | } | 1371 | m_CameraLeftAxis = agentData.CameraLeftAxis; |
1372 | 1372 | m_CameraUpAxis = agentData.CameraUpAxis; | |
1373 | if ((m_movementflag & (byte)(uint)DCF) == 0) | 1373 | |
1374 | { | 1374 | // The Agent's Draw distance setting |
1375 | if (DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) | 1375 | m_DrawDistance = agentData.Far; |
1376 | { | 1376 | |
1377 | m_movementflag |= (byte)nudgehack; | 1377 | // Check if Client has camera in 'follow cam' or 'build' mode. |
1378 | } | 1378 | Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); |
1379 | m_movementflag += (byte)(uint)DCF; | 1379 | |
1380 | update_movementflag = true; | 1380 | m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) |
1381 | } | 1381 | && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; |
1382 | } | 1382 | |
1383 | else | 1383 | m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; |
1384 | { | 1384 | m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; |
1385 | if ((m_movementflag & (byte)(uint)DCF) != 0 || | 1385 | |
1386 | ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) | 1386 | #endregion Inputs |
1387 | && ((m_movementflag & (byte)nudgehack) == nudgehack)) | 1387 | |
1388 | ) // This or is for Nudge forward | 1388 | if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) |
1389 | { | 1389 | { |
1390 | m_movementflag -= ((byte)(uint)DCF); | 1390 | StandUp(); |
1391 | 1391 | } | |
1392 | update_movementflag = true; | 1392 | |
1393 | /* | 1393 | //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); |
1394 | if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) | 1394 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view |
1395 | && ((m_movementflag & (byte)nudgehack) == nudgehack)) | 1395 | if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) |
1396 | { | 1396 | { |
1397 | m_log.Debug("Removed Hack flag"); | 1397 | if (m_followCamAuto) |
1398 | } | 1398 | { |
1399 | */ | 1399 | Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; |
1400 | } | 1400 | m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); |
1401 | else | 1401 | } |
1402 | { | 1402 | } |
1403 | bAllowUpdateMoveToPosition = true; | 1403 | lock (scriptedcontrols) |
1404 | } | 1404 | { |
1405 | } | 1405 | if (scriptedcontrols.Count > 0) |
1406 | i++; | 1406 | { |
1407 | } | 1407 | SendControlToScripts((uint)flags); |
1408 | 1408 | flags = RemoveIgnoredControls(flags, IgnoredControls); | |
1409 | //Paupaw:Do Proper PID for Autopilot here | 1409 | } |
1410 | if (bResetMoveToPosition) | 1410 | } |
1411 | { | 1411 | |
1412 | m_moveToPositionTarget = Vector3.Zero; | 1412 | if (m_autopilotMoving) |
1413 | m_moveToPositionInProgress = false; | 1413 | CheckAtSitTarget(); |
1414 | update_movementflag = true; | 1414 | |
1415 | bAllowUpdateMoveToPosition = false; | 1415 | if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) |
1416 | } | 1416 | { |
1417 | 1417 | m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick. | |
1418 | if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving)) | 1418 | Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); |
1419 | { | 1419 | |
1420 | //Check the error term of the current position in relation to the target position | 1420 | // TODO: This doesn't prevent the user from walking yet. |
1421 | if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 0.5f) | 1421 | // Setting parent ID would fix this, if we knew what value |
1422 | { | 1422 | // to use. Or we could add a m_isSitting variable. |
1423 | // we are close enough to the target | 1423 | //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); |
1424 | m_moveToPositionTarget = Vector3.Zero; | 1424 | SitGround = true; |
1425 | m_moveToPositionInProgress = false; | 1425 | } |
1426 | update_movementflag = true; | 1426 | |
1427 | } | 1427 | // In the future, these values might need to go global. |
1428 | else | 1428 | // Here's where you get them. |
1429 | { | 1429 | m_AgentControlFlags = flags; |
1430 | try | 1430 | m_headrotation = agentData.HeadRotation; |
1431 | { | 1431 | m_state = agentData.State; |
1432 | // move avatar in 2D at one meter/second towards target, in avatar coordinate frame. | 1432 | |
1433 | // This movement vector gets added to the velocity through AddNewMovement(). | 1433 | PhysicsActor actor = PhysicsActor; |
1434 | // Theoretically we might need a more complex PID approach here if other | 1434 | if (actor == null) |
1435 | // unknown forces are acting on the avatar and we need to adaptively respond | 1435 | { |
1436 | // to such forces, but the following simple approach seems to works fine. | 1436 | return; |
1437 | Vector3 LocalVectorToTarget3D = | 1437 | } |
1438 | (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords | 1438 | |
1439 | * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords | 1439 | bool update_movementflag = false; |
1440 | // Ignore z component of vector | 1440 | |
1441 | Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); | 1441 | if (m_allowMovement && !SitGround) |
1442 | LocalVectorToTarget2D.Normalize(); | 1442 | { |
1443 | agent_control_v3 += LocalVectorToTarget2D; | 1443 | if (agentData.UseClientAgentPosition) |
1444 | 1444 | { | |
1445 | // update avatar movement flags. the avatar coordinate system is as follows: | 1445 | m_moveToPositionInProgress = (agentData.ClientAgentPosition - AbsolutePosition).Length() > 0.2f; |
1446 | // | 1446 | m_moveToPositionTarget = agentData.ClientAgentPosition; |
1447 | // +X (forward) | 1447 | } |
1448 | // | 1448 | |
1449 | // ^ | 1449 | int i = 0; |
1450 | // | | 1450 | |
1451 | // | | 1451 | bool update_rotation = false; |
1452 | // | | 1452 | bool DCFlagKeyPressed = false; |
1453 | // | | 1453 | Vector3 agent_control_v3 = Vector3.Zero; |
1454 | // (left) +Y <--------o--------> -Y | 1454 | Quaternion q = bodyRotation; |
1455 | // avatar | 1455 | |
1456 | // | | 1456 | bool oldflying = PhysicsActor.Flying; |
1457 | // | | 1457 | |
1458 | // | | 1458 | if (m_forceFly) |
1459 | // | | 1459 | actor.Flying = true; |
1460 | // v | 1460 | else if (m_flyDisabled) |
1461 | // -X | 1461 | actor.Flying = false; |
1462 | // | 1462 | else |
1463 | 1463 | actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); | |
1464 | // based on the above avatar coordinate system, classify the movement into | 1464 | |
1465 | // one of left/right/back/forward. | 1465 | if (actor.Flying != oldflying) |
1466 | if (LocalVectorToTarget2D.Y > 0)//MoveLeft | 1466 | update_movementflag = true; |
1467 | { | 1467 | |
1468 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; | 1468 | if (q != m_bodyRot) |
1469 | //AgentControlFlags | 1469 | { |
1470 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; | 1470 | m_bodyRot = q; |
1471 | update_movementflag = true; | 1471 | update_rotation = true; |
1472 | } | 1472 | } |
1473 | else if (LocalVectorToTarget2D.Y < 0) //MoveRight | 1473 | |
1474 | { | 1474 | //guilty until proven innocent.. |
1475 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; | 1475 | bool Nudging = true; |
1476 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; | 1476 | //Basically, if there is at least one non-nudge control then we don't need |
1477 | update_movementflag = true; | 1477 | //to worry about stopping the avatar |
1478 | } | 1478 | |
1479 | if (LocalVectorToTarget2D.X < 0) //MoveBack | 1479 | if (m_parentID == 0) |
1480 | { | 1480 | { |
1481 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; | 1481 | bool bAllowUpdateMoveToPosition = false; |
1482 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; | 1482 | bool bResetMoveToPosition = false; |
1483 | update_movementflag = true; | 1483 | |
1484 | } | 1484 | Vector3[] dirVectors; |
1485 | else if (LocalVectorToTarget2D.X > 0) //Move Forward | 1485 | |
1486 | { | 1486 | // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying |
1487 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; | 1487 | // this prevents 'jumping' in inappropriate situations. |
1488 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; | 1488 | if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying)) |
1489 | update_movementflag = true; | 1489 | dirVectors = GetWalkDirectionVectors(); |
1490 | } | 1490 | else |
1491 | } | 1491 | dirVectors = Dir_Vectors; |
1492 | catch (Exception e) | 1492 | |
1493 | { | 1493 | bool[] isNudge = GetDirectionIsNudge(); |
1494 | //Avoid system crash, can be slower but... | 1494 | |
1495 | m_log.DebugFormat("Crash! {0}", e.ToString()); | 1495 | |
1496 | } | 1496 | |
1497 | } | 1497 | |
1498 | } | 1498 | |
1499 | } | 1499 | foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) |
1500 | 1500 | { | |
1501 | // Cause the avatar to stop flying if it's colliding | 1501 | if (((uint)flags & (uint)DCF) != 0) |
1502 | // with something with the down arrow pressed. | 1502 | { |
1503 | 1503 | bResetMoveToPosition = true; | |
1504 | // Only do this if we're flying | 1504 | DCFlagKeyPressed = true; |
1505 | if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) | 1505 | try |
1506 | { | 1506 | { |
1507 | // Landing detection code | 1507 | agent_control_v3 += dirVectors[i]; |
1508 | 1508 | if (isNudge[i] == false) | |
1509 | // Are the landing controls requirements filled? | 1509 | { |
1510 | bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || | 1510 | Nudging = false; |
1511 | ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); | 1511 | } |
1512 | 1512 | } | |
1513 | // Are the collision requirements fulfilled? | 1513 | catch (IndexOutOfRangeException) |
1514 | bool colliding = (m_physicsActor.IsColliding == true); | 1514 | { |
1515 | 1515 | // Why did I get this? | |
1516 | if (m_physicsActor.Flying && colliding && controlland) | 1516 | } |
1517 | { | 1517 | |
1518 | // nesting this check because LengthSquared() is expensive and we don't | 1518 | if ((m_movementflag & (uint)DCF) == 0) |
1519 | // want to do it every step when flying. | 1519 | { |
1520 | if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX)) | 1520 | m_movementflag += (byte)(uint)DCF; |
1521 | StopFlying(); | 1521 | update_movementflag = true; |
1522 | } | 1522 | } |
1523 | } | 1523 | } |
1524 | 1524 | else | |
1525 | if (update_movementflag || (update_rotation && DCFlagKeyPressed)) | 1525 | { |
1526 | { | 1526 | if ((m_movementflag & (uint)DCF) != 0) |
1527 | // m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed)); | 1527 | { |
1528 | // m_log.DebugFormat( | 1528 | m_movementflag -= (byte)(uint)DCF; |
1529 | // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); | 1529 | update_movementflag = true; |
1530 | 1530 | } | |
1531 | AddNewMovement(agent_control_v3, q); | 1531 | else |
1532 | 1532 | { | |
1533 | 1533 | bAllowUpdateMoveToPosition = true; | |
1534 | } | 1534 | } |
1535 | } | 1535 | } |
1536 | 1536 | i++; | |
1537 | if (update_movementflag && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0) && (m_parentID == 0) && !SitGround) | 1537 | } |
1538 | Animator.UpdateMovementAnimations(); | 1538 | //Paupaw:Do Proper PID for Autopilot here |
1539 | 1539 | if (bResetMoveToPosition) | |
1540 | m_scene.EventManager.TriggerOnClientMovement(this); | 1540 | { |
1541 | 1541 | m_moveToPositionTarget = Vector3.Zero; | |
1542 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 1542 | m_moveToPositionInProgress = false; |
1543 | } | 1543 | update_movementflag = true; |
1544 | 1544 | bAllowUpdateMoveToPosition = false; | |
1545 | public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client) | 1545 | } |
1546 | { | 1546 | |
1547 | m_autopilotMoving = true; | 1547 | if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving)) |
1548 | m_autoPilotTarget = Pos; | 1548 | { |
1549 | m_sitAtAutoTarget = false; | 1549 | //Check the error term of the current position in relation to the target position |
1550 | PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; | 1550 | if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 0.5f) |
1551 | //proxy.PCode = (byte)PCode.ParticleSystem; | 1551 | { |
1552 | 1552 | // we are close enough to the target | |
1553 | proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); | 1553 | m_moveToPositionTarget = Vector3.Zero; |
1554 | proxyObjectGroup.AttachToScene(m_scene); | 1554 | m_moveToPositionInProgress = false; |
1555 | 1555 | update_movementflag = true; | |
1556 | // Commented out this code since it could never have executed, but might still be informative. | 1556 | } |
1557 | // if (proxyObjectGroup != null) | 1557 | else |
1558 | // { | 1558 | { |
1559 | proxyObjectGroup.SendGroupFullUpdate(); | 1559 | try |
1560 | remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); | 1560 | { |
1561 | m_scene.DeleteSceneObject(proxyObjectGroup, false); | 1561 | // move avatar in 2D at one meter/second towards target, in avatar coordinate frame. |
1562 | // } | 1562 | // This movement vector gets added to the velocity through AddNewMovement(). |
1563 | // else | 1563 | // Theoretically we might need a more complex PID approach here if other |
1564 | // { | 1564 | // unknown forces are acting on the avatar and we need to adaptively respond |
1565 | // m_autopilotMoving = false; | 1565 | // to such forces, but the following simple approach seems to works fine. |
1566 | // m_autoPilotTarget = Vector3.Zero; | 1566 | Vector3 LocalVectorToTarget3D = |
1567 | // ControllingClient.SendAlertMessage("Autopilot cancelled"); | 1567 | (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords |
1568 | // } | 1568 | * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords |
1569 | } | 1569 | // Ignore z component of vector |
1570 | 1570 | Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); | |
1571 | public void DoMoveToPosition(Object sender, string method, List<String> args) | 1571 | LocalVectorToTarget2D.Normalize(); |
1572 | { | 1572 | |
1573 | try | 1573 | //We're not nudging |
1574 | { | 1574 | Nudging = false; |
1575 | float locx = 0f; | 1575 | agent_control_v3 += LocalVectorToTarget2D; |
1576 | float locy = 0f; | 1576 | |
1577 | float locz = 0f; | 1577 | // update avatar movement flags. the avatar coordinate system is as follows: |
1578 | uint regionX = 0; | 1578 | // |
1579 | uint regionY = 0; | 1579 | // +X (forward) |
1580 | try | 1580 | // |
1581 | { | 1581 | // ^ |
1582 | Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY); | 1582 | // | |
1583 | locx = Convert.ToSingle(args[0]) - (float)regionX; | 1583 | // | |
1584 | locy = Convert.ToSingle(args[1]) - (float)regionY; | 1584 | // | |
1585 | locz = Convert.ToSingle(args[2]); | 1585 | // | |
1586 | } | 1586 | // (left) +Y <--------o--------> -Y |
1587 | catch (InvalidCastException) | 1587 | // avatar |
1588 | { | 1588 | // | |
1589 | m_log.Error("[CLIENT]: Invalid autopilot request"); | 1589 | // | |
1590 | return; | 1590 | // | |
1591 | } | 1591 | // | |
1592 | m_moveToPositionInProgress = true; | 1592 | // v |
1593 | m_moveToPositionTarget = new Vector3(locx, locy, locz); | 1593 | // -X |
1594 | } | 1594 | // |
1595 | catch (Exception ex) | 1595 | |
1596 | { | 1596 | // based on the above avatar coordinate system, classify the movement into |
1597 | //Why did I get this error? | 1597 | // one of left/right/back/forward. |
1598 | m_log.Error("[SCENEPRESENCE]: DoMoveToPosition" + ex); | 1598 | if (LocalVectorToTarget2D.Y > 0)//MoveLeft |
1599 | } | 1599 | { |
1600 | } | 1600 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; |
1601 | 1601 | //AgentControlFlags | |
1602 | private void CheckAtSitTarget() | 1602 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; |
1603 | { | 1603 | update_movementflag = true; |
1604 | //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); | 1604 | } |
1605 | if (Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget) <= 1.5) | 1605 | else if (LocalVectorToTarget2D.Y < 0) //MoveRight |
1606 | { | 1606 | { |
1607 | if (m_sitAtAutoTarget) | 1607 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; |
1608 | { | 1608 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; |
1609 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetUUID); | 1609 | update_movementflag = true; |
1610 | if (part != null) | 1610 | } |
1611 | { | 1611 | if (LocalVectorToTarget2D.X < 0) //MoveBack |
1612 | AbsolutePosition = part.AbsolutePosition; | 1612 | { |
1613 | Velocity = Vector3.Zero; | 1613 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; |
1614 | SendFullUpdateToAllClients(); | 1614 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; |
1615 | 1615 | update_movementflag = true; | |
1616 | //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); | 1616 | } |
1617 | } | 1617 | else if (LocalVectorToTarget2D.X > 0) //Move Forward |
1618 | //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); | 1618 | { |
1619 | m_requestedSitTargetUUID = UUID.Zero; | 1619 | m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; |
1620 | } | 1620 | AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; |
1621 | /* | 1621 | update_movementflag = true; |
1622 | else | 1622 | } |
1623 | { | 1623 | } |
1624 | //ControllingClient.SendAlertMessage("Autopilot cancelled"); | 1624 | catch (Exception e) |
1625 | //SendTerseUpdateToAllClients(); | 1625 | { |
1626 | //PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; | 1626 | //Avoid system crash, can be slower but... |
1627 | //proxy.PCode = (byte)PCode.ParticleSystem; | 1627 | m_log.DebugFormat("Crash! {0}", e.ToString()); |
1628 | ////uint nextUUID = m_scene.NextLocalId; | 1628 | } |
1629 | 1629 | } | |
1630 | //proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, m_autoPilotTarget, Quaternion.Identity, proxy); | 1630 | } |
1631 | //if (proxyObjectGroup != null) | 1631 | } |
1632 | //{ | 1632 | |
1633 | //proxyObjectGroup.SendGroupFullUpdate(); | 1633 | // Cause the avatar to stop flying if it's colliding |
1634 | //ControllingClient.SendSitResponse(UUID.Zero, m_autoPilotTarget, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); | 1634 | // with something with the down arrow pressed. |
1635 | //m_scene.DeleteSceneObject(proxyObjectGroup); | 1635 | |
1636 | //} | 1636 | // Only do this if we're flying |
1637 | } | 1637 | if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) |
1638 | */ | 1638 | { |
1639 | m_autoPilotTarget = Vector3.Zero; | 1639 | // Landing detection code |
1640 | m_autopilotMoving = false; | 1640 | |
1641 | } | 1641 | // Are the landing controls requirements filled? |
1642 | } | 1642 | bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || |
1643 | /// <summary> | 1643 | ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); |
1644 | /// Perform the logic necessary to stand the avatar up. This method also executes | 1644 | |
1645 | /// the stand animation. | 1645 | // Are the collision requirements fulfilled? |
1646 | /// </summary> | 1646 | bool colliding = (m_physicsActor.IsColliding == true); |
1647 | public void StandUp() | 1647 | |
1648 | { | 1648 | if (m_physicsActor.Flying && colliding && controlland) |
1649 | SitGround = false; | 1649 | { |
1650 | 1650 | // nesting this check because LengthSquared() is expensive and we don't | |
1651 | if (m_parentID != 0) | 1651 | // want to do it every step when flying. |
1652 | { | 1652 | if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX)) |
1653 | m_log.Debug("StandupCode Executed"); | 1653 | StopFlying(); |
1654 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); | 1654 | } |
1655 | if (part != null) | 1655 | } |
1656 | { | 1656 | |
1657 | TaskInventoryDictionary taskIDict = part.TaskInventory; | 1657 | if (update_movementflag || (update_rotation && DCFlagKeyPressed)) |
1658 | if (taskIDict != null) | 1658 | { |
1659 | { | 1659 | // m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed)); |
1660 | lock (taskIDict) | 1660 | // m_log.DebugFormat( |
1661 | { | 1661 | // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); |
1662 | foreach (UUID taskID in taskIDict.Keys) | 1662 | |
1663 | { | 1663 | AddNewMovement(agent_control_v3, q, Nudging); |
1664 | UnRegisterControlEventsToScript(LocalId, taskID); | 1664 | |
1665 | taskIDict[taskID].PermsMask &= ~( | 1665 | |
1666 | 2048 | //PERMISSION_CONTROL_CAMERA | 1666 | } |
1667 | 4); // PERMISSION_TAKE_CONTROLS | 1667 | } |
1668 | } | 1668 | |
1669 | } | 1669 | if (update_movementflag && !SitGround) |
1670 | 1670 | Animator.UpdateMovementAnimations(); | |
1671 | } | 1671 | |
1672 | // Reset sit target. | 1672 | m_scene.EventManager.TriggerOnClientMovement(this); |
1673 | if (part.GetAvatarOnSitTarget() == UUID) | 1673 | |
1674 | part.SetAvatarOnSitTarget(UUID.Zero); | 1674 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
1675 | 1675 | } | |
1676 | m_parentPosition = part.GetWorldPosition(); | 1676 | |
1677 | ControllingClient.SendClearFollowCamProperties(part.ParentUUID); | 1677 | public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client) |
1678 | } | 1678 | { |
1679 | 1679 | m_autopilotMoving = true; | |
1680 | if (m_physicsActor == null) | 1680 | m_autoPilotTarget = Pos; |
1681 | { | 1681 | m_sitAtAutoTarget = false; |
1682 | AddToPhysicalScene(false); | 1682 | PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; |
1683 | } | 1683 | //proxy.PCode = (byte)PCode.ParticleSystem; |
1684 | 1684 | proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); | |
1685 | m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight); | 1685 | proxyObjectGroup.AttachToScene(m_scene); |
1686 | m_parentPosition = Vector3.Zero; | 1686 | |
1687 | 1687 | // Commented out this code since it could never have executed, but might still be informative. | |
1688 | m_parentID = 0; | 1688 | // if (proxyObjectGroup != null) |
1689 | SendFullUpdateToAllClients(); | 1689 | // { |
1690 | m_requestedSitTargetID = 0; | 1690 | proxyObjectGroup.SendGroupFullUpdate(); |
1691 | if ((m_physicsActor != null) && (m_avHeight > 0)) | 1691 | remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); |
1692 | { | 1692 | m_scene.DeleteSceneObject(proxyObjectGroup, false); |
1693 | SetHeight(m_avHeight); | 1693 | // } |
1694 | } | 1694 | // else |
1695 | } | 1695 | // { |
1696 | 1696 | // m_autopilotMoving = false; | |
1697 | Animator.TrySetMovementAnimation("STAND"); | 1697 | // m_autoPilotTarget = Vector3.Zero; |
1698 | } | 1698 | // ControllingClient.SendAlertMessage("Autopilot cancelled"); |
1699 | 1699 | // } | |
1700 | private SceneObjectPart FindNextAvailableSitTarget(UUID targetID) | 1700 | } |
1701 | { | 1701 | |
1702 | SceneObjectPart targetPart = m_scene.GetSceneObjectPart(targetID); | 1702 | public void DoMoveToPosition(Object sender, string method, List<String> args) |
1703 | if (targetPart == null) | 1703 | { |
1704 | return null; | 1704 | try |
1705 | 1705 | { | |
1706 | // If the primitive the player clicked on has a sit target and that sit target is not full, that sit target is used. | 1706 | float locx = 0f; |
1707 | // If the primitive the player clicked on has no sit target, and one or more other linked objects have sit targets that are not full, the sit target of the object with the lowest link number will be used. | 1707 | float locy = 0f; |
1708 | 1708 | float locz = 0f; | |
1709 | // Get our own copy of the part array, and sort into the order we want to test | 1709 | uint regionX = 0; |
1710 | SceneObjectPart[] partArray = targetPart.ParentGroup.GetParts(); | 1710 | uint regionY = 0; |
1711 | Array.Sort(partArray, delegate(SceneObjectPart p1, SceneObjectPart p2) | 1711 | try |
1712 | { | 1712 | { |
1713 | // we want the originally selected part first, then the rest in link order -- so make the selected part link num (-1) | 1713 | Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY); |
1714 | int linkNum1 = p1==targetPart ? -1 : p1.LinkNum; | 1714 | locx = Convert.ToSingle(args[0]) - (float)regionX; |
1715 | int linkNum2 = p2==targetPart ? -1 : p2.LinkNum; | 1715 | locy = Convert.ToSingle(args[1]) - (float)regionY; |
1716 | return linkNum1 - linkNum2; | 1716 | locz = Convert.ToSingle(args[2]); |
1717 | } | 1717 | } |
1718 | ); | 1718 | catch (InvalidCastException) |
1719 | 1719 | { | |
1720 | //look for prims with explicit sit targets that are available | 1720 | m_log.Error("[CLIENT]: Invalid autopilot request"); |
1721 | foreach (SceneObjectPart part in partArray) | 1721 | return; |
1722 | { | 1722 | } |
1723 | // Is a sit target available? | 1723 | m_moveToPositionInProgress = true; |
1724 | Vector3 avSitOffSet = part.SitTargetPosition; | 1724 | m_moveToPositionTarget = new Vector3(locx, locy, locz); |
1725 | Quaternion avSitOrientation = part.SitTargetOrientation; | 1725 | } |
1726 | UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); | 1726 | catch (Exception ex) |
1727 | 1727 | { | |
1728 | bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); | 1728 | //Why did I get this error? |
1729 | bool SitTargetisSet = | 1729 | m_log.Error("[SCENEPRESENCE]: DoMoveToPosition" + ex); |
1730 | (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f && | 1730 | } |
1731 | avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f)); | 1731 | } |
1732 | 1732 | ||
1733 | if (SitTargetisSet && SitTargetUnOccupied) | 1733 | private void CheckAtSitTarget() |
1734 | { | 1734 | { |
1735 | //switch the target to this prim | 1735 | //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); |
1736 | return part; | 1736 | if (Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget) <= 1.5) |
1737 | } | 1737 | { |
1738 | } | 1738 | if (m_sitAtAutoTarget) |
1739 | 1739 | { | |
1740 | // no explicit sit target found - use original target | 1740 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetUUID); |
1741 | return targetPart; | 1741 | if (part != null) |
1742 | } | 1742 | { |
1743 | 1743 | AbsolutePosition = part.AbsolutePosition; | |
1744 | private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) | 1744 | Velocity = Vector3.Zero; |
1745 | { | 1745 | SendFullUpdateToAllClients(); |
1746 | bool autopilot = true; | 1746 | |
1747 | Vector3 pos = new Vector3(); | 1747 | HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ?? |
1748 | Quaternion sitOrientation = pSitOrientation; | 1748 | } |
1749 | Vector3 cameraEyeOffset = Vector3.Zero; | 1749 | //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); |
1750 | Vector3 cameraAtOffset = Vector3.Zero; | 1750 | m_requestedSitTargetUUID = UUID.Zero; |
1751 | bool forceMouselook = false; | 1751 | } |
1752 | 1752 | /* | |
1753 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); | 1753 | else |
1754 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); | 1754 | { |
1755 | if (part != null) | 1755 | //ControllingClient.SendAlertMessage("Autopilot cancelled"); |
1756 | { | 1756 | //SendTerseUpdateToAllClients(); |
1757 | // TODO: determine position to sit at based on scene geometry; don't trust offset from client | 1757 | //PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; |
1758 | // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it | 1758 | //proxy.PCode = (byte)PCode.ParticleSystem; |
1759 | 1759 | ////uint nextUUID = m_scene.NextLocalId; | |
1760 | // Is a sit target available? | 1760 | |
1761 | Vector3 avSitOffSet = part.SitTargetPosition; | 1761 | //proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, m_autoPilotTarget, Quaternion.Identity, proxy); |
1762 | Quaternion avSitOrientation = part.SitTargetOrientation; | 1762 | //if (proxyObjectGroup != null) |
1763 | UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); | 1763 | //{ |
1764 | 1764 | //proxyObjectGroup.SendGroupFullUpdate(); | |
1765 | bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); | 1765 | //ControllingClient.SendSitResponse(UUID.Zero, m_autoPilotTarget, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); |
1766 | bool SitTargetisSet = | 1766 | //m_scene.DeleteSceneObject(proxyObjectGroup); |
1767 | (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && | 1767 | //} |
1768 | ( | 1768 | } |
1769 | avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 1f // Valid Zero Rotation quaternion | 1769 | */ |
1770 | || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point | 1770 | m_autoPilotTarget = Vector3.Zero; |
1771 | || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion | 1771 | m_autopilotMoving = false; |
1772 | ) | 1772 | } |
1773 | )); | 1773 | } |
1774 | 1774 | /// <summary> | |
1775 | if (SitTargetisSet && SitTargetUnOccupied) | 1775 | /// Perform the logic necessary to stand the avatar up. This method also executes |
1776 | { | 1776 | /// the stand animation. |
1777 | part.SetAvatarOnSitTarget(UUID); | 1777 | /// </summary> |
1778 | offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); | 1778 | public void StandUp() |
1779 | sitOrientation = avSitOrientation; | 1779 | { |
1780 | autopilot = false; | 1780 | SitGround = false; |
1781 | } | 1781 | |
1782 | 1782 | if (m_parentID != 0) | |
1783 | pos = part.AbsolutePosition + offset; | 1783 | { |
1784 | //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) | 1784 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); |
1785 | //{ | 1785 | if (part != null) |
1786 | // offset = pos; | 1786 | { |
1787 | //autopilot = false; | 1787 | part.TaskInventory.LockItemsForRead(true); |
1788 | //} | 1788 | TaskInventoryDictionary taskIDict = part.TaskInventory; |
1789 | if (m_physicsActor != null) | 1789 | if (taskIDict != null) |
1790 | { | 1790 | { |
1791 | // If we're not using the client autopilot, we're immediately warping the avatar to the location | 1791 | foreach (UUID taskID in taskIDict.Keys) |
1792 | // We can remove the physicsActor until they stand up. | 1792 | { |
1793 | m_sitAvatarHeight = m_physicsActor.Size.Z; | 1793 | UnRegisterControlEventsToScript(LocalId, taskID); |
1794 | 1794 | taskIDict[taskID].PermsMask &= ~( | |
1795 | if (autopilot) | 1795 | 2048 | //PERMISSION_CONTROL_CAMERA |
1796 | { | 1796 | 4); // PERMISSION_TAKE_CONTROLS |
1797 | if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) | 1797 | } |
1798 | { | 1798 | } |
1799 | autopilot = false; | 1799 | part.TaskInventory.LockItemsForRead(false); |
1800 | 1800 | // Reset sit target. | |
1801 | RemoveFromPhysicalScene(); | 1801 | if (part.GetAvatarOnSitTarget() == UUID) |
1802 | AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); | 1802 | part.SetAvatarOnSitTarget(UUID.Zero); |
1803 | } | 1803 | m_parentPosition = part.GetWorldPosition(); |
1804 | } | 1804 | ControllingClient.SendClearFollowCamProperties(part.ParentUUID); |
1805 | else | 1805 | } |
1806 | { | 1806 | // part.GetWorldRotation() is the rotation of the object being sat on |
1807 | RemoveFromPhysicalScene(); | 1807 | // Rotation is the sittiing Av's rotation |
1808 | } | 1808 | |
1809 | } | 1809 | Quaternion partRot; |
1810 | 1810 | // if (part.LinkNum == 1) | |
1811 | cameraAtOffset = part.GetCameraAtOffset(); | 1811 | // { // Root prim of linkset |
1812 | cameraEyeOffset = part.GetCameraEyeOffset(); | 1812 | // partRot = part.ParentGroup.RootPart.RotationOffset; |
1813 | forceMouselook = part.GetForceMouselook(); | 1813 | // } |
1814 | } | 1814 | // else |
1815 | 1815 | // { // single or child prim | |
1816 | ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); | 1816 | |
1817 | m_requestedSitTargetUUID = targetID; | 1817 | // } |
1818 | // This calls HandleAgentSit twice, once from here, and the client calls | 1818 | if (part == null) //CW: Part may be gone. llDie() for example. |
1819 | // HandleAgentSit itself after it gets to the location | 1819 | { |
1820 | // It doesn't get to the location until we've moved them there though | 1820 | partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); |
1821 | // which happens in HandleAgentSit :P | 1821 | } |
1822 | m_autopilotMoving = autopilot; | 1822 | else |
1823 | m_autoPilotTarget = pos; | 1823 | { |
1824 | m_sitAtAutoTarget = autopilot; | 1824 | partRot = part.GetWorldRotation(); |
1825 | if (!autopilot) | 1825 | } |
1826 | HandleAgentSit(remoteClient, UUID); | 1826 | |
1827 | } | 1827 | Quaternion partIRot = Quaternion.Inverse(partRot); |
1828 | 1828 | ||
1829 | public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) | 1829 | Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av |
1830 | { | 1830 | Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av |
1831 | if (m_parentID != 0) | 1831 | |
1832 | { | 1832 | |
1833 | StandUp(); | 1833 | if (m_physicsActor == null) |
1834 | } | 1834 | { |
1835 | m_nextSitAnimation = "SIT"; | 1835 | AddToPhysicalScene(false); |
1836 | 1836 | } | |
1837 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); | 1837 | //CW: If the part isn't null then we can set the current position |
1838 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); | 1838 | if (part != null) |
1839 | 1839 | { | |
1840 | if (part != null) | 1840 | Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset! |
1841 | { | 1841 | AbsolutePosition = avWorldStandUp; //KF: Fix stand up. |
1842 | if (!String.IsNullOrEmpty(part.SitAnimation)) | 1842 | part.IsOccupied = false; |
1843 | { | 1843 | part.ParentGroup.DeleteAvatar(ControllingClient.AgentId); |
1844 | m_nextSitAnimation = part.SitAnimation; | 1844 | } |
1845 | } | 1845 | else |
1846 | m_requestedSitTargetID = part.LocalId; | 1846 | { |
1847 | //m_requestedSitOffset = offset; | 1847 | //CW: Since the part doesn't exist, a coarse standup position isn't an issue |
1848 | m_requestedSitTargetUUID = targetID; | 1848 | AbsolutePosition = m_lastWorldPosition; |
1849 | 1849 | } | |
1850 | m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); | 1850 | |
1851 | 1851 | m_parentPosition = Vector3.Zero; | |
1852 | if (m_scene.PhysicsScene.SupportsRayCast()) | 1852 | m_parentID = 0; |
1853 | { | 1853 | m_linkedPrim = UUID.Zero; |
1854 | //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback()); | 1854 | m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); |
1855 | //SitRayCastAvatarPosition(part); | 1855 | SendFullUpdateToAllClients(); |
1856 | //return; | 1856 | m_requestedSitTargetID = 0; |
1857 | } | 1857 | |
1858 | } | 1858 | if ((m_physicsActor != null) && (m_avHeight > 0)) |
1859 | else | 1859 | { |
1860 | { | 1860 | SetHeight(m_avHeight); |
1861 | 1861 | } | |
1862 | m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); | 1862 | } |
1863 | } | 1863 | Animator.TrySetMovementAnimation("STAND"); |
1864 | 1864 | } | |
1865 | 1865 | ||
1866 | 1866 | private SceneObjectPart FindNextAvailableSitTarget(UUID targetID) | |
1867 | SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); | 1867 | { |
1868 | } | 1868 | SceneObjectPart targetPart = m_scene.GetSceneObjectPart(targetID); |
1869 | /* | 1869 | if (targetPart == null) |
1870 | public void SitRayCastAvatarPosition(SceneObjectPart part) | 1870 | return null; |
1871 | { | 1871 | |
1872 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; | 1872 | // If the primitive the player clicked on has a sit target and that sit target is not full, that sit target is used. |
1873 | Vector3 StartRayCastPosition = AbsolutePosition; | 1873 | // If the primitive the player clicked on has no sit target, and one or more other linked objects have sit targets that are not full, the sit target of the object with the lowest link number will be used. |
1874 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); | 1874 | |
1875 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); | 1875 | // Get our own copy of the part array, and sort into the order we want to test |
1876 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse); | 1876 | SceneObjectPart[] partArray = targetPart.ParentGroup.GetParts(); |
1877 | } | 1877 | Array.Sort(partArray, delegate(SceneObjectPart p1, SceneObjectPart p2) |
1878 | 1878 | { | |
1879 | public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) | 1879 | // we want the originally selected part first, then the rest in link order -- so make the selected part link num (-1) |
1880 | { | 1880 | int linkNum1 = p1==targetPart ? -1 : p1.LinkNum; |
1881 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); | 1881 | int linkNum2 = p2==targetPart ? -1 : p2.LinkNum; |
1882 | if (part != null) | 1882 | return linkNum1 - linkNum2; |
1883 | { | 1883 | } |
1884 | if (hitYN) | 1884 | ); |
1885 | { | 1885 | |
1886 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) | 1886 | //look for prims with explicit sit targets that are available |
1887 | { | 1887 | foreach (SceneObjectPart part in partArray) |
1888 | SitRaycastFindEdge(collisionPoint, normal); | 1888 | { |
1889 | m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); | 1889 | // Is a sit target available? |
1890 | } | 1890 | Vector3 avSitOffSet = part.SitTargetPosition; |
1891 | else | 1891 | Quaternion avSitOrientation = part.SitTargetOrientation; |
1892 | { | 1892 | UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); |
1893 | SitRayCastAvatarPositionCameraZ(part); | 1893 | bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero); |
1894 | } | 1894 | bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored. |
1895 | } | 1895 | if (SitTargetisSet && !SitTargetOccupied) |
1896 | else | 1896 | { |
1897 | { | 1897 | //switch the target to this prim |
1898 | SitRayCastAvatarPositionCameraZ(part); | 1898 | return part; |
1899 | } | 1899 | } |
1900 | } | 1900 | } |
1901 | else | 1901 | |
1902 | { | 1902 | // no explicit sit target found - use original target |
1903 | ControllingClient.SendAlertMessage("Sit position no longer exists"); | 1903 | return targetPart; |
1904 | m_requestedSitTargetUUID = UUID.Zero; | 1904 | } |
1905 | m_requestedSitTargetID = 0; | 1905 | |
1906 | m_requestedSitOffset = Vector3.Zero; | 1906 | private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) |
1907 | } | 1907 | { |
1908 | 1908 | bool autopilot = true; | |
1909 | } | 1909 | Vector3 autopilotTarget = new Vector3(); |
1910 | 1910 | Quaternion sitOrientation = Quaternion.Identity; | |
1911 | public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) | 1911 | Vector3 pos = new Vector3(); |
1912 | { | 1912 | Vector3 cameraEyeOffset = Vector3.Zero; |
1913 | // Next, try to raycast from the camera Z position | 1913 | Vector3 cameraAtOffset = Vector3.Zero; |
1914 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; | 1914 | bool forceMouselook = false; |
1915 | Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z; | 1915 | |
1916 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); | 1916 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); |
1917 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); | 1917 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); |
1918 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse); | 1918 | if (part == null) return; |
1919 | } | 1919 | |
1920 | 1920 | // TODO: determine position to sit at based on scene geometry; don't trust offset from client | |
1921 | public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) | 1921 | // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it |
1922 | { | 1922 | |
1923 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); | 1923 | // part is the prim to sit on |
1924 | if (part != null) | 1924 | // offset is the world-ref vector distance from that prim center to the click-spot |
1925 | { | 1925 | // UUID is the UUID of the Avatar doing the clicking |
1926 | if (hitYN) | 1926 | |
1927 | { | 1927 | m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation |
1928 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) | 1928 | |
1929 | { | 1929 | // Is a sit target available? |
1930 | SitRaycastFindEdge(collisionPoint, normal); | 1930 | Vector3 avSitOffSet = part.SitTargetPosition; |
1931 | m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal); | 1931 | Quaternion avSitOrientation = part.SitTargetOrientation; |
1932 | } | 1932 | |
1933 | else | 1933 | bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored. |
1934 | { | 1934 | // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation()); |
1935 | SitRayCastCameraPosition(part); | 1935 | Quaternion partRot; |
1936 | } | 1936 | // if (part.LinkNum == 1) |
1937 | } | 1937 | // { // Root prim of linkset |
1938 | else | 1938 | // partRot = part.ParentGroup.RootPart.RotationOffset; |
1939 | { | 1939 | // } |
1940 | SitRayCastCameraPosition(part); | 1940 | // else |
1941 | } | 1941 | // { // single or child prim |
1942 | } | 1942 | partRot = part.GetWorldRotation(); |
1943 | else | 1943 | // } |
1944 | { | 1944 | Quaternion partIRot = Quaternion.Inverse(partRot); |
1945 | ControllingClient.SendAlertMessage("Sit position no longer exists"); | 1945 | //Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet); |
1946 | m_requestedSitTargetUUID = UUID.Zero; | 1946 | // Sit analysis rewritten by KF 091125 |
1947 | m_requestedSitTargetID = 0; | 1947 | if (SitTargetisSet) // scipted sit |
1948 | m_requestedSitOffset = Vector3.Zero; | 1948 | { |
1949 | } | 1949 | if (!part.IsOccupied) |
1950 | 1950 | { | |
1951 | } | 1951 | //Console.WriteLine("Scripted, unoccupied"); |
1952 | 1952 | part.SetAvatarOnSitTarget(UUID); // set that Av will be on it | |
1953 | public void SitRayCastCameraPosition(SceneObjectPart part) | 1953 | offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one |
1954 | { | 1954 | |
1955 | // Next, try to raycast from the camera position | 1955 | Quaternion nrot = avSitOrientation; |
1956 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; | 1956 | if (!part.IsRoot) |
1957 | Vector3 StartRayCastPosition = CameraPosition; | 1957 | { |
1958 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); | 1958 | nrot = part.RotationOffset * avSitOrientation; |
1959 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); | 1959 | } |
1960 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse); | 1960 | sitOrientation = nrot; // Change rotatione to the scripted one |
1961 | } | 1961 | OffsetRotation = nrot; |
1962 | 1962 | autopilot = false; // Jump direct to scripted llSitPos() | |
1963 | public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) | 1963 | } |
1964 | { | 1964 | else |
1965 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); | 1965 | { |
1966 | if (part != null) | 1966 | //Console.WriteLine("Scripted, occupied"); |
1967 | { | 1967 | return; |
1968 | if (hitYN) | 1968 | } |
1969 | { | 1969 | } |
1970 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) | 1970 | else // Not Scripted |
1971 | { | 1971 | { |
1972 | SitRaycastFindEdge(collisionPoint, normal); | 1972 | if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) ) |
1973 | m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); | 1973 | { |
1974 | } | 1974 | // large prim & offset, ignore if other Avs sitting |
1975 | else | 1975 | // offset.Z -= 0.05f; |
1976 | { | 1976 | m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked |
1977 | SitRayHorizontal(part); | 1977 | autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point |
1978 | } | 1978 | |
1979 | } | 1979 | //Console.WriteLine(" offset ={0}", offset); |
1980 | else | 1980 | //Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos); |
1981 | { | 1981 | //Console.WriteLine(" autopilotTarget={0}", autopilotTarget); |
1982 | SitRayHorizontal(part); | 1982 | |
1983 | } | 1983 | } |
1984 | } | 1984 | else // small offset |
1985 | else | 1985 | { |
1986 | { | 1986 | //Console.WriteLine("Small offset"); |
1987 | ControllingClient.SendAlertMessage("Sit position no longer exists"); | 1987 | if (!part.IsOccupied) |
1988 | m_requestedSitTargetUUID = UUID.Zero; | 1988 | { |
1989 | m_requestedSitTargetID = 0; | 1989 | m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center |
1990 | m_requestedSitOffset = Vector3.Zero; | 1990 | autopilotTarget = part.AbsolutePosition; |
1991 | } | 1991 | //Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget); |
1992 | 1992 | } | |
1993 | } | 1993 | else return; // occupied small |
1994 | 1994 | } // end large/small | |
1995 | public void SitRayHorizontal(SceneObjectPart part) | 1995 | } // end Scripted/not |
1996 | { | 1996 | cameraAtOffset = part.GetCameraAtOffset(); |
1997 | // Next, try to raycast from the avatar position to fwd | 1997 | cameraEyeOffset = part.GetCameraEyeOffset(); |
1998 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; | 1998 | forceMouselook = part.GetForceMouselook(); |
1999 | Vector3 StartRayCastPosition = CameraPosition; | 1999 | if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); // |
2000 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); | 2000 | if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); // |
2001 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); | 2001 | |
2002 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); | 2002 | if (m_physicsActor != null) |
2003 | } | 2003 | { |
2004 | 2004 | // If we're not using the client autopilot, we're immediately warping the avatar to the location | |
2005 | public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) | 2005 | // We can remove the physicsActor until they stand up. |
2006 | { | 2006 | m_sitAvatarHeight = m_physicsActor.Size.Z; |
2007 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); | 2007 | if (autopilot) |
2008 | if (part != null) | 2008 | { // its not a scripted sit |
2009 | { | 2009 | // if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5) |
2010 | if (hitYN) | 2010 | if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 256.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 256.0f) ) |
2011 | { | 2011 | { |
2012 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) | 2012 | autopilot = false; // close enough |
2013 | { | 2013 | m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup. |
2014 | SitRaycastFindEdge(collisionPoint, normal); | 2014 | Not using the part's position because returning the AV to the last known standing |
2015 | m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); | 2015 | position is likely to be more friendly, isn't it? */ |
2016 | // Next, try to raycast from the camera position | 2016 | RemoveFromPhysicalScene(); |
2017 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; | 2017 | Velocity = Vector3.Zero; |
2018 | Vector3 StartRayCastPosition = CameraPosition; | 2018 | AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target |
2019 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); | 2019 | } // else the autopilot will get us close |
2020 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); | 2020 | } |
2021 | //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition); | 2021 | else |
2022 | } | 2022 | { // its a scripted sit |
2023 | else | 2023 | m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup. |
2024 | { | 2024 | I *am* using the part's position this time because we have no real idea how far away |
2025 | ControllingClient.SendAlertMessage("Sit position not accessable."); | 2025 | the avatar is from the sit target. */ |
2026 | m_requestedSitTargetUUID = UUID.Zero; | 2026 | RemoveFromPhysicalScene(); |
2027 | m_requestedSitTargetID = 0; | 2027 | Velocity = Vector3.Zero; |
2028 | m_requestedSitOffset = Vector3.Zero; | 2028 | } |
2029 | } | 2029 | } |
2030 | } | 2030 | else return; // physactor is null! |
2031 | else | 2031 | |
2032 | { | 2032 | Vector3 offsetr; // = offset * partIRot; |
2033 | ControllingClient.SendAlertMessage("Sit position not accessable."); | 2033 | // KF: In a linkset, offsetr needs to be relative to the group root! 091208 |
2034 | m_requestedSitTargetUUID = UUID.Zero; | 2034 | // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot); |
2035 | m_requestedSitTargetID = 0; | 2035 | // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error. |
2036 | m_requestedSitOffset = Vector3.Zero; | 2036 | // { // Single, or Root prim of linkset, target is ClickOffset * RootRot |
2037 | } | 2037 | //offsetr = offset * partIRot; |
2038 | } | 2038 | // |
2039 | else | 2039 | // else |
2040 | { | 2040 | // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot) |
2041 | ControllingClient.SendAlertMessage("Sit position no longer exists"); | 2041 | // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + |
2042 | m_requestedSitTargetUUID = UUID.Zero; | 2042 | // (offset * partRot); |
2043 | m_requestedSitTargetID = 0; | 2043 | // } |
2044 | m_requestedSitOffset = Vector3.Zero; | 2044 | |
2045 | } | 2045 | //Console.WriteLine(" "); |
2046 | 2046 | //Console.WriteLine("link number ={0}", part.LinkNum); | |
2047 | } | 2047 | //Console.WriteLine("Prim offset ={0}", part.OffsetPosition ); |
2048 | 2048 | //Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset); | |
2049 | private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) | 2049 | //Console.WriteLine("Click offst ={0}", offset); |
2050 | { | 2050 | //Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation()); |
2051 | int i = 0; | 2051 | //Console.WriteLine("offsetr ={0}", offsetr); |
2052 | //throw new NotImplementedException(); | 2052 | //Console.WriteLine("Camera At ={0}", cameraAtOffset); |
2053 | //m_requestedSitTargetUUID = UUID.Zero; | 2053 | //Console.WriteLine("Camera Eye ={0}", cameraEyeOffset); |
2054 | //m_requestedSitTargetID = 0; | 2054 | |
2055 | //m_requestedSitOffset = Vector3.Zero; | 2055 | //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child |
2056 | 2056 | ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); | |
2057 | SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); | 2057 | |
2058 | } | 2058 | m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target |
2059 | */ | 2059 | // This calls HandleAgentSit twice, once from here, and the client calls |
2060 | public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) | 2060 | // HandleAgentSit itself after it gets to the location |
2061 | { | 2061 | // It doesn't get to the location until we've moved them there though |
2062 | if (m_parentID != 0) | 2062 | // which happens in HandleAgentSit :P |
2063 | { | 2063 | m_autopilotMoving = autopilot; |
2064 | StandUp(); | 2064 | m_autoPilotTarget = autopilotTarget; |
2065 | } | 2065 | m_sitAtAutoTarget = autopilot; |
2066 | if (!String.IsNullOrEmpty(sitAnimation)) | 2066 | m_initialSitTarget = autopilotTarget; |
2067 | { | 2067 | if (!autopilot) |
2068 | m_nextSitAnimation = sitAnimation; | 2068 | HandleAgentSit(remoteClient, UUID); |
2069 | } | 2069 | } |
2070 | else | 2070 | |
2071 | { | 2071 | public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) |
2072 | m_nextSitAnimation = "SIT"; | 2072 | { |
2073 | } | 2073 | if (m_parentID != 0) |
2074 | 2074 | { | |
2075 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); | 2075 | StandUp(); |
2076 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); | 2076 | } |
2077 | if (part != null) | 2077 | m_nextSitAnimation = "SIT"; |
2078 | { | 2078 | |
2079 | m_requestedSitTargetID = part.LocalId; | 2079 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); |
2080 | //m_requestedSitOffset = offset; | 2080 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); |
2081 | m_requestedSitTargetUUID = targetID; | 2081 | |
2082 | 2082 | if (part != null) | |
2083 | m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); | 2083 | { |
2084 | 2084 | if (!String.IsNullOrEmpty(part.SitAnimation)) | |
2085 | if (m_scene.PhysicsScene.SupportsRayCast()) | 2085 | { |
2086 | { | 2086 | m_nextSitAnimation = part.SitAnimation; |
2087 | //SitRayCastAvatarPosition(part); | 2087 | } |
2088 | //return; | 2088 | m_requestedSitTargetID = part.LocalId; |
2089 | } | 2089 | //m_requestedSitOffset = offset; |
2090 | } | 2090 | m_requestedSitTargetUUID = targetID; |
2091 | else | 2091 | |
2092 | { | 2092 | m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); |
2093 | m_log.Warn("Sit requested on unknown object: " + targetID); | 2093 | |
2094 | } | 2094 | if (m_scene.PhysicsScene.SupportsRayCast()) |
2095 | 2095 | { | |
2096 | SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); | 2096 | //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback()); |
2097 | } | 2097 | //SitRayCastAvatarPosition(part); |
2098 | 2098 | //return; | |
2099 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) | 2099 | } |
2100 | { | 2100 | } |
2101 | if (!String.IsNullOrEmpty(m_nextSitAnimation)) | 2101 | else |
2102 | { | 2102 | { |
2103 | HandleAgentSit(remoteClient, agentID, m_nextSitAnimation); | 2103 | |
2104 | } | 2104 | m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); |
2105 | else | 2105 | } |
2106 | { | 2106 | |
2107 | HandleAgentSit(remoteClient, agentID, "SIT"); | 2107 | |
2108 | } | 2108 | |
2109 | } | 2109 | SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); |
2110 | 2110 | } | |
2111 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID, string sitAnimation) | 2111 | /* |
2112 | { | 2112 | public void SitRayCastAvatarPosition(SceneObjectPart part) |
2113 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); | 2113 | { |
2114 | 2114 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; | |
2115 | if (m_sitAtAutoTarget || !m_autopilotMoving) | 2115 | Vector3 StartRayCastPosition = AbsolutePosition; |
2116 | { | 2116 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); |
2117 | if (part != null) | 2117 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); |
2118 | { | 2118 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse); |
2119 | if (part.GetAvatarOnSitTarget() == UUID) | 2119 | } |
2120 | { | 2120 | |
2121 | Vector3 sitTargetPos = part.SitTargetPosition; | 2121 | public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) |
2122 | Quaternion sitTargetOrient = part.SitTargetOrientation; | 2122 | { |
2123 | 2123 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); | |
2124 | //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0); | 2124 | if (part != null) |
2125 | //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w); | 2125 | { |
2126 | 2126 | if (hitYN) | |
2127 | //Quaternion result = (sitTargetOrient * vq) * nq; | 2127 | { |
2128 | 2128 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) | |
2129 | m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); | 2129 | { |
2130 | m_pos += SIT_TARGET_ADJUSTMENT; | 2130 | SitRaycastFindEdge(collisionPoint, normal); |
2131 | m_bodyRot = sitTargetOrient; | 2131 | m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); |
2132 | //Rotation = sitTargetOrient; | 2132 | } |
2133 | m_parentPosition = part.AbsolutePosition; | 2133 | else |
2134 | 2134 | { | |
2135 | //SendTerseUpdateToAllClients(); | 2135 | SitRayCastAvatarPositionCameraZ(part); |
2136 | } | 2136 | } |
2137 | else | 2137 | } |
2138 | { | 2138 | else |
2139 | m_pos -= part.AbsolutePosition; | 2139 | { |
2140 | m_parentPosition = part.AbsolutePosition; | 2140 | SitRayCastAvatarPositionCameraZ(part); |
2141 | } | 2141 | } |
2142 | } | 2142 | } |
2143 | else | 2143 | else |
2144 | { | 2144 | { |
2145 | return; | 2145 | ControllingClient.SendAlertMessage("Sit position no longer exists"); |
2146 | } | 2146 | m_requestedSitTargetUUID = UUID.Zero; |
2147 | } | 2147 | m_requestedSitTargetID = 0; |
2148 | m_parentID = m_requestedSitTargetID; | 2148 | m_requestedSitOffset = Vector3.Zero; |
2149 | 2149 | } | |
2150 | Velocity = Vector3.Zero; | 2150 | |
2151 | RemoveFromPhysicalScene(); | 2151 | } |
2152 | 2152 | ||
2153 | Animator.TrySetMovementAnimation(sitAnimation); | 2153 | public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) |
2154 | SendFullUpdateToAllClients(); | 2154 | { |
2155 | // This may seem stupid, but Our Full updates don't send avatar rotation :P | 2155 | // Next, try to raycast from the camera Z position |
2156 | // So we're also sending a terse update (which has avatar rotation) | 2156 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; |
2157 | // [Update] We do now. | 2157 | Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z; |
2158 | //SendTerseUpdateToAllClients(); | 2158 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); |
2159 | } | 2159 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); |
2160 | 2160 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse); | |
2161 | /// <summary> | 2161 | } |
2162 | /// Event handler for the 'Always run' setting on the client | 2162 | |
2163 | /// Tells the physics plugin to increase speed of movement. | 2163 | public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) |
2164 | /// </summary> | 2164 | { |
2165 | public void HandleSetAlwaysRun(IClientAPI remoteClient, bool pSetAlwaysRun) | 2165 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); |
2166 | { | 2166 | if (part != null) |
2167 | m_setAlwaysRun = pSetAlwaysRun; | 2167 | { |
2168 | if (PhysicsActor != null) | 2168 | if (hitYN) |
2169 | { | 2169 | { |
2170 | PhysicsActor.SetAlwaysRun = pSetAlwaysRun; | 2170 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) |
2171 | } | 2171 | { |
2172 | } | 2172 | SitRaycastFindEdge(collisionPoint, normal); |
2173 | 2173 | m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal); | |
2174 | public void HandleStartAnim(IClientAPI remoteClient, UUID animID) | 2174 | } |
2175 | { | 2175 | else |
2176 | Animator.AddAnimation(animID, UUID.Zero); | 2176 | { |
2177 | } | 2177 | SitRayCastCameraPosition(part); |
2178 | 2178 | } | |
2179 | public void HandleStopAnim(IClientAPI remoteClient, UUID animID) | 2179 | } |
2180 | { | 2180 | else |
2181 | Animator.RemoveAnimation(animID); | 2181 | { |
2182 | } | 2182 | SitRayCastCameraPosition(part); |
2183 | 2183 | } | |
2184 | /// <summary> | 2184 | } |
2185 | /// Rotate the avatar to the given rotation and apply a movement in the given relative vector | 2185 | else |
2186 | /// </summary> | 2186 | { |
2187 | /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> | 2187 | ControllingClient.SendAlertMessage("Sit position no longer exists"); |
2188 | /// <param name="rotation">The direction in which this avatar should now face. | 2188 | m_requestedSitTargetUUID = UUID.Zero; |
2189 | public void AddNewMovement(Vector3 vec, Quaternion rotation) | 2189 | m_requestedSitTargetID = 0; |
2190 | { | 2190 | m_requestedSitOffset = Vector3.Zero; |
2191 | if (m_isChildAgent) | 2191 | } |
2192 | { | 2192 | |
2193 | // WHAT??? | 2193 | } |
2194 | m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); | 2194 | |
2195 | 2195 | public void SitRayCastCameraPosition(SceneObjectPart part) | |
2196 | // we have to reset the user's child agent connections. | 2196 | { |
2197 | // Likely, here they've lost the eventqueue for other regions so border | 2197 | // Next, try to raycast from the camera position |
2198 | // crossings will fail at this point unless we reset them. | 2198 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; |
2199 | 2199 | Vector3 StartRayCastPosition = CameraPosition; | |
2200 | List<ulong> regions = new List<ulong>(KnownChildRegionHandles); | 2200 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); |
2201 | regions.Remove(m_scene.RegionInfo.RegionHandle); | 2201 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); |
2202 | 2202 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse); | |
2203 | MakeRootAgent(new Vector3(127f, 127f, 127f), true); | 2203 | } |
2204 | 2204 | ||
2205 | // Async command | 2205 | public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) |
2206 | if (m_scene.SceneGridService != null) | 2206 | { |
2207 | { | 2207 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); |
2208 | m_scene.SceneGridService.SendCloseChildAgentConnections(UUID, regions); | 2208 | if (part != null) |
2209 | 2209 | { | |
2210 | // Give the above command some time to try and close the connections. | 2210 | if (hitYN) |
2211 | // this is really an emergency.. so sleep, or we'll get all discombobulated. | 2211 | { |
2212 | System.Threading.Thread.Sleep(500); | 2212 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) |
2213 | } | 2213 | { |
2214 | 2214 | SitRaycastFindEdge(collisionPoint, normal); | |
2215 | if (m_scene.SceneGridService != null) | 2215 | m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); |
2216 | { | 2216 | } |
2217 | IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); | 2217 | else |
2218 | if (m_agentTransfer != null) | 2218 | { |
2219 | m_agentTransfer.EnableChildAgents(this); | 2219 | SitRayHorizontal(part); |
2220 | } | 2220 | } |
2221 | 2221 | } | |
2222 | return; | 2222 | else |
2223 | } | 2223 | { |
2224 | 2224 | SitRayHorizontal(part); | |
2225 | m_perfMonMS = Util.EnvironmentTickCount(); | 2225 | } |
2226 | 2226 | } | |
2227 | Rotation = rotation; | 2227 | else |
2228 | Vector3 direc = vec * rotation; | 2228 | { |
2229 | direc.Normalize(); | 2229 | ControllingClient.SendAlertMessage("Sit position no longer exists"); |
2230 | 2230 | m_requestedSitTargetUUID = UUID.Zero; | |
2231 | direc *= 0.03f * 128f * m_speedModifier; | 2231 | m_requestedSitTargetID = 0; |
2232 | 2232 | m_requestedSitOffset = Vector3.Zero; | |
2233 | PhysicsActor actor = m_physicsActor; | 2233 | } |
2234 | if (actor != null) | 2234 | |
2235 | { | 2235 | } |
2236 | if (actor.Flying) | 2236 | |
2237 | { | 2237 | public void SitRayHorizontal(SceneObjectPart part) |
2238 | direc *= 4.0f; | 2238 | { |
2239 | //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); | 2239 | // Next, try to raycast from the avatar position to fwd |
2240 | //bool colliding = (m_physicsActor.IsColliding==true); | 2240 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; |
2241 | //if (controlland) | 2241 | Vector3 StartRayCastPosition = CameraPosition; |
2242 | // m_log.Info("[AGENT]: landCommand"); | 2242 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); |
2243 | //if (colliding) | 2243 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); |
2244 | // m_log.Info("[AGENT]: colliding"); | 2244 | m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); |
2245 | //if (m_physicsActor.Flying && colliding && controlland) | 2245 | } |
2246 | //{ | 2246 | |
2247 | // StopFlying(); | 2247 | public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) |
2248 | // m_log.Info("[AGENT]: Stop FLying"); | 2248 | { |
2249 | //} | 2249 | SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); |
2250 | } | 2250 | if (part != null) |
2251 | else if (!actor.Flying && actor.IsColliding) | 2251 | { |
2252 | { | 2252 | if (hitYN) |
2253 | if (direc.Z > 2.0f) | 2253 | { |
2254 | { | 2254 | if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) |
2255 | direc.Z *= 3.0f; | 2255 | { |
2256 | 2256 | SitRaycastFindEdge(collisionPoint, normal); | |
2257 | // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. | 2257 | m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); |
2258 | Animator.TrySetMovementAnimation("PREJUMP"); | 2258 | // Next, try to raycast from the camera position |
2259 | Animator.TrySetMovementAnimation("JUMP"); | 2259 | Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; |
2260 | } | 2260 | Vector3 StartRayCastPosition = CameraPosition; |
2261 | } | 2261 | Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); |
2262 | } | 2262 | float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); |
2263 | 2263 | //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition); | |
2264 | // TODO: Add the force instead of only setting it to support multiple forces per frame? | 2264 | } |
2265 | m_forceToApply = direc; | 2265 | else |
2266 | 2266 | { | |
2267 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2267 | ControllingClient.SendAlertMessage("Sit position not accessable."); |
2268 | } | 2268 | m_requestedSitTargetUUID = UUID.Zero; |
2269 | 2269 | m_requestedSitTargetID = 0; | |
2270 | #endregion | 2270 | m_requestedSitOffset = Vector3.Zero; |
2271 | 2271 | } | |
2272 | #region Overridden Methods | 2272 | } |
2273 | 2273 | else | |
2274 | public override void Update() | 2274 | { |
2275 | { | 2275 | ControllingClient.SendAlertMessage("Sit position not accessable."); |
2276 | const float ROTATION_TOLERANCE = 0.01f; | 2276 | m_requestedSitTargetUUID = UUID.Zero; |
2277 | const float VELOCITY_TOLERANCE = 0.001f; | 2277 | m_requestedSitTargetID = 0; |
2278 | const float POSITION_TOLERANCE = 0.05f; | 2278 | m_requestedSitOffset = Vector3.Zero; |
2279 | //const int TIME_MS_TOLERANCE = 3000; | 2279 | } |
2280 | 2280 | } | |
2281 | SendPrimUpdates(); | 2281 | else |
2282 | 2282 | { | |
2283 | if (m_isChildAgent == false) | 2283 | ControllingClient.SendAlertMessage("Sit position no longer exists"); |
2284 | { | 2284 | m_requestedSitTargetUUID = UUID.Zero; |
2285 | // PhysicsActor actor = m_physicsActor; | 2285 | m_requestedSitTargetID = 0; |
2286 | 2286 | m_requestedSitOffset = Vector3.Zero; | |
2287 | // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to | 2287 | } |
2288 | // grab the latest PhysicsActor velocity, whereas m_velocity is often | 2288 | |
2289 | // storing a requested force instead of an actual traveling velocity | 2289 | } |
2290 | 2290 | ||
2291 | // Throw away duplicate or insignificant updates | 2291 | private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) |
2292 | if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || | 2292 | { |
2293 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || | 2293 | int i = 0; |
2294 | !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) | 2294 | //throw new NotImplementedException(); |
2295 | //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) | 2295 | //m_requestedSitTargetUUID = UUID.Zero; |
2296 | { | 2296 | //m_requestedSitTargetID = 0; |
2297 | SendTerseUpdateToAllClients(); | 2297 | //m_requestedSitOffset = Vector3.Zero; |
2298 | 2298 | ||
2299 | // Update the "last" values | 2299 | SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); |
2300 | m_lastPosition = m_pos; | 2300 | } |
2301 | m_lastRotation = m_bodyRot; | 2301 | */ |
2302 | m_lastVelocity = Velocity; | 2302 | public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) |
2303 | //m_lastTerseSent = Environment.TickCount; | 2303 | { |
2304 | } | 2304 | if (m_parentID != 0) |
2305 | 2305 | { | |
2306 | // followed suggestion from mic bowman. reversed the two lines below. | 2306 | StandUp(); |
2307 | if (m_parentID == 0 && m_physicsActor != null || m_parentID != 0) // Check that we have a physics actor or we're sitting on something | 2307 | } |
2308 | CheckForBorderCrossing(); | 2308 | if (!String.IsNullOrEmpty(sitAnimation)) |
2309 | CheckForSignificantMovement(); // sends update to the modules. | 2309 | { |
2310 | } | 2310 | m_nextSitAnimation = sitAnimation; |
2311 | } | 2311 | } |
2312 | 2312 | else | |
2313 | #endregion | 2313 | { |
2314 | 2314 | m_nextSitAnimation = "SIT"; | |
2315 | #region Update Client(s) | 2315 | } |
2316 | 2316 | ||
2317 | /// <summary> | 2317 | //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); |
2318 | /// Sends a location update to the client connected to this scenePresence | 2318 | SceneObjectPart part = FindNextAvailableSitTarget(targetID); |
2319 | /// </summary> | 2319 | if (part != null) |
2320 | /// <param name="remoteClient"></param> | 2320 | { |
2321 | public void SendTerseUpdateToClient(IClientAPI remoteClient) | 2321 | m_requestedSitTargetID = part.LocalId; |
2322 | { | 2322 | //m_requestedSitOffset = offset; |
2323 | // If the client is inactive, it's getting its updates from another | 2323 | m_requestedSitTargetUUID = targetID; |
2324 | // server. | 2324 | |
2325 | if (remoteClient.IsActive) | 2325 | m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); |
2326 | { | 2326 | |
2327 | m_perfMonMS = Util.EnvironmentTickCount(); | 2327 | if (m_scene.PhysicsScene.SupportsRayCast()) |
2328 | 2328 | { | |
2329 | PhysicsActor actor = m_physicsActor; | 2329 | //SitRayCastAvatarPosition(part); |
2330 | Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero; | 2330 | //return; |
2331 | 2331 | } | |
2332 | Vector3 pos = m_pos; | 2332 | } |
2333 | pos.Z += m_appearance.HipOffset; | 2333 | else |
2334 | 2334 | { | |
2335 | //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity); | 2335 | m_log.Warn("Sit requested on unknown object: " + targetID); |
2336 | 2336 | } | |
2337 | remoteClient.SendPrimUpdate(this, PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity); | 2337 | |
2338 | 2338 | SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); | |
2339 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2339 | } |
2340 | m_scene.StatsReporter.AddAgentUpdates(1); | 2340 | |
2341 | } | 2341 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) |
2342 | } | 2342 | { |
2343 | 2343 | if (!String.IsNullOrEmpty(m_nextSitAnimation)) | |
2344 | /// <summary> | 2344 | { |
2345 | /// Send a location/velocity/accelleration update to all agents in scene | 2345 | HandleAgentSit(remoteClient, agentID, m_nextSitAnimation); |
2346 | /// </summary> | 2346 | } |
2347 | public void SendTerseUpdateToAllClients() | 2347 | else |
2348 | { | 2348 | { |
2349 | m_perfMonMS = Util.EnvironmentTickCount(); | 2349 | HandleAgentSit(remoteClient, agentID, "SIT"); |
2350 | 2350 | } | |
2351 | m_scene.ForEachClient(SendTerseUpdateToClient); | 2351 | } |
2352 | 2352 | ||
2353 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2353 | public void HandleAgentSit(IClientAPI remoteClient, UUID agentID, string sitAnimation) |
2354 | } | 2354 | { |
2355 | 2355 | SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); | |
2356 | public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs) | 2356 | |
2357 | { | 2357 | if (m_sitAtAutoTarget || !m_autopilotMoving) |
2358 | SendCourseLocationsMethod d = m_sendCourseLocationsMethod; | 2358 | { |
2359 | if (d != null) | 2359 | if (part != null) |
2360 | { | 2360 | { |
2361 | d.Invoke(m_scene.RegionInfo.originRegionID, this, coarseLocations, avatarUUIDs); | 2361 | //Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation()); |
2362 | } | 2362 | if (part.GetAvatarOnSitTarget() == UUID) |
2363 | } | 2363 | { |
2364 | 2364 | //Console.WriteLine("Scripted Sit"); | |
2365 | public void SetSendCourseLocationMethod(SendCourseLocationsMethod d) | 2365 | // Scripted sit |
2366 | { | 2366 | Vector3 sitTargetPos = part.SitTargetPosition; |
2367 | if (d != null) | 2367 | Quaternion sitTargetOrient = part.SitTargetOrientation; |
2368 | m_sendCourseLocationsMethod = d; | 2368 | m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); |
2369 | } | 2369 | m_pos += SIT_TARGET_ADJUSTMENT; |
2370 | 2370 | if (!part.IsRoot) | |
2371 | public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List<Vector3> coarseLocations, List<UUID> avatarUUIDs) | 2371 | { |
2372 | { | 2372 | m_pos *= part.RotationOffset; |
2373 | m_perfMonMS = Util.EnvironmentTickCount(); | 2373 | } |
2374 | m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations); | 2374 | m_bodyRot = sitTargetOrient; |
2375 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2375 | m_parentPosition = part.AbsolutePosition; |
2376 | } | 2376 | part.IsOccupied = true; |
2377 | 2377 | part.ParentGroup.AddAvatar(agentID); | |
2378 | /// <summary> | 2378 | } |
2379 | /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar) | 2379 | else |
2380 | /// </summary> | 2380 | { |
2381 | /// <param name="remoteAvatar"></param> | 2381 | // if m_avUnscriptedSitPos is zero then Av sits above center |
2382 | public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar) | 2382 | // Else Av sits at m_avUnscriptedSitPos |
2383 | { | 2383 | |
2384 | // 2 stage check is needed. | 2384 | // Non-scripted sit by Kitto Flora 21Nov09 |
2385 | if (remoteAvatar == null) | 2385 | // Calculate angle of line from prim to Av |
2386 | return; | 2386 | Quaternion partIRot; |
2387 | IClientAPI cl=remoteAvatar.ControllingClient; | 2387 | // if (part.LinkNum == 1) |
2388 | if (cl == null) | 2388 | // { // Root prim of linkset |
2389 | return; | 2389 | // partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset); |
2390 | if (m_appearance.Texture == null) | 2390 | // } |
2391 | return; | 2391 | // else |
2392 | 2392 | // { // single or child prim | |
2393 | Vector3 pos = m_pos; | 2393 | partIRot = Quaternion.Inverse(part.GetWorldRotation()); |
2394 | pos.Z += m_appearance.HipOffset; | 2394 | // } |
2395 | 2395 | Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos; | |
2396 | remoteAvatar.m_controllingClient.SendAvatarDataImmediate(this); | 2396 | float y_diff = (m_avInitialPos.Y - sitTargetPos.Y); |
2397 | m_scene.StatsReporter.AddAgentUpdates(1); | 2397 | float x_diff = ( m_avInitialPos.X - sitTargetPos.X); |
2398 | } | 2398 | if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0 |
2399 | 2399 | if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0 | |
2400 | /// <summary> | 2400 | float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff); |
2401 | /// Tell *ALL* agents about this agent | 2401 | // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'. |
2402 | /// </summary> | 2402 | // Av sits at world euler <0,0, z>, translated by part rotation |
2403 | public void SendInitialFullUpdateToAllClients() | 2403 | m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click |
2404 | { | 2404 | |
2405 | m_perfMonMS = Util.EnvironmentTickCount(); | 2405 | m_parentPosition = part.AbsolutePosition; |
2406 | int avUpdates = 0; | 2406 | part.IsOccupied = true; |
2407 | m_scene.ForEachScenePresence(delegate(ScenePresence avatar) | 2407 | part.ParentGroup.AddAvatar(agentID); |
2408 | { | 2408 | m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation |
2409 | ++avUpdates; | 2409 | (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center |
2410 | // only send if this is the root (children are only "listening posts" in a foreign region) | 2410 | (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) + |
2411 | if (!IsChildAgent) | 2411 | m_avUnscriptedSitPos; // adds click offset, if any |
2412 | { | 2412 | //Set up raytrace to find top surface of prim |
2413 | SendFullUpdateToOtherClient(avatar); | 2413 | Vector3 size = part.Scale; |
2414 | } | 2414 | float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z)); |
2415 | 2415 | Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag); | |
2416 | if (avatar.LocalId != LocalId) | 2416 | Vector3 down = new Vector3(0f, 0f, -1f); |
2417 | { | 2417 | //Console.WriteLine("st={0} do={1} ma={2}", start, down, mag); |
2418 | if (!avatar.IsChildAgent) | 2418 | m_scene.PhysicsScene.RaycastWorld( |
2419 | { | 2419 | start, // Vector3 position, |
2420 | avatar.SendFullUpdateToOtherClient(this); | 2420 | down, // Vector3 direction, |
2421 | avatar.SendAppearanceToOtherAgent(this); | 2421 | mag, // float length, |
2422 | avatar.Animator.SendAnimPackToClient(ControllingClient); | 2422 | SitAltitudeCallback); // retMethod |
2423 | } | 2423 | } // end scripted/not |
2424 | } | 2424 | } |
2425 | }); | 2425 | else // no Av |
2426 | 2426 | { | |
2427 | m_scene.StatsReporter.AddAgentUpdates(avUpdates); | 2427 | return; |
2428 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2428 | } |
2429 | 2429 | } | |
2430 | //Animator.SendAnimPack(); | 2430 | |
2431 | } | 2431 | //We want our offsets to reference the root prim, not the child we may have sat on |
2432 | 2432 | if (!part.IsRoot) | |
2433 | public void SendFullUpdateToAllClients() | 2433 | { |
2434 | { | 2434 | m_parentID = part.ParentGroup.RootPart.LocalId; |
2435 | m_perfMonMS = Util.EnvironmentTickCount(); | 2435 | m_pos += part.OffsetPosition; |
2436 | 2436 | } | |
2437 | // only send update from root agents to other clients; children are only "listening posts" | 2437 | else |
2438 | int count = 0; | 2438 | { |
2439 | m_scene.ForEachScenePresence(delegate(ScenePresence sp) | 2439 | m_parentID = m_requestedSitTargetID; |
2440 | { | 2440 | } |
2441 | if (sp.IsChildAgent) | 2441 | |
2442 | return; | 2442 | m_linkedPrim = part.UUID; |
2443 | SendFullUpdateToOtherClient(sp); | 2443 | if (part.GetAvatarOnSitTarget() != UUID) |
2444 | ++count; | 2444 | { |
2445 | }); | 2445 | m_offsetRotation = m_offsetRotation / part.RotationOffset; |
2446 | m_scene.StatsReporter.AddAgentUpdates(count); | 2446 | } |
2447 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2447 | Velocity = Vector3.Zero; |
2448 | 2448 | RemoveFromPhysicalScene(); | |
2449 | Animator.SendAnimPack(); | 2449 | Animator.TrySetMovementAnimation(sitAnimation); |
2450 | } | 2450 | SendFullUpdateToAllClients(); |
2451 | 2451 | SendTerseUpdateToAllClients(); | |
2452 | /// <summary> | 2452 | } |
2453 | /// Do everything required once a client completes its movement into a region | 2453 | |
2454 | /// </summary> | 2454 | public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal) |
2455 | public void SendInitialData() | 2455 | { |
2456 | { | 2456 | // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer |
2457 | // Moved this into CompleteMovement to ensure that m_appearance is initialized before | 2457 | // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height. |
2458 | // the inventory arrives | 2458 | if(hitYN) |
2459 | // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); | 2459 | { |
2460 | 2460 | // m_pos = Av offset from prim center to make look like on center | |
2461 | Vector3 pos = m_pos; | 2461 | // m_parentPosition = Actual center pos of prim |
2462 | pos.Z += m_appearance.HipOffset; | 2462 | // collisionPoint = spot on prim where we want to sit |
2463 | 2463 | // collisionPoint.Z = global sit surface height | |
2464 | m_controllingClient.SendAvatarDataImmediate(this); | 2464 | SceneObjectPart part = m_scene.GetSceneObjectPart(localid); |
2465 | 2465 | Quaternion partIRot; | |
2466 | SendInitialFullUpdateToAllClients(); | 2466 | // if (part.LinkNum == 1) |
2467 | SendAppearanceToAllOtherAgents(); | 2467 | /// { // Root prim of linkset |
2468 | } | 2468 | // partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset); |
2469 | 2469 | // } | |
2470 | /// <summary> | 2470 | // else |
2471 | /// Tell the client for this scene presence what items it should be wearing now | 2471 | // { // single or child prim |
2472 | /// </summary> | 2472 | partIRot = Quaternion.Inverse(part.GetWorldRotation()); |
2473 | public void SendWearables() | 2473 | // } |
2474 | { | 2474 | if (m_initialSitTarget != null) |
2475 | m_log.DebugFormat("[SCENE]: Received request for wearables of {0}", Name); | 2475 | { |
2476 | 2476 | float offZ = collisionPoint.Z - m_initialSitTarget.Z; | |
2477 | ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); | 2477 | Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction |
2478 | } | 2478 | //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset); |
2479 | 2479 | m_pos += offset; | |
2480 | /// <summary> | 2480 | // ControllingClient.SendClearFollowCamProperties(part.UUID); |
2481 | /// | 2481 | } |
2482 | /// </summary> | 2482 | |
2483 | public void SendAppearanceToAllOtherAgents() | 2483 | } |
2484 | { | 2484 | } // End SitAltitudeCallback KF. |
2485 | m_perfMonMS = Util.EnvironmentTickCount(); | 2485 | |
2486 | 2486 | /// <summary> | |
2487 | m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) | 2487 | /// Event handler for the 'Always run' setting on the client |
2488 | { | 2488 | /// Tells the physics plugin to increase speed of movement. |
2489 | if (scenePresence.UUID != UUID) | 2489 | /// </summary> |
2490 | { | 2490 | public void HandleSetAlwaysRun(IClientAPI remoteClient, bool pSetAlwaysRun) |
2491 | SendAppearanceToOtherAgent(scenePresence); | 2491 | { |
2492 | } | 2492 | m_setAlwaysRun = pSetAlwaysRun; |
2493 | }); | 2493 | if (PhysicsActor != null) |
2494 | 2494 | { | |
2495 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | 2495 | PhysicsActor.SetAlwaysRun = pSetAlwaysRun; |
2496 | } | 2496 | } |
2497 | 2497 | } | |
2498 | /// <summary> | 2498 | |
2499 | /// Send appearance data to an agent that isn't this one. | 2499 | public void HandleStartAnim(IClientAPI remoteClient, UUID animID) |
2500 | /// </summary> | 2500 | { |
2501 | /// <param name="avatar"></param> | 2501 | Animator.AddAnimation(animID, UUID.Zero); |
2502 | public void SendAppearanceToOtherAgent(ScenePresence avatar) | 2502 | } |
2503 | { | 2503 | |
2504 | avatar.ControllingClient.SendAppearance( | 2504 | public void HandleStopAnim(IClientAPI remoteClient, UUID animID) |
2505 | m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); | 2505 | { |
2506 | } | 2506 | Animator.RemoveAnimation(animID); |
2507 | 2507 | } | |
2508 | /// <summary> | 2508 | |
2509 | /// Set appearance data (textureentry and slider settings) received from the client | 2509 | /// <summary> |
2510 | /// </summary> | 2510 | /// Rotate the avatar to the given rotation and apply a movement in the given relative vector |
2511 | /// <param name="texture"></param> | 2511 | /// </summary> |
2512 | /// <param name="visualParam"></param> | 2512 | /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> |
2513 | public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) | 2513 | /// <param name="rotation">The direction in which this avatar should now face. |
2514 | { | 2514 | public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging) |
2515 | if (m_physicsActor != null) | 2515 | { |
2516 | { | 2516 | if (m_isChildAgent) |
2517 | if (!IsChildAgent) | 2517 | { |
2518 | { | 2518 | // WHAT??? |
2519 | // This may seem like it's redundant, remove the avatar from the physics scene | 2519 | m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); |
2520 | // just to add it back again, but it saves us from having to update | 2520 | |
2521 | // 3 variables 10 times a second. | 2521 | // we have to reset the user's child agent connections. |
2522 | bool flyingTemp = m_physicsActor.Flying; | 2522 | // Likely, here they've lost the eventqueue for other regions so border |
2523 | RemoveFromPhysicalScene(); | 2523 | // crossings will fail at this point unless we reset them. |
2524 | //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor); | 2524 | |
2525 | 2525 | List<ulong> regions = new List<ulong>(KnownChildRegionHandles); | |
2526 | //PhysicsActor = null; | 2526 | regions.Remove(m_scene.RegionInfo.RegionHandle); |
2527 | 2527 | ||
2528 | AddToPhysicalScene(flyingTemp); | 2528 | MakeRootAgent(new Vector3(127f, 127f, 127f), true); |
2529 | } | 2529 | |
2530 | } | 2530 | // Async command |
2531 | 2531 | if (m_scene.SceneGridService != null) | |
2532 | #region Bake Cache Check | 2532 | { |
2533 | 2533 | m_scene.SceneGridService.SendCloseChildAgentConnections(UUID, regions); | |
2534 | if (textureEntry != null) | 2534 | |
2535 | { | 2535 | // Give the above command some time to try and close the connections. |
2536 | for (int i = 0; i < BAKE_INDICES.Length; i++) | 2536 | // this is really an emergency.. so sleep, or we'll get all discombobulated. |
2537 | { | 2537 | System.Threading.Thread.Sleep(500); |
2538 | int j = BAKE_INDICES[i]; | 2538 | } |
2539 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[j]; | 2539 | |
2540 | 2540 | if (m_scene.SceneGridService != null) | |
2541 | if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE) | 2541 | { |
2542 | { | 2542 | IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); |
2543 | if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) | 2543 | if (m_agentTransfer != null) |
2544 | { | 2544 | m_agentTransfer.EnableChildAgents(this); |
2545 | m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); | 2545 | } |
2546 | this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); | 2546 | |
2547 | } | 2547 | return; |
2548 | } | 2548 | } |
2549 | } | 2549 | |
2550 | 2550 | m_perfMonMS = Util.EnvironmentTickCount(); | |
2551 | } | 2551 | |
2552 | 2552 | Rotation = rotation; | |
2553 | 2553 | Vector3 direc = vec * rotation; | |
2554 | #endregion Bake Cache Check | 2554 | direc.Normalize(); |
2555 | 2555 | PhysicsActor actor = m_physicsActor; | |
2556 | m_appearance.SetAppearance(textureEntry, visualParams); | 2556 | if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up. |
2557 | if (m_appearance.AvatarHeight > 0) | 2557 | |
2558 | SetHeight(m_appearance.AvatarHeight); | 2558 | direc *= 0.03f * 128f * m_speedModifier; |
2559 | 2559 | ||
2560 | // This is not needed, because only the transient data changed | 2560 | if (actor != null) |
2561 | //AvatarData adata = new AvatarData(m_appearance); | 2561 | { |
2562 | //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); | 2562 | if (actor.Flying) |
2563 | 2563 | { | |
2564 | SendAppearanceToAllOtherAgents(); | 2564 | direc *= 4.0f; |
2565 | if (!m_startAnimationSet) | 2565 | //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); |
2566 | { | 2566 | //bool colliding = (m_physicsActor.IsColliding==true); |
2567 | Animator.UpdateMovementAnimations(); | 2567 | //if (controlland) |
2568 | m_startAnimationSet = true; | 2568 | // m_log.Info("[AGENT]: landCommand"); |
2569 | } | 2569 | //if (colliding) |
2570 | 2570 | // m_log.Info("[AGENT]: colliding"); | |
2571 | Vector3 pos = m_pos; | 2571 | //if (m_physicsActor.Flying && colliding && controlland) |
2572 | pos.Z += m_appearance.HipOffset; | 2572 | //{ |
2573 | 2573 | // StopFlying(); | |
2574 | m_controllingClient.SendAvatarDataImmediate(this); | 2574 | // m_log.Info("[AGENT]: Stop FLying"); |
2575 | } | 2575 | //} |
2576 | 2576 | } | |
2577 | public void SetWearable(int wearableId, AvatarWearable wearable) | 2577 | else if (!actor.Flying && actor.IsColliding) |
2578 | { | 2578 | { |
2579 | m_appearance.SetWearable(wearableId, wearable); | 2579 | if (direc.Z > 2.0f) |
2580 | AvatarData adata = new AvatarData(m_appearance); | 2580 | { |
2581 | m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); | 2581 | if(m_animator.m_animTickJump == -1) |
2582 | m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); | 2582 | { |
2583 | } | 2583 | direc.Z *= 3.0f; // jump |
2584 | 2584 | } | |
2585 | // Because appearance setting is in a module, we actually need | 2585 | else |
2586 | // to give it access to our appearance directly, otherwise we | 2586 | { |
2587 | // get a synchronization issue. | 2587 | direc.Z *= 0.1f; // prejump |
2588 | public AvatarAppearance Appearance | 2588 | } |
2589 | { | 2589 | /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs |
2590 | get { return m_appearance; } | 2590 | Animator.TrySetMovementAnimation("PREJUMP"); |
2591 | set { m_appearance = value; } | 2591 | Animator.TrySetMovementAnimation("JUMP"); |
2592 | } | 2592 | */ |
2593 | 2593 | } | |
2594 | #endregion | 2594 | } |
2595 | 2595 | } | |
2596 | #region Significant Movement Method | 2596 | |
2597 | 2597 | // TODO: Add the force instead of only setting it to support multiple forces per frame? | |
2598 | /// <summary> | 2598 | m_forceToApply = direc; |
2599 | /// This checks for a significant movement and sends a courselocationchange update | 2599 | m_isNudging = Nudging; |
2600 | /// </summary> | 2600 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
2601 | protected void CheckForSignificantMovement() | 2601 | } |
2602 | { | 2602 | |
2603 | // Movement updates for agents in neighboring regions are sent directly to clients. | 2603 | #endregion |
2604 | // This value only affects how often agent positions are sent to neighbor regions | 2604 | |
2605 | // for things such as distance-based update prioritization | 2605 | #region Overridden Methods |
2606 | const float SIGNIFICANT_MOVEMENT = 2.0f; | 2606 | |
2607 | 2607 | public override void Update() | |
2608 | if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT) | 2608 | { |
2609 | { | 2609 | const float ROTATION_TOLERANCE = 0.01f; |
2610 | posLastSignificantMove = AbsolutePosition; | 2610 | const float VELOCITY_TOLERANCE = 0.001f; |
2611 | m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); | 2611 | const float POSITION_TOLERANCE = 0.05f; |
2612 | } | 2612 | //const int TIME_MS_TOLERANCE = 3000; |
2613 | 2613 | ||
2614 | // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m | 2614 | |
2615 | if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance || | 2615 | |
2616 | Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance) | 2616 | if (m_isChildAgent == false) |
2617 | { | 2617 | { |
2618 | m_lastChildAgentUpdatePosition = AbsolutePosition; | 2618 | // PhysicsActor actor = m_physicsActor; |
2619 | m_lastChildAgentUpdateCamPosition = CameraPosition; | 2619 | |
2620 | 2620 | // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to | |
2621 | ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); | 2621 | // grab the latest PhysicsActor velocity, whereas m_velocity is often |
2622 | cadu.ActiveGroupID = UUID.Zero.Guid; | 2622 | // storing a requested force instead of an actual traveling velocity |
2623 | cadu.AgentID = UUID.Guid; | 2623 | |
2624 | cadu.alwaysrun = m_setAlwaysRun; | 2624 | // Throw away duplicate or insignificant updates |
2625 | cadu.AVHeight = m_avHeight; | 2625 | if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || |
2626 | Vector3 tempCameraCenter = m_CameraCenter; | 2626 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || |
2627 | cadu.cameraPosition = tempCameraCenter; | 2627 | !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) |
2628 | cadu.drawdistance = m_DrawDistance; | 2628 | //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) |
2629 | cadu.GroupAccess = 0; | 2629 | { |
2630 | cadu.Position = AbsolutePosition; | 2630 | SendTerseUpdateToAllClients(); |
2631 | cadu.regionHandle = m_rootRegionHandle; | 2631 | |
2632 | float multiplier = 1; | 2632 | // Update the "last" values |
2633 | int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); | 2633 | m_lastPosition = m_pos; |
2634 | if (innacurateNeighbors != 0) | 2634 | m_lastRotation = m_bodyRot; |
2635 | { | 2635 | m_lastVelocity = Velocity; |
2636 | multiplier = 1f / (float)innacurateNeighbors; | 2636 | //m_lastTerseSent = Environment.TickCount; |
2637 | } | 2637 | } |
2638 | if (multiplier <= 0f) | 2638 | |
2639 | { | 2639 | // followed suggestion from mic bowman. reversed the two lines below. |
2640 | multiplier = 0.25f; | 2640 | if (m_parentID == 0 && m_physicsActor != null || m_parentID != 0) // Check that we have a physics actor or we're sitting on something |
2641 | } | 2641 | CheckForBorderCrossing(); |
2642 | 2642 | CheckForSignificantMovement(); // sends update to the modules. | |
2643 | //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); | 2643 | } |
2644 | cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); | 2644 | |
2645 | cadu.Velocity = Velocity; | 2645 | //Sending prim updates AFTER the avatar terse updates are sent |
2646 | 2646 | SendPrimUpdates(); | |
2647 | AgentPosition agentpos = new AgentPosition(); | 2647 | } |
2648 | agentpos.CopyFrom(cadu); | 2648 | |
2649 | 2649 | #endregion | |
2650 | m_scene.SendOutChildAgentUpdates(agentpos, this); | 2650 | |
2651 | } | 2651 | #region Update Client(s) |
2652 | } | 2652 | |
2653 | 2653 | /// <summary> | |
2654 | #endregion | 2654 | /// Sends a location update to the client connected to this scenePresence |
2655 | 2655 | /// </summary> | |
2656 | #region Border Crossing Methods | 2656 | /// <param name="remoteClient"></param> |
2657 | 2657 | public void SendTerseUpdateToClient(IClientAPI remoteClient) | |
2658 | /// <summary> | 2658 | { |
2659 | /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion | 2659 | // If the client is inactive, it's getting its updates from another |
2660 | /// </summary> | 2660 | // server. |
2661 | protected void CheckForBorderCrossing() | 2661 | if (remoteClient.IsActive) |
2662 | { | 2662 | { |
2663 | if (IsChildAgent) | 2663 | m_perfMonMS = Util.EnvironmentTickCount(); |
2664 | return; | 2664 | |
2665 | 2665 | PhysicsActor actor = m_physicsActor; | |
2666 | Vector3 pos2 = AbsolutePosition; | 2666 | Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero; |
2667 | Vector3 vel = Velocity; | 2667 | |
2668 | int neighbor = 0; | 2668 | Vector3 pos = m_pos; |
2669 | int[] fix = new int[2]; | 2669 | pos.Z += m_appearance.HipOffset; |
2670 | 2670 | ||
2671 | float timeStep = 0.1f; | 2671 | //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity); |
2672 | pos2.X = pos2.X + (vel.X*timeStep); | 2672 | |
2673 | pos2.Y = pos2.Y + (vel.Y*timeStep); | 2673 | remoteClient.SendPrimUpdate(this, PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity); |
2674 | pos2.Z = pos2.Z + (vel.Z*timeStep); | 2674 | |
2675 | 2675 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); | |
2676 | if (!IsInTransit) | 2676 | m_scene.StatsReporter.AddAgentUpdates(1); |
2677 | { | 2677 | } |
2678 | // Checks if where it's headed exists a region | 2678 | } |
2679 | 2679 | ||
2680 | bool needsTransit = false; | 2680 | /// <summary> |
2681 | if (m_scene.TestBorderCross(pos2, Cardinals.W)) | 2681 | /// Send a location/velocity/accelleration update to all agents in scene |
2682 | { | 2682 | /// </summary> |
2683 | if (m_scene.TestBorderCross(pos2, Cardinals.S)) | 2683 | public void SendTerseUpdateToAllClients() |
2684 | { | 2684 | { |
2685 | needsTransit = true; | 2685 | m_perfMonMS = Util.EnvironmentTickCount(); |
2686 | neighbor = HaveNeighbor(Cardinals.SW, ref fix); | 2686 | |
2687 | } | 2687 | m_scene.ForEachClient(SendTerseUpdateToClient); |
2688 | else if (m_scene.TestBorderCross(pos2, Cardinals.N)) | 2688 | |
2689 | { | 2689 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
2690 | needsTransit = true; | 2690 | } |
2691 | neighbor = HaveNeighbor(Cardinals.NW, ref fix); | 2691 | |
2692 | } | 2692 | public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs) |
2693 | else | 2693 | { |
2694 | { | 2694 | SendCourseLocationsMethod d = m_sendCourseLocationsMethod; |
2695 | needsTransit = true; | 2695 | if (d != null) |
2696 | neighbor = HaveNeighbor(Cardinals.W, ref fix); | 2696 | { |
2697 | } | 2697 | d.Invoke(m_scene.RegionInfo.originRegionID, this, coarseLocations, avatarUUIDs); |
2698 | } | 2698 | } |
2699 | else if (m_scene.TestBorderCross(pos2, Cardinals.E)) | 2699 | } |
2700 | { | 2700 | |
2701 | if (m_scene.TestBorderCross(pos2, Cardinals.S)) | 2701 | public void SetSendCourseLocationMethod(SendCourseLocationsMethod d) |
2702 | { | 2702 | { |
2703 | needsTransit = true; | 2703 | if (d != null) |
2704 | neighbor = HaveNeighbor(Cardinals.SE, ref fix); | 2704 | m_sendCourseLocationsMethod = d; |
2705 | } | 2705 | } |
2706 | else if (m_scene.TestBorderCross(pos2, Cardinals.N)) | 2706 | |
2707 | { | 2707 | public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List<Vector3> coarseLocations, List<UUID> avatarUUIDs) |
2708 | needsTransit = true; | 2708 | { |
2709 | neighbor = HaveNeighbor(Cardinals.NE, ref fix); | 2709 | m_perfMonMS = Util.EnvironmentTickCount(); |
2710 | } | 2710 | m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations); |
2711 | else | 2711 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
2712 | { | 2712 | } |
2713 | needsTransit = true; | 2713 | |
2714 | neighbor = HaveNeighbor(Cardinals.E, ref fix); | 2714 | /// <summary> |
2715 | } | 2715 | /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar) |
2716 | } | 2716 | /// </summary> |
2717 | else if (m_scene.TestBorderCross(pos2, Cardinals.S)) | 2717 | /// <param name="remoteAvatar"></param> |
2718 | { | 2718 | public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar) |
2719 | needsTransit = true; | 2719 | { |
2720 | neighbor = HaveNeighbor(Cardinals.S, ref fix); | 2720 | // 2 stage check is needed. |
2721 | } | 2721 | if (remoteAvatar == null) |
2722 | else if (m_scene.TestBorderCross(pos2, Cardinals.N)) | 2722 | return; |
2723 | { | 2723 | IClientAPI cl=remoteAvatar.ControllingClient; |
2724 | needsTransit = true; | 2724 | if (cl == null) |
2725 | neighbor = HaveNeighbor(Cardinals.N, ref fix); | 2725 | return; |
2726 | } | 2726 | if (m_appearance.Texture == null) |
2727 | 2727 | return; | |
2728 | 2728 | ||
2729 | // Makes sure avatar does not end up outside region | 2729 | Vector3 pos = m_pos; |
2730 | if (neighbor <= 0) | 2730 | pos.Z += m_appearance.HipOffset; |
2731 | { | 2731 | |
2732 | if (!needsTransit) | 2732 | remoteAvatar.m_controllingClient.SendAvatarDataImmediate(this); |
2733 | { | 2733 | m_scene.StatsReporter.AddAgentUpdates(1); |
2734 | if (m_requestedSitTargetUUID == UUID.Zero) | 2734 | } |
2735 | { | 2735 | |
2736 | Vector3 pos = AbsolutePosition; | 2736 | /// <summary> |
2737 | if (AbsolutePosition.X < 0) | 2737 | /// Tell *ALL* agents about this agent |
2738 | pos.X += Velocity.X; | 2738 | /// </summary> |
2739 | else if (AbsolutePosition.X > Constants.RegionSize) | 2739 | public void SendInitialFullUpdateToAllClients() |
2740 | pos.X -= Velocity.X; | 2740 | { |
2741 | if (AbsolutePosition.Y < 0) | 2741 | m_perfMonMS = Util.EnvironmentTickCount(); |
2742 | pos.Y += Velocity.Y; | 2742 | int avUpdates = 0; |
2743 | else if (AbsolutePosition.Y > Constants.RegionSize) | 2743 | m_scene.ForEachScenePresence(delegate(ScenePresence avatar) |
2744 | pos.Y -= Velocity.Y; | 2744 | { |
2745 | AbsolutePosition = pos; | 2745 | ++avUpdates; |
2746 | } | 2746 | // only send if this is the root (children are only "listening posts" in a foreign region) |
2747 | } | 2747 | if (!IsChildAgent) |
2748 | } | 2748 | { |
2749 | else if (neighbor > 0) | 2749 | SendFullUpdateToOtherClient(avatar); |
2750 | CrossToNewRegion(); | 2750 | } |
2751 | } | 2751 | |
2752 | else | 2752 | if (avatar.LocalId != LocalId) |
2753 | { | 2753 | { |
2754 | RemoveFromPhysicalScene(); | 2754 | if (!avatar.IsChildAgent) |
2755 | // This constant has been inferred from experimentation | 2755 | { |
2756 | // I'm not sure what this value should be, so I tried a few values. | 2756 | avatar.SendFullUpdateToOtherClient(this); |
2757 | timeStep = 0.04f; | 2757 | avatar.SendAppearanceToOtherAgent(this); |
2758 | pos2 = AbsolutePosition; | 2758 | avatar.Animator.SendAnimPackToClient(ControllingClient); |
2759 | pos2.X = pos2.X + (vel.X * timeStep); | 2759 | } |
2760 | pos2.Y = pos2.Y + (vel.Y * timeStep); | 2760 | } |
2761 | pos2.Z = pos2.Z + (vel.Z * timeStep); | 2761 | }); |
2762 | m_pos = pos2; | 2762 | |
2763 | } | 2763 | m_scene.StatsReporter.AddAgentUpdates(avUpdates); |
2764 | } | 2764 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
2765 | 2765 | ||
2766 | protected int HaveNeighbor(Cardinals car, ref int[] fix) | 2766 | //Animator.SendAnimPack(); |
2767 | { | 2767 | } |
2768 | uint neighbourx = m_regionInfo.RegionLocX; | 2768 | |
2769 | uint neighboury = m_regionInfo.RegionLocY; | 2769 | public void SendFullUpdateToAllClients() |
2770 | 2770 | { | |
2771 | int dir = (int)car; | 2771 | m_perfMonMS = Util.EnvironmentTickCount(); |
2772 | 2772 | ||
2773 | if (dir > 1 && dir < 5) //Heading East | 2773 | // only send update from root agents to other clients; children are only "listening posts" |
2774 | neighbourx++; | 2774 | int count = 0; |
2775 | else if (dir > 5) // Heading West | 2775 | m_scene.ForEachScenePresence(delegate(ScenePresence sp) |
2776 | neighbourx--; | 2776 | { |
2777 | 2777 | if (sp.IsChildAgent) | |
2778 | if (dir < 3 || dir == 8) // Heading North | 2778 | return; |
2779 | neighboury++; | 2779 | SendFullUpdateToOtherClient(sp); |
2780 | else if (dir > 3 && dir < 7) // Heading Sout | 2780 | ++count; |
2781 | neighboury--; | 2781 | }); |
2782 | 2782 | m_scene.StatsReporter.AddAgentUpdates(count); | |
2783 | int x = (int)(neighbourx * Constants.RegionSize); | 2783 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
2784 | int y = (int)(neighboury * Constants.RegionSize); | 2784 | |
2785 | GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, x, y); | 2785 | Animator.SendAnimPack(); |
2786 | 2786 | } | |
2787 | if (neighbourRegion == null) | 2787 | |
2788 | { | 2788 | /// <summary> |
2789 | fix[0] = (int)(m_regionInfo.RegionLocX - neighbourx); | 2789 | /// Do everything required once a client completes its movement into a region |
2790 | fix[1] = (int)(m_regionInfo.RegionLocY - neighboury); | 2790 | /// </summary> |
2791 | return dir * (-1); | 2791 | public void SendInitialData() |
2792 | } | 2792 | { |
2793 | else | 2793 | // Moved this into CompleteMovement to ensure that m_appearance is initialized before |
2794 | return dir; | 2794 | // the inventory arrives |
2795 | } | 2795 | // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); |
2796 | 2796 | ||
2797 | /// <summary> | 2797 | Vector3 pos = m_pos; |
2798 | /// Moves the agent outside the region bounds | 2798 | pos.Z += m_appearance.HipOffset; |
2799 | /// Tells neighbor region that we're crossing to it | 2799 | |
2800 | /// If the neighbor accepts, remove the agent's viewable avatar from this scene | 2800 | m_controllingClient.SendAvatarDataImmediate(this); |
2801 | /// set them to a child agent. | 2801 | |
2802 | /// </summary> | 2802 | SendInitialFullUpdateToAllClients(); |
2803 | protected void CrossToNewRegion() | 2803 | SendAppearanceToAllOtherAgents(); |
2804 | { | 2804 | } |
2805 | InTransit(); | 2805 | |
2806 | try | 2806 | /// <summary> |
2807 | { | 2807 | /// Tell the client for this scene presence what items it should be wearing now |
2808 | m_scene.CrossAgentToNewRegion(this, m_physicsActor.Flying); | 2808 | /// </summary> |
2809 | } | 2809 | public void SendWearables() |
2810 | catch | 2810 | { |
2811 | { | 2811 | m_log.DebugFormat("[SCENE]: Received request for wearables of {0}", Name); |
2812 | m_scene.CrossAgentToNewRegion(this, false); | 2812 | |
2813 | } | 2813 | ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); |
2814 | } | 2814 | } |
2815 | 2815 | ||
2816 | public void InTransit() | 2816 | /// <summary> |
2817 | { | 2817 | /// |
2818 | m_inTransit = true; | 2818 | /// </summary> |
2819 | 2819 | public void SendAppearanceToAllOtherAgents() | |
2820 | if ((m_physicsActor != null) && m_physicsActor.Flying) | 2820 | { |
2821 | m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY; | 2821 | m_perfMonMS = Util.EnvironmentTickCount(); |
2822 | else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0) | 2822 | |
2823 | m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY; | 2823 | m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) |
2824 | } | 2824 | { |
2825 | 2825 | if (scenePresence.UUID != UUID) | |
2826 | public void NotInTransit() | 2826 | { |
2827 | { | 2827 | SendAppearanceToOtherAgent(scenePresence); |
2828 | m_inTransit = false; | 2828 | } |
2829 | } | 2829 | }); |
2830 | 2830 | ||
2831 | public void RestoreInCurrentScene() | 2831 | m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); |
2832 | { | 2832 | } |
2833 | AddToPhysicalScene(false); // not exactly false | 2833 | |
2834 | } | 2834 | /// <summary> |
2835 | 2835 | /// Send appearance data to an agent that isn't this one. | |
2836 | public void Reset() | 2836 | /// </summary> |
2837 | { | 2837 | /// <param name="avatar"></param> |
2838 | // Put the child agent back at the center | 2838 | public void SendAppearanceToOtherAgent(ScenePresence avatar) |
2839 | AbsolutePosition | 2839 | { |
2840 | = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); | 2840 | avatar.ControllingClient.SendAppearance( |
2841 | Animator.ResetAnimations(); | 2841 | m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); |
2842 | } | 2842 | } |
2843 | 2843 | ||
2844 | /// <summary> | 2844 | /// <summary> |
2845 | /// Computes which child agents to close when the scene presence moves to another region. | 2845 | /// Set appearance data (textureentry and slider settings) received from the client |
2846 | /// Removes those regions from m_knownRegions. | 2846 | /// </summary> |
2847 | /// </summary> | 2847 | /// <param name="texture"></param> |
2848 | /// <param name="newRegionX">The new region's x on the map</param> | 2848 | /// <param name="visualParam"></param> |
2849 | /// <param name="newRegionY">The new region's y on the map</param> | 2849 | public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) |
2850 | /// <returns></returns> | 2850 | { |
2851 | public void CloseChildAgents(uint newRegionX, uint newRegionY) | 2851 | if (m_physicsActor != null) |
2852 | { | 2852 | { |
2853 | List<ulong> byebyeRegions = new List<ulong>(); | 2853 | if (!IsChildAgent) |
2854 | m_log.DebugFormat( | 2854 | { |
2855 | "[SCENE PRESENCE]: Closing child agents. Checking {0} regions in {1}", | 2855 | // This may seem like it's redundant, remove the avatar from the physics scene |
2856 | m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName); | 2856 | // just to add it back again, but it saves us from having to update |
2857 | //DumpKnownRegions(); | 2857 | // 3 variables 10 times a second. |
2858 | 2858 | bool flyingTemp = m_physicsActor.Flying; | |
2859 | lock (m_knownChildRegions) | 2859 | RemoveFromPhysicalScene(); |
2860 | { | 2860 | //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor); |
2861 | foreach (ulong handle in m_knownChildRegions.Keys) | 2861 | |
2862 | { | 2862 | //PhysicsActor = null; |
2863 | // Don't close the agent on this region yet | 2863 | |
2864 | if (handle != Scene.RegionInfo.RegionHandle) | 2864 | AddToPhysicalScene(flyingTemp); |
2865 | { | 2865 | } |
2866 | uint x, y; | 2866 | } |
2867 | Utils.LongToUInts(handle, out x, out y); | 2867 | |
2868 | x = x / Constants.RegionSize; | 2868 | #region Bake Cache Check |
2869 | y = y / Constants.RegionSize; | 2869 | |
2870 | 2870 | if (textureEntry != null) | |
2871 | //m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); | 2871 | { |
2872 | //m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); | 2872 | for (int i = 0; i < BAKE_INDICES.Length; i++) |
2873 | if (Util.IsOutsideView(x, newRegionX, y, newRegionY)) | 2873 | { |
2874 | { | 2874 | int j = BAKE_INDICES[i]; |
2875 | byebyeRegions.Add(handle); | 2875 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[j]; |
2876 | } | 2876 | |
2877 | } | 2877 | if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE) |
2878 | } | 2878 | { |
2879 | } | 2879 | if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) |
2880 | 2880 | { | |
2881 | if (byebyeRegions.Count > 0) | 2881 | m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); |
2882 | { | 2882 | this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); |
2883 | m_log.Debug("[SCENE PRESENCE]: Closing " + byebyeRegions.Count + " child agents"); | 2883 | } |
2884 | m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions); | 2884 | } |
2885 | } | 2885 | } |
2886 | 2886 | ||
2887 | foreach (ulong handle in byebyeRegions) | 2887 | } |
2888 | { | 2888 | |
2889 | RemoveNeighbourRegion(handle); | 2889 | |
2890 | } | 2890 | #endregion Bake Cache Check |
2891 | } | 2891 | |
2892 | 2892 | m_appearance.SetAppearance(textureEntry, visualParams); | |
2893 | #endregion | 2893 | if (m_appearance.AvatarHeight > 0) |
2894 | 2894 | SetHeight(m_appearance.AvatarHeight); | |
2895 | /// <summary> | 2895 | |
2896 | /// This allows the Sim owner the abiility to kick users from their sim currently. | 2896 | // This is not needed, because only the transient data changed |
2897 | /// It tells the client that the agent has permission to do so. | 2897 | //AvatarData adata = new AvatarData(m_appearance); |
2898 | /// </summary> | 2898 | //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); |
2899 | public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus) | 2899 | |
2900 | { | 2900 | SendAppearanceToAllOtherAgents(); |
2901 | if (godStatus) | 2901 | if (!m_startAnimationSet) |
2902 | { | 2902 | { |
2903 | // For now, assign god level 200 to anyone | 2903 | Animator.UpdateMovementAnimations(); |
2904 | // who is granted god powers, but has no god level set. | 2904 | m_startAnimationSet = true; |
2905 | // | 2905 | } |
2906 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID); | 2906 | |
2907 | if (account != null) | 2907 | Vector3 pos = m_pos; |
2908 | { | 2908 | pos.Z += m_appearance.HipOffset; |
2909 | if (account.UserLevel > 0) | 2909 | |
2910 | m_godLevel = account.UserLevel; | 2910 | m_controllingClient.SendAvatarDataImmediate(this); |
2911 | else | 2911 | } |
2912 | m_godLevel = 200; | 2912 | |
2913 | } | 2913 | public void SetWearable(int wearableId, AvatarWearable wearable) |
2914 | } | 2914 | { |
2915 | else | 2915 | m_appearance.SetWearable(wearableId, wearable); |
2916 | { | 2916 | AvatarData adata = new AvatarData(m_appearance); |
2917 | m_godLevel = 0; | 2917 | m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); |
2918 | } | 2918 | m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); |
2919 | 2919 | } | |
2920 | ControllingClient.SendAdminResponse(token, (uint)m_godLevel); | 2920 | |
2921 | } | 2921 | // Because appearance setting is in a module, we actually need |
2922 | 2922 | // to give it access to our appearance directly, otherwise we | |
2923 | #region Child Agent Updates | 2923 | // get a synchronization issue. |
2924 | 2924 | public AvatarAppearance Appearance | |
2925 | public void ChildAgentDataUpdate(AgentData cAgentData) | 2925 | { |
2926 | { | 2926 | get { return m_appearance; } |
2927 | //m_log.Debug(" >>> ChildAgentDataUpdate <<< " + Scene.RegionInfo.RegionName); | 2927 | set { m_appearance = value; } |
2928 | if (!IsChildAgent) | 2928 | } |
2929 | return; | 2929 | |
2930 | 2930 | #endregion | |
2931 | CopyFrom(cAgentData); | 2931 | |
2932 | } | 2932 | #region Significant Movement Method |
2933 | 2933 | ||
2934 | /// <summary> | 2934 | /// <summary> |
2935 | /// This updates important decision making data about a child agent | 2935 | /// This checks for a significant movement and sends a courselocationchange update |
2936 | /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region | 2936 | /// </summary> |
2937 | /// </summary> | 2937 | protected void CheckForSignificantMovement() |
2938 | public void ChildAgentDataUpdate(AgentPosition cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY) | 2938 | { |
2939 | { | 2939 | // Movement updates for agents in neighboring regions are sent directly to clients. |
2940 | if (!IsChildAgent) | 2940 | // This value only affects how often agent positions are sent to neighbor regions |
2941 | return; | 2941 | // for things such as distance-based update prioritization |
2942 | 2942 | const float SIGNIFICANT_MOVEMENT = 2.0f; | |
2943 | //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); | 2943 | |
2944 | int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; | 2944 | if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT) |
2945 | int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; | 2945 | { |
2946 | 2946 | posLastSignificantMove = AbsolutePosition; | |
2947 | Vector3 offset = new Vector3(shiftx, shifty, 0f); | 2947 | m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); |
2948 | 2948 | } | |
2949 | m_DrawDistance = cAgentData.Far; | 2949 | |
2950 | if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!! | 2950 | // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m |
2951 | m_pos = cAgentData.Position + offset; | 2951 | if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance || |
2952 | 2952 | Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance) | |
2953 | if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance) | 2953 | { |
2954 | { | 2954 | m_lastChildAgentUpdatePosition = AbsolutePosition; |
2955 | posLastSignificantMove = AbsolutePosition; | 2955 | m_lastChildAgentUpdateCamPosition = CameraPosition; |
2956 | ReprioritizeUpdates(); | 2956 | |
2957 | } | 2957 | ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); |
2958 | 2958 | cadu.ActiveGroupID = UUID.Zero.Guid; | |
2959 | m_CameraCenter = cAgentData.Center + offset; | 2959 | cadu.AgentID = UUID.Guid; |
2960 | 2960 | cadu.alwaysrun = m_setAlwaysRun; | |
2961 | m_avHeight = cAgentData.Size.Z; | 2961 | cadu.AVHeight = m_avHeight; |
2962 | //SetHeight(cAgentData.AVHeight); | 2962 | Vector3 tempCameraCenter = m_CameraCenter; |
2963 | 2963 | cadu.cameraPosition = tempCameraCenter; | |
2964 | if ((cAgentData.Throttles != null) && cAgentData.Throttles.Length > 0) | 2964 | cadu.drawdistance = m_DrawDistance; |
2965 | ControllingClient.SetChildAgentThrottle(cAgentData.Throttles); | 2965 | cadu.GroupAccess = 0; |
2966 | 2966 | cadu.Position = AbsolutePosition; | |
2967 | // Sends out the objects in the user's draw distance if m_sendTasksToChild is true. | 2967 | cadu.regionHandle = m_rootRegionHandle; |
2968 | if (m_scene.m_seeIntoRegionFromNeighbor) | 2968 | float multiplier = 1; |
2969 | m_sceneViewer.Reset(); | 2969 | int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); |
2970 | 2970 | if (innacurateNeighbors != 0) | |
2971 | //cAgentData.AVHeight; | 2971 | { |
2972 | m_rootRegionHandle = cAgentData.RegionHandle; | 2972 | multiplier = 1f / (float)innacurateNeighbors; |
2973 | //m_velocity = cAgentData.Velocity; | 2973 | } |
2974 | } | 2974 | if (multiplier <= 0f) |
2975 | 2975 | { | |
2976 | public void CopyTo(AgentData cAgent) | 2976 | multiplier = 0.25f; |
2977 | { | 2977 | } |
2978 | cAgent.AgentID = UUID; | 2978 | |
2979 | cAgent.RegionID = Scene.RegionInfo.RegionID; | 2979 | //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); |
2980 | 2980 | cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); | |
2981 | cAgent.Position = AbsolutePosition; | 2981 | cadu.Velocity = Velocity; |
2982 | cAgent.Velocity = m_velocity; | 2982 | |
2983 | cAgent.Center = m_CameraCenter; | 2983 | AgentPosition agentpos = new AgentPosition(); |
2984 | // Don't copy the size; it is inferred from apearance parameters | 2984 | agentpos.CopyFrom(cadu); |
2985 | //cAgent.Size = new Vector3(0, 0, m_avHeight); | 2985 | |
2986 | cAgent.AtAxis = m_CameraAtAxis; | 2986 | m_scene.SendOutChildAgentUpdates(agentpos, this); |
2987 | cAgent.LeftAxis = m_CameraLeftAxis; | 2987 | } |
2988 | cAgent.UpAxis = m_CameraUpAxis; | 2988 | } |
2989 | 2989 | ||
2990 | cAgent.Far = m_DrawDistance; | 2990 | #endregion |
2991 | 2991 | ||
2992 | // Throttles | 2992 | #region Border Crossing Methods |
2993 | float multiplier = 1; | 2993 | |
2994 | int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); | 2994 | /// <summary> |
2995 | if (innacurateNeighbors != 0) | 2995 | /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion |
2996 | { | 2996 | /// </summary> |
2997 | multiplier = 1f / innacurateNeighbors; | 2997 | protected void CheckForBorderCrossing() |
2998 | } | 2998 | { |
2999 | if (multiplier <= 0f) | 2999 | if (IsChildAgent) |
3000 | { | 3000 | return; |
3001 | multiplier = 0.25f; | 3001 | |
3002 | } | 3002 | Vector3 pos2 = AbsolutePosition; |
3003 | //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); | 3003 | Vector3 vel = Velocity; |
3004 | cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier); | 3004 | int neighbor = 0; |
3005 | 3005 | int[] fix = new int[2]; | |
3006 | cAgent.HeadRotation = m_headrotation; | 3006 | |
3007 | cAgent.BodyRotation = m_bodyRot; | 3007 | float timeStep = 0.1f; |
3008 | cAgent.ControlFlags = (uint)m_AgentControlFlags; | 3008 | pos2.X = pos2.X + (vel.X*timeStep); |
3009 | 3009 | pos2.Y = pos2.Y + (vel.Y*timeStep); | |
3010 | if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) | 3010 | pos2.Z = pos2.Z + (vel.Z*timeStep); |
3011 | cAgent.GodLevel = (byte)m_godLevel; | 3011 | |
3012 | else | 3012 | if (!IsInTransit) |
3013 | cAgent.GodLevel = (byte) 0; | 3013 | { |
3014 | 3014 | // Checks if where it's headed exists a region | |
3015 | cAgent.AlwaysRun = m_setAlwaysRun; | 3015 | |
3016 | 3016 | bool needsTransit = false; | |
3017 | try | 3017 | if (m_scene.TestBorderCross(pos2, Cardinals.W)) |
3018 | { | 3018 | { |
3019 | // We might not pass the Wearables in all cases... | 3019 | if (m_scene.TestBorderCross(pos2, Cardinals.S)) |
3020 | // They're only needed so that persistent changes to the appearance | 3020 | { |
3021 | // are preserved in the new region where the user is moving to. | 3021 | needsTransit = true; |
3022 | // But in Hypergrid we might not let this happen. | 3022 | neighbor = HaveNeighbor(Cardinals.SW, ref fix); |
3023 | int i = 0; | 3023 | } |
3024 | UUID[] wears = new UUID[m_appearance.Wearables.Length * 2]; | 3024 | else if (m_scene.TestBorderCross(pos2, Cardinals.N)) |
3025 | foreach (AvatarWearable aw in m_appearance.Wearables) | 3025 | { |
3026 | { | 3026 | needsTransit = true; |
3027 | if (aw != null) | 3027 | neighbor = HaveNeighbor(Cardinals.NW, ref fix); |
3028 | { | 3028 | } |
3029 | wears[i++] = aw.ItemID; | 3029 | else |
3030 | wears[i++] = aw.AssetID; | 3030 | { |
3031 | } | 3031 | needsTransit = true; |
3032 | else | 3032 | neighbor = HaveNeighbor(Cardinals.W, ref fix); |
3033 | { | 3033 | } |
3034 | wears[i++] = UUID.Zero; | 3034 | } |
3035 | wears[i++] = UUID.Zero; | 3035 | else if (m_scene.TestBorderCross(pos2, Cardinals.E)) |
3036 | } | 3036 | { |
3037 | } | 3037 | if (m_scene.TestBorderCross(pos2, Cardinals.S)) |
3038 | cAgent.Wearables = wears; | 3038 | { |
3039 | 3039 | needsTransit = true; | |
3040 | cAgent.VisualParams = m_appearance.VisualParams; | 3040 | neighbor = HaveNeighbor(Cardinals.SE, ref fix); |
3041 | 3041 | } | |
3042 | if (m_appearance.Texture != null) | 3042 | else if (m_scene.TestBorderCross(pos2, Cardinals.N)) |
3043 | cAgent.AgentTextures = m_appearance.Texture.GetBytes(); | 3043 | { |
3044 | } | 3044 | needsTransit = true; |
3045 | catch (Exception e) | 3045 | neighbor = HaveNeighbor(Cardinals.NE, ref fix); |
3046 | { | 3046 | } |
3047 | m_log.Warn("[SCENE PRESENCE]: exception in CopyTo " + e.Message); | 3047 | else |
3048 | } | 3048 | { |
3049 | 3049 | needsTransit = true; | |
3050 | //Attachments | 3050 | neighbor = HaveNeighbor(Cardinals.E, ref fix); |
3051 | List<int> attPoints = m_appearance.GetAttachedPoints(); | 3051 | } |
3052 | if (attPoints != null) | 3052 | } |
3053 | { | 3053 | else if (m_scene.TestBorderCross(pos2, Cardinals.S)) |
3054 | //m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count); | 3054 | { |
3055 | int i = 0; | 3055 | needsTransit = true; |
3056 | AttachmentData[] attachs = new AttachmentData[attPoints.Count]; | 3056 | neighbor = HaveNeighbor(Cardinals.S, ref fix); |
3057 | foreach (int point in attPoints) | 3057 | } |
3058 | { | 3058 | else if (m_scene.TestBorderCross(pos2, Cardinals.N)) |
3059 | attachs[i++] = new AttachmentData(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); | 3059 | { |
3060 | } | 3060 | needsTransit = true; |
3061 | cAgent.Attachments = attachs; | 3061 | neighbor = HaveNeighbor(Cardinals.N, ref fix); |
3062 | } | 3062 | } |
3063 | 3063 | ||
3064 | lock (scriptedcontrols) | 3064 | |
3065 | { | 3065 | // Makes sure avatar does not end up outside region |
3066 | ControllerData[] controls = new ControllerData[scriptedcontrols.Count]; | 3066 | if (neighbor <= 0) |
3067 | int i = 0; | 3067 | { |
3068 | 3068 | if (!needsTransit) | |
3069 | foreach (ScriptControllers c in scriptedcontrols.Values) | 3069 | { |
3070 | { | 3070 | if (m_requestedSitTargetUUID == UUID.Zero) |
3071 | controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); | 3071 | { |
3072 | } | 3072 | Vector3 pos = AbsolutePosition; |
3073 | cAgent.Controllers = controls; | 3073 | if (AbsolutePosition.X < 0) |
3074 | } | 3074 | pos.X += Velocity.X; |
3075 | 3075 | else if (AbsolutePosition.X > Constants.RegionSize) | |
3076 | // Animations | 3076 | pos.X -= Velocity.X; |
3077 | try | 3077 | if (AbsolutePosition.Y < 0) |
3078 | { | 3078 | pos.Y += Velocity.Y; |
3079 | cAgent.Anims = Animator.Animations.ToArray(); | 3079 | else if (AbsolutePosition.Y > Constants.RegionSize) |
3080 | } | 3080 | pos.Y -= Velocity.Y; |
3081 | catch { } | 3081 | AbsolutePosition = pos; |
3082 | 3082 | } | |
3083 | // cAgent.GroupID = ?? | 3083 | } |
3084 | // Groups??? | 3084 | } |
3085 | 3085 | else if (neighbor > 0) | |
3086 | } | 3086 | CrossToNewRegion(); |
3087 | 3087 | } | |
3088 | public void CopyFrom(AgentData cAgent) | 3088 | else |
3089 | { | 3089 | { |
3090 | m_originRegionID = cAgent.RegionID; | 3090 | RemoveFromPhysicalScene(); |
3091 | 3091 | // This constant has been inferred from experimentation | |
3092 | m_callbackURI = cAgent.CallbackURI; | 3092 | // I'm not sure what this value should be, so I tried a few values. |
3093 | 3093 | timeStep = 0.04f; | |
3094 | m_pos = cAgent.Position; | 3094 | pos2 = AbsolutePosition; |
3095 | m_velocity = cAgent.Velocity; | 3095 | pos2.X = pos2.X + (vel.X * timeStep); |
3096 | m_CameraCenter = cAgent.Center; | 3096 | pos2.Y = pos2.Y + (vel.Y * timeStep); |
3097 | //m_avHeight = cAgent.Size.Z; | 3097 | pos2.Z = pos2.Z + (vel.Z * timeStep); |
3098 | m_CameraAtAxis = cAgent.AtAxis; | 3098 | m_pos = pos2; |
3099 | m_CameraLeftAxis = cAgent.LeftAxis; | 3099 | } |
3100 | m_CameraUpAxis = cAgent.UpAxis; | 3100 | } |
3101 | 3101 | ||
3102 | m_DrawDistance = cAgent.Far; | 3102 | protected int HaveNeighbor(Cardinals car, ref int[] fix) |
3103 | 3103 | { | |
3104 | if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0) | 3104 | uint neighbourx = m_regionInfo.RegionLocX; |
3105 | ControllingClient.SetChildAgentThrottle(cAgent.Throttles); | 3105 | uint neighboury = m_regionInfo.RegionLocY; |
3106 | 3106 | ||
3107 | m_headrotation = cAgent.HeadRotation; | 3107 | int dir = (int)car; |
3108 | m_bodyRot = cAgent.BodyRotation; | 3108 | |
3109 | m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; | 3109 | if (dir > 1 && dir < 5) //Heading East |
3110 | 3110 | neighbourx++; | |
3111 | if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) | 3111 | else if (dir > 5) // Heading West |
3112 | m_godLevel = cAgent.GodLevel; | 3112 | neighbourx--; |
3113 | m_setAlwaysRun = cAgent.AlwaysRun; | 3113 | |
3114 | 3114 | if (dir < 3 || dir == 8) // Heading North | |
3115 | uint i = 0; | 3115 | neighboury++; |
3116 | try | 3116 | else if (dir > 3 && dir < 7) // Heading Sout |
3117 | { | 3117 | neighboury--; |
3118 | if (cAgent.Wearables == null) | 3118 | |
3119 | cAgent.Wearables = new UUID[0]; | 3119 | int x = (int)(neighbourx * Constants.RegionSize); |
3120 | AvatarWearable[] wears = new AvatarWearable[cAgent.Wearables.Length / 2]; | 3120 | int y = (int)(neighboury * Constants.RegionSize); |
3121 | for (uint n = 0; n < cAgent.Wearables.Length; n += 2) | 3121 | GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, x, y); |
3122 | { | 3122 | |
3123 | UUID itemId = cAgent.Wearables[n]; | 3123 | if (neighbourRegion == null) |
3124 | UUID assetId = cAgent.Wearables[n + 1]; | 3124 | { |
3125 | wears[i++] = new AvatarWearable(itemId, assetId); | 3125 | fix[0] = (int)(m_regionInfo.RegionLocX - neighbourx); |
3126 | } | 3126 | fix[1] = (int)(m_regionInfo.RegionLocY - neighboury); |
3127 | m_appearance.Wearables = wears; | 3127 | return dir * (-1); |
3128 | Primitive.TextureEntry te; | 3128 | } |
3129 | if (cAgent.AgentTextures != null && cAgent.AgentTextures.Length > 1) | 3129 | else |
3130 | te = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length); | 3130 | return dir; |
3131 | else | 3131 | } |
3132 | te = AvatarAppearance.GetDefaultTexture(); | 3132 | |
3133 | if ((cAgent.VisualParams == null) || (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT)) | 3133 | /// <summary> |
3134 | cAgent.VisualParams = AvatarAppearance.GetDefaultVisualParams(); | 3134 | /// Moves the agent outside the region bounds |
3135 | m_appearance.SetAppearance(te, (byte[])cAgent.VisualParams.Clone()); | 3135 | /// Tells neighbor region that we're crossing to it |
3136 | } | 3136 | /// If the neighbor accepts, remove the agent's viewable avatar from this scene |
3137 | catch (Exception e) | 3137 | /// set them to a child agent. |
3138 | { | 3138 | /// </summary> |
3139 | m_log.Warn("[SCENE PRESENCE]: exception in CopyFrom " + e.Message); | 3139 | protected void CrossToNewRegion() |
3140 | } | 3140 | { |
3141 | 3141 | InTransit(); | |
3142 | // Attachments | 3142 | try |
3143 | try | 3143 | { |
3144 | { | 3144 | m_scene.CrossAgentToNewRegion(this, m_physicsActor.Flying); |
3145 | if (cAgent.Attachments != null) | 3145 | } |
3146 | { | 3146 | catch |
3147 | m_appearance.ClearAttachments(); | 3147 | { |
3148 | foreach (AttachmentData att in cAgent.Attachments) | 3148 | m_scene.CrossAgentToNewRegion(this, false); |
3149 | { | 3149 | } |
3150 | m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID); | 3150 | } |
3151 | } | 3151 | |
3152 | } | 3152 | public void InTransit() |
3153 | } | 3153 | { |
3154 | catch { } | 3154 | m_inTransit = true; |
3155 | 3155 | ||
3156 | try | 3156 | if ((m_physicsActor != null) && m_physicsActor.Flying) |
3157 | { | 3157 | m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY; |
3158 | lock (scriptedcontrols) | 3158 | else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0) |
3159 | { | 3159 | m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY; |
3160 | if (cAgent.Controllers != null) | 3160 | } |
3161 | { | 3161 | |
3162 | scriptedcontrols.Clear(); | 3162 | public void NotInTransit() |
3163 | 3163 | { | |
3164 | foreach (ControllerData c in cAgent.Controllers) | 3164 | m_inTransit = false; |
3165 | { | 3165 | } |
3166 | ScriptControllers sc = new ScriptControllers(); | 3166 | |
3167 | sc.itemID = c.ItemID; | 3167 | public void RestoreInCurrentScene() |
3168 | sc.ignoreControls = (ScriptControlled)c.IgnoreControls; | 3168 | { |
3169 | sc.eventControls = (ScriptControlled)c.EventControls; | 3169 | AddToPhysicalScene(false); // not exactly false |
3170 | 3170 | } | |
3171 | scriptedcontrols[sc.itemID] = sc; | 3171 | |
3172 | } | 3172 | public void Reset() |
3173 | } | 3173 | { |
3174 | } | 3174 | // Put the child agent back at the center |
3175 | } | 3175 | AbsolutePosition |
3176 | catch { } | 3176 | = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); |
3177 | // Animations | 3177 | Animator.ResetAnimations(); |
3178 | try | 3178 | } |
3179 | { | 3179 | |
3180 | Animator.ResetAnimations(); | 3180 | /// <summary> |
3181 | Animator.Animations.FromArray(cAgent.Anims); | 3181 | /// Computes which child agents to close when the scene presence moves to another region. |
3182 | } | 3182 | /// Removes those regions from m_knownRegions. |
3183 | catch { } | 3183 | /// </summary> |
3184 | 3184 | /// <param name="newRegionX">The new region's x on the map</param> | |
3185 | //cAgent.GroupID = ?? | 3185 | /// <param name="newRegionY">The new region's y on the map</param> |
3186 | //Groups??? | 3186 | /// <returns></returns> |
3187 | } | 3187 | public void CloseChildAgents(uint newRegionX, uint newRegionY) |
3188 | 3188 | { | |
3189 | public bool CopyAgent(out IAgentData agent) | 3189 | List<ulong> byebyeRegions = new List<ulong>(); |
3190 | { | 3190 | m_log.DebugFormat( |
3191 | agent = new CompleteAgentData(); | 3191 | "[SCENE PRESENCE]: Closing child agents. Checking {0} regions in {1}", |
3192 | CopyTo((AgentData)agent); | 3192 | m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName); |
3193 | return true; | 3193 | //DumpKnownRegions(); |
3194 | } | 3194 | |
3195 | 3195 | lock (m_knownChildRegions) | |
3196 | #endregion Child Agent Updates | 3196 | { |
3197 | 3197 | foreach (ulong handle in m_knownChildRegions.Keys) | |
3198 | /// <summary> | 3198 | { |
3199 | /// Handles part of the PID controller function for moving an avatar. | 3199 | // Don't close the agent on this region yet |
3200 | /// </summary> | 3200 | if (handle != Scene.RegionInfo.RegionHandle) |
3201 | public override void UpdateMovement() | 3201 | { |
3202 | { | 3202 | uint x, y; |
3203 | if (m_forceToApply.HasValue) | 3203 | Utils.LongToUInts(handle, out x, out y); |
3204 | { | 3204 | x = x / Constants.RegionSize; |
3205 | Vector3 force = m_forceToApply.Value; | 3205 | y = y / Constants.RegionSize; |
3206 | 3206 | ||
3207 | m_updateflag = true; | 3207 | //m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); |
3208 | // movementvector = force; | 3208 | //m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); |
3209 | Velocity = force; | 3209 | if (Util.IsOutsideView(x, newRegionX, y, newRegionY)) |
3210 | 3210 | { | |
3211 | m_forceToApply = null; | 3211 | byebyeRegions.Add(handle); |
3212 | } | 3212 | } |
3213 | } | 3213 | } |
3214 | 3214 | } | |
3215 | public override void SetText(string text, Vector3 color, double alpha) | 3215 | } |
3216 | { | 3216 | |
3217 | throw new Exception("Can't set Text on avatar."); | 3217 | if (byebyeRegions.Count > 0) |
3218 | } | 3218 | { |
3219 | 3219 | m_log.Debug("[SCENE PRESENCE]: Closing " + byebyeRegions.Count + " child agents"); | |
3220 | /// <summary> | 3220 | m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions); |
3221 | /// Adds a physical representation of the avatar to the Physics plugin | 3221 | } |
3222 | /// </summary> | 3222 | |
3223 | public void AddToPhysicalScene(bool isFlying) | 3223 | foreach (ulong handle in byebyeRegions) |
3224 | { | 3224 | { |
3225 | PhysicsScene scene = m_scene.PhysicsScene; | 3225 | RemoveNeighbourRegion(handle); |
3226 | 3226 | } | |
3227 | Vector3 pVec = AbsolutePosition; | 3227 | } |
3228 | 3228 | ||
3229 | // Old bug where the height was in centimeters instead of meters | 3229 | #endregion |
3230 | if (m_avHeight == 127.0f) | 3230 | |
3231 | { | 3231 | /// <summary> |
3232 | m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new Vector3(0f, 0f, 1.56f), | 3232 | /// This allows the Sim owner the abiility to kick users from their sim currently. |
3233 | isFlying); | 3233 | /// It tells the client that the agent has permission to do so. |
3234 | } | 3234 | /// </summary> |
3235 | else | 3235 | public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus) |
3236 | { | 3236 | { |
3237 | m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, | 3237 | if (godStatus) |
3238 | new Vector3(0f, 0f, m_avHeight), isFlying); | 3238 | { |
3239 | } | 3239 | // For now, assign god level 200 to anyone |
3240 | scene.AddPhysicsActorTaint(m_physicsActor); | 3240 | // who is granted god powers, but has no god level set. |
3241 | //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; | 3241 | // |
3242 | m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; | 3242 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID); |
3243 | m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong | 3243 | if (account != null) |
3244 | m_physicsActor.SubscribeEvents(500); | 3244 | { |
3245 | m_physicsActor.LocalID = LocalId; | 3245 | if (account.UserLevel > 0) |
3246 | } | 3246 | m_godLevel = account.UserLevel; |
3247 | 3247 | else | |
3248 | private void OutOfBoundsCall(Vector3 pos) | 3248 | m_godLevel = 200; |
3249 | { | 3249 | } |
3250 | //bool flying = m_physicsActor.Flying; | 3250 | } |
3251 | //RemoveFromPhysicalScene(); | 3251 | else |
3252 | 3252 | { | |
3253 | //AddToPhysicalScene(flying); | 3253 | m_godLevel = 0; |
3254 | if (ControllingClient != null) | 3254 | } |
3255 | ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); | 3255 | |
3256 | } | 3256 | ControllingClient.SendAdminResponse(token, (uint)m_godLevel); |
3257 | 3257 | } | |
3258 | // Event called by the physics plugin to tell the avatar about a collision. | 3258 | |
3259 | private void PhysicsCollisionUpdate(EventArgs e) | 3259 | #region Child Agent Updates |
3260 | { | 3260 | |
3261 | if (e == null) | 3261 | public void ChildAgentDataUpdate(AgentData cAgentData) |
3262 | return; | 3262 | { |
3263 | 3263 | //m_log.Debug(" >>> ChildAgentDataUpdate <<< " + Scene.RegionInfo.RegionName); | |
3264 | //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) | 3264 | if (!IsChildAgent) |
3265 | // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents( | 3265 | return; |
3266 | // as of this comment the interval is set in AddToPhysicalScene | 3266 | |
3267 | if (Animator!=null) | 3267 | CopyFrom(cAgentData); |
3268 | Animator.UpdateMovementAnimations(); | 3268 | } |
3269 | 3269 | ||
3270 | CollisionEventUpdate collisionData = (CollisionEventUpdate)e; | 3270 | /// <summary> |
3271 | Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; | 3271 | /// This updates important decision making data about a child agent |
3272 | 3272 | /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region | |
3273 | CollisionPlane = Vector4.UnitW; | 3273 | /// </summary> |
3274 | 3274 | public void ChildAgentDataUpdate(AgentPosition cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY) | |
3275 | if (coldata.Count != 0 && Animator != null) | 3275 | { |
3276 | { | 3276 | if (!IsChildAgent) |
3277 | switch (Animator.CurrentMovementAnimation) | 3277 | return; |
3278 | { | 3278 | |
3279 | case "STAND": | 3279 | //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); |
3280 | case "WALK": | 3280 | int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; |
3281 | case "RUN": | 3281 | int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; |
3282 | case "CROUCH": | 3282 | |
3283 | case "CROUCHWALK": | 3283 | Vector3 offset = new Vector3(shiftx, shifty, 0f); |
3284 | { | 3284 | |
3285 | ContactPoint lowest; | 3285 | m_DrawDistance = cAgentData.Far; |
3286 | lowest.SurfaceNormal = Vector3.Zero; | 3286 | if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!! |
3287 | lowest.Position = Vector3.Zero; | 3287 | m_pos = cAgentData.Position + offset; |
3288 | lowest.Position.Z = Single.NaN; | 3288 | |
3289 | 3289 | if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance) | |
3290 | foreach (ContactPoint contact in coldata.Values) | 3290 | { |
3291 | { | 3291 | posLastSignificantMove = AbsolutePosition; |
3292 | if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) | 3292 | ReprioritizeUpdates(); |
3293 | { | 3293 | } |
3294 | lowest = contact; | 3294 | |
3295 | } | 3295 | m_CameraCenter = cAgentData.Center + offset; |
3296 | } | 3296 | |
3297 | 3297 | m_avHeight = cAgentData.Size.Z; | |
3298 | CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); | 3298 | //SetHeight(cAgentData.AVHeight); |
3299 | } | 3299 | |
3300 | break; | 3300 | if ((cAgentData.Throttles != null) && cAgentData.Throttles.Length > 0) |
3301 | } | 3301 | ControllingClient.SetChildAgentThrottle(cAgentData.Throttles); |
3302 | } | 3302 | |
3303 | 3303 | // Sends out the objects in the user's draw distance if m_sendTasksToChild is true. | |
3304 | if (m_invulnerable) | 3304 | if (m_scene.m_seeIntoRegionFromNeighbor) |
3305 | return; | 3305 | m_sceneViewer.Reset(); |
3306 | 3306 | ||
3307 | float starthealth = Health; | 3307 | //cAgentData.AVHeight; |
3308 | uint killerObj = 0; | 3308 | m_rootRegionHandle = cAgentData.RegionHandle; |
3309 | foreach (uint localid in coldata.Keys) | 3309 | //m_velocity = cAgentData.Velocity; |
3310 | { | 3310 | } |
3311 | SceneObjectPart part = Scene.GetSceneObjectPart(localid); | 3311 | |
3312 | 3312 | public void CopyTo(AgentData cAgent) | |
3313 | if (part != null && part.ParentGroup.Damage != -1.0f) | 3313 | { |
3314 | Health -= part.ParentGroup.Damage; | 3314 | cAgent.AgentID = UUID; |
3315 | else | 3315 | cAgent.RegionID = Scene.RegionInfo.RegionID; |
3316 | { | 3316 | |
3317 | if (coldata[localid].PenetrationDepth >= 0.10f) | 3317 | cAgent.Position = AbsolutePosition; |
3318 | Health -= coldata[localid].PenetrationDepth * 5.0f; | 3318 | cAgent.Velocity = m_velocity; |
3319 | } | 3319 | cAgent.Center = m_CameraCenter; |
3320 | 3320 | // Don't copy the size; it is inferred from apearance parameters | |
3321 | if (Health <= 0.0f) | 3321 | //cAgent.Size = new Vector3(0, 0, m_avHeight); |
3322 | { | 3322 | cAgent.AtAxis = m_CameraAtAxis; |
3323 | if (localid != 0) | 3323 | cAgent.LeftAxis = m_CameraLeftAxis; |
3324 | killerObj = localid; | 3324 | cAgent.UpAxis = m_CameraUpAxis; |
3325 | } | 3325 | |
3326 | //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString()); | 3326 | cAgent.Far = m_DrawDistance; |
3327 | } | 3327 | |
3328 | //Health = 100; | 3328 | // Throttles |
3329 | if (!m_invulnerable) | 3329 | float multiplier = 1; |
3330 | { | 3330 | int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); |
3331 | if (starthealth != Health) | 3331 | if (innacurateNeighbors != 0) |
3332 | { | 3332 | { |
3333 | ControllingClient.SendHealth(Health); | 3333 | multiplier = 1f / innacurateNeighbors; |
3334 | } | 3334 | } |
3335 | if (m_health <= 0) | 3335 | if (multiplier <= 0f) |
3336 | m_scene.EventManager.TriggerAvatarKill(killerObj, this); | 3336 | { |
3337 | } | 3337 | multiplier = 0.25f; |
3338 | } | 3338 | } |
3339 | 3339 | //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); | |
3340 | public void setHealthWithUpdate(float health) | 3340 | cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier); |
3341 | { | 3341 | |
3342 | Health = health; | 3342 | cAgent.HeadRotation = m_headrotation; |
3343 | ControllingClient.SendHealth(Health); | 3343 | cAgent.BodyRotation = m_bodyRot; |
3344 | } | 3344 | cAgent.ControlFlags = (uint)m_AgentControlFlags; |
3345 | 3345 | ||
3346 | public void Close() | 3346 | if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) |
3347 | { | 3347 | cAgent.GodLevel = (byte)m_godLevel; |
3348 | lock (m_attachments) | 3348 | else |
3349 | { | 3349 | cAgent.GodLevel = (byte) 0; |
3350 | // Delete attachments from scene | 3350 | |
3351 | // Don't try to save, as this thread won't live long | 3351 | cAgent.AlwaysRun = m_setAlwaysRun; |
3352 | // enough to complete the save. This would cause no copy | 3352 | |
3353 | // attachments to poof! | 3353 | try |
3354 | // | 3354 | { |
3355 | foreach (SceneObjectGroup grp in m_attachments) | 3355 | // We might not pass the Wearables in all cases... |
3356 | { | 3356 | // They're only needed so that persistent changes to the appearance |
3357 | m_scene.DeleteSceneObject(grp, false); | 3357 | // are preserved in the new region where the user is moving to. |
3358 | } | 3358 | // But in Hypergrid we might not let this happen. |
3359 | m_attachments.Clear(); | 3359 | int i = 0; |
3360 | } | 3360 | UUID[] wears = new UUID[m_appearance.Wearables.Length * 2]; |
3361 | 3361 | foreach (AvatarWearable aw in m_appearance.Wearables) | |
3362 | lock (m_knownChildRegions) | 3362 | { |
3363 | { | 3363 | if (aw != null) |
3364 | m_knownChildRegions.Clear(); | 3364 | { |
3365 | } | 3365 | wears[i++] = aw.ItemID; |
3366 | 3366 | wears[i++] = aw.AssetID; | |
3367 | lock (m_reprioritization_timer) | 3367 | } |
3368 | { | 3368 | else |
3369 | m_reprioritization_timer.Enabled = false; | 3369 | { |
3370 | m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); | 3370 | wears[i++] = UUID.Zero; |
3371 | } | 3371 | wears[i++] = UUID.Zero; |
3372 | 3372 | } | |
3373 | // I don't get it but mono crashes when you try to dispose of this timer, | 3373 | } |
3374 | // unsetting the elapsed callback should be enough to allow for cleanup however. | 3374 | cAgent.Wearables = wears; |
3375 | // m_reprioritizationTimer.Dispose(); | 3375 | |
3376 | 3376 | cAgent.VisualParams = m_appearance.VisualParams; | |
3377 | m_sceneViewer.Close(); | 3377 | |
3378 | 3378 | if (m_appearance.Texture != null) | |
3379 | RemoveFromPhysicalScene(); | 3379 | cAgent.AgentTextures = m_appearance.Texture.GetBytes(); |
3380 | m_animator.Close(); | 3380 | } |
3381 | m_animator = null; | 3381 | catch (Exception e) |
3382 | } | 3382 | { |
3383 | 3383 | m_log.Warn("[SCENE PRESENCE]: exception in CopyTo " + e.Message); | |
3384 | public void AddAttachment(SceneObjectGroup gobj) | 3384 | } |
3385 | { | 3385 | |
3386 | lock (m_attachments) | 3386 | //Attachments |
3387 | { | 3387 | List<int> attPoints = m_appearance.GetAttachedPoints(); |
3388 | m_attachments.Add(gobj); | 3388 | if (attPoints != null) |
3389 | } | 3389 | { |
3390 | } | 3390 | //m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count); |
3391 | 3391 | int i = 0; | |
3392 | public bool HasAttachments() | 3392 | AttachmentData[] attachs = new AttachmentData[attPoints.Count]; |
3393 | { | 3393 | foreach (int point in attPoints) |
3394 | return m_attachments.Count > 0; | 3394 | { |
3395 | } | 3395 | attachs[i++] = new AttachmentData(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); |
3396 | 3396 | } | |
3397 | public bool HasScriptedAttachments() | 3397 | cAgent.Attachments = attachs; |
3398 | { | 3398 | } |
3399 | lock (m_attachments) | 3399 | |
3400 | { | 3400 | lock (scriptedcontrols) |
3401 | foreach (SceneObjectGroup gobj in m_attachments) | 3401 | { |
3402 | { | 3402 | ControllerData[] controls = new ControllerData[scriptedcontrols.Count]; |
3403 | if (gobj != null) | 3403 | int i = 0; |
3404 | { | 3404 | |
3405 | if (gobj.RootPart.Inventory.ContainsScripts()) | 3405 | foreach (ScriptControllers c in scriptedcontrols.Values) |
3406 | return true; | 3406 | { |
3407 | } | 3407 | controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); |
3408 | } | 3408 | } |
3409 | } | 3409 | cAgent.Controllers = controls; |
3410 | return false; | 3410 | } |
3411 | } | 3411 | |
3412 | 3412 | // Animations | |
3413 | public void RemoveAttachment(SceneObjectGroup gobj) | 3413 | try |
3414 | { | 3414 | { |
3415 | lock (m_attachments) | 3415 | cAgent.Anims = Animator.Animations.ToArray(); |
3416 | { | 3416 | } |
3417 | if (m_attachments.Contains(gobj)) | 3417 | catch { } |
3418 | { | 3418 | |
3419 | m_attachments.Remove(gobj); | 3419 | // cAgent.GroupID = ?? |
3420 | } | 3420 | // Groups??? |
3421 | } | 3421 | |
3422 | } | 3422 | } |
3423 | 3423 | ||
3424 | public bool ValidateAttachments() | 3424 | public void CopyFrom(AgentData cAgent) |
3425 | { | 3425 | { |
3426 | lock (m_attachments) | 3426 | m_originRegionID = cAgent.RegionID; |
3427 | { | 3427 | |
3428 | // Validate | 3428 | m_callbackURI = cAgent.CallbackURI; |
3429 | foreach (SceneObjectGroup gobj in m_attachments) | 3429 | |
3430 | { | 3430 | m_pos = cAgent.Position; |
3431 | if (gobj == null) | 3431 | |
3432 | return false; | 3432 | m_velocity = cAgent.Velocity; |
3433 | 3433 | m_CameraCenter = cAgent.Center; | |
3434 | if (gobj.IsDeleted) | 3434 | //m_avHeight = cAgent.Size.Z; |
3435 | return false; | 3435 | m_CameraAtAxis = cAgent.AtAxis; |
3436 | } | 3436 | m_CameraLeftAxis = cAgent.LeftAxis; |
3437 | } | 3437 | m_CameraUpAxis = cAgent.UpAxis; |
3438 | return true; | 3438 | |
3439 | } | 3439 | m_DrawDistance = cAgent.Far; |
3440 | 3440 | ||
3441 | /// <summary> | 3441 | if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0) |
3442 | /// Send a script event to this scene presence's attachments | 3442 | ControllingClient.SetChildAgentThrottle(cAgent.Throttles); |
3443 | /// </summary> | 3443 | |
3444 | /// <param name="eventName">The name of the event</param> | 3444 | m_headrotation = cAgent.HeadRotation; |
3445 | /// <param name="args">The arguments for the event</param> | 3445 | m_bodyRot = cAgent.BodyRotation; |
3446 | public void SendScriptEventToAttachments(string eventName, Object[] args) | 3446 | m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; |
3447 | { | 3447 | |
3448 | if (m_scriptEngines != null) | 3448 | if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) |
3449 | { | 3449 | m_godLevel = cAgent.GodLevel; |
3450 | lock (m_attachments) | 3450 | m_setAlwaysRun = cAgent.AlwaysRun; |
3451 | { | 3451 | |
3452 | foreach (SceneObjectGroup grp in m_attachments) | 3452 | uint i = 0; |
3453 | { | 3453 | try |
3454 | // 16384 is CHANGED_ANIMATION | 3454 | { |
3455 | // | 3455 | if (cAgent.Wearables == null) |
3456 | // Send this to all attachment root prims | 3456 | cAgent.Wearables = new UUID[0]; |
3457 | // | 3457 | AvatarWearable[] wears = new AvatarWearable[cAgent.Wearables.Length / 2]; |
3458 | foreach (IScriptModule m in m_scriptEngines) | 3458 | for (uint n = 0; n < cAgent.Wearables.Length; n += 2) |
3459 | { | 3459 | { |
3460 | if (m == null) // No script engine loaded | 3460 | UUID itemId = cAgent.Wearables[n]; |
3461 | continue; | 3461 | UUID assetId = cAgent.Wearables[n + 1]; |
3462 | 3462 | wears[i++] = new AvatarWearable(itemId, assetId); | |
3463 | m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); | 3463 | } |
3464 | } | 3464 | m_appearance.Wearables = wears; |
3465 | } | 3465 | Primitive.TextureEntry te; |
3466 | } | 3466 | if (cAgent.AgentTextures != null && cAgent.AgentTextures.Length > 1) |
3467 | } | 3467 | te = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length); |
3468 | } | 3468 | else |
3469 | 3469 | te = AvatarAppearance.GetDefaultTexture(); | |
3470 | 3470 | if ((cAgent.VisualParams == null) || (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT)) | |
3471 | public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) | 3471 | cAgent.VisualParams = AvatarAppearance.GetDefaultVisualParams(); |
3472 | { | 3472 | m_appearance.SetAppearance(te, (byte[])cAgent.VisualParams.Clone()); |
3473 | m_controllingClient = client; | 3473 | } |
3474 | m_regionInfo = region; | 3474 | catch (Exception e) |
3475 | m_scene = scene; | 3475 | { |
3476 | 3476 | m_log.Warn("[SCENE PRESENCE]: exception in CopyFrom " + e.Message); | |
3477 | RegisterToEvents(); | 3477 | } |
3478 | 3478 | ||
3479 | /* | 3479 | // Attachments |
3480 | AbsolutePosition = client.StartPos; | 3480 | try |
3481 | 3481 | { | |
3482 | Animations = new AvatarAnimations(); | 3482 | if (cAgent.Attachments != null) |
3483 | Animations.LoadAnims(); | 3483 | { |
3484 | 3484 | m_appearance.ClearAttachments(); | |
3485 | m_animations = new List<UUID>(); | 3485 | foreach (AttachmentData att in cAgent.Attachments) |
3486 | m_animations.Add(Animations.AnimsUUID["STAND"]); | 3486 | { |
3487 | m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber); | 3487 | m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID); |
3488 | 3488 | } | |
3489 | SetDirectionVectors(); | 3489 | } |
3490 | */ | 3490 | } |
3491 | } | 3491 | catch { } |
3492 | 3492 | ||
3493 | internal void PushForce(Vector3 impulse) | 3493 | try |
3494 | { | 3494 | { |
3495 | if (PhysicsActor != null) | 3495 | lock (scriptedcontrols) |
3496 | { | 3496 | { |
3497 | PhysicsActor.AddForce(impulse,true); | 3497 | if (cAgent.Controllers != null) |
3498 | } | 3498 | { |
3499 | } | 3499 | scriptedcontrols.Clear(); |
3500 | 3500 | ||
3501 | public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) | 3501 | foreach (ControllerData c in cAgent.Controllers) |
3502 | { | 3502 | { |
3503 | ScriptControllers obj = new ScriptControllers(); | 3503 | ScriptControllers sc = new ScriptControllers(); |
3504 | obj.ignoreControls = ScriptControlled.CONTROL_ZERO; | 3504 | sc.itemID = c.ItemID; |
3505 | obj.eventControls = ScriptControlled.CONTROL_ZERO; | 3505 | sc.ignoreControls = (ScriptControlled)c.IgnoreControls; |
3506 | 3506 | sc.eventControls = (ScriptControlled)c.EventControls; | |
3507 | obj.itemID = Script_item_UUID; | 3507 | |
3508 | if (pass_on == 0 && accept == 0) | 3508 | scriptedcontrols[sc.itemID] = sc; |
3509 | { | 3509 | } |
3510 | IgnoredControls |= (ScriptControlled)controls; | 3510 | } |
3511 | obj.ignoreControls = (ScriptControlled)controls; | 3511 | } |
3512 | } | 3512 | } |
3513 | 3513 | catch { } | |
3514 | if (pass_on == 0 && accept == 1) | 3514 | // Animations |
3515 | { | 3515 | try |
3516 | IgnoredControls |= (ScriptControlled)controls; | 3516 | { |
3517 | obj.ignoreControls = (ScriptControlled)controls; | 3517 | Animator.ResetAnimations(); |
3518 | obj.eventControls = (ScriptControlled)controls; | 3518 | Animator.Animations.FromArray(cAgent.Anims); |
3519 | } | 3519 | } |
3520 | if (pass_on == 1 && accept == 1) | 3520 | catch { } |
3521 | { | 3521 | |
3522 | IgnoredControls = ScriptControlled.CONTROL_ZERO; | 3522 | //cAgent.GroupID = ?? |
3523 | obj.eventControls = (ScriptControlled)controls; | 3523 | //Groups??? |
3524 | obj.ignoreControls = ScriptControlled.CONTROL_ZERO; | 3524 | } |
3525 | } | 3525 | |
3526 | 3526 | public bool CopyAgent(out IAgentData agent) | |
3527 | lock (scriptedcontrols) | 3527 | { |
3528 | { | 3528 | agent = new CompleteAgentData(); |
3529 | if (pass_on == 1 && accept == 0) | 3529 | CopyTo((AgentData)agent); |
3530 | { | 3530 | return true; |
3531 | IgnoredControls &= ~(ScriptControlled)controls; | 3531 | } |
3532 | if (scriptedcontrols.ContainsKey(Script_item_UUID)) | 3532 | |
3533 | scriptedcontrols.Remove(Script_item_UUID); | 3533 | #endregion Child Agent Updates |
3534 | } | 3534 | |
3535 | else | 3535 | /// <summary> |
3536 | { | 3536 | /// Handles part of the PID controller function for moving an avatar. |
3537 | scriptedcontrols[Script_item_UUID] = obj; | 3537 | /// </summary> |
3538 | } | 3538 | public override void UpdateMovement() |
3539 | } | 3539 | { |
3540 | ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); | 3540 | if (m_forceToApply.HasValue) |
3541 | } | 3541 | { |
3542 | 3542 | ||
3543 | public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID) | 3543 | Vector3 force = m_forceToApply.Value; |
3544 | { | 3544 | m_updateflag = true; |
3545 | IgnoredControls = ScriptControlled.CONTROL_ZERO; | 3545 | Velocity = force; |
3546 | lock (scriptedcontrols) | 3546 | |
3547 | { | 3547 | m_forceToApply = null; |
3548 | scriptedcontrols.Clear(); | 3548 | } |
3549 | } | 3549 | else |
3550 | ControllingClient.SendTakeControls(int.MaxValue, false, false); | 3550 | { |
3551 | } | 3551 | if (m_isNudging) |
3552 | 3552 | { | |
3553 | public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) | 3553 | Vector3 force = Vector3.Zero; |
3554 | { | 3554 | |
3555 | ScriptControllers takecontrols; | 3555 | m_updateflag = true; |
3556 | 3556 | Velocity = force; | |
3557 | lock (scriptedcontrols) | 3557 | m_isNudging = false; |
3558 | { | 3558 | m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND" |
3559 | if (scriptedcontrols.TryGetValue(Script_item_UUID, out takecontrols)) | 3559 | } |
3560 | { | 3560 | } |
3561 | ScriptControlled sctc = takecontrols.eventControls; | 3561 | } |
3562 | 3562 | ||
3563 | ControllingClient.SendTakeControls((int)sctc, false, false); | 3563 | public override void SetText(string text, Vector3 color, double alpha) |
3564 | ControllingClient.SendTakeControls((int)sctc, true, false); | 3564 | { |
3565 | 3565 | throw new Exception("Can't set Text on avatar."); | |
3566 | scriptedcontrols.Remove(Script_item_UUID); | 3566 | } |
3567 | IgnoredControls = ScriptControlled.CONTROL_ZERO; | 3567 | |
3568 | foreach (ScriptControllers scData in scriptedcontrols.Values) | 3568 | /// <summary> |
3569 | { | 3569 | /// Adds a physical representation of the avatar to the Physics plugin |
3570 | IgnoredControls |= scData.ignoreControls; | 3570 | /// </summary> |
3571 | } | 3571 | public void AddToPhysicalScene(bool isFlying) |
3572 | } | 3572 | { |
3573 | } | 3573 | PhysicsScene scene = m_scene.PhysicsScene; |
3574 | } | 3574 | |
3575 | 3575 | Vector3 pVec = AbsolutePosition; | |
3576 | internal void SendControlToScripts(uint flags) | 3576 | |
3577 | { | 3577 | // Old bug where the height was in centimeters instead of meters |
3578 | ScriptControlled allflags = ScriptControlled.CONTROL_ZERO; | 3578 | if (m_avHeight == 127.0f) |
3579 | 3579 | { | |
3580 | if (MouseDown) | 3580 | m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new Vector3(0f, 0f, 1.56f), |
3581 | { | 3581 | isFlying); |
3582 | allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON); | 3582 | } |
3583 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0) | 3583 | else |
3584 | { | 3584 | { |
3585 | allflags = ScriptControlled.CONTROL_ZERO; | 3585 | m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, |
3586 | MouseDown = true; | 3586 | new Vector3(0f, 0f, m_avHeight), isFlying); |
3587 | } | 3587 | } |
3588 | } | 3588 | scene.AddPhysicsActorTaint(m_physicsActor); |
3589 | 3589 | //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; | |
3590 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0) | 3590 | m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; |
3591 | { | 3591 | m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong |
3592 | allflags |= ScriptControlled.CONTROL_ML_LBUTTON; | 3592 | m_physicsActor.SubscribeEvents(500); |
3593 | MouseDown = true; | 3593 | m_physicsActor.LocalID = LocalId; |
3594 | } | 3594 | } |
3595 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0) | 3595 | |
3596 | { | 3596 | private void OutOfBoundsCall(Vector3 pos) |
3597 | allflags |= ScriptControlled.CONTROL_LBUTTON; | 3597 | { |
3598 | MouseDown = true; | 3598 | //bool flying = m_physicsActor.Flying; |
3599 | } | 3599 | //RemoveFromPhysicalScene(); |
3600 | 3600 | ||
3601 | // find all activated controls, whether the scripts are interested in them or not | 3601 | //AddToPhysicalScene(flying); |
3602 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0) | 3602 | if (ControllingClient != null) |
3603 | { | 3603 | ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); |
3604 | allflags |= ScriptControlled.CONTROL_FWD; | 3604 | } |
3605 | } | 3605 | |
3606 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0) | 3606 | // Event called by the physics plugin to tell the avatar about a collision. |
3607 | { | 3607 | private void PhysicsCollisionUpdate(EventArgs e) |
3608 | allflags |= ScriptControlled.CONTROL_BACK; | 3608 | { |
3609 | } | 3609 | if (e == null) |
3610 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0) | 3610 | return; |
3611 | { | 3611 | |
3612 | allflags |= ScriptControlled.CONTROL_UP; | 3612 | // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents( |
3613 | } | 3613 | // as of this comment the interval is set in AddToPhysicalScene |
3614 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0) | 3614 | if (Animator!=null) |
3615 | { | 3615 | { |
3616 | allflags |= ScriptControlled.CONTROL_DOWN; | 3616 | if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper, |
3617 | } | 3617 | { // else its will lock out other animation changes, like ground sit. |
3618 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0) | 3618 | Animator.UpdateMovementAnimations(); |
3619 | { | 3619 | m_updateCount--; |
3620 | allflags |= ScriptControlled.CONTROL_LEFT; | 3620 | } |
3621 | } | 3621 | } |
3622 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0) | 3622 | |
3623 | { | 3623 | CollisionEventUpdate collisionData = (CollisionEventUpdate)e; |
3624 | allflags |= ScriptControlled.CONTROL_RIGHT; | 3624 | Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; |
3625 | } | 3625 | |
3626 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0) | 3626 | CollisionPlane = Vector4.UnitW; |
3627 | { | 3627 | |
3628 | allflags |= ScriptControlled.CONTROL_ROT_RIGHT; | 3628 | if (m_lastColCount != coldata.Count) |
3629 | } | 3629 | { |
3630 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0) | 3630 | m_updateCount = UPDATE_COUNT; |
3631 | { | 3631 | m_lastColCount = coldata.Count; |
3632 | allflags |= ScriptControlled.CONTROL_ROT_LEFT; | 3632 | } |
3633 | } | 3633 | |
3634 | // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that | 3634 | if (coldata.Count != 0 && Animator != null) |
3635 | if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands) | 3635 | { |
3636 | { | 3636 | switch (Animator.CurrentMovementAnimation) |
3637 | lock (scriptedcontrols) | 3637 | { |
3638 | { | 3638 | case "STAND": |
3639 | foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols) | 3639 | case "WALK": |
3640 | { | 3640 | case "RUN": |
3641 | UUID scriptUUID = kvp.Key; | 3641 | case "CROUCH": |
3642 | ScriptControllers scriptControlData = kvp.Value; | 3642 | case "CROUCHWALK": |
3643 | 3643 | { | |
3644 | ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us | 3644 | ContactPoint lowest; |
3645 | ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle | 3645 | lowest.SurfaceNormal = Vector3.Zero; |
3646 | ScriptControlled localChange = localHeld ^ localLast; // the changed bits | 3646 | lowest.Position = Vector3.Zero; |
3647 | if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO) | 3647 | lowest.Position.Z = Single.NaN; |
3648 | { | 3648 | |
3649 | // only send if still pressed or just changed | 3649 | foreach (ContactPoint contact in coldata.Values) |
3650 | m_scene.EventManager.TriggerControlEvent(scriptUUID, UUID, (uint)localHeld, (uint)localChange); | 3650 | { |
3651 | } | 3651 | if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) |
3652 | } | 3652 | { |
3653 | } | 3653 | lowest = contact; |
3654 | } | 3654 | } |
3655 | 3655 | } | |
3656 | LastCommands = allflags; | 3656 | |
3657 | } | 3657 | CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); |
3658 | 3658 | } | |
3659 | internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored) | 3659 | break; |
3660 | { | 3660 | } |
3661 | if (ignored == ScriptControlled.CONTROL_ZERO) | 3661 | } |
3662 | return flags; | 3662 | |
3663 | 3663 | List<uint> thisHitColliders = new List<uint>(); | |
3664 | if ((ignored & ScriptControlled.CONTROL_BACK) != 0) | 3664 | List<uint> endedColliders = new List<uint>(); |
3665 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); | 3665 | List<uint> startedColliders = new List<uint>(); |
3666 | if ((ignored & ScriptControlled.CONTROL_FWD) != 0) | 3666 | |
3667 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_AT_POS); | 3667 | foreach (uint localid in coldata.Keys) |
3668 | if ((ignored & ScriptControlled.CONTROL_DOWN) != 0) | 3668 | { |
3669 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG); | 3669 | thisHitColliders.Add(localid); |
3670 | if ((ignored & ScriptControlled.CONTROL_UP) != 0) | 3670 | if (!m_lastColliders.Contains(localid)) |
3671 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_UP_POS); | 3671 | { |
3672 | if ((ignored & ScriptControlled.CONTROL_LEFT) != 0) | 3672 | startedColliders.Add(localid); |
3673 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); | 3673 | } |
3674 | if ((ignored & ScriptControlled.CONTROL_RIGHT) != 0) | 3674 | //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); |
3675 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG); | 3675 | } |
3676 | if ((ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0) | 3676 | |
3677 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG); | 3677 | // calculate things that ended colliding |
3678 | if ((ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0) | 3678 | foreach (uint localID in m_lastColliders) |
3679 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS); | 3679 | { |
3680 | if ((ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0) | 3680 | if (!thisHitColliders.Contains(localID)) |
3681 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN); | 3681 | { |
3682 | if ((ignored & ScriptControlled.CONTROL_LBUTTON) != 0) | 3682 | endedColliders.Add(localID); |
3683 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN); | 3683 | } |
3684 | 3684 | } | |
3685 | //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, | 3685 | //add the items that started colliding this time to the last colliders list. |
3686 | //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, | 3686 | foreach (uint localID in startedColliders) |
3687 | //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, | 3687 | { |
3688 | //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, | 3688 | m_lastColliders.Add(localID); |
3689 | //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, | 3689 | } |
3690 | //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, | 3690 | // remove things that ended colliding from the last colliders list |
3691 | //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG | 3691 | foreach (uint localID in endedColliders) |
3692 | 3692 | { | |
3693 | return flags; | 3693 | m_lastColliders.Remove(localID); |
3694 | } | 3694 | } |
3695 | 3695 | ||
3696 | /// <summary> | 3696 | // do event notification |
3697 | /// RezAttachments. This should only be called upon login on the first region. | 3697 | if (startedColliders.Count > 0) |
3698 | /// Attachment rezzings on crossings and TPs are done in a different way. | 3698 | { |
3699 | /// </summary> | 3699 | ColliderArgs StartCollidingMessage = new ColliderArgs(); |
3700 | public void RezAttachments() | 3700 | List<DetectedObject> colliding = new List<DetectedObject>(); |
3701 | { | 3701 | foreach (uint localId in startedColliders) |
3702 | if (null == m_appearance) | 3702 | { |
3703 | { | 3703 | if (localId == 0) |
3704 | m_log.WarnFormat("[ATTACHMENT]: Appearance has not been initialized for agent {0}", UUID); | 3704 | continue; |
3705 | return; | 3705 | |
3706 | } | 3706 | SceneObjectPart obj = Scene.GetSceneObjectPart(localId); |
3707 | 3707 | string data = ""; | |
3708 | List<int> attPoints = m_appearance.GetAttachedPoints(); | 3708 | if (obj != null) |
3709 | foreach (int p in attPoints) | 3709 | { |
3710 | { | 3710 | DetectedObject detobj = new DetectedObject(); |
3711 | if (m_isDeleted) | 3711 | detobj.keyUUID = obj.UUID; |
3712 | return; | 3712 | detobj.nameStr = obj.Name; |
3713 | 3713 | detobj.ownerUUID = obj.OwnerID; | |
3714 | UUID itemID = m_appearance.GetAttachedItem(p); | 3714 | detobj.posVector = obj.AbsolutePosition; |
3715 | UUID assetID = m_appearance.GetAttachedAsset(p); | 3715 | detobj.rotQuat = obj.GetWorldRotation(); |
3716 | 3716 | detobj.velVector = obj.Velocity; | |
3717 | // For some reason assetIDs are being written as Zero's in the DB -- need to track tat down | 3717 | detobj.colliderType = 0; |
3718 | // But they're not used anyway, the item is being looked up for now, so let's proceed. | 3718 | detobj.groupUUID = obj.GroupID; |
3719 | //if (UUID.Zero == assetID) | 3719 | colliding.Add(detobj); |
3720 | //{ | 3720 | } |
3721 | // m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); | 3721 | } |
3722 | // continue; | 3722 | |
3723 | //} | 3723 | if (colliding.Count > 0) |
3724 | 3724 | { | |
3725 | try | 3725 | StartCollidingMessage.Colliders = colliding; |
3726 | { | 3726 | |
3727 | // Rez from inventory | 3727 | foreach (SceneObjectGroup att in Attachments) |
3728 | UUID asset | 3728 | Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); |
3729 | = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p); | 3729 | } |
3730 | 3730 | } | |
3731 | m_log.InfoFormat( | 3731 | |
3732 | "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", | 3732 | if (endedColliders.Count > 0) |
3733 | p, itemID, assetID, asset); | 3733 | { |
3734 | } | 3734 | ColliderArgs EndCollidingMessage = new ColliderArgs(); |
3735 | catch (Exception e) | 3735 | List<DetectedObject> colliding = new List<DetectedObject>(); |
3736 | { | 3736 | foreach (uint localId in endedColliders) |
3737 | m_log.ErrorFormat("[ATTACHMENT]: Unable to rez attachment: {0}", e.ToString()); | 3737 | { |
3738 | } | 3738 | if (localId == 0) |
3739 | } | 3739 | continue; |
3740 | } | 3740 | |
3741 | 3741 | SceneObjectPart obj = Scene.GetSceneObjectPart(localId); | |
3742 | private void ReprioritizeUpdates() | 3742 | string data = ""; |
3743 | { | 3743 | if (obj != null) |
3744 | if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != UpdatePrioritizationSchemes.Time) | 3744 | { |
3745 | { | 3745 | DetectedObject detobj = new DetectedObject(); |
3746 | lock (m_reprioritization_timer) | 3746 | detobj.keyUUID = obj.UUID; |
3747 | { | 3747 | detobj.nameStr = obj.Name; |
3748 | if (!m_reprioritizing) | 3748 | detobj.ownerUUID = obj.OwnerID; |
3749 | m_reprioritization_timer.Enabled = m_reprioritizing = true; | 3749 | detobj.posVector = obj.AbsolutePosition; |
3750 | else | 3750 | detobj.rotQuat = obj.GetWorldRotation(); |
3751 | m_reprioritization_called = true; | 3751 | detobj.velVector = obj.Velocity; |
3752 | } | 3752 | detobj.colliderType = 0; |
3753 | } | 3753 | detobj.groupUUID = obj.GroupID; |
3754 | } | 3754 | colliding.Add(detobj); |
3755 | 3755 | } | |
3756 | private void Reprioritize(object sender, ElapsedEventArgs e) | 3756 | } |
3757 | { | 3757 | |
3758 | m_controllingClient.ReprioritizeUpdates(); | 3758 | if (colliding.Count > 0) |
3759 | 3759 | { | |
3760 | lock (m_reprioritization_timer) | 3760 | EndCollidingMessage.Colliders = colliding; |
3761 | { | 3761 | |
3762 | m_reprioritization_timer.Enabled = m_reprioritizing = m_reprioritization_called; | 3762 | foreach (SceneObjectGroup att in Attachments) |
3763 | m_reprioritization_called = false; | 3763 | Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage); |
3764 | } | 3764 | } |
3765 | } | 3765 | } |
3766 | } | 3766 | |
3767 | } | 3767 | if (thisHitColliders.Count > 0) |
3768 | { | ||
3769 | ColliderArgs CollidingMessage = new ColliderArgs(); | ||
3770 | List<DetectedObject> colliding = new List<DetectedObject>(); | ||
3771 | foreach (uint localId in thisHitColliders) | ||
3772 | { | ||
3773 | if (localId == 0) | ||
3774 | continue; | ||
3775 | |||
3776 | SceneObjectPart obj = Scene.GetSceneObjectPart(localId); | ||
3777 | string data = ""; | ||
3778 | if (obj != null) | ||
3779 | { | ||
3780 | DetectedObject detobj = new DetectedObject(); | ||
3781 | detobj.keyUUID = obj.UUID; | ||
3782 | detobj.nameStr = obj.Name; | ||
3783 | detobj.ownerUUID = obj.OwnerID; | ||
3784 | detobj.posVector = obj.AbsolutePosition; | ||
3785 | detobj.rotQuat = obj.GetWorldRotation(); | ||
3786 | detobj.velVector = obj.Velocity; | ||
3787 | detobj.colliderType = 0; | ||
3788 | detobj.groupUUID = obj.GroupID; | ||
3789 | colliding.Add(detobj); | ||
3790 | } | ||
3791 | } | ||
3792 | |||
3793 | if (colliding.Count > 0) | ||
3794 | { | ||
3795 | CollidingMessage.Colliders = colliding; | ||
3796 | |||
3797 | lock (m_attachments) | ||
3798 | { | ||
3799 | foreach (SceneObjectGroup att in m_attachments) | ||
3800 | Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage); | ||
3801 | } | ||
3802 | } | ||
3803 | } | ||
3804 | |||
3805 | if (m_invulnerable) | ||
3806 | return; | ||
3807 | |||
3808 | float starthealth = Health; | ||
3809 | uint killerObj = 0; | ||
3810 | foreach (uint localid in coldata.Keys) | ||
3811 | { | ||
3812 | SceneObjectPart part = Scene.GetSceneObjectPart(localid); | ||
3813 | |||
3814 | if (part != null && part.ParentGroup.Damage != -1.0f) | ||
3815 | Health -= part.ParentGroup.Damage; | ||
3816 | else | ||
3817 | { | ||
3818 | if (coldata[localid].PenetrationDepth >= 0.10f) | ||
3819 | Health -= coldata[localid].PenetrationDepth * 5.0f; | ||
3820 | } | ||
3821 | |||
3822 | if (Health <= 0.0f) | ||
3823 | { | ||
3824 | if (localid != 0) | ||
3825 | killerObj = localid; | ||
3826 | } | ||
3827 | //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString()); | ||
3828 | } | ||
3829 | //Health = 100; | ||
3830 | if (!m_invulnerable) | ||
3831 | { | ||
3832 | if (starthealth != Health) | ||
3833 | { | ||
3834 | ControllingClient.SendHealth(Health); | ||
3835 | } | ||
3836 | if (m_health <= 0) | ||
3837 | m_scene.EventManager.TriggerAvatarKill(killerObj, this); | ||
3838 | } | ||
3839 | } | ||
3840 | |||
3841 | public void setHealthWithUpdate(float health) | ||
3842 | { | ||
3843 | Health = health; | ||
3844 | ControllingClient.SendHealth(Health); | ||
3845 | } | ||
3846 | |||
3847 | public void Close() | ||
3848 | { | ||
3849 | lock (m_attachments) | ||
3850 | { | ||
3851 | // Delete attachments from scene | ||
3852 | // Don't try to save, as this thread won't live long | ||
3853 | // enough to complete the save. This would cause no copy | ||
3854 | // attachments to poof! | ||
3855 | // | ||
3856 | foreach (SceneObjectGroup grp in m_attachments) | ||
3857 | { | ||
3858 | m_scene.DeleteSceneObject(grp, false); | ||
3859 | } | ||
3860 | m_attachments.Clear(); | ||
3861 | } | ||
3862 | |||
3863 | lock (m_knownChildRegions) | ||
3864 | { | ||
3865 | m_knownChildRegions.Clear(); | ||
3866 | } | ||
3867 | |||
3868 | lock (m_reprioritization_timer) | ||
3869 | { | ||
3870 | m_reprioritization_timer.Enabled = false; | ||
3871 | m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); | ||
3872 | } | ||
3873 | |||
3874 | // I don't get it but mono crashes when you try to dispose of this timer, | ||
3875 | // unsetting the elapsed callback should be enough to allow for cleanup however. | ||
3876 | // m_reprioritizationTimer.Dispose(); | ||
3877 | |||
3878 | m_sceneViewer.Close(); | ||
3879 | |||
3880 | RemoveFromPhysicalScene(); | ||
3881 | m_animator.Close(); | ||
3882 | m_animator = null; | ||
3883 | } | ||
3884 | |||
3885 | public void AddAttachment(SceneObjectGroup gobj) | ||
3886 | { | ||
3887 | lock (m_attachments) | ||
3888 | { | ||
3889 | m_attachments.Add(gobj); | ||
3890 | } | ||
3891 | } | ||
3892 | |||
3893 | public bool HasAttachments() | ||
3894 | { | ||
3895 | return m_attachments.Count > 0; | ||
3896 | } | ||
3897 | |||
3898 | public bool HasScriptedAttachments() | ||
3899 | { | ||
3900 | lock (m_attachments) | ||
3901 | { | ||
3902 | foreach (SceneObjectGroup gobj in m_attachments) | ||
3903 | { | ||
3904 | if (gobj != null) | ||
3905 | { | ||
3906 | if (gobj.RootPart.Inventory.ContainsScripts()) | ||
3907 | return true; | ||
3908 | } | ||
3909 | } | ||
3910 | } | ||
3911 | return false; | ||
3912 | } | ||
3913 | |||
3914 | public void RemoveAttachment(SceneObjectGroup gobj) | ||
3915 | { | ||
3916 | lock (m_attachments) | ||
3917 | { | ||
3918 | if (m_attachments.Contains(gobj)) | ||
3919 | { | ||
3920 | m_attachments.Remove(gobj); | ||
3921 | } | ||
3922 | } | ||
3923 | } | ||
3924 | |||
3925 | public bool ValidateAttachments() | ||
3926 | { | ||
3927 | lock (m_attachments) | ||
3928 | { | ||
3929 | // Validate | ||
3930 | foreach (SceneObjectGroup gobj in m_attachments) | ||
3931 | { | ||
3932 | if (gobj == null) | ||
3933 | return false; | ||
3934 | |||
3935 | if (gobj.IsDeleted) | ||
3936 | return false; | ||
3937 | } | ||
3938 | } | ||
3939 | return true; | ||
3940 | } | ||
3941 | |||
3942 | /// <summary> | ||
3943 | /// Send a script event to this scene presence's attachments | ||
3944 | /// </summary> | ||
3945 | /// <param name="eventName">The name of the event</param> | ||
3946 | /// <param name="args">The arguments for the event</param> | ||
3947 | public void SendScriptEventToAttachments(string eventName, Object[] args) | ||
3948 | { | ||
3949 | if (m_scriptEngines != null) | ||
3950 | { | ||
3951 | lock (m_attachments) | ||
3952 | { | ||
3953 | foreach (SceneObjectGroup grp in m_attachments) | ||
3954 | { | ||
3955 | // 16384 is CHANGED_ANIMATION | ||
3956 | // | ||
3957 | // Send this to all attachment root prims | ||
3958 | // | ||
3959 | foreach (IScriptModule m in m_scriptEngines) | ||
3960 | { | ||
3961 | if (m == null) // No script engine loaded | ||
3962 | continue; | ||
3963 | |||
3964 | m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); | ||
3965 | } | ||
3966 | } | ||
3967 | } | ||
3968 | } | ||
3969 | } | ||
3970 | |||
3971 | |||
3972 | public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) | ||
3973 | { | ||
3974 | m_controllingClient = client; | ||
3975 | m_regionInfo = region; | ||
3976 | m_scene = scene; | ||
3977 | |||
3978 | RegisterToEvents(); | ||
3979 | if (m_controllingClient != null) | ||
3980 | { | ||
3981 | m_controllingClient.ProcessPendingPackets(); | ||
3982 | } | ||
3983 | /* | ||
3984 | AbsolutePosition = client.StartPos; | ||
3985 | |||
3986 | Animations = new AvatarAnimations(); | ||
3987 | Animations.LoadAnims(); | ||
3988 | |||
3989 | m_animations = new List<UUID>(); | ||
3990 | m_animations.Add(Animations.AnimsUUID["STAND"]); | ||
3991 | m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber); | ||
3992 | |||
3993 | SetDirectionVectors(); | ||
3994 | */ | ||
3995 | } | ||
3996 | |||
3997 | internal void PushForce(Vector3 impulse) | ||
3998 | { | ||
3999 | if (PhysicsActor != null) | ||
4000 | { | ||
4001 | PhysicsActor.AddForce(impulse,true); | ||
4002 | } | ||
4003 | } | ||
4004 | |||
4005 | public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) | ||
4006 | { | ||
4007 | ScriptControllers obj = new ScriptControllers(); | ||
4008 | obj.ignoreControls = ScriptControlled.CONTROL_ZERO; | ||
4009 | obj.eventControls = ScriptControlled.CONTROL_ZERO; | ||
4010 | |||
4011 | obj.itemID = Script_item_UUID; | ||
4012 | if (pass_on == 0 && accept == 0) | ||
4013 | { | ||
4014 | IgnoredControls |= (ScriptControlled)controls; | ||
4015 | obj.ignoreControls = (ScriptControlled)controls; | ||
4016 | } | ||
4017 | |||
4018 | if (pass_on == 0 && accept == 1) | ||
4019 | { | ||
4020 | IgnoredControls |= (ScriptControlled)controls; | ||
4021 | obj.ignoreControls = (ScriptControlled)controls; | ||
4022 | obj.eventControls = (ScriptControlled)controls; | ||
4023 | } | ||
4024 | if (pass_on == 1 && accept == 1) | ||
4025 | { | ||
4026 | IgnoredControls = ScriptControlled.CONTROL_ZERO; | ||
4027 | obj.eventControls = (ScriptControlled)controls; | ||
4028 | obj.ignoreControls = ScriptControlled.CONTROL_ZERO; | ||
4029 | } | ||
4030 | |||
4031 | lock (scriptedcontrols) | ||
4032 | { | ||
4033 | if (pass_on == 1 && accept == 0) | ||
4034 | { | ||
4035 | IgnoredControls &= ~(ScriptControlled)controls; | ||
4036 | if (scriptedcontrols.ContainsKey(Script_item_UUID)) | ||
4037 | scriptedcontrols.Remove(Script_item_UUID); | ||
4038 | } | ||
4039 | else | ||
4040 | { | ||
4041 | scriptedcontrols[Script_item_UUID] = obj; | ||
4042 | } | ||
4043 | } | ||
4044 | ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); | ||
4045 | } | ||
4046 | |||
4047 | public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID) | ||
4048 | { | ||
4049 | IgnoredControls = ScriptControlled.CONTROL_ZERO; | ||
4050 | lock (scriptedcontrols) | ||
4051 | { | ||
4052 | scriptedcontrols.Clear(); | ||
4053 | } | ||
4054 | ControllingClient.SendTakeControls(int.MaxValue, false, false); | ||
4055 | } | ||
4056 | |||
4057 | public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) | ||
4058 | { | ||
4059 | ScriptControllers takecontrols; | ||
4060 | |||
4061 | lock (scriptedcontrols) | ||
4062 | { | ||
4063 | if (scriptedcontrols.TryGetValue(Script_item_UUID, out takecontrols)) | ||
4064 | { | ||
4065 | ScriptControlled sctc = takecontrols.eventControls; | ||
4066 | |||
4067 | ControllingClient.SendTakeControls((int)sctc, false, false); | ||
4068 | ControllingClient.SendTakeControls((int)sctc, true, false); | ||
4069 | |||
4070 | scriptedcontrols.Remove(Script_item_UUID); | ||
4071 | IgnoredControls = ScriptControlled.CONTROL_ZERO; | ||
4072 | foreach (ScriptControllers scData in scriptedcontrols.Values) | ||
4073 | { | ||
4074 | IgnoredControls |= scData.ignoreControls; | ||
4075 | } | ||
4076 | } | ||
4077 | } | ||
4078 | } | ||
4079 | |||
4080 | internal void SendControlToScripts(uint flags) | ||
4081 | { | ||
4082 | ScriptControlled allflags = ScriptControlled.CONTROL_ZERO; | ||
4083 | |||
4084 | if (MouseDown) | ||
4085 | { | ||
4086 | allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON); | ||
4087 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0) | ||
4088 | { | ||
4089 | allflags = ScriptControlled.CONTROL_ZERO; | ||
4090 | MouseDown = true; | ||
4091 | } | ||
4092 | } | ||
4093 | |||
4094 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0) | ||
4095 | { | ||
4096 | allflags |= ScriptControlled.CONTROL_ML_LBUTTON; | ||
4097 | MouseDown = true; | ||
4098 | } | ||
4099 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0) | ||
4100 | { | ||
4101 | allflags |= ScriptControlled.CONTROL_LBUTTON; | ||
4102 | MouseDown = true; | ||
4103 | } | ||
4104 | |||
4105 | // find all activated controls, whether the scripts are interested in them or not | ||
4106 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0) | ||
4107 | { | ||
4108 | allflags |= ScriptControlled.CONTROL_FWD; | ||
4109 | } | ||
4110 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0) | ||
4111 | { | ||
4112 | allflags |= ScriptControlled.CONTROL_BACK; | ||
4113 | } | ||
4114 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0) | ||
4115 | { | ||
4116 | allflags |= ScriptControlled.CONTROL_UP; | ||
4117 | } | ||
4118 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0) | ||
4119 | { | ||
4120 | allflags |= ScriptControlled.CONTROL_DOWN; | ||
4121 | } | ||
4122 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0) | ||
4123 | { | ||
4124 | allflags |= ScriptControlled.CONTROL_LEFT; | ||
4125 | } | ||
4126 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0) | ||
4127 | { | ||
4128 | allflags |= ScriptControlled.CONTROL_RIGHT; | ||
4129 | } | ||
4130 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0) | ||
4131 | { | ||
4132 | allflags |= ScriptControlled.CONTROL_ROT_RIGHT; | ||
4133 | } | ||
4134 | if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0) | ||
4135 | { | ||
4136 | allflags |= ScriptControlled.CONTROL_ROT_LEFT; | ||
4137 | } | ||
4138 | // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that | ||
4139 | if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands) | ||
4140 | { | ||
4141 | lock (scriptedcontrols) | ||
4142 | { | ||
4143 | foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols) | ||
4144 | { | ||
4145 | UUID scriptUUID = kvp.Key; | ||
4146 | ScriptControllers scriptControlData = kvp.Value; | ||
4147 | |||
4148 | ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us | ||
4149 | ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle | ||
4150 | ScriptControlled localChange = localHeld ^ localLast; // the changed bits | ||
4151 | if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO) | ||
4152 | { | ||
4153 | // only send if still pressed or just changed | ||
4154 | m_scene.EventManager.TriggerControlEvent(scriptUUID, UUID, (uint)localHeld, (uint)localChange); | ||
4155 | } | ||
4156 | } | ||
4157 | } | ||
4158 | } | ||
4159 | |||
4160 | LastCommands = allflags; | ||
4161 | } | ||
4162 | |||
4163 | internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored) | ||
4164 | { | ||
4165 | if (ignored == ScriptControlled.CONTROL_ZERO) | ||
4166 | return flags; | ||
4167 | |||
4168 | if ((ignored & ScriptControlled.CONTROL_BACK) != 0) | ||
4169 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); | ||
4170 | if ((ignored & ScriptControlled.CONTROL_FWD) != 0) | ||
4171 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_AT_POS); | ||
4172 | if ((ignored & ScriptControlled.CONTROL_DOWN) != 0) | ||
4173 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG); | ||
4174 | if ((ignored & ScriptControlled.CONTROL_UP) != 0) | ||
4175 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_UP_POS); | ||
4176 | if ((ignored & ScriptControlled.CONTROL_LEFT) != 0) | ||
4177 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); | ||
4178 | if ((ignored & ScriptControlled.CONTROL_RIGHT) != 0) | ||
4179 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG); | ||
4180 | if ((ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0) | ||
4181 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG); | ||
4182 | if ((ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0) | ||
4183 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS); | ||
4184 | if ((ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0) | ||
4185 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN); | ||
4186 | if ((ignored & ScriptControlled.CONTROL_LBUTTON) != 0) | ||
4187 | flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN); | ||
4188 | |||
4189 | //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, | ||
4190 | //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, | ||
4191 | //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, | ||
4192 | //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, | ||
4193 | //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, | ||
4194 | //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, | ||
4195 | //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG | ||
4196 | |||
4197 | return flags; | ||
4198 | } | ||
4199 | |||
4200 | /// <summary> | ||
4201 | /// RezAttachments. This should only be called upon login on the first region. | ||
4202 | /// Attachment rezzings on crossings and TPs are done in a different way. | ||
4203 | /// </summary> | ||
4204 | public void RezAttachments() | ||
4205 | { | ||
4206 | if (null == m_appearance) | ||
4207 | { | ||
4208 | m_log.WarnFormat("[ATTACHMENT]: Appearance has not been initialized for agent {0}", UUID); | ||
4209 | return; | ||
4210 | } | ||
4211 | |||
4212 | XmlDocument doc = new XmlDocument(); | ||
4213 | string stateData = String.Empty; | ||
4214 | |||
4215 | IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>(); | ||
4216 | if (attServ != null) | ||
4217 | { | ||
4218 | m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service"); | ||
4219 | stateData = attServ.Get(ControllingClient.AgentId.ToString()); | ||
4220 | if (stateData != String.Empty) | ||
4221 | { | ||
4222 | try | ||
4223 | { | ||
4224 | doc.LoadXml(stateData); | ||
4225 | } | ||
4226 | catch { } | ||
4227 | } | ||
4228 | } | ||
4229 | |||
4230 | Dictionary<UUID, string> itemData = new Dictionary<UUID, string>(); | ||
4231 | |||
4232 | XmlNodeList nodes = doc.GetElementsByTagName("Attachment"); | ||
4233 | if (nodes.Count > 0) | ||
4234 | { | ||
4235 | foreach (XmlNode n in nodes) | ||
4236 | { | ||
4237 | XmlElement elem = (XmlElement)n; | ||
4238 | string itemID = elem.GetAttribute("ItemID"); | ||
4239 | string xml = elem.InnerXml; | ||
4240 | |||
4241 | itemData[new UUID(itemID)] = xml; | ||
4242 | } | ||
4243 | } | ||
4244 | |||
4245 | List<int> attPoints = m_appearance.GetAttachedPoints(); | ||
4246 | foreach (int p in attPoints) | ||
4247 | { | ||
4248 | if (m_isDeleted) | ||
4249 | return; | ||
4250 | |||
4251 | UUID itemID = m_appearance.GetAttachedItem(p); | ||
4252 | UUID assetID = m_appearance.GetAttachedAsset(p); | ||
4253 | |||
4254 | // For some reason assetIDs are being written as Zero's in the DB -- need to track tat down | ||
4255 | // But they're not used anyway, the item is being looked up for now, so let's proceed. | ||
4256 | //if (UUID.Zero == assetID) | ||
4257 | //{ | ||
4258 | // m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); | ||
4259 | // continue; | ||
4260 | //} | ||
4261 | |||
4262 | try | ||
4263 | { | ||
4264 | string xmlData; | ||
4265 | XmlDocument d = new XmlDocument(); | ||
4266 | UUID asset; | ||
4267 | if (itemData.TryGetValue(itemID, out xmlData)) | ||
4268 | { | ||
4269 | d.LoadXml(xmlData); | ||
4270 | m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID); | ||
4271 | |||
4272 | // Rez from inventory | ||
4273 | asset | ||
4274 | = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d); | ||
4275 | |||
4276 | } | ||
4277 | else | ||
4278 | { | ||
4279 | // Rez from inventory (with a null doc to let | ||
4280 | // CHANGED_OWNER happen) | ||
4281 | asset | ||
4282 | = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null); | ||
4283 | } | ||
4284 | |||
4285 | m_log.InfoFormat( | ||
4286 | "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", | ||
4287 | p, itemID, assetID, asset); | ||
4288 | } | ||
4289 | catch (Exception e) | ||
4290 | { | ||
4291 | m_log.ErrorFormat("[ATTACHMENT]: Unable to rez attachment: {0}", e.ToString()); | ||
4292 | } | ||
4293 | } | ||
4294 | } | ||
4295 | |||
4296 | private void ReprioritizeUpdates() | ||
4297 | { | ||
4298 | if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != UpdatePrioritizationSchemes.Time) | ||
4299 | { | ||
4300 | lock (m_reprioritization_timer) | ||
4301 | { | ||
4302 | if (!m_reprioritizing) | ||
4303 | m_reprioritization_timer.Enabled = m_reprioritizing = true; | ||
4304 | else | ||
4305 | m_reprioritization_called = true; | ||
4306 | } | ||
4307 | } | ||
4308 | } | ||
4309 | |||
4310 | private void Reprioritize(object sender, ElapsedEventArgs e) | ||
4311 | { | ||
4312 | m_controllingClient.ReprioritizeUpdates(); | ||
4313 | |||
4314 | lock (m_reprioritization_timer) | ||
4315 | { | ||
4316 | m_reprioritization_timer.Enabled = m_reprioritizing = m_reprioritization_called; | ||
4317 | m_reprioritization_called = false; | ||
4318 | } | ||
4319 | } | ||
4320 | |||
4321 | private Vector3 Quat2Euler(Quaternion rot){ | ||
4322 | float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) , | ||
4323 | (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z))); | ||
4324 | float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W))); | ||
4325 | float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) , | ||
4326 | (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z))); | ||
4327 | return(new Vector3(x,y,z)); | ||
4328 | } | ||
4329 | |||
4330 | |||
4331 | } | ||
4332 | } | ||
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 5bdaa17..77e477f 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | |||
@@ -105,7 +105,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
105 | sceneObject.AddPart(part); | 105 | sceneObject.AddPart(part); |
106 | part.LinkNum = linkNum; | 106 | part.LinkNum = linkNum; |
107 | part.TrimPermissions(); | 107 | part.TrimPermissions(); |
108 | part.StoreUndoState(); | 108 | part.StoreUndoState(UndoType.STATE_ALL); |
109 | reader.Close(); | 109 | reader.Close(); |
110 | sr.Close(); | 110 | sr.Close(); |
111 | } | 111 | } |
@@ -231,7 +231,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
231 | if (originalLinkNum != 0) | 231 | if (originalLinkNum != 0) |
232 | part.LinkNum = originalLinkNum; | 232 | part.LinkNum = originalLinkNum; |
233 | 233 | ||
234 | part.StoreUndoState(); | 234 | part.StoreUndoState(UndoType.STATE_ALL); |
235 | reader.Close(); | 235 | reader.Close(); |
236 | sr.Close(); | 236 | sr.Close(); |
237 | } | 237 | } |
diff --git a/OpenSim/Region/Framework/Scenes/UndoState.cs b/OpenSim/Region/Framework/Scenes/UndoState.cs index 55e407e..f71b507 100644 --- a/OpenSim/Region/Framework/Scenes/UndoState.cs +++ b/OpenSim/Region/Framework/Scenes/UndoState.cs | |||
@@ -27,48 +27,125 @@ | |||
27 | 27 | ||
28 | using OpenMetaverse; | 28 | using OpenMetaverse; |
29 | using OpenSim.Region.Framework.Interfaces; | 29 | using OpenSim.Region.Framework.Interfaces; |
30 | using System; | ||
30 | 31 | ||
31 | namespace OpenSim.Region.Framework.Scenes | 32 | namespace OpenSim.Region.Framework.Scenes |
32 | { | 33 | { |
34 | [Flags] | ||
35 | public enum UndoType | ||
36 | { | ||
37 | STATE_PRIM_POSITION = 1, | ||
38 | STATE_PRIM_ROTATION = 2, | ||
39 | STATE_PRIM_SCALE = 4, | ||
40 | STATE_PRIM_ALL = 7, | ||
41 | STATE_GROUP_POSITION = 8, | ||
42 | STATE_GROUP_ROTATION = 16, | ||
43 | STATE_GROUP_SCALE = 32, | ||
44 | STATE_GROUP_ALL = 56, | ||
45 | STATE_ALL = 63 | ||
46 | } | ||
47 | |||
33 | public class UndoState | 48 | public class UndoState |
34 | { | 49 | { |
35 | public Vector3 Position = Vector3.Zero; | 50 | public Vector3 Position = Vector3.Zero; |
36 | public Vector3 Scale = Vector3.Zero; | 51 | public Vector3 Scale = Vector3.Zero; |
37 | public Quaternion Rotation = Quaternion.Identity; | 52 | public Quaternion Rotation = Quaternion.Identity; |
53 | public Vector3 GroupPosition = Vector3.Zero; | ||
54 | public Quaternion GroupRotation = Quaternion.Identity; | ||
55 | public Vector3 GroupScale = Vector3.Zero; | ||
56 | public DateTime LastUpdated = DateTime.Now; | ||
57 | public UndoType Type; | ||
38 | 58 | ||
39 | public UndoState(SceneObjectPart part) | 59 | public UndoState(SceneObjectPart part, UndoType type) |
40 | { | 60 | { |
61 | Type = type; | ||
41 | if (part != null) | 62 | if (part != null) |
42 | { | 63 | { |
43 | if (part.ParentID == 0) | 64 | if (part.ParentID == 0) |
44 | { | 65 | { |
45 | Position = part.ParentGroup.AbsolutePosition; | 66 | GroupScale = part.ParentGroup.RootPart.Shape.Scale; |
67 | |||
68 | //FUBAR WARNING: Do NOT get the group's absoluteposition here | ||
69 | //or you'll experience a loop and/or a stack issue | ||
70 | GroupPosition = part.ParentGroup.RootPart.AbsolutePosition; | ||
71 | GroupRotation = part.ParentGroup.GroupRotation; | ||
72 | Position = part.ParentGroup.RootPart.AbsolutePosition; | ||
46 | Rotation = part.RotationOffset; | 73 | Rotation = part.RotationOffset; |
47 | Scale = part.Shape.Scale; | 74 | Scale = part.Shape.Scale; |
75 | LastUpdated = DateTime.Now; | ||
48 | } | 76 | } |
49 | else | 77 | else |
50 | { | 78 | { |
79 | GroupScale = part.Shape.Scale; | ||
80 | |||
81 | //FUBAR WARNING: Do NOT get the group's absoluteposition here | ||
82 | //or you'll experience a loop and/or a stack issue | ||
83 | GroupPosition = part.ParentGroup.RootPart.AbsolutePosition; | ||
84 | GroupRotation = part.ParentGroup.Rotation; | ||
51 | Position = part.OffsetPosition; | 85 | Position = part.OffsetPosition; |
52 | Rotation = part.RotationOffset; | 86 | Rotation = part.RotationOffset; |
53 | Scale = part.Shape.Scale; | 87 | Scale = part.Shape.Scale; |
88 | LastUpdated = DateTime.Now; | ||
54 | } | 89 | } |
55 | } | 90 | } |
56 | } | 91 | } |
57 | 92 | public void Merge(UndoState last) | |
93 | { | ||
94 | if ((Type & UndoType.STATE_GROUP_POSITION) == 0 || ((last.Type & UndoType.STATE_GROUP_POSITION) >= (Type & UndoType.STATE_GROUP_POSITION))) | ||
95 | { | ||
96 | GroupPosition = last.GroupPosition; | ||
97 | Position = last.Position; | ||
98 | } | ||
99 | if ((Type & UndoType.STATE_GROUP_SCALE) == 0 || ((last.Type & UndoType.STATE_GROUP_SCALE) >= (Type & UndoType.STATE_GROUP_SCALE))) | ||
100 | { | ||
101 | GroupScale = last.GroupScale; | ||
102 | Scale = last.Scale; | ||
103 | } | ||
104 | if ((Type & UndoType.STATE_GROUP_ROTATION) == 0 || ((last.Type & UndoType.STATE_GROUP_ROTATION) >= (Type & UndoType.STATE_GROUP_ROTATION))) | ||
105 | { | ||
106 | GroupRotation = last.GroupRotation; | ||
107 | Rotation = last.Rotation; | ||
108 | } | ||
109 | if ((Type & UndoType.STATE_PRIM_POSITION) == 0 || ((last.Type & UndoType.STATE_PRIM_POSITION) >= (Type & UndoType.STATE_PRIM_POSITION))) | ||
110 | { | ||
111 | Position = last.Position; | ||
112 | } | ||
113 | if ((Type & UndoType.STATE_PRIM_SCALE) == 0 || ((last.Type & UndoType.STATE_PRIM_SCALE) >= (Type & UndoType.STATE_PRIM_SCALE))) | ||
114 | { | ||
115 | Scale = last.Scale; | ||
116 | } | ||
117 | if ((Type & UndoType.STATE_PRIM_ROTATION) == 0 || ((last.Type & UndoType.STATE_PRIM_ROTATION) >= (Type & UndoType.STATE_PRIM_ROTATION))) | ||
118 | { | ||
119 | Rotation = last.Rotation; | ||
120 | } | ||
121 | Type = Type | last.Type; | ||
122 | } | ||
123 | public bool Compare(UndoState undo) | ||
124 | { | ||
125 | if (undo == null || Position == null) return false; | ||
126 | if (undo.Position == Position && undo.Rotation == Rotation && undo.Scale == Scale && undo.GroupPosition == GroupPosition && undo.GroupScale == GroupScale && undo.GroupRotation == GroupRotation) | ||
127 | { | ||
128 | return true; | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | return false; | ||
133 | } | ||
134 | } | ||
58 | public bool Compare(SceneObjectPart part) | 135 | public bool Compare(SceneObjectPart part) |
59 | { | 136 | { |
60 | if (part != null) | 137 | if (part != null) |
61 | { | 138 | { |
62 | if (part.ParentID == 0) | 139 | if (part.ParentID == 0) |
63 | { | 140 | { |
64 | if (Position == part.ParentGroup.AbsolutePosition && Rotation == part.ParentGroup.Rotation) | 141 | if (Position == part.ParentGroup.RootPart.AbsolutePosition && Rotation == part.ParentGroup.Rotation && GroupPosition == part.ParentGroup.RootPart.AbsolutePosition && part.ParentGroup.Rotation == GroupRotation && part.Shape.Scale == GroupScale) |
65 | return true; | 142 | return true; |
66 | else | 143 | else |
67 | return false; | 144 | return false; |
68 | } | 145 | } |
69 | else | 146 | else |
70 | { | 147 | { |
71 | if (Position == part.OffsetPosition && Rotation == part.RotationOffset && Scale == part.Shape.Scale) | 148 | if (Position == part.OffsetPosition && Rotation == part.RotationOffset && Scale == part.Shape.Scale && GroupPosition == part.ParentGroup.RootPart.AbsolutePosition && part.ParentGroup.Rotation == GroupRotation && part.Shape.Scale == GroupScale) |
72 | return true; | 149 | return true; |
73 | else | 150 | else |
74 | return false; | 151 | return false; |
@@ -78,62 +155,70 @@ namespace OpenSim.Region.Framework.Scenes | |||
78 | return false; | 155 | return false; |
79 | } | 156 | } |
80 | 157 | ||
81 | public void PlaybackState(SceneObjectPart part) | 158 | private void RestoreState(SceneObjectPart part) |
82 | { | 159 | { |
160 | bool GroupChange = false; | ||
161 | if ((Type & UndoType.STATE_GROUP_POSITION) != 0 | ||
162 | || (Type & UndoType.STATE_GROUP_ROTATION) != 0 | ||
163 | || (Type & UndoType.STATE_GROUP_SCALE) != 0) | ||
164 | { | ||
165 | GroupChange = true; | ||
166 | } | ||
167 | |||
83 | if (part != null) | 168 | if (part != null) |
84 | { | 169 | { |
85 | part.Undoing = true; | 170 | part.Undoing = true; |
86 | 171 | ||
87 | if (part.ParentID == 0) | 172 | if (part.ParentID == 0 && GroupChange == false) |
88 | { | 173 | { |
89 | if (Position != Vector3.Zero) | 174 | if (Position != Vector3.Zero) |
90 | part.ParentGroup.AbsolutePosition = Position; | 175 | |
91 | part.RotationOffset = Rotation; | 176 | part.ParentGroup.UpdateSinglePosition(Position, part.LocalId); |
177 | part.ParentGroup.UpdateSingleRotation(Rotation, part.LocalId); | ||
92 | if (Scale != Vector3.Zero) | 178 | if (Scale != Vector3.Zero) |
93 | part.Resize(Scale); | 179 | part.Resize(Scale); |
94 | part.ParentGroup.ScheduleGroupForTerseUpdate(); | 180 | part.ParentGroup.ScheduleGroupForTerseUpdate(); |
95 | } | 181 | } |
96 | else | 182 | else |
97 | { | 183 | { |
98 | if (Position != Vector3.Zero) | 184 | if (GroupChange) |
99 | part.OffsetPosition = Position; | 185 | { |
100 | part.UpdateRotation(Rotation); | 186 | part.ParentGroup.RootPart.Undoing = true; |
101 | if (Scale != Vector3.Zero) | 187 | if (GroupPosition != Vector3.Zero) |
102 | part.Resize(Scale); part.ScheduleTerseUpdate(); | 188 | { |
189 | //Calculate the scale... | ||
190 | Vector3 gs = part.Shape.Scale; | ||
191 | float scale = GroupScale.Z / gs.Z; | ||
192 | |||
193 | //Scale first since it can affect our position | ||
194 | part.ParentGroup.GroupResize(gs * scale, part.LocalId); | ||
195 | part.ParentGroup.AbsolutePosition = GroupPosition; | ||
196 | part.ParentGroup.UpdateGroupRotationR(GroupRotation); | ||
197 | |||
198 | } | ||
199 | part.ParentGroup.RootPart.Undoing = false; | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | if (Position != Vector3.Zero) //We can use this for all the updates since all are set | ||
204 | { | ||
205 | part.OffsetPosition = Position; | ||
206 | part.UpdateRotation(Rotation); | ||
207 | part.Resize(Scale); part.ScheduleTerseUpdate(); | ||
208 | } | ||
209 | } | ||
103 | } | 210 | } |
104 | part.Undoing = false; | 211 | part.Undoing = false; |
105 | 212 | ||
106 | } | 213 | } |
107 | } | 214 | } |
215 | public void PlaybackState(SceneObjectPart part) | ||
216 | { | ||
217 | RestoreState(part); | ||
218 | } | ||
108 | public void PlayfwdState(SceneObjectPart part) | 219 | public void PlayfwdState(SceneObjectPart part) |
109 | { | 220 | { |
110 | if (part != null) | 221 | RestoreState(part); |
111 | { | ||
112 | part.Undoing = true; | ||
113 | |||
114 | if (part.ParentID == 0) | ||
115 | { | ||
116 | if (Position != Vector3.Zero) | ||
117 | part.ParentGroup.AbsolutePosition = Position; | ||
118 | if (Rotation != Quaternion.Identity) | ||
119 | part.UpdateRotation(Rotation); | ||
120 | if (Scale != Vector3.Zero) | ||
121 | part.Resize(Scale); | ||
122 | part.ParentGroup.ScheduleGroupForTerseUpdate(); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | if (Position != Vector3.Zero) | ||
127 | part.OffsetPosition = Position; | ||
128 | if (Rotation != Quaternion.Identity) | ||
129 | part.UpdateRotation(Rotation); | ||
130 | if (Scale != Vector3.Zero) | ||
131 | part.Resize(Scale); | ||
132 | part.ScheduleTerseUpdate(); | ||
133 | } | ||
134 | part.Undoing = false; | ||
135 | |||
136 | } | ||
137 | } | 222 | } |
138 | } | 223 | } |
139 | public class LandUndoState | 224 | public class LandUndoState |
@@ -161,3 +246,4 @@ namespace OpenSim.Region.Framework.Scenes | |||
161 | } | 246 | } |
162 | } | 247 | } |
163 | } | 248 | } |
249 | |||