|
|
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); |
… | |
… | |
285 | croak ("load_image: %s", SDL_GetError ()); |
307 | croak ("load_image: %s", SDL_GetError ()); |
286 | |
308 | |
287 | fmt.palette = NULL; |
309 | fmt.palette = NULL; |
288 | fmt.BitsPerPixel = 32; |
310 | fmt.BitsPerPixel = 32; |
289 | fmt.BytesPerPixel = 4; |
311 | fmt.BytesPerPixel = 4; |
|
|
312 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
290 | fmt.Rmask = 0x000000ff; |
313 | fmt.Rmask = 0x000000ff; |
291 | fmt.Gmask = 0x0000ff00; |
314 | fmt.Gmask = 0x0000ff00; |
292 | fmt.Bmask = 0x00ff0000; |
315 | fmt.Bmask = 0x00ff0000; |
293 | 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 |
294 | fmt.Rloss = 0; |
323 | fmt.Rloss = 0; |
295 | fmt.Gloss = 0; |
324 | fmt.Gloss = 0; |
296 | fmt.Bloss = 0; |
325 | fmt.Bloss = 0; |
297 | fmt.Aloss = 0; |
326 | fmt.Aloss = 0; |
298 | fmt.Rshift = 0; |
327 | fmt.Rshift = 0; |
… | |
… | |
312 | SDL_LockSurface (surface2); |
341 | SDL_LockSurface (surface2); |
313 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
342 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
314 | SDL_UnlockSurface (surface2); |
343 | SDL_UnlockSurface (surface2); |
315 | 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))); |
316 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
345 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
317 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); |
346 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
318 | |
347 | |
319 | SDL_FreeSurface (surface); |
348 | SDL_FreeSurface (surface); |
320 | SDL_FreeSurface (surface2); |
349 | SDL_FreeSurface (surface2); |
321 | } |
350 | } |
322 | |
351 | |
… | |
… | |
390 | STRLEN textlen; |
419 | STRLEN textlen; |
391 | char *text = SvPVutf8 (text_, textlen); |
420 | char *text = SvPVutf8 (text_, textlen); |
392 | |
421 | |
393 | pango_layout_set_markup (self->pl, text, textlen); |
422 | pango_layout_set_markup (self->pl, text, textlen); |
394 | } |
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 |
395 | |
432 | |
396 | void |
433 | void |
397 | set_height (CFClient::Layout self, int base_height) |
434 | set_height (CFClient::Layout self, int base_height) |
398 | CODE: |
435 | CODE: |
399 | self->base_height = base_height; |
436 | self->base_height = base_height; |
… | |
… | |
565 | { |
602 | { |
566 | Append (maptex, self->tex, self->texs, self->texs); |
603 | Append (maptex, self->tex, self->texs, self->texs); |
567 | self->texs *= 2; |
604 | self->texs *= 2; |
568 | } |
605 | } |
569 | |
606 | |
|
|
607 | { |
570 | maptex *tex = self->tex + texid; |
608 | maptex *tex = self->tex + texid; |
571 | |
609 | |
572 | tex->name = name; |
610 | tex->name = name; |
573 | tex->w = w; |
611 | tex->w = w; |
574 | tex->h = h; |
612 | tex->h = h; |
575 | tex->s = s; |
613 | tex->s = s; |
576 | tex->t = t; |
614 | tex->t = t; |
577 | tex->r = r; |
615 | tex->r = r; |
578 | tex->g = g; |
616 | tex->g = g; |
579 | tex->b = b; |
617 | tex->b = b; |
580 | tex->a = a; |
618 | tex->a = a; |
|
|
619 | } |
581 | } |
620 | } |
582 | |
621 | |
583 | int |
622 | int |
584 | ox (CFClient::Map self) |
623 | ox (CFClient::Map self) |
585 | ALIAS: |
624 | ALIAS: |
… | |
… | |
623 | map1a_update (CFClient::Map self, SV *data_) |
662 | map1a_update (CFClient::Map self, SV *data_) |
624 | CODE: |
663 | CODE: |
625 | { |
664 | { |
626 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
665 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
627 | 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; |
628 | |
669 | |
629 | while (data < data_end) |
670 | while (data < data_end) |
630 | { |
671 | { |
631 | int flags = (data [0] << 8) + data [1]; data += 2; |
672 | flags = (data [0] << 8) + data [1]; data += 2; |
632 | |
673 | |
633 | int x = ((flags >> 10) & 63) + self->x; |
674 | x = ((flags >> 10) & 63) + self->x; |
634 | int y = ((flags >> 4) & 63) + self->y; |
675 | y = ((flags >> 4) & 63) + self->y; |
635 | |
676 | |
636 | mapcell *cell = map_get_cell (self, x, y); |
677 | cell = map_get_cell (self, x, y); |
637 | |
678 | |
638 | if (flags & 15) |
679 | if (flags & 15) |
639 | { |
680 | { |
640 | if (cell->darkness < 0) |
681 | if (cell->darkness < 0) |
641 | { |
682 | { |
… | |
… | |
731 | |
772 | |
732 | void |
773 | void |
733 | 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) |
734 | PPCODE: |
775 | PPCODE: |
735 | { |
776 | { |
|
|
777 | int vx, vy; |
|
|
778 | int x, y, z; |
|
|
779 | int last_name; |
|
|
780 | mapface face; |
736 | int sw4 = (sw + 3) & ~3; |
781 | int sw4 = (sw + 3) & ~3; |
737 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
782 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
738 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
783 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
784 | |
739 | memset (darkness, 255, sw4 * sh); |
785 | memset (darkness, 255, sw4 * sh); |
740 | SvPOK_only (darkness_sv); |
786 | SvPOK_only (darkness_sv); |
741 | SvCUR_set (darkness_sv, sw4 * sh); |
787 | SvCUR_set (darkness_sv, sw4 * sh); |
742 | |
788 | |
743 | int vx = self->x + (self->w - sw) / 2 - shift_x; |
789 | vx = self->x + (self->w - sw) / 2 - shift_x; |
744 | int vy = self->y + (self->h - sh) / 2 - shift_y; |
790 | vy = self->y + (self->h - sh) / 2 - shift_y; |
745 | |
791 | |
746 | /* |
792 | /* |
747 | int vx = self->vx = self->w >= sw |
793 | int vx = self->vx = self->w >= sw |
748 | ? self->x + (self->w - sw) / 2 |
794 | ? self->x + (self->w - sw) / 2 |
749 | : 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)); |
… | |
… | |
758 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
804 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
759 | glEnable (GL_BLEND); |
805 | glEnable (GL_BLEND); |
760 | glEnable (GL_TEXTURE_2D); |
806 | glEnable (GL_TEXTURE_2D); |
761 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
807 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
762 | |
808 | |
763 | int x, y, z; |
|
|
764 | |
|
|
765 | int last_name = 0; |
|
|
766 | |
|
|
767 | glBegin (GL_QUADS); |
809 | glBegin (GL_QUADS); |
|
|
810 | |
|
|
811 | last_name = 0; |
768 | |
812 | |
769 | for (z = 0; z < 3; z++) |
813 | for (z = 0; z < 3; z++) |
770 | for (y = 0; y < sh; y++) |
814 | for (y = 0; y < sh; y++) |
771 | if (0 <= y + vy && y + vy < self->rows) |
815 | if (0 <= y + vy && y + vy < self->rows) |
772 | { |
816 | { |
… | |
… | |
779 | |
823 | |
780 | darkness[y * sw4 + x] = cell->darkness < 0 |
824 | darkness[y * sw4 + x] = cell->darkness < 0 |
781 | ? 255 - FOW_DARKNESS |
825 | ? 255 - FOW_DARKNESS |
782 | : 255 - cell->darkness; |
826 | : 255 - cell->darkness; |
783 | |
827 | |
784 | mapface face = cell->face [z]; |
828 | face = cell->face [z]; |
785 | |
829 | |
786 | if (face) |
830 | if (face) |
787 | { |
831 | { |
788 | maptex tex = self->tex [face]; |
832 | maptex tex = self->tex [face]; |
789 | |
833 | |
… | |
… | |
849 | for (x = x0; x < x1; x++) |
893 | for (x = x0; x < x1; x++) |
850 | { |
894 | { |
851 | if (row && row->c0 <= x && x < row->c1) |
895 | if (row && row->c0 <= x && x < row->c1) |
852 | { |
896 | { |
853 | mapcell *cell = row->col + (x - row->c0); |
897 | mapcell *cell = row->col + (x - row->c0); |
854 | |
|
|
855 | uint8_t flags = 0; |
898 | uint8_t flags = 0; |
856 | |
899 | |
857 | if (cell->face [0]) flags |= 1; |
900 | if (cell->face [0]) flags |= 1; |
858 | if (cell->face [1]) flags |= 2; |
901 | if (cell->face [1]) flags |= 2; |
859 | if (cell->face [2]) flags |= 4; |
902 | if (cell->face [2]) flags |= 4; |
… | |
… | |
893 | void |
936 | void |
894 | 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) |
895 | PPCODE: |
938 | PPCODE: |
896 | { |
939 | { |
897 | int x, y, z; |
940 | int x, y, z; |
|
|
941 | int w, h; |
898 | int x1, y1; |
942 | int x1, y1; |
899 | |
943 | |
900 | if (*data++ != 0) |
944 | if (*data++ != 0) |
901 | return; /* version mismatch */ |
945 | return; /* version mismatch */ |
902 | |
946 | |
903 | int w = *data++ << 8; w |= *data++; |
947 | w = *data++ << 8; w |= *data++; |
904 | int h = *data++ << 8; h |= *data++; |
948 | h = *data++ << 8; h |= *data++; |
905 | |
949 | |
906 | // 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 |
907 | // TODO: treat rows as we treat |
951 | // TODO: treat rows as we treat |
908 | map_get_row (self, y0 + self->y - self->oy);//D |
952 | map_get_row (self, y0 + self->y - self->oy);//D |
909 | 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 |