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.235 by root, Tue Aug 28 01:23:47 2007 UTC vs.
Revision 1.284 by elmex, Thu Dec 11 00:17:47 2008 UTC

39#include <SDL_endian.h> 39#include <SDL_endian.h>
40#include <SDL_image.h> 40#include <SDL_image.h>
41#include <SDL_mixer.h> 41#include <SDL_mixer.h>
42#include <SDL_opengl.h> 42#include <SDL_opengl.h>
43 43
44/* work around os x broken headers */
45#ifdef __MACOSX__
46typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
47#endif
48
44#define PANGO_ENABLE_BACKEND 49#define PANGO_ENABLE_BACKEND
45#define G_DISABLE_CAST_CHECKS 50#define G_DISABLE_CAST_CHECKS
46 51
47#include <glib/gmacros.h> 52#include <glib/gmacros.h>
48 53
49#include <pango/pango.h> 54#include <pango/pango.h>
55
56#ifndef PANGO_VERSION_CHECK
57# define PANGO_VERSION_CHECK(a,b,c) 0
58#endif
59
60#if !PANGO_VERSION_CHECK (1, 15, 2)
61# define pango_layout_get_line_readonly pango_layout_get_line
62# define pango_layout_get_lines_readonly pango_layout_get_lines
63# define pango_layout_iter_get_line_readonly pango_layout_iter_get_line
64# define pango_layout_iter_get_run_readonly pango_layout_iter_get_run
65#endif
50 66
51#ifndef _WIN32 67#ifndef _WIN32
52# include <sys/types.h> 68# include <sys/types.h>
53# include <sys/socket.h> 69# include <sys/socket.h>
54# include <netinet/in.h> 70# include <netinet/in.h>
55# include <netinet/tcp.h> 71# include <netinet/tcp.h>
56# include <inttypes.h> 72# include <inttypes.h>
57#endif 73#endif
58 74
75#if __GNUC__ >= 4
76# define expect(expr,value) __builtin_expect ((expr),(value))
77#else
78# define expect(expr,value) (expr)
79#endif
80
81#define expect_false(expr) expect ((expr) != 0, 0)
82#define expect_true(expr) expect ((expr) != 0, 1)
83
59#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
60 85
61#define FOW_DARKNESS 32 86#define FOW_DARKNESS 16
62 87
63#define MAP_EXTEND_X 32 88#define MAP_EXTEND_X 32
64#define MAP_EXTEND_Y 512 89#define MAP_EXTEND_Y 512
65 90
66#define MIN_FONT_HEIGHT 10 91#define MIN_FONT_HEIGHT 10
67 92
68#if 0 93/* mask out modifiers we are not interested in */
69# define PARACHUTE SDL_INIT_NOPARACHUTE 94#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
70#else 95
71# define PARACHUTE 0 96#define KMOD_LRAM 0x10000 // our extension
72#endif
73 97
74static AV *texture_av; 98static AV *texture_av;
75 99
76static struct 100static struct
77{ 101{
120 144
121#include "pango-font.c" 145#include "pango-font.c"
122#include "pango-fontmap.c" 146#include "pango-fontmap.c"
123#include "pango-render.c" 147#include "pango-render.c"
124 148
125typedef IV CFPlus__Channel; 149typedef IV DC__Channel;
126typedef SDL_RWops *CFPlus__RW; 150typedef SDL_RWops *DC__RW;
127typedef Mix_Chunk *CFPlus__MixChunk; 151typedef Mix_Chunk *DC__MixChunk;
128typedef Mix_Music *CFPlus__MixMusic; 152typedef Mix_Music *DC__MixMusic;
129 153
130typedef PangoFontDescription *CFPlus__Font; 154typedef PangoFontDescription *DC__Font;
131 155
132static int 156static int
133shape_attr_p (PangoLayoutRun *run) 157shape_attr_p (PangoLayoutRun *run)
134{ 158{
135 GSList *attrs = run->item->analysis.extra_attrs; 159 GSList *attrs = run->item->analysis.extra_attrs;
149 173
150typedef struct cf_layout { 174typedef struct cf_layout {
151 PangoLayout *pl; 175 PangoLayout *pl;
152 float r, g, b, a; // default color for rgba mode 176 float r, g, b, a; // default color for rgba mode
153 int base_height; 177 int base_height;
154 CFPlus__Font font; 178 DC__Font font;
155 rc_t *rc; 179 rc_t *rc;
156} *CFPlus__Layout; 180} *DC__Layout;
157 181
158static CFPlus__Font default_font; 182static DC__Font default_font;
159static PangoContext *opengl_context; 183static PangoContext *opengl_context;
160static PangoFontMap *opengl_fontmap; 184static PangoFontMap *opengl_fontmap;
161 185
162static void 186static void
163substitute_func (FcPattern *pattern, gpointer data) 187substitute_func (FcPattern *pattern, gpointer data)
168#endif 192#endif
169 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 193 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
170} 194}
171 195
172static void 196static void
173layout_update_font (CFPlus__Layout self) 197layout_update_font (DC__Layout self)
174{ 198{
175 /* use a random scale factor to account for unknown descenders, 0.8 works 199 /* use a random scale factor to account for unknown descenders, 0.8 works
176 * reasonably well with bitstream vera 200 * reasonably well with dejavu/bistream fonts
177 */ 201 */
178 PangoFontDescription *font = self->font ? self->font : default_font; 202 PangoFontDescription *font = self->font ? self->font : default_font;
179 203
180 pango_font_description_set_absolute_size (font, 204 pango_font_description_set_absolute_size (font,
181 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); 205 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
182 206
183 pango_layout_set_font_description (self->pl, font); 207 pango_layout_set_font_description (self->pl, font);
184} 208}
185 209
186static void 210static void
187layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 211layout_get_pixel_size (DC__Layout self, int *w, int *h)
188{ 212{
189 PangoRectangle rect; 213 PangoRectangle rect;
190 214
191 // get_pixel_* wrongly rounds down 215 // get_pixel_* wrongly rounds down
192 pango_layout_get_extents (self->pl, 0, &rect); 216 pango_layout_get_extents (self->pl, 0, &rect);
209 int w, h; 233 int w, h;
210 float s, t; 234 float s, t;
211 uint8_t r, g, b, a; 235 uint8_t r, g, b, a;
212 tileid smoothtile; 236 tileid smoothtile;
213 uint8_t smoothlevel; 237 uint8_t smoothlevel;
238 uint8_t unused; /* set to zero on use */
214} maptex; 239} maptex;
215 240
216typedef struct { 241typedef struct {
217 uint32_t player; 242 uint32_t player;
218 tileid tile[3]; 243 tileid tile[3];
231 int faces; tileid *face2tile; // [faceid] 256 int faces; tileid *face2tile; // [faceid]
232 int texs; maptex *tex; // [tileid] 257 int texs; maptex *tex; // [tileid]
233 258
234 int32_t rows; 259 int32_t rows;
235 maprow *row; 260 maprow *row;
236} *CFPlus__Map; 261} *DC__Map;
237 262
238static char * 263static char *
239prepend (char *ptr, int sze, int inc) 264prepend (char *ptr, int sze, int inc)
240{ 265{
241 char *p; 266 char *p;
279 self->texs *= 2; 304 self->texs *= 2;
280 } 305 }
281} 306}
282 307
283static maprow * 308static maprow *
284map_get_row (CFPlus__Map self, int y) 309map_get_row (DC__Map self, int y)
285{ 310{
286 if (0 > y) 311 if (0 > y)
287 { 312 {
288 int extend = - y + MAP_EXTEND_Y; 313 int extend = - y + MAP_EXTEND_Y;
289 Prepend (maprow, self->row, self->rows, extend); 314 Prepend (maprow, self->row, self->rows, extend);
327 352
328 return row->col + (x - row->c0); 353 return row->col + (x - row->c0);
329} 354}
330 355
331static mapcell * 356static mapcell *
332map_get_cell (CFPlus__Map self, int x, int y) 357map_get_cell (DC__Map self, int x, int y)
333{ 358{
334 return row_get_cell (map_get_row (self, y), x); 359 return row_get_cell (map_get_row (self, y), x);
335} 360}
336 361
337static void 362static void
338map_clear (CFPlus__Map self) 363map_clear (DC__Map self)
339{ 364{
340 int r; 365 int r;
341 366
342 for (r = 0; r < self->rows; r++) 367 for (r = 0; r < self->rows; r++)
343 Safefree (self->row[r].col); 368 Safefree (self->row[r].col);
350 self->oy = 0; 375 self->oy = 0;
351 self->row = 0; 376 self->row = 0;
352 self->rows = 0; 377 self->rows = 0;
353} 378}
354 379
380#define CELL_CLEAR(cell) \
381 do { \
382 if ((cell)->player) \
383 (cell)->tile [2] = 0; \
384 (cell)->darkness = 0; \
385 (cell)->stat_hp = 0; \
386 (cell)->flags = 0; \
387 (cell)->player = 0; \
388 } while (0)
389
355static void 390static void
356map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 391map_blank (DC__Map self, int x0, int y0, int w, int h)
357{ 392{
358 int x, y; 393 int x, y;
359 maprow *row; 394 maprow *row;
360 mapcell *cell; 395 mapcell *cell;
361 396
373 if (x >= row->c1) 408 if (x >= row->c1)
374 break; 409 break;
375 410
376 cell = row->col + x - row->c0; 411 cell = row->col + x - row->c0;
377 412
378 cell->darkness = 0; 413 CELL_CLEAR (cell);
379 cell->stat_hp = 0;
380 cell->flags = 0;
381 cell->player = 0;
382 } 414 }
383 } 415 }
384} 416}
385 417
386typedef struct { 418typedef struct {
498 return 0; 530 return 0;
499 531
500 return 1; 532 return 1;
501} 533}
502 534
503MODULE = CFPlus PACKAGE = CFPlus 535/******************************************************************************/
536
537/* process keyboard modifiers */
538static int
539mod_munge (int mod)
540{
541 mod &= MOD_MASK;
542
543 if (mod & (KMOD_META | KMOD_ALT))
544 mod |= KMOD_LRAM;
545
546 return mod;
547}
548
549static void
550deliantra_main ()
551{
552 char *argv[] = { 0 };
553 call_argv ("::main", G_DISCARD | G_VOID, argv);
554}
555
556#ifdef __MACOSX__
557 /* to due surprising braindamage on the side of SDL design, we
558 * do some mind-boggling hack here: SDL requires a custom main()
559 * on OS X, so... we provide one and call the original main(), which,
560 * due to share dlibrary magic, calls -lSDLmain's main, not perl's main,
561 * and which calls our main (== SDL_main) back.
562 */
563 extern C_LINKAGE int
564 main (int argc, char *argv[])
565 {
566 deliantra_main ();
567 }
568
569 #undef main
570
571 extern C_LINKAGE int main (int argc, char *argv[]);
572
573 static void
574 SDL_braino (void)
575 {
576 char *argv[] = { "deliantra client", 0 };
577 (main) (1, argv);
578 }
579#else
580 static void
581 SDL_braino (void)
582 {
583 deliantra_main ();
584 }
585#endif
586
587MODULE = Deliantra::Client PACKAGE = DC
504 588
505PROTOTYPES: ENABLE 589PROTOTYPES: ENABLE
506 590
507BOOT: 591BOOT:
508{ 592{
509 HV *stash = gv_stashpv ("CFPlus", 1); 593 HV *stash = gv_stashpv ("DC", 1);
510 static const struct { 594 static const struct {
511 const char *name; 595 const char *name;
512 IV iv; 596 IV iv;
513 } *civ, const_iv[] = { 597 } *civ, const_iv[] = {
514# define const_iv(name) { # name, (IV)name } 598# define const_iv(name) { # name, (IV)name }
535 const_iv (SDL_USEREVENT), 619 const_iv (SDL_USEREVENT),
536 620
537 const_iv (SDL_APPINPUTFOCUS), 621 const_iv (SDL_APPINPUTFOCUS),
538 const_iv (SDL_APPMOUSEFOCUS), 622 const_iv (SDL_APPMOUSEFOCUS),
539 const_iv (SDL_APPACTIVE), 623 const_iv (SDL_APPACTIVE),
624
625
626 const_iv (SDLK_UNKNOWN),
627 const_iv (SDLK_FIRST),
628 const_iv (SDLK_BACKSPACE),
629 const_iv (SDLK_TAB),
630 const_iv (SDLK_CLEAR),
631 const_iv (SDLK_RETURN),
632 const_iv (SDLK_PAUSE),
633 const_iv (SDLK_ESCAPE),
634 const_iv (SDLK_SPACE),
635 const_iv (SDLK_EXCLAIM),
636 const_iv (SDLK_QUOTEDBL),
637 const_iv (SDLK_HASH),
638 const_iv (SDLK_DOLLAR),
639 const_iv (SDLK_AMPERSAND),
640 const_iv (SDLK_QUOTE),
641 const_iv (SDLK_LEFTPAREN),
642 const_iv (SDLK_RIGHTPAREN),
643 const_iv (SDLK_ASTERISK),
644 const_iv (SDLK_PLUS),
645 const_iv (SDLK_COMMA),
646 const_iv (SDLK_MINUS),
647 const_iv (SDLK_PERIOD),
648 const_iv (SDLK_SLASH),
649 const_iv (SDLK_0),
650 const_iv (SDLK_1),
651 const_iv (SDLK_2),
652 const_iv (SDLK_3),
653 const_iv (SDLK_4),
654 const_iv (SDLK_5),
655 const_iv (SDLK_6),
656 const_iv (SDLK_7),
657 const_iv (SDLK_8),
658 const_iv (SDLK_9),
659 const_iv (SDLK_COLON),
660 const_iv (SDLK_SEMICOLON),
661 const_iv (SDLK_LESS),
662 const_iv (SDLK_EQUALS),
663 const_iv (SDLK_GREATER),
664 const_iv (SDLK_QUESTION),
665 const_iv (SDLK_AT),
666
667 const_iv (SDLK_LEFTBRACKET),
668 const_iv (SDLK_BACKSLASH),
669 const_iv (SDLK_RIGHTBRACKET),
670 const_iv (SDLK_CARET),
671 const_iv (SDLK_UNDERSCORE),
672 const_iv (SDLK_BACKQUOTE),
673 const_iv (SDLK_DELETE),
540 674
541 const_iv (SDLK_FIRST), 675 const_iv (SDLK_FIRST),
542 const_iv (SDLK_LAST), 676 const_iv (SDLK_LAST),
543 const_iv (SDLK_KP0), 677 const_iv (SDLK_KP0),
544 const_iv (SDLK_KP1), 678 const_iv (SDLK_KP1),
619 const_iv (KMOD_LMETA), 753 const_iv (KMOD_LMETA),
620 const_iv (KMOD_RMETA), 754 const_iv (KMOD_RMETA),
621 const_iv (KMOD_NUM), 755 const_iv (KMOD_NUM),
622 const_iv (KMOD_CAPS), 756 const_iv (KMOD_CAPS),
623 const_iv (KMOD_MODE), 757 const_iv (KMOD_MODE),
758
759 const_iv (KMOD_LRAM),
760
761 const_iv (MIX_DEFAULT_FORMAT),
762
763 const_iv (SDL_INIT_TIMER),
764 const_iv (SDL_INIT_AUDIO),
765 const_iv (SDL_INIT_VIDEO),
766 const_iv (SDL_INIT_CDROM),
767 const_iv (SDL_INIT_JOYSTICK),
768 const_iv (SDL_INIT_EVERYTHING),
769 const_iv (SDL_INIT_NOPARACHUTE),
770 const_iv (SDL_INIT_EVENTTHREAD),
771
772 const_iv (SDL_GL_RED_SIZE),
773 const_iv (SDL_GL_GREEN_SIZE),
774 const_iv (SDL_GL_BLUE_SIZE),
775 const_iv (SDL_GL_ALPHA_SIZE),
776 const_iv (SDL_GL_DOUBLEBUFFER),
777 const_iv (SDL_GL_BUFFER_SIZE),
778 const_iv (SDL_GL_DEPTH_SIZE),
779 const_iv (SDL_GL_STENCIL_SIZE),
780 const_iv (SDL_GL_ACCUM_RED_SIZE),
781 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
782 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
783 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
784 const_iv (SDL_GL_STEREO),
785 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
786 const_iv (SDL_GL_MULTISAMPLESAMPLES),
787 const_iv (SDL_GL_ACCELERATED_VISUAL),
788 const_iv (SDL_GL_SWAP_CONTROL),
789
790 const_iv (FOW_DARKNESS)
624# undef const_iv 791# undef const_iv
625 }; 792 };
626 793
627 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 794 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
628 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 795 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
657 CODE: 824 CODE:
658{ 825{
659 opengl_fontmap = pango_opengl_font_map_new (); 826 opengl_fontmap = pango_opengl_font_map_new ();
660 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); 827 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0);
661 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); 828 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
829 /*pango_context_set_font_description (opengl_context, default_font);*/
830#if PANGO_VERSION_CHECK (1, 15, 2)
831 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
832 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
833#endif
662} 834}
663 835
664char *
665SDL_GetError () 836char *SDL_GetError ()
666 837
667int 838void SDL_braino ()
668SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
669 839
670void 840int SDL_Init (U32 flags)
841
842int SDL_InitSubSystem (U32 flags)
843
844void SDL_QuitSubSystem (U32 flags)
845
671SDL_Quit () 846void SDL_Quit ()
847
848int SDL_GL_SetAttribute (int attr, int value)
849
850int SDL_GL_GetAttribute (int attr)
851 CODE:
852 if (SDL_GL_GetAttribute (attr, &RETVAL))
853 XSRETURN_UNDEF;
854 OUTPUT:
855 RETVAL
672 856
673void 857void
674SDL_ListModes (int rgb, int alpha) 858SDL_ListModes (int rgb, int alpha)
675 PPCODE: 859 PPCODE:
676{ 860{
688 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 872 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
689 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 873 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
690 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 874 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
691 875
692 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 876 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
693#if SDL_VERSION_ATLEAST(1,2,10)
694 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
695 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 877 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
696#endif
697 878
698 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 879 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
699 880
700 if (m && m != (SDL_Rect **)-1) 881 if (m && m != (SDL_Rect **)-1)
701 while (*m) 882 while (*m)
702 { 883 {
703 if ((*m)->w >= 640 && (*m)->h >= 480) 884 if ((*m)->w >= 400 && (*m)->h >= 300)
704 { 885 {
705 AV *av = newAV (); 886 AV *av = newAV ();
706 av_push (av, newSViv ((*m)->w)); 887 av_push (av, newSViv ((*m)->w));
707 av_push (av, newSViv ((*m)->h)); 888 av_push (av, newSViv ((*m)->h));
708 av_push (av, newSViv (rgb)); 889 av_push (av, newSViv (rgb));
732 913
733 if (RETVAL) 914 if (RETVAL)
734 { 915 {
735 av_clear (texture_av); 916 av_clear (texture_av);
736 917
737 SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT"); 918 SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra");
738#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 919#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
739#include "glfunc.h" 920#include "glfunc.h"
740#undef GL_FUNC 921#undef GL_FUNC
741 } 922 }
742} 923}
749char * 930char *
750SDL_GetKeyName (int sym) 931SDL_GetKeyName (int sym)
751 932
752int 933int
753SDL_GetAppState () 934SDL_GetAppState ()
935
936int
937SDL_GetModState ()
754 938
755void 939void
756poll_events () 940poll_events ()
757 PPCODE: 941 PPCODE:
758{ 942{
768 { 952 {
769 case SDL_KEYDOWN: 953 case SDL_KEYDOWN:
770 case SDL_KEYUP: 954 case SDL_KEYUP:
771 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 955 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
772 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 956 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
773 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 957 hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0);
774 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ 958 hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */
775 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 959 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
776 break; 960 break;
777 961
778 case SDL_ACTIVEEVENT: 962 case SDL_ACTIVEEVENT:
779 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 963 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
797 x = ev.motion.x; 981 x = ev.motion.x;
798 y = ev.motion.y; 982 y = ev.motion.y;
799 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 983 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
800 } 984 }
801 985
802 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 986 hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0);
803 hv_store (hv, "state", 5, newSViv (state), 0); 987 hv_store (hv, "state", 5, newSViv (state), 0);
804 hv_store (hv, "x", 1, newSViv (x), 0); 988 hv_store (hv, "x", 1, newSViv (x), 0);
805 hv_store (hv, "y", 1, newSViv (y), 0); 989 hv_store (hv, "y", 1, newSViv (y), 0);
806 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 990 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
807 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 991 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
808 } 992 }
809 break; 993 break;
810 994
811 case SDL_MOUSEBUTTONDOWN: 995 case SDL_MOUSEBUTTONDOWN:
812 case SDL_MOUSEBUTTONUP: 996 case SDL_MOUSEBUTTONUP:
813 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 997 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
814 998
815 hv_store (hv, "button", 6, newSViv (ev.button.button), 0); 999 hv_store (hv, "button", 6, newSViv (ev.button.button), 0);
816 hv_store (hv, "state", 5, newSViv (ev.button.state), 0); 1000 hv_store (hv, "state", 5, newSViv (ev.button.state), 0);
817 hv_store (hv, "x", 1, newSViv (ev.button.x), 0); 1001 hv_store (hv, "x", 1, newSViv (ev.button.x), 0);
818 hv_store (hv, "y", 1, newSViv (ev.button.y), 0); 1002 hv_store (hv, "y", 1, newSViv (ev.button.y), 0);
823 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 1007 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
824 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 1008 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
825 break; 1009 break;
826 } 1010 }
827 1011
828 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 1012 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
829 } 1013 }
830} 1014}
831 1015
832int 1016int
833Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) 1017Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
834 POSTCALL: 1018 POSTCALL:
835 Mix_HookMusicFinished (music_finished); 1019 Mix_HookMusicFinished (music_finished);
836 Mix_ChannelFinished (channel_finished); 1020 Mix_ChannelFinished (channel_finished);
1021
1022void
1023Mix_QuerySpec ()
1024 PPCODE:
1025{
1026 int freq, channels;
1027 Uint16 format;
1028
1029 if (Mix_QuerySpec (&freq, &format, &channels))
1030 {
1031 EXTEND (SP, 3);
1032 PUSHs (sv_2mortal (newSViv (freq)));
1033 PUSHs (sv_2mortal (newSViv (format)));
1034 PUSHs (sv_2mortal (newSViv (channels)));
1035 }
1036}
837 1037
838void 1038void
839Mix_CloseAudio () 1039Mix_CloseAudio ()
840 1040
841int 1041int
876 } 1076 }
877 } 1077 }
878#endif 1078#endif
879} 1079}
880 1080
881void 1081int
882add_font (char *file) 1082add_font (char *file)
883 CODE: 1083 CODE:
884 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 1084 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
1085 OUTPUT:
1086 RETVAL
885 1087
886void 1088void
887load_image_inline (SV *image_) 1089load_image_inline (SV *image_)
888 ALIAS: 1090 ALIAS:
889 load_image_file = 1 1091 load_image_file = 1
975void 1177void
976error (char *message) 1178error (char *message)
977 CODE: 1179 CODE:
978 fprintf (stderr, "ERROR: %s\n", message); 1180 fprintf (stderr, "ERROR: %s\n", message);
979#ifdef _WIN32 1181#ifdef _WIN32
980 MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); 1182 MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR);
981#endif 1183#endif
982 1184
983void 1185void
984fatal (char *message) 1186fatal (char *message)
985 CODE: 1187 CODE:
986 fprintf (stderr, "FATAL: %s\n", message); 1188 fprintf (stderr, "FATAL: %s\n", message);
987#ifdef _WIN32 1189#ifdef _WIN32
988 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 1190 MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR);
989#endif 1191#endif
990 _exit (1); 1192 _exit (1);
991 1193
992void 1194void
993_exit (int retval = 0) 1195_exit (int retval = 0)
1005#if DEBUG 1207#if DEBUG
1006 VALGRIND_DO_LEAK_CHECK; 1208 VALGRIND_DO_LEAK_CHECK;
1007#endif 1209#endif
1008} 1210}
1009 1211
1010MODULE = CFPlus PACKAGE = CFPlus::Font 1212int
1213SvREFCNT (SV *sv)
1214 CODE:
1215 RETVAL = SvREFCNT (sv);
1216 OUTPUT:
1217 RETVAL
1218
1219MODULE = Deliantra::Client PACKAGE = DC::Font
1011 1220
1012PROTOTYPES: DISABLE 1221PROTOTYPES: DISABLE
1013 1222
1014CFPlus::Font 1223DC::Font
1015new_from_file (SV *class, char *path, int id = 0) 1224new_from_file (SV *class, char *path, int id = 0)
1016 CODE: 1225 CODE:
1017{ 1226{
1018 int count; 1227 int count;
1019 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1228 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
1022} 1231}
1023 OUTPUT: 1232 OUTPUT:
1024 RETVAL 1233 RETVAL
1025 1234
1026void 1235void
1027DESTROY (CFPlus::Font self) 1236DESTROY (DC::Font self)
1028 CODE: 1237 CODE:
1029 pango_font_description_free (self); 1238 pango_font_description_free (self);
1030 1239
1031void 1240void
1032make_default (CFPlus::Font self) 1241make_default (DC::Font self)
1033 PROTOTYPE: $ 1242 PROTOTYPE: $
1034 CODE: 1243 CODE:
1035 default_font = self; 1244 default_font = self;
1036 1245
1037MODULE = CFPlus PACKAGE = CFPlus::Layout 1246MODULE = Deliantra::Client PACKAGE = DC::Layout
1038 1247
1039PROTOTYPES: DISABLE 1248PROTOTYPES: DISABLE
1040 1249
1041void 1250void
1042reset_glyph_cache () 1251glyph_cache_backup ()
1043 PROTOTYPE: 1252 PROTOTYPE:
1044 CODE: 1253 CODE:
1254 tc_backup ();
1255
1256void
1257glyph_cache_restore ()
1258 PROTOTYPE:
1259 CODE:
1045 tc_clear (); 1260 tc_restore ();
1046 1261
1047CFPlus::Layout 1262DC::Layout
1048new (SV *class) 1263new (SV *class)
1049 CODE: 1264 CODE:
1050 New (0, RETVAL, 1, struct cf_layout); 1265 New (0, RETVAL, 1, struct cf_layout);
1051 1266
1052 RETVAL->pl = pango_layout_new (opengl_context); 1267 RETVAL->pl = pango_layout_new (opengl_context);
1062 layout_update_font (RETVAL); 1277 layout_update_font (RETVAL);
1063 OUTPUT: 1278 OUTPUT:
1064 RETVAL 1279 RETVAL
1065 1280
1066void 1281void
1067DESTROY (CFPlus::Layout self) 1282DESTROY (DC::Layout self)
1068 CODE: 1283 CODE:
1069 g_object_unref (self->pl); 1284 g_object_unref (self->pl);
1070 rc_free (self->rc); 1285 rc_free (self->rc);
1071 Safefree (self); 1286 Safefree (self);
1072 1287
1073void 1288void
1074set_text (CFPlus::Layout self, SV *text_) 1289set_text (DC::Layout self, SV *text_)
1075 CODE: 1290 CODE:
1076{ 1291{
1077 STRLEN textlen; 1292 STRLEN textlen;
1078 char *text = SvPVutf8 (text_, textlen); 1293 char *text = SvPVutf8 (text_, textlen);
1079 1294
1080 pango_layout_set_text (self->pl, text, textlen); 1295 pango_layout_set_text (self->pl, text, textlen);
1081} 1296}
1082 1297
1083void 1298void
1084set_markup (CFPlus::Layout self, SV *text_) 1299set_markup (DC::Layout self, SV *text_)
1085 CODE: 1300 CODE:
1086{ 1301{
1087 STRLEN textlen; 1302 STRLEN textlen;
1088 char *text = SvPVutf8 (text_, textlen); 1303 char *text = SvPVutf8 (text_, textlen);
1089 1304
1090 pango_layout_set_markup (self->pl, text, textlen); 1305 pango_layout_set_markup (self->pl, text, textlen);
1091} 1306}
1092 1307
1093void 1308void
1094set_shapes (CFPlus::Layout self, ...) 1309set_shapes (DC::Layout self, ...)
1095 CODE: 1310 CODE:
1096{ 1311{
1097 PangoAttrList *attrs = 0; 1312 PangoAttrList *attrs = 0;
1098 const char *text = pango_layout_get_text (self->pl); 1313 const char *text = pango_layout_get_text (self->pl);
1099 const char *pos = text; 1314 const char *pos = text;
1134 if (attrs) 1349 if (attrs)
1135 pango_layout_set_attributes (self->pl, attrs); 1350 pango_layout_set_attributes (self->pl, attrs);
1136} 1351}
1137 1352
1138void 1353void
1139get_shapes (CFPlus::Layout self) 1354get_shapes (DC::Layout self)
1140 PPCODE: 1355 PPCODE:
1141{ 1356{
1142 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 1357 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
1143 1358
1144 do 1359 do
1145 { 1360 {
1146 PangoLayoutRun *run = pango_layout_iter_get_run (iter); 1361 PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter);
1147 1362
1148 if (run && shape_attr_p (run)) 1363 if (run && shape_attr_p (run))
1149 { 1364 {
1150 PangoRectangle extents; 1365 PangoRectangle extents;
1151 pango_layout_iter_get_run_extents (iter, 0, &extents); 1366 pango_layout_iter_get_run_extents (iter, 0, &extents);
1159 1374
1160 pango_layout_iter_free (iter); 1375 pango_layout_iter_free (iter);
1161} 1376}
1162 1377
1163int 1378int
1164has_wrapped (CFPlus::Layout self) 1379has_wrapped (DC::Layout self)
1165 CODE: 1380 CODE:
1166{ 1381{
1167 int lines = 1; 1382 int lines = 1;
1168 const char *text = pango_layout_get_text (self->pl); 1383 const char *text = pango_layout_get_text (self->pl);
1169 1384
1174} 1389}
1175 OUTPUT: 1390 OUTPUT:
1176 RETVAL 1391 RETVAL
1177 1392
1178SV * 1393SV *
1179get_text (CFPlus::Layout self) 1394get_text (DC::Layout self)
1180 CODE: 1395 CODE:
1181 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 1396 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
1182 sv_utf8_decode (RETVAL); 1397 sv_utf8_decode (RETVAL);
1183 OUTPUT: 1398 OUTPUT:
1184 RETVAL 1399 RETVAL
1185 1400
1186void 1401void
1187set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) 1402set_foreground (DC::Layout self, float r, float g, float b, float a = 1.)
1188 CODE: 1403 CODE:
1189 self->r = r; 1404 self->r = r;
1190 self->g = g; 1405 self->g = g;
1191 self->b = b; 1406 self->b = b;
1192 self->a = a; 1407 self->a = a;
1193 1408
1194void 1409void
1195set_font (CFPlus::Layout self, CFPlus::Font font = 0) 1410set_font (DC::Layout self, DC::Font font = 0)
1196 CODE: 1411 CODE:
1197 if (self->font != font) 1412 if (self->font != font)
1198 { 1413 {
1199 self->font = font; 1414 self->font = font;
1200 layout_update_font (self); 1415 layout_update_font (self);
1201 } 1416 }
1202 1417
1203void 1418void
1204set_height (CFPlus::Layout self, int base_height) 1419set_height (DC::Layout self, int base_height)
1205 CODE: 1420 CODE:
1206 if (self->base_height != base_height) 1421 if (self->base_height != base_height)
1207 { 1422 {
1208 self->base_height = base_height; 1423 self->base_height = base_height;
1209 layout_update_font (self); 1424 layout_update_font (self);
1210 } 1425 }
1211 1426
1212void 1427void
1213set_width (CFPlus::Layout self, int max_width = -1) 1428set_width (DC::Layout self, int max_width = -1)
1214 CODE: 1429 CODE:
1215 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 1430 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
1216 1431
1217void 1432void
1218set_indent (CFPlus::Layout self, int indent) 1433set_indent (DC::Layout self, int indent)
1219 CODE: 1434 CODE:
1220 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 1435 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
1221 1436
1222void 1437void
1223set_spacing (CFPlus::Layout self, int spacing) 1438set_spacing (DC::Layout self, int spacing)
1224 CODE: 1439 CODE:
1225 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 1440 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
1226 1441
1227void 1442void
1228set_ellipsise (CFPlus::Layout self, int ellipsise) 1443set_ellipsise (DC::Layout self, int ellipsise)
1229 CODE: 1444 CODE:
1230 pango_layout_set_ellipsize (self->pl, 1445 pango_layout_set_ellipsize (self->pl,
1231 ellipsise == 1 ? PANGO_ELLIPSIZE_START 1446 ellipsise == 1 ? PANGO_ELLIPSIZE_START
1232 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 1447 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
1233 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 1448 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
1234 : PANGO_ELLIPSIZE_NONE 1449 : PANGO_ELLIPSIZE_NONE
1235 ); 1450 );
1236 1451
1237void 1452void
1238set_single_paragraph_mode (CFPlus::Layout self, int spm) 1453set_single_paragraph_mode (DC::Layout self, int spm)
1239 CODE: 1454 CODE:
1240 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 1455 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
1241 1456
1242void 1457void
1243size (CFPlus::Layout self) 1458size (DC::Layout self)
1244 PPCODE: 1459 PPCODE:
1245{ 1460{
1246 int w, h; 1461 int w, h;
1247 1462
1248 layout_get_pixel_size (self, &w, &h); 1463 layout_get_pixel_size (self, &w, &h);
1251 PUSHs (sv_2mortal (newSViv (w))); 1466 PUSHs (sv_2mortal (newSViv (w)));
1252 PUSHs (sv_2mortal (newSViv (h))); 1467 PUSHs (sv_2mortal (newSViv (h)));
1253} 1468}
1254 1469
1255int 1470int
1256descent (CFPlus::Layout self) 1471descent (DC::Layout self)
1257 CODE: 1472 CODE:
1258{ 1473{
1259 PangoRectangle rect; 1474 PangoRectangle rect;
1260 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1475 PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0);
1261 pango_layout_line_get_pixel_extents (line, 0, &rect); 1476 pango_layout_line_get_pixel_extents (line, 0, &rect);
1262 RETVAL = PANGO_DESCENT (rect); 1477 RETVAL = PANGO_DESCENT (rect);
1263} 1478}
1264 OUTPUT: 1479 OUTPUT:
1265 RETVAL 1480 RETVAL
1266 1481
1267int 1482int
1268xy_to_index (CFPlus::Layout self, int x, int y) 1483xy_to_index (DC::Layout self, int x, int y)
1269 CODE: 1484 CODE:
1270{ 1485{
1271 int index, trailing; 1486 int index, trailing;
1272 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1487 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1273 RETVAL = index + trailing; 1488 RETVAL = index + trailing;
1274} 1489}
1275 OUTPUT: 1490 OUTPUT:
1276 RETVAL 1491 RETVAL
1277 1492
1278void 1493void
1279cursor_pos (CFPlus::Layout self, int index) 1494cursor_pos (DC::Layout self, int index)
1280 PPCODE: 1495 PPCODE:
1281{ 1496{
1282 PangoRectangle strong_pos; 1497 PangoRectangle pos;
1283 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1498 pango_layout_get_cursor_pos (self->pl, index, &pos, 0);
1284 1499
1285 EXTEND (SP, 3); 1500 EXTEND (SP, 3);
1286 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1501 PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE)));
1287 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1502 PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE)));
1288 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1503 PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE)));
1289} 1504}
1290 1505
1291void 1506void
1292index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) 1507index_to_line_x (DC::Layout self, int index, int trailing = 0)
1293 PPCODE: 1508 PPCODE:
1294{ 1509{
1295 int line, x; 1510 int line, x;
1296 1511
1297 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); 1512 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1513#if !PANGO_VERSION_CHECK (1, 17, 3)
1298 /* pango bug: line is between 1..numlines, not 0..numlines-1 */ 1514 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1299 1515 --line;
1516#endif
1300 EXTEND (SP, 2); 1517 EXTEND (SP, 2);
1301 PUSHs (sv_2mortal (newSViv (line - 1))); 1518 PUSHs (sv_2mortal (newSViv (line)));
1302 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); 1519 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1303} 1520}
1304 1521
1305void 1522void
1306line_x_to_index (CFPlus::Layout self, int line, int x) 1523line_x_to_index (DC::Layout self, int line, int x)
1307 PPCODE: 1524 PPCODE:
1308{ 1525{
1309 PangoLayoutLine *lp; 1526 PangoLayoutLine *lp;
1310 int index, trailing; 1527 int index, trailing;
1311 1528
1312 if (line < 0) 1529 if (line < 0)
1313 XSRETURN_EMPTY; 1530 XSRETURN_EMPTY;
1314 1531
1315 if (!(lp = pango_layout_get_line (self->pl, line))) 1532 if (!(lp = pango_layout_get_line_readonly (self->pl, line)))
1316 XSRETURN_EMPTY; /* do better */ 1533 XSRETURN_EMPTY; /* do better */
1317 1534
1318 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); 1535 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1319 1536
1320 EXTEND (SP, 2); 1537 EXTEND (SP, 2);
1326 PUSHs (sv_2mortal (newSViv (trailing))); 1543 PUSHs (sv_2mortal (newSViv (trailing)));
1327 } 1544 }
1328} 1545}
1329 1546
1330void 1547void
1331render (CFPlus::Layout self, float x, float y, int flags = 0) 1548render (DC::Layout self, float x, float y, int flags = 0)
1332 CODE: 1549 CODE:
1333 rc_clear (self->rc); 1550 rc_clear (self->rc);
1334 pango_opengl_render_layout_subpixel ( 1551 pango_opengl_render_layout_subpixel (
1335 self->pl, 1552 self->pl,
1336 self->rc, 1553 self->rc,
1341 // we assume that context_change actually clears/frees stuff 1558 // we assume that context_change actually clears/frees stuff
1342 // and does not do any recomputation... 1559 // and does not do any recomputation...
1343 pango_layout_context_changed (self->pl); 1560 pango_layout_context_changed (self->pl);
1344 1561
1345void 1562void
1346draw (CFPlus::Layout self) 1563draw (DC::Layout self)
1347 CODE: 1564 CODE:
1348{ 1565{
1349 glEnable (GL_TEXTURE_2D); 1566 glEnable (GL_TEXTURE_2D);
1350 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 1567 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1351 glEnable (GL_BLEND); 1568 glEnable (GL_BLEND);
1359 glDisable (GL_ALPHA_TEST); 1576 glDisable (GL_ALPHA_TEST);
1360 glDisable (GL_BLEND); 1577 glDisable (GL_BLEND);
1361 glDisable (GL_TEXTURE_2D); 1578 glDisable (GL_TEXTURE_2D);
1362} 1579}
1363 1580
1364MODULE = CFPlus PACKAGE = CFPlus::Texture 1581MODULE = Deliantra::Client PACKAGE = DC::Texture
1365 1582
1366PROTOTYPES: ENABLE 1583PROTOTYPES: ENABLE
1367 1584
1368void 1585void
1369pad (SV *data_, int ow, int oh, int nw, int nh) 1586pad (SV *data_, int ow, int oh, int nw, int nh)
1448 RETVAL = width > 0; 1665 RETVAL = width > 0;
1449} 1666}
1450 OUTPUT: 1667 OUTPUT:
1451 RETVAL 1668 RETVAL
1452 1669
1453MODULE = CFPlus PACKAGE = CFPlus::Map 1670MODULE = Deliantra::Client PACKAGE = DC::Map
1454 1671
1455PROTOTYPES: DISABLE 1672PROTOTYPES: DISABLE
1456 1673
1457CFPlus::Map 1674DC::Map
1458new (SV *class) 1675new (SV *class)
1459 CODE: 1676 CODE:
1460 New (0, RETVAL, 1, struct map); 1677 New (0, RETVAL, 1, struct map);
1461 RETVAL->x = 0; 1678 RETVAL->x = 0;
1462 RETVAL->y = 0; 1679 RETVAL->y = 0;
1470 RETVAL->row = 0; 1687 RETVAL->row = 0;
1471 OUTPUT: 1688 OUTPUT:
1472 RETVAL 1689 RETVAL
1473 1690
1474void 1691void
1475DESTROY (CFPlus::Map self) 1692DESTROY (DC::Map self)
1476 CODE: 1693 CODE:
1477{ 1694{
1478 map_clear (self); 1695 map_clear (self);
1479 Safefree (self->face2tile); 1696 Safefree (self->face2tile);
1480 Safefree (self->tex); 1697 Safefree (self->tex);
1481 Safefree (self); 1698 Safefree (self);
1482} 1699}
1483 1700
1484void 1701void
1485resize (CFPlus::Map self, int map_width, int map_height) 1702resize (DC::Map self, int map_width, int map_height)
1486 CODE: 1703 CODE:
1487 self->w = map_width; 1704 self->w = map_width;
1488 self->h = map_height; 1705 self->h = map_height;
1489 1706
1490void 1707void
1491clear (CFPlus::Map self) 1708clear (DC::Map self)
1492 CODE: 1709 CODE:
1493 map_clear (self); 1710 map_clear (self);
1494 1711
1495void 1712void
1496set_tileid (CFPlus::Map self, int face, int tile) 1713set_tileid (DC::Map self, int face, int tile)
1497 CODE: 1714 CODE:
1498{ 1715{
1499 need_facenum (self, face); self->face2tile [face] = tile; 1716 need_facenum (self, face); self->face2tile [face] = tile;
1500 need_texid (self, tile); 1717 need_texid (self, tile);
1501} 1718}
1502 1719
1503void 1720void
1504set_smooth (CFPlus::Map self, int face, int smooth, int level) 1721set_smooth (DC::Map self, int face, int smooth, int level)
1505 CODE: 1722 CODE:
1506{ 1723{
1507 tileid texid; 1724 tileid texid;
1508 maptex *tex; 1725 maptex *tex;
1509 1726
1522 tex->smoothtile = self->face2tile [smooth]; 1739 tex->smoothtile = self->face2tile [smooth];
1523 tex->smoothlevel = level; 1740 tex->smoothlevel = level;
1524} 1741}
1525 1742
1526void 1743void
1527set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1744set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1528 CODE: 1745 CODE:
1529{ 1746{
1530 need_texid (self, texid); 1747 need_texid (self, texid);
1531 1748
1532 { 1749 {
1551 // use uglier nearest interpolation because linear suffers 1768 // use uglier nearest interpolation because linear suffers
1552 // from transparent color bleeding and ugly wrapping effects. 1769 // from transparent color bleeding and ugly wrapping effects.
1553 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1770 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1554} 1771}
1555 1772
1773void
1774expire_textures (DC::Map self, int texid, int count)
1775 PPCODE:
1776 for (; texid < self->texs && count; ++texid, --count)
1777 {
1778 maptex *tex = self->tex + texid;
1779
1780 if (tex->name)
1781 {
1782 if (tex->unused)
1783 {
1784 tex->name = 0;
1785 tex->unused = 0;
1786 XPUSHs (sv_2mortal (newSViv (texid)));
1787 }
1788 else
1789 tex->unused = 1;
1790 }
1791 }
1792
1556int 1793int
1557ox (CFPlus::Map self) 1794ox (DC::Map self)
1558 ALIAS: 1795 ALIAS:
1559 oy = 1 1796 oy = 1
1560 x = 2 1797 x = 2
1561 y = 3 1798 y = 3
1562 w = 4 1799 w = 4
1573 } 1810 }
1574 OUTPUT: 1811 OUTPUT:
1575 RETVAL 1812 RETVAL
1576 1813
1577void 1814void
1578scroll (CFPlus::Map self, int dx, int dy) 1815scroll (DC::Map self, int dx, int dy)
1579 CODE: 1816 CODE:
1580{ 1817{
1581 if (dx > 0) 1818 if (dx > 0)
1582 map_blank (self, self->x, self->y, dx, self->h); 1819 map_blank (self, self->x, self->y, dx, self->h);
1583 else if (dx < 0) 1820 else if (dx < 0)
1599 self->y += MAP_EXTEND_Y; 1836 self->y += MAP_EXTEND_Y;
1600 } 1837 }
1601} 1838}
1602 1839
1603SV * 1840SV *
1604map1a_update (CFPlus::Map self, SV *data_, int extmap) 1841map1a_update (DC::Map self, SV *data_, int extmap)
1605 CODE: 1842 CODE:
1606{ 1843{
1607 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1844 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1608 uint8_t *data_end = (uint8_t *)SvEND (data_); 1845 uint8_t *data_end = (uint8_t *)SvEND (data_);
1609 mapcell *cell; 1846 mapcell *cell;
1637 uint8_t ext, cmd; 1874 uint8_t ext, cmd;
1638 1875
1639 do 1876 do
1640 { 1877 {
1641 ext = *data++; 1878 ext = *data++;
1642 cmd = ext & 0x3f; 1879 cmd = ext & 0x7f;
1643 1880
1644 if (cmd < 4) 1881 if (cmd < 4)
1645 cell->darkness = 255 - ext * 64 + 1; 1882 cell->darkness = 255 - ext * 64 + 1;
1646 else if (cmd == 5) // health 1883 else if (cmd == 5) // health
1647 { 1884 {
1650 } 1887 }
1651 else if (cmd == 6) // monster width 1888 else if (cmd == 6) // monster width
1652 cell->stat_width = *data++ + 1; 1889 cell->stat_width = *data++ + 1;
1653 else if (cmd == 0x47) 1890 else if (cmd == 0x47)
1654 { 1891 {
1655 if (*data == 4) 1892 if (*data == 1) cell->player = data [1];
1656 ; // decode player count 1893 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
1894 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
1895 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
1657 1896
1658 data += *data + 1; 1897 data += *data + 1;
1659 } 1898 }
1660 else if (cmd == 8) // cell flags 1899 else if (cmd == 8) // cell flags
1661 cell->flags = *data++; 1900 cell->flags = *data++;
1678 cell->tile [z] = self->face2tile [face]; 1917 cell->tile [z] = self->face2tile [face];
1679 1918
1680 if (cell->tile [z]) 1919 if (cell->tile [z])
1681 { 1920 {
1682 maptex *tex = self->tex + cell->tile [z]; 1921 maptex *tex = self->tex + cell->tile [z];
1922 tex->unused = 0;
1683 if (!tex->name) 1923 if (!tex->name)
1684 av_push (missing, newSViv (cell->tile [z])); 1924 av_push (missing, newSViv (cell->tile [z]));
1685 1925
1686 if (tex->smoothtile) 1926 if (tex->smoothtile)
1687 { 1927 {
1688 maptex *smooth = self->tex + tex->smoothtile; 1928 maptex *smooth = self->tex + tex->smoothtile;
1929 smooth->unused = 0;
1689 if (!smooth->name) 1930 if (!smooth->name)
1690 av_push (missing, newSViv (tex->smoothtile)); 1931 av_push (missing, newSViv (tex->smoothtile));
1691 } 1932 }
1692 } 1933 }
1693 } 1934 }
1694 } 1935 }
1695 else 1936 else
1696 cell->darkness = 0; 1937 CELL_CLEAR (cell);
1697 } 1938 }
1698} 1939}
1699 OUTPUT: 1940 OUTPUT:
1700 RETVAL 1941 RETVAL
1701 1942
1702SV * 1943SV *
1703mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1944mapmap (DC::Map self, int x0, int y0, int w, int h)
1704 CODE: 1945 CODE:
1705{ 1946{
1706 int x1, x; 1947 int x1, x;
1707 int y1, y; 1948 int y1, y;
1708 int z; 1949 int z;
1753} 1994}
1754 OUTPUT: 1995 OUTPUT:
1755 RETVAL 1996 RETVAL
1756 1997
1757void 1998void
1758draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1999draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1759 CODE: 2000 CODE:
1760{ 2001{
1761 int x, y, z; 2002 int x, y, z;
1762 2003
1763 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 2004 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1764 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2005 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1765 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2006 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1766 smooth_key skey; 2007 smooth_key skey;
1767 2008 int pl_x, pl_y;
2009 maptex pl_tex;
1768 rc_t *rc = rc_alloc (); 2010 rc_t *rc = rc_alloc ();
1769 rc_key_t key; 2011 rc_key_t key;
1770 rc_array_t *arr; 2012 rc_array_t *arr;
2013
2014 pl_tex.name = 0;
1771 2015
1772 // thats current max. sorry. 2016 // thats current max. sorry.
1773 if (sw > 255) sw = 255; 2017 if (sw > 255) sw = 255;
1774 if (sh > 255) sh = 255; 2018 if (sh > 255) sh = 255;
1775 2019
1781 key.g = 255; 2025 key.g = 255;
1782 key.b = 255; 2026 key.b = 255;
1783 key.a = 255; 2027 key.a = 255;
1784 key.mode = GL_QUADS; 2028 key.mode = GL_QUADS;
1785 key.format = GL_T2F_V3F; 2029 key.format = GL_T2F_V3F;
1786 key.texname = -1;
1787 2030
1788 mx += self->x; 2031 mx += self->x;
1789 my += self->y; 2032 my += self->y;
1790 2033
1791 // first pass: determine smooth_max 2034 // first pass: determine smooth_max
1815 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2058 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1816 2059
1817 for (z = 0; z <= 2; z++) 2060 for (z = 0; z <= 2; z++)
1818 { 2061 {
1819 memset (smooth_level, 0, sizeof (smooth_level)); 2062 memset (smooth_level, 0, sizeof (smooth_level));
2063 key.texname = -1;
1820 2064
1821 for (y = 0; y < sh; y++) 2065 for (y = 0; y < sh; y++)
1822 if (0 <= y + my && y + my < self->rows) 2066 if (0 <= y + my && y + my < self->rows)
1823 { 2067 {
1824 maprow *row = self->row + (y + my); 2068 maprow *row = self->row + (y + my);
1830 tileid tile = cell->tile [z]; 2074 tileid tile = cell->tile [z];
1831 2075
1832 if (tile) 2076 if (tile)
1833 { 2077 {
1834 maptex tex = self->tex [tile]; 2078 maptex tex = self->tex [tile];
1835 int px, py; 2079 int px = (x + 1) * T - tex.w;
2080 int py = (y + 1) * T - tex.h;
1836 2081
1837 if (key.texname != tex.name) 2082 if (key.texname != tex.name)
1838 { 2083 {
2084 self->tex [tile].unused = 0;
2085
1839 if (!tex.name) 2086 if (!tex.name)
1840 tex = self->tex [2]; /* missing, replace by noface */ 2087 tex = self->tex [2]; /* missing, replace by noface */
1841 2088
1842 key.texname = tex.name; 2089 key.texname = tex.name;
1843 arr = rc_array (rc, &key); 2090 arr = rc_array (rc, &key);
1844 } 2091 }
1845 2092
1846 px = (x + 1) * T - tex.w; 2093 if (expect_false (cell->player == player) && expect_false (z == 2))
1847 py = (y + 1) * T - tex.h; 2094 {
2095 pl_x = px;
2096 pl_y = py;
2097 pl_tex = tex;
2098 continue;
2099 }
1848 2100
1849 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2101 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1850 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2102 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1851 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2103 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1852 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2104 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1853 2105
1854 if (cell->flags && z == 2) 2106 if (expect_false (cell->flags) && expect_false (z == 2))
1855 { 2107 {
2108 /* this is a workaround to make speech bubbles drawn
2109 * for example above walls, work. */
2110 rc_draw (rc);
2111 rc_clear (rc);
2112 key.texname = -1;
2113
1856 // overlays such as the speech bubble, probably more to come 2114 // overlays such as the speech bubble, probably more to come
1857 if (cell->flags & 1) 2115 if (cell->flags & 1)
1858 { 2116 {
1859 maptex tex = self->tex [1]; 2117 maptex tex = self->tex [1];
1860 int px = x * T + T * 2 / 32; 2118 int px = x * T + T * 2 / 32;
1960 { 2218 {
1961 // this time avoiding texture state changes 2219 // this time avoiding texture state changes
1962 // save gobs of state changes. 2220 // save gobs of state changes.
1963 if (key.texname != tex.name) 2221 if (key.texname != tex.name)
1964 { 2222 {
2223 self->tex [skey->tile].unused = 0;
2224
1965 glEnd (); 2225 glEnd ();
1966 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2226 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1967 glBegin (GL_QUADS); 2227 glBegin (GL_QUADS);
1968 } 2228 }
1969 2229
1998 } 2258 }
1999 2259
2000 hv_clear (smooth); 2260 hv_clear (smooth);
2001 } 2261 }
2002 2262
2263 if (pl_tex.name)
2264 {
2265 maptex tex = pl_tex;
2266 int px = pl_x + sdx;
2267 int py = pl_y + sdy;
2268
2269 key.texname = tex.name;
2270 arr = rc_array (rc, &key);
2271
2272 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2273 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2274 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2275 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2276
2277 rc_draw (rc);
2278 }
2279
2003 glDisable (GL_BLEND); 2280 glDisable (GL_BLEND);
2004 rc_free (rc); 2281 rc_free (rc);
2005 2282
2006 // top layer: overlays such as the health bar 2283 // top layer: overlays such as the health bar
2007 for (y = 0; y < sh; y++) 2284 for (y = 0; y < sh; y++)
2014 { 2291 {
2015 mapcell *cell = row->col + (x + mx - row->c0); 2292 mapcell *cell = row->col + (x + mx - row->c0);
2016 2293
2017 int px = x * T; 2294 int px = x * T;
2018 int py = y * T; 2295 int py = y * T;
2296
2297 if (expect_false (cell->player == player))
2298 {
2299 px += sdx;
2300 py += sdy;
2301 }
2019 2302
2020 if (cell->stat_hp) 2303 if (cell->stat_hp)
2021 { 2304 {
2022 int width = cell->stat_width * T; 2305 int width = cell->stat_width * T;
2023 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; 2306 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width;
2034 } 2317 }
2035 } 2318 }
2036} 2319}
2037 2320
2038void 2321void
2039draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 2322draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data)
2040 CODE: 2323 CODE:
2041{ 2324{
2042 static float color[16][3] = { 2325 static float color[16][3] = {
2043 { 0.00F, 0.00F, 0.00F }, 2326 { 0.00F, 0.00F, 0.00F },
2044 { 1.00F, 1.00F, 1.00F }, 2327 { 1.00F, 1.00F, 1.00F },
2094 glDisable (GL_BLEND); 2377 glDisable (GL_BLEND);
2095 glDisable (GL_TEXTURE_2D); 2378 glDisable (GL_TEXTURE_2D);
2096} 2379}
2097 2380
2098void 2381void
2099fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) 2382fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2100 PPCODE: 2383 PPCODE:
2101{ 2384{
2102 int x, y; 2385 int x, y;
2103 int sw1 = sw + 2; 2386 int sw1 = sw + 2;
2104 int sh1 = sh + 2; 2387 int sh1 = sh + 2;
2112 SvCUR_set (darkness3_sv, sw34 * sh3); 2395 SvCUR_set (darkness3_sv, sw34 * sh3);
2113 2396
2114 mx += self->x - 1; 2397 mx += self->x - 1;
2115 my += self->y - 1; 2398 my += self->y - 1;
2116 2399
2117 memset (darkness1, 255, sw1 * sh1); 2400 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2118 2401
2119 for (y = 0; y < sh1; y++) 2402 for (y = 0; y < sh1; y++)
2120 if (0 <= y + my && y + my < self->rows) 2403 if (0 <= y + my && y + my < self->rows)
2121 { 2404 {
2122 maprow *row = self->row + (y + my); 2405 maprow *row = self->row + (y + my);
2175 PUSHs (sv_2mortal (newSViv (sh3))); 2458 PUSHs (sv_2mortal (newSViv (sh3)));
2176 PUSHs (darkness3_sv); 2459 PUSHs (darkness3_sv);
2177} 2460}
2178 2461
2179SV * 2462SV *
2180get_rect (CFPlus::Map self, int x0, int y0, int w, int h) 2463get_rect (DC::Map self, int x0, int y0, int w, int h)
2181 CODE: 2464 CODE:
2182{ 2465{
2183 int x, y, x1, y1; 2466 int x, y, x1, y1;
2184 SV *data_sv = newSV (w * h * 7 + 5); 2467 SV *data_sv = newSV (w * h * 7 + 5);
2185 uint8_t *data = (uint8_t *)SvPVX (data_sv); 2468 uint8_t *data = (uint8_t *)SvPVX (data_sv);
2242 else 2525 else
2243 *data++ = 0; 2526 *data++ = 0;
2244 } 2527 }
2245 } 2528 }
2246 2529
2530 /* if size is w*h + 5 then no data has been found */
2531 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2532 {
2247 SvPOK_only (data_sv); 2533 SvPOK_only (data_sv);
2248 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2534 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2535 }
2536
2249 RETVAL = data_sv; 2537 RETVAL = data_sv;
2250} 2538}
2251 OUTPUT: 2539 OUTPUT:
2252 RETVAL 2540 RETVAL
2253 2541
2254void 2542void
2255set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) 2543set_rect (DC::Map self, int x0, int y0, SV *data_sv)
2256 PPCODE: 2544 PPCODE:
2257{ 2545{
2258 int x, y, z; 2546 int x, y, z;
2259 int w, h; 2547 int w, h;
2260 int x1, y1; 2548 int x1, y1;
2549 STRLEN len;
2550 uint8_t *data, *end;
2551
2552 len = SvLEN (data_sv);
2553 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2554 data = SvPVbyte_nolen (data_sv);
2555 end = data + len + 8;
2556
2557 if (len < 5)
2558 XSRETURN_EMPTY;
2261 2559
2262 if (*data++ != 0) 2560 if (*data++ != 0)
2263 XSRETURN_EMPTY; /* version mismatch */ 2561 XSRETURN_EMPTY; /* version mismatch */
2264 2562
2265 w = *data++ << 8; w |= *data++; 2563 w = *data++ << 8; w |= *data++;
2280 { 2578 {
2281 maprow *row = map_get_row (self, y); 2579 maprow *row = map_get_row (self, y);
2282 2580
2283 for (x = x0; x < x1; x++) 2581 for (x = x0; x < x1; x++)
2284 { 2582 {
2583 uint8_t flags;
2584
2585 if (data + 7 >= end)
2586 XSRETURN_EMPTY;
2587
2285 uint8_t flags = *data++; 2588 flags = *data++;
2286 2589
2287 if (flags) 2590 if (flags)
2288 { 2591 {
2289 mapcell *cell = row_get_cell (row, x); 2592 mapcell *cell = row_get_cell (row, x);
2290 tileid tile[3] = { 0, 0, 0 }; 2593 tileid tile[3] = { 0, 0, 0 };
2293 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } 2596 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
2294 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } 2597 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
2295 2598
2296 if (cell->darkness == 0) 2599 if (cell->darkness == 0)
2297 { 2600 {
2298 cell->darkness = 0; 2601 /*cell->darkness = 0;*/
2602 EXTEND (SP, 3);
2299 2603
2300 for (z = 0; z <= 2; z++) 2604 for (z = 0; z <= 2; z++)
2301 { 2605 {
2302 tileid t = tile [z]; 2606 tileid t = tile [z];
2303 2607
2304 if (t >= self->texs || (t && !self->tex [t].name)) 2608 if (t >= self->texs || (t && !self->tex [t].name))
2305 { 2609 {
2306 XPUSHs (sv_2mortal (newSViv (t))); 2610 PUSHs (sv_2mortal (newSViv (t)));
2307 need_texid (self, t); 2611 need_texid (self, t);
2308 } 2612 }
2309 2613
2310 cell->tile [z] = t; 2614 cell->tile [z] = t;
2311 } 2615 }
2313 } 2617 }
2314 } 2618 }
2315 } 2619 }
2316} 2620}
2317 2621
2318MODULE = CFPlus PACKAGE = CFPlus::RW 2622MODULE = Deliantra::Client PACKAGE = DC::RW
2319 2623
2320CFPlus::RW 2624DC::RW
2321new (SV *class, SV *data_sv) 2625new (SV *class, SV *data_sv)
2322 CODE: 2626 CODE:
2323{ 2627{
2324 STRLEN datalen; 2628 STRLEN datalen;
2325 char *data = SvPVbyte (data_sv, datalen); 2629 char *data = SvPVbyte (data_sv, datalen);
2327 RETVAL = SDL_RWFromConstMem (data, datalen); 2631 RETVAL = SDL_RWFromConstMem (data, datalen);
2328} 2632}
2329 OUTPUT: 2633 OUTPUT:
2330 RETVAL 2634 RETVAL
2331 2635
2332CFPlus::RW 2636DC::RW
2333new_from_file (SV *class, const char *path, const char *mode = "rb") 2637new_from_file (SV *class, const char *path, const char *mode = "rb")
2334 CODE: 2638 CODE:
2335 RETVAL = SDL_RWFromFile (path, mode); 2639 RETVAL = SDL_RWFromFile (path, mode);
2336 OUTPUT: 2640 OUTPUT:
2337 RETVAL 2641 RETVAL
2338 2642
2339# fails on win32: 2643# fails on win32:
2340# CFPlus.xs(2268) : error C2059: syntax error : '(' 2644# dc.xs(2268) : error C2059: syntax error : '('
2341#void 2645#void
2342#close (CFPlus::RW self) 2646#close (DC::RW self)
2343# CODE: 2647# CODE:
2344# (self->(close)) (self); 2648# (self->(close)) (self);
2345 2649
2346MODULE = CFPlus PACKAGE = CFPlus::Channel 2650MODULE = Deliantra::Client PACKAGE = DC::Channel
2347 2651
2348PROTOTYPES: DISABLE 2652PROTOTYPES: DISABLE
2349 2653
2350CFPlus::Channel 2654DC::Channel
2351find () 2655find ()
2352 CODE: 2656 CODE:
2353{ 2657{
2354 RETVAL = Mix_GroupAvailable (-1); 2658 RETVAL = Mix_GroupAvailable (-1);
2355 2659
2368} 2672}
2369 OUTPUT: 2673 OUTPUT:
2370 RETVAL 2674 RETVAL
2371 2675
2372void 2676void
2373halt (CFPlus::Channel self) 2677halt (DC::Channel self)
2374 CODE: 2678 CODE:
2375 Mix_HaltChannel (self); 2679 Mix_HaltChannel (self);
2376 2680
2377void 2681void
2378expire (CFPlus::Channel self, int ticks = -1) 2682expire (DC::Channel self, int ticks = -1)
2379 CODE: 2683 CODE:
2380 Mix_ExpireChannel (self, ticks); 2684 Mix_ExpireChannel (self, ticks);
2381 2685
2382void 2686void
2383fade_out (CFPlus::Channel self, int ticks = -1) 2687fade_out (DC::Channel self, int ticks = -1)
2384 CODE: 2688 CODE:
2385 Mix_FadeOutChannel (self, ticks); 2689 Mix_FadeOutChannel (self, ticks);
2386 2690
2387int 2691int
2388volume (CFPlus::Channel self, int volume) 2692volume (DC::Channel self, int volume)
2389 CODE: 2693 CODE:
2390 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); 2694 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2391 OUTPUT: 2695 OUTPUT:
2392 RETVAL 2696 RETVAL
2393 2697
2394void 2698void
2395unregister_all_effects (CFPlus::Channel self) 2699unregister_all_effects (DC::Channel self)
2396 CODE: 2700 CODE:
2397 Mix_UnregisterAllEffects (self); 2701 Mix_UnregisterAllEffects (self);
2398 2702
2399void 2703void
2400set_panning (CFPlus::Channel self, int left, int right) 2704set_panning (DC::Channel self, int left, int right)
2401 CODE: 2705 CODE:
2402 left = CLAMP (left , 0, 255); 2706 left = CLAMP (left , 0, 255);
2403 right = CLAMP (right, 0, 255); 2707 right = CLAMP (right, 0, 255);
2404 Mix_SetPanning (self, left, right); 2708 Mix_SetPanning (self, left, right);
2405 2709
2406void 2710void
2407set_distance (CFPlus::Channel self, int distance) 2711set_distance (DC::Channel self, int distance)
2408 CODE: 2712 CODE:
2409 Mix_SetDistance (self, CLAMP (distance, 0, 255)); 2713 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2410 2714
2411void 2715void
2412set_position (CFPlus::Channel self, int angle, int distance) 2716set_position (DC::Channel self, int angle, int distance)
2413 CODE: 2717 CODE:
2414 2718
2415void 2719void
2416set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) 2720set_position_r (DC::Channel self, int dx, int dy, int maxdistance)
2417 CODE: 2721 CODE:
2418{ 2722{
2419 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); 2723 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2420 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); 2724 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI);
2421 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); 2725 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2422} 2726}
2423 2727
2424void 2728void
2425set_reverse_stereo (CFPlus::Channel self, int flip) 2729set_reverse_stereo (DC::Channel self, int flip)
2426 CODE: 2730 CODE:
2427 Mix_SetReverseStereo (self, flip); 2731 Mix_SetReverseStereo (self, flip);
2428 2732
2429MODULE = CFPlus PACKAGE = CFPlus::MixChunk 2733MODULE = Deliantra::Client PACKAGE = DC::MixChunk
2430 2734
2431PROTOTYPES: DISABLE 2735PROTOTYPES: DISABLE
2432 2736
2433CFPlus::MixChunk 2737DC::MixChunk
2434new (SV *class, CFPlus::RW rwops) 2738new (SV *class, DC::RW rwops)
2435 CODE: 2739 CODE:
2436 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2740 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2437 OUTPUT: 2741 OUTPUT:
2438 RETVAL 2742 RETVAL
2439 2743
2440void 2744void
2441DESTROY (CFPlus::MixChunk self) 2745DESTROY (DC::MixChunk self)
2442 CODE: 2746 CODE:
2443 Mix_FreeChunk (self); 2747 Mix_FreeChunk (self);
2444 2748
2445int 2749int
2446volume (CFPlus::MixChunk self, int volume = -1) 2750volume (DC::MixChunk self, int volume = -1)
2447 CODE: 2751 CODE:
2448 if (items > 1) 2752 if (items > 1)
2449 volume = CLAMP (volume, 0, 128); 2753 volume = CLAMP (volume, 0, 128);
2450 RETVAL = Mix_VolumeChunk (self, volume); 2754 RETVAL = Mix_VolumeChunk (self, volume);
2451 OUTPUT: 2755 OUTPUT:
2452 RETVAL 2756 RETVAL
2453 2757
2454CFPlus::Channel 2758DC::Channel
2455play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) 2759play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1)
2456 CODE: 2760 CODE:
2457{ 2761{
2458 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 2762 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
2459 2763
2460 if (RETVAL < 0) 2764 if (RETVAL < 0)
2467 } 2771 }
2468} 2772}
2469 OUTPUT: 2773 OUTPUT:
2470 RETVAL 2774 RETVAL
2471 2775
2472MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2776MODULE = Deliantra::Client PACKAGE = DC::MixMusic
2473 2777
2474int 2778int
2475volume (int volume = -1) 2779volume (int volume = -1)
2476 PROTOTYPE: ;$ 2780 PROTOTYPE: ;$
2477 CODE: 2781 CODE:
2489void 2793void
2490halt () 2794halt ()
2491 CODE: 2795 CODE:
2492 Mix_HaltMusic (); 2796 Mix_HaltMusic ();
2493 2797
2494CFPlus::MixMusic 2798DC::MixMusic
2495new (SV *class, CFPlus::RW rwops) 2799new (SV *class, DC::RW rwops)
2496 CODE: 2800 CODE:
2497 RETVAL = Mix_LoadMUS_RW (rwops); 2801 RETVAL = Mix_LoadMUS_RW (rwops);
2498 OUTPUT: 2802 OUTPUT:
2499 RETVAL 2803 RETVAL
2500 2804
2501void 2805void
2502DESTROY (CFPlus::MixMusic self) 2806DESTROY (DC::MixMusic self)
2503 CODE: 2807 CODE:
2504 Mix_FreeMusic (self); 2808 Mix_FreeMusic (self);
2505 2809
2506int 2810int
2507play (CFPlus::MixMusic self, int loops = -1) 2811play (DC::MixMusic self, int loops = -1)
2508 CODE: 2812 CODE:
2509 RETVAL = Mix_PlayMusic (self, loops); 2813 RETVAL = Mix_PlayMusic (self, loops);
2510 OUTPUT: 2814 OUTPUT:
2511 RETVAL 2815 RETVAL
2512 2816
2513void 2817void
2514fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) 2818fade_in_pos (DC::MixMusic self, int loops, int ms, double position)
2515 CODE: 2819 CODE:
2516 Mix_FadeInMusicPos (self, loops, ms, position); 2820 Mix_FadeInMusicPos (self, loops, ms, position);
2517 2821
2518MODULE = CFPlus PACKAGE = CFPlus::OpenGL 2822MODULE = Deliantra::Client PACKAGE = DC::OpenGL
2519 2823
2520PROTOTYPES: ENABLE 2824PROTOTYPES: ENABLE
2521 2825
2522BOOT: 2826BOOT:
2523{ 2827{
2524 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); 2828 HV *stash = gv_stashpv ("DC::OpenGL", 1);
2525 static const struct { 2829 static const struct {
2526 const char *name; 2830 const char *name;
2527 IV iv; 2831 IV iv;
2528 } *civ, const_iv[] = { 2832 } *civ, const_iv[] = {
2529# define const_iv(name) { # name, (IV)name } 2833# define const_iv(name) { # name, (IV)name }
2743void glRotate (float angle, float x, float y, float z) 3047void glRotate (float angle, float x, float y, float z)
2744 CODE: 3048 CODE:
2745 glRotatef (angle, x, y, z); 3049 glRotatef (angle, x, y, z);
2746 3050
2747void glColor (float r, float g, float b, float a = 1.0) 3051void glColor (float r, float g, float b, float a = 1.0)
3052 PROTOTYPE: @
2748 ALIAS: 3053 ALIAS:
2749 glColor_premultiply = 1 3054 glColor_premultiply = 1
2750 CODE: 3055 CODE:
2751 if (ix) 3056 if (ix)
2752 { 3057 {
2822void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) 3127void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column)
2823 CODE: 3128 CODE:
2824 if (gl.SeparableFilter2D) 3129 if (gl.SeparableFilter2D)
2825 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); 3130 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column);
2826 3131
2827void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) 3132void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0)
2828 3133
2829void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) 3134void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border)
2830 3135
2831void glDrawPixels (int width, int height, int format, int type, char *pixels) 3136void glDrawPixels (int width, int height, int format, int type, char *pixels)
2832 3137
2858 3163
2859void glEndList () 3164void glEndList ()
2860 3165
2861void glCallList (int list) 3166void glCallList (int list)
2862 3167
2863MODULE = CFPlus PACKAGE = CFPlus::UI::Base 3168MODULE = Deliantra::Client PACKAGE = DC::UI::Base
2864 3169
2865PROTOTYPES: DISABLE 3170PROTOTYPES: DISABLE
2866 3171
2867void 3172void
2868find_widget (SV *self, NV x, NV y) 3173find_widget (SV *self, NV x, NV y)
2872 XPUSHs (self); 3177 XPUSHs (self);
2873} 3178}
2874 3179
2875BOOT: 3180BOOT:
2876{ 3181{
2877 hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); 3182 hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV);
2878 3183
2879 draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); 3184 draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV);
2880 draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); 3185 draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV);
2881 draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); 3186 draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV);
2882 draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); 3187 draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV);
2883} 3188}
2884 3189
2885void 3190void
2886draw (SV *self) 3191draw (SV *self)
2887 CODE: 3192 CODE:
2894 SV *draw_w_sv = GvSV (draw_w_gv); 3199 SV *draw_w_sv = GvSV (draw_w_gv);
2895 SV *draw_h_sv = GvSV (draw_h_gv); 3200 SV *draw_h_sv = GvSV (draw_h_gv);
2896 double draw_x, draw_y; 3201 double draw_x, draw_y;
2897 3202
2898 if (!SvROK (self)) 3203 if (!SvROK (self))
2899 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 3204 croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self));
2900 3205
2901 hv = (HV *)SvRV (self); 3206 hv = (HV *)SvRV (self);
2902 3207
2903 if (SvTYPE (hv) != SVt_PVHV) 3208 if (SvTYPE (hv) != SVt_PVHV)
2904 croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); 3209 croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self));
2905 3210
2906 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; 3211 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.;
2907 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; 3212 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.;
2908 3213
2909 if (!h || !w) 3214 if (!h || !w)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines