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" |
11 | |
13 | |
|
|
14 | #ifdef _WIN32 |
|
|
15 | # undef pipe |
|
|
16 | #endif |
|
|
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> |
|
|
21 | #include <stdlib.h> |
15 | |
22 | |
16 | #include <SDL.h> |
23 | #include <SDL.h> |
17 | #include <SDL_endian.h> |
24 | #include <SDL_endian.h> |
18 | #include <SDL_image.h> |
25 | #include <SDL_image.h> |
19 | #include <SDL_mixer.h> |
26 | #include <SDL_mixer.h> |
20 | #include <SDL_opengl.h> |
27 | #include <SDL_opengl.h> |
21 | |
28 | |
|
|
29 | #define PANGO_ENABLE_BACKEND |
|
|
30 | #define G_DISABLE_CAST_CHECKS |
|
|
31 | |
22 | #include <glib/gmacros.h> |
32 | #include <glib/gmacros.h> |
23 | |
33 | |
24 | #include <pango/pango.h> |
34 | #include <pango/pango.h> |
25 | #include <pango/pangofc-fontmap.h> |
|
|
26 | #include <pango/pangoft2.h> |
|
|
27 | #include <pango/pangocairo.h> |
|
|
28 | |
35 | |
29 | #ifndef _WIN32 |
36 | #ifndef _WIN32 |
30 | # include <sys/types.h> |
37 | # include <sys/types.h> |
31 | # include <sys/socket.h> |
38 | # include <sys/socket.h> |
32 | # include <netinet/in.h> |
39 | # include <netinet/in.h> |
… | |
… | |
39 | typedef signed char int8_t; |
46 | typedef signed char int8_t; |
40 | typedef signed short int16_t; |
47 | typedef signed short int16_t; |
41 | typedef signed int int32_t; |
48 | typedef signed int int32_t; |
42 | #endif |
49 | #endif |
43 | |
50 | |
44 | #include "glext.h" |
51 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
45 | |
52 | |
46 | #define FOW_DARKNESS 32 |
53 | #define FOW_DARKNESS 32 |
47 | |
54 | |
48 | #define MAP_EXTEND_X 32 |
55 | #define MAP_EXTEND_X 32 |
49 | #define MAP_EXTEND_Y 512 |
56 | #define MAP_EXTEND_Y 512 |
50 | |
57 | |
51 | #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 |
52 | |
65 | |
53 | static struct |
66 | static struct |
54 | { |
67 | { |
55 | #define GL_FUNC(ptr,name) ptr name; |
68 | #define GL_FUNC(ptr,name) ptr name; |
56 | #include "glfunc.h" |
69 | #include "glfunc.h" |
… | |
… | |
65 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
78 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
66 | else |
79 | else |
67 | glBlendFunc (sa, da); |
80 | glBlendFunc (sa, da); |
68 | } |
81 | } |
69 | |
82 | |
|
|
83 | #include "texcache.c" |
|
|
84 | |
|
|
85 | #include "pango-font.c" |
|
|
86 | #include "pango-fontmap.c" |
|
|
87 | #include "pango-render.c" |
|
|
88 | |
70 | typedef Mix_Chunk *CFClient__MixChunk; |
89 | typedef Mix_Chunk *CFPlus__MixChunk; |
71 | typedef Mix_Music *CFClient__MixMusic; |
90 | typedef Mix_Music *CFPlus__MixMusic; |
72 | |
91 | |
73 | 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 | } |
74 | |
111 | |
75 | typedef struct cf_layout { |
112 | typedef struct cf_layout { |
76 | PangoLayout *pl; // either derived from a cairo or ft2 context |
113 | PangoLayout *pl; |
77 | int rgba; // wether we use rgba (cairo) or grayscale (ft2) |
|
|
78 | float r, g, b, a; // default color for rgba mode |
114 | float r, g, b, a; // default color for rgba mode |
79 | int base_height; |
115 | int base_height; |
80 | CFClient__Font font; |
116 | CFPlus__Font font; |
81 | } *CFClient__Layout; |
117 | } *CFPlus__Layout; |
82 | |
118 | |
83 | static CFClient__Font default_font; |
119 | static CFPlus__Font default_font; |
84 | static PangoContext *ft2_context, *cairo_context; |
120 | static PangoContext *opengl_context; |
85 | static PangoFontMap *ft2_fontmap, *cairo_fontmap; |
121 | static PangoFontMap *opengl_fontmap; |
86 | |
122 | |
87 | static void |
123 | static void |
88 | substitute_func (FcPattern *pattern, gpointer data) |
124 | substitute_func (FcPattern *pattern, gpointer data) |
89 | { |
125 | { |
90 | FcPatternAddBool (pattern, FC_HINTING, 1); |
126 | FcPatternAddBool (pattern, FC_HINTING, 1); |
|
|
127 | #ifdef FC_HINT_STYLE |
91 | FcPatternAddBool (pattern, FC_HINTSTYLE, FC_HINT_FULL); |
128 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
92 | #ifdef _WIN32 |
129 | #endif |
93 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
|
|
94 | #else |
|
|
95 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
130 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
96 | #endif |
|
|
97 | } |
131 | } |
98 | |
132 | |
99 | static void |
133 | static void |
100 | layout_update_font (CFClient__Layout self) |
134 | layout_update_font (CFPlus__Layout self) |
101 | { |
135 | { |
102 | /* 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 |
103 | * reasonably well with bitstream vera |
137 | * reasonably well with bitstream vera |
104 | */ |
138 | */ |
105 | PangoFontDescription *font = self->font ? self->font : default_font; |
139 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
109 | |
143 | |
110 | pango_layout_set_font_description (self->pl, font); |
144 | pango_layout_set_font_description (self->pl, font); |
111 | } |
145 | } |
112 | |
146 | |
113 | static void |
147 | static void |
114 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
148 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
115 | { |
149 | { |
|
|
150 | PangoRectangle rect; |
|
|
151 | |
|
|
152 | // get_pixel_* wrongly rounds down |
116 | pango_layout_get_pixel_size (self->pl, w, h); |
153 | pango_layout_get_extents (self->pl, 0, &rect); |
117 | |
154 | |
118 | if (!*w) *w = 1; |
155 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
119 | if (!*h) *h = 1; |
156 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
120 | |
157 | |
121 | *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; |
122 | } |
163 | } |
123 | |
164 | |
124 | typedef uint16_t mapface; |
165 | typedef uint16_t mapface; |
125 | |
166 | |
126 | typedef struct { |
167 | typedef struct { |
… | |
… | |
129 | float s, t; |
170 | float s, t; |
130 | uint8_t r, g, b, a; |
171 | uint8_t r, g, b, a; |
131 | } maptex; |
172 | } maptex; |
132 | |
173 | |
133 | typedef struct { |
174 | typedef struct { |
134 | int16_t darkness; |
175 | uint32_t player; |
135 | mapface face[3]; |
176 | mapface face[3]; |
|
|
177 | uint16_t darkness; |
|
|
178 | uint8_t stat_width, stat_hp, flags; |
136 | } mapcell; |
179 | } mapcell; |
137 | |
180 | |
138 | typedef struct { |
181 | typedef struct { |
139 | int32_t c0, c1; |
182 | int32_t c0, c1; |
140 | mapcell *col; |
183 | mapcell *col; |
… | |
… | |
149 | int texs; |
192 | int texs; |
150 | maptex *tex; |
193 | maptex *tex; |
151 | |
194 | |
152 | int32_t rows; |
195 | int32_t rows; |
153 | maprow *row; |
196 | maprow *row; |
154 | } *CFClient__Map; |
197 | } *CFPlus__Map; |
155 | |
198 | |
156 | static char * |
199 | static char * |
157 | prepend (char *ptr, int sze, int inc) |
200 | prepend (char *ptr, int sze, int inc) |
158 | { |
201 | { |
159 | char *p; |
202 | char *p; |
… | |
… | |
177 | |
220 | |
178 | #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)) |
179 | #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)) |
180 | |
223 | |
181 | static maprow * |
224 | static maprow * |
182 | map_get_row (CFClient__Map self, int y) |
225 | map_get_row (CFPlus__Map self, int y) |
183 | { |
226 | { |
184 | if (0 > y) |
227 | if (0 > y) |
185 | { |
228 | { |
186 | int extend = - y + MAP_EXTEND_Y; |
229 | int extend = - y + MAP_EXTEND_Y; |
187 | Prepend (maprow, self->row, self->rows, extend); |
230 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
225 | |
268 | |
226 | return row->col + (x - row->c0); |
269 | return row->col + (x - row->c0); |
227 | } |
270 | } |
228 | |
271 | |
229 | static mapcell * |
272 | static mapcell * |
230 | map_get_cell (CFClient__Map self, int x, int y) |
273 | map_get_cell (CFPlus__Map self, int x, int y) |
231 | { |
274 | { |
232 | return row_get_cell (map_get_row (self, y), x); |
275 | return row_get_cell (map_get_row (self, y), x); |
233 | } |
276 | } |
234 | |
277 | |
235 | static void |
278 | static void |
236 | map_clear (CFClient__Map self) |
279 | map_clear (CFPlus__Map self) |
237 | { |
280 | { |
238 | int r; |
281 | int r; |
239 | |
282 | |
240 | for (r = 0; r < self->rows; r++) |
283 | for (r = 0; r < self->rows; r++) |
241 | Safefree (self->row[r].col); |
284 | Safefree (self->row[r].col); |
… | |
… | |
249 | self->row = 0; |
292 | self->row = 0; |
250 | self->rows = 0; |
293 | self->rows = 0; |
251 | } |
294 | } |
252 | |
295 | |
253 | static void |
296 | static void |
254 | 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) |
255 | { |
298 | { |
256 | int x, y; |
299 | int x, y; |
257 | maprow *row; |
300 | maprow *row; |
|
|
301 | mapcell *cell; |
258 | |
302 | |
259 | for (y = y0; y < y0 + h; y++) |
303 | for (y = y0; y < y0 + h; y++) |
260 | if (y >= 0) |
304 | if (y >= 0) |
261 | { |
305 | { |
262 | if (y >= self->rows) |
306 | if (y >= self->rows) |
… | |
… | |
268 | if (x >= row->c0) |
312 | if (x >= row->c0) |
269 | { |
313 | { |
270 | if (x >= row->c1) |
314 | if (x >= row->c1) |
271 | break; |
315 | break; |
272 | |
316 | |
273 | 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; |
274 | } |
323 | } |
275 | } |
324 | } |
276 | } |
325 | } |
277 | |
326 | |
278 | static void |
327 | static void |
… | |
… | |
299 | ev.data2 = 0; |
348 | ev.data2 = 0; |
300 | |
349 | |
301 | SDL_PushEvent ((SDL_Event *)&ev); |
350 | SDL_PushEvent ((SDL_Event *)&ev); |
302 | } |
351 | } |
303 | |
352 | |
|
|
353 | static unsigned int |
|
|
354 | minpot (unsigned int n) |
|
|
355 | { |
|
|
356 | if (!n) |
|
|
357 | return 0; |
|
|
358 | |
|
|
359 | --n; |
|
|
360 | |
|
|
361 | n |= n >> 1; |
|
|
362 | n |= n >> 2; |
|
|
363 | n |= n >> 4; |
|
|
364 | n |= n >> 8; |
|
|
365 | n |= n >> 16; |
|
|
366 | |
|
|
367 | return n + 1; |
|
|
368 | } |
|
|
369 | |
304 | MODULE = CFClient PACKAGE = CFClient |
370 | MODULE = CFPlus PACKAGE = CFPlus |
305 | |
371 | |
306 | PROTOTYPES: ENABLE |
372 | PROTOTYPES: ENABLE |
307 | |
373 | |
308 | BOOT: |
374 | BOOT: |
309 | { |
375 | { |
310 | HV *stash = gv_stashpv ("CFClient", 1); |
376 | HV *stash = gv_stashpv ("CFPlus", 1); |
311 | static const struct { |
377 | static const struct { |
312 | const char *name; |
378 | const char *name; |
313 | IV iv; |
379 | IV iv; |
314 | } *civ, const_iv[] = { |
380 | } *civ, const_iv[] = { |
315 | # define const_iv(name) { # name, (IV)name } |
381 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
416 | |
482 | |
417 | 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; ) |
418 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
484 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
419 | } |
485 | } |
420 | |
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 | |
421 | void |
498 | void |
422 | pango_init () |
499 | pango_init () |
423 | CODE: |
500 | CODE: |
424 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
|
|
425 | { |
501 | { |
426 | { |
|
|
427 | ft2_fontmap = pango_ft2_font_map_new (); |
502 | opengl_fontmap = pango_opengl_font_map_new (); |
428 | 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); |
429 | ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); |
504 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
430 | } |
|
|
431 | { |
|
|
432 | cairo_font_options_t *fopt = cairo_font_options_create (); |
|
|
433 | cairo_fontmap = pango_cairo_font_map_get_default (); |
|
|
434 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
|
|
435 | #ifdef _WIN32 |
|
|
436 | // cairo looks like shit eaten twice on windows |
|
|
437 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); |
|
|
438 | #else |
|
|
439 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); |
|
|
440 | #endif |
|
|
441 | cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); |
|
|
442 | cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); |
|
|
443 | pango_cairo_context_set_font_options (cairo_context, fopt); |
|
|
444 | cairo_font_options_destroy (fopt); |
|
|
445 | } |
|
|
446 | } |
505 | } |
447 | |
506 | |
448 | int |
507 | int |
449 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
508 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
450 | |
509 | |
451 | void |
510 | void |
452 | SDL_Quit () |
511 | SDL_Quit () |
453 | |
512 | |
454 | void |
513 | void |
… | |
… | |
461 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); |
520 | SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); |
462 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); |
521 | SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); |
463 | SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); |
522 | SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); |
464 | |
523 | |
465 | SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); |
524 | SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); |
466 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); |
525 | SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0); |
467 | |
526 | |
468 | SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); |
527 | SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); |
469 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
528 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
470 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
529 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
471 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
530 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
472 | |
531 | |
473 | 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 |
474 | |
537 | |
475 | SDL_EnableUNICODE (1); |
538 | SDL_EnableUNICODE (1); |
476 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
539 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
477 | |
540 | |
478 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
541 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
565 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
628 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
566 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
629 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
567 | break; |
630 | break; |
568 | } |
631 | } |
569 | |
632 | |
570 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
633 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
571 | } |
634 | } |
572 | } |
635 | } |
573 | |
636 | |
574 | int |
637 | int |
575 | 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) |
… | |
… | |
589 | #ifndef _WIN32 |
652 | #ifndef _WIN32 |
590 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
591 | #endif |
654 | #endif |
592 | |
655 | |
593 | 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 |
594 | add_font (char *file) |
687 | add_font (char *file) |
595 | CODE: |
688 | CODE: |
596 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
689 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
597 | #ifdef _WIN32 |
|
|
598 | // cairo... sigh... requires win2000 |
|
|
599 | AddFontResourceEx (file, FR_PRIVATE, 0); |
|
|
600 | #endif |
|
|
601 | |
690 | |
602 | void |
691 | void |
603 | load_image_inline (SV *image_) |
692 | load_image_inline (SV *image_) |
604 | ALIAS: |
693 | ALIAS: |
605 | load_image_file = 1 |
694 | load_image_file = 1 |
… | |
… | |
647 | |
736 | |
648 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
737 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
649 | |
738 | |
650 | assert (surface2->pitch == surface2->w * 4); |
739 | assert (surface2->pitch == surface2->w * 4); |
651 | |
740 | |
|
|
741 | SDL_LockSurface (surface2); |
652 | EXTEND (SP, 5); |
742 | EXTEND (SP, 6); |
653 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
743 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
654 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
744 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
655 | SDL_LockSurface (surface2); |
|
|
656 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
745 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
657 | SDL_UnlockSurface (surface2); |
|
|
658 | 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))); |
659 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
747 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
660 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
748 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
|
|
749 | SDL_UnlockSurface (surface2); |
661 | |
750 | |
662 | SDL_FreeSurface (surface); |
751 | SDL_FreeSurface (surface); |
663 | SDL_FreeSurface (surface2); |
752 | SDL_FreeSurface (surface2); |
664 | } |
753 | } |
665 | |
754 | |
… | |
… | |
701 | CODE: |
790 | CODE: |
702 | fprintf (stderr, "FATAL: %s\n", message); |
791 | fprintf (stderr, "FATAL: %s\n", message); |
703 | #ifdef _WIN32 |
792 | #ifdef _WIN32 |
704 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
793 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
705 | #endif |
794 | #endif |
706 | exit (1); |
795 | _exit (1); |
707 | |
796 | |
|
|
797 | void |
|
|
798 | _exit (int retval = 0) |
|
|
799 | CODE: |
|
|
800 | _exit (retval); |
|
|
801 | |
708 | MODULE = CFClient PACKAGE = CFClient::Font |
802 | MODULE = CFPlus PACKAGE = CFPlus::Font |
709 | |
803 | |
710 | CFClient::Font |
804 | CFPlus::Font |
711 | new_from_file (SV *class, char *path, int id = 0) |
805 | new_from_file (SV *class, char *path, int id = 0) |
712 | CODE: |
806 | CODE: |
713 | { |
807 | { |
714 | int count; |
808 | int count; |
715 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
809 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
718 | } |
812 | } |
719 | OUTPUT: |
813 | OUTPUT: |
720 | RETVAL |
814 | RETVAL |
721 | |
815 | |
722 | void |
816 | void |
723 | DESTROY (CFClient::Font self) |
817 | DESTROY (CFPlus::Font self) |
724 | CODE: |
818 | CODE: |
725 | pango_font_description_free (self); |
819 | pango_font_description_free (self); |
726 | |
820 | |
727 | void |
821 | void |
728 | make_default (CFClient::Font self) |
822 | make_default (CFPlus::Font self) |
729 | CODE: |
823 | CODE: |
730 | default_font = self; |
824 | default_font = self; |
731 | |
825 | |
732 | MODULE = CFClient PACKAGE = CFClient::Layout |
826 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
733 | |
827 | |
734 | CFClient::Layout |
828 | void |
735 | new (SV *class, int rgba = 0) |
829 | reset_glyph_cache () |
|
|
830 | CODE: |
|
|
831 | tc_clear (); |
|
|
832 | |
|
|
833 | CFPlus::Layout |
|
|
834 | new (SV *class) |
736 | CODE: |
835 | CODE: |
737 | New (0, RETVAL, 1, struct cf_layout); |
836 | New (0, RETVAL, 1, struct cf_layout); |
738 | |
837 | |
739 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
838 | RETVAL->pl = pango_layout_new (opengl_context); |
740 | RETVAL->rgba = rgba; |
|
|
741 | RETVAL->r = 1.; |
839 | RETVAL->r = 1.; |
742 | RETVAL->g = 1.; |
840 | RETVAL->g = 1.; |
743 | RETVAL->b = 1.; |
841 | RETVAL->b = 1.; |
744 | RETVAL->a = 1.; |
842 | RETVAL->a = 1.; |
745 | RETVAL->base_height = MIN_FONT_HEIGHT; |
843 | RETVAL->base_height = MIN_FONT_HEIGHT; |
… | |
… | |
749 | layout_update_font (RETVAL); |
847 | layout_update_font (RETVAL); |
750 | OUTPUT: |
848 | OUTPUT: |
751 | RETVAL |
849 | RETVAL |
752 | |
850 | |
753 | void |
851 | void |
754 | DESTROY (CFClient::Layout self) |
852 | DESTROY (CFPlus::Layout self) |
755 | CODE: |
853 | CODE: |
756 | g_object_unref (self->pl); |
854 | g_object_unref (self->pl); |
757 | Safefree (self); |
855 | Safefree (self); |
758 | |
856 | |
759 | int |
|
|
760 | is_rgba (CFClient::Layout self) |
|
|
761 | CODE: |
|
|
762 | RETVAL = self->rgba; |
|
|
763 | OUTPUT: |
|
|
764 | RETVAL |
|
|
765 | |
|
|
766 | void |
857 | void |
767 | set_text (CFClient::Layout self, SV *text_) |
858 | set_text (CFPlus::Layout self, SV *text_) |
768 | CODE: |
859 | CODE: |
769 | { |
860 | { |
770 | STRLEN textlen; |
861 | STRLEN textlen; |
771 | char *text = SvPVutf8 (text_, textlen); |
862 | char *text = SvPVutf8 (text_, textlen); |
772 | |
863 | |
773 | pango_layout_set_text (self->pl, text, textlen); |
864 | pango_layout_set_text (self->pl, text, textlen); |
774 | } |
865 | } |
775 | |
866 | |
776 | void |
867 | void |
777 | set_markup (CFClient::Layout self, SV *text_) |
868 | set_markup (CFPlus::Layout self, SV *text_) |
778 | CODE: |
869 | CODE: |
779 | { |
870 | { |
780 | STRLEN textlen; |
871 | STRLEN textlen; |
781 | char *text = SvPVutf8 (text_, textlen); |
872 | char *text = SvPVutf8 (text_, textlen); |
782 | |
873 | |
783 | pango_layout_set_markup (self->pl, text, textlen); |
874 | pango_layout_set_markup (self->pl, text, textlen); |
784 | } |
875 | } |
785 | |
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 | |
786 | SV * |
962 | SV * |
787 | get_text (CFClient::Layout self) |
963 | get_text (CFPlus::Layout self) |
788 | CODE: |
964 | CODE: |
789 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
965 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
790 | sv_utf8_decode (RETVAL); |
966 | sv_utf8_decode (RETVAL); |
791 | OUTPUT: |
967 | OUTPUT: |
792 | RETVAL |
968 | RETVAL |
793 | |
969 | |
794 | void |
970 | void |
795 | 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.) |
796 | CODE: |
972 | CODE: |
797 | self->r = r; |
973 | self->r = r; |
798 | self->g = g; |
974 | self->g = g; |
799 | self->b = b; |
975 | self->b = b; |
800 | self->a = a; |
976 | self->a = a; |
801 | |
977 | |
802 | void |
978 | void |
803 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
979 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
804 | CODE: |
980 | CODE: |
805 | if (self->font != font) |
981 | if (self->font != font) |
806 | { |
982 | { |
807 | self->font = font; |
983 | self->font = font; |
808 | layout_update_font (self); |
984 | layout_update_font (self); |
809 | } |
985 | } |
810 | |
986 | |
811 | void |
987 | void |
812 | set_height (CFClient::Layout self, int base_height) |
988 | set_height (CFPlus::Layout self, int base_height) |
813 | CODE: |
989 | CODE: |
814 | if (self->base_height != base_height) |
990 | if (self->base_height != base_height) |
815 | { |
991 | { |
816 | self->base_height = base_height; |
992 | self->base_height = base_height; |
817 | layout_update_font (self); |
993 | layout_update_font (self); |
818 | } |
994 | } |
819 | |
995 | |
820 | void |
996 | void |
821 | set_width (CFClient::Layout self, int max_width = -1) |
997 | set_width (CFPlus::Layout self, int max_width = -1) |
822 | CODE: |
998 | CODE: |
823 | 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); |
824 | |
1000 | |
825 | void |
1001 | void |
826 | set_indent (CFClient::Layout self, int indent) |
1002 | set_indent (CFPlus::Layout self, int indent) |
827 | CODE: |
1003 | CODE: |
828 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1004 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
829 | |
1005 | |
830 | void |
1006 | void |
831 | set_spacing (CFClient::Layout self, int spacing) |
1007 | set_spacing (CFPlus::Layout self, int spacing) |
832 | CODE: |
1008 | CODE: |
833 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1009 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
834 | |
1010 | |
835 | void |
1011 | void |
836 | set_ellipsise (CFClient::Layout self, int ellipsise) |
1012 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
837 | CODE: |
1013 | CODE: |
838 | pango_layout_set_ellipsize (self->pl, |
1014 | pango_layout_set_ellipsize (self->pl, |
839 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1015 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
840 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1016 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
841 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1017 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
842 | : PANGO_ELLIPSIZE_NONE |
1018 | : PANGO_ELLIPSIZE_NONE |
843 | ); |
1019 | ); |
844 | |
1020 | |
845 | void |
1021 | void |
846 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
1022 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
847 | CODE: |
1023 | CODE: |
848 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1024 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
849 | |
1025 | |
850 | void |
1026 | void |
851 | size (CFClient::Layout self) |
1027 | size (CFPlus::Layout self) |
852 | PPCODE: |
1028 | PPCODE: |
853 | { |
1029 | { |
854 | int w, h; |
1030 | int w, h; |
855 | |
1031 | |
856 | layout_get_pixel_size (self, &w, &h); |
1032 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
859 | PUSHs (sv_2mortal (newSViv (w))); |
1035 | PUSHs (sv_2mortal (newSViv (w))); |
860 | PUSHs (sv_2mortal (newSViv (h))); |
1036 | PUSHs (sv_2mortal (newSViv (h))); |
861 | } |
1037 | } |
862 | |
1038 | |
863 | 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 |
864 | xy_to_index (CFClient::Layout self, int x, int y) |
1052 | xy_to_index (CFPlus::Layout self, int x, int y) |
865 | CODE: |
1053 | CODE: |
866 | { |
1054 | { |
867 | int index, trailing; |
1055 | int index, trailing; |
868 | 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); |
869 | RETVAL = index; |
1057 | RETVAL = index; |
870 | } |
1058 | } |
871 | OUTPUT: |
1059 | OUTPUT: |
872 | RETVAL |
1060 | RETVAL |
873 | |
1061 | |
874 | void |
1062 | void |
875 | cursor_pos (CFClient::Layout self, int index) |
1063 | cursor_pos (CFPlus::Layout self, int index) |
876 | PPCODE: |
1064 | PPCODE: |
877 | { |
1065 | { |
878 | PangoRectangle strong_pos; |
1066 | PangoRectangle strong_pos; |
879 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1067 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
880 | |
1068 | |
… | |
… | |
883 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1071 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
884 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1072 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
885 | } |
1073 | } |
886 | |
1074 | |
887 | void |
1075 | void |
888 | render (CFClient::Layout self) |
1076 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
889 | PPCODE: |
1077 | PPCODE: |
890 | { |
1078 | pango_opengl_render_layout_subpixel ( |
891 | SV *retval; |
1079 | self->pl, |
892 | int w, h; |
1080 | x * PANGO_SCALE, y * PANGO_SCALE, |
|
|
1081 | self->r, self->g, self->b, self->a, |
|
|
1082 | flags |
|
|
1083 | ); |
893 | |
1084 | |
894 | layout_get_pixel_size (self, &w, &h); |
1085 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
895 | |
1086 | |
896 | if (self->rgba) |
1087 | void |
|
|
1088 | pad2pot (SV *data_, SV *w_, SV *h_) |
|
|
1089 | CODE: |
|
|
1090 | { |
|
|
1091 | int ow = SvIV (w_); |
|
|
1092 | int oh = SvIV (h_); |
|
|
1093 | |
|
|
1094 | if (ow && oh) |
897 | { |
1095 | { |
898 | cairo_surface_t *surface; |
1096 | int nw = minpot (ow); |
899 | cairo_t *cairo; |
1097 | int nh = minpot (oh); |
900 | |
1098 | |
901 | retval = newSV (w * h * 4); |
1099 | if (nw != ow || nh != oh) |
902 | SvPOK_only (retval); |
|
|
903 | SvCUR_set (retval, w * h * 4); |
|
|
904 | |
|
|
905 | memset (SvPVX (retval), 0, w * h * 4); |
|
|
906 | |
|
|
907 | surface = cairo_image_surface_create_for_data ( |
|
|
908 | (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4); |
|
|
909 | cairo = cairo_create (surface); |
|
|
910 | cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a); |
|
|
911 | |
|
|
912 | pango_cairo_show_layout (cairo, self->pl); |
|
|
913 | |
|
|
914 | cairo_destroy (cairo); |
|
|
915 | cairo_surface_destroy (surface); |
|
|
916 | |
|
|
917 | // what a mess, and its premultiplied, too :( |
|
|
918 | { |
1100 | { |
919 | uint32_t *p = (uint32_t *)SvPVX (retval); |
1101 | if (SvOK (data_)) |
920 | uint32_t *e = p + w * h; |
|
|
921 | |
|
|
922 | while (p < e) |
|
|
923 | { |
1102 | { |
924 | uint32_t rgba = *p; |
1103 | STRLEN datalen; |
925 | rgba = (rgba >> 24) | (rgba << 8); |
1104 | char *data = SvPVbyte (data_, datalen); |
926 | #if 0 |
1105 | int bpp = datalen / (ow * oh); |
927 | #ifdef _WIN32 |
1106 | SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); |
928 | {//D |
|
|
929 | uint8_t r = rgba >> 24; |
|
|
930 | uint8_t g = rgba >> 16; |
|
|
931 | uint8_t b = rgba >> 8; |
|
|
932 | uint8_t a = rgba >> 0; |
|
|
933 | |
1107 | |
934 | rgba = (rgba & 0xffffff00) | a; |
1108 | SvPOK_only (result_); |
|
|
1109 | SvCUR_set (result_, nw * nh * bpp); |
|
|
1110 | |
|
|
1111 | memset (SvPVX (result_), 0, nw * nh * bpp); |
|
|
1112 | while (oh--) |
|
|
1113 | memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); |
|
|
1114 | |
|
|
1115 | sv_setsv (data_, result_); |
935 | } |
1116 | } |
936 | #endif |
1117 | |
937 | #endif |
1118 | sv_setiv (w_, nw); |
938 | rgba = SDL_SwapBE32 (rgba); |
1119 | sv_setiv (h_, nh); |
939 | *p++ = rgba; |
|
|
940 | } |
1120 | } |
941 | } |
|
|
942 | |
|
|
943 | EXTEND (SP, 5); |
|
|
944 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
945 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
946 | PUSHs (sv_2mortal (retval)); |
|
|
947 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
948 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
949 | } |
1121 | } |
950 | else |
|
|
951 | { |
|
|
952 | FT_Bitmap bitmap; |
|
|
953 | |
|
|
954 | retval = newSV (w * h); |
|
|
955 | SvPOK_only (retval); |
|
|
956 | SvCUR_set (retval, w * h); |
|
|
957 | |
|
|
958 | bitmap.rows = h; |
|
|
959 | bitmap.width = w; |
|
|
960 | bitmap.pitch = w; |
|
|
961 | bitmap.buffer = (unsigned char*)SvPVX (retval); |
|
|
962 | bitmap.num_grays = 256; |
|
|
963 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
|
|
964 | |
|
|
965 | memset (bitmap.buffer, 0, w * h); |
|
|
966 | |
|
|
967 | pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
|
|
968 | |
|
|
969 | EXTEND (SP, 5); |
|
|
970 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
971 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
972 | PUSHs (sv_2mortal (retval)); |
|
|
973 | PUSHs (sv_2mortal (newSViv (GL_ALPHA))); |
|
|
974 | PUSHs (sv_2mortal (newSViv (GL_ALPHA))); |
|
|
975 | } |
|
|
976 | } |
1122 | } |
977 | |
1123 | |
978 | MODULE = CFClient PACKAGE = CFClient::Texture |
|
|
979 | |
|
|
980 | void |
1124 | void |
981 | 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.) |
982 | PROTOTYPE: $$$;$$ |
1126 | PROTOTYPE: $$$;$$ |
983 | ALIAS: |
1127 | ALIAS: |
984 | draw_quad_alpha = 1 |
1128 | draw_quad_alpha = 1 |
985 | draw_quad_alpha_premultiplied = 2 |
1129 | draw_quad_alpha_premultiplied = 2 |
986 | CODE: |
1130 | CODE: |
… | |
… | |
1024 | glDisable (GL_ALPHA_TEST); |
1168 | glDisable (GL_ALPHA_TEST); |
1025 | glDisable (GL_BLEND); |
1169 | glDisable (GL_BLEND); |
1026 | } |
1170 | } |
1027 | } |
1171 | } |
1028 | |
1172 | |
1029 | MODULE = CFClient PACKAGE = CFClient::Map |
1173 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1030 | |
1174 | |
1031 | CFClient::Map |
1175 | CFPlus::Map |
1032 | new (SV *class, int map_width, int map_height) |
1176 | new (SV *class, int map_width, int map_height) |
1033 | CODE: |
1177 | CODE: |
1034 | New (0, RETVAL, 1, struct map); |
1178 | New (0, RETVAL, 1, struct map); |
1035 | RETVAL->x = 0; |
1179 | RETVAL->x = 0; |
1036 | RETVAL->y = 0; |
1180 | RETVAL->y = 0; |
… | |
… | |
1046 | RETVAL->row = 0; |
1190 | RETVAL->row = 0; |
1047 | OUTPUT: |
1191 | OUTPUT: |
1048 | RETVAL |
1192 | RETVAL |
1049 | |
1193 | |
1050 | void |
1194 | void |
1051 | DESTROY (CFClient::Map self) |
1195 | DESTROY (CFPlus::Map self) |
1052 | CODE: |
1196 | CODE: |
1053 | { |
1197 | { |
1054 | map_clear (self); |
1198 | map_clear (self); |
1055 | Safefree (self->face); |
1199 | Safefree (self->face); |
|
|
1200 | Safefree (self->tex); |
1056 | Safefree (self); |
1201 | Safefree (self); |
1057 | } |
1202 | } |
1058 | |
1203 | |
1059 | void |
1204 | void |
1060 | clear (CFClient::Map self) |
1205 | clear (CFPlus::Map self) |
1061 | CODE: |
1206 | CODE: |
1062 | map_clear (self); |
1207 | map_clear (self); |
1063 | |
1208 | |
1064 | void |
1209 | void |
1065 | set_face (CFClient::Map self, int face, int texid) |
1210 | set_face (CFPlus::Map self, int face, int texid) |
1066 | CODE: |
1211 | CODE: |
1067 | { |
1212 | { |
1068 | while (self->faces <= face) |
1213 | while (self->faces <= face) |
1069 | { |
1214 | { |
1070 | Append (mapface, self->face, self->faces, self->faces); |
1215 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1073 | |
1218 | |
1074 | self->face [face] = texid; |
1219 | self->face [face] = texid; |
1075 | } |
1220 | } |
1076 | |
1221 | |
1077 | void |
1222 | void |
1078 | 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) |
1079 | CODE: |
1224 | CODE: |
1080 | { |
1225 | { |
1081 | while (self->texs <= texid) |
1226 | while (self->texs <= texid) |
1082 | { |
1227 | { |
1083 | Append (maptex, self->tex, self->texs, self->texs); |
1228 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1107 | // from transparent color bleeding and ugly wrapping effects. |
1252 | // from transparent color bleeding and ugly wrapping effects. |
1108 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1253 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1109 | } |
1254 | } |
1110 | |
1255 | |
1111 | int |
1256 | int |
1112 | ox (CFClient::Map self) |
1257 | ox (CFPlus::Map self) |
1113 | ALIAS: |
1258 | ALIAS: |
1114 | oy = 1 |
1259 | oy = 1 |
1115 | x = 2 |
1260 | x = 2 |
1116 | y = 3 |
1261 | y = 3 |
1117 | w = 4 |
1262 | w = 4 |
… | |
… | |
1128 | } |
1273 | } |
1129 | OUTPUT: |
1274 | OUTPUT: |
1130 | RETVAL |
1275 | RETVAL |
1131 | |
1276 | |
1132 | void |
1277 | void |
1133 | scroll (CFClient::Map self, int dx, int dy) |
1278 | scroll (CFPlus::Map self, int dx, int dy) |
1134 | CODE: |
1279 | CODE: |
1135 | { |
1280 | { |
1136 | if (dx > 0) |
1281 | if (dx > 0) |
1137 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1282 | map_blank (self, self->x, self->y, dx, self->h); |
1138 | else if (dx < 0) |
1283 | else if (dx < 0) |
1139 | 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); |
1140 | |
1285 | |
1141 | if (dy > 0) |
1286 | if (dy > 0) |
1142 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1287 | map_blank (self, self->x, self->y, self->w, dy); |
1143 | else if (dy < 0) |
1288 | else if (dy < 0) |
1144 | 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); |
1145 | |
1290 | |
1146 | self->ox += dx; self->x += dx; |
1291 | self->ox += dx; self->x += dx; |
1147 | self->oy += dy; self->y += dy; |
1292 | self->oy += dy; self->y += dy; |
1148 | |
1293 | |
1149 | while (self->y < 0) |
1294 | while (self->y < 0) |
… | |
… | |
1154 | self->y += MAP_EXTEND_Y; |
1299 | self->y += MAP_EXTEND_Y; |
1155 | } |
1300 | } |
1156 | } |
1301 | } |
1157 | |
1302 | |
1158 | void |
1303 | void |
1159 | map1a_update (CFClient::Map self, SV *data_) |
1304 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1160 | CODE: |
1305 | CODE: |
1161 | { |
1306 | { |
1162 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1307 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1163 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1308 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1164 | mapcell *cell; |
1309 | mapcell *cell; |
1165 | int x, y, flags; |
1310 | int x, y, flags; |
1166 | |
1311 | |
1167 | while (data < data_end) |
1312 | while (data < data_end - 1) |
1168 | { |
1313 | { |
1169 | flags = (data [0] << 8) + data [1]; data += 2; |
1314 | flags = (data [0] << 8) + data [1]; data += 2; |
1170 | |
1315 | |
1171 | x = ((flags >> 10) & 63) + self->x; |
1316 | x = self->x + ((flags >> 10) & 63); |
1172 | y = ((flags >> 4) & 63) + self->y; |
1317 | y = self->y + ((flags >> 4) & 63); |
1173 | |
1318 | |
1174 | cell = map_get_cell (self, x, y); |
1319 | cell = map_get_cell (self, x, y); |
1175 | |
1320 | |
1176 | if (flags & 15) |
1321 | if (flags & 15) |
1177 | { |
1322 | { |
1178 | if (cell->darkness < 0) |
1323 | if (!cell->darkness) |
1179 | { |
1324 | { |
|
|
1325 | memset (cell, 0, sizeof (*cell)); |
1180 | cell->darkness = 0; |
1326 | cell->darkness = 256; |
1181 | cell->face [0] = 0; |
|
|
1182 | cell->face [1] = 0; |
|
|
1183 | cell->face [2] = 0; |
|
|
1184 | } |
1327 | } |
1185 | |
1328 | |
1186 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1187 | |
|
|
1188 | //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 | } |
1189 | |
1370 | |
1190 | if (flags & 4) |
1371 | if (flags & 4) |
1191 | { |
1372 | { |
1192 | 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; |
1193 | } |
1374 | } |
… | |
… | |
1201 | { |
1382 | { |
1202 | 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; |
1203 | } |
1384 | } |
1204 | } |
1385 | } |
1205 | else |
1386 | else |
1206 | cell->darkness = -1; |
1387 | cell->darkness = 0; |
1207 | } |
1388 | } |
1208 | } |
1389 | } |
1209 | |
1390 | |
1210 | SV * |
1391 | SV * |
1211 | 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) |
1212 | CODE: |
1393 | CODE: |
1213 | { |
1394 | { |
1214 | int x1, x; |
1395 | int x1, x; |
1215 | int y1, y; |
1396 | int y1, y; |
1216 | int z; |
1397 | int z; |
… | |
… | |
1266 | } |
1447 | } |
1267 | OUTPUT: |
1448 | OUTPUT: |
1268 | RETVAL |
1449 | RETVAL |
1269 | |
1450 | |
1270 | void |
1451 | void |
1271 | 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) |
1272 | PPCODE: |
1453 | CODE: |
1273 | { |
1454 | { |
1274 | int vx, vy; |
1455 | int vx, vy; |
1275 | int x, y, z; |
1456 | int x, y, z; |
1276 | int last_name; |
1457 | int last_name; |
1277 | mapface face; |
1458 | mapface face; |
1278 | int sw4 = (sw + 3) & ~3; |
|
|
1279 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
1280 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
|
|
1281 | |
1459 | |
1282 | memset (darkness, 255, sw4 * sh); |
|
|
1283 | SvPOK_only (darkness_sv); |
|
|
1284 | SvCUR_set (darkness_sv, sw4 * sh); |
|
|
1285 | |
|
|
1286 | vx = self->x + (self->w - sw) / 2 - shift_x; |
1460 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
1287 | vy = self->y + (self->h - sh) / 2 - shift_y; |
1461 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
1288 | |
1462 | |
1289 | /* |
1463 | /* |
1290 | int vx = self->vx = self->w >= sw |
1464 | int vx = self->vx = self->w >= sw |
1291 | ? self->x + (self->w - sw) / 2 |
1465 | ? self->x + (self->w - sw) / 2 |
1292 | : 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)); |
… | |
… | |
1296 | : 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)); |
1297 | */ |
1471 | */ |
1298 | |
1472 | |
1299 | glColor4ub (255, 255, 255, 255); |
1473 | glColor4ub (255, 255, 255, 255); |
1300 | |
1474 | |
|
|
1475 | glEnable (GL_BLEND); |
1301 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1476 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1302 | glEnable (GL_BLEND); |
|
|
1303 | glEnable (GL_TEXTURE_2D); |
1477 | glEnable (GL_TEXTURE_2D); |
1304 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1478 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1305 | |
1479 | |
1306 | glBegin (GL_QUADS); |
1480 | glBegin (GL_QUADS); |
1307 | |
1481 | |
… | |
… | |
1316 | for (x = 0; x < sw; x++) |
1490 | for (x = 0; x < sw; x++) |
1317 | if (row->c0 <= x + vx && x + vx < row->c1) |
1491 | if (row->c0 <= x + vx && x + vx < row->c1) |
1318 | { |
1492 | { |
1319 | mapcell *cell = row->col + (x + vx - row->c0); |
1493 | mapcell *cell = row->col + (x + vx - row->c0); |
1320 | |
1494 | |
1321 | darkness[y * sw4 + x] = cell->darkness < 0 |
|
|
1322 | ? 255 - FOW_DARKNESS |
|
|
1323 | : 255 - cell->darkness; |
|
|
1324 | |
|
|
1325 | face = cell->face [z]; |
1495 | face = cell->face [z]; |
1326 | |
1496 | |
1327 | if (face) |
1497 | if (face && face < self->texs) |
1328 | { |
1498 | { |
1329 | maptex tex = self->tex [face]; |
1499 | maptex tex = self->tex [face]; |
1330 | |
|
|
1331 | int px = (x + 1) * 32 - tex.w; |
1500 | int px = (x + 1) * 32 - tex.w; |
1332 | int py = (y + 1) * 32 - tex.h; |
1501 | int py = (y + 1) * 32 - tex.h; |
1333 | |
1502 | |
1334 | if (last_name != tex.name) |
1503 | if (last_name != tex.name) |
1335 | { |
1504 | { |
1336 | glEnd (); |
1505 | glEnd (); |
1337 | last_name = tex.name; |
|
|
1338 | glBindTexture (GL_TEXTURE_2D, last_name); |
1506 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1339 | glBegin (GL_QUADS); |
1507 | glBegin (GL_QUADS); |
1340 | } |
1508 | } |
1341 | |
1509 | |
1342 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1510 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1343 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1511 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1344 | 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); |
1345 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1513 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1346 | } |
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 | } |
1347 | } |
1534 | } |
1348 | } |
1535 | } |
1349 | |
1536 | |
1350 | glEnd (); |
1537 | glEnd (); |
1351 | |
1538 | |
1352 | glDisable (GL_TEXTURE_2D); |
1539 | glDisable (GL_TEXTURE_2D); |
1353 | 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 | } |
1354 | |
1666 | |
1355 | EXTEND (SP, 3); |
1667 | EXTEND (SP, 3); |
1356 | PUSHs (sv_2mortal (newSViv (sw4))); |
1668 | PUSHs (sv_2mortal (newSViv (sw4))); |
1357 | PUSHs (sv_2mortal (newSViv (sh))); |
1669 | PUSHs (sv_2mortal (newSViv (sh))); |
1358 | PUSHs (darkness_sv); |
1670 | PUSHs (darkness_sv); |
1359 | } |
1671 | } |
1360 | |
1672 | |
1361 | SV * |
1673 | SV * |
1362 | 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) |
1363 | CODE: |
1675 | CODE: |
1364 | { |
1676 | { |
1365 | int x, y, x1, y1; |
1677 | int x, y, x1, y1; |
1366 | SV *data_sv = newSV (w * h * 7 + 5); |
1678 | SV *data_sv = newSV (w * h * 7 + 5); |
1367 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1679 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1429 | } |
1741 | } |
1430 | OUTPUT: |
1742 | OUTPUT: |
1431 | RETVAL |
1743 | RETVAL |
1432 | |
1744 | |
1433 | void |
1745 | void |
1434 | 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) |
1435 | PPCODE: |
1747 | PPCODE: |
1436 | { |
1748 | { |
1437 | int x, y, z; |
1749 | int x, y, z; |
1438 | int w, h; |
1750 | int w, h; |
1439 | int x1, y1; |
1751 | int x1, y1; |
… | |
… | |
1471 | |
1783 | |
1472 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1784 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1473 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1785 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1474 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1786 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1475 | |
1787 | |
1476 | if (cell->darkness <= 0) |
1788 | if (cell->darkness == 0) |
1477 | { |
1789 | { |
1478 | cell->darkness = -1; |
1790 | cell->darkness = 0; |
1479 | |
1791 | |
1480 | for (z = 0; z <= 2; z++) |
1792 | for (z = 0; z <= 2; z++) |
1481 | { |
1793 | { |
1482 | cell->face[z] = face[z]; |
1794 | cell->face[z] = face[z]; |
1483 | |
1795 | |
… | |
… | |
1488 | } |
1800 | } |
1489 | } |
1801 | } |
1490 | } |
1802 | } |
1491 | } |
1803 | } |
1492 | |
1804 | |
1493 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1805 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1494 | |
1806 | |
1495 | CFClient::MixChunk |
1807 | CFPlus::MixChunk |
1496 | new_from_file (SV *class, char *path) |
1808 | new_from_file (SV *class, char *path) |
1497 | CODE: |
1809 | CODE: |
1498 | RETVAL = Mix_LoadWAV (path); |
1810 | RETVAL = Mix_LoadWAV (path); |
1499 | OUTPUT: |
1811 | OUTPUT: |
1500 | RETVAL |
1812 | RETVAL |
1501 | |
1813 | |
1502 | void |
1814 | void |
1503 | DESTROY (CFClient::MixChunk self) |
1815 | DESTROY (CFPlus::MixChunk self) |
1504 | CODE: |
1816 | CODE: |
1505 | Mix_FreeChunk (self); |
1817 | Mix_FreeChunk (self); |
1506 | |
1818 | |
1507 | int |
1819 | int |
1508 | volume (CFClient::MixChunk self, int volume = -1) |
1820 | volume (CFPlus::MixChunk self, int volume = -1) |
1509 | CODE: |
1821 | CODE: |
1510 | RETVAL = Mix_VolumeChunk (self, volume); |
1822 | RETVAL = Mix_VolumeChunk (self, volume); |
1511 | OUTPUT: |
1823 | OUTPUT: |
1512 | RETVAL |
1824 | RETVAL |
1513 | |
1825 | |
1514 | int |
1826 | int |
1515 | 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) |
1516 | CODE: |
1828 | CODE: |
1517 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1829 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1518 | OUTPUT: |
1830 | OUTPUT: |
1519 | RETVAL |
1831 | RETVAL |
1520 | |
1832 | |
1521 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1833 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1522 | |
1834 | |
1523 | int |
1835 | int |
1524 | volume (int volume = -1) |
1836 | volume (int volume = -1) |
1525 | CODE: |
1837 | CODE: |
1526 | RETVAL = Mix_VolumeMusic (volume); |
1838 | RETVAL = Mix_VolumeMusic (volume); |
1527 | OUTPUT: |
1839 | OUTPUT: |
1528 | RETVAL |
1840 | RETVAL |
1529 | |
1841 | |
1530 | CFClient::MixMusic |
1842 | CFPlus::MixMusic |
1531 | new_from_file (SV *class, char *path) |
1843 | new_from_file (SV *class, char *path) |
1532 | CODE: |
1844 | CODE: |
1533 | RETVAL = Mix_LoadMUS (path); |
1845 | RETVAL = Mix_LoadMUS (path); |
1534 | OUTPUT: |
1846 | OUTPUT: |
1535 | RETVAL |
1847 | RETVAL |
1536 | |
1848 | |
1537 | void |
1849 | void |
1538 | DESTROY (CFClient::MixMusic self) |
1850 | DESTROY (CFPlus::MixMusic self) |
1539 | CODE: |
1851 | CODE: |
1540 | Mix_FreeMusic (self); |
1852 | Mix_FreeMusic (self); |
1541 | |
1853 | |
1542 | int |
1854 | int |
1543 | play (CFClient::MixMusic self, int loops = -1) |
1855 | play (CFPlus::MixMusic self, int loops = -1) |
1544 | CODE: |
1856 | CODE: |
1545 | RETVAL = Mix_PlayMusic (self, loops); |
1857 | RETVAL = Mix_PlayMusic (self, loops); |
1546 | OUTPUT: |
1858 | OUTPUT: |
1547 | RETVAL |
1859 | RETVAL |
1548 | |
1860 | |
1549 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1861 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1550 | |
1862 | |
1551 | BOOT: |
1863 | BOOT: |
1552 | { |
1864 | { |
1553 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1865 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1554 | static const struct { |
1866 | static const struct { |
1555 | const char *name; |
1867 | const char *name; |
1556 | IV iv; |
1868 | IV iv; |
1557 | } *civ, const_iv[] = { |
1869 | } *civ, const_iv[] = { |
1558 | # define const_iv(name) { # name, (IV)name } |
1870 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1565 | const_iv (GL_SCISSOR_TEST), |
1877 | const_iv (GL_SCISSOR_TEST), |
1566 | const_iv (GL_DEPTH_TEST), |
1878 | const_iv (GL_DEPTH_TEST), |
1567 | const_iv (GL_ALPHA_TEST), |
1879 | const_iv (GL_ALPHA_TEST), |
1568 | const_iv (GL_NORMALIZE), |
1880 | const_iv (GL_NORMALIZE), |
1569 | const_iv (GL_RESCALE_NORMAL), |
1881 | const_iv (GL_RESCALE_NORMAL), |
|
|
1882 | const_iv (GL_FRONT), |
|
|
1883 | const_iv (GL_BACK), |
1570 | const_iv (GL_AND), |
1884 | const_iv (GL_AND), |
1571 | const_iv (GL_ONE), |
1885 | const_iv (GL_ONE), |
1572 | const_iv (GL_ZERO), |
1886 | const_iv (GL_ZERO), |
1573 | const_iv (GL_SRC_ALPHA), |
1887 | const_iv (GL_SRC_ALPHA), |
1574 | const_iv (GL_DST_ALPHA), |
1888 | const_iv (GL_DST_ALPHA), |
1575 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1889 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
1576 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
1890 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
1577 | const_iv (GL_SRC_ALPHA_SATURATE), |
1891 | const_iv (GL_SRC_ALPHA_SATURATE), |
1578 | const_iv (GL_RGB), |
1892 | const_iv (GL_RGB), |
1579 | 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), |
1580 | const_iv (GL_UNSIGNED_BYTE), |
1897 | const_iv (GL_UNSIGNED_BYTE), |
1581 | const_iv (GL_UNSIGNED_SHORT), |
1898 | const_iv (GL_UNSIGNED_SHORT), |
1582 | const_iv (GL_UNSIGNED_INT), |
1899 | const_iv (GL_UNSIGNED_INT), |
1583 | const_iv (GL_ALPHA), |
1900 | const_iv (GL_ALPHA), |
1584 | const_iv (GL_INTENSITY), |
1901 | const_iv (GL_INTENSITY), |
… | |
… | |
1616 | const_iv (GL_SEPARABLE_2D), |
1933 | const_iv (GL_SEPARABLE_2D), |
1617 | const_iv (GL_CONVOLUTION_2D), |
1934 | const_iv (GL_CONVOLUTION_2D), |
1618 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1935 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1619 | const_iv (GL_CONSTANT_BORDER), |
1936 | const_iv (GL_CONSTANT_BORDER), |
1620 | const_iv (GL_LINES), |
1937 | const_iv (GL_LINES), |
|
|
1938 | const_iv (GL_LINE_STRIP), |
1621 | const_iv (GL_LINE_LOOP), |
1939 | const_iv (GL_LINE_LOOP), |
1622 | const_iv (GL_QUADS), |
1940 | const_iv (GL_QUADS), |
1623 | const_iv (GL_QUAD_STRIP), |
1941 | const_iv (GL_QUAD_STRIP), |
1624 | const_iv (GL_TRIANGLES), |
1942 | const_iv (GL_TRIANGLES), |
1625 | const_iv (GL_TRIANGLE_STRIP), |
1943 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1658 | OUTPUT: |
1976 | OUTPUT: |
1659 | RETVAL |
1977 | RETVAL |
1660 | |
1978 | |
1661 | int glGetError () |
1979 | int glGetError () |
1662 | |
1980 | |
|
|
1981 | void glFinish () |
|
|
1982 | |
1663 | void glClear (int mask) |
1983 | void glClear (int mask) |
1664 | |
1984 | |
1665 | 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) |
1666 | PROTOTYPE: @ |
1986 | PROTOTYPE: @ |
1667 | |
1987 | |
… | |
… | |
1690 | void glPushMatrix () |
2010 | void glPushMatrix () |
1691 | |
2011 | |
1692 | void glPopMatrix () |
2012 | void glPopMatrix () |
1693 | |
2013 | |
1694 | void glLoadIdentity () |
2014 | void glLoadIdentity () |
|
|
2015 | |
|
|
2016 | void glDrawBuffer (int buffer) |
|
|
2017 | |
|
|
2018 | void glReadBuffer (int buffer) |
1695 | |
2019 | |
1696 | # near_ and far_ are due to microsofts buggy "c" compiler |
2020 | # near_ and far_ are due to microsofts buggy "c" compiler |
1697 | 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_) |
1698 | |
2022 | |
1699 | # near_ and far_ are due to microsofts buggy "c" compiler |
2023 | # near_ and far_ are due to microsofts buggy "c" compiler |
… | |
… | |
1729 | r *= a; |
2053 | r *= a; |
1730 | g *= a; |
2054 | g *= a; |
1731 | b *= a; |
2055 | b *= a; |
1732 | } |
2056 | } |
1733 | // microsoft visual "c" rounds instead of truncating... |
2057 | // microsoft visual "c" rounds instead of truncating... |
1734 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2058 | glColor4f (r, g, b, a); |
1735 | MIN ((int)(g * 256.f), 255), |
|
|
1736 | MIN ((int)(b * 256.f), 255), |
|
|
1737 | MIN ((int)(a * 256.f), 255)); |
|
|
1738 | |
2059 | |
1739 | void glInterleavedArrays (int format, int stride, char *data) |
2060 | void glInterleavedArrays (int format, int stride, char *data) |
1740 | |
2061 | |
1741 | void glDrawElements (int mode, int count, int type, char *indices) |
2062 | void glDrawElements (int mode, int count, int type, char *indices) |
1742 | |
2063 | |
… | |
… | |
1819 | |
2140 | |
1820 | void glEndList () |
2141 | void glEndList () |
1821 | |
2142 | |
1822 | void glCallList (int list) |
2143 | void glCallList (int list) |
1823 | |
2144 | |
1824 | |
|
|