~ubuntu-branches/ubuntu/precise/s3d/precise

« back to all changes in this revision

Viewing changes to server/proto.c

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2009-07-11 17:00:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090711170052-2lltwp4rr01e6oly
* New upstream release
* debian/control:
  - Reduce debhelper dependency to 5
  - Only depend on xmlto and docbook-xml in Build-Depends-Indep for
    arch all package s3d-doc
* debian/patches:
  - Add 100-installable-examples.patch, make example usable without
    extra headers
  - Remove upstream merged patches 100-hyphen-used-as-minus-sign.patch,
    101-fix-sigbus-on-mips.patch, 102-send-correct-load-over-net.patch,
    103-endian-safe-float.patch, 104-reduce-depends.patch,
    105-s3dfm-pathnames.patch, 106-g3dorientation.patch,
    107-fix-cmake-ftbfs.patch, 108-fix-gpsd-ftbfs.patch,
    109-strip-libs3d-parameters.patch, 110-s3dosm-api06.patch,
    111-xmlto-documentation.patch
* Install examples with libs3d-dev and libs3dw-dev
* Convert debian/copyright to new dep5 version
* Upgraded to policy 3.8.2, no changes required
* Install upstream changelogs

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "global.h"
26
26
#include "proto.h"
27
 
/* #include <string.h>  / *  memcpy() * / */
28
27
#include <stdlib.h>  /*  malloc() */
29
28
#include <string.h>  /*  strncpy(),memset() */
 
29
#include <stdint.h>
30
30
#ifdef WIN32
31
31
#include <winsock2.h>
32
32
#else
37
37
int focus_oid = -1;  /*  initially focus the pid */
38
38
/*  handle an incoming command from the client .. */
39
39
 
40
 
 
41
40
int prot_com_in(struct t_process *p, uint8_t *pbuf)
42
41
{
43
42
        uint8_t  command;
61
60
                }
62
61
        }
63
62
        length = ntohs(*((uint16_t *)((uint8_t *)pbuf + 1)));
64
 
        cptr = buf = pbuf + 3;
 
63
        cptr = buf = pbuf + sizeof(int_least32_t);
65
64
        /*  if (mcp_oid==-1) s3dprintf(HIGH,"couldn't find mcp-oid for pid %d!",p->id); */
66
65
        switch (command) {
67
66
        case S3D_P_C_INIT:
115
114
                        oid = ntohl(*((uint32_t *)cptr));
116
115
                        cptr += 4;
117
116
                        num = (length - 4) / (4 * 3);
 
117
                        ntohfb((float *)cptr, num * 3);
118
118
                        /*      s3dprintf(LOW,"received %d new vertices for object oid...%d", num, oid); */
119
119
                        obj_push_vertex(p, oid, (float  *)cptr, num);
120
120
                }
124
124
                        oid = ntohl(*((uint32_t *)cptr));
125
125
                        cptr += 4;
126
126
                        num = (length - 4) / (4 * 12);
 
127
                        ntohfb((float *)cptr, num * 12);
127
128
                        /*      s3dprintf(LOW,"received %d new materials for object oid...%d", num, oid); */
128
129
                        obj_push_mat(p, oid, (float *)cptr, num);
129
130
                }
134
135
                        cptr += 4;
135
136
                        num = (length - 4) / (4 * 4);
136
137
                        /*      s3dprintf(LOW,"received %d new polygons for object oid...%d", num, oid); */
137
 
                        for (i = 0;i < (num*4);i++)
138
 
                                *((uint32_t *)cptr + i) =
139
 
                                        ntohl(*((uint32_t *)cptr + i));
 
138
                        ntohlb((uint32_t *)cptr, num*4);
140
139
                        /*  convert index names */
141
140
                        obj_push_poly(p, oid, (uint32_t *)cptr, num);
142
141
                }
147
146
                        cptr += 4;
148
147
                        num = (length - 4) / (4 * 3);
149
148
                        s3dprintf(VLOW, "received %d new lines for object oid...%d", num, oid);
150
 
                        for (i = 0;i < (num*3);i++)
151
 
                                *((uint32_t *)cptr + i) =
152
 
                                        ntohl(*((uint32_t *)cptr + i));
 
149
                        ntohlb((uint32_t *)cptr, num*3);
153
150
                        /*  convert index names */
154
151
                        obj_push_line(p, oid, (uint32_t *)cptr, num);
155
152
                }
160
157
                        cptr += 4;
161
158
                        num = (length - 4) / (2 * 2);
162
159
                        s3dprintf(LOW, "received %d new textures for object oid...%d", num, oid);
163
 
                        for (i = 0;i < (num*2);i++)
164
 
                                *((uint16_t *)cptr + i) =
165
 
                                        ntohs(*((uint16_t *)cptr + i));
 
160
                        ntohsb((uint16_t *)cptr , num*2);
166
161
                        /*  convert index names */
167
162
                        obj_push_tex(p, oid, (uint16_t *)cptr, num);
168
163
                }
172
167
                        oid = ntohl(*((uint32_t *)cptr));
173
168
                        cptr += 4;
174
169
                        num = (length - 4) / (9 * 4);
 
170
                        ntohfb((float *)cptr, num * 9);
175
171
                        s3dprintf(VLOW, "PEP_POLY_NORMAL[%d]: oid %d, %f polys", length, oid, (length - 4) / (9.0*4.0));
176
172
                        obj_pep_poly_normal(p, oid, (float *)cptr, num);
177
173
                }
181
177
                        oid = ntohl(*((uint32_t *)cptr));
182
178
                        cptr += 4;
183
179
                        num = (length - 4) / (6 * 4);
 
180
                        ntohfb((float *)cptr, num * 6);
184
181
                        s3dprintf(VLOW, "PEP_LINE_NORMAL[%d]: oid %d, %.1f lines", length, oid, (length - 4) / (6.0*4.0));
185
182
                        obj_pep_line_normal(p, oid, (float *)cptr, num);
186
183
                }
190
187
                        oid = ntohl(*((uint32_t *)cptr));
191
188
                        cptr += 4;
192
189
                        num = (length - 4) / (6 * 4);
 
190
                        ntohfb((float *)cptr, num * 6);
193
191
                        s3dprintf(VLOW, "PEP_POLY_TEXC[%d]: oid %d, %f polys", length, oid, (length - 4) / (6.0*4.0));
194
192
                        obj_pep_poly_texc(p, oid, (float *)cptr, num);
195
193
                }
199
197
                        oid = ntohl(*((uint32_t *)cptr));
200
198
                        cptr += 4;
201
199
                        num = (length - 4) / (4 * 12);
 
200
                        ntohfb((float *)cptr, num * 12);
202
201
                        s3dprintf(VLOW, "PEP_MAT[%d]: %d materials for object oid...%d", length, num, oid);
203
202
                        obj_pep_mat(p, oid, (float *)cptr, num);
204
203
                }
208
207
                        oid = ntohl(*((uint32_t *)cptr));
209
208
                        cptr += 4;
210
209
                        num = (length - 4) / (4 * 3);
 
210
                        ntohfb((float *)cptr, num * 3);
211
211
                        s3dprintf(VLOW, "pepping %d new vertices for object oid...%d", num, oid);
212
212
                        obj_pep_vertex(p, oid, (float  *)cptr, num);
213
213
                }
219
219
                        cptr += 4;
220
220
                        num = (length - 4) / (4);
221
221
                        s3dprintf(VLOW, "PEP_MAT_TEX[%d]: %d materials for object oid...%d", length, num, oid);
222
 
                        for (i = 0;i < num;i++)
223
 
                                *((uint32_t *)cptr + i) =
224
 
                                        ntohl(*((uint32_t *)cptr + i));
 
222
                        ntohlb((uint32_t *)cptr, num);
225
223
                        obj_pep_mat_tex(p, oid, (uint32_t *)cptr, num);
226
224
                }
227
225
                break;
231
229
                        cptr += 4;
232
230
                        num = (length - 4) / (4 * 3);
233
231
                        s3dprintf(VLOW, "pepping %d new lines for object oid...%d", num, oid);
