… | |
… | |
33 | typedef signed char int8_t; |
33 | typedef signed char int8_t; |
34 | typedef signed short int16_t; |
34 | typedef signed short int16_t; |
35 | typedef signed int int32_t; |
35 | typedef signed int int32_t; |
36 | #endif |
36 | #endif |
37 | |
37 | |
|
|
38 | #include "glext.h" |
|
|
39 | |
38 | #define FOW_DARKNESS 32 |
40 | #define FOW_DARKNESS 32 |
39 | |
41 | |
40 | #define MAP_EXTEND_X 32 |
42 | #define MAP_EXTEND_X 32 |
41 | #define MAP_EXTEND_Y 512 |
43 | #define MAP_EXTEND_Y 512 |
42 | |
44 | |
|
|
45 | #define MIN_FONT_HEIGHT 8 |
|
|
46 | |
43 | typedef Mix_Chunk *CFClient__MixChunk; |
47 | typedef Mix_Chunk *CFClient__MixChunk; |
44 | typedef Mix_Music *CFClient__MixMusic; |
48 | typedef Mix_Music *CFClient__MixMusic; |
45 | |
49 | |
46 | static PangoContext *context; |
50 | typedef PangoFontDescription *CFClient__Font; |
47 | static PangoFontMap *fontmap; |
|
|
48 | |
51 | |
49 | typedef struct cf_layout { |
52 | typedef struct cf_layout { |
50 | PangoLayout *pl; |
53 | PangoLayout *pl; |
51 | int base_height; |
54 | int base_height; |
|
|
55 | CFClient__Font font; |
52 | } *CFClient__Layout; |
56 | } *CFClient__Layout; |
|
|
57 | |
|
|
58 | static CFClient__Font default_font; |
|
|
59 | static PangoContext *context; |
|
|
60 | static PangoFontMap *fontmap; |
53 | |
61 | |
54 | static void |
62 | static void |
55 | substitute_func (FcPattern *pattern, gpointer data) |
63 | substitute_func (FcPattern *pattern, gpointer data) |
56 | { |
64 | { |
57 | FcPatternAddBool (pattern, FC_HINTING , 1); |
65 | FcPatternAddBool (pattern, FC_HINTING , 1); |
58 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
66 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
59 | } |
67 | } |
60 | |
68 | |
61 | static void |
69 | static void |
62 | layout_update (CFClient__Layout self) |
70 | layout_update_font (CFClient__Layout self) |
63 | { |
71 | { |
64 | /* use a random scale factor to account for unknown descenders, 0.8 works |
72 | /* use a random scale factor to account for unknown descenders, 0.8 works |
65 | * reasonably well with bitstream vera |
73 | * reasonably well with bitstream vera |
66 | */ |
74 | */ |
67 | PangoFontDescription *font = pango_context_get_font_description (context); |
75 | PangoFontDescription *font = self->font ? self->font : default_font; |
68 | |
76 | |
69 | int height = self->base_height * (PANGO_SCALE * 8 / 10); |
|
|
70 | |
|
|
71 | if (pango_font_description_get_size (font) != height) |
|
|
72 | { |
|
|
73 | pango_font_description_set_absolute_size (font, height); |
77 | pango_font_description_set_absolute_size (font, |
74 | pango_layout_context_changed (self->pl); |
78 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
75 | } |
79 | |
|
|
80 | pango_layout_set_font_description (self->pl, font); |
76 | } |
81 | } |
77 | |
82 | |
78 | static void |
83 | static void |
79 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
84 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
80 | { |
85 | { |
81 | layout_update (self); |
|
|
82 | |
|
|
83 | pango_layout_get_pixel_size (self->pl, w, h); |
86 | pango_layout_get_pixel_size (self->pl, w, h); |
84 | |
87 | |
85 | *w = (*w + 3) & ~3; |
88 | *w = (*w + 3) & ~3; |
86 | if (!*w) *w = 1; |
89 | if (!*w) *w = 1; |
87 | if (!*h) *h = 1; |
90 | if (!*h) *h = 1; |
… | |
… | |
237 | break; |
240 | break; |
238 | |
241 | |
239 | row->col[x - row->c0].darkness = -1; |
242 | row->col[x - row->c0].darkness = -1; |
240 | } |
243 | } |
241 | } |
244 | } |
|
|
245 | } |
|
|
246 | |
|
|
247 | static void |
|
|
248 | music_finished () |
|
|
249 | { |
|
|
250 | SDL_UserEvent ev; |
|
|
251 | |
|
|
252 | ev.type = SDL_USEREVENT; |
|
|
253 | ev.code = 0; |
|
|
254 | ev.data1 = 0; |
|
|
255 | ev.data2 = 0; |
|
|
256 | |
|
|
257 | SDL_PushEvent ((SDL_Event *)&ev); |
242 | } |
258 | } |
243 | |
259 | |
244 | MODULE = CFClient PACKAGE = CFClient |
260 | MODULE = CFClient PACKAGE = CFClient |
245 | |
261 | |
246 | PROTOTYPES: ENABLE |
262 | PROTOTYPES: ENABLE |
… | |
… | |
463 | } |
479 | } |
464 | } |
480 | } |
465 | |
481 | |
466 | int |
482 | int |
467 | Mix_OpenAudio (int frequency = 22050, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 512) |
483 | Mix_OpenAudio (int frequency = 22050, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 512) |
|
|
484 | POSTCALL: |
|
|
485 | Mix_HookMusicFinished (music_finished); |
468 | |
486 | |
469 | void |
487 | void |
470 | Mix_CloseAudio () |
488 | Mix_CloseAudio () |
471 | |
489 | |
472 | int |
490 | int |
… | |
… | |
495 | |
513 | |
496 | void |
514 | void |
497 | add_font (char *file) |
515 | add_font (char *file) |
498 | CODE: |
516 | CODE: |
499 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
517 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
500 | |
|
|
501 | void |
|
|
502 | set_font (char *file) |
|
|
503 | CODE: |
|
|
504 | { |
|
|
505 | int count; |
|
|
506 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
|
|
507 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
508 | FcPatternDestroy (pattern); |
|
|
509 | pango_context_set_font_description (context, font); |
|
|
510 | } |
|
|
511 | |
518 | |
512 | void |
519 | void |
513 | load_image_inline (SV *image_) |
520 | load_image_inline (SV *image_) |
514 | ALIAS: |
521 | ALIAS: |
515 | load_image_file = 1 |
522 | load_image_file = 1 |
… | |
… | |
606 | #else |
613 | #else |
607 | fprintf (stderr, "FATAL: %s\n", message); |
614 | fprintf (stderr, "FATAL: %s\n", message); |
608 | #endif |
615 | #endif |
609 | exit (1); |
616 | exit (1); |
610 | |
617 | |
|
|
618 | MODULE = CFClient PACKAGE = CFClient::Font |
|
|
619 | |
|
|
620 | CFClient::Font |
|
|
621 | new_from_file (SV *class, char *path) |
|
|
622 | CODE: |
|
|
623 | { |
|
|
624 | int count; |
|
|
625 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, 0, 0, &count); |
|
|
626 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
|
|
627 | FcPatternDestroy (pattern); |
|
|
628 | } |
|
|
629 | OUTPUT: |
|
|
630 | RETVAL |
|
|
631 | |
|
|
632 | void |
|
|
633 | DESTROY (CFClient::Font self) |
|
|
634 | CODE: |
|
|
635 | pango_font_description_free (self); |
|
|
636 | |
|
|
637 | void |
|
|
638 | make_default (CFClient::Font self) |
|
|
639 | CODE: |
|
|
640 | default_font = self; |
|
|
641 | |
611 | MODULE = CFClient PACKAGE = CFClient::Layout |
642 | MODULE = CFClient PACKAGE = CFClient::Layout |
612 | |
643 | |
613 | CFClient::Layout |
644 | CFClient::Layout |
614 | new (SV *class, int base_height = 10) |
645 | new (SV *class, int base_height = MIN_FONT_HEIGHT) |
615 | CODE: |
646 | CODE: |
616 | New (0, RETVAL, 1, struct cf_layout); |
647 | New (0, RETVAL, 1, struct cf_layout); |
|
|
648 | RETVAL->pl = pango_layout_new (context); |
617 | RETVAL->base_height = base_height; |
649 | RETVAL->base_height = base_height; |
618 | RETVAL->pl = pango_layout_new (context); |
650 | RETVAL->font = 0; |
619 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
651 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
|
|
652 | pango_layout_set_font_description (RETVAL->pl, default_font); |
620 | OUTPUT: |
653 | OUTPUT: |
621 | RETVAL |
654 | RETVAL |
622 | |
655 | |
623 | void |
656 | void |
624 | DESTROY (CFClient::Layout self) |
657 | DESTROY (CFClient::Layout self) |
… | |
… | |
653 | SvUTF8_on (RETVAL); |
686 | SvUTF8_on (RETVAL); |
654 | OUTPUT: |
687 | OUTPUT: |
655 | RETVAL |
688 | RETVAL |
656 | |
689 | |
657 | void |
690 | void |
|
|
691 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
|
|
692 | CODE: |
|
|
693 | if (self->font != font) |
|
|
694 | { |
|
|
695 | self->font = font; |
|
|
696 | layout_update_font (self); |
|
|
697 | } |
|
|
698 | |
|
|
699 | void |
658 | set_height (CFClient::Layout self, int base_height) |
700 | set_height (CFClient::Layout self, int base_height) |
659 | CODE: |
701 | CODE: |
|
|
702 | if (self->base_height != base_height) |
|
|
703 | { |
660 | self->base_height = base_height; |
704 | self->base_height = base_height; |
|
|
705 | layout_update_font (self); |
|
|
706 | } |
661 | |
707 | |
662 | void |
708 | void |
663 | set_width (CFClient::Layout self, int max_width = -1) |
709 | set_width (CFClient::Layout self, int max_width = -1) |
664 | CODE: |
710 | CODE: |
665 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
711 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
… | |
… | |
668 | size (CFClient::Layout self) |
714 | size (CFClient::Layout self) |
669 | PPCODE: |
715 | PPCODE: |
670 | { |
716 | { |
671 | int w, h; |
717 | int w, h; |
672 | |
718 | |
673 | layout_update (self); |
|
|
674 | layout_get_pixel_size (self, &w, &h); |
719 | layout_get_pixel_size (self, &w, &h); |
675 | |
720 | |
676 | EXTEND (SP, 2); |
721 | EXTEND (SP, 2); |
677 | PUSHs (sv_2mortal (newSViv (w))); |
722 | PUSHs (sv_2mortal (newSViv (w))); |
678 | PUSHs (sv_2mortal (newSViv (h))); |
723 | PUSHs (sv_2mortal (newSViv (h))); |
… | |
… | |
681 | int |
726 | int |
682 | xy_to_index (CFClient::Layout self, int x, int y) |
727 | xy_to_index (CFClient::Layout self, int x, int y) |
683 | CODE: |
728 | CODE: |
684 | { |
729 | { |
685 | int index, trailing; |
730 | int index, trailing; |
686 | |
|
|
687 | layout_update (self); |
|
|
688 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
731 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
689 | |
|
|
690 | RETVAL = index; |
732 | RETVAL = index; |
691 | } |
733 | } |
692 | OUTPUT: |
734 | OUTPUT: |
693 | RETVAL |
735 | RETVAL |
694 | |
736 | |
695 | void |
737 | void |
696 | cursor_pos (CFClient::Layout self, int index) |
738 | cursor_pos (CFClient::Layout self, int index) |
697 | PPCODE: |
739 | PPCODE: |
698 | { |
740 | { |
699 | PangoRectangle strong_pos; |
741 | PangoRectangle strong_pos; |
700 | layout_update (self); |
|
|
701 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
742 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
702 | |
743 | |
703 | EXTEND (SP, 3); |
744 | EXTEND (SP, 3); |
704 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
745 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
705 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
746 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
… | |
… | |
712 | { |
753 | { |
713 | SV *retval; |
754 | SV *retval; |
714 | int w, h; |
755 | int w, h; |
715 | FT_Bitmap bitmap; |
756 | FT_Bitmap bitmap; |
716 | |
757 | |
717 | layout_update (self); |
|
|
718 | layout_get_pixel_size (self, &w, &h); |
758 | layout_get_pixel_size (self, &w, &h); |
719 | |
759 | |
720 | retval = newSV (w * h); |
760 | retval = newSV (w * h); |
721 | SvPOK_only (retval); |
761 | SvPOK_only (retval); |
722 | SvCUR_set (retval, w * h); |
762 | SvCUR_set (retval, w * h); |
… | |
… | |
933 | cell->darkness = -1; |
973 | cell->darkness = -1; |
934 | } |
974 | } |
935 | } |
975 | } |
936 | |
976 | |
937 | SV * |
977 | SV * |
938 | mapmap (CFClient::Map self, int w, int h) |
978 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
939 | CODE: |
979 | CODE: |
940 | { |
980 | { |
941 | int x0, x1, x; |
981 | int x1, x; |
942 | int y0, y1, y; |
982 | int y1, y; |
943 | int z; |
983 | int z; |
944 | SV *map_sv = newSV (w * h * sizeof (uint32_t)); |
984 | SV *map_sv = newSV (w * h * sizeof (uint32_t)); |
945 | uint32_t *map = (uint32_t *)SvPVX (map_sv); |
985 | uint32_t *map = (uint32_t *)SvPVX (map_sv); |
946 | |
986 | |
947 | SvPOK_only (map_sv); |
987 | SvPOK_only (map_sv); |
948 | SvCUR_set (map_sv, w * h * sizeof (uint32_t)); |
988 | SvCUR_set (map_sv, w * h * sizeof (uint32_t)); |
949 | |
989 | |
950 | x0 = self->x - w / 2; x1 = x0 + w; |
990 | x0 += self->x; x1 = x0 + w; |
951 | y0 = self->y - h / 2; y1 = y0 + h; |
991 | y0 += self->y; y1 = y0 + h; |
952 | |
992 | |
953 | for (y = y0; y < y1; y++) |
993 | for (y = y0; y < y1; y++) |
954 | { |
994 | { |
955 | maprow *row = 0 <= y && y < self->rows |
995 | maprow *row = 0 <= y && y < self->rows |
956 | ? self->row + y |
996 | ? self->row + y |
… | |
… | |
1096 | *data++ = 0; /* version 0 format */ |
1136 | *data++ = 0; /* version 0 format */ |
1097 | *data++ = w >> 8; *data++ = w; |
1137 | *data++ = w >> 8; *data++ = w; |
1098 | *data++ = h >> 8; *data++ = h; |
1138 | *data++ = h >> 8; *data++ = h; |
1099 | |
1139 | |
1100 | // we need to do this 'cause we don't keep an absolute coord system for rows |
1140 | // we need to do this 'cause we don't keep an absolute coord system for rows |
1101 | // TODO: treat rows as we treat |
1141 | // TODO: treat rows as we treat columns |
1102 | map_get_row (self, y0 + self->y - self->oy);//D |
1142 | map_get_row (self, y0 + self->y - self->oy);//D |
1103 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
1143 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
1104 | |
1144 | |
1105 | x0 += self->x - self->ox; |
1145 | x0 += self->x - self->ox; |
1106 | y0 += self->y - self->oy; |
1146 | y0 += self->y - self->oy; |
… | |
… | |
1170 | |
1210 | |
1171 | w = *data++ << 8; w |= *data++; |
1211 | w = *data++ << 8; w |= *data++; |
1172 | h = *data++ << 8; h |= *data++; |
1212 | h = *data++ << 8; h |= *data++; |
1173 | |
1213 | |
1174 | // we need to do this 'cause we don't keep an absolute coord system for rows |
1214 | // we need to do this 'cause we don't keep an absolute coord system for rows |
1175 | // TODO: treat rows as we treat |
1215 | // TODO: treat rows as we treat columns |
1176 | map_get_row (self, y0 + self->y - self->oy);//D |
1216 | map_get_row (self, y0 + self->y - self->oy);//D |
1177 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
1217 | map_get_row (self, y0 + self->y - self->oy + h - 1);//D |
1178 | |
1218 | |
1179 | x0 += self->x - self->ox; |
1219 | x0 += self->x - self->ox; |
1180 | y0 += self->y - self->oy; |
1220 | y0 += self->y - self->oy; |
… | |
… | |
1308 | const_iv (GL_TEXTURE_WRAP_T), |
1348 | const_iv (GL_TEXTURE_WRAP_T), |
1309 | const_iv (GL_CLAMP), |
1349 | const_iv (GL_CLAMP), |
1310 | const_iv (GL_REPEAT), |
1350 | const_iv (GL_REPEAT), |
1311 | const_iv (GL_NEAREST), |
1351 | const_iv (GL_NEAREST), |
1312 | const_iv (GL_LINEAR), |
1352 | const_iv (GL_LINEAR), |
|
|
1353 | const_iv (GL_NEAREST_MIPMAP_NEAREST), |
|
|
1354 | const_iv (GL_LINEAR_MIPMAP_NEAREST), |
|
|
1355 | const_iv (GL_NEAREST_MIPMAP_LINEAR), |
|
|
1356 | const_iv (GL_LINEAR_MIPMAP_LINEAR), |
|
|
1357 | const_iv (GL_GENERATE_MIPMAP), |
|
|
1358 | const_iv (GL_LINEAR), |
1313 | const_iv (GL_MODULATE), |
1359 | const_iv (GL_MODULATE), |
1314 | const_iv (GL_REPLACE), |
1360 | const_iv (GL_REPLACE), |
1315 | const_iv (GL_COLOR_BUFFER_BIT), |
1361 | const_iv (GL_COLOR_BUFFER_BIT), |
1316 | const_iv (GL_PROJECTION), |
1362 | const_iv (GL_PROJECTION), |
1317 | const_iv (GL_MODELVIEW), |
1363 | const_iv (GL_MODELVIEW), |
… | |
… | |
1319 | const_iv (GL_CONVOLUTION_2D), |
1365 | const_iv (GL_CONVOLUTION_2D), |
1320 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1366 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1321 | const_iv (GL_CONSTANT_BORDER), |
1367 | const_iv (GL_CONSTANT_BORDER), |
1322 | const_iv (GL_LINES), |
1368 | const_iv (GL_LINES), |
1323 | const_iv (GL_QUADS), |
1369 | const_iv (GL_QUADS), |
|
|
1370 | const_iv (GL_LINE_LOOP), |
1324 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
1371 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
1325 | const_iv (GL_FASTEST), |
1372 | const_iv (GL_FASTEST), |
1326 | # undef const_iv |
1373 | # undef const_iv |
1327 | }; |
1374 | }; |
1328 | |
1375 | |
… | |
… | |
1363 | |
1410 | |
1364 | void glTranslate (float x, float y, float z = 0.) |
1411 | void glTranslate (float x, float y, float z = 0.) |
1365 | CODE: |
1412 | CODE: |
1366 | glTranslatef (x, y, z); |
1413 | glTranslatef (x, y, z); |
1367 | |
1414 | |
1368 | void glScale (float x, float y, float z) |
1415 | void glScale (float x, float y, float z = 1.) |
1369 | CODE: |
1416 | CODE: |
1370 | glScalef (x, y, z); |
1417 | glScalef (x, y, z); |
1371 | |
1418 | |
1372 | void glRotate (float angle, float x, float y, float z) |
1419 | void glRotate (float angle, float x, float y, float z) |
1373 | CODE: |
1420 | CODE: |