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