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> |
… | |
… | |
18 | #include <SDL_endian.h> |
24 | #include <SDL_endian.h> |
19 | #include <SDL_image.h> |
25 | #include <SDL_image.h> |
20 | #include <SDL_mixer.h> |
26 | #include <SDL_mixer.h> |
21 | #include <SDL_opengl.h> |
27 | #include <SDL_opengl.h> |
22 | |
28 | |
|
|
29 | #define PANGO_ENABLE_BACKEND |
|
|
30 | #define G_DISABLE_CAST_CHECKS |
|
|
31 | |
23 | #include <glib/gmacros.h> |
32 | #include <glib/gmacros.h> |
24 | |
33 | |
25 | #include <pango/pango.h> |
34 | #include <pango/pango.h> |
26 | #include <pango/pangofc-fontmap.h> |
|
|
27 | #include <pango/pangoft2.h> |
|
|
28 | #include <pango/pangocairo.h> |
|
|
29 | |
35 | |
30 | #ifndef _WIN32 |
36 | #ifndef _WIN32 |
31 | # include <sys/types.h> |
37 | # include <sys/types.h> |
32 | # include <sys/socket.h> |
38 | # include <sys/socket.h> |
33 | # include <netinet/in.h> |
39 | # include <netinet/in.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" |
51 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
46 | |
52 | |
47 | #define FOW_DARKNESS 32 |
53 | #define FOW_DARKNESS 32 |
48 | |
54 | |
49 | #define MAP_EXTEND_X 32 |
55 | #define MAP_EXTEND_X 32 |
50 | #define MAP_EXTEND_Y 512 |
56 | #define MAP_EXTEND_Y 512 |
51 | |
57 | |
52 | #define MIN_FONT_HEIGHT 10 |
58 | #define MIN_FONT_HEIGHT 10 |
|
|
59 | |
|
|
60 | #if 0 |
|
|
61 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
|
|
62 | #else |
|
|
63 | # define PARACHUTE 0 |
|
|
64 | #endif |
53 | |
65 | |
54 | static struct |
66 | static struct |
55 | { |
67 | { |
56 | #define GL_FUNC(ptr,name) ptr name; |
68 | #define GL_FUNC(ptr,name) ptr name; |
57 | #include "glfunc.h" |
69 | #include "glfunc.h" |
… | |
… | |
66 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
78 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
67 | else |
79 | else |
68 | glBlendFunc (sa, da); |
80 | glBlendFunc (sa, da); |
69 | } |
81 | } |
70 | |
82 | |
|
|
83 | #include "texcache.c" |
|
|
84 | |
|
|
85 | #include "pango-font.c" |
|
|
86 | #include "pango-fontmap.c" |
|
|
87 | #include "pango-render.c" |
|
|
88 | |
71 | typedef Mix_Chunk *CFClient__MixChunk; |
89 | typedef Mix_Chunk *CFPlus__MixChunk; |
72 | typedef Mix_Music *CFClient__MixMusic; |
90 | typedef Mix_Music *CFPlus__MixMusic; |
73 | |
91 | |
74 | typedef PangoFontDescription *CFClient__Font; |
92 | typedef PangoFontDescription *CFPlus__Font; |
|
|
93 | |
|
|
94 | static int |
|
|
95 | shape_attr_p (PangoLayoutRun *run) |
|
|
96 | { |
|
|
97 | GSList *attrs = run->item->analysis.extra_attrs; |
|
|
98 | |
|
|
99 | while (attrs) |
|
|
100 | { |
|
|
101 | PangoAttribute *attr = attrs->data; |
|
|
102 | |
|
|
103 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
|
|
104 | return 1; |
|
|
105 | |
|
|
106 | attrs = attrs->next; |
|
|
107 | } |
|
|
108 | |
|
|
109 | return 0; |
|
|
110 | } |
75 | |
111 | |
76 | typedef struct cf_layout { |
112 | typedef struct cf_layout { |
77 | PangoLayout *pl; // either derived from a cairo or ft2 context |
113 | PangoLayout *pl; |
78 | int rgba; // wether we use rgba (cairo) or grayscale (ft2) |
|
|
79 | float r, g, b, a; // default color for rgba mode |
114 | float r, g, b, a; // default color for rgba mode |
80 | int base_height; |
115 | int base_height; |
81 | CFClient__Font font; |
116 | CFPlus__Font font; |
82 | } *CFClient__Layout; |
117 | } *CFPlus__Layout; |
83 | |
118 | |
84 | static CFClient__Font default_font; |
119 | static CFPlus__Font default_font; |
85 | static PangoContext *ft2_context, *cairo_context; |
120 | static PangoContext *opengl_context; |
86 | static PangoFontMap *ft2_fontmap, *cairo_fontmap; |
121 | static PangoFontMap *opengl_fontmap; |
87 | |
122 | |
88 | static void |
123 | static void |
89 | substitute_func (FcPattern *pattern, gpointer data) |
124 | substitute_func (FcPattern *pattern, gpointer data) |
90 | { |
125 | { |
91 | FcPatternAddBool (pattern, FC_HINTING, 1); |
126 | FcPatternAddBool (pattern, FC_HINTING, 1); |
92 | #ifdef FC_HINT_STYLE |
127 | #ifdef FC_HINT_STYLE |
93 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
128 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
94 | #endif |
129 | #endif |
95 | #ifdef _WIN32 |
|
|
96 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
|
|
97 | #else |
|
|
98 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
130 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
99 | #endif |
|
|
100 | } |
131 | } |
101 | |
132 | |
102 | static void |
133 | static void |
103 | layout_update_font (CFClient__Layout self) |
134 | layout_update_font (CFPlus__Layout self) |
104 | { |
135 | { |
105 | /* 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 |
106 | * reasonably well with bitstream vera |
137 | * reasonably well with bitstream vera |
107 | */ |
138 | */ |
108 | PangoFontDescription *font = self->font ? self->font : default_font; |
139 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
112 | |
143 | |
113 | pango_layout_set_font_description (self->pl, font); |
144 | pango_layout_set_font_description (self->pl, font); |
114 | } |
145 | } |
115 | |
146 | |
116 | static void |
147 | static void |
117 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
148 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
118 | { |
149 | { |
|
|
150 | PangoRectangle rect; |
|
|
151 | |
|
|
152 | // get_pixel_* wrongly rounds down |
119 | pango_layout_get_pixel_size (self->pl, w, h); |
153 | pango_layout_get_extents (self->pl, 0, &rect); |
120 | |
154 | |
121 | if (!*w) *w = 1; |
155 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
122 | if (!*h) *h = 1; |
156 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
123 | |
157 | |
124 | *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; |
125 | } |
163 | } |
126 | |
164 | |
127 | typedef uint16_t mapface; |
165 | typedef uint16_t mapface; |
128 | |
166 | |
129 | typedef struct { |
167 | typedef struct { |
… | |
… | |
132 | float s, t; |
170 | float s, t; |
133 | uint8_t r, g, b, a; |
171 | uint8_t r, g, b, a; |
134 | } maptex; |
172 | } maptex; |
135 | |
173 | |
136 | typedef struct { |
174 | typedef struct { |
137 | int16_t darkness; |
175 | uint32_t player; |
138 | mapface face[3]; |
176 | mapface face[3]; |
|
|
177 | uint16_t darkness; |
|
|
178 | uint8_t stat_width, stat_hp, flags; |
139 | } mapcell; |
179 | } mapcell; |
140 | |
180 | |
141 | typedef struct { |
181 | typedef struct { |
142 | int32_t c0, c1; |
182 | int32_t c0, c1; |
143 | mapcell *col; |
183 | mapcell *col; |
… | |
… | |
152 | int texs; |
192 | int texs; |
153 | maptex *tex; |
193 | maptex *tex; |
154 | |
194 | |
155 | int32_t rows; |
195 | int32_t rows; |
156 | maprow *row; |
196 | maprow *row; |
157 | } *CFClient__Map; |
197 | } *CFPlus__Map; |
158 | |
198 | |
159 | static char * |
199 | static char * |
160 | prepend (char *ptr, int sze, int inc) |
200 | prepend (char *ptr, int sze, int inc) |
161 | { |
201 | { |
162 | char *p; |
202 | char *p; |
… | |
… | |
180 | |
220 | |
181 | #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)) |
182 | #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)) |
183 | |
223 | |
184 | static maprow * |
224 | static maprow * |
185 | map_get_row (CFClient__Map self, int y) |
225 | map_get_row (CFPlus__Map self, int y) |
186 | { |
226 | { |
187 | if (0 > y) |
227 | if (0 > y) |
188 | { |
228 | { |
189 | int extend = - y + MAP_EXTEND_Y; |
229 | int extend = - y + MAP_EXTEND_Y; |
190 | Prepend (maprow, self->row, self->rows, extend); |
230 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
228 | |
268 | |
229 | return row->col + (x - row->c0); |
269 | return row->col + (x - row->c0); |
230 | } |
270 | } |
231 | |
271 | |
232 | static mapcell * |
272 | static mapcell * |
233 | map_get_cell (CFClient__Map self, int x, int y) |
273 | map_get_cell (CFPlus__Map self, int x, int y) |
234 | { |
274 | { |
235 | return row_get_cell (map_get_row (self, y), x); |
275 | return row_get_cell (map_get_row (self, y), x); |
236 | } |
276 | } |
237 | |
277 | |
238 | static void |
278 | static void |
239 | map_clear (CFClient__Map self) |
279 | map_clear (CFPlus__Map self) |
240 | { |
280 | { |
241 | int r; |
281 | int r; |
242 | |
282 | |
243 | for (r = 0; r < self->rows; r++) |
283 | for (r = 0; r < self->rows; r++) |
244 | Safefree (self->row[r].col); |
284 | Safefree (self->row[r].col); |
… | |
… | |
252 | self->row = 0; |
292 | self->row = 0; |
253 | self->rows = 0; |
293 | self->rows = 0; |
254 | } |
294 | } |
255 | |
295 | |
256 | static void |
296 | static void |
257 | 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) |
258 | { |
298 | { |
259 | int x, y; |
299 | int x, y; |
260 | maprow *row; |
300 | maprow *row; |
|
|
301 | mapcell *cell; |
261 | |
302 | |
262 | for (y = y0; y < y0 + h; y++) |
303 | for (y = y0; y < y0 + h; y++) |
263 | if (y >= 0) |
304 | if (y >= 0) |
264 | { |
305 | { |
265 | if (y >= self->rows) |
306 | if (y >= self->rows) |
… | |
… | |
271 | if (x >= row->c0) |
312 | if (x >= row->c0) |
272 | { |
313 | { |
273 | if (x >= row->c1) |
314 | if (x >= row->c1) |
274 | break; |
315 | break; |
275 | |
316 | |
276 | 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; |
277 | } |
323 | } |
278 | } |
324 | } |
279 | } |
325 | } |
280 | |
326 | |
281 | static void |
327 | static void |
… | |
… | |
319 | n |= n >> 16; |
365 | n |= n >> 16; |
320 | |
366 | |
321 | return n + 1; |
367 | return n + 1; |
322 | } |
368 | } |
323 | |
369 | |
324 | MODULE = CFClient PACKAGE = CFClient |
370 | MODULE = CFPlus PACKAGE = CFPlus |
325 | |
371 | |
326 | PROTOTYPES: ENABLE |
372 | PROTOTYPES: ENABLE |
327 | |
373 | |
328 | BOOT: |
374 | BOOT: |
329 | { |
375 | { |
330 | HV *stash = gv_stashpv ("CFClient", 1); |
376 | HV *stash = gv_stashpv ("CFPlus", 1); |
331 | static const struct { |
377 | static const struct { |
332 | const char *name; |
378 | const char *name; |
333 | IV iv; |
379 | IV iv; |
334 | } *civ, const_iv[] = { |
380 | } *civ, const_iv[] = { |
335 | # define const_iv(name) { # name, (IV)name } |
381 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
436 | |
482 | |
437 | 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; ) |
438 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
484 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
439 | } |
485 | } |
440 | |
486 | |
|
|
487 | int |
|
|
488 | in_destruct () |
|
|
489 | CODE: |
|
|
490 | RETVAL = PL_main_cv == Nullcv; |
|
|
491 | OUTPUT: |
|
|
492 | RETVAL |
|
|
493 | |
|
|
494 | NV floor (NV x) |
|
|
495 | |
|
|
496 | NV ceil (NV x) |
|
|
497 | |
441 | void |
498 | void |
442 | pango_init () |
499 | pango_init () |
443 | CODE: |
500 | CODE: |
444 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
|
|
445 | { |
501 | { |
446 | { |
|
|
447 | ft2_fontmap = pango_ft2_font_map_new (); |
502 | opengl_fontmap = pango_opengl_font_map_new (); |
448 | pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); |
503 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
449 | ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); |
504 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
450 | } |
|
|
451 | { |
|
|
452 | cairo_font_options_t *fopt = cairo_font_options_create (); |
|
|
453 | cairo_fontmap = pango_cairo_font_map_get_default (); |
|
|
454 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
|
|
455 | #ifdef _WIN32 |
|
|
456 | // cairo looks like shit eaten twice on windows |
|
|
457 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); |
|
|
458 | #else |
|
|
459 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); |
|
|
460 | #endif |
|
|
461 | cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); |
|
|
462 | cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); |
|
|
463 | pango_cairo_context_set_font_options (cairo_context, fopt); |
|
|
464 | cairo_font_options_destroy (fopt); |
|
|
465 | } |
|
|
466 | } |
505 | } |
467 | |
506 | |
468 | int |
507 | int |
469 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
508 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
470 | |
509 | |
471 | void |
510 | void |
472 | SDL_Quit () |
511 | SDL_Quit () |
473 | |
512 | |
474 | void |
513 | void |
… | |
… | |
481 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); |
520 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); |
482 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); |
521 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); |
483 | SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); |
522 | SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); |
484 | |
523 | |
485 | SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); |
524 | SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); |
486 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
525 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0); |
487 | |
526 | |
488 | SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); |
527 | SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); |
489 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
528 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
490 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
529 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
491 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
530 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
492 | |
531 | |
493 | 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 |
494 | |
537 | |
495 | SDL_EnableUNICODE (1); |
538 | SDL_EnableUNICODE (1); |
496 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
539 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
497 | |
540 | |
498 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
541 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
585 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
628 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
586 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
629 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
587 | break; |
630 | break; |
588 | } |
631 | } |
589 | |
632 | |
590 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
633 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
591 | } |
634 | } |
592 | } |
635 | } |
593 | |
636 | |
594 | int |
637 | int |
595 | 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) |
… | |
… | |
609 | #ifndef _WIN32 |
652 | #ifndef _WIN32 |
610 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
611 | #endif |
654 | #endif |
612 | |
655 | |
613 | void |
656 | void |
|
|
657 | win32_proxy_info () |
|
|
658 | PPCODE: |
|
|
659 | { |
|
|
660 | #ifdef _WIN32 |
|
|
661 | INTERNET_PROXY_INFO proxyinfo; |
|
|
662 | char buffer[2048]; |
|
|
663 | DWORD buflen; |
|
|
664 | |
|
|
665 | EXTEND (SP, 3); |
|
|
666 | |
|
|
667 | buflen = sizeof (buffer); |
|
|
668 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
669 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
670 | { |
|
|
671 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
672 | |
|
|
673 | buflen = sizeof (buffer); |
|
|
674 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
675 | { |
|
|
676 | PUSHs (newSVpv (buffer, 0)); |
|
|
677 | |
|
|
678 | buflen = sizeof (buffer); |
|
|
679 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
680 | PUSHs (newSVpv (buffer, 0)); |
|
|
681 | } |
|
|
682 | } |
|
|
683 | #endif |
|
|
684 | } |
|
|
685 | |
|
|
686 | void |
614 | add_font (char *file) |
687 | add_font (char *file) |
615 | CODE: |
688 | CODE: |
616 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
689 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
617 | #ifdef _WIN32 |
|
|
618 | // cairo... sigh... requires win2000 |
|
|
619 | AddFontResourceEx (file, FR_PRIVATE, 0); |
|
|
620 | #endif |
|
|
621 | |
690 | |
622 | void |
691 | void |
623 | load_image_inline (SV *image_) |
692 | load_image_inline (SV *image_) |
624 | ALIAS: |
693 | ALIAS: |
625 | load_image_file = 1 |
694 | load_image_file = 1 |
… | |
… | |
667 | |
736 | |
668 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
737 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
669 | |
738 | |
670 | assert (surface2->pitch == surface2->w * 4); |
739 | assert (surface2->pitch == surface2->w * 4); |
671 | |
740 | |
|
|
741 | SDL_LockSurface (surface2); |
672 | EXTEND (SP, 5); |
742 | EXTEND (SP, 6); |
673 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
743 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
674 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
744 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
675 | SDL_LockSurface (surface2); |
|
|
676 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
745 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
677 | SDL_UnlockSurface (surface2); |
|
|
678 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
746 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
679 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
747 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
680 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
748 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
|
|
749 | SDL_UnlockSurface (surface2); |
681 | |
750 | |
682 | SDL_FreeSurface (surface); |
751 | SDL_FreeSurface (surface); |
683 | SDL_FreeSurface (surface2); |
752 | SDL_FreeSurface (surface2); |
684 | } |
753 | } |
685 | |
754 | |
… | |
… | |
728 | void |
797 | void |
729 | _exit (int retval) |
798 | _exit (int retval) |
730 | CODE: |
799 | CODE: |
731 | _exit (retval); |
800 | _exit (retval); |
732 | |
801 | |
733 | MODULE = CFClient PACKAGE = CFClient::Font |
802 | MODULE = CFPlus PACKAGE = CFPlus::Font |
734 | |
803 | |
735 | CFClient::Font |
804 | CFPlus::Font |
736 | new_from_file (SV *class, char *path, int id = 0) |
805 | new_from_file (SV *class, char *path, int id = 0) |
737 | CODE: |
806 | CODE: |
738 | { |
807 | { |
739 | int count; |
808 | int count; |
740 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
809 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
743 | } |
812 | } |
744 | OUTPUT: |
813 | OUTPUT: |
745 | RETVAL |
814 | RETVAL |
746 | |
815 | |
747 | void |
816 | void |
748 | DESTROY (CFClient::Font self) |
817 | DESTROY (CFPlus::Font self) |
749 | CODE: |
818 | CODE: |
750 | pango_font_description_free (self); |
819 | pango_font_description_free (self); |
751 | |
820 | |
752 | void |
821 | void |
753 | make_default (CFClient::Font self) |
822 | make_default (CFPlus::Font self) |
754 | CODE: |
823 | CODE: |
755 | default_font = self; |
824 | default_font = self; |
756 | |
825 | |
757 | MODULE = CFClient PACKAGE = CFClient::Layout |
826 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
758 | |
827 | |
759 | CFClient::Layout |
828 | void |
760 | new (SV *class, int rgba = 0) |
829 | reset_glyph_cache () |
|
|
830 | CODE: |
|
|
831 | tc_clear (); |
|
|
832 | |
|
|
833 | CFPlus::Layout |
|
|
834 | new (SV *class) |
761 | CODE: |
835 | CODE: |
762 | New (0, RETVAL, 1, struct cf_layout); |
836 | New (0, RETVAL, 1, struct cf_layout); |
763 | |
837 | |
764 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
838 | RETVAL->pl = pango_layout_new (opengl_context); |
765 | RETVAL->rgba = rgba; |
|
|
766 | RETVAL->r = 1.; |
839 | RETVAL->r = 1.; |
767 | RETVAL->g = 1.; |
840 | RETVAL->g = 1.; |
768 | RETVAL->b = 1.; |
841 | RETVAL->b = 1.; |
769 | RETVAL->a = 1.; |
842 | RETVAL->a = 1.; |
770 | RETVAL->base_height = MIN_FONT_HEIGHT; |
843 | RETVAL->base_height = MIN_FONT_HEIGHT; |
… | |
… | |
774 | layout_update_font (RETVAL); |
847 | layout_update_font (RETVAL); |
775 | OUTPUT: |
848 | OUTPUT: |
776 | RETVAL |
849 | RETVAL |
777 | |
850 | |
778 | void |
851 | void |
779 | DESTROY (CFClient::Layout self) |
852 | DESTROY (CFPlus::Layout self) |
780 | CODE: |
853 | CODE: |
781 | g_object_unref (self->pl); |
854 | g_object_unref (self->pl); |
782 | Safefree (self); |
855 | Safefree (self); |
783 | |
856 | |
784 | int |
|
|
785 | is_rgba (CFClient::Layout self) |
|
|
786 | CODE: |
|
|
787 | RETVAL = self->rgba; |
|
|
788 | OUTPUT: |
|
|
789 | RETVAL |
|
|
790 | |
|
|
791 | void |
857 | void |
792 | set_text (CFClient::Layout self, SV *text_) |
858 | set_text (CFPlus::Layout self, SV *text_) |
793 | CODE: |
859 | CODE: |
794 | { |
860 | { |
795 | STRLEN textlen; |
861 | STRLEN textlen; |
796 | char *text = SvPVutf8 (text_, textlen); |
862 | char *text = SvPVutf8 (text_, textlen); |
797 | |
863 | |
798 | pango_layout_set_text (self->pl, text, textlen); |
864 | pango_layout_set_text (self->pl, text, textlen); |
799 | } |
865 | } |
800 | |
866 | |
801 | void |
867 | void |
802 | set_markup (CFClient::Layout self, SV *text_) |
868 | set_markup (CFPlus::Layout self, SV *text_) |
803 | CODE: |
869 | CODE: |
804 | { |
870 | { |
805 | STRLEN textlen; |
871 | STRLEN textlen; |
806 | char *text = SvPVutf8 (text_, textlen); |
872 | char *text = SvPVutf8 (text_, textlen); |
807 | |
873 | |
808 | pango_layout_set_markup (self->pl, text, textlen); |
874 | pango_layout_set_markup (self->pl, text, textlen); |
809 | } |
875 | } |
810 | |
876 | |
|
|
877 | void |
|
|
878 | set_shapes (CFPlus::Layout self, ...) |
|
|
879 | CODE: |
|
|
880 | { |
|
|
881 | PangoAttrList *attrs = 0; |
|
|
882 | const char *text = pango_layout_get_text (self->pl); |
|
|
883 | const char *pos = text; |
|
|
884 | int arg = 4; |
|
|
885 | |
|
|
886 | while (arg < items && (pos = strstr (pos, OBJ_STR))) |
|
|
887 | { |
|
|
888 | PangoRectangle inkrect, rect; |
|
|
889 | PangoAttribute *attr; |
|
|
890 | |
|
|
891 | int x = SvIV (ST (arg - 3)); |
|
|
892 | int y = SvIV (ST (arg - 2)); |
|
|
893 | int w = SvIV (ST (arg - 1)); |
|
|
894 | int h = SvIV (ST (arg )); |
|
|
895 | |
|
|
896 | inkrect.x = 0; |
|
|
897 | inkrect.y = 0; |
|
|
898 | inkrect.width = 0; |
|
|
899 | inkrect.height = 0; |
|
|
900 | |
|
|
901 | rect.x = x * PANGO_SCALE; |
|
|
902 | rect.y = y * PANGO_SCALE; |
|
|
903 | rect.width = w * PANGO_SCALE; |
|
|
904 | rect.height = h * PANGO_SCALE; |
|
|
905 | |
|
|
906 | if (!attrs) |
|
|
907 | attrs = pango_layout_get_attributes (self->pl); |
|
|
908 | |
|
|
909 | attr = pango_attr_shape_new (&inkrect, &rect); |
|
|
910 | attr->start_index = pos - text; |
|
|
911 | attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1; |
|
|
912 | pango_attr_list_insert (attrs, attr); |
|
|
913 | |
|
|
914 | arg += 4; |
|
|
915 | pos += sizeof (OBJ_STR) - 1; |
|
|
916 | } |
|
|
917 | |
|
|
918 | if (attrs) |
|
|
919 | pango_layout_set_attributes (self->pl, attrs); |
|
|
920 | } |
|
|
921 | |
|
|
922 | void |
|
|
923 | get_shapes (CFPlus::Layout self) |
|
|
924 | PPCODE: |
|
|
925 | { |
|
|
926 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
|
|
927 | |
|
|
928 | do |
|
|
929 | { |
|
|
930 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
|
|
931 | |
|
|
932 | if (run && shape_attr_p (run)) |
|
|
933 | { |
|
|
934 | PangoRectangle extents; |
|
|
935 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
|
|
936 | |
|
|
937 | EXTEND (SP, 2); |
|
|
938 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
|
|
939 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
|
|
940 | } |
|
|
941 | } |
|
|
942 | while (pango_layout_iter_next_run (iter)); |
|
|
943 | |
|
|
944 | pango_layout_iter_free (iter); |
|
|
945 | } |
|
|
946 | |
|
|
947 | int |
|
|
948 | has_wrapped (CFPlus::Layout self) |
|
|
949 | CODE: |
|
|
950 | { |
|
|
951 | int lines = 1; |
|
|
952 | const char *text = pango_layout_get_text (self->pl); |
|
|
953 | |
|
|
954 | while (*text) |
|
|
955 | lines += *text++ == '\n'; |
|
|
956 | |
|
|
957 | RETVAL = lines < pango_layout_get_line_count (self->pl); |
|
|
958 | } |
|
|
959 | OUTPUT: |
|
|
960 | RETVAL |
|
|
961 | |
811 | SV * |
962 | SV * |
812 | get_text (CFClient::Layout self) |
963 | get_text (CFPlus::Layout self) |
813 | CODE: |
964 | CODE: |
814 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
965 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
815 | sv_utf8_decode (RETVAL); |
966 | sv_utf8_decode (RETVAL); |
816 | OUTPUT: |
967 | OUTPUT: |
817 | RETVAL |
968 | RETVAL |
818 | |
969 | |
819 | void |
970 | void |
820 | set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) |
971 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
821 | CODE: |
972 | CODE: |
822 | self->r = r; |
973 | self->r = r; |
823 | self->g = g; |
974 | self->g = g; |
824 | self->b = b; |
975 | self->b = b; |
825 | self->a = a; |
976 | self->a = a; |
826 | |
977 | |
827 | void |
978 | void |
828 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
979 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
829 | CODE: |
980 | CODE: |
830 | if (self->font != font) |
981 | if (self->font != font) |
831 | { |
982 | { |
832 | self->font = font; |
983 | self->font = font; |
833 | layout_update_font (self); |
984 | layout_update_font (self); |
834 | } |
985 | } |
835 | |
986 | |
836 | void |
987 | void |
837 | set_height (CFClient::Layout self, int base_height) |
988 | set_height (CFPlus::Layout self, int base_height) |
838 | CODE: |
989 | CODE: |
839 | if (self->base_height != base_height) |
990 | if (self->base_height != base_height) |
840 | { |
991 | { |
841 | self->base_height = base_height; |
992 | self->base_height = base_height; |
842 | layout_update_font (self); |
993 | layout_update_font (self); |
843 | } |
994 | } |
844 | |
995 | |
845 | void |
996 | void |
846 | set_width (CFClient::Layout self, int max_width = -1) |
997 | set_width (CFPlus::Layout self, int max_width = -1) |
847 | CODE: |
998 | CODE: |
848 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
999 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
849 | |
1000 | |
850 | void |
1001 | void |
851 | set_indent (CFClient::Layout self, int indent) |
1002 | set_indent (CFPlus::Layout self, int indent) |
852 | CODE: |
1003 | CODE: |
853 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1004 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
854 | |
1005 | |
855 | void |
1006 | void |
856 | set_spacing (CFClient::Layout self, int spacing) |
1007 | set_spacing (CFPlus::Layout self, int spacing) |
857 | CODE: |
1008 | CODE: |
858 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1009 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
859 | |
1010 | |
860 | void |
1011 | void |
861 | set_ellipsise (CFClient::Layout self, int ellipsise) |
1012 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
862 | CODE: |
1013 | CODE: |
863 | pango_layout_set_ellipsize (self->pl, |
1014 | pango_layout_set_ellipsize (self->pl, |
864 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1015 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
865 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1016 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
866 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1017 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
867 | : PANGO_ELLIPSIZE_NONE |
1018 | : PANGO_ELLIPSIZE_NONE |
868 | ); |
1019 | ); |
869 | |
1020 | |
870 | void |
1021 | void |
871 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
1022 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
872 | CODE: |
1023 | CODE: |
873 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1024 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
874 | |
1025 | |
875 | void |
1026 | void |
876 | size (CFClient::Layout self) |
1027 | size (CFPlus::Layout self) |
877 | PPCODE: |
1028 | PPCODE: |
878 | { |
1029 | { |
879 | int w, h; |
1030 | int w, h; |
880 | |
1031 | |
881 | layout_get_pixel_size (self, &w, &h); |
1032 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
884 | PUSHs (sv_2mortal (newSViv (w))); |
1035 | PUSHs (sv_2mortal (newSViv (w))); |
885 | PUSHs (sv_2mortal (newSViv (h))); |
1036 | PUSHs (sv_2mortal (newSViv (h))); |
886 | } |
1037 | } |
887 | |
1038 | |
888 | int |
1039 | int |
|
|
1040 | descent (CFPlus::Layout self) |
|
|
1041 | CODE: |
|
|
1042 | { |
|
|
1043 | PangoRectangle rect; |
|
|
1044 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
|
|
1045 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
|
|
1046 | RETVAL = PANGO_DESCENT (rect); |
|
|
1047 | } |
|
|
1048 | OUTPUT: |
|
|
1049 | RETVAL |
|
|
1050 | |
|
|
1051 | int |
889 | xy_to_index (CFClient::Layout self, int x, int y) |
1052 | xy_to_index (CFPlus::Layout self, int x, int y) |
890 | CODE: |
1053 | CODE: |
891 | { |
1054 | { |
892 | int index, trailing; |
1055 | int index, trailing; |
893 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1056 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
894 | RETVAL = index; |
1057 | RETVAL = index; |
895 | } |
1058 | } |
896 | OUTPUT: |
1059 | OUTPUT: |
897 | RETVAL |
1060 | RETVAL |
898 | |
1061 | |
899 | void |
1062 | void |
900 | cursor_pos (CFClient::Layout self, int index) |
1063 | cursor_pos (CFPlus::Layout self, int index) |
901 | PPCODE: |
1064 | PPCODE: |
902 | { |
1065 | { |
903 | PangoRectangle strong_pos; |
1066 | PangoRectangle strong_pos; |
904 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1067 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
905 | |
1068 | |
… | |
… | |
908 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1071 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
909 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1072 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
910 | } |
1073 | } |
911 | |
1074 | |
912 | void |
1075 | void |
913 | render (CFClient::Layout self) |
1076 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
914 | PPCODE: |
1077 | PPCODE: |
915 | { |
1078 | pango_opengl_render_layout_subpixel ( |
916 | SV *retval; |
1079 | self->pl, |
917 | int w, h; |
1080 | x * PANGO_SCALE, y * PANGO_SCALE, |
918 | |
1081 | self->r, self->g, self->b, self->a, |
919 | layout_get_pixel_size (self, &w, &h); |
|
|
920 | |
|
|
921 | if (self->rgba) |
|
|
922 | { |
1082 | flags |
923 | cairo_surface_t *surface; |
|
|
924 | cairo_t *cairo; |
|
|
925 | |
|
|
926 | retval = newSV (w * h * 4); |
|
|
927 | SvPOK_only (retval); |
|
|
928 | SvCUR_set (retval, w * h * 4); |
|
|
929 | |
|
|
930 | memset (SvPVX (retval), 0, w * h * 4); |
|
|
931 | |
|
|
932 | surface = cairo_image_surface_create_for_data ( |
|
|
933 | (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4); |
|
|
934 | cairo = cairo_create (surface); |
|
|
935 | cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a); |
|
|
936 | |
|
|
937 | pango_cairo_show_layout (cairo, self->pl); |
|
|
938 | |
|
|
939 | cairo_destroy (cairo); |
|
|
940 | cairo_surface_destroy (surface); |
|
|
941 | |
|
|
942 | // what a mess, and its premultiplied, too :( |
|
|
943 | { |
|
|
944 | uint32_t *p = (uint32_t *)SvPVX (retval); |
|
|
945 | uint32_t *e = p + w * h; |
|
|
946 | |
|
|
947 | while (p < e) |
|
|
948 | { |
|
|
949 | uint32_t rgba = *p; |
|
|
950 | rgba = (rgba >> 24) | (rgba << 8); |
|
|
951 | #if 0 |
|
|
952 | #ifdef _WIN32 |
|
|
953 | {//D |
|
|
954 | uint8_t r = rgba >> 24; |
|
|
955 | uint8_t g = rgba >> 16; |
|
|
956 | uint8_t b = rgba >> 8; |
|
|
957 | uint8_t a = rgba >> 0; |
|
|
958 | |
|
|
959 | rgba = (rgba & 0xffffff00) | a; |
|
|
960 | } |
|
|
961 | #endif |
|
|
962 | #endif |
|
|
963 | rgba = SDL_SwapBE32 (rgba); |
|
|
964 | *p++ = rgba; |
|
|
965 | } |
|
|
966 | } |
|
|
967 | |
|
|
968 | EXTEND (SP, 5); |
|
|
969 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
970 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
971 | PUSHs (sv_2mortal (retval)); |
|
|
972 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
973 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
974 | } |
1083 | ); |
975 | else |
|
|
976 | { |
|
|
977 | FT_Bitmap bitmap; |
|
|
978 | |
1084 | |
979 | retval = newSV (w * h); |
|
|
980 | SvPOK_only (retval); |
|
|
981 | SvCUR_set (retval, w * h); |
|
|
982 | |
|
|
983 | bitmap.rows = h; |
|
|
984 | bitmap.width = w; |
|
|
985 | bitmap.pitch = w; |
|
|
986 | bitmap.buffer = (unsigned char*)SvPVX (retval); |
|
|
987 | bitmap.num_grays = 256; |
|
|
988 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
|
|
989 | |
|
|
990 | memset (bitmap.buffer, 0, w * h); |
|
|
991 | |
|
|
992 | pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
|
|
993 | |
|
|
994 | EXTEND (SP, 5); |
|
|
995 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
996 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
997 | PUSHs (sv_2mortal (retval)); |
|
|
998 | PUSHs (sv_2mortal (newSViv (GL_ALPHA))); |
|
|
999 | PUSHs (sv_2mortal (newSViv (GL_ALPHA))); |
|
|
1000 | } |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | MODULE = CFClient PACKAGE = CFClient::Texture |
1085 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1004 | |
1086 | |
1005 | void |
1087 | void |
1006 | pad2pot (SV *data_, SV *w_, SV *h_) |
1088 | pad2pot (SV *data_, SV *w_, SV *h_) |
1007 | CODE: |
1089 | CODE: |
1008 | { |
1090 | { |
… | |
… | |
1038 | } |
1120 | } |
1039 | } |
1121 | } |
1040 | } |
1122 | } |
1041 | |
1123 | |
1042 | void |
1124 | void |
1043 | draw_quad (SV *self, float x, float y, float w = 0, float h = 0) |
1125 | draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) |
1044 | PROTOTYPE: $$$;$$ |
1126 | PROTOTYPE: $$$;$$ |
1045 | ALIAS: |
1127 | ALIAS: |
1046 | draw_quad_alpha = 1 |
1128 | draw_quad_alpha = 1 |
1047 | draw_quad_alpha_premultiplied = 2 |
1129 | draw_quad_alpha_premultiplied = 2 |
1048 | CODE: |
1130 | CODE: |
… | |
… | |
1086 | glDisable (GL_ALPHA_TEST); |
1168 | glDisable (GL_ALPHA_TEST); |
1087 | glDisable (GL_BLEND); |
1169 | glDisable (GL_BLEND); |
1088 | } |
1170 | } |
1089 | } |
1171 | } |
1090 | |
1172 | |
1091 | MODULE = CFClient PACKAGE = CFClient::Map |
1173 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1092 | |
1174 | |
1093 | CFClient::Map |
1175 | CFPlus::Map |
1094 | new (SV *class, int map_width, int map_height) |
1176 | new (SV *class, int map_width, int map_height) |
1095 | CODE: |
1177 | CODE: |
1096 | New (0, RETVAL, 1, struct map); |
1178 | New (0, RETVAL, 1, struct map); |
1097 | RETVAL->x = 0; |
1179 | RETVAL->x = 0; |
1098 | RETVAL->y = 0; |
1180 | RETVAL->y = 0; |
… | |
… | |
1108 | RETVAL->row = 0; |
1190 | RETVAL->row = 0; |
1109 | OUTPUT: |
1191 | OUTPUT: |
1110 | RETVAL |
1192 | RETVAL |
1111 | |
1193 | |
1112 | void |
1194 | void |
1113 | DESTROY (CFClient::Map self) |
1195 | DESTROY (CFPlus::Map self) |
1114 | CODE: |
1196 | CODE: |
1115 | { |
1197 | { |
1116 | map_clear (self); |
1198 | map_clear (self); |
1117 | Safefree (self->face); |
1199 | Safefree (self->face); |
1118 | Safefree (self->tex); |
1200 | Safefree (self->tex); |
1119 | Safefree (self); |
1201 | Safefree (self); |
1120 | } |
1202 | } |
1121 | |
1203 | |
1122 | void |
1204 | void |
1123 | clear (CFClient::Map self) |
1205 | clear (CFPlus::Map self) |
1124 | CODE: |
1206 | CODE: |
1125 | map_clear (self); |
1207 | map_clear (self); |
1126 | |
1208 | |
1127 | void |
1209 | void |
1128 | set_face (CFClient::Map self, int face, int texid) |
1210 | set_face (CFPlus::Map self, int face, int texid) |
1129 | CODE: |
1211 | CODE: |
1130 | { |
1212 | { |
1131 | while (self->faces <= face) |
1213 | while (self->faces <= face) |
1132 | { |
1214 | { |
1133 | Append (mapface, self->face, self->faces, self->faces); |
1215 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1136 | |
1218 | |
1137 | self->face [face] = texid; |
1219 | self->face [face] = texid; |
1138 | } |
1220 | } |
1139 | |
1221 | |
1140 | void |
1222 | void |
1141 | 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) |
1223 | 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) |
1142 | CODE: |
1224 | CODE: |
1143 | { |
1225 | { |
1144 | while (self->texs <= texid) |
1226 | while (self->texs <= texid) |
1145 | { |
1227 | { |
1146 | Append (maptex, self->tex, self->texs, self->texs); |
1228 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1170 | // from transparent color bleeding and ugly wrapping effects. |
1252 | // from transparent color bleeding and ugly wrapping effects. |
1171 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1253 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1172 | } |
1254 | } |
1173 | |
1255 | |
1174 | int |
1256 | int |
1175 | ox (CFClient::Map self) |
1257 | ox (CFPlus::Map self) |
1176 | ALIAS: |
1258 | ALIAS: |
1177 | oy = 1 |
1259 | oy = 1 |
1178 | x = 2 |
1260 | x = 2 |
1179 | y = 3 |
1261 | y = 3 |
1180 | w = 4 |
1262 | w = 4 |
… | |
… | |
1191 | } |
1273 | } |
1192 | OUTPUT: |
1274 | OUTPUT: |
1193 | RETVAL |
1275 | RETVAL |
1194 | |
1276 | |
1195 | void |
1277 | void |
1196 | scroll (CFClient::Map self, int dx, int dy) |
1278 | scroll (CFPlus::Map self, int dx, int dy) |
1197 | CODE: |
1279 | CODE: |
1198 | { |
1280 | { |
1199 | if (dx > 0) |
1281 | if (dx > 0) |
1200 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1282 | map_blank (self, self->x, self->y, dx, self->h); |
1201 | else if (dx < 0) |
1283 | else if (dx < 0) |
1202 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1284 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1203 | |
1285 | |
1204 | if (dy > 0) |
1286 | if (dy > 0) |
1205 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1287 | map_blank (self, self->x, self->y, self->w, dy); |
1206 | else if (dy < 0) |
1288 | else if (dy < 0) |
1207 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1289 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1208 | |
1290 | |
1209 | self->ox += dx; self->x += dx; |
1291 | self->ox += dx; self->x += dx; |
1210 | self->oy += dy; self->y += dy; |
1292 | self->oy += dy; self->y += dy; |
1211 | |
1293 | |
1212 | while (self->y < 0) |
1294 | while (self->y < 0) |
… | |
… | |
1217 | self->y += MAP_EXTEND_Y; |
1299 | self->y += MAP_EXTEND_Y; |
1218 | } |
1300 | } |
1219 | } |
1301 | } |
1220 | |
1302 | |
1221 | void |
1303 | void |
1222 | map1a_update (CFClient::Map self, SV *data_) |
1304 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1223 | CODE: |
1305 | CODE: |
1224 | { |
1306 | { |
1225 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1307 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1226 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1308 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1227 | mapcell *cell; |
1309 | mapcell *cell; |
1228 | int x, y, flags; |
1310 | int x, y, flags; |
1229 | |
1311 | |
1230 | while (data < data_end) |
1312 | while (data < data_end - 1) |
1231 | { |
1313 | { |
1232 | flags = (data [0] << 8) + data [1]; data += 2; |
1314 | flags = (data [0] << 8) + data [1]; data += 2; |
1233 | |
1315 | |
1234 | x = ((flags >> 10) & 63) + self->x; |
1316 | x = self->x + ((flags >> 10) & 63); |
1235 | y = ((flags >> 4) & 63) + self->y; |
1317 | y = self->y + ((flags >> 4) & 63); |
1236 | |
1318 | |
1237 | cell = map_get_cell (self, x, y); |
1319 | cell = map_get_cell (self, x, y); |
1238 | |
1320 | |
1239 | if (flags & 15) |
1321 | if (flags & 15) |
1240 | { |
1322 | { |
1241 | if (cell->darkness < 0) |
1323 | if (!cell->darkness) |
1242 | { |
1324 | { |
|
|
1325 | memset (cell, 0, sizeof (*cell)); |
1243 | cell->darkness = 0; |
1326 | cell->darkness = 256; |
1244 | cell->face [0] = 0; |
|
|
1245 | cell->face [1] = 0; |
|
|
1246 | cell->face [2] = 0; |
|
|
1247 | } |
1327 | } |
1248 | |
1328 | |
1249 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1250 | |
|
|
1251 | //TODO: don't trust server data to be in-range(!) |
1329 | //TODO: don't trust server data to be in-range(!) |
|
|
1330 | |
|
|
1331 | if (flags & 8) |
|
|
1332 | { |
|
|
1333 | if (extmap) |
|
|
1334 | { |
|
|
1335 | uint8_t ext, cmd; |
|
|
1336 | |
|
|
1337 | do |
|
|
1338 | { |
|
|
1339 | ext = *data++; |
|
|
1340 | cmd = ext & 0x3f; |
|
|
1341 | |
|
|
1342 | if (cmd < 4) |
|
|
1343 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1344 | else if (cmd == 5) // health |
|
|
1345 | { |
|
|
1346 | cell->stat_width = 1; |
|
|
1347 | cell->stat_hp = *data++; |
|
|
1348 | } |
|
|
1349 | else if (cmd == 6) // monster width |
|
|
1350 | cell->stat_width = *data++ + 1; |
|
|
1351 | else if (cmd == 0x47) // monster width |
|
|
1352 | { |
|
|
1353 | if (*data == 4) |
|
|
1354 | ; // decode player tag |
|
|
1355 | |
|
|
1356 | data += *data + 1; |
|
|
1357 | } |
|
|
1358 | else if (cmd == 8) // cell flags |
|
|
1359 | cell->flags = *data++; |
|
|
1360 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1361 | data += *data + 1; |
|
|
1362 | else |
|
|
1363 | data++; |
|
|
1364 | } |
|
|
1365 | while (ext & 0x80); |
|
|
1366 | } |
|
|
1367 | else |
|
|
1368 | cell->darkness = *data++ + 1; |
|
|
1369 | } |
1252 | |
1370 | |
1253 | if (flags & 4) |
1371 | if (flags & 4) |
1254 | { |
1372 | { |
1255 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1373 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1256 | } |
1374 | } |
… | |
… | |
1264 | { |
1382 | { |
1265 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1383 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1266 | } |
1384 | } |
1267 | } |
1385 | } |
1268 | else |
1386 | else |
1269 | cell->darkness = -1; |
1387 | cell->darkness = 0; |
1270 | } |
1388 | } |
1271 | } |
1389 | } |
1272 | |
1390 | |
1273 | SV * |
1391 | SV * |
1274 | mapmap (CFClient::Map self, int x0, int y0, int w, int h) |
1392 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1275 | CODE: |
1393 | CODE: |
1276 | { |
1394 | { |
1277 | int x1, x; |
1395 | int x1, x; |
1278 | int y1, y; |
1396 | int y1, y; |
1279 | int z; |
1397 | int z; |
… | |
… | |
1329 | } |
1447 | } |
1330 | OUTPUT: |
1448 | OUTPUT: |
1331 | RETVAL |
1449 | RETVAL |
1332 | |
1450 | |
1333 | void |
1451 | void |
1334 | draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1452 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1335 | PPCODE: |
1453 | CODE: |
1336 | { |
1454 | { |
1337 | int vx, vy; |
1455 | int vx, vy; |
1338 | int x, y, z; |
1456 | int x, y, z; |
1339 | int last_name; |
1457 | int last_name; |
1340 | mapface face; |
1458 | mapface face; |
1341 | int sw4 = (sw + 3) & ~3; |
|
|
1342 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
1343 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
1344 | |
1459 | |
1345 | memset (darkness, 255, sw4 * sh); |
|
|
1346 | SvPOK_only (darkness_sv); |
|
|
1347 | SvCUR_set (darkness_sv, sw4 * sh); |
|
|
1348 | |
|
|
1349 | vx = self->x + (self->w - sw) / 2 - shift_x; |
1460 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
1350 | vy = self->y + (self->h - sh) / 2 - shift_y; |
1461 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
1351 | |
1462 | |
1352 | /* |
1463 | /* |
1353 | int vx = self->vx = self->w >= sw |
1464 | int vx = self->vx = self->w >= sw |
1354 | ? self->x + (self->w - sw) / 2 |
1465 | ? self->x + (self->w - sw) / 2 |
1355 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
1466 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
… | |
… | |
1359 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
1470 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
1360 | */ |
1471 | */ |
1361 | |
1472 | |
1362 | glColor4ub (255, 255, 255, 255); |
1473 | glColor4ub (255, 255, 255, 255); |
1363 | |
1474 | |
|
|
1475 | glEnable (GL_BLEND); |
1364 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1476 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1365 | glEnable (GL_BLEND); |
|
|
1366 | glEnable (GL_TEXTURE_2D); |
1477 | glEnable (GL_TEXTURE_2D); |
1367 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1478 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1368 | |
1479 | |
1369 | glBegin (GL_QUADS); |
1480 | glBegin (GL_QUADS); |
1370 | |
1481 | |
… | |
… | |
1379 | for (x = 0; x < sw; x++) |
1490 | for (x = 0; x < sw; x++) |
1380 | if (row->c0 <= x + vx && x + vx < row->c1) |
1491 | if (row->c0 <= x + vx && x + vx < row->c1) |
1381 | { |
1492 | { |
1382 | mapcell *cell = row->col + (x + vx - row->c0); |
1493 | mapcell *cell = row->col + (x + vx - row->c0); |
1383 | |
1494 | |
1384 | darkness[y * sw4 + x] = cell->darkness < 0 |
|
|
1385 | ? 255 - FOW_DARKNESS |
|
|
1386 | : 255 - cell->darkness; |
|
|
1387 | |
|
|
1388 | face = cell->face [z]; |
1495 | face = cell->face [z]; |
1389 | |
1496 | |
1390 | if (face) |
1497 | if (face && face < self->texs) |
1391 | { |
1498 | { |
1392 | maptex tex = self->tex [face]; |
1499 | maptex tex = self->tex [face]; |
1393 | |
|
|
1394 | int px = (x + 1) * 32 - tex.w; |
1500 | int px = (x + 1) * 32 - tex.w; |
1395 | int py = (y + 1) * 32 - tex.h; |
1501 | int py = (y + 1) * 32 - tex.h; |
1396 | |
1502 | |
1397 | if (last_name != tex.name) |
1503 | if (last_name != tex.name) |
1398 | { |
1504 | { |
1399 | glEnd (); |
1505 | glEnd (); |
1400 | last_name = tex.name; |
|
|
1401 | glBindTexture (GL_TEXTURE_2D, last_name); |
1506 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1402 | glBegin (GL_QUADS); |
1507 | glBegin (GL_QUADS); |
1403 | } |
1508 | } |
1404 | |
1509 | |
1405 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1510 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1406 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1511 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1407 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1512 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1408 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1513 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1409 | } |
1514 | } |
|
|
1515 | |
|
|
1516 | if (cell->flags && z == 2) |
|
|
1517 | { |
|
|
1518 | if (cell->flags & 1) |
|
|
1519 | { |
|
|
1520 | maptex tex = self->tex [1]; |
|
|
1521 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1522 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1523 | |
|
|
1524 | glEnd (); |
|
|
1525 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1526 | glBegin (GL_QUADS); |
|
|
1527 | |
|
|
1528 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1529 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1530 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1531 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1532 | } |
|
|
1533 | } |
1410 | } |
1534 | } |
1411 | } |
1535 | } |
1412 | |
1536 | |
1413 | glEnd (); |
1537 | glEnd (); |
1414 | |
1538 | |
1415 | glDisable (GL_TEXTURE_2D); |
1539 | glDisable (GL_TEXTURE_2D); |
1416 | glDisable (GL_BLEND); |
1540 | glDisable (GL_BLEND); |
|
|
1541 | |
|
|
1542 | // top layer: overlays such as the health bar |
|
|
1543 | for (y = 0; y < sh; y++) |
|
|
1544 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1545 | { |
|
|
1546 | maprow *row = self->row + (y + vy); |
|
|
1547 | |
|
|
1548 | for (x = 0; x < sw; x++) |
|
|
1549 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1550 | { |
|
|
1551 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1552 | |
|
|
1553 | int px = x * 32; |
|
|
1554 | int py = y * 32; |
|
|
1555 | |
|
|
1556 | if (cell->stat_hp) |
|
|
1557 | { |
|
|
1558 | int width = cell->stat_width * 32; |
|
|
1559 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1560 | |
|
|
1561 | glColor3ub (0, 0, 0); |
|
|
1562 | glRectf (px + 1, py - thick - 2, |
|
|
1563 | px + width - 1, py); |
|
|
1564 | |
|
|
1565 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1566 | glRectf (px + 2, |
|
|
1567 | py - thick - 1, |
|
|
1568 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1569 | } |
|
|
1570 | } |
|
|
1571 | } |
|
|
1572 | } |
|
|
1573 | |
|
|
1574 | void |
|
|
1575 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
|
|
1576 | CODE: |
|
|
1577 | { |
|
|
1578 | static float color[16][3] = { |
|
|
1579 | { 0.00F, 0.00F, 0.00F }, |
|
|
1580 | { 1.00F, 1.00F, 1.00F }, |
|
|
1581 | { 0.00F, 0.00F, 0.55F }, |
|
|
1582 | { 1.00F, 0.00F, 0.00F }, |
|
|
1583 | |
|
|
1584 | { 1.00F, 0.54F, 0.00F }, |
|
|
1585 | { 0.11F, 0.56F, 1.00F }, |
|
|
1586 | { 0.93F, 0.46F, 0.00F }, |
|
|
1587 | { 0.18F, 0.54F, 0.34F }, |
|
|
1588 | |
|
|
1589 | { 0.56F, 0.73F, 0.56F }, |
|
|
1590 | { 0.80F, 0.80F, 0.80F }, |
|
|
1591 | { 0.55F, 0.41F, 0.13F }, |
|
|
1592 | { 0.99F, 0.77F, 0.26F }, |
|
|
1593 | |
|
|
1594 | { 0.74F, 0.65F, 0.41F }, |
|
|
1595 | |
|
|
1596 | { 0.00F, 1.00F, 1.00F }, |
|
|
1597 | { 1.00F, 0.00F, 1.00F }, |
|
|
1598 | { 1.00F, 1.00F, 0.00F }, |
|
|
1599 | }; |
|
|
1600 | |
|
|
1601 | int x, y; |
|
|
1602 | |
|
|
1603 | glEnable (GL_TEXTURE_2D); |
|
|
1604 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1605 | glEnable (GL_BLEND); |
|
|
1606 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1607 | glBegin (GL_QUADS); |
|
|
1608 | |
|
|
1609 | for (y = 0; y < h; y++) |
|
|
1610 | for (x = 0; x < w; x++) |
|
|
1611 | { |
|
|
1612 | unsigned char m = data [x + y * w]; |
|
|
1613 | |
|
|
1614 | if (m) |
|
|
1615 | { |
|
|
1616 | float *c = color [m & 15]; |
|
|
1617 | |
|
|
1618 | float tx1 = m & 0x40 ? 0.5 : 0.; |
|
|
1619 | float tx2 = tx1 + 0.5; |
|
|
1620 | |
|
|
1621 | glColor4f (c[0], c[1], c[2], 0.75); |
|
|
1622 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
|
|
1623 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
|
|
1624 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
|
|
1625 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
|
|
1626 | } |
|
|
1627 | } |
|
|
1628 | |
|
|
1629 | glEnd (); |
|
|
1630 | glDisable (GL_BLEND); |
|
|
1631 | glDisable (GL_TEXTURE_2D); |
|
|
1632 | } |
|
|
1633 | |
|
|
1634 | void |
|
|
1635 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
|
|
1636 | PPCODE: |
|
|
1637 | { |
|
|
1638 | int vx, vy; |
|
|
1639 | int x, y; |
|
|
1640 | int sw4 = (sw + 3) & ~3; |
|
|
1641 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
1642 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
1643 | |
|
|
1644 | memset (darkness, 255, sw4 * sh); |
|
|
1645 | SvPOK_only (darkness_sv); |
|
|
1646 | SvCUR_set (darkness_sv, sw4 * sh); |
|
|
1647 | |
|
|
1648 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
|
|
1649 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
|
|
1650 | |
|
|
1651 | for (y = 0; y < sh; y++) |
|
|
1652 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1653 | { |
|
|
1654 | maprow *row = self->row + (y + vy); |
|
|
1655 | |
|
|
1656 | for (x = 0; x < sw; x++) |
|
|
1657 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1658 | { |
|
|
1659 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1660 | |
|
|
1661 | darkness[y * sw4 + x] = cell->darkness |
|
|
1662 | ? 255 - (cell->darkness - 1) |
|
|
1663 | : 255 - FOW_DARKNESS; |
|
|
1664 | } |
|
|
1665 | } |
1417 | |
1666 | |
1418 | EXTEND (SP, 3); |
1667 | EXTEND (SP, 3); |
1419 | PUSHs (sv_2mortal (newSViv (sw4))); |
1668 | PUSHs (sv_2mortal (newSViv (sw4))); |
1420 | PUSHs (sv_2mortal (newSViv (sh))); |
1669 | PUSHs (sv_2mortal (newSViv (sh))); |
1421 | PUSHs (darkness_sv); |
1670 | PUSHs (darkness_sv); |
1422 | } |
1671 | } |
1423 | |
1672 | |
1424 | SV * |
1673 | SV * |
1425 | get_rect (CFClient::Map self, int x0, int y0, int w, int h) |
1674 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
1426 | CODE: |
1675 | CODE: |
1427 | { |
1676 | { |
1428 | int x, y, x1, y1; |
1677 | int x, y, x1, y1; |
1429 | SV *data_sv = newSV (w * h * 7 + 5); |
1678 | SV *data_sv = newSV (w * h * 7 + 5); |
1430 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1679 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1492 | } |
1741 | } |
1493 | OUTPUT: |
1742 | OUTPUT: |
1494 | RETVAL |
1743 | RETVAL |
1495 | |
1744 | |
1496 | void |
1745 | void |
1497 | set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) |
1746 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
1498 | PPCODE: |
1747 | PPCODE: |
1499 | { |
1748 | { |
1500 | int x, y, z; |
1749 | int x, y, z; |
1501 | int w, h; |
1750 | int w, h; |
1502 | int x1, y1; |
1751 | int x1, y1; |
… | |
… | |
1534 | |
1783 | |
1535 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1784 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1536 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1785 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1537 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1786 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1538 | |
1787 | |
1539 | if (cell->darkness <= 0) |
1788 | if (cell->darkness == 0) |
1540 | { |
1789 | { |
1541 | cell->darkness = -1; |
1790 | cell->darkness = 0; |
1542 | |
1791 | |
1543 | for (z = 0; z <= 2; z++) |
1792 | for (z = 0; z <= 2; z++) |
1544 | { |
1793 | { |
1545 | cell->face[z] = face[z]; |
1794 | cell->face[z] = face[z]; |
1546 | |
1795 | |
… | |
… | |
1551 | } |
1800 | } |
1552 | } |
1801 | } |
1553 | } |
1802 | } |
1554 | } |
1803 | } |
1555 | |
1804 | |
1556 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1805 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1557 | |
1806 | |
1558 | CFClient::MixChunk |
1807 | CFPlus::MixChunk |
1559 | new_from_file (SV *class, char *path) |
1808 | new_from_file (SV *class, char *path) |
1560 | CODE: |
1809 | CODE: |
1561 | RETVAL = Mix_LoadWAV (path); |
1810 | RETVAL = Mix_LoadWAV (path); |
1562 | OUTPUT: |
1811 | OUTPUT: |
1563 | RETVAL |
1812 | RETVAL |
1564 | |
1813 | |
1565 | void |
1814 | void |
1566 | DESTROY (CFClient::MixChunk self) |
1815 | DESTROY (CFPlus::MixChunk self) |
1567 | CODE: |
1816 | CODE: |
1568 | Mix_FreeChunk (self); |
1817 | Mix_FreeChunk (self); |
1569 | |
1818 | |
1570 | int |
1819 | int |
1571 | volume (CFClient::MixChunk self, int volume = -1) |
1820 | volume (CFPlus::MixChunk self, int volume = -1) |
1572 | CODE: |
1821 | CODE: |
1573 | RETVAL = Mix_VolumeChunk (self, volume); |
1822 | RETVAL = Mix_VolumeChunk (self, volume); |
1574 | OUTPUT: |
1823 | OUTPUT: |
1575 | RETVAL |
1824 | RETVAL |
1576 | |
1825 | |
1577 | int |
1826 | int |
1578 | play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1827 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
1579 | CODE: |
1828 | CODE: |
1580 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1829 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1581 | OUTPUT: |
1830 | OUTPUT: |
1582 | RETVAL |
1831 | RETVAL |
1583 | |
1832 | |
1584 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1833 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1585 | |
1834 | |
1586 | int |
1835 | int |
1587 | volume (int volume = -1) |
1836 | volume (int volume = -1) |
1588 | CODE: |
1837 | CODE: |
1589 | RETVAL = Mix_VolumeMusic (volume); |
1838 | RETVAL = Mix_VolumeMusic (volume); |
1590 | OUTPUT: |
1839 | OUTPUT: |
1591 | RETVAL |
1840 | RETVAL |
1592 | |
1841 | |
1593 | CFClient::MixMusic |
1842 | CFPlus::MixMusic |
1594 | new_from_file (SV *class, char *path) |
1843 | new_from_file (SV *class, char *path) |
1595 | CODE: |
1844 | CODE: |
1596 | RETVAL = Mix_LoadMUS (path); |
1845 | RETVAL = Mix_LoadMUS (path); |
1597 | OUTPUT: |
1846 | OUTPUT: |
1598 | RETVAL |
1847 | RETVAL |
1599 | |
1848 | |
1600 | void |
1849 | void |
1601 | DESTROY (CFClient::MixMusic self) |
1850 | DESTROY (CFPlus::MixMusic self) |
1602 | CODE: |
1851 | CODE: |
1603 | Mix_FreeMusic (self); |
1852 | Mix_FreeMusic (self); |
1604 | |
1853 | |
1605 | int |
1854 | int |
1606 | play (CFClient::MixMusic self, int loops = -1) |
1855 | play (CFPlus::MixMusic self, int loops = -1) |
1607 | CODE: |
1856 | CODE: |
1608 | RETVAL = Mix_PlayMusic (self, loops); |
1857 | RETVAL = Mix_PlayMusic (self, loops); |
1609 | OUTPUT: |
1858 | OUTPUT: |
1610 | RETVAL |
1859 | RETVAL |
1611 | |
1860 | |
1612 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1861 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1613 | |
1862 | |
1614 | BOOT: |
1863 | BOOT: |
1615 | { |
1864 | { |
1616 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1865 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1617 | static const struct { |
1866 | static const struct { |
1618 | const char *name; |
1867 | const char *name; |
1619 | IV iv; |
1868 | IV iv; |
1620 | } *civ, const_iv[] = { |
1869 | } *civ, const_iv[] = { |
1621 | # define const_iv(name) { # name, (IV)name } |
1870 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1628 | const_iv (GL_SCISSOR_TEST), |
1877 | const_iv (GL_SCISSOR_TEST), |
1629 | const_iv (GL_DEPTH_TEST), |
1878 | const_iv (GL_DEPTH_TEST), |
1630 | const_iv (GL_ALPHA_TEST), |
1879 | const_iv (GL_ALPHA_TEST), |
1631 | const_iv (GL_NORMALIZE), |
1880 | const_iv (GL_NORMALIZE), |
1632 | const_iv (GL_RESCALE_NORMAL), |
1881 | const_iv (GL_RESCALE_NORMAL), |
|
|
1882 | const_iv (GL_FRONT), |
|
|
1883 | const_iv (GL_BACK), |
1633 | const_iv (GL_AND), |
1884 | const_iv (GL_AND), |
1634 | const_iv (GL_ONE), |
1885 | const_iv (GL_ONE), |
1635 | const_iv (GL_ZERO), |
1886 | const_iv (GL_ZERO), |
1636 | const_iv (GL_SRC_ALPHA), |
1887 | const_iv (GL_SRC_ALPHA), |
1637 | const_iv (GL_DST_ALPHA), |
1888 | const_iv (GL_DST_ALPHA), |
1638 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1889 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1639 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
1890 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
1640 | const_iv (GL_SRC_ALPHA_SATURATE), |
1891 | const_iv (GL_SRC_ALPHA_SATURATE), |
1641 | const_iv (GL_RGB), |
1892 | const_iv (GL_RGB), |
1642 | const_iv (GL_RGBA), |
1893 | const_iv (GL_RGBA), |
|
|
1894 | const_iv (GL_RGBA4), |
|
|
1895 | const_iv (GL_RGBA8), |
|
|
1896 | const_iv (GL_RGB5_A1), |
1643 | const_iv (GL_UNSIGNED_BYTE), |
1897 | const_iv (GL_UNSIGNED_BYTE), |
1644 | const_iv (GL_UNSIGNED_SHORT), |
1898 | const_iv (GL_UNSIGNED_SHORT), |
1645 | const_iv (GL_UNSIGNED_INT), |
1899 | const_iv (GL_UNSIGNED_INT), |
1646 | const_iv (GL_ALPHA), |
1900 | const_iv (GL_ALPHA), |
1647 | const_iv (GL_INTENSITY), |
1901 | const_iv (GL_INTENSITY), |
… | |
… | |
1679 | const_iv (GL_SEPARABLE_2D), |
1933 | const_iv (GL_SEPARABLE_2D), |
1680 | const_iv (GL_CONVOLUTION_2D), |
1934 | const_iv (GL_CONVOLUTION_2D), |
1681 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1935 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1682 | const_iv (GL_CONSTANT_BORDER), |
1936 | const_iv (GL_CONSTANT_BORDER), |
1683 | const_iv (GL_LINES), |
1937 | const_iv (GL_LINES), |
|
|
1938 | const_iv (GL_LINE_STRIP), |
1684 | const_iv (GL_LINE_LOOP), |
1939 | const_iv (GL_LINE_LOOP), |
1685 | const_iv (GL_QUADS), |
1940 | const_iv (GL_QUADS), |
1686 | const_iv (GL_QUAD_STRIP), |
1941 | const_iv (GL_QUAD_STRIP), |
1687 | const_iv (GL_TRIANGLES), |
1942 | const_iv (GL_TRIANGLES), |
1688 | const_iv (GL_TRIANGLE_STRIP), |
1943 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1721 | OUTPUT: |
1976 | OUTPUT: |
1722 | RETVAL |
1977 | RETVAL |
1723 | |
1978 | |
1724 | int glGetError () |
1979 | int glGetError () |
1725 | |
1980 | |
|
|
1981 | void glFinish () |
|
|
1982 | |
1726 | void glClear (int mask) |
1983 | void glClear (int mask) |
1727 | |
1984 | |
1728 | void glClearColor (float r, float g, float b, float a = 1.0) |
1985 | void glClearColor (float r, float g, float b, float a = 1.0) |
1729 | PROTOTYPE: @ |
1986 | PROTOTYPE: @ |
1730 | |
1987 | |
… | |
… | |
1753 | void glPushMatrix () |
2010 | void glPushMatrix () |
1754 | |
2011 | |
1755 | void glPopMatrix () |
2012 | void glPopMatrix () |
1756 | |
2013 | |
1757 | void glLoadIdentity () |
2014 | void glLoadIdentity () |
|
|
2015 | |
|
|
2016 | void glDrawBuffer (int buffer) |
|
|
2017 | |
|
|
2018 | void glReadBuffer (int buffer) |
1758 | |
2019 | |
1759 | # near_ and far_ are due to microsofts buggy "c" compiler |
2020 | # near_ and far_ are due to microsofts buggy "c" compiler |
1760 | void glFrustum (double left, double right, double bottom, double top, double near_, double far_) |
2021 | void glFrustum (double left, double right, double bottom, double top, double near_, double far_) |
1761 | |
2022 | |
1762 | # near_ and far_ are due to microsofts buggy "c" compiler |
2023 | # near_ and far_ are due to microsofts buggy "c" compiler |
… | |
… | |
1792 | r *= a; |
2053 | r *= a; |
1793 | g *= a; |
2054 | g *= a; |
1794 | b *= a; |
2055 | b *= a; |
1795 | } |
2056 | } |
1796 | // microsoft visual "c" rounds instead of truncating... |
2057 | // microsoft visual "c" rounds instead of truncating... |
1797 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2058 | glColor4f (r, g, b, a); |
1798 | MIN ((int)(g * 256.f), 255), |
|
|
1799 | MIN ((int)(b * 256.f), 255), |
|
|
1800 | MIN ((int)(a * 256.f), 255)); |
|
|
1801 | |
2059 | |
1802 | void glInterleavedArrays (int format, int stride, char *data) |
2060 | void glInterleavedArrays (int format, int stride, char *data) |
1803 | |
2061 | |
1804 | void glDrawElements (int mode, int count, int type, char *indices) |
2062 | void glDrawElements (int mode, int count, int type, char *indices) |
1805 | |
2063 | |
… | |
… | |
1882 | |
2140 | |
1883 | void glEndList () |
2141 | void glEndList () |
1884 | |
2142 | |
1885 | void glCallList (int list) |
2143 | void glCallList (int list) |
1886 | |
2144 | |
1887 | |
|
|