aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Simulation/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
authorMW2007-06-27 15:28:52 +0000
committerMW2007-06-27 15:28:52 +0000
commit646bbbc84b8010e0dacbeed5342cdb045f46cc49 (patch)
tree770b34d19855363c3c113ab9a0af9a56d821d887 /OpenSim/Region/Simulation/Scenes/ScenePresence.cs
downloadopensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.zip
opensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.gz
opensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.bz2
opensim-SC_OLD-646bbbc84b8010e0dacbeed5342cdb045f46cc49.tar.xz
Some work on restructuring the namespaces / project names. Note this doesn't compile yet as not all the code has been changed to use the new namespaces. Am committing it now for feedback on the namespaces.
Diffstat (limited to 'OpenSim/Region/Simulation/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Simulation/Scenes/ScenePresence.cs525
1 files changed, 525 insertions, 0 deletions
diff --git a/OpenSim/Region/Simulation/Scenes/ScenePresence.cs b/OpenSim/Region/Simulation/Scenes/ScenePresence.cs
new file mode 100644
index 0000000..45d3fed
--- /dev/null
+++ b/OpenSim/Region/Simulation/Scenes/ScenePresence.cs
@@ -0,0 +1,525 @@
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*/
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Text;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Physics.Manager;
35using OpenSim.Framework.Inventory;
36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Types;
38using Axiom.MathLib;
39
40namespace OpenSim.Region.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 #region Properties
70 /// <summary>
71 ///
72 /// </summary>
73 public PhysicsActor PhysActor
74 {
75 set
76 {
77 this._physActor = value;
78 }
79 get
80 {
81 return _physActor;
82 }
83 }
84 #endregion
85
86 #region Constructor(s)
87 /// <summary>
88 ///
89 /// </summary>
90 /// <param name="theClient"></param>
91 /// <param name="world"></param>
92 /// <param name="clientThreads"></param>
93 /// <param name="regionDat"></param>
94 public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo)
95 {
96
97 m_world = world;
98 this.uuid = theClient.AgentId;
99
100 m_regionInfo = reginfo;
101 m_regionHandle = reginfo.RegionHandle;
102 OpenSim.Framework.Console.MainLog.Instance.Verbose("Avatar.cs ");
103 ControllingClient = theClient;
104 this.firstname = ControllingClient.FirstName;
105 this.lastname = ControllingClient.LastName;
106 m_localId = m_world.NextLocalId;
107 Pos = ControllingClient.StartPos;
108 visualParams = new byte[218];
109 for (int i = 0; i < 218; i++)
110 {
111 visualParams[i] = 100;
112 }
113
114 Wearables = AvatarWearable.DefaultWearables;
115
116 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
117
118 //register for events
119 ControllingClient.OnRequestWearables += this.SendOurAppearance;
120 //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
121 ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement;
122 ControllingClient.OnCompleteMovementToRegion += this.SendInitialData;
123 ControllingClient.OnAgentUpdate += this.HandleAgentUpdate;
124 // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
125 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
126 //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
127
128 }
129 #endregion
130
131 #region Status Methods
132 /// <summary>
133 /// Not Used, most likely can be deleted
134 /// </summary>
135 /// <param name="status"></param>
136 public void ChildStatusChange(bool status)
137 {
138 this.childAgent = status;
139
140 if (this.childAgent == true)
141 {
142 this.Velocity = new LLVector3(0, 0, 0);
143 this.Pos = new LLVector3(128, 128, 70);
144
145 }
146 }
147
148 /// <summary>
149 ///
150 /// </summary>
151 /// <param name="pos"></param>
152 public void MakeAvatar(LLVector3 pos)
153 {
154 //this.childAvatar = false;
155 this.Pos = pos;
156 this.newAvatar = true;
157 this.childAgent = false;
158 }
159
160 protected void MakeChildAgent()
161 {
162 this.Velocity = new LLVector3(0, 0, 0);
163 this.Pos = new LLVector3(128, 128, 70);
164 this.childAgent = true;
165 }
166
167 /// <summary>
168 ///
169 /// </summary>
170 /// <param name="pos"></param>
171 public void Teleport(LLVector3 pos)
172 {
173 this.Pos = pos;
174 this.SendTerseUpdateToALLClients();
175 }
176
177 /// <summary>
178 ///
179 /// </summary>
180 public void StopMovement()
181 {
182
183 }
184 #endregion
185
186 #region Event Handlers
187 /// <summary>
188 ///
189 /// </summary>
190 /// <param name="texture"></param>
191 /// <param name="visualParam"></param>
192 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
193 {
194
195 }
196
197 /// <summary>
198 /// Complete Avatar's movement into the region
199 /// </summary>
200 public void CompleteMovement()
201 {
202 LLVector3 look = this.Velocity;
203 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
204 {
205 look = new LLVector3(0.99f, 0.042f, 0);
206 }
207 this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look);
208 if (this.childAgent)
209 {
210 this.childAgent = false;
211 }
212 }
213
214 /// <summary>
215 ///
216 /// </summary>
217 /// <param name="pack"></param>
218 public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
219 {
220 if ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0)
221 {
222 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z);
223 if (((movementflag & 1) == 0) || (q != this.bodyRot))
224 {
225 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
226 this.AddNewMovement(v3, q);
227 movementflag = 1;
228 this.bodyRot = q;
229 }
230 }
231 else if ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
232 {
233 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z);
234 if (((movementflag & 2) == 0) || (q != this.bodyRot))
235 {
236 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
237 this.AddNewMovement(v3, q);
238 movementflag = 2;
239 this.bodyRot = q;
240 }
241 }
242 else
243 {
244 if ((movementflag) != 0)
245 {
246 NewForce newVelocity = new NewForce();
247 newVelocity.X = 0;
248 newVelocity.Y = 0;
249 newVelocity.Z = 0;
250 this.forcesList.Add(newVelocity);
251 movementflag = 0;
252 }
253 }
254
255 }
256
257 protected void AddNewMovement(Axiom.MathLib.Vector3 vec, Axiom.MathLib.Quaternion rotation)
258 {
259 NewForce newVelocity = new NewForce();
260 Axiom.MathLib.Vector3 direc = rotation * vec;
261 direc.Normalize();
262
263 direc = direc * ((0.03f) * 128f);
264 if (this._physActor.Flying)
265 direc *= 4;
266
267 newVelocity.X = direc.x;
268 newVelocity.Y = direc.y;
269 newVelocity.Z = direc.z;
270 this.forcesList.Add(newVelocity);
271 }
272
273 #endregion
274
275 #region Overridden Methods
276 /// <summary>
277 ///
278 /// </summary>
279 public override void LandRenegerated()
280 {
281
282 }
283
284 /// <summary>
285 ///
286 /// </summary>
287 public override void update()
288 {
289 if (this.childAgent == false)
290 {
291 if (this.newForce)
292 {
293 this.SendTerseUpdateToALLClients();
294 _updateCount = 0;
295 }
296 else if (movementflag != 0)
297 {
298 _updateCount++;
299 if (_updateCount > 3)
300 {
301 this.SendTerseUpdateToALLClients();
302 _updateCount = 0;
303 }
304 }
305
306 this.CheckForBorderCrossing();
307 }
308 }
309 #endregion
310
311 #region Update Client(s)
312 /// <summary>
313 ///
314 /// </summary>
315 /// <param name="RemoteClient"></param>
316 public void SendTerseUpdateToClient(IClientAPI RemoteClient)
317 {
318 LLVector3 pos = this.Pos;
319 LLVector3 vel = this.Velocity;
320 RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z));
321 }
322
323 /// <summary>
324 ///
325 /// </summary>
326 public void SendTerseUpdateToALLClients()
327 {
328 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
329 for (int i = 0; i < avatars.Count; i++)
330 {
331 this.SendTerseUpdateToClient(avatars[i].ControllingClient);
332 }
333 }
334
335 /// <summary>
336 ///
337 /// </summary>
338 /// <param name="remoteAvatar"></param>
339 public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar)
340 {
341 remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
342 }
343
344 /// <summary>
345 ///
346 /// </summary>
347 public void SendInitialData()
348 {
349 this.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
350 if (this.newAvatar)
351 {
352 this.m_world.InformClientOfNeighbours(this.ControllingClient);
353 this.newAvatar = false;
354 }
355 }
356
357 /// <summary>
358 ///
359 /// </summary>
360 /// <param name="OurClient"></param>
361 public void SendOurAppearance(IClientAPI OurClient)
362 {
363 this.ControllingClient.SendWearables(this.Wearables);
364 }
365
366 /// <summary>
367 ///
368 /// </summary>
369 /// <param name="avatarInfo"></param>
370 public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
371 {
372
373 }
374
375 /// <summary>
376 ///
377 /// </summary>
378 /// <param name="animID"></param>
379 /// <param name="seq"></param>
380 public void SendAnimPack(LLUUID animID, int seq)
381 {
382
383
384 }
385
386 /// <summary>
387 ///
388 /// </summary>
389 public void SendAnimPack()
390 {
391
392 }
393 #endregion
394
395 #region Border Crossing Methods
396 /// <summary>
397 ///
398 /// </summary>
399 protected void CheckForBorderCrossing()
400 {
401 LLVector3 pos2 = this.Pos;
402 LLVector3 vel = this.Velocity;
403
404 float timeStep = 0.2f;
405 pos2.X = pos2.X + (vel.X * timeStep);
406 pos2.Y = pos2.Y + (vel.Y * timeStep);
407 pos2.Z = pos2.Z + (vel.Z * timeStep);
408
409 if ((pos2.X < 0) || (pos2.X > 256))
410 {
411 this.CrossToNewRegion();
412 }
413
414 if ((pos2.Y < 0) || (pos2.Y > 256))
415 {
416 this.CrossToNewRegion();
417 }
418 }
419
420 /// <summary>
421 ///
422 /// </summary>
423 protected void CrossToNewRegion()
424 {
425 LLVector3 pos = this.Pos;
426 LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z);
427 uint neighbourx = this.m_regionInfo.RegionLocX;
428 uint neighboury = this.m_regionInfo.RegionLocY;
429
430 if (pos.X < 2)
431 {
432 neighbourx -= 1;
433 newpos.X = 254;
434 }
435 if (pos.X > 253)
436 {
437 neighbourx += 1;
438 newpos.X = 1;
439 }
440 if (pos.Y < 2)
441 {
442 neighboury -= 1;
443 newpos.Y = 254;
444 }
445 if (pos.Y > 253)
446 {
447 neighboury += 1;
448 newpos.Y = 1;
449 }
450
451 LLVector3 vel = this.velocity;
452 ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * 256), (uint)(neighboury * 256));
453 RegionInfo neighbourRegion = this.m_world.RequestNeighbouringRegionInfo(neighbourHandle);
454 if (neighbourRegion != null)
455 {
456 bool res = this.m_world.InformNeighbourOfCrossing(neighbourHandle, this.ControllingClient.AgentId, newpos);
457 if (res)
458 {
459 this.MakeChildAgent();
460 this.ControllingClient.CrossRegion(neighbourHandle, newpos, vel, System.Net.IPAddress.Parse(neighbourRegion.CommsIPListenAddr), (ushort)neighbourRegion.CommsIPListenPort);
461 }
462 }
463 }
464 #endregion
465
466 /// <summary>
467 ///
468 /// </summary>
469 public static void LoadAnims()
470 {
471
472 }
473
474 /// <summary>
475 ///
476 /// </summary>
477 public override void updateMovement()
478 {
479 newForce = false;
480 lock (this.forcesList)
481 {
482 if (this.forcesList.Count > 0)
483 {
484 for (int i = 0; i < this.forcesList.Count; i++)
485 {
486 NewForce force = this.forcesList[i];
487
488 this.updateflag = true;
489 this.Velocity = new LLVector3(force.X, force.Y, force.Z);
490 this.newForce = true;
491 }
492 for (int i = 0; i < this.forcesList.Count; i++)
493 {
494 this.forcesList.RemoveAt(0);
495 }
496 }
497 }
498 }
499
500 public static void LoadTextureFile(string name)
501 {
502 FileInfo fInfo = new FileInfo(name);
503 long numBytes = fInfo.Length;
504 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
505 BinaryReader br = new BinaryReader(fStream);
506 byte[] data1 = br.ReadBytes((int)numBytes);
507 br.Close();
508 fStream.Close();
509 DefaultTexture = data1;
510 }
511
512 public class NewForce
513 {
514 public float X;
515 public float Y;
516 public float Z;
517
518 public NewForce()
519 {
520
521 }
522 }
523 }
524
525}