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