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.225 by root, Sat Aug 11 12:07:54 2007 UTC vs.
Revision 1.272 by root, Tue Aug 19 17:38:29 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 32
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
71# define PARACHUTE 0
72#endif
73 95
74static AV *texture_av; 96static AV *texture_av;
75 97
76static struct 98static struct
77{ 99{
120 142
121#include "pango-font.c" 143#include "pango-font.c"
122#include "pango-fontmap.c" 144#include "pango-fontmap.c"
123#include "pango-render.c" 145#include "pango-render.c"
124 146
125typedef IV CFPlus__Channel; 147typedef IV DC__Channel;
126typedef SDL_RWops *CFPlus__RW; 148typedef SDL_RWops *DC__RW;
127typedef Mix_Chunk *CFPlus__MixChunk; 149typedef Mix_Chunk *DC__MixChunk;
128typedef Mix_Music *CFPlus__MixMusic; 150typedef Mix_Music *DC__MixMusic;
129 151
130typedef PangoFontDescription *CFPlus__Font; 152typedef PangoFontDescription *DC__Font;
131 153
132static int 154static int
133shape_attr_p (PangoLayoutRun *run) 155shape_attr_p (PangoLayoutRun *run)
134{ 156{
135 GSList *attrs = run->item->analysis.extra_attrs; 157 GSList *attrs = run->item->analysis.extra_attrs;
149 171
150typedef struct cf_layout { 172typedef struct cf_layout {
151 PangoLayout *pl; 173 PangoLayout *pl;
152 float r, g, b, a; // default color for rgba mode 174 float r, g, b, a; // default color for rgba mode
153 int base_height; 175 int base_height;
154 CFPlus__Font font; 176 DC__Font font;
155 rc_t *rc; 177 rc_t *rc;
156} *CFPlus__Layout; 178} *DC__Layout;
157 179
158static CFPlus__Font default_font; 180static DC__Font default_font;
159static PangoContext *opengl_context; 181static PangoContext *opengl_context;
160static PangoFontMap *opengl_fontmap; 182static PangoFontMap *opengl_fontmap;
161 183
162static void 184static void
163substitute_func (FcPattern *pattern, gpointer data) 185substitute_func (FcPattern *pattern, gpointer data)
168#endif 190#endif
169 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 191 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
170} 192}
171 193
172static void 194static void
173layout_update_font (CFPlus__Layout self) 195layout_update_font (DC__Layout self)
174{ 196{
175 /* use a random scale factor to account for unknown descenders, 0.8 works 197 /* use a random scale factor to account for unknown descenders, 0.8 works
176 * reasonably well with bitstream vera 198 * reasonably well with dejavu/bistream fonts
177 */ 199 */
178 PangoFontDescription *font = self->font ? self->font : default_font; 200 PangoFontDescription *font = self->font ? self->font : default_font;
179 201
180 pango_font_description_set_absolute_size (font, 202 pango_font_description_set_absolute_size (font,
181 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); 203 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
182 204
183 pango_layout_set_font_description (self->pl, font); 205 pango_layout_set_font_description (self->pl, font);
184} 206}
185 207
186static void 208static void
187layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 209layout_get_pixel_size (DC__Layout self, int *w, int *h)
188{ 210{
189 PangoRectangle rect; 211 PangoRectangle rect;
190 212
191 // get_pixel_* wrongly rounds down 213 // get_pixel_* wrongly rounds down
192 pango_layout_get_extents (self->pl, 0, &rect); 214 pango_layout_get_extents (self->pl, 0, &rect);
203 225
204typedef uint16_t tileid; 226typedef uint16_t tileid;
205typedef uint16_t faceid; 227typedef uint16_t faceid;
206 228
207typedef struct { 229typedef struct {
208 int name; 230 GLuint name;
209 int w, h; 231 int w, h;
210 float s, t; 232 float s, t;
211 uint8_t r, g, b, a; 233 uint8_t r, g, b, a;
212 tileid smoothtile; 234 tileid smoothtile;
213 uint8_t smoothlevel; 235 uint8_t smoothlevel;
231 int faces; tileid *face2tile; // [faceid] 253 int faces; tileid *face2tile; // [faceid]
232 int texs; maptex *tex; // [tileid] 254 int texs; maptex *tex; // [tileid]
233 255
234 int32_t rows; 256 int32_t rows;
235 maprow *row; 257 maprow *row;
236} *CFPlus__Map; 258} *DC__Map;
237 259
238static char * 260static char *
239prepend (char *ptr, int sze, int inc) 261prepend (char *ptr, int sze, int inc)
240{ 262{
241 char *p; 263 char *p;
279 self->texs *= 2; 301 self->texs *= 2;
280 } 302 }
281} 303}
282 304
283static maprow * 305static maprow *
284map_get_row (CFPlus__Map self, int y) 306map_get_row (DC__Map self, int y)
285{ 307{
286 if (0 > y) 308 if (0 > y)
287 { 309 {
288 int extend = - y + MAP_EXTEND_Y; 310 int extend = - y + MAP_EXTEND_Y;
289 Prepend (maprow, self->row, self->rows, extend); 311 Prepend (maprow, self->row, self->rows, extend);
327 349
328 return row->col + (x - row->c0); 350 return row->col + (x - row->c0);
329} 351}
330 352
331static mapcell * 353static mapcell *
332map_get_cell (CFPlus__Map self, int x, int y) 354map_get_cell (DC__Map self, int x, int y)
333{ 355{
334 return row_get_cell (map_get_row (self, y), x); 356 return row_get_cell (map_get_row (self, y), x);
335} 357}
336 358
337static void 359static void
338map_clear (CFPlus__Map self) 360map_clear (DC__Map self)
339{ 361{
340 int r; 362 int r;
341 363
342 for (r = 0; r < self->rows; r++) 364 for (r = 0; r < self->rows; r++)
343 Safefree (self->row[r].col); 365 Safefree (self->row[r].col);
350 self->oy = 0; 372 self->oy = 0;
351 self->row = 0; 373 self->row = 0;
352 self->rows = 0; 374 self->rows = 0;
353} 375}
354 376
377#define CELL_CLEAR(cell) \
378 do { \
379 if ((cell)->player) \
380 (cell)->tile [2] = 0; \
381 (cell)->darkness = 0; \
382 (cell)->stat_hp = 0; \
383 (cell)->flags = 0; \
384 (cell)->player = 0; \
385 } while (0)
386
355static void 387static void
356map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 388map_blank (DC__Map self, int x0, int y0, int w, int h)
357{ 389{
358 int x, y; 390 int x, y;
359 maprow *row; 391 maprow *row;
360 mapcell *cell; 392 mapcell *cell;
361 393
373 if (x >= row->c1) 405 if (x >= row->c1)
374 break; 406 break;
375 407
376 cell = row->col + x - row->c0; 408 cell = row->col + x - row->c0;
377 409
378 cell->darkness = 0; 410 CELL_CLEAR (cell);
379 cell->stat_hp = 0;
380 cell->flags = 0;
381 cell->player = 0;
382 } 411 }
383 } 412 }
384} 413}
385 414
386typedef struct { 415typedef struct {
440 n |= n >> 16; 469 n |= n >> 16;
441 470
442 return n + 1; 471 return n + 1;
443} 472}
444 473
474static unsigned int
475popcount (unsigned int n)
476{
477 n -= (n >> 1) & 0x55555555U;
478 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
479 n = ((n >> 4) + n) & 0x0f0f0f0fU;
480 n *= 0x01010101U;
481
482 return n >> 24;
483}
484
445/* SDL should provide this, really. */ 485/* SDL should provide this, really. */
446#define SDLK_MODIFIER_MIN 300 486#define SDLK_MODIFIER_MIN 300
447#define SDLK_MODIFIER_MAX 314 487#define SDLK_MODIFIER_MAX 314
448 488
449/******************************************************************************/ 489/******************************************************************************/
487 return 0; 527 return 0;
488 528
489 return 1; 529 return 1;
490} 530}
491 531
492MODULE = CFPlus PACKAGE = CFPlus 532static void
533deliantra_main ()
534{
535 call_argv ("::main", G_DISCARD | G_VOID, 0);
536 dSP;
537}
538
539#ifdef __MACOSX__
540 /* to due surprising braindamage on the side of SDL design, we
541 * do some mind-boggling hack here: SDL requires a custom main()
542 * on OS X, so... we provide one and call the original main(), which,
543 * due to share dlibrary magic, calls -lSDLmain's main, not perl's main,
544 * and which calls our main (== SDL_main) back.
545 */
546 extern C_LINKAGE int
547 main (int argc, char *argv[])
548 {
549 deliantra_main ();
550 }
551
552 #undef main
553
554 extern C_LINKAGE int main (int argc, char *argv[]);
555
556 static void
557 SDL_braino (void)
558 {
559 char *argv[] = { "deliantra client", 0 };
560 (main) (1, argv);
561 }
562#else
563 static void
564 SDL_braino (void)
565 {
566 deliantra_main ();
567 }
568#endif
569
570MODULE = Deliantra::Client PACKAGE = DC
493 571
494PROTOTYPES: ENABLE 572PROTOTYPES: ENABLE
495 573
496BOOT: 574BOOT:
497{ 575{
498 HV *stash = gv_stashpv ("CFPlus", 1); 576 HV *stash = gv_stashpv ("DC", 1);
499 static const struct { 577 static const struct {
500 const char *name; 578 const char *name;
501 IV iv; 579 IV iv;
502 } *civ, const_iv[] = { 580 } *civ, const_iv[] = {
503# define const_iv(name) { # name, (IV)name } 581# define const_iv(name) { # name, (IV)name }
525 603
526 const_iv (SDL_APPINPUTFOCUS), 604 const_iv (SDL_APPINPUTFOCUS),
527 const_iv (SDL_APPMOUSEFOCUS), 605 const_iv (SDL_APPMOUSEFOCUS),
528 const_iv (SDL_APPACTIVE), 606 const_iv (SDL_APPACTIVE),
529 607
608 const_iv (SDLK_FIRST),
609 const_iv (SDLK_LAST),
530 const_iv (SDLK_KP0), 610 const_iv (SDLK_KP0),
531 const_iv (SDLK_KP1), 611 const_iv (SDLK_KP1),
532 const_iv (SDLK_KP2), 612 const_iv (SDLK_KP2),
533 const_iv (SDLK_KP3), 613 const_iv (SDLK_KP3),
534 const_iv (SDLK_KP4), 614 const_iv (SDLK_KP4),
606 const_iv (KMOD_LMETA), 686 const_iv (KMOD_LMETA),
607 const_iv (KMOD_RMETA), 687 const_iv (KMOD_RMETA),
608 const_iv (KMOD_NUM), 688 const_iv (KMOD_NUM),
609 const_iv (KMOD_CAPS), 689 const_iv (KMOD_CAPS),
610 const_iv (KMOD_MODE), 690 const_iv (KMOD_MODE),
691
692 const_iv (MIX_DEFAULT_FORMAT),
693
694 const_iv (SDL_INIT_TIMER),
695 const_iv (SDL_INIT_AUDIO),
696 const_iv (SDL_INIT_VIDEO),
697 const_iv (SDL_INIT_CDROM),
698 const_iv (SDL_INIT_JOYSTICK),
699 const_iv (SDL_INIT_EVERYTHING),
700 const_iv (SDL_INIT_NOPARACHUTE),
701 const_iv (SDL_INIT_EVENTTHREAD),
702
703 const_iv (SDL_GL_RED_SIZE),
704 const_iv (SDL_GL_GREEN_SIZE),
705 const_iv (SDL_GL_BLUE_SIZE),
706 const_iv (SDL_GL_ALPHA_SIZE),
707 const_iv (SDL_GL_DOUBLEBUFFER),
708 const_iv (SDL_GL_BUFFER_SIZE),
709 const_iv (SDL_GL_DEPTH_SIZE),
710 const_iv (SDL_GL_STENCIL_SIZE),
711 const_iv (SDL_GL_ACCUM_RED_SIZE),
712 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
713 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
714 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
715 const_iv (SDL_GL_STEREO),
716 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
717 const_iv (SDL_GL_MULTISAMPLESAMPLES),
718 const_iv (SDL_GL_ACCELERATED_VISUAL),
719 const_iv (SDL_GL_SWAP_CONTROL),
720
721 const_iv (FOW_DARKNESS)
611# undef const_iv 722# undef const_iv
612 }; 723 };
613 724
614 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 725 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
615 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 726 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
633 744
634NV floor (NV x) 745NV floor (NV x)
635 746
636NV ceil (NV x) 747NV ceil (NV x)
637 748
749IV minpot (UV n)
750
751IV popcount (UV n)
752
638void 753void
639pango_init () 754pango_init ()
640 CODE: 755 CODE:
641{ 756{
642 opengl_fontmap = pango_opengl_font_map_new (); 757 opengl_fontmap = pango_opengl_font_map_new ();
643 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); 758 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0);
644 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); 759 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
760 /*pango_context_set_font_description (opengl_context, default_font);*/
761#if PANGO_VERSION_CHECK (1, 15, 2)
762 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
763 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
764#endif
645} 765}
646 766
647char *
648SDL_GetError () 767char *SDL_GetError ()
649 768
650int 769void SDL_braino ()
651SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
652 770
653void 771int SDL_Init (U32 flags)
772
773int SDL_InitSubSystem (U32 flags)
774
775void SDL_QuitSubSystem (U32 flags)
776
654SDL_Quit () 777void SDL_Quit ()
778
779int SDL_GL_SetAttribute (int attr, int value)
780
781int SDL_GL_GetAttribute (int attr)
782 CODE:
783 if (SDL_GL_GetAttribute (attr, &RETVAL))
784 XSRETURN_UNDEF;
785 OUTPUT:
786 RETVAL
655 787
656void 788void
657SDL_ListModes (int rgb, int alpha) 789SDL_ListModes (int rgb, int alpha)
658 PPCODE: 790 PPCODE:
659{ 791{
671 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 803 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
672 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 804 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
673 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 805 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
674 806
675 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 807 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
676#if SDL_VERSION_ATLEAST(1,2,10)
677 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
678 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 808 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
679#endif
680 809
681 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 810 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
682 811
683 if (m && m != (SDL_Rect **)-1) 812 if (m && m != (SDL_Rect **)-1)
684 while (*m) 813 while (*m)
685 { 814 {
686 if ((*m)->w >= 640 && (*m)->h >= 480) 815 if ((*m)->w >= 400 && (*m)->h >= 300)
687 { 816 {
688 AV *av = newAV (); 817 AV *av = newAV ();
689 av_push (av, newSViv ((*m)->w)); 818 av_push (av, newSViv ((*m)->w));
690 av_push (av, newSViv ((*m)->h)); 819 av_push (av, newSViv ((*m)->h));
691 av_push (av, newSViv (rgb)); 820 av_push (av, newSViv (rgb));
715 844
716 if (RETVAL) 845 if (RETVAL)
717 { 846 {
718 av_clear (texture_av); 847 av_clear (texture_av);
719 848
720 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 849 SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra");
721#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 850#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
722#include "glfunc.h" 851#include "glfunc.h"
723#undef GL_FUNC 852#undef GL_FUNC
724 } 853 }
725} 854}
732char * 861char *
733SDL_GetKeyName (int sym) 862SDL_GetKeyName (int sym)
734 863
735int 864int
736SDL_GetAppState () 865SDL_GetAppState ()
866
867int
868SDL_GetModState ()
737 869
738void 870void
739poll_events () 871poll_events ()
740 PPCODE: 872 PPCODE:
741{ 873{
751 { 883 {
752 case SDL_KEYDOWN: 884 case SDL_KEYDOWN:
753 case SDL_KEYUP: 885 case SDL_KEYUP:
754 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 886 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
755 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 887 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
756 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 888 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0);
757 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ 889 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */
758 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 890 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
759 break; 891 break;
760 892
761 case SDL_ACTIVEEVENT: 893 case SDL_ACTIVEEVENT:
762 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 894 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
780 x = ev.motion.x; 912 x = ev.motion.x;
781 y = ev.motion.y; 913 y = ev.motion.y;
782 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 914 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
783 } 915 }
784 916
785 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 917 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
786 hv_store (hv, "state", 5, newSViv (state), 0); 918 hv_store (hv, "state", 5, newSViv (state), 0);
787 hv_store (hv, "x", 1, newSViv (x), 0); 919 hv_store (hv, "x", 1, newSViv (x), 0);
788 hv_store (hv, "y", 1, newSViv (y), 0); 920 hv_store (hv, "y", 1, newSViv (y), 0);
789 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 921 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
790 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 922 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
791 } 923 }
792 break; 924 break;
793 925
794 case SDL_MOUSEBUTTONDOWN: 926 case SDL_MOUSEBUTTONDOWN:
795 case SDL_MOUSEBUTTONUP: 927 case SDL_MOUSEBUTTONUP:
796 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 928 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
797 929
798 hv_store (hv, "button", 6, newSViv (ev.button.button), 0); 930 hv_store (hv, "button", 6, newSViv (ev.button.button), 0);
799 hv_store (hv, "state", 5, newSViv (ev.button.state), 0); 931 hv_store (hv, "state", 5, newSViv (ev.button.state), 0);
800 hv_store (hv, "x", 1, newSViv (ev.button.x), 0); 932 hv_store (hv, "x", 1, newSViv (ev.button.x), 0);
801 hv_store (hv, "y", 1, newSViv (ev.button.y), 0); 933 hv_store (hv, "y", 1, newSViv (ev.button.y), 0);
806 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 938 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
807 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 939 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
808 break; 940 break;
809 } 941 }
810 942
811 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 943 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
812 } 944 }
813} 945}
814 946
815int 947int
816Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) 948Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
817 POSTCALL: 949 POSTCALL:
818 Mix_HookMusicFinished (music_finished); 950 Mix_HookMusicFinished (music_finished);
819 Mix_ChannelFinished (channel_finished); 951 Mix_ChannelFinished (channel_finished);
952
953void
954Mix_QuerySpec ()
955 PPCODE:
956{
957 int freq, channels;
958 Uint16 format;
959
960 if (Mix_QuerySpec (&freq, &format, &channels))
961 {
962 EXTEND (SP, 3);
963 PUSHs (sv_2mortal (newSViv (freq)));
964 PUSHs (sv_2mortal (newSViv (format)));
965 PUSHs (sv_2mortal (newSViv (channels)));
966 }
967}
820 968
821void 969void
822Mix_CloseAudio () 970Mix_CloseAudio ()
823 971
824int 972int
859 } 1007 }
860 } 1008 }
861#endif 1009#endif
862} 1010}
863 1011
864void 1012int
865add_font (char *file) 1013add_font (char *file)
866 CODE: 1014 CODE:
867 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 1015 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
1016 OUTPUT:
1017 RETVAL
868 1018
869void 1019void
870load_image_inline (SV *image_) 1020load_image_inline (SV *image_)
871 ALIAS: 1021 ALIAS:
872 load_image_file = 1 1022 load_image_file = 1
958void 1108void
959error (char *message) 1109error (char *message)
960 CODE: 1110 CODE:
961 fprintf (stderr, "ERROR: %s\n", message); 1111 fprintf (stderr, "ERROR: %s\n", message);
962#ifdef _WIN32 1112#ifdef _WIN32
963 MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); 1113 MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR);
964#endif 1114#endif
965 1115
966void 1116void
967fatal (char *message) 1117fatal (char *message)
968 CODE: 1118 CODE:
969 fprintf (stderr, "FATAL: %s\n", message); 1119 fprintf (stderr, "FATAL: %s\n", message);
970#ifdef _WIN32 1120#ifdef _WIN32
971 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 1121 MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR);
972#endif 1122#endif
973 _exit (1); 1123 _exit (1);
974 1124
975void 1125void
976_exit (int retval = 0) 1126_exit (int retval = 0)
988#if DEBUG 1138#if DEBUG
989 VALGRIND_DO_LEAK_CHECK; 1139 VALGRIND_DO_LEAK_CHECK;
990#endif 1140#endif
991} 1141}
992 1142
993MODULE = CFPlus PACKAGE = CFPlus::Font 1143MODULE = Deliantra::Client PACKAGE = DC::Font
994 1144
995PROTOTYPES: DISABLE 1145PROTOTYPES: DISABLE
996 1146
997CFPlus::Font 1147DC::Font
998new_from_file (SV *class, char *path, int id = 0) 1148new_from_file (SV *class, char *path, int id = 0)
999 CODE: 1149 CODE:
1000{ 1150{
1001 int count; 1151 int count;
1002 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1152 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
1005} 1155}
1006 OUTPUT: 1156 OUTPUT:
1007 RETVAL 1157 RETVAL
1008 1158
1009void 1159void
1010DESTROY (CFPlus::Font self) 1160DESTROY (DC::Font self)
1011 CODE: 1161 CODE:
1012 pango_font_description_free (self); 1162 pango_font_description_free (self);
1013 1163
1014void 1164void
1015make_default (CFPlus::Font self) 1165make_default (DC::Font self)
1016 PROTOTYPE: $ 1166 PROTOTYPE: $
1017 CODE: 1167 CODE:
1018 default_font = self; 1168 default_font = self;
1019 1169
1020MODULE = CFPlus PACKAGE = CFPlus::Layout 1170MODULE = Deliantra::Client PACKAGE = DC::Layout
1021 1171
1022PROTOTYPES: DISABLE 1172PROTOTYPES: DISABLE
1023 1173
1024void 1174void
1025reset_glyph_cache () 1175glyph_cache_backup ()
1026 PROTOTYPE: 1176 PROTOTYPE:
1027 CODE: 1177 CODE:
1178 tc_backup ();
1179
1180void
1181glyph_cache_restore ()
1182 PROTOTYPE:
1183 CODE:
1028 tc_clear (); 1184 tc_restore ();
1029 1185
1030CFPlus::Layout 1186DC::Layout
1031new (SV *class) 1187new (SV *class)
1032 CODE: 1188 CODE:
1033 New (0, RETVAL, 1, struct cf_layout); 1189 New (0, RETVAL, 1, struct cf_layout);
1034 1190
1035 RETVAL->pl = pango_layout_new (opengl_context); 1191 RETVAL->pl = pango_layout_new (opengl_context);
1045 layout_update_font (RETVAL); 1201 layout_update_font (RETVAL);
1046 OUTPUT: 1202 OUTPUT:
1047 RETVAL 1203 RETVAL
1048 1204
1049void 1205void
1050DESTROY (CFPlus::Layout self) 1206DESTROY (DC::Layout self)
1051 CODE: 1207 CODE:
1052 g_object_unref (self->pl); 1208 g_object_unref (self->pl);
1053 rc_free (self->rc); 1209 rc_free (self->rc);
1054 Safefree (self); 1210 Safefree (self);
1055 1211
1056void 1212void
1057set_text (CFPlus::Layout self, SV *text_) 1213set_text (DC::Layout self, SV *text_)
1058 CODE: 1214 CODE:
1059{ 1215{
1060 STRLEN textlen; 1216 STRLEN textlen;
1061 char *text = SvPVutf8 (text_, textlen); 1217 char *text = SvPVutf8 (text_, textlen);
1062 1218
1063 pango_layout_set_text (self->pl, text, textlen); 1219 pango_layout_set_text (self->pl, text, textlen);
1064} 1220}
1065 1221
1066void 1222void
1067set_markup (CFPlus::Layout self, SV *text_) 1223set_markup (DC::Layout self, SV *text_)
1068 CODE: 1224 CODE:
1069{ 1225{
1070 STRLEN textlen; 1226 STRLEN textlen;
1071 char *text = SvPVutf8 (text_, textlen); 1227 char *text = SvPVutf8 (text_, textlen);
1072 1228
1073 pango_layout_set_markup (self->pl, text, textlen); 1229 pango_layout_set_markup (self->pl, text, textlen);
1074} 1230}
1075 1231
1076void 1232void
1077set_shapes (CFPlus::Layout self, ...) 1233set_shapes (DC::Layout self, ...)
1078 CODE: 1234 CODE:
1079{ 1235{
1080 PangoAttrList *attrs = 0; 1236 PangoAttrList *attrs = 0;
1081 const char *text = pango_layout_get_text (self->pl); 1237 const char *text = pango_layout_get_text (self->pl);
1082 const char *pos = text; 1238 const char *pos = text;
1117 if (attrs) 1273 if (attrs)
1118 pango_layout_set_attributes (self->pl, attrs); 1274 pango_layout_set_attributes (self->pl, attrs);
1119} 1275}
1120 1276
1121void 1277void
1122get_shapes (CFPlus::Layout self) 1278get_shapes (DC::Layout self)
1123 PPCODE: 1279 PPCODE:
1124{ 1280{
1125 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 1281 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
1126 1282
1127 do 1283 do
1128 { 1284 {
1129 PangoLayoutRun *run = pango_layout_iter_get_run (iter); 1285 PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter);
1130 1286
1131 if (run && shape_attr_p (run)) 1287 if (run && shape_attr_p (run))
1132 { 1288 {
1133 PangoRectangle extents; 1289 PangoRectangle extents;
1134 pango_layout_iter_get_run_extents (iter, 0, &extents); 1290 pango_layout_iter_get_run_extents (iter, 0, &extents);
1142 1298
1143 pango_layout_iter_free (iter); 1299 pango_layout_iter_free (iter);
1144} 1300}
1145 1301
1146int 1302int
1147has_wrapped (CFPlus::Layout self) 1303has_wrapped (DC::Layout self)
1148 CODE: 1304 CODE:
1149{ 1305{
1150 int lines = 1; 1306 int lines = 1;
1151 const char *text = pango_layout_get_text (self->pl); 1307 const char *text = pango_layout_get_text (self->pl);
1152 1308
1157} 1313}
1158 OUTPUT: 1314 OUTPUT:
1159 RETVAL 1315 RETVAL
1160 1316
1161SV * 1317SV *
1162get_text (CFPlus::Layout self) 1318get_text (DC::Layout self)
1163 CODE: 1319 CODE:
1164 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 1320 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
1165 sv_utf8_decode (RETVAL); 1321 sv_utf8_decode (RETVAL);
1166 OUTPUT: 1322 OUTPUT:
1167 RETVAL 1323 RETVAL
1168 1324
1169void 1325void
1170set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) 1326set_foreground (DC::Layout self, float r, float g, float b, float a = 1.)
1171 CODE: 1327 CODE:
1172 self->r = r; 1328 self->r = r;
1173 self->g = g; 1329 self->g = g;
1174 self->b = b; 1330 self->b = b;
1175 self->a = a; 1331 self->a = a;
1176 1332
1177void 1333void
1178set_font (CFPlus::Layout self, CFPlus::Font font = 0) 1334set_font (DC::Layout self, DC::Font font = 0)
1179 CODE: 1335 CODE:
1180 if (self->font != font) 1336 if (self->font != font)
1181 { 1337 {
1182 self->font = font; 1338 self->font = font;
1183 layout_update_font (self); 1339 layout_update_font (self);
1184 } 1340 }
1185 1341
1186void 1342void
1187set_height (CFPlus::Layout self, int base_height) 1343set_height (DC::Layout self, int base_height)
1188 CODE: 1344 CODE:
1189 if (self->base_height != base_height) 1345 if (self->base_height != base_height)
1190 { 1346 {
1191 self->base_height = base_height; 1347 self->base_height = base_height;
1192 layout_update_font (self); 1348 layout_update_font (self);
1193 } 1349 }
1194 1350
1195void 1351void
1196set_width (CFPlus::Layout self, int max_width = -1) 1352set_width (DC::Layout self, int max_width = -1)
1197 CODE: 1353 CODE:
1198 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 1354 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
1199 1355
1200void 1356void
1201set_indent (CFPlus::Layout self, int indent) 1357set_indent (DC::Layout self, int indent)
1202 CODE: 1358 CODE:
1203 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 1359 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
1204 1360
1205void 1361void
1206set_spacing (CFPlus::Layout self, int spacing) 1362set_spacing (DC::Layout self, int spacing)
1207 CODE: 1363 CODE:
1208 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 1364 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
1209 1365
1210void 1366void
1211set_ellipsise (CFPlus::Layout self, int ellipsise) 1367set_ellipsise (DC::Layout self, int ellipsise)
1212 CODE: 1368 CODE:
1213 pango_layout_set_ellipsize (self->pl, 1369 pango_layout_set_ellipsize (self->pl,
1214 ellipsise == 1 ? PANGO_ELLIPSIZE_START 1370 ellipsise == 1 ? PANGO_ELLIPSIZE_START
1215 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 1371 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
1216 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 1372 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
1217 : PANGO_ELLIPSIZE_NONE 1373 : PANGO_ELLIPSIZE_NONE
1218 ); 1374 );
1219 1375
1220void 1376void
1221set_single_paragraph_mode (CFPlus::Layout self, int spm) 1377set_single_paragraph_mode (DC::Layout self, int spm)
1222 CODE: 1378 CODE:
1223 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 1379 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
1224 1380
1225void 1381void
1226size (CFPlus::Layout self) 1382size (DC::Layout self)
1227 PPCODE: 1383 PPCODE:
1228{ 1384{
1229 int w, h; 1385 int w, h;
1230 1386
1231 layout_get_pixel_size (self, &w, &h); 1387 layout_get_pixel_size (self, &w, &h);
1234 PUSHs (sv_2mortal (newSViv (w))); 1390 PUSHs (sv_2mortal (newSViv (w)));
1235 PUSHs (sv_2mortal (newSViv (h))); 1391 PUSHs (sv_2mortal (newSViv (h)));
1236} 1392}
1237 1393
1238int 1394int
1239descent (CFPlus::Layout self) 1395descent (DC::Layout self)
1240 CODE: 1396 CODE:
1241{ 1397{
1242 PangoRectangle rect; 1398 PangoRectangle rect;
1243 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1399 PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0);
1244 pango_layout_line_get_pixel_extents (line, 0, &rect); 1400 pango_layout_line_get_pixel_extents (line, 0, &rect);
1245 RETVAL = PANGO_DESCENT (rect); 1401 RETVAL = PANGO_DESCENT (rect);
1246} 1402}
1247 OUTPUT: 1403 OUTPUT:
1248 RETVAL 1404 RETVAL
1249 1405
1250int 1406int
1251xy_to_index (CFPlus::Layout self, int x, int y) 1407xy_to_index (DC::Layout self, int x, int y)
1252 CODE: 1408 CODE:
1253{ 1409{
1254 int index, trailing; 1410 int index, trailing;
1255 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1411 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1256 RETVAL = index + trailing; 1412 RETVAL = index + trailing;
1257} 1413}
1258 OUTPUT: 1414 OUTPUT:
1259 RETVAL 1415 RETVAL
1260 1416
1261void 1417void
1262cursor_pos (CFPlus::Layout self, int index) 1418cursor_pos (DC::Layout self, int index)
1263 PPCODE: 1419 PPCODE:
1264{ 1420{
1265 PangoRectangle strong_pos; 1421 PangoRectangle pos;
1266 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1422 pango_layout_get_cursor_pos (self->pl, index, &pos, 0);
1267 1423
1268 EXTEND (SP, 3); 1424 EXTEND (SP, 3);
1269 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1425 PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE)));
1270 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1426 PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE)));
1271 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1427 PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE)));
1272} 1428}
1273 1429
1274void 1430void
1275index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) 1431index_to_line_x (DC::Layout self, int index, int trailing = 0)
1276 PPCODE: 1432 PPCODE:
1277{ 1433{
1278 int line, x; 1434 int line, x;
1279 1435
1280 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); 1436 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1437#if !PANGO_VERSION_CHECK (1, 17, 3)
1281 /* pango bug: line is between 1..numlines, not 0..numlines-1 */ 1438 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1282 1439 --line;
1440#endif
1283 EXTEND (SP, 2); 1441 EXTEND (SP, 2);
1284 PUSHs (sv_2mortal (newSViv (line - 1))); 1442 PUSHs (sv_2mortal (newSViv (line)));
1285 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); 1443 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1286} 1444}
1287 1445
1288void 1446void
1289line_x_to_index (CFPlus::Layout self, int line, int x) 1447line_x_to_index (DC::Layout self, int line, int x)
1290 PPCODE: 1448 PPCODE:
1291{ 1449{
1292 PangoLayoutLine *lp; 1450 PangoLayoutLine *lp;
1293 int index, trailing; 1451 int index, trailing;
1294 1452
1295 if (line < 0) 1453 if (line < 0)
1296 XSRETURN_EMPTY; 1454 XSRETURN_EMPTY;
1297 1455
1298 if (!(lp = pango_layout_get_line (self->pl, line))) 1456 if (!(lp = pango_layout_get_line_readonly (self->pl, line)))
1299 XSRETURN_EMPTY; /* do better */ 1457 XSRETURN_EMPTY; /* do better */
1300 1458
1301 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); 1459 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1302 1460
1303 EXTEND (SP, 2); 1461 EXTEND (SP, 2);
1309 PUSHs (sv_2mortal (newSViv (trailing))); 1467 PUSHs (sv_2mortal (newSViv (trailing)));
1310 } 1468 }
1311} 1469}
1312 1470
1313void 1471void
1314render (CFPlus::Layout self, float x, float y, int flags = 0) 1472render (DC::Layout self, float x, float y, int flags = 0)
1315 CODE: 1473 CODE:
1316 rc_clear (self->rc); 1474 rc_clear (self->rc);
1317 pango_opengl_render_layout_subpixel ( 1475 pango_opengl_render_layout_subpixel (
1318 self->pl, 1476 self->pl,
1319 self->rc, 1477 self->rc,
1324 // we assume that context_change actually clears/frees stuff 1482 // we assume that context_change actually clears/frees stuff
1325 // and does not do any recomputation... 1483 // and does not do any recomputation...
1326 pango_layout_context_changed (self->pl); 1484 pango_layout_context_changed (self->pl);
1327 1485
1328void 1486void
1329draw (CFPlus::Layout self) 1487draw (DC::Layout self)
1330 CODE: 1488 CODE:
1331{ 1489{
1332 glEnable (GL_TEXTURE_2D); 1490 glEnable (GL_TEXTURE_2D);
1333 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 1491 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1334 glEnable (GL_BLEND); 1492 glEnable (GL_BLEND);
1342 glDisable (GL_ALPHA_TEST); 1500 glDisable (GL_ALPHA_TEST);
1343 glDisable (GL_BLEND); 1501 glDisable (GL_BLEND);
1344 glDisable (GL_TEXTURE_2D); 1502 glDisable (GL_TEXTURE_2D);
1345} 1503}
1346 1504
1347MODULE = CFPlus PACKAGE = CFPlus::Texture 1505MODULE = Deliantra::Client PACKAGE = DC::Texture
1348 1506
1349PROTOTYPES: ENABLE 1507PROTOTYPES: ENABLE
1350
1351int minpot (int n)
1352 1508
1353void 1509void
1354pad (SV *data_, int ow, int oh, int nw, int nh) 1510pad (SV *data_, int ow, int oh, int nw, int nh)
1355 CODE: 1511 CODE:
1356{ 1512{
1433 RETVAL = width > 0; 1589 RETVAL = width > 0;
1434} 1590}
1435 OUTPUT: 1591 OUTPUT:
1436 RETVAL 1592 RETVAL
1437 1593
1438MODULE = CFPlus PACKAGE = CFPlus::Map 1594MODULE = Deliantra::Client PACKAGE = DC::Map
1439 1595
1440PROTOTYPES: DISABLE 1596PROTOTYPES: DISABLE
1441 1597
1442CFPlus::Map 1598DC::Map
1443new (SV *class) 1599new (SV *class)
1444 CODE: 1600 CODE:
1445 New (0, RETVAL, 1, struct map); 1601 New (0, RETVAL, 1, struct map);
1446 RETVAL->x = 0; 1602 RETVAL->x = 0;
1447 RETVAL->y = 0; 1603 RETVAL->y = 0;
1455 RETVAL->row = 0; 1611 RETVAL->row = 0;
1456 OUTPUT: 1612 OUTPUT:
1457 RETVAL 1613 RETVAL
1458 1614
1459void 1615void
1460DESTROY (CFPlus::Map self) 1616DESTROY (DC::Map self)
1461 CODE: 1617 CODE:
1462{ 1618{
1463 map_clear (self); 1619 map_clear (self);
1464 Safefree (self->face2tile); 1620 Safefree (self->face2tile);
1465 Safefree (self->tex); 1621 Safefree (self->tex);
1466 Safefree (self); 1622 Safefree (self);
1467} 1623}
1468 1624
1469void 1625void
1470resize (CFPlus::Map self, int map_width, int map_height) 1626resize (DC::Map self, int map_width, int map_height)
1471 CODE: 1627 CODE:
1472 self->w = map_width; 1628 self->w = map_width;
1473 self->h = map_height; 1629 self->h = map_height;
1474 1630
1475void 1631void
1476clear (CFPlus::Map self) 1632clear (DC::Map self)
1477 CODE: 1633 CODE:
1478 map_clear (self); 1634 map_clear (self);
1479 1635
1480void 1636void
1481set_tileid (CFPlus::Map self, int face, int tile) 1637set_tileid (DC::Map self, int face, int tile)
1482 CODE: 1638 CODE:
1483{ 1639{
1484 need_facenum (self, face); self->face2tile [face] = tile; 1640 need_facenum (self, face); self->face2tile [face] = tile;
1485 need_texid (self, tile); 1641 need_texid (self, tile);
1486} 1642}
1487 1643
1488void 1644void
1489set_smooth (CFPlus::Map self, int face, int smooth, int level) 1645set_smooth (DC::Map self, int face, int smooth, int level)
1490 CODE: 1646 CODE:
1491{ 1647{
1492 tileid texid; 1648 tileid texid;
1493 maptex *tex; 1649 maptex *tex;
1494 1650
1507 tex->smoothtile = self->face2tile [smooth]; 1663 tex->smoothtile = self->face2tile [smooth];
1508 tex->smoothlevel = level; 1664 tex->smoothlevel = level;
1509} 1665}
1510 1666
1511void 1667void
1512set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1668set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1513 CODE: 1669 CODE:
1514{ 1670{
1515 need_texid (self, texid); 1671 need_texid (self, texid);
1516 1672
1517 { 1673 {
1537 // from transparent color bleeding and ugly wrapping effects. 1693 // from transparent color bleeding and ugly wrapping effects.
1538 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1694 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1539} 1695}
1540 1696
1541int 1697int
1542ox (CFPlus::Map self) 1698ox (DC::Map self)
1543 ALIAS: 1699 ALIAS:
1544 oy = 1 1700 oy = 1
1545 x = 2 1701 x = 2
1546 y = 3 1702 y = 3
1547 w = 4 1703 w = 4
1558 } 1714 }
1559 OUTPUT: 1715 OUTPUT:
1560 RETVAL 1716 RETVAL
1561 1717
1562void 1718void
1563scroll (CFPlus::Map self, int dx, int dy) 1719scroll (DC::Map self, int dx, int dy)
1564 CODE: 1720 CODE:
1565{ 1721{
1566 if (dx > 0) 1722 if (dx > 0)
1567 map_blank (self, self->x, self->y, dx, self->h); 1723 map_blank (self, self->x, self->y, dx, self->h);
1568 else if (dx < 0) 1724 else if (dx < 0)
1584 self->y += MAP_EXTEND_Y; 1740 self->y += MAP_EXTEND_Y;
1585 } 1741 }
1586} 1742}
1587 1743
1588SV * 1744SV *
1589map1a_update (CFPlus::Map self, SV *data_, int extmap) 1745map1a_update (DC::Map self, SV *data_, int extmap)
1590 CODE: 1746 CODE:
1591{ 1747{
1592 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1748 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1593 uint8_t *data_end = (uint8_t *)SvEND (data_); 1749 uint8_t *data_end = (uint8_t *)SvEND (data_);
1594 mapcell *cell; 1750 mapcell *cell;
1622 uint8_t ext, cmd; 1778 uint8_t ext, cmd;
1623 1779
1624 do 1780 do
1625 { 1781 {
1626 ext = *data++; 1782 ext = *data++;
1627 cmd = ext & 0x3f; 1783 cmd = ext & 0x7f;
1628 1784
1629 if (cmd < 4) 1785 if (cmd < 4)
1630 cell->darkness = 255 - ext * 64 + 1; 1786 cell->darkness = 255 - ext * 64 + 1;
1631 else if (cmd == 5) // health 1787 else if (cmd == 5) // health
1632 { 1788 {
1635 } 1791 }
1636 else if (cmd == 6) // monster width 1792 else if (cmd == 6) // monster width
1637 cell->stat_width = *data++ + 1; 1793 cell->stat_width = *data++ + 1;
1638 else if (cmd == 0x47) 1794 else if (cmd == 0x47)
1639 { 1795 {
1640 if (*data == 4) 1796 if (*data == 1) cell->player = data [1];
1641 ; // decode player count 1797 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
1798 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
1799 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
1642 1800
1643 data += *data + 1; 1801 data += *data + 1;
1644 } 1802 }
1645 else if (cmd == 8) // cell flags 1803 else if (cmd == 8) // cell flags
1646 cell->flags = *data++; 1804 cell->flags = *data++;
1676 } 1834 }
1677 } 1835 }
1678 } 1836 }
1679 } 1837 }
1680 else 1838 else
1681 cell->darkness = 0; 1839 CELL_CLEAR (cell);
1682 } 1840 }
1683} 1841}
1684 OUTPUT: 1842 OUTPUT:
1685 RETVAL 1843 RETVAL
1686 1844
1687SV * 1845SV *
1688mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1846mapmap (DC::Map self, int x0, int y0, int w, int h)
1689 CODE: 1847 CODE:
1690{ 1848{
1691 int x1, x; 1849 int x1, x;
1692 int y1, y; 1850 int y1, y;
1693 int z; 1851 int z;
1738} 1896}
1739 OUTPUT: 1897 OUTPUT:
1740 RETVAL 1898 RETVAL
1741 1899
1742void 1900void
1743draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1901draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1744 CODE: 1902 CODE:
1745{ 1903{
1746 int x, y, z; 1904 int x, y, z;
1747 1905
1748 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1906 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1749 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1907 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1750 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1908 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1751 smooth_key skey; 1909 smooth_key skey;
1752 1910 int pl_x, pl_y;
1911 maptex pl_tex;
1753 rc_t *rc = rc_alloc (); 1912 rc_t *rc = rc_alloc ();
1754 rc_key_t key; 1913 rc_key_t key;
1755 rc_array_t *arr; 1914 rc_array_t *arr;
1915
1916 pl_tex.name = 0;
1756 1917
1757 // thats current max. sorry. 1918 // thats current max. sorry.
1758 if (sw > 255) sw = 255; 1919 if (sw > 255) sw = 255;
1759 if (sh > 255) sh = 255; 1920 if (sh > 255) sh = 255;
1760 1921
1815 tileid tile = cell->tile [z]; 1976 tileid tile = cell->tile [z];
1816 1977
1817 if (tile) 1978 if (tile)
1818 { 1979 {
1819 maptex tex = self->tex [tile]; 1980 maptex tex = self->tex [tile];
1820 int px, py; 1981 int px = (x + 1) * T - tex.w;
1982 int py = (y + 1) * T - tex.h;
1821 1983
1822 // suppressing texture state switches here
1823 // is only moderately effective, but worth the extra effort
1824 if (key.texname != tex.name) 1984 if (key.texname != tex.name)
1825 { 1985 {
1826 if (!tex.name) 1986 if (!tex.name)
1827 tex = self->tex [2]; /* missing, replace by noface */ 1987 tex = self->tex [2]; /* missing, replace by noface */
1828 1988
1829 key.texname = tex.name; 1989 key.texname = tex.name;
1830 arr = rc_array (rc, &key); 1990 arr = rc_array (rc, &key);
1831 } 1991 }
1832 1992
1833 px = (x + 1) * T - tex.w; 1993 if (expect_false (cell->player == player) && expect_false (z == 2))
1834 py = (y + 1) * T - tex.h; 1994 {
1995 pl_x = px;
1996 pl_y = py;
1997 pl_tex = tex;
1998 continue;
1999 }
1835 2000
1836 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2001 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1837 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2002 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1838 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2003 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1839 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2004 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1840 2005
1841 if (cell->flags && z == 2) 2006 if (expect_false (cell->flags) && expect_false (z == 2))
1842 { 2007 {
1843 // overlays such as the speech bubble, probably more to come 2008 // overlays such as the speech bubble, probably more to come
1844 if (cell->flags & 1) 2009 if (cell->flags & 1)
1845 { 2010 {
1846 maptex tex = self->tex [1]; 2011 maptex tex = self->tex [1];
1911 // go through all smoothlevels, lowest to highest, then draw. 2076 // go through all smoothlevels, lowest to highest, then draw.
1912 // this is basically counting sort 2077 // this is basically counting sort
1913 { 2078 {
1914 int w, b; 2079 int w, b;
1915 2080
2081 glEnable (GL_TEXTURE_2D);
2082 glBegin (GL_QUADS);
1916 for (w = 0; w < 256 / 32; ++w) 2083 for (w = 0; w < 256 / 32; ++w)
1917 { 2084 {
1918 uint32_t smask = smooth_level [w]; 2085 uint32_t smask = smooth_level [w];
1919 if (smask) 2086 if (smask)
1920 for (b = 0; b < 32; ++b) 2087 for (b = 0; b < 32; ++b)
1945 { 2112 {
1946 // this time avoiding texture state changes 2113 // this time avoiding texture state changes
1947 // save gobs of state changes. 2114 // save gobs of state changes.
1948 if (key.texname != tex.name) 2115 if (key.texname != tex.name)
1949 { 2116 {
2117 glEnd ();
1950 key.texname = tex.name; 2118 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1951 arr = rc_array (rc, &key); 2119 glBegin (GL_QUADS);
1952 } 2120 }
1953 2121
1954 if (border) 2122 if (border)
1955 { 2123 {
1956 float ox = border * dx; 2124 float ox = border * dx;
1957 2125
1958 rc_t2f_v3f (arr, ox , 0.f , px , py , 0); 2126 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1959 rc_t2f_v3f (arr, ox , dy , px , py + T, 0); 2127 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1960 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); 2128 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1961 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); 2129 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1962 } 2130 }
1963 2131
1964 if (corner) 2132 if (corner)
1965 { 2133 {
1966 float ox = corner * dx; 2134 float ox = corner * dx;
1967 2135
1968 rc_t2f_v3f (arr, ox , dy , px , py , 0); 2136 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1969 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); 2137 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1970 rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); 2138 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T);
1971 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); 2139 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
1972 } 2140 }
1973 } 2141 }
1974 } 2142 }
1975 } 2143 }
1976 } 2144 }
1977 } 2145 }
2146
2147 glEnd ();
2148 glDisable (GL_TEXTURE_2D);
2149 key.texname = -1;
1978 } 2150 }
1979 2151
1980 hv_clear (smooth); 2152 hv_clear (smooth);
2153 }
2154
2155 if (pl_tex.name)
2156 {
2157 maptex tex = pl_tex;
2158 int px = pl_x + sdx;
2159 int py = pl_y + sdy;
2160
2161 key.texname = tex.name;
2162 arr = rc_array (rc, &key);
2163
2164 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2165 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2166 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2167 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2168
1981 rc_draw (rc); 2169 rc_draw (rc);
1982 rc_clear (rc);
1983 } 2170 }
1984 2171
1985 glDisable (GL_BLEND); 2172 glDisable (GL_BLEND);
1986 rc_free (rc); 2173 rc_free (rc);
1987 2174
2016 } 2203 }
2017 } 2204 }
2018} 2205}
2019 2206
2020void 2207void
2021draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 2208draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data)
2022 CODE: 2209 CODE:
2023{ 2210{
2024 static float color[16][3] = { 2211 static float color[16][3] = {
2025 { 0.00F, 0.00F, 0.00F }, 2212 { 0.00F, 0.00F, 0.00F },
2026 { 1.00F, 1.00F, 1.00F }, 2213 { 1.00F, 1.00F, 1.00F },
2076 glDisable (GL_BLEND); 2263 glDisable (GL_BLEND);
2077 glDisable (GL_TEXTURE_2D); 2264 glDisable (GL_TEXTURE_2D);
2078} 2265}
2079 2266
2080void 2267void
2081fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) 2268fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2082 PPCODE: 2269 PPCODE:
2083{ 2270{
2084 int x, y; 2271 int x, y;
2085 int sw1 = sw + 2; 2272 int sw1 = sw + 2;
2086 int sh1 = sh + 2; 2273 int sh1 = sh + 2;
2094 SvCUR_set (darkness3_sv, sw34 * sh3); 2281 SvCUR_set (darkness3_sv, sw34 * sh3);
2095 2282
2096 mx += self->x - 1; 2283 mx += self->x - 1;
2097 my += self->y - 1; 2284 my += self->y - 1;
2098 2285
2099 memset (darkness1, 255, sw1 * sh1); 2286 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2100 2287
2101 for (y = 0; y < sh1; y++) 2288 for (y = 0; y < sh1; y++)
2102 if (0 <= y + my && y + my < self->rows) 2289 if (0 <= y + my && y + my < self->rows)
2103 { 2290 {
2104 maprow *row = self->row + (y + my); 2291 maprow *row = self->row + (y + my);
2157 PUSHs (sv_2mortal (newSViv (sh3))); 2344 PUSHs (sv_2mortal (newSViv (sh3)));
2158 PUSHs (darkness3_sv); 2345 PUSHs (darkness3_sv);
2159} 2346}
2160 2347
2161SV * 2348SV *
2162get_rect (CFPlus::Map self, int x0, int y0, int w, int h) 2349get_rect (DC::Map self, int x0, int y0, int w, int h)
2163 CODE: 2350 CODE:
2164{ 2351{
2165 int x, y, x1, y1; 2352 int x, y, x1, y1;
2166 SV *data_sv = newSV (w * h * 7 + 5); 2353 SV *data_sv = newSV (w * h * 7 + 5);
2167 uint8_t *data = (uint8_t *)SvPVX (data_sv); 2354 uint8_t *data = (uint8_t *)SvPVX (data_sv);
2224 else 2411 else
2225 *data++ = 0; 2412 *data++ = 0;
2226 } 2413 }
2227 } 2414 }
2228 2415
2416 /* if size is w*h + 5 then no data has been found */
2417 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2418 {
2229 SvPOK_only (data_sv); 2419 SvPOK_only (data_sv);
2230 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2420 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2421 }
2422
2231 RETVAL = data_sv; 2423 RETVAL = data_sv;
2232} 2424}
2233 OUTPUT: 2425 OUTPUT:
2234 RETVAL 2426 RETVAL
2235 2427
2236void 2428void
2237set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) 2429set_rect (DC::Map self, int x0, int y0, SV *data_sv)
2238 PPCODE: 2430 PPCODE:
2239{ 2431{
2240 int x, y, z; 2432 int x, y, z;
2241 int w, h; 2433 int w, h;
2242 int x1, y1; 2434 int x1, y1;
2435 STRLEN len;
2436 uint8_t *data, *end;
2437
2438 len = SvLEN (data_sv);
2439 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2440 data = SvPVbyte_nolen (data_sv);
2441 end = data + len + 8;
2442
2443 if (len < 5)
2444 XSRETURN_EMPTY;
2243 2445
2244 if (*data++ != 0) 2446 if (*data++ != 0)
2245 return; /* version mismatch */ 2447 XSRETURN_EMPTY; /* version mismatch */
2246 2448
2247 w = *data++ << 8; w |= *data++; 2449 w = *data++ << 8; w |= *data++;
2248 h = *data++ << 8; h |= *data++; 2450 h = *data++ << 8; h |= *data++;
2249 2451
2250 // we need to do this 'cause we don't keep an absolute coord system for rows 2452 // we need to do this 'cause we don't keep an absolute coord system for rows
2262 { 2464 {
2263 maprow *row = map_get_row (self, y); 2465 maprow *row = map_get_row (self, y);
2264 2466
2265 for (x = x0; x < x1; x++) 2467 for (x = x0; x < x1; x++)
2266 { 2468 {
2469 uint8_t flags;
2470
2471 if (data + 7 >= end)
2472 XSRETURN_EMPTY;
2473
2267 uint8_t flags = *data++; 2474 flags = *data++;
2268 2475
2269 if (flags) 2476 if (flags)
2270 { 2477 {
2271 mapcell *cell = row_get_cell (row, x); 2478 mapcell *cell = row_get_cell (row, x);
2272 tileid tile[3] = { 0, 0, 0 }; 2479 tileid tile[3] = { 0, 0, 0 };
2275 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } 2482 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
2276 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } 2483 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
2277 2484
2278 if (cell->darkness == 0) 2485 if (cell->darkness == 0)
2279 { 2486 {
2280 cell->darkness = 0; 2487 /*cell->darkness = 0;*/
2488 EXTEND (SP, 3);
2281 2489
2282 for (z = 0; z <= 2; z++) 2490 for (z = 0; z <= 2; z++)
2283 { 2491 {
2284 tileid t = tile [z]; 2492 tileid t = tile [z];
2285 2493
2286 if (t >= self->texs || (t && !self->tex [t].name)) 2494 if (t >= self->texs || (t && !self->tex [t].name))
2287 { 2495 {
2288 XPUSHs (sv_2mortal (newSViv (t))); 2496 PUSHs (sv_2mortal (newSViv (t)));
2289 need_texid (self, t); 2497 need_texid (self, t);
2290 } 2498 }
2291 2499
2292 cell->tile [z] = t; 2500 cell->tile [z] = t;
2293 } 2501 }
2295 } 2503 }
2296 } 2504 }
2297 } 2505 }
2298} 2506}
2299 2507
2300MODULE = CFPlus PACKAGE = CFPlus::RW 2508MODULE = Deliantra::Client PACKAGE = DC::RW
2301 2509
2302CFPlus::RW 2510DC::RW
2303new (SV *class, SV *data_sv) 2511new (SV *class, SV *data_sv)
2304 CODE: 2512 CODE:
2305{ 2513{
2306 STRLEN datalen; 2514 STRLEN datalen;
2307 char *data = SvPVbyte (data_sv, datalen); 2515 char *data = SvPVbyte (data_sv, datalen);
2309 RETVAL = SDL_RWFromConstMem (data, datalen); 2517 RETVAL = SDL_RWFromConstMem (data, datalen);
2310} 2518}
2311 OUTPUT: 2519 OUTPUT:
2312 RETVAL 2520 RETVAL
2313 2521
2314CFPlus::RW 2522DC::RW
2315new_from_file (SV *class, const char *path, const char *mode = "rb") 2523new_from_file (SV *class, const char *path, const char *mode = "rb")
2316 CODE: 2524 CODE:
2317 RETVAL = SDL_RWFromFile (path, mode); 2525 RETVAL = SDL_RWFromFile (path, mode);
2318 OUTPUT: 2526 OUTPUT:
2319 RETVAL 2527 RETVAL
2320 2528
2321# fails on win32: 2529# fails on win32:
2322# CFPlus.xs(2268) : error C2059: syntax error : '(' 2530# dc.xs(2268) : error C2059: syntax error : '('
2323#void 2531#void
2324#close (CFPlus::RW self) 2532#close (DC::RW self)
2325# CODE: 2533# CODE:
2326# (self->(close)) (self); 2534# (self->(close)) (self);
2327 2535
2328MODULE = CFPlus PACKAGE = CFPlus::Channel 2536MODULE = Deliantra::Client PACKAGE = DC::Channel
2329 2537
2330PROTOTYPES: DISABLE 2538PROTOTYPES: DISABLE
2331 2539
2332CFPlus::Channel 2540DC::Channel
2333find () 2541find ()
2334 CODE: 2542 CODE:
2335{ 2543{
2336 RETVAL = Mix_GroupAvailable (-1); 2544 RETVAL = Mix_GroupAvailable (-1);
2337 2545
2350} 2558}
2351 OUTPUT: 2559 OUTPUT:
2352 RETVAL 2560 RETVAL
2353 2561
2354void 2562void
2355halt (CFPlus::Channel self) 2563halt (DC::Channel self)
2356 CODE: 2564 CODE:
2357 Mix_HaltChannel (self); 2565 Mix_HaltChannel (self);
2358 2566
2359void 2567void
2360expire (CFPlus::Channel self, int ticks = -1) 2568expire (DC::Channel self, int ticks = -1)
2361 CODE: 2569 CODE:
2362 Mix_ExpireChannel (self, ticks); 2570 Mix_ExpireChannel (self, ticks);
2363 2571
2364void 2572void
2365fade_out (CFPlus::Channel self, int ticks = -1) 2573fade_out (DC::Channel self, int ticks = -1)
2366 CODE: 2574 CODE:
2367 Mix_FadeOutChannel (self, ticks); 2575 Mix_FadeOutChannel (self, ticks);
2368 2576
2369int 2577int
2370volume (CFPlus::Channel self, int volume) 2578volume (DC::Channel self, int volume)
2371 CODE: 2579 CODE:
2372 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); 2580 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2373 OUTPUT: 2581 OUTPUT:
2374 RETVAL 2582 RETVAL
2375 2583
2376void 2584void
2377unregister_all_effects (CFPlus::Channel self) 2585unregister_all_effects (DC::Channel self)
2378 CODE: 2586 CODE:
2379 Mix_UnregisterAllEffects (self); 2587 Mix_UnregisterAllEffects (self);
2380 2588
2381void 2589void
2382set_panning (CFPlus::Channel self, int left, int right) 2590set_panning (DC::Channel self, int left, int right)
2383 CODE: 2591 CODE:
2384 left = CLAMP (left , 0, 255); 2592 left = CLAMP (left , 0, 255);
2385 right = CLAMP (right, 0, 255); 2593 right = CLAMP (right, 0, 255);
2386 Mix_SetPanning (self, left, right); 2594 Mix_SetPanning (self, left, right);
2387 2595
2388void 2596void
2389set_distance (CFPlus::Channel self, int distance) 2597set_distance (DC::Channel self, int distance)
2390 CODE: 2598 CODE:
2391 Mix_SetDistance (self, CLAMP (distance, 0, 255)); 2599 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2392 2600
2393void 2601void
2394set_position (CFPlus::Channel self, int angle, int distance) 2602set_position (DC::Channel self, int angle, int distance)
2395 CODE: 2603 CODE:
2396 2604
2397void 2605void
2398set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) 2606set_position_r (DC::Channel self, int dx, int dy, int maxdistance)
2399 CODE: 2607 CODE:
2400{ 2608{
2401 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); 2609 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2402 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); 2610 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI);
2403 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); 2611 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2404} 2612}
2405 2613
2406void 2614void
2407set_reverse_stereo (CFPlus::Channel self, int flip) 2615set_reverse_stereo (DC::Channel self, int flip)
2408 CODE: 2616 CODE:
2409 Mix_SetReverseStereo (self, flip); 2617 Mix_SetReverseStereo (self, flip);
2410 2618
2411MODULE = CFPlus PACKAGE = CFPlus::MixChunk 2619MODULE = Deliantra::Client PACKAGE = DC::MixChunk
2412 2620
2413PROTOTYPES: DISABLE 2621PROTOTYPES: DISABLE
2414 2622
2415CFPlus::MixChunk 2623DC::MixChunk
2416new (SV *class, CFPlus::RW rwops) 2624new (SV *class, DC::RW rwops)
2417 CODE: 2625 CODE:
2418 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2626 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2419 OUTPUT: 2627 OUTPUT:
2420 RETVAL 2628 RETVAL
2421 2629
2422void 2630void
2423DESTROY (CFPlus::MixChunk self) 2631DESTROY (DC::MixChunk self)
2424 CODE: 2632 CODE:
2425 Mix_FreeChunk (self); 2633 Mix_FreeChunk (self);
2426 2634
2427int 2635int
2428volume (CFPlus::MixChunk self, int volume = -1) 2636volume (DC::MixChunk self, int volume = -1)
2429 CODE: 2637 CODE:
2430 if (items > 1) 2638 if (items > 1)
2431 volume = CLAMP (volume, 0, 128); 2639 volume = CLAMP (volume, 0, 128);
2432 RETVAL = Mix_VolumeChunk (self, volume); 2640 RETVAL = Mix_VolumeChunk (self, volume);
2433 OUTPUT: 2641 OUTPUT:
2434 RETVAL 2642 RETVAL
2435 2643
2436CFPlus::Channel 2644DC::Channel
2437play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) 2645play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1)
2438 CODE: 2646 CODE:
2439{ 2647{
2440 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 2648 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
2441 2649
2442 if (RETVAL < 0) 2650 if (RETVAL < 0)
2449 } 2657 }
2450} 2658}
2451 OUTPUT: 2659 OUTPUT:
2452 RETVAL 2660 RETVAL
2453 2661
2454MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2662MODULE = Deliantra::Client PACKAGE = DC::MixMusic
2455 2663
2456int 2664int
2457volume (int volume = -1) 2665volume (int volume = -1)
2458 PROTOTYPE: ;$ 2666 PROTOTYPE: ;$
2459 CODE: 2667 CODE:
2471void 2679void
2472halt () 2680halt ()
2473 CODE: 2681 CODE:
2474 Mix_HaltMusic (); 2682 Mix_HaltMusic ();
2475 2683
2476CFPlus::MixMusic 2684DC::MixMusic
2477new (SV *class, CFPlus::RW rwops) 2685new (SV *class, DC::RW rwops)
2478 CODE: 2686 CODE:
2479 RETVAL = Mix_LoadMUS_RW (rwops); 2687 RETVAL = Mix_LoadMUS_RW (rwops);
2480 OUTPUT: 2688 OUTPUT:
2481 RETVAL 2689 RETVAL
2482 2690
2483void 2691void
2484DESTROY (CFPlus::MixMusic self) 2692DESTROY (DC::MixMusic self)
2485 CODE: 2693 CODE:
2486 Mix_FreeMusic (self); 2694 Mix_FreeMusic (self);
2487 2695
2488int 2696int
2489play (CFPlus::MixMusic self, int loops = -1) 2697play (DC::MixMusic self, int loops = -1)
2490 CODE: 2698 CODE:
2491 RETVAL = Mix_PlayMusic (self, loops); 2699 RETVAL = Mix_PlayMusic (self, loops);
2492 OUTPUT: 2700 OUTPUT:
2493 RETVAL 2701 RETVAL
2494 2702
2495void 2703void
2496fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) 2704fade_in_pos (DC::MixMusic self, int loops, int ms, double position)
2497 CODE: 2705 CODE:
2498 Mix_FadeInMusicPos (self, loops, ms, position); 2706 Mix_FadeInMusicPos (self, loops, ms, position);
2499 2707
2500MODULE = CFPlus PACKAGE = CFPlus::OpenGL 2708MODULE = Deliantra::Client PACKAGE = DC::OpenGL
2501 2709
2502PROTOTYPES: ENABLE 2710PROTOTYPES: ENABLE
2503 2711
2504BOOT: 2712BOOT:
2505{ 2713{
2506 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); 2714 HV *stash = gv_stashpv ("DC::OpenGL", 1);
2507 static const struct { 2715 static const struct {
2508 const char *name; 2716 const char *name;
2509 IV iv; 2717 IV iv;
2510 } *civ, const_iv[] = { 2718 } *civ, const_iv[] = {
2511# define const_iv(name) { # name, (IV)name } 2719# define const_iv(name) { # name, (IV)name }
2546 const_iv (GL_INTENSITY), 2754 const_iv (GL_INTENSITY),
2547 const_iv (GL_LUMINANCE), 2755 const_iv (GL_LUMINANCE),
2548 const_iv (GL_LUMINANCE_ALPHA), 2756 const_iv (GL_LUMINANCE_ALPHA),
2549 const_iv (GL_FLOAT), 2757 const_iv (GL_FLOAT),
2550 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 2758 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
2759 const_iv (GL_COMPRESSED_ALPHA_ARB),
2760 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
2761 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
2762 const_iv (GL_COMPRESSED_INTENSITY_ARB),
2763 const_iv (GL_COMPRESSED_RGB_ARB),
2764 const_iv (GL_COMPRESSED_RGBA_ARB),
2551 const_iv (GL_COMPILE), 2765 const_iv (GL_COMPILE),
2552 const_iv (GL_PROXY_TEXTURE_1D), 2766 const_iv (GL_PROXY_TEXTURE_1D),
2553 const_iv (GL_PROXY_TEXTURE_2D), 2767 const_iv (GL_PROXY_TEXTURE_2D),
2554 const_iv (GL_TEXTURE_1D), 2768 const_iv (GL_TEXTURE_1D),
2555 const_iv (GL_TEXTURE_2D), 2769 const_iv (GL_TEXTURE_2D),
2594 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2808 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2595 const_iv (GL_POINT_SMOOTH_HINT), 2809 const_iv (GL_POINT_SMOOTH_HINT),
2596 const_iv (GL_LINE_SMOOTH_HINT), 2810 const_iv (GL_LINE_SMOOTH_HINT),
2597 const_iv (GL_POLYGON_SMOOTH_HINT), 2811 const_iv (GL_POLYGON_SMOOTH_HINT),
2598 const_iv (GL_GENERATE_MIPMAP_HINT), 2812 const_iv (GL_GENERATE_MIPMAP_HINT),
2813 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2599 const_iv (GL_FASTEST), 2814 const_iv (GL_FASTEST),
2600 const_iv (GL_DONT_CARE), 2815 const_iv (GL_DONT_CARE),
2601 const_iv (GL_NICEST), 2816 const_iv (GL_NICEST),
2602 const_iv (GL_V2F), 2817 const_iv (GL_V2F),
2603 const_iv (GL_V3F), 2818 const_iv (GL_V3F),
2611 2826
2612 texture_av = newAV (); 2827 texture_av = newAV ();
2613 AvREAL_off (texture_av); 2828 AvREAL_off (texture_av);
2614} 2829}
2615 2830
2831void
2832disable_GL_EXT_blend_func_separate ()
2833 CODE:
2834 gl.BlendFuncSeparate = 0;
2835 gl.BlendFuncSeparateEXT = 0;
2836
2616char * 2837char *
2617gl_vendor () 2838gl_vendor ()
2618 CODE: 2839 CODE:
2619 RETVAL = (char *)glGetString (GL_VENDOR); 2840 RETVAL = (char *)glGetString (GL_VENDOR);
2620 OUTPUT: 2841 OUTPUT:
2741 2962
2742void glRect (float x1, float y1, float x2, float y2) 2963void glRect (float x1, float y1, float x2, float y2)
2743 CODE: 2964 CODE:
2744 glRectf (x1, y1, x2, y2); 2965 glRectf (x1, y1, x2, y2);
2745 2966
2967void glRect_lineloop (float x1, float y1, float x2, float y2)
2968 CODE:
2969 glBegin (GL_LINE_LOOP);
2970 glVertex2f (x1, y1);
2971 glVertex2f (x2, y1);
2972 glVertex2f (x2, y2);
2973 glVertex2f (x1, y2);
2974 glEnd ();
2975
2746PROTOTYPES: ENABLE 2976PROTOTYPES: ENABLE
2747 2977
2748void glBegin (int mode) 2978void glBegin (int mode)
2749 2979
2750void glEnd () 2980void glEnd ()
2782void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) 3012void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column)
2783 CODE: 3013 CODE:
2784 if (gl.SeparableFilter2D) 3014 if (gl.SeparableFilter2D)
2785 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); 3015 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column);
2786 3016
2787void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) 3017void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0)
2788 3018
2789void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) 3019void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border)
2790 3020
2791void glDrawPixels (int width, int height, int format, int type, char *pixels) 3021void glDrawPixels (int width, int height, int format, int type, char *pixels)
2792 3022
2818 3048
2819void glEndList () 3049void glEndList ()
2820 3050
2821void glCallList (int list) 3051void glCallList (int list)
2822 3052
2823MODULE = CFPlus PACKAGE = CFPlus::UI::Base 3053MODULE = Deliantra::Client PACKAGE = DC::UI::Base
2824 3054
2825PROTOTYPES: DISABLE 3055PROTOTYPES: DISABLE
2826 3056
2827void 3057void
2828find_widget (SV *self, NV x, NV y) 3058find_widget (SV *self, NV x, NV y)
2832 XPUSHs (self); 3062 XPUSHs (self);
2833} 3063}
2834 3064
2835BOOT: 3065BOOT:
2836{ 3066{
2837 hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); 3067 hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV);
2838 3068
2839 draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); 3069 draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV);
2840 draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); 3070 draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV);
2841 draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); 3071 draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV);
2842 draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); 3072 draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV);
2843} 3073}
2844 3074
2845void 3075void
2846draw (SV *self) 3076draw (SV *self)
2847 CODE: 3077 CODE:
2851 NV x, y, w, h; 3081 NV x, y, w, h;
2852 SV *draw_x_sv = GvSV (draw_x_gv); 3082 SV *draw_x_sv = GvSV (draw_x_gv);
2853 SV *draw_y_sv = GvSV (draw_y_gv); 3083 SV *draw_y_sv = GvSV (draw_y_gv);
2854 SV *draw_w_sv = GvSV (draw_w_gv); 3084 SV *draw_w_sv = GvSV (draw_w_gv);
2855 SV *draw_h_sv = GvSV (draw_h_gv); 3085 SV *draw_h_sv = GvSV (draw_h_gv);
2856 SV *hover;
2857 double draw_x, draw_y, draw_w, draw_h; 3086 double draw_x, draw_y;
2858 3087
2859 if (!SvROK (self)) 3088 if (!SvROK (self))
2860 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 3089 croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self));
2861 3090
2862 hv = (HV *)SvRV (self); 3091 hv = (HV *)SvRV (self);
2863 3092
2864 if (SvTYPE (hv) != SVt_PVHV) 3093 if (SvTYPE (hv) != SVt_PVHV)
2865 croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); 3094 croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self));
2866 3095
2867 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; 3096 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.;
2868 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; 3097 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.;
2869 3098
2870 if (!h || !w) 3099 if (!h || !w)
2890 { 3119 {
2891 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 3120 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2892 3121
2893 if (svp && SvTRUE (*svp)) 3122 if (svp && SvTRUE (*svp))
2894 { 3123 {
2895 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 3124 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2896 glEnable (GL_BLEND); 3125 glEnable (GL_BLEND);
2897 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 3126 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2898 glBegin (GL_QUADS); 3127 glBegin (GL_QUADS);
2899 glVertex2f (0, 0); 3128 glVertex2f (0, 0);
2900 glVertex2f (w, 0); 3129 glVertex2f (w, 0);
2903 glEnd (); 3132 glEnd ();
2904 glDisable (GL_BLEND); 3133 glDisable (GL_BLEND);
2905 } 3134 }
2906 } 3135 }
2907#if 0 3136#if 0
2908 if ($ENV{CFPLUS_DEBUG} & 1) { 3137 // draw borders, for debugging
2909 glPushMatrix; 3138 glPushMatrix ();
2910 glColor 1, 1, 0, 1; 3139 glColor4f (1., 1., 0., 1.);
2911 glTranslate 0.375, 0.375; 3140 glTranslatef (.5, .5, 0.);
2912 glBegin GL_LINE_LOOP; 3141 glBegin (GL_LINE_LOOP);
2913 glVertex 0 , 0; 3142 glVertex2f (0 , 0);
2914 glVertex $self->{w} - 1, 0; 3143 glVertex2f (w - 1, 0);
2915 glVertex $self->{w} - 1, $self->{h} - 1; 3144 glVertex2f (w - 1, h - 1);
2916 glVertex 0 , $self->{h} - 1; 3145 glVertex2f (0 , h - 1);
2917 glEnd; 3146 glEnd ();
2918 glPopMatrix; 3147 glPopMatrix ();
2919 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2920 }
2921#endif 3148#endif
2922 PUSHMARK (SP); 3149 PUSHMARK (SP);
2923 XPUSHs (self); 3150 XPUSHs (self);
2924 PUTBACK; 3151 PUTBACK;
2925 call_method ("_draw", G_VOID | G_DISCARD); 3152 call_method ("_draw", G_VOID | G_DISCARD);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines