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.131 by root, Thu Jul 13 01:54:18 2006 UTC vs.
Revision 1.142 by root, Fri Aug 18 01:27:15 2006 UTC

83 83
84#include "pango-font.c" 84#include "pango-font.c"
85#include "pango-fontmap.c" 85#include "pango-fontmap.c"
86#include "pango-render.c" 86#include "pango-render.c"
87 87
88typedef Mix_Chunk *CFClient__MixChunk; 88typedef Mix_Chunk *CFPlus__MixChunk;
89typedef Mix_Music *CFClient__MixMusic; 89typedef Mix_Music *CFPlus__MixMusic;
90 90
91typedef PangoFontDescription *CFClient__Font; 91typedef PangoFontDescription *CFPlus__Font;
92 92
93static int 93static int
94shape_attr_p (PangoLayoutRun *run) 94shape_attr_p (PangoLayoutRun *run)
95{ 95{
96 GSList *attrs = run->item->analysis.extra_attrs; 96 GSList *attrs = run->item->analysis.extra_attrs;
110 110
111typedef struct cf_layout { 111typedef struct cf_layout {
112 PangoLayout *pl; 112 PangoLayout *pl;
113 float r, g, b, a; // default color for rgba mode 113 float r, g, b, a; // default color for rgba mode
114 int base_height; 114 int base_height;
115 CFClient__Font font; 115 CFPlus__Font font;
116} *CFClient__Layout; 116} *CFPlus__Layout;
117 117
118static CFClient__Font default_font; 118static CFPlus__Font default_font;
119static PangoContext *opengl_context; 119static PangoContext *opengl_context;
120static PangoFontMap *opengl_fontmap; 120static PangoFontMap *opengl_fontmap;
121 121
122static void 122static void
123substitute_func (FcPattern *pattern, gpointer data) 123substitute_func (FcPattern *pattern, gpointer data)
128#endif 128#endif
129 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 129 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
130} 130}
131 131
132static void 132static void
133layout_update_font (CFClient__Layout self) 133layout_update_font (CFPlus__Layout self)
134{ 134{
135 /* 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
136 * reasonably well with bitstream vera 136 * reasonably well with bitstream vera
137 */ 137 */
138 PangoFontDescription *font = self->font ? self->font : default_font; 138 PangoFontDescription *font = self->font ? self->font : default_font;
142 142
143 pango_layout_set_font_description (self->pl, font); 143 pango_layout_set_font_description (self->pl, font);
144} 144}
145 145
146static void 146static void
147layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
148{ 148{
149 PangoRectangle rect;
150
151 // get_pixel_* wrongly rounds down
149 pango_layout_get_pixel_size (self->pl, w, h); 152 pango_layout_get_extents (self->pl, 0, &rect);
150 153
151 if (!*w) *w = 1; 154 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
152 if (!*h) *h = 1; 155 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
153 156
154 *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;
155} 162}
156 163
157typedef uint16_t mapface; 164typedef uint16_t mapface;
158 165
159typedef struct { 166typedef struct {
162 float s, t; 169 float s, t;
163 uint8_t r, g, b, a; 170 uint8_t r, g, b, a;
164} maptex; 171} maptex;
165 172
166typedef struct { 173typedef struct {
167 int16_t darkness; 174 uint16_t darkness;
168 mapface face[3]; 175 mapface face[3];
176 uint8_t stat_hp;
169} mapcell; 177} mapcell;
170 178
171typedef struct { 179typedef struct {
172 int32_t c0, c1; 180 int32_t c0, c1;
173 mapcell *col; 181 mapcell *col;
182 int texs; 190 int texs;
183 maptex *tex; 191 maptex *tex;
184 192
185 int32_t rows; 193 int32_t rows;
186 maprow *row; 194 maprow *row;
187} *CFClient__Map; 195} *CFPlus__Map;
188 196
189static char * 197static char *
190prepend (char *ptr, int sze, int inc) 198prepend (char *ptr, int sze, int inc)
191{ 199{
192 char *p; 200 char *p;
210 218
211#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))
212#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))
213 221
214static maprow * 222static maprow *
215map_get_row (CFClient__Map self, int y) 223map_get_row (CFPlus__Map self, int y)
216{ 224{
217 if (0 > y) 225 if (0 > y)
218 { 226 {
219 int extend = - y + MAP_EXTEND_Y; 227 int extend = - y + MAP_EXTEND_Y;
220 Prepend (maprow, self->row, self->rows, extend); 228 Prepend (maprow, self->row, self->rows, extend);
258 266
259 return row->col + (x - row->c0); 267 return row->col + (x - row->c0);
260} 268}
261 269
262static mapcell * 270static mapcell *
263map_get_cell (CFClient__Map self, int x, int y) 271map_get_cell (CFPlus__Map self, int x, int y)
264{ 272{
265 return row_get_cell (map_get_row (self, y), x); 273 return row_get_cell (map_get_row (self, y), x);
266} 274}
267 275
268static void 276static void
269map_clear (CFClient__Map self) 277map_clear (CFPlus__Map self)
270{ 278{
271 int r; 279 int r;
272 280
273 for (r = 0; r < self->rows; r++) 281 for (r = 0; r < self->rows; r++)
274 Safefree (self->row[r].col); 282 Safefree (self->row[r].col);
282 self->row = 0; 290 self->row = 0;
283 self->rows = 0; 291 self->rows = 0;
284} 292}
285 293
286static void 294static void
287map_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)
288{ 296{
289 int x, y; 297 int x, y;
290 maprow *row; 298 maprow *row;
291 299
292 for (y = y0; y < y0 + h; y++) 300 for (y = y0; y < y0 + h; y++)
301 if (x >= row->c0) 309 if (x >= row->c0)
302 { 310 {
303 if (x >= row->c1) 311 if (x >= row->c1)
304 break; 312 break;
305 313
306 row->col[x - row->c0].darkness = -1; 314 row->col[x - row->c0].darkness = 0;
307 } 315 }
308 } 316 }
309} 317}
310 318
311static void 319static void
349 n |= n >> 16; 357 n |= n >> 16;
350 358
351 return n + 1; 359 return n + 1;
352} 360}
353 361
354MODULE = CFClient PACKAGE = CFClient 362MODULE = CFPlus PACKAGE = CFPlus
355 363
356PROTOTYPES: ENABLE 364PROTOTYPES: ENABLE
357 365
358BOOT: 366BOOT:
359{ 367{
360 HV *stash = gv_stashpv ("CFClient", 1); 368 HV *stash = gv_stashpv ("CFPlus", 1);
361 static const struct { 369 static const struct {
362 const char *name; 370 const char *name;
363 IV iv; 371 IV iv;
364 } *civ, const_iv[] = { 372 } *civ, const_iv[] = {
365# define const_iv(name) { # name, (IV)name } 373# define const_iv(name) { # name, (IV)name }
512 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 520 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
513 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 521 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
514 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 522 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
515 523
516 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 524 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
525#if SDL_VERSION_ATLEAST(1,2,10)
517 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); 526 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
518 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 527 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
528#endif
519 529
520 SDL_EnableUNICODE (1); 530 SDL_EnableUNICODE (1);
521 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 531 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
522 532
523 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 533 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
610 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 620 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
611 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 621 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
612 break; 622 break;
613 } 623 }
614 624
615 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 625 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
616 } 626 }
617} 627}
618 628
619int 629int
620Mix_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)
749void 759void
750_exit (int retval) 760_exit (int retval)
751 CODE: 761 CODE:
752 _exit (retval); 762 _exit (retval);
753 763
754MODULE = CFClient PACKAGE = CFClient::Font 764MODULE = CFPlus PACKAGE = CFPlus::Font
755 765
756CFClient::Font 766CFPlus::Font
757new_from_file (SV *class, char *path, int id = 0) 767new_from_file (SV *class, char *path, int id = 0)
758 CODE: 768 CODE:
759{ 769{
760 int count; 770 int count;
761 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 771 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
764} 774}
765 OUTPUT: 775 OUTPUT:
766 RETVAL 776 RETVAL
767 777
768void 778void
769DESTROY (CFClient::Font self) 779DESTROY (CFPlus::Font self)
770 CODE: 780 CODE:
771 pango_font_description_free (self); 781 pango_font_description_free (self);
772 782
773void 783void
774make_default (CFClient::Font self) 784make_default (CFPlus::Font self)
775 CODE: 785 CODE:
776 default_font = self; 786 default_font = self;
777 787
778MODULE = CFClient PACKAGE = CFClient::Layout 788MODULE = CFPlus PACKAGE = CFPlus::Layout
779 789
780void 790void
781reset_glyph_cache () 791reset_glyph_cache ()
782 CODE: 792 CODE:
783 tc_clear (); 793 tc_clear ();
784 794
785CFClient::Layout 795CFPlus::Layout
786new (SV *class) 796new (SV *class)
787 CODE: 797 CODE:
788 New (0, RETVAL, 1, struct cf_layout); 798 New (0, RETVAL, 1, struct cf_layout);
789 799
790 RETVAL->pl = pango_layout_new (opengl_context); 800 RETVAL->pl = pango_layout_new (opengl_context);
799 layout_update_font (RETVAL); 809 layout_update_font (RETVAL);
800 OUTPUT: 810 OUTPUT:
801 RETVAL 811 RETVAL
802 812
803void 813void
804DESTROY (CFClient::Layout self) 814DESTROY (CFPlus::Layout self)
805 CODE: 815 CODE:
806 g_object_unref (self->pl); 816 g_object_unref (self->pl);
807 Safefree (self); 817 Safefree (self);
808 818
809void 819void
810set_text (CFClient::Layout self, SV *text_) 820set_text (CFPlus::Layout self, SV *text_)
811 CODE: 821 CODE:
812{ 822{
813 STRLEN textlen; 823 STRLEN textlen;
814 char *text = SvPVutf8 (text_, textlen); 824 char *text = SvPVutf8 (text_, textlen);
815 825
816 pango_layout_set_text (self->pl, text, textlen); 826 pango_layout_set_text (self->pl, text, textlen);
817} 827}
818 828
819void 829void
820set_markup (CFClient::Layout self, SV *text_) 830set_markup (CFPlus::Layout self, SV *text_)
821 CODE: 831 CODE:
822{ 832{
823 STRLEN textlen; 833 STRLEN textlen;
824 char *text = SvPVutf8 (text_, textlen); 834 char *text = SvPVutf8 (text_, textlen);
825 835
826 pango_layout_set_markup (self->pl, text, textlen); 836 pango_layout_set_markup (self->pl, text, textlen);
827} 837}
828 838
829void 839void
830set_shapes (CFClient::Layout self, ...) 840set_shapes (CFPlus::Layout self, ...)
831 CODE: 841 CODE:
832{ 842{
833 PangoAttrList *attrs = 0; 843 PangoAttrList *attrs = 0;
834 const char *text = pango_layout_get_text (self->pl); 844 const char *text = pango_layout_get_text (self->pl);
835 const char *pos = text; 845 const char *pos = text;
870 if (attrs) 880 if (attrs)
871 pango_layout_set_attributes (self->pl, attrs); 881 pango_layout_set_attributes (self->pl, attrs);
872} 882}
873 883
874void 884void
875get_shapes (CFClient::Layout self) 885get_shapes (CFPlus::Layout self)
876 PPCODE: 886 PPCODE:
877{ 887{
878 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 888 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
879 889
880 do 890 do
895 905
896 pango_layout_iter_free (iter); 906 pango_layout_iter_free (iter);
897} 907}
898 908
899int 909int
900has_wrapped (CFClient::Layout self) 910has_wrapped (CFPlus::Layout self)
901 CODE: 911 CODE:
902{ 912{
903 int lines = 1; 913 int lines = 1;
904 const char *text = pango_layout_get_text (self->pl); 914 const char *text = pango_layout_get_text (self->pl);
905 915
910} 920}
911 OUTPUT: 921 OUTPUT:
912 RETVAL 922 RETVAL
913 923
914SV * 924SV *
915get_text (CFClient::Layout self) 925get_text (CFPlus::Layout self)
916 CODE: 926 CODE:
917 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 927 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
918 sv_utf8_decode (RETVAL); 928 sv_utf8_decode (RETVAL);
919 OUTPUT: 929 OUTPUT:
920 RETVAL 930 RETVAL
921 931
922void 932void
923set_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.)
924 CODE: 934 CODE:
925 self->r = r; 935 self->r = r;
926 self->g = g; 936 self->g = g;
927 self->b = b; 937 self->b = b;
928 self->a = a; 938 self->a = a;
929 939
930void 940void
931set_font (CFClient::Layout self, CFClient::Font font = 0) 941set_font (CFPlus::Layout self, CFPlus::Font font = 0)
932 CODE: 942 CODE:
933 if (self->font != font) 943 if (self->font != font)
934 { 944 {
935 self->font = font; 945 self->font = font;
936 layout_update_font (self); 946 layout_update_font (self);
937 } 947 }
938 948
939void 949void
940set_height (CFClient::Layout self, int base_height) 950set_height (CFPlus::Layout self, int base_height)
941 CODE: 951 CODE:
942 if (self->base_height != base_height) 952 if (self->base_height != base_height)
943 { 953 {
944 self->base_height = base_height; 954 self->base_height = base_height;
945 layout_update_font (self); 955 layout_update_font (self);
946 } 956 }
947 957
948void 958void
949set_width (CFClient::Layout self, int max_width = -1) 959set_width (CFPlus::Layout self, int max_width = -1)
950 CODE: 960 CODE:
951 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);
952 962
953void 963void
954set_indent (CFClient::Layout self, int indent) 964set_indent (CFPlus::Layout self, int indent)
955 CODE: 965 CODE:
956 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 966 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
957 967
958void 968void
959set_spacing (CFClient::Layout self, int spacing) 969set_spacing (CFPlus::Layout self, int spacing)
960 CODE: 970 CODE:
961 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 971 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
962 972
963void 973void
964set_ellipsise (CFClient::Layout self, int ellipsise) 974set_ellipsise (CFPlus::Layout self, int ellipsise)
965 CODE: 975 CODE:
966 pango_layout_set_ellipsize (self->pl, 976 pango_layout_set_ellipsize (self->pl,
967 ellipsise == 1 ? PANGO_ELLIPSIZE_START 977 ellipsise == 1 ? PANGO_ELLIPSIZE_START
968 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 978 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
969 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 979 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
970 : PANGO_ELLIPSIZE_NONE 980 : PANGO_ELLIPSIZE_NONE
971 ); 981 );
972 982
973void 983void
974set_single_paragraph_mode (CFClient::Layout self, int spm) 984set_single_paragraph_mode (CFPlus::Layout self, int spm)
975 CODE: 985 CODE:
976 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 986 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
977 987
978void 988void
979size (CFClient::Layout self) 989size (CFPlus::Layout self)
980 PPCODE: 990 PPCODE:
981{ 991{
982 int w, h; 992 int w, h;
983 993
984 layout_get_pixel_size (self, &w, &h); 994 layout_get_pixel_size (self, &w, &h);
987 PUSHs (sv_2mortal (newSViv (w))); 997 PUSHs (sv_2mortal (newSViv (w)));
988 PUSHs (sv_2mortal (newSViv (h))); 998 PUSHs (sv_2mortal (newSViv (h)));
989} 999}
990 1000
991int 1001int
992descent (CFClient::Layout self) 1002descent (CFPlus::Layout self)
993 CODE: 1003 CODE:
994{ 1004{
995 PangoRectangle rect; 1005 PangoRectangle rect;
996 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1006 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
997 pango_layout_line_get_pixel_extents (line, 0, &rect); 1007 pango_layout_line_get_pixel_extents (line, 0, &rect);
999} 1009}
1000 OUTPUT: 1010 OUTPUT:
1001 RETVAL 1011 RETVAL
1002 1012
1003int 1013int
1004xy_to_index (CFClient::Layout self, int x, int y) 1014xy_to_index (CFPlus::Layout self, int x, int y)
1005 CODE: 1015 CODE:
1006{ 1016{
1007 int index, trailing; 1017 int index, trailing;
1008 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);
1009 RETVAL = index; 1019 RETVAL = index;
1010} 1020}
1011 OUTPUT: 1021 OUTPUT:
1012 RETVAL 1022 RETVAL
1013 1023
1014void 1024void
1015cursor_pos (CFClient::Layout self, int index) 1025cursor_pos (CFPlus::Layout self, int index)
1016 PPCODE: 1026 PPCODE:
1017{ 1027{
1018 PangoRectangle strong_pos; 1028 PangoRectangle strong_pos;
1019 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1029 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
1020 1030
1023 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1033 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1024 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1034 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1025} 1035}
1026 1036
1027void 1037void
1028render (CFClient::Layout self, float x, float y) 1038render (CFPlus::Layout self, float x, float y, int flags = 0)
1029 PPCODE: 1039 PPCODE:
1030 pango_opengl_render_layout_subpixel ( 1040 pango_opengl_render_layout_subpixel (
1031 self->pl, 1041 self->pl,
1032 x * PANGO_SCALE, y * PANGO_SCALE, 1042 x * PANGO_SCALE, y * PANGO_SCALE,
1033 self->r, self->g, self->b, self->a 1043 self->r, self->g, self->b, self->a,
1044 flags
1034 ); 1045 );
1035 1046
1036MODULE = CFClient PACKAGE = CFClient::Texture 1047MODULE = CFPlus PACKAGE = CFPlus::Texture
1037 1048
1038void 1049void
1039pad2pot (SV *data_, SV *w_, SV *h_) 1050pad2pot (SV *data_, SV *w_, SV *h_)
1040 CODE: 1051 CODE:
1041{ 1052{
1119 glDisable (GL_ALPHA_TEST); 1130 glDisable (GL_ALPHA_TEST);
1120 glDisable (GL_BLEND); 1131 glDisable (GL_BLEND);
1121 } 1132 }
1122} 1133}
1123 1134
1124MODULE = CFClient PACKAGE = CFClient::Map 1135MODULE = CFPlus PACKAGE = CFPlus::Map
1125 1136
1126CFClient::Map 1137CFPlus::Map
1127new (SV *class, int map_width, int map_height) 1138new (SV *class, int map_width, int map_height)
1128 CODE: 1139 CODE:
1129 New (0, RETVAL, 1, struct map); 1140 New (0, RETVAL, 1, struct map);
1130 RETVAL->x = 0; 1141 RETVAL->x = 0;
1131 RETVAL->y = 0; 1142 RETVAL->y = 0;
1141 RETVAL->row = 0; 1152 RETVAL->row = 0;
1142 OUTPUT: 1153 OUTPUT:
1143 RETVAL 1154 RETVAL
1144 1155
1145void 1156void
1146DESTROY (CFClient::Map self) 1157DESTROY (CFPlus::Map self)
1147 CODE: 1158 CODE:
1148{ 1159{
1149 map_clear (self); 1160 map_clear (self);
1150 Safefree (self->face); 1161 Safefree (self->face);
1151 Safefree (self->tex); 1162 Safefree (self->tex);
1152 Safefree (self); 1163 Safefree (self);
1153} 1164}
1154 1165
1155void 1166void
1156clear (CFClient::Map self) 1167clear (CFPlus::Map self)
1157 CODE: 1168 CODE:
1158 map_clear (self); 1169 map_clear (self);
1159 1170
1160void 1171void
1161set_face (CFClient::Map self, int face, int texid) 1172set_face (CFPlus::Map self, int face, int texid)
1162 CODE: 1173 CODE:
1163{ 1174{
1164 while (self->faces <= face) 1175 while (self->faces <= face)
1165 { 1176 {
1166 Append (mapface, self->face, self->faces, self->faces); 1177 Append (mapface, self->face, self->faces, self->faces);
1169 1180
1170 self->face [face] = texid; 1181 self->face [face] = texid;
1171} 1182}
1172 1183
1173void 1184void
1174set_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)
1175 CODE: 1186 CODE:
1176{ 1187{
1177 while (self->texs <= texid) 1188 while (self->texs <= texid)
1178 { 1189 {
1179 Append (maptex, self->tex, self->texs, self->texs); 1190 Append (maptex, self->tex, self->texs, self->texs);
1203 // from transparent color bleeding and ugly wrapping effects. 1214 // from transparent color bleeding and ugly wrapping effects.
1204 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1215 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1205} 1216}
1206 1217
1207int 1218int
1208ox (CFClient::Map self) 1219ox (CFPlus::Map self)
1209 ALIAS: 1220 ALIAS:
1210 oy = 1 1221 oy = 1
1211 x = 2 1222 x = 2
1212 y = 3 1223 y = 3
1213 w = 4 1224 w = 4
1224 } 1235 }
1225 OUTPUT: 1236 OUTPUT:
1226 RETVAL 1237 RETVAL
1227 1238
1228void 1239void
1229scroll (CFClient::Map self, int dx, int dy) 1240scroll (CFPlus::Map self, int dx, int dy)
1230 CODE: 1241 CODE:
1231{ 1242{
1232 if (dx > 0) 1243 if (dx > 0)
1233 map_blank (self, self->x, self->y, dx - 1, self->h); 1244 map_blank (self, self->x, self->y, dx - 1, self->h);
1234 else if (dx < 0) 1245 else if (dx < 0)
1250 self->y += MAP_EXTEND_Y; 1261 self->y += MAP_EXTEND_Y;
1251 } 1262 }
1252} 1263}
1253 1264
1254void 1265void
1255map1a_update (CFClient::Map self, SV *data_) 1266map1a_update (CFPlus::Map self, SV *data_, int extmap)
1256 CODE: 1267 CODE:
1257{ 1268{
1258 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1269 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1259 uint8_t *data_end = (uint8_t *)SvEND (data_); 1270 uint8_t *data_end = (uint8_t *)SvEND (data_);
1260 mapcell *cell; 1271 mapcell *cell;
1269 1280
1270 cell = map_get_cell (self, x, y); 1281 cell = map_get_cell (self, x, y);
1271 1282
1272 if (flags & 15) 1283 if (flags & 15)
1273 { 1284 {
1274 if (cell->darkness < 0) 1285 if (!cell->darkness)
1275 { 1286 {
1276 cell->darkness = 0; 1287 cell->darkness = 256;
1277 cell->face [0] = 0; 1288 cell->face [0] = 0;
1278 cell->face [1] = 0; 1289 cell->face [1] = 0;
1279 cell->face [2] = 0; 1290 cell->face [2] = 0;
1280 } 1291 }
1281 1292
1282 cell->darkness = flags & 8 ? *data++ : 255;
1283
1284 //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 }
1285 1316
1286 if (flags & 4) 1317 if (flags & 4)
1287 { 1318 {
1288 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;
1289 } 1320 }
1297 { 1328 {
1298 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;
1299 } 1330 }
1300 } 1331 }
1301 else 1332 else
1302 cell->darkness = -1; 1333 cell->darkness = 0;
1303 } 1334 }
1304} 1335}
1305 1336
1306SV * 1337SV *
1307mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1338mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1308 CODE: 1339 CODE:
1309{ 1340{
1310 int x1, x; 1341 int x1, x;
1311 int y1, y; 1342 int y1, y;
1312 int z; 1343 int z;
1362} 1393}
1363 OUTPUT: 1394 OUTPUT:
1364 RETVAL 1395 RETVAL
1365 1396
1366void 1397void
1367draw (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)
1368 CODE: 1399 CODE:
1369{ 1400{
1370 int vx, vy; 1401 int vx, vy;
1371 int x, y, z; 1402 int x, y, z;
1372 int last_name; 1403 int last_name;
1437 glDisable (GL_TEXTURE_2D); 1468 glDisable (GL_TEXTURE_2D);
1438 glDisable (GL_BLEND); 1469 glDisable (GL_BLEND);
1439} 1470}
1440 1471
1441void 1472void
1442draw_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)
1443 CODE: 1474 CODE:
1444{ 1475{
1445 static float color[16][3] = { 1476 static float color[16][3] = {
1446 { 0.00F, 0.00F, 0.00F }, 1477 { 0.00F, 0.00F, 0.00F },
1447 { 1.00F, 1.00F, 1.00F }, 1478 { 1.00F, 1.00F, 1.00F },
1497 glDisable (GL_BLEND); 1528 glDisable (GL_BLEND);
1498 glDisable (GL_TEXTURE_2D); 1529 glDisable (GL_TEXTURE_2D);
1499} 1530}
1500 1531
1501void 1532void
1502fow_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)
1503 PPCODE: 1534 PPCODE:
1504{ 1535{
1505 int vx, vy; 1536 int vx, vy;
1506 int x, y; 1537 int x, y;
1507 int sw4 = (sw + 3) & ~3; 1538 int sw4 = (sw + 3) & ~3;
1523 for (x = 0; x < sw; x++) 1554 for (x = 0; x < sw; x++)
1524 if (row->c0 <= x + vx && x + vx < row->c1) 1555 if (row->c0 <= x + vx && x + vx < row->c1)
1525 { 1556 {
1526 mapcell *cell = row->col + (x + vx - row->c0); 1557 mapcell *cell = row->col + (x + vx - row->c0);
1527 1558
1528 darkness[y * sw4 + x] = cell->darkness < 0 1559 darkness[y * sw4 + x] = cell->darkness
1560 ? 255 - cell->darkness + 1
1529 ? 255 - FOW_DARKNESS 1561 : 255 - FOW_DARKNESS;
1530 : 255 - cell->darkness;
1531 } 1562 }
1532 } 1563 }
1533 1564
1534 EXTEND (SP, 3); 1565 EXTEND (SP, 3);
1535 PUSHs (sv_2mortal (newSViv (sw4))); 1566 PUSHs (sv_2mortal (newSViv (sw4)));
1536 PUSHs (sv_2mortal (newSViv (sh))); 1567 PUSHs (sv_2mortal (newSViv (sh)));
1537 PUSHs (darkness_sv); 1568 PUSHs (darkness_sv);
1538} 1569}
1539 1570
1540SV * 1571SV *
1541get_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)
1542 CODE: 1573 CODE:
1543{ 1574{
1544 int x, y, x1, y1; 1575 int x, y, x1, y1;
1545 SV *data_sv = newSV (w * h * 7 + 5); 1576 SV *data_sv = newSV (w * h * 7 + 5);
1546 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1577 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1608} 1639}
1609 OUTPUT: 1640 OUTPUT:
1610 RETVAL 1641 RETVAL
1611 1642
1612void 1643void
1613set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1644set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1614 PPCODE: 1645 PPCODE:
1615{ 1646{
1616 int x, y, z; 1647 int x, y, z;
1617 int w, h; 1648 int w, h;
1618 int x1, y1; 1649 int x1, y1;
1650 1681
1651 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1682 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1652 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1683 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1653 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1684 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1654 1685
1655 if (cell->darkness <= 0) 1686 if (cell->darkness <= 1)
1656 { 1687 {
1657 cell->darkness = -1; 1688 cell->darkness = 0;
1658 1689
1659 for (z = 0; z <= 2; z++) 1690 for (z = 0; z <= 2; z++)
1660 { 1691 {
1661 cell->face[z] = face[z]; 1692 cell->face[z] = face[z];
1662 1693
1667 } 1698 }
1668 } 1699 }
1669 } 1700 }
1670} 1701}
1671 1702
1672MODULE = CFClient PACKAGE = CFClient::MixChunk 1703MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1673 1704
1674CFClient::MixChunk 1705CFPlus::MixChunk
1675new_from_file (SV *class, char *path) 1706new_from_file (SV *class, char *path)
1676 CODE: 1707 CODE:
1677 RETVAL = Mix_LoadWAV (path); 1708 RETVAL = Mix_LoadWAV (path);
1678 OUTPUT: 1709 OUTPUT:
1679 RETVAL 1710 RETVAL
1680 1711
1681void 1712void
1682DESTROY (CFClient::MixChunk self) 1713DESTROY (CFPlus::MixChunk self)
1683 CODE: 1714 CODE:
1684 Mix_FreeChunk (self); 1715 Mix_FreeChunk (self);
1685 1716
1686int 1717int
1687volume (CFClient::MixChunk self, int volume = -1) 1718volume (CFPlus::MixChunk self, int volume = -1)
1688 CODE: 1719 CODE:
1689 RETVAL = Mix_VolumeChunk (self, volume); 1720 RETVAL = Mix_VolumeChunk (self, volume);
1690 OUTPUT: 1721 OUTPUT:
1691 RETVAL 1722 RETVAL
1692 1723
1693int 1724int
1694play (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)
1695 CODE: 1726 CODE:
1696 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1727 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1697 OUTPUT: 1728 OUTPUT:
1698 RETVAL 1729 RETVAL
1699 1730
1700MODULE = CFClient PACKAGE = CFClient::MixMusic 1731MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1701 1732
1702int 1733int
1703volume (int volume = -1) 1734volume (int volume = -1)
1704 CODE: 1735 CODE:
1705 RETVAL = Mix_VolumeMusic (volume); 1736 RETVAL = Mix_VolumeMusic (volume);
1706 OUTPUT: 1737 OUTPUT:
1707 RETVAL 1738 RETVAL
1708 1739
1709CFClient::MixMusic 1740CFPlus::MixMusic
1710new_from_file (SV *class, char *path) 1741new_from_file (SV *class, char *path)
1711 CODE: 1742 CODE:
1712 RETVAL = Mix_LoadMUS (path); 1743 RETVAL = Mix_LoadMUS (path);
1713 OUTPUT: 1744 OUTPUT:
1714 RETVAL 1745 RETVAL
1715 1746
1716void 1747void
1717DESTROY (CFClient::MixMusic self) 1748DESTROY (CFPlus::MixMusic self)
1718 CODE: 1749 CODE:
1719 Mix_FreeMusic (self); 1750 Mix_FreeMusic (self);
1720 1751
1721int 1752int
1722play (CFClient::MixMusic self, int loops = -1) 1753play (CFPlus::MixMusic self, int loops = -1)
1723 CODE: 1754 CODE:
1724 RETVAL = Mix_PlayMusic (self, loops); 1755 RETVAL = Mix_PlayMusic (self, loops);
1725 OUTPUT: 1756 OUTPUT:
1726 RETVAL 1757 RETVAL
1727 1758
1728MODULE = CFClient PACKAGE = CFClient::OpenGL 1759MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1729 1760
1730BOOT: 1761BOOT:
1731{ 1762{
1732 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1763 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1733 static const struct { 1764 static const struct {
1734 const char *name; 1765 const char *name;
1735 IV iv; 1766 IV iv;
1736 } *civ, const_iv[] = { 1767 } *civ, const_iv[] = {
1737# define const_iv(name) { # name, (IV)name } 1768# define const_iv(name) { # name, (IV)name }
1800 const_iv (GL_SEPARABLE_2D), 1831 const_iv (GL_SEPARABLE_2D),
1801 const_iv (GL_CONVOLUTION_2D), 1832 const_iv (GL_CONVOLUTION_2D),
1802 const_iv (GL_CONVOLUTION_BORDER_MODE), 1833 const_iv (GL_CONVOLUTION_BORDER_MODE),
1803 const_iv (GL_CONSTANT_BORDER), 1834 const_iv (GL_CONSTANT_BORDER),
1804 const_iv (GL_LINES), 1835 const_iv (GL_LINES),
1836 const_iv (GL_LINE_STRIP),
1805 const_iv (GL_LINE_LOOP), 1837 const_iv (GL_LINE_LOOP),
1806 const_iv (GL_QUADS), 1838 const_iv (GL_QUADS),
1807 const_iv (GL_QUAD_STRIP), 1839 const_iv (GL_QUAD_STRIP),
1808 const_iv (GL_TRIANGLES), 1840 const_iv (GL_TRIANGLES),
1809 const_iv (GL_TRIANGLE_STRIP), 1841 const_iv (GL_TRIANGLE_STRIP),
2006 2038
2007void glEndList () 2039void glEndList ()
2008 2040
2009void glCallList (int list) 2041void glCallList (int list)
2010 2042
2011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines