diff options
author | MW | 2007-06-12 14:50:08 +0000 |
---|---|---|
committer | MW | 2007-06-12 14:50:08 +0000 |
commit | a7b55fb26fad9c66df091e0787afe89e021229f1 (patch) | |
tree | 7920939c67a9275d72dc4a494032b66355d6eb9f /OpenSim/OpenSim.Region/World/Entities/Primitive.cs | |
parent | Some Work on the Primitive class (diff) | |
download | opensim-SC_OLD-a7b55fb26fad9c66df091e0787afe89e021229f1.zip opensim-SC_OLD-a7b55fb26fad9c66df091e0787afe89e021229f1.tar.gz opensim-SC_OLD-a7b55fb26fad9c66df091e0787afe89e021229f1.tar.bz2 opensim-SC_OLD-a7b55fb26fad9c66df091e0787afe89e021229f1.tar.xz |
Some rearranging of folders in OpenSim.Region
Diffstat (limited to 'OpenSim/OpenSim.Region/World/Entities/Primitive.cs')
-rw-r--r-- | OpenSim/OpenSim.Region/World/Entities/Primitive.cs | 525 |
1 files changed, 525 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Region/World/Entities/Primitive.cs b/OpenSim/OpenSim.Region/World/Entities/Primitive.cs new file mode 100644 index 0000000..0680eb3 --- /dev/null +++ b/OpenSim/OpenSim.Region/World/Entities/Primitive.cs | |||
@@ -0,0 +1,525 @@ | |||
1 | |||
2 | /* | ||
3 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
4 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * * Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * * Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * * Neither the name of the OpenSim Project nor the | ||
14 | * names of its contributors may be used to endorse or promote products | ||
15 | * derived from this software without specific prior written permission. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
20 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | * | ||
28 | */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using OpenSim.Region.types; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | using OpenSim.Framework.Interfaces; | ||
36 | using OpenSim.Physics.Manager; | ||
37 | using OpenSim.Framework.Types; | ||
38 | using OpenSim.Framework.Inventory; | ||
39 | |||
40 | namespace OpenSim.Region | ||
41 | { | ||
42 | public class Primitive : Entity | ||
43 | { | ||
44 | internal PrimData primData; | ||
45 | private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); | ||
46 | // private Dictionary<uint, IClientAPI> m_clientThreads; | ||
47 | private ulong m_regionHandle; | ||
48 | private const uint FULL_MASK_PERMISSIONS = 2147483647; | ||
49 | private bool physicsEnabled = false; | ||
50 | private byte updateFlag = 0; | ||
51 | |||
52 | private Dictionary<LLUUID, InventoryItem> inventoryItems; | ||
53 | |||
54 | #region Properties | ||
55 | |||
56 | public LLVector3 Scale | ||
57 | { | ||
58 | set | ||
59 | { | ||
60 | this.primData.Scale = value; | ||
61 | //this.dirtyFlag = true; | ||
62 | } | ||
63 | get | ||
64 | { | ||
65 | return this.primData.Scale; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | public PhysicsActor PhysActor | ||
70 | { | ||
71 | set | ||
72 | { | ||
73 | this._physActor = value; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public override LLVector3 Pos | ||
78 | { | ||
79 | get | ||
80 | { | ||
81 | return base.Pos; | ||
82 | } | ||
83 | set | ||
84 | { | ||
85 | base.Pos = value; | ||
86 | } | ||
87 | } | ||
88 | #endregion | ||
89 | |||
90 | /// <summary> | ||
91 | /// | ||
92 | /// </summary> | ||
93 | /// <param name="clientThreads"></param> | ||
94 | /// <param name="regionHandle"></param> | ||
95 | /// <param name="world"></param> | ||
96 | public Primitive(Dictionary<uint, IClientAPI> clientThreads, ulong regionHandle, World world) | ||
97 | { | ||
98 | // m_clientThreads = clientThreads; | ||
99 | m_regionHandle = regionHandle; | ||
100 | m_world = world; | ||
101 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
102 | } | ||
103 | |||
104 | /// <summary> | ||
105 | /// | ||
106 | /// </summary> | ||
107 | /// <param name="clientThreads"></param> | ||
108 | /// <param name="regionHandle"></param> | ||
109 | /// <param name="world"></param> | ||
110 | /// <param name="owner"></param> | ||
111 | /// <param name="fullID"></param> | ||
112 | /// <param name="localID"></param> | ||
113 | public Primitive(Dictionary<uint, IClientAPI> clientThreads, ulong regionHandle, World world, LLUUID owner, LLUUID fullID, uint localID) | ||
114 | { | ||
115 | // m_clientThreads = clientThreads; | ||
116 | m_regionHandle = regionHandle; | ||
117 | m_world = world; | ||
118 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
119 | this.primData = new PrimData(); | ||
120 | this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
121 | this.primData.OwnerID = owner; | ||
122 | this.primData.FullID = this.uuid = fullID; | ||
123 | this.primData.LocalID = this.localid = localID; | ||
124 | } | ||
125 | |||
126 | /// <summary> | ||
127 | /// Constructor to create a default cube | ||
128 | /// </summary> | ||
129 | /// <param name="clientThreads"></param> | ||
130 | /// <param name="regionHandle"></param> | ||
131 | /// <param name="world"></param> | ||
132 | /// <param name="owner"></param> | ||
133 | /// <param name="localID"></param> | ||
134 | /// <param name="position"></param> | ||
135 | public Primitive(Dictionary<uint, IClientAPI> clientThreads, ulong regionHandle, World world, LLUUID owner, uint localID, LLVector3 position) | ||
136 | { | ||
137 | //m_clientThreads = clientThreads; | ||
138 | m_regionHandle = regionHandle; | ||
139 | m_world = world; | ||
140 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
141 | this.primData = PrimData.DefaultCube(); | ||
142 | this.primData.OwnerID = owner; | ||
143 | this.primData.LocalID = this.localid = localID; | ||
144 | this.Pos = this.primData.Position = position; | ||
145 | |||
146 | this.updateFlag = 1; | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// | ||
151 | /// </summary> | ||
152 | /// <returns></returns> | ||
153 | public byte[] GetByteArray() | ||
154 | { | ||
155 | byte[] result = null; | ||
156 | List<byte[]> dataArrays = new List<byte[]>(); | ||
157 | dataArrays.Add(primData.ToBytes()); | ||
158 | foreach (Entity child in children) | ||
159 | { | ||
160 | if (child is OpenSim.Region.Primitive) | ||
161 | { | ||
162 | dataArrays.Add(((OpenSim.Region.Primitive)child).GetByteArray()); | ||
163 | } | ||
164 | } | ||
165 | byte[] primstart = Helpers.StringToField("<Prim>"); | ||
166 | byte[] primend = Helpers.StringToField("</Prim>"); | ||
167 | int totalLength = primstart.Length + primend.Length; | ||
168 | for (int i = 0; i < dataArrays.Count; i++) | ||
169 | { | ||
170 | totalLength += dataArrays[i].Length; | ||
171 | } | ||
172 | |||
173 | result = new byte[totalLength]; | ||
174 | int arraypos = 0; | ||
175 | Array.Copy(primstart, 0, result, 0, primstart.Length); | ||
176 | arraypos += primstart.Length; | ||
177 | for (int i = 0; i < dataArrays.Count; i++) | ||
178 | { | ||
179 | Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length); | ||
180 | arraypos += dataArrays[i].Length; | ||
181 | } | ||
182 | Array.Copy(primend, 0, result, arraypos, primend.Length); | ||
183 | |||
184 | return result; | ||
185 | } | ||
186 | |||
187 | #region Overridden Methods | ||
188 | |||
189 | /// <summary> | ||
190 | /// | ||
191 | /// </summary> | ||
192 | public override void update() | ||
193 | { | ||
194 | if (this.updateFlag == 1) // is a new prim just been created/reloaded | ||
195 | { | ||
196 | this.SendFullUpdateToAllClients(); | ||
197 | this.updateFlag = 0; | ||
198 | } | ||
199 | if (this.updateFlag == 2) //some change has been made so update the clients | ||
200 | { | ||
201 | this.SendTerseUpdateToALLClients(); | ||
202 | this.updateFlag = 0; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | /// <summary> | ||
207 | /// | ||
208 | /// </summary> | ||
209 | public override void BackUp() | ||
210 | { | ||
211 | |||
212 | } | ||
213 | |||
214 | #endregion | ||
215 | |||
216 | #region Packet handlers | ||
217 | |||
218 | /// <summary> | ||
219 | /// | ||
220 | /// </summary> | ||
221 | /// <param name="pos"></param> | ||
222 | public void UpdatePosition(LLVector3 pos) | ||
223 | { | ||
224 | this.Pos = new LLVector3(pos.X, pos.Y, pos.Z); | ||
225 | this.updateFlag = 2; | ||
226 | } | ||
227 | |||
228 | /// <summary> | ||
229 | /// | ||
230 | /// </summary> | ||
231 | /// <param name="addPacket"></param> | ||
232 | public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket) | ||
233 | { | ||
234 | this.primData.PathBegin = addPacket.PathBegin; | ||
235 | this.primData.PathEnd = addPacket.PathEnd; | ||
236 | this.primData.PathScaleX = addPacket.PathScaleX; | ||
237 | this.primData.PathScaleY = addPacket.PathScaleY; | ||
238 | this.primData.PathShearX = addPacket.PathShearX; | ||
239 | this.primData.PathShearY = addPacket.PathShearY; | ||
240 | this.primData.PathSkew = addPacket.PathSkew; | ||
241 | this.primData.ProfileBegin = addPacket.ProfileBegin; | ||
242 | this.primData.ProfileEnd = addPacket.ProfileEnd; | ||
243 | this.primData.PathCurve = addPacket.PathCurve; | ||
244 | this.primData.ProfileCurve = addPacket.ProfileCurve; | ||
245 | this.primData.ProfileHollow = addPacket.ProfileHollow; | ||
246 | this.primData.PathRadiusOffset = addPacket.PathRadiusOffset; | ||
247 | this.primData.PathRevolutions = addPacket.PathRevolutions; | ||
248 | this.primData.PathTaperX = addPacket.PathTaperX; | ||
249 | this.primData.PathTaperY = addPacket.PathTaperY; | ||
250 | this.primData.PathTwist = addPacket.PathTwist; | ||
251 | this.primData.PathTwistBegin = addPacket.PathTwistBegin; | ||
252 | } | ||
253 | |||
254 | /// <summary> | ||
255 | /// | ||
256 | /// </summary> | ||
257 | /// <param name="tex"></param> | ||
258 | public void UpdateTexture(byte[] tex) | ||
259 | { | ||
260 | this.primData.Texture = tex; | ||
261 | } | ||
262 | |||
263 | /// <summary> | ||
264 | /// | ||
265 | /// </summary> | ||
266 | /// <param name="pack"></param> | ||
267 | public void UpdateObjectFlags(ObjectFlagUpdatePacket pack) | ||
268 | { | ||
269 | |||
270 | } | ||
271 | |||
272 | /// <summary> | ||
273 | /// | ||
274 | /// </summary> | ||
275 | /// <param name="prim"></param> | ||
276 | public void AssignToParent(Primitive prim) | ||
277 | { | ||
278 | |||
279 | } | ||
280 | |||
281 | #endregion | ||
282 | |||
283 | # region Inventory Methods | ||
284 | /// <summary> | ||
285 | /// | ||
286 | /// </summary> | ||
287 | /// <param name="item"></param> | ||
288 | /// <returns></returns> | ||
289 | public bool AddToInventory(InventoryItem item) | ||
290 | { | ||
291 | return false; | ||
292 | } | ||
293 | |||
294 | /// <summary> | ||
295 | /// | ||
296 | /// </summary> | ||
297 | /// <param name="itemID"></param> | ||
298 | /// <returns></returns> | ||
299 | public InventoryItem RemoveFromInventory(LLUUID itemID) | ||
300 | { | ||
301 | return null; | ||
302 | } | ||
303 | |||
304 | /// <summary> | ||
305 | /// | ||
306 | /// </summary> | ||
307 | /// <param name="simClient"></param> | ||
308 | /// <param name="packet"></param> | ||
309 | public void RequestInventoryInfo(IClientAPI simClient, RequestTaskInventoryPacket packet) | ||
310 | { | ||
311 | |||
312 | } | ||
313 | |||
314 | /// <summary> | ||
315 | /// | ||
316 | /// </summary> | ||
317 | /// <param name="simClient"></param> | ||
318 | /// <param name="xferID"></param> | ||
319 | public void RequestXferInventory(IClientAPI simClient, ulong xferID) | ||
320 | { | ||
321 | //will only currently work if the total size of the inventory data array is under about 1000 bytes | ||
322 | SendXferPacketPacket send = new SendXferPacketPacket(); | ||
323 | |||
324 | send.XferID.ID = xferID; | ||
325 | send.XferID.Packet = 1 + 2147483648; | ||
326 | send.DataPacket.Data = this.ConvertInventoryToBytes(); | ||
327 | |||
328 | simClient.OutPacket(send); | ||
329 | } | ||
330 | |||
331 | /// <summary> | ||
332 | /// | ||
333 | /// </summary> | ||
334 | /// <returns></returns> | ||
335 | public byte[] ConvertInventoryToBytes() | ||
336 | { | ||
337 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
338 | byte[] result = new byte[0]; | ||
339 | List<byte[]> inventoryData = new List<byte[]>(); | ||
340 | int totallength = 0; | ||
341 | foreach (InventoryItem invItem in inventoryItems.Values) | ||
342 | { | ||
343 | byte[] data = enc.GetBytes(invItem.ExportString()); | ||
344 | inventoryData.Add(data); | ||
345 | totallength += data.Length; | ||
346 | } | ||
347 | //TODO: copy arrays into the single result array | ||
348 | |||
349 | return result; | ||
350 | } | ||
351 | |||
352 | /// <summary> | ||
353 | /// | ||
354 | /// </summary> | ||
355 | /// <param name="data"></param> | ||
356 | public void CreateInventoryFromBytes(byte[] data) | ||
357 | { | ||
358 | |||
359 | } | ||
360 | |||
361 | #endregion | ||
362 | |||
363 | #region Update viewers Methods | ||
364 | |||
365 | /// <summary> | ||
366 | /// | ||
367 | /// </summary> | ||
368 | /// <param name="remoteClient"></param> | ||
369 | public void SendFullUpdateForAllChildren(IClientAPI remoteClient) | ||
370 | { | ||
371 | this.SendFullUpdateToClient(remoteClient); | ||
372 | for (int i = 0; i < this.children.Count; i++) | ||
373 | { | ||
374 | if (this.children[i] is Primitive) | ||
375 | { | ||
376 | ((Primitive)this.children[i]).SendFullUpdateForAllChildren(remoteClient); | ||
377 | } | ||
378 | } | ||
379 | } | ||
380 | |||
381 | /// <summary> | ||
382 | /// | ||
383 | /// </summary> | ||
384 | /// <param name="remoteClient"></param> | ||
385 | public void SendFullUpdateToClient(IClientAPI remoteClient) | ||
386 | { | ||
387 | LLVector3 lPos; | ||
388 | if (this._physActor != null && this.physicsEnabled) | ||
389 | { | ||
390 | PhysicsVector pPos = this._physActor.Position; | ||
391 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
392 | } | ||
393 | else | ||
394 | { | ||
395 | lPos = this.Pos; | ||
396 | } | ||
397 | |||
398 | remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.localid, this.primData, lPos, new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
399 | } | ||
400 | |||
401 | /// <summary> | ||
402 | /// | ||
403 | /// </summary> | ||
404 | public void SendFullUpdateToAllClients() | ||
405 | { | ||
406 | List<Avatar> avatars = this.m_world.RequestAvatarList(); | ||
407 | for (int i = 0; i < avatars.Count; i++) | ||
408 | { | ||
409 | this.SendFullUpdateToClient(avatars[i].ControllingClient); | ||
410 | } | ||
411 | } | ||
412 | |||
413 | /// <summary> | ||
414 | /// | ||
415 | /// </summary> | ||
416 | /// <param name="RemoteClient"></param> | ||
417 | public void SendTerseUpdateToClient(IClientAPI RemoteClient) | ||
418 | { | ||
419 | LLVector3 lPos; | ||
420 | Axiom.MathLib.Quaternion lRot; | ||
421 | if (this._physActor != null && this.physicsEnabled) | ||
422 | { | ||
423 | PhysicsVector pPos = this._physActor.Position; | ||
424 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
425 | lRot = this._physActor.Orientation; | ||
426 | } | ||
427 | else | ||
428 | { | ||
429 | lPos = this.Pos; | ||
430 | lRot = this.rotation; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | /// <summary> | ||
435 | /// | ||
436 | /// </summary> | ||
437 | public void SendTerseUpdateToALLClients() | ||
438 | { | ||
439 | List<Avatar> avatars = this.m_world.RequestAvatarList(); | ||
440 | for (int i = 0; i < avatars.Count; i++) | ||
441 | { | ||
442 | this.SendTerseUpdateToClient(avatars[i].ControllingClient); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | #endregion | ||
447 | |||
448 | #region Create Methods | ||
449 | |||
450 | /// <summary> | ||
451 | /// | ||
452 | /// </summary> | ||
453 | /// <param name="addPacket"></param> | ||
454 | /// <param name="ownerID"></param> | ||
455 | /// <param name="localID"></param> | ||
456 | public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID) | ||
457 | { | ||
458 | PrimData PData = new PrimData(); | ||
459 | this.primData = PData; | ||
460 | this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
461 | |||
462 | PData.OwnerID = ownerID; | ||
463 | PData.PCode = addPacket.ObjectData.PCode; | ||
464 | PData.PathBegin = addPacket.ObjectData.PathBegin; | ||
465 | PData.PathEnd = addPacket.ObjectData.PathEnd; | ||
466 | PData.PathScaleX = addPacket.ObjectData.PathScaleX; | ||
467 | PData.PathScaleY = addPacket.ObjectData.PathScaleY; | ||
468 | PData.PathShearX = addPacket.ObjectData.PathShearX; | ||
469 | PData.PathShearY = addPacket.ObjectData.PathShearY; | ||
470 | PData.PathSkew = addPacket.ObjectData.PathSkew; | ||
471 | PData.ProfileBegin = addPacket.ObjectData.ProfileBegin; | ||
472 | PData.ProfileEnd = addPacket.ObjectData.ProfileEnd; | ||
473 | PData.Scale = addPacket.ObjectData.Scale; | ||
474 | PData.PathCurve = addPacket.ObjectData.PathCurve; | ||
475 | PData.ProfileCurve = addPacket.ObjectData.ProfileCurve; | ||
476 | PData.ParentID = 0; | ||
477 | PData.ProfileHollow = addPacket.ObjectData.ProfileHollow; | ||
478 | PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset; | ||
479 | PData.PathRevolutions = addPacket.ObjectData.PathRevolutions; | ||
480 | PData.PathTaperX = addPacket.ObjectData.PathTaperX; | ||
481 | PData.PathTaperY = addPacket.ObjectData.PathTaperY; | ||
482 | PData.PathTwist = addPacket.ObjectData.PathTwist; | ||
483 | PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin; | ||
484 | LLVector3 pos1 = addPacket.ObjectData.RayEnd; | ||
485 | this.primData.FullID = this.uuid = LLUUID.Random(); | ||
486 | this.primData.LocalID = this.localid = (uint)(localID); | ||
487 | this.primData.Position = this.Pos = pos1; | ||
488 | |||
489 | this.updateFlag = 1; | ||
490 | } | ||
491 | |||
492 | /// <summary> | ||
493 | /// | ||
494 | /// </summary> | ||
495 | /// <param name="data"></param> | ||
496 | public void CreateFromBytes(byte[] data) | ||
497 | { | ||
498 | |||
499 | } | ||
500 | |||
501 | /// <summary> | ||
502 | /// | ||
503 | /// </summary> | ||
504 | /// <param name="primData"></param> | ||
505 | public void CreateFromPrimData(PrimData primData) | ||
506 | { | ||
507 | this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false); | ||
508 | } | ||
509 | |||
510 | /// <summary> | ||
511 | /// | ||
512 | /// </summary> | ||
513 | /// <param name="primData"></param> | ||
514 | /// <param name="posi"></param> | ||
515 | /// <param name="localID"></param> | ||
516 | /// <param name="newprim"></param> | ||
517 | public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim) | ||
518 | { | ||
519 | |||
520 | } | ||
521 | |||
522 | #endregion | ||
523 | |||
524 | } | ||
525 | } | ||