… | |
… | |
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> |
27 | #include <stdio.h> |
32 | #include <stdio.h> |
28 | #include <stdlib.h> |
33 | #include <stdlib.h> |
|
|
34 | |
|
|
35 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
29 | |
36 | |
30 | #include <SDL.h> |
37 | #include <SDL.h> |
31 | #include <SDL_thread.h> |
38 | #include <SDL_thread.h> |
32 | #include <SDL_endian.h> |
39 | #include <SDL_endian.h> |
33 | #include <SDL_image.h> |
40 | #include <SDL_image.h> |
… | |
… | |
38 | #define G_DISABLE_CAST_CHECKS |
45 | #define G_DISABLE_CAST_CHECKS |
39 | |
46 | |
40 | #include <glib/gmacros.h> |
47 | #include <glib/gmacros.h> |
41 | |
48 | |
42 | #include <pango/pango.h> |
49 | #include <pango/pango.h> |
|
|
50 | |
|
|
51 | #if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 15, 2)) |
|
|
52 | # define pango_layout_get_line_readonly pango_layout_get_line_readonly |
|
|
53 | # define pango_layout_get_lines_readonly pango_layout_get_lines_readonly |
|
|
54 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line_readonly |
|
|
55 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run_readonly |
|
|
56 | #endif |
43 | |
57 | |
44 | #ifndef _WIN32 |
58 | #ifndef _WIN32 |
45 | # include <sys/types.h> |
59 | # include <sys/types.h> |
46 | # include <sys/socket.h> |
60 | # include <sys/socket.h> |
47 | # include <netinet/in.h> |
61 | # include <netinet/in.h> |
… | |
… | |
107 | av_push (texture_av, (SV *)(size_t)name); |
121 | av_push (texture_av, (SV *)(size_t)name); |
108 | glDeleteTextures (1, &name); |
122 | glDeleteTextures (1, &name); |
109 | } |
123 | } |
110 | |
124 | |
111 | #include "texcache.c" |
125 | #include "texcache.c" |
|
|
126 | #include "rendercache.c" |
112 | |
127 | |
113 | #include "pango-font.c" |
128 | #include "pango-font.c" |
114 | #include "pango-fontmap.c" |
129 | #include "pango-fontmap.c" |
115 | #include "pango-render.c" |
130 | #include "pango-render.c" |
116 | |
131 | |
|
|
132 | typedef IV DC__Channel; |
|
|
133 | typedef SDL_RWops *DC__RW; |
117 | typedef Mix_Chunk *CFPlus__MixChunk; |
134 | typedef Mix_Chunk *DC__MixChunk; |
118 | typedef Mix_Music *CFPlus__MixMusic; |
135 | typedef Mix_Music *DC__MixMusic; |
119 | |
136 | |
120 | typedef PangoFontDescription *CFPlus__Font; |
137 | typedef PangoFontDescription *DC__Font; |
121 | |
138 | |
122 | static int |
139 | static int |
123 | shape_attr_p (PangoLayoutRun *run) |
140 | shape_attr_p (PangoLayoutRun *run) |
124 | { |
141 | { |
125 | GSList *attrs = run->item->analysis.extra_attrs; |
142 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
139 | |
156 | |
140 | typedef struct cf_layout { |
157 | typedef struct cf_layout { |
141 | PangoLayout *pl; |
158 | PangoLayout *pl; |
142 | float r, g, b, a; // default color for rgba mode |
159 | float r, g, b, a; // default color for rgba mode |
143 | int base_height; |
160 | int base_height; |
144 | CFPlus__Font font; |
161 | DC__Font font; |
|
|
162 | rc_t *rc; |
145 | } *CFPlus__Layout; |
163 | } *DC__Layout; |
146 | |
164 | |
147 | static CFPlus__Font default_font; |
165 | static DC__Font default_font; |
148 | static PangoContext *opengl_context; |
166 | static PangoContext *opengl_context; |
149 | static PangoFontMap *opengl_fontmap; |
167 | static PangoFontMap *opengl_fontmap; |
150 | |
168 | |
151 | static void |
169 | static void |
152 | substitute_func (FcPattern *pattern, gpointer data) |
170 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
157 | #endif |
175 | #endif |
158 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
176 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
159 | } |
177 | } |
160 | |
178 | |
161 | static void |
179 | static void |
162 | layout_update_font (CFPlus__Layout self) |
180 | layout_update_font (DC__Layout self) |
163 | { |
181 | { |
164 | /* use a random scale factor to account for unknown descenders, 0.8 works |
182 | /* use a random scale factor to account for unknown descenders, 0.8 works |
165 | * reasonably well with bitstream vera |
183 | * reasonably well with bitstream vera |
166 | */ |
184 | */ |
167 | PangoFontDescription *font = self->font ? self->font : default_font; |
185 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
171 | |
189 | |
172 | pango_layout_set_font_description (self->pl, font); |
190 | pango_layout_set_font_description (self->pl, font); |
173 | } |
191 | } |
174 | |
192 | |
175 | static void |
193 | static void |
176 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
194 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
177 | { |
195 | { |
178 | PangoRectangle rect; |
196 | PangoRectangle rect; |
179 | |
197 | |
180 | // get_pixel_* wrongly rounds down |
198 | // get_pixel_* wrongly rounds down |
181 | pango_layout_get_extents (self->pl, 0, &rect); |
199 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
192 | |
210 | |
193 | typedef uint16_t tileid; |
211 | typedef uint16_t tileid; |
194 | typedef uint16_t faceid; |
212 | typedef uint16_t faceid; |
195 | |
213 | |
196 | typedef struct { |
214 | typedef struct { |
197 | int name; |
215 | GLuint name; |
198 | int w, h; |
216 | int w, h; |
199 | float s, t; |
217 | float s, t; |
200 | uint8_t r, g, b, a; |
218 | uint8_t r, g, b, a; |
201 | tileid smoothtile; |
219 | tileid smoothtile; |
202 | uint8_t smoothlevel; |
220 | uint8_t smoothlevel; |
… | |
… | |
220 | int faces; tileid *face2tile; // [faceid] |
238 | int faces; tileid *face2tile; // [faceid] |
221 | int texs; maptex *tex; // [tileid] |
239 | int texs; maptex *tex; // [tileid] |
222 | |
240 | |
223 | int32_t rows; |
241 | int32_t rows; |
224 | maprow *row; |
242 | maprow *row; |
225 | } *CFPlus__Map; |
243 | } *DC__Map; |
226 | |
244 | |
227 | static char * |
245 | static char * |
228 | prepend (char *ptr, int sze, int inc) |
246 | prepend (char *ptr, int sze, int inc) |
229 | { |
247 | { |
230 | char *p; |
248 | char *p; |
… | |
… | |
268 | self->texs *= 2; |
286 | self->texs *= 2; |
269 | } |
287 | } |
270 | } |
288 | } |
271 | |
289 | |
272 | static maprow * |
290 | static maprow * |
273 | map_get_row (CFPlus__Map self, int y) |
291 | map_get_row (DC__Map self, int y) |
274 | { |
292 | { |
275 | if (0 > y) |
293 | if (0 > y) |
276 | { |
294 | { |
277 | int extend = - y + MAP_EXTEND_Y; |
295 | int extend = - y + MAP_EXTEND_Y; |
278 | Prepend (maprow, self->row, self->rows, extend); |
296 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
316 | |
334 | |
317 | return row->col + (x - row->c0); |
335 | return row->col + (x - row->c0); |
318 | } |
336 | } |
319 | |
337 | |
320 | static mapcell * |
338 | static mapcell * |
321 | map_get_cell (CFPlus__Map self, int x, int y) |
339 | map_get_cell (DC__Map self, int x, int y) |
322 | { |
340 | { |
323 | return row_get_cell (map_get_row (self, y), x); |
341 | return row_get_cell (map_get_row (self, y), x); |
324 | } |
342 | } |
325 | |
343 | |
326 | static void |
344 | static void |
327 | map_clear (CFPlus__Map self) |
345 | map_clear (DC__Map self) |
328 | { |
346 | { |
329 | int r; |
347 | int r; |
330 | |
348 | |
331 | for (r = 0; r < self->rows; r++) |
349 | for (r = 0; r < self->rows; r++) |
332 | Safefree (self->row[r].col); |
350 | Safefree (self->row[r].col); |
… | |
… | |
340 | self->row = 0; |
358 | self->row = 0; |
341 | self->rows = 0; |
359 | self->rows = 0; |
342 | } |
360 | } |
343 | |
361 | |
344 | static void |
362 | static void |
345 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
363 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
346 | { |
364 | { |
347 | int x, y; |
365 | int x, y; |
348 | maprow *row; |
366 | maprow *row; |
349 | mapcell *cell; |
367 | mapcell *cell; |
350 | |
368 | |
… | |
… | |
429 | n |= n >> 16; |
447 | n |= n >> 16; |
430 | |
448 | |
431 | return n + 1; |
449 | return n + 1; |
432 | } |
450 | } |
433 | |
451 | |
|
|
452 | static unsigned int |
|
|
453 | popcount (unsigned int n) |
|
|
454 | { |
|
|
455 | n -= (n >> 1) & 0x55555555U; |
|
|
456 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
457 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
458 | n *= 0x01010101U; |
|
|
459 | |
|
|
460 | return n >> 24; |
|
|
461 | } |
|
|
462 | |
434 | /* SDL should provide this, really. */ |
463 | /* SDL should provide this, really. */ |
435 | #define SDLK_MODIFIER_MIN 300 |
464 | #define SDLK_MODIFIER_MIN 300 |
436 | #define SDLK_MODIFIER_MAX 314 |
465 | #define SDLK_MODIFIER_MAX 314 |
437 | |
466 | |
438 | /******************************************************************************/ |
467 | /******************************************************************************/ |
439 | |
468 | |
|
|
469 | static GV *draw_x_gv, *draw_y_gv, *draw_w_gv, *draw_h_gv; |
|
|
470 | static GV *hover_gv; |
|
|
471 | |
440 | static int |
472 | static int |
441 | within_widget (SV *widget, NV x, NV y) |
473 | within_widget (SV *widget, NV x, NV y) |
442 | { |
474 | { |
443 | HV *self; |
475 | HV *self; |
444 | SV **svp; |
476 | SV **svp; |
… | |
… | |
473 | return 0; |
505 | return 0; |
474 | |
506 | |
475 | return 1; |
507 | return 1; |
476 | } |
508 | } |
477 | |
509 | |
478 | MODULE = CFPlus PACKAGE = CFPlus |
510 | MODULE = Deliantra::Client PACKAGE = DC |
479 | |
511 | |
480 | PROTOTYPES: ENABLE |
512 | PROTOTYPES: ENABLE |
481 | |
513 | |
482 | BOOT: |
514 | BOOT: |
483 | { |
515 | { |
484 | HV *stash = gv_stashpv ("CFPlus", 1); |
516 | HV *stash = gv_stashpv ("DC", 1); |
485 | static const struct { |
517 | static const struct { |
486 | const char *name; |
518 | const char *name; |
487 | IV iv; |
519 | IV iv; |
488 | } *civ, const_iv[] = { |
520 | } *civ, const_iv[] = { |
489 | # define const_iv(name) { # name, (IV)name } |
521 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
511 | |
543 | |
512 | const_iv (SDL_APPINPUTFOCUS), |
544 | const_iv (SDL_APPINPUTFOCUS), |
513 | const_iv (SDL_APPMOUSEFOCUS), |
545 | const_iv (SDL_APPMOUSEFOCUS), |
514 | const_iv (SDL_APPACTIVE), |
546 | const_iv (SDL_APPACTIVE), |
515 | |
547 | |
|
|
548 | const_iv (SDLK_FIRST), |
|
|
549 | const_iv (SDLK_LAST), |
516 | const_iv (SDLK_KP0), |
550 | const_iv (SDLK_KP0), |
517 | const_iv (SDLK_KP1), |
551 | const_iv (SDLK_KP1), |
518 | const_iv (SDLK_KP2), |
552 | const_iv (SDLK_KP2), |
519 | const_iv (SDLK_KP3), |
553 | const_iv (SDLK_KP3), |
520 | const_iv (SDLK_KP4), |
554 | const_iv (SDLK_KP4), |
… | |
… | |
592 | const_iv (KMOD_LMETA), |
626 | const_iv (KMOD_LMETA), |
593 | const_iv (KMOD_RMETA), |
627 | const_iv (KMOD_RMETA), |
594 | const_iv (KMOD_NUM), |
628 | const_iv (KMOD_NUM), |
595 | const_iv (KMOD_CAPS), |
629 | const_iv (KMOD_CAPS), |
596 | const_iv (KMOD_MODE), |
630 | const_iv (KMOD_MODE), |
|
|
631 | |
|
|
632 | const_iv (MIX_DEFAULT_FORMAT), |
597 | # undef const_iv |
633 | # undef const_iv |
598 | }; |
634 | }; |
599 | |
635 | |
600 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
636 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
601 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
637 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
619 | |
655 | |
620 | NV floor (NV x) |
656 | NV floor (NV x) |
621 | |
657 | |
622 | NV ceil (NV x) |
658 | NV ceil (NV x) |
623 | |
659 | |
|
|
660 | IV minpot (UV n) |
|
|
661 | |
|
|
662 | IV popcount (UV n) |
|
|
663 | |
624 | void |
664 | void |
625 | pango_init () |
665 | pango_init () |
626 | CODE: |
666 | CODE: |
627 | { |
667 | { |
628 | opengl_fontmap = pango_opengl_font_map_new (); |
668 | opengl_fontmap = pango_opengl_font_map_new (); |
629 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
669 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
630 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
670 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
671 | #if defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 15, 2) |
|
|
672 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
673 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
674 | #endif |
631 | } |
675 | } |
632 | |
676 | |
633 | char * |
677 | char * |
634 | SDL_GetError () |
678 | SDL_GetError () |
635 | |
679 | |
… | |
… | |
667 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
711 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
668 | |
712 | |
669 | if (m && m != (SDL_Rect **)-1) |
713 | if (m && m != (SDL_Rect **)-1) |
670 | while (*m) |
714 | while (*m) |
671 | { |
715 | { |
672 | if ((*m)->w >= 640 && (*m)->h >= 480) |
716 | if ((*m)->w >= 800 && (*m)->h >= 480) |
673 | { |
717 | { |
674 | AV *av = newAV (); |
718 | AV *av = newAV (); |
675 | av_push (av, newSViv ((*m)->w)); |
719 | av_push (av, newSViv ((*m)->w)); |
676 | av_push (av, newSViv ((*m)->h)); |
720 | av_push (av, newSViv ((*m)->h)); |
677 | av_push (av, newSViv (rgb)); |
721 | av_push (av, newSViv (rgb)); |
… | |
… | |
701 | |
745 | |
702 | if (RETVAL) |
746 | if (RETVAL) |
703 | { |
747 | { |
704 | av_clear (texture_av); |
748 | av_clear (texture_av); |
705 | |
749 | |
706 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
750 | SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); |
707 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
751 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
708 | #include "glfunc.h" |
752 | #include "glfunc.h" |
709 | #undef GL_FUNC |
753 | #undef GL_FUNC |
710 | } |
754 | } |
711 | } |
755 | } |
… | |
… | |
792 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
836 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
793 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
837 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
794 | break; |
838 | break; |
795 | } |
839 | } |
796 | |
840 | |
797 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
841 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
798 | } |
842 | } |
799 | } |
843 | } |
800 | |
844 | |
801 | int |
845 | int |
802 | Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) |
846 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
803 | POSTCALL: |
847 | POSTCALL: |
804 | Mix_HookMusicFinished (music_finished); |
848 | Mix_HookMusicFinished (music_finished); |
805 | Mix_ChannelFinished (channel_finished); |
849 | Mix_ChannelFinished (channel_finished); |
806 | |
850 | |
807 | void |
851 | void |
|
|
852 | Mix_QuerySpec () |
|
|
853 | PPCODE: |
|
|
854 | { |
|
|
855 | int freq, channels; |
|
|
856 | Uint16 format; |
|
|
857 | |
|
|
858 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
859 | { |
|
|
860 | EXTEND (SP, 3); |
|
|
861 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
862 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
863 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
864 | } |
|
|
865 | } |
|
|
866 | |
|
|
867 | void |
808 | Mix_CloseAudio () |
868 | Mix_CloseAudio () |
809 | |
869 | |
810 | int |
870 | int |
811 | Mix_AllocateChannels (int numchans = -1) |
871 | Mix_AllocateChannels (int numchans = -1) |
|
|
872 | |
|
|
873 | const char * |
|
|
874 | Mix_GetError () |
812 | |
875 | |
813 | void |
876 | void |
814 | lowdelay (int fd, int val = 1) |
877 | lowdelay (int fd, int val = 1) |
815 | CODE: |
878 | CODE: |
816 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
879 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, sizeof (val)); |
… | |
… | |
858 | STRLEN image_len; |
921 | STRLEN image_len; |
859 | char *image = (char *)SvPVbyte (image_, image_len); |
922 | char *image = (char *)SvPVbyte (image_, image_len); |
860 | SDL_Surface *surface, *surface2; |
923 | SDL_Surface *surface, *surface2; |
861 | SDL_PixelFormat fmt; |
924 | SDL_PixelFormat fmt; |
862 | SDL_RWops *rw = ix |
925 | SDL_RWops *rw = ix |
863 | ? SDL_RWFromFile (image, "r") |
926 | ? SDL_RWFromFile (image, "rb") |
864 | : SDL_RWFromConstMem (image, image_len); |
927 | : SDL_RWFromConstMem (image, image_len); |
865 | |
928 | |
866 | if (!rw) |
929 | if (!rw) |
867 | croak ("load_image: %s", SDL_GetError ()); |
930 | croak ("load_image: %s", SDL_GetError ()); |
868 | |
931 | |
… | |
… | |
941 | void |
1004 | void |
942 | error (char *message) |
1005 | error (char *message) |
943 | CODE: |
1006 | CODE: |
944 | fprintf (stderr, "ERROR: %s\n", message); |
1007 | fprintf (stderr, "ERROR: %s\n", message); |
945 | #ifdef _WIN32 |
1008 | #ifdef _WIN32 |
946 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
1009 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
947 | #endif |
1010 | #endif |
948 | |
1011 | |
949 | void |
1012 | void |
950 | fatal (char *message) |
1013 | fatal (char *message) |
951 | CODE: |
1014 | CODE: |
952 | fprintf (stderr, "FATAL: %s\n", message); |
1015 | fprintf (stderr, "FATAL: %s\n", message); |
953 | #ifdef _WIN32 |
1016 | #ifdef _WIN32 |
954 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1017 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
955 | #endif |
1018 | #endif |
956 | _exit (1); |
1019 | _exit (1); |
957 | |
1020 | |
958 | void |
1021 | void |
959 | _exit (int retval = 0) |
1022 | _exit (int retval = 0) |
… | |
… | |
971 | #if DEBUG |
1034 | #if DEBUG |
972 | VALGRIND_DO_LEAK_CHECK; |
1035 | VALGRIND_DO_LEAK_CHECK; |
973 | #endif |
1036 | #endif |
974 | } |
1037 | } |
975 | |
1038 | |
976 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1039 | MODULE = Deliantra::Client PACKAGE = DC::Font |
977 | |
1040 | |
978 | PROTOTYPES: DISABLE |
1041 | PROTOTYPES: DISABLE |
979 | |
1042 | |
980 | CFPlus::Font |
1043 | DC::Font |
981 | new_from_file (SV *class, char *path, int id = 0) |
1044 | new_from_file (SV *class, char *path, int id = 0) |
982 | CODE: |
1045 | CODE: |
983 | { |
1046 | { |
984 | int count; |
1047 | int count; |
985 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1048 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
988 | } |
1051 | } |
989 | OUTPUT: |
1052 | OUTPUT: |
990 | RETVAL |
1053 | RETVAL |
991 | |
1054 | |
992 | void |
1055 | void |
993 | DESTROY (CFPlus::Font self) |
1056 | DESTROY (DC::Font self) |
994 | CODE: |
1057 | CODE: |
995 | pango_font_description_free (self); |
1058 | pango_font_description_free (self); |
996 | |
1059 | |
997 | void |
1060 | void |
998 | make_default (CFPlus::Font self) |
1061 | make_default (DC::Font self) |
999 | PROTOTYPE: $ |
1062 | PROTOTYPE: $ |
1000 | CODE: |
1063 | CODE: |
1001 | default_font = self; |
1064 | default_font = self; |
1002 | |
1065 | |
1003 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1066 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1004 | |
1067 | |
1005 | PROTOTYPES: DISABLE |
1068 | PROTOTYPES: DISABLE |
1006 | |
1069 | |
1007 | void |
1070 | void |
1008 | reset_glyph_cache () |
1071 | glyph_cache_backup () |
1009 | PROTOTYPE: |
1072 | PROTOTYPE: |
1010 | CODE: |
1073 | CODE: |
|
|
1074 | tc_backup (); |
|
|
1075 | |
|
|
1076 | void |
|
|
1077 | glyph_cache_restore () |
|
|
1078 | PROTOTYPE: |
|
|
1079 | CODE: |
1011 | tc_clear (); |
1080 | tc_restore (); |
1012 | |
1081 | |
1013 | CFPlus::Layout |
1082 | DC::Layout |
1014 | new (SV *class) |
1083 | new (SV *class) |
1015 | CODE: |
1084 | CODE: |
1016 | New (0, RETVAL, 1, struct cf_layout); |
1085 | New (0, RETVAL, 1, struct cf_layout); |
1017 | |
1086 | |
1018 | RETVAL->pl = pango_layout_new (opengl_context); |
1087 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
1020 | RETVAL->g = 1.; |
1089 | RETVAL->g = 1.; |
1021 | RETVAL->b = 1.; |
1090 | RETVAL->b = 1.; |
1022 | RETVAL->a = 1.; |
1091 | RETVAL->a = 1.; |
1023 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1092 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1024 | RETVAL->font = 0; |
1093 | RETVAL->font = 0; |
|
|
1094 | RETVAL->rc = rc_alloc (); |
1025 | |
1095 | |
1026 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1096 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1027 | layout_update_font (RETVAL); |
1097 | layout_update_font (RETVAL); |
1028 | OUTPUT: |
1098 | OUTPUT: |
1029 | RETVAL |
1099 | RETVAL |
1030 | |
1100 | |
1031 | void |
1101 | void |
1032 | DESTROY (CFPlus::Layout self) |
1102 | DESTROY (DC::Layout self) |
1033 | CODE: |
1103 | CODE: |
1034 | g_object_unref (self->pl); |
1104 | g_object_unref (self->pl); |
|
|
1105 | rc_free (self->rc); |
1035 | Safefree (self); |
1106 | Safefree (self); |
1036 | |
1107 | |
1037 | void |
1108 | void |
1038 | set_text (CFPlus::Layout self, SV *text_) |
1109 | set_text (DC::Layout self, SV *text_) |
1039 | CODE: |
1110 | CODE: |
1040 | { |
1111 | { |
1041 | STRLEN textlen; |
1112 | STRLEN textlen; |
1042 | char *text = SvPVutf8 (text_, textlen); |
1113 | char *text = SvPVutf8 (text_, textlen); |
1043 | |
1114 | |
1044 | pango_layout_set_text (self->pl, text, textlen); |
1115 | pango_layout_set_text (self->pl, text, textlen); |
1045 | } |
1116 | } |
1046 | |
1117 | |
1047 | void |
1118 | void |
1048 | set_markup (CFPlus::Layout self, SV *text_) |
1119 | set_markup (DC::Layout self, SV *text_) |
1049 | CODE: |
1120 | CODE: |
1050 | { |
1121 | { |
1051 | STRLEN textlen; |
1122 | STRLEN textlen; |
1052 | char *text = SvPVutf8 (text_, textlen); |
1123 | char *text = SvPVutf8 (text_, textlen); |
1053 | |
1124 | |
1054 | pango_layout_set_markup (self->pl, text, textlen); |
1125 | pango_layout_set_markup (self->pl, text, textlen); |
1055 | } |
1126 | } |
1056 | |
1127 | |
1057 | void |
1128 | void |
1058 | set_shapes (CFPlus::Layout self, ...) |
1129 | set_shapes (DC::Layout self, ...) |
1059 | CODE: |
1130 | CODE: |
1060 | { |
1131 | { |
1061 | PangoAttrList *attrs = 0; |
1132 | PangoAttrList *attrs = 0; |
1062 | const char *text = pango_layout_get_text (self->pl); |
1133 | const char *text = pango_layout_get_text (self->pl); |
1063 | const char *pos = text; |
1134 | const char *pos = text; |
… | |
… | |
1098 | if (attrs) |
1169 | if (attrs) |
1099 | pango_layout_set_attributes (self->pl, attrs); |
1170 | pango_layout_set_attributes (self->pl, attrs); |
1100 | } |
1171 | } |
1101 | |
1172 | |
1102 | void |
1173 | void |
1103 | get_shapes (CFPlus::Layout self) |
1174 | get_shapes (DC::Layout self) |
1104 | PPCODE: |
1175 | PPCODE: |
1105 | { |
1176 | { |
1106 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1177 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1107 | |
1178 | |
1108 | do |
1179 | do |
1109 | { |
1180 | { |
1110 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1181 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1111 | |
1182 | |
1112 | if (run && shape_attr_p (run)) |
1183 | if (run && shape_attr_p (run)) |
1113 | { |
1184 | { |
1114 | PangoRectangle extents; |
1185 | PangoRectangle extents; |
1115 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1186 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1123 | |
1194 | |
1124 | pango_layout_iter_free (iter); |
1195 | pango_layout_iter_free (iter); |
1125 | } |
1196 | } |
1126 | |
1197 | |
1127 | int |
1198 | int |
1128 | has_wrapped (CFPlus::Layout self) |
1199 | has_wrapped (DC::Layout self) |
1129 | CODE: |
1200 | CODE: |
1130 | { |
1201 | { |
1131 | int lines = 1; |
1202 | int lines = 1; |
1132 | const char *text = pango_layout_get_text (self->pl); |
1203 | const char *text = pango_layout_get_text (self->pl); |
1133 | |
1204 | |
… | |
… | |
1138 | } |
1209 | } |
1139 | OUTPUT: |
1210 | OUTPUT: |
1140 | RETVAL |
1211 | RETVAL |
1141 | |
1212 | |
1142 | SV * |
1213 | SV * |
1143 | get_text (CFPlus::Layout self) |
1214 | get_text (DC::Layout self) |
1144 | CODE: |
1215 | CODE: |
1145 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1216 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1146 | sv_utf8_decode (RETVAL); |
1217 | sv_utf8_decode (RETVAL); |
1147 | OUTPUT: |
1218 | OUTPUT: |
1148 | RETVAL |
1219 | RETVAL |
1149 | |
1220 | |
1150 | void |
1221 | void |
1151 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1222 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1152 | CODE: |
1223 | CODE: |
1153 | self->r = r; |
1224 | self->r = r; |
1154 | self->g = g; |
1225 | self->g = g; |
1155 | self->b = b; |
1226 | self->b = b; |
1156 | self->a = a; |
1227 | self->a = a; |
1157 | |
1228 | |
1158 | void |
1229 | void |
1159 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1230 | set_font (DC::Layout self, DC::Font font = 0) |
1160 | CODE: |
1231 | CODE: |
1161 | if (self->font != font) |
1232 | if (self->font != font) |
1162 | { |
1233 | { |
1163 | self->font = font; |
1234 | self->font = font; |
1164 | layout_update_font (self); |
1235 | layout_update_font (self); |
1165 | } |
1236 | } |
1166 | |
1237 | |
1167 | void |
1238 | void |
1168 | set_height (CFPlus::Layout self, int base_height) |
1239 | set_height (DC::Layout self, int base_height) |
1169 | CODE: |
1240 | CODE: |
1170 | if (self->base_height != base_height) |
1241 | if (self->base_height != base_height) |
1171 | { |
1242 | { |
1172 | self->base_height = base_height; |
1243 | self->base_height = base_height; |
1173 | layout_update_font (self); |
1244 | layout_update_font (self); |
1174 | } |
1245 | } |
1175 | |
1246 | |
1176 | void |
1247 | void |
1177 | set_width (CFPlus::Layout self, int max_width = -1) |
1248 | set_width (DC::Layout self, int max_width = -1) |
1178 | CODE: |
1249 | CODE: |
1179 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1250 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1180 | |
1251 | |
1181 | void |
1252 | void |
1182 | set_indent (CFPlus::Layout self, int indent) |
1253 | set_indent (DC::Layout self, int indent) |
1183 | CODE: |
1254 | CODE: |
1184 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1255 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1185 | |
1256 | |
1186 | void |
1257 | void |
1187 | set_spacing (CFPlus::Layout self, int spacing) |
1258 | set_spacing (DC::Layout self, int spacing) |
1188 | CODE: |
1259 | CODE: |
1189 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1260 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1190 | |
1261 | |
1191 | void |
1262 | void |
1192 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1263 | set_ellipsise (DC::Layout self, int ellipsise) |
1193 | CODE: |
1264 | CODE: |
1194 | pango_layout_set_ellipsize (self->pl, |
1265 | pango_layout_set_ellipsize (self->pl, |
1195 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1266 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1196 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1267 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1197 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1268 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1198 | : PANGO_ELLIPSIZE_NONE |
1269 | : PANGO_ELLIPSIZE_NONE |
1199 | ); |
1270 | ); |
1200 | |
1271 | |
1201 | void |
1272 | void |
1202 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1273 | set_single_paragraph_mode (DC::Layout self, int spm) |
1203 | CODE: |
1274 | CODE: |
1204 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1275 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1205 | |
1276 | |
1206 | void |
1277 | void |
1207 | size (CFPlus::Layout self) |
1278 | size (DC::Layout self) |
1208 | PPCODE: |
1279 | PPCODE: |
1209 | { |
1280 | { |
1210 | int w, h; |
1281 | int w, h; |
1211 | |
1282 | |
1212 | layout_get_pixel_size (self, &w, &h); |
1283 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1215 | PUSHs (sv_2mortal (newSViv (w))); |
1286 | PUSHs (sv_2mortal (newSViv (w))); |
1216 | PUSHs (sv_2mortal (newSViv (h))); |
1287 | PUSHs (sv_2mortal (newSViv (h))); |
1217 | } |
1288 | } |
1218 | |
1289 | |
1219 | int |
1290 | int |
1220 | descent (CFPlus::Layout self) |
1291 | descent (DC::Layout self) |
1221 | CODE: |
1292 | CODE: |
1222 | { |
1293 | { |
1223 | PangoRectangle rect; |
1294 | PangoRectangle rect; |
1224 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1295 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1225 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1296 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1226 | RETVAL = PANGO_DESCENT (rect); |
1297 | RETVAL = PANGO_DESCENT (rect); |
1227 | } |
1298 | } |
1228 | OUTPUT: |
1299 | OUTPUT: |
1229 | RETVAL |
1300 | RETVAL |
1230 | |
1301 | |
1231 | int |
1302 | int |
1232 | xy_to_index (CFPlus::Layout self, int x, int y) |
1303 | xy_to_index (DC::Layout self, int x, int y) |
1233 | CODE: |
1304 | CODE: |
1234 | { |
1305 | { |
1235 | int index, trailing; |
1306 | int index, trailing; |
1236 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1307 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1237 | RETVAL = index + trailing; |
1308 | RETVAL = index + trailing; |
1238 | } |
1309 | } |
1239 | OUTPUT: |
1310 | OUTPUT: |
1240 | RETVAL |
1311 | RETVAL |
1241 | |
1312 | |
1242 | void |
1313 | void |
1243 | cursor_pos (CFPlus::Layout self, int index) |
1314 | cursor_pos (DC::Layout self, int index) |
1244 | PPCODE: |
1315 | PPCODE: |
1245 | { |
1316 | { |
1246 | PangoRectangle strong_pos; |
1317 | PangoRectangle pos; |
1247 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1318 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1248 | |
1319 | |
1249 | EXTEND (SP, 3); |
1320 | EXTEND (SP, 3); |
1250 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1321 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1251 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1322 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1252 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1323 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1253 | } |
1324 | } |
1254 | |
1325 | |
1255 | void |
1326 | void |
1256 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1327 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1257 | PPCODE: |
1328 | PPCODE: |
1258 | { |
1329 | { |
1259 | int line, x; |
1330 | int line, x; |
1260 | |
1331 | |
1261 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1332 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1333 | #if !(defined (PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK (1, 17, 3)) |
1262 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1334 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1263 | |
1335 | --line; |
|
|
1336 | #endif |
1264 | EXTEND (SP, 2); |
1337 | EXTEND (SP, 2); |
1265 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1338 | PUSHs (sv_2mortal (newSViv (line))); |
1266 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1339 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1267 | } |
1340 | } |
1268 | |
1341 | |
1269 | void |
1342 | void |
1270 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1343 | line_x_to_index (DC::Layout self, int line, int x) |
1271 | PPCODE: |
1344 | PPCODE: |
1272 | { |
1345 | { |
1273 | PangoLayoutLine *lp; |
1346 | PangoLayoutLine *lp; |
1274 | int index, trailing; |
1347 | int index, trailing; |
1275 | |
1348 | |
1276 | if (line < 0) |
1349 | if (line < 0) |
1277 | XSRETURN_EMPTY; |
1350 | XSRETURN_EMPTY; |
1278 | |
1351 | |
1279 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1352 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1280 | XSRETURN_EMPTY; /* do better */ |
1353 | XSRETURN_EMPTY; /* do better */ |
1281 | |
1354 | |
1282 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1355 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1283 | |
1356 | |
1284 | EXTEND (SP, 2); |
1357 | EXTEND (SP, 2); |
… | |
… | |
1290 | PUSHs (sv_2mortal (newSViv (trailing))); |
1363 | PUSHs (sv_2mortal (newSViv (trailing))); |
1291 | } |
1364 | } |
1292 | } |
1365 | } |
1293 | |
1366 | |
1294 | void |
1367 | void |
1295 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1368 | render (DC::Layout self, float x, float y, int flags = 0) |
1296 | PPCODE: |
1369 | CODE: |
|
|
1370 | rc_clear (self->rc); |
1297 | pango_opengl_render_layout_subpixel ( |
1371 | pango_opengl_render_layout_subpixel ( |
1298 | self->pl, |
1372 | self->pl, |
|
|
1373 | self->rc, |
1299 | x * PANGO_SCALE, y * PANGO_SCALE, |
1374 | x * PANGO_SCALE, y * PANGO_SCALE, |
1300 | self->r, self->g, self->b, self->a, |
1375 | self->r, self->g, self->b, self->a, |
1301 | flags |
1376 | flags |
1302 | ); |
1377 | ); |
|
|
1378 | // we assume that context_change actually clears/frees stuff |
|
|
1379 | // and does not do any recomputation... |
|
|
1380 | pango_layout_context_changed (self->pl); |
1303 | |
1381 | |
1304 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1382 | void |
|
|
1383 | draw (DC::Layout self) |
|
|
1384 | CODE: |
|
|
1385 | { |
|
|
1386 | glEnable (GL_TEXTURE_2D); |
|
|
1387 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1388 | glEnable (GL_BLEND); |
|
|
1389 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1390 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1391 | glEnable (GL_ALPHA_TEST); |
|
|
1392 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1393 | |
|
|
1394 | rc_draw (self->rc); |
|
|
1395 | |
|
|
1396 | glDisable (GL_ALPHA_TEST); |
|
|
1397 | glDisable (GL_BLEND); |
|
|
1398 | glDisable (GL_TEXTURE_2D); |
|
|
1399 | } |
|
|
1400 | |
|
|
1401 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1305 | |
1402 | |
1306 | PROTOTYPES: ENABLE |
1403 | PROTOTYPES: ENABLE |
1307 | |
|
|
1308 | int minpot (int n) |
|
|
1309 | |
1404 | |
1310 | void |
1405 | void |
1311 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1406 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1312 | CODE: |
1407 | CODE: |
1313 | { |
1408 | { |
… | |
… | |
1340 | HV *hv = (HV *)SvRV (self); |
1435 | HV *hv = (HV *)SvRV (self); |
1341 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1436 | float s = SvNV (*hv_fetch (hv, "s", 1, 1)); |
1342 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1437 | float t = SvNV (*hv_fetch (hv, "t", 1, 1)); |
1343 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1438 | int name = SvIV (*hv_fetch (hv, "name", 4, 1)); |
1344 | |
1439 | |
|
|
1440 | if (name <= 0) |
|
|
1441 | XSRETURN_EMPTY; |
|
|
1442 | |
1345 | if (items < 5) |
1443 | if (items < 5) |
1346 | { |
1444 | { |
1347 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1445 | w = SvNV (*hv_fetch (hv, "w", 1, 1)); |
1348 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1446 | h = SvNV (*hv_fetch (hv, "h", 1, 1)); |
1349 | } |
1447 | } |
… | |
… | |
1387 | RETVAL = width > 0; |
1485 | RETVAL = width > 0; |
1388 | } |
1486 | } |
1389 | OUTPUT: |
1487 | OUTPUT: |
1390 | RETVAL |
1488 | RETVAL |
1391 | |
1489 | |
1392 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1490 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1393 | |
1491 | |
1394 | PROTOTYPES: DISABLE |
1492 | PROTOTYPES: DISABLE |
1395 | |
1493 | |
1396 | CFPlus::Map |
1494 | DC::Map |
1397 | new (SV *class) |
1495 | new (SV *class) |
1398 | CODE: |
1496 | CODE: |
1399 | New (0, RETVAL, 1, struct map); |
1497 | New (0, RETVAL, 1, struct map); |
1400 | RETVAL->x = 0; |
1498 | RETVAL->x = 0; |
1401 | RETVAL->y = 0; |
1499 | RETVAL->y = 0; |
… | |
… | |
1409 | RETVAL->row = 0; |
1507 | RETVAL->row = 0; |
1410 | OUTPUT: |
1508 | OUTPUT: |
1411 | RETVAL |
1509 | RETVAL |
1412 | |
1510 | |
1413 | void |
1511 | void |
1414 | DESTROY (CFPlus::Map self) |
1512 | DESTROY (DC::Map self) |
1415 | CODE: |
1513 | CODE: |
1416 | { |
1514 | { |
1417 | map_clear (self); |
1515 | map_clear (self); |
1418 | Safefree (self->face2tile); |
1516 | Safefree (self->face2tile); |
1419 | Safefree (self->tex); |
1517 | Safefree (self->tex); |
1420 | Safefree (self); |
1518 | Safefree (self); |
1421 | } |
1519 | } |
1422 | |
1520 | |
1423 | void |
1521 | void |
1424 | resize (CFPlus::Map self, int map_width, int map_height) |
1522 | resize (DC::Map self, int map_width, int map_height) |
1425 | CODE: |
1523 | CODE: |
1426 | self->w = map_width; |
1524 | self->w = map_width; |
1427 | self->h = map_height; |
1525 | self->h = map_height; |
1428 | |
1526 | |
1429 | void |
1527 | void |
1430 | clear (CFPlus::Map self) |
1528 | clear (DC::Map self) |
1431 | CODE: |
1529 | CODE: |
1432 | map_clear (self); |
1530 | map_clear (self); |
1433 | |
1531 | |
1434 | void |
1532 | void |
1435 | set_tileid (CFPlus::Map self, int face, int tile) |
1533 | set_tileid (DC::Map self, int face, int tile) |
1436 | CODE: |
1534 | CODE: |
1437 | { |
1535 | { |
1438 | need_facenum (self, face); self->face2tile [face] = tile; |
1536 | need_facenum (self, face); self->face2tile [face] = tile; |
1439 | need_texid (self, tile); |
1537 | need_texid (self, tile); |
1440 | } |
1538 | } |
1441 | |
1539 | |
1442 | void |
1540 | void |
1443 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1541 | set_smooth (DC::Map self, int face, int smooth, int level) |
1444 | CODE: |
1542 | CODE: |
1445 | { |
1543 | { |
1446 | tileid texid; |
1544 | tileid texid; |
1447 | maptex *tex; |
1545 | maptex *tex; |
1448 | |
1546 | |
… | |
… | |
1461 | tex->smoothtile = self->face2tile [smooth]; |
1559 | tex->smoothtile = self->face2tile [smooth]; |
1462 | tex->smoothlevel = level; |
1560 | tex->smoothlevel = level; |
1463 | } |
1561 | } |
1464 | |
1562 | |
1465 | void |
1563 | void |
1466 | 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) |
1564 | 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) |
1467 | CODE: |
1565 | CODE: |
1468 | { |
1566 | { |
1469 | need_texid (self, texid); |
1567 | need_texid (self, texid); |
1470 | |
1568 | |
1471 | { |
1569 | { |
… | |
… | |
1491 | // from transparent color bleeding and ugly wrapping effects. |
1589 | // from transparent color bleeding and ugly wrapping effects. |
1492 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1590 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1493 | } |
1591 | } |
1494 | |
1592 | |
1495 | int |
1593 | int |
1496 | ox (CFPlus::Map self) |
1594 | ox (DC::Map self) |
1497 | ALIAS: |
1595 | ALIAS: |
1498 | oy = 1 |
1596 | oy = 1 |
1499 | x = 2 |
1597 | x = 2 |
1500 | y = 3 |
1598 | y = 3 |
1501 | w = 4 |
1599 | w = 4 |
… | |
… | |
1512 | } |
1610 | } |
1513 | OUTPUT: |
1611 | OUTPUT: |
1514 | RETVAL |
1612 | RETVAL |
1515 | |
1613 | |
1516 | void |
1614 | void |
1517 | scroll (CFPlus::Map self, int dx, int dy) |
1615 | scroll (DC::Map self, int dx, int dy) |
1518 | CODE: |
1616 | CODE: |
1519 | { |
1617 | { |
1520 | if (dx > 0) |
1618 | if (dx > 0) |
1521 | map_blank (self, self->x, self->y, dx, self->h); |
1619 | map_blank (self, self->x, self->y, dx, self->h); |
1522 | else if (dx < 0) |
1620 | else if (dx < 0) |
… | |
… | |
1537 | self->rows += MAP_EXTEND_Y; |
1635 | self->rows += MAP_EXTEND_Y; |
1538 | self->y += MAP_EXTEND_Y; |
1636 | self->y += MAP_EXTEND_Y; |
1539 | } |
1637 | } |
1540 | } |
1638 | } |
1541 | |
1639 | |
1542 | void |
1640 | SV * |
1543 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1641 | map1a_update (DC::Map self, SV *data_, int extmap) |
1544 | CODE: |
1642 | CODE: |
1545 | { |
1643 | { |
1546 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1644 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1547 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1645 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1548 | mapcell *cell; |
1646 | mapcell *cell; |
1549 | int x, y, flags; |
1647 | int x, y, z, flags; |
|
|
1648 | AV *missing = newAV (); |
|
|
1649 | RETVAL = newRV_noinc ((SV *)missing); |
1550 | |
1650 | |
1551 | while (data < data_end - 1) |
1651 | while (data < data_end - 1) |
1552 | { |
1652 | { |
1553 | flags = (data [0] << 8) + data [1]; data += 2; |
1653 | flags = (data [0] << 8) + data [1]; data += 2; |
1554 | |
1654 | |
… | |
… | |
1605 | } |
1705 | } |
1606 | else |
1706 | else |
1607 | cell->darkness = *data++ + 1; |
1707 | cell->darkness = *data++ + 1; |
1608 | } |
1708 | } |
1609 | |
1709 | |
|
|
1710 | for (z = 0; z <= 2; ++z) |
1610 | if (flags & 4) |
1711 | if (flags & (4 >> z)) |
1611 | { |
1712 | { |
1612 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1713 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1613 | need_facenum (self, face); |
1714 | need_facenum (self, face); |
1614 | cell->tile [0] = self->face2tile [face]; |
1715 | cell->tile [z] = self->face2tile [face]; |
|
|
1716 | |
|
|
1717 | if (cell->tile [z]) |
|
|
1718 | { |
|
|
1719 | maptex *tex = self->tex + cell->tile [z]; |
|
|
1720 | if (!tex->name) |
|
|
1721 | av_push (missing, newSViv (cell->tile [z])); |
|
|
1722 | |
|
|
1723 | if (tex->smoothtile) |
|
|
1724 | { |
|
|
1725 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
1726 | if (!smooth->name) |
|
|
1727 | av_push (missing, newSViv (tex->smoothtile)); |
|
|
1728 | } |
|
|
1729 | } |
1615 | } |
1730 | } |
1616 | |
|
|
1617 | if (flags & 2) |
|
|
1618 | { |
|
|
1619 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1620 | need_facenum (self, face); |
|
|
1621 | cell->tile [1] = self->face2tile [face]; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | if (flags & 1) |
|
|
1625 | { |
|
|
1626 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1627 | need_facenum (self, face); |
|
|
1628 | cell->tile [2] = self->face2tile [face]; |
|
|
1629 | } |
|
|
1630 | } |
1731 | } |
1631 | else |
1732 | else |
1632 | cell->darkness = 0; |
1733 | cell->darkness = 0; |
1633 | } |
1734 | } |
1634 | } |
1735 | } |
|
|
1736 | OUTPUT: |
|
|
1737 | RETVAL |
1635 | |
1738 | |
1636 | SV * |
1739 | SV * |
1637 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1740 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1638 | CODE: |
1741 | CODE: |
1639 | { |
1742 | { |
1640 | int x1, x; |
1743 | int x1, x; |
1641 | int y1, y; |
1744 | int y1, y; |
1642 | int z; |
1745 | int z; |
… | |
… | |
1687 | } |
1790 | } |
1688 | OUTPUT: |
1791 | OUTPUT: |
1689 | RETVAL |
1792 | RETVAL |
1690 | |
1793 | |
1691 | void |
1794 | void |
1692 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1795 | draw (DC::Map self, int mx, int my, int sw, int sh, int T) |
1693 | CODE: |
1796 | CODE: |
1694 | { |
1797 | { |
|
|
1798 | int x, y, z; |
|
|
1799 | |
1695 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1800 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1696 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1801 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1697 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1802 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1698 | smooth_key skey; |
1803 | smooth_key skey; |
1699 | int x, y, z; |
1804 | |
1700 | int last_name; |
1805 | rc_t *rc = rc_alloc (); |
|
|
1806 | rc_key_t key; |
|
|
1807 | rc_array_t *arr; |
1701 | |
1808 | |
1702 | // thats current max. sorry. |
1809 | // thats current max. sorry. |
1703 | if (sw > 255) sw = 255; |
1810 | if (sw > 255) sw = 255; |
1704 | if (sh > 255) sh = 255; |
1811 | if (sh > 255) sh = 255; |
1705 | |
1812 | |
1706 | // clear key, in case of extra padding |
1813 | // clear key, in case of extra padding |
1707 | memset (&skey, 0, sizeof (skey)); |
1814 | memset (&skey, 0, sizeof (skey)); |
1708 | |
1815 | |
1709 | glColor4ub (255, 255, 255, 255); |
1816 | memset (&key, 0, sizeof (key)); |
1710 | |
1817 | key.r = 255; |
1711 | glEnable (GL_BLEND); |
1818 | key.g = 255; |
1712 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1819 | key.b = 255; |
1713 | glEnable (GL_TEXTURE_2D); |
1820 | key.a = 255; |
1714 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1821 | key.mode = GL_QUADS; |
1715 | |
1822 | key.format = GL_T2F_V3F; |
1716 | glBegin (GL_QUADS); |
1823 | key.texname = -1; |
1717 | |
|
|
1718 | last_name = 0; |
|
|
1719 | |
1824 | |
1720 | mx += self->x; |
1825 | mx += self->x; |
1721 | my += self->y; |
1826 | my += self->y; |
1722 | |
1827 | |
1723 | // first pass: determine smooth_max |
1828 | // first pass: determine smooth_max |
… | |
… | |
1739 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1844 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1740 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1845 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1741 | self->tex [cell->tile [2]].smoothlevel)); |
1846 | self->tex [cell->tile [2]].smoothlevel)); |
1742 | } |
1847 | } |
1743 | } |
1848 | } |
|
|
1849 | |
|
|
1850 | glEnable (GL_BLEND); |
|
|
1851 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1852 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1744 | |
1853 | |
1745 | for (z = 0; z <= 2; z++) |
1854 | for (z = 0; z <= 2; z++) |
1746 | { |
1855 | { |
1747 | memset (smooth_level, 0, sizeof (smooth_level)); |
1856 | memset (smooth_level, 0, sizeof (smooth_level)); |
1748 | |
1857 | |
… | |
… | |
1758 | tileid tile = cell->tile [z]; |
1867 | tileid tile = cell->tile [z]; |
1759 | |
1868 | |
1760 | if (tile) |
1869 | if (tile) |
1761 | { |
1870 | { |
1762 | maptex tex = self->tex [tile]; |
1871 | maptex tex = self->tex [tile]; |
1763 | int px = (x + 1) * T - tex.w; |
1872 | int px, py; |
1764 | int py = (y + 1) * T - tex.h; |
|
|
1765 | |
1873 | |
1766 | // suppressing texture state switches here |
|
|
1767 | // is only moderately effective, but worth the extra effort |
|
|
1768 | if (last_name != tex.name) |
1874 | if (key.texname != tex.name) |
1769 | { |
1875 | { |
1770 | if (!tex.name) |
1876 | if (!tex.name) |
1771 | tex = self->tex [2]; /* missing, replace by noface */ |
1877 | tex = self->tex [2]; /* missing, replace by noface */ |
1772 | |
1878 | |
1773 | glEnd (); |
1879 | key.texname = tex.name; |
1774 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1880 | arr = rc_array (rc, &key); |
1775 | glBegin (GL_QUADS); |
|
|
1776 | } |
1881 | } |
1777 | |
1882 | |
1778 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1883 | px = (x + 1) * T - tex.w; |
|
|
1884 | py = (y + 1) * T - tex.h; |
|
|
1885 | |
|
|
1886 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
1779 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1887 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
1780 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1888 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
1781 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1889 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1782 | |
1890 | |
1783 | if (cell->flags && z == 2) |
1891 | if (cell->flags && z == 2) |
1784 | { |
1892 | { |
|
|
1893 | // overlays such as the speech bubble, probably more to come |
1785 | if (cell->flags & 1) |
1894 | if (cell->flags & 1) |
1786 | { |
1895 | { |
1787 | maptex tex = self->tex [1]; |
1896 | maptex tex = self->tex [1]; |
1788 | int px = x * T + T * 2 / 32; |
1897 | int px = x * T + T * 2 / 32; |
1789 | int py = y * T - T * 6 / 32; |
1898 | int py = y * T - T * 6 / 32; |
1790 | |
1899 | |
|
|
1900 | if (tex.name) |
1791 | glEnd (); |
1901 | { |
1792 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1902 | if (key.texname != tex.name) |
|
|
1903 | { |
|
|
1904 | key.texname = tex.name; |
|
|
1905 | arr = rc_array (rc, &key); |
|
|
1906 | } |
|
|
1907 | |
|
|
1908 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1909 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1910 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1911 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
1793 | glBegin (GL_QUADS); |
1912 | } |
1794 | |
|
|
1795 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1796 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1797 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1798 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1799 | } |
1913 | } |
1800 | } |
1914 | } |
1801 | |
1915 | |
1802 | // update smooth hash |
1916 | // update smooth hash |
1803 | if (tex.smoothtile) |
1917 | if (tex.smoothtile) |
… | |
… | |
1839 | } |
1953 | } |
1840 | } |
1954 | } |
1841 | } |
1955 | } |
1842 | } |
1956 | } |
1843 | |
1957 | |
|
|
1958 | rc_draw (rc); |
|
|
1959 | rc_clear (rc); |
|
|
1960 | |
1844 | // go through all smoothlevels, lowest to highest, then draw. |
1961 | // go through all smoothlevels, lowest to highest, then draw. |
1845 | // this is basically counting sort |
1962 | // this is basically counting sort |
1846 | { |
1963 | { |
1847 | int w, b; |
1964 | int w, b; |
1848 | |
1965 | |
|
|
1966 | glEnable (GL_TEXTURE_2D); |
|
|
1967 | glBegin (GL_QUADS); |
1849 | for (w = 0; w < 256 / 32; ++w) |
1968 | for (w = 0; w < 256 / 32; ++w) |
1850 | { |
1969 | { |
1851 | uint32_t smask = smooth_level [w]; |
1970 | uint32_t smask = smooth_level [w]; |
1852 | if (smask) |
1971 | if (smask) |
1853 | for (b = 0; b < 32; ++b) |
1972 | for (b = 0; b < 32; ++b) |
… | |
… | |
1872 | int border = bits & 15; |
1991 | int border = bits & 15; |
1873 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1992 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1874 | float dx = tex.s * .0625f; // 16 images/row |
1993 | float dx = tex.s * .0625f; // 16 images/row |
1875 | float dy = tex.t * .5f ; // 2 images/column |
1994 | float dy = tex.t * .5f ; // 2 images/column |
1876 | |
1995 | |
1877 | // this time naively avoiding texture state changes |
|
|
1878 | // save gobs of state changes. |
|
|
1879 | if (last_name != tex.name) |
1996 | if (tex.name) |
1880 | { |
1997 | { |
|
|
1998 | // this time avoiding texture state changes |
|
|
1999 | // save gobs of state changes. |
1881 | if (!tex.name) |
2000 | if (key.texname != tex.name) |
1882 | continue; // smoothing not yet available |
2001 | { |
1883 | |
|
|
1884 | glEnd (); |
2002 | glEnd (); |
1885 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
2003 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1886 | glBegin (GL_QUADS); |
2004 | glBegin (GL_QUADS); |
1887 | } |
2005 | } |
1888 | |
2006 | |
1889 | if (border) |
2007 | if (border) |
1890 | { |
2008 | { |
1891 | float ox = border * dx; |
2009 | float ox = border * dx; |
1892 | |
2010 | |
1893 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
2011 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1894 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
2012 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1895 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
2013 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1896 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
2014 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1897 | } |
2015 | } |
1898 | |
2016 | |
1899 | if (corner) |
2017 | if (corner) |
1900 | { |
2018 | { |
1901 | float ox = corner * dx; |
2019 | float ox = corner * dx; |
1902 | |
2020 | |
1903 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
2021 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1904 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
2022 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1905 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
2023 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1906 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
2024 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
|
|
2025 | } |
1907 | } |
2026 | } |
1908 | } |
2027 | } |
1909 | } |
2028 | } |
1910 | } |
2029 | } |
1911 | } |
2030 | } |
|
|
2031 | |
|
|
2032 | glEnd (); |
|
|
2033 | glDisable (GL_TEXTURE_2D); |
|
|
2034 | key.texname = -1; |
1912 | } |
2035 | } |
1913 | |
2036 | |
1914 | hv_clear (smooth); |
2037 | hv_clear (smooth); |
1915 | } |
2038 | } |
1916 | |
2039 | |
1917 | glEnd (); |
|
|
1918 | |
|
|
1919 | glDisable (GL_TEXTURE_2D); |
|
|
1920 | glDisable (GL_BLEND); |
2040 | glDisable (GL_BLEND); |
|
|
2041 | rc_free (rc); |
1921 | |
2042 | |
1922 | // top layer: overlays such as the health bar |
2043 | // top layer: overlays such as the health bar |
1923 | for (y = 0; y < sh; y++) |
2044 | for (y = 0; y < sh; y++) |
1924 | if (0 <= y + my && y + my < self->rows) |
2045 | if (0 <= y + my && y + my < self->rows) |
1925 | { |
2046 | { |
… | |
… | |
1950 | } |
2071 | } |
1951 | } |
2072 | } |
1952 | } |
2073 | } |
1953 | |
2074 | |
1954 | void |
2075 | void |
1955 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2076 | draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1956 | CODE: |
2077 | CODE: |
1957 | { |
2078 | { |
1958 | static float color[16][3] = { |
2079 | static float color[16][3] = { |
1959 | { 0.00F, 0.00F, 0.00F }, |
2080 | { 0.00F, 0.00F, 0.00F }, |
1960 | { 1.00F, 1.00F, 1.00F }, |
2081 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
2010 | glDisable (GL_BLEND); |
2131 | glDisable (GL_BLEND); |
2011 | glDisable (GL_TEXTURE_2D); |
2132 | glDisable (GL_TEXTURE_2D); |
2012 | } |
2133 | } |
2013 | |
2134 | |
2014 | void |
2135 | void |
2015 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2136 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2016 | PPCODE: |
2137 | PPCODE: |
2017 | { |
2138 | { |
2018 | int x, y; |
2139 | int x, y; |
2019 | int sw1 = sw + 2; |
2140 | int sw1 = sw + 2; |
2020 | int sh1 = sh + 2; |
2141 | int sh1 = sh + 2; |
… | |
… | |
2091 | PUSHs (sv_2mortal (newSViv (sh3))); |
2212 | PUSHs (sv_2mortal (newSViv (sh3))); |
2092 | PUSHs (darkness3_sv); |
2213 | PUSHs (darkness3_sv); |
2093 | } |
2214 | } |
2094 | |
2215 | |
2095 | SV * |
2216 | SV * |
2096 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2217 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2097 | CODE: |
2218 | CODE: |
2098 | { |
2219 | { |
2099 | int x, y, x1, y1; |
2220 | int x, y, x1, y1; |
2100 | SV *data_sv = newSV (w * h * 7 + 5); |
2221 | SV *data_sv = newSV (w * h * 7 + 5); |
2101 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2222 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2166 | } |
2287 | } |
2167 | OUTPUT: |
2288 | OUTPUT: |
2168 | RETVAL |
2289 | RETVAL |
2169 | |
2290 | |
2170 | void |
2291 | void |
2171 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2292 | set_rect (DC::Map self, int x0, int y0, uint8_t *data) |
2172 | PPCODE: |
2293 | PPCODE: |
2173 | { |
2294 | { |
2174 | int x, y, z; |
2295 | int x, y, z; |
2175 | int w, h; |
2296 | int w, h; |
2176 | int x1, y1; |
2297 | int x1, y1; |
2177 | |
2298 | |
2178 | if (*data++ != 0) |
2299 | if (*data++ != 0) |
2179 | return; /* version mismatch */ |
2300 | XSRETURN_EMPTY; /* version mismatch */ |
2180 | |
2301 | |
2181 | w = *data++ << 8; w |= *data++; |
2302 | w = *data++ << 8; w |= *data++; |
2182 | h = *data++ << 8; h |= *data++; |
2303 | h = *data++ << 8; h |= *data++; |
2183 | |
2304 | |
2184 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2305 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2229 | } |
2350 | } |
2230 | } |
2351 | } |
2231 | } |
2352 | } |
2232 | } |
2353 | } |
2233 | |
2354 | |
2234 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2355 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2235 | |
2356 | |
2236 | PROTOTYPES: DISABLE |
2357 | DC::RW |
2237 | |
2358 | new (SV *class, SV *data_sv) |
2238 | CFPlus::MixChunk |
|
|
2239 | new_from_file (SV *class, char *path) |
|
|
2240 | CODE: |
2359 | CODE: |
2241 | RETVAL = Mix_LoadWAV (path); |
2360 | { |
|
|
2361 | STRLEN datalen; |
|
|
2362 | char *data = SvPVbyte (data_sv, datalen); |
|
|
2363 | |
|
|
2364 | RETVAL = SDL_RWFromConstMem (data, datalen); |
|
|
2365 | } |
2242 | OUTPUT: |
2366 | OUTPUT: |
2243 | RETVAL |
2367 | RETVAL |
2244 | |
2368 | |
|
|
2369 | DC::RW |
|
|
2370 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
|
|
2371 | CODE: |
|
|
2372 | RETVAL = SDL_RWFromFile (path, mode); |
|
|
2373 | OUTPUT: |
|
|
2374 | RETVAL |
|
|
2375 | |
|
|
2376 | # fails on win32: |
|
|
2377 | # dc.xs(2268) : error C2059: syntax error : '(' |
2245 | void |
2378 | #void |
|
|
2379 | #close (DC::RW self) |
|
|
2380 | # CODE: |
|
|
2381 | # (self->(close)) (self); |
|
|
2382 | |
|
|
2383 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
|
|
2384 | |
|
|
2385 | PROTOTYPES: DISABLE |
|
|
2386 | |
|
|
2387 | DC::Channel |
|
|
2388 | find () |
|
|
2389 | CODE: |
|
|
2390 | { |
|
|
2391 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2392 | |
|
|
2393 | if (RETVAL < 0) |
|
|
2394 | { |
|
|
2395 | RETVAL = Mix_GroupOldest (-1); |
|
|
2396 | |
|
|
2397 | if (RETVAL < 0) |
|
|
2398 | XSRETURN_UNDEF; |
|
|
2399 | |
|
|
2400 | Mix_HaltChannel (RETVAL); |
|
|
2401 | } |
|
|
2402 | |
|
|
2403 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2404 | Mix_Volume (RETVAL, 128); |
|
|
2405 | } |
|
|
2406 | OUTPUT: |
|
|
2407 | RETVAL |
|
|
2408 | |
|
|
2409 | void |
|
|
2410 | halt (DC::Channel self) |
|
|
2411 | CODE: |
|
|
2412 | Mix_HaltChannel (self); |
|
|
2413 | |
|
|
2414 | void |
|
|
2415 | expire (DC::Channel self, int ticks = -1) |
|
|
2416 | CODE: |
|
|
2417 | Mix_ExpireChannel (self, ticks); |
|
|
2418 | |
|
|
2419 | void |
|
|
2420 | fade_out (DC::Channel self, int ticks = -1) |
|
|
2421 | CODE: |
|
|
2422 | Mix_FadeOutChannel (self, ticks); |
|
|
2423 | |
|
|
2424 | int |
|
|
2425 | volume (DC::Channel self, int volume) |
|
|
2426 | CODE: |
|
|
2427 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
|
|
2428 | OUTPUT: |
|
|
2429 | RETVAL |
|
|
2430 | |
|
|
2431 | void |
|
|
2432 | unregister_all_effects (DC::Channel self) |
|
|
2433 | CODE: |
|
|
2434 | Mix_UnregisterAllEffects (self); |
|
|
2435 | |
|
|
2436 | void |
|
|
2437 | set_panning (DC::Channel self, int left, int right) |
|
|
2438 | CODE: |
|
|
2439 | left = CLAMP (left , 0, 255); |
|
|
2440 | right = CLAMP (right, 0, 255); |
|
|
2441 | Mix_SetPanning (self, left, right); |
|
|
2442 | |
|
|
2443 | void |
|
|
2444 | set_distance (DC::Channel self, int distance) |
|
|
2445 | CODE: |
|
|
2446 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
|
|
2447 | |
|
|
2448 | void |
|
|
2449 | set_position (DC::Channel self, int angle, int distance) |
|
|
2450 | CODE: |
|
|
2451 | |
|
|
2452 | void |
|
|
2453 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
|
|
2454 | CODE: |
|
|
2455 | { |
|
|
2456 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
|
|
2457 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
|
|
2458 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
|
|
2459 | } |
|
|
2460 | |
|
|
2461 | void |
|
|
2462 | set_reverse_stereo (DC::Channel self, int flip) |
|
|
2463 | CODE: |
|
|
2464 | Mix_SetReverseStereo (self, flip); |
|
|
2465 | |
|
|
2466 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
|
|
2467 | |
|
|
2468 | PROTOTYPES: DISABLE |
|
|
2469 | |
|
|
2470 | DC::MixChunk |
|
|
2471 | new (SV *class, DC::RW rwops) |
|
|
2472 | CODE: |
|
|
2473 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
|
|
2474 | OUTPUT: |
|
|
2475 | RETVAL |
|
|
2476 | |
|
|
2477 | void |
2246 | DESTROY (CFPlus::MixChunk self) |
2478 | DESTROY (DC::MixChunk self) |
2247 | CODE: |
2479 | CODE: |
2248 | Mix_FreeChunk (self); |
2480 | Mix_FreeChunk (self); |
2249 | |
2481 | |
2250 | int |
2482 | int |
2251 | volume (CFPlus::MixChunk self, int volume = -1) |
2483 | volume (DC::MixChunk self, int volume = -1) |
2252 | CODE: |
2484 | CODE: |
|
|
2485 | if (items > 1) |
|
|
2486 | volume = CLAMP (volume, 0, 128); |
2253 | RETVAL = Mix_VolumeChunk (self, volume); |
2487 | RETVAL = Mix_VolumeChunk (self, volume); |
2254 | OUTPUT: |
2488 | OUTPUT: |
2255 | RETVAL |
2489 | RETVAL |
2256 | |
2490 | |
2257 | int |
2491 | DC::Channel |
2258 | play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) |
2492 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2259 | CODE: |
2493 | CODE: |
|
|
2494 | { |
2260 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2495 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
|
|
2496 | |
|
|
2497 | if (RETVAL < 0) |
|
|
2498 | XSRETURN_UNDEF; |
|
|
2499 | |
|
|
2500 | if (channel < 0) |
|
|
2501 | { |
|
|
2502 | Mix_UnregisterAllEffects (RETVAL); |
|
|
2503 | Mix_Volume (RETVAL, 128); |
|
|
2504 | } |
|
|
2505 | } |
2261 | OUTPUT: |
2506 | OUTPUT: |
2262 | RETVAL |
2507 | RETVAL |
2263 | |
2508 | |
2264 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2509 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
2265 | |
2510 | |
2266 | int |
2511 | int |
2267 | volume (int volume = -1) |
2512 | volume (int volume = -1) |
2268 | PROTOTYPE: ;$ |
2513 | PROTOTYPE: ;$ |
2269 | CODE: |
2514 | CODE: |
|
|
2515 | if (items > 0) |
|
|
2516 | volume = CLAMP (volume, 0, 128); |
2270 | RETVAL = Mix_VolumeMusic (volume); |
2517 | RETVAL = Mix_VolumeMusic (volume); |
2271 | OUTPUT: |
2518 | OUTPUT: |
2272 | RETVAL |
2519 | RETVAL |
2273 | |
2520 | |
2274 | int |
2521 | void |
2275 | fade_out (int ms) |
2522 | fade_out (int ms) |
2276 | CODE: |
2523 | CODE: |
2277 | RETVAL = Mix_FadeOutMusic (ms); |
2524 | Mix_FadeOutMusic (ms); |
|
|
2525 | |
|
|
2526 | void |
|
|
2527 | halt () |
|
|
2528 | CODE: |
|
|
2529 | Mix_HaltMusic (); |
|
|
2530 | |
|
|
2531 | DC::MixMusic |
|
|
2532 | new (SV *class, DC::RW rwops) |
|
|
2533 | CODE: |
|
|
2534 | RETVAL = Mix_LoadMUS_RW (rwops); |
2278 | OUTPUT: |
2535 | OUTPUT: |
2279 | RETVAL |
2536 | RETVAL |
2280 | |
2537 | |
2281 | CFPlus::MixMusic |
|
|
2282 | new_from_file (SV *class, char *path) |
|
|
2283 | CODE: |
|
|
2284 | RETVAL = Mix_LoadMUS (path); |
|
|
2285 | OUTPUT: |
|
|
2286 | RETVAL |
|
|
2287 | |
|
|
2288 | void |
2538 | void |
2289 | DESTROY (CFPlus::MixMusic self) |
2539 | DESTROY (DC::MixMusic self) |
2290 | CODE: |
2540 | CODE: |
2291 | Mix_FreeMusic (self); |
2541 | Mix_FreeMusic (self); |
2292 | |
2542 | |
2293 | int |
2543 | int |
2294 | play (CFPlus::MixMusic self, int loops = -1) |
2544 | play (DC::MixMusic self, int loops = -1) |
2295 | CODE: |
2545 | CODE: |
2296 | RETVAL = Mix_PlayMusic (self, loops); |
2546 | RETVAL = Mix_PlayMusic (self, loops); |
2297 | OUTPUT: |
2547 | OUTPUT: |
2298 | RETVAL |
2548 | RETVAL |
2299 | |
2549 | |
2300 | int |
2550 | void |
2301 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
2551 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2302 | CODE: |
2552 | CODE: |
2303 | RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); |
2553 | Mix_FadeInMusicPos (self, loops, ms, position); |
2304 | OUTPUT: |
|
|
2305 | RETVAL |
|
|
2306 | |
2554 | |
2307 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
2555 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2308 | |
2556 | |
2309 | PROTOTYPES: ENABLE |
2557 | PROTOTYPES: ENABLE |
2310 | |
2558 | |
2311 | BOOT: |
2559 | BOOT: |
2312 | { |
2560 | { |
2313 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
2561 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2314 | static const struct { |
2562 | static const struct { |
2315 | const char *name; |
2563 | const char *name; |
2316 | IV iv; |
2564 | IV iv; |
2317 | } *civ, const_iv[] = { |
2565 | } *civ, const_iv[] = { |
2318 | # define const_iv(name) { # name, (IV)name } |
2566 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
2353 | const_iv (GL_INTENSITY), |
2601 | const_iv (GL_INTENSITY), |
2354 | const_iv (GL_LUMINANCE), |
2602 | const_iv (GL_LUMINANCE), |
2355 | const_iv (GL_LUMINANCE_ALPHA), |
2603 | const_iv (GL_LUMINANCE_ALPHA), |
2356 | const_iv (GL_FLOAT), |
2604 | const_iv (GL_FLOAT), |
2357 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
2605 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
2606 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
2607 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
2608 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
2609 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
2610 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
2611 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2358 | const_iv (GL_COMPILE), |
2612 | const_iv (GL_COMPILE), |
2359 | const_iv (GL_PROXY_TEXTURE_1D), |
2613 | const_iv (GL_PROXY_TEXTURE_1D), |
2360 | const_iv (GL_PROXY_TEXTURE_2D), |
2614 | const_iv (GL_PROXY_TEXTURE_2D), |
2361 | const_iv (GL_TEXTURE_1D), |
2615 | const_iv (GL_TEXTURE_1D), |
2362 | const_iv (GL_TEXTURE_2D), |
2616 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2401 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2655 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2402 | const_iv (GL_POINT_SMOOTH_HINT), |
2656 | const_iv (GL_POINT_SMOOTH_HINT), |
2403 | const_iv (GL_LINE_SMOOTH_HINT), |
2657 | const_iv (GL_LINE_SMOOTH_HINT), |
2404 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2658 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2405 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2659 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2660 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2406 | const_iv (GL_FASTEST), |
2661 | const_iv (GL_FASTEST), |
2407 | const_iv (GL_DONT_CARE), |
2662 | const_iv (GL_DONT_CARE), |
2408 | const_iv (GL_NICEST), |
2663 | const_iv (GL_NICEST), |
2409 | const_iv (GL_V2F), |
2664 | const_iv (GL_V2F), |
2410 | const_iv (GL_V3F), |
2665 | const_iv (GL_V3F), |
… | |
… | |
2418 | |
2673 | |
2419 | texture_av = newAV (); |
2674 | texture_av = newAV (); |
2420 | AvREAL_off (texture_av); |
2675 | AvREAL_off (texture_av); |
2421 | } |
2676 | } |
2422 | |
2677 | |
|
|
2678 | void |
|
|
2679 | disable_GL_EXT_blend_func_separate () |
|
|
2680 | CODE: |
|
|
2681 | gl.BlendFuncSeparate = 0; |
|
|
2682 | gl.BlendFuncSeparateEXT = 0; |
|
|
2683 | |
2423 | char * |
2684 | char * |
2424 | gl_vendor () |
2685 | gl_vendor () |
2425 | CODE: |
2686 | CODE: |
2426 | RETVAL = (char *)glGetString (GL_VENDOR); |
2687 | RETVAL = (char *)glGetString (GL_VENDOR); |
2427 | OUTPUT: |
2688 | OUTPUT: |
… | |
… | |
2544 | |
2805 | |
2545 | void glTexCoord (float s, float t) |
2806 | void glTexCoord (float s, float t) |
2546 | CODE: |
2807 | CODE: |
2547 | glTexCoord2f (s, t); |
2808 | glTexCoord2f (s, t); |
2548 | |
2809 | |
|
|
2810 | void glRect (float x1, float y1, float x2, float y2) |
|
|
2811 | CODE: |
|
|
2812 | glRectf (x1, y1, x2, y2); |
|
|
2813 | |
|
|
2814 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
2815 | CODE: |
|
|
2816 | glBegin (GL_LINE_LOOP); |
|
|
2817 | glVertex2f (x1, y1); |
|
|
2818 | glVertex2f (x2, y1); |
|
|
2819 | glVertex2f (x2, y2); |
|
|
2820 | glVertex2f (x1, y2); |
|
|
2821 | glEnd (); |
|
|
2822 | |
2549 | PROTOTYPES: ENABLE |
2823 | PROTOTYPES: ENABLE |
2550 | |
2824 | |
2551 | void glBegin (int mode) |
2825 | void glBegin (int mode) |
2552 | |
2826 | |
2553 | void glEnd () |
2827 | void glEnd () |
… | |
… | |
2585 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2859 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2586 | CODE: |
2860 | CODE: |
2587 | if (gl.SeparableFilter2D) |
2861 | if (gl.SeparableFilter2D) |
2588 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2862 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2589 | |
2863 | |
2590 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
2864 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2591 | |
2865 | |
2592 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2866 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2593 | |
2867 | |
2594 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2868 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2595 | |
2869 | |
… | |
… | |
2621 | |
2895 | |
2622 | void glEndList () |
2896 | void glEndList () |
2623 | |
2897 | |
2624 | void glCallList (int list) |
2898 | void glCallList (int list) |
2625 | |
2899 | |
2626 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
2900 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2627 | |
2901 | |
2628 | PROTOTYPES: DISABLE |
2902 | PROTOTYPES: DISABLE |
2629 | |
2903 | |
2630 | void |
2904 | void |
2631 | find_widget (SV *widget, NV x, NV y) |
2905 | find_widget (SV *self, NV x, NV y) |
2632 | PPCODE: |
2906 | PPCODE: |
2633 | { |
2907 | { |
2634 | if (within_widget (widget, x, y)) |
2908 | if (within_widget (self, x, y)) |
2635 | XPUSHs (widget); |
2909 | XPUSHs (self); |
2636 | } |
2910 | } |
2637 | |
2911 | |
|
|
2912 | BOOT: |
|
|
2913 | { |
|
|
2914 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
|
|
2915 | |
|
|
2916 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
|
|
2917 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
|
|
2918 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
|
|
2919 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
|
|
2920 | } |
|
|
2921 | |
|
|
2922 | void |
|
|
2923 | draw (SV *self) |
|
|
2924 | CODE: |
|
|
2925 | { |
|
|
2926 | HV *hv; |
|
|
2927 | SV **svp; |
|
|
2928 | NV x, y, w, h; |
|
|
2929 | SV *draw_x_sv = GvSV (draw_x_gv); |
|
|
2930 | SV *draw_y_sv = GvSV (draw_y_gv); |
|
|
2931 | SV *draw_w_sv = GvSV (draw_w_gv); |
|
|
2932 | SV *draw_h_sv = GvSV (draw_h_gv); |
|
|
2933 | double draw_x, draw_y; |
|
|
2934 | |
|
|
2935 | if (!SvROK (self)) |
|
|
2936 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
|
|
2937 | |
|
|
2938 | hv = (HV *)SvRV (self); |
|
|
2939 | |
|
|
2940 | if (SvTYPE (hv) != SVt_PVHV) |
|
|
2941 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
|
|
2942 | |
|
|
2943 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
|
|
2944 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
|
|
2945 | |
|
|
2946 | if (!h || !w) |
|
|
2947 | XSRETURN_EMPTY; |
|
|
2948 | |
|
|
2949 | svp = hv_fetch (hv, "x", 1, 0); x = svp ? SvNV (*svp) : 0.; |
|
|
2950 | svp = hv_fetch (hv, "y", 1, 0); y = svp ? SvNV (*svp) : 0.; |
|
|
2951 | |
|
|
2952 | draw_x = SvNV (draw_x_sv) + x; |
|
|
2953 | draw_y = SvNV (draw_y_sv) + y; |
|
|
2954 | |
|
|
2955 | if (draw_x + w < 0 || draw_x >= SvNV (draw_w_sv) |
|
|
2956 | || draw_y + h < 0 || draw_y >= SvNV (draw_h_sv)) |
|
|
2957 | XSRETURN_EMPTY; |
|
|
2958 | |
|
|
2959 | sv_setnv (draw_x_sv, draw_x); |
|
|
2960 | sv_setnv (draw_y_sv, draw_y); |
|
|
2961 | |
|
|
2962 | glPushMatrix (); |
|
|
2963 | glTranslated (x, y, 0); |
|
|
2964 | |
|
|
2965 | if (SvROK (GvSV (hover_gv)) && SvRV (GvSV (hover_gv)) == (SV *)hv) |
|
|
2966 | { |
|
|
2967 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
|
|
2968 | |
|
|
2969 | if (svp && SvTRUE (*svp)) |
|
|
2970 | { |
|
|
2971 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
|
|
2972 | glEnable (GL_BLEND); |
|
|
2973 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
2974 | glBegin (GL_QUADS); |
|
|
2975 | glVertex2f (0, 0); |
|
|
2976 | glVertex2f (w, 0); |
|
|
2977 | glVertex2f (w, h); |
|
|
2978 | glVertex2f (0, h); |
|
|
2979 | glEnd (); |
|
|
2980 | glDisable (GL_BLEND); |
|
|
2981 | } |
|
|
2982 | } |
|
|
2983 | #if 0 |
|
|
2984 | // draw borders, for debugging |
|
|
2985 | glPushMatrix (); |
|
|
2986 | glColor4f (1., 1., 0., 1.); |
|
|
2987 | glTranslatef (.5, .5, 0.); |
|
|
2988 | glBegin (GL_LINE_LOOP); |
|
|
2989 | glVertex2f (0 , 0); |
|
|
2990 | glVertex2f (w - 1, 0); |
|
|
2991 | glVertex2f (w - 1, h - 1); |
|
|
2992 | glVertex2f (0 , h - 1); |
|
|
2993 | glEnd (); |
|
|
2994 | glPopMatrix (); |
|
|
2995 | #endif |
|
|
2996 | PUSHMARK (SP); |
|
|
2997 | XPUSHs (self); |
|
|
2998 | PUTBACK; |
|
|
2999 | call_method ("_draw", G_VOID | G_DISCARD); |
|
|
3000 | SPAGAIN; |
|
|
3001 | |
|
|
3002 | glPopMatrix (); |
|
|
3003 | |
|
|
3004 | draw_x = draw_x - x; sv_setnv (draw_x_sv, draw_x); |
|
|
3005 | draw_y = draw_y - y; sv_setnv (draw_y_sv, draw_y); |
|
|
3006 | } |
|
|
3007 | |