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.219 by root, Mon Aug 6 05:06:32 2007 UTC vs.
Revision 1.270 by root, Sun Jul 20 15:05:13 2008 UTC

17#include "perl.h" 17#include "perl.h"
18#include "XSUB.h" 18#include "XSUB.h"
19 19
20#ifdef _WIN32 20#ifdef _WIN32
21# undef pipe 21# undef pipe
22// microsoft vs. C
23# define sqrtf(x) sqrt(x)
24# define roundf(x) (int)(x)
25# define atan2f(x,y) atan2(x,y)
26# define M_PI 3.14159265f
22#endif 27#endif
23 28
24#include <assert.h> 29#include <assert.h>
25#include <math.h> 30#include <math.h>
26#include <string.h> 31#include <string.h>
40#define G_DISABLE_CAST_CHECKS 45#define G_DISABLE_CAST_CHECKS
41 46
42#include <glib/gmacros.h> 47#include <glib/gmacros.h>
43 48
44#include <pango/pango.h> 49#include <pango/pango.h>
50
51#ifndef PANGO_VERSION_CHECK
52# define PANGO_VERSION_CHECK(a,b,c) 0
53#endif
54
55#if !PANGO_VERSION_CHECK (1, 15, 2)
56# define pango_layout_get_line_readonly pango_layout_get_line
57# define pango_layout_get_lines_readonly pango_layout_get_lines
58# define pango_layout_iter_get_line_readonly pango_layout_iter_get_line
59# define pango_layout_iter_get_run_readonly pango_layout_iter_get_run
60#endif
45 61
46#ifndef _WIN32 62#ifndef _WIN32
47# include <sys/types.h> 63# include <sys/types.h>
48# include <sys/socket.h> 64# include <sys/socket.h>
49# include <netinet/in.h> 65# include <netinet/in.h>
50# include <netinet/tcp.h> 66# include <netinet/tcp.h>
51# include <inttypes.h> 67# include <inttypes.h>
52#endif 68#endif
53 69
70#if __GNUC__ >= 4
71# define expect(expr,value) __builtin_expect ((expr),(value))
72#else
73# define expect(expr,value) (expr)
74#endif
75
76#define expect_false(expr) expect ((expr) != 0, 0)
77#define expect_true(expr) expect ((expr) != 0, 1)
78
54#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 79#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
55 80
56#define FOW_DARKNESS 32 81#define FOW_DARKNESS 32
57 82
58#define MAP_EXTEND_X 32 83#define MAP_EXTEND_X 32
59#define MAP_EXTEND_Y 512 84#define MAP_EXTEND_Y 512
60 85
61#define MIN_FONT_HEIGHT 10 86#define MIN_FONT_HEIGHT 10
62 87
63#if 0 88/* mask out modifiers we are not interested in */
64# define PARACHUTE SDL_INIT_NOPARACHUTE 89#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
65#else
66# define PARACHUTE 0
67#endif
68 90
69static AV *texture_av; 91static AV *texture_av;
70 92
71static struct 93static struct
72{ 94{
109 av_push (texture_av, (SV *)(size_t)name); 131 av_push (texture_av, (SV *)(size_t)name);
110 glDeleteTextures (1, &name); 132 glDeleteTextures (1, &name);
111} 133}
112 134
113#include "texcache.c" 135#include "texcache.c"
136#include "rendercache.c"
114 137
115#include "pango-font.c" 138#include "pango-font.c"
116#include "pango-fontmap.c" 139#include "pango-fontmap.c"
117#include "pango-render.c" 140#include "pango-render.c"
118 141
119typedef IV CFPlus__Channel; 142typedef IV DC__Channel;
120typedef SDL_RWops *CFPlus__RW; 143typedef SDL_RWops *DC__RW;
121typedef Mix_Chunk *CFPlus__MixChunk; 144typedef Mix_Chunk *DC__MixChunk;
122typedef Mix_Music *CFPlus__MixMusic; 145typedef Mix_Music *DC__MixMusic;
123 146
124typedef PangoFontDescription *CFPlus__Font; 147typedef PangoFontDescription *DC__Font;
125 148
126static int 149static int
127shape_attr_p (PangoLayoutRun *run) 150shape_attr_p (PangoLayoutRun *run)
128{ 151{
129 GSList *attrs = run->item->analysis.extra_attrs; 152 GSList *attrs = run->item->analysis.extra_attrs;
143 166
144typedef struct cf_layout { 167typedef struct cf_layout {
145 PangoLayout *pl; 168 PangoLayout *pl;
146 float r, g, b, a; // default color for rgba mode 169 float r, g, b, a; // default color for rgba mode
147 int base_height; 170 int base_height;
148 CFPlus__Font font; 171 DC__Font font;
172 rc_t *rc;
149} *CFPlus__Layout; 173} *DC__Layout;
150 174
151static CFPlus__Font default_font; 175static DC__Font default_font;
152static PangoContext *opengl_context; 176static PangoContext *opengl_context;
153static PangoFontMap *opengl_fontmap; 177static PangoFontMap *opengl_fontmap;
154 178
155static void 179static void
156substitute_func (FcPattern *pattern, gpointer data) 180substitute_func (FcPattern *pattern, gpointer data)
161#endif 185#endif
162 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 186 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
163} 187}
164 188
165static void 189static void
166layout_update_font (CFPlus__Layout self) 190layout_update_font (DC__Layout self)
167{ 191{
168 /* use a random scale factor to account for unknown descenders, 0.8 works 192 /* use a random scale factor to account for unknown descenders, 0.8 works
169 * reasonably well with bitstream vera 193 * reasonably well with dejavu/bistream fonts
170 */ 194 */
171 PangoFontDescription *font = self->font ? self->font : default_font; 195 PangoFontDescription *font = self->font ? self->font : default_font;
172 196
173 pango_font_description_set_absolute_size (font, 197 pango_font_description_set_absolute_size (font,
174 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); 198 MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10));
175 199
176 pango_layout_set_font_description (self->pl, font); 200 pango_layout_set_font_description (self->pl, font);
177} 201}
178 202
179static void 203static void
180layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 204layout_get_pixel_size (DC__Layout self, int *w, int *h)
181{ 205{
182 PangoRectangle rect; 206 PangoRectangle rect;
183 207
184 // get_pixel_* wrongly rounds down 208 // get_pixel_* wrongly rounds down
185 pango_layout_get_extents (self->pl, 0, &rect); 209 pango_layout_get_extents (self->pl, 0, &rect);
196 220
197typedef uint16_t tileid; 221typedef uint16_t tileid;
198typedef uint16_t faceid; 222typedef uint16_t faceid;
199 223
200typedef struct { 224typedef struct {
201 int name; 225 GLuint name;
202 int w, h; 226 int w, h;
203 float s, t; 227 float s, t;
204 uint8_t r, g, b, a; 228 uint8_t r, g, b, a;
205 tileid smoothtile; 229 tileid smoothtile;
206 uint8_t smoothlevel; 230 uint8_t smoothlevel;
224 int faces; tileid *face2tile; // [faceid] 248 int faces; tileid *face2tile; // [faceid]
225 int texs; maptex *tex; // [tileid] 249 int texs; maptex *tex; // [tileid]
226 250
227 int32_t rows; 251 int32_t rows;
228 maprow *row; 252 maprow *row;
229} *CFPlus__Map; 253} *DC__Map;
230 254
231static char * 255static char *
232prepend (char *ptr, int sze, int inc) 256prepend (char *ptr, int sze, int inc)
233{ 257{
234 char *p; 258 char *p;
272 self->texs *= 2; 296 self->texs *= 2;
273 } 297 }
274} 298}
275 299
276static maprow * 300static maprow *
277map_get_row (CFPlus__Map self, int y) 301map_get_row (DC__Map self, int y)
278{ 302{
279 if (0 > y) 303 if (0 > y)
280 { 304 {
281 int extend = - y + MAP_EXTEND_Y; 305 int extend = - y + MAP_EXTEND_Y;
282 Prepend (maprow, self->row, self->rows, extend); 306 Prepend (maprow, self->row, self->rows, extend);
320 344
321 return row->col + (x - row->c0); 345 return row->col + (x - row->c0);
322} 346}
323 347
324static mapcell * 348static mapcell *
325map_get_cell (CFPlus__Map self, int x, int y) 349map_get_cell (DC__Map self, int x, int y)
326{ 350{
327 return row_get_cell (map_get_row (self, y), x); 351 return row_get_cell (map_get_row (self, y), x);
328} 352}
329 353
330static void 354static void
331map_clear (CFPlus__Map self) 355map_clear (DC__Map self)
332{ 356{
333 int r; 357 int r;
334 358
335 for (r = 0; r < self->rows; r++) 359 for (r = 0; r < self->rows; r++)
336 Safefree (self->row[r].col); 360 Safefree (self->row[r].col);
343 self->oy = 0; 367 self->oy = 0;
344 self->row = 0; 368 self->row = 0;
345 self->rows = 0; 369 self->rows = 0;
346} 370}
347 371
372#define CELL_CLEAR(cell) \
373 do { \
374 if ((cell)->player) \
375 (cell)->tile [2] = 0; \
376 (cell)->darkness = 0; \
377 (cell)->stat_hp = 0; \
378 (cell)->flags = 0; \
379 (cell)->player = 0; \
380 } while (0)
381
348static void 382static void
349map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 383map_blank (DC__Map self, int x0, int y0, int w, int h)
350{ 384{
351 int x, y; 385 int x, y;
352 maprow *row; 386 maprow *row;
353 mapcell *cell; 387 mapcell *cell;
354 388
366 if (x >= row->c1) 400 if (x >= row->c1)
367 break; 401 break;
368 402
369 cell = row->col + x - row->c0; 403 cell = row->col + x - row->c0;
370 404
371 cell->darkness = 0; 405 CELL_CLEAR (cell);
372 cell->stat_hp = 0;
373 cell->flags = 0;
374 cell->player = 0;
375 } 406 }
376 } 407 }
377} 408}
378 409
379typedef struct { 410typedef struct {
433 n |= n >> 16; 464 n |= n >> 16;
434 465
435 return n + 1; 466 return n + 1;
436} 467}
437 468
469static unsigned int
470popcount (unsigned int n)
471{
472 n -= (n >> 1) & 0x55555555U;
473 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
474 n = ((n >> 4) + n) & 0x0f0f0f0fU;
475 n *= 0x01010101U;
476
477 return n >> 24;
478}
479
438/* SDL should provide this, really. */ 480/* SDL should provide this, really. */
439#define SDLK_MODIFIER_MIN 300 481#define SDLK_MODIFIER_MIN 300
440#define SDLK_MODIFIER_MAX 314 482#define SDLK_MODIFIER_MAX 314
441 483
442/******************************************************************************/ 484/******************************************************************************/
480 return 0; 522 return 0;
481 523
482 return 1; 524 return 1;
483} 525}
484 526
485MODULE = CFPlus PACKAGE = CFPlus 527MODULE = Deliantra::Client PACKAGE = DC
486 528
487PROTOTYPES: ENABLE 529PROTOTYPES: ENABLE
488 530
489BOOT: 531BOOT:
490{ 532{
491 HV *stash = gv_stashpv ("CFPlus", 1); 533 HV *stash = gv_stashpv ("DC", 1);
492 static const struct { 534 static const struct {
493 const char *name; 535 const char *name;
494 IV iv; 536 IV iv;
495 } *civ, const_iv[] = { 537 } *civ, const_iv[] = {
496# define const_iv(name) { # name, (IV)name } 538# define const_iv(name) { # name, (IV)name }
518 560
519 const_iv (SDL_APPINPUTFOCUS), 561 const_iv (SDL_APPINPUTFOCUS),
520 const_iv (SDL_APPMOUSEFOCUS), 562 const_iv (SDL_APPMOUSEFOCUS),
521 const_iv (SDL_APPACTIVE), 563 const_iv (SDL_APPACTIVE),
522 564
565 const_iv (SDLK_FIRST),
566 const_iv (SDLK_LAST),
523 const_iv (SDLK_KP0), 567 const_iv (SDLK_KP0),
524 const_iv (SDLK_KP1), 568 const_iv (SDLK_KP1),
525 const_iv (SDLK_KP2), 569 const_iv (SDLK_KP2),
526 const_iv (SDLK_KP3), 570 const_iv (SDLK_KP3),
527 const_iv (SDLK_KP4), 571 const_iv (SDLK_KP4),
599 const_iv (KMOD_LMETA), 643 const_iv (KMOD_LMETA),
600 const_iv (KMOD_RMETA), 644 const_iv (KMOD_RMETA),
601 const_iv (KMOD_NUM), 645 const_iv (KMOD_NUM),
602 const_iv (KMOD_CAPS), 646 const_iv (KMOD_CAPS),
603 const_iv (KMOD_MODE), 647 const_iv (KMOD_MODE),
648
649 const_iv (MIX_DEFAULT_FORMAT),
650
651 const_iv (SDL_INIT_TIMER),
652 const_iv (SDL_INIT_AUDIO),
653 const_iv (SDL_INIT_VIDEO),
654 const_iv (SDL_INIT_CDROM),
655 const_iv (SDL_INIT_JOYSTICK),
656 const_iv (SDL_INIT_EVERYTHING),
657 const_iv (SDL_INIT_NOPARACHUTE),
658 const_iv (SDL_INIT_EVENTTHREAD),
659
660 const_iv (SDL_GL_RED_SIZE),
661 const_iv (SDL_GL_GREEN_SIZE),
662 const_iv (SDL_GL_BLUE_SIZE),
663 const_iv (SDL_GL_ALPHA_SIZE),
664 const_iv (SDL_GL_DOUBLEBUFFER),
665 const_iv (SDL_GL_BUFFER_SIZE),
666 const_iv (SDL_GL_DEPTH_SIZE),
667 const_iv (SDL_GL_STENCIL_SIZE),
668 const_iv (SDL_GL_ACCUM_RED_SIZE),
669 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
670 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
671 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
672 const_iv (SDL_GL_STEREO),
673 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
674 const_iv (SDL_GL_MULTISAMPLESAMPLES),
675 const_iv (SDL_GL_ACCELERATED_VISUAL),
676 const_iv (SDL_GL_SWAP_CONTROL),
677
678 const_iv (FOW_DARKNESS)
604# undef const_iv 679# undef const_iv
605 }; 680 };
606 681
607 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 682 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
608 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 683 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
626 701
627NV floor (NV x) 702NV floor (NV x)
628 703
629NV ceil (NV x) 704NV ceil (NV x)
630 705
706NV ceilabs (NV x)
707 CODE:
708 RETVAL = x < 0. ? - ceil (-x) : ceil (x);
709 OUTPUT:
710 RETVAL
711
712IV minpot (UV n)
713
714IV popcount (UV n)
715
631void 716void
632pango_init () 717pango_init ()
633 CODE: 718 CODE:
634{ 719{
635 opengl_fontmap = pango_opengl_font_map_new (); 720 opengl_fontmap = pango_opengl_font_map_new ();
636 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); 721 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0);
637 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); 722 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
723 /*pango_context_set_font_description (opengl_context, default_font);*/
724#if PANGO_VERSION_CHECK (1, 15, 2)
725 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
726 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
727#endif
638} 728}
639 729
640char *
641SDL_GetError () 730char *SDL_GetError ()
642 731
643int 732int SDL_Init (U32 flags)
644SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
645 733
646void 734int SDL_InitSubSystem (U32 flags)
735
736void SDL_QuitSubSystem (U32 flags)
737
647SDL_Quit () 738void SDL_Quit ()
739
740int SDL_GL_SetAttribute (int attr, int value)
741
742int SDL_GL_GetAttribute (int attr)
743 CODE:
744 if (SDL_GL_GetAttribute (attr, &RETVAL))
745 XSRETURN_UNDEF;
746 OUTPUT:
747 RETVAL
648 748
649void 749void
650SDL_ListModes (int rgb, int alpha) 750SDL_ListModes (int rgb, int alpha)
651 PPCODE: 751 PPCODE:
652{ 752{
664 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 764 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
665 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 765 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
666 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 766 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
667 767
668 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 768 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
669#if SDL_VERSION_ATLEAST(1,2,10)
670 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
671 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 769 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
672#endif
673 770
674 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 771 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
675 772
676 if (m && m != (SDL_Rect **)-1) 773 if (m && m != (SDL_Rect **)-1)
677 while (*m) 774 while (*m)
678 { 775 {
679 if ((*m)->w >= 640 && (*m)->h >= 480) 776 if ((*m)->w >= 400 && (*m)->h >= 300)
680 { 777 {
681 AV *av = newAV (); 778 AV *av = newAV ();
682 av_push (av, newSViv ((*m)->w)); 779 av_push (av, newSViv ((*m)->w));
683 av_push (av, newSViv ((*m)->h)); 780 av_push (av, newSViv ((*m)->h));
684 av_push (av, newSViv (rgb)); 781 av_push (av, newSViv (rgb));
708 805
709 if (RETVAL) 806 if (RETVAL)
710 { 807 {
711 av_clear (texture_av); 808 av_clear (texture_av);
712 809
713 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 810 SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra");
714#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 811#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
715#include "glfunc.h" 812#include "glfunc.h"
716#undef GL_FUNC 813#undef GL_FUNC
717 } 814 }
718} 815}
725char * 822char *
726SDL_GetKeyName (int sym) 823SDL_GetKeyName (int sym)
727 824
728int 825int
729SDL_GetAppState () 826SDL_GetAppState ()
827
828int
829SDL_GetModState ()
730 830
731void 831void
732poll_events () 832poll_events ()
733 PPCODE: 833 PPCODE:
734{ 834{
744 { 844 {
745 case SDL_KEYDOWN: 845 case SDL_KEYDOWN:
746 case SDL_KEYUP: 846 case SDL_KEYUP:
747 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 847 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
748 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 848 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
749 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 849 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0);
750 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ 850 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */
751 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 851 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
752 break; 852 break;
753 853
754 case SDL_ACTIVEEVENT: 854 case SDL_ACTIVEEVENT:
755 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 855 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
773 x = ev.motion.x; 873 x = ev.motion.x;
774 y = ev.motion.y; 874 y = ev.motion.y;
775 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 875 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
776 } 876 }
777 877
778 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 878 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
779 hv_store (hv, "state", 5, newSViv (state), 0); 879 hv_store (hv, "state", 5, newSViv (state), 0);
780 hv_store (hv, "x", 1, newSViv (x), 0); 880 hv_store (hv, "x", 1, newSViv (x), 0);
781 hv_store (hv, "y", 1, newSViv (y), 0); 881 hv_store (hv, "y", 1, newSViv (y), 0);
782 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 882 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
783 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 883 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
784 } 884 }
785 break; 885 break;
786 886
787 case SDL_MOUSEBUTTONDOWN: 887 case SDL_MOUSEBUTTONDOWN:
788 case SDL_MOUSEBUTTONUP: 888 case SDL_MOUSEBUTTONUP:
789 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 889 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
790 890
791 hv_store (hv, "button", 6, newSViv (ev.button.button), 0); 891 hv_store (hv, "button", 6, newSViv (ev.button.button), 0);
792 hv_store (hv, "state", 5, newSViv (ev.button.state), 0); 892 hv_store (hv, "state", 5, newSViv (ev.button.state), 0);
793 hv_store (hv, "x", 1, newSViv (ev.button.x), 0); 893 hv_store (hv, "x", 1, newSViv (ev.button.x), 0);
794 hv_store (hv, "y", 1, newSViv (ev.button.y), 0); 894 hv_store (hv, "y", 1, newSViv (ev.button.y), 0);
799 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 899 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
800 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 900 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
801 break; 901 break;
802 } 902 }
803 903
804 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 904 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
805 } 905 }
806} 906}
807 907
808int 908int
809Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) 909Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
810 POSTCALL: 910 POSTCALL:
811 Mix_HookMusicFinished (music_finished); 911 Mix_HookMusicFinished (music_finished);
812 Mix_ChannelFinished (channel_finished); 912 Mix_ChannelFinished (channel_finished);
913
914void
915Mix_QuerySpec ()
916 PPCODE:
917{
918 int freq, channels;
919 Uint16 format;
920
921 if (Mix_QuerySpec (&freq, &format, &channels))
922 {
923 EXTEND (SP, 3);
924 PUSHs (sv_2mortal (newSViv (freq)));
925 PUSHs (sv_2mortal (newSViv (format)));
926 PUSHs (sv_2mortal (newSViv (channels)));
927 }
928}
813 929
814void 930void
815Mix_CloseAudio () 931Mix_CloseAudio ()
816 932
817int 933int
852 } 968 }
853 } 969 }
854#endif 970#endif
855} 971}
856 972
857void 973int
858add_font (char *file) 974add_font (char *file)
859 CODE: 975 CODE:
860 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 976 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
977 OUTPUT:
978 RETVAL
861 979
862void 980void
863load_image_inline (SV *image_) 981load_image_inline (SV *image_)
864 ALIAS: 982 ALIAS:
865 load_image_file = 1 983 load_image_file = 1
951void 1069void
952error (char *message) 1070error (char *message)
953 CODE: 1071 CODE:
954 fprintf (stderr, "ERROR: %s\n", message); 1072 fprintf (stderr, "ERROR: %s\n", message);
955#ifdef _WIN32 1073#ifdef _WIN32
956 MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); 1074 MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR);
957#endif 1075#endif
958 1076
959void 1077void
960fatal (char *message) 1078fatal (char *message)
961 CODE: 1079 CODE:
962 fprintf (stderr, "FATAL: %s\n", message); 1080 fprintf (stderr, "FATAL: %s\n", message);
963#ifdef _WIN32 1081#ifdef _WIN32
964 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 1082 MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR);
965#endif 1083#endif
966 _exit (1); 1084 _exit (1);
967 1085
968void 1086void
969_exit (int retval = 0) 1087_exit (int retval = 0)
981#if DEBUG 1099#if DEBUG
982 VALGRIND_DO_LEAK_CHECK; 1100 VALGRIND_DO_LEAK_CHECK;
983#endif 1101#endif
984} 1102}
985 1103
986MODULE = CFPlus PACKAGE = CFPlus::Font 1104MODULE = Deliantra::Client PACKAGE = DC::Font
987 1105
988PROTOTYPES: DISABLE 1106PROTOTYPES: DISABLE
989 1107
990CFPlus::Font 1108DC::Font
991new_from_file (SV *class, char *path, int id = 0) 1109new_from_file (SV *class, char *path, int id = 0)
992 CODE: 1110 CODE:
993{ 1111{
994 int count; 1112 int count;
995 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1113 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
998} 1116}
999 OUTPUT: 1117 OUTPUT:
1000 RETVAL 1118 RETVAL
1001 1119
1002void 1120void
1003DESTROY (CFPlus::Font self) 1121DESTROY (DC::Font self)
1004 CODE: 1122 CODE:
1005 pango_font_description_free (self); 1123 pango_font_description_free (self);
1006 1124
1007void 1125void
1008make_default (CFPlus::Font self) 1126make_default (DC::Font self)
1009 PROTOTYPE: $ 1127 PROTOTYPE: $
1010 CODE: 1128 CODE:
1011 default_font = self; 1129 default_font = self;
1012 1130
1013MODULE = CFPlus PACKAGE = CFPlus::Layout 1131MODULE = Deliantra::Client PACKAGE = DC::Layout
1014 1132
1015PROTOTYPES: DISABLE 1133PROTOTYPES: DISABLE
1016 1134
1017void 1135void
1018reset_glyph_cache () 1136glyph_cache_backup ()
1019 PROTOTYPE: 1137 PROTOTYPE:
1020 CODE: 1138 CODE:
1139 tc_backup ();
1140
1141void
1142glyph_cache_restore ()
1143 PROTOTYPE:
1144 CODE:
1021 tc_clear (); 1145 tc_restore ();
1022 1146
1023CFPlus::Layout 1147DC::Layout
1024new (SV *class) 1148new (SV *class)
1025 CODE: 1149 CODE:
1026 New (0, RETVAL, 1, struct cf_layout); 1150 New (0, RETVAL, 1, struct cf_layout);
1027 1151
1028 RETVAL->pl = pango_layout_new (opengl_context); 1152 RETVAL->pl = pango_layout_new (opengl_context);
1030 RETVAL->g = 1.; 1154 RETVAL->g = 1.;
1031 RETVAL->b = 1.; 1155 RETVAL->b = 1.;
1032 RETVAL->a = 1.; 1156 RETVAL->a = 1.;
1033 RETVAL->base_height = MIN_FONT_HEIGHT; 1157 RETVAL->base_height = MIN_FONT_HEIGHT;
1034 RETVAL->font = 0; 1158 RETVAL->font = 0;
1159 RETVAL->rc = rc_alloc ();
1035 1160
1036 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1161 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1037 layout_update_font (RETVAL); 1162 layout_update_font (RETVAL);
1038 OUTPUT: 1163 OUTPUT:
1039 RETVAL 1164 RETVAL
1040 1165
1041void 1166void
1042DESTROY (CFPlus::Layout self) 1167DESTROY (DC::Layout self)
1043 CODE: 1168 CODE:
1044 g_object_unref (self->pl); 1169 g_object_unref (self->pl);
1170 rc_free (self->rc);
1045 Safefree (self); 1171 Safefree (self);
1046 1172
1047void 1173void
1048set_text (CFPlus::Layout self, SV *text_) 1174set_text (DC::Layout self, SV *text_)
1049 CODE: 1175 CODE:
1050{ 1176{
1051 STRLEN textlen; 1177 STRLEN textlen;
1052 char *text = SvPVutf8 (text_, textlen); 1178 char *text = SvPVutf8 (text_, textlen);
1053 1179
1054 pango_layout_set_text (self->pl, text, textlen); 1180 pango_layout_set_text (self->pl, text, textlen);
1055} 1181}
1056 1182
1057void 1183void
1058set_markup (CFPlus::Layout self, SV *text_) 1184set_markup (DC::Layout self, SV *text_)
1059 CODE: 1185 CODE:
1060{ 1186{
1061 STRLEN textlen; 1187 STRLEN textlen;
1062 char *text = SvPVutf8 (text_, textlen); 1188 char *text = SvPVutf8 (text_, textlen);
1063 1189
1064 pango_layout_set_markup (self->pl, text, textlen); 1190 pango_layout_set_markup (self->pl, text, textlen);
1065} 1191}
1066 1192
1067void 1193void
1068set_shapes (CFPlus::Layout self, ...) 1194set_shapes (DC::Layout self, ...)
1069 CODE: 1195 CODE:
1070{ 1196{
1071 PangoAttrList *attrs = 0; 1197 PangoAttrList *attrs = 0;
1072 const char *text = pango_layout_get_text (self->pl); 1198 const char *text = pango_layout_get_text (self->pl);
1073 const char *pos = text; 1199 const char *pos = text;
1108 if (attrs) 1234 if (attrs)
1109 pango_layout_set_attributes (self->pl, attrs); 1235 pango_layout_set_attributes (self->pl, attrs);
1110} 1236}
1111 1237
1112void 1238void
1113get_shapes (CFPlus::Layout self) 1239get_shapes (DC::Layout self)
1114 PPCODE: 1240 PPCODE:
1115{ 1241{
1116 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 1242 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
1117 1243
1118 do 1244 do
1119 { 1245 {
1120 PangoLayoutRun *run = pango_layout_iter_get_run (iter); 1246 PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter);
1121 1247
1122 if (run && shape_attr_p (run)) 1248 if (run && shape_attr_p (run))
1123 { 1249 {
1124 PangoRectangle extents; 1250 PangoRectangle extents;
1125 pango_layout_iter_get_run_extents (iter, 0, &extents); 1251 pango_layout_iter_get_run_extents (iter, 0, &extents);
1133 1259
1134 pango_layout_iter_free (iter); 1260 pango_layout_iter_free (iter);
1135} 1261}
1136 1262
1137int 1263int
1138has_wrapped (CFPlus::Layout self) 1264has_wrapped (DC::Layout self)
1139 CODE: 1265 CODE:
1140{ 1266{
1141 int lines = 1; 1267 int lines = 1;
1142 const char *text = pango_layout_get_text (self->pl); 1268 const char *text = pango_layout_get_text (self->pl);
1143 1269
1148} 1274}
1149 OUTPUT: 1275 OUTPUT:
1150 RETVAL 1276 RETVAL
1151 1277
1152SV * 1278SV *
1153get_text (CFPlus::Layout self) 1279get_text (DC::Layout self)
1154 CODE: 1280 CODE:
1155 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 1281 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
1156 sv_utf8_decode (RETVAL); 1282 sv_utf8_decode (RETVAL);
1157 OUTPUT: 1283 OUTPUT:
1158 RETVAL 1284 RETVAL
1159 1285
1160void 1286void
1161set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) 1287set_foreground (DC::Layout self, float r, float g, float b, float a = 1.)
1162 CODE: 1288 CODE:
1163 self->r = r; 1289 self->r = r;
1164 self->g = g; 1290 self->g = g;
1165 self->b = b; 1291 self->b = b;
1166 self->a = a; 1292 self->a = a;
1167 1293
1168void 1294void
1169set_font (CFPlus::Layout self, CFPlus::Font font = 0) 1295set_font (DC::Layout self, DC::Font font = 0)
1170 CODE: 1296 CODE:
1171 if (self->font != font) 1297 if (self->font != font)
1172 { 1298 {
1173 self->font = font; 1299 self->font = font;
1174 layout_update_font (self); 1300 layout_update_font (self);
1175 } 1301 }
1176 1302
1177void 1303void
1178set_height (CFPlus::Layout self, int base_height) 1304set_height (DC::Layout self, int base_height)
1179 CODE: 1305 CODE:
1180 if (self->base_height != base_height) 1306 if (self->base_height != base_height)
1181 { 1307 {
1182 self->base_height = base_height; 1308 self->base_height = base_height;
1183 layout_update_font (self); 1309 layout_update_font (self);
1184 } 1310 }
1185 1311
1186void 1312void
1187set_width (CFPlus::Layout self, int max_width = -1) 1313set_width (DC::Layout self, int max_width = -1)
1188 CODE: 1314 CODE:
1189 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 1315 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
1190 1316
1191void 1317void
1192set_indent (CFPlus::Layout self, int indent) 1318set_indent (DC::Layout self, int indent)
1193 CODE: 1319 CODE:
1194 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 1320 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
1195 1321
1196void 1322void
1197set_spacing (CFPlus::Layout self, int spacing) 1323set_spacing (DC::Layout self, int spacing)
1198 CODE: 1324 CODE:
1199 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 1325 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
1200 1326
1201void 1327void
1202set_ellipsise (CFPlus::Layout self, int ellipsise) 1328set_ellipsise (DC::Layout self, int ellipsise)
1203 CODE: 1329 CODE:
1204 pango_layout_set_ellipsize (self->pl, 1330 pango_layout_set_ellipsize (self->pl,
1205 ellipsise == 1 ? PANGO_ELLIPSIZE_START 1331 ellipsise == 1 ? PANGO_ELLIPSIZE_START
1206 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 1332 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
1207 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 1333 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
1208 : PANGO_ELLIPSIZE_NONE 1334 : PANGO_ELLIPSIZE_NONE
1209 ); 1335 );
1210 1336
1211void 1337void
1212set_single_paragraph_mode (CFPlus::Layout self, int spm) 1338set_single_paragraph_mode (DC::Layout self, int spm)
1213 CODE: 1339 CODE:
1214 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 1340 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
1215 1341
1216void 1342void
1217size (CFPlus::Layout self) 1343size (DC::Layout self)
1218 PPCODE: 1344 PPCODE:
1219{ 1345{
1220 int w, h; 1346 int w, h;
1221 1347
1222 layout_get_pixel_size (self, &w, &h); 1348 layout_get_pixel_size (self, &w, &h);
1225 PUSHs (sv_2mortal (newSViv (w))); 1351 PUSHs (sv_2mortal (newSViv (w)));
1226 PUSHs (sv_2mortal (newSViv (h))); 1352 PUSHs (sv_2mortal (newSViv (h)));
1227} 1353}
1228 1354
1229int 1355int
1230descent (CFPlus::Layout self) 1356descent (DC::Layout self)
1231 CODE: 1357 CODE:
1232{ 1358{
1233 PangoRectangle rect; 1359 PangoRectangle rect;
1234 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1360 PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0);
1235 pango_layout_line_get_pixel_extents (line, 0, &rect); 1361 pango_layout_line_get_pixel_extents (line, 0, &rect);
1236 RETVAL = PANGO_DESCENT (rect); 1362 RETVAL = PANGO_DESCENT (rect);
1237} 1363}
1238 OUTPUT: 1364 OUTPUT:
1239 RETVAL 1365 RETVAL
1240 1366
1241int 1367int
1242xy_to_index (CFPlus::Layout self, int x, int y) 1368xy_to_index (DC::Layout self, int x, int y)
1243 CODE: 1369 CODE:
1244{ 1370{
1245 int index, trailing; 1371 int index, trailing;
1246 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1372 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1247 RETVAL = index + trailing; 1373 RETVAL = index + trailing;
1248} 1374}
1249 OUTPUT: 1375 OUTPUT:
1250 RETVAL 1376 RETVAL
1251 1377
1252void 1378void
1253cursor_pos (CFPlus::Layout self, int index) 1379cursor_pos (DC::Layout self, int index)
1254 PPCODE: 1380 PPCODE:
1255{ 1381{
1256 PangoRectangle strong_pos; 1382 PangoRectangle pos;
1257 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1383 pango_layout_get_cursor_pos (self->pl, index, &pos, 0);
1258 1384
1259 EXTEND (SP, 3); 1385 EXTEND (SP, 3);
1260 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1386 PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE)));
1261 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1387 PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE)));
1262 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1388 PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE)));
1263} 1389}
1264 1390
1265void 1391void
1266index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) 1392index_to_line_x (DC::Layout self, int index, int trailing = 0)
1267 PPCODE: 1393 PPCODE:
1268{ 1394{
1269 int line, x; 1395 int line, x;
1270 1396
1271 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); 1397 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1398#if !PANGO_VERSION_CHECK (1, 17, 3)
1272 /* pango bug: line is between 1..numlines, not 0..numlines-1 */ 1399 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1273 1400 --line;
1401#endif
1274 EXTEND (SP, 2); 1402 EXTEND (SP, 2);
1275 PUSHs (sv_2mortal (newSViv (line - 1))); 1403 PUSHs (sv_2mortal (newSViv (line)));
1276 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); 1404 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1277} 1405}
1278 1406
1279void 1407void
1280line_x_to_index (CFPlus::Layout self, int line, int x) 1408line_x_to_index (DC::Layout self, int line, int x)
1281 PPCODE: 1409 PPCODE:
1282{ 1410{
1283 PangoLayoutLine *lp; 1411 PangoLayoutLine *lp;
1284 int index, trailing; 1412 int index, trailing;
1285 1413
1286 if (line < 0) 1414 if (line < 0)
1287 XSRETURN_EMPTY; 1415 XSRETURN_EMPTY;
1288 1416
1289 if (!(lp = pango_layout_get_line (self->pl, line))) 1417 if (!(lp = pango_layout_get_line_readonly (self->pl, line)))
1290 XSRETURN_EMPTY; /* do better */ 1418 XSRETURN_EMPTY; /* do better */
1291 1419
1292 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); 1420 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1293 1421
1294 EXTEND (SP, 2); 1422 EXTEND (SP, 2);
1300 PUSHs (sv_2mortal (newSViv (trailing))); 1428 PUSHs (sv_2mortal (newSViv (trailing)));
1301 } 1429 }
1302} 1430}
1303 1431
1304void 1432void
1305render (CFPlus::Layout self, float x, float y, int flags = 0) 1433render (DC::Layout self, float x, float y, int flags = 0)
1306 PPCODE: 1434 CODE:
1435 rc_clear (self->rc);
1307 pango_opengl_render_layout_subpixel ( 1436 pango_opengl_render_layout_subpixel (
1308 self->pl, 1437 self->pl,
1438 self->rc,
1309 x * PANGO_SCALE, y * PANGO_SCALE, 1439 x * PANGO_SCALE, y * PANGO_SCALE,
1310 self->r, self->g, self->b, self->a, 1440 self->r, self->g, self->b, self->a,
1311 flags 1441 flags
1312 ); 1442 );
1443 // we assume that context_change actually clears/frees stuff
1444 // and does not do any recomputation...
1445 pango_layout_context_changed (self->pl);
1313 1446
1314MODULE = CFPlus PACKAGE = CFPlus::Texture 1447void
1448draw (DC::Layout self)
1449 CODE:
1450{
1451 glEnable (GL_TEXTURE_2D);
1452 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1453 glEnable (GL_BLEND);
1454 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1455 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1456 glEnable (GL_ALPHA_TEST);
1457 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1458
1459 rc_draw (self->rc);
1460
1461 glDisable (GL_ALPHA_TEST);
1462 glDisable (GL_BLEND);
1463 glDisable (GL_TEXTURE_2D);
1464}
1465
1466MODULE = Deliantra::Client PACKAGE = DC::Texture
1315 1467
1316PROTOTYPES: ENABLE 1468PROTOTYPES: ENABLE
1317
1318int minpot (int n)
1319 1469
1320void 1470void
1321pad (SV *data_, int ow, int oh, int nw, int nh) 1471pad (SV *data_, int ow, int oh, int nw, int nh)
1322 CODE: 1472 CODE:
1323{ 1473{
1400 RETVAL = width > 0; 1550 RETVAL = width > 0;
1401} 1551}
1402 OUTPUT: 1552 OUTPUT:
1403 RETVAL 1553 RETVAL
1404 1554
1405MODULE = CFPlus PACKAGE = CFPlus::Map 1555MODULE = Deliantra::Client PACKAGE = DC::Map
1406 1556
1407PROTOTYPES: DISABLE 1557PROTOTYPES: DISABLE
1408 1558
1409CFPlus::Map 1559DC::Map
1410new (SV *class) 1560new (SV *class)
1411 CODE: 1561 CODE:
1412 New (0, RETVAL, 1, struct map); 1562 New (0, RETVAL, 1, struct map);
1413 RETVAL->x = 0; 1563 RETVAL->x = 0;
1414 RETVAL->y = 0; 1564 RETVAL->y = 0;
1422 RETVAL->row = 0; 1572 RETVAL->row = 0;
1423 OUTPUT: 1573 OUTPUT:
1424 RETVAL 1574 RETVAL
1425 1575
1426void 1576void
1427DESTROY (CFPlus::Map self) 1577DESTROY (DC::Map self)
1428 CODE: 1578 CODE:
1429{ 1579{
1430 map_clear (self); 1580 map_clear (self);
1431 Safefree (self->face2tile); 1581 Safefree (self->face2tile);
1432 Safefree (self->tex); 1582 Safefree (self->tex);
1433 Safefree (self); 1583 Safefree (self);
1434} 1584}
1435 1585
1436void 1586void
1437resize (CFPlus::Map self, int map_width, int map_height) 1587resize (DC::Map self, int map_width, int map_height)
1438 CODE: 1588 CODE:
1439 self->w = map_width; 1589 self->w = map_width;
1440 self->h = map_height; 1590 self->h = map_height;
1441 1591
1442void 1592void
1443clear (CFPlus::Map self) 1593clear (DC::Map self)
1444 CODE: 1594 CODE:
1445 map_clear (self); 1595 map_clear (self);
1446 1596
1447void 1597void
1448set_tileid (CFPlus::Map self, int face, int tile) 1598set_tileid (DC::Map self, int face, int tile)
1449 CODE: 1599 CODE:
1450{ 1600{
1451 need_facenum (self, face); self->face2tile [face] = tile; 1601 need_facenum (self, face); self->face2tile [face] = tile;
1452 need_texid (self, tile); 1602 need_texid (self, tile);
1453} 1603}
1454 1604
1455void 1605void
1456set_smooth (CFPlus::Map self, int face, int smooth, int level) 1606set_smooth (DC::Map self, int face, int smooth, int level)
1457 CODE: 1607 CODE:
1458{ 1608{
1459 tileid texid; 1609 tileid texid;
1460 maptex *tex; 1610 maptex *tex;
1461 1611
1474 tex->smoothtile = self->face2tile [smooth]; 1624 tex->smoothtile = self->face2tile [smooth];
1475 tex->smoothlevel = level; 1625 tex->smoothlevel = level;
1476} 1626}
1477 1627
1478void 1628void
1479set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1629set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1480 CODE: 1630 CODE:
1481{ 1631{
1482 need_texid (self, texid); 1632 need_texid (self, texid);
1483 1633
1484 { 1634 {
1504 // from transparent color bleeding and ugly wrapping effects. 1654 // from transparent color bleeding and ugly wrapping effects.
1505 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1655 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1506} 1656}
1507 1657
1508int 1658int
1509ox (CFPlus::Map self) 1659ox (DC::Map self)
1510 ALIAS: 1660 ALIAS:
1511 oy = 1 1661 oy = 1
1512 x = 2 1662 x = 2
1513 y = 3 1663 y = 3
1514 w = 4 1664 w = 4
1525 } 1675 }
1526 OUTPUT: 1676 OUTPUT:
1527 RETVAL 1677 RETVAL
1528 1678
1529void 1679void
1530scroll (CFPlus::Map self, int dx, int dy) 1680scroll (DC::Map self, int dx, int dy)
1531 CODE: 1681 CODE:
1532{ 1682{
1533 if (dx > 0) 1683 if (dx > 0)
1534 map_blank (self, self->x, self->y, dx, self->h); 1684 map_blank (self, self->x, self->y, dx, self->h);
1535 else if (dx < 0) 1685 else if (dx < 0)
1550 self->rows += MAP_EXTEND_Y; 1700 self->rows += MAP_EXTEND_Y;
1551 self->y += MAP_EXTEND_Y; 1701 self->y += MAP_EXTEND_Y;
1552 } 1702 }
1553} 1703}
1554 1704
1555void 1705SV *
1556map1a_update (CFPlus::Map self, SV *data_, int extmap) 1706map1a_update (DC::Map self, SV *data_, int extmap)
1557 CODE: 1707 CODE:
1558{ 1708{
1559 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1709 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1560 uint8_t *data_end = (uint8_t *)SvEND (data_); 1710 uint8_t *data_end = (uint8_t *)SvEND (data_);
1561 mapcell *cell; 1711 mapcell *cell;
1562 int x, y, flags; 1712 int x, y, z, flags;
1713 AV *missing = newAV ();
1714 RETVAL = newRV_noinc ((SV *)missing);
1563 1715
1564 while (data < data_end - 1) 1716 while (data < data_end - 1)
1565 { 1717 {
1566 flags = (data [0] << 8) + data [1]; data += 2; 1718 flags = (data [0] << 8) + data [1]; data += 2;
1567 1719
1587 uint8_t ext, cmd; 1739 uint8_t ext, cmd;
1588 1740
1589 do 1741 do
1590 { 1742 {
1591 ext = *data++; 1743 ext = *data++;
1592 cmd = ext & 0x3f; 1744 cmd = ext & 0x7f;
1593 1745
1594 if (cmd < 4) 1746 if (cmd < 4)
1595 cell->darkness = 255 - ext * 64 + 1; 1747 cell->darkness = 255 - ext * 64 + 1;
1596 else if (cmd == 5) // health 1748 else if (cmd == 5) // health
1597 { 1749 {
1600 } 1752 }
1601 else if (cmd == 6) // monster width 1753 else if (cmd == 6) // monster width
1602 cell->stat_width = *data++ + 1; 1754 cell->stat_width = *data++ + 1;
1603 else if (cmd == 0x47) 1755 else if (cmd == 0x47)
1604 { 1756 {
1605 if (*data == 4) 1757 if (*data == 1) cell->player = data [1];
1606 ; // decode player count 1758 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
1759 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
1760 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
1607 1761
1608 data += *data + 1; 1762 data += *data + 1;
1609 } 1763 }
1610 else if (cmd == 8) // cell flags 1764 else if (cmd == 8) // cell flags
1611 cell->flags = *data++; 1765 cell->flags = *data++;
1618 } 1772 }
1619 else 1773 else
1620 cell->darkness = *data++ + 1; 1774 cell->darkness = *data++ + 1;
1621 } 1775 }
1622 1776
1777 for (z = 0; z <= 2; ++z)
1623 if (flags & 4) 1778 if (flags & (4 >> z))
1624 { 1779 {
1625 faceid face = (data [0] << 8) + data [1]; data += 2; 1780 faceid face = (data [0] << 8) + data [1]; data += 2;
1626 need_facenum (self, face); 1781 need_facenum (self, face);
1627 cell->tile [0] = self->face2tile [face]; 1782 cell->tile [z] = self->face2tile [face];
1783
1784 if (cell->tile [z])
1785 {
1786 maptex *tex = self->tex + cell->tile [z];
1787 if (!tex->name)
1788 av_push (missing, newSViv (cell->tile [z]));
1789
1790 if (tex->smoothtile)
1791 {
1792 maptex *smooth = self->tex + tex->smoothtile;
1793 if (!smooth->name)
1794 av_push (missing, newSViv (tex->smoothtile));
1795 }
1796 }
1628 } 1797 }
1629
1630 if (flags & 2)
1631 {
1632 faceid face = (data [0] << 8) + data [1]; data += 2;
1633 need_facenum (self, face);
1634 cell->tile [1] = self->face2tile [face];
1635 }
1636
1637 if (flags & 1)
1638 {
1639 faceid face = (data [0] << 8) + data [1]; data += 2;
1640 need_facenum (self, face);
1641 cell->tile [2] = self->face2tile [face];
1642 }
1643 } 1798 }
1644 else 1799 else
1645 cell->darkness = 0; 1800 CELL_CLEAR (cell);
1646 } 1801 }
1647} 1802}
1803 OUTPUT:
1804 RETVAL
1648 1805
1649SV * 1806SV *
1650mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1807mapmap (DC::Map self, int x0, int y0, int w, int h)
1651 CODE: 1808 CODE:
1652{ 1809{
1653 int x1, x; 1810 int x1, x;
1654 int y1, y; 1811 int y1, y;
1655 int z; 1812 int z;
1699 RETVAL = map_sv; 1856 RETVAL = map_sv;
1700} 1857}
1701 OUTPUT: 1858 OUTPUT:
1702 RETVAL 1859 RETVAL
1703 1860
1704SV * 1861void
1705draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1862draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1706 CODE: 1863 CODE:
1707{ 1864{
1865 int x, y, z;
1866
1708 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1867 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1709 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1868 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1710 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1869 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1711 smooth_key skey; 1870 smooth_key skey;
1712 int x, y, z; 1871 int pl_x, pl_y;
1713 int last_name; 1872 maptex pl_tex;
1714 AV *missing = newAV (); 1873 rc_t *rc = rc_alloc ();
1715 RETVAL = newRV_noinc ((SV *)missing); 1874 rc_key_t key;
1875 rc_array_t *arr;
1876
1877 pl_tex.name = 0;
1716 1878
1717 // thats current max. sorry. 1879 // thats current max. sorry.
1718 if (sw > 255) sw = 255; 1880 if (sw > 255) sw = 255;
1719 if (sh > 255) sh = 255; 1881 if (sh > 255) sh = 255;
1720 1882
1721 // clear key, in case of extra padding 1883 // clear key, in case of extra padding
1722 memset (&skey, 0, sizeof (skey)); 1884 memset (&skey, 0, sizeof (skey));
1723 1885
1724 glColor4ub (255, 255, 255, 255); 1886 memset (&key, 0, sizeof (key));
1725 1887 key.r = 255;
1726 glEnable (GL_BLEND); 1888 key.g = 255;
1727 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1889 key.b = 255;
1728 glEnable (GL_TEXTURE_2D); 1890 key.a = 255;
1729 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1891 key.mode = GL_QUADS;
1730 1892 key.format = GL_T2F_V3F;
1731 glBegin (GL_QUADS);
1732
1733 last_name = -1; 1893 key.texname = -1;
1734 1894
1735 mx += self->x; 1895 mx += self->x;
1736 my += self->y; 1896 my += self->y;
1737 1897
1738 // first pass: determine smooth_max 1898 // first pass: determine smooth_max
1754 MAX (self->tex [cell->tile [0]].smoothlevel, 1914 MAX (self->tex [cell->tile [0]].smoothlevel,
1755 MAX (self->tex [cell->tile [1]].smoothlevel, 1915 MAX (self->tex [cell->tile [1]].smoothlevel,
1756 self->tex [cell->tile [2]].smoothlevel)); 1916 self->tex [cell->tile [2]].smoothlevel));
1757 } 1917 }
1758 } 1918 }
1919
1920 glEnable (GL_BLEND);
1921 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1922 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1759 1923
1760 for (z = 0; z <= 2; z++) 1924 for (z = 0; z <= 2; z++)
1761 { 1925 {
1762 memset (smooth_level, 0, sizeof (smooth_level)); 1926 memset (smooth_level, 0, sizeof (smooth_level));
1763 1927
1773 tileid tile = cell->tile [z]; 1937 tileid tile = cell->tile [z];
1774 1938
1775 if (tile) 1939 if (tile)
1776 { 1940 {
1777 maptex tex = self->tex [tile]; 1941 maptex tex = self->tex [tile];
1778 int px, py; 1942 int px = (x + 1) * T - tex.w;
1943 int py = (y + 1) * T - tex.h;
1779 1944
1780 // suppressing texture state switches here
1781 // is only moderately effective, but worth the extra effort
1782 if (last_name != tex.name) 1945 if (key.texname != tex.name)
1783 { 1946 {
1784 if (!tex.name) 1947 if (!tex.name)
1785 {
1786 av_push (missing, newSViv (tile));
1787 tex = self->tex [2]; /* missing, replace by noface */ 1948 tex = self->tex [2]; /* missing, replace by noface */
1788 }
1789 1949
1790 glEnd (); 1950 key.texname = tex.name;
1791 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1951 arr = rc_array (rc, &key);
1792 glBegin (GL_QUADS);
1793 } 1952 }
1794 1953
1795 px = (x + 1) * T - tex.w; 1954 if (expect_false (cell->player == player) && expect_false (z == 2))
1796 py = (y + 1) * T - tex.h;
1797
1798 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1799 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1800 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1801 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1802
1803 if (cell->flags && z == 2)
1804 { 1955 {
1956 pl_x = px;
1957 pl_y = py;
1958 pl_tex = tex;
1959 continue;
1960 }
1961
1962 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1963 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1964 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1965 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1966
1967 if (expect_false (cell->flags) && expect_false (z == 2))
1968 {
1969 // overlays such as the speech bubble, probably more to come
1805 if (cell->flags & 1) 1970 if (cell->flags & 1)
1806 { 1971 {
1807 maptex tex = self->tex [1]; 1972 maptex tex = self->tex [1];
1808 int px = x * T + T * 2 / 32; 1973 int px = x * T + T * 2 / 32;
1809 int py = y * T - T * 6 / 32; 1974 int py = y * T - T * 6 / 32;
1810 1975
1976 if (tex.name)
1811 glEnd (); 1977 {
1812 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1978 if (key.texname != tex.name)
1979 {
1980 key.texname = tex.name;
1981 arr = rc_array (rc, &key);
1982 }
1983
1984 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1985 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
1986 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
1987 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
1813 glBegin (GL_QUADS); 1988 }
1814
1815 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1816 glTexCoord2f (0 , tex.t); glVertex2f (px , py + T);
1817 glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T);
1818 glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py );
1819 } 1989 }
1820 } 1990 }
1821 1991
1822 // update smooth hash 1992 // update smooth hash
1823 if (tex.smoothtile) 1993 if (tex.smoothtile)
1859 } 2029 }
1860 } 2030 }
1861 } 2031 }
1862 } 2032 }
1863 2033
2034 rc_draw (rc);
2035 rc_clear (rc);
2036
1864 // go through all smoothlevels, lowest to highest, then draw. 2037 // go through all smoothlevels, lowest to highest, then draw.
1865 // this is basically counting sort 2038 // this is basically counting sort
1866 { 2039 {
1867 int w, b; 2040 int w, b;
1868 2041
2042 glEnable (GL_TEXTURE_2D);
2043 glBegin (GL_QUADS);
1869 for (w = 0; w < 256 / 32; ++w) 2044 for (w = 0; w < 256 / 32; ++w)
1870 { 2045 {
1871 uint32_t smask = smooth_level [w]; 2046 uint32_t smask = smooth_level [w];
1872 if (smask) 2047 if (smask)
1873 for (b = 0; b < 32; ++b) 2048 for (b = 0; b < 32; ++b)
1892 int border = bits & 15; 2067 int border = bits & 15;
1893 int corner = (bits >> 8) & ~(bits >> 4) & 15; 2068 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1894 float dx = tex.s * .0625f; // 16 images/row 2069 float dx = tex.s * .0625f; // 16 images/row
1895 float dy = tex.t * .5f ; // 2 images/column 2070 float dy = tex.t * .5f ; // 2 images/column
1896 2071
1897 // this time naively avoiding texture state changes
1898 // save gobs of state changes.
1899 if (last_name != tex.name) 2072 if (tex.name)
1900 { 2073 {
2074 // this time avoiding texture state changes
2075 // save gobs of state changes.
1901 if (!tex.name) 2076 if (key.texname != tex.name)
1902 { 2077 {
1903 av_push (missing, newSViv (skey->tile)); 2078 glEnd ();
1904 continue; // smoothing not yet available 2079 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2080 glBegin (GL_QUADS);
1905 } 2081 }
1906 2082
1907 glEnd ();
1908 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1909 glBegin (GL_QUADS);
1910 }
1911
1912 if (border) 2083 if (border)
1913 { 2084 {
1914 float ox = border * dx; 2085 float ox = border * dx;
1915 2086
1916 glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); 2087 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1917 glTexCoord2f (ox , dy ); glVertex2f (px , py + T); 2088 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1918 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); 2089 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1919 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); 2090 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1920 } 2091 }
1921 2092
1922 if (corner) 2093 if (corner)
1923 { 2094 {
1924 float ox = corner * dx; 2095 float ox = corner * dx;
1925 2096
1926 glTexCoord2f (ox , dy ); glVertex2f (px , py ); 2097 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1927 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); 2098 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1928 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); 2099 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T);
1929 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); 2100 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
2101 }
1930 } 2102 }
1931 } 2103 }
1932 } 2104 }
1933 } 2105 }
1934 } 2106 }
2107
2108 glEnd ();
2109 glDisable (GL_TEXTURE_2D);
2110 key.texname = -1;
1935 } 2111 }
1936 2112
1937 hv_clear (smooth); 2113 hv_clear (smooth);
1938 } 2114 }
1939 2115
1940 glEnd (); 2116 if (pl_tex.name)
2117 {
2118 maptex tex = pl_tex;
2119 int px = pl_x + sdx;
2120 int py = pl_y + sdy;
1941 2121
1942 glDisable (GL_TEXTURE_2D); 2122 key.texname = tex.name;
2123 arr = rc_array (rc, &key);
2124
2125 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2126 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2127 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2128 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2129
2130 rc_draw (rc);
2131 }
2132
1943 glDisable (GL_BLEND); 2133 glDisable (GL_BLEND);
2134 rc_free (rc);
1944 2135
1945 // top layer: overlays such as the health bar 2136 // top layer: overlays such as the health bar
1946 for (y = 0; y < sh; y++) 2137 for (y = 0; y < sh; y++)
1947 if (0 <= y + my && y + my < self->rows) 2138 if (0 <= y + my && y + my < self->rows)
1948 { 2139 {
1971 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); 2162 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1972 } 2163 }
1973 } 2164 }
1974 } 2165 }
1975} 2166}
1976 OUTPUT:
1977 RETVAL
1978 2167
1979void 2168void
1980draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 2169draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data)
1981 CODE: 2170 CODE:
1982{ 2171{
1983 static float color[16][3] = { 2172 static float color[16][3] = {
1984 { 0.00F, 0.00F, 0.00F }, 2173 { 0.00F, 0.00F, 0.00F },
1985 { 1.00F, 1.00F, 1.00F }, 2174 { 1.00F, 1.00F, 1.00F },
2035 glDisable (GL_BLEND); 2224 glDisable (GL_BLEND);
2036 glDisable (GL_TEXTURE_2D); 2225 glDisable (GL_TEXTURE_2D);
2037} 2226}
2038 2227
2039void 2228void
2040fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) 2229fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2041 PPCODE: 2230 PPCODE:
2042{ 2231{
2043 int x, y; 2232 int x, y;
2044 int sw1 = sw + 2; 2233 int sw1 = sw + 2;
2045 int sh1 = sh + 2; 2234 int sh1 = sh + 2;
2053 SvCUR_set (darkness3_sv, sw34 * sh3); 2242 SvCUR_set (darkness3_sv, sw34 * sh3);
2054 2243
2055 mx += self->x - 1; 2244 mx += self->x - 1;
2056 my += self->y - 1; 2245 my += self->y - 1;
2057 2246
2058 memset (darkness1, 255, sw1 * sh1); 2247 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2059 2248
2060 for (y = 0; y < sh1; y++) 2249 for (y = 0; y < sh1; y++)
2061 if (0 <= y + my && y + my < self->rows) 2250 if (0 <= y + my && y + my < self->rows)
2062 { 2251 {
2063 maprow *row = self->row + (y + my); 2252 maprow *row = self->row + (y + my);
2116 PUSHs (sv_2mortal (newSViv (sh3))); 2305 PUSHs (sv_2mortal (newSViv (sh3)));
2117 PUSHs (darkness3_sv); 2306 PUSHs (darkness3_sv);
2118} 2307}
2119 2308
2120SV * 2309SV *
2121get_rect (CFPlus::Map self, int x0, int y0, int w, int h) 2310get_rect (DC::Map self, int x0, int y0, int w, int h)
2122 CODE: 2311 CODE:
2123{ 2312{
2124 int x, y, x1, y1; 2313 int x, y, x1, y1;
2125 SV *data_sv = newSV (w * h * 7 + 5); 2314 SV *data_sv = newSV (w * h * 7 + 5);
2126 uint8_t *data = (uint8_t *)SvPVX (data_sv); 2315 uint8_t *data = (uint8_t *)SvPVX (data_sv);
2183 else 2372 else
2184 *data++ = 0; 2373 *data++ = 0;
2185 } 2374 }
2186 } 2375 }
2187 2376
2377 /* if size is w*h + 5 then no data has been found */
2378 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2379 {
2188 SvPOK_only (data_sv); 2380 SvPOK_only (data_sv);
2189 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2381 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2382 }
2383
2190 RETVAL = data_sv; 2384 RETVAL = data_sv;
2191} 2385}
2192 OUTPUT: 2386 OUTPUT:
2193 RETVAL 2387 RETVAL
2194 2388
2195void 2389void
2196set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) 2390set_rect (DC::Map self, int x0, int y0, SV *data_sv)
2197 PPCODE: 2391 PPCODE:
2198{ 2392{
2199 int x, y, z; 2393 int x, y, z;
2200 int w, h; 2394 int w, h;
2201 int x1, y1; 2395 int x1, y1;
2396 STRLEN len;
2397 uint8_t *data, *end;
2398
2399 len = SvLEN (data_sv);
2400 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2401 data = SvPVbyte_nolen (data_sv);
2402 end = data + len + 8;
2403
2404 if (len < 5)
2405 XSRETURN_EMPTY;
2202 2406
2203 if (*data++ != 0) 2407 if (*data++ != 0)
2204 return; /* version mismatch */ 2408 XSRETURN_EMPTY; /* version mismatch */
2205 2409
2206 w = *data++ << 8; w |= *data++; 2410 w = *data++ << 8; w |= *data++;
2207 h = *data++ << 8; h |= *data++; 2411 h = *data++ << 8; h |= *data++;
2208 2412
2209 // we need to do this 'cause we don't keep an absolute coord system for rows 2413 // we need to do this 'cause we don't keep an absolute coord system for rows
2221 { 2425 {
2222 maprow *row = map_get_row (self, y); 2426 maprow *row = map_get_row (self, y);
2223 2427
2224 for (x = x0; x < x1; x++) 2428 for (x = x0; x < x1; x++)
2225 { 2429 {
2430 uint8_t flags;
2431
2432 if (data + 7 >= end)
2433 XSRETURN_EMPTY;
2434
2226 uint8_t flags = *data++; 2435 flags = *data++;
2227 2436
2228 if (flags) 2437 if (flags)
2229 { 2438 {
2230 mapcell *cell = row_get_cell (row, x); 2439 mapcell *cell = row_get_cell (row, x);
2231 tileid tile[3] = { 0, 0, 0 }; 2440 tileid tile[3] = { 0, 0, 0 };
2234 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } 2443 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
2235 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } 2444 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
2236 2445
2237 if (cell->darkness == 0) 2446 if (cell->darkness == 0)
2238 { 2447 {
2239 cell->darkness = 0; 2448 /*cell->darkness = 0;*/
2449 EXTEND (SP, 3);
2240 2450
2241 for (z = 0; z <= 2; z++) 2451 for (z = 0; z <= 2; z++)
2242 { 2452 {
2243 tileid t = tile [z]; 2453 tileid t = tile [z];
2244 2454
2245 if (t >= self->texs || (t && !self->tex [t].name)) 2455 if (t >= self->texs || (t && !self->tex [t].name))
2246 { 2456 {
2247 XPUSHs (sv_2mortal (newSViv (t))); 2457 PUSHs (sv_2mortal (newSViv (t)));
2248 need_texid (self, t); 2458 need_texid (self, t);
2249 } 2459 }
2250 2460
2251 cell->tile [z] = t; 2461 cell->tile [z] = t;
2252 } 2462 }
2254 } 2464 }
2255 } 2465 }
2256 } 2466 }
2257} 2467}
2258 2468
2259MODULE = CFPlus PACKAGE = CFPlus::RW 2469MODULE = Deliantra::Client PACKAGE = DC::RW
2260 2470
2261CFPlus::RW 2471DC::RW
2262new (SV *class, SV *data_sv) 2472new (SV *class, SV *data_sv)
2263 CODE: 2473 CODE:
2264{ 2474{
2265 STRLEN datalen; 2475 STRLEN datalen;
2266 char *data = SvPVbyte (data_sv, datalen); 2476 char *data = SvPVbyte (data_sv, datalen);
2268 RETVAL = SDL_RWFromConstMem (data, datalen); 2478 RETVAL = SDL_RWFromConstMem (data, datalen);
2269} 2479}
2270 OUTPUT: 2480 OUTPUT:
2271 RETVAL 2481 RETVAL
2272 2482
2273CFPlus::RW 2483DC::RW
2274new_from_file (SV *class, const char *path, const char *mode = "rb") 2484new_from_file (SV *class, const char *path, const char *mode = "rb")
2275 CODE: 2485 CODE:
2276 RETVAL = SDL_RWFromFile (path, mode); 2486 RETVAL = SDL_RWFromFile (path, mode);
2277 OUTPUT: 2487 OUTPUT:
2278 RETVAL 2488 RETVAL
2279 2489
2280# fails on win32: 2490# fails on win32:
2281# CFPlus.xs(2268) : error C2059: syntax error : '(' 2491# dc.xs(2268) : error C2059: syntax error : '('
2282#void 2492#void
2283#close (CFPlus::RW self) 2493#close (DC::RW self)
2284# CODE: 2494# CODE:
2285# (self->(close)) (self); 2495# (self->(close)) (self);
2286 2496
2287MODULE = CFPlus PACKAGE = CFPlus::Channel 2497MODULE = Deliantra::Client PACKAGE = DC::Channel
2288 2498
2289PROTOTYPES: DISABLE 2499PROTOTYPES: DISABLE
2290 2500
2291CFPlus::Channel 2501DC::Channel
2292find () 2502find ()
2293 CODE: 2503 CODE:
2294{ 2504{
2295 RETVAL = Mix_GroupAvailable (-1); 2505 RETVAL = Mix_GroupAvailable (-1);
2296 2506
2309} 2519}
2310 OUTPUT: 2520 OUTPUT:
2311 RETVAL 2521 RETVAL
2312 2522
2313void 2523void
2314halt (CFPlus::Channel self) 2524halt (DC::Channel self)
2315 CODE: 2525 CODE:
2316 Mix_HaltChannel (self); 2526 Mix_HaltChannel (self);
2317 2527
2318void 2528void
2319expire (CFPlus::Channel self, int ticks = -1) 2529expire (DC::Channel self, int ticks = -1)
2320 CODE: 2530 CODE:
2321 Mix_ExpireChannel (self, ticks); 2531 Mix_ExpireChannel (self, ticks);
2322 2532
2323void 2533void
2324fade_out (CFPlus::Channel self, int ticks = -1) 2534fade_out (DC::Channel self, int ticks = -1)
2325 CODE: 2535 CODE:
2326 Mix_FadeOutChannel (self, ticks); 2536 Mix_FadeOutChannel (self, ticks);
2327 2537
2328int 2538int
2329volume (CFPlus::Channel self, int volume) 2539volume (DC::Channel self, int volume)
2330 CODE: 2540 CODE:
2331 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); 2541 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2332 OUTPUT: 2542 OUTPUT:
2333 RETVAL 2543 RETVAL
2334 2544
2335void 2545void
2336unregister_all_effects (CFPlus::Channel self) 2546unregister_all_effects (DC::Channel self)
2337 CODE: 2547 CODE:
2338 Mix_UnregisterAllEffects (self); 2548 Mix_UnregisterAllEffects (self);
2339 2549
2340void 2550void
2341set_panning (CFPlus::Channel self, int left, int right) 2551set_panning (DC::Channel self, int left, int right)
2342 CODE: 2552 CODE:
2343 left = CLAMP (left , 0, 255); 2553 left = CLAMP (left , 0, 255);
2344 right = CLAMP (right, 0, 255); 2554 right = CLAMP (right, 0, 255);
2345 Mix_SetPanning (self, left, right); 2555 Mix_SetPanning (self, left, right);
2346 2556
2347void 2557void
2348set_distance (CFPlus::Channel self, int distance) 2558set_distance (DC::Channel self, int distance)
2349 CODE: 2559 CODE:
2350 Mix_SetDistance (self, CLAMP (distance, 0, 255)); 2560 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2351 2561
2352void 2562void
2353set_position (CFPlus::Channel self, int angle, int distance) 2563set_position (DC::Channel self, int angle, int distance)
2354 CODE: 2564 CODE:
2565
2566void
2567set_position_r (DC::Channel self, int dx, int dy, int maxdistance)
2568 CODE:
2569{
2570 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2571 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI);
2355 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); 2572 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2573}
2356 2574
2357void 2575void
2358set_reverse_stereo (CFPlus::Channel self, int flip) 2576set_reverse_stereo (DC::Channel self, int flip)
2359 CODE: 2577 CODE:
2360 Mix_SetReverseStereo (self, flip); 2578 Mix_SetReverseStereo (self, flip);
2361 2579
2362MODULE = CFPlus PACKAGE = CFPlus::MixChunk 2580MODULE = Deliantra::Client PACKAGE = DC::MixChunk
2363 2581
2364PROTOTYPES: DISABLE 2582PROTOTYPES: DISABLE
2365 2583
2366CFPlus::MixChunk 2584DC::MixChunk
2367new (SV *class, CFPlus::RW rwops) 2585new (SV *class, DC::RW rwops)
2368 CODE: 2586 CODE:
2369 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2587 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2370 OUTPUT: 2588 OUTPUT:
2371 RETVAL 2589 RETVAL
2372 2590
2373void 2591void
2374DESTROY (CFPlus::MixChunk self) 2592DESTROY (DC::MixChunk self)
2375 CODE: 2593 CODE:
2376 Mix_FreeChunk (self); 2594 Mix_FreeChunk (self);
2377 2595
2378int 2596int
2379volume (CFPlus::MixChunk self, int volume = -1) 2597volume (DC::MixChunk self, int volume = -1)
2380 CODE: 2598 CODE:
2381 if (items > 1) 2599 if (items > 1)
2382 volume = CLAMP (volume, 0, 128); 2600 volume = CLAMP (volume, 0, 128);
2383 RETVAL = Mix_VolumeChunk (self, volume); 2601 RETVAL = Mix_VolumeChunk (self, volume);
2384 OUTPUT: 2602 OUTPUT:
2385 RETVAL 2603 RETVAL
2386 2604
2387CFPlus::Channel 2605DC::Channel
2388play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) 2606play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1)
2389 CODE: 2607 CODE:
2390{ 2608{
2391 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 2609 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
2392 2610
2393 if (RETVAL < 0) 2611 if (RETVAL < 0)
2400 } 2618 }
2401} 2619}
2402 OUTPUT: 2620 OUTPUT:
2403 RETVAL 2621 RETVAL
2404 2622
2405MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2623MODULE = Deliantra::Client PACKAGE = DC::MixMusic
2406 2624
2407int 2625int
2408volume (int volume = -1) 2626volume (int volume = -1)
2409 PROTOTYPE: ;$ 2627 PROTOTYPE: ;$
2410 CODE: 2628 CODE:
2422void 2640void
2423halt () 2641halt ()
2424 CODE: 2642 CODE:
2425 Mix_HaltMusic (); 2643 Mix_HaltMusic ();
2426 2644
2427CFPlus::MixMusic 2645DC::MixMusic
2428new (SV *class, CFPlus::RW rwops) 2646new (SV *class, DC::RW rwops)
2429 CODE: 2647 CODE:
2430 RETVAL = Mix_LoadMUS_RW (rwops); 2648 RETVAL = Mix_LoadMUS_RW (rwops);
2431 OUTPUT: 2649 OUTPUT:
2432 RETVAL 2650 RETVAL
2433 2651
2434void 2652void
2435DESTROY (CFPlus::MixMusic self) 2653DESTROY (DC::MixMusic self)
2436 CODE: 2654 CODE:
2437 Mix_FreeMusic (self); 2655 Mix_FreeMusic (self);
2438 2656
2439int 2657int
2440play (CFPlus::MixMusic self, int loops = -1) 2658play (DC::MixMusic self, int loops = -1)
2441 CODE: 2659 CODE:
2442 RETVAL = Mix_PlayMusic (self, loops); 2660 RETVAL = Mix_PlayMusic (self, loops);
2443 OUTPUT: 2661 OUTPUT:
2444 RETVAL 2662 RETVAL
2445 2663
2446void 2664void
2447fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) 2665fade_in_pos (DC::MixMusic self, int loops, int ms, double position)
2448 CODE: 2666 CODE:
2449 Mix_FadeInMusicPos (self, loops, ms, position); 2667 Mix_FadeInMusicPos (self, loops, ms, position);
2450 2668
2451MODULE = CFPlus PACKAGE = CFPlus::OpenGL 2669MODULE = Deliantra::Client PACKAGE = DC::OpenGL
2452 2670
2453PROTOTYPES: ENABLE 2671PROTOTYPES: ENABLE
2454 2672
2455BOOT: 2673BOOT:
2456{ 2674{
2457 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); 2675 HV *stash = gv_stashpv ("DC::OpenGL", 1);
2458 static const struct { 2676 static const struct {
2459 const char *name; 2677 const char *name;
2460 IV iv; 2678 IV iv;
2461 } *civ, const_iv[] = { 2679 } *civ, const_iv[] = {
2462# define const_iv(name) { # name, (IV)name } 2680# define const_iv(name) { # name, (IV)name }
2497 const_iv (GL_INTENSITY), 2715 const_iv (GL_INTENSITY),
2498 const_iv (GL_LUMINANCE), 2716 const_iv (GL_LUMINANCE),
2499 const_iv (GL_LUMINANCE_ALPHA), 2717 const_iv (GL_LUMINANCE_ALPHA),
2500 const_iv (GL_FLOAT), 2718 const_iv (GL_FLOAT),
2501 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 2719 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
2720 const_iv (GL_COMPRESSED_ALPHA_ARB),
2721 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
2722 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
2723 const_iv (GL_COMPRESSED_INTENSITY_ARB),
2724 const_iv (GL_COMPRESSED_RGB_ARB),
2725 const_iv (GL_COMPRESSED_RGBA_ARB),
2502 const_iv (GL_COMPILE), 2726 const_iv (GL_COMPILE),
2503 const_iv (GL_PROXY_TEXTURE_1D), 2727 const_iv (GL_PROXY_TEXTURE_1D),
2504 const_iv (GL_PROXY_TEXTURE_2D), 2728 const_iv (GL_PROXY_TEXTURE_2D),
2505 const_iv (GL_TEXTURE_1D), 2729 const_iv (GL_TEXTURE_1D),
2506 const_iv (GL_TEXTURE_2D), 2730 const_iv (GL_TEXTURE_2D),
2545 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2769 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2546 const_iv (GL_POINT_SMOOTH_HINT), 2770 const_iv (GL_POINT_SMOOTH_HINT),
2547 const_iv (GL_LINE_SMOOTH_HINT), 2771 const_iv (GL_LINE_SMOOTH_HINT),
2548 const_iv (GL_POLYGON_SMOOTH_HINT), 2772 const_iv (GL_POLYGON_SMOOTH_HINT),
2549 const_iv (GL_GENERATE_MIPMAP_HINT), 2773 const_iv (GL_GENERATE_MIPMAP_HINT),
2774 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2550 const_iv (GL_FASTEST), 2775 const_iv (GL_FASTEST),
2551 const_iv (GL_DONT_CARE), 2776 const_iv (GL_DONT_CARE),
2552 const_iv (GL_NICEST), 2777 const_iv (GL_NICEST),
2553 const_iv (GL_V2F), 2778 const_iv (GL_V2F),
2554 const_iv (GL_V3F), 2779 const_iv (GL_V3F),
2562 2787
2563 texture_av = newAV (); 2788 texture_av = newAV ();
2564 AvREAL_off (texture_av); 2789 AvREAL_off (texture_av);
2565} 2790}
2566 2791
2792void
2793disable_GL_EXT_blend_func_separate ()
2794 CODE:
2795 gl.BlendFuncSeparate = 0;
2796 gl.BlendFuncSeparateEXT = 0;
2797
2567char * 2798char *
2568gl_vendor () 2799gl_vendor ()
2569 CODE: 2800 CODE:
2570 RETVAL = (char *)glGetString (GL_VENDOR); 2801 RETVAL = (char *)glGetString (GL_VENDOR);
2571 OUTPUT: 2802 OUTPUT:
2692 2923
2693void glRect (float x1, float y1, float x2, float y2) 2924void glRect (float x1, float y1, float x2, float y2)
2694 CODE: 2925 CODE:
2695 glRectf (x1, y1, x2, y2); 2926 glRectf (x1, y1, x2, y2);
2696 2927
2928void glRect_lineloop (float x1, float y1, float x2, float y2)
2929 CODE:
2930 glBegin (GL_LINE_LOOP);
2931 glVertex2f (x1, y1);
2932 glVertex2f (x2, y1);
2933 glVertex2f (x2, y2);
2934 glVertex2f (x1, y2);
2935 glEnd ();
2936
2697PROTOTYPES: ENABLE 2937PROTOTYPES: ENABLE
2698 2938
2699void glBegin (int mode) 2939void glBegin (int mode)
2700 2940
2701void glEnd () 2941void glEnd ()
2733void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) 2973void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column)
2734 CODE: 2974 CODE:
2735 if (gl.SeparableFilter2D) 2975 if (gl.SeparableFilter2D)
2736 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); 2976 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column);
2737 2977
2738void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) 2978void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0)
2739 2979
2740void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) 2980void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border)
2741 2981
2742void glDrawPixels (int width, int height, int format, int type, char *pixels) 2982void glDrawPixels (int width, int height, int format, int type, char *pixels)
2743 2983
2769 3009
2770void glEndList () 3010void glEndList ()
2771 3011
2772void glCallList (int list) 3012void glCallList (int list)
2773 3013
2774MODULE = CFPlus PACKAGE = CFPlus::UI::Base 3014MODULE = Deliantra::Client PACKAGE = DC::UI::Base
2775 3015
2776PROTOTYPES: DISABLE 3016PROTOTYPES: DISABLE
2777 3017
2778void 3018void
2779find_widget (SV *self, NV x, NV y) 3019find_widget (SV *self, NV x, NV y)
2783 XPUSHs (self); 3023 XPUSHs (self);
2784} 3024}
2785 3025
2786BOOT: 3026BOOT:
2787{ 3027{
2788 hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); 3028 hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV);
2789 3029
2790 draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); 3030 draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV);
2791 draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); 3031 draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV);
2792 draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); 3032 draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV);
2793 draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); 3033 draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV);
2794} 3034}
2795 3035
2796void 3036void
2797draw (SV *self) 3037draw (SV *self)
2798 CODE: 3038 CODE:
2802 NV x, y, w, h; 3042 NV x, y, w, h;
2803 SV *draw_x_sv = GvSV (draw_x_gv); 3043 SV *draw_x_sv = GvSV (draw_x_gv);
2804 SV *draw_y_sv = GvSV (draw_y_gv); 3044 SV *draw_y_sv = GvSV (draw_y_gv);
2805 SV *draw_w_sv = GvSV (draw_w_gv); 3045 SV *draw_w_sv = GvSV (draw_w_gv);
2806 SV *draw_h_sv = GvSV (draw_h_gv); 3046 SV *draw_h_sv = GvSV (draw_h_gv);
2807 SV *hover;
2808 double draw_x, draw_y, draw_w, draw_h; 3047 double draw_x, draw_y;
2809 3048
2810 if (!SvROK (self)) 3049 if (!SvROK (self))
2811 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 3050 croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self));
2812 3051
2813 hv = (HV *)SvRV (self); 3052 hv = (HV *)SvRV (self);
2814 3053
2815 if (SvTYPE (hv) != SVt_PVHV) 3054 if (SvTYPE (hv) != SVt_PVHV)
2816 croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); 3055 croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self));
2817 3056
2818 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; 3057 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.;
2819 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; 3058 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.;
2820 3059
2821 if (!h || !w) 3060 if (!h || !w)
2841 { 3080 {
2842 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 3081 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2843 3082
2844 if (svp && SvTRUE (*svp)) 3083 if (svp && SvTRUE (*svp))
2845 { 3084 {
2846 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 3085 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2847 glEnable (GL_BLEND); 3086 glEnable (GL_BLEND);
2848 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 3087 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2849 glBegin (GL_QUADS); 3088 glBegin (GL_QUADS);
2850 glVertex2f (0, 0); 3089 glVertex2f (0, 0);
2851 glVertex2f (w, 0); 3090 glVertex2f (w, 0);
2854 glEnd (); 3093 glEnd ();
2855 glDisable (GL_BLEND); 3094 glDisable (GL_BLEND);
2856 } 3095 }
2857 } 3096 }
2858#if 0 3097#if 0
2859 if ($ENV{CFPLUS_DEBUG} & 1) { 3098 // draw borders, for debugging
2860 glPushMatrix; 3099 glPushMatrix ();
2861 glColor 1, 1, 0, 1; 3100 glColor4f (1., 1., 0., 1.);
2862 glTranslate 0.375, 0.375; 3101 glTranslatef (.5, .5, 0.);
2863 glBegin GL_LINE_LOOP; 3102 glBegin (GL_LINE_LOOP);
2864 glVertex 0 , 0; 3103 glVertex2f (0 , 0);
2865 glVertex $self->{w} - 1, 0; 3104 glVertex2f (w - 1, 0);
2866 glVertex $self->{w} - 1, $self->{h} - 1; 3105 glVertex2f (w - 1, h - 1);
2867 glVertex 0 , $self->{h} - 1; 3106 glVertex2f (0 , h - 1);
2868 glEnd; 3107 glEnd ();
2869 glPopMatrix; 3108 glPopMatrix ();
2870 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2871 }
2872#endif 3109#endif
2873 PUSHMARK (SP); 3110 PUSHMARK (SP);
2874 XPUSHs (self); 3111 XPUSHs (self);
2875 PUTBACK; 3112 PUTBACK;
2876 call_method ("_draw", G_VOID | G_DISCARD); 3113 call_method ("_draw", G_VOID | G_DISCARD);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines