… | |
… | |
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 roundf(x) (int)(x) |
|
|
25 | # define atan2f(x,y) atan2(x,y) |
|
|
26 | # define M_PI 3.14159265f |
22 | #endif |
27 | #endif |
23 | |
28 | |
24 | #include <assert.h> |
29 | #include <assert.h> |
25 | #include <math.h> |
30 | #include <math.h> |
26 | #include <string.h> |
31 | #include <string.h> |
… | |
… | |
40 | #define G_DISABLE_CAST_CHECKS |
45 | #define G_DISABLE_CAST_CHECKS |
41 | |
46 | |
42 | #include <glib/gmacros.h> |
47 | #include <glib/gmacros.h> |
43 | |
48 | |
44 | #include <pango/pango.h> |
49 | #include <pango/pango.h> |
|
|
50 | |
|
|
51 | #ifndef PANGO_VERSION_CHECK |
|
|
52 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
|
|
53 | #endif |
|
|
54 | |
|
|
55 | #if !PANGO_VERSION_CHECK (1, 15, 2) |
|
|
56 | # define pango_layout_get_line_readonly pango_layout_get_line |
|
|
57 | # define pango_layout_get_lines_readonly pango_layout_get_lines |
|
|
58 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line |
|
|
59 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run |
|
|
60 | #endif |
45 | |
61 | |
46 | #ifndef _WIN32 |
62 | #ifndef _WIN32 |
47 | # include <sys/types.h> |
63 | # include <sys/types.h> |
48 | # include <sys/socket.h> |
64 | # include <sys/socket.h> |
49 | # include <netinet/in.h> |
65 | # include <netinet/in.h> |
50 | # include <netinet/tcp.h> |
66 | # include <netinet/tcp.h> |
51 | # include <inttypes.h> |
67 | # include <inttypes.h> |
52 | #endif |
68 | #endif |
53 | |
69 | |
|
|
70 | #if __GNUC__ >= 4 |
|
|
71 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
72 | #else |
|
|
73 | # define expect(expr,value) (expr) |
|
|
74 | #endif |
|
|
75 | |
|
|
76 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
77 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
78 | |
54 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
79 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
55 | |
80 | |
56 | #define FOW_DARKNESS 32 |
81 | #define FOW_DARKNESS 32 |
57 | |
82 | |
58 | #define MAP_EXTEND_X 32 |
83 | #define MAP_EXTEND_X 32 |
59 | #define MAP_EXTEND_Y 512 |
84 | #define MAP_EXTEND_Y 512 |
60 | |
85 | |
61 | #define MIN_FONT_HEIGHT 10 |
86 | #define MIN_FONT_HEIGHT 10 |
62 | |
87 | |
63 | #if 0 |
88 | /* mask out modifiers we are not interested in */ |
64 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
89 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
65 | #else |
|
|
66 | # define PARACHUTE 0 |
|
|
67 | #endif |
|
|
68 | |
90 | |
69 | static AV *texture_av; |
91 | static AV *texture_av; |
70 | |
92 | |
71 | static struct |
93 | static struct |
72 | { |
94 | { |
… | |
… | |
109 | av_push (texture_av, (SV *)(size_t)name); |
131 | av_push (texture_av, (SV *)(size_t)name); |
110 | glDeleteTextures (1, &name); |
132 | glDeleteTextures (1, &name); |
111 | } |
133 | } |
112 | |
134 | |
113 | #include "texcache.c" |
135 | #include "texcache.c" |
|
|
136 | #include "rendercache.c" |
114 | |
137 | |
115 | #include "pango-font.c" |
138 | #include "pango-font.c" |
116 | #include "pango-fontmap.c" |
139 | #include "pango-fontmap.c" |
117 | #include "pango-render.c" |
140 | #include "pango-render.c" |
118 | |
141 | |
119 | typedef IV CFPlus__Channel; |
142 | typedef IV DC__Channel; |
120 | typedef SDL_RWops *CFPlus__RW; |
143 | typedef SDL_RWops *DC__RW; |
121 | typedef Mix_Chunk *CFPlus__MixChunk; |
144 | typedef Mix_Chunk *DC__MixChunk; |
122 | typedef Mix_Music *CFPlus__MixMusic; |
145 | typedef Mix_Music *DC__MixMusic; |
123 | |
146 | |
124 | typedef PangoFontDescription *CFPlus__Font; |
147 | typedef PangoFontDescription *DC__Font; |
125 | |
148 | |
126 | static int |
149 | static int |
127 | shape_attr_p (PangoLayoutRun *run) |
150 | shape_attr_p (PangoLayoutRun *run) |
128 | { |
151 | { |
129 | GSList *attrs = run->item->analysis.extra_attrs; |
152 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
143 | |
166 | |
144 | typedef struct cf_layout { |
167 | typedef struct cf_layout { |
145 | PangoLayout *pl; |
168 | PangoLayout *pl; |
146 | float r, g, b, a; // default color for rgba mode |
169 | float r, g, b, a; // default color for rgba mode |
147 | int base_height; |
170 | int base_height; |
148 | CFPlus__Font font; |
171 | DC__Font font; |
|
|
172 | rc_t *rc; |
149 | } *CFPlus__Layout; |
173 | } *DC__Layout; |
150 | |
174 | |
151 | static CFPlus__Font default_font; |
175 | static DC__Font default_font; |
152 | static PangoContext *opengl_context; |
176 | static PangoContext *opengl_context; |
153 | static PangoFontMap *opengl_fontmap; |
177 | static PangoFontMap *opengl_fontmap; |
154 | |
178 | |
155 | static void |
179 | static void |
156 | substitute_func (FcPattern *pattern, gpointer data) |
180 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
161 | #endif |
185 | #endif |
162 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
186 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
163 | } |
187 | } |
164 | |
188 | |
165 | static void |
189 | static void |
166 | layout_update_font (CFPlus__Layout self) |
190 | layout_update_font (DC__Layout self) |
167 | { |
191 | { |
168 | /* use a random scale factor to account for unknown descenders, 0.8 works |
192 | /* use a random scale factor to account for unknown descenders, 0.8 works |
169 | * reasonably well with bitstream vera |
193 | * reasonably well with dejavu/bistream fonts |
170 | */ |
194 | */ |
171 | PangoFontDescription *font = self->font ? self->font : default_font; |
195 | PangoFontDescription *font = self->font ? self->font : default_font; |
172 | |
196 | |
173 | pango_font_description_set_absolute_size (font, |
197 | pango_font_description_set_absolute_size (font, |
174 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
198 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
175 | |
199 | |
176 | pango_layout_set_font_description (self->pl, font); |
200 | pango_layout_set_font_description (self->pl, font); |
177 | } |
201 | } |
178 | |
202 | |
179 | static void |
203 | static void |
180 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
204 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
181 | { |
205 | { |
182 | PangoRectangle rect; |
206 | PangoRectangle rect; |
183 | |
207 | |
184 | // get_pixel_* wrongly rounds down |
208 | // get_pixel_* wrongly rounds down |
185 | pango_layout_get_extents (self->pl, 0, &rect); |
209 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
196 | |
220 | |
197 | typedef uint16_t tileid; |
221 | typedef uint16_t tileid; |
198 | typedef uint16_t faceid; |
222 | typedef uint16_t faceid; |
199 | |
223 | |
200 | typedef struct { |
224 | typedef struct { |
201 | int name; |
225 | GLuint name; |
202 | int w, h; |
226 | int w, h; |
203 | float s, t; |
227 | float s, t; |
204 | uint8_t r, g, b, a; |
228 | uint8_t r, g, b, a; |
205 | tileid smoothtile; |
229 | tileid smoothtile; |
206 | uint8_t smoothlevel; |
230 | uint8_t smoothlevel; |
… | |
… | |
224 | int faces; tileid *face2tile; // [faceid] |
248 | int faces; tileid *face2tile; // [faceid] |
225 | int texs; maptex *tex; // [tileid] |
249 | int texs; maptex *tex; // [tileid] |
226 | |
250 | |
227 | int32_t rows; |
251 | int32_t rows; |
228 | maprow *row; |
252 | maprow *row; |
229 | } *CFPlus__Map; |
253 | } *DC__Map; |
230 | |
254 | |
231 | static char * |
255 | static char * |
232 | prepend (char *ptr, int sze, int inc) |
256 | prepend (char *ptr, int sze, int inc) |
233 | { |
257 | { |
234 | char *p; |
258 | char *p; |
… | |
… | |
272 | self->texs *= 2; |
296 | self->texs *= 2; |
273 | } |
297 | } |
274 | } |
298 | } |
275 | |
299 | |
276 | static maprow * |
300 | static maprow * |
277 | map_get_row (CFPlus__Map self, int y) |
301 | map_get_row (DC__Map self, int y) |
278 | { |
302 | { |
279 | if (0 > y) |
303 | if (0 > y) |
280 | { |
304 | { |
281 | int extend = - y + MAP_EXTEND_Y; |
305 | int extend = - y + MAP_EXTEND_Y; |
282 | Prepend (maprow, self->row, self->rows, extend); |
306 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
320 | |
344 | |
321 | return row->col + (x - row->c0); |
345 | return row->col + (x - row->c0); |
322 | } |
346 | } |
323 | |
347 | |
324 | static mapcell * |
348 | static mapcell * |
325 | map_get_cell (CFPlus__Map self, int x, int y) |
349 | map_get_cell (DC__Map self, int x, int y) |
326 | { |
350 | { |
327 | return row_get_cell (map_get_row (self, y), x); |
351 | return row_get_cell (map_get_row (self, y), x); |
328 | } |
352 | } |
329 | |
353 | |
330 | static void |
354 | static void |
331 | map_clear (CFPlus__Map self) |
355 | map_clear (DC__Map self) |
332 | { |
356 | { |
333 | int r; |
357 | int r; |
334 | |
358 | |
335 | for (r = 0; r < self->rows; r++) |
359 | for (r = 0; r < self->rows; r++) |
336 | Safefree (self->row[r].col); |
360 | Safefree (self->row[r].col); |
… | |
… | |
343 | self->oy = 0; |
367 | self->oy = 0; |
344 | self->row = 0; |
368 | self->row = 0; |
345 | self->rows = 0; |
369 | self->rows = 0; |
346 | } |
370 | } |
347 | |
371 | |
|
|
372 | #define CELL_CLEAR(cell) \ |
|
|
373 | do { \ |
|
|
374 | if ((cell)->player) \ |
|
|
375 | (cell)->tile [2] = 0; \ |
|
|
376 | (cell)->darkness = 0; \ |
|
|
377 | (cell)->stat_hp = 0; \ |
|
|
378 | (cell)->flags = 0; \ |
|
|
379 | (cell)->player = 0; \ |
|
|
380 | } while (0) |
|
|
381 | |
348 | static void |
382 | static void |
349 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
383 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
350 | { |
384 | { |
351 | int x, y; |
385 | int x, y; |
352 | maprow *row; |
386 | maprow *row; |
353 | mapcell *cell; |
387 | mapcell *cell; |
354 | |
388 | |
… | |
… | |
366 | if (x >= row->c1) |
400 | if (x >= row->c1) |
367 | break; |
401 | break; |
368 | |
402 | |
369 | cell = row->col + x - row->c0; |
403 | cell = row->col + x - row->c0; |
370 | |
404 | |
371 | cell->darkness = 0; |
405 | CELL_CLEAR (cell); |
372 | cell->stat_hp = 0; |
|
|
373 | cell->flags = 0; |
|
|
374 | cell->player = 0; |
|
|
375 | } |
406 | } |
376 | } |
407 | } |
377 | } |
408 | } |
378 | |
409 | |
379 | typedef struct { |
410 | typedef struct { |
… | |
… | |
433 | n |= n >> 16; |
464 | n |= n >> 16; |
434 | |
465 | |
435 | return n + 1; |
466 | return n + 1; |
436 | } |
467 | } |
437 | |
468 | |
|
|
469 | static unsigned int |
|
|
470 | popcount (unsigned int n) |
|
|
471 | { |
|
|
472 | n -= (n >> 1) & 0x55555555U; |
|
|
473 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
474 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
475 | n *= 0x01010101U; |
|
|
476 | |
|
|
477 | return n >> 24; |
|
|
478 | } |
|
|
479 | |
438 | /* SDL should provide this, really. */ |
480 | /* SDL should provide this, really. */ |
439 | #define SDLK_MODIFIER_MIN 300 |
481 | #define SDLK_MODIFIER_MIN 300 |
440 | #define SDLK_MODIFIER_MAX 314 |
482 | #define SDLK_MODIFIER_MAX 314 |
441 | |
483 | |
442 | /******************************************************************************/ |
484 | /******************************************************************************/ |
… | |
… | |
480 | return 0; |
522 | return 0; |
481 | |
523 | |
482 | return 1; |
524 | return 1; |
483 | } |
525 | } |
484 | |
526 | |
485 | MODULE = CFPlus PACKAGE = CFPlus |
527 | MODULE = Deliantra::Client PACKAGE = DC |
486 | |
528 | |
487 | PROTOTYPES: ENABLE |
529 | PROTOTYPES: ENABLE |
488 | |
530 | |
489 | BOOT: |
531 | BOOT: |
490 | { |
532 | { |
491 | HV *stash = gv_stashpv ("CFPlus", 1); |
533 | HV *stash = gv_stashpv ("DC", 1); |
492 | static const struct { |
534 | static const struct { |
493 | const char *name; |
535 | const char *name; |
494 | IV iv; |
536 | IV iv; |
495 | } *civ, const_iv[] = { |
537 | } *civ, const_iv[] = { |
496 | # define const_iv(name) { # name, (IV)name } |
538 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
518 | |
560 | |
519 | const_iv (SDL_APPINPUTFOCUS), |
561 | const_iv (SDL_APPINPUTFOCUS), |
520 | const_iv (SDL_APPMOUSEFOCUS), |
562 | const_iv (SDL_APPMOUSEFOCUS), |
521 | const_iv (SDL_APPACTIVE), |
563 | const_iv (SDL_APPACTIVE), |
522 | |
564 | |
|
|
565 | const_iv (SDLK_FIRST), |
|
|
566 | const_iv (SDLK_LAST), |
523 | const_iv (SDLK_KP0), |
567 | const_iv (SDLK_KP0), |
524 | const_iv (SDLK_KP1), |
568 | const_iv (SDLK_KP1), |
525 | const_iv (SDLK_KP2), |
569 | const_iv (SDLK_KP2), |
526 | const_iv (SDLK_KP3), |
570 | const_iv (SDLK_KP3), |
527 | const_iv (SDLK_KP4), |
571 | const_iv (SDLK_KP4), |
… | |
… | |
599 | const_iv (KMOD_LMETA), |
643 | const_iv (KMOD_LMETA), |
600 | const_iv (KMOD_RMETA), |
644 | const_iv (KMOD_RMETA), |
601 | const_iv (KMOD_NUM), |
645 | const_iv (KMOD_NUM), |
602 | const_iv (KMOD_CAPS), |
646 | const_iv (KMOD_CAPS), |
603 | const_iv (KMOD_MODE), |
647 | const_iv (KMOD_MODE), |
|
|
648 | |
|
|
649 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
650 | |
|
|
651 | const_iv (SDL_INIT_TIMER), |
|
|
652 | const_iv (SDL_INIT_AUDIO), |
|
|
653 | const_iv (SDL_INIT_VIDEO), |
|
|
654 | const_iv (SDL_INIT_CDROM), |
|
|
655 | const_iv (SDL_INIT_JOYSTICK), |
|
|
656 | const_iv (SDL_INIT_EVERYTHING), |
|
|
657 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
658 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
659 | |
|
|
660 | const_iv (SDL_GL_RED_SIZE), |
|
|
661 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
662 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
663 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
664 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
665 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
666 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
667 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
668 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
669 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
670 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
671 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
672 | const_iv (SDL_GL_STEREO), |
|
|
673 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
674 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
675 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
676 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
677 | |
|
|
678 | const_iv (FOW_DARKNESS) |
604 | # undef const_iv |
679 | # undef const_iv |
605 | }; |
680 | }; |
606 | |
681 | |
607 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
682 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
608 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
683 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
626 | |
701 | |
627 | NV floor (NV x) |
702 | NV floor (NV x) |
628 | |
703 | |
629 | NV ceil (NV x) |
704 | NV ceil (NV x) |
630 | |
705 | |
|
|
706 | IV minpot (UV n) |
|
|
707 | |
|
|
708 | IV popcount (UV n) |
|
|
709 | |
631 | void |
710 | void |
632 | pango_init () |
711 | pango_init () |
633 | CODE: |
712 | CODE: |
634 | { |
713 | { |
635 | opengl_fontmap = pango_opengl_font_map_new (); |
714 | opengl_fontmap = pango_opengl_font_map_new (); |
636 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
715 | 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); |
716 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
717 | /*pango_context_set_font_description (opengl_context, default_font);*/ |
|
|
718 | #if PANGO_VERSION_CHECK (1, 15, 2) |
|
|
719 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
720 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
721 | #endif |
638 | } |
722 | } |
639 | |
723 | |
640 | char * |
|
|
641 | SDL_GetError () |
724 | char *SDL_GetError () |
642 | |
725 | |
643 | int |
726 | int SDL_Init (U32 flags) |
644 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
|
|
645 | |
727 | |
646 | void |
728 | int SDL_InitSubSystem (U32 flags) |
|
|
729 | |
|
|
730 | void SDL_QuitSubSystem (U32 flags) |
|
|
731 | |
647 | SDL_Quit () |
732 | void SDL_Quit () |
|
|
733 | |
|
|
734 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
735 | |
|
|
736 | int SDL_GL_GetAttribute (int attr) |
|
|
737 | CODE: |
|
|
738 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
|
|
739 | XSRETURN_UNDEF; |
|
|
740 | OUTPUT: |
|
|
741 | RETVAL |
648 | |
742 | |
649 | void |
743 | void |
650 | SDL_ListModes (int rgb, int alpha) |
744 | SDL_ListModes (int rgb, int alpha) |
651 | PPCODE: |
745 | PPCODE: |
652 | { |
746 | { |
… | |
… | |
664 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
758 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
665 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
759 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
666 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
760 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
667 | |
761 | |
668 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
762 | 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); |
763 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
672 | #endif |
|
|
673 | |
764 | |
674 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
765 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
675 | |
766 | |
676 | if (m && m != (SDL_Rect **)-1) |
767 | if (m && m != (SDL_Rect **)-1) |
677 | while (*m) |
768 | while (*m) |
678 | { |
769 | { |
679 | if ((*m)->w >= 640 && (*m)->h >= 480) |
770 | if ((*m)->w >= 400 && (*m)->h >= 300) |
680 | { |
771 | { |
681 | AV *av = newAV (); |
772 | AV *av = newAV (); |
682 | av_push (av, newSViv ((*m)->w)); |
773 | av_push (av, newSViv ((*m)->w)); |
683 | av_push (av, newSViv ((*m)->h)); |
774 | av_push (av, newSViv ((*m)->h)); |
684 | av_push (av, newSViv (rgb)); |
775 | av_push (av, newSViv (rgb)); |
… | |
… | |
708 | |
799 | |
709 | if (RETVAL) |
800 | if (RETVAL) |
710 | { |
801 | { |
711 | av_clear (texture_av); |
802 | av_clear (texture_av); |
712 | |
803 | |
713 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
804 | SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); |
714 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
805 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
715 | #include "glfunc.h" |
806 | #include "glfunc.h" |
716 | #undef GL_FUNC |
807 | #undef GL_FUNC |
717 | } |
808 | } |
718 | } |
809 | } |
… | |
… | |
725 | char * |
816 | char * |
726 | SDL_GetKeyName (int sym) |
817 | SDL_GetKeyName (int sym) |
727 | |
818 | |
728 | int |
819 | int |
729 | SDL_GetAppState () |
820 | SDL_GetAppState () |
|
|
821 | |
|
|
822 | int |
|
|
823 | SDL_GetModState () |
730 | |
824 | |
731 | void |
825 | void |
732 | poll_events () |
826 | poll_events () |
733 | PPCODE: |
827 | PPCODE: |
734 | { |
828 | { |
… | |
… | |
744 | { |
838 | { |
745 | case SDL_KEYDOWN: |
839 | case SDL_KEYDOWN: |
746 | case SDL_KEYUP: |
840 | case SDL_KEYUP: |
747 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
841 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
748 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
842 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
749 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
843 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); |
750 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
844 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ |
751 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
845 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
752 | break; |
846 | break; |
753 | |
847 | |
754 | case SDL_ACTIVEEVENT: |
848 | case SDL_ACTIVEEVENT: |
755 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
849 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
773 | x = ev.motion.x; |
867 | x = ev.motion.x; |
774 | y = ev.motion.y; |
868 | y = ev.motion.y; |
775 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
869 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
776 | } |
870 | } |
777 | |
871 | |
778 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
872 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
779 | hv_store (hv, "state", 5, newSViv (state), 0); |
873 | hv_store (hv, "state", 5, newSViv (state), 0); |
780 | hv_store (hv, "x", 1, newSViv (x), 0); |
874 | hv_store (hv, "x", 1, newSViv (x), 0); |
781 | hv_store (hv, "y", 1, newSViv (y), 0); |
875 | hv_store (hv, "y", 1, newSViv (y), 0); |
782 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
876 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
783 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
877 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
784 | } |
878 | } |
785 | break; |
879 | break; |
786 | |
880 | |
787 | case SDL_MOUSEBUTTONDOWN: |
881 | case SDL_MOUSEBUTTONDOWN: |
788 | case SDL_MOUSEBUTTONUP: |
882 | case SDL_MOUSEBUTTONUP: |
789 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
883 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
790 | |
884 | |
791 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
885 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
792 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
886 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
793 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
887 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
794 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
888 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
799 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
893 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
800 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
894 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
801 | break; |
895 | break; |
802 | } |
896 | } |
803 | |
897 | |
804 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
898 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
805 | } |
899 | } |
806 | } |
900 | } |
807 | |
901 | |
808 | int |
902 | int |
809 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) |
903 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
810 | POSTCALL: |
904 | POSTCALL: |
811 | Mix_HookMusicFinished (music_finished); |
905 | Mix_HookMusicFinished (music_finished); |
812 | Mix_ChannelFinished (channel_finished); |
906 | Mix_ChannelFinished (channel_finished); |
|
|
907 | |
|
|
908 | void |
|
|
909 | Mix_QuerySpec () |
|
|
910 | PPCODE: |
|
|
911 | { |
|
|
912 | int freq, channels; |
|
|
913 | Uint16 format; |
|
|
914 | |
|
|
915 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
916 | { |
|
|
917 | EXTEND (SP, 3); |
|
|
918 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
919 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
920 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
921 | } |
|
|
922 | } |
813 | |
923 | |
814 | void |
924 | void |
815 | Mix_CloseAudio () |
925 | Mix_CloseAudio () |
816 | |
926 | |
817 | int |
927 | int |
… | |
… | |
852 | } |
962 | } |
853 | } |
963 | } |
854 | #endif |
964 | #endif |
855 | } |
965 | } |
856 | |
966 | |
857 | void |
967 | int |
858 | add_font (char *file) |
968 | add_font (char *file) |
859 | CODE: |
969 | CODE: |
860 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
970 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
971 | OUTPUT: |
|
|
972 | RETVAL |
861 | |
973 | |
862 | void |
974 | void |
863 | load_image_inline (SV *image_) |
975 | load_image_inline (SV *image_) |
864 | ALIAS: |
976 | ALIAS: |
865 | load_image_file = 1 |
977 | load_image_file = 1 |
… | |
… | |
951 | void |
1063 | void |
952 | error (char *message) |
1064 | error (char *message) |
953 | CODE: |
1065 | CODE: |
954 | fprintf (stderr, "ERROR: %s\n", message); |
1066 | fprintf (stderr, "ERROR: %s\n", message); |
955 | #ifdef _WIN32 |
1067 | #ifdef _WIN32 |
956 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
1068 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
957 | #endif |
1069 | #endif |
958 | |
1070 | |
959 | void |
1071 | void |
960 | fatal (char *message) |
1072 | fatal (char *message) |
961 | CODE: |
1073 | CODE: |
962 | fprintf (stderr, "FATAL: %s\n", message); |
1074 | fprintf (stderr, "FATAL: %s\n", message); |
963 | #ifdef _WIN32 |
1075 | #ifdef _WIN32 |
964 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1076 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
965 | #endif |
1077 | #endif |
966 | _exit (1); |
1078 | _exit (1); |
967 | |
1079 | |
968 | void |
1080 | void |
969 | _exit (int retval = 0) |
1081 | _exit (int retval = 0) |
… | |
… | |
981 | #if DEBUG |
1093 | #if DEBUG |
982 | VALGRIND_DO_LEAK_CHECK; |
1094 | VALGRIND_DO_LEAK_CHECK; |
983 | #endif |
1095 | #endif |
984 | } |
1096 | } |
985 | |
1097 | |
986 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1098 | MODULE = Deliantra::Client PACKAGE = DC::Font |
987 | |
1099 | |
988 | PROTOTYPES: DISABLE |
1100 | PROTOTYPES: DISABLE |
989 | |
1101 | |
990 | CFPlus::Font |
1102 | DC::Font |
991 | new_from_file (SV *class, char *path, int id = 0) |
1103 | new_from_file (SV *class, char *path, int id = 0) |
992 | CODE: |
1104 | CODE: |
993 | { |
1105 | { |
994 | int count; |
1106 | int count; |
995 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1107 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
998 | } |
1110 | } |
999 | OUTPUT: |
1111 | OUTPUT: |
1000 | RETVAL |
1112 | RETVAL |
1001 | |
1113 | |
1002 | void |
1114 | void |
1003 | DESTROY (CFPlus::Font self) |
1115 | DESTROY (DC::Font self) |
1004 | CODE: |
1116 | CODE: |
1005 | pango_font_description_free (self); |
1117 | pango_font_description_free (self); |
1006 | |
1118 | |
1007 | void |
1119 | void |
1008 | make_default (CFPlus::Font self) |
1120 | make_default (DC::Font self) |
1009 | PROTOTYPE: $ |
1121 | PROTOTYPE: $ |
1010 | CODE: |
1122 | CODE: |
1011 | default_font = self; |
1123 | default_font = self; |
1012 | |
1124 | |
1013 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1125 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1014 | |
1126 | |
1015 | PROTOTYPES: DISABLE |
1127 | PROTOTYPES: DISABLE |
1016 | |
1128 | |
1017 | void |
1129 | void |
1018 | reset_glyph_cache () |
1130 | glyph_cache_backup () |
1019 | PROTOTYPE: |
1131 | PROTOTYPE: |
1020 | CODE: |
1132 | CODE: |
|
|
1133 | tc_backup (); |
|
|
1134 | |
|
|
1135 | void |
|
|
1136 | glyph_cache_restore () |
|
|
1137 | PROTOTYPE: |
|
|
1138 | CODE: |
1021 | tc_clear (); |
1139 | tc_restore (); |
1022 | |
1140 | |
1023 | CFPlus::Layout |
1141 | DC::Layout |
1024 | new (SV *class) |
1142 | new (SV *class) |
1025 | CODE: |
1143 | CODE: |
1026 | New (0, RETVAL, 1, struct cf_layout); |
1144 | New (0, RETVAL, 1, struct cf_layout); |
1027 | |
1145 | |
1028 | RETVAL->pl = pango_layout_new (opengl_context); |
1146 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
1030 | RETVAL->g = 1.; |
1148 | RETVAL->g = 1.; |
1031 | RETVAL->b = 1.; |
1149 | RETVAL->b = 1.; |
1032 | RETVAL->a = 1.; |
1150 | RETVAL->a = 1.; |
1033 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1151 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1034 | RETVAL->font = 0; |
1152 | RETVAL->font = 0; |
|
|
1153 | RETVAL->rc = rc_alloc (); |
1035 | |
1154 | |
1036 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1155 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1037 | layout_update_font (RETVAL); |
1156 | layout_update_font (RETVAL); |
1038 | OUTPUT: |
1157 | OUTPUT: |
1039 | RETVAL |
1158 | RETVAL |
1040 | |
1159 | |
1041 | void |
1160 | void |
1042 | DESTROY (CFPlus::Layout self) |
1161 | DESTROY (DC::Layout self) |
1043 | CODE: |
1162 | CODE: |
1044 | g_object_unref (self->pl); |
1163 | g_object_unref (self->pl); |
|
|
1164 | rc_free (self->rc); |
1045 | Safefree (self); |
1165 | Safefree (self); |
1046 | |
1166 | |
1047 | void |
1167 | void |
1048 | set_text (CFPlus::Layout self, SV *text_) |
1168 | set_text (DC::Layout self, SV *text_) |
1049 | CODE: |
1169 | CODE: |
1050 | { |
1170 | { |
1051 | STRLEN textlen; |
1171 | STRLEN textlen; |
1052 | char *text = SvPVutf8 (text_, textlen); |
1172 | char *text = SvPVutf8 (text_, textlen); |
1053 | |
1173 | |
1054 | pango_layout_set_text (self->pl, text, textlen); |
1174 | pango_layout_set_text (self->pl, text, textlen); |
1055 | } |
1175 | } |
1056 | |
1176 | |
1057 | void |
1177 | void |
1058 | set_markup (CFPlus::Layout self, SV *text_) |
1178 | set_markup (DC::Layout self, SV *text_) |
1059 | CODE: |
1179 | CODE: |
1060 | { |
1180 | { |
1061 | STRLEN textlen; |
1181 | STRLEN textlen; |
1062 | char *text = SvPVutf8 (text_, textlen); |
1182 | char *text = SvPVutf8 (text_, textlen); |
1063 | |
1183 | |
1064 | pango_layout_set_markup (self->pl, text, textlen); |
1184 | pango_layout_set_markup (self->pl, text, textlen); |
1065 | } |
1185 | } |
1066 | |
1186 | |
1067 | void |
1187 | void |
1068 | set_shapes (CFPlus::Layout self, ...) |
1188 | set_shapes (DC::Layout self, ...) |
1069 | CODE: |
1189 | CODE: |
1070 | { |
1190 | { |
1071 | PangoAttrList *attrs = 0; |
1191 | PangoAttrList *attrs = 0; |
1072 | const char *text = pango_layout_get_text (self->pl); |
1192 | const char *text = pango_layout_get_text (self->pl); |
1073 | const char *pos = text; |
1193 | const char *pos = text; |
… | |
… | |
1108 | if (attrs) |
1228 | if (attrs) |
1109 | pango_layout_set_attributes (self->pl, attrs); |
1229 | pango_layout_set_attributes (self->pl, attrs); |
1110 | } |
1230 | } |
1111 | |
1231 | |
1112 | void |
1232 | void |
1113 | get_shapes (CFPlus::Layout self) |
1233 | get_shapes (DC::Layout self) |
1114 | PPCODE: |
1234 | PPCODE: |
1115 | { |
1235 | { |
1116 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1236 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1117 | |
1237 | |
1118 | do |
1238 | do |
1119 | { |
1239 | { |
1120 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1240 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1121 | |
1241 | |
1122 | if (run && shape_attr_p (run)) |
1242 | if (run && shape_attr_p (run)) |
1123 | { |
1243 | { |
1124 | PangoRectangle extents; |
1244 | PangoRectangle extents; |
1125 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1245 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1133 | |
1253 | |
1134 | pango_layout_iter_free (iter); |
1254 | pango_layout_iter_free (iter); |
1135 | } |
1255 | } |
1136 | |
1256 | |
1137 | int |
1257 | int |
1138 | has_wrapped (CFPlus::Layout self) |
1258 | has_wrapped (DC::Layout self) |
1139 | CODE: |
1259 | CODE: |
1140 | { |
1260 | { |
1141 | int lines = 1; |
1261 | int lines = 1; |
1142 | const char *text = pango_layout_get_text (self->pl); |
1262 | const char *text = pango_layout_get_text (self->pl); |
1143 | |
1263 | |
… | |
… | |
1148 | } |
1268 | } |
1149 | OUTPUT: |
1269 | OUTPUT: |
1150 | RETVAL |
1270 | RETVAL |
1151 | |
1271 | |
1152 | SV * |
1272 | SV * |
1153 | get_text (CFPlus::Layout self) |
1273 | get_text (DC::Layout self) |
1154 | CODE: |
1274 | CODE: |
1155 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1275 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1156 | sv_utf8_decode (RETVAL); |
1276 | sv_utf8_decode (RETVAL); |
1157 | OUTPUT: |
1277 | OUTPUT: |
1158 | RETVAL |
1278 | RETVAL |
1159 | |
1279 | |
1160 | void |
1280 | void |
1161 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1281 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1162 | CODE: |
1282 | CODE: |
1163 | self->r = r; |
1283 | self->r = r; |
1164 | self->g = g; |
1284 | self->g = g; |
1165 | self->b = b; |
1285 | self->b = b; |
1166 | self->a = a; |
1286 | self->a = a; |
1167 | |
1287 | |
1168 | void |
1288 | void |
1169 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1289 | set_font (DC::Layout self, DC::Font font = 0) |
1170 | CODE: |
1290 | CODE: |
1171 | if (self->font != font) |
1291 | if (self->font != font) |
1172 | { |
1292 | { |
1173 | self->font = font; |
1293 | self->font = font; |
1174 | layout_update_font (self); |
1294 | layout_update_font (self); |
1175 | } |
1295 | } |
1176 | |
1296 | |
1177 | void |
1297 | void |
1178 | set_height (CFPlus::Layout self, int base_height) |
1298 | set_height (DC::Layout self, int base_height) |
1179 | CODE: |
1299 | CODE: |
1180 | if (self->base_height != base_height) |
1300 | if (self->base_height != base_height) |
1181 | { |
1301 | { |
1182 | self->base_height = base_height; |
1302 | self->base_height = base_height; |
1183 | layout_update_font (self); |
1303 | layout_update_font (self); |
1184 | } |
1304 | } |
1185 | |
1305 | |
1186 | void |
1306 | void |
1187 | set_width (CFPlus::Layout self, int max_width = -1) |
1307 | set_width (DC::Layout self, int max_width = -1) |
1188 | CODE: |
1308 | CODE: |
1189 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1309 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1190 | |
1310 | |
1191 | void |
1311 | void |
1192 | set_indent (CFPlus::Layout self, int indent) |
1312 | set_indent (DC::Layout self, int indent) |
1193 | CODE: |
1313 | CODE: |
1194 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1314 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1195 | |
1315 | |
1196 | void |
1316 | void |
1197 | set_spacing (CFPlus::Layout self, int spacing) |
1317 | set_spacing (DC::Layout self, int spacing) |
1198 | CODE: |
1318 | CODE: |
1199 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1319 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1200 | |
1320 | |
1201 | void |
1321 | void |
1202 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1322 | set_ellipsise (DC::Layout self, int ellipsise) |
1203 | CODE: |
1323 | CODE: |
1204 | pango_layout_set_ellipsize (self->pl, |
1324 | pango_layout_set_ellipsize (self->pl, |
1205 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1325 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1206 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1326 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1207 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1327 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1208 | : PANGO_ELLIPSIZE_NONE |
1328 | : PANGO_ELLIPSIZE_NONE |
1209 | ); |
1329 | ); |
1210 | |
1330 | |
1211 | void |
1331 | void |
1212 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1332 | set_single_paragraph_mode (DC::Layout self, int spm) |
1213 | CODE: |
1333 | CODE: |
1214 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1334 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1215 | |
1335 | |
1216 | void |
1336 | void |
1217 | size (CFPlus::Layout self) |
1337 | size (DC::Layout self) |
1218 | PPCODE: |
1338 | PPCODE: |
1219 | { |
1339 | { |
1220 | int w, h; |
1340 | int w, h; |
1221 | |
1341 | |
1222 | layout_get_pixel_size (self, &w, &h); |
1342 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1225 | PUSHs (sv_2mortal (newSViv (w))); |
1345 | PUSHs (sv_2mortal (newSViv (w))); |
1226 | PUSHs (sv_2mortal (newSViv (h))); |
1346 | PUSHs (sv_2mortal (newSViv (h))); |
1227 | } |
1347 | } |
1228 | |
1348 | |
1229 | int |
1349 | int |
1230 | descent (CFPlus::Layout self) |
1350 | descent (DC::Layout self) |
1231 | CODE: |
1351 | CODE: |
1232 | { |
1352 | { |
1233 | PangoRectangle rect; |
1353 | PangoRectangle rect; |
1234 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1354 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1235 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1355 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1236 | RETVAL = PANGO_DESCENT (rect); |
1356 | RETVAL = PANGO_DESCENT (rect); |
1237 | } |
1357 | } |
1238 | OUTPUT: |
1358 | OUTPUT: |
1239 | RETVAL |
1359 | RETVAL |
1240 | |
1360 | |
1241 | int |
1361 | int |
1242 | xy_to_index (CFPlus::Layout self, int x, int y) |
1362 | xy_to_index (DC::Layout self, int x, int y) |
1243 | CODE: |
1363 | CODE: |
1244 | { |
1364 | { |
1245 | int index, trailing; |
1365 | int index, trailing; |
1246 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1366 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1247 | RETVAL = index + trailing; |
1367 | RETVAL = index + trailing; |
1248 | } |
1368 | } |
1249 | OUTPUT: |
1369 | OUTPUT: |
1250 | RETVAL |
1370 | RETVAL |
1251 | |
1371 | |
1252 | void |
1372 | void |
1253 | cursor_pos (CFPlus::Layout self, int index) |
1373 | cursor_pos (DC::Layout self, int index) |
1254 | PPCODE: |
1374 | PPCODE: |
1255 | { |
1375 | { |
1256 | PangoRectangle strong_pos; |
1376 | PangoRectangle pos; |
1257 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1377 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1258 | |
1378 | |
1259 | EXTEND (SP, 3); |
1379 | EXTEND (SP, 3); |
1260 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1380 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1261 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1381 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1262 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1382 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1263 | } |
1383 | } |
1264 | |
1384 | |
1265 | void |
1385 | void |
1266 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1386 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1267 | PPCODE: |
1387 | PPCODE: |
1268 | { |
1388 | { |
1269 | int line, x; |
1389 | int line, x; |
1270 | |
1390 | |
1271 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1391 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1392 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1272 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1393 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1273 | |
1394 | --line; |
|
|
1395 | #endif |
1274 | EXTEND (SP, 2); |
1396 | EXTEND (SP, 2); |
1275 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1397 | PUSHs (sv_2mortal (newSViv (line))); |
1276 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1398 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1277 | } |
1399 | } |
1278 | |
1400 | |
1279 | void |
1401 | void |
1280 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1402 | line_x_to_index (DC::Layout self, int line, int x) |
1281 | PPCODE: |
1403 | PPCODE: |
1282 | { |
1404 | { |
1283 | PangoLayoutLine *lp; |
1405 | PangoLayoutLine *lp; |
1284 | int index, trailing; |
1406 | int index, trailing; |
1285 | |
1407 | |
1286 | if (line < 0) |
1408 | if (line < 0) |
1287 | XSRETURN_EMPTY; |
1409 | XSRETURN_EMPTY; |
1288 | |
1410 | |
1289 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1411 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1290 | XSRETURN_EMPTY; /* do better */ |
1412 | XSRETURN_EMPTY; /* do better */ |
1291 | |
1413 | |
1292 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1414 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1293 | |
1415 | |
1294 | EXTEND (SP, 2); |
1416 | EXTEND (SP, 2); |
… | |
… | |
1300 | PUSHs (sv_2mortal (newSViv (trailing))); |
1422 | PUSHs (sv_2mortal (newSViv (trailing))); |
1301 | } |
1423 | } |
1302 | } |
1424 | } |
1303 | |
1425 | |
1304 | void |
1426 | void |
1305 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1427 | render (DC::Layout self, float x, float y, int flags = 0) |
1306 | PPCODE: |
1428 | CODE: |
|
|
1429 | rc_clear (self->rc); |
1307 | pango_opengl_render_layout_subpixel ( |
1430 | pango_opengl_render_layout_subpixel ( |
1308 | self->pl, |
1431 | self->pl, |
|
|
1432 | self->rc, |
1309 | x * PANGO_SCALE, y * PANGO_SCALE, |
1433 | x * PANGO_SCALE, y * PANGO_SCALE, |
1310 | self->r, self->g, self->b, self->a, |
1434 | self->r, self->g, self->b, self->a, |
1311 | flags |
1435 | flags |
1312 | ); |
1436 | ); |
|
|
1437 | // we assume that context_change actually clears/frees stuff |
|
|
1438 | // and does not do any recomputation... |
|
|
1439 | pango_layout_context_changed (self->pl); |
1313 | |
1440 | |
1314 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1441 | void |
|
|
1442 | draw (DC::Layout self) |
|
|
1443 | CODE: |
|
|
1444 | { |
|
|
1445 | glEnable (GL_TEXTURE_2D); |
|
|
1446 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1447 | glEnable (GL_BLEND); |
|
|
1448 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1449 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1450 | glEnable (GL_ALPHA_TEST); |
|
|
1451 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1452 | |
|
|
1453 | rc_draw (self->rc); |
|
|
1454 | |
|
|
1455 | glDisable (GL_ALPHA_TEST); |
|
|
1456 | glDisable (GL_BLEND); |
|
|
1457 | glDisable (GL_TEXTURE_2D); |
|
|
1458 | } |
|
|
1459 | |
|
|
1460 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1315 | |
1461 | |
1316 | PROTOTYPES: ENABLE |
1462 | PROTOTYPES: ENABLE |
1317 | |
|
|
1318 | int minpot (int n) |
|
|
1319 | |
1463 | |
1320 | void |
1464 | void |
1321 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1465 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1322 | CODE: |
1466 | CODE: |
1323 | { |
1467 | { |
… | |
… | |
1400 | RETVAL = width > 0; |
1544 | RETVAL = width > 0; |
1401 | } |
1545 | } |
1402 | OUTPUT: |
1546 | OUTPUT: |
1403 | RETVAL |
1547 | RETVAL |
1404 | |
1548 | |
1405 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1549 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1406 | |
1550 | |
1407 | PROTOTYPES: DISABLE |
1551 | PROTOTYPES: DISABLE |
1408 | |
1552 | |
1409 | CFPlus::Map |
1553 | DC::Map |
1410 | new (SV *class) |
1554 | new (SV *class) |
1411 | CODE: |
1555 | CODE: |
1412 | New (0, RETVAL, 1, struct map); |
1556 | New (0, RETVAL, 1, struct map); |
1413 | RETVAL->x = 0; |
1557 | RETVAL->x = 0; |
1414 | RETVAL->y = 0; |
1558 | RETVAL->y = 0; |
… | |
… | |
1422 | RETVAL->row = 0; |
1566 | RETVAL->row = 0; |
1423 | OUTPUT: |
1567 | OUTPUT: |
1424 | RETVAL |
1568 | RETVAL |
1425 | |
1569 | |
1426 | void |
1570 | void |
1427 | DESTROY (CFPlus::Map self) |
1571 | DESTROY (DC::Map self) |
1428 | CODE: |
1572 | CODE: |
1429 | { |
1573 | { |
1430 | map_clear (self); |
1574 | map_clear (self); |
1431 | Safefree (self->face2tile); |
1575 | Safefree (self->face2tile); |
1432 | Safefree (self->tex); |
1576 | Safefree (self->tex); |
1433 | Safefree (self); |
1577 | Safefree (self); |
1434 | } |
1578 | } |
1435 | |
1579 | |
1436 | void |
1580 | void |
1437 | resize (CFPlus::Map self, int map_width, int map_height) |
1581 | resize (DC::Map self, int map_width, int map_height) |
1438 | CODE: |
1582 | CODE: |
1439 | self->w = map_width; |
1583 | self->w = map_width; |
1440 | self->h = map_height; |
1584 | self->h = map_height; |
1441 | |
1585 | |
1442 | void |
1586 | void |
1443 | clear (CFPlus::Map self) |
1587 | clear (DC::Map self) |
1444 | CODE: |
1588 | CODE: |
1445 | map_clear (self); |
1589 | map_clear (self); |
1446 | |
1590 | |
1447 | void |
1591 | void |
1448 | set_tileid (CFPlus::Map self, int face, int tile) |
1592 | set_tileid (DC::Map self, int face, int tile) |
1449 | CODE: |
1593 | CODE: |
1450 | { |
1594 | { |
1451 | need_facenum (self, face); self->face2tile [face] = tile; |
1595 | need_facenum (self, face); self->face2tile [face] = tile; |
1452 | need_texid (self, tile); |
1596 | need_texid (self, tile); |
1453 | } |
1597 | } |
1454 | |
1598 | |
1455 | void |
1599 | void |
1456 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1600 | set_smooth (DC::Map self, int face, int smooth, int level) |
1457 | CODE: |
1601 | CODE: |
1458 | { |
1602 | { |
1459 | tileid texid; |
1603 | tileid texid; |
1460 | maptex *tex; |
1604 | maptex *tex; |
1461 | |
1605 | |
… | |
… | |
1474 | tex->smoothtile = self->face2tile [smooth]; |
1618 | tex->smoothtile = self->face2tile [smooth]; |
1475 | tex->smoothlevel = level; |
1619 | tex->smoothlevel = level; |
1476 | } |
1620 | } |
1477 | |
1621 | |
1478 | void |
1622 | void |
1479 | 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) |
1623 | 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) |
1480 | CODE: |
1624 | CODE: |
1481 | { |
1625 | { |
1482 | need_texid (self, texid); |
1626 | need_texid (self, texid); |
1483 | |
1627 | |
1484 | { |
1628 | { |
… | |
… | |
1504 | // from transparent color bleeding and ugly wrapping effects. |
1648 | // from transparent color bleeding and ugly wrapping effects. |
1505 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1649 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1506 | } |
1650 | } |
1507 | |
1651 | |
1508 | int |
1652 | int |
1509 | ox (CFPlus::Map self) |
1653 | ox (DC::Map self) |
1510 | ALIAS: |
1654 | ALIAS: |
1511 | oy = 1 |
1655 | oy = 1 |
1512 | x = 2 |
1656 | x = 2 |
1513 | y = 3 |
1657 | y = 3 |
1514 | w = 4 |
1658 | w = 4 |
… | |
… | |
1525 | } |
1669 | } |
1526 | OUTPUT: |
1670 | OUTPUT: |
1527 | RETVAL |
1671 | RETVAL |
1528 | |
1672 | |
1529 | void |
1673 | void |
1530 | scroll (CFPlus::Map self, int dx, int dy) |
1674 | scroll (DC::Map self, int dx, int dy) |
1531 | CODE: |
1675 | CODE: |
1532 | { |
1676 | { |
1533 | if (dx > 0) |
1677 | if (dx > 0) |
1534 | map_blank (self, self->x, self->y, dx, self->h); |
1678 | map_blank (self, self->x, self->y, dx, self->h); |
1535 | else if (dx < 0) |
1679 | else if (dx < 0) |
… | |
… | |
1551 | self->y += MAP_EXTEND_Y; |
1695 | self->y += MAP_EXTEND_Y; |
1552 | } |
1696 | } |
1553 | } |
1697 | } |
1554 | |
1698 | |
1555 | SV * |
1699 | SV * |
1556 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1700 | map1a_update (DC::Map self, SV *data_, int extmap) |
1557 | CODE: |
1701 | CODE: |
1558 | { |
1702 | { |
1559 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1703 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1560 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1704 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1561 | mapcell *cell; |
1705 | mapcell *cell; |
… | |
… | |
1589 | uint8_t ext, cmd; |
1733 | uint8_t ext, cmd; |
1590 | |
1734 | |
1591 | do |
1735 | do |
1592 | { |
1736 | { |
1593 | ext = *data++; |
1737 | ext = *data++; |
1594 | cmd = ext & 0x3f; |
1738 | cmd = ext & 0x7f; |
1595 | |
1739 | |
1596 | if (cmd < 4) |
1740 | if (cmd < 4) |
1597 | cell->darkness = 255 - ext * 64 + 1; |
1741 | cell->darkness = 255 - ext * 64 + 1; |
1598 | else if (cmd == 5) // health |
1742 | else if (cmd == 5) // health |
1599 | { |
1743 | { |
… | |
… | |
1602 | } |
1746 | } |
1603 | else if (cmd == 6) // monster width |
1747 | else if (cmd == 6) // monster width |
1604 | cell->stat_width = *data++ + 1; |
1748 | cell->stat_width = *data++ + 1; |
1605 | else if (cmd == 0x47) |
1749 | else if (cmd == 0x47) |
1606 | { |
1750 | { |
1607 | if (*data == 4) |
1751 | if (*data == 1) cell->player = data [1]; |
1608 | ; // decode player count |
1752 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
1753 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
1754 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
1609 | |
1755 | |
1610 | data += *data + 1; |
1756 | data += *data + 1; |
1611 | } |
1757 | } |
1612 | else if (cmd == 8) // cell flags |
1758 | else if (cmd == 8) // cell flags |
1613 | cell->flags = *data++; |
1759 | cell->flags = *data++; |
… | |
… | |
1643 | } |
1789 | } |
1644 | } |
1790 | } |
1645 | } |
1791 | } |
1646 | } |
1792 | } |
1647 | else |
1793 | else |
1648 | cell->darkness = 0; |
1794 | CELL_CLEAR (cell); |
1649 | } |
1795 | } |
1650 | } |
1796 | } |
1651 | OUTPUT: |
1797 | OUTPUT: |
1652 | RETVAL |
1798 | RETVAL |
1653 | |
1799 | |
1654 | SV * |
1800 | SV * |
1655 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1801 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1656 | CODE: |
1802 | CODE: |
1657 | { |
1803 | { |
1658 | int x1, x; |
1804 | int x1, x; |
1659 | int y1, y; |
1805 | int y1, y; |
1660 | int z; |
1806 | int z; |
… | |
… | |
1705 | } |
1851 | } |
1706 | OUTPUT: |
1852 | OUTPUT: |
1707 | RETVAL |
1853 | RETVAL |
1708 | |
1854 | |
1709 | void |
1855 | void |
1710 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1856 | draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
1711 | CODE: |
1857 | CODE: |
1712 | { |
1858 | { |
|
|
1859 | int x, y, z; |
|
|
1860 | |
1713 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1861 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1714 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1862 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1715 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1863 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1716 | smooth_key skey; |
1864 | smooth_key skey; |
1717 | int x, y, z; |
1865 | int pl_x, pl_y; |
1718 | int last_name; |
1866 | maptex pl_tex; |
|
|
1867 | rc_t *rc = rc_alloc (); |
|
|
1868 | rc_key_t key; |
|
|
1869 | rc_array_t *arr; |
|
|
1870 | |
|
|
1871 | pl_tex.name = 0; |
1719 | |
1872 | |
1720 | // thats current max. sorry. |
1873 | // thats current max. sorry. |
1721 | if (sw > 255) sw = 255; |
1874 | if (sw > 255) sw = 255; |
1722 | if (sh > 255) sh = 255; |
1875 | if (sh > 255) sh = 255; |
1723 | |
1876 | |
1724 | // clear key, in case of extra padding |
1877 | // clear key, in case of extra padding |
1725 | memset (&skey, 0, sizeof (skey)); |
1878 | memset (&skey, 0, sizeof (skey)); |
1726 | |
1879 | |
1727 | glColor4ub (255, 255, 255, 255); |
1880 | memset (&key, 0, sizeof (key)); |
1728 | |
1881 | key.r = 255; |
1729 | glEnable (GL_BLEND); |
1882 | key.g = 255; |
1730 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1883 | key.b = 255; |
1731 | glEnable (GL_TEXTURE_2D); |
1884 | key.a = 255; |
1732 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1885 | key.mode = GL_QUADS; |
1733 | |
1886 | key.format = GL_T2F_V3F; |
1734 | glBegin (GL_QUADS); |
|
|
1735 | |
|
|
1736 | last_name = -1; |
1887 | key.texname = -1; |
1737 | |
1888 | |
1738 | mx += self->x; |
1889 | mx += self->x; |
1739 | my += self->y; |
1890 | my += self->y; |
1740 | |
1891 | |
1741 | // first pass: determine smooth_max |
1892 | // first pass: determine smooth_max |
… | |
… | |
1757 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1908 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1758 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1909 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1759 | self->tex [cell->tile [2]].smoothlevel)); |
1910 | self->tex [cell->tile [2]].smoothlevel)); |
1760 | } |
1911 | } |
1761 | } |
1912 | } |
|
|
1913 | |
|
|
1914 | glEnable (GL_BLEND); |
|
|
1915 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1916 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1762 | |
1917 | |
1763 | for (z = 0; z <= 2; z++) |
1918 | for (z = 0; z <= 2; z++) |
1764 | { |
1919 | { |
1765 | memset (smooth_level, 0, sizeof (smooth_level)); |
1920 | memset (smooth_level, 0, sizeof (smooth_level)); |
1766 | |
1921 | |
… | |
… | |
1776 | tileid tile = cell->tile [z]; |
1931 | tileid tile = cell->tile [z]; |
1777 | |
1932 | |
1778 | if (tile) |
1933 | if (tile) |
1779 | { |
1934 | { |
1780 | maptex tex = self->tex [tile]; |
1935 | maptex tex = self->tex [tile]; |
1781 | int px, py; |
1936 | int px = (x + 1) * T - tex.w; |
|
|
1937 | int py = (y + 1) * T - tex.h; |
1782 | |
1938 | |
1783 | // suppressing texture state switches here |
|
|
1784 | // is only moderately effective, but worth the extra effort |
|
|
1785 | if (last_name != tex.name) |
1939 | if (key.texname != tex.name) |
1786 | { |
1940 | { |
1787 | if (!tex.name) |
1941 | if (!tex.name) |
1788 | tex = self->tex [2]; /* missing, replace by noface */ |
1942 | tex = self->tex [2]; /* missing, replace by noface */ |
1789 | |
1943 | |
1790 | glEnd (); |
1944 | key.texname = tex.name; |
1791 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1945 | arr = rc_array (rc, &key); |
1792 | glBegin (GL_QUADS); |
|
|
1793 | } |
1946 | } |
1794 | |
1947 | |
1795 | px = (x + 1) * T - tex.w; |
1948 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
1796 | py = (y + 1) * T - tex.h; |
|
|
1797 | |
|
|
1798 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1799 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1800 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1801 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1802 | |
|
|
1803 | if (cell->flags && z == 2) |
|
|
1804 | { |
1949 | { |
|
|
1950 | pl_x = px; |
|
|
1951 | pl_y = py; |
|
|
1952 | pl_tex = tex; |
|
|
1953 | continue; |
|
|
1954 | } |
|
|
1955 | |
|
|
1956 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1957 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
1958 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
1959 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
|
|
1960 | |
|
|
1961 | if (expect_false (cell->flags) && expect_false (z == 2)) |
|
|
1962 | { |
|
|
1963 | // overlays such as the speech bubble, probably more to come |
1805 | if (cell->flags & 1) |
1964 | if (cell->flags & 1) |
1806 | { |
1965 | { |
1807 | maptex tex = self->tex [1]; |
1966 | maptex tex = self->tex [1]; |
1808 | int px = x * T + T * 2 / 32; |
1967 | int px = x * T + T * 2 / 32; |
1809 | int py = y * T - T * 6 / 32; |
1968 | int py = y * T - T * 6 / 32; |
1810 | |
1969 | |
|
|
1970 | if (tex.name) |
1811 | glEnd (); |
1971 | { |
1812 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1972 | if (key.texname != tex.name) |
|
|
1973 | { |
|
|
1974 | key.texname = tex.name; |
|
|
1975 | arr = rc_array (rc, &key); |
|
|
1976 | } |
|
|
1977 | |
|
|
1978 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1979 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1980 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1981 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
1813 | glBegin (GL_QUADS); |
1982 | } |
1814 | |
|
|
1815 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1816 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1817 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1818 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1819 | } |
1983 | } |
1820 | } |
1984 | } |
1821 | |
1985 | |
1822 | // update smooth hash |
1986 | // update smooth hash |
1823 | if (tex.smoothtile) |
1987 | if (tex.smoothtile) |
… | |
… | |
1859 | } |
2023 | } |
1860 | } |
2024 | } |
1861 | } |
2025 | } |
1862 | } |
2026 | } |
1863 | |
2027 | |
|
|
2028 | rc_draw (rc); |
|
|
2029 | rc_clear (rc); |
|
|
2030 | |
1864 | // go through all smoothlevels, lowest to highest, then draw. |
2031 | // go through all smoothlevels, lowest to highest, then draw. |
1865 | // this is basically counting sort |
2032 | // this is basically counting sort |
1866 | { |
2033 | { |
1867 | int w, b; |
2034 | int w, b; |
1868 | |
2035 | |
|
|
2036 | glEnable (GL_TEXTURE_2D); |
|
|
2037 | glBegin (GL_QUADS); |
1869 | for (w = 0; w < 256 / 32; ++w) |
2038 | for (w = 0; w < 256 / 32; ++w) |
1870 | { |
2039 | { |
1871 | uint32_t smask = smooth_level [w]; |
2040 | uint32_t smask = smooth_level [w]; |
1872 | if (smask) |
2041 | if (smask) |
1873 | for (b = 0; b < 32; ++b) |
2042 | for (b = 0; b < 32; ++b) |
… | |
… | |
1892 | int border = bits & 15; |
2061 | int border = bits & 15; |
1893 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2062 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1894 | float dx = tex.s * .0625f; // 16 images/row |
2063 | float dx = tex.s * .0625f; // 16 images/row |
1895 | float dy = tex.t * .5f ; // 2 images/column |
2064 | float dy = tex.t * .5f ; // 2 images/column |
1896 | |
2065 | |
1897 | // this time naively avoiding texture state changes |
|
|
1898 | // save gobs of state changes. |
|
|
1899 | if (last_name != tex.name) |
2066 | if (tex.name) |
1900 | { |
2067 | { |
|
|
2068 | // this time avoiding texture state changes |
|
|
2069 | // save gobs of state changes. |
1901 | if (!tex.name) |
2070 | if (key.texname != tex.name) |
1902 | continue; // smoothing not yet available |
2071 | { |
1903 | |
|
|
1904 | glEnd (); |
2072 | glEnd (); |
1905 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
2073 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1906 | glBegin (GL_QUADS); |
2074 | glBegin (GL_QUADS); |
1907 | } |
2075 | } |
1908 | |
2076 | |
1909 | if (border) |
2077 | if (border) |
1910 | { |
2078 | { |
1911 | float ox = border * dx; |
2079 | float ox = border * dx; |
1912 | |
2080 | |
1913 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
2081 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1914 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
2082 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1915 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
2083 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1916 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
2084 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1917 | } |
2085 | } |
1918 | |
2086 | |
1919 | if (corner) |
2087 | if (corner) |
1920 | { |
2088 | { |
1921 | float ox = corner * dx; |
2089 | float ox = corner * dx; |
1922 | |
2090 | |
1923 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
2091 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1924 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
2092 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1925 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
2093 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1926 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
2094 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
|
|
2095 | } |
1927 | } |
2096 | } |
1928 | } |
2097 | } |
1929 | } |
2098 | } |
1930 | } |
2099 | } |
1931 | } |
2100 | } |
|
|
2101 | |
|
|
2102 | glEnd (); |
|
|
2103 | glDisable (GL_TEXTURE_2D); |
|
|
2104 | key.texname = -1; |
1932 | } |
2105 | } |
1933 | |
2106 | |
1934 | hv_clear (smooth); |
2107 | hv_clear (smooth); |
1935 | } |
2108 | } |
1936 | |
2109 | |
1937 | glEnd (); |
2110 | if (pl_tex.name) |
|
|
2111 | { |
|
|
2112 | maptex tex = pl_tex; |
|
|
2113 | int px = pl_x + sdx; |
|
|
2114 | int py = pl_y + sdy; |
1938 | |
2115 | |
1939 | glDisable (GL_TEXTURE_2D); |
2116 | key.texname = tex.name; |
|
|
2117 | arr = rc_array (rc, &key); |
|
|
2118 | |
|
|
2119 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
2120 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
2121 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2122 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
|
|
2123 | |
|
|
2124 | rc_draw (rc); |
|
|
2125 | } |
|
|
2126 | |
1940 | glDisable (GL_BLEND); |
2127 | glDisable (GL_BLEND); |
|
|
2128 | rc_free (rc); |
1941 | |
2129 | |
1942 | // top layer: overlays such as the health bar |
2130 | // top layer: overlays such as the health bar |
1943 | for (y = 0; y < sh; y++) |
2131 | for (y = 0; y < sh; y++) |
1944 | if (0 <= y + my && y + my < self->rows) |
2132 | if (0 <= y + my && y + my < self->rows) |
1945 | { |
2133 | { |
… | |
… | |
1970 | } |
2158 | } |
1971 | } |
2159 | } |
1972 | } |
2160 | } |
1973 | |
2161 | |
1974 | void |
2162 | void |
1975 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2163 | draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1976 | CODE: |
2164 | CODE: |
1977 | { |
2165 | { |
1978 | static float color[16][3] = { |
2166 | static float color[16][3] = { |
1979 | { 0.00F, 0.00F, 0.00F }, |
2167 | { 0.00F, 0.00F, 0.00F }, |
1980 | { 1.00F, 1.00F, 1.00F }, |
2168 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
2030 | glDisable (GL_BLEND); |
2218 | glDisable (GL_BLEND); |
2031 | glDisable (GL_TEXTURE_2D); |
2219 | glDisable (GL_TEXTURE_2D); |
2032 | } |
2220 | } |
2033 | |
2221 | |
2034 | void |
2222 | void |
2035 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2223 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2036 | PPCODE: |
2224 | PPCODE: |
2037 | { |
2225 | { |
2038 | int x, y; |
2226 | int x, y; |
2039 | int sw1 = sw + 2; |
2227 | int sw1 = sw + 2; |
2040 | int sh1 = sh + 2; |
2228 | int sh1 = sh + 2; |
… | |
… | |
2048 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2236 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2049 | |
2237 | |
2050 | mx += self->x - 1; |
2238 | mx += self->x - 1; |
2051 | my += self->y - 1; |
2239 | my += self->y - 1; |
2052 | |
2240 | |
2053 | memset (darkness1, 255, sw1 * sh1); |
2241 | memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); |
2054 | |
2242 | |
2055 | for (y = 0; y < sh1; y++) |
2243 | for (y = 0; y < sh1; y++) |
2056 | if (0 <= y + my && y + my < self->rows) |
2244 | if (0 <= y + my && y + my < self->rows) |
2057 | { |
2245 | { |
2058 | maprow *row = self->row + (y + my); |
2246 | maprow *row = self->row + (y + my); |
… | |
… | |
2111 | PUSHs (sv_2mortal (newSViv (sh3))); |
2299 | PUSHs (sv_2mortal (newSViv (sh3))); |
2112 | PUSHs (darkness3_sv); |
2300 | PUSHs (darkness3_sv); |
2113 | } |
2301 | } |
2114 | |
2302 | |
2115 | SV * |
2303 | SV * |
2116 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2304 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2117 | CODE: |
2305 | CODE: |
2118 | { |
2306 | { |
2119 | int x, y, x1, y1; |
2307 | int x, y, x1, y1; |
2120 | SV *data_sv = newSV (w * h * 7 + 5); |
2308 | SV *data_sv = newSV (w * h * 7 + 5); |
2121 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2309 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2178 | else |
2366 | else |
2179 | *data++ = 0; |
2367 | *data++ = 0; |
2180 | } |
2368 | } |
2181 | } |
2369 | } |
2182 | |
2370 | |
|
|
2371 | /* if size is w*h + 5 then no data has been found */ |
|
|
2372 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
|
|
2373 | { |
2183 | SvPOK_only (data_sv); |
2374 | SvPOK_only (data_sv); |
2184 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2375 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
2376 | } |
|
|
2377 | |
2185 | RETVAL = data_sv; |
2378 | RETVAL = data_sv; |
2186 | } |
2379 | } |
2187 | OUTPUT: |
2380 | OUTPUT: |
2188 | RETVAL |
2381 | RETVAL |
2189 | |
2382 | |
2190 | void |
2383 | void |
2191 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2384 | set_rect (DC::Map self, int x0, int y0, SV *data_sv) |
2192 | PPCODE: |
2385 | PPCODE: |
2193 | { |
2386 | { |
2194 | int x, y, z; |
2387 | int x, y, z; |
2195 | int w, h; |
2388 | int w, h; |
2196 | int x1, y1; |
2389 | int x1, y1; |
|
|
2390 | STRLEN len; |
|
|
2391 | uint8_t *data, *end; |
|
|
2392 | |
|
|
2393 | len = SvLEN (data_sv); |
|
|
2394 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
|
|
2395 | data = SvPVbyte_nolen (data_sv); |
|
|
2396 | end = data + len + 8; |
|
|
2397 | |
|
|
2398 | if (len < 5) |
|
|
2399 | XSRETURN_EMPTY; |
2197 | |
2400 | |
2198 | if (*data++ != 0) |
2401 | if (*data++ != 0) |
2199 | return; /* version mismatch */ |
2402 | XSRETURN_EMPTY; /* version mismatch */ |
2200 | |
2403 | |
2201 | w = *data++ << 8; w |= *data++; |
2404 | w = *data++ << 8; w |= *data++; |
2202 | h = *data++ << 8; h |= *data++; |
2405 | h = *data++ << 8; h |= *data++; |
2203 | |
2406 | |
2204 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2407 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2216 | { |
2419 | { |
2217 | maprow *row = map_get_row (self, y); |
2420 | maprow *row = map_get_row (self, y); |
2218 | |
2421 | |
2219 | for (x = x0; x < x1; x++) |
2422 | for (x = x0; x < x1; x++) |
2220 | { |
2423 | { |
|
|
2424 | uint8_t flags; |
|
|
2425 | |
|
|
2426 | if (data + 7 >= end) |
|
|
2427 | XSRETURN_EMPTY; |
|
|
2428 | |
2221 | uint8_t flags = *data++; |
2429 | flags = *data++; |
2222 | |
2430 | |
2223 | if (flags) |
2431 | if (flags) |
2224 | { |
2432 | { |
2225 | mapcell *cell = row_get_cell (row, x); |
2433 | mapcell *cell = row_get_cell (row, x); |
2226 | tileid tile[3] = { 0, 0, 0 }; |
2434 | tileid tile[3] = { 0, 0, 0 }; |
… | |
… | |
2229 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2437 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2230 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2438 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2231 | |
2439 | |
2232 | if (cell->darkness == 0) |
2440 | if (cell->darkness == 0) |
2233 | { |
2441 | { |
2234 | cell->darkness = 0; |
2442 | /*cell->darkness = 0;*/ |
|
|
2443 | EXTEND (SP, 3); |
2235 | |
2444 | |
2236 | for (z = 0; z <= 2; z++) |
2445 | for (z = 0; z <= 2; z++) |
2237 | { |
2446 | { |
2238 | tileid t = tile [z]; |
2447 | tileid t = tile [z]; |
2239 | |
2448 | |
2240 | if (t >= self->texs || (t && !self->tex [t].name)) |
2449 | if (t >= self->texs || (t && !self->tex [t].name)) |
2241 | { |
2450 | { |
2242 | XPUSHs (sv_2mortal (newSViv (t))); |
2451 | PUSHs (sv_2mortal (newSViv (t))); |
2243 | need_texid (self, t); |
2452 | need_texid (self, t); |
2244 | } |
2453 | } |
2245 | |
2454 | |
2246 | cell->tile [z] = t; |
2455 | cell->tile [z] = t; |
2247 | } |
2456 | } |
… | |
… | |
2249 | } |
2458 | } |
2250 | } |
2459 | } |
2251 | } |
2460 | } |
2252 | } |
2461 | } |
2253 | |
2462 | |
2254 | MODULE = CFPlus PACKAGE = CFPlus::RW |
2463 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2255 | |
2464 | |
2256 | CFPlus::RW |
2465 | DC::RW |
2257 | new (SV *class, SV *data_sv) |
2466 | new (SV *class, SV *data_sv) |
2258 | CODE: |
2467 | CODE: |
2259 | { |
2468 | { |
2260 | STRLEN datalen; |
2469 | STRLEN datalen; |
2261 | char *data = SvPVbyte (data_sv, datalen); |
2470 | char *data = SvPVbyte (data_sv, datalen); |
… | |
… | |
2263 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2472 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2264 | } |
2473 | } |
2265 | OUTPUT: |
2474 | OUTPUT: |
2266 | RETVAL |
2475 | RETVAL |
2267 | |
2476 | |
2268 | CFPlus::RW |
2477 | DC::RW |
2269 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2478 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2270 | CODE: |
2479 | CODE: |
2271 | RETVAL = SDL_RWFromFile (path, mode); |
2480 | RETVAL = SDL_RWFromFile (path, mode); |
2272 | OUTPUT: |
2481 | OUTPUT: |
2273 | RETVAL |
2482 | RETVAL |
2274 | |
2483 | |
2275 | # fails on win32: |
2484 | # fails on win32: |
2276 | # CFPlus.xs(2268) : error C2059: syntax error : '(' |
2485 | # dc.xs(2268) : error C2059: syntax error : '(' |
2277 | #void |
2486 | #void |
2278 | #close (CFPlus::RW self) |
2487 | #close (DC::RW self) |
2279 | # CODE: |
2488 | # CODE: |
2280 | # (self->(close)) (self); |
2489 | # (self->(close)) (self); |
2281 | |
2490 | |
2282 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2491 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
2283 | |
2492 | |
2284 | PROTOTYPES: DISABLE |
2493 | PROTOTYPES: DISABLE |
2285 | |
2494 | |
2286 | CFPlus::Channel |
2495 | DC::Channel |
2287 | find () |
2496 | find () |
2288 | CODE: |
2497 | CODE: |
2289 | { |
2498 | { |
2290 | RETVAL = Mix_GroupAvailable (-1); |
2499 | RETVAL = Mix_GroupAvailable (-1); |
2291 | |
2500 | |
… | |
… | |
2304 | } |
2513 | } |
2305 | OUTPUT: |
2514 | OUTPUT: |
2306 | RETVAL |
2515 | RETVAL |
2307 | |
2516 | |
2308 | void |
2517 | void |
2309 | halt (CFPlus::Channel self) |
2518 | halt (DC::Channel self) |
2310 | CODE: |
2519 | CODE: |
2311 | Mix_HaltChannel (self); |
2520 | Mix_HaltChannel (self); |
2312 | |
2521 | |
2313 | void |
2522 | void |
2314 | expire (CFPlus::Channel self, int ticks = -1) |
2523 | expire (DC::Channel self, int ticks = -1) |
2315 | CODE: |
2524 | CODE: |
2316 | Mix_ExpireChannel (self, ticks); |
2525 | Mix_ExpireChannel (self, ticks); |
2317 | |
2526 | |
2318 | void |
2527 | void |
2319 | fade_out (CFPlus::Channel self, int ticks = -1) |
2528 | fade_out (DC::Channel self, int ticks = -1) |
2320 | CODE: |
2529 | CODE: |
2321 | Mix_FadeOutChannel (self, ticks); |
2530 | Mix_FadeOutChannel (self, ticks); |
2322 | |
2531 | |
2323 | int |
2532 | int |
2324 | volume (CFPlus::Channel self, int volume) |
2533 | volume (DC::Channel self, int volume) |
2325 | CODE: |
2534 | CODE: |
2326 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2535 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2327 | OUTPUT: |
2536 | OUTPUT: |
2328 | RETVAL |
2537 | RETVAL |
2329 | |
2538 | |
2330 | void |
2539 | void |
2331 | unregister_all_effects (CFPlus::Channel self) |
2540 | unregister_all_effects (DC::Channel self) |
2332 | CODE: |
2541 | CODE: |
2333 | Mix_UnregisterAllEffects (self); |
2542 | Mix_UnregisterAllEffects (self); |
2334 | |
2543 | |
2335 | void |
2544 | void |
2336 | set_panning (CFPlus::Channel self, int left, int right) |
2545 | set_panning (DC::Channel self, int left, int right) |
2337 | CODE: |
2546 | CODE: |
2338 | left = CLAMP (left , 0, 255); |
2547 | left = CLAMP (left , 0, 255); |
2339 | right = CLAMP (right, 0, 255); |
2548 | right = CLAMP (right, 0, 255); |
2340 | Mix_SetPanning (self, left, right); |
2549 | Mix_SetPanning (self, left, right); |
2341 | |
2550 | |
2342 | void |
2551 | void |
2343 | set_distance (CFPlus::Channel self, int distance) |
2552 | set_distance (DC::Channel self, int distance) |
2344 | CODE: |
2553 | CODE: |
2345 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2554 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2346 | |
2555 | |
2347 | void |
2556 | void |
2348 | set_position (CFPlus::Channel self, int angle, int distance) |
2557 | set_position (DC::Channel self, int angle, int distance) |
2349 | CODE: |
2558 | CODE: |
2350 | |
2559 | |
2351 | void |
2560 | void |
2352 | set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) |
2561 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
2353 | CODE: |
2562 | CODE: |
2354 | { |
2563 | { |
2355 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2564 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2356 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2565 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2357 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2566 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2358 | } |
2567 | } |
2359 | |
2568 | |
2360 | void |
2569 | void |
2361 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2570 | set_reverse_stereo (DC::Channel self, int flip) |
2362 | CODE: |
2571 | CODE: |
2363 | Mix_SetReverseStereo (self, flip); |
2572 | Mix_SetReverseStereo (self, flip); |
2364 | |
2573 | |
2365 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2574 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
2366 | |
2575 | |
2367 | PROTOTYPES: DISABLE |
2576 | PROTOTYPES: DISABLE |
2368 | |
2577 | |
2369 | CFPlus::MixChunk |
2578 | DC::MixChunk |
2370 | new (SV *class, CFPlus::RW rwops) |
2579 | new (SV *class, DC::RW rwops) |
2371 | CODE: |
2580 | CODE: |
2372 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2581 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2373 | OUTPUT: |
2582 | OUTPUT: |
2374 | RETVAL |
2583 | RETVAL |
2375 | |
2584 | |
2376 | void |
2585 | void |
2377 | DESTROY (CFPlus::MixChunk self) |
2586 | DESTROY (DC::MixChunk self) |
2378 | CODE: |
2587 | CODE: |
2379 | Mix_FreeChunk (self); |
2588 | Mix_FreeChunk (self); |
2380 | |
2589 | |
2381 | int |
2590 | int |
2382 | volume (CFPlus::MixChunk self, int volume = -1) |
2591 | volume (DC::MixChunk self, int volume = -1) |
2383 | CODE: |
2592 | CODE: |
2384 | if (items > 1) |
2593 | if (items > 1) |
2385 | volume = CLAMP (volume, 0, 128); |
2594 | volume = CLAMP (volume, 0, 128); |
2386 | RETVAL = Mix_VolumeChunk (self, volume); |
2595 | RETVAL = Mix_VolumeChunk (self, volume); |
2387 | OUTPUT: |
2596 | OUTPUT: |
2388 | RETVAL |
2597 | RETVAL |
2389 | |
2598 | |
2390 | CFPlus::Channel |
2599 | DC::Channel |
2391 | play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) |
2600 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2392 | CODE: |
2601 | CODE: |
2393 | { |
2602 | { |
2394 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2603 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2395 | |
2604 | |
2396 | if (RETVAL < 0) |
2605 | if (RETVAL < 0) |
… | |
… | |
2403 | } |
2612 | } |
2404 | } |
2613 | } |
2405 | OUTPUT: |
2614 | OUTPUT: |
2406 | RETVAL |
2615 | RETVAL |
2407 | |
2616 | |
2408 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2617 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
2409 | |
2618 | |
2410 | int |
2619 | int |
2411 | volume (int volume = -1) |
2620 | volume (int volume = -1) |
2412 | PROTOTYPE: ;$ |
2621 | PROTOTYPE: ;$ |
2413 | CODE: |
2622 | CODE: |
… | |
… | |
2425 | void |
2634 | void |
2426 | halt () |
2635 | halt () |
2427 | CODE: |
2636 | CODE: |
2428 | Mix_HaltMusic (); |
2637 | Mix_HaltMusic (); |
2429 | |
2638 | |
2430 | CFPlus::MixMusic |
2639 | DC::MixMusic |
2431 | new (SV *class, CFPlus::RW rwops) |
2640 | new (SV *class, DC::RW rwops) |
2432 | CODE: |
2641 | CODE: |
2433 | RETVAL = Mix_LoadMUS_RW (rwops); |
2642 | RETVAL = Mix_LoadMUS_RW (rwops); |
2434 | OUTPUT: |
2643 | OUTPUT: |
2435 | RETVAL |
2644 | RETVAL |
2436 | |
2645 | |
2437 | void |
2646 | void |
2438 | DESTROY (CFPlus::MixMusic self) |
2647 | DESTROY (DC::MixMusic self) |
2439 | CODE: |
2648 | CODE: |
2440 | Mix_FreeMusic (self); |
2649 | Mix_FreeMusic (self); |
2441 | |
2650 | |
2442 | int |
2651 | int |
2443 | play (CFPlus::MixMusic self, int loops = -1) |
2652 | play (DC::MixMusic self, int loops = -1) |
2444 | CODE: |
2653 | CODE: |
2445 | RETVAL = Mix_PlayMusic (self, loops); |
2654 | RETVAL = Mix_PlayMusic (self, loops); |
2446 | OUTPUT: |
2655 | OUTPUT: |
2447 | RETVAL |
2656 | RETVAL |
2448 | |
2657 | |
2449 | void |
2658 | void |
2450 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
2659 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2451 | CODE: |
2660 | CODE: |
2452 | Mix_FadeInMusicPos (self, loops, ms, position); |
2661 | Mix_FadeInMusicPos (self, loops, ms, position); |
2453 | |
2662 | |
2454 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
2663 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2455 | |
2664 | |
2456 | PROTOTYPES: ENABLE |
2665 | PROTOTYPES: ENABLE |
2457 | |
2666 | |
2458 | BOOT: |
2667 | BOOT: |
2459 | { |
2668 | { |
2460 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
2669 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2461 | static const struct { |
2670 | static const struct { |
2462 | const char *name; |
2671 | const char *name; |
2463 | IV iv; |
2672 | IV iv; |
2464 | } *civ, const_iv[] = { |
2673 | } *civ, const_iv[] = { |
2465 | # define const_iv(name) { # name, (IV)name } |
2674 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
2500 | const_iv (GL_INTENSITY), |
2709 | const_iv (GL_INTENSITY), |
2501 | const_iv (GL_LUMINANCE), |
2710 | const_iv (GL_LUMINANCE), |
2502 | const_iv (GL_LUMINANCE_ALPHA), |
2711 | const_iv (GL_LUMINANCE_ALPHA), |
2503 | const_iv (GL_FLOAT), |
2712 | const_iv (GL_FLOAT), |
2504 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
2713 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
2714 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
2715 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
2716 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
2717 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
2718 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
2719 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2505 | const_iv (GL_COMPILE), |
2720 | const_iv (GL_COMPILE), |
2506 | const_iv (GL_PROXY_TEXTURE_1D), |
2721 | const_iv (GL_PROXY_TEXTURE_1D), |
2507 | const_iv (GL_PROXY_TEXTURE_2D), |
2722 | const_iv (GL_PROXY_TEXTURE_2D), |
2508 | const_iv (GL_TEXTURE_1D), |
2723 | const_iv (GL_TEXTURE_1D), |
2509 | const_iv (GL_TEXTURE_2D), |
2724 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2548 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2763 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2549 | const_iv (GL_POINT_SMOOTH_HINT), |
2764 | const_iv (GL_POINT_SMOOTH_HINT), |
2550 | const_iv (GL_LINE_SMOOTH_HINT), |
2765 | const_iv (GL_LINE_SMOOTH_HINT), |
2551 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2766 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2552 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2767 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2768 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2553 | const_iv (GL_FASTEST), |
2769 | const_iv (GL_FASTEST), |
2554 | const_iv (GL_DONT_CARE), |
2770 | const_iv (GL_DONT_CARE), |
2555 | const_iv (GL_NICEST), |
2771 | const_iv (GL_NICEST), |
2556 | const_iv (GL_V2F), |
2772 | const_iv (GL_V2F), |
2557 | const_iv (GL_V3F), |
2773 | const_iv (GL_V3F), |
… | |
… | |
2565 | |
2781 | |
2566 | texture_av = newAV (); |
2782 | texture_av = newAV (); |
2567 | AvREAL_off (texture_av); |
2783 | AvREAL_off (texture_av); |
2568 | } |
2784 | } |
2569 | |
2785 | |
|
|
2786 | void |
|
|
2787 | disable_GL_EXT_blend_func_separate () |
|
|
2788 | CODE: |
|
|
2789 | gl.BlendFuncSeparate = 0; |
|
|
2790 | gl.BlendFuncSeparateEXT = 0; |
|
|
2791 | |
2570 | char * |
2792 | char * |
2571 | gl_vendor () |
2793 | gl_vendor () |
2572 | CODE: |
2794 | CODE: |
2573 | RETVAL = (char *)glGetString (GL_VENDOR); |
2795 | RETVAL = (char *)glGetString (GL_VENDOR); |
2574 | OUTPUT: |
2796 | OUTPUT: |
… | |
… | |
2695 | |
2917 | |
2696 | void glRect (float x1, float y1, float x2, float y2) |
2918 | void glRect (float x1, float y1, float x2, float y2) |
2697 | CODE: |
2919 | CODE: |
2698 | glRectf (x1, y1, x2, y2); |
2920 | glRectf (x1, y1, x2, y2); |
2699 | |
2921 | |
|
|
2922 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
2923 | CODE: |
|
|
2924 | glBegin (GL_LINE_LOOP); |
|
|
2925 | glVertex2f (x1, y1); |
|
|
2926 | glVertex2f (x2, y1); |
|
|
2927 | glVertex2f (x2, y2); |
|
|
2928 | glVertex2f (x1, y2); |
|
|
2929 | glEnd (); |
|
|
2930 | |
2700 | PROTOTYPES: ENABLE |
2931 | PROTOTYPES: ENABLE |
2701 | |
2932 | |
2702 | void glBegin (int mode) |
2933 | void glBegin (int mode) |
2703 | |
2934 | |
2704 | void glEnd () |
2935 | void glEnd () |
… | |
… | |
2736 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2967 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2737 | CODE: |
2968 | CODE: |
2738 | if (gl.SeparableFilter2D) |
2969 | if (gl.SeparableFilter2D) |
2739 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2970 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2740 | |
2971 | |
2741 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
2972 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2742 | |
2973 | |
2743 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2974 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2744 | |
2975 | |
2745 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2976 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2746 | |
2977 | |
… | |
… | |
2772 | |
3003 | |
2773 | void glEndList () |
3004 | void glEndList () |
2774 | |
3005 | |
2775 | void glCallList (int list) |
3006 | void glCallList (int list) |
2776 | |
3007 | |
2777 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
3008 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2778 | |
3009 | |
2779 | PROTOTYPES: DISABLE |
3010 | PROTOTYPES: DISABLE |
2780 | |
3011 | |
2781 | void |
3012 | void |
2782 | find_widget (SV *self, NV x, NV y) |
3013 | find_widget (SV *self, NV x, NV y) |
… | |
… | |
2786 | XPUSHs (self); |
3017 | XPUSHs (self); |
2787 | } |
3018 | } |
2788 | |
3019 | |
2789 | BOOT: |
3020 | BOOT: |
2790 | { |
3021 | { |
2791 | hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); |
3022 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
2792 | |
3023 | |
2793 | draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); |
3024 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
2794 | draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); |
3025 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
2795 | draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); |
3026 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
2796 | draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); |
3027 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
2797 | } |
3028 | } |
2798 | |
3029 | |
2799 | void |
3030 | void |
2800 | draw (SV *self) |
3031 | draw (SV *self) |
2801 | CODE: |
3032 | CODE: |
… | |
… | |
2805 | NV x, y, w, h; |
3036 | NV x, y, w, h; |
2806 | SV *draw_x_sv = GvSV (draw_x_gv); |
3037 | SV *draw_x_sv = GvSV (draw_x_gv); |
2807 | SV *draw_y_sv = GvSV (draw_y_gv); |
3038 | SV *draw_y_sv = GvSV (draw_y_gv); |
2808 | SV *draw_w_sv = GvSV (draw_w_gv); |
3039 | SV *draw_w_sv = GvSV (draw_w_gv); |
2809 | SV *draw_h_sv = GvSV (draw_h_gv); |
3040 | SV *draw_h_sv = GvSV (draw_h_gv); |
2810 | SV *hover; |
|
|
2811 | double draw_x, draw_y, draw_w, draw_h; |
3041 | double draw_x, draw_y; |
2812 | |
3042 | |
2813 | if (!SvROK (self)) |
3043 | if (!SvROK (self)) |
2814 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
3044 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
2815 | |
3045 | |
2816 | hv = (HV *)SvRV (self); |
3046 | hv = (HV *)SvRV (self); |
2817 | |
3047 | |
2818 | if (SvTYPE (hv) != SVt_PVHV) |
3048 | if (SvTYPE (hv) != SVt_PVHV) |
2819 | croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); |
3049 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2820 | |
3050 | |
2821 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
3051 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2822 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
3052 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2823 | |
3053 | |
2824 | if (!h || !w) |
3054 | if (!h || !w) |
… | |
… | |
2844 | { |
3074 | { |
2845 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
3075 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2846 | |
3076 | |
2847 | if (svp && SvTRUE (*svp)) |
3077 | if (svp && SvTRUE (*svp)) |
2848 | { |
3078 | { |
2849 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
3079 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2850 | glEnable (GL_BLEND); |
3080 | glEnable (GL_BLEND); |
2851 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
3081 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2852 | glBegin (GL_QUADS); |
3082 | glBegin (GL_QUADS); |
2853 | glVertex2f (0, 0); |
3083 | glVertex2f (0, 0); |
2854 | glVertex2f (w, 0); |
3084 | glVertex2f (w, 0); |
… | |
… | |
2857 | glEnd (); |
3087 | glEnd (); |
2858 | glDisable (GL_BLEND); |
3088 | glDisable (GL_BLEND); |
2859 | } |
3089 | } |
2860 | } |
3090 | } |
2861 | #if 0 |
3091 | #if 0 |
2862 | if ($ENV{CFPLUS_DEBUG} & 1) { |
3092 | // draw borders, for debugging |
2863 | glPushMatrix; |
3093 | glPushMatrix (); |
2864 | glColor 1, 1, 0, 1; |
3094 | glColor4f (1., 1., 0., 1.); |
2865 | glTranslate 0.375, 0.375; |
3095 | glTranslatef (.5, .5, 0.); |
2866 | glBegin GL_LINE_LOOP; |
3096 | glBegin (GL_LINE_LOOP); |
2867 | glVertex 0 , 0; |
3097 | glVertex2f (0 , 0); |
2868 | glVertex $self->{w} - 1, 0; |
3098 | glVertex2f (w - 1, 0); |
2869 | glVertex $self->{w} - 1, $self->{h} - 1; |
3099 | glVertex2f (w - 1, h - 1); |
2870 | glVertex 0 , $self->{h} - 1; |
3100 | glVertex2f (0 , h - 1); |
2871 | glEnd; |
3101 | glEnd (); |
2872 | glPopMatrix; |
3102 | glPopMatrix (); |
2873 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2874 | } |
|
|
2875 | #endif |
3103 | #endif |
2876 | PUSHMARK (SP); |
3104 | PUSHMARK (SP); |
2877 | XPUSHs (self); |
3105 | XPUSHs (self); |
2878 | PUTBACK; |
3106 | PUTBACK; |
2879 | call_method ("_draw", G_VOID | G_DISCARD); |
3107 | call_method ("_draw", G_VOID | G_DISCARD); |