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.129 by root, Wed Jul 12 17:20:04 2006 UTC vs.
Revision 1.152 by root, Sat Aug 19 18:18:36 2006 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2# define WIN32_LEAN_AND_MEAN
2# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls
3# include <malloc.h> 4# include <malloc.h>
4# include <windows.h> 5# include <windows.h>
5# pragma warning(disable:4244) 6# pragma warning(disable:4244)
6#endif 7#endif
7 8
8#include "EXTERN.h" 9#include "EXTERN.h"
9#include "perl.h" 10#include "perl.h"
10#include "XSUB.h" 11#include "XSUB.h"
12
13#ifdef _WIN32
14# undef pipe
15#endif
11 16
12#include <math.h> 17#include <math.h>
13#include <string.h> 18#include <string.h>
14#include <stdio.h> 19#include <stdio.h>
15#include <stdlib.h> 20#include <stdlib.h>
40 typedef signed char int8_t; 45 typedef signed char int8_t;
41 typedef signed short int16_t; 46 typedef signed short int16_t;
42 typedef signed int int32_t; 47 typedef signed int int32_t;
43#endif 48#endif
44 49
45#include "glext.h"
46
47#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ 50#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */
48 51
49#define FOW_DARKNESS 32 52#define FOW_DARKNESS 32
50 53
51#define MAP_EXTEND_X 32 54#define MAP_EXTEND_X 32
80 83
81#include "pango-font.c" 84#include "pango-font.c"
82#include "pango-fontmap.c" 85#include "pango-fontmap.c"
83#include "pango-render.c" 86#include "pango-render.c"
84 87
85typedef Mix_Chunk *CFClient__MixChunk; 88typedef Mix_Chunk *CFPlus__MixChunk;
86typedef Mix_Music *CFClient__MixMusic; 89typedef Mix_Music *CFPlus__MixMusic;
87 90
88typedef PangoFontDescription *CFClient__Font; 91typedef PangoFontDescription *CFPlus__Font;
89 92
90static int 93static int
91shape_attr_p (PangoLayoutRun *run) 94shape_attr_p (PangoLayoutRun *run)
92{ 95{
93 GSList *attrs = run->item->analysis.extra_attrs; 96 GSList *attrs = run->item->analysis.extra_attrs;
107 110
108typedef struct cf_layout { 111typedef struct cf_layout {
109 PangoLayout *pl; 112 PangoLayout *pl;
110 float r, g, b, a; // default color for rgba mode 113 float r, g, b, a; // default color for rgba mode
111 int base_height; 114 int base_height;
112 CFClient__Font font; 115 CFPlus__Font font;
113} *CFClient__Layout; 116} *CFPlus__Layout;
114 117
115static CFClient__Font default_font; 118static CFPlus__Font default_font;
116static PangoContext *opengl_context; 119static PangoContext *opengl_context;
117static PangoFontMap *opengl_fontmap; 120static PangoFontMap *opengl_fontmap;
118 121
119static void 122static void
120substitute_func (FcPattern *pattern, gpointer data) 123substitute_func (FcPattern *pattern, gpointer data)
125#endif 128#endif
126 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 129 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
127} 130}
128 131
129static void 132static void
130layout_update_font (CFClient__Layout self) 133layout_update_font (CFPlus__Layout self)
131{ 134{
132 /* use a random scale factor to account for unknown descenders, 0.8 works 135 /* use a random scale factor to account for unknown descenders, 0.8 works
133 * reasonably well with bitstream vera 136 * reasonably well with bitstream vera
134 */ 137 */
135 PangoFontDescription *font = self->font ? self->font : default_font; 138 PangoFontDescription *font = self->font ? self->font : default_font;
139 142
140 pango_layout_set_font_description (self->pl, font); 143 pango_layout_set_font_description (self->pl, font);
141} 144}
142 145
143static void 146static void
144layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
145{ 148{
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_width, 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;
299 mapcell *cell;
288 300
289 for (y = y0; y < y0 + h; y++) 301 for (y = y0; y < y0 + h; y++)
290 if (y >= 0) 302 if (y >= 0)
291 { 303 {
292 if (y >= self->rows) 304 if (y >= self->rows)
298 if (x >= row->c0) 310 if (x >= row->c0)
299 { 311 {
300 if (x >= row->c1) 312 if (x >= row->c1)
301 break; 313 break;
302 314
303 row->col[x - row->c0].darkness = -1; 315 cell = row->col + x - row->c0;
316
317 cell->darkness = 0;
318 cell->stat_hp = 0;
304 } 319 }
305 } 320 }
306} 321}
307 322
308static void 323static void
346 n |= n >> 16; 361 n |= n >> 16;
347 362
348 return n + 1; 363 return n + 1;
349} 364}
350 365
351MODULE = CFClient PACKAGE = CFClient 366MODULE = CFPlus PACKAGE = CFPlus
352 367
353PROTOTYPES: ENABLE 368PROTOTYPES: ENABLE
354 369
355BOOT: 370BOOT:
356{ 371{
357 HV *stash = gv_stashpv ("CFClient", 1); 372 HV *stash = gv_stashpv ("CFPlus", 1);
358 static const struct { 373 static const struct {
359 const char *name; 374 const char *name;
360 IV iv; 375 IV iv;
361 } *civ, const_iv[] = { 376 } *civ, const_iv[] = {
362# define const_iv(name) { # name, (IV)name } 377# define const_iv(name) { # name, (IV)name }
509 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 524 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
510 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); 525 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
511 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 526 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
512 527
513 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 528 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
529#if SDL_VERSION_ATLEAST(1,2,10)
530 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
531 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
532#endif
514 533
515 SDL_EnableUNICODE (1); 534 SDL_EnableUNICODE (1);
516 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 535 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
517 536
518 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 537 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
605 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 624 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
606 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 625 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
607 break; 626 break;
608 } 627 }
609 628
610 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 629 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
611 } 630 }
612} 631}
613 632
614int 633int
615Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048) 634Mix_OpenAudio (int frequency = 48000, int format = MIX_DEFAULT_FORMAT, int channels = 1, int chunksize = 2048)
744void 763void
745_exit (int retval) 764_exit (int retval)
746 CODE: 765 CODE:
747 _exit (retval); 766 _exit (retval);
748 767
749MODULE = CFClient PACKAGE = CFClient::Font 768MODULE = CFPlus PACKAGE = CFPlus::Font
750 769
751CFClient::Font 770CFPlus::Font
752new_from_file (SV *class, char *path, int id = 0) 771new_from_file (SV *class, char *path, int id = 0)
753 CODE: 772 CODE:
754{ 773{
755 int count; 774 int count;
756 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 775 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
759} 778}
760 OUTPUT: 779 OUTPUT:
761 RETVAL 780 RETVAL
762 781
763void 782void
764DESTROY (CFClient::Font self) 783DESTROY (CFPlus::Font self)
765 CODE: 784 CODE:
766 pango_font_description_free (self); 785 pango_font_description_free (self);
767 786
768void 787void
769make_default (CFClient::Font self) 788make_default (CFPlus::Font self)
770 CODE: 789 CODE:
771 default_font = self; 790 default_font = self;
772 791
773MODULE = CFClient PACKAGE = CFClient::Layout 792MODULE = CFPlus PACKAGE = CFPlus::Layout
774 793
775void 794void
776reset_glyph_cache () 795reset_glyph_cache ()
777 CODE: 796 CODE:
778 tc_clear (); 797 tc_clear ();
779 798
780CFClient::Layout 799CFPlus::Layout
781new (SV *class) 800new (SV *class)
782 CODE: 801 CODE:
783 New (0, RETVAL, 1, struct cf_layout); 802 New (0, RETVAL, 1, struct cf_layout);
784 803
785 RETVAL->pl = pango_layout_new (opengl_context); 804 RETVAL->pl = pango_layout_new (opengl_context);
794 layout_update_font (RETVAL); 813 layout_update_font (RETVAL);
795 OUTPUT: 814 OUTPUT:
796 RETVAL 815 RETVAL
797 816
798void 817void
799DESTROY (CFClient::Layout self) 818DESTROY (CFPlus::Layout self)
800 CODE: 819 CODE:
801 g_object_unref (self->pl); 820 g_object_unref (self->pl);
802 Safefree (self); 821 Safefree (self);
803 822
804void 823void
805set_text (CFClient::Layout self, SV *text_) 824set_text (CFPlus::Layout self, SV *text_)
806 CODE: 825 CODE:
807{ 826{
808 STRLEN textlen; 827 STRLEN textlen;
809 char *text = SvPVutf8 (text_, textlen); 828 char *text = SvPVutf8 (text_, textlen);
810 829
811 pango_layout_set_text (self->pl, text, textlen); 830 pango_layout_set_text (self->pl, text, textlen);
812} 831}
813 832
814void 833void
815set_markup (CFClient::Layout self, SV *text_) 834set_markup (CFPlus::Layout self, SV *text_)
816 CODE: 835 CODE:
817{ 836{
818 STRLEN textlen; 837 STRLEN textlen;
819 char *text = SvPVutf8 (text_, textlen); 838 char *text = SvPVutf8 (text_, textlen);
820 839
821 pango_layout_set_markup (self->pl, text, textlen); 840 pango_layout_set_markup (self->pl, text, textlen);
822} 841}
823 842
824void 843void
825set_shapes (CFClient::Layout self, ...) 844set_shapes (CFPlus::Layout self, ...)
826 CODE: 845 CODE:
827{ 846{
828 PangoAttrList *attrs = 0; 847 PangoAttrList *attrs = 0;
829 const char *text = pango_layout_get_text (self->pl); 848 const char *text = pango_layout_get_text (self->pl);
830 const char *pos = text; 849 const char *pos = text;
865 if (attrs) 884 if (attrs)
866 pango_layout_set_attributes (self->pl, attrs); 885 pango_layout_set_attributes (self->pl, attrs);
867} 886}
868 887
869void 888void
870get_shapes (CFClient::Layout self) 889get_shapes (CFPlus::Layout self)
871 PPCODE: 890 PPCODE:
872{ 891{
873 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 892 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
874 893
875 do 894 do
890 909
891 pango_layout_iter_free (iter); 910 pango_layout_iter_free (iter);
892} 911}
893 912
894int 913int
895has_wrapped (CFClient::Layout self) 914has_wrapped (CFPlus::Layout self)
896 CODE: 915 CODE:
897{ 916{
898 int lines = 1; 917 int lines = 1;
899 const char *text = pango_layout_get_text (self->pl); 918 const char *text = pango_layout_get_text (self->pl);
900 919
905} 924}
906 OUTPUT: 925 OUTPUT:
907 RETVAL 926 RETVAL
908 927
909SV * 928SV *
910get_text (CFClient::Layout self) 929get_text (CFPlus::Layout self)
911 CODE: 930 CODE:
912 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 931 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
913 sv_utf8_decode (RETVAL); 932 sv_utf8_decode (RETVAL);
914 OUTPUT: 933 OUTPUT:
915 RETVAL 934 RETVAL
916 935
917void 936void
918set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) 937set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.)
919 CODE: 938 CODE:
920 self->r = r; 939 self->r = r;
921 self->g = g; 940 self->g = g;
922 self->b = b; 941 self->b = b;
923 self->a = a; 942 self->a = a;
924 943
925void 944void
926set_font (CFClient::Layout self, CFClient::Font font = 0) 945set_font (CFPlus::Layout self, CFPlus::Font font = 0)
927 CODE: 946 CODE:
928 if (self->font != font) 947 if (self->font != font)
929 { 948 {
930 self->font = font; 949 self->font = font;
931 layout_update_font (self); 950 layout_update_font (self);
932 } 951 }
933 952
934void 953void
935set_height (CFClient::Layout self, int base_height) 954set_height (CFPlus::Layout self, int base_height)
936 CODE: 955 CODE:
937 if (self->base_height != base_height) 956 if (self->base_height != base_height)
938 { 957 {
939 self->base_height = base_height; 958 self->base_height = base_height;
940 layout_update_font (self); 959 layout_update_font (self);
941 } 960 }
942 961
943void 962void
944set_width (CFClient::Layout self, int max_width = -1) 963set_width (CFPlus::Layout self, int max_width = -1)
945 CODE: 964 CODE:
946 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 965 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
947 966
948void 967void
949set_indent (CFClient::Layout self, int indent) 968set_indent (CFPlus::Layout self, int indent)
950 CODE: 969 CODE:
951 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 970 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
952 971
953void 972void
954set_spacing (CFClient::Layout self, int spacing) 973set_spacing (CFPlus::Layout self, int spacing)
955 CODE: 974 CODE:
956 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 975 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
957 976
958void 977void
959set_ellipsise (CFClient::Layout self, int ellipsise) 978set_ellipsise (CFPlus::Layout self, int ellipsise)
960 CODE: 979 CODE:
961 pango_layout_set_ellipsize (self->pl, 980 pango_layout_set_ellipsize (self->pl,
962 ellipsise == 1 ? PANGO_ELLIPSIZE_START 981 ellipsise == 1 ? PANGO_ELLIPSIZE_START
963 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 982 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
964 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 983 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
965 : PANGO_ELLIPSIZE_NONE 984 : PANGO_ELLIPSIZE_NONE
966 ); 985 );
967 986
968void 987void
969set_single_paragraph_mode (CFClient::Layout self, int spm) 988set_single_paragraph_mode (CFPlus::Layout self, int spm)
970 CODE: 989 CODE:
971 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 990 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
972 991
973void 992void
974size (CFClient::Layout self) 993size (CFPlus::Layout self)
975 PPCODE: 994 PPCODE:
976{ 995{
977 int w, h; 996 int w, h;
978 997
979 layout_get_pixel_size (self, &w, &h); 998 layout_get_pixel_size (self, &w, &h);
982 PUSHs (sv_2mortal (newSViv (w))); 1001 PUSHs (sv_2mortal (newSViv (w)));
983 PUSHs (sv_2mortal (newSViv (h))); 1002 PUSHs (sv_2mortal (newSViv (h)));
984} 1003}
985 1004
986int 1005int
987descent (CFClient::Layout self) 1006descent (CFPlus::Layout self)
988 CODE: 1007 CODE:
989{ 1008{
990 PangoRectangle rect; 1009 PangoRectangle rect;
991 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1010 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0);
992 pango_layout_line_get_pixel_extents (line, 0, &rect); 1011 pango_layout_line_get_pixel_extents (line, 0, &rect);
994} 1013}
995 OUTPUT: 1014 OUTPUT:
996 RETVAL 1015 RETVAL
997 1016
998int 1017int
999xy_to_index (CFClient::Layout self, int x, int y) 1018xy_to_index (CFPlus::Layout self, int x, int y)
1000 CODE: 1019 CODE:
1001{ 1020{
1002 int index, trailing; 1021 int index, trailing;
1003 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1022 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1004 RETVAL = index; 1023 RETVAL = index;
1005} 1024}
1006 OUTPUT: 1025 OUTPUT:
1007 RETVAL 1026 RETVAL
1008 1027
1009void 1028void
1010cursor_pos (CFClient::Layout self, int index) 1029cursor_pos (CFPlus::Layout self, int index)
1011 PPCODE: 1030 PPCODE:
1012{ 1031{
1013 PangoRectangle strong_pos; 1032 PangoRectangle strong_pos;
1014 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1033 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
1015 1034
1018 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1037 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1019 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1038 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1020} 1039}
1021 1040
1022void 1041void
1023render (CFClient::Layout self, float x, float y) 1042render (CFPlus::Layout self, float x, float y, int flags = 0)
1024 PPCODE: 1043 PPCODE:
1025 pango_opengl_render_layout_subpixel ( 1044 pango_opengl_render_layout_subpixel (
1026 self->pl, 1045 self->pl,
1027 x * PANGO_SCALE, y * PANGO_SCALE, 1046 x * PANGO_SCALE, y * PANGO_SCALE,
1028 self->r, self->g, self->b, self->a 1047 self->r, self->g, self->b, self->a,
1048 flags
1029 ); 1049 );
1030 1050
1031MODULE = CFClient PACKAGE = CFClient::Texture 1051MODULE = CFPlus PACKAGE = CFPlus::Texture
1032 1052
1033void 1053void
1034pad2pot (SV *data_, SV *w_, SV *h_) 1054pad2pot (SV *data_, SV *w_, SV *h_)
1035 CODE: 1055 CODE:
1036{ 1056{
1114 glDisable (GL_ALPHA_TEST); 1134 glDisable (GL_ALPHA_TEST);
1115 glDisable (GL_BLEND); 1135 glDisable (GL_BLEND);
1116 } 1136 }
1117} 1137}
1118 1138
1119MODULE = CFClient PACKAGE = CFClient::Map 1139MODULE = CFPlus PACKAGE = CFPlus::Map
1120 1140
1121CFClient::Map 1141CFPlus::Map
1122new (SV *class, int map_width, int map_height) 1142new (SV *class, int map_width, int map_height)
1123 CODE: 1143 CODE:
1124 New (0, RETVAL, 1, struct map); 1144 New (0, RETVAL, 1, struct map);
1125 RETVAL->x = 0; 1145 RETVAL->x = 0;
1126 RETVAL->y = 0; 1146 RETVAL->y = 0;
1136 RETVAL->row = 0; 1156 RETVAL->row = 0;
1137 OUTPUT: 1157 OUTPUT:
1138 RETVAL 1158 RETVAL
1139 1159
1140void 1160void
1141DESTROY (CFClient::Map self) 1161DESTROY (CFPlus::Map self)
1142 CODE: 1162 CODE:
1143{ 1163{
1144 map_clear (self); 1164 map_clear (self);
1145 Safefree (self->face); 1165 Safefree (self->face);
1146 Safefree (self->tex); 1166 Safefree (self->tex);
1147 Safefree (self); 1167 Safefree (self);
1148} 1168}
1149 1169
1150void 1170void
1151clear (CFClient::Map self) 1171clear (CFPlus::Map self)
1152 CODE: 1172 CODE:
1153 map_clear (self); 1173 map_clear (self);
1154 1174
1155void 1175void
1156set_face (CFClient::Map self, int face, int texid) 1176set_face (CFPlus::Map self, int face, int texid)
1157 CODE: 1177 CODE:
1158{ 1178{
1159 while (self->faces <= face) 1179 while (self->faces <= face)
1160 { 1180 {
1161 Append (mapface, self->face, self->faces, self->faces); 1181 Append (mapface, self->face, self->faces, self->faces);
1164 1184
1165 self->face [face] = texid; 1185 self->face [face] = texid;
1166} 1186}
1167 1187
1168void 1188void
1169set_texture (CFClient::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1189set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1170 CODE: 1190 CODE:
1171{ 1191{
1172 while (self->texs <= texid) 1192 while (self->texs <= texid)
1173 { 1193 {
1174 Append (maptex, self->tex, self->texs, self->texs); 1194 Append (maptex, self->tex, self->texs, self->texs);
1198 // from transparent color bleeding and ugly wrapping effects. 1218 // from transparent color bleeding and ugly wrapping effects.
1199 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1219 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1200} 1220}
1201 1221
1202int 1222int
1203ox (CFClient::Map self) 1223ox (CFPlus::Map self)
1204 ALIAS: 1224 ALIAS:
1205 oy = 1 1225 oy = 1
1206 x = 2 1226 x = 2
1207 y = 3 1227 y = 3
1208 w = 4 1228 w = 4
1219 } 1239 }
1220 OUTPUT: 1240 OUTPUT:
1221 RETVAL 1241 RETVAL
1222 1242
1223void 1243void
1224scroll (CFClient::Map self, int dx, int dy) 1244scroll (CFPlus::Map self, int dx, int dy)
1225 CODE: 1245 CODE:
1226{ 1246{
1227 if (dx > 0) 1247 if (dx > 0)
1228 map_blank (self, self->x, self->y, dx - 1, self->h); 1248 map_blank (self, self->x, self->y, dx - 1, self->h);
1229 else if (dx < 0) 1249 else if (dx < 0)
1245 self->y += MAP_EXTEND_Y; 1265 self->y += MAP_EXTEND_Y;
1246 } 1266 }
1247} 1267}
1248 1268
1249void 1269void
1250map1a_update (CFClient::Map self, SV *data_) 1270map1a_update (CFPlus::Map self, SV *data_, int extmap)
1251 CODE: 1271 CODE:
1252{ 1272{
1253 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1273 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1254 uint8_t *data_end = (uint8_t *)SvEND (data_); 1274 uint8_t *data_end = (uint8_t *)SvEND (data_);
1255 mapcell *cell; 1275 mapcell *cell;
1256 int x, y, flags; 1276 int x, y, flags;
1257 1277
1258 while (data < data_end) 1278 while (data < data_end - 1)
1259 { 1279 {
1260 flags = (data [0] << 8) + data [1]; data += 2; 1280 flags = (data [0] << 8) + data [1]; data += 2;
1261 1281
1262 x = self->x + ((flags >> 10) & 63); 1282 x = self->x + ((flags >> 10) & 63);
1263 y = self->y + ((flags >> 4) & 63); 1283 y = self->y + ((flags >> 4) & 63);
1264 1284
1265 cell = map_get_cell (self, x, y); 1285 cell = map_get_cell (self, x, y);
1266 1286
1267 if (flags & 15) 1287 if (flags & 15)
1268 { 1288 {
1269 if (cell->darkness < 0) 1289 if (!cell->darkness)
1270 { 1290 {
1271 cell->darkness = 0; 1291 cell->darkness = 256;
1272 cell->face [0] = 0; 1292 cell->face [0] = 0;
1273 cell->face [1] = 0; 1293 cell->face [1] = 0;
1274 cell->face [2] = 0; 1294 cell->face [2] = 0;
1275 } 1295 }
1276 1296
1277 cell->darkness = flags & 8 ? *data++ : 255;
1278
1279 //TODO: don't trust server data to be in-range(!) 1297 //TODO: don't trust server data to be in-range(!)
1298
1299 if (flags & 8)
1300 {
1301 if (extmap)
1302 {
1303 uint8_t ext, cmd;
1304
1305 do
1306 {
1307 ext = *data++;
1308 cmd = ext & 0x3f;
1309
1310 if (cmd < 4)
1311 cell->darkness = 255 - ext * 64 + 1;
1312 else if (cmd == 5) // health
1313 {
1314 cell->stat_width = 1;
1315 cell->stat_hp = *data++;
1316 }
1317 else if (cmd == 6) // monster width
1318 cell->stat_width = *data++ + 1;
1319 else if (ext & 0x40) // unknown, multibyte => skip
1320 data += *data + 1;
1321 else
1322 data++;
1323 }
1324 while (ext & 0x80);
1325 }
1326 else
1327 cell->darkness = *data++ + 1;
1328 }
1280 1329
1281 if (flags & 4) 1330 if (flags & 4)
1282 { 1331 {
1283 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1332 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1284 } 1333 }
1292 { 1341 {
1293 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1342 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1294 } 1343 }
1295 } 1344 }
1296 else 1345 else
1346 {
1297 cell->darkness = -1; 1347 cell->darkness = 0;
1348 cell->stat_hp = 0;
1349 }
1298 } 1350 }
1299} 1351}
1300 1352
1301SV * 1353SV *
1302mapmap (CFClient::Map self, int x0, int y0, int w, int h) 1354mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1303 CODE: 1355 CODE:
1304{ 1356{
1305 int x1, x; 1357 int x1, x;
1306 int y1, y; 1358 int y1, y;
1307 int z; 1359 int z;
1357} 1409}
1358 OUTPUT: 1410 OUTPUT:
1359 RETVAL 1411 RETVAL
1360 1412
1361void 1413void
1362draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1414draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1363 CODE: 1415 CODE:
1364{ 1416{
1365 int vx, vy; 1417 int vx, vy;
1366 int x, y, z; 1418 int x, y, z;
1367 int last_name; 1419 int last_name;
1402 { 1454 {
1403 mapcell *cell = row->col + (x + vx - row->c0); 1455 mapcell *cell = row->col + (x + vx - row->c0);
1404 1456
1405 face = cell->face [z]; 1457 face = cell->face [z];
1406 1458
1407 if (face) 1459 if (face && face < self->texs)
1408 { 1460 {
1409 maptex tex = self->tex [face]; 1461 maptex tex = self->tex [face];
1410 1462
1411 int px = (x + 1) * 32 - tex.w; 1463 int px = (x + 1) * 32 - tex.w;
1412 int py = (y + 1) * 32 - tex.h; 1464 int py = (y + 1) * 32 - tex.h;
1429 1481
1430 glEnd (); 1482 glEnd ();
1431 1483
1432 glDisable (GL_TEXTURE_2D); 1484 glDisable (GL_TEXTURE_2D);
1433 glDisable (GL_BLEND); 1485 glDisable (GL_BLEND);
1434}
1435 1486
1487 // top layer: overlays such as the health bar
1488 for (y = 0; y < sh; y++)
1489 if (0 <= y + vy && y + vy < self->rows)
1490 {
1491 maprow *row = self->row + (y + vy);
1492
1493 for (x = 0; x < sw; x++)
1494 if (row->c0 <= x + vx && x + vx < row->c1)
1495 {
1496 mapcell *cell = row->col + (x + vx - row->c0);
1497
1498 int px = x * 32;
1499 int py = y * 32;
1500
1501 if (cell->stat_hp)
1502 {
1503 int width = cell->stat_width * 32;
1504 int thick = sh / 28 + 1 + cell->stat_width;
1505
1506 glColor3ub (0, 0, 0);
1507 glRectf (px + 1, py - thick - 2,
1508 px + width - 1, py);
1509
1510 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1511 glRectf (px + 2,
1512 py - thick - 1,
1513 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1514 }
1515 }
1516 }
1517}
1518
1436void 1519void
1437draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) 1520draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1438 CODE: 1521 CODE:
1439{ 1522{
1440 static float color[16][3] = { 1523 static float color[16][3] = {
1441 { 0.00F, 0.00F, 0.00F }, 1524 { 0.00F, 0.00F, 0.00F },
1442 { 1.00F, 1.00F, 1.00F }, 1525 { 1.00F, 1.00F, 1.00F },
1492 glDisable (GL_BLEND); 1575 glDisable (GL_BLEND);
1493 glDisable (GL_TEXTURE_2D); 1576 glDisable (GL_TEXTURE_2D);
1494} 1577}
1495 1578
1496void 1579void
1497fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 1580fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
1498 PPCODE: 1581 PPCODE:
1499{ 1582{
1500 int vx, vy; 1583 int vx, vy;
1501 int x, y; 1584 int x, y;
1502 int sw4 = (sw + 3) & ~3; 1585 int sw4 = (sw + 3) & ~3;
1518 for (x = 0; x < sw; x++) 1601 for (x = 0; x < sw; x++)
1519 if (row->c0 <= x + vx && x + vx < row->c1) 1602 if (row->c0 <= x + vx && x + vx < row->c1)
1520 { 1603 {
1521 mapcell *cell = row->col + (x + vx - row->c0); 1604 mapcell *cell = row->col + (x + vx - row->c0);
1522 1605
1523 darkness[y * sw4 + x] = cell->darkness < 0 1606 darkness[y * sw4 + x] = cell->darkness
1607 ? 255 - (cell->darkness - 1)
1524 ? 255 - FOW_DARKNESS 1608 : 255 - FOW_DARKNESS;
1525 : 255 - cell->darkness;
1526 } 1609 }
1527 } 1610 }
1528 1611
1529 EXTEND (SP, 3); 1612 EXTEND (SP, 3);
1530 PUSHs (sv_2mortal (newSViv (sw4))); 1613 PUSHs (sv_2mortal (newSViv (sw4)));
1531 PUSHs (sv_2mortal (newSViv (sh))); 1614 PUSHs (sv_2mortal (newSViv (sh)));
1532 PUSHs (darkness_sv); 1615 PUSHs (darkness_sv);
1533} 1616}
1534 1617
1535SV * 1618SV *
1536get_rect (CFClient::Map self, int x0, int y0, int w, int h) 1619get_rect (CFPlus::Map self, int x0, int y0, int w, int h)
1537 CODE: 1620 CODE:
1538{ 1621{
1539 int x, y, x1, y1; 1622 int x, y, x1, y1;
1540 SV *data_sv = newSV (w * h * 7 + 5); 1623 SV *data_sv = newSV (w * h * 7 + 5);
1541 uint8_t *data = (uint8_t *)SvPVX (data_sv); 1624 uint8_t *data = (uint8_t *)SvPVX (data_sv);
1603} 1686}
1604 OUTPUT: 1687 OUTPUT:
1605 RETVAL 1688 RETVAL
1606 1689
1607void 1690void
1608set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 1691set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data)
1609 PPCODE: 1692 PPCODE:
1610{ 1693{
1611 int x, y, z; 1694 int x, y, z;
1612 int w, h; 1695 int w, h;
1613 int x1, y1; 1696 int x1, y1;
1645 1728
1646 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1729 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1647 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1730 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1648 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1731 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1649 1732
1650 if (cell->darkness <= 0) 1733 if (cell->darkness == 0)
1651 { 1734 {
1652 cell->darkness = -1; 1735 cell->darkness = 0;
1653 1736
1654 for (z = 0; z <= 2; z++) 1737 for (z = 0; z <= 2; z++)
1655 { 1738 {
1656 cell->face[z] = face[z]; 1739 cell->face[z] = face[z];
1657 1740
1662 } 1745 }
1663 } 1746 }
1664 } 1747 }
1665} 1748}
1666 1749
1667MODULE = CFClient PACKAGE = CFClient::MixChunk 1750MODULE = CFPlus PACKAGE = CFPlus::MixChunk
1668 1751
1669CFClient::MixChunk 1752CFPlus::MixChunk
1670new_from_file (SV *class, char *path) 1753new_from_file (SV *class, char *path)
1671 CODE: 1754 CODE:
1672 RETVAL = Mix_LoadWAV (path); 1755 RETVAL = Mix_LoadWAV (path);
1673 OUTPUT: 1756 OUTPUT:
1674 RETVAL 1757 RETVAL
1675 1758
1676void 1759void
1677DESTROY (CFClient::MixChunk self) 1760DESTROY (CFPlus::MixChunk self)
1678 CODE: 1761 CODE:
1679 Mix_FreeChunk (self); 1762 Mix_FreeChunk (self);
1680 1763
1681int 1764int
1682volume (CFClient::MixChunk self, int volume = -1) 1765volume (CFPlus::MixChunk self, int volume = -1)
1683 CODE: 1766 CODE:
1684 RETVAL = Mix_VolumeChunk (self, volume); 1767 RETVAL = Mix_VolumeChunk (self, volume);
1685 OUTPUT: 1768 OUTPUT:
1686 RETVAL 1769 RETVAL
1687 1770
1688int 1771int
1689play (CFClient::MixChunk self, int channel = -1, int loops = 0, int ticks = -1) 1772play (CFPlus::MixChunk self, int channel = -1, int loops = 0, int ticks = -1)
1690 CODE: 1773 CODE:
1691 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 1774 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
1692 OUTPUT: 1775 OUTPUT:
1693 RETVAL 1776 RETVAL
1694 1777
1695MODULE = CFClient PACKAGE = CFClient::MixMusic 1778MODULE = CFPlus PACKAGE = CFPlus::MixMusic
1696 1779
1697int 1780int
1698volume (int volume = -1) 1781volume (int volume = -1)
1699 CODE: 1782 CODE:
1700 RETVAL = Mix_VolumeMusic (volume); 1783 RETVAL = Mix_VolumeMusic (volume);
1701 OUTPUT: 1784 OUTPUT:
1702 RETVAL 1785 RETVAL
1703 1786
1704CFClient::MixMusic 1787CFPlus::MixMusic
1705new_from_file (SV *class, char *path) 1788new_from_file (SV *class, char *path)
1706 CODE: 1789 CODE:
1707 RETVAL = Mix_LoadMUS (path); 1790 RETVAL = Mix_LoadMUS (path);
1708 OUTPUT: 1791 OUTPUT:
1709 RETVAL 1792 RETVAL
1710 1793
1711void 1794void
1712DESTROY (CFClient::MixMusic self) 1795DESTROY (CFPlus::MixMusic self)
1713 CODE: 1796 CODE:
1714 Mix_FreeMusic (self); 1797 Mix_FreeMusic (self);
1715 1798
1716int 1799int
1717play (CFClient::MixMusic self, int loops = -1) 1800play (CFPlus::MixMusic self, int loops = -1)
1718 CODE: 1801 CODE:
1719 RETVAL = Mix_PlayMusic (self, loops); 1802 RETVAL = Mix_PlayMusic (self, loops);
1720 OUTPUT: 1803 OUTPUT:
1721 RETVAL 1804 RETVAL
1722 1805
1723MODULE = CFClient PACKAGE = CFClient::OpenGL 1806MODULE = CFPlus PACKAGE = CFPlus::OpenGL
1724 1807
1725BOOT: 1808BOOT:
1726{ 1809{
1727 HV *stash = gv_stashpv ("CFClient::OpenGL", 1); 1810 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1);
1728 static const struct { 1811 static const struct {
1729 const char *name; 1812 const char *name;
1730 IV iv; 1813 IV iv;
1731 } *civ, const_iv[] = { 1814 } *civ, const_iv[] = {
1732# define const_iv(name) { # name, (IV)name } 1815# define const_iv(name) { # name, (IV)name }
1795 const_iv (GL_SEPARABLE_2D), 1878 const_iv (GL_SEPARABLE_2D),
1796 const_iv (GL_CONVOLUTION_2D), 1879 const_iv (GL_CONVOLUTION_2D),
1797 const_iv (GL_CONVOLUTION_BORDER_MODE), 1880 const_iv (GL_CONVOLUTION_BORDER_MODE),
1798 const_iv (GL_CONSTANT_BORDER), 1881 const_iv (GL_CONSTANT_BORDER),
1799 const_iv (GL_LINES), 1882 const_iv (GL_LINES),
1883 const_iv (GL_LINE_STRIP),
1800 const_iv (GL_LINE_LOOP), 1884 const_iv (GL_LINE_LOOP),
1801 const_iv (GL_QUADS), 1885 const_iv (GL_QUADS),
1802 const_iv (GL_QUAD_STRIP), 1886 const_iv (GL_QUAD_STRIP),
1803 const_iv (GL_TRIANGLES), 1887 const_iv (GL_TRIANGLES),
1804 const_iv (GL_TRIANGLE_STRIP), 1888 const_iv (GL_TRIANGLE_STRIP),
1914 r *= a; 1998 r *= a;
1915 g *= a; 1999 g *= a;
1916 b *= a; 2000 b *= a;
1917 } 2001 }
1918 // microsoft visual "c" rounds instead of truncating... 2002 // microsoft visual "c" rounds instead of truncating...
1919 glColor4ub (MIN ((int)(r * 256.f), 255), 2003 glColor4f (r, g, b, a);
1920 MIN ((int)(g * 256.f), 255),
1921 MIN ((int)(b * 256.f), 255),
1922 MIN ((int)(a * 256.f), 255));
1923 2004
1924void glInterleavedArrays (int format, int stride, char *data) 2005void glInterleavedArrays (int format, int stride, char *data)
1925 2006
1926void glDrawElements (int mode, int count, int type, char *indices) 2007void glDrawElements (int mode, int count, int type, char *indices)
1927 2008
2004 2085
2005void glEndList () 2086void glEndList ()
2006 2087
2007void glCallList (int list) 2088void glCallList (int list)
2008 2089
2009

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines