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