aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs435
1 files changed, 0 insertions, 435 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs
deleted file mode 100644
index a64ee9e..0000000
--- a/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs
+++ /dev/null
@@ -1,435 +0,0 @@
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.RegionServer.Client;
38
39using Axiom.MathLib;
40
41namespace OpenSim.RegionServer.Simulator
42{
43 public partial class Avatar : Entity
44 {
45 public static bool PhysicsEngineFlying = false;
46 public static AvatarAnimations Animations;
47 public string firstname;
48 public string lastname;
49 public ClientView ControllingClient;
50 public LLUUID current_anim;
51 public int anim_seq;
52 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
53 private bool updateflag = false;
54 private byte movementflag = 0;
55 private List<NewForce> forcesList = new List<NewForce>();
56 private short _updateCount = 0;
57 private Axiom.MathLib.Quaternion bodyRot;
58 private LLObject.TextureEntry avatarAppearanceTexture = null;
59 private byte[] visualParams;
60 private AvatarWearable[] Wearables;
61 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
62 private LLVector3 positionFrameBeforeLast = new LLVector3(0, 0, 0);
63
64 private int positionRoundedX = 0;
65 private int positionRoundedY = 0;
66
67 private int positionParcelHoverLocalID = -1; //Local ID of the last parcel they were over
68 private int parcelUpdateSequenceIncrement = 1;
69
70 private bool childAvatar = false;
71
72 public Avatar(ClientView TheClient, World world)
73 {
74 m_world = world;
75 ControllingClient = TheClient;
76
77 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs - Loading details from grid (DUMMY)");
78 localid = 8880000 + (this.m_world._localNumber++);
79 Pos = ControllingClient.startpos;
80 visualParams = new byte[218];
81 for (int i = 0; i < 218; i++)
82 {
83 visualParams[i] = 100;
84 }
85 Wearables = new AvatarWearable[13]; //should be 13 of these
86 for (int i = 0; i < 13; i++)
87 {
88 Wearables[i] = new AvatarWearable();
89 }
90 this.Wearables[0].AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
91 this.Wearables[0].ItemID = LLUUID.Random();
92
93 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
94
95 //register for events
96 ControllingClient.OnRequestWearables += new ClientView.GenericCall(this.SendOurAppearance);
97 ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
98 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.CompleteMovement);
99 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.SendInitialPosition);
100 ControllingClient.OnAgentUpdate += new ClientView.GenericCall3(this.HandleAgentUpdate);
101 ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
102 ControllingClient.OnChildAgentStatus += new ClientView.StatusChange(this.ChildStatusChange);
103
104 }
105
106 public PhysicsActor PhysActor
107 {
108 set
109 {
110 this._physActor = value;
111 }
112 get
113 {
114 return _physActor;
115 }
116 }
117
118 public void ChildStatusChange(bool status)
119 {
120 this.childAvatar = status;
121
122 if (this.childAvatar == true)
123 {
124 this._physActor.Velocity = new PhysicsVector(0, 0, 0);
125 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
126 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
127 terse.RegionData.RegionHandle = m_world.m_regInfo.RegionHandle;
128 terse.RegionData.TimeDilation = 64096;
129 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
130 terse.ObjectData[0] = terseBlock;
131 List<Avatar> avList = this.m_world.RequestAvatarList();
132 foreach (Avatar client in avList)
133 {
134 client.SendPacketToViewer(terse);
135 }
136 }
137 else
138 {
139 LLVector3 startp = ControllingClient.StartPos;
140 lock (m_world.LockPhysicsEngine)
141 {
142 this._physActor.Position = new PhysicsVector(startp.X, startp.Y, startp.Z);
143 }
144 }
145 }
146
147 public override void addForces()
148 {
149 lock (this.forcesList)
150 {
151 if (this.forcesList.Count > 0)
152 {
153 for (int i = 0; i < this.forcesList.Count; i++)
154 {
155 NewForce force = this.forcesList[i];
156 PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
157 lock (m_world.LockPhysicsEngine)
158 {
159 this._physActor.Velocity = phyVector;
160 }
161 this.updateflag = true;
162 this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
163 // but as we are setting the velocity (rather than using real forces) at the moment it is okay.
164 }
165 for (int i = 0; i < this.forcesList.Count; i++)
166 {
167 this.forcesList.RemoveAt(0);
168 }
169 }
170 }
171 }
172
173 public static void SetupTemplate(string name)
174 {
175 FileInfo fInfo = new FileInfo(name);
176 long numBytes = fInfo.Length;
177 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
178 BinaryReader br = new BinaryReader(fStream);
179 byte[] data1 = br.ReadBytes((int)numBytes);
180 br.Close();
181 fStream.Close();
182
183 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
184
185 SetDefaultPacketValues(objdata);
186 objdata.TextureEntry = data1;
187 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
188 objdata.PathCurve = 16;
189 objdata.ProfileCurve = 1;
190 objdata.PathScaleX = 100;
191 objdata.PathScaleY = 100;
192 objdata.ParentID = 0;
193 objdata.OwnerID = LLUUID.Zero;
194 objdata.Scale = new LLVector3(1, 1, 1);
195 objdata.PCode = 47;
196 System.Text.Encoding enc = System.Text.Encoding.ASCII;
197 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
198 pos.X = 100f;
199 objdata.ID = 8880000;
200 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
201 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
202 //objdata.FullID=user.AgentID;
203 byte[] pb = pos.GetBytes();
204 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
205
206 Avatar.AvatarTemplate = objdata;
207 }
208
209 protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
210 {
211 objdata.PSBlock = new byte[0];
212 objdata.ExtraParams = new byte[1];
213 objdata.MediaURL = new byte[0];
214 objdata.NameValue = new byte[0];
215 objdata.Text = new byte[0];
216 objdata.TextColor = new byte[4];
217 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
218 objdata.JointPivot = new LLVector3(0, 0, 0);
219 objdata.Material = 4;
220 objdata.TextureAnim = new byte[0];
221 objdata.Sound = LLUUID.Zero;
222 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
223 objdata.TextureEntry = ntex.ToBytes();
224 objdata.State = 0;
225 objdata.Data = new byte[0];
226
227 objdata.ObjectData = new byte[76];
228 objdata.ObjectData[15] = 128;
229 objdata.ObjectData[16] = 63;
230 objdata.ObjectData[56] = 128;
231 objdata.ObjectData[61] = 102;
232 objdata.ObjectData[62] = 40;
233 objdata.ObjectData[63] = 61;
234 objdata.ObjectData[64] = 189;
235
236
237 }
238
239 public void CompleteMovement()
240 {
241 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
242 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
243 mov.AgentData.SessionID = this.ControllingClient.SessionID;
244 mov.AgentData.AgentID = this.ControllingClient.AgentID;
245 mov.Data.RegionHandle = this.m_world.m_regInfo.RegionHandle;
246 // TODO - dynamicalise this stuff
247 mov.Data.Timestamp = 1172750370;
248 mov.Data.Position = this.ControllingClient.startpos;
249 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
250
251 ControllingClient.OutPacket(mov);
252 }
253
254 public void HandleAgentUpdate(Packet pack)
255 {
256 this.HandleUpdate((AgentUpdatePacket)pack);
257 }
258
259 public void HandleUpdate(AgentUpdatePacket pack)
260 {
261 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0)
262 {
263 if (this._physActor.Flying == false)
264 {
265 this.current_anim = Animations.AnimsLLUUID["FLY"];
266 this.anim_seq = 1;
267 this.SendAnimPack();
268 }
269 this._physActor.Flying = true;
270
271 }
272 else
273 {
274 if (this._physActor.Flying == true)
275 {
276 this.current_anim = Animations.AnimsLLUUID["STAND"];
277 this.anim_seq = 1;
278 this.SendAnimPack();
279 }
280 this._physActor.Flying = false;
281 }
282 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0)
283 {
284 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
285 if (((movementflag & 1) == 0) || (q != this.bodyRot))
286 {
287
288 if (((movementflag & 1) == 0) && (!this._physActor.Flying))
289 {
290 this.current_anim = Animations.AnimsLLUUID["WALK"];
291 this.anim_seq = 1;
292 this.SendAnimPack();
293 }
294
295
296 //we should add a new force to the list
297 // but for now we will deal with velocities
298 NewForce newVelocity = new NewForce();
299 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
300 Axiom.MathLib.Vector3 direc = q * v3;
301 direc.Normalize();
302
303 //work out velocity for sim physics system
304 direc = direc * ((0.03f) * 128f);
305 if (this._physActor.Flying)
306 direc *= 4;
307
308 newVelocity.X = direc.x;
309 newVelocity.Y = direc.y;
310 newVelocity.Z = direc.z;
311 this.forcesList.Add(newVelocity);
312 movementflag = 1;
313 this.bodyRot = q;
314 }
315 }
316 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying))
317 {
318 if (((movementflag & 2) == 0) && this._physActor.Flying)
319 {
320 //we should add a new force to the list
321 // but for now we will deal with velocities
322 NewForce newVelocity = new NewForce();
323 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
324 Axiom.MathLib.Vector3 direc = v3;
325 direc.Normalize();
326
327 //work out velocity for sim physics system
328 direc = direc * ((0.03f) * 128f * 2);
329 newVelocity.X = direc.x;
330 newVelocity.Y = direc.y;
331 newVelocity.Z = direc.z;
332 this.forcesList.Add(newVelocity);
333 movementflag = 2;
334 }
335 }
336 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying))
337 {
338 if (((movementflag & 4) == 0) && this._physActor.Flying)
339 {
340 //we should add a new force to the list
341 // but for now we will deal with velocities
342 NewForce newVelocity = new NewForce();
343 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
344 //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
345 Axiom.MathLib.Vector3 direc = v3;
346 direc.Normalize();
347
348 //work out velocity for sim physics system
349 direc = direc * ((0.03f) * 128f * 2);
350 newVelocity.X = direc.x;
351 newVelocity.Y = direc.y;
352 newVelocity.Z = direc.z;
353 this.forcesList.Add(newVelocity);
354 movementflag = 4;
355 }
356 }
357 else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
358 {
359 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
360 if (((movementflag & 8) == 0) || (q != this.bodyRot))
361 {
362 //we should add a new force to the list
363 // but for now we will deal with velocities
364 NewForce newVelocity = new NewForce();
365 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
366 Axiom.MathLib.Vector3 direc = q * v3;
367 direc.Normalize();
368
369 //work out velocity for sim physics system
370 direc = direc * ((0.03f) * 128f);
371 if (this._physActor.Flying)
372 direc *= 2;
373
374 newVelocity.X = direc.x;
375 newVelocity.Y = direc.y;
376 newVelocity.Z = direc.z;
377 this.forcesList.Add(newVelocity);
378 movementflag = 8;
379 this.bodyRot = q;
380 }
381 }
382 else
383 {
384 if (movementflag == 16)
385 {
386 movementflag = 0;
387 }
388 if ((movementflag) != 0)
389 {
390 NewForce newVelocity = new NewForce();
391 newVelocity.X = 0;
392 newVelocity.Y = 0;
393 newVelocity.Z = 0;
394 this.forcesList.Add(newVelocity);
395 movementflag = 0;
396 // We're standing still, so make it show!
397 if (this._physActor.Flying == false)
398 {
399 this.current_anim = Animations.AnimsLLUUID["STAND"];
400 this.anim_seq = 1;
401 this.SendAnimPack();
402 }
403 this.movementflag = 16;
404
405 }
406 }
407 }
408
409
410
411 public static void LoadAnims()
412 {
413 Avatar.Animations = new AvatarAnimations();
414 Avatar.Animations.LoadAnims();
415 }
416
417 public override void LandRenegerated()
418 {
419 Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 50.0f);
420 }
421 }
422
423 public class NewForce
424 {
425 public float X;
426 public float Y;
427 public float Z;
428
429 public NewForce()
430 {
431
432 }
433 }
434
435}