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.124 by root, Tue Jul 4 23:23:31 2006 UTC vs.
Revision 1.141 by root, Fri Aug 18 01:01:00 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)
121{ 124{
122 FcPatternAddBool (pattern, FC_HINTING, 1); 125 FcPatternAddBool (pattern, FC_HINTING, 1);
123#ifdef FC_HINT_STYLE 126#ifdef FC_HINT_STYLE
124 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); 127 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL);
125#endif 128#endif
126#ifdef _WIN32
127 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
128#else
129 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 129 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
130#endif
131} 130}
132 131
133static void 132static void
134layout_update_font (CFClient__Layout self) 133layout_update_font (CFPlus__Layout self)
135{ 134{
136 /* 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
137 * reasonably well with bitstream vera 136 * reasonably well with bitstream vera
138 */ 137 */
139 PangoFontDescription *font = self->font ? self->font : default_font; 138 PangoFontDescription *font = self->font ? self->font : default_font;
143 142
144 pango_layout_set_font_description (self->pl, font); 143 pango_layout_set_font_description (self->pl, font);
145} 144}
146 145
147static void 146static void
148layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
149{ 148{
149 PangoRectangle rect;
150
151 // get_pixel_* wrongly rounds down
150 pango_layout_get_pixel_size (self->pl, w, h); 152 pango_layout_get_extents (self->pl, 0, &rect);
151 153
152 if (!*w) *w = 1; 154 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
153 if (!*h) *h = 1; 155 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
154 156
155 *w = (*w + 3) & ~3; 157 if (!rect.width) rect.width = 1;
158 if (!rect.height) rect.height = 1;
159
160 *w = rect.width;
161 *h = rect.height;
156} 162}
157 163
158typedef uint16_t mapface; 164typedef uint16_t mapface;
159 165
160typedef struct { 166typedef struct {
183 int texs; 189 int texs;
184 maptex *tex; 190 maptex *tex;
185 191
186 int32_t rows; 192 int32_t rows;
187 maprow *row; 193 maprow *row;
188} *CFClient__Map; 194} *CFPlus__Map;
189 195
190static char * 196static char *
191prepend (char *ptr, int sze, int inc) 197prepend (char *ptr, int sze, int inc)
192{ 198{
193 char *p; 199 char *p;
211 217
212#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 218#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
213#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 219#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
214 220
215static maprow * 221static maprow *
216map_get_row (CFClient__Map self, int y) 222map_get_row (CFPlus__Map self, int y)
217{ 223{
218 if (0 > y) 224 if (0 > y)
219 { 225 {
220 int extend = - y + MAP_EXTEND_Y; 226 int extend = - y + MAP_EXTEND_Y;
221 Prepend (maprow, self->row, self->rows, extend); 227 Prepend (maprow, self->row, self->rows, extend);
259 265
260 return row->col + (x - row->c0); 266 return row->col + (x - row->c0);
261} 267}
262 268
263static mapcell * 269static mapcell *
264map_get_cell (CFClient__Map self, int x, int y) 270map_get_cell (CFPlus__Map self, int x, int y)
265{ 271{
266 return row_get_cell (map_get_row (self, y), x); 272 return row_get_cell (map_get_row (self, y), x);
267} 273}
268 274
269static void 275static void
270map_clear (CFClient__Map self) 276map_clear (CFPlus__Map self)
271{ 277{
272 int r; 278 int r;
273 279
274 for (r = 0; r < self->rows; r++) 280 for (r = 0; r < self->rows; r++)
275 Safefree (self->row[r].col); 281 Safefree (self->row[r].col);
283 self->row = 0; 289 self->row = 0;
284 self->rows = 0; 290 self->rows = 0;
285} 291}
286 292
287static void 293static void
288map_blank (CFClient__Map self, int x0, int y0, int w, int h) 294map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
289{ 295{
290 int x, y; 296 int x, y;
291 maprow *row; 297 maprow *row;
292 298
293 for (y = y0; y < y0 + h; y++) 299 for (y = y0; y < y0 + h; y++)
350 n |= n >> 16; 356 n |= n >> 16;
351 357
352 return n + 1; 358 return n + 1;
353} 359}
354 360
355MODULE = CFClient PACKAGE = CFClient 361MODULE = CFPlus PACKAGE = CFPlus
356 362
357PROTOTYPES: ENABLE 363PROTOTYPES: ENABLE
358 364
359BOOT: 365BOOT:
360{ 366{
361 HV *stash = gv_stashpv ("CFClient", 1); 367 HV *stash = gv_stashpv ("CFPlus", 1);
362 static const struct { 368 static const struct {
363 const char *name; 369 const char *name;
364 IV iv; 370 IV iv;
365 } *civ, const_iv[] = { 371 } *civ, const_iv[] = {
366# define const_iv(name) { # name, (IV)name } 372# define const_iv(name) { # name, (IV)name }
467 473
468 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 474 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
469 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 475 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
470} 476}
471 477
478int
479in_destruct ()
480 CODE:
481 RETVAL = PL_main_cv == Nullcv;
482 OUTPUT:
483 RETVAL
484
472NV floor (NV x) 485NV floor (NV x)
473 486
474NV ceil (NV x) 487NV ceil (NV x)
475 488
476void 489void
506 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 519 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
507 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 520 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
508 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 521 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
509 522
510 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 523 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
524#if SDL_VERSION_ATLEAST(1,2,10)
525 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
526 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
527#endif
511 528
512 SDL_EnableUNICODE (1); 529 SDL_EnableUNICODE (1);
513 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 530 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
514 531
515 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 532 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
602 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 619 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
603 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 620 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
604 break; 621 break;
605 } 622 }
606 623
607 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 624 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
608 } 625 }
609} 626}
610 627
611int 628int
612Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) 629Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048)
628#endif 645#endif
629 646
630void 647void
631add_font (char *file) 648add_font (char *file)
632 CODE: 649 CODE:
633 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 650 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
634 651
635void 652void
636load_image_inline (SV *image_) 653load_image_inline (SV *image_)
637 ALIAS: 654 ALIAS:
638 load_image_file = 1 655 load_image_file = 1
680 697
681 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); 698 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE);
682 699
683 assert (surface2->pitch == surface2->w * 4); 700 assert (surface2->pitch == surface2->w * 4);
684 701
702 SDL_LockSurface (surface2);
685 EXTEND (SP, 5); 703 EXTEND (SP, 6);
686 PUSHs (sv_2mortal (newSViv (surface2->w))); 704 PUSHs (sv_2mortal (newSViv (surface2->w)));
687 PUSHs (sv_2mortal (newSViv (surface2->h))); 705 PUSHs (sv_2mortal (newSViv (surface2->h)));
688 SDL_LockSurface (surface2);
689 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 706 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch)));
690 SDL_UnlockSurface (surface2);
691 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 707 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
692 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 708 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
693 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 709 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
710 SDL_UnlockSurface (surface2);
694 711
695 SDL_FreeSurface (surface); 712 SDL_FreeSurface (surface);
696 SDL_FreeSurface (surface2); 713 SDL_FreeSurface (surface2);
697} 714}
698 715
741void 758void
742_exit (int retval) 759_exit (int retval)
743 CODE: 760 CODE:
744 _exit (retval); 761 _exit (retval);
745 762
746MODULE = CFClient PACKAGE = CFClient::Font 763MODULE = CFPlus PACKAGE = CFPlus::Font
747 764
748CFClient::Font 765CFPlus::Font
749new_from_file (SV *class, char *path, int id = 0) 766new_from_file (SV *class, char *path, int id = 0)
750 CODE: 767 CODE:
751{ 768{
752 int count; 769 int count;
753 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 770 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
756} 773}
757 OUTPUT: 774 OUTPUT:
758 RETVAL 775 RETVAL
759 776
760void 777void
761DESTROY (CFClient::Font self) 778DESTROY (CFPlus::Font self)
762 CODE: 779 CODE:
763 pango_font_description_free (self); 780 pango_font_description_free (self);
764 781
765void 782void
766make_default (CFClient::Font self) 783make_default (CFPlus::Font self)
767 CODE: 784 CODE:
768 default_font = self; 785 default_font = self;
769 786
770MODULE = CFClient PACKAGE = CFClient::Layout 787MODULE = CFPlus PACKAGE = CFPlus::Layout
771 788
772void 789void
773clear_font_cache () 790reset_glyph_cache ()
774 CODE: 791 CODE:
775 pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap);
776 tc_clear (); 792 tc_clear ();
777 793
778CFClient::Layout 794CFPlus::Layout
779new (SV *class, int type = 0) 795new (SV *class)
780 CODE: 796 CODE:
781 New (0, RETVAL, 1, struct cf_layout); 797 New (0, RETVAL, 1, struct cf_layout);
782 798
783 RETVAL->pl = pango_layout_new (opengl_context); 799 RETVAL->pl = pango_layout_new (opengl_context);
784 RETVAL->r = 1.; 800 RETVAL->r = 1.;
792 layout_update_font (RETVAL); 808 layout_update_font (RETVAL);
793 OUTPUT: 809 OUTPUT:
794 RETVAL 810 RETVAL
795 811
796void 812void
797DESTROY (CFClient::Layout self) 813DESTROY (CFPlus::Layout self)
798 CODE: 814 CODE:
799 g_object_unref (self->pl); 815 g_object_unref (self->pl);
800 Safefree (self); 816 Safefree (self);
801 817
802void 818void
803set_text (CFClient::Layout self, SV *text_) 819set_text (CFPlus::Layout self, SV *text_)
804 CODE: 820 CODE:
805{ 821{
806 STRLEN textlen; 822 STRLEN textlen;
807 char *text = SvPVutf8 (text_, textlen); 823 char *text = SvPVutf8 (text_, textlen);
808 824
809 pango_layout_set_text (self->pl, text, textlen); 825 pango_layout_set_text (self->pl, text, textlen);
810} 826}
811 827
812void 828void
813set_markup (CFClient::Layout self, SV *text_) 829set_markup (CFPlus::Layout self, SV *text_)
814 CODE: 830 CODE:
815{ 831{
816 STRLEN textlen; 832 STRLEN textlen;
817 char *text = SvPVutf8 (text_, textlen); 833 char *text = SvPVutf8 (text_, textlen);
818 834
819 pango_layout_set_markup (self->pl, text, textlen); 835 pango_layout_set_markup (self->pl, text, textlen);
820} 836}
821 837
822void 838void
823set_shapes (CFClient::Layout self, ...) 839set_shapes (CFPlus::Layout self, ...)
824 CODE: 840 CODE:
825{ 841{
826 PangoAttrList *attrs = 0; 842 PangoAttrList *attrs = 0;
827 const char *text = pango_layout_get_text (self->pl); 843 const char *text = pango_layout_get_text (self->pl);
828 const char *pos = text; 844 const char *pos = text;
863 if (attrs) 879 if (attrs)
864 pango_layout_set_attributes (self->pl, attrs); 880 pango_layout_set_attributes (self->pl, attrs);
865} 881}
866 882
867void 883void
868get_shapes (CFClient::Layout self) 884get_shapes (CFPlus::Layout self)
869 PPCODE: 885 PPCODE:
870{ 886{
871 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 887 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
872 888
873 do 889 do
877 if (run && shape_attr_p (run)) 893 if (run && shape_attr_p (run))
878 { 894 {
879 PangoRectangle extents; 895 PangoRectangle extents;
880 pango_layout_iter_get_run_extents (iter, 0, &extents); 896 pango_layout_iter_get_run_extents (iter, 0, &extents);
881 897
898 EXTEND (SP, 2);
882 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); 899 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x))));
883 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); 900 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y))));
884 } 901 }
885 } 902 }
886 while (pango_layout_iter_next_run (iter)); 903 while (pango_layout_iter_next_run (iter));
887 904
888 pango_layout_iter_free (iter); 905 pango_layout_iter_free (iter);
889} 906}
890 907
891int 908int
892has_wrapped (CFClient::Layout self) 909has_wrapped (CFPlus::Layout self)
893 CODE: 910 CODE:
894{ 911{
895 int lines = 1; 912 int lines = 1;
896 const char *text = pango_layout_get_text (self->pl); 913 const char *text = pango_layout_get_text (self->pl);
897 914
902} 919}
903 OUTPUT: 920 OUTPUT:
904 RETVAL 921 RETVAL
905 922
906SV * 923SV *
907get_text (CFClient::Layout self) 924get_text (CFPlus::Layout self)
908 CODE: 925 CODE:
909 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 926 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
910 sv_utf8_decode (RETVAL); 927 sv_utf8_decode (RETVAL);
911 OUTPUT: 928 OUTPUT:
912 RETVAL 929 RETVAL
913 930
914void 931void
915set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) 932set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.)
916 CODE: 933 CODE:
917 self->r = r; 934 self->r = r;
918 self->g = g; 935 self->g = g;
919 self->b = b; 936 self->b = b;
920 self->a = a; 937 self->a = a;
921 938
922void 939void
923set_font (CFClient::Layout self, CFClient::Font font = 0) 940set_font (CFPlus::Layout self, CFPlus::Font font = 0)
924 CODE: 941 CODE:
925 if (self->font != font) 942 if (self->font != font)
926 { 943 {
927 self->font = font; 944 self->font = font;
928 layout_update_font (self); 945 layout_update_font (self);
929 } 946 }
930 947
931void 948void
932set_height (CFClient::Layout self, int base_height) 949set_height (CFPlus::Layout self, int base_height)
933 CODE: 950 CODE:
934 if (self->base_height != base_height) 951 if (self->base_height != base_height)
935 { 952 {
936 self->base_height = base_height; 953 self->base_height = base_height;
937 layout_update_font (self); 954 layout_update_font (self);
938 } 955 }
939 956
940void 957void
941set_width (CFClient::Layout self, int max_width = -1) 958set_width (CFPlus::Layout self, int max_width = -1)
942 CODE: 959 CODE:
943 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 960 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
944 961
945void 962void
946set_indent (CFClient::Layout self, int indent) 963set_indent (CFPlus::Layout self, int indent)
947 CODE: 964 CODE:
948 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 965 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
949 966
950void 967void
951set_spacing (CFClient::Layout self, int spacing) 968set_spacing (CFPlus::Layout self, int spacing)
952 CODE: 969 CODE:
953 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 970 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
954 971
955void 972void
956set_ellipsise (CFClient::Layout self, int ellipsise) 973set_ellipsise (CFPlus::Layout self, int ellipsise)
957 CODE: 974 CODE:
958 pango_layout_set_ellipsize (self->pl, 975 pango_layout_set_ellipsize (self->pl,
959 ellipsise == 1 ? PANGO_ELLIPSIZE_START 976 ellipsise == 1 ? PANGO_ELLIPSIZE_START
960 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 977 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
961 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 978 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
962 : PANGO_ELLIPSIZE_NONE 979 : PANGO_ELLIPSIZE_NONE
963 ); 980 );
964 981
965void 982void
966set_single_paragraph_mode (CFClient::Layout self, int spm) 983set_single_paragraph_mode (CFPlus::Layout self, int spm)
967 CODE: 984 CODE:
968 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 985 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
969 986
970void 987void
971size (CFClient::Layout self) 988size (CFPlus::Layout self)
972 PPCODE: 989 PPCODE:
973{ 990{
974 int w, h; 991 int w, h;
975 992
976 layout_get_pixel_size (self, &w, &h); 993 layout_get_pixel_size (self, &w, &h);
979 PUSHs (sv_2mortal (newSViv (w))); 996 PUSHs (sv_2mortal (newSViv (w)));
980 PUSHs (sv_2mortal (newSViv (h))); 997 PUSHs (sv_2mortal (newSViv (h)));
981} 998}
982 999
983int 1000int
984descent (CFClient::Layout self) 1001descent (CFPlus::Layout self)
985 CODE: 1002 CODE:
986{ 1003{
987 PangoRectangle rect; 1004 PangoRectangle rect;
988 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1005 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
989 pango_layout_line_get_pixel_extents (line, 0, &rect); 1006 pango_layout_line_get_pixel_extents (line, 0, &rect);
991} 1008}
992 OUTPUT: 1009 OUTPUT:
993 RETVAL 1010 RETVAL
994 1011
995int 1012int
996xy_to_index (CFClient::Layout self, int x, int y) 1013xy_to_index (CFPlus::Layout self, int x, int y)
997 CODE: 1014 CODE:
998{ 1015{
999 int index, trailing; 1016 int index, trailing;
1000 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1017 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1001 RETVAL = index; 1018 RETVAL = index;
1002} 1019}
1003 OUTPUT: 1020 OUTPUT:
1004 RETVAL 1021 RETVAL
1005 1022
1006void 1023void
1007cursor_pos (CFClient::Layout self, int index) 1024cursor_pos (CFPlus::Layout self, int index)
1008 PPCODE: 1025 PPCODE:
1009{ 1026{
1010 PangoRectangle strong_pos; 1027 PangoRectangle strong_pos;
1011 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1028 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
1012 1029
1015 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1032 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1016 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1033 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1017} 1034}
1018 1035
1019void 1036void
1020render (CFClient::Layout self, float x, float y) 1037render (CFPlus::Layout self, float x, float y, int flags = 0)
1021 PPCODE: 1038 PPCODE:
1022 pango_opengl_render_layout_subpixel ( 1039 pango_opengl_render_layout_subpixel (
1023 self->pl, 1040 self->pl,
1024 x * PANGO_SCALE, y * PANGO_SCALE, 1041 x * PANGO_SCALE, y * PANGO_SCALE,
1025 self->r, self->g, self->b, self->a 1042 self->r, self->g, self->b, self->a,
1043 flags
1026 ); 1044 );
1027 1045
1028MODULE = CFClient PACKAGE = CFClient::Texture 1046MODULE = CFPlus PACKAGE = CFPlus::Texture
1029 1047
1030void 1048void
1031pad2pot (SV *data_, SV *w_, SV *h_) 1049pad2pot (SV *data_, SV *w_, SV *h_)
1032 CODE: 1050 CODE:
1033{ 1051{
1111 glDisable (GL_ALPHA_TEST); 1129 glDisable (GL_ALPHA_TEST);
1112 glDisable (GL_BLEND); 1130 glDisable (GL_BLEND);
1113 } 1131 }
1114} 1132}
1115 1133
1116MODULE = CFClient PACKAGE = CFClient::Map 1134MODULE = CFPlus PACKAGE = CFPlus::Map
1117 1135
1118CFClient::Map 1136CFPlus::Map
1119new (SV *class, int map_width, int map_height) 1137new (SV *class, int map_width, int map_height)
1120 CODE: 1138 CODE:
1121 New (0, RETVAL, 1, struct map); 1139 New (0, RETVAL, 1, struct map);
1122 RETVAL->x = 0; 1140 RETVAL->x = 0;
1123 RETVAL->y = 0; 1141 RETVAL->y = 0;
1133 RETVAL->row = 0; 1151 RETVAL->row = 0;
1134 OUTPUT: 1152 OUTPUT:
1135 RETVAL 1153 RETVAL
1136 1154
1137void 1155void
1138DESTROY (CFClient::Map self) 1156DESTROY (CFPlus::Map self)
1139 CODE: 1157 CODE:
1140{ 1158{
1141 map_clear (self); 1159 map_clear (self);
1142 Safefree (self->face); 1160 Safefree (self->face);
1143 Safefree (self->tex); 1161 Safefree (self->tex);
1144 Safefree (self); 1162 Safefree (self);
1145} 1163}
1146 1164
1147void 1165void
1148clear (CFClient::Map self) 1166clear (CFPlus::Map self)
1149 CODE: 1167 CODE:
1150 map_clear (self); 1168 map_clear (self);
1151 1169
1152void 1170void
1153set_face (CFClient::Map self, int face, int texid) 1171set_face (CFPlus::Map self, int face, int texid)
1154 CODE: 1172 CODE:
1155{ 1173{
1156 while (self->faces <= face) 1174 while (self->faces <= face)
1157 { 1175 {
1158 Append (mapface, self->face, self->faces, self->faces); 1176 Append (mapface, self->face, self->faces, self->faces);
1161 1179
1162 self->face [face] = texid; 1180 self->face [face] = texid;
1163} 1181}
1164 1182
1165void 1183void
1166set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1184set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1167 CODE: 1185 CODE:
1168{ 1186{
1169 while (self->texs <= texid) 1187 while (self->texs <= texid)
1170 { 1188 {
1171 Append (maptex, self->tex, self->texs, self->texs); 1189 Append (maptex, self->tex, self->texs, self->texs);
1195 // from transparent color bleeding and ugly wrapping effects. 1213 // from transparent color bleeding and ugly wrapping effects.
1196 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1214 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1197} 1215}
1198 1216
1199int 1217int
1200ox (CFClient::Map self) 1218ox (CFPlus::Map self)
1201 ALIAS: 1219 ALIAS:
1202 oy = 1 1220 oy = 1
1203 x = 2 1221 x = 2
1204 y = 3 1222 y = 3
1205 w = 4 1223 w = 4
1216 } 1234 }
1217 OUTPUT: 1235 OUTPUT:
1218 RETVAL 1236 RETVAL
1219 1237
1220void 1238void
1221scroll (CFClient::Map self, int dx, int dy) 1239scroll (CFPlus::Map self, int dx, int dy)
1222 CODE: 1240 CODE:
1223{ 1241{
1224 if (dx > 0) 1242 if (dx > 0)
1225 map_blank (self, self->x, self->y, dx - 1, self->h); 1243 map_blank (self, self->x, self->y, dx - 1, self->h);
1226 else if (dx < 0) 1244 else if (dx < 0)
1242 self->y += MAP_EXTEND_Y; 1260 self->y += MAP_EXTEND_Y;
1243 } 1261 }
1244} 1262}
1245 1263
1246void 1264void
1247map1a_update (CFClient::Map self, SV *data_) 1265map1a_update (CFPlus::Map self, SV *data_, int extmap)
1248 CODE: 1266 CODE:
1249{ 1267{
1250 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1268 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1251 uint8_t *data_end = (uint8_t *)SvEND (data_); 1269 uint8_t *data_end = (uint8_t *)SvEND (data_);
1252 mapcell *cell; 1270 mapcell *cell;
1269 cell->face [0] = 0; 1287 cell->face [0] = 0;
1270 cell->face [1] = 0; 1288 cell->face [1] = 0;
1271 cell->face [2] = 0; 1289 cell->face [2] = 0;
1272 } 1290 }
1273 1291
1292 if (flags & 8)
1293 {
1294 fprintf (stderr, "oi\n");//D
1295 if (extmap)
1296 {
1297 uint8_t ext, cmd;
1298
1299 do
1300 {
1301
1302 ext = *data++;
1303 cmd = ext & 0x7f;
1304
1305 fprintf (stderr, "extcmd = %x\n", ext);//D
1306
1307 if (ext < 4)
1308 cell->darkness = 255 - ext * 64;
1309 }
1310 while (cmd & 0x80);
1311 }
1312 else
1274 cell->darkness = flags & 8 ? *data++ : 255; 1313 cell->darkness = flags & 8 ? *data++ : 255;
1314 }
1275 1315
1276 //TODO: don't trust server data to be in-range(!) 1316 //TODO: don't trust server data to be in-range(!)
1277 1317
1278 if (flags & 4) 1318 if (flags & 4)
1279 { 1319 {
1294 cell->darkness = -1; 1334 cell->darkness = -1;
1295 } 1335 }
1296} 1336}
1297 1337
1298SV * 1338SV *
1299mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1339mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1300 CODE: 1340 CODE:
1301{ 1341{
1302 int x1, x; 1342 int x1, x;
1303 int y1, y; 1343 int y1, y;
1304 int z; 1344 int z;
1354} 1394}
1355 OUTPUT: 1395 OUTPUT:
1356 RETVAL 1396 RETVAL
1357 1397
1358void 1398void
1359draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1399draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1360 CODE: 1400 CODE:
1361{ 1401{
1362 int vx, vy; 1402 int vx, vy;
1363 int x, y, z; 1403 int x, y, z;
1364 int last_name; 1404 int last_name;
1429 glDisable (GL_TEXTURE_2D); 1469 glDisable (GL_TEXTURE_2D);
1430 glDisable (GL_BLEND); 1470 glDisable (GL_BLEND);
1431} 1471}
1432 1472
1433void 1473void
1434draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) 1474draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1435 CODE: 1475 CODE:
1436{ 1476{
1437 static float color[16][3] = { 1477 static float color[16][3] = {
1438 { 0.00F, 0.00F, 0.00F }, 1478 { 0.00F, 0.00F, 0.00F },
1439 { 1.00F, 1.00F, 1.00F }, 1479 { 1.00F, 1.00F, 1.00F },
1489 glDisable (GL_BLEND); 1529 glDisable (GL_BLEND);
1490 glDisable (GL_TEXTURE_2D); 1530 glDisable (GL_TEXTURE_2D);
1491} 1531}
1492 1532
1493void 1533void
1494fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1534fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1495 PPCODE: 1535 PPCODE:
1496{ 1536{
1497 int vx, vy; 1537 int vx, vy;
1498 int x, y; 1538 int x, y;
1499 int sw4 = (sw + 3) & ~3; 1539 int sw4 = (sw + 3) & ~3;
1528 PUSHs (sv_2mortal (newSViv (sh))); 1568 PUSHs (sv_2mortal (newSViv (sh)));
1529 PUSHs (darkness_sv); 1569 PUSHs (darkness_sv);
1530} 1570}
1531 1571
1532SV * 1572SV *
1533get_rect (CFClient::Map self, int x0, int y0, int w, int h) 1573get_rect (CFPlus::Map self, int x0, int y0, int w, int h)
1534 CODE: 1574 CODE:
1535{ 1575{
1536 int x, y, x1, y1; 1576 int x, y, x1, y1;
1537 SV *data_sv = newSV (w * h * 7 + 5); 1577 SV *data_sv = newSV (w * h * 7 + 5);
1538 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1578 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1600} 1640}
1601 OUTPUT: 1641 OUTPUT:
1602 RETVAL 1642 RETVAL
1603 1643
1604void 1644void
1605set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1645set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1606 PPCODE: 1646 PPCODE:
1607{ 1647{
1608 int x, y, z; 1648 int x, y, z;
1609 int w, h; 1649 int w, h;
1610 int x1, y1; 1650 int x1, y1;
1659 } 1699 }
1660 } 1700 }
1661 } 1701 }
1662} 1702}
1663 1703
1664MODULE = CFClient PACKAGE = CFClient::MixChunk 1704MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1665 1705
1666CFClient::MixChunk 1706CFPlus::MixChunk
1667new_from_file (SV *class, char *path) 1707new_from_file (SV *class, char *path)
1668 CODE: 1708 CODE:
1669 RETVAL = Mix_LoadWAV (path); 1709 RETVAL = Mix_LoadWAV (path);
1670 OUTPUT: 1710 OUTPUT:
1671 RETVAL 1711 RETVAL
1672 1712
1673void 1713void
1674DESTROY (CFClient::MixChunk self) 1714DESTROY (CFPlus::MixChunk self)
1675 CODE: 1715 CODE:
1676 Mix_FreeChunk (self); 1716 Mix_FreeChunk (self);
1677 1717
1678int 1718int
1679volume (CFClient::MixChunk self, int volume = -1) 1719volume (CFPlus::MixChunk self, int volume = -1)
1680 CODE: 1720 CODE:
1681 RETVAL = Mix_VolumeChunk (self, volume); 1721 RETVAL = Mix_VolumeChunk (self, volume);
1682 OUTPUT: 1722 OUTPUT:
1683 RETVAL 1723 RETVAL
1684 1724
1685int 1725int
1686play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) 1726play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1)
1687 CODE: 1727 CODE:
1688 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1728 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1689 OUTPUT: 1729 OUTPUT:
1690 RETVAL 1730 RETVAL
1691 1731
1692MODULE = CFClient PACKAGE = CFClient::MixMusic 1732MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1693 1733
1694int 1734int
1695volume (int volume = -1) 1735volume (int volume = -1)
1696 CODE: 1736 CODE:
1697 RETVAL = Mix_VolumeMusic (volume); 1737 RETVAL = Mix_VolumeMusic (volume);
1698 OUTPUT: 1738 OUTPUT:
1699 RETVAL 1739 RETVAL
1700 1740
1701CFClient::MixMusic 1741CFPlus::MixMusic
1702new_from_file (SV *class, char *path) 1742new_from_file (SV *class, char *path)
1703 CODE: 1743 CODE:
1704 RETVAL = Mix_LoadMUS (path); 1744 RETVAL = Mix_LoadMUS (path);
1705 OUTPUT: 1745 OUTPUT:
1706 RETVAL 1746 RETVAL
1707 1747
1708void 1748void
1709DESTROY (CFClient::MixMusic self) 1749DESTROY (CFPlus::MixMusic self)
1710 CODE: 1750 CODE:
1711 Mix_FreeMusic (self); 1751 Mix_FreeMusic (self);
1712 1752
1713int 1753int
1714play (CFClient::MixMusic self, int loops = -1) 1754play (CFPlus::MixMusic self, int loops = -1)
1715 CODE: 1755 CODE:
1716 RETVAL = Mix_PlayMusic (self, loops); 1756 RETVAL = Mix_PlayMusic (self, loops);
1717 OUTPUT: 1757 OUTPUT:
1718 RETVAL 1758 RETVAL
1719 1759
1720MODULE = CFClient PACKAGE = CFClient::OpenGL 1760MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1721 1761
1722BOOT: 1762BOOT:
1723{ 1763{
1724 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1764 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1725 static const struct { 1765 static const struct {
1726 const char *name; 1766 const char *name;
1727 IV iv; 1767 IV iv;
1728 } *civ, const_iv[] = { 1768 } *civ, const_iv[] = {
1729# define const_iv(name) { # name, (IV)name } 1769# define const_iv(name) { # name, (IV)name }
1792 const_iv (GL_SEPARABLE_2D), 1832 const_iv (GL_SEPARABLE_2D),
1793 const_iv (GL_CONVOLUTION_2D), 1833 const_iv (GL_CONVOLUTION_2D),
1794 const_iv (GL_CONVOLUTION_BORDER_MODE), 1834 const_iv (GL_CONVOLUTION_BORDER_MODE),
1795 const_iv (GL_CONSTANT_BORDER), 1835 const_iv (GL_CONSTANT_BORDER),
1796 const_iv (GL_LINES), 1836 const_iv (GL_LINES),
1837 const_iv (GL_LINE_STRIP),
1797 const_iv (GL_LINE_LOOP), 1838 const_iv (GL_LINE_LOOP),
1798 const_iv (GL_QUADS), 1839 const_iv (GL_QUADS),
1799 const_iv (GL_QUAD_STRIP), 1840 const_iv (GL_QUAD_STRIP),
1800 const_iv (GL_TRIANGLES), 1841 const_iv (GL_TRIANGLES),
1801 const_iv (GL_TRIANGLE_STRIP), 1842 const_iv (GL_TRIANGLE_STRIP),
1911 r *= a; 1952 r *= a;
1912 g *= a; 1953 g *= a;
1913 b *= a; 1954 b *= a;
1914 } 1955 }
1915 // microsoft visual "c" rounds instead of truncating... 1956 // microsoft visual "c" rounds instead of truncating...
1916 glColor4ub (MIN ((int)(r * 256.f), 255), 1957 glColor4f (r, g, b, a);
1917 MIN ((int)(g * 256.f), 255),
1918 MIN ((int)(b * 256.f), 255),
1919 MIN ((int)(a * 256.f), 255));
1920 1958
1921void glInterleavedArrays (int format, int stride, char *data) 1959void glInterleavedArrays (int format, int stride, char *data)
1922 1960
1923void glDrawElements (int mode, int count, int type, char *indices) 1961void glDrawElements (int mode, int count, int type, char *indices)
1924 1962
2001 2039
2002void glEndList () 2040void glEndList ()
2003 2041
2004void glCallList (int list) 2042void glCallList (int list)
2005 2043
2006

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines