… | |
… | |
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> |
… | |
… | |
109 | av_push (texture_av, (SV *)(size_t)name); |
114 | av_push (texture_av, (SV *)(size_t)name); |
110 | glDeleteTextures (1, &name); |
115 | glDeleteTextures (1, &name); |
111 | } |
116 | } |
112 | |
117 | |
113 | #include "texcache.c" |
118 | #include "texcache.c" |
|
|
119 | #include "rendercache.c" |
114 | |
120 | |
115 | #include "pango-font.c" |
121 | #include "pango-font.c" |
116 | #include "pango-fontmap.c" |
122 | #include "pango-fontmap.c" |
117 | #include "pango-render.c" |
123 | #include "pango-render.c" |
118 | |
124 | |
119 | typedef IV CFPlus__Channel; |
125 | typedef IV DC__Channel; |
120 | typedef SDL_RWops *CFPlus__RW; |
126 | typedef SDL_RWops *DC__RW; |
121 | typedef Mix_Chunk *CFPlus__MixChunk; |
127 | typedef Mix_Chunk *DC__MixChunk; |
122 | typedef Mix_Music *CFPlus__MixMusic; |
128 | typedef Mix_Music *DC__MixMusic; |
123 | |
129 | |
124 | typedef PangoFontDescription *CFPlus__Font; |
130 | typedef PangoFontDescription *DC__Font; |
125 | |
131 | |
126 | static int |
132 | static int |
127 | shape_attr_p (PangoLayoutRun *run) |
133 | shape_attr_p (PangoLayoutRun *run) |
128 | { |
134 | { |
129 | GSList *attrs = run->item->analysis.extra_attrs; |
135 | GSList *attrs = run->item->analysis.extra_attrs; |
… | |
… | |
143 | |
149 | |
144 | typedef struct cf_layout { |
150 | typedef struct cf_layout { |
145 | PangoLayout *pl; |
151 | PangoLayout *pl; |
146 | float r, g, b, a; // default color for rgba mode |
152 | float r, g, b, a; // default color for rgba mode |
147 | int base_height; |
153 | int base_height; |
148 | CFPlus__Font font; |
154 | DC__Font font; |
|
|
155 | rc_t *rc; |
149 | } *CFPlus__Layout; |
156 | } *DC__Layout; |
150 | |
157 | |
151 | static CFPlus__Font default_font; |
158 | static DC__Font default_font; |
152 | static PangoContext *opengl_context; |
159 | static PangoContext *opengl_context; |
153 | static PangoFontMap *opengl_fontmap; |
160 | static PangoFontMap *opengl_fontmap; |
154 | |
161 | |
155 | static void |
162 | static void |
156 | substitute_func (FcPattern *pattern, gpointer data) |
163 | substitute_func (FcPattern *pattern, gpointer data) |
… | |
… | |
161 | #endif |
168 | #endif |
162 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
169 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
163 | } |
170 | } |
164 | |
171 | |
165 | static void |
172 | static void |
166 | layout_update_font (CFPlus__Layout self) |
173 | layout_update_font (DC__Layout self) |
167 | { |
174 | { |
168 | /* use a random scale factor to account for unknown descenders, 0.8 works |
175 | /* use a random scale factor to account for unknown descenders, 0.8 works |
169 | * reasonably well with bitstream vera |
176 | * reasonably well with bitstream vera |
170 | */ |
177 | */ |
171 | PangoFontDescription *font = self->font ? self->font : default_font; |
178 | PangoFontDescription *font = self->font ? self->font : default_font; |
… | |
… | |
175 | |
182 | |
176 | pango_layout_set_font_description (self->pl, font); |
183 | pango_layout_set_font_description (self->pl, font); |
177 | } |
184 | } |
178 | |
185 | |
179 | static void |
186 | static void |
180 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
187 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
181 | { |
188 | { |
182 | PangoRectangle rect; |
189 | PangoRectangle rect; |
183 | |
190 | |
184 | // get_pixel_* wrongly rounds down |
191 | // get_pixel_* wrongly rounds down |
185 | pango_layout_get_extents (self->pl, 0, &rect); |
192 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
196 | |
203 | |
197 | typedef uint16_t tileid; |
204 | typedef uint16_t tileid; |
198 | typedef uint16_t faceid; |
205 | typedef uint16_t faceid; |
199 | |
206 | |
200 | typedef struct { |
207 | typedef struct { |
201 | int name; |
208 | GLuint name; |
202 | int w, h; |
209 | int w, h; |
203 | float s, t; |
210 | float s, t; |
204 | uint8_t r, g, b, a; |
211 | uint8_t r, g, b, a; |
205 | tileid smoothtile; |
212 | tileid smoothtile; |
206 | uint8_t smoothlevel; |
213 | uint8_t smoothlevel; |
… | |
… | |
224 | int faces; tileid *face2tile; // [faceid] |
231 | int faces; tileid *face2tile; // [faceid] |
225 | int texs; maptex *tex; // [tileid] |
232 | int texs; maptex *tex; // [tileid] |
226 | |
233 | |
227 | int32_t rows; |
234 | int32_t rows; |
228 | maprow *row; |
235 | maprow *row; |
229 | } *CFPlus__Map; |
236 | } *DC__Map; |
230 | |
237 | |
231 | static char * |
238 | static char * |
232 | prepend (char *ptr, int sze, int inc) |
239 | prepend (char *ptr, int sze, int inc) |
233 | { |
240 | { |
234 | char *p; |
241 | char *p; |
… | |
… | |
272 | self->texs *= 2; |
279 | self->texs *= 2; |
273 | } |
280 | } |
274 | } |
281 | } |
275 | |
282 | |
276 | static maprow * |
283 | static maprow * |
277 | map_get_row (CFPlus__Map self, int y) |
284 | map_get_row (DC__Map self, int y) |
278 | { |
285 | { |
279 | if (0 > y) |
286 | if (0 > y) |
280 | { |
287 | { |
281 | int extend = - y + MAP_EXTEND_Y; |
288 | int extend = - y + MAP_EXTEND_Y; |
282 | Prepend (maprow, self->row, self->rows, extend); |
289 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
320 | |
327 | |
321 | return row->col + (x - row->c0); |
328 | return row->col + (x - row->c0); |
322 | } |
329 | } |
323 | |
330 | |
324 | static mapcell * |
331 | static mapcell * |
325 | map_get_cell (CFPlus__Map self, int x, int y) |
332 | map_get_cell (DC__Map self, int x, int y) |
326 | { |
333 | { |
327 | return row_get_cell (map_get_row (self, y), x); |
334 | return row_get_cell (map_get_row (self, y), x); |
328 | } |
335 | } |
329 | |
336 | |
330 | static void |
337 | static void |
331 | map_clear (CFPlus__Map self) |
338 | map_clear (DC__Map self) |
332 | { |
339 | { |
333 | int r; |
340 | int r; |
334 | |
341 | |
335 | for (r = 0; r < self->rows; r++) |
342 | for (r = 0; r < self->rows; r++) |
336 | Safefree (self->row[r].col); |
343 | Safefree (self->row[r].col); |
… | |
… | |
344 | self->row = 0; |
351 | self->row = 0; |
345 | self->rows = 0; |
352 | self->rows = 0; |
346 | } |
353 | } |
347 | |
354 | |
348 | static void |
355 | static void |
349 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
356 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
350 | { |
357 | { |
351 | int x, y; |
358 | int x, y; |
352 | maprow *row; |
359 | maprow *row; |
353 | mapcell *cell; |
360 | mapcell *cell; |
354 | |
361 | |
… | |
… | |
433 | n |= n >> 16; |
440 | n |= n >> 16; |
434 | |
441 | |
435 | return n + 1; |
442 | return n + 1; |
436 | } |
443 | } |
437 | |
444 | |
|
|
445 | static unsigned int |
|
|
446 | popcount (unsigned int n) |
|
|
447 | { |
|
|
448 | n -= (n >> 1) & 0x55555555U; |
|
|
449 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
450 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
451 | n *= 0x01010101U; |
|
|
452 | |
|
|
453 | return n >> 24; |
|
|
454 | } |
|
|
455 | |
438 | /* SDL should provide this, really. */ |
456 | /* SDL should provide this, really. */ |
439 | #define SDLK_MODIFIER_MIN 300 |
457 | #define SDLK_MODIFIER_MIN 300 |
440 | #define SDLK_MODIFIER_MAX 314 |
458 | #define SDLK_MODIFIER_MAX 314 |
441 | |
459 | |
442 | /******************************************************************************/ |
460 | /******************************************************************************/ |
… | |
… | |
480 | return 0; |
498 | return 0; |
481 | |
499 | |
482 | return 1; |
500 | return 1; |
483 | } |
501 | } |
484 | |
502 | |
485 | MODULE = CFPlus PACKAGE = CFPlus |
503 | MODULE = Deliantra::Client PACKAGE = DC |
486 | |
504 | |
487 | PROTOTYPES: ENABLE |
505 | PROTOTYPES: ENABLE |
488 | |
506 | |
489 | BOOT: |
507 | BOOT: |
490 | { |
508 | { |
491 | HV *stash = gv_stashpv ("CFPlus", 1); |
509 | HV *stash = gv_stashpv ("DC", 1); |
492 | static const struct { |
510 | static const struct { |
493 | const char *name; |
511 | const char *name; |
494 | IV iv; |
512 | IV iv; |
495 | } *civ, const_iv[] = { |
513 | } *civ, const_iv[] = { |
496 | # define const_iv(name) { # name, (IV)name } |
514 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
518 | |
536 | |
519 | const_iv (SDL_APPINPUTFOCUS), |
537 | const_iv (SDL_APPINPUTFOCUS), |
520 | const_iv (SDL_APPMOUSEFOCUS), |
538 | const_iv (SDL_APPMOUSEFOCUS), |
521 | const_iv (SDL_APPACTIVE), |
539 | const_iv (SDL_APPACTIVE), |
522 | |
540 | |
|
|
541 | const_iv (SDLK_FIRST), |
|
|
542 | const_iv (SDLK_LAST), |
523 | const_iv (SDLK_KP0), |
543 | const_iv (SDLK_KP0), |
524 | const_iv (SDLK_KP1), |
544 | const_iv (SDLK_KP1), |
525 | const_iv (SDLK_KP2), |
545 | const_iv (SDLK_KP2), |
526 | const_iv (SDLK_KP3), |
546 | const_iv (SDLK_KP3), |
527 | const_iv (SDLK_KP4), |
547 | const_iv (SDLK_KP4), |
… | |
… | |
599 | const_iv (KMOD_LMETA), |
619 | const_iv (KMOD_LMETA), |
600 | const_iv (KMOD_RMETA), |
620 | const_iv (KMOD_RMETA), |
601 | const_iv (KMOD_NUM), |
621 | const_iv (KMOD_NUM), |
602 | const_iv (KMOD_CAPS), |
622 | const_iv (KMOD_CAPS), |
603 | const_iv (KMOD_MODE), |
623 | const_iv (KMOD_MODE), |
|
|
624 | |
|
|
625 | const_iv (MIX_DEFAULT_FORMAT), |
604 | # undef const_iv |
626 | # undef const_iv |
605 | }; |
627 | }; |
606 | |
628 | |
607 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
629 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
608 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
630 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
625 | RETVAL |
647 | RETVAL |
626 | |
648 | |
627 | NV floor (NV x) |
649 | NV floor (NV x) |
628 | |
650 | |
629 | NV ceil (NV x) |
651 | NV ceil (NV x) |
|
|
652 | |
|
|
653 | IV minpot (UV n) |
|
|
654 | |
|
|
655 | IV popcount (UV n) |
630 | |
656 | |
631 | void |
657 | void |
632 | pango_init () |
658 | pango_init () |
633 | CODE: |
659 | CODE: |
634 | { |
660 | { |
… | |
… | |
674 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
700 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
675 | |
701 | |
676 | if (m && m != (SDL_Rect **)-1) |
702 | if (m && m != (SDL_Rect **)-1) |
677 | while (*m) |
703 | while (*m) |
678 | { |
704 | { |
679 | if ((*m)->w >= 640 && (*m)->h >= 480) |
705 | if ((*m)->w >= 800 && (*m)->h >= 480) |
680 | { |
706 | { |
681 | AV *av = newAV (); |
707 | AV *av = newAV (); |
682 | av_push (av, newSViv ((*m)->w)); |
708 | av_push (av, newSViv ((*m)->w)); |
683 | av_push (av, newSViv ((*m)->h)); |
709 | av_push (av, newSViv ((*m)->h)); |
684 | av_push (av, newSViv (rgb)); |
710 | av_push (av, newSViv (rgb)); |
… | |
… | |
708 | |
734 | |
709 | if (RETVAL) |
735 | if (RETVAL) |
710 | { |
736 | { |
711 | av_clear (texture_av); |
737 | av_clear (texture_av); |
712 | |
738 | |
713 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
739 | SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra"); |
714 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
740 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
715 | #include "glfunc.h" |
741 | #include "glfunc.h" |
716 | #undef GL_FUNC |
742 | #undef GL_FUNC |
717 | } |
743 | } |
718 | } |
744 | } |
… | |
… | |
799 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
825 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
800 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
826 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
801 | break; |
827 | break; |
802 | } |
828 | } |
803 | |
829 | |
804 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
830 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
805 | } |
831 | } |
806 | } |
832 | } |
807 | |
833 | |
808 | int |
834 | int |
809 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) |
835 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
810 | POSTCALL: |
836 | POSTCALL: |
811 | Mix_HookMusicFinished (music_finished); |
837 | Mix_HookMusicFinished (music_finished); |
812 | Mix_ChannelFinished (channel_finished); |
838 | Mix_ChannelFinished (channel_finished); |
|
|
839 | |
|
|
840 | void |
|
|
841 | Mix_QuerySpec () |
|
|
842 | PPCODE: |
|
|
843 | { |
|
|
844 | int freq, channels; |
|
|
845 | Uint16 format; |
|
|
846 | |
|
|
847 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
848 | { |
|
|
849 | EXTEND (SP, 3); |
|
|
850 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
851 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
852 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
853 | } |
|
|
854 | } |
813 | |
855 | |
814 | void |
856 | void |
815 | Mix_CloseAudio () |
857 | Mix_CloseAudio () |
816 | |
858 | |
817 | int |
859 | int |
… | |
… | |
951 | void |
993 | void |
952 | error (char *message) |
994 | error (char *message) |
953 | CODE: |
995 | CODE: |
954 | fprintf (stderr, "ERROR: %s\n", message); |
996 | fprintf (stderr, "ERROR: %s\n", message); |
955 | #ifdef _WIN32 |
997 | #ifdef _WIN32 |
956 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
998 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
957 | #endif |
999 | #endif |
958 | |
1000 | |
959 | void |
1001 | void |
960 | fatal (char *message) |
1002 | fatal (char *message) |
961 | CODE: |
1003 | CODE: |
962 | fprintf (stderr, "FATAL: %s\n", message); |
1004 | fprintf (stderr, "FATAL: %s\n", message); |
963 | #ifdef _WIN32 |
1005 | #ifdef _WIN32 |
964 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1006 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
965 | #endif |
1007 | #endif |
966 | _exit (1); |
1008 | _exit (1); |
967 | |
1009 | |
968 | void |
1010 | void |
969 | _exit (int retval = 0) |
1011 | _exit (int retval = 0) |
… | |
… | |
981 | #if DEBUG |
1023 | #if DEBUG |
982 | VALGRIND_DO_LEAK_CHECK; |
1024 | VALGRIND_DO_LEAK_CHECK; |
983 | #endif |
1025 | #endif |
984 | } |
1026 | } |
985 | |
1027 | |
986 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1028 | MODULE = Deliantra::Client PACKAGE = DC::Font |
987 | |
1029 | |
988 | PROTOTYPES: DISABLE |
1030 | PROTOTYPES: DISABLE |
989 | |
1031 | |
990 | CFPlus::Font |
1032 | DC::Font |
991 | new_from_file (SV *class, char *path, int id = 0) |
1033 | new_from_file (SV *class, char *path, int id = 0) |
992 | CODE: |
1034 | CODE: |
993 | { |
1035 | { |
994 | int count; |
1036 | int count; |
995 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1037 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
… | |
… | |
998 | } |
1040 | } |
999 | OUTPUT: |
1041 | OUTPUT: |
1000 | RETVAL |
1042 | RETVAL |
1001 | |
1043 | |
1002 | void |
1044 | void |
1003 | DESTROY (CFPlus::Font self) |
1045 | DESTROY (DC::Font self) |
1004 | CODE: |
1046 | CODE: |
1005 | pango_font_description_free (self); |
1047 | pango_font_description_free (self); |
1006 | |
1048 | |
1007 | void |
1049 | void |
1008 | make_default (CFPlus::Font self) |
1050 | make_default (DC::Font self) |
1009 | PROTOTYPE: $ |
1051 | PROTOTYPE: $ |
1010 | CODE: |
1052 | CODE: |
1011 | default_font = self; |
1053 | default_font = self; |
1012 | |
1054 | |
1013 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1055 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1014 | |
1056 | |
1015 | PROTOTYPES: DISABLE |
1057 | PROTOTYPES: DISABLE |
1016 | |
1058 | |
1017 | void |
1059 | void |
1018 | reset_glyph_cache () |
1060 | glyph_cache_backup () |
1019 | PROTOTYPE: |
1061 | PROTOTYPE: |
1020 | CODE: |
1062 | CODE: |
|
|
1063 | tc_backup (); |
|
|
1064 | |
|
|
1065 | void |
|
|
1066 | glyph_cache_restore () |
|
|
1067 | PROTOTYPE: |
|
|
1068 | CODE: |
1021 | tc_clear (); |
1069 | tc_restore (); |
1022 | |
1070 | |
1023 | CFPlus::Layout |
1071 | DC::Layout |
1024 | new (SV *class) |
1072 | new (SV *class) |
1025 | CODE: |
1073 | CODE: |
1026 | New (0, RETVAL, 1, struct cf_layout); |
1074 | New (0, RETVAL, 1, struct cf_layout); |
1027 | |
1075 | |
1028 | RETVAL->pl = pango_layout_new (opengl_context); |
1076 | RETVAL->pl = pango_layout_new (opengl_context); |
… | |
… | |
1030 | RETVAL->g = 1.; |
1078 | RETVAL->g = 1.; |
1031 | RETVAL->b = 1.; |
1079 | RETVAL->b = 1.; |
1032 | RETVAL->a = 1.; |
1080 | RETVAL->a = 1.; |
1033 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1081 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1034 | RETVAL->font = 0; |
1082 | RETVAL->font = 0; |
|
|
1083 | RETVAL->rc = rc_alloc (); |
1035 | |
1084 | |
1036 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1085 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1037 | layout_update_font (RETVAL); |
1086 | layout_update_font (RETVAL); |
1038 | OUTPUT: |
1087 | OUTPUT: |
1039 | RETVAL |
1088 | RETVAL |
1040 | |
1089 | |
1041 | void |
1090 | void |
1042 | DESTROY (CFPlus::Layout self) |
1091 | DESTROY (DC::Layout self) |
1043 | CODE: |
1092 | CODE: |
1044 | g_object_unref (self->pl); |
1093 | g_object_unref (self->pl); |
|
|
1094 | rc_free (self->rc); |
1045 | Safefree (self); |
1095 | Safefree (self); |
1046 | |
1096 | |
1047 | void |
1097 | void |
1048 | set_text (CFPlus::Layout self, SV *text_) |
1098 | set_text (DC::Layout self, SV *text_) |
1049 | CODE: |
1099 | CODE: |
1050 | { |
1100 | { |
1051 | STRLEN textlen; |
1101 | STRLEN textlen; |
1052 | char *text = SvPVutf8 (text_, textlen); |
1102 | char *text = SvPVutf8 (text_, textlen); |
1053 | |
1103 | |
1054 | pango_layout_set_text (self->pl, text, textlen); |
1104 | pango_layout_set_text (self->pl, text, textlen); |
1055 | } |
1105 | } |
1056 | |
1106 | |
1057 | void |
1107 | void |
1058 | set_markup (CFPlus::Layout self, SV *text_) |
1108 | set_markup (DC::Layout self, SV *text_) |
1059 | CODE: |
1109 | CODE: |
1060 | { |
1110 | { |
1061 | STRLEN textlen; |
1111 | STRLEN textlen; |
1062 | char *text = SvPVutf8 (text_, textlen); |
1112 | char *text = SvPVutf8 (text_, textlen); |
1063 | |
1113 | |
1064 | pango_layout_set_markup (self->pl, text, textlen); |
1114 | pango_layout_set_markup (self->pl, text, textlen); |
1065 | } |
1115 | } |
1066 | |
1116 | |
1067 | void |
1117 | void |
1068 | set_shapes (CFPlus::Layout self, ...) |
1118 | set_shapes (DC::Layout self, ...) |
1069 | CODE: |
1119 | CODE: |
1070 | { |
1120 | { |
1071 | PangoAttrList *attrs = 0; |
1121 | PangoAttrList *attrs = 0; |
1072 | const char *text = pango_layout_get_text (self->pl); |
1122 | const char *text = pango_layout_get_text (self->pl); |
1073 | const char *pos = text; |
1123 | const char *pos = text; |
… | |
… | |
1108 | if (attrs) |
1158 | if (attrs) |
1109 | pango_layout_set_attributes (self->pl, attrs); |
1159 | pango_layout_set_attributes (self->pl, attrs); |
1110 | } |
1160 | } |
1111 | |
1161 | |
1112 | void |
1162 | void |
1113 | get_shapes (CFPlus::Layout self) |
1163 | get_shapes (DC::Layout self) |
1114 | PPCODE: |
1164 | PPCODE: |
1115 | { |
1165 | { |
1116 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1166 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1117 | |
1167 | |
1118 | do |
1168 | do |
… | |
… | |
1133 | |
1183 | |
1134 | pango_layout_iter_free (iter); |
1184 | pango_layout_iter_free (iter); |
1135 | } |
1185 | } |
1136 | |
1186 | |
1137 | int |
1187 | int |
1138 | has_wrapped (CFPlus::Layout self) |
1188 | has_wrapped (DC::Layout self) |
1139 | CODE: |
1189 | CODE: |
1140 | { |
1190 | { |
1141 | int lines = 1; |
1191 | int lines = 1; |
1142 | const char *text = pango_layout_get_text (self->pl); |
1192 | const char *text = pango_layout_get_text (self->pl); |
1143 | |
1193 | |
… | |
… | |
1148 | } |
1198 | } |
1149 | OUTPUT: |
1199 | OUTPUT: |
1150 | RETVAL |
1200 | RETVAL |
1151 | |
1201 | |
1152 | SV * |
1202 | SV * |
1153 | get_text (CFPlus::Layout self) |
1203 | get_text (DC::Layout self) |
1154 | CODE: |
1204 | CODE: |
1155 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1205 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1156 | sv_utf8_decode (RETVAL); |
1206 | sv_utf8_decode (RETVAL); |
1157 | OUTPUT: |
1207 | OUTPUT: |
1158 | RETVAL |
1208 | RETVAL |
1159 | |
1209 | |
1160 | void |
1210 | void |
1161 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1211 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1162 | CODE: |
1212 | CODE: |
1163 | self->r = r; |
1213 | self->r = r; |
1164 | self->g = g; |
1214 | self->g = g; |
1165 | self->b = b; |
1215 | self->b = b; |
1166 | self->a = a; |
1216 | self->a = a; |
1167 | |
1217 | |
1168 | void |
1218 | void |
1169 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1219 | set_font (DC::Layout self, DC::Font font = 0) |
1170 | CODE: |
1220 | CODE: |
1171 | if (self->font != font) |
1221 | if (self->font != font) |
1172 | { |
1222 | { |
1173 | self->font = font; |
1223 | self->font = font; |
1174 | layout_update_font (self); |
1224 | layout_update_font (self); |
1175 | } |
1225 | } |
1176 | |
1226 | |
1177 | void |
1227 | void |
1178 | set_height (CFPlus::Layout self, int base_height) |
1228 | set_height (DC::Layout self, int base_height) |
1179 | CODE: |
1229 | CODE: |
1180 | if (self->base_height != base_height) |
1230 | if (self->base_height != base_height) |
1181 | { |
1231 | { |
1182 | self->base_height = base_height; |
1232 | self->base_height = base_height; |
1183 | layout_update_font (self); |
1233 | layout_update_font (self); |
1184 | } |
1234 | } |
1185 | |
1235 | |
1186 | void |
1236 | void |
1187 | set_width (CFPlus::Layout self, int max_width = -1) |
1237 | set_width (DC::Layout self, int max_width = -1) |
1188 | CODE: |
1238 | CODE: |
1189 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1239 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1190 | |
1240 | |
1191 | void |
1241 | void |
1192 | set_indent (CFPlus::Layout self, int indent) |
1242 | set_indent (DC::Layout self, int indent) |
1193 | CODE: |
1243 | CODE: |
1194 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1244 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1195 | |
1245 | |
1196 | void |
1246 | void |
1197 | set_spacing (CFPlus::Layout self, int spacing) |
1247 | set_spacing (DC::Layout self, int spacing) |
1198 | CODE: |
1248 | CODE: |
1199 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1249 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1200 | |
1250 | |
1201 | void |
1251 | void |
1202 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1252 | set_ellipsise (DC::Layout self, int ellipsise) |
1203 | CODE: |
1253 | CODE: |
1204 | pango_layout_set_ellipsize (self->pl, |
1254 | pango_layout_set_ellipsize (self->pl, |
1205 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1255 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1206 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1256 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1207 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1257 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1208 | : PANGO_ELLIPSIZE_NONE |
1258 | : PANGO_ELLIPSIZE_NONE |
1209 | ); |
1259 | ); |
1210 | |
1260 | |
1211 | void |
1261 | void |
1212 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1262 | set_single_paragraph_mode (DC::Layout self, int spm) |
1213 | CODE: |
1263 | CODE: |
1214 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1264 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1215 | |
1265 | |
1216 | void |
1266 | void |
1217 | size (CFPlus::Layout self) |
1267 | size (DC::Layout self) |
1218 | PPCODE: |
1268 | PPCODE: |
1219 | { |
1269 | { |
1220 | int w, h; |
1270 | int w, h; |
1221 | |
1271 | |
1222 | layout_get_pixel_size (self, &w, &h); |
1272 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1225 | PUSHs (sv_2mortal (newSViv (w))); |
1275 | PUSHs (sv_2mortal (newSViv (w))); |
1226 | PUSHs (sv_2mortal (newSViv (h))); |
1276 | PUSHs (sv_2mortal (newSViv (h))); |
1227 | } |
1277 | } |
1228 | |
1278 | |
1229 | int |
1279 | int |
1230 | descent (CFPlus::Layout self) |
1280 | descent (DC::Layout self) |
1231 | CODE: |
1281 | CODE: |
1232 | { |
1282 | { |
1233 | PangoRectangle rect; |
1283 | PangoRectangle rect; |
1234 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1284 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1235 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1285 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
… | |
… | |
1237 | } |
1287 | } |
1238 | OUTPUT: |
1288 | OUTPUT: |
1239 | RETVAL |
1289 | RETVAL |
1240 | |
1290 | |
1241 | int |
1291 | int |
1242 | xy_to_index (CFPlus::Layout self, int x, int y) |
1292 | xy_to_index (DC::Layout self, int x, int y) |
1243 | CODE: |
1293 | CODE: |
1244 | { |
1294 | { |
1245 | int index, trailing; |
1295 | int index, trailing; |
1246 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1296 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1247 | RETVAL = index + trailing; |
1297 | RETVAL = index + trailing; |
1248 | } |
1298 | } |
1249 | OUTPUT: |
1299 | OUTPUT: |
1250 | RETVAL |
1300 | RETVAL |
1251 | |
1301 | |
1252 | void |
1302 | void |
1253 | cursor_pos (CFPlus::Layout self, int index) |
1303 | cursor_pos (DC::Layout self, int index) |
1254 | PPCODE: |
1304 | PPCODE: |
1255 | { |
1305 | { |
1256 | PangoRectangle strong_pos; |
1306 | PangoRectangle strong_pos; |
1257 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1307 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1258 | |
1308 | |
… | |
… | |
1261 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1311 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1262 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1312 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1263 | } |
1313 | } |
1264 | |
1314 | |
1265 | void |
1315 | void |
1266 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1316 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1267 | PPCODE: |
1317 | PPCODE: |
1268 | { |
1318 | { |
1269 | int line, x; |
1319 | int line, x; |
1270 | |
1320 | |
1271 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1321 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1322 | #if !PANGO_VERSION_CHECK (1, 17. 3) |
1272 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1323 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1273 | |
1324 | --line; |
|
|
1325 | #endif |
1274 | EXTEND (SP, 2); |
1326 | EXTEND (SP, 2); |
1275 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1327 | PUSHs (sv_2mortal (newSViv (line))); |
1276 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1328 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1277 | } |
1329 | } |
1278 | |
1330 | |
1279 | void |
1331 | void |
1280 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1332 | line_x_to_index (DC::Layout self, int line, int x) |
1281 | PPCODE: |
1333 | PPCODE: |
1282 | { |
1334 | { |
1283 | PangoLayoutLine *lp; |
1335 | PangoLayoutLine *lp; |
1284 | int index, trailing; |
1336 | int index, trailing; |
1285 | |
1337 | |
… | |
… | |
1300 | PUSHs (sv_2mortal (newSViv (trailing))); |
1352 | PUSHs (sv_2mortal (newSViv (trailing))); |
1301 | } |
1353 | } |
1302 | } |
1354 | } |
1303 | |
1355 | |
1304 | void |
1356 | void |
1305 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1357 | render (DC::Layout self, float x, float y, int flags = 0) |
1306 | PPCODE: |
1358 | CODE: |
|
|
1359 | rc_clear (self->rc); |
1307 | pango_opengl_render_layout_subpixel ( |
1360 | pango_opengl_render_layout_subpixel ( |
1308 | self->pl, |
1361 | self->pl, |
|
|
1362 | self->rc, |
1309 | x * PANGO_SCALE, y * PANGO_SCALE, |
1363 | x * PANGO_SCALE, y * PANGO_SCALE, |
1310 | self->r, self->g, self->b, self->a, |
1364 | self->r, self->g, self->b, self->a, |
1311 | flags |
1365 | flags |
1312 | ); |
1366 | ); |
|
|
1367 | // we assume that context_change actually clears/frees stuff |
|
|
1368 | // and does not do any recomputation... |
|
|
1369 | pango_layout_context_changed (self->pl); |
1313 | |
1370 | |
1314 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1371 | void |
|
|
1372 | draw (DC::Layout self) |
|
|
1373 | CODE: |
|
|
1374 | { |
|
|
1375 | glEnable (GL_TEXTURE_2D); |
|
|
1376 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1377 | glEnable (GL_BLEND); |
|
|
1378 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
1379 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
|
|
1380 | glEnable (GL_ALPHA_TEST); |
|
|
1381 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
|
|
1382 | |
|
|
1383 | rc_draw (self->rc); |
|
|
1384 | |
|
|
1385 | glDisable (GL_ALPHA_TEST); |
|
|
1386 | glDisable (GL_BLEND); |
|
|
1387 | glDisable (GL_TEXTURE_2D); |
|
|
1388 | } |
|
|
1389 | |
|
|
1390 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1315 | |
1391 | |
1316 | PROTOTYPES: ENABLE |
1392 | PROTOTYPES: ENABLE |
1317 | |
|
|
1318 | int minpot (int n) |
|
|
1319 | |
1393 | |
1320 | void |
1394 | void |
1321 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1395 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1322 | CODE: |
1396 | CODE: |
1323 | { |
1397 | { |
… | |
… | |
1400 | RETVAL = width > 0; |
1474 | RETVAL = width > 0; |
1401 | } |
1475 | } |
1402 | OUTPUT: |
1476 | OUTPUT: |
1403 | RETVAL |
1477 | RETVAL |
1404 | |
1478 | |
1405 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1479 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1406 | |
1480 | |
1407 | PROTOTYPES: DISABLE |
1481 | PROTOTYPES: DISABLE |
1408 | |
1482 | |
1409 | CFPlus::Map |
1483 | DC::Map |
1410 | new (SV *class) |
1484 | new (SV *class) |
1411 | CODE: |
1485 | CODE: |
1412 | New (0, RETVAL, 1, struct map); |
1486 | New (0, RETVAL, 1, struct map); |
1413 | RETVAL->x = 0; |
1487 | RETVAL->x = 0; |
1414 | RETVAL->y = 0; |
1488 | RETVAL->y = 0; |
… | |
… | |
1422 | RETVAL->row = 0; |
1496 | RETVAL->row = 0; |
1423 | OUTPUT: |
1497 | OUTPUT: |
1424 | RETVAL |
1498 | RETVAL |
1425 | |
1499 | |
1426 | void |
1500 | void |
1427 | DESTROY (CFPlus::Map self) |
1501 | DESTROY (DC::Map self) |
1428 | CODE: |
1502 | CODE: |
1429 | { |
1503 | { |
1430 | map_clear (self); |
1504 | map_clear (self); |
1431 | Safefree (self->face2tile); |
1505 | Safefree (self->face2tile); |
1432 | Safefree (self->tex); |
1506 | Safefree (self->tex); |
1433 | Safefree (self); |
1507 | Safefree (self); |
1434 | } |
1508 | } |
1435 | |
1509 | |
1436 | void |
1510 | void |
1437 | resize (CFPlus::Map self, int map_width, int map_height) |
1511 | resize (DC::Map self, int map_width, int map_height) |
1438 | CODE: |
1512 | CODE: |
1439 | self->w = map_width; |
1513 | self->w = map_width; |
1440 | self->h = map_height; |
1514 | self->h = map_height; |
1441 | |
1515 | |
1442 | void |
1516 | void |
1443 | clear (CFPlus::Map self) |
1517 | clear (DC::Map self) |
1444 | CODE: |
1518 | CODE: |
1445 | map_clear (self); |
1519 | map_clear (self); |
1446 | |
1520 | |
1447 | void |
1521 | void |
1448 | set_tileid (CFPlus::Map self, int face, int tile) |
1522 | set_tileid (DC::Map self, int face, int tile) |
1449 | CODE: |
1523 | CODE: |
1450 | { |
1524 | { |
1451 | need_facenum (self, face); self->face2tile [face] = tile; |
1525 | need_facenum (self, face); self->face2tile [face] = tile; |
1452 | need_texid (self, tile); |
1526 | need_texid (self, tile); |
1453 | } |
1527 | } |
1454 | |
1528 | |
1455 | void |
1529 | void |
1456 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1530 | set_smooth (DC::Map self, int face, int smooth, int level) |
1457 | CODE: |
1531 | CODE: |
1458 | { |
1532 | { |
1459 | tileid texid; |
1533 | tileid texid; |
1460 | maptex *tex; |
1534 | maptex *tex; |
1461 | |
1535 | |
… | |
… | |
1474 | tex->smoothtile = self->face2tile [smooth]; |
1548 | tex->smoothtile = self->face2tile [smooth]; |
1475 | tex->smoothlevel = level; |
1549 | tex->smoothlevel = level; |
1476 | } |
1550 | } |
1477 | |
1551 | |
1478 | void |
1552 | 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) |
1553 | 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: |
1554 | CODE: |
1481 | { |
1555 | { |
1482 | need_texid (self, texid); |
1556 | need_texid (self, texid); |
1483 | |
1557 | |
1484 | { |
1558 | { |
… | |
… | |
1504 | // from transparent color bleeding and ugly wrapping effects. |
1578 | // from transparent color bleeding and ugly wrapping effects. |
1505 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1579 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1506 | } |
1580 | } |
1507 | |
1581 | |
1508 | int |
1582 | int |
1509 | ox (CFPlus::Map self) |
1583 | ox (DC::Map self) |
1510 | ALIAS: |
1584 | ALIAS: |
1511 | oy = 1 |
1585 | oy = 1 |
1512 | x = 2 |
1586 | x = 2 |
1513 | y = 3 |
1587 | y = 3 |
1514 | w = 4 |
1588 | w = 4 |
… | |
… | |
1525 | } |
1599 | } |
1526 | OUTPUT: |
1600 | OUTPUT: |
1527 | RETVAL |
1601 | RETVAL |
1528 | |
1602 | |
1529 | void |
1603 | void |
1530 | scroll (CFPlus::Map self, int dx, int dy) |
1604 | scroll (DC::Map self, int dx, int dy) |
1531 | CODE: |
1605 | CODE: |
1532 | { |
1606 | { |
1533 | if (dx > 0) |
1607 | if (dx > 0) |
1534 | map_blank (self, self->x, self->y, dx, self->h); |
1608 | map_blank (self, self->x, self->y, dx, self->h); |
1535 | else if (dx < 0) |
1609 | else if (dx < 0) |
… | |
… | |
1550 | self->rows += MAP_EXTEND_Y; |
1624 | self->rows += MAP_EXTEND_Y; |
1551 | self->y += MAP_EXTEND_Y; |
1625 | self->y += MAP_EXTEND_Y; |
1552 | } |
1626 | } |
1553 | } |
1627 | } |
1554 | |
1628 | |
1555 | void |
1629 | SV * |
1556 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1630 | map1a_update (DC::Map self, SV *data_, int extmap) |
1557 | CODE: |
1631 | CODE: |
1558 | { |
1632 | { |
1559 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1633 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1560 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1634 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1561 | mapcell *cell; |
1635 | mapcell *cell; |
1562 | int x, y, flags; |
1636 | int x, y, z, flags; |
|
|
1637 | AV *missing = newAV (); |
|
|
1638 | RETVAL = newRV_noinc ((SV *)missing); |
1563 | |
1639 | |
1564 | while (data < data_end - 1) |
1640 | while (data < data_end - 1) |
1565 | { |
1641 | { |
1566 | flags = (data [0] << 8) + data [1]; data += 2; |
1642 | flags = (data [0] << 8) + data [1]; data += 2; |
1567 | |
1643 | |
… | |
… | |
1618 | } |
1694 | } |
1619 | else |
1695 | else |
1620 | cell->darkness = *data++ + 1; |
1696 | cell->darkness = *data++ + 1; |
1621 | } |
1697 | } |
1622 | |
1698 | |
|
|
1699 | for (z = 0; z <= 2; ++z) |
1623 | if (flags & 4) |
1700 | if (flags & (4 >> z)) |
1624 | { |
1701 | { |
1625 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1702 | faceid face = (data [0] << 8) + data [1]; data += 2; |
1626 | need_facenum (self, face); |
1703 | need_facenum (self, face); |
1627 | cell->tile [0] = self->face2tile [face]; |
1704 | cell->tile [z] = self->face2tile [face]; |
|
|
1705 | |
|
|
1706 | if (cell->tile [z]) |
|
|
1707 | { |
|
|
1708 | maptex *tex = self->tex + cell->tile [z]; |
|
|
1709 | if (!tex->name) |
|
|
1710 | av_push (missing, newSViv (cell->tile [z])); |
|
|
1711 | |
|
|
1712 | if (tex->smoothtile) |
|
|
1713 | { |
|
|
1714 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
1715 | if (!smooth->name) |
|
|
1716 | av_push (missing, newSViv (tex->smoothtile)); |
|
|
1717 | } |
|
|
1718 | } |
1628 | } |
1719 | } |
1629 | |
|
|
1630 | if (flags & 2) |
|
|
1631 | { |
|
|
1632 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1633 | need_facenum (self, face); |
|
|
1634 | cell->tile [1] = self->face2tile [face]; |
|
|
1635 | } |
|
|
1636 | |
|
|
1637 | if (flags & 1) |
|
|
1638 | { |
|
|
1639 | faceid face = (data [0] << 8) + data [1]; data += 2; |
|
|
1640 | need_facenum (self, face); |
|
|
1641 | cell->tile [2] = self->face2tile [face]; |
|
|
1642 | } |
|
|
1643 | } |
1720 | } |
1644 | else |
1721 | else |
1645 | cell->darkness = 0; |
1722 | cell->darkness = 0; |
1646 | } |
1723 | } |
1647 | } |
1724 | } |
|
|
1725 | OUTPUT: |
|
|
1726 | RETVAL |
1648 | |
1727 | |
1649 | SV * |
1728 | SV * |
1650 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1729 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1651 | CODE: |
1730 | CODE: |
1652 | { |
1731 | { |
1653 | int x1, x; |
1732 | int x1, x; |
1654 | int y1, y; |
1733 | int y1, y; |
1655 | int z; |
1734 | int z; |
… | |
… | |
1699 | RETVAL = map_sv; |
1778 | RETVAL = map_sv; |
1700 | } |
1779 | } |
1701 | OUTPUT: |
1780 | OUTPUT: |
1702 | RETVAL |
1781 | RETVAL |
1703 | |
1782 | |
1704 | SV * |
1783 | void |
1705 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1784 | draw (DC::Map self, int mx, int my, int sw, int sh, int T) |
1706 | CODE: |
1785 | CODE: |
1707 | { |
1786 | { |
|
|
1787 | int x, y, z; |
|
|
1788 | |
1708 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1789 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1709 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1790 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1710 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1791 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
1711 | smooth_key skey; |
1792 | smooth_key skey; |
1712 | int x, y, z; |
1793 | |
1713 | int last_name; |
1794 | rc_t *rc = rc_alloc (); |
1714 | AV *missing = newAV (); |
1795 | rc_key_t key; |
1715 | RETVAL = newRV_noinc ((SV *)missing); |
1796 | rc_array_t *arr; |
1716 | |
1797 | |
1717 | // thats current max. sorry. |
1798 | // thats current max. sorry. |
1718 | if (sw > 255) sw = 255; |
1799 | if (sw > 255) sw = 255; |
1719 | if (sh > 255) sh = 255; |
1800 | if (sh > 255) sh = 255; |
1720 | |
1801 | |
1721 | // clear key, in case of extra padding |
1802 | // clear key, in case of extra padding |
1722 | memset (&skey, 0, sizeof (skey)); |
1803 | memset (&skey, 0, sizeof (skey)); |
1723 | |
1804 | |
1724 | glColor4ub (255, 255, 255, 255); |
1805 | memset (&key, 0, sizeof (key)); |
1725 | |
1806 | key.r = 255; |
1726 | glEnable (GL_BLEND); |
1807 | key.g = 255; |
1727 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1808 | key.b = 255; |
1728 | glEnable (GL_TEXTURE_2D); |
1809 | key.a = 255; |
1729 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1810 | key.mode = GL_QUADS; |
1730 | |
1811 | key.format = GL_T2F_V3F; |
1731 | glBegin (GL_QUADS); |
|
|
1732 | |
|
|
1733 | last_name = -1; |
1812 | key.texname = -1; |
1734 | |
1813 | |
1735 | mx += self->x; |
1814 | mx += self->x; |
1736 | my += self->y; |
1815 | my += self->y; |
1737 | |
1816 | |
1738 | // first pass: determine smooth_max |
1817 | // first pass: determine smooth_max |
… | |
… | |
1754 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1833 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1755 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1834 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1756 | self->tex [cell->tile [2]].smoothlevel)); |
1835 | self->tex [cell->tile [2]].smoothlevel)); |
1757 | } |
1836 | } |
1758 | } |
1837 | } |
|
|
1838 | |
|
|
1839 | glEnable (GL_BLEND); |
|
|
1840 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1841 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1759 | |
1842 | |
1760 | for (z = 0; z <= 2; z++) |
1843 | for (z = 0; z <= 2; z++) |
1761 | { |
1844 | { |
1762 | memset (smooth_level, 0, sizeof (smooth_level)); |
1845 | memset (smooth_level, 0, sizeof (smooth_level)); |
1763 | |
1846 | |
… | |
… | |
1775 | if (tile) |
1858 | if (tile) |
1776 | { |
1859 | { |
1777 | maptex tex = self->tex [tile]; |
1860 | maptex tex = self->tex [tile]; |
1778 | int px, py; |
1861 | int px, py; |
1779 | |
1862 | |
1780 | // suppressing texture state switches here |
|
|
1781 | // is only moderately effective, but worth the extra effort |
|
|
1782 | if (last_name != tex.name) |
1863 | if (key.texname != tex.name) |
1783 | { |
1864 | { |
1784 | if (!tex.name) |
1865 | if (!tex.name) |
1785 | { |
|
|
1786 | av_push (missing, newSViv (tile)); |
|
|
1787 | tex = self->tex [2]; /* missing, replace by noface */ |
1866 | tex = self->tex [2]; /* missing, replace by noface */ |
1788 | } |
|
|
1789 | |
1867 | |
1790 | glEnd (); |
1868 | key.texname = tex.name; |
1791 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1869 | arr = rc_array (rc, &key); |
1792 | glBegin (GL_QUADS); |
|
|
1793 | } |
1870 | } |
1794 | |
1871 | |
1795 | px = (x + 1) * T - tex.w; |
1872 | px = (x + 1) * T - tex.w; |
1796 | py = (y + 1) * T - tex.h; |
1873 | py = (y + 1) * T - tex.h; |
1797 | |
1874 | |
1798 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1875 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
1799 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1876 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
1800 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1877 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
1801 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1878 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1802 | |
1879 | |
1803 | if (cell->flags && z == 2) |
1880 | if (cell->flags && z == 2) |
1804 | { |
1881 | { |
|
|
1882 | // overlays such as the speech bubble, probably more to come |
1805 | if (cell->flags & 1) |
1883 | if (cell->flags & 1) |
1806 | { |
1884 | { |
1807 | maptex tex = self->tex [1]; |
1885 | maptex tex = self->tex [1]; |
1808 | int px = x * T + T * 2 / 32; |
1886 | int px = x * T + T * 2 / 32; |
1809 | int py = y * T - T * 6 / 32; |
1887 | int py = y * T - T * 6 / 32; |
1810 | |
1888 | |
|
|
1889 | if (tex.name) |
1811 | glEnd (); |
1890 | { |
1812 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1891 | if (key.texname != tex.name) |
|
|
1892 | { |
|
|
1893 | key.texname = tex.name; |
|
|
1894 | arr = rc_array (rc, &key); |
|
|
1895 | } |
|
|
1896 | |
|
|
1897 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1898 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1899 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1900 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
1813 | glBegin (GL_QUADS); |
1901 | } |
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 | } |
1902 | } |
1820 | } |
1903 | } |
1821 | |
1904 | |
1822 | // update smooth hash |
1905 | // update smooth hash |
1823 | if (tex.smoothtile) |
1906 | if (tex.smoothtile) |
… | |
… | |
1859 | } |
1942 | } |
1860 | } |
1943 | } |
1861 | } |
1944 | } |
1862 | } |
1945 | } |
1863 | |
1946 | |
|
|
1947 | rc_draw (rc); |
|
|
1948 | rc_clear (rc); |
|
|
1949 | |
1864 | // go through all smoothlevels, lowest to highest, then draw. |
1950 | // go through all smoothlevels, lowest to highest, then draw. |
1865 | // this is basically counting sort |
1951 | // this is basically counting sort |
1866 | { |
1952 | { |
1867 | int w, b; |
1953 | int w, b; |
1868 | |
1954 | |
|
|
1955 | glEnable (GL_TEXTURE_2D); |
|
|
1956 | glBegin (GL_QUADS); |
1869 | for (w = 0; w < 256 / 32; ++w) |
1957 | for (w = 0; w < 256 / 32; ++w) |
1870 | { |
1958 | { |
1871 | uint32_t smask = smooth_level [w]; |
1959 | uint32_t smask = smooth_level [w]; |
1872 | if (smask) |
1960 | if (smask) |
1873 | for (b = 0; b < 32; ++b) |
1961 | for (b = 0; b < 32; ++b) |
… | |
… | |
1892 | int border = bits & 15; |
1980 | int border = bits & 15; |
1893 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1981 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1894 | float dx = tex.s * .0625f; // 16 images/row |
1982 | float dx = tex.s * .0625f; // 16 images/row |
1895 | float dy = tex.t * .5f ; // 2 images/column |
1983 | float dy = tex.t * .5f ; // 2 images/column |
1896 | |
1984 | |
1897 | // this time naively avoiding texture state changes |
|
|
1898 | // save gobs of state changes. |
|
|
1899 | if (last_name != tex.name) |
1985 | if (tex.name) |
1900 | { |
1986 | { |
|
|
1987 | // this time avoiding texture state changes |
|
|
1988 | // save gobs of state changes. |
1901 | if (!tex.name) |
1989 | if (key.texname != tex.name) |
1902 | { |
1990 | { |
1903 | av_push (missing, newSViv (skey->tile)); |
1991 | glEnd (); |
1904 | continue; // smoothing not yet available |
1992 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
|
|
1993 | glBegin (GL_QUADS); |
1905 | } |
1994 | } |
1906 | |
1995 | |
1907 | glEnd (); |
|
|
1908 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1909 | glBegin (GL_QUADS); |
|
|
1910 | } |
|
|
1911 | |
|
|
1912 | if (border) |
1996 | if (border) |
1913 | { |
1997 | { |
1914 | float ox = border * dx; |
1998 | float ox = border * dx; |
1915 | |
1999 | |
1916 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
2000 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1917 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
2001 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
1918 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
2002 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
1919 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
2003 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
1920 | } |
2004 | } |
1921 | |
2005 | |
1922 | if (corner) |
2006 | if (corner) |
1923 | { |
2007 | { |
1924 | float ox = corner * dx; |
2008 | float ox = corner * dx; |
1925 | |
2009 | |
1926 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
2010 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1927 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
2011 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
1928 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
2012 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
1929 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
2013 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
|
|
2014 | } |
1930 | } |
2015 | } |
1931 | } |
2016 | } |
1932 | } |
2017 | } |
1933 | } |
2018 | } |
1934 | } |
2019 | } |
|
|
2020 | |
|
|
2021 | glEnd (); |
|
|
2022 | glDisable (GL_TEXTURE_2D); |
|
|
2023 | key.texname = -1; |
1935 | } |
2024 | } |
1936 | |
2025 | |
1937 | hv_clear (smooth); |
2026 | hv_clear (smooth); |
1938 | } |
2027 | } |
1939 | |
2028 | |
1940 | glEnd (); |
|
|
1941 | |
|
|
1942 | glDisable (GL_TEXTURE_2D); |
|
|
1943 | glDisable (GL_BLEND); |
2029 | glDisable (GL_BLEND); |
|
|
2030 | rc_free (rc); |
1944 | |
2031 | |
1945 | // top layer: overlays such as the health bar |
2032 | // top layer: overlays such as the health bar |
1946 | for (y = 0; y < sh; y++) |
2033 | for (y = 0; y < sh; y++) |
1947 | if (0 <= y + my && y + my < self->rows) |
2034 | if (0 <= y + my && y + my < self->rows) |
1948 | { |
2035 | { |
… | |
… | |
1971 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
2058 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
1972 | } |
2059 | } |
1973 | } |
2060 | } |
1974 | } |
2061 | } |
1975 | } |
2062 | } |
1976 | OUTPUT: |
|
|
1977 | RETVAL |
|
|
1978 | |
2063 | |
1979 | void |
2064 | void |
1980 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2065 | draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1981 | CODE: |
2066 | CODE: |
1982 | { |
2067 | { |
1983 | static float color[16][3] = { |
2068 | static float color[16][3] = { |
1984 | { 0.00F, 0.00F, 0.00F }, |
2069 | { 0.00F, 0.00F, 0.00F }, |
1985 | { 1.00F, 1.00F, 1.00F }, |
2070 | { 1.00F, 1.00F, 1.00F }, |
… | |
… | |
2035 | glDisable (GL_BLEND); |
2120 | glDisable (GL_BLEND); |
2036 | glDisable (GL_TEXTURE_2D); |
2121 | glDisable (GL_TEXTURE_2D); |
2037 | } |
2122 | } |
2038 | |
2123 | |
2039 | void |
2124 | void |
2040 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2125 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2041 | PPCODE: |
2126 | PPCODE: |
2042 | { |
2127 | { |
2043 | int x, y; |
2128 | int x, y; |
2044 | int sw1 = sw + 2; |
2129 | int sw1 = sw + 2; |
2045 | int sh1 = sh + 2; |
2130 | int sh1 = sh + 2; |
… | |
… | |
2116 | PUSHs (sv_2mortal (newSViv (sh3))); |
2201 | PUSHs (sv_2mortal (newSViv (sh3))); |
2117 | PUSHs (darkness3_sv); |
2202 | PUSHs (darkness3_sv); |
2118 | } |
2203 | } |
2119 | |
2204 | |
2120 | SV * |
2205 | SV * |
2121 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2206 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2122 | CODE: |
2207 | CODE: |
2123 | { |
2208 | { |
2124 | int x, y, x1, y1; |
2209 | int x, y, x1, y1; |
2125 | SV *data_sv = newSV (w * h * 7 + 5); |
2210 | SV *data_sv = newSV (w * h * 7 + 5); |
2126 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2211 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2191 | } |
2276 | } |
2192 | OUTPUT: |
2277 | OUTPUT: |
2193 | RETVAL |
2278 | RETVAL |
2194 | |
2279 | |
2195 | void |
2280 | void |
2196 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2281 | set_rect (DC::Map self, int x0, int y0, uint8_t *data) |
2197 | PPCODE: |
2282 | PPCODE: |
2198 | { |
2283 | { |
2199 | int x, y, z; |
2284 | int x, y, z; |
2200 | int w, h; |
2285 | int w, h; |
2201 | int x1, y1; |
2286 | int x1, y1; |
2202 | |
2287 | |
2203 | if (*data++ != 0) |
2288 | if (*data++ != 0) |
2204 | return; /* version mismatch */ |
2289 | XSRETURN_EMPTY; /* version mismatch */ |
2205 | |
2290 | |
2206 | w = *data++ << 8; w |= *data++; |
2291 | w = *data++ << 8; w |= *data++; |
2207 | h = *data++ << 8; h |= *data++; |
2292 | h = *data++ << 8; h |= *data++; |
2208 | |
2293 | |
2209 | // we need to do this 'cause we don't keep an absolute coord system for rows |
2294 | // we need to do this 'cause we don't keep an absolute coord system for rows |
… | |
… | |
2254 | } |
2339 | } |
2255 | } |
2340 | } |
2256 | } |
2341 | } |
2257 | } |
2342 | } |
2258 | |
2343 | |
2259 | MODULE = CFPlus PACKAGE = CFPlus::RW |
2344 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2260 | |
2345 | |
2261 | CFPlus::RW |
2346 | DC::RW |
2262 | new (SV *class, SV *data_sv) |
2347 | new (SV *class, SV *data_sv) |
2263 | CODE: |
2348 | CODE: |
2264 | { |
2349 | { |
2265 | STRLEN datalen; |
2350 | STRLEN datalen; |
2266 | char *data = SvPVbyte (data_sv, datalen); |
2351 | char *data = SvPVbyte (data_sv, datalen); |
… | |
… | |
2268 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2353 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2269 | } |
2354 | } |
2270 | OUTPUT: |
2355 | OUTPUT: |
2271 | RETVAL |
2356 | RETVAL |
2272 | |
2357 | |
2273 | CFPlus::RW |
2358 | DC::RW |
2274 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2359 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2275 | CODE: |
2360 | CODE: |
2276 | RETVAL = SDL_RWFromFile (path, mode); |
2361 | RETVAL = SDL_RWFromFile (path, mode); |
2277 | OUTPUT: |
2362 | OUTPUT: |
2278 | RETVAL |
2363 | RETVAL |
2279 | |
2364 | |
2280 | # fails on win32: |
2365 | # fails on win32: |
2281 | # CFPlus.xs(2268) : error C2059: syntax error : '(' |
2366 | # dc.xs(2268) : error C2059: syntax error : '(' |
2282 | #void |
2367 | #void |
2283 | #close (CFPlus::RW self) |
2368 | #close (DC::RW self) |
2284 | # CODE: |
2369 | # CODE: |
2285 | # (self->(close)) (self); |
2370 | # (self->(close)) (self); |
2286 | |
2371 | |
2287 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2372 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
2288 | |
2373 | |
2289 | PROTOTYPES: DISABLE |
2374 | PROTOTYPES: DISABLE |
2290 | |
2375 | |
2291 | CFPlus::Channel |
2376 | DC::Channel |
2292 | find () |
2377 | find () |
2293 | CODE: |
2378 | CODE: |
2294 | { |
2379 | { |
2295 | RETVAL = Mix_GroupAvailable (-1); |
2380 | RETVAL = Mix_GroupAvailable (-1); |
2296 | |
2381 | |
… | |
… | |
2309 | } |
2394 | } |
2310 | OUTPUT: |
2395 | OUTPUT: |
2311 | RETVAL |
2396 | RETVAL |
2312 | |
2397 | |
2313 | void |
2398 | void |
2314 | halt (CFPlus::Channel self) |
2399 | halt (DC::Channel self) |
2315 | CODE: |
2400 | CODE: |
2316 | Mix_HaltChannel (self); |
2401 | Mix_HaltChannel (self); |
2317 | |
2402 | |
2318 | void |
2403 | void |
2319 | expire (CFPlus::Channel self, int ticks = -1) |
2404 | expire (DC::Channel self, int ticks = -1) |
2320 | CODE: |
2405 | CODE: |
2321 | Mix_ExpireChannel (self, ticks); |
2406 | Mix_ExpireChannel (self, ticks); |
2322 | |
2407 | |
2323 | void |
2408 | void |
2324 | fade_out (CFPlus::Channel self, int ticks = -1) |
2409 | fade_out (DC::Channel self, int ticks = -1) |
2325 | CODE: |
2410 | CODE: |
2326 | Mix_FadeOutChannel (self, ticks); |
2411 | Mix_FadeOutChannel (self, ticks); |
2327 | |
2412 | |
2328 | int |
2413 | int |
2329 | volume (CFPlus::Channel self, int volume) |
2414 | volume (DC::Channel self, int volume) |
2330 | CODE: |
2415 | CODE: |
2331 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2416 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2332 | OUTPUT: |
2417 | OUTPUT: |
2333 | RETVAL |
2418 | RETVAL |
2334 | |
2419 | |
2335 | void |
2420 | void |
2336 | unregister_all_effects (CFPlus::Channel self) |
2421 | unregister_all_effects (DC::Channel self) |
2337 | CODE: |
2422 | CODE: |
2338 | Mix_UnregisterAllEffects (self); |
2423 | Mix_UnregisterAllEffects (self); |
2339 | |
2424 | |
2340 | void |
2425 | void |
2341 | set_panning (CFPlus::Channel self, int left, int right) |
2426 | set_panning (DC::Channel self, int left, int right) |
2342 | CODE: |
2427 | CODE: |
2343 | left = CLAMP (left , 0, 255); |
2428 | left = CLAMP (left , 0, 255); |
2344 | right = CLAMP (right, 0, 255); |
2429 | right = CLAMP (right, 0, 255); |
2345 | Mix_SetPanning (self, left, right); |
2430 | Mix_SetPanning (self, left, right); |
2346 | |
2431 | |
2347 | void |
2432 | void |
2348 | set_distance (CFPlus::Channel self, int distance) |
2433 | set_distance (DC::Channel self, int distance) |
2349 | CODE: |
2434 | CODE: |
2350 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2435 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2351 | |
2436 | |
2352 | void |
2437 | void |
2353 | set_position (CFPlus::Channel self, int angle, int distance) |
2438 | set_position (DC::Channel self, int angle, int distance) |
2354 | CODE: |
2439 | CODE: |
|
|
2440 | |
|
|
2441 | void |
|
|
2442 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
|
|
2443 | CODE: |
|
|
2444 | { |
|
|
2445 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
|
|
2446 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2355 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2447 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
|
|
2448 | } |
2356 | |
2449 | |
2357 | void |
2450 | void |
2358 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2451 | set_reverse_stereo (DC::Channel self, int flip) |
2359 | CODE: |
2452 | CODE: |
2360 | Mix_SetReverseStereo (self, flip); |
2453 | Mix_SetReverseStereo (self, flip); |
2361 | |
2454 | |
2362 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2455 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
2363 | |
2456 | |
2364 | PROTOTYPES: DISABLE |
2457 | PROTOTYPES: DISABLE |
2365 | |
2458 | |
2366 | CFPlus::MixChunk |
2459 | DC::MixChunk |
2367 | new (SV *class, CFPlus::RW rwops) |
2460 | new (SV *class, DC::RW rwops) |
2368 | CODE: |
2461 | CODE: |
2369 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2462 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2370 | OUTPUT: |
2463 | OUTPUT: |
2371 | RETVAL |
2464 | RETVAL |
2372 | |
2465 | |
2373 | void |
2466 | void |
2374 | DESTROY (CFPlus::MixChunk self) |
2467 | DESTROY (DC::MixChunk self) |
2375 | CODE: |
2468 | CODE: |
2376 | Mix_FreeChunk (self); |
2469 | Mix_FreeChunk (self); |
2377 | |
2470 | |
2378 | int |
2471 | int |
2379 | volume (CFPlus::MixChunk self, int volume = -1) |
2472 | volume (DC::MixChunk self, int volume = -1) |
2380 | CODE: |
2473 | CODE: |
2381 | if (items > 1) |
2474 | if (items > 1) |
2382 | volume = CLAMP (volume, 0, 128); |
2475 | volume = CLAMP (volume, 0, 128); |
2383 | RETVAL = Mix_VolumeChunk (self, volume); |
2476 | RETVAL = Mix_VolumeChunk (self, volume); |
2384 | OUTPUT: |
2477 | OUTPUT: |
2385 | RETVAL |
2478 | RETVAL |
2386 | |
2479 | |
2387 | CFPlus::Channel |
2480 | DC::Channel |
2388 | play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) |
2481 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2389 | CODE: |
2482 | CODE: |
2390 | { |
2483 | { |
2391 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2484 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2392 | |
2485 | |
2393 | if (RETVAL < 0) |
2486 | if (RETVAL < 0) |
… | |
… | |
2400 | } |
2493 | } |
2401 | } |
2494 | } |
2402 | OUTPUT: |
2495 | OUTPUT: |
2403 | RETVAL |
2496 | RETVAL |
2404 | |
2497 | |
2405 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2498 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
2406 | |
2499 | |
2407 | int |
2500 | int |
2408 | volume (int volume = -1) |
2501 | volume (int volume = -1) |
2409 | PROTOTYPE: ;$ |
2502 | PROTOTYPE: ;$ |
2410 | CODE: |
2503 | CODE: |
… | |
… | |
2422 | void |
2515 | void |
2423 | halt () |
2516 | halt () |
2424 | CODE: |
2517 | CODE: |
2425 | Mix_HaltMusic (); |
2518 | Mix_HaltMusic (); |
2426 | |
2519 | |
2427 | CFPlus::MixMusic |
2520 | DC::MixMusic |
2428 | new (SV *class, CFPlus::RW rwops) |
2521 | new (SV *class, DC::RW rwops) |
2429 | CODE: |
2522 | CODE: |
2430 | RETVAL = Mix_LoadMUS_RW (rwops); |
2523 | RETVAL = Mix_LoadMUS_RW (rwops); |
2431 | OUTPUT: |
2524 | OUTPUT: |
2432 | RETVAL |
2525 | RETVAL |
2433 | |
2526 | |
2434 | void |
2527 | void |
2435 | DESTROY (CFPlus::MixMusic self) |
2528 | DESTROY (DC::MixMusic self) |
2436 | CODE: |
2529 | CODE: |
2437 | Mix_FreeMusic (self); |
2530 | Mix_FreeMusic (self); |
2438 | |
2531 | |
2439 | int |
2532 | int |
2440 | play (CFPlus::MixMusic self, int loops = -1) |
2533 | play (DC::MixMusic self, int loops = -1) |
2441 | CODE: |
2534 | CODE: |
2442 | RETVAL = Mix_PlayMusic (self, loops); |
2535 | RETVAL = Mix_PlayMusic (self, loops); |
2443 | OUTPUT: |
2536 | OUTPUT: |
2444 | RETVAL |
2537 | RETVAL |
2445 | |
2538 | |
2446 | void |
2539 | void |
2447 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
2540 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2448 | CODE: |
2541 | CODE: |
2449 | Mix_FadeInMusicPos (self, loops, ms, position); |
2542 | Mix_FadeInMusicPos (self, loops, ms, position); |
2450 | |
2543 | |
2451 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
2544 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2452 | |
2545 | |
2453 | PROTOTYPES: ENABLE |
2546 | PROTOTYPES: ENABLE |
2454 | |
2547 | |
2455 | BOOT: |
2548 | BOOT: |
2456 | { |
2549 | { |
2457 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
2550 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2458 | static const struct { |
2551 | static const struct { |
2459 | const char *name; |
2552 | const char *name; |
2460 | IV iv; |
2553 | IV iv; |
2461 | } *civ, const_iv[] = { |
2554 | } *civ, const_iv[] = { |
2462 | # define const_iv(name) { # name, (IV)name } |
2555 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
2497 | const_iv (GL_INTENSITY), |
2590 | const_iv (GL_INTENSITY), |
2498 | const_iv (GL_LUMINANCE), |
2591 | const_iv (GL_LUMINANCE), |
2499 | const_iv (GL_LUMINANCE_ALPHA), |
2592 | const_iv (GL_LUMINANCE_ALPHA), |
2500 | const_iv (GL_FLOAT), |
2593 | const_iv (GL_FLOAT), |
2501 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
2594 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
2595 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
2596 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
2597 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
2598 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
2599 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
2600 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2502 | const_iv (GL_COMPILE), |
2601 | const_iv (GL_COMPILE), |
2503 | const_iv (GL_PROXY_TEXTURE_1D), |
2602 | const_iv (GL_PROXY_TEXTURE_1D), |
2504 | const_iv (GL_PROXY_TEXTURE_2D), |
2603 | const_iv (GL_PROXY_TEXTURE_2D), |
2505 | const_iv (GL_TEXTURE_1D), |
2604 | const_iv (GL_TEXTURE_1D), |
2506 | const_iv (GL_TEXTURE_2D), |
2605 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2545 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2644 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2546 | const_iv (GL_POINT_SMOOTH_HINT), |
2645 | const_iv (GL_POINT_SMOOTH_HINT), |
2547 | const_iv (GL_LINE_SMOOTH_HINT), |
2646 | const_iv (GL_LINE_SMOOTH_HINT), |
2548 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2647 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2549 | const_iv (GL_GENERATE_MIPMAP_HINT), |
2648 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
2649 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2550 | const_iv (GL_FASTEST), |
2650 | const_iv (GL_FASTEST), |
2551 | const_iv (GL_DONT_CARE), |
2651 | const_iv (GL_DONT_CARE), |
2552 | const_iv (GL_NICEST), |
2652 | const_iv (GL_NICEST), |
2553 | const_iv (GL_V2F), |
2653 | const_iv (GL_V2F), |
2554 | const_iv (GL_V3F), |
2654 | const_iv (GL_V3F), |
… | |
… | |
2562 | |
2662 | |
2563 | texture_av = newAV (); |
2663 | texture_av = newAV (); |
2564 | AvREAL_off (texture_av); |
2664 | AvREAL_off (texture_av); |
2565 | } |
2665 | } |
2566 | |
2666 | |
|
|
2667 | void |
|
|
2668 | disable_GL_EXT_blend_func_separate () |
|
|
2669 | CODE: |
|
|
2670 | gl.BlendFuncSeparate = 0; |
|
|
2671 | gl.BlendFuncSeparateEXT = 0; |
|
|
2672 | |
2567 | char * |
2673 | char * |
2568 | gl_vendor () |
2674 | gl_vendor () |
2569 | CODE: |
2675 | CODE: |
2570 | RETVAL = (char *)glGetString (GL_VENDOR); |
2676 | RETVAL = (char *)glGetString (GL_VENDOR); |
2571 | OUTPUT: |
2677 | OUTPUT: |
… | |
… | |
2692 | |
2798 | |
2693 | void glRect (float x1, float y1, float x2, float y2) |
2799 | void glRect (float x1, float y1, float x2, float y2) |
2694 | CODE: |
2800 | CODE: |
2695 | glRectf (x1, y1, x2, y2); |
2801 | glRectf (x1, y1, x2, y2); |
2696 | |
2802 | |
|
|
2803 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
2804 | CODE: |
|
|
2805 | glBegin (GL_LINE_LOOP); |
|
|
2806 | glVertex2f (x1, y1); |
|
|
2807 | glVertex2f (x2, y1); |
|
|
2808 | glVertex2f (x2, y2); |
|
|
2809 | glVertex2f (x1, y2); |
|
|
2810 | glEnd (); |
|
|
2811 | |
2697 | PROTOTYPES: ENABLE |
2812 | PROTOTYPES: ENABLE |
2698 | |
2813 | |
2699 | void glBegin (int mode) |
2814 | void glBegin (int mode) |
2700 | |
2815 | |
2701 | void glEnd () |
2816 | void glEnd () |
… | |
… | |
2733 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2848 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2734 | CODE: |
2849 | CODE: |
2735 | if (gl.SeparableFilter2D) |
2850 | if (gl.SeparableFilter2D) |
2736 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2851 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2737 | |
2852 | |
2738 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
2853 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2739 | |
2854 | |
2740 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2855 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2741 | |
2856 | |
2742 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2857 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2743 | |
2858 | |
… | |
… | |
2769 | |
2884 | |
2770 | void glEndList () |
2885 | void glEndList () |
2771 | |
2886 | |
2772 | void glCallList (int list) |
2887 | void glCallList (int list) |
2773 | |
2888 | |
2774 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
2889 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2775 | |
2890 | |
2776 | PROTOTYPES: DISABLE |
2891 | PROTOTYPES: DISABLE |
2777 | |
2892 | |
2778 | void |
2893 | void |
2779 | find_widget (SV *self, NV x, NV y) |
2894 | find_widget (SV *self, NV x, NV y) |
… | |
… | |
2783 | XPUSHs (self); |
2898 | XPUSHs (self); |
2784 | } |
2899 | } |
2785 | |
2900 | |
2786 | BOOT: |
2901 | BOOT: |
2787 | { |
2902 | { |
2788 | hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); |
2903 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
2789 | |
2904 | |
2790 | draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); |
2905 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
2791 | draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); |
2906 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
2792 | draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); |
2907 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
2793 | draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); |
2908 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
2794 | } |
2909 | } |
2795 | |
2910 | |
2796 | void |
2911 | void |
2797 | draw (SV *self) |
2912 | draw (SV *self) |
2798 | CODE: |
2913 | CODE: |
… | |
… | |
2802 | NV x, y, w, h; |
2917 | NV x, y, w, h; |
2803 | SV *draw_x_sv = GvSV (draw_x_gv); |
2918 | SV *draw_x_sv = GvSV (draw_x_gv); |
2804 | SV *draw_y_sv = GvSV (draw_y_gv); |
2919 | SV *draw_y_sv = GvSV (draw_y_gv); |
2805 | SV *draw_w_sv = GvSV (draw_w_gv); |
2920 | SV *draw_w_sv = GvSV (draw_w_gv); |
2806 | SV *draw_h_sv = GvSV (draw_h_gv); |
2921 | SV *draw_h_sv = GvSV (draw_h_gv); |
2807 | SV *hover; |
|
|
2808 | double draw_x, draw_y, draw_w, draw_h; |
2922 | double draw_x, draw_y; |
2809 | |
2923 | |
2810 | if (!SvROK (self)) |
2924 | if (!SvROK (self)) |
2811 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
2925 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
2812 | |
2926 | |
2813 | hv = (HV *)SvRV (self); |
2927 | hv = (HV *)SvRV (self); |
2814 | |
2928 | |
2815 | if (SvTYPE (hv) != SVt_PVHV) |
2929 | if (SvTYPE (hv) != SVt_PVHV) |
2816 | croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2930 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2817 | |
2931 | |
2818 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2932 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2819 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2933 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2820 | |
2934 | |
2821 | if (!h || !w) |
2935 | if (!h || !w) |
… | |
… | |
2841 | { |
2955 | { |
2842 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2956 | svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); |
2843 | |
2957 | |
2844 | if (svp && SvTRUE (*svp)) |
2958 | if (svp && SvTRUE (*svp)) |
2845 | { |
2959 | { |
2846 | glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); |
2960 | glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f); |
2847 | glEnable (GL_BLEND); |
2961 | glEnable (GL_BLEND); |
2848 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2962 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
2849 | glBegin (GL_QUADS); |
2963 | glBegin (GL_QUADS); |
2850 | glVertex2f (0, 0); |
2964 | glVertex2f (0, 0); |
2851 | glVertex2f (w, 0); |
2965 | glVertex2f (w, 0); |
… | |
… | |
2854 | glEnd (); |
2968 | glEnd (); |
2855 | glDisable (GL_BLEND); |
2969 | glDisable (GL_BLEND); |
2856 | } |
2970 | } |
2857 | } |
2971 | } |
2858 | #if 0 |
2972 | #if 0 |
2859 | if ($ENV{CFPLUS_DEBUG} & 1) { |
2973 | // draw borders, for debugging |
2860 | glPushMatrix; |
2974 | glPushMatrix (); |
2861 | glColor 1, 1, 0, 1; |
2975 | glColor4f (1., 1., 0., 1.); |
2862 | glTranslate 0.375, 0.375; |
2976 | glTranslatef (.5, .5, 0.); |
2863 | glBegin GL_LINE_LOOP; |
2977 | glBegin (GL_LINE_LOOP); |
2864 | glVertex 0 , 0; |
2978 | glVertex2f (0 , 0); |
2865 | glVertex $self->{w} - 1, 0; |
2979 | glVertex2f (w - 1, 0); |
2866 | glVertex $self->{w} - 1, $self->{h} - 1; |
2980 | glVertex2f (w - 1, h - 1); |
2867 | glVertex 0 , $self->{h} - 1; |
2981 | glVertex2f (0 , h - 1); |
2868 | glEnd; |
2982 | glEnd (); |
2869 | glPopMatrix; |
2983 | glPopMatrix (); |
2870 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2871 | } |
|
|
2872 | #endif |
2984 | #endif |
2873 | PUSHMARK (SP); |
2985 | PUSHMARK (SP); |
2874 | XPUSHs (self); |
2986 | XPUSHs (self); |
2875 | PUTBACK; |
2987 | PUTBACK; |
2876 | call_method ("_draw", G_VOID | G_DISCARD); |
2988 | call_method ("_draw", G_VOID | G_DISCARD); |