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