ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.128 by root, Wed Jul 5 03:01:01 2006 UTC vs.
Revision 1.133 by root, Sun Jul 30 13:16:44 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2# define WIN32_LEAN_AND_MEAN
2# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
3# include <malloc.h> 4# include <malloc.h>
4# include <windows.h> 5# include <windows.h>
5# pragma warning(disable:4244) 6# pragma warning(disable:4244)
6#endif 7#endif
7 8
8#include "EXTERN.h" 9#include "EXTERN.h"
9#include "perl.h" 10#include "perl.h"
10#include "XSUB.h" 11#include "XSUB.h"
12
13#ifdef _WIN32
14# undef pipe
15#endif
11 16
12#include <math.h> 17#include <math.h>
13#include <string.h> 18#include <string.h>
14#include <stdio.h> 19#include <stdio.h>
15#include <stdlib.h> 20#include <stdlib.h>
40 typedef signed char int8_t; 45 typedef signed char int8_t;
41 typedef signed short int16_t; 46 typedef signed short int16_t;
42 typedef signed int int32_t; 47 typedef signed int int32_t;
43#endif 48#endif
44 49
45#include "glext.h"
46
47#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 50#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */
48 51
49#define FOW_DARKNESS 32 52#define FOW_DARKNESS 32
50 53
51#define MAP_EXTEND_X 32 54#define MAP_EXTEND_X 32
80 83
81#include "pango-font.c" 84#include "pango-font.c"
82#include "pango-fontmap.c" 85#include "pango-fontmap.c"
83#include "pango-render.c" 86#include "pango-render.c"
84 87
85typedef Mix_Chunk *CFClient__MixChunk; 88typedef Mix_Chunk *CFPlus__MixChunk;
86typedef Mix_Music *CFClient__MixMusic; 89typedef Mix_Music *CFPlus__MixMusic;
87 90
88typedef PangoFontDescription *CFClient__Font; 91typedef PangoFontDescription *CFPlus__Font;
89 92
90static int 93static int
91shape_attr_p (PangoLayoutRun *run) 94shape_attr_p (PangoLayoutRun *run)
92{ 95{
93 GSList *attrs = run->item->analysis.extra_attrs; 96 GSList *attrs = run->item->analysis.extra_attrs;
107 110
108typedef struct cf_layout { 111typedef struct cf_layout {
109 PangoLayout *pl; 112 PangoLayout *pl;
110 float r, g, b, a; // default color for rgba mode 113 float r, g, b, a; // default color for rgba mode
111 int base_height; 114 int base_height;
112 CFClient__Font font; 115 CFPlus__Font font;
113} *CFClient__Layout; 116} *CFPlus__Layout;
114 117
115static CFClient__Font default_font; 118static CFPlus__Font default_font;
116static PangoContext *opengl_context; 119static PangoContext *opengl_context;
117static PangoFontMap *opengl_fontmap; 120static PangoFontMap *opengl_fontmap;
118 121
119static void 122static void
120substitute_func (FcPattern *pattern, gpointer data) 123substitute_func (FcPattern *pattern, gpointer data)
125#endif 128#endif
126 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 129 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
127} 130}
128 131
129static void 132static void
130layout_update_font (CFClient__Layout self) 133layout_update_font (CFPlus__Layout self)
131{ 134{
132 /* use a random scale factor to account for unknown descenders, 0.8 works 135 /* use a random scale factor to account for unknown descenders, 0.8 works
133 * reasonably well with bitstream vera 136 * reasonably well with bitstream vera
134 */ 137 */
135 PangoFontDescription *font = self->font ? self->font : default_font; 138 PangoFontDescription *font = self->font ? self->font : default_font;
139 142
140 pango_layout_set_font_description (self->pl, font); 143 pango_layout_set_font_description (self->pl, font);
141} 144}
142 145
143static void 146static void
144layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
145{ 148{
146 pango_layout_get_pixel_size (self->pl, w, h); 149 pango_layout_get_pixel_size (self->pl, w, h);
147 150
148 if (!*w) *w = 1; 151 if (!*w) *w = 1;
149 if (!*h) *h = 1; 152 if (!*h) *h = 1;
179 int texs; 182 int texs;
180 maptex *tex; 183 maptex *tex;
181 184
182 int32_t rows; 185 int32_t rows;
183 maprow *row; 186 maprow *row;
184} *CFClient__Map; 187} *CFPlus__Map;
185 188
186static char * 189static char *
187prepend (char *ptr, int sze, int inc) 190prepend (char *ptr, int sze, int inc)
188{ 191{
189 char *p; 192 char *p;
207 210
208#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 211#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
209#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 212#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
210 213
211static maprow * 214static maprow *
212map_get_row (CFClient__Map self, int y) 215map_get_row (CFPlus__Map self, int y)
213{ 216{
214 if (0 > y) 217 if (0 > y)
215 { 218 {
216 int extend = - y + MAP_EXTEND_Y; 219 int extend = - y + MAP_EXTEND_Y;
217 Prepend (maprow, self->row, self->rows, extend); 220 Prepend (maprow, self->row, self->rows, extend);
255 258
256 return row->col + (x - row->c0); 259 return row->col + (x - row->c0);
257} 260}
258 261
259static mapcell * 262static mapcell *
260map_get_cell (CFClient__Map self, int x, int y) 263map_get_cell (CFPlus__Map self, int x, int y)
261{ 264{
262 return row_get_cell (map_get_row (self, y), x); 265 return row_get_cell (map_get_row (self, y), x);
263} 266}
264 267
265static void 268static void
266map_clear (CFClient__Map self) 269map_clear (CFPlus__Map self)
267{ 270{
268 int r; 271 int r;
269 272
270 for (r = 0; r < self->rows; r++) 273 for (r = 0; r < self->rows; r++)
271 Safefree (self->row[r].col); 274 Safefree (self->row[r].col);
279 self->row = 0; 282 self->row = 0;
280 self->rows = 0; 283 self->rows = 0;
281} 284}
282 285
283static void 286static void
284map_blank (CFClient__Map self, int x0, int y0, int w, int h) 287map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
285{ 288{
286 int x, y; 289 int x, y;
287 maprow *row; 290 maprow *row;
288 291
289 for (y = y0; y < y0 + h; y++) 292 for (y = y0; y < y0 + h; y++)
346 n |= n >> 16; 349 n |= n >> 16;
347 350
348 return n + 1; 351 return n + 1;
349} 352}
350 353
351MODULE = CFClient PACKAGE = CFClient 354MODULE = CFPlus PACKAGE = CFPlus
352 355
353PROTOTYPES: ENABLE 356PROTOTYPES: ENABLE
354 357
355BOOT: 358BOOT:
356{ 359{
357 HV *stash = gv_stashpv ("CFClient", 1); 360 HV *stash = gv_stashpv ("CFPlus", 1);
358 static const struct { 361 static const struct {
359 const char *name; 362 const char *name;
360 IV iv; 363 IV iv;
361 } *civ, const_iv[] = { 364 } *civ, const_iv[] = {
362# define const_iv(name) { # name, (IV)name } 365# define const_iv(name) { # name, (IV)name }
463 466
464 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 467 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
465 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 468 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
466} 469}
467 470
471int
472in_destruct ()
473 CODE:
474 RETVAL = PL_main_cv == Nullcv;
475 OUTPUT:
476 RETVAL
477
468NV floor (NV x) 478NV floor (NV x)
469 479
470NV ceil (NV x) 480NV ceil (NV x)
471 481
472void 482void
502 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 512 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
503 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 513 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
504 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 514 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
505 515
506 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 516 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
517 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
518 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
507 519
508 SDL_EnableUNICODE (1); 520 SDL_EnableUNICODE (1);
509 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 521 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
510 522
511 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 523 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
598 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 610 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
599 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 611 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
600 break; 612 break;
601 } 613 }
602 614
603 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 615 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
604 } 616 }
605} 617}
606 618
607int 619int
608Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) 620Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048)
624#endif 636#endif
625 637
626void 638void
627add_font (char *file) 639add_font (char *file)
628 CODE: 640 CODE:
629 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 641 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
630 642
631void 643void
632load_image_inline (SV *image_) 644load_image_inline (SV *image_)
633 ALIAS: 645 ALIAS:
634 load_image_file = 1 646 load_image_file = 1
676 688
677 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); 689 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE);
678 690
679 assert (surface2->pitch == surface2->w * 4); 691 assert (surface2->pitch == surface2->w * 4);
680 692
693 SDL_LockSurface (surface2);
681 EXTEND (SP, 5); 694 EXTEND (SP, 6);
682 PUSHs (sv_2mortal (newSViv (surface2->w))); 695 PUSHs (sv_2mortal (newSViv (surface2->w)));
683 PUSHs (sv_2mortal (newSViv (surface2->h))); 696 PUSHs (sv_2mortal (newSViv (surface2->h)));
684 SDL_LockSurface (surface2);
685 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 697 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch)));
686 SDL_UnlockSurface (surface2);
687 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 698 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
688 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 699 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
689 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 700 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
701 SDL_UnlockSurface (surface2);
690 702
691 SDL_FreeSurface (surface); 703 SDL_FreeSurface (surface);
692 SDL_FreeSurface (surface2); 704 SDL_FreeSurface (surface2);
693} 705}
694 706
737void 749void
738_exit (int retval) 750_exit (int retval)
739 CODE: 751 CODE:
740 _exit (retval); 752 _exit (retval);
741 753
742MODULE = CFClient PACKAGE = CFClient::Font 754MODULE = CFPlus PACKAGE = CFPlus::Font
743 755
744CFClient::Font 756CFPlus::Font
745new_from_file (SV *class, char *path, int id = 0) 757new_from_file (SV *class, char *path, int id = 0)
746 CODE: 758 CODE:
747{ 759{
748 int count; 760 int count;
749 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 761 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
752} 764}
753 OUTPUT: 765 OUTPUT:
754 RETVAL 766 RETVAL
755 767
756void 768void
757DESTROY (CFClient::Font self) 769DESTROY (CFPlus::Font self)
758 CODE: 770 CODE:
759 pango_font_description_free (self); 771 pango_font_description_free (self);
760 772
761void 773void
762make_default (CFClient::Font self) 774make_default (CFPlus::Font self)
763 CODE: 775 CODE:
764 default_font = self; 776 default_font = self;
765 777
766MODULE = CFClient PACKAGE = CFClient::Layout 778MODULE = CFPlus PACKAGE = CFPlus::Layout
767 779
768void 780void
769clear_font_cache () 781reset_glyph_cache ()
770 CODE: 782 CODE:
771 tc_clear (); 783 tc_clear ();
772 784
773CFClient::Layout 785CFPlus::Layout
774new (SV *class) 786new (SV *class)
775 CODE: 787 CODE:
776 New (0, RETVAL, 1, struct cf_layout); 788 New (0, RETVAL, 1, struct cf_layout);
777 789
778 RETVAL->pl = pango_layout_new (opengl_context); 790 RETVAL->pl = pango_layout_new (opengl_context);
787 layout_update_font (RETVAL); 799 layout_update_font (RETVAL);
788 OUTPUT: 800 OUTPUT:
789 RETVAL 801 RETVAL
790 802
791void 803void
792DESTROY (CFClient::Layout self) 804DESTROY (CFPlus::Layout self)
793 CODE: 805 CODE:
794 g_object_unref (self->pl); 806 g_object_unref (self->pl);
795 Safefree (self); 807 Safefree (self);
796 808
797void 809void
798set_text (CFClient::Layout self, SV *text_) 810set_text (CFPlus::Layout self, SV *text_)
799 CODE: 811 CODE:
800{ 812{
801 STRLEN textlen; 813 STRLEN textlen;
802 char *text = SvPVutf8 (text_, textlen); 814 char *text = SvPVutf8 (text_, textlen);
803 815
804 pango_layout_set_text (self->pl, text, textlen); 816 pango_layout_set_text (self->pl, text, textlen);
805} 817}
806 818
807void 819void
808set_markup (CFClient::Layout self, SV *text_) 820set_markup (CFPlus::Layout self, SV *text_)
809 CODE: 821 CODE:
810{ 822{
811 STRLEN textlen; 823 STRLEN textlen;
812 char *text = SvPVutf8 (text_, textlen); 824 char *text = SvPVutf8 (text_, textlen);
813 825
814 pango_layout_set_markup (self->pl, text, textlen); 826 pango_layout_set_markup (self->pl, text, textlen);
815} 827}
816 828
817void 829void
818set_shapes (CFClient::Layout self, ...) 830set_shapes (CFPlus::Layout self, ...)
819 CODE: 831 CODE:
820{ 832{
821 PangoAttrList *attrs = 0; 833 PangoAttrList *attrs = 0;
822 const char *text = pango_layout_get_text (self->pl); 834 const char *text = pango_layout_get_text (self->pl);
823 const char *pos = text; 835 const char *pos = text;
858 if (attrs) 870 if (attrs)
859 pango_layout_set_attributes (self->pl, attrs); 871 pango_layout_set_attributes (self->pl, attrs);
860} 872}
861 873
862void 874void
863get_shapes (CFClient::Layout self) 875get_shapes (CFPlus::Layout self)
864 PPCODE: 876 PPCODE:
865{ 877{
866 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 878 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
867 879
868 do 880 do
872 if (run && shape_attr_p (run)) 884 if (run && shape_attr_p (run))
873 { 885 {
874 PangoRectangle extents; 886 PangoRectangle extents;
875 pango_layout_iter_get_run_extents (iter, 0, &extents); 887 pango_layout_iter_get_run_extents (iter, 0, &extents);
876 888
889 EXTEND (SP, 2);
877 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); 890 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x))));
878 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); 891 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y))));
879 } 892 }
880 } 893 }
881 while (pango_layout_iter_next_run (iter)); 894 while (pango_layout_iter_next_run (iter));
882 895
883 pango_layout_iter_free (iter); 896 pango_layout_iter_free (iter);
884} 897}
885 898
886int 899int
887has_wrapped (CFClient::Layout self) 900has_wrapped (CFPlus::Layout self)
888 CODE: 901 CODE:
889{ 902{
890 int lines = 1; 903 int lines = 1;
891 const char *text = pango_layout_get_text (self->pl); 904 const char *text = pango_layout_get_text (self->pl);
892 905
897} 910}
898 OUTPUT: 911 OUTPUT:
899 RETVAL 912 RETVAL
900 913
901SV * 914SV *
902get_text (CFClient::Layout self) 915get_text (CFPlus::Layout self)
903 CODE: 916 CODE:
904 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 917 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
905 sv_utf8_decode (RETVAL); 918 sv_utf8_decode (RETVAL);
906 OUTPUT: 919 OUTPUT:
907 RETVAL 920 RETVAL
908 921
909void 922void
910set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) 923set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.)
911 CODE: 924 CODE:
912 self->r = r; 925 self->r = r;
913 self->g = g; 926 self->g = g;
914 self->b = b; 927 self->b = b;
915 self->a = a; 928 self->a = a;
916 929
917void 930void
918set_font (CFClient::Layout self, CFClient::Font font = 0) 931set_font (CFPlus::Layout self, CFPlus::Font font = 0)
919 CODE: 932 CODE:
920 if (self->font != font) 933 if (self->font != font)
921 { 934 {
922 self->font = font; 935 self->font = font;
923 layout_update_font (self); 936 layout_update_font (self);
924 } 937 }
925 938
926void 939void
927set_height (CFClient::Layout self, int base_height) 940set_height (CFPlus::Layout self, int base_height)
928 CODE: 941 CODE:
929 if (self->base_height != base_height) 942 if (self->base_height != base_height)
930 { 943 {
931 self->base_height = base_height; 944 self->base_height = base_height;
932 layout_update_font (self); 945 layout_update_font (self);
933 } 946 }
934 947
935void 948void
936set_width (CFClient::Layout self, int max_width = -1) 949set_width (CFPlus::Layout self, int max_width = -1)
937 CODE: 950 CODE:
938 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 951 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
939 952
940void 953void
941set_indent (CFClient::Layout self, int indent) 954set_indent (CFPlus::Layout self, int indent)
942 CODE: 955 CODE:
943 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 956 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
944 957
945void 958void
946set_spacing (CFClient::Layout self, int spacing) 959set_spacing (CFPlus::Layout self, int spacing)
947 CODE: 960 CODE:
948 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 961 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
949 962
950void 963void
951set_ellipsise (CFClient::Layout self, int ellipsise) 964set_ellipsise (CFPlus::Layout self, int ellipsise)
952 CODE: 965 CODE:
953 pango_layout_set_ellipsize (self->pl, 966 pango_layout_set_ellipsize (self->pl,
954 ellipsise == 1 ? PANGO_ELLIPSIZE_START 967 ellipsise == 1 ? PANGO_ELLIPSIZE_START
955 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 968 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
956 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 969 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
957 : PANGO_ELLIPSIZE_NONE 970 : PANGO_ELLIPSIZE_NONE
958 ); 971 );
959 972
960void 973void
961set_single_paragraph_mode (CFClient::Layout self, int spm) 974set_single_paragraph_mode (CFPlus::Layout self, int spm)
962 CODE: 975 CODE:
963 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 976 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
964 977
965void 978void
966size (CFClient::Layout self) 979size (CFPlus::Layout self)
967 PPCODE: 980 PPCODE:
968{ 981{
969 int w, h; 982 int w, h;
970 983
971 layout_get_pixel_size (self, &w, &h); 984 layout_get_pixel_size (self, &w, &h);
974 PUSHs (sv_2mortal (newSViv (w))); 987 PUSHs (sv_2mortal (newSViv (w)));
975 PUSHs (sv_2mortal (newSViv (h))); 988 PUSHs (sv_2mortal (newSViv (h)));
976} 989}
977 990
978int 991int
979descent (CFClient::Layout self) 992descent (CFPlus::Layout self)
980 CODE: 993 CODE:
981{ 994{
982 PangoRectangle rect; 995 PangoRectangle rect;
983 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 996 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
984 pango_layout_line_get_pixel_extents (line, 0, &rect); 997 pango_layout_line_get_pixel_extents (line, 0, &rect);
986} 999}
987 OUTPUT: 1000 OUTPUT:
988 RETVAL 1001 RETVAL
989 1002
990int 1003int
991xy_to_index (CFClient::Layout self, int x, int y) 1004xy_to_index (CFPlus::Layout self, int x, int y)
992 CODE: 1005 CODE:
993{ 1006{
994 int index, trailing; 1007 int index, trailing;
995 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1008 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
996 RETVAL = index; 1009 RETVAL = index;
997} 1010}
998 OUTPUT: 1011 OUTPUT:
999 RETVAL 1012 RETVAL
1000 1013
1001void 1014void
1002cursor_pos (CFClient::Layout self, int index) 1015cursor_pos (CFPlus::Layout self, int index)
1003 PPCODE: 1016 PPCODE:
1004{ 1017{
1005 PangoRectangle strong_pos; 1018 PangoRectangle strong_pos;
1006 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1019 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
1007 1020
1010 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1023 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1011 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1024 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1012} 1025}
1013 1026
1014void 1027void
1015render (CFClient::Layout self, float x, float y) 1028render (CFPlus::Layout self, float x, float y)
1016 PPCODE: 1029 PPCODE:
1017 pango_opengl_render_layout_subpixel ( 1030 pango_opengl_render_layout_subpixel (
1018 self->pl, 1031 self->pl,
1019 x * PANGO_SCALE, y * PANGO_SCALE, 1032 x * PANGO_SCALE, y * PANGO_SCALE,
1020 self->r, self->g, self->b, self->a 1033 self->r, self->g, self->b, self->a
1021 ); 1034 );
1022 1035
1023MODULE = CFClient PACKAGE = CFClient::Texture 1036MODULE = CFPlus PACKAGE = CFPlus::Texture
1024 1037
1025void 1038void
1026pad2pot (SV *data_, SV *w_, SV *h_) 1039pad2pot (SV *data_, SV *w_, SV *h_)
1027 CODE: 1040 CODE:
1028{ 1041{
1106 glDisable (GL_ALPHA_TEST); 1119 glDisable (GL_ALPHA_TEST);
1107 glDisable (GL_BLEND); 1120 glDisable (GL_BLEND);
1108 } 1121 }
1109} 1122}
1110 1123
1111MODULE = CFClient PACKAGE = CFClient::Map 1124MODULE = CFPlus PACKAGE = CFPlus::Map
1112 1125
1113CFClient::Map 1126CFPlus::Map
1114new (SV *class, int map_width, int map_height) 1127new (SV *class, int map_width, int map_height)
1115 CODE: 1128 CODE:
1116 New (0, RETVAL, 1, struct map); 1129 New (0, RETVAL, 1, struct map);
1117 RETVAL->x = 0; 1130 RETVAL->x = 0;
1118 RETVAL->y = 0; 1131 RETVAL->y = 0;
1128 RETVAL->row = 0; 1141 RETVAL->row = 0;
1129 OUTPUT: 1142 OUTPUT:
1130 RETVAL 1143 RETVAL
1131 1144
1132void 1145void
1133DESTROY (CFClient::Map self) 1146DESTROY (CFPlus::Map self)
1134 CODE: 1147 CODE:
1135{ 1148{
1136 map_clear (self); 1149 map_clear (self);
1137 Safefree (self->face); 1150 Safefree (self->face);
1138 Safefree (self->tex); 1151 Safefree (self->tex);
1139 Safefree (self); 1152 Safefree (self);
1140} 1153}
1141 1154
1142void 1155void
1143clear (CFClient::Map self) 1156clear (CFPlus::Map self)
1144 CODE: 1157 CODE:
1145 map_clear (self); 1158 map_clear (self);
1146 1159
1147void 1160void
1148set_face (CFClient::Map self, int face, int texid) 1161set_face (CFPlus::Map self, int face, int texid)
1149 CODE: 1162 CODE:
1150{ 1163{
1151 while (self->faces <= face) 1164 while (self->faces <= face)
1152 { 1165 {
1153 Append (mapface, self->face, self->faces, self->faces); 1166 Append (mapface, self->face, self->faces, self->faces);
1156 1169
1157 self->face [face] = texid; 1170 self->face [face] = texid;
1158} 1171}
1159 1172
1160void 1173void
1161set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1174set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1162 CODE: 1175 CODE:
1163{ 1176{
1164 while (self->texs <= texid) 1177 while (self->texs <= texid)
1165 { 1178 {
1166 Append (maptex, self->tex, self->texs, self->texs); 1179 Append (maptex, self->tex, self->texs, self->texs);
1190 // from transparent color bleeding and ugly wrapping effects. 1203 // from transparent color bleeding and ugly wrapping effects.
1191 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1204 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1192} 1205}
1193 1206
1194int 1207int
1195ox (CFClient::Map self) 1208ox (CFPlus::Map self)
1196 ALIAS: 1209 ALIAS:
1197 oy = 1 1210 oy = 1
1198 x = 2 1211 x = 2
1199 y = 3 1212 y = 3
1200 w = 4 1213 w = 4
1211 } 1224 }
1212 OUTPUT: 1225 OUTPUT:
1213 RETVAL 1226 RETVAL
1214 1227
1215void 1228void
1216scroll (CFClient::Map self, int dx, int dy) 1229scroll (CFPlus::Map self, int dx, int dy)
1217 CODE: 1230 CODE:
1218{ 1231{
1219 if (dx > 0) 1232 if (dx > 0)
1220 map_blank (self, self->x, self->y, dx - 1, self->h); 1233 map_blank (self, self->x, self->y, dx - 1, self->h);
1221 else if (dx < 0) 1234 else if (dx < 0)
1237 self->y += MAP_EXTEND_Y; 1250 self->y += MAP_EXTEND_Y;
1238 } 1251 }
1239} 1252}
1240 1253
1241void 1254void
1242map1a_update (CFClient::Map self, SV *data_) 1255map1a_update (CFPlus::Map self, SV *data_)
1243 CODE: 1256 CODE:
1244{ 1257{
1245 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1258 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1246 uint8_t *data_end = (uint8_t *)SvEND (data_); 1259 uint8_t *data_end = (uint8_t *)SvEND (data_);
1247 mapcell *cell; 1260 mapcell *cell;
1289 cell->darkness = -1; 1302 cell->darkness = -1;
1290 } 1303 }
1291} 1304}
1292 1305
1293SV * 1306SV *
1294mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1307mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1295 CODE: 1308 CODE:
1296{ 1309{
1297 int x1, x; 1310 int x1, x;
1298 int y1, y; 1311 int y1, y;
1299 int z; 1312 int z;
1349} 1362}
1350 OUTPUT: 1363 OUTPUT:
1351 RETVAL 1364 RETVAL
1352 1365
1353void 1366void
1354draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1367draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1355 CODE: 1368 CODE:
1356{ 1369{
1357 int vx, vy; 1370 int vx, vy;
1358 int x, y, z; 1371 int x, y, z;
1359 int last_name; 1372 int last_name;
1424 glDisable (GL_TEXTURE_2D); 1437 glDisable (GL_TEXTURE_2D);
1425 glDisable (GL_BLEND); 1438 glDisable (GL_BLEND);
1426} 1439}
1427 1440
1428void 1441void
1429draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) 1442draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1430 CODE: 1443 CODE:
1431{ 1444{
1432 static float color[16][3] = { 1445 static float color[16][3] = {
1433 { 0.00F, 0.00F, 0.00F }, 1446 { 0.00F, 0.00F, 0.00F },
1434 { 1.00F, 1.00F, 1.00F }, 1447 { 1.00F, 1.00F, 1.00F },
1484 glDisable (GL_BLEND); 1497 glDisable (GL_BLEND);
1485 glDisable (GL_TEXTURE_2D); 1498 glDisable (GL_TEXTURE_2D);
1486} 1499}
1487 1500
1488void 1501void
1489fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1502fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1490 PPCODE: 1503 PPCODE:
1491{ 1504{
1492 int vx, vy; 1505 int vx, vy;
1493 int x, y; 1506 int x, y;
1494 int sw4 = (sw + 3) & ~3; 1507 int sw4 = (sw + 3) & ~3;
1523 PUSHs (sv_2mortal (newSViv (sh))); 1536 PUSHs (sv_2mortal (newSViv (sh)));
1524 PUSHs (darkness_sv); 1537 PUSHs (darkness_sv);
1525} 1538}
1526 1539
1527SV * 1540SV *
1528get_rect (CFClient::Map self, int x0, int y0, int w, int h) 1541get_rect (CFPlus::Map self, int x0, int y0, int w, int h)
1529 CODE: 1542 CODE:
1530{ 1543{
1531 int x, y, x1, y1; 1544 int x, y, x1, y1;
1532 SV *data_sv = newSV (w * h * 7 + 5); 1545 SV *data_sv = newSV (w * h * 7 + 5);
1533 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1546 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1595} 1608}
1596 OUTPUT: 1609 OUTPUT:
1597 RETVAL 1610 RETVAL
1598 1611
1599void 1612void
1600set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1613set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1601 PPCODE: 1614 PPCODE:
1602{ 1615{
1603 int x, y, z; 1616 int x, y, z;
1604 int w, h; 1617 int w, h;
1605 int x1, y1; 1618 int x1, y1;
1654 } 1667 }
1655 } 1668 }
1656 } 1669 }
1657} 1670}
1658 1671
1659MODULE = CFClient PACKAGE = CFClient::MixChunk 1672MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1660 1673
1661CFClient::MixChunk 1674CFPlus::MixChunk
1662new_from_file (SV *class, char *path) 1675new_from_file (SV *class, char *path)
1663 CODE: 1676 CODE:
1664 RETVAL = Mix_LoadWAV (path); 1677 RETVAL = Mix_LoadWAV (path);
1665 OUTPUT: 1678 OUTPUT:
1666 RETVAL 1679 RETVAL
1667 1680
1668void 1681void
1669DESTROY (CFClient::MixChunk self) 1682DESTROY (CFPlus::MixChunk self)
1670 CODE: 1683 CODE:
1671 Mix_FreeChunk (self); 1684 Mix_FreeChunk (self);
1672 1685
1673int 1686int
1674volume (CFClient::MixChunk self, int volume = -1) 1687volume (CFPlus::MixChunk self, int volume = -1)
1675 CODE: 1688 CODE:
1676 RETVAL = Mix_VolumeChunk (self, volume); 1689 RETVAL = Mix_VolumeChunk (self, volume);
1677 OUTPUT: 1690 OUTPUT:
1678 RETVAL 1691 RETVAL
1679 1692
1680int 1693int
1681play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) 1694play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1)
1682 CODE: 1695 CODE:
1683 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1696 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1684 OUTPUT: 1697 OUTPUT:
1685 RETVAL 1698 RETVAL
1686 1699
1687MODULE = CFClient PACKAGE = CFClient::MixMusic 1700MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1688 1701
1689int 1702int
1690volume (int volume = -1) 1703volume (int volume = -1)
1691 CODE: 1704 CODE:
1692 RETVAL = Mix_VolumeMusic (volume); 1705 RETVAL = Mix_VolumeMusic (volume);
1693 OUTPUT: 1706 OUTPUT:
1694 RETVAL 1707 RETVAL
1695 1708
1696CFClient::MixMusic 1709CFPlus::MixMusic
1697new_from_file (SV *class, char *path) 1710new_from_file (SV *class, char *path)
1698 CODE: 1711 CODE:
1699 RETVAL = Mix_LoadMUS (path); 1712 RETVAL = Mix_LoadMUS (path);
1700 OUTPUT: 1713 OUTPUT:
1701 RETVAL 1714 RETVAL
1702 1715
1703void 1716void
1704DESTROY (CFClient::MixMusic self) 1717DESTROY (CFPlus::MixMusic self)
1705 CODE: 1718 CODE:
1706 Mix_FreeMusic (self); 1719 Mix_FreeMusic (self);
1707 1720
1708int 1721int
1709play (CFClient::MixMusic self, int loops = -1) 1722play (CFPlus::MixMusic self, int loops = -1)
1710 CODE: 1723 CODE:
1711 RETVAL = Mix_PlayMusic (self, loops); 1724 RETVAL = Mix_PlayMusic (self, loops);
1712 OUTPUT: 1725 OUTPUT:
1713 RETVAL 1726 RETVAL
1714 1727
1715MODULE = CFClient PACKAGE = CFClient::OpenGL 1728MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1716 1729
1717BOOT: 1730BOOT:
1718{ 1731{
1719 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1732 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1720 static const struct { 1733 static const struct {
1721 const char *name; 1734 const char *name;
1722 IV iv; 1735 IV iv;
1723 } *civ, const_iv[] = { 1736 } *civ, const_iv[] = {
1724# define const_iv(name) { # name, (IV)name } 1737# define const_iv(name) { # name, (IV)name }
1906 r *= a; 1919 r *= a;
1907 g *= a; 1920 g *= a;
1908 b *= a; 1921 b *= a;
1909 } 1922 }
1910 // microsoft visual "c" rounds instead of truncating... 1923 // microsoft visual "c" rounds instead of truncating...
1911 glColor4ub (MIN ((int)(r * 256.f), 255), 1924 glColor4f (r, g, b, a);
1912 MIN ((int)(g * 256.f), 255),
1913 MIN ((int)(b * 256.f), 255),
1914 MIN ((int)(a * 256.f), 255));
1915 1925
1916void glInterleavedArrays (int format, int stride, char *data) 1926void glInterleavedArrays (int format, int stride, char *data)
1917 1927
1918void glDrawElements (int mode, int count, int type, char *indices) 1928void glDrawElements (int mode, int count, int type, char *indices)
1919 1929

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines