… | |
… | |
17 | #include <sys/socket.h> |
17 | #include <sys/socket.h> |
18 | #include <netinet/in.h> |
18 | #include <netinet/in.h> |
19 | #include <netinet/tcp.h> |
19 | #include <netinet/tcp.h> |
20 | |
20 | |
21 | #include <inttypes.h> |
21 | #include <inttypes.h> |
|
|
22 | |
|
|
23 | #define FOW_DARKNESS 32 |
|
|
24 | |
|
|
25 | #define MAP_EXTEND_X 32 |
|
|
26 | #define MAP_EXTEND_Y 512 |
22 | |
27 | |
23 | static PangoContext *context; |
28 | static PangoContext *context; |
24 | static PangoFontMap *fontmap; |
29 | static PangoFontMap *fontmap; |
25 | |
30 | |
26 | typedef struct cf_layout { |
31 | typedef struct cf_layout { |
… | |
… | |
56 | if (!*w) *w = 1; |
61 | if (!*w) *w = 1; |
57 | if (!*h) *h = 1; |
62 | if (!*h) *h = 1; |
58 | } |
63 | } |
59 | |
64 | |
60 | typedef struct { |
65 | typedef struct { |
|
|
66 | int16_t darkness; |
61 | uint16_t face[3]; |
67 | uint16_t face[3]; |
62 | uint8_t darkness; |
|
|
63 | uint8_t padding; |
|
|
64 | } mapcell; |
68 | } mapcell; |
65 | |
69 | |
66 | typedef struct { |
70 | typedef struct { |
67 | uint32_t cols; |
71 | uint32_t c0, c1; |
68 | mapcell *col; |
72 | mapcell *col; |
69 | } maprow; |
73 | } maprow; |
70 | |
74 | |
71 | typedef struct map { |
75 | typedef struct map { |
72 | int x, y, w, h; |
76 | int x, y, w, h; |
… | |
… | |
74 | GLint *face; |
78 | GLint *face; |
75 | |
79 | |
76 | uint32_t rows; |
80 | uint32_t rows; |
77 | maprow *row; |
81 | maprow *row; |
78 | } *CFClient__Map; |
82 | } *CFClient__Map; |
|
|
83 | |
|
|
84 | static void |
|
|
85 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
|
|
86 | { |
|
|
87 | int x, y; |
|
|
88 | |
|
|
89 | for (y = y0; y < y0 + h; y++) |
|
|
90 | { |
|
|
91 | if (y >= self->rows) |
|
|
92 | break; |
|
|
93 | |
|
|
94 | maprow *row = self->row + y; |
|
|
95 | |
|
|
96 | for (x = x0; x < x0 + w; x++) |
|
|
97 | if (x >= row->c0) |
|
|
98 | { |
|
|
99 | if (x >= row->c1) |
|
|
100 | break; |
|
|
101 | |
|
|
102 | row->col[x].darkness = -1; |
|
|
103 | } |
|
|
104 | } |
|
|
105 | } |
79 | |
106 | |
80 | MODULE = CFClient PACKAGE = CFClient |
107 | MODULE = CFClient PACKAGE = CFClient |
81 | |
108 | |
82 | PROTOTYPES: ENABLE |
109 | PROTOTYPES: ENABLE |
83 | |
110 | |
… | |
… | |
334 | New (0, RETVAL, 1, struct map); |
361 | New (0, RETVAL, 1, struct map); |
335 | RETVAL->x = 0; |
362 | RETVAL->x = 0; |
336 | RETVAL->y = 0; |
363 | RETVAL->y = 0; |
337 | RETVAL->w = map_width; |
364 | RETVAL->w = map_width; |
338 | RETVAL->h = map_height; |
365 | RETVAL->h = map_height; |
339 | RETVAL->faces = 0; |
366 | RETVAL->faces = 1; |
340 | RETVAL->face = 0; |
367 | Newz (0, RETVAL->face, 1, GLint); |
341 | |
|
|
342 | RETVAL->rows = 0; |
368 | RETVAL->rows = 0; |
343 | RETVAL->row = 0; |
369 | RETVAL->row = 0; |
|
|
370 | printf ("new map %d,%d\n", map_width, map_height);//D |
344 | OUTPUT: |
371 | OUTPUT: |
345 | RETVAL |
372 | RETVAL |
346 | |
373 | |
347 | void |
374 | void |
348 | DESTROY (CFClient::Map self) |
375 | DESTROY (CFClient::Map self) |
349 | CODE: |
376 | CODE: |
350 | { |
377 | { |
351 | int r, c; |
378 | int r, c; |
352 | |
379 | |
|
|
380 | printf ("detroy map\n");//D |
353 | Safefree (self->face); |
381 | Safefree (self->face); |
|
|
382 | |
354 | for (r = 0; r < self->rows; r++) |
383 | for (r = 0; r < self->rows; r++) |
355 | { |
|
|
356 | maprow *row = self->row + r; |
|
|
357 | if (!row) |
|
|
358 | continue; |
|
|
359 | |
|
|
360 | Safefree (row->col); |
384 | Safefree (self->row[r].col); |
361 | } |
|
|
362 | |
385 | |
363 | Safefree (self->row); |
386 | Safefree (self->row); |
364 | Safefree (self); |
387 | Safefree (self); |
365 | } |
388 | } |
366 | |
389 | |
|
|
390 | void |
|
|
391 | set_face (CFClient::Map self, int facenum, int face) |
|
|
392 | CODE: |
|
|
393 | { |
|
|
394 | while (self->faces < facenum) |
|
|
395 | { |
|
|
396 | printf ("setface %d (%d) = %d\n",facenum, self->faces, face);//D |
|
|
397 | Renew (self->face, self->faces * 2, GLint); |
|
|
398 | Zero (self->face + self->faces, self->faces, GLint); |
|
|
399 | self->faces *= 2; |
|
|
400 | } |
|
|
401 | |
|
|
402 | self->face [facenum] = face; |
|
|
403 | } |
|
|
404 | |
|
|
405 | void |
|
|
406 | scroll (CFClient::Map self, int dx, int dy) |
|
|
407 | CODE: |
|
|
408 | { |
|
|
409 | printf ("map_scroll %d,%d\n", dx, dy);//D |
|
|
410 | if (dx > 0) |
|
|
411 | map_blank (self, self->x, self->y, dx - 1, self->h); |
|
|
412 | else if (dx < 0) |
|
|
413 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
|
|
414 | |
|
|
415 | if (dy > 0) |
|
|
416 | map_blank (self, self->x, self->y, self->w, dy - 1); |
|
|
417 | else if (dy < 0) |
|
|
418 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
|
|
419 | |
|
|
420 | self->x += dx; |
|
|
421 | self->y += dy; |
|
|
422 | |
|
|
423 | while (self->y < 0) |
|
|
424 | { |
|
|
425 | maprow *row; |
|
|
426 | |
|
|
427 | New (0, row, self->rows + MAP_EXTEND_Y, maprow); |
|
|
428 | Move (self->row, row + MAP_EXTEND_Y, self->rows, maprow); |
|
|
429 | Zero (row, MAP_EXTEND_Y, maprow); |
|
|
430 | |
|
|
431 | self->rows += MAP_EXTEND_Y; |
|
|
432 | self->y += MAP_EXTEND_Y; |
|
|
433 | self->row = row; |
|
|
434 | } |
|
|
435 | |
|
|
436 | if (self->x < 0) |
|
|
437 | { |
|
|
438 | int y; |
|
|
439 | for (y = 0; y < self->rows; y++) |
|
|
440 | { |
|
|
441 | self->row[y].c0 += self->x; |
|
|
442 | self->row[y].c1 += self->x; |
|
|
443 | } |
|
|
444 | |
|
|
445 | self->x = 0; |
|
|
446 | } |
|
|
447 | } |
|
|
448 | |
|
|
449 | void |
|
|
450 | map1a_update (CFClient::Map self, SV *data_) |
|
|
451 | CODE: |
|
|
452 | { |
|
|
453 | uint8_t *data = (uint8_t *)SvPVbytes_nolen (data_); |
|
|
454 | uint8_t *data_end = (uint8_t *)SvEND (data_) + 1; |
|
|
455 | |
|
|
456 | while (data < data_end) |
|
|
457 | { |
|
|
458 | int flags = (data [0] << 8) + data [1]; data += 2; |
|
|
459 | int x = ((flags >> 10) & 63) + self->x; |
|
|
460 | int y = ((flags >> 4) & 63) + self->y; |
|
|
461 | |
|
|
462 | while (y >= self->rows) |
|
|
463 | { |
|
|
464 | Renew (self->row, self->rows + MAP_EXTEND_Y, maprow); |
|
|
465 | Zero (self->row + self->rows, MAP_EXTEND_Y, maprow); |
|
|
466 | |
|
|
467 | self->rows += MAP_EXTEND_Y; |
|
|
468 | } |
|
|
469 | |
|
|
470 | assert (y < self->rows);//D |
|
|
471 | |
|
|
472 | maprow *row = self->row + y; |
|
|
473 | |
|
|
474 | if (!row->col) |
|
|
475 | { |
|
|
476 | Newz (0, row->col, MAP_EXTEND_X, mapcell); |
|
|
477 | row->c0 = self->x - MAP_EXTEND_X / 4; |
|
|
478 | row->c1 = row->c0 + MAP_EXTEND_X; |
|
|
479 | } |
|
|
480 | |
|
|
481 | if (row->c0 > x) |
|
|
482 | { |
|
|
483 | int extend = row->c0 - x + MAP_EXTEND_X; |
|
|
484 | mapcell *col; |
|
|
485 | |
|
|
486 | New (0, col, row->c1 - row->c0 + extend, mapcell); |
|
|
487 | Move (row->col, col + extend, row->c1 - row->c0, mapcell); |
|
|
488 | Zero (col, extend, mapcell); |
|
|
489 | |
|
|
490 | row->col = col; |
|
|
491 | row->c0 -= extend; |
|
|
492 | } |
|
|
493 | else if (x >= row->c1) |
|
|
494 | { |
|
|
495 | int extend = x - row->c1 + MAP_EXTEND_X; |
|
|
496 | |
|
|
497 | Renew (row->col, row->c1 - row->c0 + extend, mapcell); |
|
|
498 | Zero (row->col + row->c1 - row->c0, extend, mapcell); |
|
|
499 | |
|
|
500 | row->c1 += extend; |
|
|
501 | } |
|
|
502 | |
|
|
503 | assert (x >= row->c0);//D |
|
|
504 | assert (x < row->c1);//D |
|
|
505 | mapcell *cell = row->col + (x - row->c0); |
|
|
506 | |
|
|
507 | if (flags & 15) |
|
|
508 | { |
|
|
509 | if (cell->darkness < 0) |
|
|
510 | { |
|
|
511 | cell->darkness = 0; |
|
|
512 | cell->face [0] = 0; |
|
|
513 | cell->face [1] = 0; |
|
|
514 | cell->face [2] = 0; |
|
|
515 | } |
|
|
516 | |
|
|
517 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
518 | |
|
|
519 | if (flags & 4) |
|
|
520 | { |
|
|
521 | cell->face [0] = (data [0] << 8) + data [1]; data += 2; |
|
|
522 | } |
|
|
523 | |
|
|
524 | if (flags & 2) |
|
|
525 | { |
|
|
526 | cell->face [1] = (data [0] << 8) + data [1]; data += 2; |
|
|
527 | } |
|
|
528 | |
|
|
529 | if (flags & 1) |
|
|
530 | { |
|
|
531 | cell->face [2] = (data [0] << 8) + data [1]; data += 2; |
|
|
532 | } |
|
|
533 | } |
|
|
534 | else |
|
|
535 | cell->darkness = -1; |
|
|
536 | } |
|
|
537 | } |
|
|
538 | |