diff options
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/ScenePresence.cs')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/ScenePresence.cs | 549 |
1 files changed, 549 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs new file mode 100644 index 0000000..b90004e --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs | |||
@@ -0,0 +1,549 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Text; | ||
32 | using libsecondlife; | ||
33 | using libsecondlife.Packets; | ||
34 | using OpenSim.Physics.Manager; | ||
35 | using OpenSim.Framework.Inventory; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Types; | ||
38 | using Axiom.MathLib; | ||
39 | |||
40 | namespace OpenSim.Region.Environment.Scenes | ||
41 | { | ||
42 | public partial class ScenePresence : Entity | ||
43 | { | ||
44 | public static bool PhysicsEngineFlying = false; | ||
45 | public static AvatarAnimations Animations; | ||
46 | public static byte[] DefaultTexture; | ||
47 | public string firstname; | ||
48 | public string lastname; | ||
49 | public IClientAPI ControllingClient; | ||
50 | public LLUUID current_anim; | ||
51 | public int anim_seq; | ||
52 | private bool updateflag = false; | ||
53 | private byte movementflag = 0; | ||
54 | private List<NewForce> forcesList = new List<NewForce>(); | ||
55 | private short _updateCount = 0; | ||
56 | private Axiom.MathLib.Quaternion bodyRot; | ||
57 | private LLObject.TextureEntry avatarAppearanceTexture = null; | ||
58 | private byte[] visualParams; | ||
59 | private AvatarWearable[] Wearables; | ||
60 | private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); | ||
61 | private ulong m_regionHandle; | ||
62 | private bool childAgent = false; | ||
63 | private bool newForce = false; | ||
64 | private bool newAvatar = false; | ||
65 | private IScenePresenceBody m_body; | ||
66 | |||
67 | protected RegionInfo m_regionInfo; | ||
68 | |||
69 | private Vector3[] Dir_Vectors = new Vector3[6]; | ||
70 | private enum Dir_ControlFlags | ||
71 | { | ||
72 | DIR_CONTROL_FLAG_FOWARD = MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS, | ||
73 | DIR_CONTROL_FLAG_BACK = MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG, | ||
74 | DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS, | ||
75 | DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG, | ||
76 | DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS, | ||
77 | DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG | ||
78 | } | ||
79 | |||
80 | #region Properties | ||
81 | /// <summary> | ||
82 | /// | ||
83 | /// </summary> | ||
84 | public PhysicsActor PhysActor | ||
85 | { | ||
86 | set | ||
87 | { | ||
88 | this._physActor = value; | ||
89 | } | ||
90 | get | ||
91 | { | ||
92 | return _physActor; | ||
93 | } | ||
94 | } | ||
95 | #endregion | ||
96 | |||
97 | #region Constructor(s) | ||
98 | /// <summary> | ||
99 | /// | ||
100 | /// </summary> | ||
101 | /// <param name="theClient"></param> | ||
102 | /// <param name="world"></param> | ||
103 | /// <param name="clientThreads"></param> | ||
104 | /// <param name="regionDat"></param> | ||
105 | public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo) | ||
106 | { | ||
107 | |||
108 | m_world = world; | ||
109 | this.uuid = theClient.AgentId; | ||
110 | |||
111 | m_regionInfo = reginfo; | ||
112 | m_regionHandle = reginfo.RegionHandle; | ||
113 | OpenSim.Framework.Console.MainLog.Instance.Verbose("Avatar.cs "); | ||
114 | ControllingClient = theClient; | ||
115 | this.firstname = ControllingClient.FirstName; | ||
116 | this.lastname = ControllingClient.LastName; | ||
117 | m_localId = m_world.NextLocalId; | ||
118 | Pos = ControllingClient.StartPos; | ||
119 | visualParams = new byte[218]; | ||
120 | for (int i = 0; i < 218; i++) | ||
121 | { | ||
122 | visualParams[i] = 100; | ||
123 | } | ||
124 | |||
125 | Wearables = AvatarWearable.DefaultWearables; | ||
126 | |||
127 | this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
128 | |||
129 | //register for events | ||
130 | ControllingClient.OnRequestWearables += this.SendOurAppearance; | ||
131 | //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance); | ||
132 | ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement; | ||
133 | ControllingClient.OnCompleteMovementToRegion += this.SendInitialData; | ||
134 | ControllingClient.OnAgentUpdate += this.HandleAgentUpdate; | ||
135 | // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack); | ||
136 | // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); | ||
137 | //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); | ||
138 | |||
139 | Dir_Vectors[0] = new Vector3(1, 0, 0); //FOWARD | ||
140 | Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK | ||
141 | Dir_Vectors[2] = new Vector3(0, 1, 0); //LEFT | ||
142 | Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT | ||
143 | Dir_Vectors[4] = new Vector3(0, 0, 1); //UP | ||
144 | Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN | ||
145 | |||
146 | } | ||
147 | #endregion | ||
148 | |||
149 | #region Status Methods | ||
150 | /// <summary> | ||
151 | /// Not Used, most likely can be deleted | ||
152 | /// </summary> | ||
153 | /// <param name="status"></param> | ||
154 | public void ChildStatusChange(bool status) | ||
155 | { | ||
156 | this.childAgent = status; | ||
157 | |||
158 | if (this.childAgent == true) | ||
159 | { | ||
160 | this.Velocity = new LLVector3(0, 0, 0); | ||
161 | this.Pos = new LLVector3(128, 128, 70); | ||
162 | |||
163 | } | ||
164 | } | ||
165 | |||
166 | /// <summary> | ||
167 | /// | ||
168 | /// </summary> | ||
169 | /// <param name="pos"></param> | ||
170 | public void MakeAvatar(LLVector3 pos) | ||
171 | { | ||
172 | //this.childAvatar = false; | ||
173 | this.Pos = pos; | ||
174 | this.newAvatar = true; | ||
175 | this.childAgent = false; | ||
176 | } | ||
177 | |||
178 | protected void MakeChildAgent() | ||
179 | { | ||
180 | this.Velocity = new LLVector3(0, 0, 0); | ||
181 | this.Pos = new LLVector3(128, 128, 70); | ||
182 | this.childAgent = true; | ||
183 | } | ||
184 | |||
185 | /// <summary> | ||
186 | /// | ||
187 | /// </summary> | ||
188 | /// <param name="pos"></param> | ||
189 | public void Teleport(LLVector3 pos) | ||
190 | { | ||
191 | this.Pos = pos; | ||
192 | this.SendTerseUpdateToALLClients(); | ||
193 | } | ||
194 | |||
195 | /// <summary> | ||
196 | /// | ||
197 | /// </summary> | ||
198 | public void StopMovement() | ||
199 | { | ||
200 | |||
201 | } | ||
202 | #endregion | ||
203 | |||
204 | #region Event Handlers | ||
205 | /// <summary> | ||
206 | /// | ||
207 | /// </summary> | ||
208 | /// <param name="texture"></param> | ||
209 | /// <param name="visualParam"></param> | ||
210 | public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam) | ||
211 | { | ||
212 | |||
213 | } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Complete Avatar's movement into the region | ||
217 | /// </summary> | ||
218 | public void CompleteMovement() | ||
219 | { | ||
220 | LLVector3 look = this.Velocity; | ||
221 | if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) | ||
222 | { | ||
223 | look = new LLVector3(0.99f, 0.042f, 0); | ||
224 | } | ||
225 | this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look); | ||
226 | if (this.childAgent) | ||
227 | { | ||
228 | this.childAgent = false; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | /// <summary> | ||
233 | /// | ||
234 | /// </summary> | ||
235 | /// <param name="pack"></param> | ||
236 | public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) | ||
237 | { | ||
238 | int i = 0; | ||
239 | bool update_movementflag = false; | ||
240 | bool update_rotation = false; | ||
241 | bool DCFlagKeyPressed = false; | ||
242 | Vector3 agent_control_v3 = new Vector3(0, 0, 0); | ||
243 | Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z); | ||
244 | |||
245 | this.PhysActor.Flying = ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0); | ||
246 | |||
247 | if (q != this.bodyRot) | ||
248 | { | ||
249 | this.bodyRot = q; | ||
250 | update_rotation = true; | ||
251 | } | ||
252 | foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof(Dir_ControlFlags))) | ||
253 | { | ||
254 | if ((flags & (uint)DCF) != 0) | ||
255 | { | ||
256 | DCFlagKeyPressed = true; | ||
257 | agent_control_v3 += Dir_Vectors[i]; | ||
258 | if ((movementflag & (uint)DCF) == 0) | ||
259 | { | ||
260 | movementflag += (byte)(uint)DCF; | ||
261 | update_movementflag = true; | ||
262 | } | ||
263 | } | ||
264 | else | ||
265 | { | ||
266 | if ((movementflag & (uint)DCF) != 0) | ||
267 | { | ||
268 | movementflag -= (byte)(uint)DCF; | ||
269 | update_movementflag = true; | ||
270 | } | ||
271 | } | ||
272 | i++; | ||
273 | } | ||
274 | if ((update_movementflag) || (update_rotation && DCFlagKeyPressed)) | ||
275 | { | ||
276 | this.AddNewMovement(agent_control_v3, q); | ||
277 | } | ||
278 | |||
279 | } | ||
280 | |||
281 | protected void AddNewMovement(Axiom.MathLib.Vector3 vec, Axiom.MathLib.Quaternion rotation) | ||
282 | { | ||
283 | NewForce newVelocity = new NewForce(); | ||
284 | Axiom.MathLib.Vector3 direc = rotation * vec; | ||
285 | direc.Normalize(); | ||
286 | |||
287 | direc = direc * ((0.03f) * 128f); | ||
288 | if (this._physActor.Flying) | ||
289 | direc *= 4; | ||
290 | |||
291 | newVelocity.X = direc.x; | ||
292 | newVelocity.Y = direc.y; | ||
293 | newVelocity.Z = direc.z; | ||
294 | this.forcesList.Add(newVelocity); | ||
295 | } | ||
296 | |||
297 | #endregion | ||
298 | |||
299 | #region Overridden Methods | ||
300 | /// <summary> | ||
301 | /// | ||
302 | /// </summary> | ||
303 | public override void LandRenegerated() | ||
304 | { | ||
305 | |||
306 | } | ||
307 | |||
308 | /// <summary> | ||
309 | /// | ||
310 | /// </summary> | ||
311 | public override void update() | ||
312 | { | ||
313 | if (this.childAgent == false) | ||
314 | { | ||
315 | if (this.newForce) | ||
316 | { | ||
317 | this.SendTerseUpdateToALLClients(); | ||
318 | _updateCount = 0; | ||
319 | } | ||
320 | else if (movementflag != 0) | ||
321 | { | ||
322 | _updateCount++; | ||
323 | if (_updateCount > 3) | ||
324 | { | ||
325 | this.SendTerseUpdateToALLClients(); | ||
326 | _updateCount = 0; | ||
327 | } | ||
328 | } | ||
329 | |||
330 | this.CheckForBorderCrossing(); | ||
331 | } | ||
332 | } | ||
333 | #endregion | ||
334 | |||
335 | #region Update Client(s) | ||
336 | /// <summary> | ||
337 | /// | ||
338 | /// </summary> | ||
339 | /// <param name="RemoteClient"></param> | ||
340 | public void SendTerseUpdateToClient(IClientAPI RemoteClient) | ||
341 | { | ||
342 | LLVector3 pos = this.Pos; | ||
343 | LLVector3 vel = this.Velocity; | ||
344 | RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z)); | ||
345 | } | ||
346 | |||
347 | /// <summary> | ||
348 | /// | ||
349 | /// </summary> | ||
350 | public void SendTerseUpdateToALLClients() | ||
351 | { | ||
352 | List<ScenePresence> avatars = this.m_world.RequestAvatarList(); | ||
353 | for (int i = 0; i < avatars.Count; i++) | ||
354 | { | ||
355 | this.SendTerseUpdateToClient(avatars[i].ControllingClient); | ||
356 | } | ||
357 | } | ||
358 | |||
359 | /// <summary> | ||
360 | /// | ||
361 | /// </summary> | ||
362 | /// <param name="remoteAvatar"></param> | ||
363 | public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar) | ||
364 | { | ||
365 | remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture); | ||
366 | } | ||
367 | |||
368 | /// <summary> | ||
369 | /// | ||
370 | /// </summary> | ||
371 | public void SendInitialData() | ||
372 | { | ||
373 | this.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture); | ||
374 | if (this.newAvatar) | ||
375 | { | ||
376 | this.m_world.InformClientOfNeighbours(this.ControllingClient); | ||
377 | this.newAvatar = false; | ||
378 | } | ||
379 | } | ||
380 | |||
381 | /// <summary> | ||
382 | /// | ||
383 | /// </summary> | ||
384 | /// <param name="OurClient"></param> | ||
385 | public void SendOurAppearance(IClientAPI OurClient) | ||
386 | { | ||
387 | this.ControllingClient.SendWearables(this.Wearables); | ||
388 | } | ||
389 | |||
390 | /// <summary> | ||
391 | /// | ||
392 | /// </summary> | ||
393 | /// <param name="avatarInfo"></param> | ||
394 | public void SendAppearanceToOtherAgent(ScenePresence avatarInfo) | ||
395 | { | ||
396 | |||
397 | } | ||
398 | |||
399 | /// <summary> | ||
400 | /// | ||
401 | /// </summary> | ||
402 | /// <param name="animID"></param> | ||
403 | /// <param name="seq"></param> | ||
404 | public void SendAnimPack(LLUUID animID, int seq) | ||
405 | { | ||
406 | |||
407 | |||
408 | } | ||
409 | |||
410 | /// <summary> | ||
411 | /// | ||
412 | /// </summary> | ||
413 | public void SendAnimPack() | ||
414 | { | ||
415 | |||
416 | } | ||
417 | #endregion | ||
418 | |||
419 | #region Border Crossing Methods | ||
420 | /// <summary> | ||
421 | /// | ||
422 | /// </summary> | ||
423 | protected void CheckForBorderCrossing() | ||
424 | { | ||
425 | LLVector3 pos2 = this.Pos; | ||
426 | LLVector3 vel = this.Velocity; | ||
427 | |||
428 | float timeStep = 0.2f; | ||
429 | pos2.X = pos2.X + (vel.X * timeStep); | ||
430 | pos2.Y = pos2.Y + (vel.Y * timeStep); | ||
431 | pos2.Z = pos2.Z + (vel.Z * timeStep); | ||
432 | |||
433 | if ((pos2.X < 0) || (pos2.X > 256)) | ||
434 | { | ||
435 | this.CrossToNewRegion(); | ||
436 | } | ||
437 | |||
438 | if ((pos2.Y < 0) || (pos2.Y > 256)) | ||
439 | { | ||
440 | this.CrossToNewRegion(); | ||
441 | } | ||
442 | } | ||
443 | |||
444 | /// <summary> | ||
445 | /// | ||
446 | /// </summary> | ||
447 | protected void CrossToNewRegion() | ||
448 | { | ||
449 | LLVector3 pos = this.Pos; | ||
450 | LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z); | ||
451 | uint neighbourx = this.m_regionInfo.RegionLocX; | ||
452 | uint neighboury = this.m_regionInfo.RegionLocY; | ||
453 | |||
454 | if (pos.X < 2) | ||
455 | { | ||
456 | neighbourx -= 1; | ||
457 | newpos.X = 254; | ||
458 | } | ||
459 | if (pos.X > 253) | ||
460 | { | ||
461 | neighbourx += 1; | ||
462 | newpos.X = 1; | ||
463 | } | ||
464 | if (pos.Y < 2) | ||
465 | { | ||
466 | neighboury -= 1; | ||
467 | newpos.Y = 254; | ||
468 | } | ||
469 | if (pos.Y > 253) | ||
470 | { | ||
471 | neighboury += 1; | ||
472 | newpos.Y = 1; | ||
473 | } | ||
474 | |||
475 | LLVector3 vel = this.velocity; | ||
476 | ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * 256), (uint)(neighboury * 256)); | ||
477 | RegionInfo neighbourRegion = this.m_world.RequestNeighbouringRegionInfo(neighbourHandle); | ||
478 | if (neighbourRegion != null) | ||
479 | { | ||
480 | bool res = this.m_world.InformNeighbourOfCrossing(neighbourHandle, this.ControllingClient.AgentId, newpos); | ||
481 | if (res) | ||
482 | { | ||
483 | this.MakeChildAgent(); | ||
484 | this.ControllingClient.CrossRegion(neighbourHandle, newpos, vel, System.Net.IPAddress.Parse(neighbourRegion.CommsIPListenAddr), (ushort)neighbourRegion.CommsIPListenPort); | ||
485 | } | ||
486 | } | ||
487 | } | ||
488 | #endregion | ||
489 | |||
490 | /// <summary> | ||
491 | /// | ||
492 | /// </summary> | ||
493 | public static void LoadAnims() | ||
494 | { | ||
495 | |||
496 | } | ||
497 | |||
498 | /// <summary> | ||
499 | /// | ||
500 | /// </summary> | ||
501 | public override void updateMovement() | ||
502 | { | ||
503 | newForce = false; | ||
504 | lock (this.forcesList) | ||
505 | { | ||
506 | if (this.forcesList.Count > 0) | ||
507 | { | ||
508 | for (int i = 0; i < this.forcesList.Count; i++) | ||
509 | { | ||
510 | NewForce force = this.forcesList[i]; | ||
511 | |||
512 | this.updateflag = true; | ||
513 | this.Velocity = new LLVector3(force.X, force.Y, force.Z); | ||
514 | this.newForce = true; | ||
515 | } | ||
516 | for (int i = 0; i < this.forcesList.Count; i++) | ||
517 | { | ||
518 | this.forcesList.RemoveAt(0); | ||
519 | } | ||
520 | } | ||
521 | } | ||
522 | } | ||
523 | |||
524 | public static void LoadTextureFile(string name) | ||
525 | { | ||
526 | FileInfo fInfo = new FileInfo(name); | ||
527 | long numBytes = fInfo.Length; | ||
528 | FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); | ||
529 | BinaryReader br = new BinaryReader(fStream); | ||
530 | byte[] data1 = br.ReadBytes((int)numBytes); | ||
531 | br.Close(); | ||
532 | fStream.Close(); | ||
533 | DefaultTexture = data1; | ||
534 | } | ||
535 | |||
536 | public class NewForce | ||
537 | { | ||
538 | public float X; | ||
539 | public float Y; | ||
540 | public float Z; | ||
541 | |||
542 | public NewForce() | ||
543 | { | ||
544 | |||
545 | } | ||
546 | } | ||
547 | } | ||
548 | |||
549 | } | ||