… | |
… | |
15 | |
15 | |
16 | #include "EXTERN.h" |
16 | #include "EXTERN.h" |
17 | #include "perl.h" |
17 | #include "perl.h" |
18 | #include "XSUB.h" |
18 | #include "XSUB.h" |
19 | |
19 | |
|
|
20 | #include "flat_hash_map.hpp" |
|
|
21 | |
20 | #ifdef _WIN32 |
22 | #ifdef _WIN32 |
21 | # undef pipe |
23 | # undef pipe |
22 | // microsoft vs. C |
24 | // microsoft vs. C |
23 | # define sqrtf(x) sqrt(x) |
25 | # define sqrtf(x) sqrt(x) |
24 | # define roundf(x) (int)(x) |
|
|
25 | # define atan2f(x,y) atan2(x,y) |
26 | # define atan2f(x,y) atan2(x,y) |
26 | # define M_PI 3.14159265f |
27 | # define M_PI 3.14159265f |
27 | #endif |
28 | #endif |
28 | |
29 | |
29 | #include <assert.h> |
30 | #include <cassert> |
30 | #include <math.h> |
31 | #include <cmath> |
31 | #include <string.h> |
32 | #include <cstring> |
32 | #include <stdio.h> |
33 | #include <cstdio> |
33 | #include <stdlib.h> |
34 | #include <cstdlib> |
|
|
35 | |
|
|
36 | #include <utility> |
34 | |
37 | |
35 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
38 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
36 | |
39 | |
37 | #include <SDL.h> |
40 | #include <SDL.h> |
38 | #include <SDL_thread.h> |
41 | #include <SDL_thread.h> |
39 | #include <SDL_endian.h> |
42 | #include <SDL_endian.h> |
40 | #include <SDL_image.h> |
43 | #include <SDL_image.h> |
41 | #include <SDL_mixer.h> |
44 | #include <SDL_mixer.h> |
42 | #include <SDL_opengl.h> |
45 | #include <SDL_opengl.h> |
43 | |
46 | |
|
|
47 | /* work around os x broken headers */ |
|
|
48 | #ifdef __MACOSX__ |
|
|
49 | typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); |
|
|
50 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); |
|
|
51 | typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); |
|
|
52 | #endif |
|
|
53 | |
44 | #define PANGO_ENABLE_BACKEND |
54 | #define PANGO_ENABLE_BACKEND |
45 | #define G_DISABLE_CAST_CHECKS |
55 | #define G_DISABLE_CAST_CHECKS |
46 | |
56 | |
47 | #include <glib/gmacros.h> |
57 | #include <glib.h> |
48 | |
58 | |
49 | #include <pango/pango.h> |
59 | #include <pango/pango.h> |
|
|
60 | |
|
|
61 | #ifndef PANGO_VERSION_CHECK |
|
|
62 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
|
|
63 | #endif |
|
|
64 | |
|
|
65 | #if !PANGO_VERSION_CHECK (1, 15, 2) |
|
|
66 | # define pango_layout_get_line_readonly pango_layout_get_line |
|
|
67 | # define pango_layout_get_lines_readonly pango_layout_get_lines |
|
|
68 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line |
|
|
69 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run |
|
|
70 | #endif |
50 | |
71 | |
51 | #ifndef _WIN32 |
72 | #ifndef _WIN32 |
52 | # include <sys/types.h> |
73 | # include <sys/types.h> |
53 | # include <sys/socket.h> |
74 | # include <sys/socket.h> |
54 | # include <netinet/in.h> |
75 | # include <netinet/in.h> |
55 | # include <netinet/tcp.h> |
76 | # include <netinet/tcp.h> |
56 | # include <inttypes.h> |
77 | # include <inttypes.h> |
57 | #endif |
78 | #endif |
58 | |
79 | |
|
|
80 | #if __GNUC__ >= 4 |
|
|
81 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
82 | #else |
|
|
83 | # define expect(expr,value) (expr) |
|
|
84 | #endif |
|
|
85 | |
|
|
86 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
87 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
88 | |
59 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
89 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
60 | |
90 | |
|
|
91 | /* this is used as fow flag as well, so has to have a different value */ |
|
|
92 | /* then anything that is computed by incoming darkness */ |
61 | #define FOW_DARKNESS 32 |
93 | #define FOW_DARKNESS 50 |
|
|
94 | #define DARKNESS_ADJUST(n) (n) |
62 | |
95 | |
63 | #define MAP_EXTEND_X 32 |
96 | #define MAP_EXTEND_X 32 |
64 | #define MAP_EXTEND_Y 512 |
97 | #define MAP_EXTEND_Y 512 |
65 | |
98 | |
66 | #define MIN_FONT_HEIGHT 10 |
99 | #define MIN_FONT_HEIGHT 10 |
67 | |
100 | |
68 | #if 0 |
101 | /* mask out modifiers we are not interested in */ |
69 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
102 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
70 | #else |
103 | |
71 | # define PARACHUTE 0 |
104 | #define KMOD_LRAM 0x10000 // our extension |
72 | #endif |
105 | |
|
|
106 | #define TEXID_SPEECH 1 |
|
|
107 | #define TEXID_NOFACE 2 |
|
|
108 | |
|
|
109 | static char * |
|
|
110 | fast_sv_grow (SV *sv, STRLEN need) |
|
|
111 | { |
|
|
112 | STRLEN len = SvLEN (sv); |
|
|
113 | STRLEN want = SvCUR (sv) + need; |
|
|
114 | |
|
|
115 | if (expect_false (len < want)) |
|
|
116 | { |
|
|
117 | do |
|
|
118 | len *= 2; |
|
|
119 | while (len < want); |
|
|
120 | |
|
|
121 | sv_grow (sv, len); |
|
|
122 | } |
|
|
123 | |
|
|
124 | SvCUR_set (sv, want); |
|
|
125 | return SvEND (sv) - need; |
|
|
126 | } |
73 | |
127 | |
74 | static AV *texture_av; |
128 | static AV *texture_av; |
75 | |
129 | |
76 | static struct |
130 | static struct |
77 | { |
131 | { |
… | |
… | |
120 | |
174 | |
121 | #include "pango-font.c" |
175 | #include "pango-font.c" |
122 | #include "pango-fontmap.c" |
176 | #include "pango-fontmap.c" |
123 | #include "pango-render.c" |
177 | #include "pango-render.c" |
124 | |
178 | |
125 | typedef IV CFPlus__Channel; |
179 | typedef IV DC__Channel; |
126 | typedef SDL_RWops *CFPlus__RW; |
180 | typedef SDL_RWops *DC__RW; |
127 | typedef Mix_Chunk *CFPlus__MixChunk; |
181 | typedef Mix_Chunk *DC__MixChunk; |
128 | typedef Mix_Music *CFPlus__MixMusic; |
182 | typedef Mix_Music *DC__MixMusic; |
129 | |
183 | |
130 | typedef PangoFontDescription *CFPlus__Font; |
184 | typedef PangoFontDescription *DC__Font; |
131 | |
185 | |
132 | static int |
186 | static int |
133 | shape_attr_p (PangoLayoutRun *run) |
187 | shape_attr_p (PangoLayoutRun *run) |
134 | { |
188 | { |
135 | GSList *attrs = run->item->analysis.extra_attrs; |
189 | GSList *attrs = run->item->analysis.extra_attrs; |
136 | |
190 | |
137 | while (attrs) |
191 | while (attrs) |
138 | { |
192 | { |
139 | PangoAttribute *attr = attrs->data; |
193 | PangoAttribute *attr = (PangoAttribute *)attrs->data; |
140 | |
194 | |
141 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
195 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
142 | return 1; |
196 | return 1; |
143 | |
197 | |
144 | attrs = attrs->next; |
198 | attrs = attrs->next; |
… | |
… | |
149 | |
203 | |
150 | typedef struct cf_layout { |
204 | typedef struct cf_layout { |
151 | PangoLayout *pl; |
205 | PangoLayout *pl; |
152 | float r, g, b, a; // default color for rgba mode |
206 | float r, g, b, a; // default color for rgba mode |
153 | int base_height; |
207 | int base_height; |
154 | CFPlus__Font font; |
208 | DC__Font font; |
|
|
209 | rc_t *rc; |
155 | } *CFPlus__Layout; |
210 | } *DC__Layout; |
156 | |
211 | |
157 | static CFPlus__Font default_font; |
212 | static DC__Font default_font; |
158 | static PangoContext *opengl_context; |
213 | static PangoContext *opengl_context; |
159 | static PangoFontMap *opengl_fontmap; |
214 | static PangoFontMap *opengl_fontmap; |
160 | |
215 | |
161 | static void |
216 | static void |
162 | substitute_func (FcPattern *pattern, gpointer data) |
217 | substitute_func (FcPattern *pattern, gpointer data) |
163 | { |
218 | { |
164 | FcPatternAddBool (pattern, FC_HINTING, 1); |
219 | FcPatternAddBool (pattern, FC_HINTING, 1); |
165 | #ifdef FC_HINT_STYLE |
220 | #ifdef FC_HINT_STYLE |
166 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
221 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
167 | #endif |
222 | #endif |
168 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
223 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
169 | } |
224 | } |
170 | |
225 | |
171 | static void |
226 | static void |
172 | layout_update_font (CFPlus__Layout self) |
227 | layout_update_font (DC__Layout self) |
173 | { |
228 | { |
174 | /* use a random scale factor to account for unknown descenders, 0.8 works |
229 | /* use a random scale factor to account for unknown descenders, 0.8 works |
175 | * reasonably well with bitstream vera |
230 | * reasonably well with dejavu/bistream fonts |
176 | */ |
231 | */ |
177 | PangoFontDescription *font = self->font ? self->font : default_font; |
232 | PangoFontDescription *font = self->font ? self->font : default_font; |
178 | |
233 | |
179 | pango_font_description_set_absolute_size (font, |
234 | pango_font_description_set_absolute_size (font, |
180 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
235 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
181 | |
236 | |
182 | pango_layout_set_font_description (self->pl, font); |
237 | pango_layout_set_font_description (self->pl, font); |
183 | } |
238 | } |
184 | |
239 | |
185 | static void |
240 | static void |
186 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
241 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
187 | { |
242 | { |
188 | PangoRectangle rect; |
243 | PangoRectangle rect; |
189 | |
244 | |
190 | // get_pixel_* wrongly rounds down |
245 | // get_pixel_* wrongly rounds down |
191 | pango_layout_get_extents (self->pl, 0, &rect); |
246 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
202 | |
257 | |
203 | typedef uint16_t tileid; |
258 | typedef uint16_t tileid; |
204 | typedef uint16_t faceid; |
259 | typedef uint16_t faceid; |
205 | |
260 | |
206 | typedef struct { |
261 | typedef struct { |
207 | int name; |
262 | GLuint name; |
208 | int w, h; |
263 | int w, h; |
209 | float s, t; |
264 | float s, t; |
210 | uint8_t r, g, b, a; |
265 | uint8_t r, g, b, a; |
211 | tileid smoothtile; |
266 | tileid smoothtile; |
212 | uint8_t smoothlevel; |
267 | uint8_t smoothlevel; |
|
|
268 | uint8_t unused; /* set to zero on use */ |
213 | } maptex; |
269 | } maptex; |
214 | |
270 | |
215 | typedef struct { |
271 | typedef struct { |
216 | uint32_t player; |
272 | uint32_t player; |
217 | tileid tile[3]; |
273 | tileid tile[3]; |
… | |
… | |
230 | int faces; tileid *face2tile; // [faceid] |
286 | int faces; tileid *face2tile; // [faceid] |
231 | int texs; maptex *tex; // [tileid] |
287 | int texs; maptex *tex; // [tileid] |
232 | |
288 | |
233 | int32_t rows; |
289 | int32_t rows; |
234 | maprow *row; |
290 | maprow *row; |
235 | } *CFPlus__Map; |
291 | } *DC__Map; |
236 | |
292 | |
237 | static char * |
293 | static char * |
238 | prepend (char *ptr, int sze, int inc) |
294 | prepend (char *ptr, int sze, int inc) |
239 | { |
295 | { |
240 | char *p; |
296 | char *p; |
… | |
… | |
278 | self->texs *= 2; |
334 | self->texs *= 2; |
279 | } |
335 | } |
280 | } |
336 | } |
281 | |
337 | |
282 | static maprow * |
338 | static maprow * |
283 | map_get_row (CFPlus__Map self, int y) |
339 | map_get_row (DC__Map self, int y) |
284 | { |
340 | { |
285 | if (0 > y) |
341 | if (0 > y) |
286 | { |
342 | { |
287 | int extend = - y + MAP_EXTEND_Y; |
343 | int extend = - y + MAP_EXTEND_Y; |
288 | Prepend (maprow, self->row, self->rows, extend); |
344 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
326 | |
382 | |
327 | return row->col + (x - row->c0); |
383 | return row->col + (x - row->c0); |
328 | } |
384 | } |
329 | |
385 | |
330 | static mapcell * |
386 | static mapcell * |
331 | map_get_cell (CFPlus__Map self, int x, int y) |
387 | map_get_cell (DC__Map self, int x, int y) |
332 | { |
388 | { |
333 | return row_get_cell (map_get_row (self, y), x); |
389 | return row_get_cell (map_get_row (self, y), x); |
334 | } |
390 | } |
335 | |
391 | |
336 | static void |
392 | static void |
337 | map_clear (CFPlus__Map self) |
393 | map_clear (DC__Map self) |
338 | { |
394 | { |
339 | int r; |
395 | int r; |
340 | |
396 | |
341 | for (r = 0; r < self->rows; r++) |
397 | for (r = 0; r < self->rows; r++) |
342 | Safefree (self->row[r].col); |
398 | Safefree (self->row[r].col); |
… | |
… | |
349 | self->oy = 0; |
405 | self->oy = 0; |
350 | self->row = 0; |
406 | self->row = 0; |
351 | self->rows = 0; |
407 | self->rows = 0; |
352 | } |
408 | } |
353 | |
409 | |
|
|
410 | #define CELL_CLEAR(cell) \ |
|
|
411 | do { \ |
|
|
412 | if ((cell)->player) \ |
|
|
413 | (cell)->tile [2] = 0; \ |
|
|
414 | (cell)->darkness = 0; \ |
|
|
415 | (cell)->stat_hp = 0; \ |
|
|
416 | (cell)->flags = 0; \ |
|
|
417 | (cell)->player = 0; \ |
|
|
418 | } while (0) |
|
|
419 | |
354 | static void |
420 | static void |
355 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
421 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
356 | { |
422 | { |
357 | int x, y; |
423 | int x, y; |
358 | maprow *row; |
424 | maprow *row; |
359 | mapcell *cell; |
425 | mapcell *cell; |
360 | |
426 | |
… | |
… | |
372 | if (x >= row->c1) |
438 | if (x >= row->c1) |
373 | break; |
439 | break; |
374 | |
440 | |
375 | cell = row->col + x - row->c0; |
441 | cell = row->col + x - row->c0; |
376 | |
442 | |
377 | cell->darkness = 0; |
443 | CELL_CLEAR (cell); |
378 | cell->stat_hp = 0; |
|
|
379 | cell->flags = 0; |
|
|
380 | cell->player = 0; |
|
|
381 | } |
444 | } |
382 | } |
445 | } |
383 | } |
446 | } |
384 | |
447 | |
385 | typedef struct { |
448 | struct smooth_key |
|
|
449 | { |
386 | tileid tile; |
450 | tileid tile; |
387 | uint8_t x, y, level; |
451 | uint8_t x, y, level; |
388 | } smooth_key; |
452 | |
|
|
453 | bool operator == (const smooth_key &o) const |
|
|
454 | { |
|
|
455 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
456 | } |
|
|
457 | }; |
|
|
458 | |
|
|
459 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
460 | |
|
|
461 | namespace std { |
|
|
462 | template <> |
|
|
463 | struct hash<smooth_key> |
|
|
464 | { |
|
|
465 | size_t operator () (const smooth_key &v) const |
|
|
466 | { |
|
|
467 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
468 | } |
|
|
469 | }; |
|
|
470 | } |
389 | |
471 | |
390 | static void |
472 | static void |
391 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
473 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
392 | { |
474 | { |
393 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
475 | auto &&it = h.find (key); |
394 | |
476 | |
395 | if (SvIOK (*sv)) |
477 | if (it == h.end ()) |
396 | SvIV_set (*sv, SvIVX (*sv) | bits); |
478 | h.insert (std::make_pair (key, bits)); |
397 | else |
479 | else |
398 | sv_setiv (*sv, bits); |
480 | it->second |= bits; |
399 | } |
481 | } |
400 | |
482 | |
401 | static void |
483 | static void |
402 | music_finished (void) |
484 | music_finished (void) |
403 | { |
485 | { |
… | |
… | |
420 | ev.code = 1; |
502 | ev.code = 1; |
421 | ev.data1 = (void *)(long)channel; |
503 | ev.data1 = (void *)(long)channel; |
422 | ev.data2 = 0; |
504 | ev.data2 = 0; |
423 | |
505 | |
424 | SDL_PushEvent ((SDL_Event *)&ev); |
506 | SDL_PushEvent ((SDL_Event *)&ev); |
|
|
507 | } |
|
|
508 | |
|
|
509 | // approximately divide by 255 |
|
|
510 | static unsigned int |
|
|
511 | div255 (unsigned int n) |
|
|
512 | { |
|
|
513 | return (n + (n >> 8)) >> 8; |
425 | } |
514 | } |
426 | |
515 | |
427 | static unsigned int |
516 | static unsigned int |
428 | minpot (unsigned int n) |
517 | minpot (unsigned int n) |
429 | { |
518 | { |
… | |
… | |
439 | n |= n >> 16; |
528 | n |= n >> 16; |
440 | |
529 | |
441 | return n + 1; |
530 | return n + 1; |
442 | } |
531 | } |
443 | |
532 | |
|
|
533 | static unsigned int |
|
|
534 | popcount (unsigned int n) |
|
|
535 | { |
|
|
536 | n -= (n >> 1) & 0x55555555U; |
|
|
537 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
538 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
539 | n *= 0x01010101U; |
|
|
540 | |
|
|
541 | return n >> 24; |
|
|
542 | } |
|
|
543 | |
444 | /* SDL should provide this, really. */ |
544 | /* SDL should provide this, really. */ |
445 | #define SDLK_MODIFIER_MIN 300 |
545 | #define SDLK_MODIFIER_MIN 300 |
446 | #define SDLK_MODIFIER_MAX 314 |
546 | #define SDLK_MODIFIER_MAX 314 |
447 | |
547 | |
448 | /******************************************************************************/ |
548 | /******************************************************************************/ |
… | |
… | |
486 | return 0; |
586 | return 0; |
487 | |
587 | |
488 | return 1; |
588 | return 1; |
489 | } |
589 | } |
490 | |
590 | |
491 | MODULE = CFPlus PACKAGE = CFPlus |
591 | /******************************************************************************/ |
|
|
592 | |
|
|
593 | /* process keyboard modifiers */ |
|
|
594 | static int |
|
|
595 | mod_munge (int mod) |
|
|
596 | { |
|
|
597 | mod &= MOD_MASK; |
|
|
598 | |
|
|
599 | if (mod & (KMOD_META | KMOD_ALT)) |
|
|
600 | mod |= KMOD_LRAM; |
|
|
601 | |
|
|
602 | return mod; |
|
|
603 | } |
|
|
604 | |
|
|
605 | static void |
|
|
606 | deliantra_main (SV *real_main) |
|
|
607 | { |
|
|
608 | dSP; |
|
|
609 | |
|
|
610 | PUSHMARK (SP); |
|
|
611 | call_sv (real_main, G_DISCARD | G_VOID); |
|
|
612 | } |
|
|
613 | |
|
|
614 | #ifdef __MACOSX__ |
|
|
615 | static SV *real_main; |
|
|
616 | |
|
|
617 | /* to due surprising braindamage on the side of SDL design, we |
|
|
618 | * do some mind-boggling hack here: SDL requires a custom main() |
|
|
619 | * on OS X, so... we provide one and call the original main(), which, |
|
|
620 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
|
|
621 | * and which calls our main (== SDL_main) back. |
|
|
622 | */ |
|
|
623 | extern C_LINKAGE int |
|
|
624 | main (int argc, char *argv[]) |
|
|
625 | { |
|
|
626 | deliantra_main (real_main); |
|
|
627 | } |
|
|
628 | |
|
|
629 | #undef main |
|
|
630 | |
|
|
631 | extern C_LINKAGE int main (int argc, char *argv[]); |
|
|
632 | |
|
|
633 | static void |
|
|
634 | SDL_main_hack (SV *real_main_) |
|
|
635 | { |
|
|
636 | real_main = real_main_; |
|
|
637 | |
|
|
638 | char *argv[] = { "deliantra client", 0 }; |
|
|
639 | (main) (1, argv); |
|
|
640 | } |
|
|
641 | #else |
|
|
642 | static void |
|
|
643 | SDL_main_hack (SV *real_main) |
|
|
644 | { |
|
|
645 | deliantra_main (real_main); |
|
|
646 | } |
|
|
647 | #endif |
|
|
648 | |
|
|
649 | MODULE = Deliantra::Client PACKAGE = DC |
492 | |
650 | |
493 | PROTOTYPES: ENABLE |
651 | PROTOTYPES: ENABLE |
494 | |
652 | |
495 | BOOT: |
653 | BOOT: |
496 | { |
654 | { |
497 | HV *stash = gv_stashpv ("CFPlus", 1); |
655 | HV *stash = gv_stashpv ("DC", 1); |
498 | static const struct { |
656 | static const struct { |
499 | const char *name; |
657 | const char *name; |
500 | IV iv; |
658 | IV iv; |
501 | } *civ, const_iv[] = { |
659 | } *civ, const_iv[] = { |
502 | # define const_iv(name) { # name, (IV)name } |
660 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
524 | |
682 | |
525 | const_iv (SDL_APPINPUTFOCUS), |
683 | const_iv (SDL_APPINPUTFOCUS), |
526 | const_iv (SDL_APPMOUSEFOCUS), |
684 | const_iv (SDL_APPMOUSEFOCUS), |
527 | const_iv (SDL_APPACTIVE), |
685 | const_iv (SDL_APPACTIVE), |
528 | |
686 | |
|
|
687 | |
|
|
688 | const_iv (SDLK_UNKNOWN), |
|
|
689 | const_iv (SDLK_FIRST), |
|
|
690 | const_iv (SDLK_BACKSPACE), |
|
|
691 | const_iv (SDLK_TAB), |
|
|
692 | const_iv (SDLK_CLEAR), |
|
|
693 | const_iv (SDLK_RETURN), |
|
|
694 | const_iv (SDLK_PAUSE), |
|
|
695 | const_iv (SDLK_ESCAPE), |
|
|
696 | const_iv (SDLK_SPACE), |
|
|
697 | const_iv (SDLK_EXCLAIM), |
|
|
698 | const_iv (SDLK_QUOTEDBL), |
|
|
699 | const_iv (SDLK_HASH), |
|
|
700 | const_iv (SDLK_DOLLAR), |
|
|
701 | const_iv (SDLK_AMPERSAND), |
|
|
702 | const_iv (SDLK_QUOTE), |
|
|
703 | const_iv (SDLK_LEFTPAREN), |
|
|
704 | const_iv (SDLK_RIGHTPAREN), |
|
|
705 | const_iv (SDLK_ASTERISK), |
|
|
706 | const_iv (SDLK_PLUS), |
|
|
707 | const_iv (SDLK_COMMA), |
|
|
708 | const_iv (SDLK_MINUS), |
|
|
709 | const_iv (SDLK_PERIOD), |
|
|
710 | const_iv (SDLK_SLASH), |
|
|
711 | const_iv (SDLK_0), |
|
|
712 | const_iv (SDLK_1), |
|
|
713 | const_iv (SDLK_2), |
|
|
714 | const_iv (SDLK_3), |
|
|
715 | const_iv (SDLK_4), |
|
|
716 | const_iv (SDLK_5), |
|
|
717 | const_iv (SDLK_6), |
|
|
718 | const_iv (SDLK_7), |
|
|
719 | const_iv (SDLK_8), |
|
|
720 | const_iv (SDLK_9), |
|
|
721 | const_iv (SDLK_COLON), |
|
|
722 | const_iv (SDLK_SEMICOLON), |
|
|
723 | const_iv (SDLK_LESS), |
|
|
724 | const_iv (SDLK_EQUALS), |
|
|
725 | const_iv (SDLK_GREATER), |
|
|
726 | const_iv (SDLK_QUESTION), |
|
|
727 | const_iv (SDLK_AT), |
|
|
728 | |
|
|
729 | const_iv (SDLK_LEFTBRACKET), |
|
|
730 | const_iv (SDLK_BACKSLASH), |
|
|
731 | const_iv (SDLK_RIGHTBRACKET), |
|
|
732 | const_iv (SDLK_CARET), |
|
|
733 | const_iv (SDLK_UNDERSCORE), |
|
|
734 | const_iv (SDLK_BACKQUOTE), |
|
|
735 | const_iv (SDLK_DELETE), |
|
|
736 | |
|
|
737 | const_iv (SDLK_FIRST), |
|
|
738 | const_iv (SDLK_LAST), |
529 | const_iv (SDLK_KP0), |
739 | const_iv (SDLK_KP0), |
530 | const_iv (SDLK_KP1), |
740 | const_iv (SDLK_KP1), |
531 | const_iv (SDLK_KP2), |
741 | const_iv (SDLK_KP2), |
532 | const_iv (SDLK_KP3), |
742 | const_iv (SDLK_KP3), |
533 | const_iv (SDLK_KP4), |
743 | const_iv (SDLK_KP4), |
… | |
… | |
605 | const_iv (KMOD_LMETA), |
815 | const_iv (KMOD_LMETA), |
606 | const_iv (KMOD_RMETA), |
816 | const_iv (KMOD_RMETA), |
607 | const_iv (KMOD_NUM), |
817 | const_iv (KMOD_NUM), |
608 | const_iv (KMOD_CAPS), |
818 | const_iv (KMOD_CAPS), |
609 | const_iv (KMOD_MODE), |
819 | const_iv (KMOD_MODE), |
|
|
820 | |
|
|
821 | const_iv (KMOD_LRAM), |
|
|
822 | |
|
|
823 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
824 | |
|
|
825 | const_iv (SDL_INIT_TIMER), |
|
|
826 | const_iv (SDL_INIT_AUDIO), |
|
|
827 | const_iv (SDL_INIT_VIDEO), |
|
|
828 | const_iv (SDL_INIT_CDROM), |
|
|
829 | const_iv (SDL_INIT_JOYSTICK), |
|
|
830 | const_iv (SDL_INIT_EVERYTHING), |
|
|
831 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
832 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
833 | |
|
|
834 | const_iv (SDL_GL_RED_SIZE), |
|
|
835 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
836 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
837 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
838 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
839 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
840 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
841 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
842 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
843 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
844 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
845 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
846 | const_iv (SDL_GL_STEREO), |
|
|
847 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
848 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
849 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
850 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
851 | |
|
|
852 | const_iv (FOW_DARKNESS) |
610 | # undef const_iv |
853 | # undef const_iv |
611 | }; |
854 | }; |
612 | |
855 | |
613 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
856 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
614 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
857 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
615 | |
858 | |
616 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
859 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
617 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
860 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
618 | } |
861 | } |
619 | |
862 | |
… | |
… | |
631 | RETVAL |
874 | RETVAL |
632 | |
875 | |
633 | NV floor (NV x) |
876 | NV floor (NV x) |
634 | |
877 | |
635 | NV ceil (NV x) |
878 | NV ceil (NV x) |
|
|
879 | |
|
|
880 | IV minpot (UV n) |
|
|
881 | |
|
|
882 | IV popcount (UV n) |
|
|
883 | |
|
|
884 | NV distance (NV dx, NV dy) |
|
|
885 | CODE: |
|
|
886 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
|
|
887 | OUTPUT: |
|
|
888 | RETVAL |
636 | |
889 | |
637 | void |
890 | void |
638 | pango_init () |
891 | pango_init () |
639 | CODE: |
892 | CODE: |
640 | { |
893 | { |
641 | opengl_fontmap = pango_opengl_font_map_new (); |
894 | opengl_fontmap = pango_opengl_font_map_new (); |
642 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
895 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
643 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
896 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
897 | /*pango_context_set_font_description (opengl_context, default_font);*/ |
|
|
898 | #if PANGO_VERSION_CHECK (1, 15, 2) |
|
|
899 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
900 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
901 | #endif |
644 | } |
902 | } |
645 | |
903 | |
646 | char * |
|
|
647 | SDL_GetError () |
904 | char *SDL_GetError () |
648 | |
905 | |
649 | int |
906 | void SDL_main_hack (SV *real_main) |
650 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
907 | PROTOTYPE: & |
651 | |
908 | |
652 | void |
909 | int SDL_Init (U32 flags) |
|
|
910 | |
|
|
911 | int SDL_InitSubSystem (U32 flags) |
|
|
912 | |
|
|
913 | void SDL_QuitSubSystem (U32 flags) |
|
|
914 | |
653 | SDL_Quit () |
915 | void SDL_Quit () |
|
|
916 | |
|
|
917 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
918 | C_ARGS: (SDL_GLattr)attr, value |
|
|
919 | |
|
|
920 | int SDL_GL_GetAttribute (int attr) |
|
|
921 | CODE: |
|
|
922 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
|
|
923 | XSRETURN_UNDEF; |
|
|
924 | OUTPUT: |
|
|
925 | RETVAL |
654 | |
926 | |
655 | void |
927 | void |
656 | SDL_ListModes (int rgb, int alpha) |
928 | SDL_ListModes (int rgb, int alpha) |
657 | PPCODE: |
929 | PPCODE: |
658 | { |
930 | { |
… | |
… | |
670 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
942 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
671 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
943 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
672 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
944 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
673 | |
945 | |
674 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
946 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
675 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
676 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
677 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
947 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
678 | #endif |
|
|
679 | |
948 | |
680 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
949 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
681 | |
950 | |
682 | if (m && m != (SDL_Rect **)-1) |
951 | if (m && m != (SDL_Rect **)-1) |
683 | while (*m) |
952 | while (*m) |
684 | { |
953 | { |
685 | if ((*m)->w >= 640 && (*m)->h >= 480) |
954 | if ((*m)->w >= 400 && (*m)->h >= 300) |
686 | { |
955 | { |
687 | AV *av = newAV (); |
956 | AV *av = newAV (); |
688 | av_push (av, newSViv ((*m)->w)); |
957 | av_push (av, newSViv ((*m)->w)); |
689 | av_push (av, newSViv ((*m)->h)); |
958 | av_push (av, newSViv ((*m)->h)); |
690 | av_push (av, newSViv (rgb)); |
959 | av_push (av, newSViv (rgb)); |
… | |
… | |
713 | ); |
982 | ); |
714 | |
983 | |
715 | if (RETVAL) |
984 | if (RETVAL) |
716 | { |
985 | { |
717 | av_clear (texture_av); |
986 | av_clear (texture_av); |
718 | |
|
|
719 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
|
|
720 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
987 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
721 | #include "glfunc.h" |
988 | #include "glfunc.h" |
722 | #undef GL_FUNC |
989 | #undef GL_FUNC |
|
|
990 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
|
|
991 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
723 | } |
992 | } |
724 | } |
993 | } |
725 | OUTPUT: |
994 | OUTPUT: |
726 | RETVAL |
995 | RETVAL |
|
|
996 | |
|
|
997 | void |
|
|
998 | SDL_WM_SetCaption (const char *title, const char *icon) |
727 | |
999 | |
728 | void |
1000 | void |
729 | SDL_GL_SwapBuffers () |
1001 | SDL_GL_SwapBuffers () |
730 | |
1002 | |
731 | char * |
1003 | char * |
732 | SDL_GetKeyName (int sym) |
1004 | SDL_GetKeyName (int sym) |
|
|
1005 | C_ARGS: (SDLKey)sym |
733 | |
1006 | |
734 | int |
1007 | int |
735 | SDL_GetAppState () |
1008 | SDL_GetAppState () |
736 | |
1009 | |
|
|
1010 | int |
|
|
1011 | SDL_GetModState () |
|
|
1012 | |
|
|
1013 | int |
|
|
1014 | SDL_WaitEvent () |
|
|
1015 | C_ARGS: 0 |
|
|
1016 | |
737 | void |
1017 | void |
|
|
1018 | SDL_PumpEvents () |
|
|
1019 | |
|
|
1020 | void |
738 | poll_events () |
1021 | peep_events () |
739 | PPCODE: |
1022 | PPCODE: |
740 | { |
1023 | { |
741 | SDL_Event ev; |
1024 | SDL_Event ev; |
742 | |
1025 | |
743 | SDL_PumpEvents (); |
1026 | SDL_PumpEvents (); |
… | |
… | |
750 | { |
1033 | { |
751 | case SDL_KEYDOWN: |
1034 | case SDL_KEYDOWN: |
752 | case SDL_KEYUP: |
1035 | case SDL_KEYUP: |
753 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
1036 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
754 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
1037 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
755 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
1038 | hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0); |
756 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
1039 | hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */ |
757 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
1040 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
758 | break; |
1041 | break; |
759 | |
1042 | |
760 | case SDL_ACTIVEEVENT: |
1043 | case SDL_ACTIVEEVENT: |
761 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
1044 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
779 | x = ev.motion.x; |
1062 | x = ev.motion.x; |
780 | y = ev.motion.y; |
1063 | y = ev.motion.y; |
781 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
1064 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
782 | } |
1065 | } |
783 | |
1066 | |
784 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1067 | hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); |
785 | hv_store (hv, "state", 5, newSViv (state), 0); |
1068 | hv_store (hv, "state", 5, newSViv (state), 0); |
786 | hv_store (hv, "x", 1, newSViv (x), 0); |
1069 | hv_store (hv, "x", 1, newSViv (x), 0); |
787 | hv_store (hv, "y", 1, newSViv (y), 0); |
1070 | hv_store (hv, "y", 1, newSViv (y), 0); |
788 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
1071 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
789 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
1072 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
790 | } |
1073 | } |
791 | break; |
1074 | break; |
792 | |
1075 | |
793 | case SDL_MOUSEBUTTONDOWN: |
1076 | case SDL_MOUSEBUTTONDOWN: |
794 | case SDL_MOUSEBUTTONUP: |
1077 | case SDL_MOUSEBUTTONUP: |
795 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1078 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
796 | |
1079 | |
797 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
1080 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
798 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
1081 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
799 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
1082 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
800 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
1083 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
805 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
1088 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
806 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
1089 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
807 | break; |
1090 | break; |
808 | } |
1091 | } |
809 | |
1092 | |
810 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
1093 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
811 | } |
1094 | } |
812 | } |
1095 | } |
813 | |
1096 | |
|
|
1097 | char * |
|
|
1098 | SDL_AudioDriverName () |
|
|
1099 | CODE: |
|
|
1100 | { |
|
|
1101 | char buf [256]; |
|
|
1102 | if (!SDL_AudioDriverName (buf, sizeof (buf))) |
|
|
1103 | XSRETURN_UNDEF; |
|
|
1104 | |
|
|
1105 | RETVAL = buf; |
|
|
1106 | } |
|
|
1107 | OUTPUT: |
|
|
1108 | RETVAL |
|
|
1109 | |
814 | int |
1110 | int |
815 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) |
1111 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
816 | POSTCALL: |
1112 | POSTCALL: |
817 | Mix_HookMusicFinished (music_finished); |
1113 | Mix_HookMusicFinished (music_finished); |
818 | Mix_ChannelFinished (channel_finished); |
1114 | Mix_ChannelFinished (channel_finished); |
|
|
1115 | |
|
|
1116 | void |
|
|
1117 | Mix_QuerySpec () |
|
|
1118 | PPCODE: |
|
|
1119 | { |
|
|
1120 | int freq, channels; |
|
|
1121 | Uint16 format; |
|
|
1122 | |
|
|
1123 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
1124 | { |
|
|
1125 | EXTEND (SP, 3); |
|
|
1126 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
1127 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
1128 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
1129 | } |
|
|
1130 | } |
819 | |
1131 | |
820 | void |
1132 | void |
821 | Mix_CloseAudio () |
1133 | Mix_CloseAudio () |
822 | |
1134 | |
823 | int |
1135 | int |
… | |
… | |
858 | } |
1170 | } |
859 | } |
1171 | } |
860 | #endif |
1172 | #endif |
861 | } |
1173 | } |
862 | |
1174 | |
863 | void |
1175 | int |
864 | add_font (char *file) |
1176 | add_font (char *file) |
865 | CODE: |
1177 | CODE: |
866 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1178 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
1179 | OUTPUT: |
|
|
1180 | RETVAL |
|
|
1181 | |
|
|
1182 | void |
|
|
1183 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
|
|
1184 | |
|
|
1185 | # MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s |
|
|
1186 | void |
|
|
1187 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) |
867 | |
1188 | |
868 | void |
1189 | void |
869 | load_image_inline (SV *image_) |
1190 | load_image_inline (SV *image_) |
870 | ALIAS: |
1191 | ALIAS: |
871 | load_image_file = 1 |
1192 | load_image_file = 1 |
… | |
… | |
917 | |
1238 | |
918 | SDL_LockSurface (surface2); |
1239 | SDL_LockSurface (surface2); |
919 | EXTEND (SP, 6); |
1240 | EXTEND (SP, 6); |
920 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1241 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
921 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1242 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
922 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1243 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
923 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1244 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
924 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1245 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
925 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1246 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
926 | SDL_UnlockSurface (surface2); |
1247 | SDL_UnlockSurface (surface2); |
927 | |
1248 | |
… | |
… | |
957 | void |
1278 | void |
958 | error (char *message) |
1279 | error (char *message) |
959 | CODE: |
1280 | CODE: |
960 | fprintf (stderr, "ERROR: %s\n", message); |
1281 | fprintf (stderr, "ERROR: %s\n", message); |
961 | #ifdef _WIN32 |
1282 | #ifdef _WIN32 |
962 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
1283 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
963 | #endif |
1284 | #endif |
964 | |
1285 | |
965 | void |
1286 | void |
966 | fatal (char *message) |
1287 | fatal (char *message) |
967 | CODE: |
1288 | CODE: |
968 | fprintf (stderr, "FATAL: %s\n", message); |
1289 | fprintf (stderr, "FATAL: %s\n", message); |
969 | #ifdef _WIN32 |
1290 | #ifdef _WIN32 |
970 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1291 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
971 | #endif |
1292 | #endif |
972 | _exit (1); |
1293 | _exit (1); |
973 | |
1294 | |
974 | void |
1295 | void |
975 | _exit (int retval = 0) |
1296 | _exit (int retval = 0) |
… | |
… | |
987 | #if DEBUG |
1308 | #if DEBUG |
988 | VALGRIND_DO_LEAK_CHECK; |
1309 | VALGRIND_DO_LEAK_CHECK; |
989 | #endif |
1310 | #endif |
990 | } |
1311 | } |
991 | |
1312 | |
992 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1313 | int |
|
|
1314 | SvREFCNT (SV *sv) |
|
|
1315 | CODE: |
|
|
1316 | RETVAL = SvREFCNT (sv); |
|
|
1317 | OUTPUT: |
|
|
1318 | RETVAL |
|
|
1319 | |
|
|
1320 | MODULE = Deliantra::Client PACKAGE = DC::Font |
993 | |
1321 | |
994 | PROTOTYPES: DISABLE |
1322 | PROTOTYPES: DISABLE |
995 | |
1323 | |
996 | CFPlus::Font |
1324 | DC::Font |
997 | new_from_file (SV *class, char *path, int id = 0) |
1325 | new_from_file (SV *klass, char *path, int id = 0) |
998 | CODE: |
1326 | CODE: |
999 | { |
1327 | { |
1000 | int count; |
1328 | int count; |
1001 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1329 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1002 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1330 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1004 | } |
1332 | } |
1005 | OUTPUT: |
1333 | OUTPUT: |
1006 | RETVAL |
1334 | RETVAL |
1007 | |
1335 | |
1008 | void |
1336 | void |
1009 | DESTROY (CFPlus::Font self) |
1337 | DESTROY (DC::Font self) |
1010 | CODE: |
1338 | CODE: |
1011 | pango_font_description_free (self); |
1339 | pango_font_description_free (self); |
1012 | |
1340 | |
1013 | void |
1341 | void |
1014 | make_default (CFPlus::Font self) |
1342 | make_default (DC::Font self) |
1015 | PROTOTYPE: $ |
1343 | PROTOTYPE: $ |
1016 | CODE: |
1344 | CODE: |
1017 | default_font = self; |
1345 | default_font = self; |
1018 | |
1346 | |
1019 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1347 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1020 | |
1348 | |
1021 | PROTOTYPES: DISABLE |
1349 | PROTOTYPES: DISABLE |
1022 | |
1350 | |
1023 | void |
1351 | void |
1024 | reset_glyph_cache () |
1352 | glyph_cache_backup () |
1025 | PROTOTYPE: |
1353 | PROTOTYPE: |
1026 | CODE: |
1354 | CODE: |
|
|
1355 | tc_backup (); |
|
|
1356 | |
|
|
1357 | void |
|
|
1358 | glyph_cache_restore () |
|
|
1359 | PROTOTYPE: |
|
|
1360 | CODE: |
1027 | tc_clear (); |
1361 | tc_restore (); |
1028 | |
1362 | |
1029 | CFPlus::Layout |
1363 | DC::Layout |
1030 | new (SV *class) |
1364 | new (SV *klass) |
1031 | CODE: |
1365 | CODE: |
1032 | New (0, RETVAL, 1, struct cf_layout); |
1366 | New (0, RETVAL, 1, struct cf_layout); |
1033 | |
1367 | |
1034 | RETVAL->pl = pango_layout_new (opengl_context); |
1368 | RETVAL->pl = pango_layout_new (opengl_context); |
1035 | RETVAL->r = 1.; |
1369 | RETVAL->r = 1.; |
1036 | RETVAL->g = 1.; |
1370 | RETVAL->g = 1.; |
1037 | RETVAL->b = 1.; |
1371 | RETVAL->b = 1.; |
1038 | RETVAL->a = 1.; |
1372 | RETVAL->a = 1.; |
1039 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1373 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1040 | RETVAL->font = 0; |
1374 | RETVAL->font = 0; |
|
|
1375 | RETVAL->rc = rc_alloc (); |
1041 | |
1376 | |
1042 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1377 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1043 | layout_update_font (RETVAL); |
1378 | layout_update_font (RETVAL); |
1044 | OUTPUT: |
1379 | OUTPUT: |
1045 | RETVAL |
1380 | RETVAL |
1046 | |
1381 | |
1047 | void |
1382 | void |
1048 | DESTROY (CFPlus::Layout self) |
1383 | DESTROY (DC::Layout self) |
1049 | CODE: |
1384 | CODE: |
1050 | g_object_unref (self->pl); |
1385 | g_object_unref (self->pl); |
|
|
1386 | rc_free (self->rc); |
1051 | Safefree (self); |
1387 | Safefree (self); |
1052 | |
1388 | |
1053 | void |
1389 | void |
1054 | set_text (CFPlus::Layout self, SV *text_) |
1390 | set_text (DC::Layout self, SV *text_) |
1055 | CODE: |
1391 | CODE: |
1056 | { |
1392 | { |
1057 | STRLEN textlen; |
1393 | STRLEN textlen; |
1058 | char *text = SvPVutf8 (text_, textlen); |
1394 | char *text = SvPVutf8 (text_, textlen); |
1059 | |
1395 | |
1060 | pango_layout_set_text (self->pl, text, textlen); |
1396 | pango_layout_set_text (self->pl, text, textlen); |
1061 | } |
1397 | } |
1062 | |
1398 | |
1063 | void |
1399 | void |
1064 | set_markup (CFPlus::Layout self, SV *text_) |
1400 | set_markup (DC::Layout self, SV *text_) |
1065 | CODE: |
1401 | CODE: |
1066 | { |
1402 | { |
1067 | STRLEN textlen; |
1403 | STRLEN textlen; |
1068 | char *text = SvPVutf8 (text_, textlen); |
1404 | char *text = SvPVutf8 (text_, textlen); |
1069 | |
1405 | |
1070 | pango_layout_set_markup (self->pl, text, textlen); |
1406 | pango_layout_set_markup (self->pl, text, textlen); |
1071 | } |
1407 | } |
1072 | |
1408 | |
1073 | void |
1409 | void |
1074 | set_shapes (CFPlus::Layout self, ...) |
1410 | set_shapes (DC::Layout self, ...) |
1075 | CODE: |
1411 | CODE: |
1076 | { |
1412 | { |
1077 | PangoAttrList *attrs = 0; |
1413 | PangoAttrList *attrs = 0; |
1078 | const char *text = pango_layout_get_text (self->pl); |
1414 | const char *text = pango_layout_get_text (self->pl); |
1079 | const char *pos = text; |
1415 | const char *pos = text; |
… | |
… | |
1114 | if (attrs) |
1450 | if (attrs) |
1115 | pango_layout_set_attributes (self->pl, attrs); |
1451 | pango_layout_set_attributes (self->pl, attrs); |
1116 | } |
1452 | } |
1117 | |
1453 | |
1118 | void |
1454 | void |
1119 | get_shapes (CFPlus::Layout self) |
1455 | get_shapes (DC::Layout self) |
1120 | PPCODE: |
1456 | PPCODE: |
1121 | { |
1457 | { |
1122 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1458 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1123 | |
1459 | |
1124 | do |
1460 | do |
1125 | { |
1461 | { |
1126 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1462 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1127 | |
1463 | |
1128 | if (run && shape_attr_p (run)) |
1464 | if (run && shape_attr_p (run)) |
1129 | { |
1465 | { |
1130 | PangoRectangle extents; |
1466 | PangoRectangle extents; |
1131 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1467 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1139 | |
1475 | |
1140 | pango_layout_iter_free (iter); |
1476 | pango_layout_iter_free (iter); |
1141 | } |
1477 | } |
1142 | |
1478 | |
1143 | int |
1479 | int |
1144 | has_wrapped (CFPlus::Layout self) |
1480 | has_wrapped (DC::Layout self) |
1145 | CODE: |
1481 | CODE: |
1146 | { |
1482 | { |
1147 | int lines = 1; |
1483 | int lines = 1; |
1148 | const char *text = pango_layout_get_text (self->pl); |
1484 | const char *text = pango_layout_get_text (self->pl); |
1149 | |
1485 | |
… | |
… | |
1154 | } |
1490 | } |
1155 | OUTPUT: |
1491 | OUTPUT: |
1156 | RETVAL |
1492 | RETVAL |
1157 | |
1493 | |
1158 | SV * |
1494 | SV * |
1159 | get_text (CFPlus::Layout self) |
1495 | get_text (DC::Layout self) |
1160 | CODE: |
1496 | CODE: |
1161 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1497 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1162 | sv_utf8_decode (RETVAL); |
1498 | sv_utf8_decode (RETVAL); |
1163 | OUTPUT: |
1499 | OUTPUT: |
1164 | RETVAL |
1500 | RETVAL |
1165 | |
1501 | |
1166 | void |
1502 | void |
1167 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1503 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1168 | CODE: |
1504 | CODE: |
1169 | self->r = r; |
1505 | self->r = r; |
1170 | self->g = g; |
1506 | self->g = g; |
1171 | self->b = b; |
1507 | self->b = b; |
1172 | self->a = a; |
1508 | self->a = a; |
1173 | |
1509 | |
1174 | void |
1510 | void |
1175 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1511 | set_font (DC::Layout self, DC::Font font = 0) |
1176 | CODE: |
1512 | CODE: |
1177 | if (self->font != font) |
1513 | if (self->font != font) |
1178 | { |
1514 | { |
1179 | self->font = font; |
1515 | self->font = font; |
1180 | layout_update_font (self); |
1516 | layout_update_font (self); |
1181 | } |
1517 | } |
1182 | |
1518 | |
1183 | void |
1519 | void |
1184 | set_height (CFPlus::Layout self, int base_height) |
1520 | set_height (DC::Layout self, int base_height) |
1185 | CODE: |
1521 | CODE: |
1186 | if (self->base_height != base_height) |
1522 | if (self->base_height != base_height) |
1187 | { |
1523 | { |
1188 | self->base_height = base_height; |
1524 | self->base_height = base_height; |
1189 | layout_update_font (self); |
1525 | layout_update_font (self); |
1190 | } |
1526 | } |
1191 | |
1527 | |
1192 | void |
1528 | void |
1193 | set_width (CFPlus::Layout self, int max_width = -1) |
1529 | set_width (DC::Layout self, int max_width = -1) |
1194 | CODE: |
1530 | CODE: |
1195 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1531 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1196 | |
1532 | |
1197 | void |
1533 | void |
1198 | set_indent (CFPlus::Layout self, int indent) |
1534 | set_indent (DC::Layout self, int indent) |
1199 | CODE: |
1535 | CODE: |
1200 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1536 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1201 | |
1537 | |
1202 | void |
1538 | void |
1203 | set_spacing (CFPlus::Layout self, int spacing) |
1539 | set_spacing (DC::Layout self, int spacing) |
1204 | CODE: |
1540 | CODE: |
1205 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1541 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1206 | |
1542 | |
1207 | void |
1543 | void |
1208 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1544 | set_ellipsise (DC::Layout self, int ellipsise) |
1209 | CODE: |
1545 | CODE: |
1210 | pango_layout_set_ellipsize (self->pl, |
1546 | pango_layout_set_ellipsize (self->pl, |
1211 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1547 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1212 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1548 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1213 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1549 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1214 | : PANGO_ELLIPSIZE_NONE |
1550 | : PANGO_ELLIPSIZE_NONE |
1215 | ); |
1551 | ); |
1216 | |
1552 | |
1217 | void |
1553 | void |
1218 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1554 | set_single_paragraph_mode (DC::Layout self, int spm) |
1219 | CODE: |
1555 | CODE: |
1220 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1556 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1221 | |
1557 | |
1222 | void |
1558 | void |
1223 | size (CFPlus::Layout self) |
1559 | size (DC::Layout self) |
1224 | PPCODE: |
1560 | PPCODE: |
1225 | { |
1561 | { |
1226 | int w, h; |
1562 | int w, h; |
1227 | |
1563 | |
1228 | layout_get_pixel_size (self, &w, &h); |
1564 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1231 | PUSHs (sv_2mortal (newSViv (w))); |
1567 | PUSHs (sv_2mortal (newSViv (w))); |
1232 | PUSHs (sv_2mortal (newSViv (h))); |
1568 | PUSHs (sv_2mortal (newSViv (h))); |
1233 | } |
1569 | } |
1234 | |
1570 | |
1235 | int |
1571 | int |
1236 | descent (CFPlus::Layout self) |
1572 | descent (DC::Layout self) |
1237 | CODE: |
1573 | CODE: |
1238 | { |
1574 | { |
1239 | PangoRectangle rect; |
1575 | PangoRectangle rect; |
1240 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1576 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1241 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1577 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1242 | RETVAL = PANGO_DESCENT (rect); |
1578 | RETVAL = PANGO_DESCENT (rect); |
1243 | } |
1579 | } |
1244 | OUTPUT: |
1580 | OUTPUT: |
1245 | RETVAL |
1581 | RETVAL |
1246 | |
1582 | |
1247 | int |
1583 | int |
1248 | xy_to_index (CFPlus::Layout self, int x, int y) |
1584 | xy_to_index (DC::Layout self, int x, int y) |
1249 | CODE: |
1585 | CODE: |
1250 | { |
1586 | { |
1251 | int index, trailing; |
1587 | int index, trailing; |
1252 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1588 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1253 | RETVAL = index + trailing; |
1589 | RETVAL = index + trailing; |
1254 | } |
1590 | } |
1255 | OUTPUT: |
1591 | OUTPUT: |
1256 | RETVAL |
1592 | RETVAL |
1257 | |
1593 | |
1258 | void |
1594 | void |
1259 | cursor_pos (CFPlus::Layout self, int index) |
1595 | cursor_pos (DC::Layout self, int index) |
1260 | PPCODE: |
1596 | PPCODE: |
1261 | { |
1597 | { |
1262 | PangoRectangle strong_pos; |
1598 | PangoRectangle pos; |
1263 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1599 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1264 | |
1600 | |
1265 | EXTEND (SP, 3); |
1601 | EXTEND (SP, 3); |
1266 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1602 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1267 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1603 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1268 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1604 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1269 | } |
1605 | } |
1270 | |
1606 | |
1271 | void |
1607 | void |
1272 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1608 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1273 | PPCODE: |
1609 | PPCODE: |
1274 | { |
1610 | { |
1275 | int line, x; |
1611 | int line, x; |
1276 | |
1612 | |
1277 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1613 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1614 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1278 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1615 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1279 | |
1616 | --line; |
|
|
1617 | #endif |
1280 | EXTEND (SP, 2); |
1618 | EXTEND (SP, 2); |
1281 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1619 | PUSHs (sv_2mortal (newSViv (line))); |
1282 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1620 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1283 | } |
1621 | } |
1284 | |
1622 | |
1285 | void |
1623 | void |
1286 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1624 | line_x_to_index (DC::Layout self, int line, int x) |
1287 | PPCODE: |
1625 | PPCODE: |
1288 | { |
1626 | { |
1289 | PangoLayoutLine *lp; |
1627 | PangoLayoutLine *lp; |
1290 | int index, trailing; |
1628 | int index, trailing; |
1291 | |
1629 | |
1292 | if (line < 0) |
1630 | if (line < 0) |
1293 | XSRETURN_EMPTY; |
1631 | XSRETURN_EMPTY; |
1294 | |
1632 | |
1295 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1633 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1296 | XSRETURN_EMPTY; /* do better */ |
1634 | XSRETURN_EMPTY; /* do better */ |
1297 | |
1635 | |
1298 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1636 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1299 | |
1637 | |
1300 | EXTEND (SP, 2); |
1638 | EXTEND (SP, 2); |
… | |
… | |
1306 | PUSHs (sv_2mortal (newSViv (trailing))); |
1644 | PUSHs (sv_2mortal (newSViv (trailing))); |
1307 | } |
1645 | } |
1308 | } |
1646 | } |
1309 | |
1647 | |
1310 | void |
1648 | void |
1311 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1649 | render (DC::Layout self, float x, float y, int flags = 0) |
1312 | PPCODE: |
1650 | CODE: |
|
|
1651 | rc_clear (self->rc); |
1313 | pango_opengl_render_layout_subpixel ( |
1652 | pango_opengl_render_layout_subpixel ( |
1314 | self->pl, |
1653 | self->pl, |
|
|
1654 | self->rc, |
1315 | x * PANGO_SCALE, y * PANGO_SCALE, |
1655 | x * PANGO_SCALE, y * PANGO_SCALE, |
1316 | self->r, self->g, self->b, self->a, |
1656 | self->r, self->g, self->b, self->a, |
1317 | flags |
1657 | flags |
1318 | ); |
1658 | ); |
|
|
1659 | // we assume that context_change actually clears/frees stuff |
|
|
1660 | // and does not do any recomputation... |
|
|
1661 | pango_layout_context_changed (self->pl); |
1319 | |
1662 | |
1320 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1663 | void |
|
|
1664 | draw (DC::Layout self) |
|
|
1665 | CODE: |
|
|
1666 | { |
|
|
1667 | glEnable (GL_TEXTURE_2D); |
|
|
1668 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1669 | glEnable (GL_BLEND); |
|
|
1670 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1671 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1672 | glEnable (GL_ALPHA_TEST); |
|
|
1673 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1674 | |
|
|
1675 | rc_draw (self->rc); |
|
|
1676 | |
|
|
1677 | glDisable (GL_ALPHA_TEST); |
|
|
1678 | glDisable (GL_BLEND); |
|
|
1679 | glDisable (GL_TEXTURE_2D); |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1321 | |
1683 | |
1322 | PROTOTYPES: ENABLE |
1684 | PROTOTYPES: ENABLE |
1323 | |
|
|
1324 | int minpot (int n) |
|
|
1325 | |
1685 | |
1326 | void |
1686 | void |
1327 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1687 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1328 | CODE: |
1688 | CODE: |
1329 | { |
1689 | { |
… | |
… | |
1395 | glDisable (GL_ALPHA_TEST); |
1755 | glDisable (GL_ALPHA_TEST); |
1396 | glDisable (GL_BLEND); |
1756 | glDisable (GL_BLEND); |
1397 | } |
1757 | } |
1398 | } |
1758 | } |
1399 | |
1759 | |
|
|
1760 | void |
|
|
1761 | draw_fow_texture (float intensity, int hidden_tex, int name1, uint8_t *data1, float s, float t, int w, int h, float blend = 0.f, int dx = 0, int dy = 0, int name2 = 0, uint8_t *data2 = data1) |
|
|
1762 | PROTOTYPE: @ |
|
|
1763 | CODE: |
|
|
1764 | { |
|
|
1765 | glEnable (GL_BLEND); |
|
|
1766 | glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1767 | glEnable (GL_TEXTURE_2D); |
|
|
1768 | glBindTexture (GL_TEXTURE_2D, name1); |
|
|
1769 | |
|
|
1770 | glColor3f (intensity, intensity, intensity); |
|
|
1771 | glPushMatrix (); |
|
|
1772 | glScalef (1./3, 1./3, 1.); |
|
|
1773 | |
|
|
1774 | if (blend > 0.f) |
|
|
1775 | { |
|
|
1776 | float dx3 = dx * -3.f / w; |
|
|
1777 | float dy3 = dy * -3.f / h; |
|
|
1778 | GLfloat env_color[4] = { 0., 0., 0., blend }; |
|
|
1779 | |
|
|
1780 | /* interpolate the two shadow textures */ |
|
|
1781 | /* stage 0 == rgb(glcolor) + alpha(t0) */ |
|
|
1782 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1783 | |
|
|
1784 | /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */ |
|
|
1785 | gl.ActiveTexture (GL_TEXTURE1); |
|
|
1786 | glEnable (GL_TEXTURE_2D); |
|
|
1787 | glBindTexture (GL_TEXTURE_2D, name2); |
|
|
1788 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); |
|
|
1789 | |
|
|
1790 | /* rgb == rgb(glcolor) */ |
|
|
1791 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); |
|
|
1792 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR); |
|
|
1793 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
|
|
1794 | |
|
|
1795 | /* alpha = interpolate t0, t1 by env_alpha */ |
|
|
1796 | glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color); |
|
|
1797 | |
|
|
1798 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); |
|
|
1799 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); |
|
|
1800 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); |
|
|
1801 | |
|
|
1802 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); |
|
|
1803 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); |
|
|
1804 | |
|
|
1805 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); |
|
|
1806 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); |
|
|
1807 | |
|
|
1808 | glBegin (GL_QUADS); |
|
|
1809 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0); |
|
|
1810 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h); |
|
|
1811 | gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h); |
|
|
1812 | gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0); |
|
|
1813 | glEnd (); |
|
|
1814 | |
|
|
1815 | glDisable (GL_TEXTURE_2D); |
|
|
1816 | gl.ActiveTexture (GL_TEXTURE0); |
|
|
1817 | } |
|
|
1818 | else |
|
|
1819 | { |
|
|
1820 | /* simple blending of one texture, also opengl <1.3 path */ |
|
|
1821 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1822 | |
|
|
1823 | glBegin (GL_QUADS); |
|
|
1824 | glTexCoord2f (0, 0); glVertex2f (0, 0); |
|
|
1825 | glTexCoord2f (0, t); glVertex2f (0, h); |
|
|
1826 | glTexCoord2f (s, t); glVertex2f (w, h); |
|
|
1827 | glTexCoord2f (s, 0); glVertex2f (w, 0); |
|
|
1828 | glEnd (); |
|
|
1829 | } |
|
|
1830 | |
|
|
1831 | /* draw ?-marks or equivalent, this is very clumsy code :/ */ |
|
|
1832 | { |
|
|
1833 | int x, y; |
|
|
1834 | int dx3 = dx * 3; |
|
|
1835 | int dy3 = dy * 3; |
|
|
1836 | |
|
|
1837 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1838 | glBindTexture (GL_TEXTURE_2D, hidden_tex); |
|
|
1839 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1840 | glTranslatef (-1., -1., 0); |
|
|
1841 | glBegin (GL_QUADS); |
|
|
1842 | |
|
|
1843 | for (y = 1; y < h; y += 3) |
|
|
1844 | { |
|
|
1845 | int y1 = y - dy3; |
|
|
1846 | int y1valid = y1 >= 0 && y1 < h; |
|
|
1847 | |
|
|
1848 | for (x = 1; x < w; x += 3) |
|
|
1849 | { |
|
|
1850 | int x1 = x - dx3; |
|
|
1851 | uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1852 | uint8_t h2; |
|
|
1853 | |
|
|
1854 | if (y1valid && x1 >= 0 && x1 < w) |
|
|
1855 | h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1856 | else |
|
|
1857 | h2 = 1; /* out of range == invisible */ |
|
|
1858 | |
|
|
1859 | if (h1 || h2) |
|
|
1860 | { |
|
|
1861 | float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend; |
|
|
1862 | glColor4f (1., 1., 1., alpha); |
|
|
1863 | |
|
|
1864 | glTexCoord2f (0, 0.); glVertex2i (x , y ); |
|
|
1865 | glTexCoord2f (0, 1.); glVertex2i (x , y + 3); |
|
|
1866 | glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3); |
|
|
1867 | glTexCoord2f (1, 0.); glVertex2i (x + 3, y ); |
|
|
1868 | } |
|
|
1869 | } |
|
|
1870 | } |
|
|
1871 | } |
|
|
1872 | |
|
|
1873 | glEnd (); |
|
|
1874 | |
|
|
1875 | glPopMatrix (); |
|
|
1876 | |
|
|
1877 | glDisable (GL_TEXTURE_2D); |
|
|
1878 | glDisable (GL_BLEND); |
|
|
1879 | } |
|
|
1880 | |
1400 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1881 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1401 | CODE: |
1882 | CODE: |
1402 | { |
1883 | { |
1403 | GLint width; |
1884 | GLint width; |
1404 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
1885 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
… | |
… | |
1406 | RETVAL = width > 0; |
1887 | RETVAL = width > 0; |
1407 | } |
1888 | } |
1408 | OUTPUT: |
1889 | OUTPUT: |
1409 | RETVAL |
1890 | RETVAL |
1410 | |
1891 | |
1411 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1892 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1412 | |
1893 | |
1413 | PROTOTYPES: DISABLE |
1894 | PROTOTYPES: DISABLE |
1414 | |
1895 | |
1415 | CFPlus::Map |
1896 | DC::Map |
1416 | new (SV *class) |
1897 | new (SV *klass) |
1417 | CODE: |
1898 | CODE: |
1418 | New (0, RETVAL, 1, struct map); |
1899 | New (0, RETVAL, 1, struct map); |
1419 | RETVAL->x = 0; |
1900 | RETVAL->x = 0; |
1420 | RETVAL->y = 0; |
1901 | RETVAL->y = 0; |
1421 | RETVAL->w = 0; |
1902 | RETVAL->w = 0; |
… | |
… | |
1428 | RETVAL->row = 0; |
1909 | RETVAL->row = 0; |
1429 | OUTPUT: |
1910 | OUTPUT: |
1430 | RETVAL |
1911 | RETVAL |
1431 | |
1912 | |
1432 | void |
1913 | void |
1433 | DESTROY (CFPlus::Map self) |
1914 | DESTROY (DC::Map self) |
1434 | CODE: |
1915 | CODE: |
1435 | { |
1916 | { |
1436 | map_clear (self); |
1917 | map_clear (self); |
1437 | Safefree (self->face2tile); |
1918 | Safefree (self->face2tile); |
1438 | Safefree (self->tex); |
1919 | Safefree (self->tex); |
1439 | Safefree (self); |
1920 | Safefree (self); |
1440 | } |
1921 | } |
1441 | |
1922 | |
1442 | void |
1923 | void |
1443 | resize (CFPlus::Map self, int map_width, int map_height) |
1924 | resize (DC::Map self, int map_width, int map_height) |
1444 | CODE: |
1925 | CODE: |
1445 | self->w = map_width; |
1926 | self->w = map_width; |
1446 | self->h = map_height; |
1927 | self->h = map_height; |
1447 | |
1928 | |
1448 | void |
1929 | void |
1449 | clear (CFPlus::Map self) |
1930 | clear (DC::Map self) |
1450 | CODE: |
1931 | CODE: |
1451 | map_clear (self); |
1932 | map_clear (self); |
1452 | |
1933 | |
1453 | void |
1934 | void |
1454 | set_tileid (CFPlus::Map self, int face, int tile) |
1935 | set_tileid (DC::Map self, int face, int tile) |
1455 | CODE: |
1936 | CODE: |
1456 | { |
1937 | { |
1457 | need_facenum (self, face); self->face2tile [face] = tile; |
1938 | need_facenum (self, face); self->face2tile [face] = tile; |
1458 | need_texid (self, tile); |
1939 | need_texid (self, tile); |
1459 | } |
1940 | } |
1460 | |
1941 | |
1461 | void |
1942 | void |
1462 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1943 | set_smooth (DC::Map self, int face, int smooth, int level) |
1463 | CODE: |
1944 | CODE: |
1464 | { |
1945 | { |
1465 | tileid texid; |
1946 | tileid texid; |
1466 | maptex *tex; |
1947 | maptex *tex; |
1467 | |
1948 | |
1468 | if (face < 0 || face >= self->faces) |
1949 | if (face < 0 || face >= self->faces) |
1469 | return; |
1950 | return; |
1470 | |
1951 | |
1471 | if (smooth < 0 || smooth >= self->faces) |
1952 | if (smooth < 0 || smooth >= self->faces) |
1472 | return; |
1953 | return; |
1473 | |
1954 | |
1474 | texid = self->face2tile [face]; |
1955 | texid = self->face2tile [face]; |
1475 | |
1956 | |
1476 | if (!texid) |
1957 | if (!texid) |
1477 | return; |
1958 | return; |
1478 | |
1959 | |
1479 | tex = self->tex + texid; |
1960 | tex = self->tex + texid; |
1480 | tex->smoothtile = self->face2tile [smooth]; |
1961 | tex->smoothtile = self->face2tile [smooth]; |
1481 | tex->smoothlevel = level; |
1962 | tex->smoothlevel = level; |
1482 | } |
1963 | } |
1483 | |
1964 | |
1484 | void |
1965 | void |
1485 | 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) |
1966 | set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1486 | CODE: |
1967 | CODE: |
1487 | { |
1968 | { |
1488 | need_texid (self, texid); |
1969 | need_texid (self, texid); |
1489 | |
1970 | |
1490 | { |
1971 | { |
… | |
… | |
1509 | // use uglier nearest interpolation because linear suffers |
1990 | // use uglier nearest interpolation because linear suffers |
1510 | // from transparent color bleeding and ugly wrapping effects. |
1991 | // from transparent color bleeding and ugly wrapping effects. |
1511 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1992 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1512 | } |
1993 | } |
1513 | |
1994 | |
|
|
1995 | void |
|
|
1996 | expire_textures (DC::Map self, int texid, int count) |
|
|
1997 | PPCODE: |
|
|
1998 | for (; texid < self->texs && count; ++texid, --count) |
|
|
1999 | { |
|
|
2000 | maptex *tex = self->tex + texid; |
|
|
2001 | |
|
|
2002 | if (tex->name) |
|
|
2003 | { |
|
|
2004 | if (tex->unused) |
|
|
2005 | { |
|
|
2006 | tex->name = 0; |
|
|
2007 | tex->unused = 0; |
|
|
2008 | XPUSHs (sv_2mortal (newSViv (texid))); |
|
|
2009 | } |
|
|
2010 | else |
|
|
2011 | tex->unused = 1; |
|
|
2012 | } |
|
|
2013 | } |
|
|
2014 | |
1514 | int |
2015 | int |
1515 | ox (CFPlus::Map self) |
2016 | ox (DC::Map self) |
1516 | ALIAS: |
2017 | ALIAS: |
1517 | oy = 1 |
2018 | oy = 1 |
1518 | x = 2 |
2019 | x = 2 |
1519 | y = 3 |
2020 | y = 3 |
1520 | w = 4 |
2021 | w = 4 |
… | |
… | |
1531 | } |
2032 | } |
1532 | OUTPUT: |
2033 | OUTPUT: |
1533 | RETVAL |
2034 | RETVAL |
1534 | |
2035 | |
1535 | void |
2036 | void |
1536 | scroll (CFPlus::Map self, int dx, int dy) |
2037 | scroll (DC::Map self, int dx, int dy) |
1537 | CODE: |
2038 | CODE: |
1538 | { |
2039 | { |
1539 | if (dx > 0) |
2040 | if (dx > 0) |
1540 | map_blank (self, self->x, self->y, dx, self->h); |
2041 | map_blank (self, self->x, self->y, dx, self->h); |
1541 | else if (dx < 0) |
2042 | else if (dx < 0) |
… | |
… | |
1557 | self->y += MAP_EXTEND_Y; |
2058 | self->y += MAP_EXTEND_Y; |
1558 | } |
2059 | } |
1559 | } |
2060 | } |
1560 | |
2061 | |
1561 | SV * |
2062 | SV * |
1562 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
2063 | map1a_update (DC::Map self, SV *data_) |
1563 | CODE: |
2064 | CODE: |
1564 | { |
2065 | { |
1565 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2066 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1566 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2067 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1567 | mapcell *cell; |
2068 | mapcell *cell; |
… | |
… | |
1588 | |
2089 | |
1589 | //TODO: don't trust server data to be in-range(!) |
2090 | //TODO: don't trust server data to be in-range(!) |
1590 | |
2091 | |
1591 | if (flags & 8) |
2092 | if (flags & 8) |
1592 | { |
2093 | { |
|
|
2094 | uint8_t ext, cmd; |
|
|
2095 | |
1593 | if (extmap) |
2096 | do |
1594 | { |
2097 | { |
1595 | uint8_t ext, cmd; |
2098 | ext = *data++; |
|
|
2099 | cmd = ext & 0x7f; |
1596 | |
2100 | |
1597 | do |
2101 | if (cmd < 4) |
|
|
2102 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2103 | else if (cmd == 5) // health |
1598 | { |
2104 | { |
1599 | ext = *data++; |
|
|
1600 | cmd = ext & 0x3f; |
|
|
1601 | |
|
|
1602 | if (cmd < 4) |
|
|
1603 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1604 | else if (cmd == 5) // health |
|
|
1605 | { |
|
|
1606 | cell->stat_width = 1; |
2105 | cell->stat_width = 1; |
1607 | cell->stat_hp = *data++; |
2106 | cell->stat_hp = *data++; |
1608 | } |
|
|
1609 | else if (cmd == 6) // monster width |
|
|
1610 | cell->stat_width = *data++ + 1; |
|
|
1611 | else if (cmd == 0x47) |
|
|
1612 | { |
|
|
1613 | if (*data == 4) |
|
|
1614 | ; // decode player count |
|
|
1615 | |
|
|
1616 | data += *data + 1; |
|
|
1617 | } |
|
|
1618 | else if (cmd == 8) // cell flags |
|
|
1619 | cell->flags = *data++; |
|
|
1620 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1621 | data += *data + 1; |
|
|
1622 | else |
|
|
1623 | data++; |
|
|
1624 | } |
2107 | } |
1625 | while (ext & 0x80); |
2108 | else if (cmd == 6) // monster width |
|
|
2109 | cell->stat_width = *data++ + 1; |
|
|
2110 | else if (cmd == 0x47) |
|
|
2111 | { |
|
|
2112 | if (*data == 1) cell->player = data [1]; |
|
|
2113 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2114 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2115 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2116 | |
|
|
2117 | data += *data + 1; |
|
|
2118 | } |
|
|
2119 | else if (cmd == 8) // cell flags |
|
|
2120 | cell->flags = *data++; |
|
|
2121 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2122 | data += *data + 1; |
|
|
2123 | else |
|
|
2124 | data++; |
1626 | } |
2125 | } |
1627 | else |
2126 | while (ext & 0x80); |
1628 | cell->darkness = *data++ + 1; |
|
|
1629 | } |
2127 | } |
1630 | |
2128 | |
1631 | for (z = 0; z <= 2; ++z) |
2129 | for (z = 0; z <= 2; ++z) |
1632 | if (flags & (4 >> z)) |
2130 | if (flags & (4 >> z)) |
1633 | { |
2131 | { |
… | |
… | |
1636 | cell->tile [z] = self->face2tile [face]; |
2134 | cell->tile [z] = self->face2tile [face]; |
1637 | |
2135 | |
1638 | if (cell->tile [z]) |
2136 | if (cell->tile [z]) |
1639 | { |
2137 | { |
1640 | maptex *tex = self->tex + cell->tile [z]; |
2138 | maptex *tex = self->tex + cell->tile [z]; |
|
|
2139 | tex->unused = 0; |
1641 | if (!tex->name) |
2140 | if (!tex->name) |
1642 | av_push (missing, newSViv (cell->tile [z])); |
2141 | av_push (missing, newSViv (cell->tile [z])); |
1643 | |
2142 | |
1644 | if (tex->smoothtile) |
2143 | if (tex->smoothtile) |
1645 | { |
2144 | { |
1646 | maptex *smooth = self->tex + tex->smoothtile; |
2145 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
2146 | smooth->unused = 0; |
1647 | if (!smooth->name) |
2147 | if (!smooth->name) |
1648 | av_push (missing, newSViv (tex->smoothtile)); |
2148 | av_push (missing, newSViv (tex->smoothtile)); |
1649 | } |
2149 | } |
1650 | } |
2150 | } |
1651 | } |
2151 | } |
1652 | } |
2152 | } |
1653 | else |
2153 | else |
1654 | cell->darkness = 0; |
2154 | CELL_CLEAR (cell); |
1655 | } |
2155 | } |
1656 | } |
2156 | } |
1657 | OUTPUT: |
2157 | OUTPUT: |
1658 | RETVAL |
2158 | RETVAL |
1659 | |
2159 | |
1660 | SV * |
2160 | SV * |
1661 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
2161 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1662 | CODE: |
2162 | CODE: |
1663 | { |
2163 | { |
1664 | int x1, x; |
2164 | int x1, x; |
1665 | int y1, y; |
2165 | int y1, y; |
1666 | int z; |
2166 | int z; |
… | |
… | |
1679 | ? self->row + y |
2179 | ? self->row + y |
1680 | : 0; |
2180 | : 0; |
1681 | |
2181 | |
1682 | for (x = x0; x < x1; x++) |
2182 | for (x = x0; x < x1; x++) |
1683 | { |
2183 | { |
1684 | int r = 32, g = 32, b = 32, a = 192; |
2184 | unsigned int r = 32, g = 32, b = 32, a = 192; |
1685 | |
2185 | |
1686 | if (row && row->c0 <= x && x < row->c1) |
2186 | if (row && row->c0 <= x && x < row->c1) |
1687 | { |
2187 | { |
1688 | mapcell *cell = row->col + (x - row->c0); |
2188 | mapcell *cell = row->col + (x - row->c0); |
1689 | |
2189 | |
… | |
… | |
1691 | { |
2191 | { |
1692 | maptex tex = self->tex [cell->tile [z]]; |
2192 | maptex tex = self->tex [cell->tile [z]]; |
1693 | int a0 = 255 - tex.a; |
2193 | int a0 = 255 - tex.a; |
1694 | int a1 = tex.a; |
2194 | int a1 = tex.a; |
1695 | |
2195 | |
1696 | r = (r * a0 + tex.r * a1) / 255; |
2196 | r = div255 (r * a0 + tex.r * a1); |
1697 | g = (g * a0 + tex.g * a1) / 255; |
2197 | g = div255 (g * a0 + tex.g * a1); |
1698 | b = (b * a0 + tex.b * a1) / 255; |
2198 | b = div255 (b * a0 + tex.b * a1); |
1699 | a = (a * a0 + tex.a * a1) / 255; |
2199 | a = div255 (a * a0 + tex.a * a1); |
1700 | } |
2200 | } |
1701 | } |
2201 | } |
1702 | |
2202 | |
1703 | *map++ = (r ) |
2203 | *map++ = (r ) |
1704 | | (g << 8) |
2204 | | (g << 8) |
1705 | | (b << 16) |
2205 | | (b << 16) |
1706 | | (a << 24); |
2206 | | (a << 24); |
1707 | } |
2207 | } |
1708 | } |
2208 | } |
1709 | |
2209 | |
1710 | RETVAL = map_sv; |
2210 | RETVAL = map_sv; |
1711 | } |
2211 | } |
1712 | OUTPUT: |
2212 | OUTPUT: |
1713 | RETVAL |
2213 | RETVAL |
1714 | |
2214 | |
1715 | void |
2215 | void |
1716 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
2216 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
1717 | CODE: |
2217 | CODE: |
1718 | { |
2218 | { |
1719 | int x, y, z; |
2219 | int x, y, z; |
1720 | |
2220 | |
1721 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
1722 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2221 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1723 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
2222 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1724 | smooth_key skey; |
2223 | smooth_key skey; |
1725 | |
2224 | int pl_x, pl_y; |
|
|
2225 | maptex pl_tex; |
1726 | rc_t *rc = rc_alloc (); |
2226 | rc_t *rc = rc_alloc (); |
|
|
2227 | rc_t *rc_ov = rc_alloc (); |
1727 | rc_key_t key; |
2228 | rc_key_t key; |
1728 | rc_array_t *arr; |
2229 | rc_array_t *arr; |
1729 | |
2230 | |
|
|
2231 | pl_tex.name = 0; |
|
|
2232 | |
1730 | // thats current max. sorry. |
2233 | // that's current max. sorry. |
1731 | if (sw > 255) sw = 255; |
2234 | if (sw > 255) sw = 255; |
1732 | if (sh > 255) sh = 255; |
2235 | if (sh > 255) sh = 255; |
1733 | |
2236 | |
1734 | // clear key, in case of extra padding |
2237 | // clear key, in case of extra padding |
1735 | memset (&skey, 0, sizeof (skey)); |
2238 | memset (&skey, 0, sizeof (skey)); |
… | |
… | |
1739 | key.g = 255; |
2242 | key.g = 255; |
1740 | key.b = 255; |
2243 | key.b = 255; |
1741 | key.a = 255; |
2244 | key.a = 255; |
1742 | key.mode = GL_QUADS; |
2245 | key.mode = GL_QUADS; |
1743 | key.format = GL_T2F_V3F; |
2246 | key.format = GL_T2F_V3F; |
1744 | key.texname = -1; |
|
|
1745 | |
2247 | |
1746 | mx += self->x; |
2248 | mx += self->x; |
1747 | my += self->y; |
2249 | my += self->y; |
1748 | |
2250 | |
1749 | // first pass: determine smooth_max |
2251 | // first pass: determine smooth_max |
… | |
… | |
1772 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2274 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1773 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2275 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1774 | |
2276 | |
1775 | for (z = 0; z <= 2; z++) |
2277 | for (z = 0; z <= 2; z++) |
1776 | { |
2278 | { |
|
|
2279 | smooth_hash smooth; |
1777 | memset (smooth_level, 0, sizeof (smooth_level)); |
2280 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
2281 | key.texname = -1; |
1778 | |
2282 | |
1779 | for (y = 0; y < sh; y++) |
2283 | for (y = 0; y < sh; y++) |
1780 | if (0 <= y + my && y + my < self->rows) |
2284 | if (0 <= y + my && y + my < self->rows) |
1781 | { |
2285 | { |
1782 | maprow *row = self->row + (y + my); |
2286 | maprow *row = self->row + (y + my); |
… | |
… | |
1790 | if (tile) |
2294 | if (tile) |
1791 | { |
2295 | { |
1792 | maptex tex = self->tex [tile]; |
2296 | maptex tex = self->tex [tile]; |
1793 | int px, py; |
2297 | int px, py; |
1794 | |
2298 | |
1795 | // suppressing texture state switches here |
|
|
1796 | // is only moderately effective, but worth the extra effort |
|
|
1797 | if (key.texname != tex.name) |
2299 | if (key.texname != tex.name) |
1798 | { |
2300 | { |
|
|
2301 | self->tex [tile].unused = 0; |
|
|
2302 | |
1799 | if (!tex.name) |
2303 | if (!tex.name) |
1800 | tex = self->tex [2]; /* missing, replace by noface */ |
2304 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
1801 | |
2305 | |
1802 | key.texname = tex.name; |
2306 | key.texname = tex.name; |
1803 | arr = rc_array (rc, &key); |
2307 | arr = rc_array (rc, &key); |
1804 | } |
2308 | } |
1805 | |
2309 | |
1806 | px = (x + 1) * T - tex.w; |
2310 | px = (x + 1) * Th - tex.w; |
1807 | py = (y + 1) * T - tex.h; |
2311 | py = (y + 1) * Tw - tex.h; |
|
|
2312 | |
|
|
2313 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
|
|
2314 | { |
|
|
2315 | pl_x = px; |
|
|
2316 | pl_y = py; |
|
|
2317 | pl_tex = tex; |
|
|
2318 | continue; |
|
|
2319 | } |
1808 | |
2320 | |
1809 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2321 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
1810 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2322 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
1811 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2323 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
1812 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2324 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1813 | |
|
|
1814 | if (cell->flags && z == 2) |
|
|
1815 | { |
|
|
1816 | // overlays such as the speech bubble, probably more to come |
|
|
1817 | if (cell->flags & 1) |
|
|
1818 | { |
|
|
1819 | maptex tex = self->tex [1]; |
|
|
1820 | int px = x * T + T * 2 / 32; |
|
|
1821 | int py = y * T - T * 6 / 32; |
|
|
1822 | |
|
|
1823 | if (tex.name) |
|
|
1824 | { |
|
|
1825 | if (key.texname != tex.name) |
|
|
1826 | { |
|
|
1827 | key.texname = tex.name; |
|
|
1828 | arr = rc_array (rc, &key); |
|
|
1829 | } |
|
|
1830 | |
|
|
1831 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1832 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1833 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1834 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
|
|
1835 | } |
|
|
1836 | } |
|
|
1837 | } |
|
|
1838 | |
2325 | |
1839 | // update smooth hash |
2326 | // update smooth hash |
1840 | if (tex.smoothtile) |
2327 | if (tex.smoothtile) |
1841 | { |
2328 | { |
1842 | skey.tile = tex.smoothtile; |
2329 | skey.tile = tex.smoothtile; |
… | |
… | |
1858 | |
2345 | |
1859 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2346 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
1860 | // ·· ·· ·┏ ┓· |
2347 | // ·· ·· ·┏ ┓· |
1861 | |
2348 | |
1862 | // full tile |
2349 | // full tile |
1863 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2350 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
1864 | |
2351 | |
1865 | // borders |
2352 | // borders |
1866 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2353 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
1867 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2354 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
1868 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2355 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
1869 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2356 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
1870 | |
2357 | |
1871 | // corners |
2358 | // corners |
1872 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2359 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
1873 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2360 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
1874 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2361 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
1875 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2362 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
|
|
2363 | } |
|
|
2364 | } |
|
|
2365 | |
|
|
2366 | if (expect_false (z == 2) && expect_false (cell->flags)) |
|
|
2367 | { |
|
|
2368 | // overlays such as the speech bubble, probably more to come |
|
|
2369 | if (cell->flags & 1) |
|
|
2370 | { |
|
|
2371 | rc_key_t key_ov = key; |
|
|
2372 | maptex tex = self->tex [TEXID_SPEECH]; |
|
|
2373 | rc_array_t *arr; |
|
|
2374 | int px = x * Tw + Tw * 2 / 32; |
|
|
2375 | int py = y * Th - Th * 6 / 32; |
|
|
2376 | |
|
|
2377 | key_ov.texname = tex.name; |
|
|
2378 | arr = rc_array (rc_ov, &key_ov); |
|
|
2379 | |
|
|
2380 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2381 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
|
|
2382 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
|
|
2383 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
1876 | } |
2384 | } |
1877 | } |
2385 | } |
1878 | } |
2386 | } |
1879 | } |
2387 | } |
1880 | |
2388 | |
… | |
… | |
1884 | // go through all smoothlevels, lowest to highest, then draw. |
2392 | // go through all smoothlevels, lowest to highest, then draw. |
1885 | // this is basically counting sort |
2393 | // this is basically counting sort |
1886 | { |
2394 | { |
1887 | int w, b; |
2395 | int w, b; |
1888 | |
2396 | |
|
|
2397 | glEnable (GL_TEXTURE_2D); |
|
|
2398 | glBegin (GL_QUADS); |
1889 | for (w = 0; w < 256 / 32; ++w) |
2399 | for (w = 0; w < 256 / 32; ++w) |
1890 | { |
2400 | { |
1891 | uint32_t smask = smooth_level [w]; |
2401 | uint32_t smask = smooth_level [w]; |
1892 | if (smask) |
2402 | if (smask) |
1893 | for (b = 0; b < 32; ++b) |
2403 | for (b = 0; b < 32; ++b) |
1894 | if (smask & (((uint32_t)1) << b)) |
2404 | if (smask & (((uint32_t)1) << b)) |
1895 | { |
2405 | { |
1896 | int level = (w << 5) | b; |
2406 | int level = (w << 5) | b; |
1897 | HE *he; |
2407 | HE *he; |
1898 | |
2408 | |
1899 | hv_iterinit (smooth); |
2409 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
1900 | while ((he = hv_iternext (smooth))) |
|
|
1901 | { |
2410 | { |
1902 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2411 | smooth_key &skey = it->first; |
1903 | IV bits = SvIVX (HeVAL (he)); |
2412 | IV bits = it->second; |
1904 | |
2413 | |
1905 | if (!(bits & 0x1000) |
2414 | if (!(bits & 0x1000) |
1906 | && skey->level == level |
2415 | && skey.level == level |
1907 | && level > smooth_max [skey->x][skey->y]) |
2416 | && level > smooth_max [skey.x][skey.y]) |
1908 | { |
2417 | { |
1909 | maptex tex = self->tex [skey->tile]; |
2418 | maptex tex = self->tex [skey.tile]; |
1910 | int px = (((int)skey->x) - 1) * T; |
2419 | int px = (((int)skey.x) - 1) * Tw; |
1911 | int py = (((int)skey->y) - 1) * T; |
2420 | int py = (((int)skey.y) - 1) * Th; |
1912 | int border = bits & 15; |
2421 | int border = bits & 15; |
1913 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2422 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1914 | float dx = tex.s * .0625f; // 16 images/row |
2423 | float dx = tex.s * .0625f; // 16 images/row |
1915 | float dy = tex.t * .5f ; // 2 images/column |
2424 | float dy = tex.t * .5f ; // 2 images/column |
1916 | |
2425 | |
… | |
… | |
1918 | { |
2427 | { |
1919 | // this time avoiding texture state changes |
2428 | // this time avoiding texture state changes |
1920 | // save gobs of state changes. |
2429 | // save gobs of state changes. |
1921 | if (key.texname != tex.name) |
2430 | if (key.texname != tex.name) |
1922 | { |
2431 | { |
|
|
2432 | self->tex [skey.tile].unused = 0; |
|
|
2433 | |
|
|
2434 | glEnd (); |
1923 | key.texname = tex.name; |
2435 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1924 | arr = rc_array (rc, &key); |
2436 | glBegin (GL_QUADS); |
1925 | } |
2437 | } |
1926 | |
2438 | |
1927 | if (border) |
2439 | if (border) |
1928 | { |
2440 | { |
1929 | float ox = border * dx; |
2441 | float ox = border * dx; |
1930 | |
2442 | |
1931 | rc_t2f_v3f (arr, ox , 0.f , px , py , 0); |
2443 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1932 | rc_t2f_v3f (arr, ox , dy , px , py + T, 0); |
2444 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
1933 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); |
2445 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
1934 | rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); |
2446 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
1935 | } |
2447 | } |
1936 | |
2448 | |
1937 | if (corner) |
2449 | if (corner) |
1938 | { |
2450 | { |
1939 | float ox = corner * dx; |
2451 | float ox = corner * dx; |
1940 | |
2452 | |
1941 | rc_t2f_v3f (arr, ox , dy , px , py , 0); |
2453 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1942 | rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); |
2454 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
1943 | rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); |
2455 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
1944 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); |
2456 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
1945 | } |
2457 | } |
1946 | } |
2458 | } |
1947 | } |
2459 | } |
1948 | } |
2460 | } |
1949 | } |
2461 | } |
1950 | } |
2462 | } |
|
|
2463 | |
|
|
2464 | glEnd (); |
|
|
2465 | glDisable (GL_TEXTURE_2D); |
|
|
2466 | key.texname = -1; |
1951 | } |
2467 | } |
|
|
2468 | } |
1952 | |
2469 | |
1953 | hv_clear (smooth); |
2470 | if (pl_tex.name) |
|
|
2471 | { |
|
|
2472 | maptex tex = pl_tex; |
|
|
2473 | int px = pl_x + sdx; |
|
|
2474 | int py = pl_y + sdy; |
|
|
2475 | |
|
|
2476 | key.texname = tex.name; |
|
|
2477 | arr = rc_array (rc, &key); |
|
|
2478 | |
|
|
2479 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2480 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
2481 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2482 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
|
|
2483 | |
1954 | rc_draw (rc); |
2484 | rc_draw (rc); |
1955 | rc_clear (rc); |
|
|
1956 | } |
2485 | } |
|
|
2486 | |
|
|
2487 | rc_draw (rc_ov); |
|
|
2488 | rc_clear (rc_ov); |
1957 | |
2489 | |
1958 | glDisable (GL_BLEND); |
2490 | glDisable (GL_BLEND); |
1959 | rc_free (rc); |
2491 | rc_free (rc); |
|
|
2492 | rc_free (rc_ov); |
1960 | |
2493 | |
1961 | // top layer: overlays such as the health bar |
2494 | // top layer: overlays such as the health bar |
1962 | for (y = 0; y < sh; y++) |
2495 | for (y = 0; y < sh; y++) |
1963 | if (0 <= y + my && y + my < self->rows) |
2496 | if (0 <= y + my && y + my < self->rows) |
1964 | { |
2497 | { |
… | |
… | |
1967 | for (x = 0; x < sw; x++) |
2500 | for (x = 0; x < sw; x++) |
1968 | if (row->c0 <= x + mx && x + mx < row->c1) |
2501 | if (row->c0 <= x + mx && x + mx < row->c1) |
1969 | { |
2502 | { |
1970 | mapcell *cell = row->col + (x + mx - row->c0); |
2503 | mapcell *cell = row->col + (x + mx - row->c0); |
1971 | |
2504 | |
1972 | int px = x * T; |
2505 | int px = x * Tw; |
1973 | int py = y * T; |
2506 | int py = y * Th; |
|
|
2507 | |
|
|
2508 | if (expect_false (cell->player == player)) |
|
|
2509 | { |
|
|
2510 | px += sdx; |
|
|
2511 | py += sdy; |
|
|
2512 | } |
1974 | |
2513 | |
1975 | if (cell->stat_hp) |
2514 | if (cell->stat_hp) |
1976 | { |
2515 | { |
1977 | int width = cell->stat_width * T; |
2516 | int width = cell->stat_width * Tw; |
1978 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2517 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
1979 | |
2518 | |
1980 | glColor3ub (0, 0, 0); |
2519 | glColor3ub (0, 0, 0); |
1981 | glRectf (px + 1, py - thick - 2, |
2520 | glRectf (px + 1, py - thick - 2, |
1982 | px + width - 1, py); |
2521 | px + width - 1, py); |
1983 | |
2522 | |
… | |
… | |
1989 | } |
2528 | } |
1990 | } |
2529 | } |
1991 | } |
2530 | } |
1992 | |
2531 | |
1993 | void |
2532 | void |
1994 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2533 | draw_magicmap (DC::Map self, int w, int h, unsigned char *data) |
1995 | CODE: |
2534 | CODE: |
1996 | { |
2535 | { |
1997 | static float color[16][3] = { |
2536 | static float color[16][3] = { |
1998 | { 0.00F, 0.00F, 0.00F }, |
2537 | { 0.00f, 0.00f, 0.00f }, |
1999 | { 1.00F, 1.00F, 1.00F }, |
2538 | { 1.00f, 1.00f, 1.00f }, |
2000 | { 0.00F, 0.00F, 0.55F }, |
2539 | { 0.00f, 0.00f, 0.55f }, |
2001 | { 1.00F, 0.00F, 0.00F }, |
2540 | { 1.00f, 0.00f, 0.00f }, |
2002 | |
2541 | |
2003 | { 1.00F, 0.54F, 0.00F }, |
2542 | { 1.00f, 0.54f, 0.00f }, |
2004 | { 0.11F, 0.56F, 1.00F }, |
2543 | { 0.11f, 0.56f, 1.00f }, |
2005 | { 0.93F, 0.46F, 0.00F }, |
2544 | { 0.93f, 0.46f, 0.00f }, |
2006 | { 0.18F, 0.54F, 0.34F }, |
2545 | { 0.18f, 0.54f, 0.34f }, |
2007 | |
2546 | |
2008 | { 0.56F, 0.73F, 0.56F }, |
2547 | { 0.56f, 0.73f, 0.56f }, |
2009 | { 0.80F, 0.80F, 0.80F }, |
2548 | { 0.80f, 0.80f, 0.80f }, |
2010 | { 0.55F, 0.41F, 0.13F }, |
2549 | { 0.55f, 0.41f, 0.13f }, |
2011 | { 0.99F, 0.77F, 0.26F }, |
2550 | { 0.99f, 0.77f, 0.26f }, |
2012 | |
2551 | |
2013 | { 0.74F, 0.65F, 0.41F }, |
2552 | { 0.74f, 0.65f, 0.41f }, |
2014 | |
2553 | |
2015 | { 0.00F, 1.00F, 1.00F }, |
2554 | { 0.00f, 1.00f, 1.00f }, |
2016 | { 1.00F, 0.00F, 1.00F }, |
2555 | { 1.00f, 0.00f, 1.00f }, |
2017 | { 1.00F, 1.00F, 0.00F }, |
2556 | { 1.00f, 1.00f, 0.00f }, |
2018 | }; |
2557 | }; |
2019 | |
2558 | |
2020 | int x, y; |
2559 | int x, y; |
2021 | |
2560 | |
2022 | glEnable (GL_TEXTURE_2D); |
2561 | glEnable (GL_TEXTURE_2D); |
|
|
2562 | /* GL_REPLACE would be correct, as we don't need to modulate alpha, |
|
|
2563 | * but the nvidia driver (185.18.14) mishandles alpha textures |
|
|
2564 | * and takes the colour from god knows where instead of using |
|
|
2565 | * Cp. MODULATE results in the same colour, but slightly different |
|
|
2566 | * alpha, but atcually gives us the correct colour with nvidia. |
|
|
2567 | */ |
2023 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2568 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
2024 | glEnable (GL_BLEND); |
2569 | glEnable (GL_BLEND); |
2025 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2570 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2026 | glBegin (GL_QUADS); |
2571 | glBegin (GL_QUADS); |
2027 | |
2572 | |
2028 | for (y = 0; y < h; y++) |
2573 | for (y = 0; y < h; y++) |
… | |
… | |
2032 | |
2577 | |
2033 | if (m) |
2578 | if (m) |
2034 | { |
2579 | { |
2035 | float *c = color [m & 15]; |
2580 | float *c = color [m & 15]; |
2036 | |
2581 | |
2037 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2582 | float tx1 = m & 0x40 ? 0.5f : 0.f; |
2038 | float tx2 = tx1 + 0.5; |
2583 | float tx2 = tx1 + 0.5f; |
2039 | |
2584 | |
2040 | glColor4f (c[0], c[1], c[2], 0.75); |
2585 | glColor4f (c[0], c[1], c[2], 1); |
2041 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2586 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2042 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2587 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2043 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2588 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2044 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2589 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2045 | } |
2590 | } |
… | |
… | |
2049 | glDisable (GL_BLEND); |
2594 | glDisable (GL_BLEND); |
2050 | glDisable (GL_TEXTURE_2D); |
2595 | glDisable (GL_TEXTURE_2D); |
2051 | } |
2596 | } |
2052 | |
2597 | |
2053 | void |
2598 | void |
2054 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2599 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2055 | PPCODE: |
2600 | PPCODE: |
2056 | { |
2601 | { |
2057 | int x, y; |
2602 | int x, y; |
2058 | int sw1 = sw + 2; |
2603 | int sw1 = sw + 2; |
2059 | int sh1 = sh + 2; |
2604 | int sh1 = sh + 2; |
2060 | int sh3 = sh * 3; |
2605 | int sh3 = sh * 3; |
2061 | int sw34 = (sw * 3 + 3) & ~3; |
2606 | int sw3 = sw * 3; |
|
|
2607 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
|
|
2608 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
2062 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2609 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2063 | SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); |
2610 | memset (darkness1, 0, sw1*sh1); |
2064 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
2065 | |
2611 | |
2066 | SvPOK_only (darkness3_sv); |
2612 | SvPOK_only (darkness3_sv); |
2067 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2613 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2068 | |
2614 | |
2069 | mx += self->x - 1; |
2615 | mx += self->x - 1; |
2070 | my += self->y - 1; |
2616 | my += self->y - 1; |
2071 | |
|
|
2072 | memset (darkness1, 255, sw1 * sh1); |
|
|
2073 | |
2617 | |
2074 | for (y = 0; y < sh1; y++) |
2618 | for (y = 0; y < sh1; y++) |
2075 | if (0 <= y + my && y + my < self->rows) |
2619 | if (0 <= y + my && y + my < self->rows) |
2076 | { |
2620 | { |
2077 | maprow *row = self->row + (y + my); |
2621 | maprow *row = self->row + (y + my); |
… | |
… | |
2080 | if (row->c0 <= x + mx && x + mx < row->c1) |
2624 | if (row->c0 <= x + mx && x + mx < row->c1) |
2081 | { |
2625 | { |
2082 | mapcell *cell = row->col + (x + mx - row->c0); |
2626 | mapcell *cell = row->col + (x + mx - row->c0); |
2083 | |
2627 | |
2084 | darkness1 [y * sw1 + x] = cell->darkness |
2628 | darkness1 [y * sw1 + x] = cell->darkness |
2085 | ? 255 - (cell->darkness - 1) |
2629 | ? DARKNESS_ADJUST (255 - (cell->darkness - 1)) |
2086 | : 255 - FOW_DARKNESS; |
2630 | : DARKNESS_ADJUST (255 - FOW_DARKNESS); |
2087 | } |
2631 | } |
2088 | } |
2632 | } |
2089 | |
2633 | |
2090 | for (y = 0; y < sh; ++y) |
2634 | for (y = 0; y < sh; ++y) |
2091 | for (x = 0; x < sw; ++x) |
2635 | for (x = 0; x < sw; ++x) |
… | |
… | |
2110 | |
2654 | |
2111 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2655 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2112 | uint8_t r23 = d23; |
2656 | uint8_t r23 = d23; |
2113 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2657 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2114 | |
2658 | |
2115 | darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); |
2659 | darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11); |
2116 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); |
2660 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21); |
2117 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); |
2661 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31); |
2118 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); |
2662 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12); |
2119 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); |
2663 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */ |
2120 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); |
2664 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32); |
2121 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); |
2665 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13); |
2122 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); |
2666 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23); |
2123 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); |
2667 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33); |
2124 | } |
2668 | } |
2125 | |
2669 | |
2126 | free (darkness1); |
2670 | free (darkness1); |
2127 | |
2671 | |
2128 | EXTEND (SP, 3); |
2672 | EXTEND (SP, 3); |
2129 | PUSHs (sv_2mortal (newSViv (sw34))); |
2673 | PUSHs (sv_2mortal (newSViv (sw3))); |
2130 | PUSHs (sv_2mortal (newSViv (sh3))); |
2674 | PUSHs (sv_2mortal (newSViv (sh3))); |
2131 | PUSHs (darkness3_sv); |
2675 | PUSHs (darkness3_sv); |
2132 | } |
2676 | } |
2133 | |
2677 | |
2134 | SV * |
2678 | SV * |
2135 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2679 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2136 | CODE: |
2680 | CODE: |
2137 | { |
2681 | { |
2138 | int x, y, x1, y1; |
2682 | int x, y, x1, y1; |
2139 | SV *data_sv = newSV (w * h * 7 + 5); |
2683 | SV *data_sv = newSV (w * h * 7 + 5); |
2140 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2684 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2197 | else |
2741 | else |
2198 | *data++ = 0; |
2742 | *data++ = 0; |
2199 | } |
2743 | } |
2200 | } |
2744 | } |
2201 | |
2745 | |
|
|
2746 | /* if size is w*h + 5 then no data has been found */ |
|
|
2747 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
|
|
2748 | { |
2202 | SvPOK_only (data_sv); |
2749 | SvPOK_only (data_sv); |
2203 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2750 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
2751 | } |
|
|
2752 | |
2204 | RETVAL = data_sv; |
2753 | RETVAL = data_sv; |
2205 | } |
2754 | } |
2206 | OUTPUT: |
2755 | OUTPUT: |
2207 | RETVAL |
2756 | RETVAL |
2208 | |
2757 | |
2209 | void |
2758 | void |
2210 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2759 | set_rect (DC::Map self, int x0, int y0, SV *data_sv) |
2211 | PPCODE: |
2760 | PPCODE: |
2212 | { |
2761 | { |
2213 | int x, y, z; |
2762 | int x, y, z; |
2214 | int w, h; |
2763 | int w, h; |
2215 | int x1, y1; |
2764 | int x1, y1; |
|
|
2765 | STRLEN len; |
|
|
2766 | uint8_t *data, *end; |
|
|
2767 | |
|
|
2768 | len = SvLEN (data_sv); |
|
|
2769 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
|
|
2770 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
|
|
2771 | end = data + len + 8; |
|
|
2772 | |
|
|
2773 | if (len < 5) |
|
|
2774 | XSRETURN_EMPTY; |
2216 | |
2775 | |
2217 | if (*data++ != 0) |
2776 | if (*data++ != 0) |
2218 | return; /* version mismatch */ |
2777 | XSRETURN_EMPTY; /* version mismatch */ |
2219 | |
2778 | |
2220 | w = *data++ << 8; w |= *data++; |
2779 | w = *data++ << 8; w |= *data++; |
2221 | h = *data++ << 8; h |= *data++; |
2780 | h = *data++ << 8; h |= *data++; |
2222 | |
2781 | |
2223 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2782 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2235 | { |
2794 | { |
2236 | maprow *row = map_get_row (self, y); |
2795 | maprow *row = map_get_row (self, y); |
2237 | |
2796 | |
2238 | for (x = x0; x < x1; x++) |
2797 | for (x = x0; x < x1; x++) |
2239 | { |
2798 | { |
|
|
2799 | uint8_t flags; |
|
|
2800 | |
|
|
2801 | if (data + 7 >= end) |
|
|
2802 | XSRETURN_EMPTY; |
|
|
2803 | |
2240 | uint8_t flags = *data++; |
2804 | flags = *data++; |
2241 | |
2805 | |
2242 | if (flags) |
2806 | if (flags) |
2243 | { |
2807 | { |
2244 | mapcell *cell = row_get_cell (row, x); |
2808 | mapcell *cell = row_get_cell (row, x); |
2245 | tileid tile[3] = { 0, 0, 0 }; |
2809 | tileid tile[3] = { 0, 0, 0 }; |
… | |
… | |
2248 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2812 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2249 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2813 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2250 | |
2814 | |
2251 | if (cell->darkness == 0) |
2815 | if (cell->darkness == 0) |
2252 | { |
2816 | { |
2253 | cell->darkness = 0; |
2817 | /*cell->darkness = 0;*/ |
|
|
2818 | EXTEND (SP, 3); |
2254 | |
2819 | |
2255 | for (z = 0; z <= 2; z++) |
2820 | for (z = 0; z <= 2; z++) |
2256 | { |
2821 | { |
2257 | tileid t = tile [z]; |
2822 | tileid t = tile [z]; |
2258 | |
2823 | |
2259 | if (t >= self->texs || (t && !self->tex [t].name)) |
2824 | if (t >= self->texs || (t && !self->tex [t].name)) |
2260 | { |
2825 | { |
2261 | XPUSHs (sv_2mortal (newSViv (t))); |
2826 | PUSHs (sv_2mortal (newSViv (t))); |
2262 | need_texid (self, t); |
2827 | need_texid (self, t); |
2263 | } |
2828 | } |
2264 | |
2829 | |
2265 | cell->tile [z] = t; |
2830 | cell->tile [z] = t; |
2266 | } |
2831 | } |
… | |
… | |
2268 | } |
2833 | } |
2269 | } |
2834 | } |
2270 | } |
2835 | } |
2271 | } |
2836 | } |
2272 | |
2837 | |
2273 | MODULE = CFPlus PACKAGE = CFPlus::RW |
2838 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2274 | |
2839 | |
2275 | CFPlus::RW |
2840 | DC::RW |
2276 | new (SV *class, SV *data_sv) |
2841 | new (SV *klass, SV *data_sv) |
2277 | CODE: |
2842 | CODE: |
2278 | { |
2843 | { |
2279 | STRLEN datalen; |
2844 | STRLEN datalen; |
2280 | char *data = SvPVbyte (data_sv, datalen); |
2845 | char *data = SvPVbyte (data_sv, datalen); |
2281 | |
2846 | |
2282 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2847 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2283 | } |
2848 | } |
2284 | OUTPUT: |
2849 | OUTPUT: |
2285 | RETVAL |
2850 | RETVAL |
2286 | |
2851 | |
2287 | CFPlus::RW |
2852 | DC::RW |
2288 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2853 | new_from_file (SV *klass, const char *path, const char *mode = "rb") |
2289 | CODE: |
2854 | CODE: |
2290 | RETVAL = SDL_RWFromFile (path, mode); |
2855 | RETVAL = SDL_RWFromFile (path, mode); |
2291 | OUTPUT: |
2856 | OUTPUT: |
2292 | RETVAL |
2857 | RETVAL |
2293 | |
2858 | |
2294 | # fails on win32: |
2859 | # fails on win32: |
2295 | # CFPlus.xs(2268) : error C2059: syntax error : '(' |
2860 | # dc.xs(2268) : error C2059: syntax error : '(' |
2296 | #void |
2861 | #void |
2297 | #close (CFPlus::RW self) |
2862 | #close (DC::RW self) |
2298 | # CODE: |
2863 | # CODE: |
2299 | # (self->(close)) (self); |
2864 | # (self->(close)) (self); |
2300 | |
2865 | |
2301 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2866 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
2302 | |
2867 | |
2303 | PROTOTYPES: DISABLE |
2868 | PROTOTYPES: DISABLE |
2304 | |
2869 | |
2305 | CFPlus::Channel |
2870 | DC::Channel |
2306 | find () |
2871 | find () |
2307 | CODE: |
2872 | CODE: |
2308 | { |
2873 | { |
2309 | RETVAL = Mix_GroupAvailable (-1); |
2874 | RETVAL = Mix_GroupAvailable (-1); |
2310 | |
2875 | |
2311 | if (RETVAL < 0) |
2876 | if (RETVAL < 0) |
2312 | { |
2877 | { |
2313 | RETVAL = Mix_GroupOldest (-1); |
2878 | RETVAL = Mix_GroupOldest (-1); |
2314 | |
2879 | |
2315 | if (RETVAL < 0) |
2880 | if (RETVAL < 0) |
|
|
2881 | { |
|
|
2882 | // happens sometimes, maybe it just stopped playing(?) |
|
|
2883 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2884 | |
|
|
2885 | if (RETVAL < 0) |
2316 | XSRETURN_UNDEF; |
2886 | XSRETURN_UNDEF; |
2317 | |
2887 | } |
|
|
2888 | else |
2318 | Mix_HaltChannel (RETVAL); |
2889 | Mix_HaltChannel (RETVAL); |
2319 | } |
2890 | } |
2320 | |
2891 | |
2321 | Mix_UnregisterAllEffects (RETVAL); |
2892 | Mix_UnregisterAllEffects (RETVAL); |
2322 | Mix_Volume (RETVAL, 128); |
2893 | Mix_Volume (RETVAL, 128); |
2323 | } |
2894 | } |
2324 | OUTPUT: |
2895 | OUTPUT: |
2325 | RETVAL |
2896 | RETVAL |
2326 | |
2897 | |
2327 | void |
2898 | void |
2328 | halt (CFPlus::Channel self) |
2899 | halt (DC::Channel self) |
2329 | CODE: |
2900 | CODE: |
2330 | Mix_HaltChannel (self); |
2901 | Mix_HaltChannel (self); |
2331 | |
2902 | |
2332 | void |
2903 | void |
2333 | expire (CFPlus::Channel self, int ticks = -1) |
2904 | expire (DC::Channel self, int ticks = -1) |
2334 | CODE: |
2905 | CODE: |
2335 | Mix_ExpireChannel (self, ticks); |
2906 | Mix_ExpireChannel (self, ticks); |
2336 | |
2907 | |
2337 | void |
2908 | void |
2338 | fade_out (CFPlus::Channel self, int ticks = -1) |
2909 | fade_out (DC::Channel self, int ticks = -1) |
2339 | CODE: |
2910 | CODE: |
2340 | Mix_FadeOutChannel (self, ticks); |
2911 | Mix_FadeOutChannel (self, ticks); |
2341 | |
2912 | |
2342 | int |
2913 | int |
2343 | volume (CFPlus::Channel self, int volume) |
2914 | volume (DC::Channel self, int volume) |
2344 | CODE: |
2915 | CODE: |
2345 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2916 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2346 | OUTPUT: |
2917 | OUTPUT: |
2347 | RETVAL |
2918 | RETVAL |
2348 | |
2919 | |
2349 | void |
2920 | void |
2350 | unregister_all_effects (CFPlus::Channel self) |
2921 | unregister_all_effects (DC::Channel self) |
2351 | CODE: |
2922 | CODE: |
2352 | Mix_UnregisterAllEffects (self); |
2923 | Mix_UnregisterAllEffects (self); |
2353 | |
2924 | |
2354 | void |
2925 | void |
2355 | set_panning (CFPlus::Channel self, int left, int right) |
2926 | set_panning (DC::Channel self, int left, int right) |
2356 | CODE: |
2927 | CODE: |
2357 | left = CLAMP (left , 0, 255); |
2928 | left = CLAMP (left , 0, 255); |
2358 | right = CLAMP (right, 0, 255); |
2929 | right = CLAMP (right, 0, 255); |
2359 | Mix_SetPanning (self, left, right); |
2930 | Mix_SetPanning (self, left, right); |
2360 | |
2931 | |
2361 | void |
2932 | void |
2362 | set_distance (CFPlus::Channel self, int distance) |
2933 | set_distance (DC::Channel self, int distance) |
2363 | CODE: |
2934 | CODE: |
2364 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2935 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2365 | |
2936 | |
2366 | void |
2937 | void |
2367 | set_position (CFPlus::Channel self, int angle, int distance) |
2938 | set_position (DC::Channel self, int angle, int distance) |
2368 | CODE: |
2939 | CODE: |
2369 | |
2940 | |
2370 | void |
2941 | void |
2371 | set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) |
2942 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
2372 | CODE: |
2943 | CODE: |
2373 | { |
2944 | { |
2374 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2945 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2375 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2946 | int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f; |
2376 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2947 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2377 | } |
2948 | } |
2378 | |
2949 | |
2379 | void |
2950 | void |
2380 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2951 | set_reverse_stereo (DC::Channel self, int flip) |
2381 | CODE: |
2952 | CODE: |
2382 | Mix_SetReverseStereo (self, flip); |
2953 | Mix_SetReverseStereo (self, flip); |
2383 | |
2954 | |
2384 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2955 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
2385 | |
2956 | |
2386 | PROTOTYPES: DISABLE |
2957 | PROTOTYPES: DISABLE |
2387 | |
2958 | |
|
|
2959 | void |
|
|
2960 | decoders () |
|
|
2961 | PPCODE: |
|
|
2962 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
2963 | int i, num = Mix_GetNumChunkDecoders (); |
|
|
2964 | EXTEND (SP, num); |
|
|
2965 | for (i = 0; i < num; ++i) |
|
|
2966 | PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0))); |
|
|
2967 | #else |
|
|
2968 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
2969 | #endif |
|
|
2970 | |
2388 | CFPlus::MixChunk |
2971 | DC::MixChunk |
2389 | new (SV *class, CFPlus::RW rwops) |
2972 | new (SV *klass, DC::RW rwops) |
2390 | CODE: |
2973 | CODE: |
2391 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2974 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2392 | OUTPUT: |
2975 | OUTPUT: |
2393 | RETVAL |
2976 | RETVAL |
2394 | |
2977 | |
2395 | void |
2978 | void |
2396 | DESTROY (CFPlus::MixChunk self) |
2979 | DESTROY (DC::MixChunk self) |
2397 | CODE: |
2980 | CODE: |
2398 | Mix_FreeChunk (self); |
2981 | Mix_FreeChunk (self); |
2399 | |
2982 | |
2400 | int |
2983 | int |
2401 | volume (CFPlus::MixChunk self, int volume = -1) |
2984 | volume (DC::MixChunk self, int volume = -1) |
2402 | CODE: |
2985 | CODE: |
2403 | if (items > 1) |
2986 | if (items > 1) |
2404 | volume = CLAMP (volume, 0, 128); |
2987 | volume = CLAMP (volume, 0, 128); |
2405 | RETVAL = Mix_VolumeChunk (self, volume); |
2988 | RETVAL = Mix_VolumeChunk (self, volume); |
2406 | OUTPUT: |
2989 | OUTPUT: |
2407 | RETVAL |
2990 | RETVAL |
2408 | |
2991 | |
2409 | CFPlus::Channel |
2992 | DC::Channel |
2410 | play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) |
2993 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2411 | CODE: |
2994 | CODE: |
2412 | { |
2995 | { |
2413 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2996 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2414 | |
2997 | |
2415 | if (RETVAL < 0) |
2998 | if (RETVAL < 0) |
… | |
… | |
2422 | } |
3005 | } |
2423 | } |
3006 | } |
2424 | OUTPUT: |
3007 | OUTPUT: |
2425 | RETVAL |
3008 | RETVAL |
2426 | |
3009 | |
2427 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
3010 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
|
|
3011 | |
|
|
3012 | void |
|
|
3013 | decoders () |
|
|
3014 | PPCODE: |
|
|
3015 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
3016 | int i, num = Mix_GetNumMusicDecoders (); |
|
|
3017 | EXTEND (SP, num); |
|
|
3018 | for (i = 0; i < num; ++i) |
|
|
3019 | PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0))); |
|
|
3020 | #else |
|
|
3021 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
3022 | #endif |
2428 | |
3023 | |
2429 | int |
3024 | int |
2430 | volume (int volume = -1) |
3025 | volume (int volume = -1) |
2431 | PROTOTYPE: ;$ |
3026 | PROTOTYPE: ;$ |
2432 | CODE: |
3027 | CODE: |
… | |
… | |
2444 | void |
3039 | void |
2445 | halt () |
3040 | halt () |
2446 | CODE: |
3041 | CODE: |
2447 | Mix_HaltMusic (); |
3042 | Mix_HaltMusic (); |
2448 | |
3043 | |
|
|
3044 | int |
|
|
3045 | playing () |
|
|
3046 | CODE: |
|
|
3047 | RETVAL = Mix_PlayingMusic (); |
|
|
3048 | OUTPUT: |
|
|
3049 | RETVAL |
|
|
3050 | |
2449 | CFPlus::MixMusic |
3051 | DC::MixMusic |
2450 | new (SV *class, CFPlus::RW rwops) |
3052 | new (SV *klass, DC::RW rwops) |
2451 | CODE: |
3053 | CODE: |
2452 | RETVAL = Mix_LoadMUS_RW (rwops); |
3054 | RETVAL = Mix_LoadMUS_RW (rwops); |
2453 | OUTPUT: |
3055 | OUTPUT: |
2454 | RETVAL |
3056 | RETVAL |
2455 | |
3057 | |
2456 | void |
3058 | void |
2457 | DESTROY (CFPlus::MixMusic self) |
3059 | DESTROY (DC::MixMusic self) |
2458 | CODE: |
3060 | CODE: |
2459 | Mix_FreeMusic (self); |
3061 | Mix_FreeMusic (self); |
2460 | |
3062 | |
2461 | int |
3063 | int |
2462 | play (CFPlus::MixMusic self, int loops = -1) |
3064 | play (DC::MixMusic self, int loops = -1) |
2463 | CODE: |
3065 | CODE: |
2464 | RETVAL = Mix_PlayMusic (self, loops); |
3066 | RETVAL = Mix_PlayMusic (self, loops); |
2465 | OUTPUT: |
3067 | OUTPUT: |
2466 | RETVAL |
3068 | RETVAL |
2467 | |
3069 | |
2468 | void |
3070 | void |
2469 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
3071 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2470 | CODE: |
3072 | CODE: |
2471 | Mix_FadeInMusicPos (self, loops, ms, position); |
3073 | Mix_FadeInMusicPos (self, loops, ms, position); |
2472 | |
3074 | |
2473 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
3075 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2474 | |
3076 | |
2475 | PROTOTYPES: ENABLE |
3077 | PROTOTYPES: ENABLE |
2476 | |
3078 | |
2477 | BOOT: |
3079 | BOOT: |
2478 | { |
3080 | { |
2479 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
3081 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2480 | static const struct { |
3082 | static const struct { |
2481 | const char *name; |
3083 | const char *name; |
2482 | IV iv; |
3084 | IV iv; |
2483 | } *civ, const_iv[] = { |
3085 | } *civ, const_iv[] = { |
2484 | # define const_iv(name) { # name, (IV)name } |
3086 | # define const_iv(name) { # name, (IV)name } |
2485 | const_iv (GL_VENDOR), |
3087 | const_iv (GL_VENDOR), |
2486 | const_iv (GL_VERSION), |
3088 | const_iv (GL_VERSION), |
2487 | const_iv (GL_EXTENSIONS), |
3089 | const_iv (GL_EXTENSIONS), |
|
|
3090 | const_iv (GL_MAX_TEXTURE_UNITS), |
2488 | const_iv (GL_COLOR_MATERIAL), |
3091 | const_iv (GL_COLOR_MATERIAL), |
2489 | const_iv (GL_SMOOTH), |
3092 | const_iv (GL_SMOOTH), |
2490 | const_iv (GL_FLAT), |
3093 | const_iv (GL_FLAT), |
2491 | const_iv (GL_DITHER), |
3094 | const_iv (GL_DITHER), |
2492 | const_iv (GL_BLEND), |
3095 | const_iv (GL_BLEND), |
… | |
… | |
2504 | const_iv (GL_ZERO), |
3107 | const_iv (GL_ZERO), |
2505 | const_iv (GL_SRC_ALPHA), |
3108 | const_iv (GL_SRC_ALPHA), |
2506 | const_iv (GL_DST_ALPHA), |
3109 | const_iv (GL_DST_ALPHA), |
2507 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
3110 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
2508 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
3111 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
|
|
3112 | const_iv (GL_SRC_COLOR), |
|
|
3113 | const_iv (GL_DST_COLOR), |
|
|
3114 | const_iv (GL_ONE_MINUS_SRC_COLOR), |
|
|
3115 | const_iv (GL_ONE_MINUS_DST_COLOR), |
2509 | const_iv (GL_SRC_ALPHA_SATURATE), |
3116 | const_iv (GL_SRC_ALPHA_SATURATE), |
2510 | const_iv (GL_RGB), |
3117 | const_iv (GL_RGB), |
2511 | const_iv (GL_RGBA), |
3118 | const_iv (GL_RGBA), |
2512 | const_iv (GL_RGBA4), |
3119 | const_iv (GL_RGBA4), |
2513 | const_iv (GL_RGBA8), |
3120 | const_iv (GL_RGBA8), |
… | |
… | |
2519 | const_iv (GL_INTENSITY), |
3126 | const_iv (GL_INTENSITY), |
2520 | const_iv (GL_LUMINANCE), |
3127 | const_iv (GL_LUMINANCE), |
2521 | const_iv (GL_LUMINANCE_ALPHA), |
3128 | const_iv (GL_LUMINANCE_ALPHA), |
2522 | const_iv (GL_FLOAT), |
3129 | const_iv (GL_FLOAT), |
2523 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
3130 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
3131 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
3132 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
3133 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
3134 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
3135 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
3136 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2524 | const_iv (GL_COMPILE), |
3137 | const_iv (GL_COMPILE), |
2525 | const_iv (GL_PROXY_TEXTURE_1D), |
3138 | const_iv (GL_PROXY_TEXTURE_1D), |
2526 | const_iv (GL_PROXY_TEXTURE_2D), |
3139 | const_iv (GL_PROXY_TEXTURE_2D), |
2527 | const_iv (GL_TEXTURE_1D), |
3140 | const_iv (GL_TEXTURE_1D), |
2528 | const_iv (GL_TEXTURE_2D), |
3141 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2567 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
3180 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2568 | const_iv (GL_POINT_SMOOTH_HINT), |
3181 | const_iv (GL_POINT_SMOOTH_HINT), |
2569 | const_iv (GL_LINE_SMOOTH_HINT), |
3182 | const_iv (GL_LINE_SMOOTH_HINT), |
2570 | const_iv (GL_POLYGON_SMOOTH_HINT), |
3183 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2571 | const_iv (GL_GENERATE_MIPMAP_HINT), |
3184 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
3185 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2572 | const_iv (GL_FASTEST), |
3186 | const_iv (GL_FASTEST), |
2573 | const_iv (GL_DONT_CARE), |
3187 | const_iv (GL_DONT_CARE), |
2574 | const_iv (GL_NICEST), |
3188 | const_iv (GL_NICEST), |
2575 | const_iv (GL_V2F), |
3189 | const_iv (GL_V2F), |
2576 | const_iv (GL_V3F), |
3190 | const_iv (GL_V3F), |
2577 | const_iv (GL_T2F_V3F), |
3191 | const_iv (GL_T2F_V3F), |
2578 | const_iv (GL_T2F_N3F_V3F), |
3192 | const_iv (GL_T2F_N3F_V3F), |
|
|
3193 | const_iv (GL_FUNC_ADD), |
|
|
3194 | const_iv (GL_FUNC_SUBTRACT), |
|
|
3195 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
2579 | # undef const_iv |
3196 | # undef const_iv |
2580 | }; |
3197 | }; |
2581 | |
3198 | |
2582 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3199 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
2583 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3200 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
2584 | |
3201 | |
2585 | texture_av = newAV (); |
3202 | texture_av = newAV (); |
2586 | AvREAL_off (texture_av); |
3203 | AvREAL_off (texture_av); |
2587 | } |
3204 | } |
2588 | |
3205 | |
2589 | char * |
3206 | void |
|
|
3207 | disable_GL_EXT_blend_func_separate () |
|
|
3208 | CODE: |
|
|
3209 | gl.BlendFuncSeparate = 0; |
|
|
3210 | gl.BlendFuncSeparateEXT = 0; |
|
|
3211 | |
|
|
3212 | void |
|
|
3213 | apple_nvidia_bug (int enable) |
|
|
3214 | |
|
|
3215 | const char * |
2590 | gl_vendor () |
3216 | gl_vendor () |
2591 | CODE: |
3217 | CODE: |
2592 | RETVAL = (char *)glGetString (GL_VENDOR); |
3218 | RETVAL = (const char *)glGetString (GL_VENDOR); |
2593 | OUTPUT: |
3219 | OUTPUT: |
2594 | RETVAL |
3220 | RETVAL |
2595 | |
3221 | |
2596 | char * |
3222 | const char * |
2597 | gl_version () |
3223 | gl_version () |
2598 | CODE: |
3224 | CODE: |
2599 | RETVAL = (char *)glGetString (GL_VERSION); |
3225 | RETVAL = (const char *)glGetString (GL_VERSION); |
2600 | OUTPUT: |
3226 | OUTPUT: |
2601 | RETVAL |
3227 | RETVAL |
2602 | |
3228 | |
2603 | char * |
3229 | const char * |
2604 | gl_extensions () |
3230 | gl_extensions () |
2605 | CODE: |
3231 | CODE: |
2606 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3232 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
2607 | OUTPUT: |
3233 | OUTPUT: |
2608 | RETVAL |
3234 | RETVAL |
2609 | |
3235 | |
2610 | const char *glGetString (GLenum pname) |
3236 | const char *glGetString (GLenum pname) |
|
|
3237 | CODE: |
|
|
3238 | RETVAL = (const char *)glGetString (pname); |
|
|
3239 | OUTPUT: |
|
|
3240 | RETVAL |
2611 | |
3241 | |
2612 | GLint glGetInteger (GLenum pname) |
3242 | GLint glGetInteger (GLenum pname) |
2613 | CODE: |
3243 | CODE: |
2614 | glGetIntegerv (pname, &RETVAL); |
3244 | glGetIntegerv (pname, &RETVAL); |
2615 | OUTPUT: |
3245 | OUTPUT: |
… | |
… | |
2623 | |
3253 | |
2624 | int glGetError () |
3254 | int glGetError () |
2625 | |
3255 | |
2626 | void glFinish () |
3256 | void glFinish () |
2627 | |
3257 | |
|
|
3258 | void glFlush () |
|
|
3259 | |
2628 | void glClear (int mask) |
3260 | void glClear (int mask) |
2629 | |
3261 | |
2630 | void glClearColor (float r, float g, float b, float a = 1.0) |
3262 | void glClearColor (float r, float g, float b, float a = 1.0) |
2631 | PROTOTYPE: @ |
3263 | PROTOTYPE: @ |
2632 | |
3264 | |
… | |
… | |
2641 | void glBlendFunc (int sfactor, int dfactor) |
3273 | void glBlendFunc (int sfactor, int dfactor) |
2642 | |
3274 | |
2643 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
3275 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
2644 | CODE: |
3276 | CODE: |
2645 | gl_BlendFuncSeparate (sa, da, saa, daa); |
3277 | gl_BlendFuncSeparate (sa, da, saa, daa); |
|
|
3278 | |
|
|
3279 | # void glBlendEquation (int se) |
2646 | |
3280 | |
2647 | void glDepthMask (int flag) |
3281 | void glDepthMask (int flag) |
2648 | |
3282 | |
2649 | void glLogicOp (int opcode) |
3283 | void glLogicOp (int opcode) |
2650 | |
3284 | |
… | |
… | |
2685 | void glRotate (float angle, float x, float y, float z) |
3319 | void glRotate (float angle, float x, float y, float z) |
2686 | CODE: |
3320 | CODE: |
2687 | glRotatef (angle, x, y, z); |
3321 | glRotatef (angle, x, y, z); |
2688 | |
3322 | |
2689 | void glColor (float r, float g, float b, float a = 1.0) |
3323 | void glColor (float r, float g, float b, float a = 1.0) |
|
|
3324 | PROTOTYPE: @ |
2690 | ALIAS: |
3325 | ALIAS: |
2691 | glColor_premultiply = 1 |
3326 | glColor_premultiply = 1 |
2692 | CODE: |
3327 | CODE: |
2693 | if (ix) |
3328 | if (ix) |
2694 | { |
3329 | { |
… | |
… | |
2714 | |
3349 | |
2715 | void glRect (float x1, float y1, float x2, float y2) |
3350 | void glRect (float x1, float y1, float x2, float y2) |
2716 | CODE: |
3351 | CODE: |
2717 | glRectf (x1, y1, x2, y2); |
3352 | glRectf (x1, y1, x2, y2); |
2718 | |
3353 | |
|
|
3354 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
3355 | CODE: |
|
|
3356 | glBegin (GL_LINE_LOOP); |
|
|
3357 | glVertex2f (x1, y1); |
|
|
3358 | glVertex2f (x2, y1); |
|
|
3359 | glVertex2f (x2, y2); |
|
|
3360 | glVertex2f (x1, y2); |
|
|
3361 | glEnd (); |
|
|
3362 | |
2719 | PROTOTYPES: ENABLE |
3363 | PROTOTYPES: ENABLE |
2720 | |
3364 | |
2721 | void glBegin (int mode) |
3365 | void glBegin (int mode) |
2722 | |
3366 | |
2723 | void glEnd () |
3367 | void glEnd () |
… | |
… | |
2755 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
3399 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2756 | CODE: |
3400 | CODE: |
2757 | if (gl.SeparableFilter2D) |
3401 | if (gl.SeparableFilter2D) |
2758 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
3402 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2759 | |
3403 | |
2760 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
3404 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2761 | |
3405 | |
2762 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
3406 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2763 | |
3407 | |
2764 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
3408 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2765 | |
3409 | |
… | |
… | |
2791 | |
3435 | |
2792 | void glEndList () |
3436 | void glEndList () |
2793 | |
3437 | |
2794 | void glCallList (int list) |
3438 | void glCallList (int list) |
2795 | |
3439 | |
2796 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
3440 | void c_init () |
|
|
3441 | CODE: |
|
|
3442 | glPixelStorei (GL_PACK_ALIGNMENT , 1); |
|
|
3443 | glPixelStorei (GL_UNPACK_ALIGNMENT, 1); |
|
|
3444 | |
|
|
3445 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2797 | |
3446 | |
2798 | PROTOTYPES: DISABLE |
3447 | PROTOTYPES: DISABLE |
2799 | |
3448 | |
2800 | void |
3449 | void |
2801 | find_widget (SV *self, NV x, NV y) |
3450 | find_widget (SV *self, NV x, NV y) |
2802 | PPCODE: |
3451 | PPCODE: |
2803 | { |
3452 | { |
2804 | if (within_widget (self, x, y)) |
3453 | if (within_widget (self, x, y)) |
2805 | XPUSHs (self); |
3454 | XPUSHs (self); |
2806 | } |
3455 | } |
2807 | |
3456 | |
2808 | BOOT: |
3457 | BOOT: |
2809 | { |
3458 | { |
2810 | hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); |
3459 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
2811 | |
3460 | |
2812 | draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); |
3461 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
2813 | draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); |
3462 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
2814 | draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); |
3463 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
2815 | draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); |
3464 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
2816 | } |
3465 | } |
2817 | |
3466 | |
2818 | void |
3467 | void |
2819 | draw (SV *self) |
3468 | draw (SV *self) |
2820 | CODE: |
3469 | CODE: |
2821 | { |
3470 | { |
2822 | HV *hv; |
3471 | HV *hv; |
2823 | SV **svp; |
3472 | SV **svp; |
2824 | NV x, y, w, h; |
3473 | NV x, y, w, h; |
2825 | SV *draw_x_sv = GvSV (draw_x_gv); |
3474 | SV *draw_x_sv = GvSV (draw_x_gv); |
2826 | SV *draw_y_sv = GvSV (draw_y_gv); |
3475 | SV *draw_y_sv = GvSV (draw_y_gv); |
2827 | SV *draw_w_sv = GvSV (draw_w_gv); |
3476 | SV *draw_w_sv = GvSV (draw_w_gv); |
2828 | SV *draw_h_sv = GvSV (draw_h_gv); |
3477 | SV *draw_h_sv = GvSV (draw_h_gv); |
2829 | SV *hover; |
|
|
2830 | double draw_x, draw_y, draw_w, draw_h; |
3478 | double draw_x, draw_y; |
2831 | |
3479 | |
2832 | if (!SvROK (self)) |
3480 | if (!SvROK (self)) |
2833 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
3481 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
2834 | |
3482 | |
2835 | hv = (HV *)SvRV (self); |
3483 | hv = (HV *)SvRV (self); |
2836 | |
3484 | |
2837 | if (SvTYPE (hv) != SVt_PVHV) |
3485 | if (SvTYPE (hv) != SVt_PVHV) |
2838 | croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); |
3486 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2839 | |
3487 | |
2840 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
3488 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2841 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
3489 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2842 | |
3490 | |
2843 | if (!h || !w) |
3491 | if (!h || !w) |
… | |
… | |
2863 | { |
3511 | { |
2864 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
3512 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2865 | |
3513 | |
2866 | if (svp && SvTRUE (*svp)) |
3514 | if (svp && SvTRUE (*svp)) |
2867 | { |
3515 | { |
2868 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
3516 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2869 | glEnable (GL_BLEND); |
3517 | glEnable (GL_BLEND); |
2870 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
3518 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2871 | glBegin (GL_QUADS); |
3519 | glBegin (GL_QUADS); |
2872 | glVertex2f (0, 0); |
3520 | glVertex2f (0, 0); |
2873 | glVertex2f (w, 0); |
3521 | glVertex2f (w, 0); |
… | |
… | |
2876 | glEnd (); |
3524 | glEnd (); |
2877 | glDisable (GL_BLEND); |
3525 | glDisable (GL_BLEND); |
2878 | } |
3526 | } |
2879 | } |
3527 | } |
2880 | #if 0 |
3528 | #if 0 |
2881 | if ($ENV{CFPLUS_DEBUG} & 1) { |
3529 | // draw borders, for debugging |
2882 | glPushMatrix; |
3530 | glPushMatrix (); |
2883 | glColor 1, 1, 0, 1; |
3531 | glColor4f (1., 1., 0., 1.); |
2884 | glTranslate 0.375, 0.375; |
3532 | glTranslatef (.5, .5, 0.); |
2885 | glBegin GL_LINE_LOOP; |
3533 | glBegin (GL_LINE_LOOP); |
2886 | glVertex 0 , 0; |
3534 | glVertex2f (0 , 0); |
2887 | glVertex $self->{w} - 1, 0; |
3535 | glVertex2f (w - 1, 0); |
2888 | glVertex $self->{w} - 1, $self->{h} - 1; |
3536 | glVertex2f (w - 1, h - 1); |
2889 | glVertex 0 , $self->{h} - 1; |
3537 | glVertex2f (0 , h - 1); |
2890 | glEnd; |
3538 | glEnd (); |
2891 | glPopMatrix; |
3539 | glPopMatrix (); |
2892 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2893 | } |
|
|
2894 | #endif |
3540 | #endif |
2895 | PUSHMARK (SP); |
3541 | PUSHMARK (SP); |
2896 | XPUSHs (self); |
3542 | XPUSHs (self); |
2897 | PUTBACK; |
3543 | PUTBACK; |
2898 | call_method ("_draw", G_VOID | G_DISCARD); |
3544 | call_method ("_draw", G_VOID | G_DISCARD); |