… | |
… | |
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> |
… | |
… | |
34 | #include <SDL_endian.h> |
38 | #include <SDL_endian.h> |
35 | #include <SDL_image.h> |
39 | #include <SDL_image.h> |
36 | #include <SDL_mixer.h> |
40 | #include <SDL_mixer.h> |
37 | #include <SDL_opengl.h> |
41 | #include <SDL_opengl.h> |
38 | |
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 | |
39 | #define PANGO_ENABLE_BACKEND |
50 | #define PANGO_ENABLE_BACKEND |
40 | #define G_DISABLE_CAST_CHECKS |
51 | #define G_DISABLE_CAST_CHECKS |
41 | |
52 | |
42 | #include <glib/gmacros.h> |
53 | #include <glib/gmacros.h> |
43 | |
54 | |
44 | #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 |
45 | |
67 | |
46 | #ifndef _WIN32 |
68 | #ifndef _WIN32 |
47 | # include <sys/types.h> |
69 | # include <sys/types.h> |
48 | # include <sys/socket.h> |
70 | # include <sys/socket.h> |
49 | # include <netinet/in.h> |
71 | # include <netinet/in.h> |
50 | # include <netinet/tcp.h> |
72 | # include <netinet/tcp.h> |
51 | # include <inttypes.h> |
73 | # include <inttypes.h> |
52 | #endif |
74 | #endif |
53 | |
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 | |
54 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
85 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
55 | |
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 */ |
56 | #define FOW_DARKNESS 32 |
89 | #define FOW_DARKNESS 50 |
|
|
90 | #define DARKNESS_ADJUST(n) (n) |
57 | |
91 | |
58 | #define MAP_EXTEND_X 32 |
92 | #define MAP_EXTEND_X 32 |
59 | #define MAP_EXTEND_Y 512 |
93 | #define MAP_EXTEND_Y 512 |
60 | |
94 | |
61 | #define MIN_FONT_HEIGHT 10 |
95 | #define MIN_FONT_HEIGHT 10 |
62 | |
96 | |
63 | #if 0 |
97 | /* mask out modifiers we are not interested in */ |
64 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
98 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
65 | #else |
99 | |
66 | # define PARACHUTE 0 |
100 | #define KMOD_LRAM 0x10000 // our extension |
67 | #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 | } |
68 | |
123 | |
69 | static AV *texture_av; |
124 | static AV *texture_av; |
70 | |
125 | |
71 | static struct |
126 | static struct |
72 | { |
127 | { |
… | |
… | |
109 | av_push (texture_av, (SV *)(size_t)name); |
164 | av_push (texture_av, (SV *)(size_t)name); |
110 | glDeleteTextures (1, &name); |
165 | glDeleteTextures (1, &name); |
111 | } |
166 | } |
112 | |
167 | |
113 | #include "texcache.c" |
168 | #include "texcache.c" |
|
|
169 | #include "rendercache.c" |
114 | |
170 | |
115 | #include "pango-font.c" |
171 | #include "pango-font.c" |
116 | #include "pango-fontmap.c" |
172 | #include "pango-fontmap.c" |
117 | #include "pango-render.c" |
173 | #include "pango-render.c" |
118 | |
174 | |
119 | typedef IV CFPlus__Channel; |
175 | typedef IV DC__Channel; |
120 | typedef SDL_RWops *CFPlus__RW; |
176 | typedef SDL_RWops *DC__RW; |
121 | typedef Mix_Chunk *CFPlus__MixChunk; |
177 | typedef Mix_Chunk *DC__MixChunk; |
122 | typedef Mix_Music *CFPlus__MixMusic; |
178 | typedef Mix_Music *DC__MixMusic; |
123 | |
179 | |
124 | typedef PangoFontDescription *CFPlus__Font; |
180 | typedef PangoFontDescription *DC__Font; |
125 | |
181 | |
126 | static int |
182 | static int |
127 | shape_attr_p (PangoLayoutRun *run) |
183 | shape_attr_p (PangoLayoutRun *run) |
128 | { |
184 | { |
129 | GSList *attrs = run->item->analysis.extra_attrs; |
185 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
143 | |
199 | |
144 | typedef struct cf_layout { |
200 | typedef struct cf_layout { |
145 | PangoLayout *pl; |
201 | PangoLayout *pl; |
146 | float r, g, b, a; // default color for rgba mode |
202 | float r, g, b, a; // default color for rgba mode |
147 | int base_height; |
203 | int base_height; |
148 | CFPlus__Font font; |
204 | DC__Font font; |
|
|
205 | rc_t *rc; |
149 | } *CFPlus__Layout; |
206 | } *DC__Layout; |
150 | |
207 | |
151 | static CFPlus__Font default_font; |
208 | static DC__Font default_font; |
152 | static PangoContext *opengl_context; |
209 | static PangoContext *opengl_context; |
153 | static PangoFontMap *opengl_fontmap; |
210 | static PangoFontMap *opengl_fontmap; |
154 | |
211 | |
155 | static void |
212 | static void |
156 | substitute_func (FcPattern *pattern, gpointer data) |
213 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
161 | #endif |
218 | #endif |
162 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
219 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
163 | } |
220 | } |
164 | |
221 | |
165 | static void |
222 | static void |
166 | layout_update_font (CFPlus__Layout self) |
223 | layout_update_font (DC__Layout self) |
167 | { |
224 | { |
168 | /* 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 |
169 | * reasonably well with bitstream vera |
226 | * reasonably well with dejavu/bistream fonts |
170 | */ |
227 | */ |
171 | PangoFontDescription *font = self->font ? self->font : default_font; |
228 | PangoFontDescription *font = self->font ? self->font : default_font; |
172 | |
229 | |
173 | pango_font_description_set_absolute_size (font, |
230 | pango_font_description_set_absolute_size (font, |
174 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
231 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
175 | |
232 | |
176 | pango_layout_set_font_description (self->pl, font); |
233 | pango_layout_set_font_description (self->pl, font); |
177 | } |
234 | } |
178 | |
235 | |
179 | static void |
236 | static void |
180 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
237 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
181 | { |
238 | { |
182 | PangoRectangle rect; |
239 | PangoRectangle rect; |
183 | |
240 | |
184 | // get_pixel_* wrongly rounds down |
241 | // get_pixel_* wrongly rounds down |
185 | pango_layout_get_extents (self->pl, 0, &rect); |
242 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
196 | |
253 | |
197 | typedef uint16_t tileid; |
254 | typedef uint16_t tileid; |
198 | typedef uint16_t faceid; |
255 | typedef uint16_t faceid; |
199 | |
256 | |
200 | typedef struct { |
257 | typedef struct { |
201 | int name; |
258 | GLuint name; |
202 | int w, h; |
259 | int w, h; |
203 | float s, t; |
260 | float s, t; |
204 | uint8_t r, g, b, a; |
261 | uint8_t r, g, b, a; |
205 | tileid smoothtile; |
262 | tileid smoothtile; |
206 | uint8_t smoothlevel; |
263 | uint8_t smoothlevel; |
|
|
264 | uint8_t unused; /* set to zero on use */ |
207 | } maptex; |
265 | } maptex; |
208 | |
266 | |
209 | typedef struct { |
267 | typedef struct { |
210 | uint32_t player; |
268 | uint32_t player; |
211 | tileid tile[3]; |
269 | tileid tile[3]; |
… | |
… | |
224 | int faces; tileid *face2tile; // [faceid] |
282 | int faces; tileid *face2tile; // [faceid] |
225 | int texs; maptex *tex; // [tileid] |
283 | int texs; maptex *tex; // [tileid] |
226 | |
284 | |
227 | int32_t rows; |
285 | int32_t rows; |
228 | maprow *row; |
286 | maprow *row; |
229 | } *CFPlus__Map; |
287 | } *DC__Map; |
230 | |
288 | |
231 | static char * |
289 | static char * |
232 | prepend (char *ptr, int sze, int inc) |
290 | prepend (char *ptr, int sze, int inc) |
233 | { |
291 | { |
234 | char *p; |
292 | char *p; |
… | |
… | |
272 | self->texs *= 2; |
330 | self->texs *= 2; |
273 | } |
331 | } |
274 | } |
332 | } |
275 | |
333 | |
276 | static maprow * |
334 | static maprow * |
277 | map_get_row (CFPlus__Map self, int y) |
335 | map_get_row (DC__Map self, int y) |
278 | { |
336 | { |
279 | if (0 > y) |
337 | if (0 > y) |
280 | { |
338 | { |
281 | int extend = - y + MAP_EXTEND_Y; |
339 | int extend = - y + MAP_EXTEND_Y; |
282 | Prepend (maprow, self->row, self->rows, extend); |
340 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
320 | |
378 | |
321 | return row->col + (x - row->c0); |
379 | return row->col + (x - row->c0); |
322 | } |
380 | } |
323 | |
381 | |
324 | static mapcell * |
382 | static mapcell * |
325 | map_get_cell (CFPlus__Map self, int x, int y) |
383 | map_get_cell (DC__Map self, int x, int y) |
326 | { |
384 | { |
327 | return row_get_cell (map_get_row (self, y), x); |
385 | return row_get_cell (map_get_row (self, y), x); |
328 | } |
386 | } |
329 | |
387 | |
330 | static void |
388 | static void |
331 | map_clear (CFPlus__Map self) |
389 | map_clear (DC__Map self) |
332 | { |
390 | { |
333 | int r; |
391 | int r; |
334 | |
392 | |
335 | for (r = 0; r < self->rows; r++) |
393 | for (r = 0; r < self->rows; r++) |
336 | Safefree (self->row[r].col); |
394 | Safefree (self->row[r].col); |
… | |
… | |
343 | self->oy = 0; |
401 | self->oy = 0; |
344 | self->row = 0; |
402 | self->row = 0; |
345 | self->rows = 0; |
403 | self->rows = 0; |
346 | } |
404 | } |
347 | |
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 | |
348 | static void |
416 | static void |
349 | 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) |
350 | { |
418 | { |
351 | int x, y; |
419 | int x, y; |
352 | maprow *row; |
420 | maprow *row; |
353 | mapcell *cell; |
421 | mapcell *cell; |
354 | |
422 | |
… | |
… | |
366 | if (x >= row->c1) |
434 | if (x >= row->c1) |
367 | break; |
435 | break; |
368 | |
436 | |
369 | cell = row->col + x - row->c0; |
437 | cell = row->col + x - row->c0; |
370 | |
438 | |
371 | cell->darkness = 0; |
439 | CELL_CLEAR (cell); |
372 | cell->stat_hp = 0; |
|
|
373 | cell->flags = 0; |
|
|
374 | cell->player = 0; |
|
|
375 | } |
440 | } |
376 | } |
441 | } |
377 | } |
442 | } |
378 | |
443 | |
379 | typedef struct { |
444 | typedef struct { |
… | |
… | |
414 | ev.code = 1; |
479 | ev.code = 1; |
415 | ev.data1 = (void *)(long)channel; |
480 | ev.data1 = (void *)(long)channel; |
416 | ev.data2 = 0; |
481 | ev.data2 = 0; |
417 | |
482 | |
418 | 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; |
419 | } |
490 | } |
420 | |
491 | |
421 | static unsigned int |
492 | static unsigned int |
422 | minpot (unsigned int n) |
493 | minpot (unsigned int n) |
423 | { |
494 | { |
… | |
… | |
433 | n |= n >> 16; |
504 | n |= n >> 16; |
434 | |
505 | |
435 | return n + 1; |
506 | return n + 1; |
436 | } |
507 | } |
437 | |
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 | |
438 | /* SDL should provide this, really. */ |
520 | /* SDL should provide this, really. */ |
439 | #define SDLK_MODIFIER_MIN 300 |
521 | #define SDLK_MODIFIER_MIN 300 |
440 | #define SDLK_MODIFIER_MAX 314 |
522 | #define SDLK_MODIFIER_MAX 314 |
441 | |
523 | |
442 | /******************************************************************************/ |
524 | /******************************************************************************/ |
… | |
… | |
480 | return 0; |
562 | return 0; |
481 | |
563 | |
482 | return 1; |
564 | return 1; |
483 | } |
565 | } |
484 | |
566 | |
485 | MODULE = CFPlus PACKAGE = CFPlus |
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 () |
|
|
583 | { |
|
|
584 | char *argv[] = { 0 }; |
|
|
585 | call_argv ("::main", G_DISCARD | G_VOID, argv); |
|
|
586 | } |
|
|
587 | |
|
|
588 | #ifdef __MACOSX__ |
|
|
589 | /* to due surprising braindamage on the side of SDL design, we |
|
|
590 | * do some mind-boggling hack here: SDL requires a custom main() |
|
|
591 | * on OS X, so... we provide one and call the original main(), which, |
|
|
592 | * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, |
|
|
593 | * and which calls our main (== SDL_main) back. |
|
|
594 | */ |
|
|
595 | extern C_LINKAGE int |
|
|
596 | main (int argc, char *argv[]) |
|
|
597 | { |
|
|
598 | deliantra_main (); |
|
|
599 | } |
|
|
600 | |
|
|
601 | #undef main |
|
|
602 | |
|
|
603 | extern C_LINKAGE int main (int argc, char *argv[]); |
|
|
604 | |
|
|
605 | static void |
|
|
606 | SDL_braino (void) |
|
|
607 | { |
|
|
608 | char *argv[] = { "deliantra client", 0 }; |
|
|
609 | (main) (1, argv); |
|
|
610 | } |
|
|
611 | #else |
|
|
612 | static void |
|
|
613 | SDL_braino (void) |
|
|
614 | { |
|
|
615 | deliantra_main (); |
|
|
616 | } |
|
|
617 | #endif |
|
|
618 | |
|
|
619 | MODULE = Deliantra::Client PACKAGE = DC |
486 | |
620 | |
487 | PROTOTYPES: ENABLE |
621 | PROTOTYPES: ENABLE |
488 | |
622 | |
489 | BOOT: |
623 | BOOT: |
490 | { |
624 | { |
491 | HV *stash = gv_stashpv ("CFPlus", 1); |
625 | HV *stash = gv_stashpv ("DC", 1); |
492 | static const struct { |
626 | static const struct { |
493 | const char *name; |
627 | const char *name; |
494 | IV iv; |
628 | IV iv; |
495 | } *civ, const_iv[] = { |
629 | } *civ, const_iv[] = { |
496 | # define const_iv(name) { # name, (IV)name } |
630 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
518 | |
652 | |
519 | const_iv (SDL_APPINPUTFOCUS), |
653 | const_iv (SDL_APPINPUTFOCUS), |
520 | const_iv (SDL_APPMOUSEFOCUS), |
654 | const_iv (SDL_APPMOUSEFOCUS), |
521 | const_iv (SDL_APPACTIVE), |
655 | const_iv (SDL_APPACTIVE), |
522 | |
656 | |
|
|
657 | |
|
|
658 | const_iv (SDLK_UNKNOWN), |
|
|
659 | const_iv (SDLK_FIRST), |
|
|
660 | const_iv (SDLK_BACKSPACE), |
|
|
661 | const_iv (SDLK_TAB), |
|
|
662 | const_iv (SDLK_CLEAR), |
|
|
663 | const_iv (SDLK_RETURN), |
|
|
664 | const_iv (SDLK_PAUSE), |
|
|
665 | const_iv (SDLK_ESCAPE), |
|
|
666 | const_iv (SDLK_SPACE), |
|
|
667 | const_iv (SDLK_EXCLAIM), |
|
|
668 | const_iv (SDLK_QUOTEDBL), |
|
|
669 | const_iv (SDLK_HASH), |
|
|
670 | const_iv (SDLK_DOLLAR), |
|
|
671 | const_iv (SDLK_AMPERSAND), |
|
|
672 | const_iv (SDLK_QUOTE), |
|
|
673 | const_iv (SDLK_LEFTPAREN), |
|
|
674 | const_iv (SDLK_RIGHTPAREN), |
|
|
675 | const_iv (SDLK_ASTERISK), |
|
|
676 | const_iv (SDLK_PLUS), |
|
|
677 | const_iv (SDLK_COMMA), |
|
|
678 | const_iv (SDLK_MINUS), |
|
|
679 | const_iv (SDLK_PERIOD), |
|
|
680 | const_iv (SDLK_SLASH), |
|
|
681 | const_iv (SDLK_0), |
|
|
682 | const_iv (SDLK_1), |
|
|
683 | const_iv (SDLK_2), |
|
|
684 | const_iv (SDLK_3), |
|
|
685 | const_iv (SDLK_4), |
|
|
686 | const_iv (SDLK_5), |
|
|
687 | const_iv (SDLK_6), |
|
|
688 | const_iv (SDLK_7), |
|
|
689 | const_iv (SDLK_8), |
|
|
690 | const_iv (SDLK_9), |
|
|
691 | const_iv (SDLK_COLON), |
|
|
692 | const_iv (SDLK_SEMICOLON), |
|
|
693 | const_iv (SDLK_LESS), |
|
|
694 | const_iv (SDLK_EQUALS), |
|
|
695 | const_iv (SDLK_GREATER), |
|
|
696 | const_iv (SDLK_QUESTION), |
|
|
697 | const_iv (SDLK_AT), |
|
|
698 | |
|
|
699 | const_iv (SDLK_LEFTBRACKET), |
|
|
700 | const_iv (SDLK_BACKSLASH), |
|
|
701 | const_iv (SDLK_RIGHTBRACKET), |
|
|
702 | const_iv (SDLK_CARET), |
|
|
703 | const_iv (SDLK_UNDERSCORE), |
|
|
704 | const_iv (SDLK_BACKQUOTE), |
|
|
705 | const_iv (SDLK_DELETE), |
|
|
706 | |
|
|
707 | const_iv (SDLK_FIRST), |
|
|
708 | const_iv (SDLK_LAST), |
523 | const_iv (SDLK_KP0), |
709 | const_iv (SDLK_KP0), |
524 | const_iv (SDLK_KP1), |
710 | const_iv (SDLK_KP1), |
525 | const_iv (SDLK_KP2), |
711 | const_iv (SDLK_KP2), |
526 | const_iv (SDLK_KP3), |
712 | const_iv (SDLK_KP3), |
527 | const_iv (SDLK_KP4), |
713 | const_iv (SDLK_KP4), |
… | |
… | |
599 | const_iv (KMOD_LMETA), |
785 | const_iv (KMOD_LMETA), |
600 | const_iv (KMOD_RMETA), |
786 | const_iv (KMOD_RMETA), |
601 | const_iv (KMOD_NUM), |
787 | const_iv (KMOD_NUM), |
602 | const_iv (KMOD_CAPS), |
788 | const_iv (KMOD_CAPS), |
603 | const_iv (KMOD_MODE), |
789 | const_iv (KMOD_MODE), |
|
|
790 | |
|
|
791 | const_iv (KMOD_LRAM), |
|
|
792 | |
|
|
793 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
794 | |
|
|
795 | const_iv (SDL_INIT_TIMER), |
|
|
796 | const_iv (SDL_INIT_AUDIO), |
|
|
797 | const_iv (SDL_INIT_VIDEO), |
|
|
798 | const_iv (SDL_INIT_CDROM), |
|
|
799 | const_iv (SDL_INIT_JOYSTICK), |
|
|
800 | const_iv (SDL_INIT_EVERYTHING), |
|
|
801 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
802 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
803 | |
|
|
804 | const_iv (SDL_GL_RED_SIZE), |
|
|
805 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
806 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
807 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
808 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
809 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
810 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
811 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
812 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
813 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
814 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
815 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
816 | const_iv (SDL_GL_STEREO), |
|
|
817 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
818 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
819 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
820 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
821 | |
|
|
822 | const_iv (FOW_DARKNESS) |
604 | # undef const_iv |
823 | # undef const_iv |
605 | }; |
824 | }; |
606 | |
825 | |
607 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
826 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
608 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
827 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
626 | |
845 | |
627 | NV floor (NV x) |
846 | NV floor (NV x) |
628 | |
847 | |
629 | NV ceil (NV x) |
848 | NV ceil (NV x) |
630 | |
849 | |
|
|
850 | IV minpot (UV n) |
|
|
851 | |
|
|
852 | IV popcount (UV n) |
|
|
853 | |
|
|
854 | NV distance (NV dx, NV dy) |
|
|
855 | CODE: |
|
|
856 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
|
|
857 | OUTPUT: |
|
|
858 | RETVAL |
|
|
859 | |
631 | void |
860 | void |
632 | pango_init () |
861 | pango_init () |
633 | CODE: |
862 | CODE: |
634 | { |
863 | { |
635 | opengl_fontmap = pango_opengl_font_map_new (); |
864 | opengl_fontmap = pango_opengl_font_map_new (); |
636 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
865 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
637 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
866 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
867 | /*pango_context_set_font_description (opengl_context, default_font);*/ |
|
|
868 | #if PANGO_VERSION_CHECK (1, 15, 2) |
|
|
869 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
870 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
871 | #endif |
638 | } |
872 | } |
639 | |
873 | |
640 | char * |
|
|
641 | SDL_GetError () |
874 | char *SDL_GetError () |
642 | |
875 | |
643 | int |
876 | void SDL_braino () |
644 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
|
|
645 | |
877 | |
646 | void |
878 | int SDL_Init (U32 flags) |
|
|
879 | |
|
|
880 | int SDL_InitSubSystem (U32 flags) |
|
|
881 | |
|
|
882 | void SDL_QuitSubSystem (U32 flags) |
|
|
883 | |
647 | SDL_Quit () |
884 | void SDL_Quit () |
|
|
885 | |
|
|
886 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
887 | |
|
|
888 | int SDL_GL_GetAttribute (int attr) |
|
|
889 | CODE: |
|
|
890 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
|
|
891 | XSRETURN_UNDEF; |
|
|
892 | OUTPUT: |
|
|
893 | RETVAL |
648 | |
894 | |
649 | void |
895 | void |
650 | SDL_ListModes (int rgb, int alpha) |
896 | SDL_ListModes (int rgb, int alpha) |
651 | PPCODE: |
897 | PPCODE: |
652 | { |
898 | { |
… | |
… | |
664 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
910 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
665 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
911 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
666 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
912 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
667 | |
913 | |
668 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
914 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
669 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
670 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
671 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
915 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
672 | #endif |
|
|
673 | |
916 | |
674 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
917 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
675 | |
918 | |
676 | if (m && m != (SDL_Rect **)-1) |
919 | if (m && m != (SDL_Rect **)-1) |
677 | while (*m) |
920 | while (*m) |
678 | { |
921 | { |
679 | if ((*m)->w >= 640 && (*m)->h >= 480) |
922 | if ((*m)->w >= 400 && (*m)->h >= 300) |
680 | { |
923 | { |
681 | AV *av = newAV (); |
924 | AV *av = newAV (); |
682 | av_push (av, newSViv ((*m)->w)); |
925 | av_push (av, newSViv ((*m)->w)); |
683 | av_push (av, newSViv ((*m)->h)); |
926 | av_push (av, newSViv ((*m)->h)); |
684 | av_push (av, newSViv (rgb)); |
927 | av_push (av, newSViv (rgb)); |
… | |
… | |
708 | |
951 | |
709 | if (RETVAL) |
952 | if (RETVAL) |
710 | { |
953 | { |
711 | av_clear (texture_av); |
954 | av_clear (texture_av); |
712 | |
955 | |
713 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
956 | SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); |
714 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
957 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
715 | #include "glfunc.h" |
958 | #include "glfunc.h" |
716 | #undef GL_FUNC |
959 | #undef GL_FUNC |
|
|
960 | |
|
|
961 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
|
|
962 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
717 | } |
963 | } |
718 | } |
964 | } |
719 | OUTPUT: |
965 | OUTPUT: |
720 | RETVAL |
966 | RETVAL |
721 | |
967 | |
… | |
… | |
725 | char * |
971 | char * |
726 | SDL_GetKeyName (int sym) |
972 | SDL_GetKeyName (int sym) |
727 | |
973 | |
728 | int |
974 | int |
729 | SDL_GetAppState () |
975 | SDL_GetAppState () |
|
|
976 | |
|
|
977 | int |
|
|
978 | SDL_GetModState () |
730 | |
979 | |
731 | void |
980 | void |
732 | poll_events () |
981 | poll_events () |
733 | PPCODE: |
982 | PPCODE: |
734 | { |
983 | { |
… | |
… | |
744 | { |
993 | { |
745 | case SDL_KEYDOWN: |
994 | case SDL_KEYDOWN: |
746 | case SDL_KEYUP: |
995 | case SDL_KEYUP: |
747 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
996 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
748 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
997 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
749 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
998 | hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0); |
750 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
999 | hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */ |
751 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
1000 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
752 | break; |
1001 | break; |
753 | |
1002 | |
754 | case SDL_ACTIVEEVENT: |
1003 | case SDL_ACTIVEEVENT: |
755 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
1004 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
773 | x = ev.motion.x; |
1022 | x = ev.motion.x; |
774 | y = ev.motion.y; |
1023 | y = ev.motion.y; |
775 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
1024 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
776 | } |
1025 | } |
777 | |
1026 | |
778 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1027 | hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); |
779 | hv_store (hv, "state", 5, newSViv (state), 0); |
1028 | hv_store (hv, "state", 5, newSViv (state), 0); |
780 | hv_store (hv, "x", 1, newSViv (x), 0); |
1029 | hv_store (hv, "x", 1, newSViv (x), 0); |
781 | hv_store (hv, "y", 1, newSViv (y), 0); |
1030 | hv_store (hv, "y", 1, newSViv (y), 0); |
782 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
1031 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
783 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
1032 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
784 | } |
1033 | } |
785 | break; |
1034 | break; |
786 | |
1035 | |
787 | case SDL_MOUSEBUTTONDOWN: |
1036 | case SDL_MOUSEBUTTONDOWN: |
788 | case SDL_MOUSEBUTTONUP: |
1037 | case SDL_MOUSEBUTTONUP: |
789 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1038 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
790 | |
1039 | |
791 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
1040 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
792 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
1041 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
793 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
1042 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
794 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
1043 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
799 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
1048 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
800 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
1049 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
801 | break; |
1050 | break; |
802 | } |
1051 | } |
803 | |
1052 | |
804 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
1053 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
805 | } |
1054 | } |
806 | } |
1055 | } |
|
|
1056 | |
|
|
1057 | char * |
|
|
1058 | SDL_AudioDriverName () |
|
|
1059 | CODE: |
|
|
1060 | { |
|
|
1061 | char buf [256]; |
|
|
1062 | if (!SDL_AudioDriverName (buf, sizeof (buf))) |
|
|
1063 | XSRETURN_UNDEF; |
|
|
1064 | |
|
|
1065 | RETVAL = buf; |
|
|
1066 | } |
|
|
1067 | OUTPUT: |
|
|
1068 | RETVAL |
807 | |
1069 | |
808 | int |
1070 | int |
809 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1071 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
810 | POSTCALL: |
1072 | POSTCALL: |
811 | Mix_HookMusicFinished (music_finished); |
1073 | Mix_HookMusicFinished (music_finished); |
812 | Mix_ChannelFinished (channel_finished); |
1074 | Mix_ChannelFinished (channel_finished); |
813 | |
1075 | |
814 | void |
1076 | void |
|
|
1077 | Mix_QuerySpec () |
|
|
1078 | PPCODE: |
|
|
1079 | { |
|
|
1080 | int freq, channels; |
|
|
1081 | Uint16 format; |
|
|
1082 | |
|
|
1083 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
1084 | { |
|
|
1085 | EXTEND (SP, 3); |
|
|
1086 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
1087 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
1088 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
1089 | } |
|
|
1090 | } |
|
|
1091 | |
|
|
1092 | void |
815 | Mix_CloseAudio () |
1093 | Mix_CloseAudio () |
816 | |
1094 | |
817 | int |
1095 | int |
818 | Mix_AllocateChannels (int numchans = -1) |
1096 | Mix_AllocateChannels (int numchans = -1) |
|
|
1097 | |
|
|
1098 | const char * |
|
|
1099 | Mix_GetError () |
819 | |
1100 | |
820 | void |
1101 | void |
821 | lowdelay (int fd, int val = 1) |
1102 | lowdelay (int fd, int val = 1) |
822 | CODE: |
1103 | CODE: |
823 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
1104 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
… | |
… | |
849 | } |
1130 | } |
850 | } |
1131 | } |
851 | #endif |
1132 | #endif |
852 | } |
1133 | } |
853 | |
1134 | |
854 | void |
1135 | int |
855 | add_font (char *file) |
1136 | add_font (char *file) |
856 | CODE: |
1137 | CODE: |
857 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1138 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
1139 | OUTPUT: |
|
|
1140 | RETVAL |
|
|
1141 | |
|
|
1142 | void |
|
|
1143 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
858 | |
1144 | |
859 | void |
1145 | void |
860 | load_image_inline (SV *image_) |
1146 | load_image_inline (SV *image_) |
861 | ALIAS: |
1147 | ALIAS: |
862 | load_image_file = 1 |
1148 | load_image_file = 1 |
… | |
… | |
948 | void |
1234 | void |
949 | error (char *message) |
1235 | error (char *message) |
950 | CODE: |
1236 | CODE: |
951 | fprintf (stderr, "ERROR: %s\n", message); |
1237 | fprintf (stderr, "ERROR: %s\n", message); |
952 | #ifdef _WIN32 |
1238 | #ifdef _WIN32 |
953 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
1239 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
954 | #endif |
1240 | #endif |
955 | |
1241 | |
956 | void |
1242 | void |
957 | fatal (char *message) |
1243 | fatal (char *message) |
958 | CODE: |
1244 | CODE: |
959 | fprintf (stderr, "FATAL: %s\n", message); |
1245 | fprintf (stderr, "FATAL: %s\n", message); |
960 | #ifdef _WIN32 |
1246 | #ifdef _WIN32 |
961 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1247 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
962 | #endif |
1248 | #endif |
963 | _exit (1); |
1249 | _exit (1); |
964 | |
1250 | |
965 | void |
1251 | void |
966 | _exit (int retval = 0) |
1252 | _exit (int retval = 0) |
… | |
… | |
978 | #if DEBUG |
1264 | #if DEBUG |
979 | VALGRIND_DO_LEAK_CHECK; |
1265 | VALGRIND_DO_LEAK_CHECK; |
980 | #endif |
1266 | #endif |
981 | } |
1267 | } |
982 | |
1268 | |
983 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1269 | int |
|
|
1270 | SvREFCNT (SV *sv) |
|
|
1271 | CODE: |
|
|
1272 | RETVAL = SvREFCNT (sv); |
|
|
1273 | OUTPUT: |
|
|
1274 | RETVAL |
|
|
1275 | |
|
|
1276 | MODULE = Deliantra::Client PACKAGE = DC::Font |
984 | |
1277 | |
985 | PROTOTYPES: DISABLE |
1278 | PROTOTYPES: DISABLE |
986 | |
1279 | |
987 | CFPlus::Font |
1280 | DC::Font |
988 | new_from_file (SV *class, char *path, int id = 0) |
1281 | new_from_file (SV *class, char *path, int id = 0) |
989 | CODE: |
1282 | CODE: |
990 | { |
1283 | { |
991 | int count; |
1284 | int count; |
992 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1285 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
995 | } |
1288 | } |
996 | OUTPUT: |
1289 | OUTPUT: |
997 | RETVAL |
1290 | RETVAL |
998 | |
1291 | |
999 | void |
1292 | void |
1000 | DESTROY (CFPlus::Font self) |
1293 | DESTROY (DC::Font self) |
1001 | CODE: |
1294 | CODE: |
1002 | pango_font_description_free (self); |
1295 | pango_font_description_free (self); |
1003 | |
1296 | |
1004 | void |
1297 | void |
1005 | make_default (CFPlus::Font self) |
1298 | make_default (DC::Font self) |
1006 | PROTOTYPE: $ |
1299 | PROTOTYPE: $ |
1007 | CODE: |
1300 | CODE: |
1008 | default_font = self; |
1301 | default_font = self; |
1009 | |
1302 | |
1010 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1303 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1011 | |
1304 | |
1012 | PROTOTYPES: DISABLE |
1305 | PROTOTYPES: DISABLE |
1013 | |
1306 | |
1014 | void |
1307 | void |
1015 | reset_glyph_cache () |
1308 | glyph_cache_backup () |
1016 | PROTOTYPE: |
1309 | PROTOTYPE: |
1017 | CODE: |
1310 | CODE: |
|
|
1311 | tc_backup (); |
|
|
1312 | |
|
|
1313 | void |
|
|
1314 | glyph_cache_restore () |
|
|
1315 | PROTOTYPE: |
|
|
1316 | CODE: |
1018 | tc_clear (); |
1317 | tc_restore (); |
1019 | |
1318 | |
1020 | CFPlus::Layout |
1319 | DC::Layout |
1021 | new (SV *class) |
1320 | new (SV *class) |
1022 | CODE: |
1321 | CODE: |
1023 | New (0, RETVAL, 1, struct cf_layout); |
1322 | New (0, RETVAL, 1, struct cf_layout); |
1024 | |
1323 | |
1025 | RETVAL->pl = pango_layout_new (opengl_context); |
1324 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
1027 | RETVAL->g = 1.; |
1326 | RETVAL->g = 1.; |
1028 | RETVAL->b = 1.; |
1327 | RETVAL->b = 1.; |
1029 | RETVAL->a = 1.; |
1328 | RETVAL->a = 1.; |
1030 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1329 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1031 | RETVAL->font = 0; |
1330 | RETVAL->font = 0; |
|
|
1331 | RETVAL->rc = rc_alloc (); |
1032 | |
1332 | |
1033 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1333 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1034 | layout_update_font (RETVAL); |
1334 | layout_update_font (RETVAL); |
1035 | OUTPUT: |
1335 | OUTPUT: |
1036 | RETVAL |
1336 | RETVAL |
1037 | |
1337 | |
1038 | void |
1338 | void |
1039 | DESTROY (CFPlus::Layout self) |
1339 | DESTROY (DC::Layout self) |
1040 | CODE: |
1340 | CODE: |
1041 | g_object_unref (self->pl); |
1341 | g_object_unref (self->pl); |
|
|
1342 | rc_free (self->rc); |
1042 | Safefree (self); |
1343 | Safefree (self); |
1043 | |
1344 | |
1044 | void |
1345 | void |
1045 | set_text (CFPlus::Layout self, SV *text_) |
1346 | set_text (DC::Layout self, SV *text_) |
1046 | CODE: |
1347 | CODE: |
1047 | { |
1348 | { |
1048 | STRLEN textlen; |
1349 | STRLEN textlen; |
1049 | char *text = SvPVutf8 (text_, textlen); |
1350 | char *text = SvPVutf8 (text_, textlen); |
1050 | |
1351 | |
1051 | pango_layout_set_text (self->pl, text, textlen); |
1352 | pango_layout_set_text (self->pl, text, textlen); |
1052 | } |
1353 | } |
1053 | |
1354 | |
1054 | void |
1355 | void |
1055 | set_markup (CFPlus::Layout self, SV *text_) |
1356 | set_markup (DC::Layout self, SV *text_) |
1056 | CODE: |
1357 | CODE: |
1057 | { |
1358 | { |
1058 | STRLEN textlen; |
1359 | STRLEN textlen; |
1059 | char *text = SvPVutf8 (text_, textlen); |
1360 | char *text = SvPVutf8 (text_, textlen); |
1060 | |
1361 | |
1061 | pango_layout_set_markup (self->pl, text, textlen); |
1362 | pango_layout_set_markup (self->pl, text, textlen); |
1062 | } |
1363 | } |
1063 | |
1364 | |
1064 | void |
1365 | void |
1065 | set_shapes (CFPlus::Layout self, ...) |
1366 | set_shapes (DC::Layout self, ...) |
1066 | CODE: |
1367 | CODE: |
1067 | { |
1368 | { |
1068 | PangoAttrList *attrs = 0; |
1369 | PangoAttrList *attrs = 0; |
1069 | const char *text = pango_layout_get_text (self->pl); |
1370 | const char *text = pango_layout_get_text (self->pl); |
1070 | const char *pos = text; |
1371 | const char *pos = text; |
… | |
… | |
1105 | if (attrs) |
1406 | if (attrs) |
1106 | pango_layout_set_attributes (self->pl, attrs); |
1407 | pango_layout_set_attributes (self->pl, attrs); |
1107 | } |
1408 | } |
1108 | |
1409 | |
1109 | void |
1410 | void |
1110 | get_shapes (CFPlus::Layout self) |
1411 | get_shapes (DC::Layout self) |
1111 | PPCODE: |
1412 | PPCODE: |
1112 | { |
1413 | { |
1113 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1414 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1114 | |
1415 | |
1115 | do |
1416 | do |
1116 | { |
1417 | { |
1117 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1418 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1118 | |
1419 | |
1119 | if (run && shape_attr_p (run)) |
1420 | if (run && shape_attr_p (run)) |
1120 | { |
1421 | { |
1121 | PangoRectangle extents; |
1422 | PangoRectangle extents; |
1122 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1423 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1130 | |
1431 | |
1131 | pango_layout_iter_free (iter); |
1432 | pango_layout_iter_free (iter); |
1132 | } |
1433 | } |
1133 | |
1434 | |
1134 | int |
1435 | int |
1135 | has_wrapped (CFPlus::Layout self) |
1436 | has_wrapped (DC::Layout self) |
1136 | CODE: |
1437 | CODE: |
1137 | { |
1438 | { |
1138 | int lines = 1; |
1439 | int lines = 1; |
1139 | const char *text = pango_layout_get_text (self->pl); |
1440 | const char *text = pango_layout_get_text (self->pl); |
1140 | |
1441 | |
… | |
… | |
1145 | } |
1446 | } |
1146 | OUTPUT: |
1447 | OUTPUT: |
1147 | RETVAL |
1448 | RETVAL |
1148 | |
1449 | |
1149 | SV * |
1450 | SV * |
1150 | get_text (CFPlus::Layout self) |
1451 | get_text (DC::Layout self) |
1151 | CODE: |
1452 | CODE: |
1152 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1453 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1153 | sv_utf8_decode (RETVAL); |
1454 | sv_utf8_decode (RETVAL); |
1154 | OUTPUT: |
1455 | OUTPUT: |
1155 | RETVAL |
1456 | RETVAL |
1156 | |
1457 | |
1157 | void |
1458 | void |
1158 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1459 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1159 | CODE: |
1460 | CODE: |
1160 | self->r = r; |
1461 | self->r = r; |
1161 | self->g = g; |
1462 | self->g = g; |
1162 | self->b = b; |
1463 | self->b = b; |
1163 | self->a = a; |
1464 | self->a = a; |
1164 | |
1465 | |
1165 | void |
1466 | void |
1166 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1467 | set_font (DC::Layout self, DC::Font font = 0) |
1167 | CODE: |
1468 | CODE: |
1168 | if (self->font != font) |
1469 | if (self->font != font) |
1169 | { |
1470 | { |
1170 | self->font = font; |
1471 | self->font = font; |
1171 | layout_update_font (self); |
1472 | layout_update_font (self); |
1172 | } |
1473 | } |
1173 | |
1474 | |
1174 | void |
1475 | void |
1175 | set_height (CFPlus::Layout self, int base_height) |
1476 | set_height (DC::Layout self, int base_height) |
1176 | CODE: |
1477 | CODE: |
1177 | if (self->base_height != base_height) |
1478 | if (self->base_height != base_height) |
1178 | { |
1479 | { |
1179 | self->base_height = base_height; |
1480 | self->base_height = base_height; |
1180 | layout_update_font (self); |
1481 | layout_update_font (self); |
1181 | } |
1482 | } |
1182 | |
1483 | |
1183 | void |
1484 | void |
1184 | set_width (CFPlus::Layout self, int max_width = -1) |
1485 | set_width (DC::Layout self, int max_width = -1) |
1185 | CODE: |
1486 | CODE: |
1186 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1487 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1187 | |
1488 | |
1188 | void |
1489 | void |
1189 | set_indent (CFPlus::Layout self, int indent) |
1490 | set_indent (DC::Layout self, int indent) |
1190 | CODE: |
1491 | CODE: |
1191 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1492 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1192 | |
1493 | |
1193 | void |
1494 | void |
1194 | set_spacing (CFPlus::Layout self, int spacing) |
1495 | set_spacing (DC::Layout self, int spacing) |
1195 | CODE: |
1496 | CODE: |
1196 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1497 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1197 | |
1498 | |
1198 | void |
1499 | void |
1199 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1500 | set_ellipsise (DC::Layout self, int ellipsise) |
1200 | CODE: |
1501 | CODE: |
1201 | pango_layout_set_ellipsize (self->pl, |
1502 | pango_layout_set_ellipsize (self->pl, |
1202 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1503 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1203 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1504 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1204 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1505 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1205 | : PANGO_ELLIPSIZE_NONE |
1506 | : PANGO_ELLIPSIZE_NONE |
1206 | ); |
1507 | ); |
1207 | |
1508 | |
1208 | void |
1509 | void |
1209 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1510 | set_single_paragraph_mode (DC::Layout self, int spm) |
1210 | CODE: |
1511 | CODE: |
1211 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1512 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1212 | |
1513 | |
1213 | void |
1514 | void |
1214 | size (CFPlus::Layout self) |
1515 | size (DC::Layout self) |
1215 | PPCODE: |
1516 | PPCODE: |
1216 | { |
1517 | { |
1217 | int w, h; |
1518 | int w, h; |
1218 | |
1519 | |
1219 | layout_get_pixel_size (self, &w, &h); |
1520 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1222 | PUSHs (sv_2mortal (newSViv (w))); |
1523 | PUSHs (sv_2mortal (newSViv (w))); |
1223 | PUSHs (sv_2mortal (newSViv (h))); |
1524 | PUSHs (sv_2mortal (newSViv (h))); |
1224 | } |
1525 | } |
1225 | |
1526 | |
1226 | int |
1527 | int |
1227 | descent (CFPlus::Layout self) |
1528 | descent (DC::Layout self) |
1228 | CODE: |
1529 | CODE: |
1229 | { |
1530 | { |
1230 | PangoRectangle rect; |
1531 | PangoRectangle rect; |
1231 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1532 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1232 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1533 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1233 | RETVAL = PANGO_DESCENT (rect); |
1534 | RETVAL = PANGO_DESCENT (rect); |
1234 | } |
1535 | } |
1235 | OUTPUT: |
1536 | OUTPUT: |
1236 | RETVAL |
1537 | RETVAL |
1237 | |
1538 | |
1238 | int |
1539 | int |
1239 | xy_to_index (CFPlus::Layout self, int x, int y) |
1540 | xy_to_index (DC::Layout self, int x, int y) |
1240 | CODE: |
1541 | CODE: |
1241 | { |
1542 | { |
1242 | int index, trailing; |
1543 | int index, trailing; |
1243 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1544 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1244 | RETVAL = index + trailing; |
1545 | RETVAL = index + trailing; |
1245 | } |
1546 | } |
1246 | OUTPUT: |
1547 | OUTPUT: |
1247 | RETVAL |
1548 | RETVAL |
1248 | |
1549 | |
1249 | void |
1550 | void |
1250 | cursor_pos (CFPlus::Layout self, int index) |
1551 | cursor_pos (DC::Layout self, int index) |
1251 | PPCODE: |
1552 | PPCODE: |
1252 | { |
1553 | { |
1253 | PangoRectangle strong_pos; |
1554 | PangoRectangle pos; |
1254 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1555 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1255 | |
1556 | |
1256 | EXTEND (SP, 3); |
1557 | EXTEND (SP, 3); |
1257 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1558 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1258 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1559 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1259 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1560 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1260 | } |
1561 | } |
1261 | |
1562 | |
1262 | void |
1563 | void |
1263 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1564 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1264 | PPCODE: |
1565 | PPCODE: |
1265 | { |
1566 | { |
1266 | int line, x; |
1567 | int line, x; |
1267 | |
1568 | |
1268 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1569 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1570 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1269 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1571 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1270 | |
1572 | --line; |
|
|
1573 | #endif |
1271 | EXTEND (SP, 2); |
1574 | EXTEND (SP, 2); |
1272 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1575 | PUSHs (sv_2mortal (newSViv (line))); |
1273 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1576 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1274 | } |
1577 | } |
1275 | |
1578 | |
1276 | void |
1579 | void |
1277 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1580 | line_x_to_index (DC::Layout self, int line, int x) |
1278 | PPCODE: |
1581 | PPCODE: |
1279 | { |
1582 | { |
1280 | PangoLayoutLine *lp; |
1583 | PangoLayoutLine *lp; |
1281 | int index, trailing; |
1584 | int index, trailing; |
1282 | |
1585 | |
1283 | if (line < 0) |
1586 | if (line < 0) |
1284 | XSRETURN_EMPTY; |
1587 | XSRETURN_EMPTY; |
1285 | |
1588 | |
1286 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1589 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1287 | XSRETURN_EMPTY; /* do better */ |
1590 | XSRETURN_EMPTY; /* do better */ |
1288 | |
1591 | |
1289 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1592 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1290 | |
1593 | |
1291 | EXTEND (SP, 2); |
1594 | EXTEND (SP, 2); |
… | |
… | |
1297 | PUSHs (sv_2mortal (newSViv (trailing))); |
1600 | PUSHs (sv_2mortal (newSViv (trailing))); |
1298 | } |
1601 | } |
1299 | } |
1602 | } |
1300 | |
1603 | |
1301 | void |
1604 | void |
1302 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1605 | render (DC::Layout self, float x, float y, int flags = 0) |
1303 | PPCODE: |
1606 | CODE: |
|
|
1607 | rc_clear (self->rc); |
1304 | pango_opengl_render_layout_subpixel ( |
1608 | pango_opengl_render_layout_subpixel ( |
1305 | self->pl, |
1609 | self->pl, |
|
|
1610 | self->rc, |
1306 | x * PANGO_SCALE, y * PANGO_SCALE, |
1611 | x * PANGO_SCALE, y * PANGO_SCALE, |
1307 | self->r, self->g, self->b, self->a, |
1612 | self->r, self->g, self->b, self->a, |
1308 | flags |
1613 | flags |
1309 | ); |
1614 | ); |
|
|
1615 | // we assume that context_change actually clears/frees stuff |
|
|
1616 | // and does not do any recomputation... |
|
|
1617 | pango_layout_context_changed (self->pl); |
1310 | |
1618 | |
1311 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1619 | void |
|
|
1620 | draw (DC::Layout self) |
|
|
1621 | CODE: |
|
|
1622 | { |
|
|
1623 | glEnable (GL_TEXTURE_2D); |
|
|
1624 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1625 | glEnable (GL_BLEND); |
|
|
1626 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1627 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1628 | glEnable (GL_ALPHA_TEST); |
|
|
1629 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1630 | |
|
|
1631 | rc_draw (self->rc); |
|
|
1632 | |
|
|
1633 | glDisable (GL_ALPHA_TEST); |
|
|
1634 | glDisable (GL_BLEND); |
|
|
1635 | glDisable (GL_TEXTURE_2D); |
|
|
1636 | } |
|
|
1637 | |
|
|
1638 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1312 | |
1639 | |
1313 | PROTOTYPES: ENABLE |
1640 | PROTOTYPES: ENABLE |
1314 | |
|
|
1315 | int minpot (int n) |
|
|
1316 | |
1641 | |
1317 | void |
1642 | void |
1318 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1643 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1319 | CODE: |
1644 | CODE: |
1320 | { |
1645 | { |
… | |
… | |
1347 | HV *hv = (HV *)SvRV (self); |
1672 | HV *hv = (HV *)SvRV (self); |
1348 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1673 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1349 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1674 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1350 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1675 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1351 | |
1676 | |
|
|
1677 | if (name <= 0) |
|
|
1678 | XSRETURN_EMPTY; |
|
|
1679 | |
1352 | if (items < 5) |
1680 | if (items < 5) |
1353 | { |
1681 | { |
1354 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1682 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1355 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1683 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1356 | } |
1684 | } |
… | |
… | |
1383 | glDisable (GL_ALPHA_TEST); |
1711 | glDisable (GL_ALPHA_TEST); |
1384 | glDisable (GL_BLEND); |
1712 | glDisable (GL_BLEND); |
1385 | } |
1713 | } |
1386 | } |
1714 | } |
1387 | |
1715 | |
|
|
1716 | void |
|
|
1717 | 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) |
|
|
1718 | PROTOTYPE: @ |
|
|
1719 | CODE: |
|
|
1720 | { |
|
|
1721 | glEnable (GL_BLEND); |
|
|
1722 | glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1723 | glEnable (GL_TEXTURE_2D); |
|
|
1724 | glBindTexture (GL_TEXTURE_2D, name1); |
|
|
1725 | |
|
|
1726 | glColor3f (intensity, intensity, intensity); |
|
|
1727 | glPushMatrix (); |
|
|
1728 | glScalef (1./3, 1./3, 1.); |
|
|
1729 | |
|
|
1730 | if (blend > 0.f) |
|
|
1731 | { |
|
|
1732 | float dx3 = dx * -3.f / w; |
|
|
1733 | float dy3 = dy * -3.f / h; |
|
|
1734 | GLfloat env_color[4] = { 0., 0., 0., blend }; |
|
|
1735 | |
|
|
1736 | /* interpolate the two shadow textures */ |
|
|
1737 | /* stage 0 == rgb(glcolor) + alpha(t0) */ |
|
|
1738 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1739 | |
|
|
1740 | /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */ |
|
|
1741 | gl.ActiveTexture (GL_TEXTURE1); |
|
|
1742 | glEnable (GL_TEXTURE_2D); |
|
|
1743 | glBindTexture (GL_TEXTURE_2D, name2); |
|
|
1744 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); |
|
|
1745 | |
|
|
1746 | /* rgb == rgb(glcolor) */ |
|
|
1747 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); |
|
|
1748 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR); |
|
|
1749 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
|
|
1750 | |
|
|
1751 | /* alpha = interpolate t0, t1 by env_alpha */ |
|
|
1752 | glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color); |
|
|
1753 | |
|
|
1754 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); |
|
|
1755 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); |
|
|
1756 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); |
|
|
1757 | |
|
|
1758 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); |
|
|
1759 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); |
|
|
1760 | |
|
|
1761 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); |
|
|
1762 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); |
|
|
1763 | |
|
|
1764 | glBegin (GL_QUADS); |
|
|
1765 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0); |
|
|
1766 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h); |
|
|
1767 | gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h); |
|
|
1768 | gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0); |
|
|
1769 | glEnd (); |
|
|
1770 | |
|
|
1771 | glDisable (GL_TEXTURE_2D); |
|
|
1772 | gl.ActiveTexture (GL_TEXTURE0); |
|
|
1773 | } |
|
|
1774 | else |
|
|
1775 | { |
|
|
1776 | /* simple blending of one texture, also opengl <1.3 path */ |
|
|
1777 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1778 | |
|
|
1779 | glBegin (GL_QUADS); |
|
|
1780 | glTexCoord2f (0, 0); glVertex2f (0, 0); |
|
|
1781 | glTexCoord2f (0, t); glVertex2f (0, h); |
|
|
1782 | glTexCoord2f (s, t); glVertex2f (w, h); |
|
|
1783 | glTexCoord2f (s, 0); glVertex2f (w, 0); |
|
|
1784 | glEnd (); |
|
|
1785 | } |
|
|
1786 | |
|
|
1787 | /* draw ?-marks or equivalent, this is very clumsy code :/ */ |
|
|
1788 | { |
|
|
1789 | int x, y; |
|
|
1790 | int dx3 = dx * 3; |
|
|
1791 | int dy3 = dy * 3; |
|
|
1792 | |
|
|
1793 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1794 | glBindTexture (GL_TEXTURE_2D, hidden_tex); |
|
|
1795 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1796 | glTranslatef (-1., -1., 0); |
|
|
1797 | glBegin (GL_QUADS); |
|
|
1798 | |
|
|
1799 | for (y = 1; y < h; y += 3) |
|
|
1800 | { |
|
|
1801 | int y1 = y - dy3; |
|
|
1802 | int y1valid = y1 >= 0 && y1 < h; |
|
|
1803 | |
|
|
1804 | for (x = 1; x < w; x += 3) |
|
|
1805 | { |
|
|
1806 | int x1 = x - dx3; |
|
|
1807 | uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1808 | uint8_t h2; |
|
|
1809 | |
|
|
1810 | if (y1valid && x1 >= 0 && x1 < w) |
|
|
1811 | h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1812 | else |
|
|
1813 | h2 = 1; /* out of range == invisible */ |
|
|
1814 | |
|
|
1815 | if (h1 || h2) |
|
|
1816 | { |
|
|
1817 | float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend; |
|
|
1818 | glColor4f (1., 1., 1., alpha); |
|
|
1819 | |
|
|
1820 | glTexCoord2f (0, 0.); glVertex2i (x , y ); |
|
|
1821 | glTexCoord2f (0, 1.); glVertex2i (x , y + 3); |
|
|
1822 | glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3); |
|
|
1823 | glTexCoord2f (1, 0.); glVertex2i (x + 3, y ); |
|
|
1824 | } |
|
|
1825 | } |
|
|
1826 | } |
|
|
1827 | } |
|
|
1828 | |
|
|
1829 | glEnd (); |
|
|
1830 | |
|
|
1831 | glPopMatrix (); |
|
|
1832 | |
|
|
1833 | glDisable (GL_TEXTURE_2D); |
|
|
1834 | glDisable (GL_BLEND); |
|
|
1835 | } |
|
|
1836 | |
1388 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1837 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1389 | CODE: |
1838 | CODE: |
1390 | { |
1839 | { |
1391 | GLint width; |
1840 | GLint width; |
1392 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
1841 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
… | |
… | |
1394 | RETVAL = width > 0; |
1843 | RETVAL = width > 0; |
1395 | } |
1844 | } |
1396 | OUTPUT: |
1845 | OUTPUT: |
1397 | RETVAL |
1846 | RETVAL |
1398 | |
1847 | |
1399 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1848 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1400 | |
1849 | |
1401 | PROTOTYPES: DISABLE |
1850 | PROTOTYPES: DISABLE |
1402 | |
1851 | |
1403 | CFPlus::Map |
1852 | DC::Map |
1404 | new (SV *class) |
1853 | new (SV *class) |
1405 | CODE: |
1854 | CODE: |
1406 | New (0, RETVAL, 1, struct map); |
1855 | New (0, RETVAL, 1, struct map); |
1407 | RETVAL->x = 0; |
1856 | RETVAL->x = 0; |
1408 | RETVAL->y = 0; |
1857 | RETVAL->y = 0; |
… | |
… | |
1416 | RETVAL->row = 0; |
1865 | RETVAL->row = 0; |
1417 | OUTPUT: |
1866 | OUTPUT: |
1418 | RETVAL |
1867 | RETVAL |
1419 | |
1868 | |
1420 | void |
1869 | void |
1421 | DESTROY (CFPlus::Map self) |
1870 | DESTROY (DC::Map self) |
1422 | CODE: |
1871 | CODE: |
1423 | { |
1872 | { |
1424 | map_clear (self); |
1873 | map_clear (self); |
1425 | Safefree (self->face2tile); |
1874 | Safefree (self->face2tile); |
1426 | Safefree (self->tex); |
1875 | Safefree (self->tex); |
1427 | Safefree (self); |
1876 | Safefree (self); |
1428 | } |
1877 | } |
1429 | |
1878 | |
1430 | void |
1879 | void |
1431 | resize (CFPlus::Map self, int map_width, int map_height) |
1880 | resize (DC::Map self, int map_width, int map_height) |
1432 | CODE: |
1881 | CODE: |
1433 | self->w = map_width; |
1882 | self->w = map_width; |
1434 | self->h = map_height; |
1883 | self->h = map_height; |
1435 | |
1884 | |
1436 | void |
1885 | void |
1437 | clear (CFPlus::Map self) |
1886 | clear (DC::Map self) |
1438 | CODE: |
1887 | CODE: |
1439 | map_clear (self); |
1888 | map_clear (self); |
1440 | |
1889 | |
1441 | void |
1890 | void |
1442 | set_tileid (CFPlus::Map self, int face, int tile) |
1891 | set_tileid (DC::Map self, int face, int tile) |
1443 | CODE: |
1892 | CODE: |
1444 | { |
1893 | { |
1445 | need_facenum (self, face); self->face2tile [face] = tile; |
1894 | need_facenum (self, face); self->face2tile [face] = tile; |
1446 | need_texid (self, tile); |
1895 | need_texid (self, tile); |
1447 | } |
1896 | } |
1448 | |
1897 | |
1449 | void |
1898 | void |
1450 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1899 | set_smooth (DC::Map self, int face, int smooth, int level) |
1451 | CODE: |
1900 | CODE: |
1452 | { |
1901 | { |
1453 | tileid texid; |
1902 | tileid texid; |
1454 | maptex *tex; |
1903 | maptex *tex; |
1455 | |
1904 | |
… | |
… | |
1468 | tex->smoothtile = self->face2tile [smooth]; |
1917 | tex->smoothtile = self->face2tile [smooth]; |
1469 | tex->smoothlevel = level; |
1918 | tex->smoothlevel = level; |
1470 | } |
1919 | } |
1471 | |
1920 | |
1472 | void |
1921 | void |
1473 | 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) |
1922 | 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) |
1474 | CODE: |
1923 | CODE: |
1475 | { |
1924 | { |
1476 | need_texid (self, texid); |
1925 | need_texid (self, texid); |
1477 | |
1926 | |
1478 | { |
1927 | { |
… | |
… | |
1497 | // use uglier nearest interpolation because linear suffers |
1946 | // use uglier nearest interpolation because linear suffers |
1498 | // from transparent color bleeding and ugly wrapping effects. |
1947 | // from transparent color bleeding and ugly wrapping effects. |
1499 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1948 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1500 | } |
1949 | } |
1501 | |
1950 | |
|
|
1951 | void |
|
|
1952 | expire_textures (DC::Map self, int texid, int count) |
|
|
1953 | PPCODE: |
|
|
1954 | for (; texid < self->texs && count; ++texid, --count) |
|
|
1955 | { |
|
|
1956 | maptex *tex = self->tex + texid; |
|
|
1957 | |
|
|
1958 | if (tex->name) |
|
|
1959 | { |
|
|
1960 | if (tex->unused) |
|
|
1961 | { |
|
|
1962 | tex->name = 0; |
|
|
1963 | tex->unused = 0; |
|
|
1964 | XPUSHs (sv_2mortal (newSViv (texid))); |
|
|
1965 | } |
|
|
1966 | else |
|
|
1967 | tex->unused = 1; |
|
|
1968 | } |
|
|
1969 | } |
|
|
1970 | |
1502 | int |
1971 | int |
1503 | ox (CFPlus::Map self) |
1972 | ox (DC::Map self) |
1504 | ALIAS: |
1973 | ALIAS: |
1505 | oy = 1 |
1974 | oy = 1 |
1506 | x = 2 |
1975 | x = 2 |
1507 | y = 3 |
1976 | y = 3 |
1508 | w = 4 |
1977 | w = 4 |
… | |
… | |
1519 | } |
1988 | } |
1520 | OUTPUT: |
1989 | OUTPUT: |
1521 | RETVAL |
1990 | RETVAL |
1522 | |
1991 | |
1523 | void |
1992 | void |
1524 | scroll (CFPlus::Map self, int dx, int dy) |
1993 | scroll (DC::Map self, int dx, int dy) |
1525 | CODE: |
1994 | CODE: |
1526 | { |
1995 | { |
1527 | if (dx > 0) |
1996 | if (dx > 0) |
1528 | map_blank (self, self->x, self->y, dx, self->h); |
1997 | map_blank (self, self->x, self->y, dx, self->h); |
1529 | else if (dx < 0) |
1998 | else if (dx < 0) |
… | |
… | |
1544 | self->rows += MAP_EXTEND_Y; |
2013 | self->rows += MAP_EXTEND_Y; |
1545 | self->y += MAP_EXTEND_Y; |
2014 | self->y += MAP_EXTEND_Y; |
1546 | } |
2015 | } |
1547 | } |
2016 | } |
1548 | |
2017 | |
1549 | void |
2018 | SV * |
1550 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
2019 | map1a_update (DC::Map self, SV *data_, int extmap) |
1551 | CODE: |
2020 | CODE: |
1552 | { |
2021 | { |
1553 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2022 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1554 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2023 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1555 | mapcell *cell; |
2024 | mapcell *cell; |
1556 | int x, y, flags; |
2025 | int x, y, z, flags; |
|
|
2026 | AV *missing = newAV (); |
|
|
2027 | RETVAL = newRV_noinc ((SV *)missing); |
1557 | |
2028 | |
1558 | while (data < data_end - 1) |
2029 | while (data < data_end - 1) |
1559 | { |
2030 | { |
1560 | flags = (data [0] << 8) + data [1]; data += 2; |
2031 | flags = (data [0] << 8) + data [1]; data += 2; |
1561 | |
2032 | |
… | |
… | |
1581 | uint8_t ext, cmd; |
2052 | uint8_t ext, cmd; |
1582 | |
2053 | |
1583 | do |
2054 | do |
1584 | { |
2055 | { |
1585 | ext = *data++; |
2056 | ext = *data++; |
1586 | cmd = ext & 0x3f; |
2057 | cmd = ext & 0x7f; |
1587 | |
2058 | |
1588 | if (cmd < 4) |
2059 | if (cmd < 4) |
1589 | cell->darkness = 255 - ext * 64 + 1; |
2060 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
1590 | else if (cmd == 5) // health |
2061 | else if (cmd == 5) // health |
1591 | { |
2062 | { |
1592 | cell->stat_width = 1; |
2063 | cell->stat_width = 1; |
1593 | cell->stat_hp = *data++; |
2064 | cell->stat_hp = *data++; |
1594 | } |
2065 | } |
1595 | else if (cmd == 6) // monster width |
2066 | else if (cmd == 6) // monster width |
1596 | cell->stat_width = *data++ + 1; |
2067 | cell->stat_width = *data++ + 1; |
1597 | else if (cmd == 0x47) |
2068 | else if (cmd == 0x47) |
1598 | { |
2069 | { |
1599 | if (*data == 4) |
2070 | if (*data == 1) cell->player = data [1]; |
1600 | ; // decode player count |
2071 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2072 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2073 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
1601 | |
2074 | |
1602 | data += *data + 1; |
2075 | data += *data + 1; |
1603 | } |
2076 | } |
1604 | else if (cmd == 8) // cell flags |
2077 | else if (cmd == 8) // cell flags |
1605 | cell->flags = *data++; |
2078 | cell->flags = *data++; |
… | |
… | |
1612 | } |
2085 | } |
1613 | else |
2086 | else |
1614 | cell->darkness = *data++ + 1; |
2087 | cell->darkness = *data++ + 1; |
1615 | } |
2088 | } |
1616 | |
2089 | |
|
|
2090 | for (z = 0; z <= 2; ++z) |
1617 | if (flags & 4) |
2091 | if (flags & (4 >> z)) |
1618 | { |
2092 | { |
1619 | faceid face = (data [0] << 8) + data [1]; data += 2; |
2093 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1620 | need_facenum (self, face); |
2094 | need_facenum (self, face); |
1621 | cell->tile [0] = self->face2tile [face]; |
2095 | cell->tile [z] = self->face2tile [face]; |
|
|
2096 | |
|
|
2097 | if (cell->tile [z]) |
|
|
2098 | { |
|
|
2099 | maptex *tex = self->tex + cell->tile [z]; |
|
|
2100 | tex->unused = 0; |
|
|
2101 | if (!tex->name) |
|
|
2102 | av_push (missing, newSViv (cell->tile [z])); |
|
|
2103 | |
|
|
2104 | if (tex->smoothtile) |
|
|
2105 | { |
|
|
2106 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
2107 | smooth->unused = 0; |
|
|
2108 | if (!smooth->name) |
|
|
2109 | av_push (missing, newSViv (tex->smoothtile)); |
|
|
2110 | } |
|
|
2111 | } |
1622 | } |
2112 | } |
1623 | |
|
|
1624 | if (flags & 2) |
|
|
1625 | { |
|
|
1626 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1627 | need_facenum (self, face); |
|
|
1628 | cell->tile [1] = self->face2tile [face]; |
|
|
1629 | } |
|
|
1630 | |
|
|
1631 | if (flags & 1) |
|
|
1632 | { |
|
|
1633 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1634 | need_facenum (self, face); |
|
|
1635 | cell->tile [2] = self->face2tile [face]; |
|
|
1636 | } |
|
|
1637 | } |
2113 | } |
1638 | else |
2114 | else |
1639 | cell->darkness = 0; |
2115 | CELL_CLEAR (cell); |
1640 | } |
2116 | } |
1641 | } |
2117 | } |
|
|
2118 | OUTPUT: |
|
|
2119 | RETVAL |
1642 | |
2120 | |
1643 | SV * |
2121 | SV * |
1644 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
2122 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1645 | CODE: |
2123 | CODE: |
1646 | { |
2124 | { |
1647 | int x1, x; |
2125 | int x1, x; |
1648 | int y1, y; |
2126 | int y1, y; |
1649 | int z; |
2127 | int z; |
… | |
… | |
1662 | ? self->row + y |
2140 | ? self->row + y |
1663 | : 0; |
2141 | : 0; |
1664 | |
2142 | |
1665 | for (x = x0; x < x1; x++) |
2143 | for (x = x0; x < x1; x++) |
1666 | { |
2144 | { |
1667 | int r = 32, g = 32, b = 32, a = 192; |
2145 | unsigned int r = 32, g = 32, b = 32, a = 192; |
1668 | |
2146 | |
1669 | if (row && row->c0 <= x && x < row->c1) |
2147 | if (row && row->c0 <= x && x < row->c1) |
1670 | { |
2148 | { |
1671 | mapcell *cell = row->col + (x - row->c0); |
2149 | mapcell *cell = row->col + (x - row->c0); |
1672 | |
2150 | |
… | |
… | |
1674 | { |
2152 | { |
1675 | maptex tex = self->tex [cell->tile [z]]; |
2153 | maptex tex = self->tex [cell->tile [z]]; |
1676 | int a0 = 255 - tex.a; |
2154 | int a0 = 255 - tex.a; |
1677 | int a1 = tex.a; |
2155 | int a1 = tex.a; |
1678 | |
2156 | |
1679 | r = (r * a0 + tex.r * a1) / 255; |
2157 | r = div255 (r * a0 + tex.r * a1); |
1680 | g = (g * a0 + tex.g * a1) / 255; |
2158 | g = div255 (g * a0 + tex.g * a1); |
1681 | b = (b * a0 + tex.b * a1) / 255; |
2159 | b = div255 (b * a0 + tex.b * a1); |
1682 | a = (a * a0 + tex.a * a1) / 255; |
2160 | a = div255 (a * a0 + tex.a * a1); |
1683 | } |
2161 | } |
1684 | } |
2162 | } |
1685 | |
2163 | |
1686 | *map++ = (r ) |
2164 | *map++ = (r ) |
1687 | | (g << 8) |
2165 | | (g << 8) |
… | |
… | |
1694 | } |
2172 | } |
1695 | OUTPUT: |
2173 | OUTPUT: |
1696 | RETVAL |
2174 | RETVAL |
1697 | |
2175 | |
1698 | void |
2176 | void |
1699 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
2177 | 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) |
1700 | CODE: |
2178 | CODE: |
1701 | { |
2179 | { |
|
|
2180 | int x, y, z; |
|
|
2181 | |
1702 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
2182 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1703 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2183 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1704 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
2184 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1705 | smooth_key skey; |
2185 | smooth_key skey; |
1706 | int x, y, z; |
2186 | int pl_x, pl_y; |
1707 | int last_name; |
2187 | maptex pl_tex; |
|
|
2188 | rc_t *rc = rc_alloc (); |
|
|
2189 | rc_t *rc_ov = rc_alloc (); |
|
|
2190 | rc_key_t key; |
|
|
2191 | rc_array_t *arr; |
1708 | |
2192 | |
|
|
2193 | pl_tex.name = 0; |
|
|
2194 | |
1709 | // thats current max. sorry. |
2195 | // that's current max. sorry. |
1710 | if (sw > 255) sw = 255; |
2196 | if (sw > 255) sw = 255; |
1711 | if (sh > 255) sh = 255; |
2197 | if (sh > 255) sh = 255; |
1712 | |
2198 | |
1713 | // clear key, in case of extra padding |
2199 | // clear key, in case of extra padding |
1714 | memset (&skey, 0, sizeof (skey)); |
2200 | memset (&skey, 0, sizeof (skey)); |
1715 | |
2201 | |
1716 | glColor4ub (255, 255, 255, 255); |
2202 | memset (&key, 0, sizeof (key)); |
1717 | |
2203 | key.r = 255; |
1718 | glEnable (GL_BLEND); |
2204 | key.g = 255; |
1719 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2205 | key.b = 255; |
1720 | glEnable (GL_TEXTURE_2D); |
2206 | key.a = 255; |
1721 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2207 | key.mode = GL_QUADS; |
1722 | |
2208 | key.format = GL_T2F_V3F; |
1723 | glBegin (GL_QUADS); |
|
|
1724 | |
|
|
1725 | last_name = 0; |
|
|
1726 | |
2209 | |
1727 | mx += self->x; |
2210 | mx += self->x; |
1728 | my += self->y; |
2211 | my += self->y; |
1729 | |
2212 | |
1730 | // first pass: determine smooth_max |
2213 | // first pass: determine smooth_max |
… | |
… | |
1747 | MAX (self->tex [cell->tile [1]].smoothlevel, |
2230 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1748 | self->tex [cell->tile [2]].smoothlevel)); |
2231 | self->tex [cell->tile [2]].smoothlevel)); |
1749 | } |
2232 | } |
1750 | } |
2233 | } |
1751 | |
2234 | |
|
|
2235 | glEnable (GL_BLEND); |
|
|
2236 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
2237 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
2238 | |
1752 | for (z = 0; z <= 2; z++) |
2239 | for (z = 0; z <= 2; z++) |
1753 | { |
2240 | { |
1754 | memset (smooth_level, 0, sizeof (smooth_level)); |
2241 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
2242 | key.texname = -1; |
1755 | |
2243 | |
1756 | for (y = 0; y < sh; y++) |
2244 | for (y = 0; y < sh; y++) |
1757 | if (0 <= y + my && y + my < self->rows) |
2245 | if (0 <= y + my && y + my < self->rows) |
1758 | { |
2246 | { |
1759 | maprow *row = self->row + (y + my); |
2247 | maprow *row = self->row + (y + my); |
… | |
… | |
1765 | tileid tile = cell->tile [z]; |
2253 | tileid tile = cell->tile [z]; |
1766 | |
2254 | |
1767 | if (tile) |
2255 | if (tile) |
1768 | { |
2256 | { |
1769 | maptex tex = self->tex [tile]; |
2257 | maptex tex = self->tex [tile]; |
1770 | int px = (x + 1) * T - tex.w; |
2258 | int px, py; |
1771 | int py = (y + 1) * T - tex.h; |
|
|
1772 | |
2259 | |
1773 | // suppressing texture state switches here |
|
|
1774 | // is only moderately effective, but worth the extra effort |
|
|
1775 | if (last_name != tex.name) |
2260 | if (key.texname != tex.name) |
1776 | { |
2261 | { |
|
|
2262 | self->tex [tile].unused = 0; |
|
|
2263 | |
1777 | if (!tex.name) |
2264 | if (!tex.name) |
1778 | tex = self->tex [2]; /* missing, replace by noface */ |
2265 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
1779 | |
2266 | |
1780 | glEnd (); |
2267 | key.texname = tex.name; |
1781 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
2268 | arr = rc_array (rc, &key); |
1782 | glBegin (GL_QUADS); |
|
|
1783 | } |
2269 | } |
1784 | |
2270 | |
1785 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
2271 | px = (x + 1) * Th - tex.w; |
1786 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
2272 | py = (y + 1) * Tw - tex.h; |
1787 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1788 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1789 | |
2273 | |
1790 | if (cell->flags && z == 2) |
2274 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
1791 | { |
2275 | { |
1792 | if (cell->flags & 1) |
2276 | pl_x = px; |
|
|
2277 | pl_y = py; |
|
|
2278 | pl_tex = tex; |
1793 | { |
2279 | continue; |
1794 | maptex tex = self->tex [1]; |
|
|
1795 | int px = x * T + T * 2 / 32; |
|
|
1796 | int py = y * T - T * 6 / 32; |
|
|
1797 | |
|
|
1798 | glEnd (); |
|
|
1799 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1800 | glBegin (GL_QUADS); |
|
|
1801 | |
|
|
1802 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1803 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1804 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1805 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1806 | } |
|
|
1807 | } |
2280 | } |
|
|
2281 | |
|
|
2282 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2283 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
2284 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2285 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1808 | |
2286 | |
1809 | // update smooth hash |
2287 | // update smooth hash |
1810 | if (tex.smoothtile) |
2288 | if (tex.smoothtile) |
1811 | { |
2289 | { |
1812 | skey.tile = tex.smoothtile; |
2290 | skey.tile = tex.smoothtile; |
… | |
… | |
1843 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2321 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
1844 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2322 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
1845 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2323 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
1846 | } |
2324 | } |
1847 | } |
2325 | } |
|
|
2326 | |
|
|
2327 | if (expect_false (z == 2) && expect_false (cell->flags)) |
|
|
2328 | { |
|
|
2329 | // overlays such as the speech bubble, probably more to come |
|
|
2330 | if (cell->flags & 1) |
|
|
2331 | { |
|
|
2332 | rc_key_t key_ov = key; |
|
|
2333 | maptex tex = self->tex [TEXID_SPEECH]; |
|
|
2334 | rc_array_t *arr; |
|
|
2335 | int px = x * Tw + Tw * 2 / 32; |
|
|
2336 | int py = y * Th - Th * 6 / 32; |
|
|
2337 | |
|
|
2338 | key_ov.texname = tex.name; |
|
|
2339 | arr = rc_array (rc_ov, &key_ov); |
|
|
2340 | |
|
|
2341 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2342 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
|
|
2343 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
|
|
2344 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
|
|
2345 | } |
|
|
2346 | } |
1848 | } |
2347 | } |
1849 | } |
2348 | } |
|
|
2349 | |
|
|
2350 | rc_draw (rc); |
|
|
2351 | rc_clear (rc); |
1850 | |
2352 | |
1851 | // go through all smoothlevels, lowest to highest, then draw. |
2353 | // go through all smoothlevels, lowest to highest, then draw. |
1852 | // this is basically counting sort |
2354 | // this is basically counting sort |
1853 | { |
2355 | { |
1854 | int w, b; |
2356 | int w, b; |
1855 | |
2357 | |
|
|
2358 | glEnable (GL_TEXTURE_2D); |
|
|
2359 | glBegin (GL_QUADS); |
1856 | for (w = 0; w < 256 / 32; ++w) |
2360 | for (w = 0; w < 256 / 32; ++w) |
1857 | { |
2361 | { |
1858 | uint32_t smask = smooth_level [w]; |
2362 | uint32_t smask = smooth_level [w]; |
1859 | if (smask) |
2363 | if (smask) |
1860 | for (b = 0; b < 32; ++b) |
2364 | for (b = 0; b < 32; ++b) |
… | |
… | |
1872 | if (!(bits & 0x1000) |
2376 | if (!(bits & 0x1000) |
1873 | && skey->level == level |
2377 | && skey->level == level |
1874 | && level > smooth_max [skey->x][skey->y]) |
2378 | && level > smooth_max [skey->x][skey->y]) |
1875 | { |
2379 | { |
1876 | maptex tex = self->tex [skey->tile]; |
2380 | maptex tex = self->tex [skey->tile]; |
1877 | int px = (((int)skey->x) - 1) * T; |
2381 | int px = (((int)skey->x) - 1) * Tw; |
1878 | int py = (((int)skey->y) - 1) * T; |
2382 | int py = (((int)skey->y) - 1) * Th; |
1879 | int border = bits & 15; |
2383 | int border = bits & 15; |
1880 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2384 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1881 | float dx = tex.s * .0625f; // 16 images/row |
2385 | float dx = tex.s * .0625f; // 16 images/row |
1882 | float dy = tex.t * .5f ; // 2 images/column |
2386 | float dy = tex.t * .5f ; // 2 images/column |
1883 | |
2387 | |
1884 | // this time naively avoiding texture state changes |
|
|
1885 | // save gobs of state changes. |
|
|
1886 | if (last_name != tex.name) |
2388 | if (tex.name) |
1887 | { |
2389 | { |
|
|
2390 | // this time avoiding texture state changes |
|
|
2391 | // save gobs of state changes. |
1888 | if (!tex.name) |
2392 | if (key.texname != tex.name) |
1889 | continue; // smoothing not yet available |
2393 | { |
|
|
2394 | self->tex [skey->tile].unused = 0; |
1890 | |
2395 | |
1891 | glEnd (); |
2396 | glEnd (); |
1892 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
2397 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1893 | glBegin (GL_QUADS); |
2398 | glBegin (GL_QUADS); |
1894 | } |
2399 | } |
1895 | |
2400 | |
1896 | if (border) |
2401 | if (border) |
1897 | { |
2402 | { |
1898 | float ox = border * dx; |
2403 | float ox = border * dx; |
1899 | |
2404 | |
1900 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
2405 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1901 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
2406 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
1902 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
2407 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
1903 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
2408 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
1904 | } |
2409 | } |
1905 | |
2410 | |
1906 | if (corner) |
2411 | if (corner) |
1907 | { |
2412 | { |
1908 | float ox = corner * dx; |
2413 | float ox = corner * dx; |
1909 | |
2414 | |
1910 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
2415 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1911 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
2416 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
1912 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
2417 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
1913 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
2418 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
|
|
2419 | } |
1914 | } |
2420 | } |
1915 | } |
2421 | } |
1916 | } |
2422 | } |
1917 | } |
2423 | } |
1918 | } |
2424 | } |
|
|
2425 | |
|
|
2426 | glEnd (); |
|
|
2427 | glDisable (GL_TEXTURE_2D); |
|
|
2428 | key.texname = -1; |
1919 | } |
2429 | } |
1920 | |
2430 | |
1921 | hv_clear (smooth); |
2431 | hv_clear (smooth); |
1922 | } |
2432 | } |
1923 | |
2433 | |
1924 | glEnd (); |
2434 | if (pl_tex.name) |
|
|
2435 | { |
|
|
2436 | maptex tex = pl_tex; |
|
|
2437 | int px = pl_x + sdx; |
|
|
2438 | int py = pl_y + sdy; |
1925 | |
2439 | |
1926 | glDisable (GL_TEXTURE_2D); |
2440 | key.texname = tex.name; |
|
|
2441 | arr = rc_array (rc, &key); |
|
|
2442 | |
|
|
2443 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2444 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
2445 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2446 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
|
|
2447 | |
|
|
2448 | rc_draw (rc); |
|
|
2449 | } |
|
|
2450 | |
|
|
2451 | rc_draw (rc_ov); |
|
|
2452 | rc_clear (rc_ov); |
|
|
2453 | |
1927 | glDisable (GL_BLEND); |
2454 | glDisable (GL_BLEND); |
|
|
2455 | rc_free (rc); |
|
|
2456 | rc_free (rc_ov); |
1928 | |
2457 | |
1929 | // top layer: overlays such as the health bar |
2458 | // top layer: overlays such as the health bar |
1930 | for (y = 0; y < sh; y++) |
2459 | for (y = 0; y < sh; y++) |
1931 | if (0 <= y + my && y + my < self->rows) |
2460 | if (0 <= y + my && y + my < self->rows) |
1932 | { |
2461 | { |
… | |
… | |
1935 | for (x = 0; x < sw; x++) |
2464 | for (x = 0; x < sw; x++) |
1936 | if (row->c0 <= x + mx && x + mx < row->c1) |
2465 | if (row->c0 <= x + mx && x + mx < row->c1) |
1937 | { |
2466 | { |
1938 | mapcell *cell = row->col + (x + mx - row->c0); |
2467 | mapcell *cell = row->col + (x + mx - row->c0); |
1939 | |
2468 | |
1940 | int px = x * T; |
2469 | int px = x * Tw; |
1941 | int py = y * T; |
2470 | int py = y * Th; |
|
|
2471 | |
|
|
2472 | if (expect_false (cell->player == player)) |
|
|
2473 | { |
|
|
2474 | px += sdx; |
|
|
2475 | py += sdy; |
|
|
2476 | } |
1942 | |
2477 | |
1943 | if (cell->stat_hp) |
2478 | if (cell->stat_hp) |
1944 | { |
2479 | { |
1945 | int width = cell->stat_width * T; |
2480 | int width = cell->stat_width * Tw; |
1946 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2481 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
1947 | |
2482 | |
1948 | glColor3ub (0, 0, 0); |
2483 | glColor3ub (0, 0, 0); |
1949 | glRectf (px + 1, py - thick - 2, |
2484 | glRectf (px + 1, py - thick - 2, |
1950 | px + width - 1, py); |
2485 | px + width - 1, py); |
1951 | |
2486 | |
… | |
… | |
1957 | } |
2492 | } |
1958 | } |
2493 | } |
1959 | } |
2494 | } |
1960 | |
2495 | |
1961 | void |
2496 | void |
1962 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2497 | draw_magicmap (DC::Map self, int w, int h, unsigned char *data) |
1963 | CODE: |
2498 | CODE: |
1964 | { |
2499 | { |
1965 | static float color[16][3] = { |
2500 | static float color[16][3] = { |
1966 | { 0.00F, 0.00F, 0.00F }, |
2501 | { 0.00f, 0.00f, 0.00f }, |
1967 | { 1.00F, 1.00F, 1.00F }, |
2502 | { 1.00f, 1.00f, 1.00f }, |
1968 | { 0.00F, 0.00F, 0.55F }, |
2503 | { 0.00f, 0.00f, 0.55f }, |
1969 | { 1.00F, 0.00F, 0.00F }, |
2504 | { 1.00f, 0.00f, 0.00f }, |
1970 | |
2505 | |
1971 | { 1.00F, 0.54F, 0.00F }, |
2506 | { 1.00f, 0.54f, 0.00f }, |
1972 | { 0.11F, 0.56F, 1.00F }, |
2507 | { 0.11f, 0.56f, 1.00f }, |
1973 | { 0.93F, 0.46F, 0.00F }, |
2508 | { 0.93f, 0.46f, 0.00f }, |
1974 | { 0.18F, 0.54F, 0.34F }, |
2509 | { 0.18f, 0.54f, 0.34f }, |
1975 | |
2510 | |
1976 | { 0.56F, 0.73F, 0.56F }, |
2511 | { 0.56f, 0.73f, 0.56f }, |
1977 | { 0.80F, 0.80F, 0.80F }, |
2512 | { 0.80f, 0.80f, 0.80f }, |
1978 | { 0.55F, 0.41F, 0.13F }, |
2513 | { 0.55f, 0.41f, 0.13f }, |
1979 | { 0.99F, 0.77F, 0.26F }, |
2514 | { 0.99f, 0.77f, 0.26f }, |
1980 | |
2515 | |
1981 | { 0.74F, 0.65F, 0.41F }, |
2516 | { 0.74f, 0.65f, 0.41f }, |
1982 | |
2517 | |
1983 | { 0.00F, 1.00F, 1.00F }, |
2518 | { 0.00f, 1.00f, 1.00f }, |
1984 | { 1.00F, 0.00F, 1.00F }, |
2519 | { 1.00f, 0.00f, 1.00f }, |
1985 | { 1.00F, 1.00F, 0.00F }, |
2520 | { 1.00f, 1.00f, 0.00f }, |
1986 | }; |
2521 | }; |
1987 | |
2522 | |
1988 | int x, y; |
2523 | int x, y; |
1989 | |
2524 | |
1990 | glEnable (GL_TEXTURE_2D); |
2525 | glEnable (GL_TEXTURE_2D); |
|
|
2526 | /* GL_REPLACE would be correct, as we don't need to modulate alpha, |
|
|
2527 | * but the nvidia driver (185.18.14) mishandles alpha textures |
|
|
2528 | * and takes the colour from god knows where instead of using |
|
|
2529 | * Cp. MODULATE results in the same colour, but slightly different |
|
|
2530 | * alpha, but atcually gives us the correct colour with nvidia. |
|
|
2531 | */ |
1991 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2532 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
1992 | glEnable (GL_BLEND); |
2533 | glEnable (GL_BLEND); |
1993 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2534 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1994 | glBegin (GL_QUADS); |
2535 | glBegin (GL_QUADS); |
1995 | |
2536 | |
1996 | for (y = 0; y < h; y++) |
2537 | for (y = 0; y < h; y++) |
… | |
… | |
2000 | |
2541 | |
2001 | if (m) |
2542 | if (m) |
2002 | { |
2543 | { |
2003 | float *c = color [m & 15]; |
2544 | float *c = color [m & 15]; |
2004 | |
2545 | |
2005 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2546 | float tx1 = m & 0x40 ? 0.5f : 0.f; |
2006 | float tx2 = tx1 + 0.5; |
2547 | float tx2 = tx1 + 0.5f; |
2007 | |
2548 | |
2008 | glColor4f (c[0], c[1], c[2], 0.75); |
2549 | glColor4f (c[0], c[1], c[2], 1); |
2009 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2550 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2010 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2551 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2011 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2552 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2012 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2553 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2013 | } |
2554 | } |
… | |
… | |
2017 | glDisable (GL_BLEND); |
2558 | glDisable (GL_BLEND); |
2018 | glDisable (GL_TEXTURE_2D); |
2559 | glDisable (GL_TEXTURE_2D); |
2019 | } |
2560 | } |
2020 | |
2561 | |
2021 | void |
2562 | void |
2022 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2563 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2023 | PPCODE: |
2564 | PPCODE: |
2024 | { |
2565 | { |
2025 | int x, y; |
2566 | int x, y; |
2026 | int sw1 = sw + 2; |
2567 | int sw1 = sw + 2; |
2027 | int sh1 = sh + 2; |
2568 | int sh1 = sh + 2; |
2028 | int sh3 = sh * 3; |
2569 | int sh3 = sh * 3; |
2029 | int sw34 = (sw * 3 + 3) & ~3; |
2570 | int sw3 = sw * 3; |
|
|
2571 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
|
|
2572 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
2030 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2573 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2031 | SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); |
2574 | memset (darkness1, 0, sw1*sh1); |
2032 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
2033 | |
2575 | |
2034 | SvPOK_only (darkness3_sv); |
2576 | SvPOK_only (darkness3_sv); |
2035 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2577 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2036 | |
2578 | |
2037 | mx += self->x - 1; |
2579 | mx += self->x - 1; |
2038 | my += self->y - 1; |
2580 | my += self->y - 1; |
2039 | |
|
|
2040 | memset (darkness1, 255, sw1 * sh1); |
|
|
2041 | |
2581 | |
2042 | for (y = 0; y < sh1; y++) |
2582 | for (y = 0; y < sh1; y++) |
2043 | if (0 <= y + my && y + my < self->rows) |
2583 | if (0 <= y + my && y + my < self->rows) |
2044 | { |
2584 | { |
2045 | maprow *row = self->row + (y + my); |
2585 | maprow *row = self->row + (y + my); |
… | |
… | |
2048 | if (row->c0 <= x + mx && x + mx < row->c1) |
2588 | if (row->c0 <= x + mx && x + mx < row->c1) |
2049 | { |
2589 | { |
2050 | mapcell *cell = row->col + (x + mx - row->c0); |
2590 | mapcell *cell = row->col + (x + mx - row->c0); |
2051 | |
2591 | |
2052 | darkness1 [y * sw1 + x] = cell->darkness |
2592 | darkness1 [y * sw1 + x] = cell->darkness |
2053 | ? 255 - (cell->darkness - 1) |
2593 | ? DARKNESS_ADJUST (255 - (cell->darkness - 1)) |
2054 | : 255 - FOW_DARKNESS; |
2594 | : DARKNESS_ADJUST (255 - FOW_DARKNESS); |
2055 | } |
2595 | } |
2056 | } |
2596 | } |
2057 | |
2597 | |
2058 | for (y = 0; y < sh; ++y) |
2598 | for (y = 0; y < sh; ++y) |
2059 | for (x = 0; x < sw; ++x) |
2599 | for (x = 0; x < sw; ++x) |
… | |
… | |
2078 | |
2618 | |
2079 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2619 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2080 | uint8_t r23 = d23; |
2620 | uint8_t r23 = d23; |
2081 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2621 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2082 | |
2622 | |
2083 | darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); |
2623 | darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11); |
2084 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); |
2624 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21); |
2085 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); |
2625 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31); |
2086 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); |
2626 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12); |
2087 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); |
2627 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */ |
2088 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); |
2628 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32); |
2089 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); |
2629 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13); |
2090 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); |
2630 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23); |
2091 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); |
2631 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33); |
2092 | } |
2632 | } |
2093 | |
2633 | |
2094 | free (darkness1); |
2634 | free (darkness1); |
2095 | |
2635 | |
2096 | EXTEND (SP, 3); |
2636 | EXTEND (SP, 3); |
2097 | PUSHs (sv_2mortal (newSViv (sw34))); |
2637 | PUSHs (sv_2mortal (newSViv (sw3))); |
2098 | PUSHs (sv_2mortal (newSViv (sh3))); |
2638 | PUSHs (sv_2mortal (newSViv (sh3))); |
2099 | PUSHs (darkness3_sv); |
2639 | PUSHs (darkness3_sv); |
2100 | } |
2640 | } |
2101 | |
2641 | |
2102 | SV * |
2642 | SV * |
2103 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2643 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2104 | CODE: |
2644 | CODE: |
2105 | { |
2645 | { |
2106 | int x, y, x1, y1; |
2646 | int x, y, x1, y1; |
2107 | SV *data_sv = newSV (w * h * 7 + 5); |
2647 | SV *data_sv = newSV (w * h * 7 + 5); |
2108 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2648 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2165 | else |
2705 | else |
2166 | *data++ = 0; |
2706 | *data++ = 0; |
2167 | } |
2707 | } |
2168 | } |
2708 | } |
2169 | |
2709 | |
|
|
2710 | /* if size is w*h + 5 then no data has been found */ |
|
|
2711 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
|
|
2712 | { |
2170 | SvPOK_only (data_sv); |
2713 | SvPOK_only (data_sv); |
2171 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2714 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
2715 | } |
|
|
2716 | |
2172 | RETVAL = data_sv; |
2717 | RETVAL = data_sv; |
2173 | } |
2718 | } |
2174 | OUTPUT: |
2719 | OUTPUT: |
2175 | RETVAL |
2720 | RETVAL |
2176 | |
2721 | |
2177 | void |
2722 | void |
2178 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2723 | set_rect (DC::Map self, int x0, int y0, SV *data_sv) |
2179 | PPCODE: |
2724 | PPCODE: |
2180 | { |
2725 | { |
2181 | int x, y, z; |
2726 | int x, y, z; |
2182 | int w, h; |
2727 | int w, h; |
2183 | int x1, y1; |
2728 | int x1, y1; |
|
|
2729 | STRLEN len; |
|
|
2730 | uint8_t *data, *end; |
|
|
2731 | |
|
|
2732 | len = SvLEN (data_sv); |
|
|
2733 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
|
|
2734 | data = SvPVbyte_nolen (data_sv); |
|
|
2735 | end = data + len + 8; |
|
|
2736 | |
|
|
2737 | if (len < 5) |
|
|
2738 | XSRETURN_EMPTY; |
2184 | |
2739 | |
2185 | if (*data++ != 0) |
2740 | if (*data++ != 0) |
2186 | return; /* version mismatch */ |
2741 | XSRETURN_EMPTY; /* version mismatch */ |
2187 | |
2742 | |
2188 | w = *data++ << 8; w |= *data++; |
2743 | w = *data++ << 8; w |= *data++; |
2189 | h = *data++ << 8; h |= *data++; |
2744 | h = *data++ << 8; h |= *data++; |
2190 | |
2745 | |
2191 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2746 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2203 | { |
2758 | { |
2204 | maprow *row = map_get_row (self, y); |
2759 | maprow *row = map_get_row (self, y); |
2205 | |
2760 | |
2206 | for (x = x0; x < x1; x++) |
2761 | for (x = x0; x < x1; x++) |
2207 | { |
2762 | { |
|
|
2763 | uint8_t flags; |
|
|
2764 | |
|
|
2765 | if (data + 7 >= end) |
|
|
2766 | XSRETURN_EMPTY; |
|
|
2767 | |
2208 | uint8_t flags = *data++; |
2768 | flags = *data++; |
2209 | |
2769 | |
2210 | if (flags) |
2770 | if (flags) |
2211 | { |
2771 | { |
2212 | mapcell *cell = row_get_cell (row, x); |
2772 | mapcell *cell = row_get_cell (row, x); |
2213 | tileid tile[3] = { 0, 0, 0 }; |
2773 | tileid tile[3] = { 0, 0, 0 }; |
… | |
… | |
2216 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2776 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2217 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2777 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2218 | |
2778 | |
2219 | if (cell->darkness == 0) |
2779 | if (cell->darkness == 0) |
2220 | { |
2780 | { |
2221 | cell->darkness = 0; |
2781 | /*cell->darkness = 0;*/ |
|
|
2782 | EXTEND (SP, 3); |
2222 | |
2783 | |
2223 | for (z = 0; z <= 2; z++) |
2784 | for (z = 0; z <= 2; z++) |
2224 | { |
2785 | { |
2225 | tileid t = tile [z]; |
2786 | tileid t = tile [z]; |
2226 | |
2787 | |
2227 | if (t >= self->texs || (t && !self->tex [t].name)) |
2788 | if (t >= self->texs || (t && !self->tex [t].name)) |
2228 | { |
2789 | { |
2229 | XPUSHs (sv_2mortal (newSViv (t))); |
2790 | PUSHs (sv_2mortal (newSViv (t))); |
2230 | need_texid (self, t); |
2791 | need_texid (self, t); |
2231 | } |
2792 | } |
2232 | |
2793 | |
2233 | cell->tile [z] = t; |
2794 | cell->tile [z] = t; |
2234 | } |
2795 | } |
… | |
… | |
2236 | } |
2797 | } |
2237 | } |
2798 | } |
2238 | } |
2799 | } |
2239 | } |
2800 | } |
2240 | |
2801 | |
2241 | MODULE = CFPlus PACKAGE = CFPlus::RW |
2802 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2242 | |
2803 | |
2243 | CFPlus::RW |
2804 | DC::RW |
2244 | new (SV *class, SV *data_sv) |
2805 | new (SV *class, SV *data_sv) |
2245 | CODE: |
2806 | CODE: |
2246 | { |
2807 | { |
2247 | STRLEN datalen; |
2808 | STRLEN datalen; |
2248 | char *data = SvPVbyte (data_sv, datalen); |
2809 | char *data = SvPVbyte (data_sv, datalen); |
… | |
… | |
2250 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2811 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2251 | } |
2812 | } |
2252 | OUTPUT: |
2813 | OUTPUT: |
2253 | RETVAL |
2814 | RETVAL |
2254 | |
2815 | |
2255 | CFPlus::RW |
2816 | DC::RW |
2256 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2817 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2257 | CODE: |
2818 | CODE: |
2258 | RETVAL = SDL_RWFromFile (path, mode); |
2819 | RETVAL = SDL_RWFromFile (path, mode); |
2259 | OUTPUT: |
2820 | OUTPUT: |
2260 | RETVAL |
2821 | RETVAL |
2261 | |
2822 | |
|
|
2823 | # fails on win32: |
|
|
2824 | # dc.xs(2268) : error C2059: syntax error : '(' |
2262 | void |
2825 | #void |
2263 | close (CFPlus::RW self) |
2826 | #close (DC::RW self) |
2264 | CODE: |
2827 | # CODE: |
2265 | SDL_RWclose (self); |
2828 | # (self->(close)) (self); |
2266 | |
2829 | |
2267 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2830 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
2268 | |
2831 | |
2269 | PROTOTYPES: DISABLE |
2832 | PROTOTYPES: DISABLE |
2270 | |
2833 | |
2271 | int |
2834 | DC::Channel |
2272 | volume (CFPlus::Channel self, int volume) |
2835 | find () |
2273 | CODE: |
2836 | CODE: |
2274 | RETVAL = Mix_Volume (self, volume); |
2837 | { |
|
|
2838 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2839 | |
|
|
2840 | if (RETVAL < 0) |
|
|
2841 | { |
|
|
2842 | RETVAL = Mix_GroupOldest (-1); |
|
|
2843 | |
|
|
2844 | if (RETVAL < 0) |
|
|
2845 | { |
|
|
2846 | // happens sometimes, maybe it just stopped playing(?) |
|
|
2847 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2848 | |
|
|
2849 | if (RETVAL < 0) |
|
|
2850 | XSRETURN_UNDEF; |
|
|
2851 | } |
|
|
2852 | else |
|
|
2853 | Mix_HaltChannel (RETVAL); |
|
|
2854 | } |
|
|
2855 | |
|
|
2856 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2857 | Mix_Volume (RETVAL, 128); |
|
|
2858 | } |
2275 | OUTPUT: |
2859 | OUTPUT: |
2276 | RETVAL |
2860 | RETVAL |
2277 | |
2861 | |
|
|
2862 | void |
|
|
2863 | halt (DC::Channel self) |
|
|
2864 | CODE: |
|
|
2865 | Mix_HaltChannel (self); |
|
|
2866 | |
|
|
2867 | void |
|
|
2868 | expire (DC::Channel self, int ticks = -1) |
|
|
2869 | CODE: |
|
|
2870 | Mix_ExpireChannel (self, ticks); |
|
|
2871 | |
|
|
2872 | void |
|
|
2873 | fade_out (DC::Channel self, int ticks = -1) |
|
|
2874 | CODE: |
|
|
2875 | Mix_FadeOutChannel (self, ticks); |
|
|
2876 | |
2278 | int |
2877 | int |
2279 | unregister_all_effects (CFPlus::Channel self) |
2878 | volume (DC::Channel self, int volume) |
2280 | CODE: |
2879 | CODE: |
2281 | RETVAL = Mix_UnregisterAllEffects (self); |
2880 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2282 | OUTPUT: |
2881 | OUTPUT: |
2283 | RETVAL |
2882 | RETVAL |
2284 | |
2883 | |
2285 | int |
2884 | void |
|
|
2885 | unregister_all_effects (DC::Channel self) |
|
|
2886 | CODE: |
|
|
2887 | Mix_UnregisterAllEffects (self); |
|
|
2888 | |
|
|
2889 | void |
2286 | set_panning (CFPlus::Channel self, int left, int right) |
2890 | set_panning (DC::Channel self, int left, int right) |
2287 | CODE: |
2891 | CODE: |
|
|
2892 | left = CLAMP (left , 0, 255); |
|
|
2893 | right = CLAMP (right, 0, 255); |
2288 | RETVAL = Mix_SetPanning (self, left, right); |
2894 | Mix_SetPanning (self, left, right); |
2289 | OUTPUT: |
|
|
2290 | RETVAL |
|
|
2291 | |
2895 | |
2292 | int |
2896 | void |
2293 | set_distance (CFPlus::Channel self, int distance) |
2897 | set_distance (DC::Channel self, int distance) |
2294 | CODE: |
2898 | CODE: |
2295 | RETVAL = Mix_SetDistance (self, distance); |
2899 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2296 | OUTPUT: |
|
|
2297 | RETVAL |
|
|
2298 | |
2900 | |
2299 | int |
2901 | void |
2300 | set_position (CFPlus::Channel self, int angle, int distance) |
2902 | set_position (DC::Channel self, int angle, int distance) |
2301 | CODE: |
2903 | CODE: |
|
|
2904 | |
|
|
2905 | void |
|
|
2906 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
|
|
2907 | CODE: |
|
|
2908 | { |
|
|
2909 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
|
|
2910 | int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f; |
2302 | RETVAL = Mix_SetPosition (self, angle, distance); |
2911 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2303 | OUTPUT: |
2912 | } |
2304 | RETVAL |
|
|
2305 | |
2913 | |
2306 | int |
2914 | void |
2307 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2915 | set_reverse_stereo (DC::Channel self, int flip) |
2308 | CODE: |
2916 | CODE: |
2309 | RETVAL = Mix_SetReverseStereo (self, flip); |
2917 | Mix_SetReverseStereo (self, flip); |
2310 | OUTPUT: |
|
|
2311 | RETVAL |
|
|
2312 | |
2918 | |
2313 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2919 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
2314 | |
2920 | |
2315 | PROTOTYPES: DISABLE |
2921 | PROTOTYPES: DISABLE |
2316 | |
2922 | |
|
|
2923 | void |
|
|
2924 | decoders () |
|
|
2925 | PPCODE: |
|
|
2926 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
2927 | int i, num = Mix_GetNumChunkDecoders (); |
|
|
2928 | EXTEND (SP, num); |
|
|
2929 | for (i = 0; i < num; ++i) |
|
|
2930 | PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0))); |
|
|
2931 | #else |
|
|
2932 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
2933 | #endif |
|
|
2934 | |
2317 | CFPlus::MixChunk |
2935 | DC::MixChunk |
2318 | new (SV *class, CFPlus::RW rwops) |
2936 | new (SV *class, DC::RW rwops) |
2319 | CODE: |
2937 | CODE: |
2320 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2938 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2321 | OUTPUT: |
2939 | OUTPUT: |
2322 | RETVAL |
2940 | RETVAL |
2323 | |
2941 | |
2324 | void |
2942 | void |
2325 | DESTROY (CFPlus::MixChunk self) |
2943 | DESTROY (DC::MixChunk self) |
2326 | CODE: |
2944 | CODE: |
2327 | Mix_FreeChunk (self); |
2945 | Mix_FreeChunk (self); |
2328 | |
2946 | |
2329 | int |
2947 | int |
2330 | volume (CFPlus::MixChunk self, int volume = -1) |
2948 | volume (DC::MixChunk self, int volume = -1) |
2331 | CODE: |
2949 | CODE: |
|
|
2950 | if (items > 1) |
|
|
2951 | volume = CLAMP (volume, 0, 128); |
2332 | RETVAL = Mix_VolumeChunk (self, volume); |
2952 | RETVAL = Mix_VolumeChunk (self, volume); |
2333 | OUTPUT: |
2953 | OUTPUT: |
2334 | RETVAL |
2954 | RETVAL |
2335 | |
2955 | |
2336 | CFPlus::Channel |
2956 | DC::Channel |
2337 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
2957 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2338 | CODE: |
2958 | CODE: |
|
|
2959 | { |
2339 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2960 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
|
|
2961 | |
|
|
2962 | if (RETVAL < 0) |
|
|
2963 | XSRETURN_UNDEF; |
|
|
2964 | |
|
|
2965 | if (channel < 0) |
|
|
2966 | { |
2340 | Mix_UnregisterAllEffects (RETVAL); |
2967 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2968 | Mix_Volume (RETVAL, 128); |
|
|
2969 | } |
|
|
2970 | } |
2341 | OUTPUT: |
2971 | OUTPUT: |
2342 | RETVAL |
2972 | RETVAL |
2343 | |
2973 | |
2344 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2974 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
|
|
2975 | |
|
|
2976 | void |
|
|
2977 | decoders () |
|
|
2978 | PPCODE: |
|
|
2979 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
2980 | int i, num = Mix_GetNumMusicDecoders (); |
|
|
2981 | EXTEND (SP, num); |
|
|
2982 | for (i = 0; i < num; ++i) |
|
|
2983 | PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0))); |
|
|
2984 | #else |
|
|
2985 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
2986 | #endif |
2345 | |
2987 | |
2346 | int |
2988 | int |
2347 | volume (int volume = -1) |
2989 | volume (int volume = -1) |
2348 | PROTOTYPE: ;$ |
2990 | PROTOTYPE: ;$ |
2349 | CODE: |
2991 | CODE: |
|
|
2992 | if (items > 0) |
|
|
2993 | volume = CLAMP (volume, 0, 128); |
2350 | RETVAL = Mix_VolumeMusic (volume); |
2994 | RETVAL = Mix_VolumeMusic (volume); |
2351 | OUTPUT: |
2995 | OUTPUT: |
2352 | RETVAL |
2996 | RETVAL |
2353 | |
2997 | |
|
|
2998 | void |
|
|
2999 | fade_out (int ms) |
|
|
3000 | CODE: |
|
|
3001 | Mix_FadeOutMusic (ms); |
|
|
3002 | |
|
|
3003 | void |
|
|
3004 | halt () |
|
|
3005 | CODE: |
|
|
3006 | Mix_HaltMusic (); |
|
|
3007 | |
2354 | int |
3008 | int |
2355 | fade_out (int ms) |
3009 | playing () |
2356 | CODE: |
3010 | CODE: |
2357 | RETVAL = Mix_FadeOutMusic (ms); |
3011 | RETVAL = Mix_PlayingMusic (); |
2358 | OUTPUT: |
3012 | OUTPUT: |
2359 | RETVAL |
3013 | RETVAL |
2360 | |
3014 | |
2361 | void |
|
|
2362 | halt () |
|
|
2363 | CODE: |
|
|
2364 | Mix_HaltMusic (); |
|
|
2365 | |
|
|
2366 | CFPlus::MixMusic |
3015 | DC::MixMusic |
2367 | new (SV *class, CFPlus::RW rwops) |
3016 | new (SV *class, DC::RW rwops) |
2368 | CODE: |
3017 | CODE: |
2369 | RETVAL = Mix_LoadMUS_RW (rwops); |
3018 | RETVAL = Mix_LoadMUS_RW (rwops); |
2370 | OUTPUT: |
3019 | OUTPUT: |
2371 | RETVAL |
3020 | RETVAL |
2372 | |
3021 | |
2373 | void |
3022 | void |
2374 | DESTROY (CFPlus::MixMusic self) |
3023 | DESTROY (DC::MixMusic self) |
2375 | CODE: |
3024 | CODE: |
2376 | Mix_FreeMusic (self); |
3025 | Mix_FreeMusic (self); |
2377 | |
3026 | |
2378 | int |
3027 | int |
2379 | play (CFPlus::MixMusic self, int loops = -1) |
3028 | play (DC::MixMusic self, int loops = -1) |
2380 | CODE: |
3029 | CODE: |
2381 | RETVAL = Mix_PlayMusic (self, loops); |
3030 | RETVAL = Mix_PlayMusic (self, loops); |
2382 | OUTPUT: |
3031 | OUTPUT: |
2383 | RETVAL |
3032 | RETVAL |
2384 | |
3033 | |
2385 | int |
3034 | void |
2386 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
3035 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2387 | CODE: |
3036 | CODE: |
2388 | RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); |
3037 | Mix_FadeInMusicPos (self, loops, ms, position); |
2389 | OUTPUT: |
|
|
2390 | RETVAL |
|
|
2391 | |
3038 | |
2392 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
3039 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2393 | |
3040 | |
2394 | PROTOTYPES: ENABLE |
3041 | PROTOTYPES: ENABLE |
2395 | |
3042 | |
2396 | BOOT: |
3043 | BOOT: |
2397 | { |
3044 | { |
2398 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
3045 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2399 | static const struct { |
3046 | static const struct { |
2400 | const char *name; |
3047 | const char *name; |
2401 | IV iv; |
3048 | IV iv; |
2402 | } *civ, const_iv[] = { |
3049 | } *civ, const_iv[] = { |
2403 | # define const_iv(name) { # name, (IV)name } |
3050 | # define const_iv(name) { # name, (IV)name } |
2404 | const_iv (GL_VENDOR), |
3051 | const_iv (GL_VENDOR), |
2405 | const_iv (GL_VERSION), |
3052 | const_iv (GL_VERSION), |
2406 | const_iv (GL_EXTENSIONS), |
3053 | const_iv (GL_EXTENSIONS), |
|
|
3054 | const_iv (GL_MAX_TEXTURE_UNITS), |
2407 | const_iv (GL_COLOR_MATERIAL), |
3055 | const_iv (GL_COLOR_MATERIAL), |
2408 | const_iv (GL_SMOOTH), |
3056 | const_iv (GL_SMOOTH), |
2409 | const_iv (GL_FLAT), |
3057 | const_iv (GL_FLAT), |
2410 | const_iv (GL_DITHER), |
3058 | const_iv (GL_DITHER), |
2411 | const_iv (GL_BLEND), |
3059 | const_iv (GL_BLEND), |
… | |
… | |
2423 | const_iv (GL_ZERO), |
3071 | const_iv (GL_ZERO), |
2424 | const_iv (GL_SRC_ALPHA), |
3072 | const_iv (GL_SRC_ALPHA), |
2425 | const_iv (GL_DST_ALPHA), |
3073 | const_iv (GL_DST_ALPHA), |
2426 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
3074 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
2427 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
3075 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
|
|
3076 | const_iv (GL_SRC_COLOR), |
|
|
3077 | const_iv (GL_DST_COLOR), |
|
|
3078 | const_iv (GL_ONE_MINUS_SRC_COLOR), |
|
|
3079 | const_iv (GL_ONE_MINUS_DST_COLOR), |
2428 | const_iv (GL_SRC_ALPHA_SATURATE), |
3080 | const_iv (GL_SRC_ALPHA_SATURATE), |
2429 | const_iv (GL_RGB), |
3081 | const_iv (GL_RGB), |
2430 | const_iv (GL_RGBA), |
3082 | const_iv (GL_RGBA), |
2431 | const_iv (GL_RGBA4), |
3083 | const_iv (GL_RGBA4), |
2432 | const_iv (GL_RGBA8), |
3084 | const_iv (GL_RGBA8), |
… | |
… | |
2438 | const_iv (GL_INTENSITY), |
3090 | const_iv (GL_INTENSITY), |
2439 | const_iv (GL_LUMINANCE), |
3091 | const_iv (GL_LUMINANCE), |
2440 | const_iv (GL_LUMINANCE_ALPHA), |
3092 | const_iv (GL_LUMINANCE_ALPHA), |
2441 | const_iv (GL_FLOAT), |
3093 | const_iv (GL_FLOAT), |
2442 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
3094 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
3095 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
3096 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
3097 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
3098 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
3099 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
3100 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2443 | const_iv (GL_COMPILE), |
3101 | const_iv (GL_COMPILE), |
2444 | const_iv (GL_PROXY_TEXTURE_1D), |
3102 | const_iv (GL_PROXY_TEXTURE_1D), |
2445 | const_iv (GL_PROXY_TEXTURE_2D), |
3103 | const_iv (GL_PROXY_TEXTURE_2D), |
2446 | const_iv (GL_TEXTURE_1D), |
3104 | const_iv (GL_TEXTURE_1D), |
2447 | const_iv (GL_TEXTURE_2D), |
3105 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2486 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
3144 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2487 | const_iv (GL_POINT_SMOOTH_HINT), |
3145 | const_iv (GL_POINT_SMOOTH_HINT), |
2488 | const_iv (GL_LINE_SMOOTH_HINT), |
3146 | const_iv (GL_LINE_SMOOTH_HINT), |
2489 | const_iv (GL_POLYGON_SMOOTH_HINT), |
3147 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2490 | const_iv (GL_GENERATE_MIPMAP_HINT), |
3148 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
3149 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2491 | const_iv (GL_FASTEST), |
3150 | const_iv (GL_FASTEST), |
2492 | const_iv (GL_DONT_CARE), |
3151 | const_iv (GL_DONT_CARE), |
2493 | const_iv (GL_NICEST), |
3152 | const_iv (GL_NICEST), |
2494 | const_iv (GL_V2F), |
3153 | const_iv (GL_V2F), |
2495 | const_iv (GL_V3F), |
3154 | const_iv (GL_V3F), |
2496 | const_iv (GL_T2F_V3F), |
3155 | const_iv (GL_T2F_V3F), |
2497 | const_iv (GL_T2F_N3F_V3F), |
3156 | const_iv (GL_T2F_N3F_V3F), |
|
|
3157 | const_iv (GL_FUNC_ADD), |
|
|
3158 | const_iv (GL_FUNC_SUBTRACT), |
|
|
3159 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
2498 | # undef const_iv |
3160 | # undef const_iv |
2499 | }; |
3161 | }; |
2500 | |
3162 | |
2501 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3163 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
2502 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3164 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
2503 | |
3165 | |
2504 | texture_av = newAV (); |
3166 | texture_av = newAV (); |
2505 | AvREAL_off (texture_av); |
3167 | AvREAL_off (texture_av); |
2506 | } |
3168 | } |
2507 | |
3169 | |
|
|
3170 | void |
|
|
3171 | disable_GL_EXT_blend_func_separate () |
|
|
3172 | CODE: |
|
|
3173 | gl.BlendFuncSeparate = 0; |
|
|
3174 | gl.BlendFuncSeparateEXT = 0; |
|
|
3175 | |
|
|
3176 | void |
|
|
3177 | apple_nvidia_bug (int enable) |
|
|
3178 | |
2508 | char * |
3179 | char * |
2509 | gl_vendor () |
3180 | gl_vendor () |
2510 | CODE: |
3181 | CODE: |
2511 | RETVAL = (char *)glGetString (GL_VENDOR); |
3182 | RETVAL = (char *)glGetString (GL_VENDOR); |
2512 | OUTPUT: |
3183 | OUTPUT: |
… | |
… | |
2542 | |
3213 | |
2543 | int glGetError () |
3214 | int glGetError () |
2544 | |
3215 | |
2545 | void glFinish () |
3216 | void glFinish () |
2546 | |
3217 | |
|
|
3218 | void glFlush () |
|
|
3219 | |
2547 | void glClear (int mask) |
3220 | void glClear (int mask) |
2548 | |
3221 | |
2549 | void glClearColor (float r, float g, float b, float a = 1.0) |
3222 | void glClearColor (float r, float g, float b, float a = 1.0) |
2550 | PROTOTYPE: @ |
3223 | PROTOTYPE: @ |
2551 | |
3224 | |
… | |
… | |
2560 | void glBlendFunc (int sfactor, int dfactor) |
3233 | void glBlendFunc (int sfactor, int dfactor) |
2561 | |
3234 | |
2562 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
3235 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
2563 | CODE: |
3236 | CODE: |
2564 | gl_BlendFuncSeparate (sa, da, saa, daa); |
3237 | gl_BlendFuncSeparate (sa, da, saa, daa); |
|
|
3238 | |
|
|
3239 | # void glBlendEquation (int se) |
2565 | |
3240 | |
2566 | void glDepthMask (int flag) |
3241 | void glDepthMask (int flag) |
2567 | |
3242 | |
2568 | void glLogicOp (int opcode) |
3243 | void glLogicOp (int opcode) |
2569 | |
3244 | |
… | |
… | |
2604 | void glRotate (float angle, float x, float y, float z) |
3279 | void glRotate (float angle, float x, float y, float z) |
2605 | CODE: |
3280 | CODE: |
2606 | glRotatef (angle, x, y, z); |
3281 | glRotatef (angle, x, y, z); |
2607 | |
3282 | |
2608 | void glColor (float r, float g, float b, float a = 1.0) |
3283 | void glColor (float r, float g, float b, float a = 1.0) |
|
|
3284 | PROTOTYPE: @ |
2609 | ALIAS: |
3285 | ALIAS: |
2610 | glColor_premultiply = 1 |
3286 | glColor_premultiply = 1 |
2611 | CODE: |
3287 | CODE: |
2612 | if (ix) |
3288 | if (ix) |
2613 | { |
3289 | { |
… | |
… | |
2633 | |
3309 | |
2634 | void glRect (float x1, float y1, float x2, float y2) |
3310 | void glRect (float x1, float y1, float x2, float y2) |
2635 | CODE: |
3311 | CODE: |
2636 | glRectf (x1, y1, x2, y2); |
3312 | glRectf (x1, y1, x2, y2); |
2637 | |
3313 | |
|
|
3314 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
3315 | CODE: |
|
|
3316 | glBegin (GL_LINE_LOOP); |
|
|
3317 | glVertex2f (x1, y1); |
|
|
3318 | glVertex2f (x2, y1); |
|
|
3319 | glVertex2f (x2, y2); |
|
|
3320 | glVertex2f (x1, y2); |
|
|
3321 | glEnd (); |
|
|
3322 | |
2638 | PROTOTYPES: ENABLE |
3323 | PROTOTYPES: ENABLE |
2639 | |
3324 | |
2640 | void glBegin (int mode) |
3325 | void glBegin (int mode) |
2641 | |
3326 | |
2642 | void glEnd () |
3327 | void glEnd () |
… | |
… | |
2674 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
3359 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2675 | CODE: |
3360 | CODE: |
2676 | if (gl.SeparableFilter2D) |
3361 | if (gl.SeparableFilter2D) |
2677 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
3362 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2678 | |
3363 | |
2679 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
3364 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2680 | |
3365 | |
2681 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
3366 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2682 | |
3367 | |
2683 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
3368 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2684 | |
3369 | |
… | |
… | |
2710 | |
3395 | |
2711 | void glEndList () |
3396 | void glEndList () |
2712 | |
3397 | |
2713 | void glCallList (int list) |
3398 | void glCallList (int list) |
2714 | |
3399 | |
2715 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
3400 | void c_init () |
|
|
3401 | CODE: |
|
|
3402 | glPixelStorei (GL_PACK_ALIGNMENT , 1); |
|
|
3403 | glPixelStorei (GL_UNPACK_ALIGNMENT, 1); |
|
|
3404 | |
|
|
3405 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2716 | |
3406 | |
2717 | PROTOTYPES: DISABLE |
3407 | PROTOTYPES: DISABLE |
2718 | |
3408 | |
2719 | void |
3409 | void |
2720 | find_widget (SV *self, NV x, NV y) |
3410 | find_widget (SV *self, NV x, NV y) |
… | |
… | |
2724 | XPUSHs (self); |
3414 | XPUSHs (self); |
2725 | } |
3415 | } |
2726 | |
3416 | |
2727 | BOOT: |
3417 | BOOT: |
2728 | { |
3418 | { |
2729 | hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); |
3419 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
2730 | |
3420 | |
2731 | draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); |
3421 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
2732 | draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); |
3422 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
2733 | draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); |
3423 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
2734 | draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); |
3424 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
2735 | } |
3425 | } |
2736 | |
3426 | |
2737 | void |
3427 | void |
2738 | draw (SV *self) |
3428 | draw (SV *self) |
2739 | CODE: |
3429 | CODE: |
… | |
… | |
2743 | NV x, y, w, h; |
3433 | NV x, y, w, h; |
2744 | SV *draw_x_sv = GvSV (draw_x_gv); |
3434 | SV *draw_x_sv = GvSV (draw_x_gv); |
2745 | SV *draw_y_sv = GvSV (draw_y_gv); |
3435 | SV *draw_y_sv = GvSV (draw_y_gv); |
2746 | SV *draw_w_sv = GvSV (draw_w_gv); |
3436 | SV *draw_w_sv = GvSV (draw_w_gv); |
2747 | SV *draw_h_sv = GvSV (draw_h_gv); |
3437 | SV *draw_h_sv = GvSV (draw_h_gv); |
2748 | SV *hover; |
|
|
2749 | double draw_x, draw_y, draw_w, draw_h; |
3438 | double draw_x, draw_y; |
2750 | |
3439 | |
2751 | if (!SvROK (self)) |
3440 | if (!SvROK (self)) |
2752 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
3441 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
2753 | |
3442 | |
2754 | hv = (HV *)SvRV (self); |
3443 | hv = (HV *)SvRV (self); |
2755 | |
3444 | |
2756 | if (SvTYPE (hv) != SVt_PVHV) |
3445 | if (SvTYPE (hv) != SVt_PVHV) |
2757 | croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); |
3446 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2758 | |
3447 | |
2759 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
3448 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2760 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
3449 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2761 | |
3450 | |
2762 | if (!h || !w) |
3451 | if (!h || !w) |
… | |
… | |
2782 | { |
3471 | { |
2783 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
3472 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2784 | |
3473 | |
2785 | if (svp && SvTRUE (*svp)) |
3474 | if (svp && SvTRUE (*svp)) |
2786 | { |
3475 | { |
2787 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
3476 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2788 | glEnable (GL_BLEND); |
3477 | glEnable (GL_BLEND); |
2789 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
3478 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2790 | glBegin (GL_QUADS); |
3479 | glBegin (GL_QUADS); |
2791 | glVertex2f (0, 0); |
3480 | glVertex2f (0, 0); |
2792 | glVertex2f (w, 0); |
3481 | glVertex2f (w, 0); |
… | |
… | |
2795 | glEnd (); |
3484 | glEnd (); |
2796 | glDisable (GL_BLEND); |
3485 | glDisable (GL_BLEND); |
2797 | } |
3486 | } |
2798 | } |
3487 | } |
2799 | #if 0 |
3488 | #if 0 |
2800 | if ($ENV{CFPLUS_DEBUG} & 1) { |
3489 | // draw borders, for debugging |
2801 | glPushMatrix; |
3490 | glPushMatrix (); |
2802 | glColor 1, 1, 0, 1; |
3491 | glColor4f (1., 1., 0., 1.); |
2803 | glTranslate 0.375, 0.375; |
3492 | glTranslatef (.5, .5, 0.); |
2804 | glBegin GL_LINE_LOOP; |
3493 | glBegin (GL_LINE_LOOP); |
2805 | glVertex 0 , 0; |
3494 | glVertex2f (0 , 0); |
2806 | glVertex $self->{w} - 1, 0; |
3495 | glVertex2f (w - 1, 0); |
2807 | glVertex $self->{w} - 1, $self->{h} - 1; |
3496 | glVertex2f (w - 1, h - 1); |
2808 | glVertex 0 , $self->{h} - 1; |
3497 | glVertex2f (0 , h - 1); |
2809 | glEnd; |
3498 | glEnd (); |
2810 | glPopMatrix; |
3499 | glPopMatrix (); |
2811 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2812 | } |
|
|
2813 | #endif |
3500 | #endif |
2814 | PUSHMARK (SP); |
3501 | PUSHMARK (SP); |
2815 | XPUSHs (self); |
3502 | XPUSHs (self); |
2816 | PUTBACK; |
3503 | PUTBACK; |
2817 | call_method ("_draw", G_VOID | G_DISCARD); |
3504 | call_method ("_draw", G_VOID | G_DISCARD); |