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" |
|
|
46 | |
|
|
47 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
51 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
48 | |
52 | |
49 | #define FOW_DARKNESS 32 |
53 | #define FOW_DARKNESS 32 |
50 | |
54 | |
51 | #define MAP_EXTEND_X 32 |
55 | #define MAP_EXTEND_X 32 |
52 | #define MAP_EXTEND_Y 512 |
56 | #define MAP_EXTEND_Y 512 |
53 | |
57 | |
54 | #define MIN_FONT_HEIGHT 10 |
58 | #define MIN_FONT_HEIGHT 10 |
|
|
59 | |
|
|
60 | #if 0 |
|
|
61 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
|
|
62 | #else |
|
|
63 | # define PARACHUTE 0 |
|
|
64 | #endif |
55 | |
65 | |
56 | static struct |
66 | static struct |
57 | { |
67 | { |
58 | #define GL_FUNC(ptr,name) ptr name; |
68 | #define GL_FUNC(ptr,name) ptr name; |
59 | #include "glfunc.h" |
69 | #include "glfunc.h" |
… | |
… | |
68 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
78 | gl.BlendFuncSeparateEXT (sa, da, saa, daa); |
69 | else |
79 | else |
70 | glBlendFunc (sa, da); |
80 | glBlendFunc (sa, da); |
71 | } |
81 | } |
72 | |
82 | |
|
|
83 | #include "texcache.c" |
|
|
84 | |
|
|
85 | #include "pango-font.c" |
|
|
86 | #include "pango-fontmap.c" |
|
|
87 | #include "pango-render.c" |
|
|
88 | |
73 | typedef Mix_Chunk *CFClient__MixChunk; |
89 | typedef Mix_Chunk *CFPlus__MixChunk; |
74 | typedef Mix_Music *CFClient__MixMusic; |
90 | typedef Mix_Music *CFPlus__MixMusic; |
75 | |
91 | |
76 | typedef PangoFontDescription *CFClient__Font; |
92 | typedef PangoFontDescription *CFPlus__Font; |
77 | |
93 | |
78 | static int |
94 | static int |
79 | shape_attr_p (PangoLayoutRun *run) |
95 | shape_attr_p (PangoLayoutRun *run) |
80 | { |
96 | { |
81 | GSList *attrs = run->item->analysis.extra_attrs; |
97 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
92 | |
108 | |
93 | return 0; |
109 | return 0; |
94 | } |
110 | } |
95 | |
111 | |
96 | typedef struct cf_layout { |
112 | typedef struct cf_layout { |
97 | PangoLayout *pl; // either derived from a cairo or ft2 context |
113 | PangoLayout *pl; |
98 | int rgba; // wether we use rgba (cairo) or grayscale (ft2) |
|
|
99 | float r, g, b, a; // default color for rgba mode |
114 | float r, g, b, a; // default color for rgba mode |
100 | int base_height; |
115 | int base_height; |
101 | CFClient__Font font; |
116 | CFPlus__Font font; |
102 | } *CFClient__Layout; |
117 | } *CFPlus__Layout; |
103 | |
118 | |
104 | static CFClient__Font default_font; |
119 | static CFPlus__Font default_font; |
105 | static PangoContext *ft2_context, *cairo_context; |
120 | static PangoContext *opengl_context; |
106 | static PangoFontMap *ft2_fontmap, *cairo_fontmap; |
121 | static PangoFontMap *opengl_fontmap; |
107 | |
122 | |
108 | static void |
123 | static void |
109 | substitute_func (FcPattern *pattern, gpointer data) |
124 | substitute_func (FcPattern *pattern, gpointer data) |
110 | { |
125 | { |
111 | FcPatternAddBool (pattern, FC_HINTING, 1); |
126 | FcPatternAddBool (pattern, FC_HINTING, 1); |
112 | #ifdef FC_HINT_STYLE |
127 | #ifdef FC_HINT_STYLE |
113 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
128 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
114 | #endif |
129 | #endif |
115 | #ifdef _WIN32 |
|
|
116 | FcPatternAddBool (pattern, FC_AUTOHINT, 1); |
|
|
117 | #else |
|
|
118 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
130 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
119 | #endif |
|
|
120 | } |
131 | } |
121 | |
132 | |
122 | static void |
133 | static void |
123 | layout_update_font (CFClient__Layout self) |
134 | layout_update_font (CFPlus__Layout self) |
124 | { |
135 | { |
125 | /* 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 |
126 | * reasonably well with bitstream vera |
137 | * reasonably well with bitstream vera |
127 | */ |
138 | */ |
128 | PangoFontDescription *font = self->font ? self->font : default_font; |
139 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
132 | |
143 | |
133 | pango_layout_set_font_description (self->pl, font); |
144 | pango_layout_set_font_description (self->pl, font); |
134 | } |
145 | } |
135 | |
146 | |
136 | static void |
147 | static void |
137 | layout_get_pixel_size (CFClient__Layout self, int *w, int *h) |
148 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
138 | { |
149 | { |
|
|
150 | PangoRectangle rect; |
|
|
151 | |
|
|
152 | // get_pixel_* wrongly rounds down |
139 | pango_layout_get_pixel_size (self->pl, w, h); |
153 | pango_layout_get_extents (self->pl, 0, &rect); |
140 | |
154 | |
141 | if (!*w) *w = 1; |
155 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
142 | if (!*h) *h = 1; |
156 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
143 | |
157 | |
144 | *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; |
145 | } |
163 | } |
146 | |
164 | |
147 | typedef uint16_t mapface; |
165 | typedef uint16_t mapface; |
148 | |
166 | |
149 | typedef struct { |
167 | typedef struct { |
… | |
… | |
152 | float s, t; |
170 | float s, t; |
153 | uint8_t r, g, b, a; |
171 | uint8_t r, g, b, a; |
154 | } maptex; |
172 | } maptex; |
155 | |
173 | |
156 | typedef struct { |
174 | typedef struct { |
157 | int16_t darkness; |
175 | uint32_t player; |
158 | mapface face[3]; |
176 | mapface face[3]; |
|
|
177 | uint16_t darkness; |
|
|
178 | uint8_t stat_width, stat_hp, flags; |
159 | } mapcell; |
179 | } mapcell; |
160 | |
180 | |
161 | typedef struct { |
181 | typedef struct { |
162 | int32_t c0, c1; |
182 | int32_t c0, c1; |
163 | mapcell *col; |
183 | mapcell *col; |
… | |
… | |
172 | int texs; |
192 | int texs; |
173 | maptex *tex; |
193 | maptex *tex; |
174 | |
194 | |
175 | int32_t rows; |
195 | int32_t rows; |
176 | maprow *row; |
196 | maprow *row; |
177 | } *CFClient__Map; |
197 | } *CFPlus__Map; |
178 | |
198 | |
179 | static char * |
199 | static char * |
180 | prepend (char *ptr, int sze, int inc) |
200 | prepend (char *ptr, int sze, int inc) |
181 | { |
201 | { |
182 | char *p; |
202 | char *p; |
… | |
… | |
200 | |
220 | |
201 | #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)) |
202 | #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)) |
203 | |
223 | |
204 | static maprow * |
224 | static maprow * |
205 | map_get_row (CFClient__Map self, int y) |
225 | map_get_row (CFPlus__Map self, int y) |
206 | { |
226 | { |
207 | if (0 > y) |
227 | if (0 > y) |
208 | { |
228 | { |
209 | int extend = - y + MAP_EXTEND_Y; |
229 | int extend = - y + MAP_EXTEND_Y; |
210 | Prepend (maprow, self->row, self->rows, extend); |
230 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
248 | |
268 | |
249 | return row->col + (x - row->c0); |
269 | return row->col + (x - row->c0); |
250 | } |
270 | } |
251 | |
271 | |
252 | static mapcell * |
272 | static mapcell * |
253 | map_get_cell (CFClient__Map self, int x, int y) |
273 | map_get_cell (CFPlus__Map self, int x, int y) |
254 | { |
274 | { |
255 | return row_get_cell (map_get_row (self, y), x); |
275 | return row_get_cell (map_get_row (self, y), x); |
256 | } |
276 | } |
257 | |
277 | |
258 | static void |
278 | static void |
259 | map_clear (CFClient__Map self) |
279 | map_clear (CFPlus__Map self) |
260 | { |
280 | { |
261 | int r; |
281 | int r; |
262 | |
282 | |
263 | for (r = 0; r < self->rows; r++) |
283 | for (r = 0; r < self->rows; r++) |
264 | Safefree (self->row[r].col); |
284 | Safefree (self->row[r].col); |
… | |
… | |
272 | self->row = 0; |
292 | self->row = 0; |
273 | self->rows = 0; |
293 | self->rows = 0; |
274 | } |
294 | } |
275 | |
295 | |
276 | static void |
296 | static void |
277 | 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) |
278 | { |
298 | { |
279 | int x, y; |
299 | int x, y; |
280 | maprow *row; |
300 | maprow *row; |
|
|
301 | mapcell *cell; |
281 | |
302 | |
282 | for (y = y0; y < y0 + h; y++) |
303 | for (y = y0; y < y0 + h; y++) |
283 | if (y >= 0) |
304 | if (y >= 0) |
284 | { |
305 | { |
285 | if (y >= self->rows) |
306 | if (y >= self->rows) |
… | |
… | |
291 | if (x >= row->c0) |
312 | if (x >= row->c0) |
292 | { |
313 | { |
293 | if (x >= row->c1) |
314 | if (x >= row->c1) |
294 | break; |
315 | break; |
295 | |
316 | |
296 | 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; |
297 | } |
323 | } |
298 | } |
324 | } |
299 | } |
325 | } |
300 | |
326 | |
301 | static void |
327 | static void |
… | |
… | |
339 | n |= n >> 16; |
365 | n |= n >> 16; |
340 | |
366 | |
341 | return n + 1; |
367 | return n + 1; |
342 | } |
368 | } |
343 | |
369 | |
344 | MODULE = CFClient PACKAGE = CFClient |
370 | MODULE = CFPlus PACKAGE = CFPlus |
345 | |
371 | |
346 | PROTOTYPES: ENABLE |
372 | PROTOTYPES: ENABLE |
347 | |
373 | |
348 | BOOT: |
374 | BOOT: |
349 | { |
375 | { |
350 | HV *stash = gv_stashpv ("CFClient", 1); |
376 | HV *stash = gv_stashpv ("CFPlus", 1); |
351 | static const struct { |
377 | static const struct { |
352 | const char *name; |
378 | const char *name; |
353 | IV iv; |
379 | IV iv; |
354 | } *civ, const_iv[] = { |
380 | } *civ, const_iv[] = { |
355 | # define const_iv(name) { # name, (IV)name } |
381 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
456 | |
482 | |
457 | 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; ) |
458 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
484 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
459 | } |
485 | } |
460 | |
486 | |
|
|
487 | int |
|
|
488 | in_destruct () |
|
|
489 | CODE: |
|
|
490 | RETVAL = PL_main_cv == Nullcv; |
|
|
491 | OUTPUT: |
|
|
492 | RETVAL |
|
|
493 | |
461 | NV floor (NV x) |
494 | NV floor (NV x) |
462 | |
495 | |
463 | NV ceil (NV x) |
496 | NV ceil (NV x) |
464 | |
497 | |
465 | void |
498 | void |
466 | pango_init () |
499 | pango_init () |
467 | CODE: |
500 | CODE: |
468 | // delayed, so it can pick up new fonts added by AddFontResourceEx |
|
|
469 | { |
501 | { |
470 | { |
|
|
471 | ft2_fontmap = pango_ft2_font_map_new (); |
502 | opengl_fontmap = pango_opengl_font_map_new (); |
472 | 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); |
473 | ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); |
504 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
474 | } |
|
|
475 | { |
|
|
476 | cairo_font_options_t *fopt = cairo_font_options_create (); |
|
|
477 | cairo_fontmap = pango_cairo_font_map_get_default (); |
|
|
478 | cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); |
|
|
479 | #ifdef _WIN32 |
|
|
480 | // cairo looks like shit eaten twice on windows |
|
|
481 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); |
|
|
482 | #else |
|
|
483 | cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); |
|
|
484 | #endif |
|
|
485 | cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); |
|
|
486 | cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); |
|
|
487 | pango_cairo_context_set_font_options (cairo_context, fopt); |
|
|
488 | cairo_font_options_destroy (fopt); |
|
|
489 | } |
|
|
490 | } |
505 | } |
491 | |
506 | |
492 | int |
507 | int |
493 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) |
508 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
494 | |
509 | |
495 | void |
510 | void |
496 | SDL_Quit () |
511 | SDL_Quit () |
497 | |
512 | |
498 | void |
513 | void |
… | |
… | |
513 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
528 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
514 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
529 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
515 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
530 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
516 | |
531 | |
517 | 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 |
518 | |
537 | |
519 | SDL_EnableUNICODE (1); |
538 | SDL_EnableUNICODE (1); |
520 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
539 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
521 | |
540 | |
522 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
541 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
609 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
628 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
610 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
629 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
611 | break; |
630 | break; |
612 | } |
631 | } |
613 | |
632 | |
614 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
633 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
615 | } |
634 | } |
616 | } |
635 | } |
617 | |
636 | |
618 | int |
637 | int |
619 | 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) |
… | |
… | |
633 | #ifndef _WIN32 |
652 | #ifndef _WIN32 |
634 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
635 | #endif |
654 | #endif |
636 | |
655 | |
637 | 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 |
638 | add_font (char *file) |
687 | add_font (char *file) |
639 | CODE: |
688 | CODE: |
640 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
689 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
641 | #ifdef _WIN32 |
|
|
642 | // cairo... sigh... requires win2000 |
|
|
643 | AddFontResourceEx (file, FR_PRIVATE, 0); |
|
|
644 | #endif |
|
|
645 | |
690 | |
646 | void |
691 | void |
647 | load_image_inline (SV *image_) |
692 | load_image_inline (SV *image_) |
648 | ALIAS: |
693 | ALIAS: |
649 | load_image_file = 1 |
694 | load_image_file = 1 |
… | |
… | |
691 | |
736 | |
692 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
737 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
693 | |
738 | |
694 | assert (surface2->pitch == surface2->w * 4); |
739 | assert (surface2->pitch == surface2->w * 4); |
695 | |
740 | |
|
|
741 | SDL_LockSurface (surface2); |
696 | EXTEND (SP, 5); |
742 | EXTEND (SP, 6); |
697 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
743 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
698 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
744 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
699 | SDL_LockSurface (surface2); |
|
|
700 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
745 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
701 | SDL_UnlockSurface (surface2); |
|
|
702 | 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))); |
703 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
747 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
704 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
748 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
|
|
749 | SDL_UnlockSurface (surface2); |
705 | |
750 | |
706 | SDL_FreeSurface (surface); |
751 | SDL_FreeSurface (surface); |
707 | SDL_FreeSurface (surface2); |
752 | SDL_FreeSurface (surface2); |
708 | } |
753 | } |
709 | |
754 | |
… | |
… | |
748 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
793 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
749 | #endif |
794 | #endif |
750 | _exit (1); |
795 | _exit (1); |
751 | |
796 | |
752 | void |
797 | void |
753 | _exit (int retval) |
798 | _exit (int retval = 0) |
754 | CODE: |
799 | CODE: |
755 | _exit (retval); |
800 | _exit (retval); |
756 | |
801 | |
757 | MODULE = CFClient PACKAGE = CFClient::Font |
802 | MODULE = CFPlus PACKAGE = CFPlus::Font |
758 | |
803 | |
759 | CFClient::Font |
804 | CFPlus::Font |
760 | new_from_file (SV *class, char *path, int id = 0) |
805 | new_from_file (SV *class, char *path, int id = 0) |
761 | CODE: |
806 | CODE: |
762 | { |
807 | { |
763 | int count; |
808 | int count; |
764 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
809 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
767 | } |
812 | } |
768 | OUTPUT: |
813 | OUTPUT: |
769 | RETVAL |
814 | RETVAL |
770 | |
815 | |
771 | void |
816 | void |
772 | DESTROY (CFClient::Font self) |
817 | DESTROY (CFPlus::Font self) |
773 | CODE: |
818 | CODE: |
774 | pango_font_description_free (self); |
819 | pango_font_description_free (self); |
775 | |
820 | |
776 | void |
821 | void |
777 | make_default (CFClient::Font self) |
822 | make_default (CFPlus::Font self) |
778 | CODE: |
823 | CODE: |
779 | default_font = self; |
824 | default_font = self; |
780 | |
825 | |
781 | MODULE = CFClient PACKAGE = CFClient::Layout |
826 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
782 | |
827 | |
783 | CFClient::Layout |
828 | void |
784 | new (SV *class, int rgba = 0) |
829 | reset_glyph_cache () |
|
|
830 | CODE: |
|
|
831 | tc_clear (); |
|
|
832 | |
|
|
833 | CFPlus::Layout |
|
|
834 | new (SV *class) |
785 | CODE: |
835 | CODE: |
786 | New (0, RETVAL, 1, struct cf_layout); |
836 | New (0, RETVAL, 1, struct cf_layout); |
787 | |
837 | |
788 | RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); |
838 | RETVAL->pl = pango_layout_new (opengl_context); |
789 | RETVAL->rgba = rgba; |
|
|
790 | RETVAL->r = 1.; |
839 | RETVAL->r = 1.; |
791 | RETVAL->g = 1.; |
840 | RETVAL->g = 1.; |
792 | RETVAL->b = 1.; |
841 | RETVAL->b = 1.; |
793 | RETVAL->a = 1.; |
842 | RETVAL->a = 1.; |
794 | RETVAL->base_height = MIN_FONT_HEIGHT; |
843 | RETVAL->base_height = MIN_FONT_HEIGHT; |
… | |
… | |
798 | layout_update_font (RETVAL); |
847 | layout_update_font (RETVAL); |
799 | OUTPUT: |
848 | OUTPUT: |
800 | RETVAL |
849 | RETVAL |
801 | |
850 | |
802 | void |
851 | void |
803 | DESTROY (CFClient::Layout self) |
852 | DESTROY (CFPlus::Layout self) |
804 | CODE: |
853 | CODE: |
805 | g_object_unref (self->pl); |
854 | g_object_unref (self->pl); |
806 | Safefree (self); |
855 | Safefree (self); |
807 | |
856 | |
808 | int |
|
|
809 | is_rgba (CFClient::Layout self) |
|
|
810 | CODE: |
|
|
811 | RETVAL = self->rgba; |
|
|
812 | OUTPUT: |
|
|
813 | RETVAL |
|
|
814 | |
|
|
815 | void |
857 | void |
816 | set_text (CFClient::Layout self, SV *text_) |
858 | set_text (CFPlus::Layout self, SV *text_) |
817 | CODE: |
859 | CODE: |
818 | { |
860 | { |
819 | STRLEN textlen; |
861 | STRLEN textlen; |
820 | char *text = SvPVutf8 (text_, textlen); |
862 | char *text = SvPVutf8 (text_, textlen); |
821 | |
863 | |
822 | pango_layout_set_text (self->pl, text, textlen); |
864 | pango_layout_set_text (self->pl, text, textlen); |
823 | } |
865 | } |
824 | |
866 | |
825 | void |
867 | void |
826 | set_markup (CFClient::Layout self, SV *text_) |
868 | set_markup (CFPlus::Layout self, SV *text_) |
827 | CODE: |
869 | CODE: |
828 | { |
870 | { |
829 | STRLEN textlen; |
871 | STRLEN textlen; |
830 | char *text = SvPVutf8 (text_, textlen); |
872 | char *text = SvPVutf8 (text_, textlen); |
831 | |
873 | |
832 | pango_layout_set_markup (self->pl, text, textlen); |
874 | pango_layout_set_markup (self->pl, text, textlen); |
833 | } |
875 | } |
834 | |
876 | |
835 | void |
877 | void |
836 | set_shapes (CFClient::Layout self, ...) |
878 | set_shapes (CFPlus::Layout self, ...) |
837 | CODE: |
879 | CODE: |
838 | { |
880 | { |
839 | PangoAttrList *attrs = 0; |
881 | PangoAttrList *attrs = 0; |
840 | const char *text = pango_layout_get_text (self->pl); |
882 | const char *text = pango_layout_get_text (self->pl); |
841 | const char *pos = text; |
883 | const char *pos = text; |
842 | int arg = 2; |
884 | int arg = 4; |
843 | |
885 | |
844 | while (arg < items && (pos = strstr (pos, OBJ_STR))) |
886 | while (arg < items && (pos = strstr (pos, OBJ_STR))) |
845 | { |
887 | { |
846 | PangoRectangle rect; |
888 | PangoRectangle inkrect, rect; |
847 | PangoAttribute *attr; |
889 | PangoAttribute *attr; |
848 | |
890 | |
|
|
891 | int x = SvIV (ST (arg - 3)); |
|
|
892 | int y = SvIV (ST (arg - 2)); |
849 | int w = SvIV (ST (arg - 1)); |
893 | int w = SvIV (ST (arg - 1)); |
850 | int h = SvIV (ST (arg)); |
894 | int h = SvIV (ST (arg )); |
851 | |
895 | |
852 | arg += 2; |
|
|
853 | |
|
|
854 | rect.x = 0; |
896 | inkrect.x = 0; |
|
|
897 | inkrect.y = 0; |
|
|
898 | inkrect.width = 0; |
|
|
899 | inkrect.height = 0; |
|
|
900 | |
|
|
901 | rect.x = x * PANGO_SCALE; |
855 | rect.y = -h * PANGO_SCALE; |
902 | rect.y = y * PANGO_SCALE; |
856 | rect.width = w * PANGO_SCALE; |
903 | rect.width = w * PANGO_SCALE; |
857 | rect.height = h * PANGO_SCALE; |
904 | rect.height = h * PANGO_SCALE; |
858 | |
905 | |
859 | if (!attrs) |
906 | if (!attrs) |
860 | attrs = pango_layout_get_attributes (self->pl); |
907 | attrs = pango_layout_get_attributes (self->pl); |
861 | |
908 | |
862 | attr = pango_attr_shape_new (&rect, &rect); |
909 | attr = pango_attr_shape_new (&inkrect, &rect); |
863 | attr->start_index = pos - text; |
910 | attr->start_index = pos - text; |
864 | attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1; |
911 | attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1; |
865 | pango_attr_list_insert (attrs, attr); |
912 | pango_attr_list_insert (attrs, attr); |
866 | |
913 | |
|
|
914 | arg += 4; |
867 | pos += sizeof (OBJ_STR) - 1; |
915 | pos += sizeof (OBJ_STR) - 1; |
868 | } |
916 | } |
869 | |
917 | |
870 | if (attrs) |
918 | if (attrs) |
871 | pango_layout_set_attributes (self->pl, attrs); |
919 | pango_layout_set_attributes (self->pl, attrs); |
872 | } |
920 | } |
873 | |
921 | |
874 | void |
922 | void |
875 | get_shapes (CFClient::Layout self) |
923 | get_shapes (CFPlus::Layout self) |
876 | PPCODE: |
924 | PPCODE: |
877 | { |
925 | { |
878 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
926 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
879 | |
927 | |
880 | do |
928 | do |
… | |
… | |
884 | if (run && shape_attr_p (run)) |
932 | if (run && shape_attr_p (run)) |
885 | { |
933 | { |
886 | PangoRectangle extents; |
934 | PangoRectangle extents; |
887 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
935 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
888 | |
936 | |
|
|
937 | EXTEND (SP, 2); |
889 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
938 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); |
890 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
939 | PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); |
891 | } |
940 | } |
892 | } |
941 | } |
893 | while (pango_layout_iter_next_run (iter)); |
942 | while (pango_layout_iter_next_run (iter)); |
894 | |
943 | |
895 | pango_layout_iter_free (iter); |
944 | pango_layout_iter_free (iter); |
896 | } |
945 | } |
897 | |
946 | |
898 | int |
947 | int |
899 | has_wrapped (CFClient::Layout self) |
948 | has_wrapped (CFPlus::Layout self) |
900 | CODE: |
949 | CODE: |
901 | { |
950 | { |
902 | int lines = 1; |
951 | int lines = 1; |
903 | const char *text = pango_layout_get_text (self->pl); |
952 | const char *text = pango_layout_get_text (self->pl); |
904 | |
953 | |
… | |
… | |
909 | } |
958 | } |
910 | OUTPUT: |
959 | OUTPUT: |
911 | RETVAL |
960 | RETVAL |
912 | |
961 | |
913 | SV * |
962 | SV * |
914 | get_text (CFClient::Layout self) |
963 | get_text (CFPlus::Layout self) |
915 | CODE: |
964 | CODE: |
916 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
965 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
917 | sv_utf8_decode (RETVAL); |
966 | sv_utf8_decode (RETVAL); |
918 | OUTPUT: |
967 | OUTPUT: |
919 | RETVAL |
968 | RETVAL |
920 | |
969 | |
921 | void |
970 | void |
922 | 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.) |
923 | CODE: |
972 | CODE: |
924 | self->r = r; |
973 | self->r = r; |
925 | self->g = g; |
974 | self->g = g; |
926 | self->b = b; |
975 | self->b = b; |
927 | self->a = a; |
976 | self->a = a; |
928 | |
977 | |
929 | void |
978 | void |
930 | set_font (CFClient::Layout self, CFClient::Font font = 0) |
979 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
931 | CODE: |
980 | CODE: |
932 | if (self->font != font) |
981 | if (self->font != font) |
933 | { |
982 | { |
934 | self->font = font; |
983 | self->font = font; |
935 | layout_update_font (self); |
984 | layout_update_font (self); |
936 | } |
985 | } |
937 | |
986 | |
938 | void |
987 | void |
939 | set_height (CFClient::Layout self, int base_height) |
988 | set_height (CFPlus::Layout self, int base_height) |
940 | CODE: |
989 | CODE: |
941 | if (self->base_height != base_height) |
990 | if (self->base_height != base_height) |
942 | { |
991 | { |
943 | self->base_height = base_height; |
992 | self->base_height = base_height; |
944 | layout_update_font (self); |
993 | layout_update_font (self); |
945 | } |
994 | } |
946 | |
995 | |
947 | void |
996 | void |
948 | set_width (CFClient::Layout self, int max_width = -1) |
997 | set_width (CFPlus::Layout self, int max_width = -1) |
949 | CODE: |
998 | CODE: |
950 | 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); |
951 | |
1000 | |
952 | void |
1001 | void |
953 | set_indent (CFClient::Layout self, int indent) |
1002 | set_indent (CFPlus::Layout self, int indent) |
954 | CODE: |
1003 | CODE: |
955 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1004 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
956 | |
1005 | |
957 | void |
1006 | void |
958 | set_spacing (CFClient::Layout self, int spacing) |
1007 | set_spacing (CFPlus::Layout self, int spacing) |
959 | CODE: |
1008 | CODE: |
960 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1009 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
961 | |
1010 | |
962 | void |
1011 | void |
963 | set_ellipsise (CFClient::Layout self, int ellipsise) |
1012 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
964 | CODE: |
1013 | CODE: |
965 | pango_layout_set_ellipsize (self->pl, |
1014 | pango_layout_set_ellipsize (self->pl, |
966 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1015 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
967 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1016 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
968 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1017 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
969 | : PANGO_ELLIPSIZE_NONE |
1018 | : PANGO_ELLIPSIZE_NONE |
970 | ); |
1019 | ); |
971 | |
1020 | |
972 | void |
1021 | void |
973 | set_single_paragraph_mode (CFClient::Layout self, int spm) |
1022 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
974 | CODE: |
1023 | CODE: |
975 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1024 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
976 | |
1025 | |
977 | void |
1026 | void |
978 | size (CFClient::Layout self) |
1027 | size (CFPlus::Layout self) |
979 | PPCODE: |
1028 | PPCODE: |
980 | { |
1029 | { |
981 | int w, h; |
1030 | int w, h; |
982 | |
1031 | |
983 | layout_get_pixel_size (self, &w, &h); |
1032 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
986 | PUSHs (sv_2mortal (newSViv (w))); |
1035 | PUSHs (sv_2mortal (newSViv (w))); |
987 | PUSHs (sv_2mortal (newSViv (h))); |
1036 | PUSHs (sv_2mortal (newSViv (h))); |
988 | } |
1037 | } |
989 | |
1038 | |
990 | 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 |
991 | xy_to_index (CFClient::Layout self, int x, int y) |
1052 | xy_to_index (CFPlus::Layout self, int x, int y) |
992 | CODE: |
1053 | CODE: |
993 | { |
1054 | { |
994 | int index, trailing; |
1055 | int index, trailing; |
995 | 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); |
996 | RETVAL = index; |
1057 | RETVAL = index; |
997 | } |
1058 | } |
998 | OUTPUT: |
1059 | OUTPUT: |
999 | RETVAL |
1060 | RETVAL |
1000 | |
1061 | |
1001 | void |
1062 | void |
1002 | cursor_pos (CFClient::Layout self, int index) |
1063 | cursor_pos (CFPlus::Layout self, int index) |
1003 | PPCODE: |
1064 | PPCODE: |
1004 | { |
1065 | { |
1005 | PangoRectangle strong_pos; |
1066 | PangoRectangle strong_pos; |
1006 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1067 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1007 | |
1068 | |
… | |
… | |
1010 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1071 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1011 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1072 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1012 | } |
1073 | } |
1013 | |
1074 | |
1014 | void |
1075 | void |
1015 | render (CFClient::Layout self) |
1076 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1016 | PPCODE: |
1077 | PPCODE: |
1017 | { |
1078 | pango_opengl_render_layout_subpixel ( |
1018 | SV *retval; |
1079 | self->pl, |
1019 | int w, h; |
1080 | x * PANGO_SCALE, y * PANGO_SCALE, |
1020 | |
1081 | self->r, self->g, self->b, self->a, |
1021 | layout_get_pixel_size (self, &w, &h); |
|
|
1022 | |
|
|
1023 | if (self->rgba) |
|
|
1024 | { |
1082 | flags |
1025 | cairo_surface_t *surface; |
|
|
1026 | cairo_t *cairo; |
|
|
1027 | |
|
|
1028 | retval = newSV (w * h * 4); |
|
|
1029 | SvPOK_only (retval); |
|
|
1030 | SvCUR_set (retval, w * h * 4); |
|
|
1031 | |
|
|
1032 | memset (SvPVX (retval), 0, w * h * 4); |
|
|
1033 | |
|
|
1034 | surface = cairo_image_surface_create_for_data ( |
|
|
1035 | (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4); |
|
|
1036 | cairo = cairo_create (surface); |
|
|
1037 | cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a); |
|
|
1038 | |
|
|
1039 | pango_cairo_show_layout (cairo, self->pl); |
|
|
1040 | |
|
|
1041 | cairo_destroy (cairo); |
|
|
1042 | cairo_surface_destroy (surface); |
|
|
1043 | |
|
|
1044 | // what a mess, and its premultiplied, too :( |
|
|
1045 | { |
|
|
1046 | uint32_t *p = (uint32_t *)SvPVX (retval); |
|
|
1047 | uint32_t *e = p + w * h; |
|
|
1048 | |
|
|
1049 | while (p < e) |
|
|
1050 | { |
|
|
1051 | uint32_t rgba = *p; |
|
|
1052 | rgba = (rgba >> 24) | (rgba << 8); |
|
|
1053 | #if 0 |
|
|
1054 | #ifdef _WIN32 |
|
|
1055 | {//D |
|
|
1056 | uint8_t r = rgba >> 24; |
|
|
1057 | uint8_t g = rgba >> 16; |
|
|
1058 | uint8_t b = rgba >> 8; |
|
|
1059 | uint8_t a = rgba >> 0; |
|
|
1060 | |
|
|
1061 | rgba = (rgba & 0xffffff00) | a; |
|
|
1062 | } |
|
|
1063 | #endif |
|
|
1064 | #endif |
|
|
1065 | rgba = SDL_SwapBE32 (rgba); |
|
|
1066 | *p++ = rgba; |
|
|
1067 | } |
|
|
1068 | } |
|
|
1069 | |
|
|
1070 | EXTEND (SP, 5); |
|
|
1071 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
1072 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
1073 | PUSHs (sv_2mortal (retval)); |
|
|
1074 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
1075 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
1076 | } |
1083 | ); |
1077 | else |
|
|
1078 | { |
|
|
1079 | FT_Bitmap bitmap; |
|
|
1080 | |
1084 | |
1081 | retval = newSV (w * h); |
|
|
1082 | SvPOK_only (retval); |
|
|
1083 | SvCUR_set (retval, w * h); |
|
|
1084 | |
|
|
1085 | bitmap.rows = h; |
|
|
1086 | bitmap.width = w; |
|
|
1087 | bitmap.pitch = w; |
|
|
1088 | bitmap.buffer = (unsigned char*)SvPVX (retval); |
|
|
1089 | bitmap.num_grays = 256; |
|
|
1090 | bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
|
|
1091 | |
|
|
1092 | memset (bitmap.buffer, 0, w * h); |
|
|
1093 | |
|
|
1094 | pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
|
|
1095 | |
|
|
1096 | EXTEND (SP, 5); |
|
|
1097 | PUSHs (sv_2mortal (newSViv (w))); |
|
|
1098 | PUSHs (sv_2mortal (newSViv (h))); |
|
|
1099 | PUSHs (sv_2mortal (retval)); |
|
|
1100 | PUSHs (sv_2mortal (newSViv (GL_ALPHA))); |
|
|
1101 | PUSHs (sv_2mortal (newSViv (GL_ALPHA))); |
|
|
1102 | } |
|
|
1103 | } |
|
|
1104 | |
|
|
1105 | MODULE = CFClient PACKAGE = CFClient::Texture |
1085 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1106 | |
1086 | |
1107 | void |
1087 | void |
1108 | pad2pot (SV *data_, SV *w_, SV *h_) |
1088 | pad2pot (SV *data_, SV *w_, SV *h_) |
1109 | CODE: |
1089 | CODE: |
1110 | { |
1090 | { |
… | |
… | |
1188 | glDisable (GL_ALPHA_TEST); |
1168 | glDisable (GL_ALPHA_TEST); |
1189 | glDisable (GL_BLEND); |
1169 | glDisable (GL_BLEND); |
1190 | } |
1170 | } |
1191 | } |
1171 | } |
1192 | |
1172 | |
1193 | MODULE = CFClient PACKAGE = CFClient::Map |
1173 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1194 | |
1174 | |
1195 | CFClient::Map |
1175 | CFPlus::Map |
1196 | new (SV *class, int map_width, int map_height) |
1176 | new (SV *class, int map_width, int map_height) |
1197 | CODE: |
1177 | CODE: |
1198 | New (0, RETVAL, 1, struct map); |
1178 | New (0, RETVAL, 1, struct map); |
1199 | RETVAL->x = 0; |
1179 | RETVAL->x = 0; |
1200 | RETVAL->y = 0; |
1180 | RETVAL->y = 0; |
… | |
… | |
1210 | RETVAL->row = 0; |
1190 | RETVAL->row = 0; |
1211 | OUTPUT: |
1191 | OUTPUT: |
1212 | RETVAL |
1192 | RETVAL |
1213 | |
1193 | |
1214 | void |
1194 | void |
1215 | DESTROY (CFClient::Map self) |
1195 | DESTROY (CFPlus::Map self) |
1216 | CODE: |
1196 | CODE: |
1217 | { |
1197 | { |
1218 | map_clear (self); |
1198 | map_clear (self); |
1219 | Safefree (self->face); |
1199 | Safefree (self->face); |
1220 | Safefree (self->tex); |
1200 | Safefree (self->tex); |
1221 | Safefree (self); |
1201 | Safefree (self); |
1222 | } |
1202 | } |
1223 | |
1203 | |
1224 | void |
1204 | void |
1225 | clear (CFClient::Map self) |
1205 | clear (CFPlus::Map self) |
1226 | CODE: |
1206 | CODE: |
1227 | map_clear (self); |
1207 | map_clear (self); |
1228 | |
1208 | |
1229 | void |
1209 | void |
1230 | set_face (CFClient::Map self, int face, int texid) |
1210 | set_face (CFPlus::Map self, int face, int texid) |
1231 | CODE: |
1211 | CODE: |
1232 | { |
1212 | { |
1233 | while (self->faces <= face) |
1213 | while (self->faces <= face) |
1234 | { |
1214 | { |
1235 | Append (mapface, self->face, self->faces, self->faces); |
1215 | Append (mapface, self->face, self->faces, self->faces); |
… | |
… | |
1238 | |
1218 | |
1239 | self->face [face] = texid; |
1219 | self->face [face] = texid; |
1240 | } |
1220 | } |
1241 | |
1221 | |
1242 | void |
1222 | void |
1243 | 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) |
1244 | CODE: |
1224 | CODE: |
1245 | { |
1225 | { |
1246 | while (self->texs <= texid) |
1226 | while (self->texs <= texid) |
1247 | { |
1227 | { |
1248 | Append (maptex, self->tex, self->texs, self->texs); |
1228 | Append (maptex, self->tex, self->texs, self->texs); |
… | |
… | |
1272 | // from transparent color bleeding and ugly wrapping effects. |
1252 | // from transparent color bleeding and ugly wrapping effects. |
1273 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1253 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1274 | } |
1254 | } |
1275 | |
1255 | |
1276 | int |
1256 | int |
1277 | ox (CFClient::Map self) |
1257 | ox (CFPlus::Map self) |
1278 | ALIAS: |
1258 | ALIAS: |
1279 | oy = 1 |
1259 | oy = 1 |
1280 | x = 2 |
1260 | x = 2 |
1281 | y = 3 |
1261 | y = 3 |
1282 | w = 4 |
1262 | w = 4 |
… | |
… | |
1293 | } |
1273 | } |
1294 | OUTPUT: |
1274 | OUTPUT: |
1295 | RETVAL |
1275 | RETVAL |
1296 | |
1276 | |
1297 | void |
1277 | void |
1298 | scroll (CFClient::Map self, int dx, int dy) |
1278 | scroll (CFPlus::Map self, int dx, int dy) |
1299 | CODE: |
1279 | CODE: |
1300 | { |
1280 | { |
1301 | if (dx > 0) |
1281 | if (dx > 0) |
1302 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1282 | map_blank (self, self->x, self->y, dx, self->h); |
1303 | else if (dx < 0) |
1283 | else if (dx < 0) |
1304 | 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); |
1305 | |
1285 | |
1306 | if (dy > 0) |
1286 | if (dy > 0) |
1307 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1287 | map_blank (self, self->x, self->y, self->w, dy); |
1308 | else if (dy < 0) |
1288 | else if (dy < 0) |
1309 | 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); |
1310 | |
1290 | |
1311 | self->ox += dx; self->x += dx; |
1291 | self->ox += dx; self->x += dx; |
1312 | self->oy += dy; self->y += dy; |
1292 | self->oy += dy; self->y += dy; |
1313 | |
1293 | |
1314 | while (self->y < 0) |
1294 | while (self->y < 0) |
… | |
… | |
1319 | self->y += MAP_EXTEND_Y; |
1299 | self->y += MAP_EXTEND_Y; |
1320 | } |
1300 | } |
1321 | } |
1301 | } |
1322 | |
1302 | |
1323 | void |
1303 | void |
1324 | map1a_update (CFClient::Map self, SV *data_) |
1304 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1325 | CODE: |
1305 | CODE: |
1326 | { |
1306 | { |
1327 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1307 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1328 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1308 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1329 | mapcell *cell; |
1309 | mapcell *cell; |
1330 | int x, y, flags; |
1310 | int x, y, flags; |
1331 | |
1311 | |
1332 | while (data < data_end) |
1312 | while (data < data_end - 1) |
1333 | { |
1313 | { |
1334 | flags = (data [0] << 8) + data [1]; data += 2; |
1314 | flags = (data [0] << 8) + data [1]; data += 2; |
1335 | |
1315 | |
1336 | x = self->x + ((flags >> 10) & 63); |
1316 | x = self->x + ((flags >> 10) & 63); |
1337 | y = self->y + ((flags >> 4) & 63); |
1317 | y = self->y + ((flags >> 4) & 63); |
1338 | |
1318 | |
1339 | cell = map_get_cell (self, x, y); |
1319 | cell = map_get_cell (self, x, y); |
1340 | |
1320 | |
1341 | if (flags & 15) |
1321 | if (flags & 15) |
1342 | { |
1322 | { |
1343 | if (cell->darkness < 0) |
1323 | if (!cell->darkness) |
1344 | { |
1324 | { |
|
|
1325 | memset (cell, 0, sizeof (*cell)); |
1345 | cell->darkness = 0; |
1326 | cell->darkness = 256; |
1346 | cell->face [0] = 0; |
|
|
1347 | cell->face [1] = 0; |
|
|
1348 | cell->face [2] = 0; |
|
|
1349 | } |
1327 | } |
1350 | |
1328 | |
1351 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1352 | |
|
|
1353 | //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 | } |
1354 | |
1370 | |
1355 | if (flags & 4) |
1371 | if (flags & 4) |
1356 | { |
1372 | { |
1357 | 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; |
1358 | } |
1374 | } |
… | |
… | |
1366 | { |
1382 | { |
1367 | 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; |
1368 | } |
1384 | } |
1369 | } |
1385 | } |
1370 | else |
1386 | else |
1371 | cell->darkness = -1; |
1387 | cell->darkness = 0; |
1372 | } |
1388 | } |
1373 | } |
1389 | } |
1374 | |
1390 | |
1375 | SV * |
1391 | SV * |
1376 | 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) |
1377 | CODE: |
1393 | CODE: |
1378 | { |
1394 | { |
1379 | int x1, x; |
1395 | int x1, x; |
1380 | int y1, y; |
1396 | int y1, y; |
1381 | int z; |
1397 | int z; |
… | |
… | |
1431 | } |
1447 | } |
1432 | OUTPUT: |
1448 | OUTPUT: |
1433 | RETVAL |
1449 | RETVAL |
1434 | |
1450 | |
1435 | void |
1451 | void |
1436 | 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) |
1437 | CODE: |
1453 | CODE: |
1438 | { |
1454 | { |
1439 | int vx, vy; |
1455 | int vx, vy; |
1440 | int x, y, z; |
1456 | int x, y, z; |
1441 | int last_name; |
1457 | int last_name; |
… | |
… | |
1476 | { |
1492 | { |
1477 | mapcell *cell = row->col + (x + vx - row->c0); |
1493 | mapcell *cell = row->col + (x + vx - row->c0); |
1478 | |
1494 | |
1479 | face = cell->face [z]; |
1495 | face = cell->face [z]; |
1480 | |
1496 | |
1481 | if (face) |
1497 | if (face && face < self->texs) |
1482 | { |
1498 | { |
1483 | maptex tex = self->tex [face]; |
1499 | maptex tex = self->tex [face]; |
1484 | |
|
|
1485 | int px = (x + 1) * 32 - tex.w; |
1500 | int px = (x + 1) * 32 - tex.w; |
1486 | int py = (y + 1) * 32 - tex.h; |
1501 | int py = (y + 1) * 32 - tex.h; |
1487 | |
1502 | |
1488 | if (last_name != tex.name) |
1503 | if (last_name != tex.name) |
1489 | { |
1504 | { |
1490 | glEnd (); |
1505 | glEnd (); |
1491 | last_name = tex.name; |
|
|
1492 | glBindTexture (GL_TEXTURE_2D, last_name); |
1506 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1493 | glBegin (GL_QUADS); |
1507 | glBegin (GL_QUADS); |
1494 | } |
1508 | } |
1495 | |
1509 | |
1496 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1510 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1497 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1511 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1498 | 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); |
1499 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1513 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1500 | } |
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 | } |
1501 | } |
1534 | } |
1502 | } |
1535 | } |
1503 | |
1536 | |
1504 | glEnd (); |
1537 | glEnd (); |
1505 | |
1538 | |
1506 | glDisable (GL_TEXTURE_2D); |
1539 | glDisable (GL_TEXTURE_2D); |
1507 | glDisable (GL_BLEND); |
1540 | glDisable (GL_BLEND); |
1508 | } |
|
|
1509 | |
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 | |
1510 | void |
1574 | void |
1511 | draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1575 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1512 | CODE: |
1576 | CODE: |
1513 | { |
1577 | { |
1514 | static float color[16][3] = { |
1578 | static float color[16][3] = { |
1515 | { 0.00, 0.00, 0.00 }, |
1579 | { 0.00F, 0.00F, 0.00F }, |
1516 | { 1.00, 1.00, 1.00 }, |
1580 | { 1.00F, 1.00F, 1.00F }, |
1517 | { 0.00, 0.00, 0.55 }, |
1581 | { 0.00F, 0.00F, 0.55F }, |
1518 | { 1.00, 0.00, 0.00 }, |
1582 | { 1.00F, 0.00F, 0.00F }, |
1519 | |
1583 | |
1520 | { 1.00, 0.54, 0.00 }, |
1584 | { 1.00F, 0.54F, 0.00F }, |
1521 | { 0.11, 0.56, 1.00 }, |
1585 | { 0.11F, 0.56F, 1.00F }, |
1522 | { 0.93, 0.46, 0.00 }, |
1586 | { 0.93F, 0.46F, 0.00F }, |
1523 | { 0.18, 0.54, 0.34 }, |
1587 | { 0.18F, 0.54F, 0.34F }, |
1524 | |
1588 | |
1525 | { 0.56, 0.73, 0.56 }, |
1589 | { 0.56F, 0.73F, 0.56F }, |
1526 | { 0.80, 0.80, 0.80 }, |
1590 | { 0.80F, 0.80F, 0.80F }, |
1527 | { 0.55, 0.41, 0.13 }, |
1591 | { 0.55F, 0.41F, 0.13F }, |
1528 | { 0.99, 0.77, 0.26 }, |
1592 | { 0.99F, 0.77F, 0.26F }, |
1529 | |
1593 | |
1530 | { 0.74, 0.65, 0.41 }, |
1594 | { 0.74F, 0.65F, 0.41F }, |
1531 | |
1595 | |
1532 | { 0.00, 1.00, 1.00 }, |
1596 | { 0.00F, 1.00F, 1.00F }, |
1533 | { 1.00, 0.00, 1.00 }, |
1597 | { 1.00F, 0.00F, 1.00F }, |
1534 | { 1.00, 1.00, 0.00 }, |
1598 | { 1.00F, 1.00F, 0.00F }, |
1535 | }; |
1599 | }; |
1536 | |
1600 | |
1537 | int x, y; |
1601 | int x, y; |
1538 | |
1602 | |
1539 | glEnable (GL_TEXTURE_2D); |
1603 | glEnable (GL_TEXTURE_2D); |
… | |
… | |
1566 | glDisable (GL_BLEND); |
1630 | glDisable (GL_BLEND); |
1567 | glDisable (GL_TEXTURE_2D); |
1631 | glDisable (GL_TEXTURE_2D); |
1568 | } |
1632 | } |
1569 | |
1633 | |
1570 | void |
1634 | void |
1571 | fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1635 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1572 | PPCODE: |
1636 | PPCODE: |
1573 | { |
1637 | { |
1574 | int vx, vy; |
1638 | int vx, vy; |
1575 | int x, y; |
1639 | int x, y; |
1576 | int sw4 = (sw + 3) & ~3; |
1640 | int sw4 = (sw + 3) & ~3; |
… | |
… | |
1592 | for (x = 0; x < sw; x++) |
1656 | for (x = 0; x < sw; x++) |
1593 | if (row->c0 <= x + vx && x + vx < row->c1) |
1657 | if (row->c0 <= x + vx && x + vx < row->c1) |
1594 | { |
1658 | { |
1595 | mapcell *cell = row->col + (x + vx - row->c0); |
1659 | mapcell *cell = row->col + (x + vx - row->c0); |
1596 | |
1660 | |
1597 | darkness[y * sw4 + x] = cell->darkness < 0 |
1661 | darkness[y * sw4 + x] = cell->darkness |
|
|
1662 | ? 255 - (cell->darkness - 1) |
1598 | ? 255 - FOW_DARKNESS |
1663 | : 255 - FOW_DARKNESS; |
1599 | : 255 - cell->darkness; |
|
|
1600 | } |
1664 | } |
1601 | } |
1665 | } |
1602 | |
1666 | |
1603 | EXTEND (SP, 3); |
1667 | EXTEND (SP, 3); |
1604 | PUSHs (sv_2mortal (newSViv (sw4))); |
1668 | PUSHs (sv_2mortal (newSViv (sw4))); |
1605 | PUSHs (sv_2mortal (newSViv (sh))); |
1669 | PUSHs (sv_2mortal (newSViv (sh))); |
1606 | PUSHs (darkness_sv); |
1670 | PUSHs (darkness_sv); |
1607 | } |
1671 | } |
1608 | |
1672 | |
1609 | SV * |
1673 | SV * |
1610 | 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) |
1611 | CODE: |
1675 | CODE: |
1612 | { |
1676 | { |
1613 | int x, y, x1, y1; |
1677 | int x, y, x1, y1; |
1614 | SV *data_sv = newSV (w * h * 7 + 5); |
1678 | SV *data_sv = newSV (w * h * 7 + 5); |
1615 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
1679 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
1677 | } |
1741 | } |
1678 | OUTPUT: |
1742 | OUTPUT: |
1679 | RETVAL |
1743 | RETVAL |
1680 | |
1744 | |
1681 | void |
1745 | void |
1682 | 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) |
1683 | PPCODE: |
1747 | PPCODE: |
1684 | { |
1748 | { |
1685 | int x, y, z; |
1749 | int x, y, z; |
1686 | int w, h; |
1750 | int w, h; |
1687 | int x1, y1; |
1751 | int x1, y1; |
… | |
… | |
1719 | |
1783 | |
1720 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1784 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1721 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1785 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1722 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1786 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1723 | |
1787 | |
1724 | if (cell->darkness <= 0) |
1788 | if (cell->darkness == 0) |
1725 | { |
1789 | { |
1726 | cell->darkness = -1; |
1790 | cell->darkness = 0; |
1727 | |
1791 | |
1728 | for (z = 0; z <= 2; z++) |
1792 | for (z = 0; z <= 2; z++) |
1729 | { |
1793 | { |
1730 | cell->face[z] = face[z]; |
1794 | cell->face[z] = face[z]; |
1731 | |
1795 | |
… | |
… | |
1736 | } |
1800 | } |
1737 | } |
1801 | } |
1738 | } |
1802 | } |
1739 | } |
1803 | } |
1740 | |
1804 | |
1741 | MODULE = CFClient PACKAGE = CFClient::MixChunk |
1805 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
1742 | |
1806 | |
1743 | CFClient::MixChunk |
1807 | CFPlus::MixChunk |
1744 | new_from_file (SV *class, char *path) |
1808 | new_from_file (SV *class, char *path) |
1745 | CODE: |
1809 | CODE: |
1746 | RETVAL = Mix_LoadWAV (path); |
1810 | RETVAL = Mix_LoadWAV (path); |
1747 | OUTPUT: |
1811 | OUTPUT: |
1748 | RETVAL |
1812 | RETVAL |
1749 | |
1813 | |
1750 | void |
1814 | void |
1751 | DESTROY (CFClient::MixChunk self) |
1815 | DESTROY (CFPlus::MixChunk self) |
1752 | CODE: |
1816 | CODE: |
1753 | Mix_FreeChunk (self); |
1817 | Mix_FreeChunk (self); |
1754 | |
1818 | |
1755 | int |
1819 | int |
1756 | volume (CFClient::MixChunk self, int volume = -1) |
1820 | volume (CFPlus::MixChunk self, int volume = -1) |
1757 | CODE: |
1821 | CODE: |
1758 | RETVAL = Mix_VolumeChunk (self, volume); |
1822 | RETVAL = Mix_VolumeChunk (self, volume); |
1759 | OUTPUT: |
1823 | OUTPUT: |
1760 | RETVAL |
1824 | RETVAL |
1761 | |
1825 | |
1762 | int |
1826 | int |
1763 | 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) |
1764 | CODE: |
1828 | CODE: |
1765 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1829 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
1766 | OUTPUT: |
1830 | OUTPUT: |
1767 | RETVAL |
1831 | RETVAL |
1768 | |
1832 | |
1769 | MODULE = CFClient PACKAGE = CFClient::MixMusic |
1833 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
1770 | |
1834 | |
1771 | int |
1835 | int |
1772 | volume (int volume = -1) |
1836 | volume (int volume = -1) |
1773 | CODE: |
1837 | CODE: |
1774 | RETVAL = Mix_VolumeMusic (volume); |
1838 | RETVAL = Mix_VolumeMusic (volume); |
1775 | OUTPUT: |
1839 | OUTPUT: |
1776 | RETVAL |
1840 | RETVAL |
1777 | |
1841 | |
1778 | CFClient::MixMusic |
1842 | CFPlus::MixMusic |
1779 | new_from_file (SV *class, char *path) |
1843 | new_from_file (SV *class, char *path) |
1780 | CODE: |
1844 | CODE: |
1781 | RETVAL = Mix_LoadMUS (path); |
1845 | RETVAL = Mix_LoadMUS (path); |
1782 | OUTPUT: |
1846 | OUTPUT: |
1783 | RETVAL |
1847 | RETVAL |
1784 | |
1848 | |
1785 | void |
1849 | void |
1786 | DESTROY (CFClient::MixMusic self) |
1850 | DESTROY (CFPlus::MixMusic self) |
1787 | CODE: |
1851 | CODE: |
1788 | Mix_FreeMusic (self); |
1852 | Mix_FreeMusic (self); |
1789 | |
1853 | |
1790 | int |
1854 | int |
1791 | play (CFClient::MixMusic self, int loops = -1) |
1855 | play (CFPlus::MixMusic self, int loops = -1) |
1792 | CODE: |
1856 | CODE: |
1793 | RETVAL = Mix_PlayMusic (self, loops); |
1857 | RETVAL = Mix_PlayMusic (self, loops); |
1794 | OUTPUT: |
1858 | OUTPUT: |
1795 | RETVAL |
1859 | RETVAL |
1796 | |
1860 | |
1797 | MODULE = CFClient PACKAGE = CFClient::OpenGL |
1861 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
1798 | |
1862 | |
1799 | BOOT: |
1863 | BOOT: |
1800 | { |
1864 | { |
1801 | HV *stash = gv_stashpv ("CFClient::OpenGL", 1); |
1865 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
1802 | static const struct { |
1866 | static const struct { |
1803 | const char *name; |
1867 | const char *name; |
1804 | IV iv; |
1868 | IV iv; |
1805 | } *civ, const_iv[] = { |
1869 | } *civ, const_iv[] = { |
1806 | # define const_iv(name) { # name, (IV)name } |
1870 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
1869 | const_iv (GL_SEPARABLE_2D), |
1933 | const_iv (GL_SEPARABLE_2D), |
1870 | const_iv (GL_CONVOLUTION_2D), |
1934 | const_iv (GL_CONVOLUTION_2D), |
1871 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1935 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1872 | const_iv (GL_CONSTANT_BORDER), |
1936 | const_iv (GL_CONSTANT_BORDER), |
1873 | const_iv (GL_LINES), |
1937 | const_iv (GL_LINES), |
|
|
1938 | const_iv (GL_LINE_STRIP), |
1874 | const_iv (GL_LINE_LOOP), |
1939 | const_iv (GL_LINE_LOOP), |
1875 | const_iv (GL_QUADS), |
1940 | const_iv (GL_QUADS), |
1876 | const_iv (GL_QUAD_STRIP), |
1941 | const_iv (GL_QUAD_STRIP), |
1877 | const_iv (GL_TRIANGLES), |
1942 | const_iv (GL_TRIANGLES), |
1878 | const_iv (GL_TRIANGLE_STRIP), |
1943 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
1988 | r *= a; |
2053 | r *= a; |
1989 | g *= a; |
2054 | g *= a; |
1990 | b *= a; |
2055 | b *= a; |
1991 | } |
2056 | } |
1992 | // microsoft visual "c" rounds instead of truncating... |
2057 | // microsoft visual "c" rounds instead of truncating... |
1993 | glColor4ub (MIN ((int)(r * 256.f), 255), |
2058 | glColor4f (r, g, b, a); |
1994 | MIN ((int)(g * 256.f), 255), |
|
|
1995 | MIN ((int)(b * 256.f), 255), |
|
|
1996 | MIN ((int)(a * 256.f), 255)); |
|
|
1997 | |
2059 | |
1998 | void glInterleavedArrays (int format, int stride, char *data) |
2060 | void glInterleavedArrays (int format, int stride, char *data) |
1999 | |
2061 | |
2000 | void glDrawElements (int mode, int count, int type, char *indices) |
2062 | void glDrawElements (int mode, int count, int type, char *indices) |
2001 | |
2063 | |
… | |
… | |
2078 | |
2140 | |
2079 | void glEndList () |
2141 | void glEndList () |
2080 | |
2142 | |
2081 | void glCallList (int list) |
2143 | void glCallList (int list) |
2082 | |
2144 | |
2083 | |
|
|