234
 
                        for (i = 0;i < (num*3);i++)
235
 
                                *((uint32_t *)cptr + i) =
236
 
                                        ntohl(*((uint32_t *)cptr + i));
 
232
                        ntohlb((uint32_t *)cptr, num*3);
237
233
                        obj_pep_line(p, oid, (uint32_t *)cptr, num);
238
234
                }
239
235
                break;
244
240
                        toid = ntohl(*((uint32_t *)cptr));
245
241
                        cptr += 4;
246
242
                        num = (length - 8) / (6 * 4);
 
243
                        ntohfb((float *)cptr, num * 6);
247
244
                        s3dprintf(VLOW, "LOAD_POLY_NORMAL[%d]: oid %d, %.2f lines", length, oid, (length - 8) / (6.0*4.0));
248
245
                        obj_load_line_normal(p, oid, (float *)cptr, toid, num);
249
246
                }
255
252
                        toid = ntohl(*((uint32_t *)cptr));
256
253
                        cptr += 4;
257
254
                        num = (length - 8) / (9 * 4);
 
255
                        ntohfb((float *)cptr, num * 9);
258
256
                        s3dprintf(MED, "LOAD_POLY_NORMAL[%d]: oid %d, %f polys", length, oid, (length - 8) / (9.0*4.0));
259
257
                        obj_load_poly_normal(p, oid, (float *)cptr, toid, num);
260
258
                }
266
264
                        toid = ntohl(*((uint32_t *)cptr));
267
265
                        cptr += 4;
268
266
                        num = (length - 8) / (6 * 4);
 
267
                        ntohfb((float *)cptr, num * 6);
269
268
                        s3dprintf(MED, "LOAD_POLY_TEXC[%d]: oid %d, %f polys", length, oid, (length - 8) / (6.0*4.0));
270
269
                        obj_load_poly_texc(p, oid, (float *)cptr, toid, num);
271
270
                }
277
276
                        toid = ntohl(*((uint32_t *)cptr));
278
277
                        cptr += 4;
279
278
                        num = (length - 8) / (4 * 12);
 
279
                        ntohfb((float *)cptr, num * 12);
280
280
                        s3dprintf(LOW, "LOAD_MAT[%d]: %d materials for object oid...%d", length, num, oid);
281
281
                        obj_load_mat(p, oid, (float *)cptr, toid, num);
282
282
                }
304
304
        case S3D_P_C_UPDATE_TEX:
305
305
                if (length == 16) {
306
306
                        oid = ntohl(*((uint32_t *)cptr));
307
 
                        cptr += 4;
 
307
                        cptr += sizeof(uint32_t);
308
308
                        toid = ntohl(*((uint32_t *)cptr));
309
 
                        cptr += 4;
 
309
                        cptr += sizeof(uint32_t);
310
310
                        x = ntohs(*((uint16_t *)cptr));
311
 
                        cptr += 2;
 
311
                        cptr += sizeof(uint16_t);
312
312
                        y = ntohs(*((uint16_t *)cptr));
313
 
                        cptr += 2;
 
313
                        cptr += sizeof(uint16_t);
314
314
                        w = ntohs(*((uint16_t *)cptr));
315
 
                        cptr += 2;
 
315
                        cptr += sizeof(uint16_t);
316
316
                        h = ntohs(*((uint16_t *)cptr));
317
 
                        cptr += 2;
 
317
 
318
318
                        s3dprintf(VLOW, "UPDATE_TEX[%d]: oid %d, texture %d, [%d x %d] data at [%d x %d] ", length, oid, toid, w, h, x, y);
319
319
                        obj_update_tex(p, oid, toid, x, y, w, h, NULL);
320
320
                }
323
323
        case S3D_P_C_DEL_VERTEX:
324
324
                if (length == 8) {
325
325
                        oid = ntohl(*((uint32_t *)cptr));
326
 
                        cptr += 4;
 
326
                        cptr += sizeof(uint32_t);
327
327
                        num = ntohl(*((uint32_t *)cptr));
328
 
                        cptr += 4;
 
328
 
329
329
                        /*      s3dprintf(LOW,"deleting %d vertices for object oid...%d", num, oid); */
330
330
                        obj_del_vertex(p, oid, num);
331
331
                }
