aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/world/Primitive2.cs
diff options
context:
space:
mode:
authorMW2007-05-24 12:35:32 +0000
committerMW2007-05-24 12:35:32 +0000
commitf95b6081cba084d1b067acea99c0effa2b3bf42c (patch)
tree7a7ab4aa037f75afa54f403c701a735acb101575 /OpenSim/OpenSim.RegionServer/world/Primitive2.cs
parentDie ServiceManager! (Not really Gareth, just the old directory, new directory... (diff)
downloadopensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.zip
opensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.gz
opensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.bz2
opensim-SC_OLD-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.xz
Renamed the new Directories. (removed the "-Source" from the end of them)
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/world/Primitive2.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Primitive2.cs491
1 files changed, 491 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.RegionServer/world/Primitive2.cs b/OpenSim/OpenSim.RegionServer/world/Primitive2.cs
new file mode 100644
index 0000000..6d071d4
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Primitive2.cs
@@ -0,0 +1,491 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.types;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Physics.Manager;
9using OpenSim.Framework.Types;
10using OpenSim.Framework.Inventory;
11
12namespace OpenSim.world
13{
14 public class Primitive2 : Entity
15 {
16 protected PrimData primData;
17 //private ObjectUpdatePacket OurPacket;
18 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
19 private Dictionary<uint, ClientView> m_clientThreads;
20 private ulong m_regionHandle;
21 private const uint FULL_MASK_PERMISSIONS = 2147483647;
22 private bool physicsEnabled = false;
23
24 private Dictionary<LLUUID, InventoryItem> inventoryItems;
25
26 #region Properties
27
28 public LLVector3 Scale
29 {
30 set
31 {
32 this.primData.Scale = value;
33 //this.dirtyFlag = true;
34 }
35 get
36 {
37 return this.primData.Scale;
38 }
39 }
40
41 public PhysicsActor PhysActor
42 {
43 set
44 {
45 this._physActor = value;
46 }
47 }
48 public override LLVector3 Pos
49 {
50 get
51 {
52 return base.Pos;
53 }
54 set
55 {
56 base.Pos = value;
57 }
58 }
59 #endregion
60
61 public Primitive2(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world)
62 {
63 m_clientThreads = clientThreads;
64 m_regionHandle = regionHandle;
65 m_world = world;
66 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
67 }
68
69 public Primitive2(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world, LLUUID owner)
70 {
71 m_clientThreads = clientThreads;
72 m_regionHandle = regionHandle;
73 m_world = world;
74 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
75 this.primData = new PrimData();
76 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
77 this.primData.OwnerID = owner;
78 }
79
80 public byte[] GetByteArray()
81 {
82 byte[] result = null;
83 List<byte[]> dataArrays = new List<byte[]>();
84 dataArrays.Add(primData.ToBytes());
85 foreach (Entity child in children)
86 {
87 if (child is OpenSim.world.Primitive2)
88 {
89 dataArrays.Add(((OpenSim.world.Primitive2)child).GetByteArray());
90 }
91 }
92 byte[] primstart = Helpers.StringToField("<Prim>");
93 byte[] primend = Helpers.StringToField("</Prim>");
94 int totalLength = primstart.Length + primend.Length;
95 for (int i = 0; i < dataArrays.Count; i++)
96 {
97 totalLength += dataArrays[i].Length;
98 }
99
100 result = new byte[totalLength];
101 int arraypos = 0;
102 Array.Copy(primstart, 0, result, 0, primstart.Length);
103 arraypos += primstart.Length;
104 for (int i = 0; i < dataArrays.Count; i++)
105 {
106 Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length);
107 arraypos += dataArrays[i].Length;
108 }
109 Array.Copy(primend, 0, result, arraypos, primend.Length);
110
111 return result;
112 }
113
114 #region Overridden Methods
115
116 public override void update()
117 {
118 LLVector3 pos2 = new LLVector3(0, 0, 0);
119 }
120
121 public override void BackUp()
122 {
123
124 }
125
126 #endregion
127
128 #region Packet handlers
129
130 public void UpdatePosition(LLVector3 pos)
131 {
132
133 }
134
135 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
136 {
137 this.primData.PathBegin = addPacket.PathBegin;
138 this.primData.PathEnd = addPacket.PathEnd;
139 this.primData.PathScaleX = addPacket.PathScaleX;
140 this.primData.PathScaleY = addPacket.PathScaleY;
141 this.primData.PathShearX = addPacket.PathShearX;
142 this.primData.PathShearY = addPacket.PathShearY;
143 this.primData.PathSkew = addPacket.PathSkew;
144 this.primData.ProfileBegin = addPacket.ProfileBegin;
145 this.primData.ProfileEnd = addPacket.ProfileEnd;
146 this.primData.PathCurve = addPacket.PathCurve;
147 this.primData.ProfileCurve = addPacket.ProfileCurve;
148 this.primData.ProfileHollow = addPacket.ProfileHollow;
149 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
150 this.primData.PathRevolutions = addPacket.PathRevolutions;
151 this.primData.PathTaperX = addPacket.PathTaperX;
152 this.primData.PathTaperY = addPacket.PathTaperY;
153 this.primData.PathTwist = addPacket.PathTwist;
154 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
155 }
156
157 public void UpdateTexture(byte[] tex)
158 {
159 this.primData.Texture = tex;
160 //this.dirtyFlag = true;
161 }
162
163 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
164 {
165
166 }
167
168 public void AssignToParent(Primitive prim)
169 {
170
171 }
172
173 public void GetProperites(ClientView client)
174 {
175 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
176 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
177 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
178 proper.ObjectData[0].ItemID = LLUUID.Zero;
179 proper.ObjectData[0].CreationDate = (ulong)this.primData.CreationDate;
180 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
181 proper.ObjectData[0].FolderID = LLUUID.Zero;
182 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
183 proper.ObjectData[0].GroupID = LLUUID.Zero;
184 proper.ObjectData[0].InventorySerial = 0;
185 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
186 proper.ObjectData[0].ObjectID = this.uuid;
187 proper.ObjectData[0].OwnerID = primData.OwnerID;
188 proper.ObjectData[0].TouchName = new byte[0];
189 proper.ObjectData[0].TextureID = new byte[0];
190 proper.ObjectData[0].SitName = new byte[0];
191 proper.ObjectData[0].Name = new byte[0];
192 proper.ObjectData[0].Description = new byte[0];
193 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
194 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
195 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
196 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
197 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
198
199 client.OutPacket(proper);
200 }
201
202 #endregion
203
204 # region Inventory Methods
205
206 public bool AddToInventory(InventoryItem item)
207 {
208 return false;
209 }
210
211 public InventoryItem RemoveFromInventory(LLUUID itemID)
212 {
213 return null;
214 }
215
216 public void RequestInventoryInfo(ClientView simClient, RequestTaskInventoryPacket packet)
217 {
218
219 }
220
221 public void RequestXferInventory(ClientView simClient, ulong xferID)
222 {
223 //will only currently work if the total size of the inventory data array is under about 1000 bytes
224 SendXferPacketPacket send = new SendXferPacketPacket();
225
226 send.XferID.ID = xferID;
227 send.XferID.Packet = 1 + 2147483648;
228 send.DataPacket.Data = this.ConvertInventoryToBytes();
229
230 simClient.OutPacket(send);
231 }
232
233 public byte[] ConvertInventoryToBytes()
234 {
235 System.Text.Encoding enc = System.Text.Encoding.ASCII;
236 byte[] result = new byte[0];
237 List<byte[]> inventoryData = new List<byte[]>();
238 int totallength = 0;
239 foreach (InventoryItem invItem in inventoryItems.Values)
240 {
241 byte[] data = enc.GetBytes(invItem.ExportString());
242 inventoryData.Add(data);
243 totallength += data.Length;
244 }
245 //TODO: copy arrays into the single result array
246
247 return result;
248 }
249
250 public void CreateInventoryFromBytes(byte[] data)
251 {
252
253 }
254
255 #endregion
256
257 #region Update viewers Methods
258
259 //should change these mehtods, so that outgoing packets are sent through the avatar class
260 public void SendFullUpdateToClient(ClientView remoteClient)
261 {
262 LLVector3 lPos;
263 if (this._physActor != null && this.physicsEnabled)
264 {
265 PhysicsVector pPos = this._physActor.Position;
266 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
267 }
268 else
269 {
270 lPos = this.Pos;
271 }
272
273 ObjectUpdatePacket outPacket = new ObjectUpdatePacket();
274 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
275 outPacket.ObjectData[0] = this.CreateUpdateBlock();
276 byte[] pb = lPos.GetBytes();
277 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
278
279 remoteClient.OutPacket(outPacket);
280 }
281
282 public void SendFullUpdateToAllClients()
283 {
284
285 }
286
287 public void SendTerseUpdateToClient(ClientView RemoteClient)
288 {
289
290 }
291
292 public void SendTerseUpdateToALLClients()
293 {
294
295 }
296
297 #endregion
298
299 #region Create Methods
300
301 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
302 {
303 PrimData PData = new PrimData();
304 this.primData = PData;
305 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
306
307 PData.OwnerID = ownerID;
308 PData.PCode = addPacket.ObjectData.PCode;
309 PData.PathBegin = addPacket.ObjectData.PathBegin;
310 PData.PathEnd = addPacket.ObjectData.PathEnd;
311 PData.PathScaleX = addPacket.ObjectData.PathScaleX;
312 PData.PathScaleY = addPacket.ObjectData.PathScaleY;
313 PData.PathShearX = addPacket.ObjectData.PathShearX;
314 PData.PathShearY = addPacket.ObjectData.PathShearY;
315 PData.PathSkew = addPacket.ObjectData.PathSkew;
316 PData.ProfileBegin = addPacket.ObjectData.ProfileBegin;
317 PData.ProfileEnd = addPacket.ObjectData.ProfileEnd;
318 PData.Scale = addPacket.ObjectData.Scale;
319 PData.PathCurve = addPacket.ObjectData.PathCurve;
320 PData.ProfileCurve = addPacket.ObjectData.ProfileCurve;
321 PData.ParentID = 0;
322 PData.ProfileHollow = addPacket.ObjectData.ProfileHollow;
323 PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
324 PData.PathRevolutions = addPacket.ObjectData.PathRevolutions;
325 PData.PathTaperX = addPacket.ObjectData.PathTaperX;
326 PData.PathTaperY = addPacket.ObjectData.PathTaperY;
327 PData.PathTwist = addPacket.ObjectData.PathTwist;
328 PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
329 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
330 this.primData.FullID = this.uuid = LLUUID.Random();
331 this.localid = (uint)(localID);
332 this.primData.Position = this.Pos = pos1;
333 }
334
335 public void CreateFromBytes(byte[] data)
336 {
337
338 }
339
340 public void CreateFromPrimData(PrimData primData)
341 {
342 this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false);
343 }
344
345 public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim)
346 {
347
348 }
349
350 #endregion
351
352 #region Packet Update Methods
353 protected void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
354 {
355 objdata.PSBlock = new byte[0];
356 objdata.ExtraParams = new byte[1];
357 objdata.MediaURL = new byte[0];
358 objdata.NameValue = new byte[0];
359 objdata.Text = new byte[0];
360 objdata.TextColor = new byte[4];
361 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
362 objdata.JointPivot = new LLVector3(0, 0, 0);
363 objdata.Material = 3;
364 objdata.TextureAnim = new byte[0];
365 objdata.Sound = LLUUID.Zero;
366 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
367 this.primData.Texture = objdata.TextureEntry = ntex.ToBytes();
368 objdata.State = 0;
369 objdata.Data = new byte[0];
370
371 objdata.ObjectData = new byte[60];
372 objdata.ObjectData[46] = 128;
373 objdata.ObjectData[47] = 63;
374 }
375
376 protected void SetPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData)
377 {
378 objectData.OwnerID = this.primData.OwnerID;
379 objectData.PCode = this.primData.PCode;
380 objectData.PathBegin = this.primData.PathBegin;
381 objectData.PathEnd = this.primData.PathEnd;
382 objectData.PathScaleX = this.primData.PathScaleX;
383 objectData.PathScaleY = this.primData.PathScaleY;
384 objectData.PathShearX = this.primData.PathShearX;
385 objectData.PathShearY = this.primData.PathShearY;
386 objectData.PathSkew = this.primData.PathSkew;
387 objectData.ProfileBegin = this.primData.ProfileBegin;
388 objectData.ProfileEnd = this.primData.ProfileEnd;
389 objectData.Scale = this.primData.Scale;
390 objectData.PathCurve = this.primData.PathCurve;
391 objectData.ProfileCurve = this.primData.ProfileCurve;
392 objectData.ParentID = this.primData.ParentID;
393 objectData.ProfileHollow = this.primData.ProfileHollow;
394 objectData.PathRadiusOffset = this.primData.PathRadiusOffset;
395 objectData.PathRevolutions = this.primData.PathRevolutions;
396 objectData.PathTaperX = this.primData.PathTaperX;
397 objectData.PathTaperY = this.primData.PathTaperY;
398 objectData.PathTwist = this.primData.PathTwist;
399 objectData.PathTwistBegin = this.primData.PathTwistBegin;
400 }
401
402 #endregion
403 protected ObjectUpdatePacket.ObjectDataBlock CreateUpdateBlock()
404 {
405 ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
406 this.SetDefaultPacketValues(objupdate);
407 objupdate.UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
408 this.SetPacketShapeData(objupdate);
409 byte[] pb = this.Pos.GetBytes();
410 Array.Copy(pb, 0, objupdate.ObjectData, 0, pb.Length);
411 return objupdate;
412 }
413
414 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
415 {
416 uint ID = this.localid;
417 byte[] bytes = new byte[60];
418
419 int i = 0;
420 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
421 dat.TextureEntry = new byte[0];
422 bytes[i++] = (byte)(ID % 256);
423 bytes[i++] = (byte)((ID >> 8) % 256);
424 bytes[i++] = (byte)((ID >> 16) % 256);
425 bytes[i++] = (byte)((ID >> 24) % 256);
426 bytes[i++] = 0;
427 bytes[i++] = 0;
428
429 LLVector3 lPos;
430 Axiom.MathLib.Quaternion lRot;
431 if (this._physActor != null && this.physicsEnabled)
432 {
433 PhysicsVector pPos = this._physActor.Position;
434 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
435 lRot = this._physActor.Orientation;
436 }
437 else
438 {
439 lPos = this.Pos;
440 lRot = this.rotation;
441 }
442 byte[] pb = lPos.GetBytes();
443 Array.Copy(pb, 0, bytes, i, pb.Length);
444 i += 12;
445 ushort ac = 32767;
446
447 //vel
448 bytes[i++] = (byte)(ac % 256);
449 bytes[i++] = (byte)((ac >> 8) % 256);
450 bytes[i++] = (byte)(ac % 256);
451 bytes[i++] = (byte)((ac >> 8) % 256);
452 bytes[i++] = (byte)(ac % 256);
453 bytes[i++] = (byte)((ac >> 8) % 256);
454
455 //accel
456 bytes[i++] = (byte)(ac % 256);
457 bytes[i++] = (byte)((ac >> 8) % 256);
458 bytes[i++] = (byte)(ac % 256);
459 bytes[i++] = (byte)((ac >> 8) % 256);
460 bytes[i++] = (byte)(ac % 256);
461 bytes[i++] = (byte)((ac >> 8) % 256);
462
463 ushort rw, rx, ry, rz;
464 rw = (ushort)(32768 * (lRot.w + 1));
465 rx = (ushort)(32768 * (lRot.x + 1));
466 ry = (ushort)(32768 * (lRot.y + 1));
467 rz = (ushort)(32768 * (lRot.z + 1));
468
469 //rot
470 bytes[i++] = (byte)(rx % 256);
471 bytes[i++] = (byte)((rx >> 8) % 256);
472 bytes[i++] = (byte)(ry % 256);
473 bytes[i++] = (byte)((ry >> 8) % 256);
474 bytes[i++] = (byte)(rz % 256);
475 bytes[i++] = (byte)((rz >> 8) % 256);
476 bytes[i++] = (byte)(rw % 256);
477 bytes[i++] = (byte)((rw >> 8) % 256);
478
479 //rotation vel
480 bytes[i++] = (byte)(ac % 256);
481 bytes[i++] = (byte)((ac >> 8) % 256);
482 bytes[i++] = (byte)(ac % 256);
483 bytes[i++] = (byte)((ac >> 8) % 256);
484 bytes[i++] = (byte)(ac % 256);
485 bytes[i++] = (byte)((ac >> 8) % 256);
486
487 dat.Data = bytes;
488 return dat;
489 }
490 }
491}