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 |
52 | #define MAP_EXTEND_Y 512 |
55 | #define MAP_EXTEND_Y 512 |
53 | |
56 | |
54 | #define MIN_FONT_HEIGHT 10 |
57 | #define MIN_FONT_HEIGHT 10 |
55 | |
58 | |
56 | #if 1 |
59 | #if 0 |
57 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
60 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
58 | #else |
61 | #else |
59 | # define PARACHUTE 0 |
62 | # define PARACHUTE 0 |
60 | #endif |
63 | #endif |
61 | |
64 | |
… | |
… | |
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 { |
… | |
… | |
159 | float s, t; |
169 | float s, t; |
160 | uint8_t r, g, b, a; |
170 | uint8_t r, g, b, a; |
161 | } maptex; |
171 | } maptex; |
162 | |
172 | |
163 | typedef struct { |
173 | typedef struct { |
164 | int16_t darkness; |
174 | uint16_t darkness; |
165 | mapface face[3]; |
175 | mapface face[3]; |
|
|
176 | uint8_t stat_width, stat_hp; |
166 | } mapcell; |
177 | } mapcell; |
167 | |
178 | |
168 | typedef struct { |
179 | typedef struct { |
169 | int32_t c0, c1; |
180 | int32_t c0, c1; |
170 | mapcell *col; |
181 | mapcell *col; |
… | |
… | |
179 | int texs; |
190 | int texs; |
180 | maptex *tex; |
191 | maptex *tex; |
181 | |
192 | |
182 | int32_t rows; |
193 | int32_t rows; |
183 | maprow *row; |
194 | maprow *row; |
184 | } *CFClient__Map; |
195 | } *CFPlus__Map; |
185 | |
196 | |
186 | static char * |
197 | static char * |
187 | prepend (char *ptr, int sze, int inc) |
198 | prepend (char *ptr, int sze, int inc) |
188 | { |
199 | { |
189 | char *p; |
200 | char *p; |
… | |
… | |
207 | |
218 | |
208 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
219 | #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)) |
220 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
210 | |
221 | |
211 | static maprow * |
222 | static maprow * |
212 | map_get_row (CFClient__Map self, int y) |
223 | map_get_row (CFPlus__Map self, int y) |
213 | { |
224 | { |
214 | if (0 > y) |
225 | if (0 > y) |
215 | { |
226 | { |
216 | int extend = - y + MAP_EXTEND_Y; |
227 | int extend = - y + MAP_EXTEND_Y; |
217 | Prepend (maprow, self->row, self->rows, extend); |
228 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
255 | |
266 | |
256 | return row->col + (x - row->c0); |
267 | return row->col + (x - row->c0); |
257 | } |
268 | } |
258 | |
269 | |
259 | static mapcell * |
270 | static mapcell * |
260 | map_get_cell (CFClient__Map self, int x, int y) |
271 | map_get_cell (CFPlus__Map self, int x, int y) |
261 | { |
272 | { |
262 | return row_get_cell (map_get_row (self, y), x); |
273 | return row_get_cell (map_get_row (self, y), x); |
263 | } |
274 | } |
264 | |
275 | |
265 | static void |
276 | static void |
266 | map_clear (CFClient__Map self) |
277 | map_clear (CFPlus__Map self) |
267 | { |
278 | { |
268 | int r; |
279 | int r; |
269 | |
280 | |
270 | for (r = 0; r < self->rows; r++) |
281 | for (r = 0; r < self->rows; r++) |
271 | Safefree (self->row[r].col); |
282 | Safefree (self->row[r].col); |
… | |
… | |
279 | self->row = 0; |
290 | self->row = 0; |
280 | self->rows = 0; |
291 | self->rows = 0; |
281 | } |
292 | } |
282 | |
293 | |
283 | static void |
294 | static void |
284 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
295 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
285 | { |
296 | { |
286 | int x, y; |
297 | int x, y; |
287 | maprow *row; |
298 | maprow *row; |
|
|
299 | mapcell *cell; |
288 | |
300 | |
289 | for (y = y0; y < y0 + h; y++) |
301 | for (y = y0; y < y0 + h; y++) |
290 | if (y >= 0) |
302 | if (y >= 0) |
291 | { |
303 | { |
292 | if (y >= self->rows) |
304 | if (y >= self->rows) |
… | |
… | |
298 | if (x >= row->c0) |
310 | if (x >= row->c0) |
299 | { |
311 | { |
300 | if (x >= row->c1) |
312 | if (x >= row->c1) |
301 | break; |
313 | break; |
302 | |
314 | |
303 | row->col[x - row->c0].darkness = -1; |
315 | cell = row->col + x - row->c0; |
|
|
316 | |
|
|
317 | cell->darkness = 0; |
|
|
318 | cell->stat_hp = 0; |
304 | } |
319 | } |
305 | } |
320 | } |
306 | } |
321 | } |
307 | |
322 | |
308 | static void |
323 | static void |
… | |
… | |
346 | n |= n >> 16; |
361 | n |= n >> 16; |
347 | |
362 | |
348 | return n + 1; |
363 | return n + 1; |
349 | } |
364 | } |
350 | |
365 | |
351 | MODULE = CFClient PACKAGE = CFClient |
366 | MODULE = CFPlus PACKAGE = CFPlus |
352 | |
367 | |
353 | PROTOTYPES: ENABLE |
368 | PROTOTYPES: ENABLE |
354 | |
369 | |
355 | BOOT: |
370 | BOOT: |
356 | { |
371 | { |
357 | HV *stash = gv_stashpv ("CFClient", 1); |
372 | HV *stash = gv_stashpv ("CFPlus", 1); |
358 | static const struct { |
373 | static const struct { |
359 | const char *name; |
374 | const char *name; |
360 | IV iv; |
375 | IV iv; |
361 | } *civ, const_iv[] = { |
376 | } *civ, const_iv[] = { |
362 | # define const_iv(name) { # name, (IV)name } |
377 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
463 | |
478 | |
464 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
479 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
465 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
480 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
466 | } |
481 | } |
467 | |
482 | |
|
|
483 | int |
|
|
484 | in_destruct () |
|
|
485 | CODE: |
|
|
486 | RETVAL = PL_main_cv == Nullcv; |
|
|
487 | OUTPUT: |
|
|
488 | RETVAL |
|
|
489 | |
468 | NV floor (NV x) |
490 | NV floor (NV x) |
469 | |
491 | |
470 | NV ceil (NV x) |
492 | NV ceil (NV x) |
471 | |
493 | |
472 | void |
494 | void |
… | |
… | |
502 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
524 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
503 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
525 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
504 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
526 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
505 | |
527 | |
506 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
528 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
|
|
529 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
530 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
531 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
|
|
532 | #endif |
507 | |
533 | |
508 | SDL_EnableUNICODE (1); |
534 | SDL_EnableUNICODE (1); |
509 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
535 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
510 | |
536 | |
511 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
537 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
598 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
624 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
599 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
625 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
600 | break; |
626 | break; |
601 | } |
627 | } |
602 | |
628 | |
603 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
629 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
604 | } |
630 | } |
605 | } |
631 | } |
606 | |
632 | |
607 | int |
633 | int |
608 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
634 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
… | |
… | |
624 | #endif |
650 | #endif |
625 | |
651 | |
626 | void |
652 | void |
627 | add_font (char *file) |
653 | add_font (char *file) |
628 | CODE: |
654 | CODE: |
629 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
655 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
630 | |
656 | |
631 | void |
657 | void |
632 | load_image_inline (SV *image_) |
658 | load_image_inline (SV *image_) |
633 | ALIAS: |
659 | ALIAS: |
634 | load_image_file = 1 |
660 | load_image_file = 1 |
… | |
… | |
676 | |
702 | |
677 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
703 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
678 | |
704 | |
679 | assert (surface2->pitch == surface2->w * 4); |
705 | assert (surface2->pitch == surface2->w * 4); |
680 | |
706 | |
|
|
707 | SDL_LockSurface (surface2); |
681 | EXTEND (SP, 5); |
708 | EXTEND (SP, 6); |
682 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
709 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
683 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
710 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
684 | SDL_LockSurface (surface2); |
|
|
685 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
711 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
686 | SDL_UnlockSurface (surface2); |
|
|
687 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
712 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
688 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
713 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
689 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
714 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
|
|
715 | SDL_UnlockSurface (surface2); |
690 | |
716 | |
691 | SDL_FreeSurface (surface); |
717 | SDL_FreeSurface (surface); |
692 | SDL_FreeSurface (surface2); |
718 | SDL_FreeSurface (surface2); |
693 | } |
719 | } |
694 | |
720 | |
… | |
… | |
737 | void |
763 | void |
738 | _exit (int retval) |
764 | _exit (int retval) |
739 | CODE: |
765 | CODE: |
740 | _exit (retval); |
766 | _exit (retval); |
741 | |
767 | |
742 | MODULE = CFClient PACKAGE = CFClient::Font |
768 | MODULE = CFPlus PACKAGE = CFPlus::Font |
743 | |
769 | |
744 | CFClient::Font |
770 | CFPlus::Font |
745 | new_from_file (SV *class, char *path, int id = 0) |
771 | new_from_file (SV *class, char *path, int id = 0) |
746 | CODE: |
772 | CODE: |
747 | { |
773 | { |
748 | int count; |
774 | int count; |
749 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
775 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
752 | } |
778 | } |
753 | OUTPUT: |
779 | OUTPUT: |
754 | RETVAL |
780 | RETVAL |
755 | |
781 | |
756 | void |
782 | void |
757 | DESTROY (CFClient::Font self) |
783 | DESTROY (CFPlus::Font self) |
758 | CODE: |
784 | CODE: |
759 | pango_font_description_free (self); |
785 | pango_font_description_free (self); |
760 | |
786 | |
761 | void |
787 | void |
762 | make_default (CFClient::Font self) |
788 | make_default (CFPlus::Font self) |
763 | CODE: |
789 | CODE: |
764 | default_font = self; |
790 | default_font = self; |
765 | |
791 | |
766 | MODULE = CFClient PACKAGE = CFClient::Layout |
792 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
767 | |
793 | |
768 | void |
794 | void |
769 | clear_font_cache () |
795 | reset_glyph_cache () |
770 | CODE: |
796 | CODE: |
771 | pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap); |
|
|
772 | tc_clear (); |
797 | tc_clear (); |
773 | |
798 | |
774 | CFClient::Layout |
799 | CFPlus::Layout |
775 | new (SV *class, int type = 0) |
800 | new (SV *class) |
776 | CODE: |
801 | CODE: |
777 | New (0, RETVAL, 1, struct cf_layout); |
802 | New (0, RETVAL, 1, struct cf_layout); |
778 | |
803 | |
779 | RETVAL->pl = pango_layout_new (opengl_context); |
804 | RETVAL->pl = pango_layout_new (opengl_context); |
780 | RETVAL->r = 1.; |
805 | RETVAL->r = 1.; |
… | |
… | |
788 | layout_update_font (RETVAL); |
813 | layout_update_font (RETVAL); |
789 | OUTPUT: |
814 | OUTPUT: |
790 | RETVAL |
815 | RETVAL |
791 | |
816 | |
792 | void |
817 | void |
793 | DESTROY (CFClient::Layout self) |
818 | DESTROY (CFPlus::Layout self) |
794 | CODE: |
819 | CODE: |
795 | g_object_unref (self->pl); |
820 | g_object_unref (self->pl); |
796 | Safefree (self); |
821 | Safefree (self); |
797 | |
822 | |
798 | void |
823 | void |
799 | set_text (CFClient::Layout self, SV *text_) |
824 | set_text (CFPlus::Layout self, SV *text_) |
800 | CODE: |
825 | CODE: |
801 | { |
826 | { |
802 | STRLEN textlen; |
827 | STRLEN textlen; |
803 | char *text = SvPVutf8 (text_, textlen); |
828 | char *text = SvPVutf8 (text_, textlen); |
804 | |
829 | |
805 | pango_layout_set_text (self->pl, text, textlen); |
830 | pango_layout_set_text (self->pl, text, textlen); |
806 | } |
831 | } |
807 | |
832 | |
808 | void |
833 | void |
809 | set_markup (CFClient::Layout self, SV *text_) |
834 | set_markup (CFPlus::Layout self, SV *text_) |
810 | CODE: |
835 | CODE: |
811 | { |
836 | { |
812 | STRLEN textlen; |
837 | STRLEN textlen; |
813 | char *text = SvPVutf8 (text_, textlen); |
838 | char *text = SvPVutf8 (text_, textlen); |
814 | |
839 | |
815 | pango_layout_set_markup (self->pl, text, textlen); |
840 | pango_layout_set_markup (self->pl, text, textlen); |
816 | } |
841 | } |
817 | |
842 | |
818 | void |
843 | void |
819 | set_shapes (CFClient::Layout self, ...) |
844 | set_shapes (CFPlus::Layout self, ...) |
820 | CODE: |
845 | CODE: |
821 | { |
846 | { |
822 | PangoAttrList *attrs = 0; |
847 | PangoAttrList *attrs = 0; |
823 | const char *text = pango_layout_get_text (self->pl); |
848 | const char *text = pango_layout_get_text (self->pl); |
824 | const char *pos = text; |
849 | const char *pos = text; |
… | |
… | |
859 | if (attrs) |
884 | if (attrs) |
860 | pango_layout_set_attributes (self->pl, attrs); |
885 | pango_layout_set_attributes (self->pl, attrs); |
861 | } |
886 | } |
862 | |
887 | |
863 | void |
888 | void |
864 | get_shapes (CFClient::Layout self) |
889 | get_shapes (CFPlus::Layout self) |
865 | PPCODE: |
890 | PPCODE: |
866 | { |
891 | { |
867 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
892 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
868 | |
893 | |
869 | do |
894 | do |
… | |
… | |
873 | if (run && shape_attr_p (run)) |
898 | if (run && shape_attr_p (run)) |
874 | { |
899 | { |
875 | PangoRectangle extents; |
900 | PangoRectangle extents; |
876 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
901 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
877 | |
902 | |
|
|
903 | EXTEND (SP, 2); |
878 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
904 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
879 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
905 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
880 | } |
906 | } |
881 | } |
907 | } |
882 | while (pango_layout_iter_next_run (iter)); |
908 | while (pango_layout_iter_next_run (iter)); |
883 | |
909 | |
884 | pango_layout_iter_free (iter); |
910 | pango_layout_iter_free (iter); |
885 | } |
911 | } |
886 | |
912 | |
887 | int |
913 | int |
888 | has_wrapped (CFClient::Layout self) |
914 | has_wrapped (CFPlus::Layout self) |
889 | CODE: |
915 | CODE: |
890 | { |
916 | { |
891 | int lines = 1; |
917 | int lines = 1; |
892 | const char *text = pango_layout_get_text (self->pl); |
918 | const char *text = pango_layout_get_text (self->pl); |
893 | |
919 | |
… | |
… | |
898 | } |
924 | } |
899 | OUTPUT: |
925 | OUTPUT: |
900 | RETVAL |
926 | RETVAL |
901 | |
927 | |
902 | SV * |
928 | SV * |
903 | get_text (CFClient::Layout self) |
929 | get_text (CFPlus::Layout self) |
904 | CODE: |
930 | CODE: |
905 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
931 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
906 | sv_utf8_decode (RETVAL); |
932 | sv_utf8_decode (RETVAL); |
907 | OUTPUT: |
933 | OUTPUT: |
908 | RETVAL |
934 | RETVAL |
909 | |
935 | |
910 | void |
936 | void |
911 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
937 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
912 | CODE: |
938 | CODE: |
913 | self->r = r; |
939 | self->r = r; |
914 | self->g = g; |
940 | self->g = g; |
915 | self->b = b; |
941 | self->b = b; |
916 | self->a = a; |
942 | self->a = a; |
917 | |
943 | |
918 | void |
944 | void |
919 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
945 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
920 | CODE: |
946 | CODE: |
921 | if (self->font != font) |
947 | if (self->font != font) |
922 | { |
948 | { |
923 | self->font = font; |
949 | self->font = font; |
924 | layout_update_font (self); |
950 | layout_update_font (self); |
925 | } |
951 | } |
926 | |
952 | |
927 | void |
953 | void |
928 | set_height (CFClient::Layout self, int base_height) |
954 | set_height (CFPlus::Layout self, int base_height) |
929 | CODE: |
955 | CODE: |
930 | if (self->base_height != base_height) |
956 | if (self->base_height != base_height) |
931 | { |
957 | { |
932 | self->base_height = base_height; |
958 | self->base_height = base_height; |
933 | layout_update_font (self); |
959 | layout_update_font (self); |
934 | } |
960 | } |
935 | |
961 | |
936 | void |
962 | void |
937 | set_width (CFClient::Layout self, int max_width = -1) |
963 | set_width (CFPlus::Layout self, int max_width = -1) |
938 | CODE: |
964 | CODE: |
939 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
965 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
940 | |
966 | |
941 | void |
967 | void |
942 | set_indent (CFClient::Layout self, int indent) |
968 | set_indent (CFPlus::Layout self, int indent) |
943 | CODE: |
969 | CODE: |
944 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
970 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
945 | |
971 | |
946 | void |
972 | void |
947 | set_spacing (CFClient::Layout self, int spacing) |
973 | set_spacing (CFPlus::Layout self, int spacing) |
948 | CODE: |
974 | CODE: |
949 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
975 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
950 | |
976 | |
951 | void |
977 | void |
952 | set_ellipsise (CFClient::Layout self, int ellipsise) |
978 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
953 | CODE: |
979 | CODE: |
954 | pango_layout_set_ellipsize (self->pl, |
980 | pango_layout_set_ellipsize (self->pl, |
955 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
981 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
956 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
982 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
957 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
983 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
958 | : PANGO_ELLIPSIZE_NONE |
984 | : PANGO_ELLIPSIZE_NONE |
959 | ); |
985 | ); |
960 | |
986 | |
961 | void |
987 | void |
962 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
988 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
963 | CODE: |
989 | CODE: |
964 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
990 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
965 | |
991 | |
966 | void |
992 | void |
967 | size (CFClient::Layout self) |
993 | size (CFPlus::Layout self) |
968 | PPCODE: |
994 | PPCODE: |
969 | { |
995 | { |
970 | int w, h; |
996 | int w, h; |
971 | |
997 | |
972 | layout_get_pixel_size (self, &w, &h); |
998 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
975 | PUSHs (sv_2mortal (newSViv (w))); |
1001 | PUSHs (sv_2mortal (newSViv (w))); |
976 | PUSHs (sv_2mortal (newSViv (h))); |
1002 | PUSHs (sv_2mortal (newSViv (h))); |
977 | } |
1003 | } |
978 | |
1004 | |
979 | int |
1005 | int |
980 | descent (CFClient::Layout self) |
1006 | descent (CFPlus::Layout self) |
981 | CODE: |
1007 | CODE: |
982 | { |
1008 | { |
983 | PangoRectangle rect; |
1009 | PangoRectangle rect; |
984 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1010 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
985 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1011 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
… | |
… | |
987 | } |
1013 | } |
988 | OUTPUT: |
1014 | OUTPUT: |
989 | RETVAL |
1015 | RETVAL |
990 | |
1016 | |
991 | int |
1017 | int |
992 | xy_to_index (CFClient::Layout self, int x, int y) |
1018 | xy_to_index (CFPlus::Layout self, int x, int y) |
993 | CODE: |
1019 | CODE: |
994 | { |
1020 | { |
995 | int index, trailing; |
1021 | int index, trailing; |
996 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1022 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
997 | RETVAL = index; |
1023 | RETVAL = index; |
998 | } |
1024 | } |
999 | OUTPUT: |
1025 | OUTPUT: |
1000 | RETVAL |
1026 | RETVAL |
1001 | |
1027 | |
1002 | void |
1028 | void |
1003 | cursor_pos (CFClient::Layout self, int index) |
1029 | cursor_pos (CFPlus::Layout self, int index) |
1004 | PPCODE: |
1030 | PPCODE: |
1005 | { |
1031 | { |
1006 | PangoRectangle strong_pos; |
1032 | PangoRectangle strong_pos; |
1007 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1033 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1008 | |
1034 | |
… | |
… | |
1011 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1037 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1012 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1038 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1013 | } |
1039 | } |
1014 | |
1040 | |
1015 | void |
1041 | void |
1016 | render (CFClient::Layout self, float x, float y) |
1042 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1017 | PPCODE: |
1043 | PPCODE: |
1018 | pango_opengl_render_layout_subpixel ( |
1044 | pango_opengl_render_layout_subpixel ( |
1019 | self->pl, |
1045 | self->pl, |
1020 | x * PANGO_SCALE, y * PANGO_SCALE, |
1046 | x * PANGO_SCALE, y * PANGO_SCALE, |
1021 | self->r, self->g, self->b, self->a |
1047 | self->r, self->g, self->b, self->a, |
|
|
1048 | flags |
1022 | ); |
1049 | ); |
1023 | |
1050 | |
1024 | MODULE = CFClient PACKAGE = CFClient::Texture |
1051 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1025 | |
1052 | |
1026 | void |
1053 | void |
1027 | pad2pot (SV *data_, SV *w_, SV *h_) |
1054 | pad2pot (SV *data_, SV *w_, SV *h_) |
1028 | CODE: |
1055 | CODE: |
1029 | { |
1056 | { |
… | |
… | |
1107 | glDisable (GL_ALPHA_TEST); |
1134 | glDisable (GL_ALPHA_TEST); |
1108 | glDisable (GL_BLEND); |
1135 | glDisable (GL_BLEND); |
1109 | } |
1136 | } |
1110 | } |
1137 | } |
1111 | |
1138 | |
1112 | MODULE = CFClient PACKAGE = CFClient::Map |
1139 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1113 | |
1140 | |
1114 | CFClient::Map |
1141 | CFPlus::Map |
1115 | new (SV *class, int map_width, int map_height) |
1142 | new (SV *class, int map_width, int map_height) |
1116 | CODE: |
1143 | CODE: |
1117 | New (0, RETVAL, 1, struct map); |
1144 | New (0, RETVAL, 1, struct map); |
1118 | RETVAL->x = 0; |
1145 | RETVAL->x = 0; |
1119 | RETVAL->y = 0; |
1146 | RETVAL->y = 0; |
… | |
… | |
1129 | RETVAL->row = 0; |
1156 | RETVAL->row = 0; |
1130 | OUTPUT: |
1157 | OUTPUT: |
1131 | RETVAL |
1158 | RETVAL |
1132 | |
1159 | |
1133 | void |
1160 | void |
1134 | DESTROY (CFClient::Map self) |
1161 | DESTROY (CFPlus::Map self) |
1135 | CODE: |
1162 | CODE: |
1136 | { |
1163 | { |
1137 | map_clear (self); |
1164 | map_clear (self); |
1138 | Safefree (self->face); |
1165 | Safefree (self->face); |
1139 | Safefree (self->tex); |
1166 | Safefree (self->tex); |
1140 | Safefree (self); |
1167 | Safefree (self); |
1141 | } |
1168 | } |
1142 | |
1169 | |
1143 | void |
1170 | void |
1144 | clear (CFClient::Map self) |
1171 | clear (CFPlus::Map self) |
1145 | CODE: |
1172 | CODE: |
1146 | map_clear (self); |
1173 | map_clear (self); |
1147 | |
1174 | |
1148 | void |
1175 | void |
1149 | set_face (CFClient::Map self, int face, int texid) |
1176 | set_face (CFPlus::Map self, int face, int texid) |
1150 | CODE: |
1177 | CODE: |
1151 | { |
1178 | { |
1152 | while (self->faces <= face) |
1179 | while (self->faces <= face) |
1153 | { |
1180 | { |
1154 | Append (mapface, self->face, self->faces, self->faces); |
1181 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1157 | |
1184 | |
1158 | self->face [face] = texid; |
1185 | self->face [face] = texid; |
1159 | } |
1186 | } |
1160 | |
1187 | |
1161 | void |
1188 | void |
1162 | 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) |
1189 | 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) |
1163 | CODE: |
1190 | CODE: |
1164 | { |
1191 | { |
1165 | while (self->texs <= texid) |
1192 | while (self->texs <= texid) |
1166 | { |
1193 | { |
1167 | Append (maptex, self->tex, self->texs, self->texs); |
1194 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1191 | // from transparent color bleeding and ugly wrapping effects. |
1218 | // from transparent color bleeding and ugly wrapping effects. |
1192 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1219 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1193 | } |
1220 | } |
1194 | |
1221 | |
1195 | int |
1222 | int |
1196 | ox (CFClient::Map self) |
1223 | ox (CFPlus::Map self) |
1197 | ALIAS: |
1224 | ALIAS: |
1198 | oy = 1 |
1225 | oy = 1 |
1199 | x = 2 |
1226 | x = 2 |
1200 | y = 3 |
1227 | y = 3 |
1201 | w = 4 |
1228 | w = 4 |
… | |
… | |
1212 | } |
1239 | } |
1213 | OUTPUT: |
1240 | OUTPUT: |
1214 | RETVAL |
1241 | RETVAL |
1215 | |
1242 | |
1216 | void |
1243 | void |
1217 | scroll (CFClient::Map self, int dx, int dy) |
1244 | scroll (CFPlus::Map self, int dx, int dy) |
1218 | CODE: |
1245 | CODE: |
1219 | { |
1246 | { |
1220 | if (dx > 0) |
1247 | if (dx > 0) |
1221 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1248 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1222 | else if (dx < 0) |
1249 | else if (dx < 0) |
… | |
… | |
1238 | self->y += MAP_EXTEND_Y; |
1265 | self->y += MAP_EXTEND_Y; |
1239 | } |
1266 | } |
1240 | } |
1267 | } |
1241 | |
1268 | |
1242 | void |
1269 | void |
1243 | map1a_update (CFClient::Map self, SV *data_) |
1270 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1244 | CODE: |
1271 | CODE: |
1245 | { |
1272 | { |
1246 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1273 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1247 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1274 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1248 | mapcell *cell; |
1275 | mapcell *cell; |
… | |
… | |
1257 | |
1284 | |
1258 | cell = map_get_cell (self, x, y); |
1285 | cell = map_get_cell (self, x, y); |
1259 | |
1286 | |
1260 | if (flags & 15) |
1287 | if (flags & 15) |
1261 | { |
1288 | { |
1262 | if (cell->darkness < 0) |
1289 | if (!cell->darkness) |
1263 | { |
1290 | { |
1264 | cell->darkness = 0; |
1291 | cell->darkness = 256; |
1265 | cell->face [0] = 0; |
1292 | cell->face [0] = 0; |
1266 | cell->face [1] = 0; |
1293 | cell->face [1] = 0; |
1267 | cell->face [2] = 0; |
1294 | cell->face [2] = 0; |
1268 | } |
1295 | } |
1269 | |
1296 | |
1270 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1271 | |
|
|
1272 | //TODO: don't trust server data to be in-range(!) |
1297 | //TODO: don't trust server data to be in-range(!) |
|
|
1298 | |
|
|
1299 | if (flags & 8) |
|
|
1300 | { |
|
|
1301 | if (extmap) |
|
|
1302 | { |
|
|
1303 | uint8_t ext, cmd; |
|
|
1304 | |
|
|
1305 | do |
|
|
1306 | { |
|
|
1307 | ext = *data++; |
|
|
1308 | cmd = ext & 0x3f; |
|
|
1309 | |
|
|
1310 | if (cmd < 4) |
|
|
1311 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1312 | else if (cmd == 5) // health |
|
|
1313 | { |
|
|
1314 | cell->stat_width = 1; |
|
|
1315 | cell->stat_hp = *data++; |
|
|
1316 | } |
|
|
1317 | else if (cmd == 6) // monster width |
|
|
1318 | cell->stat_width = *data++ + 1; |
|
|
1319 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1320 | data += *data + 1; |
|
|
1321 | else |
|
|
1322 | data++; |
|
|
1323 | } |
|
|
1324 | while (ext & 0x80); |
|
|
1325 | } |
|
|
1326 | else |
|
|
1327 | cell->darkness = *data++ + 1; |
|
|
1328 | } |
1273 | |
1329 | |
1274 | if (flags & 4) |
1330 | if (flags & 4) |
1275 | { |
1331 | { |
1276 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1332 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1277 | } |
1333 | } |
… | |
… | |
1285 | { |
1341 | { |
1286 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1342 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1287 | } |
1343 | } |
1288 | } |
1344 | } |
1289 | else |
1345 | else |
|
|
1346 | { |
1290 | cell->darkness = -1; |
1347 | cell->darkness = 0; |
|
|
1348 | cell->stat_hp = 0; |
|
|
1349 | } |
1291 | } |
1350 | } |
1292 | } |
1351 | } |
1293 | |
1352 | |
1294 | SV * |
1353 | SV * |
1295 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
1354 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1296 | CODE: |
1355 | CODE: |
1297 | { |
1356 | { |
1298 | int x1, x; |
1357 | int x1, x; |
1299 | int y1, y; |
1358 | int y1, y; |
1300 | int z; |
1359 | int z; |
… | |
… | |
1350 | } |
1409 | } |
1351 | OUTPUT: |
1410 | OUTPUT: |
1352 | RETVAL |
1411 | RETVAL |
1353 | |
1412 | |
1354 | void |
1413 | void |
1355 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1414 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1356 | CODE: |
1415 | CODE: |
1357 | { |
1416 | { |
1358 | int vx, vy; |
1417 | int vx, vy; |
1359 | int x, y, z; |
1418 | int x, y, z; |
1360 | int last_name; |
1419 | int last_name; |
… | |
… | |
1395 | { |
1454 | { |
1396 | mapcell *cell = row->col + (x + vx - row->c0); |
1455 | mapcell *cell = row->col + (x + vx - row->c0); |
1397 | |
1456 | |
1398 | face = cell->face [z]; |
1457 | face = cell->face [z]; |
1399 | |
1458 | |
1400 | if (face) |
1459 | if (face && face < self->texs) |
1401 | { |
1460 | { |
1402 | maptex tex = self->tex [face]; |
1461 | maptex tex = self->tex [face]; |
1403 | |
1462 | |
1404 | int px = (x + 1) * 32 - tex.w; |
1463 | int px = (x + 1) * 32 - tex.w; |
1405 | int py = (y + 1) * 32 - tex.h; |
1464 | int py = (y + 1) * 32 - tex.h; |
… | |
… | |
1421 | } |
1480 | } |
1422 | |
1481 | |
1423 | glEnd (); |
1482 | glEnd (); |
1424 | |
1483 | |
1425 | glDisable (GL_TEXTURE_2D); |
1484 | glDisable (GL_TEXTURE_2D); |
|
|
1485 | |
|
|
1486 | // top layer: overlays such as the health bar |
|
|
1487 | for (y = 0; y < sh; y++) |
|
|
1488 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1489 | { |
|
|
1490 | maprow *row = self->row + (y + vy); |
|
|
1491 | |
|
|
1492 | for (x = 0; x < sw; x++) |
|
|
1493 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1494 | { |
|
|
1495 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1496 | |
|
|
1497 | int px = x * 32; |
|
|
1498 | int py = y * 32; |
|
|
1499 | |
|
|
1500 | if (cell->stat_hp) |
|
|
1501 | { |
|
|
1502 | int width = cell->stat_width * 32; |
|
|
1503 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1504 | |
|
|
1505 | glColor4ub (0, 0, 0, 127); |
|
|
1506 | glRectf (px + 1, py, |
|
|
1507 | px + width - 1, py + thick + 2); |
|
|
1508 | |
|
|
1509 | glColor4ub (cell->stat_hp, 255 - cell->stat_hp, 0, 255); |
|
|
1510 | glRectf (px + 2, |
|
|
1511 | py + 1, |
|
|
1512 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py + thick + 1); |
|
|
1513 | } |
|
|
1514 | } |
|
|
1515 | } |
|
|
1516 | |
1426 | glDisable (GL_BLEND); |
1517 | glDisable (GL_BLEND); |
1427 | } |
1518 | } |
1428 | |
1519 | |
1429 | void |
1520 | void |
1430 | draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1521 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1431 | CODE: |
1522 | CODE: |
1432 | { |
1523 | { |
1433 | static float color[16][3] = { |
1524 | static float color[16][3] = { |
1434 | { 0.00F, 0.00F, 0.00F }, |
1525 | { 0.00F, 0.00F, 0.00F }, |
1435 | { 1.00F, 1.00F, 1.00F }, |
1526 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
1485 | glDisable (GL_BLEND); |
1576 | glDisable (GL_BLEND); |
1486 | glDisable (GL_TEXTURE_2D); |
1577 | glDisable (GL_TEXTURE_2D); |
1487 | } |
1578 | } |
1488 | |
1579 | |
1489 | void |
1580 | void |
1490 | fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1581 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1491 | PPCODE: |
1582 | PPCODE: |
1492 | { |
1583 | { |
1493 | int vx, vy; |
1584 | int vx, vy; |
1494 | int x, y; |
1585 | int x, y; |
1495 | int sw4 = (sw + 3) & ~3; |
1586 | int sw4 = (sw + 3) & ~3; |
… | |
… | |
1511 | for (x = 0; x < sw; x++) |
1602 | for (x = 0; x < sw; x++) |
1512 | if (row->c0 <= x + vx && x + vx < row->c1) |
1603 | if (row->c0 <= x + vx && x + vx < row->c1) |
1513 | { |
1604 | { |
1514 | mapcell *cell = row->col + (x + vx - row->c0); |
1605 | mapcell *cell = row->col + (x + vx - row->c0); |
1515 | |
1606 | |
1516 | darkness[y * sw4 + x] = cell->darkness < 0 |
1607 | darkness[y * sw4 + x] = cell->darkness |
|
|
1608 | ? 255 - (cell->darkness - 1) |
1517 | ? 255 - FOW_DARKNESS |
1609 | : 255 - FOW_DARKNESS; |
1518 | : 255 - cell->darkness; |
|
|
1519 | } |
1610 | } |
1520 | } |
1611 | } |
1521 | |
1612 | |
1522 | EXTEND (SP, 3); |
1613 | EXTEND (SP, 3); |
1523 | PUSHs (sv_2mortal (newSViv (sw4))); |
1614 | PUSHs (sv_2mortal (newSViv (sw4))); |
1524 | PUSHs (sv_2mortal (newSViv (sh))); |
1615 | PUSHs (sv_2mortal (newSViv (sh))); |
1525 | PUSHs (darkness_sv); |
1616 | PUSHs (darkness_sv); |
1526 | } |
1617 | } |
1527 | |
1618 | |
1528 | SV * |
1619 | SV * |
1529 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
1620 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
1530 | CODE: |
1621 | CODE: |
1531 | { |
1622 | { |
1532 | int x, y, x1, y1; |
1623 | int x, y, x1, y1; |
1533 | SV *data_sv = newSV (w * h * 7 + 5); |
1624 | SV *data_sv = newSV (w * h * 7 + 5); |
1534 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1625 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1596 | } |
1687 | } |
1597 | OUTPUT: |
1688 | OUTPUT: |
1598 | RETVAL |
1689 | RETVAL |
1599 | |
1690 | |
1600 | void |
1691 | void |
1601 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
1692 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
1602 | PPCODE: |
1693 | PPCODE: |
1603 | { |
1694 | { |
1604 | int x, y, z; |
1695 | int x, y, z; |
1605 | int w, h; |
1696 | int w, h; |
1606 | int x1, y1; |
1697 | int x1, y1; |
… | |
… | |
1638 | |
1729 | |
1639 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1730 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1640 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1731 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1641 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1732 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1642 | |
1733 | |
1643 | if (cell->darkness <= 0) |
1734 | if (cell->darkness == 0) |
1644 | { |
1735 | { |
1645 | cell->darkness = -1; |
1736 | cell->darkness = 0; |
1646 | |
1737 | |
1647 | for (z = 0; z <= 2; z++) |
1738 | for (z = 0; z <= 2; z++) |
1648 | { |
1739 | { |
1649 | cell->face[z] = face[z]; |
1740 | cell->face[z] = face[z]; |
1650 | |
1741 | |
… | |
… | |
1655 | } |
1746 | } |
1656 | } |
1747 | } |
1657 | } |
1748 | } |
1658 | } |
1749 | } |
1659 | |
1750 | |
1660 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1751 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1661 | |
1752 | |
1662 | CFClient::MixChunk |
1753 | CFPlus::MixChunk |
1663 | new_from_file (SV *class, char *path) |
1754 | new_from_file (SV *class, char *path) |
1664 | CODE: |
1755 | CODE: |
1665 | RETVAL = Mix_LoadWAV (path); |
1756 | RETVAL = Mix_LoadWAV (path); |
1666 | OUTPUT: |
1757 | OUTPUT: |
1667 | RETVAL |
1758 | RETVAL |
1668 | |
1759 | |
1669 | void |
1760 | void |
1670 | DESTROY (CFClient::MixChunk self) |
1761 | DESTROY (CFPlus::MixChunk self) |
1671 | CODE: |
1762 | CODE: |
1672 | Mix_FreeChunk (self); |
1763 | Mix_FreeChunk (self); |
1673 | |
1764 | |
1674 | int |
1765 | int |
1675 | volume (CFClient::MixChunk self, int volume = -1) |
1766 | volume (CFPlus::MixChunk self, int volume = -1) |
1676 | CODE: |
1767 | CODE: |
1677 | RETVAL = Mix_VolumeChunk (self, volume); |
1768 | RETVAL = Mix_VolumeChunk (self, volume); |
1678 | OUTPUT: |
1769 | OUTPUT: |
1679 | RETVAL |
1770 | RETVAL |
1680 | |
1771 | |
1681 | int |
1772 | int |
1682 | play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1773 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1683 | CODE: |
1774 | CODE: |
1684 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1775 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1685 | OUTPUT: |
1776 | OUTPUT: |
1686 | RETVAL |
1777 | RETVAL |
1687 | |
1778 | |
1688 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1779 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1689 | |
1780 | |
1690 | int |
1781 | int |
1691 | volume (int volume = -1) |
1782 | volume (int volume = -1) |
1692 | CODE: |
1783 | CODE: |
1693 | RETVAL = Mix_VolumeMusic (volume); |
1784 | RETVAL = Mix_VolumeMusic (volume); |
1694 | OUTPUT: |
1785 | OUTPUT: |
1695 | RETVAL |
1786 | RETVAL |
1696 | |
1787 | |
1697 | CFClient::MixMusic |
1788 | CFPlus::MixMusic |
1698 | new_from_file (SV *class, char *path) |
1789 | new_from_file (SV *class, char *path) |
1699 | CODE: |
1790 | CODE: |
1700 | RETVAL = Mix_LoadMUS (path); |
1791 | RETVAL = Mix_LoadMUS (path); |
1701 | OUTPUT: |
1792 | OUTPUT: |
1702 | RETVAL |
1793 | RETVAL |
1703 | |
1794 | |
1704 | void |
1795 | void |
1705 | DESTROY (CFClient::MixMusic self) |
1796 | DESTROY (CFPlus::MixMusic self) |
1706 | CODE: |
1797 | CODE: |
1707 | Mix_FreeMusic (self); |
1798 | Mix_FreeMusic (self); |
1708 | |
1799 | |
1709 | int |
1800 | int |
1710 | play (CFClient::MixMusic self, int loops = -1) |
1801 | play (CFPlus::MixMusic self, int loops = -1) |
1711 | CODE: |
1802 | CODE: |
1712 | RETVAL = Mix_PlayMusic (self, loops); |
1803 | RETVAL = Mix_PlayMusic (self, loops); |
1713 | OUTPUT: |
1804 | OUTPUT: |
1714 | RETVAL |
1805 | RETVAL |
1715 | |
1806 | |
1716 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1807 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1717 | |
1808 | |
1718 | BOOT: |
1809 | BOOT: |
1719 | { |
1810 | { |
1720 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1811 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1721 | static const struct { |
1812 | static const struct { |
1722 | const char *name; |
1813 | const char *name; |
1723 | IV iv; |
1814 | IV iv; |
1724 | } *civ, const_iv[] = { |
1815 | } *civ, const_iv[] = { |
1725 | # define const_iv(name) { # name, (IV)name } |
1816 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1788 | const_iv (GL_SEPARABLE_2D), |
1879 | const_iv (GL_SEPARABLE_2D), |
1789 | const_iv (GL_CONVOLUTION_2D), |
1880 | const_iv (GL_CONVOLUTION_2D), |
1790 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1881 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1791 | const_iv (GL_CONSTANT_BORDER), |
1882 | const_iv (GL_CONSTANT_BORDER), |
1792 | const_iv (GL_LINES), |
1883 | const_iv (GL_LINES), |
|
|
1884 | const_iv (GL_LINE_STRIP), |
1793 | const_iv (GL_LINE_LOOP), |
1885 | const_iv (GL_LINE_LOOP), |
1794 | const_iv (GL_QUADS), |
1886 | const_iv (GL_QUADS), |
1795 | const_iv (GL_QUAD_STRIP), |
1887 | const_iv (GL_QUAD_STRIP), |
1796 | const_iv (GL_TRIANGLES), |
1888 | const_iv (GL_TRIANGLES), |
1797 | const_iv (GL_TRIANGLE_STRIP), |
1889 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1907 | r *= a; |
1999 | r *= a; |
1908 | g *= a; |
2000 | g *= a; |
1909 | b *= a; |
2001 | b *= a; |
1910 | } |
2002 | } |
1911 | // microsoft visual "c" rounds instead of truncating... |
2003 | // microsoft visual "c" rounds instead of truncating... |
1912 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2004 | glColor4f (r, g, b, a); |
1913 | MIN ((int)(g * 256.f), 255), |
|
|
1914 | MIN ((int)(b * 256.f), 255), |
|
|
1915 | MIN ((int)(a * 256.f), 255)); |
|
|
1916 | |
2005 | |
1917 | void glInterleavedArrays (int format, int stride, char *data) |
2006 | void glInterleavedArrays (int format, int stride, char *data) |
1918 | |
2007 | |
1919 | void glDrawElements (int mode, int count, int type, char *indices) |
2008 | void glDrawElements (int mode, int count, int type, char *indices) |
1920 | |
2009 | |
… | |
… | |
1997 | |
2086 | |
1998 | void glEndList () |
2087 | void glEndList () |
1999 | |
2088 | |
2000 | void glCallList (int list) |
2089 | void glCallList (int list) |
2001 | |
2090 | |
2002 | |
|
|