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.125 by root, Tue Jul 4 23:44:23 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
52#define MAP_EXTEND_Y 512 55#define MAP_EXTEND_Y 512
53 56
54#define MIN_FONT_HEIGHT 10 57#define MIN_FONT_HEIGHT 10
55 58
56#if 1 59#if 0
57# define PARACHUTE SDL_INIT_NOPARACHUTE 60# define PARACHUTE SDL_INIT_NOPARACHUTE
58#else 61#else
59# define PARACHUTE 0 62# define PARACHUTE 0
60#endif 63#endif
61 64
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 pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap);
772 tc_clear (); 783 tc_clear ();
773 784
774CFClient::Layout 785CFPlus::Layout
775new (SV *class, int type = 0) 786new (SV *class)
776 CODE: 787 CODE:
777 New (0, RETVAL, 1, struct cf_layout); 788 New (0, RETVAL, 1, struct cf_layout);
778 789
779 RETVAL->pl = pango_layout_new (opengl_context); 790 RETVAL->pl = pango_layout_new (opengl_context);
780 RETVAL->r = 1.; 791 RETVAL->r = 1.;
788 layout_update_font (RETVAL); 799 layout_update_font (RETVAL);
789 OUTPUT: 800 OUTPUT:
790 RETVAL 801 RETVAL
791 802
792void 803void
793DESTROY (CFClient::Layout self) 804DESTROY (CFPlus::Layout self)
794 CODE: 805 CODE:
795 g_object_unref (self->pl); 806 g_object_unref (self->pl);
796 Safefree (self); 807 Safefree (self);
797 808
798void 809void
799set_text (CFClient::Layout self, SV *text_) 810set_text (CFPlus::Layout self, SV *text_)
800 CODE: 811 CODE:
801{ 812{
802 STRLEN textlen; 813 STRLEN textlen;
803 char *text = SvPVutf8 (text_, textlen); 814 char *text = SvPVutf8 (text_, textlen);
804 815
805 pango_layout_set_text (self->pl, text, textlen); 816 pango_layout_set_text (self->pl, text, textlen);
806} 817}
807 818
808void 819void
809set_markup (CFClient::Layout self, SV *text_) 820set_markup (CFPlus::Layout self, SV *text_)
810 CODE: 821 CODE:
811{ 822{
812 STRLEN textlen; 823 STRLEN textlen;
813 char *text = SvPVutf8 (text_, textlen); 824 char *text = SvPVutf8 (text_, textlen);
814 825
815 pango_layout_set_markup (self->pl, text, textlen); 826 pango_layout_set_markup (self->pl, text, textlen);
816} 827}
817 828
818void 829void
819set_shapes (CFClient::Layout self, ...) 830set_shapes (CFPlus::Layout self, ...)
820 CODE: 831 CODE:
821{ 832{
822 PangoAttrList *attrs = 0; 833 PangoAttrList *attrs = 0;
823 const char *text = pango_layout_get_text (self->pl); 834 const char *text = pango_layout_get_text (self->pl);
824 const char *pos = text; 835 const char *pos = text;
859 if (attrs) 870 if (attrs)
860 pango_layout_set_attributes (self->pl, attrs); 871 pango_layout_set_attributes (self->pl, attrs);
861} 872}
862 873
863void 874void
864get_shapes (CFClient::Layout self) 875get_shapes (CFPlus::Layout self)
865 PPCODE: 876 PPCODE:
866{ 877{
867 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 878 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
868 879
869 do 880 do
873 if (run && shape_attr_p (run)) 884 if (run && shape_attr_p (run))
874 { 885 {
875 PangoRectangle extents; 886 PangoRectangle extents;
876 pango_layout_iter_get_run_extents (iter, 0, &extents); 887 pango_layout_iter_get_run_extents (iter, 0, &extents);
877 888
889 EXTEND (SP, 2);
878 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); 890 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x))));
879 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); 891 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y))));
880 } 892 }
881 } 893 }
882 while (pango_layout_iter_next_run (iter)); 894 while (pango_layout_iter_next_run (iter));
883 895
884 pango_layout_iter_free (iter); 896 pango_layout_iter_free (iter);
885} 897}
886 898
887int 899int
888has_wrapped (CFClient::Layout self) 900has_wrapped (CFPlus::Layout self)
889 CODE: 901 CODE:
890{ 902{
891 int lines = 1; 903 int lines = 1;
892 const char *text = pango_layout_get_text (self->pl); 904 const char *text = pango_layout_get_text (self->pl);
893 905
898} 910}
899 OUTPUT: 911 OUTPUT:
900 RETVAL 912 RETVAL
901 913
902SV * 914SV *
903get_text (CFClient::Layout self) 915get_text (CFPlus::Layout self)
904 CODE: 916 CODE:
905 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 917 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
906 sv_utf8_decode (RETVAL); 918 sv_utf8_decode (RETVAL);
907 OUTPUT: 919 OUTPUT:
908 RETVAL 920 RETVAL
909 921
910void 922void
911set_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.)
912 CODE: 924 CODE:
913 self->r = r; 925 self->r = r;
914 self->g = g; 926 self->g = g;
915 self->b = b; 927 self->b = b;
916 self->a = a; 928 self->a = a;
917 929
918void 930void
919set_font (CFClient::Layout self, CFClient::Font font = 0) 931set_font (CFPlus::Layout self, CFPlus::Font font = 0)
920 CODE: 932 CODE:
921 if (self->font != font) 933 if (self->font != font)
922 { 934 {
923 self->font = font; 935 self->font = font;
924 layout_update_font (self); 936 layout_update_font (self);
925 } 937 }
926 938
927void 939void
928set_height (CFClient::Layout self, int base_height) 940set_height (CFPlus::Layout self, int base_height)
929 CODE: 941 CODE:
930 if (self->base_height != base_height) 942 if (self->base_height != base_height)
931 { 943 {
932 self->base_height = base_height; 944 self->base_height = base_height;
933 layout_update_font (self); 945 layout_update_font (self);
934 } 946 }
935 947
936void 948void
937set_width (CFClient::Layout self, int max_width = -1) 949set_width (CFPlus::Layout self, int max_width = -1)
938 CODE: 950 CODE:
939 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);
940 952
941void 953void
942set_indent (CFClient::Layout self, int indent) 954set_indent (CFPlus::Layout self, int indent)
943 CODE: 955 CODE:
944 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 956 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
945 957
946void 958void
947set_spacing (CFClient::Layout self, int spacing) 959set_spacing (CFPlus::Layout self, int spacing)
948 CODE: 960 CODE:
949 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 961 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
950 962
951void 963void
952set_ellipsise (CFClient::Layout self, int ellipsise) 964set_ellipsise (CFPlus::Layout self, int ellipsise)
953 CODE: 965 CODE:
954 pango_layout_set_ellipsize (self->pl, 966 pango_layout_set_ellipsize (self->pl,
955 ellipsise == 1 ? PANGO_ELLIPSIZE_START 967 ellipsise == 1 ? PANGO_ELLIPSIZE_START
956 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 968 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
957 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 969 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
958 : PANGO_ELLIPSIZE_NONE 970 : PANGO_ELLIPSIZE_NONE
959 ); 971 );
960 972
961void 973void
962set_single_paragraph_mode (CFClient::Layout self, int spm) 974set_single_paragraph_mode (CFPlus::Layout self, int spm)
963 CODE: 975 CODE:
964 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 976 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
965 977
966void 978void
967size (CFClient::Layout self) 979size (CFPlus::Layout self)
968 PPCODE: 980 PPCODE:
969{ 981{
970 int w, h; 982 int w, h;
971 983
972 layout_get_pixel_size (self, &w, &h); 984 layout_get_pixel_size (self, &w, &h);
975 PUSHs (sv_2mortal (newSViv (w))); 987 PUSHs (sv_2mortal (newSViv (w)));
976 PUSHs (sv_2mortal (newSViv (h))); 988 PUSHs (sv_2mortal (newSViv (h)));
977} 989}
978 990
979int 991int
980descent (CFClient::Layout self) 992descent (CFPlus::Layout self)
981 CODE: 993 CODE:
982{ 994{
983 PangoRectangle rect; 995 PangoRectangle rect;
984 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 996 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
985 pango_layout_line_get_pixel_extents (line, 0, &rect); 997 pango_layout_line_get_pixel_extents (line, 0, &rect);
987} 999}
988 OUTPUT: 1000 OUTPUT:
989 RETVAL 1001 RETVAL
990 1002
991int 1003int
992xy_to_index (CFClient::Layout self, int x, int y) 1004xy_to_index (CFPlus::Layout self, int x, int y)
993 CODE: 1005 CODE:
994{ 1006{
995 int index, trailing; 1007 int index, trailing;
996 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);
997 RETVAL = index; 1009 RETVAL = index;
998} 1010}
999 OUTPUT: 1011 OUTPUT:
1000 RETVAL 1012 RETVAL
1001 1013
1002void 1014void
1003cursor_pos (CFClient::Layout self, int index) 1015cursor_pos (CFPlus::Layout self, int index)
1004 PPCODE: 1016 PPCODE:
1005{ 1017{
1006 PangoRectangle strong_pos; 1018 PangoRectangle strong_pos;
1007 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1019 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
1008 1020
1011 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1023 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1012 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1024 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1013} 1025}
1014 1026
1015void 1027void
1016render (CFClient::Layout self, float x, float y) 1028render (CFPlus::Layout self, float x, float y)
1017 PPCODE: 1029 PPCODE:
1018 pango_opengl_render_layout_subpixel ( 1030 pango_opengl_render_layout_subpixel (
1019 self->pl, 1031 self->pl,
1020 x * PANGO_SCALE, y * PANGO_SCALE, 1032 x * PANGO_SCALE, y * PANGO_SCALE,
1021 self->r, self->g, self->b, self->a 1033 self->r, self->g, self->b, self->a
1022 ); 1034 );
1023 1035
1024MODULE = CFClient PACKAGE = CFClient::Texture 1036MODULE = CFPlus PACKAGE = CFPlus::Texture
1025 1037
1026void 1038void
1027pad2pot (SV *data_, SV *w_, SV *h_) 1039pad2pot (SV *data_, SV *w_, SV *h_)
1028 CODE: 1040 CODE:
1029{ 1041{
1107 glDisable (GL_ALPHA_TEST); 1119 glDisable (GL_ALPHA_TEST);
1108 glDisable (GL_BLEND); 1120 glDisable (GL_BLEND);
1109 } 1121 }
1110} 1122}
1111 1123
1112MODULE = CFClient PACKAGE = CFClient::Map 1124MODULE = CFPlus PACKAGE = CFPlus::Map
1113 1125
1114CFClient::Map 1126CFPlus::Map
1115new (SV *class, int map_width, int map_height) 1127new (SV *class, int map_width, int map_height)
1116 CODE: 1128 CODE:
1117 New (0, RETVAL, 1, struct map); 1129 New (0, RETVAL, 1, struct map);
1118 RETVAL->x = 0; 1130 RETVAL->x = 0;
1119 RETVAL->y = 0; 1131 RETVAL->y = 0;
1129 RETVAL->row = 0; 1141 RETVAL->row = 0;
1130 OUTPUT: 1142 OUTPUT:
1131 RETVAL 1143 RETVAL
1132 1144
1133void 1145void
1134DESTROY (CFClient::Map self) 1146DESTROY (CFPlus::Map self)
1135 CODE: 1147 CODE:
1136{ 1148{
1137 map_clear (self); 1149 map_clear (self);
1138 Safefree (self->face); 1150 Safefree (self->face);
1139 Safefree (self->tex); 1151 Safefree (self->tex);
1140 Safefree (self); 1152 Safefree (self);
1141} 1153}
1142 1154
1143void 1155void
1144clear (CFClient::Map self) 1156clear (CFPlus::Map self)
1145 CODE: 1157 CODE:
1146 map_clear (self); 1158 map_clear (self);
1147 1159
1148void 1160void
1149set_face (CFClient::Map self, int face, int texid) 1161set_face (CFPlus::Map self, int face, int texid)
1150 CODE: 1162 CODE:
1151{ 1163{
1152 while (self->faces <= face) 1164 while (self->faces <= face)
1153 { 1165 {
1154 Append (mapface, self->face, self->faces, self->faces); 1166 Append (mapface, self->face, self->faces, self->faces);
1157 1169
1158 self->face [face] = texid; 1170 self->face [face] = texid;
1159} 1171}
1160 1172
1161void 1173void
1162set_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)
1163 CODE: 1175 CODE:
1164{ 1176{
1165 while (self->texs <= texid) 1177 while (self->texs <= texid)
1166 { 1178 {
1167 Append (maptex, self->tex, self->texs, self->texs); 1179 Append (maptex, self->tex, self->texs, self->texs);
1191 // from transparent color bleeding and ugly wrapping effects. 1203 // from transparent color bleeding and ugly wrapping effects.
1192 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1204 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1193} 1205}
1194 1206
1195int 1207int
1196ox (CFClient::Map self) 1208ox (CFPlus::Map self)
1197 ALIAS: 1209 ALIAS:
1198 oy = 1 1210 oy = 1
1199 x = 2 1211 x = 2
1200 y = 3 1212 y = 3
1201 w = 4 1213 w = 4
1212 } 1224 }
1213 OUTPUT: 1225 OUTPUT:
1214 RETVAL 1226 RETVAL
1215 1227
1216void 1228void
1217scroll (CFClient::Map self, int dx, int dy) 1229scroll (CFPlus::Map self, int dx, int dy)
1218 CODE: 1230 CODE:
1219{ 1231{
1220 if (dx > 0) 1232 if (dx > 0)
1221 map_blank (self, self->x, self->y, dx - 1, self->h); 1233 map_blank (self, self->x, self->y, dx - 1, self->h);
1222 else if (dx < 0) 1234 else if (dx < 0)
1238 self->y += MAP_EXTEND_Y; 1250 self->y += MAP_EXTEND_Y;
1239 } 1251 }
1240} 1252}
1241 1253
1242void 1254void
1243map1a_update (CFClient::Map self, SV *data_) 1255map1a_update (CFPlus::Map self, SV *data_)
1244 CODE: 1256 CODE:
1245{ 1257{
1246 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1258 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1247 uint8_t *data_end = (uint8_t *)SvEND (data_); 1259 uint8_t *data_end = (uint8_t *)SvEND (data_);
1248 mapcell *cell; 1260 mapcell *cell;
1290 cell->darkness = -1; 1302 cell->darkness = -1;
1291 } 1303 }
1292} 1304}
1293 1305
1294SV * 1306SV *
1295mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1307mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1296 CODE: 1308 CODE:
1297{ 1309{
1298 int x1, x; 1310 int x1, x;
1299 int y1, y; 1311 int y1, y;
1300 int z; 1312 int z;
1350} 1362}
1351 OUTPUT: 1363 OUTPUT:
1352 RETVAL 1364 RETVAL
1353 1365
1354void 1366void
1355draw (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)
1356 CODE: 1368 CODE:
1357{ 1369{
1358 int vx, vy; 1370 int vx, vy;
1359 int x, y, z; 1371 int x, y, z;
1360 int last_name; 1372 int last_name;
1425 glDisable (GL_TEXTURE_2D); 1437 glDisable (GL_TEXTURE_2D);
1426 glDisable (GL_BLEND); 1438 glDisable (GL_BLEND);
1427} 1439}
1428 1440
1429void 1441void
1430draw_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)
1431 CODE: 1443 CODE:
1432{ 1444{
1433 static float color[16][3] = { 1445 static float color[16][3] = {
1434 { 0.00F, 0.00F, 0.00F }, 1446 { 0.00F, 0.00F, 0.00F },
1435 { 1.00F, 1.00F, 1.00F }, 1447 { 1.00F, 1.00F, 1.00F },
1485 glDisable (GL_BLEND); 1497 glDisable (GL_BLEND);
1486 glDisable (GL_TEXTURE_2D); 1498 glDisable (GL_TEXTURE_2D);
1487} 1499}
1488 1500
1489void 1501void
1490fow_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)
1491 PPCODE: 1503 PPCODE:
1492{ 1504{
1493 int vx, vy; 1505 int vx, vy;
1494 int x, y; 1506 int x, y;
1495 int sw4 = (sw + 3) & ~3; 1507 int sw4 = (sw + 3) & ~3;
1524 PUSHs (sv_2mortal (newSViv (sh))); 1536 PUSHs (sv_2mortal (newSViv (sh)));
1525 PUSHs (darkness_sv); 1537 PUSHs (darkness_sv);
1526} 1538}
1527 1539
1528SV * 1540SV *
1529get_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)
1530 CODE: 1542 CODE:
1531{ 1543{
1532 int x, y, x1, y1; 1544 int x, y, x1, y1;
1533 SV *data_sv = newSV (w * h * 7 + 5); 1545 SV *data_sv = newSV (w * h * 7 + 5);
1534 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1546 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1596} 1608}
1597 OUTPUT: 1609 OUTPUT:
1598 RETVAL 1610 RETVAL
1599 1611
1600void 1612void
1601set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1613set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1602 PPCODE: 1614 PPCODE:
1603{ 1615{
1604 int x, y, z; 1616 int x, y, z;
1605 int w, h; 1617 int w, h;
1606 int x1, y1; 1618 int x1, y1;
1655 } 1667 }
1656 } 1668 }
1657 } 1669 }
1658} 1670}
1659 1671
1660MODULE = CFClient PACKAGE = CFClient::MixChunk 1672MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1661 1673
1662CFClient::MixChunk 1674CFPlus::MixChunk
1663new_from_file (SV *class, char *path) 1675new_from_file (SV *class, char *path)
1664 CODE: 1676 CODE:
1665 RETVAL = Mix_LoadWAV (path); 1677 RETVAL = Mix_LoadWAV (path);
1666 OUTPUT: 1678 OUTPUT:
1667 RETVAL 1679 RETVAL
1668 1680
1669void 1681void
1670DESTROY (CFClient::MixChunk self) 1682DESTROY (CFPlus::MixChunk self)
1671 CODE: 1683 CODE:
1672 Mix_FreeChunk (self); 1684 Mix_FreeChunk (self);
1673 1685
1674int 1686int
1675volume (CFClient::MixChunk self, int volume = -1) 1687volume (CFPlus::MixChunk self, int volume = -1)
1676 CODE: 1688 CODE:
1677 RETVAL = Mix_VolumeChunk (self, volume); 1689 RETVAL = Mix_VolumeChunk (self, volume);
1678 OUTPUT: 1690 OUTPUT:
1679 RETVAL 1691 RETVAL
1680 1692
1681int 1693int
1682play (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)
1683 CODE: 1695 CODE:
1684 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1696 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1685 OUTPUT: 1697 OUTPUT:
1686 RETVAL 1698 RETVAL
1687 1699
1688MODULE = CFClient PACKAGE = CFClient::MixMusic 1700MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1689 1701
1690int 1702int
1691volume (int volume = -1) 1703volume (int volume = -1)
1692 CODE: 1704 CODE:
1693 RETVAL = Mix_VolumeMusic (volume); 1705 RETVAL = Mix_VolumeMusic (volume);
1694 OUTPUT: 1706 OUTPUT:
1695 RETVAL 1707 RETVAL
1696 1708
1697CFClient::MixMusic 1709CFPlus::MixMusic
1698new_from_file (SV *class, char *path) 1710new_from_file (SV *class, char *path)
1699 CODE: 1711 CODE:
1700 RETVAL = Mix_LoadMUS (path); 1712 RETVAL = Mix_LoadMUS (path);
1701 OUTPUT: 1713 OUTPUT:
1702 RETVAL 1714 RETVAL
1703 1715
1704void 1716void
1705DESTROY (CFClient::MixMusic self) 1717DESTROY (CFPlus::MixMusic self)
1706 CODE: 1718 CODE:
1707 Mix_FreeMusic (self); 1719 Mix_FreeMusic (self);
1708 1720
1709int 1721int
1710play (CFClient::MixMusic self, int loops = -1) 1722play (CFPlus::MixMusic self, int loops = -1)
1711 CODE: 1723 CODE:
1712 RETVAL = Mix_PlayMusic (self, loops); 1724 RETVAL = Mix_PlayMusic (self, loops);
1713 OUTPUT: 1725 OUTPUT:
1714 RETVAL 1726 RETVAL
1715 1727
1716MODULE = CFClient PACKAGE = CFClient::OpenGL 1728MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1717 1729
1718BOOT: 1730BOOT:
1719{ 1731{
1720 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1732 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1721 static const struct { 1733 static const struct {
1722 const char *name; 1734 const char *name;
1723 IV iv; 1735 IV iv;
1724 } *civ, const_iv[] = { 1736 } *civ, const_iv[] = {
1725# define const_iv(name) { # name, (IV)name } 1737# define const_iv(name) { # name, (IV)name }
1907 r *= a; 1919 r *= a;
1908 g *= a; 1920 g *= a;
1909 b *= a; 1921 b *= a;
1910 } 1922 }
1911 // microsoft visual "c" rounds instead of truncating... 1923 // microsoft visual "c" rounds instead of truncating...
1912 glColor4ub (MIN ((int)(r * 256.f), 255), 1924 glColor4f (r, g, b, a);
1913 MIN ((int)(g * 256.f), 255),
1914 MIN ((int)(b * 256.f), 255),
1915 MIN ((int)(a * 256.f), 255));
1916 1925
1917void glInterleavedArrays (int format, int stride, char *data) 1926void glInterleavedArrays (int format, int stride, char *data)
1918 1927
1919void glDrawElements (int mode, int count, int type, char *indices) 1928void glDrawElements (int mode, int count, int type, char *indices)
1920 1929

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines