|
|
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 | { |
… | |
… | |
83 | mapcell *col; |
102 | mapcell *col; |
84 | } maprow; |
103 | } maprow; |
85 | |
104 | |
86 | typedef struct map { |
105 | typedef struct map { |
87 | int x, y, w, h; |
106 | int x, y, w, h; |
88 | int dx, dy; /* delayed map scrolling */ |
|
|
89 | int ox, oy; /* offset to virtual global coordinate system */ |
107 | int ox, oy; /* offset to virtual global coordinate system */ |
90 | int faces; |
108 | int faces; |
91 | mapface *face; |
109 | mapface *face; |
92 | |
110 | |
93 | int texs; |
111 | int texs; |
94 | maptex *tex; |
112 | maptex *tex; |
95 | |
113 | |
96 | uint32_t rows; |
114 | int32_t rows; |
97 | maprow *row; |
115 | maprow *row; |
98 | } *CFClient__Map; |
116 | } *CFClient__Map; |
99 | |
117 | |
100 | static char * |
118 | static char * |
101 | prepend (char *ptr, int sze, int inc) |
119 | prepend (char *ptr, int sze, int inc) |
… | |
… | |
196 | |
214 | |
197 | static void |
215 | static void |
198 | 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) |
199 | { |
217 | { |
200 | int x, y; |
218 | int x, y; |
|
|
219 | maprow *row; |
201 | |
220 | |
202 | for (y = y0; y < y0 + h; y++) |
221 | for (y = y0; y < y0 + h; y++) |
203 | if (y >= 0) |
222 | if (y >= 0) |
204 | { |
223 | { |
205 | if (y >= self->rows) |
224 | if (y >= self->rows) |
206 | break; |
225 | break; |
207 | |
226 | |
208 | maprow *row = self->row + y; |
227 | row = self->row + y; |
209 | |
228 | |
210 | for (x = x0; x < x0 + w; x++) |
229 | for (x = x0; x < x0 + w; x++) |
211 | if (x >= row->c0) |
230 | if (x >= row->c0) |
212 | { |
231 | { |
213 | if (x >= row->c1) |
232 | if (x >= row->c1) |
… | |
… | |
230 | } |
249 | } |
231 | |
250 | |
232 | void |
251 | void |
233 | lowdelay (int fd, int val = 1) |
252 | lowdelay (int fd, int val = 1) |
234 | CODE: |
253 | CODE: |
|
|
254 | #ifndef _WIN32 |
235 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
255 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
|
|
256 | #endif |
236 | |
257 | |
237 | char * |
258 | char * |
238 | gl_version () |
259 | gl_version () |
239 | CODE: |
260 | CODE: |
240 | RETVAL = (char *)glGetString (GL_VERSION); |
261 | RETVAL = (char *)glGetString (GL_VERSION); |
… | |
… | |
286 | croak ("load_image: %s", SDL_GetError ()); |
307 | croak ("load_image: %s", SDL_GetError ()); |
287 | |
308 | |
288 | fmt.palette = NULL; |
309 | fmt.palette = NULL; |
289 | fmt.BitsPerPixel = 32; |
310 | fmt.BitsPerPixel = 32; |
290 | fmt.BytesPerPixel = 4; |
311 | fmt.BytesPerPixel = 4; |
|
|
312 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
291 | fmt.Rmask = 0x000000ff; |
313 | fmt.Rmask = 0x000000ff; |
292 | fmt.Gmask = 0x0000ff00; |
314 | fmt.Gmask = 0x0000ff00; |
293 | fmt.Bmask = 0x00ff0000; |
315 | fmt.Bmask = 0x00ff0000; |
294 | fmt.Amask = 0xff000000; |
316 | fmt.Amask = 0xff000000; |
|
|
317 | #else |
|
|
318 | fmt.Rmask = 0xff000000; |
|
|
319 | fmt.Gmask = 0x00ff0000; |
|
|
320 | fmt.Bmask = 0x0000ff00; |
|
|
321 | fmt.Amask = 0x000000ff; |
|
|
322 | #endif |
295 | fmt.Rloss = 0; |
323 | fmt.Rloss = 0; |
296 | fmt.Gloss = 0; |
324 | fmt.Gloss = 0; |
297 | fmt.Bloss = 0; |
325 | fmt.Bloss = 0; |
298 | fmt.Aloss = 0; |
326 | fmt.Aloss = 0; |
299 | fmt.Rshift = 0; |
327 | fmt.Rshift = 0; |
… | |
… | |
313 | SDL_LockSurface (surface2); |
341 | SDL_LockSurface (surface2); |
314 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
342 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
315 | SDL_UnlockSurface (surface2); |
343 | SDL_UnlockSurface (surface2); |
316 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
344 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
317 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
345 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
318 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); |
346 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
319 | |
347 | |
320 | SDL_FreeSurface (surface); |
348 | SDL_FreeSurface (surface); |
321 | SDL_FreeSurface (surface2); |
349 | SDL_FreeSurface (surface2); |
322 | } |
350 | } |
323 | |
351 | |
… | |
… | |
391 | STRLEN textlen; |
419 | STRLEN textlen; |
392 | char *text = SvPVutf8 (text_, textlen); |
420 | char *text = SvPVutf8 (text_, textlen); |
393 | |
421 | |
394 | pango_layout_set_markup (self->pl, text, textlen); |
422 | pango_layout_set_markup (self->pl, text, textlen); |
395 | } |
423 | } |
|
|
424 | |
|
|
425 | SV * |
|
|
426 | get_text (CFClient::Layout self) |
|
|
427 | CODE: |
|
|
428 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
|
|
429 | SvUTF8_on (RETVAL); |
|
|
430 | OUTPUT: |
|
|
431 | RETVAL |
396 | |
432 | |
397 | void |
433 | void |
398 | set_height (CFClient::Layout self, int base_height) |
434 | set_height (CFClient::Layout self, int base_height) |
399 | CODE: |
435 | CODE: |
400 | self->base_height = base_height; |
436 | self->base_height = base_height; |
… | |
… | |
566 | { |
602 | { |
567 | Append (maptex, self->tex, self->texs, self->texs); |
603 | Append (maptex, self->tex, self->texs, self->texs); |
568 | self->texs *= 2; |
604 | self->texs *= 2; |
569 | } |
605 | } |
570 | |
606 | |
|
|
607 | { |
571 | maptex *tex = self->tex + texid; |
608 | maptex *tex = self->tex + texid; |
572 | |
609 | |
573 | tex->name = name; |
610 | tex->name = name; |
574 | tex->w = w; |
611 | tex->w = w; |
575 | tex->h = h; |
612 | tex->h = h; |
576 | tex->s = s; |
613 | tex->s = s; |
577 | tex->t = t; |
614 | tex->t = t; |
578 | tex->r = r; |
615 | tex->r = r; |
579 | tex->g = g; |
616 | tex->g = g; |
580 | tex->b = b; |
617 | tex->b = b; |
581 | tex->a = a; |
618 | tex->a = a; |
|
|
619 | } |
582 | } |
620 | } |
583 | |
621 | |
584 | int |
622 | int |
585 | ox (CFClient::Map self) |
623 | ox (CFClient::Map self) |
586 | ALIAS: |
624 | ALIAS: |
… | |
… | |
596 | |
634 | |
597 | void |
635 | void |
598 | scroll (CFClient::Map self, int dx, int dy) |
636 | scroll (CFClient::Map self, int dx, int dy) |
599 | CODE: |
637 | CODE: |
600 | { |
638 | { |
601 | self->dx += dx; self->ox += dx; |
|
|
602 | self->dy += dy; self->oy += dy; |
|
|
603 | } |
|
|
604 | |
|
|
605 | void |
|
|
606 | map1a_update (CFClient::Map self, SV *data_) |
|
|
607 | CODE: |
|
|
608 | { |
|
|
609 | if (self->dx > 0) |
639 | if (dx > 0) |
610 | map_blank (self, self->x, self->y, self->dx - 1, self->h); |
640 | map_blank (self, self->x, self->y, dx - 1, self->h); |
611 | else if (self->dx < 0) |
641 | else if (dx < 0) |
612 | map_blank (self, self->x + self->w + self->dx + 1, self->y, 1 - self->dx, self->h); |
642 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
613 | |
643 | |
614 | if (self->dy > 0) |
644 | if (dy > 0) |
615 | map_blank (self, self->x, self->y, self->w, self->dy - 1); |
645 | map_blank (self, self->x, self->y, self->w, dy - 1); |
616 | else if (self->dy < 0) |
646 | else if (dy < 0) |
617 | map_blank (self, self->x, self->y + self->h + self->dy + 1, self->w, 1 - self->dy); |
647 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
618 | |
648 | |
619 | self->x += self->dx; self->dx = 0; |
649 | self->ox += dx; self->x += dx; |
620 | self->y += self->dy; self->dy = 0; |
650 | self->oy += dy; self->y += dy; |
621 | |
651 | |
622 | while (self->y < 0) |
652 | while (self->y < 0) |
623 | { |
653 | { |
624 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
654 | Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); |
625 | |
655 | |
626 | self->rows += MAP_EXTEND_Y; |
656 | self->rows += MAP_EXTEND_Y; |
627 | self->y += MAP_EXTEND_Y; |
657 | self->y += MAP_EXTEND_Y; |
628 | } |
658 | } |
|
|
659 | } |
629 | |
660 | |
|
|
661 | void |
|
|
662 | map1a_update (CFClient::Map self, SV *data_) |
|
|
663 | CODE: |
|
|
664 | { |
630 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
665 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
631 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
666 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
|
|
667 | mapcell *cell; |
|
|
668 | int x, y, flags; |
632 | |
669 | |
633 | while (data < data_end) |
670 | while (data < data_end) |
634 | { |
671 | { |
635 | int flags = (data [0] << 8) + data [1]; data += 2; |
672 | flags = (data [0] << 8) + data [1]; data += 2; |
636 | |
673 | |
637 | int x = ((flags >> 10) & 63) + self->x; |
674 | x = ((flags >> 10) & 63) + self->x; |
638 | int y = ((flags >> 4) & 63) + self->y; |
675 | y = ((flags >> 4) & 63) + self->y; |
639 | |
676 | |
640 | mapcell *cell = map_get_cell (self, x, y); |
677 | cell = map_get_cell (self, x, y); |
641 | |
678 | |
642 | if (flags & 15) |
679 | if (flags & 15) |
643 | { |
680 | { |
644 | if (cell->darkness < 0) // && x < self->w && y < self->h) |
681 | if (cell->darkness < 0) |
645 | { |
682 | { |
646 | cell->darkness = 0; |
683 | cell->darkness = 0; |
647 | cell->face [0] = 0; |
684 | cell->face [0] = 0; |
648 | cell->face [1] = 0; |
685 | cell->face [1] = 0; |
649 | cell->face [2] = 0; |
686 | cell->face [2] = 0; |
650 | } |
687 | } |
651 | |
688 | |
652 | cell->darkness = flags & 8 ? *data++ : 255; |
689 | cell->darkness = flags & 8 ? *data++ : 255; |
653 | |
690 | |
654 | //TODO: don't trust server data to be in-range(!) |
691 | //TODO: don't trust server data to be in-range(!) |
655 | |
692 | |
656 | if (flags & 4) |
693 | if (flags & 4) |
… | |
… | |
735 | |
772 | |
736 | void |
773 | void |
737 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
774 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
738 | PPCODE: |
775 | PPCODE: |
739 | { |
776 | { |
|
|
777 | int vx, vy; |
|
|
778 | int x, y, z; |
|
|
779 | int last_name; |
|
|
780 | mapface face; |
740 | int sw4 = (sw + 3) & ~3; |
781 | int sw4 = (sw + 3) & ~3; |
741 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
782 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
742 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
783 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
784 | |
743 | memset (darkness, 255, sw4 * sh); |
785 | memset (darkness, 255, sw4 * sh); |
744 | SvPOK_only (darkness_sv); |
786 | SvPOK_only (darkness_sv); |
745 | SvCUR_set (darkness_sv, sw4 * sh); |
787 | SvCUR_set (darkness_sv, sw4 * sh); |
746 | |
788 | |
747 | int vx = self->x + (self->w - sw) / 2 - shift_x; |
789 | vx = self->x + (self->w - sw) / 2 - shift_x; |
748 | int vy = self->y + (self->h - sh) / 2 - shift_y; |
790 | vy = self->y + (self->h - sh) / 2 - shift_y; |
749 | |
791 | |
750 | /* |
792 | /* |
751 | int vx = self->vx = self->w >= sw |
793 | int vx = self->vx = self->w >= sw |
752 | ? self->x + (self->w - sw) / 2 |
794 | ? self->x + (self->w - sw) / 2 |
753 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
795 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
… | |
… | |
762 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
804 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
763 | glEnable (GL_BLEND); |
805 | glEnable (GL_BLEND); |
764 | glEnable (GL_TEXTURE_2D); |
806 | glEnable (GL_TEXTURE_2D); |
765 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
807 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
766 | |
808 | |
767 | int x, y, z; |
|
|
768 | |
|
|
769 | int last_name = 0; |
|
|
770 | |
|
|
771 | glBegin (GL_QUADS); |
809 | glBegin (GL_QUADS); |
|
|
810 | |
|
|
811 | last_name = 0; |
772 | |
812 | |
773 | for (z = 0; z < 3; z++) |
813 | for (z = 0; z < 3; z++) |
774 | for (y = 0; y < sh; y++) |
814 | for (y = 0; y < sh; y++) |
775 | if (0 <= y + vy && y + vy < self->rows) |
815 | if (0 <= y + vy && y + vy < self->rows) |
776 | { |
816 | { |
… | |
… | |
783 | |
823 | |
784 | darkness[y * sw4 + x] = cell->darkness < 0 |
824 | darkness[y * sw4 + x] = cell->darkness < 0 |
785 | ? 255 - FOW_DARKNESS |
825 | ? 255 - FOW_DARKNESS |
786 | : 255 - cell->darkness; |
826 | : 255 - cell->darkness; |
787 | |
827 | |
788 | mapface face = cell->face [z]; |
828 | face = cell->face [z]; |
789 | |
829 | |
790 | if (face) |
830 | if (face) |
791 | { |
831 | { |
792 | maptex tex = self->tex [face]; |
832 | maptex tex = self->tex [face]; |
793 | |
833 | |
… | |
… | |
853 | for (x = x0; x < x1; x++) |
893 | for (x = x0; x < x1; x++) |
854 | { |
894 | { |
855 | if (row && row->c0 <= x && x < row->c1) |
895 | if (row && row->c0 <= x && x < row->c1) |
856 | { |
896 | { |
857 | mapcell *cell = row->col + (x - row->c0); |
897 | mapcell *cell = row->col + (x - row->c0); |
858 | |
|
|
859 | uint8_t flags = 0; |
898 | uint8_t flags = 0; |
860 | |
899 | |
861 | if (cell->face [0]) flags |= 1; |
900 | if (cell->face [0]) flags |= 1; |
862 | if (cell->face [1]) flags |= 2; |
901 | if (cell->face [1]) flags |= 2; |
863 | if (cell->face [2]) flags |= 4; |
902 | if (cell->face [2]) flags |= 4; |
… | |
… | |
897 | void |
936 | void |
898 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
937 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
899 | PPCODE: |
938 | PPCODE: |
900 | { |
939 | { |
901 | int x, y, z; |
940 | int x, y, z; |
|
|
941 | int w, h; |
902 | int x1, y1; |
942 | int x1, y1; |
903 | |
943 | |
904 | if (*data++ != 0) |
944 | if (*data++ != 0) |
905 | return; /* version mismatch */ |
945 | return; /* version mismatch */ |
906 | |
946 | |
907 | int w = *data++ << 8; w |= *data++; |
947 | w = *data++ << 8; w |= *data++; |
908 | int h = *data++ << 8; h |= *data++; |
948 | h = *data++ << 8; h |= *data++; |
909 | |
949 | |
910 | // we need to do this 'cause we don't keep an absolute coord system for rows |
950 | // we need to do this 'cause we don't keep an absolute coord system for rows |
911 | // TODO: treat rows as we treat |
951 | // TODO: treat rows as we treat |
912 | map_get_row (self, y0 + self->y - self->oy);//D |
952 | map_get_row (self, y0 + self->y - self->oy);//D |
913 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
953 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |