|
|
1 | #ifdef _WIN32 |
|
|
2 | # include <malloc.h> |
|
|
3 | #endif |
|
|
4 | |
1 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
2 | #include "perl.h" |
6 | #include "perl.h" |
3 | #include "XSUB.h" |
7 | #include "XSUB.h" |
4 | |
8 | |
5 | #include <string.h> |
9 | #include <string.h> |
… | |
… | |
13 | |
17 | |
14 | #include <pango/pango.h> |
18 | #include <pango/pango.h> |
15 | #include <pango/pangofc-fontmap.h> |
19 | #include <pango/pangofc-fontmap.h> |
16 | #include <pango/pangoft2.h> |
20 | #include <pango/pangoft2.h> |
17 | |
21 | |
|
|
22 | #ifndef _WIN32 |
18 | #include <sys/types.h> |
23 | # include <sys/types.h> |
19 | #include <sys/socket.h> |
24 | # include <sys/socket.h> |
20 | #include <netinet/in.h> |
25 | # include <netinet/in.h> |
21 | #include <netinet/tcp.h> |
26 | # include <netinet/tcp.h> |
22 | |
|
|
23 | #include <inttypes.h> |
27 | # include <inttypes.h> |
|
|
28 | #else |
|
|
29 | typedef unsigned char uint8_t; |
|
|
30 | typedef unsigned short uint16_t; |
|
|
31 | typedef unsigned int uint32_t; |
|
|
32 | typedef signed char int8_t; |
|
|
33 | typedef signed short int16_t; |
|
|
34 | typedef signed int int32_t; |
|
|
35 | #endif |
24 | |
36 | |
25 | #define FOW_DARKNESS 32 |
37 | #define FOW_DARKNESS 32 |
26 | |
38 | |
27 | #define MAP_EXTEND_X 32 |
39 | #define MAP_EXTEND_X 32 |
28 | #define MAP_EXTEND_Y 512 |
40 | #define MAP_EXTEND_Y 512 |
… | |
… | |
47 | { |
59 | { |
48 | /* use a random scale factor to account for unknown descenders, 0.8 works |
60 | /* use a random scale factor to account for unknown descenders, 0.8 works |
49 | * reasonably well with bitstream vera |
61 | * reasonably well with bitstream vera |
50 | */ |
62 | */ |
51 | PangoFontDescription *font = pango_context_get_font_description (context); |
63 | PangoFontDescription *font = pango_context_get_font_description (context); |
52 | pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10)); |
64 | |
|
|
65 | int height = self->base_height * (PANGO_SCALE * 8 / 10); |
|
|
66 | |
|
|
67 | if (pango_font_description_get_size (font) != height) |
|
|
68 | { |
|
|
69 | pango_font_description_set_absolute_size (font, height); |
|
|
70 | pango_layout_context_changed (self->pl); |
|
|
71 | } |
53 | } |
72 | } |
54 | |
73 | |
55 | static void |
74 | static void |
56 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
75 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
57 | { |
76 | { |
… | |
… | |
90 | mapface *face; |
109 | mapface *face; |
91 | |
110 | |
92 | int texs; |
111 | int texs; |
93 | maptex *tex; |
112 | maptex *tex; |
94 | |
113 | |
95 | uint32_t rows; |
114 | int32_t rows; |
96 | maprow *row; |
115 | maprow *row; |
97 | } *CFClient__Map; |
116 | } *CFClient__Map; |
98 | |
117 | |
99 | static char * |
118 | static char * |
100 | prepend (char *ptr, int sze, int inc) |
119 | prepend (char *ptr, int sze, int inc) |
… | |
… | |
195 | |
214 | |
196 | static void |
215 | static void |
197 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
216 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
198 | { |
217 | { |
199 | int x, y; |
218 | int x, y; |
|
|
219 | maprow *row; |
200 | |
220 | |
201 | for (y = y0; y < y0 + h; y++) |
221 | for (y = y0; y < y0 + h; y++) |
202 | if (y >= 0) |
222 | if (y >= 0) |
203 | { |
223 | { |
204 | if (y >= self->rows) |
224 | if (y >= self->rows) |
205 | break; |
225 | break; |
206 | |
226 | |
207 | maprow *row = self->row + y; |
227 | row = self->row + y; |
208 | |
228 | |
209 | for (x = x0; x < x0 + w; x++) |
229 | for (x = x0; x < x0 + w; x++) |
210 | if (x >= row->c0) |
230 | if (x >= row->c0) |
211 | { |
231 | { |
212 | if (x >= row->c1) |
232 | if (x >= row->c1) |
… | |
… | |
229 | } |
249 | } |
230 | |
250 | |
231 | void |
251 | void |
232 | lowdelay (int fd, int val = 1) |
252 | lowdelay (int fd, int val = 1) |
233 | CODE: |
253 | CODE: |
|
|
254 | #ifndef _WIN32 |
234 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
255 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
|
|
256 | #endif |
235 | |
257 | |
236 | char * |
258 | char * |
237 | gl_version () |
259 | gl_version () |
238 | CODE: |
260 | CODE: |
239 | RETVAL = (char *)glGetString (GL_VERSION); |
261 | RETVAL = (char *)glGetString (GL_VERSION); |
… | |
… | |
391 | char *text = SvPVutf8 (text_, textlen); |
413 | char *text = SvPVutf8 (text_, textlen); |
392 | |
414 | |
393 | pango_layout_set_markup (self->pl, text, textlen); |
415 | pango_layout_set_markup (self->pl, text, textlen); |
394 | } |
416 | } |
395 | |
417 | |
|
|
418 | SV * |
|
|
419 | get_text (CFClient::Layout self) |
|
|
420 | CODE: |
|
|
421 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
|
|
422 | SvUTF8_on (RETVAL); |
|
|
423 | OUTPUT: |
|
|
424 | RETVAL |
|
|
425 | |
396 | void |
426 | void |
397 | set_height (CFClient::Layout self, int base_height) |
427 | set_height (CFClient::Layout self, int base_height) |
398 | CODE: |
428 | CODE: |
399 | self->base_height = base_height; |
429 | self->base_height = base_height; |
400 | |
430 | |
… | |
… | |
565 | { |
595 | { |
566 | Append (maptex, self->tex, self->texs, self->texs); |
596 | Append (maptex, self->tex, self->texs, self->texs); |
567 | self->texs *= 2; |
597 | self->texs *= 2; |
568 | } |
598 | } |
569 | |
599 | |
|
|
600 | { |
570 | maptex *tex = self->tex + texid; |
601 | maptex *tex = self->tex + texid; |
571 | |
602 | |
572 | tex->name = name; |
603 | tex->name = name; |
573 | tex->w = w; |
604 | tex->w = w; |
574 | tex->h = h; |
605 | tex->h = h; |
575 | tex->s = s; |
606 | tex->s = s; |
576 | tex->t = t; |
607 | tex->t = t; |
577 | tex->r = r; |
608 | tex->r = r; |
578 | tex->g = g; |
609 | tex->g = g; |
579 | tex->b = b; |
610 | tex->b = b; |
580 | tex->a = a; |
611 | tex->a = a; |
|
|
612 | } |
581 | } |
613 | } |
582 | |
614 | |
583 | int |
615 | int |
584 | ox (CFClient::Map self) |
616 | ox (CFClient::Map self) |
585 | ALIAS: |
617 | ALIAS: |
… | |
… | |
623 | map1a_update (CFClient::Map self, SV *data_) |
655 | map1a_update (CFClient::Map self, SV *data_) |
624 | CODE: |
656 | CODE: |
625 | { |
657 | { |
626 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
658 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
627 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
659 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
|
|
660 | mapcell *cell; |
|
|
661 | int x, y, flags; |
628 | |
662 | |
629 | while (data < data_end) |
663 | while (data < data_end) |
630 | { |
664 | { |
631 | int flags = (data [0] << 8) + data [1]; data += 2; |
665 | flags = (data [0] << 8) + data [1]; data += 2; |
632 | |
666 | |
633 | int x = ((flags >> 10) & 63) + self->x; |
667 | x = ((flags >> 10) & 63) + self->x; |
634 | int y = ((flags >> 4) & 63) + self->y; |
668 | y = ((flags >> 4) & 63) + self->y; |
635 | |
669 | |
636 | mapcell *cell = map_get_cell (self, x, y); |
670 | cell = map_get_cell (self, x, y); |
637 | |
671 | |
638 | if (flags & 15) |
672 | if (flags & 15) |
639 | { |
673 | { |
640 | if (cell->darkness < 0) // && x < self->w && y < self->h) |
674 | if (cell->darkness < 0) |
641 | { |
675 | { |
642 | cell->darkness = 0; |
676 | cell->darkness = 0; |
643 | cell->face [0] = 0; |
677 | cell->face [0] = 0; |
644 | cell->face [1] = 0; |
678 | cell->face [1] = 0; |
645 | cell->face [2] = 0; |
679 | cell->face [2] = 0; |
646 | } |
680 | } |
647 | |
681 | |
648 | cell->darkness = flags & 8 ? *data++ : 255; |
682 | cell->darkness = flags & 8 ? *data++ : 255; |
649 | |
683 | |
650 | //TODO: don't trust server data to be in-range(!) |
684 | //TODO: don't trust server data to be in-range(!) |
651 | |
685 | |
652 | if (flags & 4) |
686 | if (flags & 4) |
… | |
… | |
731 | |
765 | |
732 | void |
766 | void |
733 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
767 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
734 | PPCODE: |
768 | PPCODE: |
735 | { |
769 | { |
|
|
770 | int vx, vy; |
|
|
771 | int x, y, z; |
|
|
772 | int last_name; |
|
|
773 | mapface face; |
736 | int sw4 = (sw + 3) & ~3; |
774 | int sw4 = (sw + 3) & ~3; |
737 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
775 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
738 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
776 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
777 | |
739 | memset (darkness, 255, sw4 * sh); |
778 | memset (darkness, 255, sw4 * sh); |
740 | SvPOK_only (darkness_sv); |
779 | SvPOK_only (darkness_sv); |
741 | SvCUR_set (darkness_sv, sw4 * sh); |
780 | SvCUR_set (darkness_sv, sw4 * sh); |
742 | |
781 | |
743 | int vx = self->x + (self->w - sw) / 2 - shift_x; |
782 | vx = self->x + (self->w - sw) / 2 - shift_x; |
744 | int vy = self->y + (self->h - sh) / 2 - shift_y; |
783 | vy = self->y + (self->h - sh) / 2 - shift_y; |
745 | |
784 | |
746 | /* |
785 | /* |
747 | int vx = self->vx = self->w >= sw |
786 | int vx = self->vx = self->w >= sw |
748 | ? self->x + (self->w - sw) / 2 |
787 | ? self->x + (self->w - sw) / 2 |
749 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
788 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
… | |
… | |
758 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
797 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
759 | glEnable (GL_BLEND); |
798 | glEnable (GL_BLEND); |
760 | glEnable (GL_TEXTURE_2D); |
799 | glEnable (GL_TEXTURE_2D); |
761 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
800 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
762 | |
801 | |
763 | int x, y, z; |
|
|
764 | |
|
|
765 | int last_name = 0; |
|
|
766 | |
|
|
767 | glBegin (GL_QUADS); |
802 | glBegin (GL_QUADS); |
|
|
803 | |
|
|
804 | last_name = 0; |
768 | |
805 | |
769 | for (z = 0; z < 3; z++) |
806 | for (z = 0; z < 3; z++) |
770 | for (y = 0; y < sh; y++) |
807 | for (y = 0; y < sh; y++) |
771 | if (0 <= y + vy && y + vy < self->rows) |
808 | if (0 <= y + vy && y + vy < self->rows) |
772 | { |
809 | { |
… | |
… | |
779 | |
816 | |
780 | darkness[y * sw4 + x] = cell->darkness < 0 |
817 | darkness[y * sw4 + x] = cell->darkness < 0 |
781 | ? 255 - FOW_DARKNESS |
818 | ? 255 - FOW_DARKNESS |
782 | : 255 - cell->darkness; |
819 | : 255 - cell->darkness; |
783 | |
820 | |
784 | mapface face = cell->face [z]; |
821 | face = cell->face [z]; |
785 | |
822 | |
786 | if (face) |
823 | if (face) |
787 | { |
824 | { |
788 | maptex tex = self->tex [face]; |
825 | maptex tex = self->tex [face]; |
789 | |
826 | |
… | |
… | |
849 | for (x = x0; x < x1; x++) |
886 | for (x = x0; x < x1; x++) |
850 | { |
887 | { |
851 | if (row && row->c0 <= x && x < row->c1) |
888 | if (row && row->c0 <= x && x < row->c1) |
852 | { |
889 | { |
853 | mapcell *cell = row->col + (x - row->c0); |
890 | mapcell *cell = row->col + (x - row->c0); |
854 | |
|
|
855 | uint8_t flags = 0; |
891 | uint8_t flags = 0; |
856 | |
892 | |
857 | if (cell->face [0]) flags |= 1; |
893 | if (cell->face [0]) flags |= 1; |
858 | if (cell->face [1]) flags |= 2; |
894 | if (cell->face [1]) flags |= 2; |
859 | if (cell->face [2]) flags |= 4; |
895 | if (cell->face [2]) flags |= 4; |
… | |
… | |
893 | void |
929 | void |
894 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
930 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
895 | PPCODE: |
931 | PPCODE: |
896 | { |
932 | { |
897 | int x, y, z; |
933 | int x, y, z; |
|
|
934 | int w, h; |
898 | int x1, y1; |
935 | int x1, y1; |
899 | |
936 | |
900 | if (*data++ != 0) |
937 | if (*data++ != 0) |
901 | return; /* version mismatch */ |
938 | return; /* version mismatch */ |
902 | |
939 | |
903 | int w = *data++ << 8; w |= *data++; |
940 | w = *data++ << 8; w |= *data++; |
904 | int h = *data++ << 8; h |= *data++; |
941 | h = *data++ << 8; h |= *data++; |
905 | |
942 | |
906 | // we need to do this 'cause we don't keep an absolute coord system for rows |
943 | // we need to do this 'cause we don't keep an absolute coord system for rows |
907 | // TODO: treat rows as we treat |
944 | // TODO: treat rows as we treat |
908 | map_get_row (self, y0 + self->y - self->oy);//D |
945 | map_get_row (self, y0 + self->y - self->oy);//D |
909 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
946 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |