… | |
… | |
17 | #include "perl.h" |
17 | #include "perl.h" |
18 | #include "XSUB.h" |
18 | #include "XSUB.h" |
19 | |
19 | |
20 | #ifdef _WIN32 |
20 | #ifdef _WIN32 |
21 | # undef pipe |
21 | # undef pipe |
|
|
22 | // microsoft vs. C |
|
|
23 | # define sqrtf(x) sqrt(x) |
|
|
24 | # define atan2f(x,y) atan2(x,y) |
|
|
25 | # define M_PI 3.14159265f |
22 | #endif |
26 | #endif |
23 | |
27 | |
24 | #include <assert.h> |
28 | #include <assert.h> |
25 | #include <math.h> |
29 | #include <math.h> |
26 | #include <string.h> |
30 | #include <string.h> |
27 | #include <stdio.h> |
31 | #include <stdio.h> |
28 | #include <stdlib.h> |
32 | #include <stdlib.h> |
|
|
33 | |
|
|
34 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
29 | |
35 | |
30 | #include <SDL.h> |
36 | #include <SDL.h> |
31 | #include <SDL_thread.h> |
37 | #include <SDL_thread.h> |
32 | #include <SDL_endian.h> |
38 | #include <SDL_endian.h> |
33 | #include <SDL_image.h> |
39 | #include <SDL_image.h> |
34 | #include <SDL_mixer.h> |
40 | #include <SDL_mixer.h> |
35 | #include <SDL_opengl.h> |
41 | #include <SDL_opengl.h> |
36 | |
42 | |
|
|
43 | /* work around os x broken headers */ |
|
|
44 | #ifdef __MACOSX__ |
|
|
45 | typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); |
|
|
46 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); |
|
|
47 | typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); |
|
|
48 | #endif |
|
|
49 | |
37 | #define PANGO_ENABLE_BACKEND |
50 | #define PANGO_ENABLE_BACKEND |
38 | #define G_DISABLE_CAST_CHECKS |
51 | #define G_DISABLE_CAST_CHECKS |
39 | |
52 | |
40 | #include <glib/gmacros.h> |
53 | #include <glib/gmacros.h> |
41 | |
54 | |
42 | #include <pango/pango.h> |
55 | #include <pango/pango.h> |
|
|
56 | |
|
|
57 | #ifndef PANGO_VERSION_CHECK |
|
|
58 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
|
|
59 | #endif |
|
|
60 | |
|
|
61 | #if !PANGO_VERSION_CHECK (1, 15, 2) |
|
|
62 | # define pango_layout_get_line_readonly pango_layout_get_line |
|
|
63 | # define pango_layout_get_lines_readonly pango_layout_get_lines |
|
|
64 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line |
|
|
65 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run |
|
|
66 | #endif |
43 | |
67 | |
44 | #ifndef _WIN32 |
68 | #ifndef _WIN32 |
45 | # include <sys/types.h> |
69 | # include <sys/types.h> |
46 | # include <sys/socket.h> |
70 | # include <sys/socket.h> |
47 | # include <netinet/in.h> |
71 | # include <netinet/in.h> |
48 | # include <netinet/tcp.h> |
72 | # include <netinet/tcp.h> |
49 | # include <inttypes.h> |
73 | # include <inttypes.h> |
50 | #endif |
74 | #endif |
51 | |
75 | |
|
|
76 | #if __GNUC__ >= 4 |
|
|
77 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
78 | #else |
|
|
79 | # define expect(expr,value) (expr) |
|
|
80 | #endif |
|
|
81 | |
|
|
82 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
83 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
84 | |
52 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
85 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
53 | |
86 | |
|
|
87 | /* this is used as fow flag as well, so has to have a different value */ |
|
|
88 | /* then anything that is computed by incoming darkness */ |
54 | #define FOW_DARKNESS 32 |
89 | #define FOW_DARKNESS 50 |
|
|
90 | #define DARKNESS_ADJUST(n) (n) |
55 | |
91 | |
56 | #define MAP_EXTEND_X 32 |
92 | #define MAP_EXTEND_X 32 |
57 | #define MAP_EXTEND_Y 512 |
93 | #define MAP_EXTEND_Y 512 |
58 | |
94 | |
59 | #define MIN_FONT_HEIGHT 10 |
95 | #define MIN_FONT_HEIGHT 10 |
60 | |
96 | |
61 | #if 0 |
97 | /* mask out modifiers we are not interested in */ |
62 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
98 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
63 | #else |
99 | |
64 | # define PARACHUTE 0 |
100 | #define KMOD_LRAM 0x10000 // our extension |
65 | #endif |
101 | |
|
|
102 | #define TEXID_SPEECH 1 |
|
|
103 | #define TEXID_NOFACE 2 |
|
|
104 | |
|
|
105 | static char * |
|
|
106 | fast_sv_grow (SV *sv, STRLEN need) |
|
|
107 | { |
|
|
108 | STRLEN len = SvLEN (sv); |
|
|
109 | STRLEN want = SvCUR (sv) + need; |
|
|
110 | |
|
|
111 | if (expect_false (len < want)) |
|
|
112 | { |
|
|
113 | do |
|
|
114 | len *= 2; |
|
|
115 | while (len < want); |
|
|
116 | |
|
|
117 | sv_grow (sv, len); |
|
|
118 | } |
|
|
119 | |
|
|
120 | SvCUR_set (sv, want); |
|
|
121 | return SvEND (sv) - need; |
|
|
122 | } |
66 | |
123 | |
67 | static AV *texture_av; |
124 | static AV *texture_av; |
68 | |
125 | |
69 | static struct |
126 | static struct |
70 | { |
127 | { |
… | |
… | |
107 | av_push (texture_av, (SV *)(size_t)name); |
164 | av_push (texture_av, (SV *)(size_t)name); |
108 | glDeleteTextures (1, &name); |
165 | glDeleteTextures (1, &name); |
109 | } |
166 | } |
110 | |
167 | |
111 | #include "texcache.c" |
168 | #include "texcache.c" |
|
|
169 | #include "rendercache.c" |
112 | |
170 | |
113 | #include "pango-font.c" |
171 | #include "pango-font.c" |
114 | #include "pango-fontmap.c" |
172 | #include "pango-fontmap.c" |
115 | #include "pango-render.c" |
173 | #include "pango-render.c" |
116 | |
174 | |
|
|
175 | typedef IV DC__Channel; |
|
|
176 | typedef SDL_RWops *DC__RW; |
117 | typedef Mix_Chunk *CFPlus__MixChunk; |
177 | typedef Mix_Chunk *DC__MixChunk; |
118 | typedef Mix_Music *CFPlus__MixMusic; |
178 | typedef Mix_Music *DC__MixMusic; |
119 | |
179 | |
120 | typedef PangoFontDescription *CFPlus__Font; |
180 | typedef PangoFontDescription *DC__Font; |
121 | |
181 | |
122 | static int |
182 | static int |
123 | shape_attr_p (PangoLayoutRun *run) |
183 | shape_attr_p (PangoLayoutRun *run) |
124 | { |
184 | { |
125 | GSList *attrs = run->item->analysis.extra_attrs; |
185 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
139 | |
199 | |
140 | typedef struct cf_layout { |
200 | typedef struct cf_layout { |
141 | PangoLayout *pl; |
201 | PangoLayout *pl; |
142 | float r, g, b, a; // default color for rgba mode |
202 | float r, g, b, a; // default color for rgba mode |
143 | int base_height; |
203 | int base_height; |
144 | CFPlus__Font font; |
204 | DC__Font font; |
|
|
205 | rc_t *rc; |
145 | } *CFPlus__Layout; |
206 | } *DC__Layout; |
146 | |
207 | |
147 | static CFPlus__Font default_font; |
208 | static DC__Font default_font; |
148 | static PangoContext *opengl_context; |
209 | static PangoContext *opengl_context; |
149 | static PangoFontMap *opengl_fontmap; |
210 | static PangoFontMap *opengl_fontmap; |
150 | |
211 | |
151 | static void |
212 | static void |
152 | substitute_func (FcPattern *pattern, gpointer data) |
213 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
157 | #endif |
218 | #endif |
158 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
159 | } |
220 | } |
160 | |
221 | |
161 | static void |
222 | static void |
162 | layout_update_font (CFPlus__Layout self) |
223 | layout_update_font (DC__Layout self) |
163 | { |
224 | { |
164 | /* use a random scale factor to account for unknown descenders, 0.8 works |
225 | /* use a random scale factor to account for unknown descenders, 0.8 works |
165 | * reasonably well with bitstream vera |
226 | * reasonably well with dejavu/bistream fonts |
166 | */ |
227 | */ |
167 | PangoFontDescription *font = self->font ? self->font : default_font; |
228 | PangoFontDescription *font = self->font ? self->font : default_font; |
168 | |
229 | |
169 | pango_font_description_set_absolute_size (font, |
230 | pango_font_description_set_absolute_size (font, |
170 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
231 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
171 | |
232 | |
172 | pango_layout_set_font_description (self->pl, font); |
233 | pango_layout_set_font_description (self->pl, font); |
173 | } |
234 | } |
174 | |
235 | |
175 | static void |
236 | static void |
176 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
237 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
177 | { |
238 | { |
178 | PangoRectangle rect; |
239 | PangoRectangle rect; |
179 | |
240 | |
180 | // get_pixel_* wrongly rounds down |
241 | // get_pixel_* wrongly rounds down |
181 | pango_layout_get_extents (self->pl, 0, &rect); |
242 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
192 | |
253 | |
193 | typedef uint16_t tileid; |
254 | typedef uint16_t tileid; |
194 | typedef uint16_t faceid; |
255 | typedef uint16_t faceid; |
195 | |
256 | |
196 | typedef struct { |
257 | typedef struct { |
197 | int name; |
258 | GLuint name; |
198 | int w, h; |
259 | int w, h; |
199 | float s, t; |
260 | float s, t; |
200 | uint8_t r, g, b, a; |
261 | uint8_t r, g, b, a; |
201 | tileid smoothtile; |
262 | tileid smoothtile; |
202 | uint8_t smoothlevel; |
263 | uint8_t smoothlevel; |
|
|
264 | uint8_t unused; /* set to zero on use */ |
203 | } maptex; |
265 | } maptex; |
204 | |
266 | |
205 | typedef struct { |
267 | typedef struct { |
206 | uint32_t player; |
268 | uint32_t player; |
207 | tileid tile[3]; |
269 | tileid tile[3]; |
… | |
… | |
220 | int faces; tileid *face2tile; // [faceid] |
282 | int faces; tileid *face2tile; // [faceid] |
221 | int texs; maptex *tex; // [tileid] |
283 | int texs; maptex *tex; // [tileid] |
222 | |
284 | |
223 | int32_t rows; |
285 | int32_t rows; |
224 | maprow *row; |
286 | maprow *row; |
225 | } *CFPlus__Map; |
287 | } *DC__Map; |
226 | |
288 | |
227 | static char * |
289 | static char * |
228 | prepend (char *ptr, int sze, int inc) |
290 | prepend (char *ptr, int sze, int inc) |
229 | { |
291 | { |
230 | char *p; |
292 | char *p; |
… | |
… | |
268 | self->texs *= 2; |
330 | self->texs *= 2; |
269 | } |
331 | } |
270 | } |
332 | } |
271 | |
333 | |
272 | static maprow * |
334 | static maprow * |
273 | map_get_row (CFPlus__Map self, int y) |
335 | map_get_row (DC__Map self, int y) |
274 | { |
336 | { |
275 | if (0 > y) |
337 | if (0 > y) |
276 | { |
338 | { |
277 | int extend = - y + MAP_EXTEND_Y; |
339 | int extend = - y + MAP_EXTEND_Y; |
278 | Prepend (maprow, self->row, self->rows, extend); |
340 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
316 | |
378 | |
317 | return row->col + (x - row->c0); |
379 | return row->col + (x - row->c0); |
318 | } |
380 | } |
319 | |
381 | |
320 | static mapcell * |
382 | static mapcell * |
321 | map_get_cell (CFPlus__Map self, int x, int y) |
383 | map_get_cell (DC__Map self, int x, int y) |
322 | { |
384 | { |
323 | return row_get_cell (map_get_row (self, y), x); |
385 | return row_get_cell (map_get_row (self, y), x); |
324 | } |
386 | } |
325 | |
387 | |
326 | static void |
388 | static void |
327 | map_clear (CFPlus__Map self) |
389 | map_clear (DC__Map self) |
328 | { |
390 | { |
329 | int r; |
391 | int r; |
330 | |
392 | |
331 | for (r = 0; r < self->rows; r++) |
393 | for (r = 0; r < self->rows; r++) |
332 | Safefree (self->row[r].col); |
394 | Safefree (self->row[r].col); |
… | |
… | |
339 | self->oy = 0; |
401 | self->oy = 0; |
340 | self->row = 0; |
402 | self->row = 0; |
341 | self->rows = 0; |
403 | self->rows = 0; |
342 | } |
404 | } |
343 | |
405 | |
|
|
406 | #define CELL_CLEAR(cell) \ |
|
|
407 | do { \ |
|
|
408 | if ((cell)->player) \ |
|
|
409 | (cell)->tile [2] = 0; \ |
|
|
410 | (cell)->darkness = 0; \ |
|
|
411 | (cell)->stat_hp = 0; \ |
|
|
412 | (cell)->flags = 0; \ |
|
|
413 | (cell)->player = 0; \ |
|
|
414 | } while (0) |
|
|
415 | |
344 | static void |
416 | static void |
345 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
417 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
346 | { |
418 | { |
347 | int x, y; |
419 | int x, y; |
348 | maprow *row; |
420 | maprow *row; |
349 | mapcell *cell; |
421 | mapcell *cell; |
350 | |
422 | |
… | |
… | |
362 | if (x >= row->c1) |
434 | if (x >= row->c1) |
363 | break; |
435 | break; |
364 | |
436 | |
365 | cell = row->col + x - row->c0; |
437 | cell = row->col + x - row->c0; |
366 | |
438 | |
367 | cell->darkness = 0; |
439 | CELL_CLEAR (cell); |
368 | cell->stat_hp = 0; |
|
|
369 | cell->flags = 0; |
|
|
370 | cell->player = 0; |
|
|
371 | } |
440 | } |
372 | } |
441 | } |
373 | } |
442 | } |
374 | |
443 | |
375 | typedef struct { |
444 | typedef struct { |
… | |
… | |
410 | ev.code = 1; |
479 | ev.code = 1; |
411 | ev.data1 = (void *)(long)channel; |
480 | ev.data1 = (void *)(long)channel; |
412 | ev.data2 = 0; |
481 | ev.data2 = 0; |
413 | |
482 | |
414 | SDL_PushEvent ((SDL_Event *)&ev); |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
|
|
484 | } |
|
|
485 | |
|
|
486 | static unsigned int |
|
|
487 | div255 (unsigned int n) |
|
|
488 | { |
|
|
489 | return (n + (n >> 8)) >> 8; |
415 | } |
490 | } |
416 | |
491 | |
417 | static unsigned int |
492 | static unsigned int |
418 | minpot (unsigned int n) |
493 | minpot (unsigned int n) |
419 | { |
494 | { |
… | |
… | |
429 | n |= n >> 16; |
504 | n |= n >> 16; |
430 | |
505 | |
431 | return n + 1; |
506 | return n + 1; |
432 | } |
507 | } |
433 | |
508 | |
|
|
509 | static unsigned int |
|
|
510 | popcount (unsigned int n) |
|
|
511 | { |
|
|
512 | n -= (n >> 1) & 0x55555555U; |
|
|
513 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
514 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
515 | n *= 0x01010101U; |
|
|
516 | |
|
|
517 | return n >> 24; |
|
|
518 | } |
|
|
519 | |
434 | /* SDL should provide this, really. */ |
520 | /* SDL should provide this, really. */ |
435 | #define SDLK_MODIFIER_MIN 300 |
521 | #define SDLK_MODIFIER_MIN 300 |
436 | #define SDLK_MODIFIER_MAX 314 |
522 | #define SDLK_MODIFIER_MAX 314 |
437 | |
523 | |
438 | MODULE = CFPlus PACKAGE = CFPlus |
524 | /******************************************************************************/ |
|
|
525 | |
|
|
526 | static GV *draw_x_gv, *draw_y_gv, *draw_w_gv, *draw_h_gv; |
|
|
527 | static GV *hover_gv; |
|
|
528 | |
|
|
529 | static int |
|
|
530 | within_widget (SV *widget, NV x, NV y) |
|
|
531 | { |
|
|
532 | HV *self; |
|
|
533 | SV **svp; |
|
|
534 | NV wx, ww, wy, wh; |
|
|
535 | |
|
|
536 | if (!SvROK (widget)) |
|
|
537 | return 0; |
|
|
538 | |
|
|
539 | self = (HV *)SvRV (widget); |
|
|
540 | |
|
|
541 | if (SvTYPE (self) != SVt_PVHV) |
|
|
542 | return 0; |
|
|
543 | |
|
|
544 | svp = hv_fetch (self, "y", 1, 0); wy = svp ? SvNV (*svp) : 0.; |
|
|
545 | if (y < wy) |
|
|
546 | return 0; |
|
|
547 | |
|
|
548 | svp = hv_fetch (self, "h", 1, 0); wh = svp ? SvNV (*svp) : 0.; |
|
|
549 | if (y >= wy + wh) |
|
|
550 | return 0; |
|
|
551 | |
|
|
552 | svp = hv_fetch (self, "x", 1, 0); wx = svp ? SvNV (*svp) : 0.; |
|
|
553 | if (x < wx) |
|
|
554 | return 0; |
|
|
555 | |
|
|
556 | svp = hv_fetch (self, "w", 1, 0); ww = svp ? SvNV (*svp) : 0.; |
|
|
557 | if (x >= wx + ww) |
|
|
558 | return 0; |
|
|
559 | |
|
|
560 | svp = hv_fetch (self, "can_events", sizeof ("can_events") - 1, 0); |
|
|
561 | if (!svp || !SvTRUE (*svp)) |
|
|
562 | return 0; |
|
|
563 | |
|
|
564 | return 1; |
|
|
565 | } |
|
|
566 | |
|
|
567 | /******************************************************************************/ |
|
|
568 | |
|
|
569 | /* process keyboard modifiers */ |
|
|
570 | static int |
|
|
571 | mod_munge (int mod) |
|
|
572 | { |
|
|
573 | mod &= MOD_MASK; |
|
|
574 | |
|
|
575 | if (mod & (KMOD_META | KMOD_ALT)) |
|
|
576 | mod |= KMOD_LRAM; |
|
|
577 | |
|
|
578 | return mod; |
|
|
579 | } |
|
|
580 | |
|
|
581 | static void |
|
|
582 | deliantra_main (SV *real_main) |
|
|
583 | { |
|
|
584 | dSP; |
|
|
585 | |
|
|
586 | PUSHMARK (SP); |
|
|
587 | call_sv (real_main, G_DISCARD | G_VOID); |
|
|
588 | } |
|
|
589 | |
|
|
590 | #ifdef __MACOSX__ |
|
|
591 | static SV *real_main; |
|
|
592 | |
|
|
593 | /* to due surprising braindamage on the side of SDL design, we |
|
|
594 | * do some mind-boggling hack here: SDL requires a custom main() |
|
|
595 | * on OS X, so... we provide one and call the original main(), which, |
|
|
596 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
|
|
597 | * and which calls our main (== SDL_main) back. |
|
|
598 | */ |
|
|
599 | extern C_LINKAGE int |
|
|
600 | main (int argc, char *argv[]) |
|
|
601 | { |
|
|
602 | deliantra_main (real_main); |
|
|
603 | } |
|
|
604 | |
|
|
605 | #undef main |
|
|
606 | |
|
|
607 | extern C_LINKAGE int main (int argc, char *argv[]); |
|
|
608 | |
|
|
609 | static void |
|
|
610 | SDL_main_hack (SV *real_main_) |
|
|
611 | { |
|
|
612 | real_main = real_main; |
|
|
613 | |
|
|
614 | char *argv[] = { "deliantra client", 0 }; |
|
|
615 | (main) (1, argv); |
|
|
616 | } |
|
|
617 | #else |
|
|
618 | static void |
|
|
619 | SDL_main_hack (SV *real_main) |
|
|
620 | { |
|
|
621 | deliantra_main (real_main); |
|
|
622 | } |
|
|
623 | #endif |
|
|
624 | |
|
|
625 | MODULE = Deliantra::Client PACKAGE = DC |
439 | |
626 | |
440 | PROTOTYPES: ENABLE |
627 | PROTOTYPES: ENABLE |
441 | |
628 | |
442 | BOOT: |
629 | BOOT: |
443 | { |
630 | { |
444 | HV *stash = gv_stashpv ("CFPlus", 1); |
631 | HV *stash = gv_stashpv ("DC", 1); |
445 | static const struct { |
632 | static const struct { |
446 | const char *name; |
633 | const char *name; |
447 | IV iv; |
634 | IV iv; |
448 | } *civ, const_iv[] = { |
635 | } *civ, const_iv[] = { |
449 | # define const_iv(name) { # name, (IV)name } |
636 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
471 | |
658 | |
472 | const_iv (SDL_APPINPUTFOCUS), |
659 | const_iv (SDL_APPINPUTFOCUS), |
473 | const_iv (SDL_APPMOUSEFOCUS), |
660 | const_iv (SDL_APPMOUSEFOCUS), |
474 | const_iv (SDL_APPACTIVE), |
661 | const_iv (SDL_APPACTIVE), |
475 | |
662 | |
|
|
663 | |
|
|
664 | const_iv (SDLK_UNKNOWN), |
|
|
665 | const_iv (SDLK_FIRST), |
|
|
666 | const_iv (SDLK_BACKSPACE), |
|
|
667 | const_iv (SDLK_TAB), |
|
|
668 | const_iv (SDLK_CLEAR), |
|
|
669 | const_iv (SDLK_RETURN), |
|
|
670 | const_iv (SDLK_PAUSE), |
|
|
671 | const_iv (SDLK_ESCAPE), |
|
|
672 | const_iv (SDLK_SPACE), |
|
|
673 | const_iv (SDLK_EXCLAIM), |
|
|
674 | const_iv (SDLK_QUOTEDBL), |
|
|
675 | const_iv (SDLK_HASH), |
|
|
676 | const_iv (SDLK_DOLLAR), |
|
|
677 | const_iv (SDLK_AMPERSAND), |
|
|
678 | const_iv (SDLK_QUOTE), |
|
|
679 | const_iv (SDLK_LEFTPAREN), |
|
|
680 | const_iv (SDLK_RIGHTPAREN), |
|
|
681 | const_iv (SDLK_ASTERISK), |
|
|
682 | const_iv (SDLK_PLUS), |
|
|
683 | const_iv (SDLK_COMMA), |
|
|
684 | const_iv (SDLK_MINUS), |
|
|
685 | const_iv (SDLK_PERIOD), |
|
|
686 | const_iv (SDLK_SLASH), |
|
|
687 | const_iv (SDLK_0), |
|
|
688 | const_iv (SDLK_1), |
|
|
689 | const_iv (SDLK_2), |
|
|
690 | const_iv (SDLK_3), |
|
|
691 | const_iv (SDLK_4), |
|
|
692 | const_iv (SDLK_5), |
|
|
693 | const_iv (SDLK_6), |
|
|
694 | const_iv (SDLK_7), |
|
|
695 | const_iv (SDLK_8), |
|
|
696 | const_iv (SDLK_9), |
|
|
697 | const_iv (SDLK_COLON), |
|
|
698 | const_iv (SDLK_SEMICOLON), |
|
|
699 | const_iv (SDLK_LESS), |
|
|
700 | const_iv (SDLK_EQUALS), |
|
|
701 | const_iv (SDLK_GREATER), |
|
|
702 | const_iv (SDLK_QUESTION), |
|
|
703 | const_iv (SDLK_AT), |
|
|
704 | |
|
|
705 | const_iv (SDLK_LEFTBRACKET), |
|
|
706 | const_iv (SDLK_BACKSLASH), |
|
|
707 | const_iv (SDLK_RIGHTBRACKET), |
|
|
708 | const_iv (SDLK_CARET), |
|
|
709 | const_iv (SDLK_UNDERSCORE), |
|
|
710 | const_iv (SDLK_BACKQUOTE), |
|
|
711 | const_iv (SDLK_DELETE), |
|
|
712 | |
|
|
713 | const_iv (SDLK_FIRST), |
|
|
714 | const_iv (SDLK_LAST), |
476 | const_iv (SDLK_KP0), |
715 | const_iv (SDLK_KP0), |
477 | const_iv (SDLK_KP1), |
716 | const_iv (SDLK_KP1), |
478 | const_iv (SDLK_KP2), |
717 | const_iv (SDLK_KP2), |
479 | const_iv (SDLK_KP3), |
718 | const_iv (SDLK_KP3), |
480 | const_iv (SDLK_KP4), |
719 | const_iv (SDLK_KP4), |
… | |
… | |
552 | const_iv (KMOD_LMETA), |
791 | const_iv (KMOD_LMETA), |
553 | const_iv (KMOD_RMETA), |
792 | const_iv (KMOD_RMETA), |
554 | const_iv (KMOD_NUM), |
793 | const_iv (KMOD_NUM), |
555 | const_iv (KMOD_CAPS), |
794 | const_iv (KMOD_CAPS), |
556 | const_iv (KMOD_MODE), |
795 | const_iv (KMOD_MODE), |
|
|
796 | |
|
|
797 | const_iv (KMOD_LRAM), |
|
|
798 | |
|
|
799 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
800 | |
|
|
801 | const_iv (SDL_INIT_TIMER), |
|
|
802 | const_iv (SDL_INIT_AUDIO), |
|
|
803 | const_iv (SDL_INIT_VIDEO), |
|
|
804 | const_iv (SDL_INIT_CDROM), |
|
|
805 | const_iv (SDL_INIT_JOYSTICK), |
|
|
806 | const_iv (SDL_INIT_EVERYTHING), |
|
|
807 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
808 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
809 | |
|
|
810 | const_iv (SDL_GL_RED_SIZE), |
|
|
811 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
812 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
813 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
814 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
815 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
816 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
817 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
818 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
819 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
820 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
821 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
822 | const_iv (SDL_GL_STEREO), |
|
|
823 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
824 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
825 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
826 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
827 | |
|
|
828 | const_iv (FOW_DARKNESS) |
557 | # undef const_iv |
829 | # undef const_iv |
558 | }; |
830 | }; |
559 | |
831 | |
560 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
832 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
561 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
833 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
562 | |
834 | |
563 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
835 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
564 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
836 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
565 | } |
837 | } |
566 | |
838 | |
… | |
… | |
579 | |
851 | |
580 | NV floor (NV x) |
852 | NV floor (NV x) |
581 | |
853 | |
582 | NV ceil (NV x) |
854 | NV ceil (NV x) |
583 | |
855 | |
|
|
856 | IV minpot (UV n) |
|
|
857 | |
|
|
858 | IV popcount (UV n) |
|
|
859 | |
|
|
860 | NV distance (NV dx, NV dy) |
|
|
861 | CODE: |
|
|
862 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
|
|
863 | OUTPUT: |
|
|
864 | RETVAL |
|
|
865 | |
584 | void |
866 | void |
585 | pango_init () |
867 | pango_init () |
586 | CODE: |
868 | CODE: |
587 | { |
869 | { |
588 | opengl_fontmap = pango_opengl_font_map_new (); |
870 | opengl_fontmap = pango_opengl_font_map_new (); |
589 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
871 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
590 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
872 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
873 | /*pango_context_set_font_description (opengl_context, default_font);*/ |
|
|
874 | #if PANGO_VERSION_CHECK (1, 15, 2) |
|
|
875 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
876 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
877 | #endif |
591 | } |
878 | } |
592 | |
879 | |
593 | char * |
|
|
594 | SDL_GetError () |
880 | char *SDL_GetError () |
595 | |
881 | |
596 | int |
882 | void SDL_main_hack (SV *real_main) |
597 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
883 | PROTOTYPE: & |
598 | |
884 | |
599 | void |
885 | int SDL_Init (U32 flags) |
|
|
886 | |
|
|
887 | int SDL_InitSubSystem (U32 flags) |
|
|
888 | |
|
|
889 | void SDL_QuitSubSystem (U32 flags) |
|
|
890 | |
600 | SDL_Quit () |
891 | void SDL_Quit () |
|
|
892 | |
|
|
893 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
894 | |
|
|
895 | int SDL_GL_GetAttribute (int attr) |
|
|
896 | CODE: |
|
|
897 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
|
|
898 | XSRETURN_UNDEF; |
|
|
899 | OUTPUT: |
|
|
900 | RETVAL |
601 | |
901 | |
602 | void |
902 | void |
603 | SDL_ListModes (int rgb, int alpha) |
903 | SDL_ListModes (int rgb, int alpha) |
604 | PPCODE: |
904 | PPCODE: |
605 | { |
905 | { |
… | |
… | |
617 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
917 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
618 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
918 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
619 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
919 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
620 | |
920 | |
621 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
921 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
622 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
623 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
624 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
922 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
625 | #endif |
|
|
626 | |
923 | |
627 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
924 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
628 | |
925 | |
629 | if (m && m != (SDL_Rect **)-1) |
926 | if (m && m != (SDL_Rect **)-1) |
630 | while (*m) |
927 | while (*m) |
631 | { |
928 | { |
632 | if ((*m)->w >= 640 && (*m)->h >= 480) |
929 | if ((*m)->w >= 400 && (*m)->h >= 300) |
633 | { |
930 | { |
634 | AV *av = newAV (); |
931 | AV *av = newAV (); |
635 | av_push (av, newSViv ((*m)->w)); |
932 | av_push (av, newSViv ((*m)->w)); |
636 | av_push (av, newSViv ((*m)->h)); |
933 | av_push (av, newSViv ((*m)->h)); |
637 | av_push (av, newSViv (rgb)); |
934 | av_push (av, newSViv (rgb)); |
… | |
… | |
660 | ); |
957 | ); |
661 | |
958 | |
662 | if (RETVAL) |
959 | if (RETVAL) |
663 | { |
960 | { |
664 | av_clear (texture_av); |
961 | av_clear (texture_av); |
665 | |
|
|
666 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
|
|
667 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
962 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
668 | #include "glfunc.h" |
963 | #include "glfunc.h" |
669 | #undef GL_FUNC |
964 | #undef GL_FUNC |
|
|
965 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
|
|
966 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
670 | } |
967 | } |
671 | } |
968 | } |
672 | OUTPUT: |
969 | OUTPUT: |
673 | RETVAL |
970 | RETVAL |
674 | |
971 | |
675 | void |
972 | void |
|
|
973 | SDL_WM_SetCaption (const char *title, const char *icon) |
|
|
974 | |
|
|
975 | void |
676 | SDL_GL_SwapBuffers () |
976 | SDL_GL_SwapBuffers () |
677 | |
977 | |
678 | char * |
978 | char * |
679 | SDL_GetKeyName (int sym) |
979 | SDL_GetKeyName (int sym) |
680 | |
980 | |
681 | int |
981 | int |
682 | SDL_GetAppState () |
982 | SDL_GetAppState () |
683 | |
983 | |
|
|
984 | int |
|
|
985 | SDL_GetModState () |
|
|
986 | |
|
|
987 | int |
|
|
988 | SDL_WaitEvent () |
|
|
989 | C_ARGS: 0 |
|
|
990 | |
684 | void |
991 | void |
|
|
992 | SDL_PumpEvents () |
|
|
993 | |
|
|
994 | void |
685 | poll_events () |
995 | peep_events () |
686 | PPCODE: |
996 | PPCODE: |
687 | { |
997 | { |
688 | SDL_Event ev; |
998 | SDL_Event ev; |
689 | |
999 | |
690 | SDL_PumpEvents (); |
1000 | SDL_PumpEvents (); |
… | |
… | |
697 | { |
1007 | { |
698 | case SDL_KEYDOWN: |
1008 | case SDL_KEYDOWN: |
699 | case SDL_KEYUP: |
1009 | case SDL_KEYUP: |
700 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
1010 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
701 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
1011 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
702 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
1012 | hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0); |
703 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
1013 | hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */ |
704 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
1014 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
705 | break; |
1015 | break; |
706 | |
1016 | |
707 | case SDL_ACTIVEEVENT: |
1017 | case SDL_ACTIVEEVENT: |
708 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
1018 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
726 | x = ev.motion.x; |
1036 | x = ev.motion.x; |
727 | y = ev.motion.y; |
1037 | y = ev.motion.y; |
728 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
1038 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
729 | } |
1039 | } |
730 | |
1040 | |
731 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1041 | hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); |
732 | hv_store (hv, "state", 5, newSViv (state), 0); |
1042 | hv_store (hv, "state", 5, newSViv (state), 0); |
733 | hv_store (hv, "x", 1, newSViv (x), 0); |
1043 | hv_store (hv, "x", 1, newSViv (x), 0); |
734 | hv_store (hv, "y", 1, newSViv (y), 0); |
1044 | hv_store (hv, "y", 1, newSViv (y), 0); |
735 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
1045 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
736 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
1046 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
737 | } |
1047 | } |
738 | break; |
1048 | break; |
739 | |
1049 | |
740 | case SDL_MOUSEBUTTONDOWN: |
1050 | case SDL_MOUSEBUTTONDOWN: |
741 | case SDL_MOUSEBUTTONUP: |
1051 | case SDL_MOUSEBUTTONUP: |
742 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1052 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
743 | |
1053 | |
744 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
1054 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
745 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
1055 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
746 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
1056 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
747 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
1057 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
752 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
1062 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
753 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
1063 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
754 | break; |
1064 | break; |
755 | } |
1065 | } |
756 | |
1066 | |
757 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
1067 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
758 | } |
1068 | } |
759 | } |
1069 | } |
760 | |
1070 | |
|
|
1071 | char * |
|
|
1072 | SDL_AudioDriverName () |
|
|
1073 | CODE: |
|
|
1074 | { |
|
|
1075 | char buf [256]; |
|
|
1076 | if (!SDL_AudioDriverName (buf, sizeof (buf))) |
|
|
1077 | XSRETURN_UNDEF; |
|
|
1078 | |
|
|
1079 | RETVAL = buf; |
|
|
1080 | } |
|
|
1081 | OUTPUT: |
|
|
1082 | RETVAL |
|
|
1083 | |
761 | int |
1084 | int |
762 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
1085 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
763 | POSTCALL: |
1086 | POSTCALL: |
764 | Mix_HookMusicFinished (music_finished); |
1087 | Mix_HookMusicFinished (music_finished); |
765 | Mix_ChannelFinished (channel_finished); |
1088 | Mix_ChannelFinished (channel_finished); |
766 | |
1089 | |
767 | void |
1090 | void |
|
|
1091 | Mix_QuerySpec () |
|
|
1092 | PPCODE: |
|
|
1093 | { |
|
|
1094 | int freq, channels; |
|
|
1095 | Uint16 format; |
|
|
1096 | |
|
|
1097 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
1098 | { |
|
|
1099 | EXTEND (SP, 3); |
|
|
1100 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
1101 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
1102 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
1103 | } |
|
|
1104 | } |
|
|
1105 | |
|
|
1106 | void |
768 | Mix_CloseAudio () |
1107 | Mix_CloseAudio () |
769 | |
1108 | |
770 | int |
1109 | int |
771 | Mix_AllocateChannels (int numchans = -1) |
1110 | Mix_AllocateChannels (int numchans = -1) |
|
|
1111 | |
|
|
1112 | const char * |
|
|
1113 | Mix_GetError () |
772 | |
1114 | |
773 | void |
1115 | void |
774 | lowdelay (int fd, int val = 1) |
1116 | lowdelay (int fd, int val = 1) |
775 | CODE: |
1117 | CODE: |
776 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
1118 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
… | |
… | |
802 | } |
1144 | } |
803 | } |
1145 | } |
804 | #endif |
1146 | #endif |
805 | } |
1147 | } |
806 | |
1148 | |
807 | void |
1149 | int |
808 | add_font (char *file) |
1150 | add_font (char *file) |
809 | CODE: |
1151 | CODE: |
810 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1152 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
1153 | OUTPUT: |
|
|
1154 | RETVAL |
|
|
1155 | |
|
|
1156 | void |
|
|
1157 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
|
|
1158 | |
|
|
1159 | # MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s |
|
|
1160 | void |
|
|
1161 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) |
811 | |
1162 | |
812 | void |
1163 | void |
813 | load_image_inline (SV *image_) |
1164 | load_image_inline (SV *image_) |
814 | ALIAS: |
1165 | ALIAS: |
815 | load_image_file = 1 |
1166 | load_image_file = 1 |
… | |
… | |
818 | STRLEN image_len; |
1169 | STRLEN image_len; |
819 | char *image = (char *)SvPVbyte (image_, image_len); |
1170 | char *image = (char *)SvPVbyte (image_, image_len); |
820 | SDL_Surface *surface, *surface2; |
1171 | SDL_Surface *surface, *surface2; |
821 | SDL_PixelFormat fmt; |
1172 | SDL_PixelFormat fmt; |
822 | SDL_RWops *rw = ix |
1173 | SDL_RWops *rw = ix |
823 | ? SDL_RWFromFile (image, "r") |
1174 | ? SDL_RWFromFile (image, "rb") |
824 | : SDL_RWFromConstMem (image, image_len); |
1175 | : SDL_RWFromConstMem (image, image_len); |
825 | |
1176 | |
826 | if (!rw) |
1177 | if (!rw) |
827 | croak ("load_image: %s", SDL_GetError ()); |
1178 | croak ("load_image: %s", SDL_GetError ()); |
828 | |
1179 | |
… | |
… | |
901 | void |
1252 | void |
902 | error (char *message) |
1253 | error (char *message) |
903 | CODE: |
1254 | CODE: |
904 | fprintf (stderr, "ERROR: %s\n", message); |
1255 | fprintf (stderr, "ERROR: %s\n", message); |
905 | #ifdef _WIN32 |
1256 | #ifdef _WIN32 |
906 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
1257 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
907 | #endif |
1258 | #endif |
908 | |
1259 | |
909 | void |
1260 | void |
910 | fatal (char *message) |
1261 | fatal (char *message) |
911 | CODE: |
1262 | CODE: |
912 | fprintf (stderr, "FATAL: %s\n", message); |
1263 | fprintf (stderr, "FATAL: %s\n", message); |
913 | #ifdef _WIN32 |
1264 | #ifdef _WIN32 |
914 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1265 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
915 | #endif |
1266 | #endif |
916 | _exit (1); |
1267 | _exit (1); |
917 | |
1268 | |
918 | void |
1269 | void |
919 | _exit (int retval = 0) |
1270 | _exit (int retval = 0) |
… | |
… | |
931 | #if DEBUG |
1282 | #if DEBUG |
932 | VALGRIND_DO_LEAK_CHECK; |
1283 | VALGRIND_DO_LEAK_CHECK; |
933 | #endif |
1284 | #endif |
934 | } |
1285 | } |
935 | |
1286 | |
936 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1287 | int |
|
|
1288 | SvREFCNT (SV *sv) |
|
|
1289 | CODE: |
|
|
1290 | RETVAL = SvREFCNT (sv); |
|
|
1291 | OUTPUT: |
|
|
1292 | RETVAL |
|
|
1293 | |
|
|
1294 | MODULE = Deliantra::Client PACKAGE = DC::Font |
937 | |
1295 | |
938 | PROTOTYPES: DISABLE |
1296 | PROTOTYPES: DISABLE |
939 | |
1297 | |
940 | CFPlus::Font |
1298 | DC::Font |
941 | new_from_file (SV *class, char *path, int id = 0) |
1299 | new_from_file (SV *class, char *path, int id = 0) |
942 | CODE: |
1300 | CODE: |
943 | { |
1301 | { |
944 | int count; |
1302 | int count; |
945 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1303 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
948 | } |
1306 | } |
949 | OUTPUT: |
1307 | OUTPUT: |
950 | RETVAL |
1308 | RETVAL |
951 | |
1309 | |
952 | void |
1310 | void |
953 | DESTROY (CFPlus::Font self) |
1311 | DESTROY (DC::Font self) |
954 | CODE: |
1312 | CODE: |
955 | pango_font_description_free (self); |
1313 | pango_font_description_free (self); |
956 | |
1314 | |
957 | void |
1315 | void |
958 | make_default (CFPlus::Font self) |
1316 | make_default (DC::Font self) |
959 | PROTOTYPE: $ |
1317 | PROTOTYPE: $ |
960 | CODE: |
1318 | CODE: |
961 | default_font = self; |
1319 | default_font = self; |
962 | |
1320 | |
963 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1321 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
964 | |
1322 | |
965 | PROTOTYPES: DISABLE |
1323 | PROTOTYPES: DISABLE |
966 | |
1324 | |
967 | void |
1325 | void |
968 | reset_glyph_cache () |
1326 | glyph_cache_backup () |
969 | PROTOTYPE: |
1327 | PROTOTYPE: |
970 | CODE: |
1328 | CODE: |
|
|
1329 | tc_backup (); |
|
|
1330 | |
|
|
1331 | void |
|
|
1332 | glyph_cache_restore () |
|
|
1333 | PROTOTYPE: |
|
|
1334 | CODE: |
971 | tc_clear (); |
1335 | tc_restore (); |
972 | |
1336 | |
973 | CFPlus::Layout |
1337 | DC::Layout |
974 | new (SV *class) |
1338 | new (SV *class) |
975 | CODE: |
1339 | CODE: |
976 | New (0, RETVAL, 1, struct cf_layout); |
1340 | New (0, RETVAL, 1, struct cf_layout); |
977 | |
1341 | |
978 | RETVAL->pl = pango_layout_new (opengl_context); |
1342 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
980 | RETVAL->g = 1.; |
1344 | RETVAL->g = 1.; |
981 | RETVAL->b = 1.; |
1345 | RETVAL->b = 1.; |
982 | RETVAL->a = 1.; |
1346 | RETVAL->a = 1.; |
983 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1347 | RETVAL->base_height = MIN_FONT_HEIGHT; |
984 | RETVAL->font = 0; |
1348 | RETVAL->font = 0; |
|
|
1349 | RETVAL->rc = rc_alloc (); |
985 | |
1350 | |
986 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1351 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
987 | layout_update_font (RETVAL); |
1352 | layout_update_font (RETVAL); |
988 | OUTPUT: |
1353 | OUTPUT: |
989 | RETVAL |
1354 | RETVAL |
990 | |
1355 | |
991 | void |
1356 | void |
992 | DESTROY (CFPlus::Layout self) |
1357 | DESTROY (DC::Layout self) |
993 | CODE: |
1358 | CODE: |
994 | g_object_unref (self->pl); |
1359 | g_object_unref (self->pl); |
|
|
1360 | rc_free (self->rc); |
995 | Safefree (self); |
1361 | Safefree (self); |
996 | |
1362 | |
997 | void |
1363 | void |
998 | set_text (CFPlus::Layout self, SV *text_) |
1364 | set_text (DC::Layout self, SV *text_) |
999 | CODE: |
1365 | CODE: |
1000 | { |
1366 | { |
1001 | STRLEN textlen; |
1367 | STRLEN textlen; |
1002 | char *text = SvPVutf8 (text_, textlen); |
1368 | char *text = SvPVutf8 (text_, textlen); |
1003 | |
1369 | |
1004 | pango_layout_set_text (self->pl, text, textlen); |
1370 | pango_layout_set_text (self->pl, text, textlen); |
1005 | } |
1371 | } |
1006 | |
1372 | |
1007 | void |
1373 | void |
1008 | set_markup (CFPlus::Layout self, SV *text_) |
1374 | set_markup (DC::Layout self, SV *text_) |
1009 | CODE: |
1375 | CODE: |
1010 | { |
1376 | { |
1011 | STRLEN textlen; |
1377 | STRLEN textlen; |
1012 | char *text = SvPVutf8 (text_, textlen); |
1378 | char *text = SvPVutf8 (text_, textlen); |
1013 | |
1379 | |
1014 | pango_layout_set_markup (self->pl, text, textlen); |
1380 | pango_layout_set_markup (self->pl, text, textlen); |
1015 | } |
1381 | } |
1016 | |
1382 | |
1017 | void |
1383 | void |
1018 | set_shapes (CFPlus::Layout self, ...) |
1384 | set_shapes (DC::Layout self, ...) |
1019 | CODE: |
1385 | CODE: |
1020 | { |
1386 | { |
1021 | PangoAttrList *attrs = 0; |
1387 | PangoAttrList *attrs = 0; |
1022 | const char *text = pango_layout_get_text (self->pl); |
1388 | const char *text = pango_layout_get_text (self->pl); |
1023 | const char *pos = text; |
1389 | const char *pos = text; |
… | |
… | |
1058 | if (attrs) |
1424 | if (attrs) |
1059 | pango_layout_set_attributes (self->pl, attrs); |
1425 | pango_layout_set_attributes (self->pl, attrs); |
1060 | } |
1426 | } |
1061 | |
1427 | |
1062 | void |
1428 | void |
1063 | get_shapes (CFPlus::Layout self) |
1429 | get_shapes (DC::Layout self) |
1064 | PPCODE: |
1430 | PPCODE: |
1065 | { |
1431 | { |
1066 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1432 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1067 | |
1433 | |
1068 | do |
1434 | do |
1069 | { |
1435 | { |
1070 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1436 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1071 | |
1437 | |
1072 | if (run && shape_attr_p (run)) |
1438 | if (run && shape_attr_p (run)) |
1073 | { |
1439 | { |
1074 | PangoRectangle extents; |
1440 | PangoRectangle extents; |
1075 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1441 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1083 | |
1449 | |
1084 | pango_layout_iter_free (iter); |
1450 | pango_layout_iter_free (iter); |
1085 | } |
1451 | } |
1086 | |
1452 | |
1087 | int |
1453 | int |
1088 | has_wrapped (CFPlus::Layout self) |
1454 | has_wrapped (DC::Layout self) |
1089 | CODE: |
1455 | CODE: |
1090 | { |
1456 | { |
1091 | int lines = 1; |
1457 | int lines = 1; |
1092 | const char *text = pango_layout_get_text (self->pl); |
1458 | const char *text = pango_layout_get_text (self->pl); |
1093 | |
1459 | |
… | |
… | |
1098 | } |
1464 | } |
1099 | OUTPUT: |
1465 | OUTPUT: |
1100 | RETVAL |
1466 | RETVAL |
1101 | |
1467 | |
1102 | SV * |
1468 | SV * |
1103 | get_text (CFPlus::Layout self) |
1469 | get_text (DC::Layout self) |
1104 | CODE: |
1470 | CODE: |
1105 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1471 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1106 | sv_utf8_decode (RETVAL); |
1472 | sv_utf8_decode (RETVAL); |
1107 | OUTPUT: |
1473 | OUTPUT: |
1108 | RETVAL |
1474 | RETVAL |
1109 | |
1475 | |
1110 | void |
1476 | void |
1111 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1477 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1112 | CODE: |
1478 | CODE: |
1113 | self->r = r; |
1479 | self->r = r; |
1114 | self->g = g; |
1480 | self->g = g; |
1115 | self->b = b; |
1481 | self->b = b; |
1116 | self->a = a; |
1482 | self->a = a; |
1117 | |
1483 | |
1118 | void |
1484 | void |
1119 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1485 | set_font (DC::Layout self, DC::Font font = 0) |
1120 | CODE: |
1486 | CODE: |
1121 | if (self->font != font) |
1487 | if (self->font != font) |
1122 | { |
1488 | { |
1123 | self->font = font; |
1489 | self->font = font; |
1124 | layout_update_font (self); |
1490 | layout_update_font (self); |
1125 | } |
1491 | } |
1126 | |
1492 | |
1127 | void |
1493 | void |
1128 | set_height (CFPlus::Layout self, int base_height) |
1494 | set_height (DC::Layout self, int base_height) |
1129 | CODE: |
1495 | CODE: |
1130 | if (self->base_height != base_height) |
1496 | if (self->base_height != base_height) |
1131 | { |
1497 | { |
1132 | self->base_height = base_height; |
1498 | self->base_height = base_height; |
1133 | layout_update_font (self); |
1499 | layout_update_font (self); |
1134 | } |
1500 | } |
1135 | |
1501 | |
1136 | void |
1502 | void |
1137 | set_width (CFPlus::Layout self, int max_width = -1) |
1503 | set_width (DC::Layout self, int max_width = -1) |
1138 | CODE: |
1504 | CODE: |
1139 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1505 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1140 | |
1506 | |
1141 | void |
1507 | void |
1142 | set_indent (CFPlus::Layout self, int indent) |
1508 | set_indent (DC::Layout self, int indent) |
1143 | CODE: |
1509 | CODE: |
1144 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1510 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1145 | |
1511 | |
1146 | void |
1512 | void |
1147 | set_spacing (CFPlus::Layout self, int spacing) |
1513 | set_spacing (DC::Layout self, int spacing) |
1148 | CODE: |
1514 | CODE: |
1149 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1515 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1150 | |
1516 | |
1151 | void |
1517 | void |
1152 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1518 | set_ellipsise (DC::Layout self, int ellipsise) |
1153 | CODE: |
1519 | CODE: |
1154 | pango_layout_set_ellipsize (self->pl, |
1520 | pango_layout_set_ellipsize (self->pl, |
1155 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1521 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1156 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1522 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1157 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1523 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1158 | : PANGO_ELLIPSIZE_NONE |
1524 | : PANGO_ELLIPSIZE_NONE |
1159 | ); |
1525 | ); |
1160 | |
1526 | |
1161 | void |
1527 | void |
1162 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1528 | set_single_paragraph_mode (DC::Layout self, int spm) |
1163 | CODE: |
1529 | CODE: |
1164 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1530 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1165 | |
1531 | |
1166 | void |
1532 | void |
1167 | size (CFPlus::Layout self) |
1533 | size (DC::Layout self) |
1168 | PPCODE: |
1534 | PPCODE: |
1169 | { |
1535 | { |
1170 | int w, h; |
1536 | int w, h; |
1171 | |
1537 | |
1172 | layout_get_pixel_size (self, &w, &h); |
1538 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1175 | PUSHs (sv_2mortal (newSViv (w))); |
1541 | PUSHs (sv_2mortal (newSViv (w))); |
1176 | PUSHs (sv_2mortal (newSViv (h))); |
1542 | PUSHs (sv_2mortal (newSViv (h))); |
1177 | } |
1543 | } |
1178 | |
1544 | |
1179 | int |
1545 | int |
1180 | descent (CFPlus::Layout self) |
1546 | descent (DC::Layout self) |
1181 | CODE: |
1547 | CODE: |
1182 | { |
1548 | { |
1183 | PangoRectangle rect; |
1549 | PangoRectangle rect; |
1184 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1550 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1185 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1551 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1186 | RETVAL = PANGO_DESCENT (rect); |
1552 | RETVAL = PANGO_DESCENT (rect); |
1187 | } |
1553 | } |
1188 | OUTPUT: |
1554 | OUTPUT: |
1189 | RETVAL |
1555 | RETVAL |
1190 | |
1556 | |
1191 | int |
1557 | int |
1192 | xy_to_index (CFPlus::Layout self, int x, int y) |
1558 | xy_to_index (DC::Layout self, int x, int y) |
1193 | CODE: |
1559 | CODE: |
1194 | { |
1560 | { |
1195 | int index, trailing; |
1561 | int index, trailing; |
1196 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1562 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1197 | RETVAL = index + trailing; |
1563 | RETVAL = index + trailing; |
1198 | } |
1564 | } |
1199 | OUTPUT: |
1565 | OUTPUT: |
1200 | RETVAL |
1566 | RETVAL |
1201 | |
1567 | |
1202 | void |
1568 | void |
1203 | cursor_pos (CFPlus::Layout self, int index) |
1569 | cursor_pos (DC::Layout self, int index) |
1204 | PPCODE: |
1570 | PPCODE: |
1205 | { |
1571 | { |
1206 | PangoRectangle strong_pos; |
1572 | PangoRectangle pos; |
1207 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1573 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1208 | |
1574 | |
1209 | EXTEND (SP, 3); |
1575 | EXTEND (SP, 3); |
1210 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1576 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1211 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1577 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1212 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1578 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1213 | } |
1579 | } |
1214 | |
1580 | |
1215 | void |
1581 | void |
1216 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1582 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1217 | PPCODE: |
1583 | PPCODE: |
1218 | { |
1584 | { |
1219 | int line, x; |
1585 | int line, x; |
1220 | |
1586 | |
1221 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1587 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1588 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1222 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1589 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1223 | |
1590 | --line; |
|
|
1591 | #endif |
1224 | EXTEND (SP, 2); |
1592 | EXTEND (SP, 2); |
1225 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1593 | PUSHs (sv_2mortal (newSViv (line))); |
1226 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1594 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1227 | } |
1595 | } |
1228 | |
1596 | |
1229 | void |
1597 | void |
1230 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1598 | line_x_to_index (DC::Layout self, int line, int x) |
1231 | PPCODE: |
1599 | PPCODE: |
1232 | { |
1600 | { |
1233 | PangoLayoutLine *lp; |
1601 | PangoLayoutLine *lp; |
1234 | int index, trailing; |
1602 | int index, trailing; |
1235 | |
1603 | |
1236 | if (line < 0) |
1604 | if (line < 0) |
1237 | XSRETURN_EMPTY; |
1605 | XSRETURN_EMPTY; |
1238 | |
1606 | |
1239 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1607 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1240 | XSRETURN_EMPTY; /* do better */ |
1608 | XSRETURN_EMPTY; /* do better */ |
1241 | |
1609 | |
1242 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1610 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1243 | |
1611 | |
1244 | EXTEND (SP, 2); |
1612 | EXTEND (SP, 2); |
… | |
… | |
1250 | PUSHs (sv_2mortal (newSViv (trailing))); |
1618 | PUSHs (sv_2mortal (newSViv (trailing))); |
1251 | } |
1619 | } |
1252 | } |
1620 | } |
1253 | |
1621 | |
1254 | void |
1622 | void |
1255 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1623 | render (DC::Layout self, float x, float y, int flags = 0) |
1256 | PPCODE: |
1624 | CODE: |
|
|
1625 | rc_clear (self->rc); |
1257 | pango_opengl_render_layout_subpixel ( |
1626 | pango_opengl_render_layout_subpixel ( |
1258 | self->pl, |
1627 | self->pl, |
|
|
1628 | self->rc, |
1259 | x * PANGO_SCALE, y * PANGO_SCALE, |
1629 | x * PANGO_SCALE, y * PANGO_SCALE, |
1260 | self->r, self->g, self->b, self->a, |
1630 | self->r, self->g, self->b, self->a, |
1261 | flags |
1631 | flags |
1262 | ); |
1632 | ); |
|
|
1633 | // we assume that context_change actually clears/frees stuff |
|
|
1634 | // and does not do any recomputation... |
|
|
1635 | pango_layout_context_changed (self->pl); |
1263 | |
1636 | |
1264 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1637 | void |
|
|
1638 | draw (DC::Layout self) |
|
|
1639 | CODE: |
|
|
1640 | { |
|
|
1641 | glEnable (GL_TEXTURE_2D); |
|
|
1642 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1643 | glEnable (GL_BLEND); |
|
|
1644 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1645 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1646 | glEnable (GL_ALPHA_TEST); |
|
|
1647 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1648 | |
|
|
1649 | rc_draw (self->rc); |
|
|
1650 | |
|
|
1651 | glDisable (GL_ALPHA_TEST); |
|
|
1652 | glDisable (GL_BLEND); |
|
|
1653 | glDisable (GL_TEXTURE_2D); |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1265 | |
1657 | |
1266 | PROTOTYPES: ENABLE |
1658 | PROTOTYPES: ENABLE |
1267 | |
|
|
1268 | int minpot (int n) |
|
|
1269 | |
1659 | |
1270 | void |
1660 | void |
1271 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1661 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1272 | CODE: |
1662 | CODE: |
1273 | { |
1663 | { |
… | |
… | |
1300 | HV *hv = (HV *)SvRV (self); |
1690 | HV *hv = (HV *)SvRV (self); |
1301 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1691 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1302 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1692 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1303 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1693 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1304 | |
1694 | |
|
|
1695 | if (name <= 0) |
|
|
1696 | XSRETURN_EMPTY; |
|
|
1697 | |
1305 | if (items < 5) |
1698 | if (items < 5) |
1306 | { |
1699 | { |
1307 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1700 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1308 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1701 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1309 | } |
1702 | } |
… | |
… | |
1336 | glDisable (GL_ALPHA_TEST); |
1729 | glDisable (GL_ALPHA_TEST); |
1337 | glDisable (GL_BLEND); |
1730 | glDisable (GL_BLEND); |
1338 | } |
1731 | } |
1339 | } |
1732 | } |
1340 | |
1733 | |
|
|
1734 | void |
|
|
1735 | 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) |
|
|
1736 | PROTOTYPE: @ |
|
|
1737 | CODE: |
|
|
1738 | { |
|
|
1739 | glEnable (GL_BLEND); |
|
|
1740 | glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1741 | glEnable (GL_TEXTURE_2D); |
|
|
1742 | glBindTexture (GL_TEXTURE_2D, name1); |
|
|
1743 | |
|
|
1744 | glColor3f (intensity, intensity, intensity); |
|
|
1745 | glPushMatrix (); |
|
|
1746 | glScalef (1./3, 1./3, 1.); |
|
|
1747 | |
|
|
1748 | if (blend > 0.f) |
|
|
1749 | { |
|
|
1750 | float dx3 = dx * -3.f / w; |
|
|
1751 | float dy3 = dy * -3.f / h; |
|
|
1752 | GLfloat env_color[4] = { 0., 0., 0., blend }; |
|
|
1753 | |
|
|
1754 | /* interpolate the two shadow textures */ |
|
|
1755 | /* stage 0 == rgb(glcolor) + alpha(t0) */ |
|
|
1756 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1757 | |
|
|
1758 | /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */ |
|
|
1759 | gl.ActiveTexture (GL_TEXTURE1); |
|
|
1760 | glEnable (GL_TEXTURE_2D); |
|
|
1761 | glBindTexture (GL_TEXTURE_2D, name2); |
|
|
1762 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); |
|
|
1763 | |
|
|
1764 | /* rgb == rgb(glcolor) */ |
|
|
1765 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); |
|
|
1766 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR); |
|
|
1767 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
|
|
1768 | |
|
|
1769 | /* alpha = interpolate t0, t1 by env_alpha */ |
|
|
1770 | glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color); |
|
|
1771 | |
|
|
1772 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); |
|
|
1773 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); |
|
|
1774 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); |
|
|
1775 | |
|
|
1776 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); |
|
|
1777 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); |
|
|
1778 | |
|
|
1779 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); |
|
|
1780 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); |
|
|
1781 | |
|
|
1782 | glBegin (GL_QUADS); |
|
|
1783 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0); |
|
|
1784 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h); |
|
|
1785 | gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h); |
|
|
1786 | gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0); |
|
|
1787 | glEnd (); |
|
|
1788 | |
|
|
1789 | glDisable (GL_TEXTURE_2D); |
|
|
1790 | gl.ActiveTexture (GL_TEXTURE0); |
|
|
1791 | } |
|
|
1792 | else |
|
|
1793 | { |
|
|
1794 | /* simple blending of one texture, also opengl <1.3 path */ |
|
|
1795 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1796 | |
|
|
1797 | glBegin (GL_QUADS); |
|
|
1798 | glTexCoord2f (0, 0); glVertex2f (0, 0); |
|
|
1799 | glTexCoord2f (0, t); glVertex2f (0, h); |
|
|
1800 | glTexCoord2f (s, t); glVertex2f (w, h); |
|
|
1801 | glTexCoord2f (s, 0); glVertex2f (w, 0); |
|
|
1802 | glEnd (); |
|
|
1803 | } |
|
|
1804 | |
|
|
1805 | /* draw ?-marks or equivalent, this is very clumsy code :/ */ |
|
|
1806 | { |
|
|
1807 | int x, y; |
|
|
1808 | int dx3 = dx * 3; |
|
|
1809 | int dy3 = dy * 3; |
|
|
1810 | |
|
|
1811 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1812 | glBindTexture (GL_TEXTURE_2D, hidden_tex); |
|
|
1813 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1814 | glTranslatef (-1., -1., 0); |
|
|
1815 | glBegin (GL_QUADS); |
|
|
1816 | |
|
|
1817 | for (y = 1; y < h; y += 3) |
|
|
1818 | { |
|
|
1819 | int y1 = y - dy3; |
|
|
1820 | int y1valid = y1 >= 0 && y1 < h; |
|
|
1821 | |
|
|
1822 | for (x = 1; x < w; x += 3) |
|
|
1823 | { |
|
|
1824 | int x1 = x - dx3; |
|
|
1825 | uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1826 | uint8_t h2; |
|
|
1827 | |
|
|
1828 | if (y1valid && x1 >= 0 && x1 < w) |
|
|
1829 | h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1830 | else |
|
|
1831 | h2 = 1; /* out of range == invisible */ |
|
|
1832 | |
|
|
1833 | if (h1 || h2) |
|
|
1834 | { |
|
|
1835 | float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend; |
|
|
1836 | glColor4f (1., 1., 1., alpha); |
|
|
1837 | |
|
|
1838 | glTexCoord2f (0, 0.); glVertex2i (x , y ); |
|
|
1839 | glTexCoord2f (0, 1.); glVertex2i (x , y + 3); |
|
|
1840 | glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3); |
|
|
1841 | glTexCoord2f (1, 0.); glVertex2i (x + 3, y ); |
|
|
1842 | } |
|
|
1843 | } |
|
|
1844 | } |
|
|
1845 | } |
|
|
1846 | |
|
|
1847 | glEnd (); |
|
|
1848 | |
|
|
1849 | glPopMatrix (); |
|
|
1850 | |
|
|
1851 | glDisable (GL_TEXTURE_2D); |
|
|
1852 | glDisable (GL_BLEND); |
|
|
1853 | } |
|
|
1854 | |
1341 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1855 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1342 | CODE: |
1856 | CODE: |
1343 | { |
1857 | { |
1344 | GLint width; |
1858 | GLint width; |
1345 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
1859 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
… | |
… | |
1347 | RETVAL = width > 0; |
1861 | RETVAL = width > 0; |
1348 | } |
1862 | } |
1349 | OUTPUT: |
1863 | OUTPUT: |
1350 | RETVAL |
1864 | RETVAL |
1351 | |
1865 | |
1352 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1866 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1353 | |
1867 | |
1354 | PROTOTYPES: DISABLE |
1868 | PROTOTYPES: DISABLE |
1355 | |
1869 | |
1356 | CFPlus::Map |
1870 | DC::Map |
1357 | new (SV *class) |
1871 | new (SV *class) |
1358 | CODE: |
1872 | CODE: |
1359 | New (0, RETVAL, 1, struct map); |
1873 | New (0, RETVAL, 1, struct map); |
1360 | RETVAL->x = 0; |
1874 | RETVAL->x = 0; |
1361 | RETVAL->y = 0; |
1875 | RETVAL->y = 0; |
… | |
… | |
1369 | RETVAL->row = 0; |
1883 | RETVAL->row = 0; |
1370 | OUTPUT: |
1884 | OUTPUT: |
1371 | RETVAL |
1885 | RETVAL |
1372 | |
1886 | |
1373 | void |
1887 | void |
1374 | DESTROY (CFPlus::Map self) |
1888 | DESTROY (DC::Map self) |
1375 | CODE: |
1889 | CODE: |
1376 | { |
1890 | { |
1377 | map_clear (self); |
1891 | map_clear (self); |
1378 | Safefree (self->face2tile); |
1892 | Safefree (self->face2tile); |
1379 | Safefree (self->tex); |
1893 | Safefree (self->tex); |
1380 | Safefree (self); |
1894 | Safefree (self); |
1381 | } |
1895 | } |
1382 | |
1896 | |
1383 | void |
1897 | void |
1384 | resize (CFPlus::Map self, int map_width, int map_height) |
1898 | resize (DC::Map self, int map_width, int map_height) |
1385 | CODE: |
1899 | CODE: |
1386 | self->w = map_width; |
1900 | self->w = map_width; |
1387 | self->h = map_height; |
1901 | self->h = map_height; |
1388 | |
1902 | |
1389 | void |
1903 | void |
1390 | clear (CFPlus::Map self) |
1904 | clear (DC::Map self) |
1391 | CODE: |
1905 | CODE: |
1392 | map_clear (self); |
1906 | map_clear (self); |
1393 | |
1907 | |
1394 | void |
1908 | void |
1395 | set_tileid (CFPlus::Map self, int face, int tile) |
1909 | set_tileid (DC::Map self, int face, int tile) |
1396 | CODE: |
1910 | CODE: |
1397 | { |
1911 | { |
1398 | need_facenum (self, face); self->face2tile [face] = tile; |
1912 | need_facenum (self, face); self->face2tile [face] = tile; |
1399 | need_texid (self, tile); |
1913 | need_texid (self, tile); |
1400 | } |
1914 | } |
1401 | |
1915 | |
1402 | void |
1916 | void |
1403 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1917 | set_smooth (DC::Map self, int face, int smooth, int level) |
1404 | CODE: |
1918 | CODE: |
1405 | { |
1919 | { |
1406 | tileid texid; |
1920 | tileid texid; |
1407 | maptex *tex; |
1921 | maptex *tex; |
1408 | |
1922 | |
… | |
… | |
1421 | tex->smoothtile = self->face2tile [smooth]; |
1935 | tex->smoothtile = self->face2tile [smooth]; |
1422 | tex->smoothlevel = level; |
1936 | tex->smoothlevel = level; |
1423 | } |
1937 | } |
1424 | |
1938 | |
1425 | void |
1939 | void |
1426 | 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) |
1940 | 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) |
1427 | CODE: |
1941 | CODE: |
1428 | { |
1942 | { |
1429 | need_texid (self, texid); |
1943 | need_texid (self, texid); |
1430 | |
1944 | |
1431 | { |
1945 | { |
… | |
… | |
1450 | // use uglier nearest interpolation because linear suffers |
1964 | // use uglier nearest interpolation because linear suffers |
1451 | // from transparent color bleeding and ugly wrapping effects. |
1965 | // from transparent color bleeding and ugly wrapping effects. |
1452 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1966 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1453 | } |
1967 | } |
1454 | |
1968 | |
|
|
1969 | void |
|
|
1970 | expire_textures (DC::Map self, int texid, int count) |
|
|
1971 | PPCODE: |
|
|
1972 | for (; texid < self->texs && count; ++texid, --count) |
|
|
1973 | { |
|
|
1974 | maptex *tex = self->tex + texid; |
|
|
1975 | |
|
|
1976 | if (tex->name) |
|
|
1977 | { |
|
|
1978 | if (tex->unused) |
|
|
1979 | { |
|
|
1980 | tex->name = 0; |
|
|
1981 | tex->unused = 0; |
|
|
1982 | XPUSHs (sv_2mortal (newSViv (texid))); |
|
|
1983 | } |
|
|
1984 | else |
|
|
1985 | tex->unused = 1; |
|
|
1986 | } |
|
|
1987 | } |
|
|
1988 | |
1455 | int |
1989 | int |
1456 | ox (CFPlus::Map self) |
1990 | ox (DC::Map self) |
1457 | ALIAS: |
1991 | ALIAS: |
1458 | oy = 1 |
1992 | oy = 1 |
1459 | x = 2 |
1993 | x = 2 |
1460 | y = 3 |
1994 | y = 3 |
1461 | w = 4 |
1995 | w = 4 |
… | |
… | |
1472 | } |
2006 | } |
1473 | OUTPUT: |
2007 | OUTPUT: |
1474 | RETVAL |
2008 | RETVAL |
1475 | |
2009 | |
1476 | void |
2010 | void |
1477 | scroll (CFPlus::Map self, int dx, int dy) |
2011 | scroll (DC::Map self, int dx, int dy) |
1478 | CODE: |
2012 | CODE: |
1479 | { |
2013 | { |
1480 | if (dx > 0) |
2014 | if (dx > 0) |
1481 | map_blank (self, self->x, self->y, dx, self->h); |
2015 | map_blank (self, self->x, self->y, dx, self->h); |
1482 | else if (dx < 0) |
2016 | else if (dx < 0) |
… | |
… | |
1497 | self->rows += MAP_EXTEND_Y; |
2031 | self->rows += MAP_EXTEND_Y; |
1498 | self->y += MAP_EXTEND_Y; |
2032 | self->y += MAP_EXTEND_Y; |
1499 | } |
2033 | } |
1500 | } |
2034 | } |
1501 | |
2035 | |
1502 | void |
2036 | SV * |
1503 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
2037 | map1a_update (DC::Map self, SV *data_, int extmap) |
1504 | CODE: |
2038 | CODE: |
1505 | { |
2039 | { |
1506 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2040 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1507 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2041 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1508 | mapcell *cell; |
2042 | mapcell *cell; |
1509 | int x, y, flags; |
2043 | int x, y, z, flags; |
|
|
2044 | AV *missing = newAV (); |
|
|
2045 | RETVAL = newRV_noinc ((SV *)missing); |
1510 | |
2046 | |
1511 | while (data < data_end - 1) |
2047 | while (data < data_end - 1) |
1512 | { |
2048 | { |
1513 | flags = (data [0] << 8) + data [1]; data += 2; |
2049 | flags = (data [0] << 8) + data [1]; data += 2; |
1514 | |
2050 | |
… | |
… | |
1534 | uint8_t ext, cmd; |
2070 | uint8_t ext, cmd; |
1535 | |
2071 | |
1536 | do |
2072 | do |
1537 | { |
2073 | { |
1538 | ext = *data++; |
2074 | ext = *data++; |
1539 | cmd = ext & 0x3f; |
2075 | cmd = ext & 0x7f; |
1540 | |
2076 | |
1541 | if (cmd < 4) |
2077 | if (cmd < 4) |
1542 | cell->darkness = 255 - ext * 64 + 1; |
2078 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
1543 | else if (cmd == 5) // health |
2079 | else if (cmd == 5) // health |
1544 | { |
2080 | { |
1545 | cell->stat_width = 1; |
2081 | cell->stat_width = 1; |
1546 | cell->stat_hp = *data++; |
2082 | cell->stat_hp = *data++; |
1547 | } |
2083 | } |
1548 | else if (cmd == 6) // monster width |
2084 | else if (cmd == 6) // monster width |
1549 | cell->stat_width = *data++ + 1; |
2085 | cell->stat_width = *data++ + 1; |
1550 | else if (cmd == 0x47) |
2086 | else if (cmd == 0x47) |
1551 | { |
2087 | { |
1552 | if (*data == 4) |
2088 | if (*data == 1) cell->player = data [1]; |
1553 | ; // decode player count |
2089 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2090 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2091 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
1554 | |
2092 | |
1555 | data += *data + 1; |
2093 | data += *data + 1; |
1556 | } |
2094 | } |
1557 | else if (cmd == 8) // cell flags |
2095 | else if (cmd == 8) // cell flags |
1558 | cell->flags = *data++; |
2096 | cell->flags = *data++; |
… | |
… | |
1565 | } |
2103 | } |
1566 | else |
2104 | else |
1567 | cell->darkness = *data++ + 1; |
2105 | cell->darkness = *data++ + 1; |
1568 | } |
2106 | } |
1569 | |
2107 | |
|
|
2108 | for (z = 0; z <= 2; ++z) |
1570 | if (flags & 4) |
2109 | if (flags & (4 >> z)) |
1571 | { |
2110 | { |
1572 | faceid face = (data [0] << 8) + data [1]; data += 2; |
2111 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1573 | need_facenum (self, face); |
2112 | need_facenum (self, face); |
1574 | cell->tile [0] = self->face2tile [face]; |
2113 | cell->tile [z] = self->face2tile [face]; |
|
|
2114 | |
|
|
2115 | if (cell->tile [z]) |
|
|
2116 | { |
|
|
2117 | maptex *tex = self->tex + cell->tile [z]; |
|
|
2118 | tex->unused = 0; |
|
|
2119 | if (!tex->name) |
|
|
2120 | av_push (missing, newSViv (cell->tile [z])); |
|
|
2121 | |
|
|
2122 | if (tex->smoothtile) |
|
|
2123 | { |
|
|
2124 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
2125 | smooth->unused = 0; |
|
|
2126 | if (!smooth->name) |
|
|
2127 | av_push (missing, newSViv (tex->smoothtile)); |
|
|
2128 | } |
|
|
2129 | } |
1575 | } |
2130 | } |
1576 | |
|
|
1577 | if (flags & 2) |
|
|
1578 | { |
|
|
1579 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1580 | need_facenum (self, face); |
|
|
1581 | cell->tile [1] = self->face2tile [face]; |
|
|
1582 | } |
|
|
1583 | |
|
|
1584 | if (flags & 1) |
|
|
1585 | { |
|
|
1586 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1587 | need_facenum (self, face); |
|
|
1588 | cell->tile [2] = self->face2tile [face]; |
|
|
1589 | } |
|
|
1590 | } |
2131 | } |
1591 | else |
2132 | else |
1592 | cell->darkness = 0; |
2133 | CELL_CLEAR (cell); |
1593 | } |
2134 | } |
1594 | } |
2135 | } |
|
|
2136 | OUTPUT: |
|
|
2137 | RETVAL |
1595 | |
2138 | |
1596 | SV * |
2139 | SV * |
1597 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
2140 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1598 | CODE: |
2141 | CODE: |
1599 | { |
2142 | { |
1600 | int x1, x; |
2143 | int x1, x; |
1601 | int y1, y; |
2144 | int y1, y; |
1602 | int z; |
2145 | int z; |
… | |
… | |
1615 | ? self->row + y |
2158 | ? self->row + y |
1616 | : 0; |
2159 | : 0; |
1617 | |
2160 | |
1618 | for (x = x0; x < x1; x++) |
2161 | for (x = x0; x < x1; x++) |
1619 | { |
2162 | { |
1620 | int r = 32, g = 32, b = 32, a = 192; |
2163 | unsigned int r = 32, g = 32, b = 32, a = 192; |
1621 | |
2164 | |
1622 | if (row && row->c0 <= x && x < row->c1) |
2165 | if (row && row->c0 <= x && x < row->c1) |
1623 | { |
2166 | { |
1624 | mapcell *cell = row->col + (x - row->c0); |
2167 | mapcell *cell = row->col + (x - row->c0); |
1625 | |
2168 | |
… | |
… | |
1627 | { |
2170 | { |
1628 | maptex tex = self->tex [cell->tile [z]]; |
2171 | maptex tex = self->tex [cell->tile [z]]; |
1629 | int a0 = 255 - tex.a; |
2172 | int a0 = 255 - tex.a; |
1630 | int a1 = tex.a; |
2173 | int a1 = tex.a; |
1631 | |
2174 | |
1632 | r = (r * a0 + tex.r * a1) / 255; |
2175 | r = div255 (r * a0 + tex.r * a1); |
1633 | g = (g * a0 + tex.g * a1) / 255; |
2176 | g = div255 (g * a0 + tex.g * a1); |
1634 | b = (b * a0 + tex.b * a1) / 255; |
2177 | b = div255 (b * a0 + tex.b * a1); |
1635 | a = (a * a0 + tex.a * a1) / 255; |
2178 | a = div255 (a * a0 + tex.a * a1); |
1636 | } |
2179 | } |
1637 | } |
2180 | } |
1638 | |
2181 | |
1639 | *map++ = (r ) |
2182 | *map++ = (r ) |
1640 | | (g << 8) |
2183 | | (g << 8) |
… | |
… | |
1647 | } |
2190 | } |
1648 | OUTPUT: |
2191 | OUTPUT: |
1649 | RETVAL |
2192 | RETVAL |
1650 | |
2193 | |
1651 | void |
2194 | void |
1652 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
2195 | 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) |
1653 | CODE: |
2196 | CODE: |
1654 | { |
2197 | { |
|
|
2198 | int x, y, z; |
|
|
2199 | |
1655 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
2200 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1656 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2201 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1657 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
2202 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1658 | smooth_key skey; |
2203 | smooth_key skey; |
1659 | int x, y, z; |
2204 | int pl_x, pl_y; |
1660 | int last_name; |
2205 | maptex pl_tex; |
|
|
2206 | rc_t *rc = rc_alloc (); |
|
|
2207 | rc_t *rc_ov = rc_alloc (); |
|
|
2208 | rc_key_t key; |
|
|
2209 | rc_array_t *arr; |
1661 | |
2210 | |
|
|
2211 | pl_tex.name = 0; |
|
|
2212 | |
1662 | // thats current max. sorry. |
2213 | // that's current max. sorry. |
1663 | if (sw > 255) sw = 255; |
2214 | if (sw > 255) sw = 255; |
1664 | if (sh > 255) sh = 255; |
2215 | if (sh > 255) sh = 255; |
1665 | |
2216 | |
1666 | // clear key, in case of extra padding |
2217 | // clear key, in case of extra padding |
1667 | memset (&skey, 0, sizeof (skey)); |
2218 | memset (&skey, 0, sizeof (skey)); |
1668 | |
2219 | |
1669 | glColor4ub (255, 255, 255, 255); |
2220 | memset (&key, 0, sizeof (key)); |
1670 | |
2221 | key.r = 255; |
1671 | glEnable (GL_BLEND); |
2222 | key.g = 255; |
1672 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2223 | key.b = 255; |
1673 | glEnable (GL_TEXTURE_2D); |
2224 | key.a = 255; |
1674 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2225 | key.mode = GL_QUADS; |
1675 | |
2226 | key.format = GL_T2F_V3F; |
1676 | glBegin (GL_QUADS); |
|
|
1677 | |
|
|
1678 | last_name = 0; |
|
|
1679 | |
2227 | |
1680 | mx += self->x; |
2228 | mx += self->x; |
1681 | my += self->y; |
2229 | my += self->y; |
1682 | |
2230 | |
1683 | // first pass: determine smooth_max |
2231 | // first pass: determine smooth_max |
… | |
… | |
1700 | MAX (self->tex [cell->tile [1]].smoothlevel, |
2248 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1701 | self->tex [cell->tile [2]].smoothlevel)); |
2249 | self->tex [cell->tile [2]].smoothlevel)); |
1702 | } |
2250 | } |
1703 | } |
2251 | } |
1704 | |
2252 | |
|
|
2253 | glEnable (GL_BLEND); |
|
|
2254 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
2255 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
2256 | |
1705 | for (z = 0; z <= 2; z++) |
2257 | for (z = 0; z <= 2; z++) |
1706 | { |
2258 | { |
1707 | memset (smooth_level, 0, sizeof (smooth_level)); |
2259 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
2260 | key.texname = -1; |
1708 | |
2261 | |
1709 | for (y = 0; y < sh; y++) |
2262 | for (y = 0; y < sh; y++) |
1710 | if (0 <= y + my && y + my < self->rows) |
2263 | if (0 <= y + my && y + my < self->rows) |
1711 | { |
2264 | { |
1712 | maprow *row = self->row + (y + my); |
2265 | maprow *row = self->row + (y + my); |
… | |
… | |
1718 | tileid tile = cell->tile [z]; |
2271 | tileid tile = cell->tile [z]; |
1719 | |
2272 | |
1720 | if (tile) |
2273 | if (tile) |
1721 | { |
2274 | { |
1722 | maptex tex = self->tex [tile]; |
2275 | maptex tex = self->tex [tile]; |
1723 | int px = (x + 1) * T - tex.w; |
2276 | int px, py; |
1724 | int py = (y + 1) * T - tex.h; |
|
|
1725 | |
2277 | |
1726 | // suppressing texture state switches here |
|
|
1727 | // is only moderately effective, but worth the extra effort |
|
|
1728 | if (last_name != tex.name) |
2278 | if (key.texname != tex.name) |
1729 | { |
2279 | { |
|
|
2280 | self->tex [tile].unused = 0; |
|
|
2281 | |
1730 | if (!tex.name) |
2282 | if (!tex.name) |
1731 | tex = self->tex [2]; /* missing, replace by noface */ |
2283 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
1732 | |
2284 | |
1733 | glEnd (); |
2285 | key.texname = tex.name; |
1734 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
2286 | arr = rc_array (rc, &key); |
1735 | glBegin (GL_QUADS); |
|
|
1736 | } |
2287 | } |
1737 | |
2288 | |
1738 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
2289 | px = (x + 1) * Th - tex.w; |
1739 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
2290 | py = (y + 1) * Tw - tex.h; |
1740 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1741 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1742 | |
2291 | |
1743 | if (cell->flags && z == 2) |
2292 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
1744 | { |
2293 | { |
1745 | if (cell->flags & 1) |
2294 | pl_x = px; |
|
|
2295 | pl_y = py; |
|
|
2296 | pl_tex = tex; |
1746 | { |
2297 | continue; |
1747 | maptex tex = self->tex [1]; |
|
|
1748 | int px = x * T + T * 2 / 32; |
|
|
1749 | int py = y * T - T * 6 / 32; |
|
|
1750 | |
|
|
1751 | glEnd (); |
|
|
1752 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1753 | glBegin (GL_QUADS); |
|
|
1754 | |
|
|
1755 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1756 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1757 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1758 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1759 | } |
|
|
1760 | } |
2298 | } |
|
|
2299 | |
|
|
2300 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2301 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
2302 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2303 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1761 | |
2304 | |
1762 | // update smooth hash |
2305 | // update smooth hash |
1763 | if (tex.smoothtile) |
2306 | if (tex.smoothtile) |
1764 | { |
2307 | { |
1765 | skey.tile = tex.smoothtile; |
2308 | skey.tile = tex.smoothtile; |
… | |
… | |
1796 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2339 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
1797 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2340 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
1798 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2341 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
1799 | } |
2342 | } |
1800 | } |
2343 | } |
|
|
2344 | |
|
|
2345 | if (expect_false (z == 2) && expect_false (cell->flags)) |
|
|
2346 | { |
|
|
2347 | // overlays such as the speech bubble, probably more to come |
|
|
2348 | if (cell->flags & 1) |
|
|
2349 | { |
|
|
2350 | rc_key_t key_ov = key; |
|
|
2351 | maptex tex = self->tex [TEXID_SPEECH]; |
|
|
2352 | rc_array_t *arr; |
|
|
2353 | int px = x * Tw + Tw * 2 / 32; |
|
|
2354 | int py = y * Th - Th * 6 / 32; |
|
|
2355 | |
|
|
2356 | key_ov.texname = tex.name; |
|
|
2357 | arr = rc_array (rc_ov, &key_ov); |
|
|
2358 | |
|
|
2359 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2360 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
|
|
2361 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
|
|
2362 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
|
|
2363 | } |
|
|
2364 | } |
1801 | } |
2365 | } |
1802 | } |
2366 | } |
|
|
2367 | |
|
|
2368 | rc_draw (rc); |
|
|
2369 | rc_clear (rc); |
1803 | |
2370 | |
1804 | // go through all smoothlevels, lowest to highest, then draw. |
2371 | // go through all smoothlevels, lowest to highest, then draw. |
1805 | // this is basically counting sort |
2372 | // this is basically counting sort |
1806 | { |
2373 | { |
1807 | int w, b; |
2374 | int w, b; |
1808 | |
2375 | |
|
|
2376 | glEnable (GL_TEXTURE_2D); |
|
|
2377 | glBegin (GL_QUADS); |
1809 | for (w = 0; w < 256 / 32; ++w) |
2378 | for (w = 0; w < 256 / 32; ++w) |
1810 | { |
2379 | { |
1811 | uint32_t smask = smooth_level [w]; |
2380 | uint32_t smask = smooth_level [w]; |
1812 | if (smask) |
2381 | if (smask) |
1813 | for (b = 0; b < 32; ++b) |
2382 | for (b = 0; b < 32; ++b) |
… | |
… | |
1825 | if (!(bits & 0x1000) |
2394 | if (!(bits & 0x1000) |
1826 | && skey->level == level |
2395 | && skey->level == level |
1827 | && level > smooth_max [skey->x][skey->y]) |
2396 | && level > smooth_max [skey->x][skey->y]) |
1828 | { |
2397 | { |
1829 | maptex tex = self->tex [skey->tile]; |
2398 | maptex tex = self->tex [skey->tile]; |
1830 | int px = (((int)skey->x) - 1) * T; |
2399 | int px = (((int)skey->x) - 1) * Tw; |
1831 | int py = (((int)skey->y) - 1) * T; |
2400 | int py = (((int)skey->y) - 1) * Th; |
1832 | int border = bits & 15; |
2401 | int border = bits & 15; |
1833 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2402 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1834 | float dx = tex.s * .0625f; // 16 images/row |
2403 | float dx = tex.s * .0625f; // 16 images/row |
1835 | float dy = tex.t * .5f ; // 2 images/column |
2404 | float dy = tex.t * .5f ; // 2 images/column |
1836 | |
2405 | |
1837 | // this time naively avoiding texture state changes |
|
|
1838 | // save gobs of state changes. |
|
|
1839 | if (last_name != tex.name) |
2406 | if (tex.name) |
1840 | { |
2407 | { |
|
|
2408 | // this time avoiding texture state changes |
|
|
2409 | // save gobs of state changes. |
1841 | if (!tex.name) |
2410 | if (key.texname != tex.name) |
1842 | continue; // smoothing not yet available |
2411 | { |
|
|
2412 | self->tex [skey->tile].unused = 0; |
1843 | |
2413 | |
1844 | glEnd (); |
2414 | glEnd (); |
1845 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
2415 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1846 | glBegin (GL_QUADS); |
2416 | glBegin (GL_QUADS); |
1847 | } |
2417 | } |
1848 | |
2418 | |
1849 | if (border) |
2419 | if (border) |
1850 | { |
2420 | { |
1851 | float ox = border * dx; |
2421 | float ox = border * dx; |
1852 | |
2422 | |
1853 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
2423 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1854 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
2424 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
1855 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
2425 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
1856 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
2426 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
1857 | } |
2427 | } |
1858 | |
2428 | |
1859 | if (corner) |
2429 | if (corner) |
1860 | { |
2430 | { |
1861 | float ox = corner * dx; |
2431 | float ox = corner * dx; |
1862 | |
2432 | |
1863 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
2433 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1864 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
2434 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
1865 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
2435 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
1866 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
2436 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
|
|
2437 | } |
1867 | } |
2438 | } |
1868 | } |
2439 | } |
1869 | } |
2440 | } |
1870 | } |
2441 | } |
1871 | } |
2442 | } |
|
|
2443 | |
|
|
2444 | glEnd (); |
|
|
2445 | glDisable (GL_TEXTURE_2D); |
|
|
2446 | key.texname = -1; |
1872 | } |
2447 | } |
1873 | |
2448 | |
1874 | hv_clear (smooth); |
2449 | hv_clear (smooth); |
1875 | } |
2450 | } |
1876 | |
2451 | |
1877 | glEnd (); |
2452 | if (pl_tex.name) |
|
|
2453 | { |
|
|
2454 | maptex tex = pl_tex; |
|
|
2455 | int px = pl_x + sdx; |
|
|
2456 | int py = pl_y + sdy; |
1878 | |
2457 | |
1879 | glDisable (GL_TEXTURE_2D); |
2458 | key.texname = tex.name; |
|
|
2459 | arr = rc_array (rc, &key); |
|
|
2460 | |
|
|
2461 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2462 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
2463 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2464 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
|
|
2465 | |
|
|
2466 | rc_draw (rc); |
|
|
2467 | } |
|
|
2468 | |
|
|
2469 | rc_draw (rc_ov); |
|
|
2470 | rc_clear (rc_ov); |
|
|
2471 | |
1880 | glDisable (GL_BLEND); |
2472 | glDisable (GL_BLEND); |
|
|
2473 | rc_free (rc); |
|
|
2474 | rc_free (rc_ov); |
1881 | |
2475 | |
1882 | // top layer: overlays such as the health bar |
2476 | // top layer: overlays such as the health bar |
1883 | for (y = 0; y < sh; y++) |
2477 | for (y = 0; y < sh; y++) |
1884 | if (0 <= y + my && y + my < self->rows) |
2478 | if (0 <= y + my && y + my < self->rows) |
1885 | { |
2479 | { |
… | |
… | |
1888 | for (x = 0; x < sw; x++) |
2482 | for (x = 0; x < sw; x++) |
1889 | if (row->c0 <= x + mx && x + mx < row->c1) |
2483 | if (row->c0 <= x + mx && x + mx < row->c1) |
1890 | { |
2484 | { |
1891 | mapcell *cell = row->col + (x + mx - row->c0); |
2485 | mapcell *cell = row->col + (x + mx - row->c0); |
1892 | |
2486 | |
1893 | int px = x * T; |
2487 | int px = x * Tw; |
1894 | int py = y * T; |
2488 | int py = y * Th; |
|
|
2489 | |
|
|
2490 | if (expect_false (cell->player == player)) |
|
|
2491 | { |
|
|
2492 | px += sdx; |
|
|
2493 | py += sdy; |
|
|
2494 | } |
1895 | |
2495 | |
1896 | if (cell->stat_hp) |
2496 | if (cell->stat_hp) |
1897 | { |
2497 | { |
1898 | int width = cell->stat_width * T; |
2498 | int width = cell->stat_width * Tw; |
1899 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2499 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
1900 | |
2500 | |
1901 | glColor3ub (0, 0, 0); |
2501 | glColor3ub (0, 0, 0); |
1902 | glRectf (px + 1, py - thick - 2, |
2502 | glRectf (px + 1, py - thick - 2, |
1903 | px + width - 1, py); |
2503 | px + width - 1, py); |
1904 | |
2504 | |
… | |
… | |
1910 | } |
2510 | } |
1911 | } |
2511 | } |
1912 | } |
2512 | } |
1913 | |
2513 | |
1914 | void |
2514 | void |
1915 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2515 | draw_magicmap (DC::Map self, int w, int h, unsigned char *data) |
1916 | CODE: |
2516 | CODE: |
1917 | { |
2517 | { |
1918 | static float color[16][3] = { |
2518 | static float color[16][3] = { |
1919 | { 0.00F, 0.00F, 0.00F }, |
2519 | { 0.00f, 0.00f, 0.00f }, |
1920 | { 1.00F, 1.00F, 1.00F }, |
2520 | { 1.00f, 1.00f, 1.00f }, |
1921 | { 0.00F, 0.00F, 0.55F }, |
2521 | { 0.00f, 0.00f, 0.55f }, |
1922 | { 1.00F, 0.00F, 0.00F }, |
2522 | { 1.00f, 0.00f, 0.00f }, |
1923 | |
2523 | |
1924 | { 1.00F, 0.54F, 0.00F }, |
2524 | { 1.00f, 0.54f, 0.00f }, |
1925 | { 0.11F, 0.56F, 1.00F }, |
2525 | { 0.11f, 0.56f, 1.00f }, |
1926 | { 0.93F, 0.46F, 0.00F }, |
2526 | { 0.93f, 0.46f, 0.00f }, |
1927 | { 0.18F, 0.54F, 0.34F }, |
2527 | { 0.18f, 0.54f, 0.34f }, |
1928 | |
2528 | |
1929 | { 0.56F, 0.73F, 0.56F }, |
2529 | { 0.56f, 0.73f, 0.56f }, |
1930 | { 0.80F, 0.80F, 0.80F }, |
2530 | { 0.80f, 0.80f, 0.80f }, |
1931 | { 0.55F, 0.41F, 0.13F }, |
2531 | { 0.55f, 0.41f, 0.13f }, |
1932 | { 0.99F, 0.77F, 0.26F }, |
2532 | { 0.99f, 0.77f, 0.26f }, |
1933 | |
2533 | |
1934 | { 0.74F, 0.65F, 0.41F }, |
2534 | { 0.74f, 0.65f, 0.41f }, |
1935 | |
2535 | |
1936 | { 0.00F, 1.00F, 1.00F }, |
2536 | { 0.00f, 1.00f, 1.00f }, |
1937 | { 1.00F, 0.00F, 1.00F }, |
2537 | { 1.00f, 0.00f, 1.00f }, |
1938 | { 1.00F, 1.00F, 0.00F }, |
2538 | { 1.00f, 1.00f, 0.00f }, |
1939 | }; |
2539 | }; |
1940 | |
2540 | |
1941 | int x, y; |
2541 | int x, y; |
1942 | |
2542 | |
1943 | glEnable (GL_TEXTURE_2D); |
2543 | glEnable (GL_TEXTURE_2D); |
|
|
2544 | /* GL_REPLACE would be correct, as we don't need to modulate alpha, |
|
|
2545 | * but the nvidia driver (185.18.14) mishandles alpha textures |
|
|
2546 | * and takes the colour from god knows where instead of using |
|
|
2547 | * Cp. MODULATE results in the same colour, but slightly different |
|
|
2548 | * alpha, but atcually gives us the correct colour with nvidia. |
|
|
2549 | */ |
1944 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2550 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
1945 | glEnable (GL_BLEND); |
2551 | glEnable (GL_BLEND); |
1946 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2552 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1947 | glBegin (GL_QUADS); |
2553 | glBegin (GL_QUADS); |
1948 | |
2554 | |
1949 | for (y = 0; y < h; y++) |
2555 | for (y = 0; y < h; y++) |
… | |
… | |
1953 | |
2559 | |
1954 | if (m) |
2560 | if (m) |
1955 | { |
2561 | { |
1956 | float *c = color [m & 15]; |
2562 | float *c = color [m & 15]; |
1957 | |
2563 | |
1958 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2564 | float tx1 = m & 0x40 ? 0.5f : 0.f; |
1959 | float tx2 = tx1 + 0.5; |
2565 | float tx2 = tx1 + 0.5f; |
1960 | |
2566 | |
1961 | glColor4f (c[0], c[1], c[2], 0.75); |
2567 | glColor4f (c[0], c[1], c[2], 1); |
1962 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2568 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
1963 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2569 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
1964 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2570 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
1965 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2571 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
1966 | } |
2572 | } |
… | |
… | |
1970 | glDisable (GL_BLEND); |
2576 | glDisable (GL_BLEND); |
1971 | glDisable (GL_TEXTURE_2D); |
2577 | glDisable (GL_TEXTURE_2D); |
1972 | } |
2578 | } |
1973 | |
2579 | |
1974 | void |
2580 | void |
1975 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2581 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
1976 | PPCODE: |
2582 | PPCODE: |
1977 | { |
2583 | { |
1978 | int x, y; |
2584 | int x, y; |
1979 | int sw1 = sw + 2; |
2585 | int sw1 = sw + 2; |
1980 | int sh1 = sh + 2; |
2586 | int sh1 = sh + 2; |
1981 | int sh3 = sh * 3; |
2587 | int sh3 = sh * 3; |
1982 | int sw34 = (sw * 3 + 3) & ~3; |
2588 | int sw3 = sw * 3; |
|
|
2589 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
|
|
2590 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
1983 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2591 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
1984 | SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); |
2592 | memset (darkness1, 0, sw1*sh1); |
1985 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
1986 | |
2593 | |
1987 | SvPOK_only (darkness3_sv); |
2594 | SvPOK_only (darkness3_sv); |
1988 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2595 | SvCUR_set (darkness3_sv, sw3 * sh3); |
1989 | |
2596 | |
1990 | mx += self->x - 1; |
2597 | mx += self->x - 1; |
1991 | my += self->y - 1; |
2598 | my += self->y - 1; |
1992 | |
|
|
1993 | memset (darkness1, 255, sw1 * sh1); |
|
|
1994 | |
2599 | |
1995 | for (y = 0; y < sh1; y++) |
2600 | for (y = 0; y < sh1; y++) |
1996 | if (0 <= y + my && y + my < self->rows) |
2601 | if (0 <= y + my && y + my < self->rows) |
1997 | { |
2602 | { |
1998 | maprow *row = self->row + (y + my); |
2603 | maprow *row = self->row + (y + my); |
… | |
… | |
2001 | if (row->c0 <= x + mx && x + mx < row->c1) |
2606 | if (row->c0 <= x + mx && x + mx < row->c1) |
2002 | { |
2607 | { |
2003 | mapcell *cell = row->col + (x + mx - row->c0); |
2608 | mapcell *cell = row->col + (x + mx - row->c0); |
2004 | |
2609 | |
2005 | darkness1 [y * sw1 + x] = cell->darkness |
2610 | darkness1 [y * sw1 + x] = cell->darkness |
2006 | ? 255 - (cell->darkness - 1) |
2611 | ? DARKNESS_ADJUST (255 - (cell->darkness - 1)) |
2007 | : 255 - FOW_DARKNESS; |
2612 | : DARKNESS_ADJUST (255 - FOW_DARKNESS); |
2008 | } |
2613 | } |
2009 | } |
2614 | } |
2010 | |
2615 | |
2011 | for (y = 0; y < sh; ++y) |
2616 | for (y = 0; y < sh; ++y) |
2012 | for (x = 0; x < sw; ++x) |
2617 | for (x = 0; x < sw; ++x) |
… | |
… | |
2031 | |
2636 | |
2032 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2637 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2033 | uint8_t r23 = d23; |
2638 | uint8_t r23 = d23; |
2034 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2639 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2035 | |
2640 | |
2036 | darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); |
2641 | darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11); |
2037 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); |
2642 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21); |
2038 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); |
2643 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31); |
2039 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); |
2644 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12); |
2040 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); |
2645 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */ |
2041 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); |
2646 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32); |
2042 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); |
2647 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13); |
2043 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); |
2648 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23); |
2044 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); |
2649 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33); |
2045 | } |
2650 | } |
2046 | |
2651 | |
2047 | free (darkness1); |
2652 | free (darkness1); |
2048 | |
2653 | |
2049 | EXTEND (SP, 3); |
2654 | EXTEND (SP, 3); |
2050 | PUSHs (sv_2mortal (newSViv (sw34))); |
2655 | PUSHs (sv_2mortal (newSViv (sw3))); |
2051 | PUSHs (sv_2mortal (newSViv (sh3))); |
2656 | PUSHs (sv_2mortal (newSViv (sh3))); |
2052 | PUSHs (darkness3_sv); |
2657 | PUSHs (darkness3_sv); |
2053 | } |
2658 | } |
2054 | |
2659 | |
2055 | SV * |
2660 | SV * |
2056 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2661 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2057 | CODE: |
2662 | CODE: |
2058 | { |
2663 | { |
2059 | int x, y, x1, y1; |
2664 | int x, y, x1, y1; |
2060 | SV *data_sv = newSV (w * h * 7 + 5); |
2665 | SV *data_sv = newSV (w * h * 7 + 5); |
2061 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2666 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2118 | else |
2723 | else |
2119 | *data++ = 0; |
2724 | *data++ = 0; |
2120 | } |
2725 | } |
2121 | } |
2726 | } |
2122 | |
2727 | |
|
|
2728 | /* if size is w*h + 5 then no data has been found */ |
|
|
2729 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
|
|
2730 | { |
2123 | SvPOK_only (data_sv); |
2731 | SvPOK_only (data_sv); |
2124 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2732 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
2733 | } |
|
|
2734 | |
2125 | RETVAL = data_sv; |
2735 | RETVAL = data_sv; |
2126 | } |
2736 | } |
2127 | OUTPUT: |
2737 | OUTPUT: |
2128 | RETVAL |
2738 | RETVAL |
2129 | |
2739 | |
2130 | void |
2740 | void |
2131 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2741 | set_rect (DC::Map self, int x0, int y0, SV *data_sv) |
2132 | PPCODE: |
2742 | PPCODE: |
2133 | { |
2743 | { |
2134 | int x, y, z; |
2744 | int x, y, z; |
2135 | int w, h; |
2745 | int w, h; |
2136 | int x1, y1; |
2746 | int x1, y1; |
|
|
2747 | STRLEN len; |
|
|
2748 | uint8_t *data, *end; |
|
|
2749 | |
|
|
2750 | len = SvLEN (data_sv); |
|
|
2751 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
|
|
2752 | data = SvPVbyte_nolen (data_sv); |
|
|
2753 | end = data + len + 8; |
|
|
2754 | |
|
|
2755 | if (len < 5) |
|
|
2756 | XSRETURN_EMPTY; |
2137 | |
2757 | |
2138 | if (*data++ != 0) |
2758 | if (*data++ != 0) |
2139 | return; /* version mismatch */ |
2759 | XSRETURN_EMPTY; /* version mismatch */ |
2140 | |
2760 | |
2141 | w = *data++ << 8; w |= *data++; |
2761 | w = *data++ << 8; w |= *data++; |
2142 | h = *data++ << 8; h |= *data++; |
2762 | h = *data++ << 8; h |= *data++; |
2143 | |
2763 | |
2144 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2764 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2156 | { |
2776 | { |
2157 | maprow *row = map_get_row (self, y); |
2777 | maprow *row = map_get_row (self, y); |
2158 | |
2778 | |
2159 | for (x = x0; x < x1; x++) |
2779 | for (x = x0; x < x1; x++) |
2160 | { |
2780 | { |
|
|
2781 | uint8_t flags; |
|
|
2782 | |
|
|
2783 | if (data + 7 >= end) |
|
|
2784 | XSRETURN_EMPTY; |
|
|
2785 | |
2161 | uint8_t flags = *data++; |
2786 | flags = *data++; |
2162 | |
2787 | |
2163 | if (flags) |
2788 | if (flags) |
2164 | { |
2789 | { |
2165 | mapcell *cell = row_get_cell (row, x); |
2790 | mapcell *cell = row_get_cell (row, x); |
2166 | tileid tile[3] = { 0, 0, 0 }; |
2791 | tileid tile[3] = { 0, 0, 0 }; |
… | |
… | |
2169 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2794 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2170 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2795 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2171 | |
2796 | |
2172 | if (cell->darkness == 0) |
2797 | if (cell->darkness == 0) |
2173 | { |
2798 | { |
2174 | cell->darkness = 0; |
2799 | /*cell->darkness = 0;*/ |
|
|
2800 | EXTEND (SP, 3); |
2175 | |
2801 | |
2176 | for (z = 0; z <= 2; z++) |
2802 | for (z = 0; z <= 2; z++) |
2177 | { |
2803 | { |
2178 | tileid t = tile [z]; |
2804 | tileid t = tile [z]; |
2179 | |
2805 | |
2180 | if (t >= self->texs || (t && !self->tex [t].name)) |
2806 | if (t >= self->texs || (t && !self->tex [t].name)) |
2181 | { |
2807 | { |
2182 | XPUSHs (sv_2mortal (newSViv (t))); |
2808 | PUSHs (sv_2mortal (newSViv (t))); |
2183 | need_texid (self, t); |
2809 | need_texid (self, t); |
2184 | } |
2810 | } |
2185 | |
2811 | |
2186 | cell->tile [z] = t; |
2812 | cell->tile [z] = t; |
2187 | } |
2813 | } |
… | |
… | |
2189 | } |
2815 | } |
2190 | } |
2816 | } |
2191 | } |
2817 | } |
2192 | } |
2818 | } |
2193 | |
2819 | |
2194 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2820 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2195 | |
2821 | |
2196 | PROTOTYPES: DISABLE |
2822 | DC::RW |
2197 | |
2823 | new (SV *class, SV *data_sv) |
2198 | CFPlus::MixChunk |
|
|
2199 | new_from_file (SV *class, char *path) |
|
|
2200 | CODE: |
2824 | CODE: |
2201 | RETVAL = Mix_LoadWAV (path); |
2825 | { |
|
|
2826 | STRLEN datalen; |
|
|
2827 | char *data = SvPVbyte (data_sv, datalen); |
|
|
2828 | |
|
|
2829 | RETVAL = SDL_RWFromConstMem (data, datalen); |
|
|
2830 | } |
2202 | OUTPUT: |
2831 | OUTPUT: |
2203 | RETVAL |
2832 | RETVAL |
2204 | |
2833 | |
|
|
2834 | DC::RW |
|
|
2835 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
|
|
2836 | CODE: |
|
|
2837 | RETVAL = SDL_RWFromFile (path, mode); |
|
|
2838 | OUTPUT: |
|
|
2839 | RETVAL |
|
|
2840 | |
|
|
2841 | # fails on win32: |
|
|
2842 | # dc.xs(2268) : error C2059: syntax error : '(' |
2205 | void |
2843 | #void |
|
|
2844 | #close (DC::RW self) |
|
|
2845 | # CODE: |
|
|
2846 | # (self->(close)) (self); |
|
|
2847 | |
|
|
2848 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
|
|
2849 | |
|
|
2850 | PROTOTYPES: DISABLE |
|
|
2851 | |
|
|
2852 | DC::Channel |
|
|
2853 | find () |
|
|
2854 | CODE: |
|
|
2855 | { |
|
|
2856 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2857 | |
|
|
2858 | if (RETVAL < 0) |
|
|
2859 | { |
|
|
2860 | RETVAL = Mix_GroupOldest (-1); |
|
|
2861 | |
|
|
2862 | if (RETVAL < 0) |
|
|
2863 | { |
|
|
2864 | // happens sometimes, maybe it just stopped playing(?) |
|
|
2865 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2866 | |
|
|
2867 | if (RETVAL < 0) |
|
|
2868 | XSRETURN_UNDEF; |
|
|
2869 | } |
|
|
2870 | else |
|
|
2871 | Mix_HaltChannel (RETVAL); |
|
|
2872 | } |
|
|
2873 | |
|
|
2874 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2875 | Mix_Volume (RETVAL, 128); |
|
|
2876 | } |
|
|
2877 | OUTPUT: |
|
|
2878 | RETVAL |
|
|
2879 | |
|
|
2880 | void |
|
|
2881 | halt (DC::Channel self) |
|
|
2882 | CODE: |
|
|
2883 | Mix_HaltChannel (self); |
|
|
2884 | |
|
|
2885 | void |
|
|
2886 | expire (DC::Channel self, int ticks = -1) |
|
|
2887 | CODE: |
|
|
2888 | Mix_ExpireChannel (self, ticks); |
|
|
2889 | |
|
|
2890 | void |
|
|
2891 | fade_out (DC::Channel self, int ticks = -1) |
|
|
2892 | CODE: |
|
|
2893 | Mix_FadeOutChannel (self, ticks); |
|
|
2894 | |
|
|
2895 | int |
|
|
2896 | volume (DC::Channel self, int volume) |
|
|
2897 | CODE: |
|
|
2898 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
|
|
2899 | OUTPUT: |
|
|
2900 | RETVAL |
|
|
2901 | |
|
|
2902 | void |
|
|
2903 | unregister_all_effects (DC::Channel self) |
|
|
2904 | CODE: |
|
|
2905 | Mix_UnregisterAllEffects (self); |
|
|
2906 | |
|
|
2907 | void |
|
|
2908 | set_panning (DC::Channel self, int left, int right) |
|
|
2909 | CODE: |
|
|
2910 | left = CLAMP (left , 0, 255); |
|
|
2911 | right = CLAMP (right, 0, 255); |
|
|
2912 | Mix_SetPanning (self, left, right); |
|
|
2913 | |
|
|
2914 | void |
|
|
2915 | set_distance (DC::Channel self, int distance) |
|
|
2916 | CODE: |
|
|
2917 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
|
|
2918 | |
|
|
2919 | void |
|
|
2920 | set_position (DC::Channel self, int angle, int distance) |
|
|
2921 | CODE: |
|
|
2922 | |
|
|
2923 | void |
|
|
2924 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
|
|
2925 | CODE: |
|
|
2926 | { |
|
|
2927 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
|
|
2928 | int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f; |
|
|
2929 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
|
|
2930 | } |
|
|
2931 | |
|
|
2932 | void |
|
|
2933 | set_reverse_stereo (DC::Channel self, int flip) |
|
|
2934 | CODE: |
|
|
2935 | Mix_SetReverseStereo (self, flip); |
|
|
2936 | |
|
|
2937 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
|
|
2938 | |
|
|
2939 | PROTOTYPES: DISABLE |
|
|
2940 | |
|
|
2941 | void |
|
|
2942 | decoders () |
|
|
2943 | PPCODE: |
|
|
2944 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
2945 | int i, num = Mix_GetNumChunkDecoders (); |
|
|
2946 | EXTEND (SP, num); |
|
|
2947 | for (i = 0; i < num; ++i) |
|
|
2948 | PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0))); |
|
|
2949 | #else |
|
|
2950 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
2951 | #endif |
|
|
2952 | |
|
|
2953 | DC::MixChunk |
|
|
2954 | new (SV *class, DC::RW rwops) |
|
|
2955 | CODE: |
|
|
2956 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
|
|
2957 | OUTPUT: |
|
|
2958 | RETVAL |
|
|
2959 | |
|
|
2960 | void |
2206 | DESTROY (CFPlus::MixChunk self) |
2961 | DESTROY (DC::MixChunk self) |
2207 | CODE: |
2962 | CODE: |
2208 | Mix_FreeChunk (self); |
2963 | Mix_FreeChunk (self); |
2209 | |
2964 | |
2210 | int |
2965 | int |
2211 | volume (CFPlus::MixChunk self, int volume = -1) |
2966 | volume (DC::MixChunk self, int volume = -1) |
2212 | CODE: |
2967 | CODE: |
|
|
2968 | if (items > 1) |
|
|
2969 | volume = CLAMP (volume, 0, 128); |
2213 | RETVAL = Mix_VolumeChunk (self, volume); |
2970 | RETVAL = Mix_VolumeChunk (self, volume); |
2214 | OUTPUT: |
2971 | OUTPUT: |
2215 | RETVAL |
2972 | RETVAL |
2216 | |
2973 | |
2217 | int |
2974 | DC::Channel |
2218 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
2975 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2219 | CODE: |
2976 | CODE: |
|
|
2977 | { |
2220 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2978 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
|
|
2979 | |
|
|
2980 | if (RETVAL < 0) |
|
|
2981 | XSRETURN_UNDEF; |
|
|
2982 | |
|
|
2983 | if (channel < 0) |
|
|
2984 | { |
|
|
2985 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2986 | Mix_Volume (RETVAL, 128); |
|
|
2987 | } |
|
|
2988 | } |
2221 | OUTPUT: |
2989 | OUTPUT: |
2222 | RETVAL |
2990 | RETVAL |
2223 | |
2991 | |
2224 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2992 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
|
|
2993 | |
|
|
2994 | void |
|
|
2995 | decoders () |
|
|
2996 | PPCODE: |
|
|
2997 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
2998 | int i, num = Mix_GetNumMusicDecoders (); |
|
|
2999 | EXTEND (SP, num); |
|
|
3000 | for (i = 0; i < num; ++i) |
|
|
3001 | PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0))); |
|
|
3002 | #else |
|
|
3003 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
3004 | #endif |
2225 | |
3005 | |
2226 | int |
3006 | int |
2227 | volume (int volume = -1) |
3007 | volume (int volume = -1) |
2228 | PROTOTYPE: ;$ |
3008 | PROTOTYPE: ;$ |
2229 | CODE: |
3009 | CODE: |
|
|
3010 | if (items > 0) |
|
|
3011 | volume = CLAMP (volume, 0, 128); |
2230 | RETVAL = Mix_VolumeMusic (volume); |
3012 | RETVAL = Mix_VolumeMusic (volume); |
2231 | OUTPUT: |
3013 | OUTPUT: |
2232 | RETVAL |
3014 | RETVAL |
2233 | |
3015 | |
|
|
3016 | void |
|
|
3017 | fade_out (int ms) |
|
|
3018 | CODE: |
|
|
3019 | Mix_FadeOutMusic (ms); |
|
|
3020 | |
|
|
3021 | void |
|
|
3022 | halt () |
|
|
3023 | CODE: |
|
|
3024 | Mix_HaltMusic (); |
|
|
3025 | |
2234 | int |
3026 | int |
2235 | fade_out (int ms) |
3027 | playing () |
2236 | CODE: |
3028 | CODE: |
2237 | RETVAL = Mix_FadeOutMusic (ms); |
3029 | RETVAL = Mix_PlayingMusic (); |
2238 | OUTPUT: |
3030 | OUTPUT: |
2239 | RETVAL |
3031 | RETVAL |
2240 | |
3032 | |
2241 | CFPlus::MixMusic |
3033 | DC::MixMusic |
2242 | new_from_file (SV *class, char *path) |
3034 | new (SV *class, DC::RW rwops) |
2243 | CODE: |
3035 | CODE: |
2244 | RETVAL = Mix_LoadMUS (path); |
3036 | RETVAL = Mix_LoadMUS_RW (rwops); |
2245 | OUTPUT: |
3037 | OUTPUT: |
2246 | RETVAL |
3038 | RETVAL |
2247 | |
3039 | |
2248 | void |
3040 | void |
2249 | DESTROY (CFPlus::MixMusic self) |
3041 | DESTROY (DC::MixMusic self) |
2250 | CODE: |
3042 | CODE: |
2251 | Mix_FreeMusic (self); |
3043 | Mix_FreeMusic (self); |
2252 | |
3044 | |
2253 | int |
3045 | int |
2254 | play (CFPlus::MixMusic self, int loops = -1) |
3046 | play (DC::MixMusic self, int loops = -1) |
2255 | CODE: |
3047 | CODE: |
2256 | RETVAL = Mix_PlayMusic (self, loops); |
3048 | RETVAL = Mix_PlayMusic (self, loops); |
2257 | OUTPUT: |
3049 | OUTPUT: |
2258 | RETVAL |
3050 | RETVAL |
2259 | |
3051 | |
2260 | int |
3052 | void |
2261 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
3053 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2262 | CODE: |
3054 | CODE: |
2263 | RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); |
3055 | Mix_FadeInMusicPos (self, loops, ms, position); |
2264 | OUTPUT: |
|
|
2265 | RETVAL |
|
|
2266 | |
3056 | |
2267 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
3057 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2268 | |
3058 | |
2269 | PROTOTYPES: ENABLE |
3059 | PROTOTYPES: ENABLE |
2270 | |
3060 | |
2271 | BOOT: |
3061 | BOOT: |
2272 | { |
3062 | { |
2273 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
3063 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2274 | static const struct { |
3064 | static const struct { |
2275 | const char *name; |
3065 | const char *name; |
2276 | IV iv; |
3066 | IV iv; |
2277 | } *civ, const_iv[] = { |
3067 | } *civ, const_iv[] = { |
2278 | # define const_iv(name) { # name, (IV)name } |
3068 | # define const_iv(name) { # name, (IV)name } |
2279 | const_iv (GL_VENDOR), |
3069 | const_iv (GL_VENDOR), |
2280 | const_iv (GL_VERSION), |
3070 | const_iv (GL_VERSION), |
2281 | const_iv (GL_EXTENSIONS), |
3071 | const_iv (GL_EXTENSIONS), |
|
|
3072 | const_iv (GL_MAX_TEXTURE_UNITS), |
2282 | const_iv (GL_COLOR_MATERIAL), |
3073 | const_iv (GL_COLOR_MATERIAL), |
2283 | const_iv (GL_SMOOTH), |
3074 | const_iv (GL_SMOOTH), |
2284 | const_iv (GL_FLAT), |
3075 | const_iv (GL_FLAT), |
2285 | const_iv (GL_DITHER), |
3076 | const_iv (GL_DITHER), |
2286 | const_iv (GL_BLEND), |
3077 | const_iv (GL_BLEND), |
… | |
… | |
2290 | const_iv (GL_ALPHA_TEST), |
3081 | const_iv (GL_ALPHA_TEST), |
2291 | const_iv (GL_NORMALIZE), |
3082 | const_iv (GL_NORMALIZE), |
2292 | const_iv (GL_RESCALE_NORMAL), |
3083 | const_iv (GL_RESCALE_NORMAL), |
2293 | const_iv (GL_FRONT), |
3084 | const_iv (GL_FRONT), |
2294 | const_iv (GL_BACK), |
3085 | const_iv (GL_BACK), |
|
|
3086 | const_iv (GL_AUX0), |
2295 | const_iv (GL_AND), |
3087 | const_iv (GL_AND), |
2296 | const_iv (GL_ONE), |
3088 | const_iv (GL_ONE), |
2297 | const_iv (GL_ZERO), |
3089 | const_iv (GL_ZERO), |
2298 | const_iv (GL_SRC_ALPHA), |
3090 | const_iv (GL_SRC_ALPHA), |
2299 | const_iv (GL_DST_ALPHA), |
3091 | const_iv (GL_DST_ALPHA), |
2300 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
3092 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
2301 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
3093 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
|
|
3094 | const_iv (GL_SRC_COLOR), |
|
|
3095 | const_iv (GL_DST_COLOR), |
|
|
3096 | const_iv (GL_ONE_MINUS_SRC_COLOR), |
|
|
3097 | const_iv (GL_ONE_MINUS_DST_COLOR), |
2302 | const_iv (GL_SRC_ALPHA_SATURATE), |
3098 | const_iv (GL_SRC_ALPHA_SATURATE), |
2303 | const_iv (GL_RGB), |
3099 | const_iv (GL_RGB), |
2304 | const_iv (GL_RGBA), |
3100 | const_iv (GL_RGBA), |
2305 | const_iv (GL_RGBA4), |
3101 | const_iv (GL_RGBA4), |
2306 | const_iv (GL_RGBA8), |
3102 | const_iv (GL_RGBA8), |
… | |
… | |
2312 | const_iv (GL_INTENSITY), |
3108 | const_iv (GL_INTENSITY), |
2313 | const_iv (GL_LUMINANCE), |
3109 | const_iv (GL_LUMINANCE), |
2314 | const_iv (GL_LUMINANCE_ALPHA), |
3110 | const_iv (GL_LUMINANCE_ALPHA), |
2315 | const_iv (GL_FLOAT), |
3111 | const_iv (GL_FLOAT), |
2316 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
3112 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
3113 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
3114 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
3115 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
3116 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
3117 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
3118 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2317 | const_iv (GL_COMPILE), |
3119 | const_iv (GL_COMPILE), |
2318 | const_iv (GL_PROXY_TEXTURE_1D), |
3120 | const_iv (GL_PROXY_TEXTURE_1D), |
2319 | const_iv (GL_PROXY_TEXTURE_2D), |
3121 | const_iv (GL_PROXY_TEXTURE_2D), |
2320 | const_iv (GL_TEXTURE_1D), |
3122 | const_iv (GL_TEXTURE_1D), |
2321 | const_iv (GL_TEXTURE_2D), |
3123 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2345 | const_iv (GL_COLOR_LOGIC_OP), |
3147 | const_iv (GL_COLOR_LOGIC_OP), |
2346 | const_iv (GL_SEPARABLE_2D), |
3148 | const_iv (GL_SEPARABLE_2D), |
2347 | const_iv (GL_CONVOLUTION_2D), |
3149 | const_iv (GL_CONVOLUTION_2D), |
2348 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
3150 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
2349 | const_iv (GL_CONSTANT_BORDER), |
3151 | const_iv (GL_CONSTANT_BORDER), |
|
|
3152 | const_iv (GL_POINTS), |
2350 | const_iv (GL_LINES), |
3153 | const_iv (GL_LINES), |
2351 | const_iv (GL_LINE_STRIP), |
3154 | const_iv (GL_LINE_STRIP), |
2352 | const_iv (GL_LINE_LOOP), |
3155 | const_iv (GL_LINE_LOOP), |
2353 | const_iv (GL_QUADS), |
3156 | const_iv (GL_QUADS), |
2354 | const_iv (GL_QUAD_STRIP), |
3157 | const_iv (GL_QUAD_STRIP), |
2355 | const_iv (GL_TRIANGLES), |
3158 | const_iv (GL_TRIANGLES), |
2356 | const_iv (GL_TRIANGLE_STRIP), |
3159 | const_iv (GL_TRIANGLE_STRIP), |
2357 | const_iv (GL_TRIANGLE_FAN), |
3160 | const_iv (GL_TRIANGLE_FAN), |
|
|
3161 | const_iv (GL_POLYGON), |
2358 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
3162 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
|
|
3163 | const_iv (GL_POINT_SMOOTH_HINT), |
|
|
3164 | const_iv (GL_LINE_SMOOTH_HINT), |
|
|
3165 | const_iv (GL_POLYGON_SMOOTH_HINT), |
|
|
3166 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
3167 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2359 | const_iv (GL_FASTEST), |
3168 | const_iv (GL_FASTEST), |
|
|
3169 | const_iv (GL_DONT_CARE), |
|
|
3170 | const_iv (GL_NICEST), |
2360 | const_iv (GL_V2F), |
3171 | const_iv (GL_V2F), |
2361 | const_iv (GL_V3F), |
3172 | const_iv (GL_V3F), |
2362 | const_iv (GL_T2F_V3F), |
3173 | const_iv (GL_T2F_V3F), |
2363 | const_iv (GL_T2F_N3F_V3F), |
3174 | const_iv (GL_T2F_N3F_V3F), |
|
|
3175 | const_iv (GL_FUNC_ADD), |
|
|
3176 | const_iv (GL_FUNC_SUBTRACT), |
|
|
3177 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
2364 | # undef const_iv |
3178 | # undef const_iv |
2365 | }; |
3179 | }; |
2366 | |
3180 | |
2367 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3181 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
2368 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3182 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
2369 | |
3183 | |
2370 | texture_av = newAV (); |
3184 | texture_av = newAV (); |
2371 | AvREAL_off (texture_av); |
3185 | AvREAL_off (texture_av); |
2372 | } |
3186 | } |
|
|
3187 | |
|
|
3188 | void |
|
|
3189 | disable_GL_EXT_blend_func_separate () |
|
|
3190 | CODE: |
|
|
3191 | gl.BlendFuncSeparate = 0; |
|
|
3192 | gl.BlendFuncSeparateEXT = 0; |
|
|
3193 | |
|
|
3194 | void |
|
|
3195 | apple_nvidia_bug (int enable) |
2373 | |
3196 | |
2374 | char * |
3197 | char * |
2375 | gl_vendor () |
3198 | gl_vendor () |
2376 | CODE: |
3199 | CODE: |
2377 | RETVAL = (char *)glGetString (GL_VENDOR); |
3200 | RETVAL = (char *)glGetString (GL_VENDOR); |
… | |
… | |
2408 | |
3231 | |
2409 | int glGetError () |
3232 | int glGetError () |
2410 | |
3233 | |
2411 | void glFinish () |
3234 | void glFinish () |
2412 | |
3235 | |
|
|
3236 | void glFlush () |
|
|
3237 | |
2413 | void glClear (int mask) |
3238 | void glClear (int mask) |
2414 | |
3239 | |
2415 | void glClearColor (float r, float g, float b, float a = 1.0) |
3240 | void glClearColor (float r, float g, float b, float a = 1.0) |
2416 | PROTOTYPE: @ |
3241 | PROTOTYPE: @ |
2417 | |
3242 | |
… | |
… | |
2427 | |
3252 | |
2428 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
3253 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
2429 | CODE: |
3254 | CODE: |
2430 | gl_BlendFuncSeparate (sa, da, saa, daa); |
3255 | gl_BlendFuncSeparate (sa, da, saa, daa); |
2431 | |
3256 | |
|
|
3257 | # void glBlendEquation (int se) |
|
|
3258 | |
2432 | void glDepthMask (int flag) |
3259 | void glDepthMask (int flag) |
2433 | |
3260 | |
2434 | void glLogicOp (int opcode) |
3261 | void glLogicOp (int opcode) |
2435 | |
3262 | |
2436 | void glColorMask (int red, int green, int blue, int alpha) |
3263 | void glColorMask (int red, int green, int blue, int alpha) |
… | |
… | |
2450 | # near_ and far_ are due to microsofts buggy "c" compiler |
3277 | # near_ and far_ are due to microsofts buggy "c" compiler |
2451 | void glFrustum (double left, double right, double bottom, double top, double near_, double far_) |
3278 | void glFrustum (double left, double right, double bottom, double top, double near_, double far_) |
2452 | |
3279 | |
2453 | # near_ and far_ are due to microsofts buggy "c" compiler |
3280 | # near_ and far_ are due to microsofts buggy "c" compiler |
2454 | void glOrtho (double left, double right, double bottom, double top, double near_, double far_) |
3281 | void glOrtho (double left, double right, double bottom, double top, double near_, double far_) |
|
|
3282 | |
|
|
3283 | PROTOTYPES: DISABLE |
2455 | |
3284 | |
2456 | void glViewport (int x, int y, int width, int height) |
3285 | void glViewport (int x, int y, int width, int height) |
2457 | |
3286 | |
2458 | void glScissor (int x, int y, int width, int height) |
3287 | void glScissor (int x, int y, int width, int height) |
2459 | |
3288 | |
… | |
… | |
2467 | |
3296 | |
2468 | void glRotate (float angle, float x, float y, float z) |
3297 | void glRotate (float angle, float x, float y, float z) |
2469 | CODE: |
3298 | CODE: |
2470 | glRotatef (angle, x, y, z); |
3299 | glRotatef (angle, x, y, z); |
2471 | |
3300 | |
2472 | void glBegin (int mode) |
|
|
2473 | |
|
|
2474 | void glEnd () |
|
|
2475 | |
|
|
2476 | void glColor (float r, float g, float b, float a = 1.0) |
3301 | void glColor (float r, float g, float b, float a = 1.0) |
2477 | PROTOTYPE: @ |
3302 | PROTOTYPE: @ |
2478 | ALIAS: |
3303 | ALIAS: |
2479 | glColor_premultiply = 1 |
3304 | glColor_premultiply = 1 |
2480 | CODE: |
3305 | CODE: |
2481 | if (ix) |
3306 | if (ix) |
2482 | { |
3307 | { |
… | |
… | |
2485 | b *= a; |
3310 | b *= a; |
2486 | } |
3311 | } |
2487 | // microsoft visual "c" rounds instead of truncating... |
3312 | // microsoft visual "c" rounds instead of truncating... |
2488 | glColor4f (r, g, b, a); |
3313 | glColor4f (r, g, b, a); |
2489 | |
3314 | |
2490 | void glInterleavedArrays (int format, int stride, char *data) |
|
|
2491 | |
|
|
2492 | void glDrawElements (int mode, int count, int type, char *indices) |
|
|
2493 | |
|
|
2494 | # 1.2 void glDrawRangeElements (int mode, int start, int end |
|
|
2495 | |
|
|
2496 | void glRasterPos (float x, float y, float z = 0.) |
3315 | void glRasterPos (float x, float y, float z = 0.) |
2497 | CODE: |
3316 | CODE: |
2498 | glRasterPos3f (0, 0, z); |
3317 | glRasterPos3f (0, 0, z); |
2499 | glBitmap (0, 0, 0, 0, x, y, 0); |
3318 | glBitmap (0, 0, 0, 0, x, y, 0); |
2500 | |
3319 | |
… | |
… | |
2504 | |
3323 | |
2505 | void glTexCoord (float s, float t) |
3324 | void glTexCoord (float s, float t) |
2506 | CODE: |
3325 | CODE: |
2507 | glTexCoord2f (s, t); |
3326 | glTexCoord2f (s, t); |
2508 | |
3327 | |
|
|
3328 | void glRect (float x1, float y1, float x2, float y2) |
|
|
3329 | CODE: |
|
|
3330 | glRectf (x1, y1, x2, y2); |
|
|
3331 | |
|
|
3332 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
3333 | CODE: |
|
|
3334 | glBegin (GL_LINE_LOOP); |
|
|
3335 | glVertex2f (x1, y1); |
|
|
3336 | glVertex2f (x2, y1); |
|
|
3337 | glVertex2f (x2, y2); |
|
|
3338 | glVertex2f (x1, y2); |
|
|
3339 | glEnd (); |
|
|
3340 | |
|
|
3341 | PROTOTYPES: ENABLE |
|
|
3342 | |
|
|
3343 | void glBegin (int mode) |
|
|
3344 | |
|
|
3345 | void glEnd () |
|
|
3346 | |
|
|
3347 | void glPointSize (GLfloat size) |
|
|
3348 | |
|
|
3349 | void glLineWidth (GLfloat width) |
|
|
3350 | |
|
|
3351 | void glInterleavedArrays (int format, int stride, char *data) |
|
|
3352 | |
|
|
3353 | void glDrawElements (int mode, int count, int type, char *indices) |
|
|
3354 | |
|
|
3355 | # 1.2 void glDrawRangeElements (int mode, int start, int end |
|
|
3356 | |
2509 | void glTexEnv (int target, int pname, float param) |
3357 | void glTexEnv (int target, int pname, float param) |
2510 | CODE: |
3358 | CODE: |
2511 | glTexEnvf (target, pname, param); |
3359 | glTexEnvf (target, pname, param); |
2512 | |
3360 | |
2513 | void glTexParameter (int target, int pname, float param) |
3361 | void glTexParameter (int target, int pname, float param) |
… | |
… | |
2529 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
3377 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2530 | CODE: |
3378 | CODE: |
2531 | if (gl.SeparableFilter2D) |
3379 | if (gl.SeparableFilter2D) |
2532 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
3380 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2533 | |
3381 | |
2534 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
3382 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2535 | |
3383 | |
2536 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
3384 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2537 | |
3385 | |
2538 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
3386 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2539 | |
3387 | |
… | |
… | |
2565 | |
3413 | |
2566 | void glEndList () |
3414 | void glEndList () |
2567 | |
3415 | |
2568 | void glCallList (int list) |
3416 | void glCallList (int list) |
2569 | |
3417 | |
|
|
3418 | void c_init () |
|
|
3419 | CODE: |
|
|
3420 | glPixelStorei (GL_PACK_ALIGNMENT , 1); |
|
|
3421 | glPixelStorei (GL_UNPACK_ALIGNMENT, 1); |
|
|
3422 | |
|
|
3423 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
|
|
3424 | |
|
|
3425 | PROTOTYPES: DISABLE |
|
|
3426 | |
|
|
3427 | void |
|
|
3428 | find_widget (SV *self, NV x, NV y) |
|
|
3429 | PPCODE: |
|
|
3430 | { |
|
|
3431 | if (within_widget (self, x, y)) |
|
|
3432 | XPUSHs (self); |
|
|
3433 | } |
|
|
3434 | |
|
|
3435 | BOOT: |
|
|
3436 | { |
|
|
3437 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
|
|
3438 | |
|
|
3439 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
|
|
3440 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
|
|
3441 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
|
|
3442 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
|
|
3443 | } |
|
|
3444 | |
|
|
3445 | void |
|
|
3446 | draw (SV *self) |
|
|
3447 | CODE: |
|
|
3448 | { |
|
|
3449 | HV *hv; |
|
|
3450 | SV **svp; |
|
|
3451 | NV x, y, w, h; |
|
|
3452 | SV *draw_x_sv = GvSV (draw_x_gv); |
|
|
3453 | SV *draw_y_sv = GvSV (draw_y_gv); |
|
|
3454 | SV *draw_w_sv = GvSV (draw_w_gv); |
|
|
3455 | SV *draw_h_sv = GvSV (draw_h_gv); |
|
|
3456 | double draw_x, draw_y; |
|
|
3457 | |
|
|
3458 | if (!SvROK (self)) |
|
|
3459 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
|
|
3460 | |
|
|
3461 | hv = (HV *)SvRV (self); |
|
|
3462 | |
|
|
3463 | if (SvTYPE (hv) != SVt_PVHV) |
|
|
3464 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
|
|
3465 | |
|
|
3466 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
|
|
3467 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
|
|
3468 | |
|
|
3469 | if (!h || !w) |
|
|
3470 | XSRETURN_EMPTY; |
|
|
3471 | |
|
|
3472 | svp = hv_fetch (hv, "x", 1, 0); x = svp ? SvNV (*svp) : 0.; |
|
|
3473 | svp = hv_fetch (hv, "y", 1, 0); y = svp ? SvNV (*svp) : 0.; |
|
|
3474 | |
|
|
3475 | draw_x = SvNV (draw_x_sv) + x; |
|
|
3476 | draw_y = SvNV (draw_y_sv) + y; |
|
|
3477 | |
|
|
3478 | if (draw_x + w < 0 || draw_x >= SvNV (draw_w_sv) |
|
|
3479 | || draw_y + h < 0 || draw_y >= SvNV (draw_h_sv)) |
|
|
3480 | XSRETURN_EMPTY; |
|
|
3481 | |
|
|
3482 | sv_setnv (draw_x_sv, draw_x); |
|
|
3483 | sv_setnv (draw_y_sv, draw_y); |
|
|
3484 | |
|
|
3485 | glPushMatrix (); |
|
|
3486 | glTranslated (x, y, 0); |
|
|
3487 | |
|
|
3488 | if (SvROK (GvSV (hover_gv)) && SvRV (GvSV (hover_gv)) == (SV *)hv) |
|
|
3489 | { |
|
|
3490 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
|
|
3491 | |
|
|
3492 | if (svp && SvTRUE (*svp)) |
|
|
3493 | { |
|
|
3494 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
|
|
3495 | glEnable (GL_BLEND); |
|
|
3496 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
3497 | glBegin (GL_QUADS); |
|
|
3498 | glVertex2f (0, 0); |
|
|
3499 | glVertex2f (w, 0); |
|
|
3500 | glVertex2f (w, h); |
|
|
3501 | glVertex2f (0, h); |
|
|
3502 | glEnd (); |
|
|
3503 | glDisable (GL_BLEND); |
|
|
3504 | } |
|
|
3505 | } |
|
|
3506 | #if 0 |
|
|
3507 | // draw borders, for debugging |
|
|
3508 | glPushMatrix (); |
|
|
3509 | glColor4f (1., 1., 0., 1.); |
|
|
3510 | glTranslatef (.5, .5, 0.); |
|
|
3511 | glBegin (GL_LINE_LOOP); |
|
|
3512 | glVertex2f (0 , 0); |
|
|
3513 | glVertex2f (w - 1, 0); |
|
|
3514 | glVertex2f (w - 1, h - 1); |
|
|
3515 | glVertex2f (0 , h - 1); |
|
|
3516 | glEnd (); |
|
|
3517 | glPopMatrix (); |
|
|
3518 | #endif |
|
|
3519 | PUSHMARK (SP); |
|
|
3520 | XPUSHs (self); |
|
|
3521 | PUTBACK; |
|
|
3522 | call_method ("_draw", G_VOID | G_DISCARD); |
|
|
3523 | SPAGAIN; |
|
|
3524 | |
|
|
3525 | glPopMatrix (); |
|
|
3526 | |
|
|
3527 | draw_x = draw_x - x; sv_setnv (draw_x_sv, draw_x); |
|
|
3528 | draw_y = draw_y - y; sv_setnv (draw_y_sv, draw_y); |
|
|
3529 | } |
|
|
3530 | |