1 | #ifdef _WIN32 |
1 | #ifdef _WIN32 |
|
|
2 | # define WIN32_LEAN_AND_MEAN |
2 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
3 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
3 | # include <malloc.h> |
4 | # include <malloc.h> |
4 | # include <windows.h> |
5 | # include <windows.h> |
5 | # pragma warning(disable:4244) |
6 | # pragma warning(disable:4244) |
6 | #endif |
7 | #endif |
7 | |
8 | |
8 | #include "EXTERN.h" |
9 | #include "EXTERN.h" |
9 | #include "perl.h" |
10 | #include "perl.h" |
10 | #include "XSUB.h" |
11 | #include "XSUB.h" |
|
|
12 | |
|
|
13 | #ifdef _WIN32 |
|
|
14 | # undef pipe |
|
|
15 | #endif |
11 | |
16 | |
12 | #include <math.h> |
17 | #include <math.h> |
13 | #include <string.h> |
18 | #include <string.h> |
14 | #include <stdio.h> |
19 | #include <stdio.h> |
15 | #include <stdlib.h> |
20 | #include <stdlib.h> |
… | |
… | |
40 | typedef signed char int8_t; |
45 | typedef signed char int8_t; |
41 | typedef signed short int16_t; |
46 | typedef signed short int16_t; |
42 | typedef signed int int32_t; |
47 | typedef signed int int32_t; |
43 | #endif |
48 | #endif |
44 | |
49 | |
45 | #include "glext.h" |
|
|
46 | |
|
|
47 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
50 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
48 | |
51 | |
49 | #define FOW_DARKNESS 32 |
52 | #define FOW_DARKNESS 32 |
50 | |
53 | |
51 | #define MAP_EXTEND_X 32 |
54 | #define MAP_EXTEND_X 32 |
… | |
… | |
80 | |
83 | |
81 | #include "pango-font.c" |
84 | #include "pango-font.c" |
82 | #include "pango-fontmap.c" |
85 | #include "pango-fontmap.c" |
83 | #include "pango-render.c" |
86 | #include "pango-render.c" |
84 | |
87 | |
85 | typedef Mix_Chunk *CFClient__MixChunk; |
88 | typedef Mix_Chunk *CFPlus__MixChunk; |
86 | typedef Mix_Music *CFClient__MixMusic; |
89 | typedef Mix_Music *CFPlus__MixMusic; |
87 | |
90 | |
88 | typedef PangoFontDescription *CFClient__Font; |
91 | typedef PangoFontDescription *CFPlus__Font; |
89 | |
92 | |
90 | static int |
93 | static int |
91 | shape_attr_p (PangoLayoutRun *run) |
94 | shape_attr_p (PangoLayoutRun *run) |
92 | { |
95 | { |
93 | GSList *attrs = run->item->analysis.extra_attrs; |
96 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
107 | |
110 | |
108 | typedef struct cf_layout { |
111 | typedef struct cf_layout { |
109 | PangoLayout *pl; |
112 | PangoLayout *pl; |
110 | float r, g, b, a; // default color for rgba mode |
113 | float r, g, b, a; // default color for rgba mode |
111 | int base_height; |
114 | int base_height; |
112 | CFClient__Font font; |
115 | CFPlus__Font font; |
113 | } *CFClient__Layout; |
116 | } *CFPlus__Layout; |
114 | |
117 | |
115 | static CFClient__Font default_font; |
118 | static CFPlus__Font default_font; |
116 | static PangoContext *opengl_context; |
119 | static PangoContext *opengl_context; |
117 | static PangoFontMap *opengl_fontmap; |
120 | static PangoFontMap *opengl_fontmap; |
118 | |
121 | |
119 | static void |
122 | static void |
120 | substitute_func (FcPattern *pattern, gpointer data) |
123 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
125 | #endif |
128 | #endif |
126 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
129 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
127 | } |
130 | } |
128 | |
131 | |
129 | static void |
132 | static void |
130 | layout_update_font (CFClient__Layout self) |
133 | layout_update_font (CFPlus__Layout self) |
131 | { |
134 | { |
132 | /* use a random scale factor to account for unknown descenders, 0.8 works |
135 | /* use a random scale factor to account for unknown descenders, 0.8 works |
133 | * reasonably well with bitstream vera |
136 | * reasonably well with bitstream vera |
134 | */ |
137 | */ |
135 | PangoFontDescription *font = self->font ? self->font : default_font; |
138 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
139 | |
142 | |
140 | pango_layout_set_font_description (self->pl, font); |
143 | pango_layout_set_font_description (self->pl, font); |
141 | } |
144 | } |
142 | |
145 | |
143 | static void |
146 | static void |
144 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
147 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
145 | { |
148 | { |
|
|
149 | PangoRectangle rect; |
|
|
150 | |
|
|
151 | // get_pixel_* wrongly rounds down |
146 | pango_layout_get_pixel_size (self->pl, w, h); |
152 | pango_layout_get_extents (self->pl, 0, &rect); |
147 | |
153 | |
148 | if (!*w) *w = 1; |
154 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
149 | if (!*h) *h = 1; |
155 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
150 | |
156 | |
151 | *w = (*w + 3) & ~3; |
157 | if (!rect.width) rect.width = 1; |
|
|
158 | if (!rect.height) rect.height = 1; |
|
|
159 | |
|
|
160 | *w = rect.width; |
|
|
161 | *h = rect.height; |
152 | } |
162 | } |
153 | |
163 | |
154 | typedef uint16_t mapface; |
164 | typedef uint16_t mapface; |
155 | |
165 | |
156 | typedef struct { |
166 | typedef struct { |
… | |
… | |
179 | int texs; |
189 | int texs; |
180 | maptex *tex; |
190 | maptex *tex; |
181 | |
191 | |
182 | int32_t rows; |
192 | int32_t rows; |
183 | maprow *row; |
193 | maprow *row; |
184 | } *CFClient__Map; |
194 | } *CFPlus__Map; |
185 | |
195 | |
186 | static char * |
196 | static char * |
187 | prepend (char *ptr, int sze, int inc) |
197 | prepend (char *ptr, int sze, int inc) |
188 | { |
198 | { |
189 | char *p; |
199 | char *p; |
… | |
… | |
207 | |
217 | |
208 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
218 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
209 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
219 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
210 | |
220 | |
211 | static maprow * |
221 | static maprow * |
212 | map_get_row (CFClient__Map self, int y) |
222 | map_get_row (CFPlus__Map self, int y) |
213 | { |
223 | { |
214 | if (0 > y) |
224 | if (0 > y) |
215 | { |
225 | { |
216 | int extend = - y + MAP_EXTEND_Y; |
226 | int extend = - y + MAP_EXTEND_Y; |
217 | Prepend (maprow, self->row, self->rows, extend); |
227 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
255 | |
265 | |
256 | return row->col + (x - row->c0); |
266 | return row->col + (x - row->c0); |
257 | } |
267 | } |
258 | |
268 | |
259 | static mapcell * |
269 | static mapcell * |
260 | map_get_cell (CFClient__Map self, int x, int y) |
270 | map_get_cell (CFPlus__Map self, int x, int y) |
261 | { |
271 | { |
262 | return row_get_cell (map_get_row (self, y), x); |
272 | return row_get_cell (map_get_row (self, y), x); |
263 | } |
273 | } |
264 | |
274 | |
265 | static void |
275 | static void |
266 | map_clear (CFClient__Map self) |
276 | map_clear (CFPlus__Map self) |
267 | { |
277 | { |
268 | int r; |
278 | int r; |
269 | |
279 | |
270 | for (r = 0; r < self->rows; r++) |
280 | for (r = 0; r < self->rows; r++) |
271 | Safefree (self->row[r].col); |
281 | Safefree (self->row[r].col); |
… | |
… | |
279 | self->row = 0; |
289 | self->row = 0; |
280 | self->rows = 0; |
290 | self->rows = 0; |
281 | } |
291 | } |
282 | |
292 | |
283 | static void |
293 | static void |
284 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
294 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
285 | { |
295 | { |
286 | int x, y; |
296 | int x, y; |
287 | maprow *row; |
297 | maprow *row; |
288 | |
298 | |
289 | for (y = y0; y < y0 + h; y++) |
299 | for (y = y0; y < y0 + h; y++) |
… | |
… | |
346 | n |= n >> 16; |
356 | n |= n >> 16; |
347 | |
357 | |
348 | return n + 1; |
358 | return n + 1; |
349 | } |
359 | } |
350 | |
360 | |
351 | MODULE = CFClient PACKAGE = CFClient |
361 | MODULE = CFPlus PACKAGE = CFPlus |
352 | |
362 | |
353 | PROTOTYPES: ENABLE |
363 | PROTOTYPES: ENABLE |
354 | |
364 | |
355 | BOOT: |
365 | BOOT: |
356 | { |
366 | { |
357 | HV *stash = gv_stashpv ("CFClient", 1); |
367 | HV *stash = gv_stashpv ("CFPlus", 1); |
358 | static const struct { |
368 | static const struct { |
359 | const char *name; |
369 | const char *name; |
360 | IV iv; |
370 | IV iv; |
361 | } *civ, const_iv[] = { |
371 | } *civ, const_iv[] = { |
362 | # define const_iv(name) { # name, (IV)name } |
372 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
509 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
519 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
510 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
520 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
511 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
521 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
512 | |
522 | |
513 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
523 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
|
|
524 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
525 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
526 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
|
|
527 | #endif |
514 | |
528 | |
515 | SDL_EnableUNICODE (1); |
529 | SDL_EnableUNICODE (1); |
516 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
530 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
517 | |
531 | |
518 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
532 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
605 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
619 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
606 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
620 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
607 | break; |
621 | break; |
608 | } |
622 | } |
609 | |
623 | |
610 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
624 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
611 | } |
625 | } |
612 | } |
626 | } |
613 | |
627 | |
614 | int |
628 | int |
615 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
629 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
… | |
… | |
744 | void |
758 | void |
745 | _exit (int retval) |
759 | _exit (int retval) |
746 | CODE: |
760 | CODE: |
747 | _exit (retval); |
761 | _exit (retval); |
748 | |
762 | |
749 | MODULE = CFClient PACKAGE = CFClient::Font |
763 | MODULE = CFPlus PACKAGE = CFPlus::Font |
750 | |
764 | |
751 | CFClient::Font |
765 | CFPlus::Font |
752 | new_from_file (SV *class, char *path, int id = 0) |
766 | new_from_file (SV *class, char *path, int id = 0) |
753 | CODE: |
767 | CODE: |
754 | { |
768 | { |
755 | int count; |
769 | int count; |
756 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
770 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
759 | } |
773 | } |
760 | OUTPUT: |
774 | OUTPUT: |
761 | RETVAL |
775 | RETVAL |
762 | |
776 | |
763 | void |
777 | void |
764 | DESTROY (CFClient::Font self) |
778 | DESTROY (CFPlus::Font self) |
765 | CODE: |
779 | CODE: |
766 | pango_font_description_free (self); |
780 | pango_font_description_free (self); |
767 | |
781 | |
768 | void |
782 | void |
769 | make_default (CFClient::Font self) |
783 | make_default (CFPlus::Font self) |
770 | CODE: |
784 | CODE: |
771 | default_font = self; |
785 | default_font = self; |
772 | |
786 | |
773 | MODULE = CFClient PACKAGE = CFClient::Layout |
787 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
774 | |
788 | |
775 | void |
789 | void |
776 | reset_glyph_cache () |
790 | reset_glyph_cache () |
777 | CODE: |
791 | CODE: |
778 | tc_clear (); |
792 | tc_clear (); |
779 | |
793 | |
780 | CFClient::Layout |
794 | CFPlus::Layout |
781 | new (SV *class) |
795 | new (SV *class) |
782 | CODE: |
796 | CODE: |
783 | New (0, RETVAL, 1, struct cf_layout); |
797 | New (0, RETVAL, 1, struct cf_layout); |
784 | |
798 | |
785 | RETVAL->pl = pango_layout_new (opengl_context); |
799 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
794 | layout_update_font (RETVAL); |
808 | layout_update_font (RETVAL); |
795 | OUTPUT: |
809 | OUTPUT: |
796 | RETVAL |
810 | RETVAL |
797 | |
811 | |
798 | void |
812 | void |
799 | DESTROY (CFClient::Layout self) |
813 | DESTROY (CFPlus::Layout self) |
800 | CODE: |
814 | CODE: |
801 | g_object_unref (self->pl); |
815 | g_object_unref (self->pl); |
802 | Safefree (self); |
816 | Safefree (self); |
803 | |
817 | |
804 | void |
818 | void |
805 | set_text (CFClient::Layout self, SV *text_) |
819 | set_text (CFPlus::Layout self, SV *text_) |
806 | CODE: |
820 | CODE: |
807 | { |
821 | { |
808 | STRLEN textlen; |
822 | STRLEN textlen; |
809 | char *text = SvPVutf8 (text_, textlen); |
823 | char *text = SvPVutf8 (text_, textlen); |
810 | |
824 | |
811 | pango_layout_set_text (self->pl, text, textlen); |
825 | pango_layout_set_text (self->pl, text, textlen); |
812 | } |
826 | } |
813 | |
827 | |
814 | void |
828 | void |
815 | set_markup (CFClient::Layout self, SV *text_) |
829 | set_markup (CFPlus::Layout self, SV *text_) |
816 | CODE: |
830 | CODE: |
817 | { |
831 | { |
818 | STRLEN textlen; |
832 | STRLEN textlen; |
819 | char *text = SvPVutf8 (text_, textlen); |
833 | char *text = SvPVutf8 (text_, textlen); |
820 | |
834 | |
821 | pango_layout_set_markup (self->pl, text, textlen); |
835 | pango_layout_set_markup (self->pl, text, textlen); |
822 | } |
836 | } |
823 | |
837 | |
824 | void |
838 | void |
825 | set_shapes (CFClient::Layout self, ...) |
839 | set_shapes (CFPlus::Layout self, ...) |
826 | CODE: |
840 | CODE: |
827 | { |
841 | { |
828 | PangoAttrList *attrs = 0; |
842 | PangoAttrList *attrs = 0; |
829 | const char *text = pango_layout_get_text (self->pl); |
843 | const char *text = pango_layout_get_text (self->pl); |
830 | const char *pos = text; |
844 | const char *pos = text; |
… | |
… | |
865 | if (attrs) |
879 | if (attrs) |
866 | pango_layout_set_attributes (self->pl, attrs); |
880 | pango_layout_set_attributes (self->pl, attrs); |
867 | } |
881 | } |
868 | |
882 | |
869 | void |
883 | void |
870 | get_shapes (CFClient::Layout self) |
884 | get_shapes (CFPlus::Layout self) |
871 | PPCODE: |
885 | PPCODE: |
872 | { |
886 | { |
873 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
887 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
874 | |
888 | |
875 | do |
889 | do |
… | |
… | |
890 | |
904 | |
891 | pango_layout_iter_free (iter); |
905 | pango_layout_iter_free (iter); |
892 | } |
906 | } |
893 | |
907 | |
894 | int |
908 | int |
895 | has_wrapped (CFClient::Layout self) |
909 | has_wrapped (CFPlus::Layout self) |
896 | CODE: |
910 | CODE: |
897 | { |
911 | { |
898 | int lines = 1; |
912 | int lines = 1; |
899 | const char *text = pango_layout_get_text (self->pl); |
913 | const char *text = pango_layout_get_text (self->pl); |
900 | |
914 | |
… | |
… | |
905 | } |
919 | } |
906 | OUTPUT: |
920 | OUTPUT: |
907 | RETVAL |
921 | RETVAL |
908 | |
922 | |
909 | SV * |
923 | SV * |
910 | get_text (CFClient::Layout self) |
924 | get_text (CFPlus::Layout self) |
911 | CODE: |
925 | CODE: |
912 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
926 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
913 | sv_utf8_decode (RETVAL); |
927 | sv_utf8_decode (RETVAL); |
914 | OUTPUT: |
928 | OUTPUT: |
915 | RETVAL |
929 | RETVAL |
916 | |
930 | |
917 | void |
931 | void |
918 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
932 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
919 | CODE: |
933 | CODE: |
920 | self->r = r; |
934 | self->r = r; |
921 | self->g = g; |
935 | self->g = g; |
922 | self->b = b; |
936 | self->b = b; |
923 | self->a = a; |
937 | self->a = a; |
924 | |
938 | |
925 | void |
939 | void |
926 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
940 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
927 | CODE: |
941 | CODE: |
928 | if (self->font != font) |
942 | if (self->font != font) |
929 | { |
943 | { |
930 | self->font = font; |
944 | self->font = font; |
931 | layout_update_font (self); |
945 | layout_update_font (self); |
932 | } |
946 | } |
933 | |
947 | |
934 | void |
948 | void |
935 | set_height (CFClient::Layout self, int base_height) |
949 | set_height (CFPlus::Layout self, int base_height) |
936 | CODE: |
950 | CODE: |
937 | if (self->base_height != base_height) |
951 | if (self->base_height != base_height) |
938 | { |
952 | { |
939 | self->base_height = base_height; |
953 | self->base_height = base_height; |
940 | layout_update_font (self); |
954 | layout_update_font (self); |
941 | } |
955 | } |
942 | |
956 | |
943 | void |
957 | void |
944 | set_width (CFClient::Layout self, int max_width = -1) |
958 | set_width (CFPlus::Layout self, int max_width = -1) |
945 | CODE: |
959 | CODE: |
946 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
960 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
947 | |
961 | |
948 | void |
962 | void |
949 | set_indent (CFClient::Layout self, int indent) |
963 | set_indent (CFPlus::Layout self, int indent) |
950 | CODE: |
964 | CODE: |
951 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
965 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
952 | |
966 | |
953 | void |
967 | void |
954 | set_spacing (CFClient::Layout self, int spacing) |
968 | set_spacing (CFPlus::Layout self, int spacing) |
955 | CODE: |
969 | CODE: |
956 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
970 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
957 | |
971 | |
958 | void |
972 | void |
959 | set_ellipsise (CFClient::Layout self, int ellipsise) |
973 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
960 | CODE: |
974 | CODE: |
961 | pango_layout_set_ellipsize (self->pl, |
975 | pango_layout_set_ellipsize (self->pl, |
962 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
976 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
963 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
977 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
964 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
978 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
965 | : PANGO_ELLIPSIZE_NONE |
979 | : PANGO_ELLIPSIZE_NONE |
966 | ); |
980 | ); |
967 | |
981 | |
968 | void |
982 | void |
969 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
983 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
970 | CODE: |
984 | CODE: |
971 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
985 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
972 | |
986 | |
973 | void |
987 | void |
974 | size (CFClient::Layout self) |
988 | size (CFPlus::Layout self) |
975 | PPCODE: |
989 | PPCODE: |
976 | { |
990 | { |
977 | int w, h; |
991 | int w, h; |
978 | |
992 | |
979 | layout_get_pixel_size (self, &w, &h); |
993 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
982 | PUSHs (sv_2mortal (newSViv (w))); |
996 | PUSHs (sv_2mortal (newSViv (w))); |
983 | PUSHs (sv_2mortal (newSViv (h))); |
997 | PUSHs (sv_2mortal (newSViv (h))); |
984 | } |
998 | } |
985 | |
999 | |
986 | int |
1000 | int |
987 | descent (CFClient::Layout self) |
1001 | descent (CFPlus::Layout self) |
988 | CODE: |
1002 | CODE: |
989 | { |
1003 | { |
990 | PangoRectangle rect; |
1004 | PangoRectangle rect; |
991 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1005 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
992 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1006 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
… | |
… | |
994 | } |
1008 | } |
995 | OUTPUT: |
1009 | OUTPUT: |
996 | RETVAL |
1010 | RETVAL |
997 | |
1011 | |
998 | int |
1012 | int |
999 | xy_to_index (CFClient::Layout self, int x, int y) |
1013 | xy_to_index (CFPlus::Layout self, int x, int y) |
1000 | CODE: |
1014 | CODE: |
1001 | { |
1015 | { |
1002 | int index, trailing; |
1016 | int index, trailing; |
1003 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1017 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1004 | RETVAL = index; |
1018 | RETVAL = index; |
1005 | } |
1019 | } |
1006 | OUTPUT: |
1020 | OUTPUT: |
1007 | RETVAL |
1021 | RETVAL |
1008 | |
1022 | |
1009 | void |
1023 | void |
1010 | cursor_pos (CFClient::Layout self, int index) |
1024 | cursor_pos (CFPlus::Layout self, int index) |
1011 | PPCODE: |
1025 | PPCODE: |
1012 | { |
1026 | { |
1013 | PangoRectangle strong_pos; |
1027 | PangoRectangle strong_pos; |
1014 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1028 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1015 | |
1029 | |
… | |
… | |
1018 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1032 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1019 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1033 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1020 | } |
1034 | } |
1021 | |
1035 | |
1022 | void |
1036 | void |
1023 | render (CFClient::Layout self, float x, float y) |
1037 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1024 | PPCODE: |
1038 | PPCODE: |
1025 | pango_opengl_render_layout_subpixel ( |
1039 | pango_opengl_render_layout_subpixel ( |
1026 | self->pl, |
1040 | self->pl, |
1027 | x * PANGO_SCALE, y * PANGO_SCALE, |
1041 | x * PANGO_SCALE, y * PANGO_SCALE, |
1028 | self->r, self->g, self->b, self->a |
1042 | self->r, self->g, self->b, self->a, |
|
|
1043 | flags |
1029 | ); |
1044 | ); |
1030 | |
1045 | |
1031 | MODULE = CFClient PACKAGE = CFClient::Texture |
1046 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1032 | |
1047 | |
1033 | void |
1048 | void |
1034 | pad2pot (SV *data_, SV *w_, SV *h_) |
1049 | pad2pot (SV *data_, SV *w_, SV *h_) |
1035 | CODE: |
1050 | CODE: |
1036 | { |
1051 | { |
… | |
… | |
1114 | glDisable (GL_ALPHA_TEST); |
1129 | glDisable (GL_ALPHA_TEST); |
1115 | glDisable (GL_BLEND); |
1130 | glDisable (GL_BLEND); |
1116 | } |
1131 | } |
1117 | } |
1132 | } |
1118 | |
1133 | |
1119 | MODULE = CFClient PACKAGE = CFClient::Map |
1134 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1120 | |
1135 | |
1121 | CFClient::Map |
1136 | CFPlus::Map |
1122 | new (SV *class, int map_width, int map_height) |
1137 | new (SV *class, int map_width, int map_height) |
1123 | CODE: |
1138 | CODE: |
1124 | New (0, RETVAL, 1, struct map); |
1139 | New (0, RETVAL, 1, struct map); |
1125 | RETVAL->x = 0; |
1140 | RETVAL->x = 0; |
1126 | RETVAL->y = 0; |
1141 | RETVAL->y = 0; |
… | |
… | |
1136 | RETVAL->row = 0; |
1151 | RETVAL->row = 0; |
1137 | OUTPUT: |
1152 | OUTPUT: |
1138 | RETVAL |
1153 | RETVAL |
1139 | |
1154 | |
1140 | void |
1155 | void |
1141 | DESTROY (CFClient::Map self) |
1156 | DESTROY (CFPlus::Map self) |
1142 | CODE: |
1157 | CODE: |
1143 | { |
1158 | { |
1144 | map_clear (self); |
1159 | map_clear (self); |
1145 | Safefree (self->face); |
1160 | Safefree (self->face); |
1146 | Safefree (self->tex); |
1161 | Safefree (self->tex); |
1147 | Safefree (self); |
1162 | Safefree (self); |
1148 | } |
1163 | } |
1149 | |
1164 | |
1150 | void |
1165 | void |
1151 | clear (CFClient::Map self) |
1166 | clear (CFPlus::Map self) |
1152 | CODE: |
1167 | CODE: |
1153 | map_clear (self); |
1168 | map_clear (self); |
1154 | |
1169 | |
1155 | void |
1170 | void |
1156 | set_face (CFClient::Map self, int face, int texid) |
1171 | set_face (CFPlus::Map self, int face, int texid) |
1157 | CODE: |
1172 | CODE: |
1158 | { |
1173 | { |
1159 | while (self->faces <= face) |
1174 | while (self->faces <= face) |
1160 | { |
1175 | { |
1161 | Append (mapface, self->face, self->faces, self->faces); |
1176 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1164 | |
1179 | |
1165 | self->face [face] = texid; |
1180 | self->face [face] = texid; |
1166 | } |
1181 | } |
1167 | |
1182 | |
1168 | void |
1183 | void |
1169 | set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1184 | set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1170 | CODE: |
1185 | CODE: |
1171 | { |
1186 | { |
1172 | while (self->texs <= texid) |
1187 | while (self->texs <= texid) |
1173 | { |
1188 | { |
1174 | Append (maptex, self->tex, self->texs, self->texs); |
1189 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1198 | // from transparent color bleeding and ugly wrapping effects. |
1213 | // from transparent color bleeding and ugly wrapping effects. |
1199 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1214 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1200 | } |
1215 | } |
1201 | |
1216 | |
1202 | int |
1217 | int |
1203 | ox (CFClient::Map self) |
1218 | ox (CFPlus::Map self) |
1204 | ALIAS: |
1219 | ALIAS: |
1205 | oy = 1 |
1220 | oy = 1 |
1206 | x = 2 |
1221 | x = 2 |
1207 | y = 3 |
1222 | y = 3 |
1208 | w = 4 |
1223 | w = 4 |
… | |
… | |
1219 | } |
1234 | } |
1220 | OUTPUT: |
1235 | OUTPUT: |
1221 | RETVAL |
1236 | RETVAL |
1222 | |
1237 | |
1223 | void |
1238 | void |
1224 | scroll (CFClient::Map self, int dx, int dy) |
1239 | scroll (CFPlus::Map self, int dx, int dy) |
1225 | CODE: |
1240 | CODE: |
1226 | { |
1241 | { |
1227 | if (dx > 0) |
1242 | if (dx > 0) |
1228 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1243 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1229 | else if (dx < 0) |
1244 | else if (dx < 0) |
… | |
… | |
1245 | self->y += MAP_EXTEND_Y; |
1260 | self->y += MAP_EXTEND_Y; |
1246 | } |
1261 | } |
1247 | } |
1262 | } |
1248 | |
1263 | |
1249 | void |
1264 | void |
1250 | map1a_update (CFClient::Map self, SV *data_) |
1265 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1251 | CODE: |
1266 | CODE: |
1252 | { |
1267 | { |
1253 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1268 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1254 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1269 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1255 | mapcell *cell; |
1270 | mapcell *cell; |
… | |
… | |
1272 | cell->face [0] = 0; |
1287 | cell->face [0] = 0; |
1273 | cell->face [1] = 0; |
1288 | cell->face [1] = 0; |
1274 | cell->face [2] = 0; |
1289 | cell->face [2] = 0; |
1275 | } |
1290 | } |
1276 | |
1291 | |
|
|
1292 | if (flags & 8) |
|
|
1293 | { |
|
|
1294 | fprintf (stderr, "oi\n");//D |
|
|
1295 | if (extmap) |
|
|
1296 | { |
|
|
1297 | uint8_t ext, cmd; |
|
|
1298 | |
|
|
1299 | do |
|
|
1300 | { |
|
|
1301 | |
|
|
1302 | ext = *data++; |
|
|
1303 | cmd = ext & 0x7f; |
|
|
1304 | |
|
|
1305 | fprintf (stderr, "extcmd = %x\n", ext);//D |
|
|
1306 | |
|
|
1307 | if (ext < 4) |
|
|
1308 | cell->darkness = 255 - ext * 64; |
|
|
1309 | } |
|
|
1310 | while (cmd & 0x80); |
|
|
1311 | } |
|
|
1312 | else |
1277 | cell->darkness = flags & 8 ? *data++ : 255; |
1313 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1314 | } |
1278 | |
1315 | |
1279 | //TODO: don't trust server data to be in-range(!) |
1316 | //TODO: don't trust server data to be in-range(!) |
1280 | |
1317 | |
1281 | if (flags & 4) |
1318 | if (flags & 4) |
1282 | { |
1319 | { |
… | |
… | |
1297 | cell->darkness = -1; |
1334 | cell->darkness = -1; |
1298 | } |
1335 | } |
1299 | } |
1336 | } |
1300 | |
1337 | |
1301 | SV * |
1338 | SV * |
1302 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
1339 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1303 | CODE: |
1340 | CODE: |
1304 | { |
1341 | { |
1305 | int x1, x; |
1342 | int x1, x; |
1306 | int y1, y; |
1343 | int y1, y; |
1307 | int z; |
1344 | int z; |
… | |
… | |
1357 | } |
1394 | } |
1358 | OUTPUT: |
1395 | OUTPUT: |
1359 | RETVAL |
1396 | RETVAL |
1360 | |
1397 | |
1361 | void |
1398 | void |
1362 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1399 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1363 | CODE: |
1400 | CODE: |
1364 | { |
1401 | { |
1365 | int vx, vy; |
1402 | int vx, vy; |
1366 | int x, y, z; |
1403 | int x, y, z; |
1367 | int last_name; |
1404 | int last_name; |
… | |
… | |
1432 | glDisable (GL_TEXTURE_2D); |
1469 | glDisable (GL_TEXTURE_2D); |
1433 | glDisable (GL_BLEND); |
1470 | glDisable (GL_BLEND); |
1434 | } |
1471 | } |
1435 | |
1472 | |
1436 | void |
1473 | void |
1437 | draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1474 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1438 | CODE: |
1475 | CODE: |
1439 | { |
1476 | { |
1440 | static float color[16][3] = { |
1477 | static float color[16][3] = { |
1441 | { 0.00F, 0.00F, 0.00F }, |
1478 | { 0.00F, 0.00F, 0.00F }, |
1442 | { 1.00F, 1.00F, 1.00F }, |
1479 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
1492 | glDisable (GL_BLEND); |
1529 | glDisable (GL_BLEND); |
1493 | glDisable (GL_TEXTURE_2D); |
1530 | glDisable (GL_TEXTURE_2D); |
1494 | } |
1531 | } |
1495 | |
1532 | |
1496 | void |
1533 | void |
1497 | fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1534 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1498 | PPCODE: |
1535 | PPCODE: |
1499 | { |
1536 | { |
1500 | int vx, vy; |
1537 | int vx, vy; |
1501 | int x, y; |
1538 | int x, y; |
1502 | int sw4 = (sw + 3) & ~3; |
1539 | int sw4 = (sw + 3) & ~3; |
… | |
… | |
1531 | PUSHs (sv_2mortal (newSViv (sh))); |
1568 | PUSHs (sv_2mortal (newSViv (sh))); |
1532 | PUSHs (darkness_sv); |
1569 | PUSHs (darkness_sv); |
1533 | } |
1570 | } |
1534 | |
1571 | |
1535 | SV * |
1572 | SV * |
1536 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
1573 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
1537 | CODE: |
1574 | CODE: |
1538 | { |
1575 | { |
1539 | int x, y, x1, y1; |
1576 | int x, y, x1, y1; |
1540 | SV *data_sv = newSV (w * h * 7 + 5); |
1577 | SV *data_sv = newSV (w * h * 7 + 5); |
1541 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1578 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1603 | } |
1640 | } |
1604 | OUTPUT: |
1641 | OUTPUT: |
1605 | RETVAL |
1642 | RETVAL |
1606 | |
1643 | |
1607 | void |
1644 | void |
1608 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
1645 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
1609 | PPCODE: |
1646 | PPCODE: |
1610 | { |
1647 | { |
1611 | int x, y, z; |
1648 | int x, y, z; |
1612 | int w, h; |
1649 | int w, h; |
1613 | int x1, y1; |
1650 | int x1, y1; |
… | |
… | |
1662 | } |
1699 | } |
1663 | } |
1700 | } |
1664 | } |
1701 | } |
1665 | } |
1702 | } |
1666 | |
1703 | |
1667 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1704 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1668 | |
1705 | |
1669 | CFClient::MixChunk |
1706 | CFPlus::MixChunk |
1670 | new_from_file (SV *class, char *path) |
1707 | new_from_file (SV *class, char *path) |
1671 | CODE: |
1708 | CODE: |
1672 | RETVAL = Mix_LoadWAV (path); |
1709 | RETVAL = Mix_LoadWAV (path); |
1673 | OUTPUT: |
1710 | OUTPUT: |
1674 | RETVAL |
1711 | RETVAL |
1675 | |
1712 | |
1676 | void |
1713 | void |
1677 | DESTROY (CFClient::MixChunk self) |
1714 | DESTROY (CFPlus::MixChunk self) |
1678 | CODE: |
1715 | CODE: |
1679 | Mix_FreeChunk (self); |
1716 | Mix_FreeChunk (self); |
1680 | |
1717 | |
1681 | int |
1718 | int |
1682 | volume (CFClient::MixChunk self, int volume = -1) |
1719 | volume (CFPlus::MixChunk self, int volume = -1) |
1683 | CODE: |
1720 | CODE: |
1684 | RETVAL = Mix_VolumeChunk (self, volume); |
1721 | RETVAL = Mix_VolumeChunk (self, volume); |
1685 | OUTPUT: |
1722 | OUTPUT: |
1686 | RETVAL |
1723 | RETVAL |
1687 | |
1724 | |
1688 | int |
1725 | int |
1689 | play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1726 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1690 | CODE: |
1727 | CODE: |
1691 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1728 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1692 | OUTPUT: |
1729 | OUTPUT: |
1693 | RETVAL |
1730 | RETVAL |
1694 | |
1731 | |
1695 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1732 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1696 | |
1733 | |
1697 | int |
1734 | int |
1698 | volume (int volume = -1) |
1735 | volume (int volume = -1) |
1699 | CODE: |
1736 | CODE: |
1700 | RETVAL = Mix_VolumeMusic (volume); |
1737 | RETVAL = Mix_VolumeMusic (volume); |
1701 | OUTPUT: |
1738 | OUTPUT: |
1702 | RETVAL |
1739 | RETVAL |
1703 | |
1740 | |
1704 | CFClient::MixMusic |
1741 | CFPlus::MixMusic |
1705 | new_from_file (SV *class, char *path) |
1742 | new_from_file (SV *class, char *path) |
1706 | CODE: |
1743 | CODE: |
1707 | RETVAL = Mix_LoadMUS (path); |
1744 | RETVAL = Mix_LoadMUS (path); |
1708 | OUTPUT: |
1745 | OUTPUT: |
1709 | RETVAL |
1746 | RETVAL |
1710 | |
1747 | |
1711 | void |
1748 | void |
1712 | DESTROY (CFClient::MixMusic self) |
1749 | DESTROY (CFPlus::MixMusic self) |
1713 | CODE: |
1750 | CODE: |
1714 | Mix_FreeMusic (self); |
1751 | Mix_FreeMusic (self); |
1715 | |
1752 | |
1716 | int |
1753 | int |
1717 | play (CFClient::MixMusic self, int loops = -1) |
1754 | play (CFPlus::MixMusic self, int loops = -1) |
1718 | CODE: |
1755 | CODE: |
1719 | RETVAL = Mix_PlayMusic (self, loops); |
1756 | RETVAL = Mix_PlayMusic (self, loops); |
1720 | OUTPUT: |
1757 | OUTPUT: |
1721 | RETVAL |
1758 | RETVAL |
1722 | |
1759 | |
1723 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1760 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1724 | |
1761 | |
1725 | BOOT: |
1762 | BOOT: |
1726 | { |
1763 | { |
1727 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1764 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1728 | static const struct { |
1765 | static const struct { |
1729 | const char *name; |
1766 | const char *name; |
1730 | IV iv; |
1767 | IV iv; |
1731 | } *civ, const_iv[] = { |
1768 | } *civ, const_iv[] = { |
1732 | # define const_iv(name) { # name, (IV)name } |
1769 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1795 | const_iv (GL_SEPARABLE_2D), |
1832 | const_iv (GL_SEPARABLE_2D), |
1796 | const_iv (GL_CONVOLUTION_2D), |
1833 | const_iv (GL_CONVOLUTION_2D), |
1797 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1834 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1798 | const_iv (GL_CONSTANT_BORDER), |
1835 | const_iv (GL_CONSTANT_BORDER), |
1799 | const_iv (GL_LINES), |
1836 | const_iv (GL_LINES), |
|
|
1837 | const_iv (GL_LINE_STRIP), |
1800 | const_iv (GL_LINE_LOOP), |
1838 | const_iv (GL_LINE_LOOP), |
1801 | const_iv (GL_QUADS), |
1839 | const_iv (GL_QUADS), |
1802 | const_iv (GL_QUAD_STRIP), |
1840 | const_iv (GL_QUAD_STRIP), |
1803 | const_iv (GL_TRIANGLES), |
1841 | const_iv (GL_TRIANGLES), |
1804 | const_iv (GL_TRIANGLE_STRIP), |
1842 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
2001 | |
2039 | |
2002 | void glEndList () |
2040 | void glEndList () |
2003 | |
2041 | |
2004 | void glCallList (int list) |
2042 | void glCallList (int list) |
2005 | |
2043 | |
2006 | |
|
|