1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
/*
* Copyright (c) Contributors, http://www.openmetaverse.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using libsecondlife;
using libsecondlife.Packets;
using OpenSim.Physics.Manager;
using OpenSim.Framework.Inventory;
using OpenSim.Framework.Interfaces;
using OpenSim.RegionServer.Client;
using Axiom.MathLib;
namespace OpenSim.RegionServer.Simulator
{
public partial class Avatar : Entity
{
public static bool PhysicsEngineFlying = false;
public static AvatarAnimations Animations;
public string firstname;
public string lastname;
public ClientView ControllingClient;
public LLUUID current_anim;
public int anim_seq;
private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
private bool updateflag = false;
private byte movementflag = 0;
private List<NewForce> forcesList = new List<NewForce>();
private short _updateCount = 0;
private Axiom.MathLib.Quaternion bodyRot;
private LLObject.TextureEntry avatarAppearanceTexture = null;
private byte[] visualParams;
private AvatarWearable[] Wearables;
private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
private LLVector3 positionFrameBeforeLast = new LLVector3(0, 0, 0);
private int positionRoundedX = 0;
private int positionRoundedY = 0;
private int positionParcelHoverLocalID = -1; //Local ID of the last parcel they were over
private int parcelUpdateSequenceIncrement = 1;
private bool childAvatar = false;
public Avatar(ClientView TheClient, World world)
{
m_world = world;
ControllingClient = TheClient;
OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs - Loading details from grid (DUMMY)");
localid = 8880000 + (this.m_world._localNumber++);
Pos = ControllingClient.startpos;
visualParams = new byte[218];
for (int i = 0; i < 218; i++)
{
visualParams[i] = 100;
}
Wearables = new AvatarWearable[13]; //should be 13 of these
for (int i = 0; i < 13; i++)
{
Wearables[i] = new AvatarWearable();
}
this.Wearables[0].AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
this.Wearables[0].ItemID = LLUUID.Random();
this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
//register for events
ControllingClient.OnRequestWearables += new ClientView.GenericCall(this.SendOurAppearance);
ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.CompleteMovement);
ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.SendInitialPosition);
ControllingClient.OnAgentUpdate += new ClientView.GenericCall3(this.HandleAgentUpdate);
ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
ControllingClient.OnChildAgentStatus += new ClientView.StatusChange(this.ChildStatusChange);
}
public PhysicsActor PhysActor
{
set
{
this._physActor = value;
}
get
{
return _physActor;
}
}
public void ChildStatusChange(bool status)
{
this.childAvatar = status;
if (this.childAvatar == true)
{
this._physActor.Velocity = new PhysicsVector(0, 0, 0);
ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
terse.RegionData.RegionHandle = m_world.m_regInfo.RegionHandle;
terse.RegionData.TimeDilation = 64096;
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
terse.ObjectData[0] = terseBlock;
List<Avatar> avList = this.m_world.RequestAvatarList();
foreach (Avatar client in avList)
{
client.SendPacketToViewer(terse);
}
}
else
{
LLVector3 startp = ControllingClient.StartPos;
lock (m_world.LockPhysicsEngine)
{
this._physActor.Position = new PhysicsVector(startp.X, startp.Y, startp.Z);
}
}
}
public override void addForces()
{
lock (this.forcesList)
{
if (this.forcesList.Count > 0)
{
for (int i = 0; i < this.forcesList.Count; i++)
{
NewForce force = this.forcesList[i];
PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
lock (m_world.LockPhysicsEngine)
{
this._physActor.Velocity = phyVector;
}
this.updateflag = true;
this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
// but as we are setting the velocity (rather than using real forces) at the moment it is okay.
}
for (int i = 0; i < this.forcesList.Count; i++)
{
this.forcesList.RemoveAt(0);
}
}
}
}
public static void SetupTemplate(string name)
{
FileInfo fInfo = new FileInfo(name);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
byte[] data1 = br.ReadBytes((int)numBytes);
br.Close();
fStream.Close();
libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
SetDefaultPacketValues(objdata);
objdata.TextureEntry = data1;
objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
objdata.PathCurve = 16;
objdata.ProfileCurve = 1;
objdata.PathScaleX = 100;
objdata.PathScaleY = 100;
objdata.ParentID = 0;
objdata.OwnerID = LLUUID.Zero;
objdata.Scale = new LLVector3(1, 1, 1);
objdata.PCode = 47;
System.Text.Encoding enc = System.Text.Encoding.ASCII;
libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
pos.X = 100f;
objdata.ID = 8880000;
objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
//objdata.FullID=user.AgentID;
byte[] pb = pos.GetBytes();
Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
Avatar.AvatarTemplate = objdata;
}
protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
{
objdata.PSBlock = new byte[0];
objdata.ExtraParams = new byte[1];
objdata.MediaURL = new byte[0];
objdata.NameValue = new byte[0];
objdata.Text = new byte[0];
objdata.TextColor = new byte[4];
objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
objdata.JointPivot = new LLVector3(0, 0, 0);
objdata.Material = 4;
objdata.TextureAnim = new byte[0];
objdata.Sound = LLUUID.Zero;
LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
objdata.TextureEntry = ntex.ToBytes();
objdata.State = 0;
objdata.Data = new byte[0];
objdata.ObjectData = new byte[76];
objdata.ObjectData[15] = 128;
objdata.ObjectData[16] = 63;
objdata.ObjectData[56] = 128;
objdata.ObjectData[61] = 102;
objdata.ObjectData[62] = 40;
objdata.ObjectData[63] = 61;
objdata.ObjectData[64] = 189;
}
public void CompleteMovement()
{
OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
mov.AgentData.SessionID = this.ControllingClient.SessionID;
mov.AgentData.AgentID = this.ControllingClient.AgentID;
mov.Data.RegionHandle = this.m_world.m_regInfo.RegionHandle;
// TODO - dynamicalise this stuff
mov.Data.Timestamp = 1172750370;
mov.Data.Position = this.ControllingClient.startpos;
mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
ControllingClient.OutPacket(mov);
}
public void HandleAgentUpdate(Packet pack)
{
this.HandleUpdate((AgentUpdatePacket)pack);
}
public void HandleUpdate(AgentUpdatePacket pack)
{
if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0)
{
if (this._physActor.Flying == false)
{
this.current_anim = Animations.AnimsLLUUID["FLY"];
this.anim_seq = 1;
this.SendAnimPack();
}
this._physActor.Flying = true;
}
else
{
if (this._physActor.Flying == true)
{
this.current_anim = Animations.AnimsLLUUID["STAND"];
this.anim_seq = 1;
this.SendAnimPack();
}
this._physActor.Flying = false;
}
if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0)
{
Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
if (((movementflag & 1) == 0) || (q != this.bodyRot))
{
if (((movementflag & 1) == 0) && (!this._physActor.Flying))
{
this.current_anim = Animations.AnimsLLUUID["WALK"];
this.anim_seq = 1;
this.SendAnimPack();
}
//we should add a new force to the list
// but for now we will deal with velocities
NewForce newVelocity = new NewForce();
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
Axiom.MathLib.Vector3 direc = q * v3;
direc.Normalize();
//work out velocity for sim physics system
direc = direc * ((0.03f) * 128f);
if (this._physActor.Flying)
direc *= 4;
newVelocity.X = direc.x;
newVelocity.Y = direc.y;
newVelocity.Z = direc.z;
this.forcesList.Add(newVelocity);
movementflag = 1;
this.bodyRot = q;
}
}
else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying))
{
if (((movementflag & 2) == 0) && this._physActor.Flying)
{
//we should add a new force to the list
// but for now we will deal with velocities
NewForce newVelocity = new NewForce();
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
Axiom.MathLib.Vector3 direc = v3;
direc.Normalize();
//work out velocity for sim physics system
direc = direc * ((0.03f) * 128f * 2);
newVelocity.X = direc.x;
newVelocity.Y = direc.y;
newVelocity.Z = direc.z;
this.forcesList.Add(newVelocity);
movementflag = 2;
}
}
else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying))
{
if (((movementflag & 4) == 0) && this._physActor.Flying)
{
//we should add a new force to the list
// but for now we will deal with velocities
NewForce newVelocity = new NewForce();
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
//Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
Axiom.MathLib.Vector3 direc = v3;
direc.Normalize();
//work out velocity for sim physics system
direc = direc * ((0.03f) * 128f * 2);
newVelocity.X = direc.x;
newVelocity.Y = direc.y;
newVelocity.Z = direc.z;
this.forcesList.Add(newVelocity);
movementflag = 4;
}
}
else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
{
Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
if (((movementflag & 8) == 0) || (q != this.bodyRot))
{
//we should add a new force to the list
// but for now we will deal with velocities
NewForce newVelocity = new NewForce();
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
Axiom.MathLib.Vector3 direc = q * v3;
direc.Normalize();
//work out velocity for sim physics system
direc = direc * ((0.03f) * 128f);
if (this._physActor.Flying)
direc *= 2;
newVelocity.X = direc.x;
newVelocity.Y = direc.y;
newVelocity.Z = direc.z;
this.forcesList.Add(newVelocity);
movementflag = 8;
this.bodyRot = q;
}
}
else
{
if (movementflag == 16)
{
movementflag = 0;
}
if ((movementflag) != 0)
{
NewForce newVelocity = new NewForce();
newVelocity.X = 0;
newVelocity.Y = 0;
newVelocity.Z = 0;
this.forcesList.Add(newVelocity);
movementflag = 0;
// We're standing still, so make it show!
if (this._physActor.Flying == false)
{
this.current_anim = Animations.AnimsLLUUID["STAND"];
this.anim_seq = 1;
this.SendAnimPack();
}
this.movementflag = 16;
}
}
}
public static void LoadAnims()
{
Avatar.Animations = new AvatarAnimations();
Avatar.Animations.LoadAnims();
}
public override void LandRenegerated()
{
Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 50.0f);
}
}
public class NewForce
{
public float X;
public float Y;
public float Z;
public NewForce()
{
}
}
}
|