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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines