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> |
|
|
6 | # include <wininet.h> |
5 | # pragma warning(disable:4244) |
7 | # pragma warning(disable:4244) |
6 | #endif |
8 | #endif |
7 | |
9 | |
8 | #include "EXTERN.h" |
10 | #include "EXTERN.h" |
9 | #include "perl.h" |
11 | #include "perl.h" |
10 | #include "XSUB.h" |
12 | #include "XSUB.h" |
|
|
13 | |
|
|
14 | #ifdef _WIN32 |
|
|
15 | # undef pipe |
|
|
16 | #endif |
11 | |
17 | |
12 | #include <math.h> |
18 | #include <math.h> |
13 | #include <string.h> |
19 | #include <string.h> |
14 | #include <stdio.h> |
20 | #include <stdio.h> |
15 | #include <stdlib.h> |
21 | #include <stdlib.h> |
… | |
… | |
40 | typedef signed char int8_t; |
46 | typedef signed char int8_t; |
41 | typedef signed short int16_t; |
47 | typedef signed short int16_t; |
42 | typedef signed int int32_t; |
48 | typedef signed int int32_t; |
43 | #endif |
49 | #endif |
44 | |
50 | |
45 | #include "glext.h" |
|
|
46 | |
|
|
47 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
51 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
48 | |
52 | |
49 | #define FOW_DARKNESS 32 |
53 | #define FOW_DARKNESS 32 |
50 | |
54 | |
51 | #define MAP_EXTEND_X 32 |
55 | #define MAP_EXTEND_X 32 |
52 | #define MAP_EXTEND_Y 512 |
56 | #define MAP_EXTEND_Y 512 |
53 | |
57 | |
54 | #define MIN_FONT_HEIGHT 10 |
58 | #define MIN_FONT_HEIGHT 10 |
55 | |
59 | |
56 | #if 1 |
60 | #if 0 |
57 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
61 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
58 | #else |
62 | #else |
59 | # define PARACHUTE 0 |
63 | # define PARACHUTE 0 |
60 | #endif |
64 | #endif |
61 | |
65 | |
… | |
… | |
80 | |
84 | |
81 | #include "pango-font.c" |
85 | #include "pango-font.c" |
82 | #include "pango-fontmap.c" |
86 | #include "pango-fontmap.c" |
83 | #include "pango-render.c" |
87 | #include "pango-render.c" |
84 | |
88 | |
85 | typedef Mix_Chunk *CFClient__MixChunk; |
89 | typedef Mix_Chunk *CFPlus__MixChunk; |
86 | typedef Mix_Music *CFClient__MixMusic; |
90 | typedef Mix_Music *CFPlus__MixMusic; |
87 | |
91 | |
88 | typedef PangoFontDescription *CFClient__Font; |
92 | typedef PangoFontDescription *CFPlus__Font; |
89 | |
93 | |
90 | static int |
94 | static int |
91 | shape_attr_p (PangoLayoutRun *run) |
95 | shape_attr_p (PangoLayoutRun *run) |
92 | { |
96 | { |
93 | GSList *attrs = run->item->analysis.extra_attrs; |
97 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
107 | |
111 | |
108 | typedef struct cf_layout { |
112 | typedef struct cf_layout { |
109 | PangoLayout *pl; |
113 | PangoLayout *pl; |
110 | float r, g, b, a; // default color for rgba mode |
114 | float r, g, b, a; // default color for rgba mode |
111 | int base_height; |
115 | int base_height; |
112 | CFClient__Font font; |
116 | CFPlus__Font font; |
113 | } *CFClient__Layout; |
117 | } *CFPlus__Layout; |
114 | |
118 | |
115 | static CFClient__Font default_font; |
119 | static CFPlus__Font default_font; |
116 | static PangoContext *opengl_context; |
120 | static PangoContext *opengl_context; |
117 | static PangoFontMap *opengl_fontmap; |
121 | static PangoFontMap *opengl_fontmap; |
118 | |
122 | |
119 | static void |
123 | static void |
120 | substitute_func (FcPattern *pattern, gpointer data) |
124 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
125 | #endif |
129 | #endif |
126 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
130 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
127 | } |
131 | } |
128 | |
132 | |
129 | static void |
133 | static void |
130 | layout_update_font (CFClient__Layout self) |
134 | layout_update_font (CFPlus__Layout self) |
131 | { |
135 | { |
132 | /* use a random scale factor to account for unknown descenders, 0.8 works |
136 | /* use a random scale factor to account for unknown descenders, 0.8 works |
133 | * reasonably well with bitstream vera |
137 | * reasonably well with bitstream vera |
134 | */ |
138 | */ |
135 | PangoFontDescription *font = self->font ? self->font : default_font; |
139 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
139 | |
143 | |
140 | pango_layout_set_font_description (self->pl, font); |
144 | pango_layout_set_font_description (self->pl, font); |
141 | } |
145 | } |
142 | |
146 | |
143 | static void |
147 | static void |
144 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
148 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
145 | { |
149 | { |
|
|
150 | PangoRectangle rect; |
|
|
151 | |
|
|
152 | // get_pixel_* wrongly rounds down |
146 | pango_layout_get_pixel_size (self->pl, w, h); |
153 | pango_layout_get_extents (self->pl, 0, &rect); |
147 | |
154 | |
148 | if (!*w) *w = 1; |
155 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
149 | if (!*h) *h = 1; |
156 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
150 | |
157 | |
151 | *w = (*w + 3) & ~3; |
158 | if (!rect.width) rect.width = 1; |
|
|
159 | if (!rect.height) rect.height = 1; |
|
|
160 | |
|
|
161 | *w = rect.width; |
|
|
162 | *h = rect.height; |
152 | } |
163 | } |
153 | |
164 | |
154 | typedef uint16_t mapface; |
165 | typedef uint16_t mapface; |
155 | |
166 | |
156 | typedef struct { |
167 | typedef struct { |
… | |
… | |
159 | float s, t; |
170 | float s, t; |
160 | uint8_t r, g, b, a; |
171 | uint8_t r, g, b, a; |
161 | } maptex; |
172 | } maptex; |
162 | |
173 | |
163 | typedef struct { |
174 | typedef struct { |
164 | int16_t darkness; |
175 | uint32_t player; |
165 | mapface face[3]; |
176 | mapface face[3]; |
|
|
177 | uint16_t darkness; |
|
|
178 | uint8_t stat_width, stat_hp, flags; |
166 | } mapcell; |
179 | } mapcell; |
167 | |
180 | |
168 | typedef struct { |
181 | typedef struct { |
169 | int32_t c0, c1; |
182 | int32_t c0, c1; |
170 | mapcell *col; |
183 | mapcell *col; |
… | |
… | |
179 | int texs; |
192 | int texs; |
180 | maptex *tex; |
193 | maptex *tex; |
181 | |
194 | |
182 | int32_t rows; |
195 | int32_t rows; |
183 | maprow *row; |
196 | maprow *row; |
184 | } *CFClient__Map; |
197 | } *CFPlus__Map; |
185 | |
198 | |
186 | static char * |
199 | static char * |
187 | prepend (char *ptr, int sze, int inc) |
200 | prepend (char *ptr, int sze, int inc) |
188 | { |
201 | { |
189 | char *p; |
202 | char *p; |
… | |
… | |
207 | |
220 | |
208 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
221 | #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)) |
222 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
210 | |
223 | |
211 | static maprow * |
224 | static maprow * |
212 | map_get_row (CFClient__Map self, int y) |
225 | map_get_row (CFPlus__Map self, int y) |
213 | { |
226 | { |
214 | if (0 > y) |
227 | if (0 > y) |
215 | { |
228 | { |
216 | int extend = - y + MAP_EXTEND_Y; |
229 | int extend = - y + MAP_EXTEND_Y; |
217 | Prepend (maprow, self->row, self->rows, extend); |
230 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
255 | |
268 | |
256 | return row->col + (x - row->c0); |
269 | return row->col + (x - row->c0); |
257 | } |
270 | } |
258 | |
271 | |
259 | static mapcell * |
272 | static mapcell * |
260 | map_get_cell (CFClient__Map self, int x, int y) |
273 | map_get_cell (CFPlus__Map self, int x, int y) |
261 | { |
274 | { |
262 | return row_get_cell (map_get_row (self, y), x); |
275 | return row_get_cell (map_get_row (self, y), x); |
263 | } |
276 | } |
264 | |
277 | |
265 | static void |
278 | static void |
266 | map_clear (CFClient__Map self) |
279 | map_clear (CFPlus__Map self) |
267 | { |
280 | { |
268 | int r; |
281 | int r; |
269 | |
282 | |
270 | for (r = 0; r < self->rows; r++) |
283 | for (r = 0; r < self->rows; r++) |
271 | Safefree (self->row[r].col); |
284 | Safefree (self->row[r].col); |
… | |
… | |
279 | self->row = 0; |
292 | self->row = 0; |
280 | self->rows = 0; |
293 | self->rows = 0; |
281 | } |
294 | } |
282 | |
295 | |
283 | static void |
296 | static void |
284 | map_blank (CFClient__Map self, int x0, int y0, int w, int h) |
297 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
285 | { |
298 | { |
286 | int x, y; |
299 | int x, y; |
287 | maprow *row; |
300 | maprow *row; |
|
|
301 | mapcell *cell; |
288 | |
302 | |
289 | for (y = y0; y < y0 + h; y++) |
303 | for (y = y0; y < y0 + h; y++) |
290 | if (y >= 0) |
304 | if (y >= 0) |
291 | { |
305 | { |
292 | if (y >= self->rows) |
306 | if (y >= self->rows) |
… | |
… | |
298 | if (x >= row->c0) |
312 | if (x >= row->c0) |
299 | { |
313 | { |
300 | if (x >= row->c1) |
314 | if (x >= row->c1) |
301 | break; |
315 | break; |
302 | |
316 | |
303 | row->col[x - row->c0].darkness = -1; |
317 | cell = row->col + x - row->c0; |
|
|
318 | |
|
|
319 | cell->darkness = 0; |
|
|
320 | cell->stat_hp = 0; |
|
|
321 | cell->flags = 0; |
|
|
322 | cell->player = 0; |
304 | } |
323 | } |
305 | } |
324 | } |
306 | } |
325 | } |
307 | |
326 | |
308 | static void |
327 | static void |
… | |
… | |
346 | n |= n >> 16; |
365 | n |= n >> 16; |
347 | |
366 | |
348 | return n + 1; |
367 | return n + 1; |
349 | } |
368 | } |
350 | |
369 | |
351 | MODULE = CFClient PACKAGE = CFClient |
370 | MODULE = CFPlus PACKAGE = CFPlus |
352 | |
371 | |
353 | PROTOTYPES: ENABLE |
372 | PROTOTYPES: ENABLE |
354 | |
373 | |
355 | BOOT: |
374 | BOOT: |
356 | { |
375 | { |
357 | HV *stash = gv_stashpv ("CFClient", 1); |
376 | HV *stash = gv_stashpv ("CFPlus", 1); |
358 | static const struct { |
377 | static const struct { |
359 | const char *name; |
378 | const char *name; |
360 | IV iv; |
379 | IV iv; |
361 | } *civ, const_iv[] = { |
380 | } *civ, const_iv[] = { |
362 | # define const_iv(name) { # name, (IV)name } |
381 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
463 | |
482 | |
464 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
483 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
465 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
484 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
466 | } |
485 | } |
467 | |
486 | |
|
|
487 | int |
|
|
488 | in_destruct () |
|
|
489 | CODE: |
|
|
490 | RETVAL = PL_main_cv == Nullcv; |
|
|
491 | OUTPUT: |
|
|
492 | RETVAL |
|
|
493 | |
468 | NV floor (NV x) |
494 | NV floor (NV x) |
469 | |
495 | |
470 | NV ceil (NV x) |
496 | NV ceil (NV x) |
471 | |
497 | |
472 | void |
498 | void |
… | |
… | |
502 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
528 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
503 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
529 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
504 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
530 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
505 | |
531 | |
506 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
532 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
|
|
533 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
534 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
535 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
|
|
536 | #endif |
507 | |
537 | |
508 | SDL_EnableUNICODE (1); |
538 | SDL_EnableUNICODE (1); |
509 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
539 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
510 | |
540 | |
511 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
541 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
598 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
628 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
599 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
629 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
600 | break; |
630 | break; |
601 | } |
631 | } |
602 | |
632 | |
603 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
633 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
604 | } |
634 | } |
605 | } |
635 | } |
606 | |
636 | |
607 | int |
637 | int |
608 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
638 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
… | |
… | |
622 | #ifndef _WIN32 |
652 | #ifndef _WIN32 |
623 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
624 | #endif |
654 | #endif |
625 | |
655 | |
626 | void |
656 | void |
|
|
657 | win32_proxy_info () |
|
|
658 | PPCODE: |
|
|
659 | { |
|
|
660 | #ifdef _WIN32 |
|
|
661 | char buffer[2048]; |
|
|
662 | DWORD buflen; |
|
|
663 | |
|
|
664 | EXTEND (SP, 3); |
|
|
665 | |
|
|
666 | buflen = sizeof (buffer); |
|
|
667 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
668 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
669 | { |
|
|
670 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
671 | |
|
|
672 | buflen = sizeof (buffer); |
|
|
673 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
674 | { |
|
|
675 | PUSHs (newSVpv (buffer, 0)); |
|
|
676 | |
|
|
677 | buflen = sizeof (buffer); |
|
|
678 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
679 | PUSHs (newSVpv (buffer, 0)); |
|
|
680 | } |
|
|
681 | } |
|
|
682 | #endif |
|
|
683 | } |
|
|
684 | |
|
|
685 | void |
627 | add_font (char *file) |
686 | add_font (char *file) |
628 | CODE: |
687 | CODE: |
629 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
688 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
630 | |
689 | |
631 | void |
690 | void |
632 | load_image_inline (SV *image_) |
691 | load_image_inline (SV *image_) |
633 | ALIAS: |
692 | ALIAS: |
634 | load_image_file = 1 |
693 | load_image_file = 1 |
… | |
… | |
676 | |
735 | |
677 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
736 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
678 | |
737 | |
679 | assert (surface2->pitch == surface2->w * 4); |
738 | assert (surface2->pitch == surface2->w * 4); |
680 | |
739 | |
|
|
740 | SDL_LockSurface (surface2); |
681 | EXTEND (SP, 5); |
741 | EXTEND (SP, 6); |
682 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
742 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
683 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
743 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
684 | SDL_LockSurface (surface2); |
|
|
685 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
744 | 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))); |
745 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
688 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
746 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
689 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
747 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
|
|
748 | SDL_UnlockSurface (surface2); |
690 | |
749 | |
691 | SDL_FreeSurface (surface); |
750 | SDL_FreeSurface (surface); |
692 | SDL_FreeSurface (surface2); |
751 | SDL_FreeSurface (surface2); |
693 | } |
752 | } |
694 | |
753 | |
… | |
… | |
733 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
792 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
734 | #endif |
793 | #endif |
735 | _exit (1); |
794 | _exit (1); |
736 | |
795 | |
737 | void |
796 | void |
738 | _exit (int retval) |
797 | _exit (int retval = 0) |
739 | CODE: |
798 | CODE: |
740 | _exit (retval); |
799 | _exit (retval); |
741 | |
800 | |
742 | MODULE = CFClient PACKAGE = CFClient::Font |
801 | MODULE = CFPlus PACKAGE = CFPlus::Font |
743 | |
802 | |
744 | CFClient::Font |
803 | CFPlus::Font |
745 | new_from_file (SV *class, char *path, int id = 0) |
804 | new_from_file (SV *class, char *path, int id = 0) |
746 | CODE: |
805 | CODE: |
747 | { |
806 | { |
748 | int count; |
807 | int count; |
749 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
808 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
752 | } |
811 | } |
753 | OUTPUT: |
812 | OUTPUT: |
754 | RETVAL |
813 | RETVAL |
755 | |
814 | |
756 | void |
815 | void |
757 | DESTROY (CFClient::Font self) |
816 | DESTROY (CFPlus::Font self) |
758 | CODE: |
817 | CODE: |
759 | pango_font_description_free (self); |
818 | pango_font_description_free (self); |
760 | |
819 | |
761 | void |
820 | void |
762 | make_default (CFClient::Font self) |
821 | make_default (CFPlus::Font self) |
763 | CODE: |
822 | CODE: |
764 | default_font = self; |
823 | default_font = self; |
765 | |
824 | |
766 | MODULE = CFClient PACKAGE = CFClient::Layout |
825 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
767 | |
826 | |
768 | void |
827 | void |
769 | clear_font_cache () |
828 | reset_glyph_cache () |
770 | CODE: |
829 | CODE: |
771 | pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap); |
|
|
772 | tc_clear (); |
830 | tc_clear (); |
773 | |
831 | |
774 | CFClient::Layout |
832 | CFPlus::Layout |
775 | new (SV *class, int type = 0) |
833 | new (SV *class) |
776 | CODE: |
834 | CODE: |
777 | New (0, RETVAL, 1, struct cf_layout); |
835 | New (0, RETVAL, 1, struct cf_layout); |
778 | |
836 | |
779 | RETVAL->pl = pango_layout_new (opengl_context); |
837 | RETVAL->pl = pango_layout_new (opengl_context); |
780 | RETVAL->r = 1.; |
838 | RETVAL->r = 1.; |
… | |
… | |
788 | layout_update_font (RETVAL); |
846 | layout_update_font (RETVAL); |
789 | OUTPUT: |
847 | OUTPUT: |
790 | RETVAL |
848 | RETVAL |
791 | |
849 | |
792 | void |
850 | void |
793 | DESTROY (CFClient::Layout self) |
851 | DESTROY (CFPlus::Layout self) |
794 | CODE: |
852 | CODE: |
795 | g_object_unref (self->pl); |
853 | g_object_unref (self->pl); |
796 | Safefree (self); |
854 | Safefree (self); |
797 | |
855 | |
798 | void |
856 | void |
799 | set_text (CFClient::Layout self, SV *text_) |
857 | set_text (CFPlus::Layout self, SV *text_) |
800 | CODE: |
858 | CODE: |
801 | { |
859 | { |
802 | STRLEN textlen; |
860 | STRLEN textlen; |
803 | char *text = SvPVutf8 (text_, textlen); |
861 | char *text = SvPVutf8 (text_, textlen); |
804 | |
862 | |
805 | pango_layout_set_text (self->pl, text, textlen); |
863 | pango_layout_set_text (self->pl, text, textlen); |
806 | } |
864 | } |
807 | |
865 | |
808 | void |
866 | void |
809 | set_markup (CFClient::Layout self, SV *text_) |
867 | set_markup (CFPlus::Layout self, SV *text_) |
810 | CODE: |
868 | CODE: |
811 | { |
869 | { |
812 | STRLEN textlen; |
870 | STRLEN textlen; |
813 | char *text = SvPVutf8 (text_, textlen); |
871 | char *text = SvPVutf8 (text_, textlen); |
814 | |
872 | |
815 | pango_layout_set_markup (self->pl, text, textlen); |
873 | pango_layout_set_markup (self->pl, text, textlen); |
816 | } |
874 | } |
817 | |
875 | |
818 | void |
876 | void |
819 | set_shapes (CFClient::Layout self, ...) |
877 | set_shapes (CFPlus::Layout self, ...) |
820 | CODE: |
878 | CODE: |
821 | { |
879 | { |
822 | PangoAttrList *attrs = 0; |
880 | PangoAttrList *attrs = 0; |
823 | const char *text = pango_layout_get_text (self->pl); |
881 | const char *text = pango_layout_get_text (self->pl); |
824 | const char *pos = text; |
882 | const char *pos = text; |
… | |
… | |
859 | if (attrs) |
917 | if (attrs) |
860 | pango_layout_set_attributes (self->pl, attrs); |
918 | pango_layout_set_attributes (self->pl, attrs); |
861 | } |
919 | } |
862 | |
920 | |
863 | void |
921 | void |
864 | get_shapes (CFClient::Layout self) |
922 | get_shapes (CFPlus::Layout self) |
865 | PPCODE: |
923 | PPCODE: |
866 | { |
924 | { |
867 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
925 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
868 | |
926 | |
869 | do |
927 | do |
… | |
… | |
873 | if (run && shape_attr_p (run)) |
931 | if (run && shape_attr_p (run)) |
874 | { |
932 | { |
875 | PangoRectangle extents; |
933 | PangoRectangle extents; |
876 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
934 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
877 | |
935 | |
|
|
936 | EXTEND (SP, 2); |
878 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
937 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
879 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
938 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
880 | } |
939 | } |
881 | } |
940 | } |
882 | while (pango_layout_iter_next_run (iter)); |
941 | while (pango_layout_iter_next_run (iter)); |
883 | |
942 | |
884 | pango_layout_iter_free (iter); |
943 | pango_layout_iter_free (iter); |
885 | } |
944 | } |
886 | |
945 | |
887 | int |
946 | int |
888 | has_wrapped (CFClient::Layout self) |
947 | has_wrapped (CFPlus::Layout self) |
889 | CODE: |
948 | CODE: |
890 | { |
949 | { |
891 | int lines = 1; |
950 | int lines = 1; |
892 | const char *text = pango_layout_get_text (self->pl); |
951 | const char *text = pango_layout_get_text (self->pl); |
893 | |
952 | |
… | |
… | |
898 | } |
957 | } |
899 | OUTPUT: |
958 | OUTPUT: |
900 | RETVAL |
959 | RETVAL |
901 | |
960 | |
902 | SV * |
961 | SV * |
903 | get_text (CFClient::Layout self) |
962 | get_text (CFPlus::Layout self) |
904 | CODE: |
963 | CODE: |
905 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
964 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
906 | sv_utf8_decode (RETVAL); |
965 | sv_utf8_decode (RETVAL); |
907 | OUTPUT: |
966 | OUTPUT: |
908 | RETVAL |
967 | RETVAL |
909 | |
968 | |
910 | void |
969 | void |
911 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
970 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
912 | CODE: |
971 | CODE: |
913 | self->r = r; |
972 | self->r = r; |
914 | self->g = g; |
973 | self->g = g; |
915 | self->b = b; |
974 | self->b = b; |
916 | self->a = a; |
975 | self->a = a; |
917 | |
976 | |
918 | void |
977 | void |
919 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
978 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
920 | CODE: |
979 | CODE: |
921 | if (self->font != font) |
980 | if (self->font != font) |
922 | { |
981 | { |
923 | self->font = font; |
982 | self->font = font; |
924 | layout_update_font (self); |
983 | layout_update_font (self); |
925 | } |
984 | } |
926 | |
985 | |
927 | void |
986 | void |
928 | set_height (CFClient::Layout self, int base_height) |
987 | set_height (CFPlus::Layout self, int base_height) |
929 | CODE: |
988 | CODE: |
930 | if (self->base_height != base_height) |
989 | if (self->base_height != base_height) |
931 | { |
990 | { |
932 | self->base_height = base_height; |
991 | self->base_height = base_height; |
933 | layout_update_font (self); |
992 | layout_update_font (self); |
934 | } |
993 | } |
935 | |
994 | |
936 | void |
995 | void |
937 | set_width (CFClient::Layout self, int max_width = -1) |
996 | set_width (CFPlus::Layout self, int max_width = -1) |
938 | CODE: |
997 | CODE: |
939 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
998 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
940 | |
999 | |
941 | void |
1000 | void |
942 | set_indent (CFClient::Layout self, int indent) |
1001 | set_indent (CFPlus::Layout self, int indent) |
943 | CODE: |
1002 | CODE: |
944 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1003 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
945 | |
1004 | |
946 | void |
1005 | void |
947 | set_spacing (CFClient::Layout self, int spacing) |
1006 | set_spacing (CFPlus::Layout self, int spacing) |
948 | CODE: |
1007 | CODE: |
949 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1008 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
950 | |
1009 | |
951 | void |
1010 | void |
952 | set_ellipsise (CFClient::Layout self, int ellipsise) |
1011 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
953 | CODE: |
1012 | CODE: |
954 | pango_layout_set_ellipsize (self->pl, |
1013 | pango_layout_set_ellipsize (self->pl, |
955 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1014 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
956 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1015 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
957 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1016 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
958 | : PANGO_ELLIPSIZE_NONE |
1017 | : PANGO_ELLIPSIZE_NONE |
959 | ); |
1018 | ); |
960 | |
1019 | |
961 | void |
1020 | void |
962 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
1021 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
963 | CODE: |
1022 | CODE: |
964 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1023 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
965 | |
1024 | |
966 | void |
1025 | void |
967 | size (CFClient::Layout self) |
1026 | size (CFPlus::Layout self) |
968 | PPCODE: |
1027 | PPCODE: |
969 | { |
1028 | { |
970 | int w, h; |
1029 | int w, h; |
971 | |
1030 | |
972 | layout_get_pixel_size (self, &w, &h); |
1031 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
975 | PUSHs (sv_2mortal (newSViv (w))); |
1034 | PUSHs (sv_2mortal (newSViv (w))); |
976 | PUSHs (sv_2mortal (newSViv (h))); |
1035 | PUSHs (sv_2mortal (newSViv (h))); |
977 | } |
1036 | } |
978 | |
1037 | |
979 | int |
1038 | int |
980 | descent (CFClient::Layout self) |
1039 | descent (CFPlus::Layout self) |
981 | CODE: |
1040 | CODE: |
982 | { |
1041 | { |
983 | PangoRectangle rect; |
1042 | PangoRectangle rect; |
984 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1043 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
985 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1044 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
… | |
… | |
987 | } |
1046 | } |
988 | OUTPUT: |
1047 | OUTPUT: |
989 | RETVAL |
1048 | RETVAL |
990 | |
1049 | |
991 | int |
1050 | int |
992 | xy_to_index (CFClient::Layout self, int x, int y) |
1051 | xy_to_index (CFPlus::Layout self, int x, int y) |
993 | CODE: |
1052 | CODE: |
994 | { |
1053 | { |
995 | int index, trailing; |
1054 | int index, trailing; |
996 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1055 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
997 | RETVAL = index; |
1056 | RETVAL = index; |
998 | } |
1057 | } |
999 | OUTPUT: |
1058 | OUTPUT: |
1000 | RETVAL |
1059 | RETVAL |
1001 | |
1060 | |
1002 | void |
1061 | void |
1003 | cursor_pos (CFClient::Layout self, int index) |
1062 | cursor_pos (CFPlus::Layout self, int index) |
1004 | PPCODE: |
1063 | PPCODE: |
1005 | { |
1064 | { |
1006 | PangoRectangle strong_pos; |
1065 | PangoRectangle strong_pos; |
1007 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1066 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1008 | |
1067 | |
… | |
… | |
1011 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1070 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1012 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1071 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1013 | } |
1072 | } |
1014 | |
1073 | |
1015 | void |
1074 | void |
1016 | render (CFClient::Layout self, float x, float y) |
1075 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1017 | PPCODE: |
1076 | PPCODE: |
1018 | pango_opengl_render_layout_subpixel ( |
1077 | pango_opengl_render_layout_subpixel ( |
1019 | self->pl, |
1078 | self->pl, |
1020 | x * PANGO_SCALE, y * PANGO_SCALE, |
1079 | x * PANGO_SCALE, y * PANGO_SCALE, |
1021 | self->r, self->g, self->b, self->a |
1080 | self->r, self->g, self->b, self->a, |
|
|
1081 | flags |
1022 | ); |
1082 | ); |
1023 | |
1083 | |
1024 | MODULE = CFClient PACKAGE = CFClient::Texture |
1084 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1025 | |
1085 | |
1026 | void |
1086 | void |
1027 | pad2pot (SV *data_, SV *w_, SV *h_) |
1087 | pad2pot (SV *data_, SV *w_, SV *h_) |
1028 | CODE: |
1088 | CODE: |
1029 | { |
1089 | { |
… | |
… | |
1107 | glDisable (GL_ALPHA_TEST); |
1167 | glDisable (GL_ALPHA_TEST); |
1108 | glDisable (GL_BLEND); |
1168 | glDisable (GL_BLEND); |
1109 | } |
1169 | } |
1110 | } |
1170 | } |
1111 | |
1171 | |
1112 | MODULE = CFClient PACKAGE = CFClient::Map |
1172 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1113 | |
1173 | |
1114 | CFClient::Map |
1174 | CFPlus::Map |
1115 | new (SV *class, int map_width, int map_height) |
1175 | new (SV *class, int map_width, int map_height) |
1116 | CODE: |
1176 | CODE: |
1117 | New (0, RETVAL, 1, struct map); |
1177 | New (0, RETVAL, 1, struct map); |
1118 | RETVAL->x = 0; |
1178 | RETVAL->x = 0; |
1119 | RETVAL->y = 0; |
1179 | RETVAL->y = 0; |
… | |
… | |
1129 | RETVAL->row = 0; |
1189 | RETVAL->row = 0; |
1130 | OUTPUT: |
1190 | OUTPUT: |
1131 | RETVAL |
1191 | RETVAL |
1132 | |
1192 | |
1133 | void |
1193 | void |
1134 | DESTROY (CFClient::Map self) |
1194 | DESTROY (CFPlus::Map self) |
1135 | CODE: |
1195 | CODE: |
1136 | { |
1196 | { |
1137 | map_clear (self); |
1197 | map_clear (self); |
1138 | Safefree (self->face); |
1198 | Safefree (self->face); |
1139 | Safefree (self->tex); |
1199 | Safefree (self->tex); |
1140 | Safefree (self); |
1200 | Safefree (self); |
1141 | } |
1201 | } |
1142 | |
1202 | |
1143 | void |
1203 | void |
1144 | clear (CFClient::Map self) |
1204 | clear (CFPlus::Map self) |
1145 | CODE: |
1205 | CODE: |
1146 | map_clear (self); |
1206 | map_clear (self); |
1147 | |
1207 | |
1148 | void |
1208 | void |
1149 | set_face (CFClient::Map self, int face, int texid) |
1209 | set_face (CFPlus::Map self, int face, int texid) |
1150 | CODE: |
1210 | CODE: |
1151 | { |
1211 | { |
1152 | while (self->faces <= face) |
1212 | while (self->faces <= face) |
1153 | { |
1213 | { |
1154 | Append (mapface, self->face, self->faces, self->faces); |
1214 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1157 | |
1217 | |
1158 | self->face [face] = texid; |
1218 | self->face [face] = texid; |
1159 | } |
1219 | } |
1160 | |
1220 | |
1161 | void |
1221 | 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) |
1222 | 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: |
1223 | CODE: |
1164 | { |
1224 | { |
1165 | while (self->texs <= texid) |
1225 | while (self->texs <= texid) |
1166 | { |
1226 | { |
1167 | Append (maptex, self->tex, self->texs, self->texs); |
1227 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1191 | // from transparent color bleeding and ugly wrapping effects. |
1251 | // from transparent color bleeding and ugly wrapping effects. |
1192 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1252 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1193 | } |
1253 | } |
1194 | |
1254 | |
1195 | int |
1255 | int |
1196 | ox (CFClient::Map self) |
1256 | ox (CFPlus::Map self) |
1197 | ALIAS: |
1257 | ALIAS: |
1198 | oy = 1 |
1258 | oy = 1 |
1199 | x = 2 |
1259 | x = 2 |
1200 | y = 3 |
1260 | y = 3 |
1201 | w = 4 |
1261 | w = 4 |
… | |
… | |
1212 | } |
1272 | } |
1213 | OUTPUT: |
1273 | OUTPUT: |
1214 | RETVAL |
1274 | RETVAL |
1215 | |
1275 | |
1216 | void |
1276 | void |
1217 | scroll (CFClient::Map self, int dx, int dy) |
1277 | scroll (CFPlus::Map self, int dx, int dy) |
1218 | CODE: |
1278 | CODE: |
1219 | { |
1279 | { |
1220 | if (dx > 0) |
1280 | if (dx > 0) |
1221 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1281 | map_blank (self, self->x, self->y, dx, self->h); |
1222 | else if (dx < 0) |
1282 | else if (dx < 0) |
1223 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1283 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1224 | |
1284 | |
1225 | if (dy > 0) |
1285 | if (dy > 0) |
1226 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1286 | map_blank (self, self->x, self->y, self->w, dy); |
1227 | else if (dy < 0) |
1287 | else if (dy < 0) |
1228 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1288 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1229 | |
1289 | |
1230 | self->ox += dx; self->x += dx; |
1290 | self->ox += dx; self->x += dx; |
1231 | self->oy += dy; self->y += dy; |
1291 | self->oy += dy; self->y += dy; |
1232 | |
1292 | |
1233 | while (self->y < 0) |
1293 | while (self->y < 0) |
… | |
… | |
1238 | self->y += MAP_EXTEND_Y; |
1298 | self->y += MAP_EXTEND_Y; |
1239 | } |
1299 | } |
1240 | } |
1300 | } |
1241 | |
1301 | |
1242 | void |
1302 | void |
1243 | map1a_update (CFClient::Map self, SV *data_) |
1303 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1244 | CODE: |
1304 | CODE: |
1245 | { |
1305 | { |
1246 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1306 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1247 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1307 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1248 | mapcell *cell; |
1308 | mapcell *cell; |
1249 | int x, y, flags; |
1309 | int x, y, flags; |
1250 | |
1310 | |
1251 | while (data < data_end) |
1311 | while (data < data_end - 1) |
1252 | { |
1312 | { |
1253 | flags = (data [0] << 8) + data [1]; data += 2; |
1313 | flags = (data [0] << 8) + data [1]; data += 2; |
1254 | |
1314 | |
1255 | x = self->x + ((flags >> 10) & 63); |
1315 | x = self->x + ((flags >> 10) & 63); |
1256 | y = self->y + ((flags >> 4) & 63); |
1316 | y = self->y + ((flags >> 4) & 63); |
1257 | |
1317 | |
1258 | cell = map_get_cell (self, x, y); |
1318 | cell = map_get_cell (self, x, y); |
1259 | |
1319 | |
1260 | if (flags & 15) |
1320 | if (flags & 15) |
1261 | { |
1321 | { |
1262 | if (cell->darkness < 0) |
1322 | if (!cell->darkness) |
1263 | { |
1323 | { |
|
|
1324 | memset (cell, 0, sizeof (*cell)); |
1264 | cell->darkness = 0; |
1325 | cell->darkness = 256; |
1265 | cell->face [0] = 0; |
|
|
1266 | cell->face [1] = 0; |
|
|
1267 | cell->face [2] = 0; |
|
|
1268 | } |
1326 | } |
1269 | |
1327 | |
1270 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1271 | |
|
|
1272 | //TODO: don't trust server data to be in-range(!) |
1328 | //TODO: don't trust server data to be in-range(!) |
|
|
1329 | |
|
|
1330 | if (flags & 8) |
|
|
1331 | { |
|
|
1332 | if (extmap) |
|
|
1333 | { |
|
|
1334 | uint8_t ext, cmd; |
|
|
1335 | |
|
|
1336 | do |
|
|
1337 | { |
|
|
1338 | ext = *data++; |
|
|
1339 | cmd = ext & 0x3f; |
|
|
1340 | |
|
|
1341 | if (cmd < 4) |
|
|
1342 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1343 | else if (cmd == 5) // health |
|
|
1344 | { |
|
|
1345 | cell->stat_width = 1; |
|
|
1346 | cell->stat_hp = *data++; |
|
|
1347 | } |
|
|
1348 | else if (cmd == 6) // monster width |
|
|
1349 | cell->stat_width = *data++ + 1; |
|
|
1350 | else if (cmd == 0x47) // monster width |
|
|
1351 | { |
|
|
1352 | if (*data == 4) |
|
|
1353 | ; // decode player tag |
|
|
1354 | |
|
|
1355 | data += *data + 1; |
|
|
1356 | } |
|
|
1357 | else if (cmd == 8) // cell flags |
|
|
1358 | cell->flags = *data++; |
|
|
1359 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1360 | data += *data + 1; |
|
|
1361 | else |
|
|
1362 | data++; |
|
|
1363 | } |
|
|
1364 | while (ext & 0x80); |
|
|
1365 | } |
|
|
1366 | else |
|
|
1367 | cell->darkness = *data++ + 1; |
|
|
1368 | } |
1273 | |
1369 | |
1274 | if (flags & 4) |
1370 | if (flags & 4) |
1275 | { |
1371 | { |
1276 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1372 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1277 | } |
1373 | } |
… | |
… | |
1285 | { |
1381 | { |
1286 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1382 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1287 | } |
1383 | } |
1288 | } |
1384 | } |
1289 | else |
1385 | else |
1290 | cell->darkness = -1; |
1386 | cell->darkness = 0; |
1291 | } |
1387 | } |
1292 | } |
1388 | } |
1293 | |
1389 | |
1294 | SV * |
1390 | SV * |
1295 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
1391 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1296 | CODE: |
1392 | CODE: |
1297 | { |
1393 | { |
1298 | int x1, x; |
1394 | int x1, x; |
1299 | int y1, y; |
1395 | int y1, y; |
1300 | int z; |
1396 | int z; |
… | |
… | |
1350 | } |
1446 | } |
1351 | OUTPUT: |
1447 | OUTPUT: |
1352 | RETVAL |
1448 | RETVAL |
1353 | |
1449 | |
1354 | void |
1450 | void |
1355 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1451 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1356 | CODE: |
1452 | CODE: |
1357 | { |
1453 | { |
1358 | int vx, vy; |
1454 | int vx, vy; |
1359 | int x, y, z; |
1455 | int x, y, z; |
1360 | int last_name; |
1456 | int last_name; |
… | |
… | |
1395 | { |
1491 | { |
1396 | mapcell *cell = row->col + (x + vx - row->c0); |
1492 | mapcell *cell = row->col + (x + vx - row->c0); |
1397 | |
1493 | |
1398 | face = cell->face [z]; |
1494 | face = cell->face [z]; |
1399 | |
1495 | |
1400 | if (face) |
1496 | if (face && face < self->texs) |
1401 | { |
1497 | { |
1402 | maptex tex = self->tex [face]; |
1498 | maptex tex = self->tex [face]; |
1403 | |
|
|
1404 | int px = (x + 1) * 32 - tex.w; |
1499 | int px = (x + 1) * 32 - tex.w; |
1405 | int py = (y + 1) * 32 - tex.h; |
1500 | int py = (y + 1) * 32 - tex.h; |
1406 | |
1501 | |
1407 | if (last_name != tex.name) |
1502 | if (last_name != tex.name) |
1408 | { |
1503 | { |
1409 | glEnd (); |
1504 | glEnd (); |
1410 | last_name = tex.name; |
|
|
1411 | glBindTexture (GL_TEXTURE_2D, last_name); |
1505 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1412 | glBegin (GL_QUADS); |
1506 | glBegin (GL_QUADS); |
1413 | } |
1507 | } |
1414 | |
1508 | |
1415 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1509 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1416 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1510 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1417 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1511 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1418 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1512 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1419 | } |
1513 | } |
|
|
1514 | |
|
|
1515 | if (cell->flags && z == 2) |
|
|
1516 | { |
|
|
1517 | if (cell->flags & 1) |
|
|
1518 | { |
|
|
1519 | maptex tex = self->tex [1]; |
|
|
1520 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1521 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1522 | |
|
|
1523 | glEnd (); |
|
|
1524 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1525 | glBegin (GL_QUADS); |
|
|
1526 | |
|
|
1527 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1528 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1529 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1530 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1531 | } |
|
|
1532 | } |
1420 | } |
1533 | } |
1421 | } |
1534 | } |
1422 | |
1535 | |
1423 | glEnd (); |
1536 | glEnd (); |
1424 | |
1537 | |
1425 | glDisable (GL_TEXTURE_2D); |
1538 | glDisable (GL_TEXTURE_2D); |
1426 | glDisable (GL_BLEND); |
1539 | glDisable (GL_BLEND); |
1427 | } |
|
|
1428 | |
1540 | |
|
|
1541 | // top layer: overlays such as the health bar |
|
|
1542 | for (y = 0; y < sh; y++) |
|
|
1543 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1544 | { |
|
|
1545 | maprow *row = self->row + (y + vy); |
|
|
1546 | |
|
|
1547 | for (x = 0; x < sw; x++) |
|
|
1548 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1549 | { |
|
|
1550 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1551 | |
|
|
1552 | int px = x * 32; |
|
|
1553 | int py = y * 32; |
|
|
1554 | |
|
|
1555 | if (cell->stat_hp) |
|
|
1556 | { |
|
|
1557 | int width = cell->stat_width * 32; |
|
|
1558 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1559 | |
|
|
1560 | glColor3ub (0, 0, 0); |
|
|
1561 | glRectf (px + 1, py - thick - 2, |
|
|
1562 | px + width - 1, py); |
|
|
1563 | |
|
|
1564 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1565 | glRectf (px + 2, |
|
|
1566 | py - thick - 1, |
|
|
1567 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1568 | } |
|
|
1569 | } |
|
|
1570 | } |
|
|
1571 | } |
|
|
1572 | |
1429 | void |
1573 | void |
1430 | draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1574 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1431 | CODE: |
1575 | CODE: |
1432 | { |
1576 | { |
1433 | static float color[16][3] = { |
1577 | static float color[16][3] = { |
1434 | { 0.00F, 0.00F, 0.00F }, |
1578 | { 0.00F, 0.00F, 0.00F }, |
1435 | { 1.00F, 1.00F, 1.00F }, |
1579 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
1485 | glDisable (GL_BLEND); |
1629 | glDisable (GL_BLEND); |
1486 | glDisable (GL_TEXTURE_2D); |
1630 | glDisable (GL_TEXTURE_2D); |
1487 | } |
1631 | } |
1488 | |
1632 | |
1489 | void |
1633 | void |
1490 | fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1634 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1491 | PPCODE: |
1635 | PPCODE: |
1492 | { |
1636 | { |
1493 | int vx, vy; |
1637 | int vx, vy; |
1494 | int x, y; |
1638 | int x, y; |
1495 | int sw4 = (sw + 3) & ~3; |
1639 | int sw4 = (sw + 3) & ~3; |
… | |
… | |
1511 | for (x = 0; x < sw; x++) |
1655 | for (x = 0; x < sw; x++) |
1512 | if (row->c0 <= x + vx && x + vx < row->c1) |
1656 | if (row->c0 <= x + vx && x + vx < row->c1) |
1513 | { |
1657 | { |
1514 | mapcell *cell = row->col + (x + vx - row->c0); |
1658 | mapcell *cell = row->col + (x + vx - row->c0); |
1515 | |
1659 | |
1516 | darkness[y * sw4 + x] = cell->darkness < 0 |
1660 | darkness[y * sw4 + x] = cell->darkness |
|
|
1661 | ? 255 - (cell->darkness - 1) |
1517 | ? 255 - FOW_DARKNESS |
1662 | : 255 - FOW_DARKNESS; |
1518 | : 255 - cell->darkness; |
|
|
1519 | } |
1663 | } |
1520 | } |
1664 | } |
1521 | |
1665 | |
1522 | EXTEND (SP, 3); |
1666 | EXTEND (SP, 3); |
1523 | PUSHs (sv_2mortal (newSViv (sw4))); |
1667 | PUSHs (sv_2mortal (newSViv (sw4))); |
1524 | PUSHs (sv_2mortal (newSViv (sh))); |
1668 | PUSHs (sv_2mortal (newSViv (sh))); |
1525 | PUSHs (darkness_sv); |
1669 | PUSHs (darkness_sv); |
1526 | } |
1670 | } |
1527 | |
1671 | |
1528 | SV * |
1672 | SV * |
1529 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
1673 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
1530 | CODE: |
1674 | CODE: |
1531 | { |
1675 | { |
1532 | int x, y, x1, y1; |
1676 | int x, y, x1, y1; |
1533 | SV *data_sv = newSV (w * h * 7 + 5); |
1677 | SV *data_sv = newSV (w * h * 7 + 5); |
1534 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1678 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1596 | } |
1740 | } |
1597 | OUTPUT: |
1741 | OUTPUT: |
1598 | RETVAL |
1742 | RETVAL |
1599 | |
1743 | |
1600 | void |
1744 | void |
1601 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
1745 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
1602 | PPCODE: |
1746 | PPCODE: |
1603 | { |
1747 | { |
1604 | int x, y, z; |
1748 | int x, y, z; |
1605 | int w, h; |
1749 | int w, h; |
1606 | int x1, y1; |
1750 | int x1, y1; |
… | |
… | |
1638 | |
1782 | |
1639 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1783 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1640 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1784 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1641 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1785 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1642 | |
1786 | |
1643 | if (cell->darkness <= 0) |
1787 | if (cell->darkness == 0) |
1644 | { |
1788 | { |
1645 | cell->darkness = -1; |
1789 | cell->darkness = 0; |
1646 | |
1790 | |
1647 | for (z = 0; z <= 2; z++) |
1791 | for (z = 0; z <= 2; z++) |
1648 | { |
1792 | { |
1649 | cell->face[z] = face[z]; |
1793 | cell->face[z] = face[z]; |
1650 | |
1794 | |
… | |
… | |
1655 | } |
1799 | } |
1656 | } |
1800 | } |
1657 | } |
1801 | } |
1658 | } |
1802 | } |
1659 | |
1803 | |
1660 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1804 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1661 | |
1805 | |
1662 | CFClient::MixChunk |
1806 | CFPlus::MixChunk |
1663 | new_from_file (SV *class, char *path) |
1807 | new_from_file (SV *class, char *path) |
1664 | CODE: |
1808 | CODE: |
1665 | RETVAL = Mix_LoadWAV (path); |
1809 | RETVAL = Mix_LoadWAV (path); |
1666 | OUTPUT: |
1810 | OUTPUT: |
1667 | RETVAL |
1811 | RETVAL |
1668 | |
1812 | |
1669 | void |
1813 | void |
1670 | DESTROY (CFClient::MixChunk self) |
1814 | DESTROY (CFPlus::MixChunk self) |
1671 | CODE: |
1815 | CODE: |
1672 | Mix_FreeChunk (self); |
1816 | Mix_FreeChunk (self); |
1673 | |
1817 | |
1674 | int |
1818 | int |
1675 | volume (CFClient::MixChunk self, int volume = -1) |
1819 | volume (CFPlus::MixChunk self, int volume = -1) |
1676 | CODE: |
1820 | CODE: |
1677 | RETVAL = Mix_VolumeChunk (self, volume); |
1821 | RETVAL = Mix_VolumeChunk (self, volume); |
1678 | OUTPUT: |
1822 | OUTPUT: |
1679 | RETVAL |
1823 | RETVAL |
1680 | |
1824 | |
1681 | int |
1825 | int |
1682 | play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1826 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1683 | CODE: |
1827 | CODE: |
1684 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1828 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1685 | OUTPUT: |
1829 | OUTPUT: |
1686 | RETVAL |
1830 | RETVAL |
1687 | |
1831 | |
1688 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1832 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1689 | |
1833 | |
1690 | int |
1834 | int |
1691 | volume (int volume = -1) |
1835 | volume (int volume = -1) |
1692 | CODE: |
1836 | CODE: |
1693 | RETVAL = Mix_VolumeMusic (volume); |
1837 | RETVAL = Mix_VolumeMusic (volume); |
1694 | OUTPUT: |
1838 | OUTPUT: |
1695 | RETVAL |
1839 | RETVAL |
1696 | |
1840 | |
1697 | CFClient::MixMusic |
1841 | CFPlus::MixMusic |
1698 | new_from_file (SV *class, char *path) |
1842 | new_from_file (SV *class, char *path) |
1699 | CODE: |
1843 | CODE: |
1700 | RETVAL = Mix_LoadMUS (path); |
1844 | RETVAL = Mix_LoadMUS (path); |
1701 | OUTPUT: |
1845 | OUTPUT: |
1702 | RETVAL |
1846 | RETVAL |
1703 | |
1847 | |
1704 | void |
1848 | void |
1705 | DESTROY (CFClient::MixMusic self) |
1849 | DESTROY (CFPlus::MixMusic self) |
1706 | CODE: |
1850 | CODE: |
1707 | Mix_FreeMusic (self); |
1851 | Mix_FreeMusic (self); |
1708 | |
1852 | |
1709 | int |
1853 | int |
1710 | play (CFClient::MixMusic self, int loops = -1) |
1854 | play (CFPlus::MixMusic self, int loops = -1) |
1711 | CODE: |
1855 | CODE: |
1712 | RETVAL = Mix_PlayMusic (self, loops); |
1856 | RETVAL = Mix_PlayMusic (self, loops); |
1713 | OUTPUT: |
1857 | OUTPUT: |
1714 | RETVAL |
1858 | RETVAL |
1715 | |
1859 | |
1716 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1860 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1717 | |
1861 | |
1718 | BOOT: |
1862 | BOOT: |
1719 | { |
1863 | { |
1720 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1864 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1721 | static const struct { |
1865 | static const struct { |
1722 | const char *name; |
1866 | const char *name; |
1723 | IV iv; |
1867 | IV iv; |
1724 | } *civ, const_iv[] = { |
1868 | } *civ, const_iv[] = { |
1725 | # define const_iv(name) { # name, (IV)name } |
1869 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1788 | const_iv (GL_SEPARABLE_2D), |
1932 | const_iv (GL_SEPARABLE_2D), |
1789 | const_iv (GL_CONVOLUTION_2D), |
1933 | const_iv (GL_CONVOLUTION_2D), |
1790 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1934 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1791 | const_iv (GL_CONSTANT_BORDER), |
1935 | const_iv (GL_CONSTANT_BORDER), |
1792 | const_iv (GL_LINES), |
1936 | const_iv (GL_LINES), |
|
|
1937 | const_iv (GL_LINE_STRIP), |
1793 | const_iv (GL_LINE_LOOP), |
1938 | const_iv (GL_LINE_LOOP), |
1794 | const_iv (GL_QUADS), |
1939 | const_iv (GL_QUADS), |
1795 | const_iv (GL_QUAD_STRIP), |
1940 | const_iv (GL_QUAD_STRIP), |
1796 | const_iv (GL_TRIANGLES), |
1941 | const_iv (GL_TRIANGLES), |
1797 | const_iv (GL_TRIANGLE_STRIP), |
1942 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1907 | r *= a; |
2052 | r *= a; |
1908 | g *= a; |
2053 | g *= a; |
1909 | b *= a; |
2054 | b *= a; |
1910 | } |
2055 | } |
1911 | // microsoft visual "c" rounds instead of truncating... |
2056 | // microsoft visual "c" rounds instead of truncating... |
1912 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2057 | 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 | |
2058 | |
1917 | void glInterleavedArrays (int format, int stride, char *data) |
2059 | void glInterleavedArrays (int format, int stride, char *data) |
1918 | |
2060 | |
1919 | void glDrawElements (int mode, int count, int type, char *indices) |
2061 | void glDrawElements (int mode, int count, int type, char *indices) |
1920 | |
2062 | |
… | |
… | |
1997 | |
2139 | |
1998 | void glEndList () |
2140 | void glEndList () |
1999 | |
2141 | |
2000 | void glCallList (int list) |
2142 | void glCallList (int list) |
2001 | |
2143 | |
2002 | |
|
|