diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim.RegionServer/world/Primitive2.cs | 254 |
1 files changed, 254 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/world/Primitive2.cs b/OpenSim.RegionServer/world/Primitive2.cs new file mode 100644 index 0000000..87a1d65 --- /dev/null +++ b/OpenSim.RegionServer/world/Primitive2.cs | |||
@@ -0,0 +1,254 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.types; | ||
5 | using libsecondlife; | ||
6 | using libsecondlife.Packets; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Physics.Manager; | ||
9 | using OpenSim.Framework.Assets; | ||
10 | using OpenSim.Framework.Inventory; | ||
11 | |||
12 | namespace 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, SimClient> 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 | private string inventoryFileName = ""; | ||
26 | |||
27 | public LLVector3 Scale | ||
28 | { | ||
29 | set | ||
30 | { | ||
31 | this.primData.Scale = value; | ||
32 | //this.dirtyFlag = true; | ||
33 | } | ||
34 | get | ||
35 | { | ||
36 | return this.primData.Scale; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | public PhysicsActor PhysActor | ||
41 | { | ||
42 | set | ||
43 | { | ||
44 | this._physActor = value; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | |||
49 | public Primitive2(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, World world) | ||
50 | { | ||
51 | m_clientThreads = clientThreads; | ||
52 | m_regionHandle = regionHandle; | ||
53 | m_world = world; | ||
54 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
55 | } | ||
56 | |||
57 | public byte[] GetByteArray() | ||
58 | { | ||
59 | byte[] result = null; | ||
60 | List<byte[]> dataArrays = new List<byte[]>(); | ||
61 | dataArrays.Add(primData.ToBytes()); | ||
62 | foreach (Entity child in children) | ||
63 | { | ||
64 | if (child is OpenSim.world.Primitive2) | ||
65 | { | ||
66 | dataArrays.Add(((OpenSim.world.Primitive2)child).GetByteArray()); | ||
67 | } | ||
68 | } | ||
69 | byte[] primstart = Helpers.StringToField("<Prim>"); | ||
70 | byte[] primend = Helpers.StringToField("</Prim>"); | ||
71 | int totalLength = primstart.Length + primend.Length; | ||
72 | for (int i = 0; i < dataArrays.Count; i++) | ||
73 | { | ||
74 | totalLength += dataArrays[i].Length; | ||
75 | } | ||
76 | |||
77 | result = new byte[totalLength]; | ||
78 | int arraypos = 0; | ||
79 | Array.Copy(primstart, 0, result, 0, primstart.Length); | ||
80 | arraypos += primstart.Length; | ||
81 | for (int i = 0; i < dataArrays.Count; i++) | ||
82 | { | ||
83 | Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length); | ||
84 | arraypos += dataArrays[i].Length; | ||
85 | } | ||
86 | Array.Copy(primend, 0, result, arraypos, primend.Length); | ||
87 | |||
88 | return result; | ||
89 | } | ||
90 | |||
91 | public override void update() | ||
92 | { | ||
93 | LLVector3 pos2 = new LLVector3(0, 0, 0); | ||
94 | } | ||
95 | |||
96 | public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket) | ||
97 | { | ||
98 | |||
99 | } | ||
100 | |||
101 | public void UpdateTexture(byte[] tex) | ||
102 | { | ||
103 | this.OurPacket.ObjectData[0].TextureEntry = tex; | ||
104 | this.primData.Texture = tex; | ||
105 | //this.dirtyFlag = true; | ||
106 | } | ||
107 | |||
108 | public void UpdateObjectFlags(ObjectFlagUpdatePacket pack) | ||
109 | { | ||
110 | |||
111 | } | ||
112 | |||
113 | public void AssignToParent(Primitive prim) | ||
114 | { | ||
115 | |||
116 | } | ||
117 | |||
118 | public bool AddToInventory(InventoryItem item) | ||
119 | { | ||
120 | return false; | ||
121 | } | ||
122 | |||
123 | public InventoryItem RemoveFromInventory(LLUUID itemID) | ||
124 | { | ||
125 | return null; | ||
126 | } | ||
127 | |||
128 | public void RequestInventoryInfo(SimClient simClient, RequestTaskInventoryPacket packet) | ||
129 | { | ||
130 | |||
131 | } | ||
132 | |||
133 | public void RequestXferInventory(SimClient simClient, ulong xferID) | ||
134 | { | ||
135 | //will only currently work if the total size of the inventory data array is under about 1000 bytes | ||
136 | SendXferPacketPacket send = new SendXferPacketPacket(); | ||
137 | |||
138 | send.XferID.ID = xferID; | ||
139 | send.XferID.Packet = 1 + 2147483648; | ||
140 | send.DataPacket.Data = this.ConvertInventoryToBytes(); | ||
141 | |||
142 | simClient.OutPacket(send); | ||
143 | } | ||
144 | |||
145 | public byte[] ConvertInventoryToBytes() | ||
146 | { | ||
147 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
148 | byte[] result = new byte[0]; | ||
149 | List<byte[]> inventoryData = new List<byte[]>(); | ||
150 | int totallength = 0; | ||
151 | foreach (InventoryItem invItem in inventoryItems.Values) | ||
152 | { | ||
153 | byte[] data = enc.GetBytes(invItem.ExportString()); | ||
154 | inventoryData.Add(data); | ||
155 | totallength += data.Length; | ||
156 | } | ||
157 | //TODO: copy arrays into the single result array | ||
158 | |||
159 | return result; | ||
160 | } | ||
161 | |||
162 | public void CreateInventoryFromBytes(byte[] data) | ||
163 | { | ||
164 | |||
165 | } | ||
166 | |||
167 | public override void BackUp() | ||
168 | { | ||
169 | |||
170 | } | ||
171 | |||
172 | public void SendFullUpdateToClient(SimClient RemoteClient) | ||
173 | { | ||
174 | |||
175 | } | ||
176 | |||
177 | public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock() | ||
178 | { | ||
179 | uint ID = this.localid; | ||
180 | byte[] bytes = new byte[60]; | ||
181 | |||
182 | int i = 0; | ||
183 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
184 | dat.TextureEntry = new byte[0]; | ||
185 | bytes[i++] = (byte)(ID % 256); | ||
186 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
187 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
188 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
189 | bytes[i++] = 0; | ||
190 | bytes[i++] = 0; | ||
191 | |||
192 | LLVector3 lPos; | ||
193 | Axiom.MathLib.Quaternion lRot; | ||
194 | if (this._physActor != null && this.physicsEnabled) | ||
195 | { | ||
196 | PhysicsVector pPos = this._physActor.Position; | ||
197 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
198 | lRot = this._physActor.Orientation; | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | lPos = this.Pos; | ||
203 | lRot = this.rotation; | ||
204 | } | ||
205 | byte[] pb = lPos.GetBytes(); | ||
206 | Array.Copy(pb, 0, bytes, i, pb.Length); | ||
207 | i += 12; | ||
208 | ushort ac = 32767; | ||
209 | |||
210 | //vel | ||
211 | bytes[i++] = (byte)(ac % 256); | ||
212 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
213 | bytes[i++] = (byte)(ac % 256); | ||
214 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
215 | bytes[i++] = (byte)(ac % 256); | ||
216 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
217 | |||
218 | //accel | ||
219 | bytes[i++] = (byte)(ac % 256); | ||
220 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
221 | bytes[i++] = (byte)(ac % 256); | ||
222 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
223 | bytes[i++] = (byte)(ac % 256); | ||
224 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
225 | |||
226 | ushort rw, rx, ry, rz; | ||
227 | rw = (ushort)(32768 * (lRot.w + 1)); | ||
228 | rx = (ushort)(32768 * (lRot.x + 1)); | ||
229 | ry = (ushort)(32768 * (lRot.y + 1)); | ||
230 | rz = (ushort)(32768 * (lRot.z + 1)); | ||
231 | |||
232 | //rot | ||
233 | bytes[i++] = (byte)(rx % 256); | ||
234 | bytes[i++] = (byte)((rx >> 8) % 256); | ||
235 | bytes[i++] = (byte)(ry % 256); | ||
236 | bytes[i++] = (byte)((ry >> 8) % 256); | ||
237 | bytes[i++] = (byte)(rz % 256); | ||
238 | bytes[i++] = (byte)((rz >> 8) % 256); | ||
239 | bytes[i++] = (byte)(rw % 256); | ||
240 | bytes[i++] = (byte)((rw >> 8) % 256); | ||
241 | |||
242 | //rotation vel | ||
243 | bytes[i++] = (byte)(ac % 256); | ||
244 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
245 | bytes[i++] = (byte)(ac % 256); | ||
246 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
247 | bytes[i++] = (byte)(ac % 256); | ||
248 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
249 | |||
250 | dat.Data = bytes; | ||
251 | return dat; | ||
252 | } | ||
253 | } | ||
254 | } | ||