333
333
        case S3D_P_C_DEL_POLY:
334
334
                if (length == 8) {
335
335
                        oid = ntohl(*((uint32_t *)cptr));
336
 
                        cptr += 4;
 
336
                        cptr += sizeof(uint32_t);
337
337
                        num = ntohl(*((uint32_t *)cptr));
338
 
                        cptr += 4;
 
338
 
339
339
                        /*      s3dprintf(LOW,"deleting %d vertices for object oid...%d", num, oid); */
340
340
                        obj_del_poly(p, oid, num);
341
341
                }
343
343
        case S3D_P_C_DEL_LINE:
344
344
                if (length == 8) {
345
345
                        oid = ntohl(*((uint32_t *)cptr));
346
 
                        cptr += 4;
 
346
                        cptr += sizeof(uint32_t);
347
347
                        num = ntohl(*((uint32_t *)cptr));
348
 
                        cptr += 4;
 
348
 
349
349
                        s3dprintf(VLOW, "deleting %d lines for object oid...%d", num, oid);
350
350
                        obj_del_line(p, oid, num);
351
351
                }
354
354
        case S3D_P_C_DEL_MAT:
355
355
                if (length == 8) {
356
356
                        oid = ntohl(*((uint32_t *)cptr));
357
 
                        cptr += 4;
 
357
                        cptr += sizeof(uint32_t);
358
358
                        num = ntohl(*((uint32_t *)cptr));
359
 
                        cptr += 4;
 
359
 
360
360
                        /*      s3dprintf(LOW,"deleting %d materials for object oid...%d", num, oid); */
361
361
                        obj_del_mat(p, oid, num);
362
362
                }
364
364
        case S3D_P_C_DEL_TEX:
365
365
                if (length == 8) {
366
366
                        oid = ntohl(*((uint32_t *)cptr));
367
 
                        cptr += 4;
 
367
                        cptr += sizeof(uint32_t);
368
368
                        num = ntohl(*((uint32_t *)cptr));
369
 
                        cptr += 4;
 
369
 
370
370
                        /*      s3dprintf(LOW,"deleting %d textures for object oid...%d", num, oid); */
371
371
                        obj_del_tex(p, oid, num);
372
372
                }
374
374
        case S3D_P_C_TOGGLE_FLAGS:
375
375
                if (length == 9) {
376
376
                        oid = ntohl(*((uint32_t *)cptr));
377
 
                        cptr += 4;
 
377
                        cptr += sizeof(uint32_t);;
378
378
                        type = *cptr;
379
 
                        cptr += 1;
 
379
                        cptr += sizeof(unsigned char);
380
380
                        flags = ntohl(*((uint32_t *)cptr));
381
 
                        cptr += 4;
 
381
 
382
382
                        obj_toggle_flags(p, oid, type, flags);
383
383
                }
384
384
                break;
385
385
        case S3D_P_C_TRANSLATE:
386
386
                if (length >= 16) {
387
387
                        oid = ntohl(*((uint32_t *)cptr));
388
 
                        cptr += 4;
 
388
                        cptr += sizeof(uint32_t);
 
389
                        ntohfb((float *)cptr, 3);
389
390
                        obj_translate(p, oid, (float *)cptr);
390
391
                }
391
392
                break;
393
394
                if (length >= 16) {
394
395
                        oid = ntohl(*((uint32_t *)cptr));
395
396
                        cptr += 4;
 
397
                        ntohfb((float *)cptr, 3);
396
398
                        obj_rotate(p, oid, (float *)cptr);
397
399
                }
398
400
                break;
400
402
                if (length >= 8) {
401
403
                        oid = ntohl(*((uint32_t *)cptr));
402
404
                        cptr += 4;
 
405
                        ntohfb((float *)cptr, 3);
403
406
                        obj_scale(p, oid, *((float *)cptr));
404
407
                }
405
408
                break;