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.126 by root, Tue Jul 4 23:56:34 2006 UTC vs.
Revision 1.142 by root, Fri Aug 18 01:27:15 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{
149 PangoRectangle rect;
150
151 // get_pixel_* wrongly rounds down
146 pango_layout_get_pixel_size (self->pl, w, h); 152 pango_layout_get_extents (self->pl, 0, &rect);
147 153
148 if (!*w) *w = 1; 154 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
149 if (!*h) *h = 1; 155 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
150 156
151 *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;
152} 162}
153 163
154typedef uint16_t mapface; 164typedef uint16_t mapface;
155 165
156typedef struct { 166typedef struct {
159 float s, t; 169 float s, t;
160 uint8_t r, g, b, a; 170 uint8_t r, g, b, a;
161} maptex; 171} maptex;
162 172
163typedef struct { 173typedef struct {
164 int16_t darkness; 174 uint16_t darkness;
165 mapface face[3]; 175 mapface face[3];
176 uint8_t stat_hp;
166} mapcell; 177} mapcell;
167 178
168typedef struct { 179typedef struct {
169 int32_t c0, c1; 180 int32_t c0, c1;
170 mapcell *col; 181 mapcell *col;
179 int texs; 190 int texs;
180 maptex *tex; 191 maptex *tex;
181 192
182 int32_t rows; 193 int32_t rows;
183 maprow *row; 194 maprow *row;
184} *CFClient__Map; 195} *CFPlus__Map;
185 196
186static char * 197static char *
187prepend (char *ptr, int sze, int inc) 198prepend (char *ptr, int sze, int inc)
188{ 199{
189 char *p; 200 char *p;
207 218
208#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 219#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)) 220#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
210 221
211static maprow * 222static maprow *
212map_get_row (CFClient__Map self, int y) 223map_get_row (CFPlus__Map self, int y)
213{ 224{
214 if (0 > y) 225 if (0 > y)
215 { 226 {
216 int extend = - y + MAP_EXTEND_Y; 227 int extend = - y + MAP_EXTEND_Y;
217 Prepend (maprow, self->row, self->rows, extend); 228 Prepend (maprow, self->row, self->rows, extend);
255 266
256 return row->col + (x - row->c0); 267 return row->col + (x - row->c0);
257} 268}
258 269
259static mapcell * 270static mapcell *
260map_get_cell (CFClient__Map self, int x, int y) 271map_get_cell (CFPlus__Map self, int x, int y)
261{ 272{
262 return row_get_cell (map_get_row (self, y), x); 273 return row_get_cell (map_get_row (self, y), x);
263} 274}
264 275
265static void 276static void
266map_clear (CFClient__Map self) 277map_clear (CFPlus__Map self)
267{ 278{
268 int r; 279 int r;
269 280
270 for (r = 0; r < self->rows; r++) 281 for (r = 0; r < self->rows; r++)
271 Safefree (self->row[r].col); 282 Safefree (self->row[r].col);
279 self->row = 0; 290 self->row = 0;
280 self->rows = 0; 291 self->rows = 0;
281} 292}
282 293
283static void 294static void
284map_blank (CFClient__Map self, int x0, int y0, int w, int h) 295map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
285{ 296{
286 int x, y; 297 int x, y;
287 maprow *row; 298 maprow *row;
288 299
289 for (y = y0; y < y0 + h; y++) 300 for (y = y0; y < y0 + h; y++)
298 if (x >= row->c0) 309 if (x >= row->c0)
299 { 310 {
300 if (x >= row->c1) 311 if (x >= row->c1)
301 break; 312 break;
302 313
303 row->col[x - row->c0].darkness = -1; 314 row->col[x - row->c0].darkness = 0;
304 } 315 }
305 } 316 }
306} 317}
307 318
308static void 319static void
346 n |= n >> 16; 357 n |= n >> 16;
347 358
348 return n + 1; 359 return n + 1;
349} 360}
350 361
351MODULE = CFClient PACKAGE = CFClient 362MODULE = CFPlus PACKAGE = CFPlus
352 363
353PROTOTYPES: ENABLE 364PROTOTYPES: ENABLE
354 365
355BOOT: 366BOOT:
356{ 367{
357 HV *stash = gv_stashpv ("CFClient", 1); 368 HV *stash = gv_stashpv ("CFPlus", 1);
358 static const struct { 369 static const struct {
359 const char *name; 370 const char *name;
360 IV iv; 371 IV iv;
361 } *civ, const_iv[] = { 372 } *civ, const_iv[] = {
362# define const_iv(name) { # name, (IV)name } 373# define const_iv(name) { # name, (IV)name }
463 474
464 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 475 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
465 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 476 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
466} 477}
467 478
479int
480in_destruct ()
481 CODE:
482 RETVAL = PL_main_cv == Nullcv;
483 OUTPUT:
484 RETVAL
485
468NV floor (NV x) 486NV floor (NV x)
469 487
470NV ceil (NV x) 488NV ceil (NV x)
471 489
472void 490void
502 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 520 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
503 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 521 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
504 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 522 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
505 523
506 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 524 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
525#if SDL_VERSION_ATLEAST(1,2,10)
526 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
527 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
528#endif
507 529
508 SDL_EnableUNICODE (1); 530 SDL_EnableUNICODE (1);
509 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 531 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
510 532
511 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 533 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
598 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 620 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
599 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 621 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
600 break; 622 break;
601 } 623 }
602 624
603 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 625 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
604 } 626 }
605} 627}
606 628
607int 629int
608Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) 630Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048)
624#endif 646#endif
625 647
626void 648void
627add_font (char *file) 649add_font (char *file)
628 CODE: 650 CODE:
629 FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ 651 FcConfigAppFontAddFile (0, (const FcChar8 *)file);
630 652
631void 653void
632load_image_inline (SV *image_) 654load_image_inline (SV *image_)
633 ALIAS: 655 ALIAS:
634 load_image_file = 1 656 load_image_file = 1
676 698
677 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); 699 surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE);
678 700
679 assert (surface2->pitch == surface2->w * 4); 701 assert (surface2->pitch == surface2->w * 4);
680 702
703 SDL_LockSurface (surface2);
681 EXTEND (SP, 5); 704 EXTEND (SP, 6);
682 PUSHs (sv_2mortal (newSViv (surface2->w))); 705 PUSHs (sv_2mortal (newSViv (surface2->w)));
683 PUSHs (sv_2mortal (newSViv (surface2->h))); 706 PUSHs (sv_2mortal (newSViv (surface2->h)));
684 SDL_LockSurface (surface2);
685 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 707 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))); 708 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
688 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 709 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
689 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); 710 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
711 SDL_UnlockSurface (surface2);
690 712
691 SDL_FreeSurface (surface); 713 SDL_FreeSurface (surface);
692 SDL_FreeSurface (surface2); 714 SDL_FreeSurface (surface2);
693} 715}
694 716
737void 759void
738_exit (int retval) 760_exit (int retval)
739 CODE: 761 CODE:
740 _exit (retval); 762 _exit (retval);
741 763
742MODULE = CFClient PACKAGE = CFClient::Font 764MODULE = CFPlus PACKAGE = CFPlus::Font
743 765
744CFClient::Font 766CFPlus::Font
745new_from_file (SV *class, char *path, int id = 0) 767new_from_file (SV *class, char *path, int id = 0)
746 CODE: 768 CODE:
747{ 769{
748 int count; 770 int count;
749 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 771 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
752} 774}
753 OUTPUT: 775 OUTPUT:
754 RETVAL 776 RETVAL
755 777
756void 778void
757DESTROY (CFClient::Font self) 779DESTROY (CFPlus::Font self)
758 CODE: 780 CODE:
759 pango_font_description_free (self); 781 pango_font_description_free (self);
760 782
761void 783void
762make_default (CFClient::Font self) 784make_default (CFPlus::Font self)
763 CODE: 785 CODE:
764 default_font = self; 786 default_font = self;
765 787
766MODULE = CFClient PACKAGE = CFClient::Layout 788MODULE = CFPlus PACKAGE = CFPlus::Layout
767 789
768void 790void
769clear_font_cache () 791reset_glyph_cache ()
770 CODE: 792 CODE:
771 tc_clear (); 793 tc_clear ();
772 794
773CFClient::Layout 795CFPlus::Layout
774new (SV *class, int type = 0) 796new (SV *class)
775 CODE: 797 CODE:
776 New (0, RETVAL, 1, struct cf_layout); 798 New (0, RETVAL, 1, struct cf_layout);
777 799
778 RETVAL->pl = pango_layout_new (opengl_context); 800 RETVAL->pl = pango_layout_new (opengl_context);
779 RETVAL->r = 1.; 801 RETVAL->r = 1.;
787 layout_update_font (RETVAL); 809 layout_update_font (RETVAL);
788 OUTPUT: 810 OUTPUT:
789 RETVAL 811 RETVAL
790 812
791void 813void
792DESTROY (CFClient::Layout self) 814DESTROY (CFPlus::Layout self)
793 CODE: 815 CODE:
794 g_object_unref (self->pl); 816 g_object_unref (self->pl);
795 Safefree (self); 817 Safefree (self);
796 818
797void 819void
798set_text (CFClient::Layout self, SV *text_) 820set_text (CFPlus::Layout self, SV *text_)
799 CODE: 821 CODE:
800{ 822{
801 STRLEN textlen; 823 STRLEN textlen;
802 char *text = SvPVutf8 (text_, textlen); 824 char *text = SvPVutf8 (text_, textlen);
803 825
804 pango_layout_set_text (self->pl, text, textlen); 826 pango_layout_set_text (self->pl, text, textlen);
805} 827}
806 828
807void 829void
808set_markup (CFClient::Layout self, SV *text_) 830set_markup (CFPlus::Layout self, SV *text_)
809 CODE: 831 CODE:
810{ 832{
811 STRLEN textlen; 833 STRLEN textlen;
812 char *text = SvPVutf8 (text_, textlen); 834 char *text = SvPVutf8 (text_, textlen);
813 835
814 pango_layout_set_markup (self->pl, text, textlen); 836 pango_layout_set_markup (self->pl, text, textlen);
815} 837}
816 838
817void 839void
818set_shapes (CFClient::Layout self, ...) 840set_shapes (CFPlus::Layout self, ...)
819 CODE: 841 CODE:
820{ 842{
821 PangoAttrList *attrs = 0; 843 PangoAttrList *attrs = 0;
822 const char *text = pango_layout_get_text (self->pl); 844 const char *text = pango_layout_get_text (self->pl);
823 const char *pos = text; 845 const char *pos = text;
858 if (attrs) 880 if (attrs)
859 pango_layout_set_attributes (self->pl, attrs); 881 pango_layout_set_attributes (self->pl, attrs);
860} 882}
861 883
862void 884void
863get_shapes (CFClient::Layout self) 885get_shapes (CFPlus::Layout self)
864 PPCODE: 886 PPCODE:
865{ 887{
866 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 888 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
867 889
868 do 890 do
872 if (run && shape_attr_p (run)) 894 if (run && shape_attr_p (run))
873 { 895 {
874 PangoRectangle extents; 896 PangoRectangle extents;
875 pango_layout_iter_get_run_extents (iter, 0, &extents); 897 pango_layout_iter_get_run_extents (iter, 0, &extents);
876 898
899 EXTEND (SP, 2);
877 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); 900 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x))));
878 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); 901 PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y))));
879 } 902 }
880 } 903 }
881 while (pango_layout_iter_next_run (iter)); 904 while (pango_layout_iter_next_run (iter));
882 905
883 pango_layout_iter_free (iter); 906 pango_layout_iter_free (iter);
884} 907}
885 908
886int 909int
887has_wrapped (CFClient::Layout self) 910has_wrapped (CFPlus::Layout self)
888 CODE: 911 CODE:
889{ 912{
890 int lines = 1; 913 int lines = 1;
891 const char *text = pango_layout_get_text (self->pl); 914 const char *text = pango_layout_get_text (self->pl);
892 915
897} 920}
898 OUTPUT: 921 OUTPUT:
899 RETVAL 922 RETVAL
900 923
901SV * 924SV *
902get_text (CFClient::Layout self) 925get_text (CFPlus::Layout self)
903 CODE: 926 CODE:
904 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 927 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
905 sv_utf8_decode (RETVAL); 928 sv_utf8_decode (RETVAL);
906 OUTPUT: 929 OUTPUT:
907 RETVAL 930 RETVAL
908 931
909void 932void
910set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) 933set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.)
911 CODE: 934 CODE:
912 self->r = r; 935 self->r = r;
913 self->g = g; 936 self->g = g;
914 self->b = b; 937 self->b = b;
915 self->a = a; 938 self->a = a;
916 939
917void 940void
918set_font (CFClient::Layout self, CFClient::Font font = 0) 941set_font (CFPlus::Layout self, CFPlus::Font font = 0)
919 CODE: 942 CODE:
920 if (self->font != font) 943 if (self->font != font)
921 { 944 {
922 self->font = font; 945 self->font = font;
923 layout_update_font (self); 946 layout_update_font (self);
924 } 947 }
925 948
926void 949void
927set_height (CFClient::Layout self, int base_height) 950set_height (CFPlus::Layout self, int base_height)
928 CODE: 951 CODE:
929 if (self->base_height != base_height) 952 if (self->base_height != base_height)
930 { 953 {
931 self->base_height = base_height; 954 self->base_height = base_height;
932 layout_update_font (self); 955 layout_update_font (self);
933 } 956 }
934 957
935void 958void
936set_width (CFClient::Layout self, int max_width = -1) 959set_width (CFPlus::Layout self, int max_width = -1)
937 CODE: 960 CODE:
938 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 961 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
939 962
940void 963void
941set_indent (CFClient::Layout self, int indent) 964set_indent (CFPlus::Layout self, int indent)
942 CODE: 965 CODE:
943 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 966 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
944 967
945void 968void
946set_spacing (CFClient::Layout self, int spacing) 969set_spacing (CFPlus::Layout self, int spacing)
947 CODE: 970 CODE:
948 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 971 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
949 972
950void 973void
951set_ellipsise (CFClient::Layout self, int ellipsise) 974set_ellipsise (CFPlus::Layout self, int ellipsise)
952 CODE: 975 CODE:
953 pango_layout_set_ellipsize (self->pl, 976 pango_layout_set_ellipsize (self->pl,
954 ellipsise == 1 ? PANGO_ELLIPSIZE_START 977 ellipsise == 1 ? PANGO_ELLIPSIZE_START
955 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 978 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
956 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 979 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
957 : PANGO_ELLIPSIZE_NONE 980 : PANGO_ELLIPSIZE_NONE
958 ); 981 );
959 982
960void 983void
961set_single_paragraph_mode (CFClient::Layout self, int spm) 984set_single_paragraph_mode (CFPlus::Layout self, int spm)
962 CODE: 985 CODE:
963 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 986 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
964 987
965void 988void
966size (CFClient::Layout self) 989size (CFPlus::Layout self)
967 PPCODE: 990 PPCODE:
968{ 991{
969 int w, h; 992 int w, h;
970 993
971 layout_get_pixel_size (self, &w, &h); 994 layout_get_pixel_size (self, &w, &h);
974 PUSHs (sv_2mortal (newSViv (w))); 997 PUSHs (sv_2mortal (newSViv (w)));
975 PUSHs (sv_2mortal (newSViv (h))); 998 PUSHs (sv_2mortal (newSViv (h)));
976} 999}
977 1000
978int 1001int
979descent (CFClient::Layout self) 1002descent (CFPlus::Layout self)
980 CODE: 1003 CODE:
981{ 1004{
982 PangoRectangle rect; 1005 PangoRectangle rect;
983 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1006 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
984 pango_layout_line_get_pixel_extents (line, 0, &rect); 1007 pango_layout_line_get_pixel_extents (line, 0, &rect);
986} 1009}
987 OUTPUT: 1010 OUTPUT:
988 RETVAL 1011 RETVAL
989 1012
990int 1013int
991xy_to_index (CFClient::Layout self, int x, int y) 1014xy_to_index (CFPlus::Layout self, int x, int y)
992 CODE: 1015 CODE:
993{ 1016{
994 int index, trailing; 1017 int index, trailing;
995 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1018 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
996 RETVAL = index; 1019 RETVAL = index;
997} 1020}
998 OUTPUT: 1021 OUTPUT:
999 RETVAL 1022 RETVAL
1000 1023
1001void 1024void
1002cursor_pos (CFClient::Layout self, int index) 1025cursor_pos (CFPlus::Layout self, int index)
1003 PPCODE: 1026 PPCODE:
1004{ 1027{
1005 PangoRectangle strong_pos; 1028 PangoRectangle strong_pos;
1006 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1029 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
1007 1030
1010 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1033 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1011 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1034 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1012} 1035}
1013 1036
1014void 1037void
1015render (CFClient::Layout self, float x, float y) 1038render (CFPlus::Layout self, float x, float y, int flags = 0)
1016 PPCODE: 1039 PPCODE:
1017 pango_opengl_render_layout_subpixel ( 1040 pango_opengl_render_layout_subpixel (
1018 self->pl, 1041 self->pl,
1019 x * PANGO_SCALE, y * PANGO_SCALE, 1042 x * PANGO_SCALE, y * PANGO_SCALE,
1020 self->r, self->g, self->b, self->a 1043 self->r, self->g, self->b, self->a,
1044 flags
1021 ); 1045 );
1022 1046
1023MODULE = CFClient PACKAGE = CFClient::Texture 1047MODULE = CFPlus PACKAGE = CFPlus::Texture
1024 1048
1025void 1049void
1026pad2pot (SV *data_, SV *w_, SV *h_) 1050pad2pot (SV *data_, SV *w_, SV *h_)
1027 CODE: 1051 CODE:
1028{ 1052{
1106 glDisable (GL_ALPHA_TEST); 1130 glDisable (GL_ALPHA_TEST);
1107 glDisable (GL_BLEND); 1131 glDisable (GL_BLEND);
1108 } 1132 }
1109} 1133}
1110 1134
1111MODULE = CFClient PACKAGE = CFClient::Map 1135MODULE = CFPlus PACKAGE = CFPlus::Map
1112 1136
1113CFClient::Map 1137CFPlus::Map
1114new (SV *class, int map_width, int map_height) 1138new (SV *class, int map_width, int map_height)
1115 CODE: 1139 CODE:
1116 New (0, RETVAL, 1, struct map); 1140 New (0, RETVAL, 1, struct map);
1117 RETVAL->x = 0; 1141 RETVAL->x = 0;
1118 RETVAL->y = 0; 1142 RETVAL->y = 0;
1128 RETVAL->row = 0; 1152 RETVAL->row = 0;
1129 OUTPUT: 1153 OUTPUT:
1130 RETVAL 1154 RETVAL
1131 1155
1132void 1156void
1133DESTROY (CFClient::Map self) 1157DESTROY (CFPlus::Map self)
1134 CODE: 1158 CODE:
1135{ 1159{
1136 map_clear (self); 1160 map_clear (self);
1137 Safefree (self->face); 1161 Safefree (self->face);
1138 Safefree (self->tex); 1162 Safefree (self->tex);
1139 Safefree (self); 1163 Safefree (self);
1140} 1164}
1141 1165
1142void 1166void
1143clear (CFClient::Map self) 1167clear (CFPlus::Map self)
1144 CODE: 1168 CODE:
1145 map_clear (self); 1169 map_clear (self);
1146 1170
1147void 1171void
1148set_face (CFClient::Map self, int face, int texid) 1172set_face (CFPlus::Map self, int face, int texid)
1149 CODE: 1173 CODE:
1150{ 1174{
1151 while (self->faces <= face) 1175 while (self->faces <= face)
1152 { 1176 {
1153 Append (mapface, self->face, self->faces, self->faces); 1177 Append (mapface, self->face, self->faces, self->faces);
1156 1180
1157 self->face [face] = texid; 1181 self->face [face] = texid;
1158} 1182}
1159 1183
1160void 1184void
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) 1185set_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: 1186 CODE:
1163{ 1187{
1164 while (self->texs <= texid) 1188 while (self->texs <= texid)
1165 { 1189 {
1166 Append (maptex, self->tex, self->texs, self->texs); 1190 Append (maptex, self->tex, self->texs, self->texs);
1190 // from transparent color bleeding and ugly wrapping effects. 1214 // from transparent color bleeding and ugly wrapping effects.
1191 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1215 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1192} 1216}
1193 1217
1194int 1218int
1195ox (CFClient::Map self) 1219ox (CFPlus::Map self)
1196 ALIAS: 1220 ALIAS:
1197 oy = 1 1221 oy = 1
1198 x = 2 1222 x = 2
1199 y = 3 1223 y = 3
1200 w = 4 1224 w = 4
1211 } 1235 }
1212 OUTPUT: 1236 OUTPUT:
1213 RETVAL 1237 RETVAL
1214 1238
1215void 1239void
1216scroll (CFClient::Map self, int dx, int dy) 1240scroll (CFPlus::Map self, int dx, int dy)
1217 CODE: 1241 CODE:
1218{ 1242{
1219 if (dx > 0) 1243 if (dx > 0)
1220 map_blank (self, self->x, self->y, dx - 1, self->h); 1244 map_blank (self, self->x, self->y, dx - 1, self->h);
1221 else if (dx < 0) 1245 else if (dx < 0)
1237 self->y += MAP_EXTEND_Y; 1261 self->y += MAP_EXTEND_Y;
1238 } 1262 }
1239} 1263}
1240 1264
1241void 1265void
1242map1a_update (CFClient::Map self, SV *data_) 1266map1a_update (CFPlus::Map self, SV *data_, int extmap)
1243 CODE: 1267 CODE:
1244{ 1268{
1245 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1269 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1246 uint8_t *data_end = (uint8_t *)SvEND (data_); 1270 uint8_t *data_end = (uint8_t *)SvEND (data_);
1247 mapcell *cell; 1271 mapcell *cell;
1256 1280
1257 cell = map_get_cell (self, x, y); 1281 cell = map_get_cell (self, x, y);
1258 1282
1259 if (flags & 15) 1283 if (flags & 15)
1260 { 1284 {
1261 if (cell->darkness < 0) 1285 if (!cell->darkness)
1262 { 1286 {
1263 cell->darkness = 0; 1287 cell->darkness = 256;
1264 cell->face [0] = 0; 1288 cell->face [0] = 0;
1265 cell->face [1] = 0; 1289 cell->face [1] = 0;
1266 cell->face [2] = 0; 1290 cell->face [2] = 0;
1267 } 1291 }
1268 1292
1269 cell->darkness = flags & 8 ? *data++ : 255;
1270
1271 //TODO: don't trust server data to be in-range(!) 1293 //TODO: don't trust server data to be in-range(!)
1294
1295 if (flags & 8)
1296 {
1297 if (extmap)
1298 {
1299 uint8_t ext, cmd;
1300
1301 do
1302 {
1303 ext = *data++;
1304 cmd = ext & 0x7f;
1305
1306 if (ext < 4)
1307 cell->darkness = 255 - ext * 64 + 1;
1308 else if (ext == 5) // health
1309 cell->stat_hp = *data++;
1310 }
1311 while (cmd & 0x80);
1312 }
1313 else
1314 cell->darkness = *data++ + 1;
1315 }
1272 1316
1273 if (flags & 4) 1317 if (flags & 4)
1274 { 1318 {
1275 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1319 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1276 } 1320 }
1284 { 1328 {
1285 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1329 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1286 } 1330 }
1287 } 1331 }
1288 else 1332 else
1289 cell->darkness = -1; 1333 cell->darkness = 0;
1290 } 1334 }
1291} 1335}
1292 1336
1293SV * 1337SV *
1294mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1338mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1295 CODE: 1339 CODE:
1296{ 1340{
1297 int x1, x; 1341 int x1, x;
1298 int y1, y; 1342 int y1, y;
1299 int z; 1343 int z;
1349} 1393}
1350 OUTPUT: 1394 OUTPUT:
1351 RETVAL 1395 RETVAL
1352 1396
1353void 1397void
1354draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1398draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1355 CODE: 1399 CODE:
1356{ 1400{
1357 int vx, vy; 1401 int vx, vy;
1358 int x, y, z; 1402 int x, y, z;
1359 int last_name; 1403 int last_name;
1424 glDisable (GL_TEXTURE_2D); 1468 glDisable (GL_TEXTURE_2D);
1425 glDisable (GL_BLEND); 1469 glDisable (GL_BLEND);
1426} 1470}
1427 1471
1428void 1472void
1429draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) 1473draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1430 CODE: 1474 CODE:
1431{ 1475{
1432 static float color[16][3] = { 1476 static float color[16][3] = {
1433 { 0.00F, 0.00F, 0.00F }, 1477 { 0.00F, 0.00F, 0.00F },
1434 { 1.00F, 1.00F, 1.00F }, 1478 { 1.00F, 1.00F, 1.00F },
1484 glDisable (GL_BLEND); 1528 glDisable (GL_BLEND);
1485 glDisable (GL_TEXTURE_2D); 1529 glDisable (GL_TEXTURE_2D);
1486} 1530}
1487 1531
1488void 1532void
1489fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1533fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1490 PPCODE: 1534 PPCODE:
1491{ 1535{
1492 int vx, vy; 1536 int vx, vy;
1493 int x, y; 1537 int x, y;
1494 int sw4 = (sw + 3) & ~3; 1538 int sw4 = (sw + 3) & ~3;
1510 for (x = 0; x < sw; x++) 1554 for (x = 0; x < sw; x++)
1511 if (row->c0 <= x + vx && x + vx < row->c1) 1555 if (row->c0 <= x + vx && x + vx < row->c1)
1512 { 1556 {
1513 mapcell *cell = row->col + (x + vx - row->c0); 1557 mapcell *cell = row->col + (x + vx - row->c0);
1514 1558
1515 darkness[y * sw4 + x] = cell->darkness < 0 1559 darkness[y * sw4 + x] = cell->darkness
1560 ? 255 - cell->darkness + 1
1516 ? 255 - FOW_DARKNESS 1561 : 255 - FOW_DARKNESS;
1517 : 255 - cell->darkness;
1518 } 1562 }
1519 } 1563 }
1520 1564
1521 EXTEND (SP, 3); 1565 EXTEND (SP, 3);
1522 PUSHs (sv_2mortal (newSViv (sw4))); 1566 PUSHs (sv_2mortal (newSViv (sw4)));
1523 PUSHs (sv_2mortal (newSViv (sh))); 1567 PUSHs (sv_2mortal (newSViv (sh)));
1524 PUSHs (darkness_sv); 1568 PUSHs (darkness_sv);
1525} 1569}
1526 1570
1527SV * 1571SV *
1528get_rect (CFClient::Map self, int x0, int y0, int w, int h) 1572get_rect (CFPlus::Map self, int x0, int y0, int w, int h)
1529 CODE: 1573 CODE:
1530{ 1574{
1531 int x, y, x1, y1; 1575 int x, y, x1, y1;
1532 SV *data_sv = newSV (w * h * 7 + 5); 1576 SV *data_sv = newSV (w * h * 7 + 5);
1533 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1577 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1595} 1639}
1596 OUTPUT: 1640 OUTPUT:
1597 RETVAL 1641 RETVAL
1598 1642
1599void 1643void
1600set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1644set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1601 PPCODE: 1645 PPCODE:
1602{ 1646{
1603 int x, y, z; 1647 int x, y, z;
1604 int w, h; 1648 int w, h;
1605 int x1, y1; 1649 int x1, y1;
1637 1681
1638 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1682 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1639 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1683 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1640 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1684 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1641 1685
1642 if (cell->darkness <= 0) 1686 if (cell->darkness <= 1)
1643 { 1687 {
1644 cell->darkness = -1; 1688 cell->darkness = 0;
1645 1689
1646 for (z = 0; z <= 2; z++) 1690 for (z = 0; z <= 2; z++)
1647 { 1691 {
1648 cell->face[z] = face[z]; 1692 cell->face[z] = face[z];
1649 1693
1654 } 1698 }
1655 } 1699 }
1656 } 1700 }
1657} 1701}
1658 1702
1659MODULE = CFClient PACKAGE = CFClient::MixChunk 1703MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1660 1704
1661CFClient::MixChunk 1705CFPlus::MixChunk
1662new_from_file (SV *class, char *path) 1706new_from_file (SV *class, char *path)
1663 CODE: 1707 CODE:
1664 RETVAL = Mix_LoadWAV (path); 1708 RETVAL = Mix_LoadWAV (path);
1665 OUTPUT: 1709 OUTPUT:
1666 RETVAL 1710 RETVAL
1667 1711
1668void 1712void
1669DESTROY (CFClient::MixChunk self) 1713DESTROY (CFPlus::MixChunk self)
1670 CODE: 1714 CODE:
1671 Mix_FreeChunk (self); 1715 Mix_FreeChunk (self);
1672 1716
1673int 1717int
1674volume (CFClient::MixChunk self, int volume = -1) 1718volume (CFPlus::MixChunk self, int volume = -1)
1675 CODE: 1719 CODE:
1676 RETVAL = Mix_VolumeChunk (self, volume); 1720 RETVAL = Mix_VolumeChunk (self, volume);
1677 OUTPUT: 1721 OUTPUT:
1678 RETVAL 1722 RETVAL
1679 1723
1680int 1724int
1681play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) 1725play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1)
1682 CODE: 1726 CODE:
1683 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1727 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1684 OUTPUT: 1728 OUTPUT:
1685 RETVAL 1729 RETVAL
1686 1730
1687MODULE = CFClient PACKAGE = CFClient::MixMusic 1731MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1688 1732
1689int 1733int
1690volume (int volume = -1) 1734volume (int volume = -1)
1691 CODE: 1735 CODE:
1692 RETVAL = Mix_VolumeMusic (volume); 1736 RETVAL = Mix_VolumeMusic (volume);
1693 OUTPUT: 1737 OUTPUT:
1694 RETVAL 1738 RETVAL
1695 1739
1696CFClient::MixMusic 1740CFPlus::MixMusic
1697new_from_file (SV *class, char *path) 1741new_from_file (SV *class, char *path)
1698 CODE: 1742 CODE:
1699 RETVAL = Mix_LoadMUS (path); 1743 RETVAL = Mix_LoadMUS (path);
1700 OUTPUT: 1744 OUTPUT:
1701 RETVAL 1745 RETVAL
1702 1746
1703void 1747void
1704DESTROY (CFClient::MixMusic self) 1748DESTROY (CFPlus::MixMusic self)
1705 CODE: 1749 CODE:
1706 Mix_FreeMusic (self); 1750 Mix_FreeMusic (self);
1707 1751
1708int 1752int
1709play (CFClient::MixMusic self, int loops = -1) 1753play (CFPlus::MixMusic self, int loops = -1)
1710 CODE: 1754 CODE:
1711 RETVAL = Mix_PlayMusic (self, loops); 1755 RETVAL = Mix_PlayMusic (self, loops);
1712 OUTPUT: 1756 OUTPUT:
1713 RETVAL 1757 RETVAL
1714 1758
1715MODULE = CFClient PACKAGE = CFClient::OpenGL 1759MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1716 1760
1717BOOT: 1761BOOT:
1718{ 1762{
1719 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1763 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1720 static const struct { 1764 static const struct {
1721 const char *name; 1765 const char *name;
1722 IV iv; 1766 IV iv;
1723 } *civ, const_iv[] = { 1767 } *civ, const_iv[] = {
1724# define const_iv(name) { # name, (IV)name } 1768# define const_iv(name) { # name, (IV)name }
1787 const_iv (GL_SEPARABLE_2D), 1831 const_iv (GL_SEPARABLE_2D),
1788 const_iv (GL_CONVOLUTION_2D), 1832 const_iv (GL_CONVOLUTION_2D),
1789 const_iv (GL_CONVOLUTION_BORDER_MODE), 1833 const_iv (GL_CONVOLUTION_BORDER_MODE),
1790 const_iv (GL_CONSTANT_BORDER), 1834 const_iv (GL_CONSTANT_BORDER),
1791 const_iv (GL_LINES), 1835 const_iv (GL_LINES),
1836 const_iv (GL_LINE_STRIP),
1792 const_iv (GL_LINE_LOOP), 1837 const_iv (GL_LINE_LOOP),
1793 const_iv (GL_QUADS), 1838 const_iv (GL_QUADS),
1794 const_iv (GL_QUAD_STRIP), 1839 const_iv (GL_QUAD_STRIP),
1795 const_iv (GL_TRIANGLES), 1840 const_iv (GL_TRIANGLES),
1796 const_iv (GL_TRIANGLE_STRIP), 1841 const_iv (GL_TRIANGLE_STRIP),
1906 r *= a; 1951 r *= a;
1907 g *= a; 1952 g *= a;
1908 b *= a; 1953 b *= a;
1909 } 1954 }
1910 // microsoft visual "c" rounds instead of truncating... 1955 // microsoft visual "c" rounds instead of truncating...
1911 glColor4ub (MIN ((int)(r * 256.f), 255), 1956 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 1957
1916void glInterleavedArrays (int format, int stride, char *data) 1958void glInterleavedArrays (int format, int stride, char *data)
1917 1959
1918void glDrawElements (int mode, int count, int type, char *indices) 1960void glDrawElements (int mode, int count, int type, char *indices)
1919 1961
1996 2038
1997void glEndList () 2039void glEndList ()
1998 2040
1999void glCallList (int list) 2041void glCallList (int list)
2000 2042
2001

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines