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: |
|
|
799 | #ifdef WIN32 |
|
|
800 | ExitThread (retval); // unclean, please beam me up |
|
|
801 | #else |
740 | _exit (retval); |
802 | _exit (retval); |
|
|
803 | #endif |
741 | |
804 | |
742 | MODULE = CFClient PACKAGE = CFClient::Font |
805 | MODULE = CFPlus PACKAGE = CFPlus::Font |
743 | |
806 | |
744 | CFClient::Font |
807 | CFPlus::Font |
745 | new_from_file (SV *class, char *path, int id = 0) |
808 | new_from_file (SV *class, char *path, int id = 0) |
746 | CODE: |
809 | CODE: |
747 | { |
810 | { |
748 | int count; |
811 | int count; |
749 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
812 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
752 | } |
815 | } |
753 | OUTPUT: |
816 | OUTPUT: |
754 | RETVAL |
817 | RETVAL |
755 | |
818 | |
756 | void |
819 | void |
757 | DESTROY (CFClient::Font self) |
820 | DESTROY (CFPlus::Font self) |
758 | CODE: |
821 | CODE: |
759 | pango_font_description_free (self); |
822 | pango_font_description_free (self); |
760 | |
823 | |
761 | void |
824 | void |
762 | make_default (CFClient::Font self) |
825 | make_default (CFPlus::Font self) |
763 | CODE: |
826 | CODE: |
764 | default_font = self; |
827 | default_font = self; |
765 | |
828 | |
766 | MODULE = CFClient PACKAGE = CFClient::Layout |
829 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
767 | |
830 | |
768 | void |
831 | void |
769 | clear_font_cache () |
832 | reset_glyph_cache () |
770 | CODE: |
833 | CODE: |
771 | pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap); |
|
|
772 | tc_clear (); |
834 | tc_clear (); |
773 | |
835 | |
774 | CFClient::Layout |
836 | CFPlus::Layout |
775 | new (SV *class, int type = 0) |
837 | new (SV *class) |
776 | CODE: |
838 | CODE: |
777 | New (0, RETVAL, 1, struct cf_layout); |
839 | New (0, RETVAL, 1, struct cf_layout); |
778 | |
840 | |
779 | RETVAL->pl = pango_layout_new (opengl_context); |
841 | RETVAL->pl = pango_layout_new (opengl_context); |
780 | RETVAL->r = 1.; |
842 | RETVAL->r = 1.; |
… | |
… | |
788 | layout_update_font (RETVAL); |
850 | layout_update_font (RETVAL); |
789 | OUTPUT: |
851 | OUTPUT: |
790 | RETVAL |
852 | RETVAL |
791 | |
853 | |
792 | void |
854 | void |
793 | DESTROY (CFClient::Layout self) |
855 | DESTROY (CFPlus::Layout self) |
794 | CODE: |
856 | CODE: |
795 | g_object_unref (self->pl); |
857 | g_object_unref (self->pl); |
796 | Safefree (self); |
858 | Safefree (self); |
797 | |
859 | |
798 | void |
860 | void |
799 | set_text (CFClient::Layout self, SV *text_) |
861 | set_text (CFPlus::Layout self, SV *text_) |
800 | CODE: |
862 | CODE: |
801 | { |
863 | { |
802 | STRLEN textlen; |
864 | STRLEN textlen; |
803 | char *text = SvPVutf8 (text_, textlen); |
865 | char *text = SvPVutf8 (text_, textlen); |
804 | |
866 | |
805 | pango_layout_set_text (self->pl, text, textlen); |
867 | pango_layout_set_text (self->pl, text, textlen); |
806 | } |
868 | } |
807 | |
869 | |
808 | void |
870 | void |
809 | set_markup (CFClient::Layout self, SV *text_) |
871 | set_markup (CFPlus::Layout self, SV *text_) |
810 | CODE: |
872 | CODE: |
811 | { |
873 | { |
812 | STRLEN textlen; |
874 | STRLEN textlen; |
813 | char *text = SvPVutf8 (text_, textlen); |
875 | char *text = SvPVutf8 (text_, textlen); |
814 | |
876 | |
815 | pango_layout_set_markup (self->pl, text, textlen); |
877 | pango_layout_set_markup (self->pl, text, textlen); |
816 | } |
878 | } |
817 | |
879 | |
818 | void |
880 | void |
819 | set_shapes (CFClient::Layout self, ...) |
881 | set_shapes (CFPlus::Layout self, ...) |
820 | CODE: |
882 | CODE: |
821 | { |
883 | { |
822 | PangoAttrList *attrs = 0; |
884 | PangoAttrList *attrs = 0; |
823 | const char *text = pango_layout_get_text (self->pl); |
885 | const char *text = pango_layout_get_text (self->pl); |
824 | const char *pos = text; |
886 | const char *pos = text; |
… | |
… | |
859 | if (attrs) |
921 | if (attrs) |
860 | pango_layout_set_attributes (self->pl, attrs); |
922 | pango_layout_set_attributes (self->pl, attrs); |
861 | } |
923 | } |
862 | |
924 | |
863 | void |
925 | void |
864 | get_shapes (CFClient::Layout self) |
926 | get_shapes (CFPlus::Layout self) |
865 | PPCODE: |
927 | PPCODE: |
866 | { |
928 | { |
867 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
929 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
868 | |
930 | |
869 | do |
931 | do |
… | |
… | |
873 | if (run && shape_attr_p (run)) |
935 | if (run && shape_attr_p (run)) |
874 | { |
936 | { |
875 | PangoRectangle extents; |
937 | PangoRectangle extents; |
876 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
938 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
877 | |
939 | |
|
|
940 | EXTEND (SP, 2); |
878 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
941 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
879 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
942 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
880 | } |
943 | } |
881 | } |
944 | } |
882 | while (pango_layout_iter_next_run (iter)); |
945 | while (pango_layout_iter_next_run (iter)); |
883 | |
946 | |
884 | pango_layout_iter_free (iter); |
947 | pango_layout_iter_free (iter); |
885 | } |
948 | } |
886 | |
949 | |
887 | int |
950 | int |
888 | has_wrapped (CFClient::Layout self) |
951 | has_wrapped (CFPlus::Layout self) |
889 | CODE: |
952 | CODE: |
890 | { |
953 | { |
891 | int lines = 1; |
954 | int lines = 1; |
892 | const char *text = pango_layout_get_text (self->pl); |
955 | const char *text = pango_layout_get_text (self->pl); |
893 | |
956 | |
… | |
… | |
898 | } |
961 | } |
899 | OUTPUT: |
962 | OUTPUT: |
900 | RETVAL |
963 | RETVAL |
901 | |
964 | |
902 | SV * |
965 | SV * |
903 | get_text (CFClient::Layout self) |
966 | get_text (CFPlus::Layout self) |
904 | CODE: |
967 | CODE: |
905 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
968 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
906 | sv_utf8_decode (RETVAL); |
969 | sv_utf8_decode (RETVAL); |
907 | OUTPUT: |
970 | OUTPUT: |
908 | RETVAL |
971 | RETVAL |
909 | |
972 | |
910 | void |
973 | void |
911 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
974 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
912 | CODE: |
975 | CODE: |
913 | self->r = r; |
976 | self->r = r; |
914 | self->g = g; |
977 | self->g = g; |
915 | self->b = b; |
978 | self->b = b; |
916 | self->a = a; |
979 | self->a = a; |
917 | |
980 | |
918 | void |
981 | void |
919 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
982 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
920 | CODE: |
983 | CODE: |
921 | if (self->font != font) |
984 | if (self->font != font) |
922 | { |
985 | { |
923 | self->font = font; |
986 | self->font = font; |
924 | layout_update_font (self); |
987 | layout_update_font (self); |
925 | } |
988 | } |
926 | |
989 | |
927 | void |
990 | void |
928 | set_height (CFClient::Layout self, int base_height) |
991 | set_height (CFPlus::Layout self, int base_height) |
929 | CODE: |
992 | CODE: |
930 | if (self->base_height != base_height) |
993 | if (self->base_height != base_height) |
931 | { |
994 | { |
932 | self->base_height = base_height; |
995 | self->base_height = base_height; |
933 | layout_update_font (self); |
996 | layout_update_font (self); |
934 | } |
997 | } |
935 | |
998 | |
936 | void |
999 | void |
937 | set_width (CFClient::Layout self, int max_width = -1) |
1000 | set_width (CFPlus::Layout self, int max_width = -1) |
938 | CODE: |
1001 | CODE: |
939 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1002 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
940 | |
1003 | |
941 | void |
1004 | void |
942 | set_indent (CFClient::Layout self, int indent) |
1005 | set_indent (CFPlus::Layout self, int indent) |
943 | CODE: |
1006 | CODE: |
944 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1007 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
945 | |
1008 | |
946 | void |
1009 | void |
947 | set_spacing (CFClient::Layout self, int spacing) |
1010 | set_spacing (CFPlus::Layout self, int spacing) |
948 | CODE: |
1011 | CODE: |
949 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1012 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
950 | |
1013 | |
951 | void |
1014 | void |
952 | set_ellipsise (CFClient::Layout self, int ellipsise) |
1015 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
953 | CODE: |
1016 | CODE: |
954 | pango_layout_set_ellipsize (self->pl, |
1017 | pango_layout_set_ellipsize (self->pl, |
955 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1018 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
956 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1019 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
957 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1020 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
958 | : PANGO_ELLIPSIZE_NONE |
1021 | : PANGO_ELLIPSIZE_NONE |
959 | ); |
1022 | ); |
960 | |
1023 | |
961 | void |
1024 | void |
962 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
1025 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
963 | CODE: |
1026 | CODE: |
964 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1027 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
965 | |
1028 | |
966 | void |
1029 | void |
967 | size (CFClient::Layout self) |
1030 | size (CFPlus::Layout self) |
968 | PPCODE: |
1031 | PPCODE: |
969 | { |
1032 | { |
970 | int w, h; |
1033 | int w, h; |
971 | |
1034 | |
972 | layout_get_pixel_size (self, &w, &h); |
1035 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
975 | PUSHs (sv_2mortal (newSViv (w))); |
1038 | PUSHs (sv_2mortal (newSViv (w))); |
976 | PUSHs (sv_2mortal (newSViv (h))); |
1039 | PUSHs (sv_2mortal (newSViv (h))); |
977 | } |
1040 | } |
978 | |
1041 | |
979 | int |
1042 | int |
980 | descent (CFClient::Layout self) |
1043 | descent (CFPlus::Layout self) |
981 | CODE: |
1044 | CODE: |
982 | { |
1045 | { |
983 | PangoRectangle rect; |
1046 | PangoRectangle rect; |
984 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1047 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
985 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1048 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
… | |
… | |
987 | } |
1050 | } |
988 | OUTPUT: |
1051 | OUTPUT: |
989 | RETVAL |
1052 | RETVAL |
990 | |
1053 | |
991 | int |
1054 | int |
992 | xy_to_index (CFClient::Layout self, int x, int y) |
1055 | xy_to_index (CFPlus::Layout self, int x, int y) |
993 | CODE: |
1056 | CODE: |
994 | { |
1057 | { |
995 | int index, trailing; |
1058 | int index, trailing; |
996 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1059 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
997 | RETVAL = index; |
1060 | RETVAL = index; |
998 | } |
1061 | } |
999 | OUTPUT: |
1062 | OUTPUT: |
1000 | RETVAL |
1063 | RETVAL |
1001 | |
1064 | |
1002 | void |
1065 | void |
1003 | cursor_pos (CFClient::Layout self, int index) |
1066 | cursor_pos (CFPlus::Layout self, int index) |
1004 | PPCODE: |
1067 | PPCODE: |
1005 | { |
1068 | { |
1006 | PangoRectangle strong_pos; |
1069 | PangoRectangle strong_pos; |
1007 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1070 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1008 | |
1071 | |
… | |
… | |
1011 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1074 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1012 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1075 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1013 | } |
1076 | } |
1014 | |
1077 | |
1015 | void |
1078 | void |
1016 | render (CFClient::Layout self, float x, float y) |
1079 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1017 | PPCODE: |
1080 | PPCODE: |
1018 | pango_opengl_render_layout_subpixel ( |
1081 | pango_opengl_render_layout_subpixel ( |
1019 | self->pl, |
1082 | self->pl, |
1020 | x * PANGO_SCALE, y * PANGO_SCALE, |
1083 | x * PANGO_SCALE, y * PANGO_SCALE, |
1021 | self->r, self->g, self->b, self->a |
1084 | self->r, self->g, self->b, self->a, |
|
|
1085 | flags |
1022 | ); |
1086 | ); |
1023 | |
1087 | |
1024 | MODULE = CFClient PACKAGE = CFClient::Texture |
1088 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1025 | |
1089 | |
1026 | void |
1090 | void |
1027 | pad2pot (SV *data_, SV *w_, SV *h_) |
1091 | pad2pot (SV *data_, SV *w_, SV *h_) |
1028 | CODE: |
1092 | CODE: |
1029 | { |
1093 | { |
… | |
… | |
1107 | glDisable (GL_ALPHA_TEST); |
1171 | glDisable (GL_ALPHA_TEST); |
1108 | glDisable (GL_BLEND); |
1172 | glDisable (GL_BLEND); |
1109 | } |
1173 | } |
1110 | } |
1174 | } |
1111 | |
1175 | |
1112 | MODULE = CFClient PACKAGE = CFClient::Map |
1176 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1113 | |
1177 | |
1114 | CFClient::Map |
1178 | CFPlus::Map |
1115 | new (SV *class, int map_width, int map_height) |
1179 | new (SV *class, int map_width, int map_height) |
1116 | CODE: |
1180 | CODE: |
1117 | New (0, RETVAL, 1, struct map); |
1181 | New (0, RETVAL, 1, struct map); |
1118 | RETVAL->x = 0; |
1182 | RETVAL->x = 0; |
1119 | RETVAL->y = 0; |
1183 | RETVAL->y = 0; |
… | |
… | |
1129 | RETVAL->row = 0; |
1193 | RETVAL->row = 0; |
1130 | OUTPUT: |
1194 | OUTPUT: |
1131 | RETVAL |
1195 | RETVAL |
1132 | |
1196 | |
1133 | void |
1197 | void |
1134 | DESTROY (CFClient::Map self) |
1198 | DESTROY (CFPlus::Map self) |
1135 | CODE: |
1199 | CODE: |
1136 | { |
1200 | { |
1137 | map_clear (self); |
1201 | map_clear (self); |
1138 | Safefree (self->face); |
1202 | Safefree (self->face); |
1139 | Safefree (self->tex); |
1203 | Safefree (self->tex); |
1140 | Safefree (self); |
1204 | Safefree (self); |
1141 | } |
1205 | } |
1142 | |
1206 | |
1143 | void |
1207 | void |
1144 | clear (CFClient::Map self) |
1208 | clear (CFPlus::Map self) |
1145 | CODE: |
1209 | CODE: |
1146 | map_clear (self); |
1210 | map_clear (self); |
1147 | |
1211 | |
1148 | void |
1212 | void |
1149 | set_face (CFClient::Map self, int face, int texid) |
1213 | set_face (CFPlus::Map self, int face, int texid) |
1150 | CODE: |
1214 | CODE: |
1151 | { |
1215 | { |
1152 | while (self->faces <= face) |
1216 | while (self->faces <= face) |
1153 | { |
1217 | { |
1154 | Append (mapface, self->face, self->faces, self->faces); |
1218 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1157 | |
1221 | |
1158 | self->face [face] = texid; |
1222 | self->face [face] = texid; |
1159 | } |
1223 | } |
1160 | |
1224 | |
1161 | void |
1225 | 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) |
1226 | 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: |
1227 | CODE: |
1164 | { |
1228 | { |
1165 | while (self->texs <= texid) |
1229 | while (self->texs <= texid) |
1166 | { |
1230 | { |
1167 | Append (maptex, self->tex, self->texs, self->texs); |
1231 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1191 | // from transparent color bleeding and ugly wrapping effects. |
1255 | // from transparent color bleeding and ugly wrapping effects. |
1192 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1256 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1193 | } |
1257 | } |
1194 | |
1258 | |
1195 | int |
1259 | int |
1196 | ox (CFClient::Map self) |
1260 | ox (CFPlus::Map self) |
1197 | ALIAS: |
1261 | ALIAS: |
1198 | oy = 1 |
1262 | oy = 1 |
1199 | x = 2 |
1263 | x = 2 |
1200 | y = 3 |
1264 | y = 3 |
1201 | w = 4 |
1265 | w = 4 |
… | |
… | |
1212 | } |
1276 | } |
1213 | OUTPUT: |
1277 | OUTPUT: |
1214 | RETVAL |
1278 | RETVAL |
1215 | |
1279 | |
1216 | void |
1280 | void |
1217 | scroll (CFClient::Map self, int dx, int dy) |
1281 | scroll (CFPlus::Map self, int dx, int dy) |
1218 | CODE: |
1282 | CODE: |
1219 | { |
1283 | { |
1220 | if (dx > 0) |
1284 | if (dx > 0) |
1221 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1285 | map_blank (self, self->x, self->y, dx, self->h); |
1222 | else if (dx < 0) |
1286 | else if (dx < 0) |
1223 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1287 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1224 | |
1288 | |
1225 | if (dy > 0) |
1289 | if (dy > 0) |
1226 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1290 | map_blank (self, self->x, self->y, self->w, dy); |
1227 | else if (dy < 0) |
1291 | else if (dy < 0) |
1228 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1292 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1229 | |
1293 | |
1230 | self->ox += dx; self->x += dx; |
1294 | self->ox += dx; self->x += dx; |
1231 | self->oy += dy; self->y += dy; |
1295 | self->oy += dy; self->y += dy; |
1232 | |
1296 | |
1233 | while (self->y < 0) |
1297 | while (self->y < 0) |
… | |
… | |
1238 | self->y += MAP_EXTEND_Y; |
1302 | self->y += MAP_EXTEND_Y; |
1239 | } |
1303 | } |
1240 | } |
1304 | } |
1241 | |
1305 | |
1242 | void |
1306 | void |
1243 | map1a_update (CFClient::Map self, SV *data_) |
1307 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1244 | CODE: |
1308 | CODE: |
1245 | { |
1309 | { |
1246 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1310 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1247 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1311 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1248 | mapcell *cell; |
1312 | mapcell *cell; |
1249 | int x, y, flags; |
1313 | int x, y, flags; |
1250 | |
1314 | |
1251 | while (data < data_end) |
1315 | while (data < data_end - 1) |
1252 | { |
1316 | { |
1253 | flags = (data [0] << 8) + data [1]; data += 2; |
1317 | flags = (data [0] << 8) + data [1]; data += 2; |
1254 | |
1318 | |
1255 | x = self->x + ((flags >> 10) & 63); |
1319 | x = self->x + ((flags >> 10) & 63); |
1256 | y = self->y + ((flags >> 4) & 63); |
1320 | y = self->y + ((flags >> 4) & 63); |
1257 | |
1321 | |
1258 | cell = map_get_cell (self, x, y); |
1322 | cell = map_get_cell (self, x, y); |
1259 | |
1323 | |
1260 | if (flags & 15) |
1324 | if (flags & 15) |
1261 | { |
1325 | { |
1262 | if (cell->darkness < 0) |
1326 | if (!cell->darkness) |
1263 | { |
1327 | { |
|
|
1328 | memset (cell, 0, sizeof (*cell)); |
1264 | cell->darkness = 0; |
1329 | cell->darkness = 256; |
1265 | cell->face [0] = 0; |
|
|
1266 | cell->face [1] = 0; |
|
|
1267 | cell->face [2] = 0; |
|
|
1268 | } |
1330 | } |
1269 | |
1331 | |
1270 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1271 | |
|
|
1272 | //TODO: don't trust server data to be in-range(!) |
1332 | //TODO: don't trust server data to be in-range(!) |
|
|
1333 | |
|
|
1334 | if (flags & 8) |
|
|
1335 | { |
|
|
1336 | if (extmap) |
|
|
1337 | { |
|
|
1338 | uint8_t ext, cmd; |
|
|
1339 | |
|
|
1340 | do |
|
|
1341 | { |
|
|
1342 | ext = *data++; |
|
|
1343 | cmd = ext & 0x3f; |
|
|
1344 | |
|
|
1345 | if (cmd < 4) |
|
|
1346 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1347 | else if (cmd == 5) // health |
|
|
1348 | { |
|
|
1349 | cell->stat_width = 1; |
|
|
1350 | cell->stat_hp = *data++; |
|
|
1351 | } |
|
|
1352 | else if (cmd == 6) // monster width |
|
|
1353 | cell->stat_width = *data++ + 1; |
|
|
1354 | else if (cmd == 0x47) // monster width |
|
|
1355 | { |
|
|
1356 | if (*data == 4) |
|
|
1357 | ; // decode player tag |
|
|
1358 | |
|
|
1359 | data += *data + 1; |
|
|
1360 | } |
|
|
1361 | else if (cmd == 8) // cell flags |
|
|
1362 | cell->flags = *data++; |
|
|
1363 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1364 | data += *data + 1; |
|
|
1365 | else |
|
|
1366 | data++; |
|
|
1367 | } |
|
|
1368 | while (ext & 0x80); |
|
|
1369 | } |
|
|
1370 | else |
|
|
1371 | cell->darkness = *data++ + 1; |
|
|
1372 | } |
1273 | |
1373 | |
1274 | if (flags & 4) |
1374 | if (flags & 4) |
1275 | { |
1375 | { |
1276 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1376 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1277 | } |
1377 | } |
… | |
… | |
1285 | { |
1385 | { |
1286 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1386 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1287 | } |
1387 | } |
1288 | } |
1388 | } |
1289 | else |
1389 | else |
1290 | cell->darkness = -1; |
1390 | cell->darkness = 0; |
1291 | } |
1391 | } |
1292 | } |
1392 | } |
1293 | |
1393 | |
1294 | SV * |
1394 | SV * |
1295 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
1395 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1296 | CODE: |
1396 | CODE: |
1297 | { |
1397 | { |
1298 | int x1, x; |
1398 | int x1, x; |
1299 | int y1, y; |
1399 | int y1, y; |
1300 | int z; |
1400 | int z; |
… | |
… | |
1350 | } |
1450 | } |
1351 | OUTPUT: |
1451 | OUTPUT: |
1352 | RETVAL |
1452 | RETVAL |
1353 | |
1453 | |
1354 | void |
1454 | void |
1355 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1455 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1356 | CODE: |
1456 | CODE: |
1357 | { |
1457 | { |
1358 | int vx, vy; |
1458 | int vx, vy; |
1359 | int x, y, z; |
1459 | int x, y, z; |
1360 | int last_name; |
1460 | int last_name; |
… | |
… | |
1395 | { |
1495 | { |
1396 | mapcell *cell = row->col + (x + vx - row->c0); |
1496 | mapcell *cell = row->col + (x + vx - row->c0); |
1397 | |
1497 | |
1398 | face = cell->face [z]; |
1498 | face = cell->face [z]; |
1399 | |
1499 | |
1400 | if (face) |
1500 | if (face && face < self->texs) |
1401 | { |
1501 | { |
1402 | maptex tex = self->tex [face]; |
1502 | maptex tex = self->tex [face]; |
1403 | |
|
|
1404 | int px = (x + 1) * 32 - tex.w; |
1503 | int px = (x + 1) * 32 - tex.w; |
1405 | int py = (y + 1) * 32 - tex.h; |
1504 | int py = (y + 1) * 32 - tex.h; |
1406 | |
1505 | |
1407 | if (last_name != tex.name) |
1506 | if (last_name != tex.name) |
1408 | { |
1507 | { |
1409 | glEnd (); |
1508 | glEnd (); |
1410 | last_name = tex.name; |
|
|
1411 | glBindTexture (GL_TEXTURE_2D, last_name); |
1509 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1412 | glBegin (GL_QUADS); |
1510 | glBegin (GL_QUADS); |
1413 | } |
1511 | } |
1414 | |
1512 | |
1415 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1513 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1416 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1514 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1417 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1515 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1418 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1516 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1419 | } |
1517 | } |
|
|
1518 | |
|
|
1519 | if (cell->flags && z == 2) |
|
|
1520 | { |
|
|
1521 | if (cell->flags & 1) |
|
|
1522 | { |
|
|
1523 | maptex tex = self->tex [1]; |
|
|
1524 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1525 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1526 | |
|
|
1527 | glEnd (); |
|
|
1528 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1529 | glBegin (GL_QUADS); |
|
|
1530 | |
|
|
1531 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1532 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1533 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1534 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1535 | } |
|
|
1536 | } |
1420 | } |
1537 | } |
1421 | } |
1538 | } |
1422 | |
1539 | |
1423 | glEnd (); |
1540 | glEnd (); |
1424 | |
1541 | |
1425 | glDisable (GL_TEXTURE_2D); |
1542 | glDisable (GL_TEXTURE_2D); |
1426 | glDisable (GL_BLEND); |
1543 | glDisable (GL_BLEND); |
1427 | } |
|
|
1428 | |
1544 | |
|
|
1545 | // top layer: overlays such as the health bar |
|
|
1546 | for (y = 0; y < sh; y++) |
|
|
1547 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1548 | { |
|
|
1549 | maprow *row = self->row + (y + vy); |
|
|
1550 | |
|
|
1551 | for (x = 0; x < sw; x++) |
|
|
1552 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1553 | { |
|
|
1554 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1555 | |
|
|
1556 | int px = x * 32; |
|
|
1557 | int py = y * 32; |
|
|
1558 | |
|
|
1559 | if (cell->stat_hp) |
|
|
1560 | { |
|
|
1561 | int width = cell->stat_width * 32; |
|
|
1562 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1563 | |
|
|
1564 | glColor3ub (0, 0, 0); |
|
|
1565 | glRectf (px + 1, py - thick - 2, |
|
|
1566 | px + width - 1, py); |
|
|
1567 | |
|
|
1568 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1569 | glRectf (px + 2, |
|
|
1570 | py - thick - 1, |
|
|
1571 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1572 | } |
|
|
1573 | } |
|
|
1574 | } |
|
|
1575 | } |
|
|
1576 | |
1429 | void |
1577 | void |
1430 | draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1578 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1431 | CODE: |
1579 | CODE: |
1432 | { |
1580 | { |
1433 | static float color[16][3] = { |
1581 | static float color[16][3] = { |
1434 | { 0.00F, 0.00F, 0.00F }, |
1582 | { 0.00F, 0.00F, 0.00F }, |
1435 | { 1.00F, 1.00F, 1.00F }, |
1583 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
1485 | glDisable (GL_BLEND); |
1633 | glDisable (GL_BLEND); |
1486 | glDisable (GL_TEXTURE_2D); |
1634 | glDisable (GL_TEXTURE_2D); |
1487 | } |
1635 | } |
1488 | |
1636 | |
1489 | void |
1637 | void |
1490 | fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1638 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1491 | PPCODE: |
1639 | PPCODE: |
1492 | { |
1640 | { |
1493 | int vx, vy; |
1641 | int vx, vy; |
1494 | int x, y; |
1642 | int x, y; |
1495 | int sw4 = (sw + 3) & ~3; |
1643 | int sw4 = (sw + 3) & ~3; |
… | |
… | |
1511 | for (x = 0; x < sw; x++) |
1659 | for (x = 0; x < sw; x++) |
1512 | if (row->c0 <= x + vx && x + vx < row->c1) |
1660 | if (row->c0 <= x + vx && x + vx < row->c1) |
1513 | { |
1661 | { |
1514 | mapcell *cell = row->col + (x + vx - row->c0); |
1662 | mapcell *cell = row->col + (x + vx - row->c0); |
1515 | |
1663 | |
1516 | darkness[y * sw4 + x] = cell->darkness < 0 |
1664 | darkness[y * sw4 + x] = cell->darkness |
|
|
1665 | ? 255 - (cell->darkness - 1) |
1517 | ? 255 - FOW_DARKNESS |
1666 | : 255 - FOW_DARKNESS; |
1518 | : 255 - cell->darkness; |
|
|
1519 | } |
1667 | } |
1520 | } |
1668 | } |
1521 | |
1669 | |
1522 | EXTEND (SP, 3); |
1670 | EXTEND (SP, 3); |
1523 | PUSHs (sv_2mortal (newSViv (sw4))); |
1671 | PUSHs (sv_2mortal (newSViv (sw4))); |
1524 | PUSHs (sv_2mortal (newSViv (sh))); |
1672 | PUSHs (sv_2mortal (newSViv (sh))); |
1525 | PUSHs (darkness_sv); |
1673 | PUSHs (darkness_sv); |
1526 | } |
1674 | } |
1527 | |
1675 | |
1528 | SV * |
1676 | SV * |
1529 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
1677 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
1530 | CODE: |
1678 | CODE: |
1531 | { |
1679 | { |
1532 | int x, y, x1, y1; |
1680 | int x, y, x1, y1; |
1533 | SV *data_sv = newSV (w * h * 7 + 5); |
1681 | SV *data_sv = newSV (w * h * 7 + 5); |
1534 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1682 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1596 | } |
1744 | } |
1597 | OUTPUT: |
1745 | OUTPUT: |
1598 | RETVAL |
1746 | RETVAL |
1599 | |
1747 | |
1600 | void |
1748 | void |
1601 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
1749 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
1602 | PPCODE: |
1750 | PPCODE: |
1603 | { |
1751 | { |
1604 | int x, y, z; |
1752 | int x, y, z; |
1605 | int w, h; |
1753 | int w, h; |
1606 | int x1, y1; |
1754 | int x1, y1; |
… | |
… | |
1638 | |
1786 | |
1639 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1787 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1640 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1788 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1641 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1789 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1642 | |
1790 | |
1643 | if (cell->darkness <= 0) |
1791 | if (cell->darkness == 0) |
1644 | { |
1792 | { |
1645 | cell->darkness = -1; |
1793 | cell->darkness = 0; |
1646 | |
1794 | |
1647 | for (z = 0; z <= 2; z++) |
1795 | for (z = 0; z <= 2; z++) |
1648 | { |
1796 | { |
1649 | cell->face[z] = face[z]; |
1797 | cell->face[z] = face[z]; |
1650 | |
1798 | |
… | |
… | |
1655 | } |
1803 | } |
1656 | } |
1804 | } |
1657 | } |
1805 | } |
1658 | } |
1806 | } |
1659 | |
1807 | |
1660 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1808 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1661 | |
1809 | |
1662 | CFClient::MixChunk |
1810 | CFPlus::MixChunk |
1663 | new_from_file (SV *class, char *path) |
1811 | new_from_file (SV *class, char *path) |
1664 | CODE: |
1812 | CODE: |
1665 | RETVAL = Mix_LoadWAV (path); |
1813 | RETVAL = Mix_LoadWAV (path); |
1666 | OUTPUT: |
1814 | OUTPUT: |
1667 | RETVAL |
1815 | RETVAL |
1668 | |
1816 | |
1669 | void |
1817 | void |
1670 | DESTROY (CFClient::MixChunk self) |
1818 | DESTROY (CFPlus::MixChunk self) |
1671 | CODE: |
1819 | CODE: |
1672 | Mix_FreeChunk (self); |
1820 | Mix_FreeChunk (self); |
1673 | |
1821 | |
1674 | int |
1822 | int |
1675 | volume (CFClient::MixChunk self, int volume = -1) |
1823 | volume (CFPlus::MixChunk self, int volume = -1) |
1676 | CODE: |
1824 | CODE: |
1677 | RETVAL = Mix_VolumeChunk (self, volume); |
1825 | RETVAL = Mix_VolumeChunk (self, volume); |
1678 | OUTPUT: |
1826 | OUTPUT: |
1679 | RETVAL |
1827 | RETVAL |
1680 | |
1828 | |
1681 | int |
1829 | int |
1682 | play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1830 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1683 | CODE: |
1831 | CODE: |
1684 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1832 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1685 | OUTPUT: |
1833 | OUTPUT: |
1686 | RETVAL |
1834 | RETVAL |
1687 | |
1835 | |
1688 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1836 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1689 | |
1837 | |
1690 | int |
1838 | int |
1691 | volume (int volume = -1) |
1839 | volume (int volume = -1) |
1692 | CODE: |
1840 | CODE: |
1693 | RETVAL = Mix_VolumeMusic (volume); |
1841 | RETVAL = Mix_VolumeMusic (volume); |
1694 | OUTPUT: |
1842 | OUTPUT: |
1695 | RETVAL |
1843 | RETVAL |
1696 | |
1844 | |
1697 | CFClient::MixMusic |
1845 | CFPlus::MixMusic |
1698 | new_from_file (SV *class, char *path) |
1846 | new_from_file (SV *class, char *path) |
1699 | CODE: |
1847 | CODE: |
1700 | RETVAL = Mix_LoadMUS (path); |
1848 | RETVAL = Mix_LoadMUS (path); |
1701 | OUTPUT: |
1849 | OUTPUT: |
1702 | RETVAL |
1850 | RETVAL |
1703 | |
1851 | |
1704 | void |
1852 | void |
1705 | DESTROY (CFClient::MixMusic self) |
1853 | DESTROY (CFPlus::MixMusic self) |
1706 | CODE: |
1854 | CODE: |
1707 | Mix_FreeMusic (self); |
1855 | Mix_FreeMusic (self); |
1708 | |
1856 | |
1709 | int |
1857 | int |
1710 | play (CFClient::MixMusic self, int loops = -1) |
1858 | play (CFPlus::MixMusic self, int loops = -1) |
1711 | CODE: |
1859 | CODE: |
1712 | RETVAL = Mix_PlayMusic (self, loops); |
1860 | RETVAL = Mix_PlayMusic (self, loops); |
1713 | OUTPUT: |
1861 | OUTPUT: |
1714 | RETVAL |
1862 | RETVAL |
1715 | |
1863 | |
1716 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1864 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1717 | |
1865 | |
1718 | BOOT: |
1866 | BOOT: |
1719 | { |
1867 | { |
1720 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1868 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1721 | static const struct { |
1869 | static const struct { |
1722 | const char *name; |
1870 | const char *name; |
1723 | IV iv; |
1871 | IV iv; |
1724 | } *civ, const_iv[] = { |
1872 | } *civ, const_iv[] = { |
1725 | # define const_iv(name) { # name, (IV)name } |
1873 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1788 | const_iv (GL_SEPARABLE_2D), |
1936 | const_iv (GL_SEPARABLE_2D), |
1789 | const_iv (GL_CONVOLUTION_2D), |
1937 | const_iv (GL_CONVOLUTION_2D), |
1790 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1938 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1791 | const_iv (GL_CONSTANT_BORDER), |
1939 | const_iv (GL_CONSTANT_BORDER), |
1792 | const_iv (GL_LINES), |
1940 | const_iv (GL_LINES), |
|
|
1941 | const_iv (GL_LINE_STRIP), |
1793 | const_iv (GL_LINE_LOOP), |
1942 | const_iv (GL_LINE_LOOP), |
1794 | const_iv (GL_QUADS), |
1943 | const_iv (GL_QUADS), |
1795 | const_iv (GL_QUAD_STRIP), |
1944 | const_iv (GL_QUAD_STRIP), |
1796 | const_iv (GL_TRIANGLES), |
1945 | const_iv (GL_TRIANGLES), |
1797 | const_iv (GL_TRIANGLE_STRIP), |
1946 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1907 | r *= a; |
2056 | r *= a; |
1908 | g *= a; |
2057 | g *= a; |
1909 | b *= a; |
2058 | b *= a; |
1910 | } |
2059 | } |
1911 | // microsoft visual "c" rounds instead of truncating... |
2060 | // microsoft visual "c" rounds instead of truncating... |
1912 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2061 | 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 | |
2062 | |
1917 | void glInterleavedArrays (int format, int stride, char *data) |
2063 | void glInterleavedArrays (int format, int stride, char *data) |
1918 | |
2064 | |
1919 | void glDrawElements (int mode, int count, int type, char *indices) |
2065 | void glDrawElements (int mode, int count, int type, char *indices) |
1920 | |
2066 | |
… | |
… | |
1997 | |
2143 | |
1998 | void glEndList () |
2144 | void glEndList () |
1999 | |
2145 | |
2000 | void glCallList (int list) |
2146 | void glCallList (int list) |
2001 | |
2147 | |
2002 | |
|
|