diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 8099 |
1 files changed, 4332 insertions, 3767 deletions
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 | } | ||