diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs | 353 |
1 files changed, 353 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs new file mode 100644 index 0000000..e7e7bb3 --- /dev/null +++ b/OpenSim/Region/Physics/ChOdePlugin/OdeUtils.cs | |||
@@ -0,0 +1,353 @@ | |||
1 | /* Ubit 2012 | ||
2 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
3 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
4 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
5 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
6 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
7 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
8 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
9 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
10 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
11 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
12 | */ | ||
13 | |||
14 | // no endian conversion. So can't be use to pass information around diferent cpus with diferent endian | ||
15 | |||
16 | using System; | ||
17 | using System.IO; | ||
18 | using OpenMetaverse; | ||
19 | |||
20 | namespace OpenSim.Region.Physics.OdePlugin | ||
21 | { | ||
22 | |||
23 | unsafe public class wstreamer | ||
24 | { | ||
25 | byte[] buf; | ||
26 | int index; | ||
27 | byte* src; | ||
28 | |||
29 | public wstreamer() | ||
30 | { | ||
31 | buf = new byte[1024]; | ||
32 | index = 0; | ||
33 | } | ||
34 | public wstreamer(int size) | ||
35 | { | ||
36 | buf = new byte[size]; | ||
37 | index = 0; | ||
38 | } | ||
39 | |||
40 | public byte[] close() | ||
41 | { | ||
42 | byte[] data = new byte[index]; | ||
43 | Buffer.BlockCopy(buf, 0, data, 0, index); | ||
44 | return data; | ||
45 | } | ||
46 | |||
47 | public void Seek(int pos) | ||
48 | { | ||
49 | index = pos; | ||
50 | } | ||
51 | |||
52 | public void Seekrel(int pos) | ||
53 | { | ||
54 | index += pos; | ||
55 | } | ||
56 | |||
57 | public void Wbyte(byte value) | ||
58 | { | ||
59 | buf[index++] = value; | ||
60 | } | ||
61 | public void Wshort(short value) | ||
62 | { | ||
63 | src = (byte*)&value; | ||
64 | buf[index++] = *src++; | ||
65 | buf[index++] = *src; | ||
66 | } | ||
67 | public void Wushort(ushort value) | ||
68 | { | ||
69 | src = (byte*)&value; | ||
70 | buf[index++] = *src++; | ||
71 | buf[index++] = *src; | ||
72 | } | ||
73 | public void Wint(int value) | ||
74 | { | ||
75 | src = (byte*)&value; | ||
76 | buf[index++] = *src++; | ||
77 | buf[index++] = *src++; | ||
78 | buf[index++] = *src++; | ||
79 | buf[index++] = *src; | ||
80 | } | ||
81 | public void Wuint(uint value) | ||
82 | { | ||
83 | src = (byte*)&value; | ||
84 | buf[index++] = *src++; | ||
85 | buf[index++] = *src++; | ||
86 | buf[index++] = *src++; | ||
87 | buf[index++] = *src; | ||
88 | } | ||
89 | public void Wlong(long value) | ||
90 | { | ||
91 | src = (byte*)&value; | ||
92 | buf[index++] = *src++; | ||
93 | buf[index++] = *src++; | ||
94 | buf[index++] = *src++; | ||
95 | buf[index++] = *src++; | ||
96 | buf[index++] = *src++; | ||
97 | buf[index++] = *src++; | ||
98 | buf[index++] = *src++; | ||
99 | buf[index++] = *src; | ||
100 | } | ||
101 | public void Wulong(ulong value) | ||
102 | { | ||
103 | src = (byte*)&value; | ||
104 | buf[index++] = *src++; | ||
105 | buf[index++] = *src++; | ||
106 | buf[index++] = *src++; | ||
107 | buf[index++] = *src++; | ||
108 | buf[index++] = *src++; | ||
109 | buf[index++] = *src++; | ||
110 | buf[index++] = *src++; | ||
111 | buf[index++] = *src; | ||
112 | } | ||
113 | |||
114 | public void Wfloat(float value) | ||
115 | { | ||
116 | src = (byte*)&value; | ||
117 | buf[index++] = *src++; | ||
118 | buf[index++] = *src++; | ||
119 | buf[index++] = *src++; | ||
120 | buf[index++] = *src; | ||
121 | } | ||
122 | |||
123 | public void Wdouble(double value) | ||
124 | { | ||
125 | src = (byte*)&value; | ||
126 | buf[index++] = *src++; | ||
127 | buf[index++] = *src++; | ||
128 | buf[index++] = *src++; | ||
129 | buf[index++] = *src++; | ||
130 | buf[index++] = *src++; | ||
131 | buf[index++] = *src++; | ||
132 | buf[index++] = *src++; | ||
133 | buf[index++] = *src; | ||
134 | } | ||
135 | |||
136 | public void Wvector3(Vector3 value) | ||
137 | { | ||
138 | src = (byte*)&value.X; | ||
139 | buf[index++] = *src++; | ||
140 | buf[index++] = *src++; | ||
141 | buf[index++] = *src++; | ||
142 | buf[index++] = *src; | ||
143 | src = (byte*)&value.Y; // it may have padding ?? | ||
144 | buf[index++] = *src++; | ||
145 | buf[index++] = *src++; | ||
146 | buf[index++] = *src++; | ||
147 | buf[index++] = *src; | ||
148 | src = (byte*)&value.Z; | ||
149 | buf[index++] = *src++; | ||
150 | buf[index++] = *src++; | ||
151 | buf[index++] = *src++; | ||
152 | buf[index++] = *src; | ||
153 | } | ||
154 | public void Wquat(Quaternion value) | ||
155 | { | ||
156 | src = (byte*)&value.X; | ||
157 | buf[index++] = *src++; | ||
158 | buf[index++] = *src++; | ||
159 | buf[index++] = *src++; | ||
160 | buf[index++] = *src; | ||
161 | src = (byte*)&value.Y; // it may have padding ?? | ||
162 | buf[index++] = *src++; | ||
163 | buf[index++] = *src++; | ||
164 | buf[index++] = *src++; | ||
165 | buf[index++] = *src; | ||
166 | src = (byte*)&value.Z; | ||
167 | buf[index++] = *src++; | ||
168 | buf[index++] = *src++; | ||
169 | buf[index++] = *src++; | ||
170 | buf[index++] = *src; | ||
171 | src = (byte*)&value.W; | ||
172 | buf[index++] = *src++; | ||
173 | buf[index++] = *src++; | ||
174 | buf[index++] = *src++; | ||
175 | buf[index++] = *src; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | unsafe public class rstreamer | ||
180 | { | ||
181 | private byte[] rbuf; | ||
182 | private int ptr; | ||
183 | private byte* dst; | ||
184 | |||
185 | public rstreamer(byte[] data) | ||
186 | { | ||
187 | rbuf = data; | ||
188 | ptr = 0; | ||
189 | } | ||
190 | |||
191 | public void close() | ||
192 | { | ||
193 | } | ||
194 | |||
195 | public void Seek(int pos) | ||
196 | { | ||
197 | ptr = pos; | ||
198 | } | ||
199 | |||
200 | public void Seekrel(int pos) | ||
201 | { | ||
202 | ptr += pos; | ||
203 | } | ||
204 | |||
205 | public byte Rbyte() | ||
206 | { | ||
207 | return (byte)rbuf[ptr++]; | ||
208 | } | ||
209 | |||
210 | public short Rshort() | ||
211 | { | ||
212 | short v; | ||
213 | dst = (byte*)&v; | ||
214 | *dst++ = rbuf[ptr++]; | ||
215 | *dst = rbuf[ptr++]; | ||
216 | return v; | ||
217 | } | ||
218 | public ushort Rushort() | ||
219 | { | ||
220 | ushort v; | ||
221 | dst = (byte*)&v; | ||
222 | *dst++ = rbuf[ptr++]; | ||
223 | *dst = rbuf[ptr++]; | ||
224 | return v; | ||
225 | } | ||
226 | public int Rint() | ||
227 | { | ||
228 | int v; | ||
229 | dst = (byte*)&v; | ||
230 | *dst++ = rbuf[ptr++]; | ||
231 | *dst++ = rbuf[ptr++]; | ||
232 | *dst++ = rbuf[ptr++]; | ||
233 | *dst = rbuf[ptr++]; | ||
234 | return v; | ||
235 | } | ||
236 | public uint Ruint() | ||
237 | { | ||
238 | uint v; | ||
239 | dst = (byte*)&v; | ||
240 | *dst++ = rbuf[ptr++]; | ||
241 | *dst++ = rbuf[ptr++]; | ||
242 | *dst++ = rbuf[ptr++]; | ||
243 | *dst = rbuf[ptr++]; | ||
244 | return v; | ||
245 | } | ||
246 | public long Rlong() | ||
247 | { | ||
248 | long v; | ||
249 | dst = (byte*)&v; | ||
250 | *dst++ = rbuf[ptr++]; | ||
251 | *dst++ = rbuf[ptr++]; | ||
252 | *dst++ = rbuf[ptr++]; | ||
253 | *dst++ = rbuf[ptr++]; | ||
254 | *dst++ = rbuf[ptr++]; | ||
255 | *dst++ = rbuf[ptr++]; | ||
256 | *dst++ = rbuf[ptr++]; | ||
257 | *dst = rbuf[ptr++]; | ||
258 | return v; | ||
259 | } | ||
260 | public ulong Rulong() | ||
261 | { | ||
262 | ulong v; | ||
263 | dst = (byte*)&v; | ||
264 | *dst++ = rbuf[ptr++]; | ||
265 | *dst++ = rbuf[ptr++]; | ||
266 | *dst++ = rbuf[ptr++]; | ||
267 | *dst++ = rbuf[ptr++]; | ||
268 | *dst++ = rbuf[ptr++]; | ||
269 | *dst++ = rbuf[ptr++]; | ||
270 | *dst++ = rbuf[ptr++]; | ||
271 | *dst = rbuf[ptr++]; | ||
272 | return v; | ||
273 | } | ||
274 | public float Rfloat() | ||
275 | { | ||
276 | float v; | ||
277 | dst = (byte*)&v; | ||
278 | *dst++ = rbuf[ptr++]; | ||
279 | *dst++ = rbuf[ptr++]; | ||
280 | *dst++ = rbuf[ptr++]; | ||
281 | *dst = rbuf[ptr++]; | ||
282 | return v; | ||
283 | } | ||
284 | |||
285 | public double Rdouble() | ||
286 | { | ||
287 | double v; | ||
288 | dst = (byte*)&v; | ||
289 | *dst++ = rbuf[ptr++]; | ||
290 | *dst++ = rbuf[ptr++]; | ||
291 | *dst++ = rbuf[ptr++]; | ||
292 | *dst++ = rbuf[ptr++]; | ||
293 | *dst++ = rbuf[ptr++]; | ||
294 | *dst++ = rbuf[ptr++]; | ||
295 | *dst++ = rbuf[ptr++]; | ||
296 | *dst = rbuf[ptr++]; | ||
297 | return v; | ||
298 | } | ||
299 | |||
300 | public Vector3 Rvector3() | ||
301 | { | ||
302 | Vector3 v; | ||
303 | dst = (byte*)&v.X; | ||
304 | *dst++ = rbuf[ptr++]; | ||
305 | *dst++ = rbuf[ptr++]; | ||
306 | *dst++ = rbuf[ptr++]; | ||
307 | *dst = rbuf[ptr++]; | ||
308 | |||
309 | dst = (byte*)&v.Y; | ||
310 | *dst++ = rbuf[ptr++]; | ||
311 | *dst++ = rbuf[ptr++]; | ||
312 | *dst++ = rbuf[ptr++]; | ||
313 | *dst = rbuf[ptr++]; | ||
314 | |||
315 | dst = (byte*)&v.Z; | ||
316 | *dst++ = rbuf[ptr++]; | ||
317 | *dst++ = rbuf[ptr++]; | ||
318 | *dst++ = rbuf[ptr++]; | ||
319 | *dst = rbuf[ptr++]; | ||
320 | return v; | ||
321 | } | ||
322 | |||
323 | public Quaternion Rquat() | ||
324 | { | ||
325 | Quaternion v; | ||
326 | dst = (byte*)&v.X; | ||
327 | *dst++ = rbuf[ptr++]; | ||
328 | *dst++ = rbuf[ptr++]; | ||
329 | *dst++ = rbuf[ptr++]; | ||
330 | *dst = rbuf[ptr++]; | ||
331 | |||
332 | dst = (byte*)&v.Y; | ||
333 | *dst++ = rbuf[ptr++]; | ||
334 | *dst++ = rbuf[ptr++]; | ||
335 | *dst++ = rbuf[ptr++]; | ||
336 | *dst = rbuf[ptr++]; | ||
337 | |||
338 | dst = (byte*)&v.Z; | ||
339 | *dst++ = rbuf[ptr++]; | ||
340 | *dst++ = rbuf[ptr++]; | ||
341 | *dst++ = rbuf[ptr++]; | ||
342 | *dst = rbuf[ptr++]; | ||
343 | |||
344 | dst = (byte*)&v.W; | ||
345 | *dst++ = rbuf[ptr++]; | ||
346 | *dst++ = rbuf[ptr++]; | ||
347 | *dst++ = rbuf[ptr++]; | ||
348 | *dst = rbuf[ptr++]; | ||
349 | |||
350 | return v; | ||
351 | } | ||
352 | } | ||
353 | } | ||