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.220 by root, Thu Aug 9 11:02:08 2007 UTC vs.
Revision 1.271 by root, Sun Jul 20 15:09:29 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
706IV minpot (UV n)
707
708IV popcount (UV n)
709
631void 710void
632pango_init () 711pango_init ()
633 CODE: 712 CODE:
634{ 713{
635 opengl_fontmap = pango_opengl_font_map_new (); 714 opengl_fontmap = pango_opengl_font_map_new ();
636 pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); 715 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); 716 opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap);
717 /*pango_context_set_font_description (opengl_context, default_font);*/
718#if PANGO_VERSION_CHECK (1, 15, 2)
719 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
720 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
721#endif
638} 722}
639 723
640char *
641SDL_GetError () 724char *SDL_GetError ()
642 725
643int 726int SDL_Init (U32 flags)
644SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
645 727
646void 728int SDL_InitSubSystem (U32 flags)
729
730void SDL_QuitSubSystem (U32 flags)
731
647SDL_Quit () 732void SDL_Quit ()
733
734int SDL_GL_SetAttribute (int attr, int value)
735
736int SDL_GL_GetAttribute (int attr)
737 CODE:
738 if (SDL_GL_GetAttribute (attr, &RETVAL))
739 XSRETURN_UNDEF;
740 OUTPUT:
741 RETVAL
648 742
649void 743void
650SDL_ListModes (int rgb, int alpha) 744SDL_ListModes (int rgb, int alpha)
651 PPCODE: 745 PPCODE:
652{ 746{
664 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 758 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
665 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 759 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
666 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 760 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
667 761
668 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 762 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); 763 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
672#endif
673 764
674 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 765 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
675 766
676 if (m && m != (SDL_Rect **)-1) 767 if (m && m != (SDL_Rect **)-1)
677 while (*m) 768 while (*m)
678 { 769 {
679 if ((*m)->w >= 640 && (*m)->h >= 480) 770 if ((*m)->w >= 400 && (*m)->h >= 300)
680 { 771 {
681 AV *av = newAV (); 772 AV *av = newAV ();
682 av_push (av, newSViv ((*m)->w)); 773 av_push (av, newSViv ((*m)->w));
683 av_push (av, newSViv ((*m)->h)); 774 av_push (av, newSViv ((*m)->h));
684 av_push (av, newSViv (rgb)); 775 av_push (av, newSViv (rgb));
708 799
709 if (RETVAL) 800 if (RETVAL)
710 { 801 {
711 av_clear (texture_av); 802 av_clear (texture_av);
712 803
713 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 804 SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra");
714#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 805#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
715#include "glfunc.h" 806#include "glfunc.h"
716#undef GL_FUNC 807#undef GL_FUNC
717 } 808 }
718} 809}
725char * 816char *
726SDL_GetKeyName (int sym) 817SDL_GetKeyName (int sym)
727 818
728int 819int
729SDL_GetAppState () 820SDL_GetAppState ()
821
822int
823SDL_GetModState ()
730 824
731void 825void
732poll_events () 826poll_events ()
733 PPCODE: 827 PPCODE:
734{ 828{
744 { 838 {
745 case SDL_KEYDOWN: 839 case SDL_KEYDOWN:
746 case SDL_KEYUP: 840 case SDL_KEYUP:
747 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 841 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
748 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 842 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
749 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 843 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 */ 844 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); 845 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
752 break; 846 break;
753 847
754 case SDL_ACTIVEEVENT: 848 case SDL_ACTIVEEVENT:
755 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 849 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
773 x = ev.motion.x; 867 x = ev.motion.x;
774 y = ev.motion.y; 868 y = ev.motion.y;
775 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 869 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
776 } 870 }
777 871
778 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 872 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
779 hv_store (hv, "state", 5, newSViv (state), 0); 873 hv_store (hv, "state", 5, newSViv (state), 0);
780 hv_store (hv, "x", 1, newSViv (x), 0); 874 hv_store (hv, "x", 1, newSViv (x), 0);
781 hv_store (hv, "y", 1, newSViv (y), 0); 875 hv_store (hv, "y", 1, newSViv (y), 0);
782 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 876 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
783 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 877 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
784 } 878 }
785 break; 879 break;
786 880
787 case SDL_MOUSEBUTTONDOWN: 881 case SDL_MOUSEBUTTONDOWN:
788 case SDL_MOUSEBUTTONUP: 882 case SDL_MOUSEBUTTONUP:
789 hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); 883 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0);
790 884
791 hv_store (hv, "button", 6, newSViv (ev.button.button), 0); 885 hv_store (hv, "button", 6, newSViv (ev.button.button), 0);
792 hv_store (hv, "state", 5, newSViv (ev.button.state), 0); 886 hv_store (hv, "state", 5, newSViv (ev.button.state), 0);
793 hv_store (hv, "x", 1, newSViv (ev.button.x), 0); 887 hv_store (hv, "x", 1, newSViv (ev.button.x), 0);
794 hv_store (hv, "y", 1, newSViv (ev.button.y), 0); 888 hv_store (hv, "y", 1, newSViv (ev.button.y), 0);
799 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); 893 hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0);
800 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); 894 hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0);
801 break; 895 break;
802 } 896 }
803 897
804 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 898 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
805 } 899 }
806} 900}
807 901
808int 902int
809Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) 903Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
810 POSTCALL: 904 POSTCALL:
811 Mix_HookMusicFinished (music_finished); 905 Mix_HookMusicFinished (music_finished);
812 Mix_ChannelFinished (channel_finished); 906 Mix_ChannelFinished (channel_finished);
907
908void
909Mix_QuerySpec ()
910 PPCODE:
911{
912 int freq, channels;
913 Uint16 format;
914
915 if (Mix_QuerySpec (&freq, &format, &channels))
916 {
917 EXTEND (SP, 3);
918 PUSHs (sv_2mortal (newSViv (freq)));
919 PUSHs (sv_2mortal (newSViv (format)));
920 PUSHs (sv_2mortal (newSViv (channels)));
921 }
922}
813 923
814void 924void
815Mix_CloseAudio () 925Mix_CloseAudio ()
816 926
817int 927int
852 } 962 }
853 } 963 }
854#endif 964#endif
855} 965}
856 966
857void 967int
858add_font (char *file) 968add_font (char *file)
859 CODE: 969 CODE:
860 FcConfigAppFontAddFile (0, (const FcChar8 *)file); 970 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
971 OUTPUT:
972 RETVAL
861 973
862void 974void
863load_image_inline (SV *image_) 975load_image_inline (SV *image_)
864 ALIAS: 976 ALIAS:
865 load_image_file = 1 977 load_image_file = 1
951void 1063void
952error (char *message) 1064error (char *message)
953 CODE: 1065 CODE:
954 fprintf (stderr, "ERROR: %s\n", message); 1066 fprintf (stderr, "ERROR: %s\n", message);
955#ifdef _WIN32 1067#ifdef _WIN32
956 MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); 1068 MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR);
957#endif 1069#endif
958 1070
959void 1071void
960fatal (char *message) 1072fatal (char *message)
961 CODE: 1073 CODE:
962 fprintf (stderr, "FATAL: %s\n", message); 1074 fprintf (stderr, "FATAL: %s\n", message);
963#ifdef _WIN32 1075#ifdef _WIN32
964 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 1076 MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR);
965#endif 1077#endif
966 _exit (1); 1078 _exit (1);
967 1079
968void 1080void
969_exit (int retval = 0) 1081_exit (int retval = 0)
981#if DEBUG 1093#if DEBUG
982 VALGRIND_DO_LEAK_CHECK; 1094 VALGRIND_DO_LEAK_CHECK;
983#endif 1095#endif
984} 1096}
985 1097
986MODULE = CFPlus PACKAGE = CFPlus::Font 1098MODULE = Deliantra::Client PACKAGE = DC::Font
987 1099
988PROTOTYPES: DISABLE 1100PROTOTYPES: DISABLE
989 1101
990CFPlus::Font 1102DC::Font
991new_from_file (SV *class, char *path, int id = 0) 1103new_from_file (SV *class, char *path, int id = 0)
992 CODE: 1104 CODE:
993{ 1105{
994 int count; 1106 int count;
995 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); 1107 FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count);
998} 1110}
999 OUTPUT: 1111 OUTPUT:
1000 RETVAL 1112 RETVAL
1001 1113
1002void 1114void
1003DESTROY (CFPlus::Font self) 1115DESTROY (DC::Font self)
1004 CODE: 1116 CODE:
1005 pango_font_description_free (self); 1117 pango_font_description_free (self);
1006 1118
1007void 1119void
1008make_default (CFPlus::Font self) 1120make_default (DC::Font self)
1009 PROTOTYPE: $ 1121 PROTOTYPE: $
1010 CODE: 1122 CODE:
1011 default_font = self; 1123 default_font = self;
1012 1124
1013MODULE = CFPlus PACKAGE = CFPlus::Layout 1125MODULE = Deliantra::Client PACKAGE = DC::Layout
1014 1126
1015PROTOTYPES: DISABLE 1127PROTOTYPES: DISABLE
1016 1128
1017void 1129void
1018reset_glyph_cache () 1130glyph_cache_backup ()
1019 PROTOTYPE: 1131 PROTOTYPE:
1020 CODE: 1132 CODE:
1133 tc_backup ();
1134
1135void
1136glyph_cache_restore ()
1137 PROTOTYPE:
1138 CODE:
1021 tc_clear (); 1139 tc_restore ();
1022 1140
1023CFPlus::Layout 1141DC::Layout
1024new (SV *class) 1142new (SV *class)
1025 CODE: 1143 CODE:
1026 New (0, RETVAL, 1, struct cf_layout); 1144 New (0, RETVAL, 1, struct cf_layout);
1027 1145
1028 RETVAL->pl = pango_layout_new (opengl_context); 1146 RETVAL->pl = pango_layout_new (opengl_context);
1030 RETVAL->g = 1.; 1148 RETVAL->g = 1.;
1031 RETVAL->b = 1.; 1149 RETVAL->b = 1.;
1032 RETVAL->a = 1.; 1150 RETVAL->a = 1.;
1033 RETVAL->base_height = MIN_FONT_HEIGHT; 1151 RETVAL->base_height = MIN_FONT_HEIGHT;
1034 RETVAL->font = 0; 1152 RETVAL->font = 0;
1153 RETVAL->rc = rc_alloc ();
1035 1154
1036 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1155 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1037 layout_update_font (RETVAL); 1156 layout_update_font (RETVAL);
1038 OUTPUT: 1157 OUTPUT:
1039 RETVAL 1158 RETVAL
1040 1159
1041void 1160void
1042DESTROY (CFPlus::Layout self) 1161DESTROY (DC::Layout self)
1043 CODE: 1162 CODE:
1044 g_object_unref (self->pl); 1163 g_object_unref (self->pl);
1164 rc_free (self->rc);
1045 Safefree (self); 1165 Safefree (self);
1046 1166
1047void 1167void
1048set_text (CFPlus::Layout self, SV *text_) 1168set_text (DC::Layout self, SV *text_)
1049 CODE: 1169 CODE:
1050{ 1170{
1051 STRLEN textlen; 1171 STRLEN textlen;
1052 char *text = SvPVutf8 (text_, textlen); 1172 char *text = SvPVutf8 (text_, textlen);
1053 1173
1054 pango_layout_set_text (self->pl, text, textlen); 1174 pango_layout_set_text (self->pl, text, textlen);
1055} 1175}
1056 1176
1057void 1177void
1058set_markup (CFPlus::Layout self, SV *text_) 1178set_markup (DC::Layout self, SV *text_)
1059 CODE: 1179 CODE:
1060{ 1180{
1061 STRLEN textlen; 1181 STRLEN textlen;
1062 char *text = SvPVutf8 (text_, textlen); 1182 char *text = SvPVutf8 (text_, textlen);
1063 1183
1064 pango_layout_set_markup (self->pl, text, textlen); 1184 pango_layout_set_markup (self->pl, text, textlen);
1065} 1185}
1066 1186
1067void 1187void
1068set_shapes (CFPlus::Layout self, ...) 1188set_shapes (DC::Layout self, ...)
1069 CODE: 1189 CODE:
1070{ 1190{
1071 PangoAttrList *attrs = 0; 1191 PangoAttrList *attrs = 0;
1072 const char *text = pango_layout_get_text (self->pl); 1192 const char *text = pango_layout_get_text (self->pl);
1073 const char *pos = text; 1193 const char *pos = text;
1108 if (attrs) 1228 if (attrs)
1109 pango_layout_set_attributes (self->pl, attrs); 1229 pango_layout_set_attributes (self->pl, attrs);
1110} 1230}
1111 1231
1112void 1232void
1113get_shapes (CFPlus::Layout self) 1233get_shapes (DC::Layout self)
1114 PPCODE: 1234 PPCODE:
1115{ 1235{
1116 PangoLayoutIter *iter = pango_layout_get_iter (self->pl); 1236 PangoLayoutIter *iter = pango_layout_get_iter (self->pl);
1117 1237
1118 do 1238 do
1119 { 1239 {
1120 PangoLayoutRun *run = pango_layout_iter_get_run (iter); 1240 PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter);
1121 1241
1122 if (run && shape_attr_p (run)) 1242 if (run && shape_attr_p (run))
1123 { 1243 {
1124 PangoRectangle extents; 1244 PangoRectangle extents;
1125 pango_layout_iter_get_run_extents (iter, 0, &extents); 1245 pango_layout_iter_get_run_extents (iter, 0, &extents);
1133 1253
1134 pango_layout_iter_free (iter); 1254 pango_layout_iter_free (iter);
1135} 1255}
1136 1256
1137int 1257int
1138has_wrapped (CFPlus::Layout self) 1258has_wrapped (DC::Layout self)
1139 CODE: 1259 CODE:
1140{ 1260{
1141 int lines = 1; 1261 int lines = 1;
1142 const char *text = pango_layout_get_text (self->pl); 1262 const char *text = pango_layout_get_text (self->pl);
1143 1263
1148} 1268}
1149 OUTPUT: 1269 OUTPUT:
1150 RETVAL 1270 RETVAL
1151 1271
1152SV * 1272SV *
1153get_text (CFPlus::Layout self) 1273get_text (DC::Layout self)
1154 CODE: 1274 CODE:
1155 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 1275 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
1156 sv_utf8_decode (RETVAL); 1276 sv_utf8_decode (RETVAL);
1157 OUTPUT: 1277 OUTPUT:
1158 RETVAL 1278 RETVAL
1159 1279
1160void 1280void
1161set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) 1281set_foreground (DC::Layout self, float r, float g, float b, float a = 1.)
1162 CODE: 1282 CODE:
1163 self->r = r; 1283 self->r = r;
1164 self->g = g; 1284 self->g = g;
1165 self->b = b; 1285 self->b = b;
1166 self->a = a; 1286 self->a = a;
1167 1287
1168void 1288void
1169set_font (CFPlus::Layout self, CFPlus::Font font = 0) 1289set_font (DC::Layout self, DC::Font font = 0)
1170 CODE: 1290 CODE:
1171 if (self->font != font) 1291 if (self->font != font)
1172 { 1292 {
1173 self->font = font; 1293 self->font = font;
1174 layout_update_font (self); 1294 layout_update_font (self);
1175 } 1295 }
1176 1296
1177void 1297void
1178set_height (CFPlus::Layout self, int base_height) 1298set_height (DC::Layout self, int base_height)
1179 CODE: 1299 CODE:
1180 if (self->base_height != base_height) 1300 if (self->base_height != base_height)
1181 { 1301 {
1182 self->base_height = base_height; 1302 self->base_height = base_height;
1183 layout_update_font (self); 1303 layout_update_font (self);
1184 } 1304 }
1185 1305
1186void 1306void
1187set_width (CFPlus::Layout self, int max_width = -1) 1307set_width (DC::Layout self, int max_width = -1)
1188 CODE: 1308 CODE:
1189 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 1309 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
1190 1310
1191void 1311void
1192set_indent (CFPlus::Layout self, int indent) 1312set_indent (DC::Layout self, int indent)
1193 CODE: 1313 CODE:
1194 pango_layout_set_indent (self->pl, indent * PANGO_SCALE); 1314 pango_layout_set_indent (self->pl, indent * PANGO_SCALE);
1195 1315
1196void 1316void
1197set_spacing (CFPlus::Layout self, int spacing) 1317set_spacing (DC::Layout self, int spacing)
1198 CODE: 1318 CODE:
1199 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); 1319 pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE);
1200 1320
1201void 1321void
1202set_ellipsise (CFPlus::Layout self, int ellipsise) 1322set_ellipsise (DC::Layout self, int ellipsise)
1203 CODE: 1323 CODE:
1204 pango_layout_set_ellipsize (self->pl, 1324 pango_layout_set_ellipsize (self->pl,
1205 ellipsise == 1 ? PANGO_ELLIPSIZE_START 1325 ellipsise == 1 ? PANGO_ELLIPSIZE_START
1206 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE 1326 : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE
1207 : ellipsise == 3 ? PANGO_ELLIPSIZE_END 1327 : ellipsise == 3 ? PANGO_ELLIPSIZE_END
1208 : PANGO_ELLIPSIZE_NONE 1328 : PANGO_ELLIPSIZE_NONE
1209 ); 1329 );
1210 1330
1211void 1331void
1212set_single_paragraph_mode (CFPlus::Layout self, int spm) 1332set_single_paragraph_mode (DC::Layout self, int spm)
1213 CODE: 1333 CODE:
1214 pango_layout_set_single_paragraph_mode (self->pl, !!spm); 1334 pango_layout_set_single_paragraph_mode (self->pl, !!spm);
1215 1335
1216void 1336void
1217size (CFPlus::Layout self) 1337size (DC::Layout self)
1218 PPCODE: 1338 PPCODE:
1219{ 1339{
1220 int w, h; 1340 int w, h;
1221 1341
1222 layout_get_pixel_size (self, &w, &h); 1342 layout_get_pixel_size (self, &w, &h);
1225 PUSHs (sv_2mortal (newSViv (w))); 1345 PUSHs (sv_2mortal (newSViv (w)));
1226 PUSHs (sv_2mortal (newSViv (h))); 1346 PUSHs (sv_2mortal (newSViv (h)));
1227} 1347}
1228 1348
1229int 1349int
1230descent (CFPlus::Layout self) 1350descent (DC::Layout self)
1231 CODE: 1351 CODE:
1232{ 1352{
1233 PangoRectangle rect; 1353 PangoRectangle rect;
1234 PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); 1354 PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0);
1235 pango_layout_line_get_pixel_extents (line, 0, &rect); 1355 pango_layout_line_get_pixel_extents (line, 0, &rect);
1236 RETVAL = PANGO_DESCENT (rect); 1356 RETVAL = PANGO_DESCENT (rect);
1237} 1357}
1238 OUTPUT: 1358 OUTPUT:
1239 RETVAL 1359 RETVAL
1240 1360
1241int 1361int
1242xy_to_index (CFPlus::Layout self, int x, int y) 1362xy_to_index (DC::Layout self, int x, int y)
1243 CODE: 1363 CODE:
1244{ 1364{
1245 int index, trailing; 1365 int index, trailing;
1246 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1366 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1247 RETVAL = index + trailing; 1367 RETVAL = index + trailing;
1248} 1368}
1249 OUTPUT: 1369 OUTPUT:
1250 RETVAL 1370 RETVAL
1251 1371
1252void 1372void
1253cursor_pos (CFPlus::Layout self, int index) 1373cursor_pos (DC::Layout self, int index)
1254 PPCODE: 1374 PPCODE:
1255{ 1375{
1256 PangoRectangle strong_pos; 1376 PangoRectangle pos;
1257 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); 1377 pango_layout_get_cursor_pos (self->pl, index, &pos, 0);
1258 1378
1259 EXTEND (SP, 3); 1379 EXTEND (SP, 3);
1260 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1380 PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE)));
1261 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1381 PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE)));
1262 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1382 PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE)));
1263} 1383}
1264 1384
1265void 1385void
1266index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) 1386index_to_line_x (DC::Layout self, int index, int trailing = 0)
1267 PPCODE: 1387 PPCODE:
1268{ 1388{
1269 int line, x; 1389 int line, x;
1270 1390
1271 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); 1391 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1392#if !PANGO_VERSION_CHECK (1, 17, 3)
1272 /* pango bug: line is between 1..numlines, not 0..numlines-1 */ 1393 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1273 1394 --line;
1395#endif
1274 EXTEND (SP, 2); 1396 EXTEND (SP, 2);
1275 PUSHs (sv_2mortal (newSViv (line - 1))); 1397 PUSHs (sv_2mortal (newSViv (line)));
1276 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); 1398 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1277} 1399}
1278 1400
1279void 1401void
1280line_x_to_index (CFPlus::Layout self, int line, int x) 1402line_x_to_index (DC::Layout self, int line, int x)
1281 PPCODE: 1403 PPCODE:
1282{ 1404{
1283 PangoLayoutLine *lp; 1405 PangoLayoutLine *lp;
1284 int index, trailing; 1406 int index, trailing;
1285 1407
1286 if (line < 0) 1408 if (line < 0)
1287 XSRETURN_EMPTY; 1409 XSRETURN_EMPTY;
1288 1410
1289 if (!(lp = pango_layout_get_line (self->pl, line))) 1411 if (!(lp = pango_layout_get_line_readonly (self->pl, line)))
1290 XSRETURN_EMPTY; /* do better */ 1412 XSRETURN_EMPTY; /* do better */
1291 1413
1292 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); 1414 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1293 1415
1294 EXTEND (SP, 2); 1416 EXTEND (SP, 2);
1300 PUSHs (sv_2mortal (newSViv (trailing))); 1422 PUSHs (sv_2mortal (newSViv (trailing)));
1301 } 1423 }
1302} 1424}
1303 1425
1304void 1426void
1305render (CFPlus::Layout self, float x, float y, int flags = 0) 1427render (DC::Layout self, float x, float y, int flags = 0)
1306 PPCODE: 1428 CODE:
1429 rc_clear (self->rc);
1307 pango_opengl_render_layout_subpixel ( 1430 pango_opengl_render_layout_subpixel (
1308 self->pl, 1431 self->pl,
1432 self->rc,
1309 x * PANGO_SCALE, y * PANGO_SCALE, 1433 x * PANGO_SCALE, y * PANGO_SCALE,
1310 self->r, self->g, self->b, self->a, 1434 self->r, self->g, self->b, self->a,
1311 flags 1435 flags
1312 ); 1436 );
1437 // we assume that context_change actually clears/frees stuff
1438 // and does not do any recomputation...
1439 pango_layout_context_changed (self->pl);
1313 1440
1314MODULE = CFPlus PACKAGE = CFPlus::Texture 1441void
1442draw (DC::Layout self)
1443 CODE:
1444{
1445 glEnable (GL_TEXTURE_2D);
1446 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1447 glEnable (GL_BLEND);
1448 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1449 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1450 glEnable (GL_ALPHA_TEST);
1451 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1452
1453 rc_draw (self->rc);
1454
1455 glDisable (GL_ALPHA_TEST);
1456 glDisable (GL_BLEND);
1457 glDisable (GL_TEXTURE_2D);
1458}
1459
1460MODULE = Deliantra::Client PACKAGE = DC::Texture
1315 1461
1316PROTOTYPES: ENABLE 1462PROTOTYPES: ENABLE
1317
1318int minpot (int n)
1319 1463
1320void 1464void
1321pad (SV *data_, int ow, int oh, int nw, int nh) 1465pad (SV *data_, int ow, int oh, int nw, int nh)
1322 CODE: 1466 CODE:
1323{ 1467{
1400 RETVAL = width > 0; 1544 RETVAL = width > 0;
1401} 1545}
1402 OUTPUT: 1546 OUTPUT:
1403 RETVAL 1547 RETVAL
1404 1548
1405MODULE = CFPlus PACKAGE = CFPlus::Map 1549MODULE = Deliantra::Client PACKAGE = DC::Map
1406 1550
1407PROTOTYPES: DISABLE 1551PROTOTYPES: DISABLE
1408 1552
1409CFPlus::Map 1553DC::Map
1410new (SV *class) 1554new (SV *class)
1411 CODE: 1555 CODE:
1412 New (0, RETVAL, 1, struct map); 1556 New (0, RETVAL, 1, struct map);
1413 RETVAL->x = 0; 1557 RETVAL->x = 0;
1414 RETVAL->y = 0; 1558 RETVAL->y = 0;
1422 RETVAL->row = 0; 1566 RETVAL->row = 0;
1423 OUTPUT: 1567 OUTPUT:
1424 RETVAL 1568 RETVAL
1425 1569
1426void 1570void
1427DESTROY (CFPlus::Map self) 1571DESTROY (DC::Map self)
1428 CODE: 1572 CODE:
1429{ 1573{
1430 map_clear (self); 1574 map_clear (self);
1431 Safefree (self->face2tile); 1575 Safefree (self->face2tile);
1432 Safefree (self->tex); 1576 Safefree (self->tex);
1433 Safefree (self); 1577 Safefree (self);
1434} 1578}
1435 1579
1436void 1580void
1437resize (CFPlus::Map self, int map_width, int map_height) 1581resize (DC::Map self, int map_width, int map_height)
1438 CODE: 1582 CODE:
1439 self->w = map_width; 1583 self->w = map_width;
1440 self->h = map_height; 1584 self->h = map_height;
1441 1585
1442void 1586void
1443clear (CFPlus::Map self) 1587clear (DC::Map self)
1444 CODE: 1588 CODE:
1445 map_clear (self); 1589 map_clear (self);
1446 1590
1447void 1591void
1448set_tileid (CFPlus::Map self, int face, int tile) 1592set_tileid (DC::Map self, int face, int tile)
1449 CODE: 1593 CODE:
1450{ 1594{
1451 need_facenum (self, face); self->face2tile [face] = tile; 1595 need_facenum (self, face); self->face2tile [face] = tile;
1452 need_texid (self, tile); 1596 need_texid (self, tile);
1453} 1597}
1454 1598
1455void 1599void
1456set_smooth (CFPlus::Map self, int face, int smooth, int level) 1600set_smooth (DC::Map self, int face, int smooth, int level)
1457 CODE: 1601 CODE:
1458{ 1602{
1459 tileid texid; 1603 tileid texid;
1460 maptex *tex; 1604 maptex *tex;
1461 1605
1474 tex->smoothtile = self->face2tile [smooth]; 1618 tex->smoothtile = self->face2tile [smooth];
1475 tex->smoothlevel = level; 1619 tex->smoothlevel = level;
1476} 1620}
1477 1621
1478void 1622void
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) 1623set_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: 1624 CODE:
1481{ 1625{
1482 need_texid (self, texid); 1626 need_texid (self, texid);
1483 1627
1484 { 1628 {
1504 // from transparent color bleeding and ugly wrapping effects. 1648 // from transparent color bleeding and ugly wrapping effects.
1505 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1649 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1506} 1650}
1507 1651
1508int 1652int
1509ox (CFPlus::Map self) 1653ox (DC::Map self)
1510 ALIAS: 1654 ALIAS:
1511 oy = 1 1655 oy = 1
1512 x = 2 1656 x = 2
1513 y = 3 1657 y = 3
1514 w = 4 1658 w = 4
1525 } 1669 }
1526 OUTPUT: 1670 OUTPUT:
1527 RETVAL 1671 RETVAL
1528 1672
1529void 1673void
1530scroll (CFPlus::Map self, int dx, int dy) 1674scroll (DC::Map self, int dx, int dy)
1531 CODE: 1675 CODE:
1532{ 1676{
1533 if (dx > 0) 1677 if (dx > 0)
1534 map_blank (self, self->x, self->y, dx, self->h); 1678 map_blank (self, self->x, self->y, dx, self->h);
1535 else if (dx < 0) 1679 else if (dx < 0)
1550 self->rows += MAP_EXTEND_Y; 1694 self->rows += MAP_EXTEND_Y;
1551 self->y += MAP_EXTEND_Y; 1695 self->y += MAP_EXTEND_Y;
1552 } 1696 }
1553} 1697}
1554 1698
1555void 1699SV *
1556map1a_update (CFPlus::Map self, SV *data_, int extmap) 1700map1a_update (DC::Map self, SV *data_, int extmap)
1557 CODE: 1701 CODE:
1558{ 1702{
1559 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1703 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1560 uint8_t *data_end = (uint8_t *)SvEND (data_); 1704 uint8_t *data_end = (uint8_t *)SvEND (data_);
1561 mapcell *cell; 1705 mapcell *cell;
1562 int x, y, flags; 1706 int x, y, z, flags;
1707 AV *missing = newAV ();
1708 RETVAL = newRV_noinc ((SV *)missing);
1563 1709
1564 while (data < data_end - 1) 1710 while (data < data_end - 1)
1565 { 1711 {
1566 flags = (data [0] << 8) + data [1]; data += 2; 1712 flags = (data [0] << 8) + data [1]; data += 2;
1567 1713
1587 uint8_t ext, cmd; 1733 uint8_t ext, cmd;
1588 1734
1589 do 1735 do
1590 { 1736 {
1591 ext = *data++; 1737 ext = *data++;
1592 cmd = ext & 0x3f; 1738 cmd = ext & 0x7f;
1593 1739
1594 if (cmd < 4) 1740 if (cmd < 4)
1595 cell->darkness = 255 - ext * 64 + 1; 1741 cell->darkness = 255 - ext * 64 + 1;
1596 else if (cmd == 5) // health 1742 else if (cmd == 5) // health
1597 { 1743 {
1600 } 1746 }
1601 else if (cmd == 6) // monster width 1747 else if (cmd == 6) // monster width
1602 cell->stat_width = *data++ + 1; 1748 cell->stat_width = *data++ + 1;
1603 else if (cmd == 0x47) 1749 else if (cmd == 0x47)
1604 { 1750 {
1605 if (*data == 4) 1751 if (*data == 1) cell->player = data [1];
1606 ; // decode player count 1752 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
1753 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
1754 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
1607 1755
1608 data += *data + 1; 1756 data += *data + 1;
1609 } 1757 }
1610 else if (cmd == 8) // cell flags 1758 else if (cmd == 8) // cell flags
1611 cell->flags = *data++; 1759 cell->flags = *data++;
1618 } 1766 }
1619 else 1767 else
1620 cell->darkness = *data++ + 1; 1768 cell->darkness = *data++ + 1;
1621 } 1769 }
1622 1770
1771 for (z = 0; z <= 2; ++z)
1623 if (flags & 4) 1772 if (flags & (4 >> z))
1624 { 1773 {
1625 faceid face = (data [0] << 8) + data [1]; data += 2; 1774 faceid face = (data [0] << 8) + data [1]; data += 2;
1626 need_facenum (self, face); 1775 need_facenum (self, face);
1627 cell->tile [0] = self->face2tile [face]; 1776 cell->tile [z] = self->face2tile [face];
1777
1778 if (cell->tile [z])
1779 {
1780 maptex *tex = self->tex + cell->tile [z];
1781 if (!tex->name)
1782 av_push (missing, newSViv (cell->tile [z]));
1783
1784 if (tex->smoothtile)
1785 {
1786 maptex *smooth = self->tex + tex->smoothtile;
1787 if (!smooth->name)
1788 av_push (missing, newSViv (tex->smoothtile));
1789 }
1790 }
1628 } 1791 }
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 } 1792 }
1644 else 1793 else
1645 cell->darkness = 0; 1794 CELL_CLEAR (cell);
1646 } 1795 }
1647} 1796}
1797 OUTPUT:
1798 RETVAL
1648 1799
1649SV * 1800SV *
1650mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1801mapmap (DC::Map self, int x0, int y0, int w, int h)
1651 CODE: 1802 CODE:
1652{ 1803{
1653 int x1, x; 1804 int x1, x;
1654 int y1, y; 1805 int y1, y;
1655 int z; 1806 int z;
1699 RETVAL = map_sv; 1850 RETVAL = map_sv;
1700} 1851}
1701 OUTPUT: 1852 OUTPUT:
1702 RETVAL 1853 RETVAL
1703 1854
1704SV * 1855void
1705draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1856draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1706 CODE: 1857 CODE:
1707{ 1858{
1859 int x, y, z;
1860
1708 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1861 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1709 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1862 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) 1863 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1711 smooth_key skey; 1864 smooth_key skey;
1712 int x, y, z; 1865 int pl_x, pl_y;
1713 int last_name; 1866 maptex pl_tex;
1714 AV *missing = newAV (); 1867 rc_t *rc = rc_alloc ();
1715 RETVAL = newRV_noinc ((SV *)missing); 1868 rc_key_t key;
1869 rc_array_t *arr;
1870
1871 pl_tex.name = 0;
1716 1872
1717 // thats current max. sorry. 1873 // thats current max. sorry.
1718 if (sw > 255) sw = 255; 1874 if (sw > 255) sw = 255;
1719 if (sh > 255) sh = 255; 1875 if (sh > 255) sh = 255;
1720 1876
1721 // clear key, in case of extra padding 1877 // clear key, in case of extra padding
1722 memset (&skey, 0, sizeof (skey)); 1878 memset (&skey, 0, sizeof (skey));
1723 1879
1724 glColor4ub (255, 255, 255, 255); 1880 memset (&key, 0, sizeof (key));
1725 1881 key.r = 255;
1726 glEnable (GL_BLEND); 1882 key.g = 255;
1727 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1883 key.b = 255;
1728 glEnable (GL_TEXTURE_2D); 1884 key.a = 255;
1729 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1885 key.mode = GL_QUADS;
1730 1886 key.format = GL_T2F_V3F;
1731 glBegin (GL_QUADS);
1732
1733 last_name = -1; 1887 key.texname = -1;
1734 1888
1735 mx += self->x; 1889 mx += self->x;
1736 my += self->y; 1890 my += self->y;
1737 1891
1738 // first pass: determine smooth_max 1892 // first pass: determine smooth_max
1754 MAX (self->tex [cell->tile [0]].smoothlevel, 1908 MAX (self->tex [cell->tile [0]].smoothlevel,
1755 MAX (self->tex [cell->tile [1]].smoothlevel, 1909 MAX (self->tex [cell->tile [1]].smoothlevel,
1756 self->tex [cell->tile [2]].smoothlevel)); 1910 self->tex [cell->tile [2]].smoothlevel));
1757 } 1911 }
1758 } 1912 }
1913
1914 glEnable (GL_BLEND);
1915 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1916 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1759 1917
1760 for (z = 0; z <= 2; z++) 1918 for (z = 0; z <= 2; z++)
1761 { 1919 {
1762 memset (smooth_level, 0, sizeof (smooth_level)); 1920 memset (smooth_level, 0, sizeof (smooth_level));
1763 1921
1773 tileid tile = cell->tile [z]; 1931 tileid tile = cell->tile [z];
1774 1932
1775 if (tile) 1933 if (tile)
1776 { 1934 {
1777 maptex tex = self->tex [tile]; 1935 maptex tex = self->tex [tile];
1778 int px, py; 1936 int px = (x + 1) * T - tex.w;
1937 int py = (y + 1) * T - tex.h;
1779 1938
1780 // suppressing texture state switches here
1781 // is only moderately effective, but worth the extra effort
1782 if (last_name != tex.name) 1939 if (key.texname != tex.name)
1783 { 1940 {
1784 if (!tex.name) 1941 if (!tex.name)
1785 {
1786 av_push (missing, newSViv (tile));
1787 tex = self->tex [2]; /* missing, replace by noface */ 1942 tex = self->tex [2]; /* missing, replace by noface */
1788 }
1789 1943
1790 glEnd (); 1944 key.texname = tex.name;
1791 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1945 arr = rc_array (rc, &key);
1792 glBegin (GL_QUADS);
1793 } 1946 }
1794 1947
1795 px = (x + 1) * T - tex.w; 1948 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 { 1949 {
1950 pl_x = px;
1951 pl_y = py;
1952 pl_tex = tex;
1953 continue;
1954 }
1955
1956 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1957 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1958 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1959 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1960
1961 if (expect_false (cell->flags) && expect_false (z == 2))
1962 {
1963 // overlays such as the speech bubble, probably more to come
1805 if (cell->flags & 1) 1964 if (cell->flags & 1)
1806 { 1965 {
1807 maptex tex = self->tex [1]; 1966 maptex tex = self->tex [1];
1808 int px = x * T + T * 2 / 32; 1967 int px = x * T + T * 2 / 32;
1809 int py = y * T - T * 6 / 32; 1968 int py = y * T - T * 6 / 32;
1810 1969
1970 if (tex.name)
1811 glEnd (); 1971 {
1812 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1972 if (key.texname != tex.name)
1973 {
1974 key.texname = tex.name;
1975 arr = rc_array (rc, &key);
1976 }
1977
1978 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1979 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
1980 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
1981 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
1813 glBegin (GL_QUADS); 1982 }
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 } 1983 }
1820 } 1984 }
1821 1985
1822 // update smooth hash 1986 // update smooth hash
1823 if (tex.smoothtile) 1987 if (tex.smoothtile)
1859 } 2023 }
1860 } 2024 }
1861 } 2025 }
1862 } 2026 }
1863 2027
2028 rc_draw (rc);
2029 rc_clear (rc);
2030
1864 // go through all smoothlevels, lowest to highest, then draw. 2031 // go through all smoothlevels, lowest to highest, then draw.
1865 // this is basically counting sort 2032 // this is basically counting sort
1866 { 2033 {
1867 int w, b; 2034 int w, b;
1868 2035
2036 glEnable (GL_TEXTURE_2D);
2037 glBegin (GL_QUADS);
1869 for (w = 0; w < 256 / 32; ++w) 2038 for (w = 0; w < 256 / 32; ++w)
1870 { 2039 {
1871 uint32_t smask = smooth_level [w]; 2040 uint32_t smask = smooth_level [w];
1872 if (smask) 2041 if (smask)
1873 for (b = 0; b < 32; ++b) 2042 for (b = 0; b < 32; ++b)
1892 int border = bits & 15; 2061 int border = bits & 15;
1893 int corner = (bits >> 8) & ~(bits >> 4) & 15; 2062 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1894 float dx = tex.s * .0625f; // 16 images/row 2063 float dx = tex.s * .0625f; // 16 images/row
1895 float dy = tex.t * .5f ; // 2 images/column 2064 float dy = tex.t * .5f ; // 2 images/column
1896 2065
1897 // this time naively avoiding texture state changes
1898 // save gobs of state changes.
1899 if (last_name != tex.name) 2066 if (tex.name)
1900 { 2067 {
2068 // this time avoiding texture state changes
2069 // save gobs of state changes.
1901 if (!tex.name) 2070 if (key.texname != tex.name)
1902 { 2071 {
1903 av_push (missing, newSViv (skey->tile)); 2072 glEnd ();
1904 continue; // smoothing not yet available 2073 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2074 glBegin (GL_QUADS);
1905 } 2075 }
1906 2076
1907 glEnd ();
1908 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1909 glBegin (GL_QUADS);
1910 }
1911
1912 if (border) 2077 if (border)
1913 { 2078 {
1914 float ox = border * dx; 2079 float ox = border * dx;
1915 2080
1916 glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); 2081 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1917 glTexCoord2f (ox , dy ); glVertex2f (px , py + T); 2082 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1918 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); 2083 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1919 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); 2084 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1920 } 2085 }
1921 2086
1922 if (corner) 2087 if (corner)
1923 { 2088 {
1924 float ox = corner * dx; 2089 float ox = corner * dx;
1925 2090
1926 glTexCoord2f (ox , dy ); glVertex2f (px , py ); 2091 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1927 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); 2092 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1928 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); 2093 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T);
1929 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); 2094 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
2095 }
1930 } 2096 }
1931 } 2097 }
1932 } 2098 }
1933 } 2099 }
1934 } 2100 }
2101
2102 glEnd ();
2103 glDisable (GL_TEXTURE_2D);
2104 key.texname = -1;
1935 } 2105 }
1936 2106
1937 hv_clear (smooth); 2107 hv_clear (smooth);
1938 } 2108 }
1939 2109
1940 glEnd (); 2110 if (pl_tex.name)
2111 {
2112 maptex tex = pl_tex;
2113 int px = pl_x + sdx;
2114 int py = pl_y + sdy;
1941 2115
1942 glDisable (GL_TEXTURE_2D); 2116 key.texname = tex.name;
2117 arr = rc_array (rc, &key);
2118
2119 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2120 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2121 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2122 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2123
2124 rc_draw (rc);
2125 }
2126
1943 glDisable (GL_BLEND); 2127 glDisable (GL_BLEND);
2128 rc_free (rc);
1944 2129
1945 // top layer: overlays such as the health bar 2130 // top layer: overlays such as the health bar
1946 for (y = 0; y < sh; y++) 2131 for (y = 0; y < sh; y++)
1947 if (0 <= y + my && y + my < self->rows) 2132 if (0 <= y + my && y + my < self->rows)
1948 { 2133 {
1971 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); 2156 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1972 } 2157 }
1973 } 2158 }
1974 } 2159 }
1975} 2160}
1976 OUTPUT:
1977 RETVAL
1978 2161
1979void 2162void
1980draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 2163draw_magicmap (DC::Map self, int dx, int dy, int w, int h, unsigned char *data)
1981 CODE: 2164 CODE:
1982{ 2165{
1983 static float color[16][3] = { 2166 static float color[16][3] = {
1984 { 0.00F, 0.00F, 0.00F }, 2167 { 0.00F, 0.00F, 0.00F },
1985 { 1.00F, 1.00F, 1.00F }, 2168 { 1.00F, 1.00F, 1.00F },
2035 glDisable (GL_BLEND); 2218 glDisable (GL_BLEND);
2036 glDisable (GL_TEXTURE_2D); 2219 glDisable (GL_TEXTURE_2D);
2037} 2220}
2038 2221
2039void 2222void
2040fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) 2223fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2041 PPCODE: 2224 PPCODE:
2042{ 2225{
2043 int x, y; 2226 int x, y;
2044 int sw1 = sw + 2; 2227 int sw1 = sw + 2;
2045 int sh1 = sh + 2; 2228 int sh1 = sh + 2;
2053 SvCUR_set (darkness3_sv, sw34 * sh3); 2236 SvCUR_set (darkness3_sv, sw34 * sh3);
2054 2237
2055 mx += self->x - 1; 2238 mx += self->x - 1;
2056 my += self->y - 1; 2239 my += self->y - 1;
2057 2240
2058 memset (darkness1, 255, sw1 * sh1); 2241 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2059 2242
2060 for (y = 0; y < sh1; y++) 2243 for (y = 0; y < sh1; y++)
2061 if (0 <= y + my && y + my < self->rows) 2244 if (0 <= y + my && y + my < self->rows)
2062 { 2245 {
2063 maprow *row = self->row + (y + my); 2246 maprow *row = self->row + (y + my);
2116 PUSHs (sv_2mortal (newSViv (sh3))); 2299 PUSHs (sv_2mortal (newSViv (sh3)));
2117 PUSHs (darkness3_sv); 2300 PUSHs (darkness3_sv);
2118} 2301}
2119 2302
2120SV * 2303SV *
2121get_rect (CFPlus::Map self, int x0, int y0, int w, int h) 2304get_rect (DC::Map self, int x0, int y0, int w, int h)
2122 CODE: 2305 CODE:
2123{ 2306{
2124 int x, y, x1, y1; 2307 int x, y, x1, y1;
2125 SV *data_sv = newSV (w * h * 7 + 5); 2308 SV *data_sv = newSV (w * h * 7 + 5);
2126 uint8_t *data = (uint8_t *)SvPVX (data_sv); 2309 uint8_t *data = (uint8_t *)SvPVX (data_sv);
2183 else 2366 else
2184 *data++ = 0; 2367 *data++ = 0;
2185 } 2368 }
2186 } 2369 }
2187 2370
2371 /* if size is w*h + 5 then no data has been found */
2372 if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5)
2373 {
2188 SvPOK_only (data_sv); 2374 SvPOK_only (data_sv);
2189 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); 2375 SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv));
2376 }
2377
2190 RETVAL = data_sv; 2378 RETVAL = data_sv;
2191} 2379}
2192 OUTPUT: 2380 OUTPUT:
2193 RETVAL 2381 RETVAL
2194 2382
2195void 2383void
2196set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) 2384set_rect (DC::Map self, int x0, int y0, SV *data_sv)
2197 PPCODE: 2385 PPCODE:
2198{ 2386{
2199 int x, y, z; 2387 int x, y, z;
2200 int w, h; 2388 int w, h;
2201 int x1, y1; 2389 int x1, y1;
2390 STRLEN len;
2391 uint8_t *data, *end;
2392
2393 len = SvLEN (data_sv);
2394 SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more
2395 data = SvPVbyte_nolen (data_sv);
2396 end = data + len + 8;
2397
2398 if (len < 5)
2399 XSRETURN_EMPTY;
2202 2400
2203 if (*data++ != 0) 2401 if (*data++ != 0)
2204 return; /* version mismatch */ 2402 XSRETURN_EMPTY; /* version mismatch */
2205 2403
2206 w = *data++ << 8; w |= *data++; 2404 w = *data++ << 8; w |= *data++;
2207 h = *data++ << 8; h |= *data++; 2405 h = *data++ << 8; h |= *data++;
2208 2406
2209 // we need to do this 'cause we don't keep an absolute coord system for rows 2407 // we need to do this 'cause we don't keep an absolute coord system for rows
2221 { 2419 {
2222 maprow *row = map_get_row (self, y); 2420 maprow *row = map_get_row (self, y);
2223 2421
2224 for (x = x0; x < x1; x++) 2422 for (x = x0; x < x1; x++)
2225 { 2423 {
2424 uint8_t flags;
2425
2426 if (data + 7 >= end)
2427 XSRETURN_EMPTY;
2428
2226 uint8_t flags = *data++; 2429 flags = *data++;
2227 2430
2228 if (flags) 2431 if (flags)
2229 { 2432 {
2230 mapcell *cell = row_get_cell (row, x); 2433 mapcell *cell = row_get_cell (row, x);
2231 tileid tile[3] = { 0, 0, 0 }; 2434 tileid tile[3] = { 0, 0, 0 };
2234 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } 2437 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
2235 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } 2438 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
2236 2439
2237 if (cell->darkness == 0) 2440 if (cell->darkness == 0)
2238 { 2441 {
2239 cell->darkness = 0; 2442 /*cell->darkness = 0;*/
2443 EXTEND (SP, 3);
2240 2444
2241 for (z = 0; z <= 2; z++) 2445 for (z = 0; z <= 2; z++)
2242 { 2446 {
2243 tileid t = tile [z]; 2447 tileid t = tile [z];
2244 2448
2245 if (t >= self->texs || (t && !self->tex [t].name)) 2449 if (t >= self->texs || (t && !self->tex [t].name))
2246 { 2450 {
2247 XPUSHs (sv_2mortal (newSViv (t))); 2451 PUSHs (sv_2mortal (newSViv (t)));
2248 need_texid (self, t); 2452 need_texid (self, t);
2249 } 2453 }
2250 2454
2251 cell->tile [z] = t; 2455 cell->tile [z] = t;
2252 } 2456 }
2254 } 2458 }
2255 } 2459 }
2256 } 2460 }
2257} 2461}
2258 2462
2259MODULE = CFPlus PACKAGE = CFPlus::RW 2463MODULE = Deliantra::Client PACKAGE = DC::RW
2260 2464
2261CFPlus::RW 2465DC::RW
2262new (SV *class, SV *data_sv) 2466new (SV *class, SV *data_sv)
2263 CODE: 2467 CODE:
2264{ 2468{
2265 STRLEN datalen; 2469 STRLEN datalen;
2266 char *data = SvPVbyte (data_sv, datalen); 2470 char *data = SvPVbyte (data_sv, datalen);
2268 RETVAL = SDL_RWFromConstMem (data, datalen); 2472 RETVAL = SDL_RWFromConstMem (data, datalen);
2269} 2473}
2270 OUTPUT: 2474 OUTPUT:
2271 RETVAL 2475 RETVAL
2272 2476
2273CFPlus::RW 2477DC::RW
2274new_from_file (SV *class, const char *path, const char *mode = "rb") 2478new_from_file (SV *class, const char *path, const char *mode = "rb")
2275 CODE: 2479 CODE:
2276 RETVAL = SDL_RWFromFile (path, mode); 2480 RETVAL = SDL_RWFromFile (path, mode);
2277 OUTPUT: 2481 OUTPUT:
2278 RETVAL 2482 RETVAL
2279 2483
2280# fails on win32: 2484# fails on win32:
2281# CFPlus.xs(2268) : error C2059: syntax error : '(' 2485# dc.xs(2268) : error C2059: syntax error : '('
2282#void 2486#void
2283#close (CFPlus::RW self) 2487#close (DC::RW self)
2284# CODE: 2488# CODE:
2285# (self->(close)) (self); 2489# (self->(close)) (self);
2286 2490
2287MODULE = CFPlus PACKAGE = CFPlus::Channel 2491MODULE = Deliantra::Client PACKAGE = DC::Channel
2288 2492
2289PROTOTYPES: DISABLE 2493PROTOTYPES: DISABLE
2290 2494
2291CFPlus::Channel 2495DC::Channel
2292find () 2496find ()
2293 CODE: 2497 CODE:
2294{ 2498{
2295 RETVAL = Mix_GroupAvailable (-1); 2499 RETVAL = Mix_GroupAvailable (-1);
2296 2500
2309} 2513}
2310 OUTPUT: 2514 OUTPUT:
2311 RETVAL 2515 RETVAL
2312 2516
2313void 2517void
2314halt (CFPlus::Channel self) 2518halt (DC::Channel self)
2315 CODE: 2519 CODE:
2316 Mix_HaltChannel (self); 2520 Mix_HaltChannel (self);
2317 2521
2318void 2522void
2319expire (CFPlus::Channel self, int ticks = -1) 2523expire (DC::Channel self, int ticks = -1)
2320 CODE: 2524 CODE:
2321 Mix_ExpireChannel (self, ticks); 2525 Mix_ExpireChannel (self, ticks);
2322 2526
2323void 2527void
2324fade_out (CFPlus::Channel self, int ticks = -1) 2528fade_out (DC::Channel self, int ticks = -1)
2325 CODE: 2529 CODE:
2326 Mix_FadeOutChannel (self, ticks); 2530 Mix_FadeOutChannel (self, ticks);
2327 2531
2328int 2532int
2329volume (CFPlus::Channel self, int volume) 2533volume (DC::Channel self, int volume)
2330 CODE: 2534 CODE:
2331 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); 2535 RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128));
2332 OUTPUT: 2536 OUTPUT:
2333 RETVAL 2537 RETVAL
2334 2538
2335void 2539void
2336unregister_all_effects (CFPlus::Channel self) 2540unregister_all_effects (DC::Channel self)
2337 CODE: 2541 CODE:
2338 Mix_UnregisterAllEffects (self); 2542 Mix_UnregisterAllEffects (self);
2339 2543
2340void 2544void
2341set_panning (CFPlus::Channel self, int left, int right) 2545set_panning (DC::Channel self, int left, int right)
2342 CODE: 2546 CODE:
2343 left = CLAMP (left , 0, 255); 2547 left = CLAMP (left , 0, 255);
2344 right = CLAMP (right, 0, 255); 2548 right = CLAMP (right, 0, 255);
2345 Mix_SetPanning (self, left, right); 2549 Mix_SetPanning (self, left, right);
2346 2550
2347void 2551void
2348set_distance (CFPlus::Channel self, int distance) 2552set_distance (DC::Channel self, int distance)
2349 CODE: 2553 CODE:
2350 Mix_SetDistance (self, CLAMP (distance, 0, 255)); 2554 Mix_SetDistance (self, CLAMP (distance, 0, 255));
2351 2555
2352void 2556void
2353set_position (CFPlus::Channel self, int angle, int distance) 2557set_position (DC::Channel self, int angle, int distance)
2354 CODE: 2558 CODE:
2355 2559
2356void 2560void
2357set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) 2561set_position_r (DC::Channel self, int dx, int dy, int maxdistance)
2358 CODE: 2562 CODE:
2359{ 2563{
2360 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); 2564 int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance));
2361 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); 2565 int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI);
2362 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); 2566 Mix_SetPosition (self, angle, CLAMP (distance, 0, 255));
2363} 2567}
2364 2568
2365void 2569void
2366set_reverse_stereo (CFPlus::Channel self, int flip) 2570set_reverse_stereo (DC::Channel self, int flip)
2367 CODE: 2571 CODE:
2368 Mix_SetReverseStereo (self, flip); 2572 Mix_SetReverseStereo (self, flip);
2369 2573
2370MODULE = CFPlus PACKAGE = CFPlus::MixChunk 2574MODULE = Deliantra::Client PACKAGE = DC::MixChunk
2371 2575
2372PROTOTYPES: DISABLE 2576PROTOTYPES: DISABLE
2373 2577
2374CFPlus::MixChunk 2578DC::MixChunk
2375new (SV *class, CFPlus::RW rwops) 2579new (SV *class, DC::RW rwops)
2376 CODE: 2580 CODE:
2377 RETVAL = Mix_LoadWAV_RW (rwops, 1); 2581 RETVAL = Mix_LoadWAV_RW (rwops, 1);
2378 OUTPUT: 2582 OUTPUT:
2379 RETVAL 2583 RETVAL
2380 2584
2381void 2585void
2382DESTROY (CFPlus::MixChunk self) 2586DESTROY (DC::MixChunk self)
2383 CODE: 2587 CODE:
2384 Mix_FreeChunk (self); 2588 Mix_FreeChunk (self);
2385 2589
2386int 2590int
2387volume (CFPlus::MixChunk self, int volume = -1) 2591volume (DC::MixChunk self, int volume = -1)
2388 CODE: 2592 CODE:
2389 if (items > 1) 2593 if (items > 1)
2390 volume = CLAMP (volume, 0, 128); 2594 volume = CLAMP (volume, 0, 128);
2391 RETVAL = Mix_VolumeChunk (self, volume); 2595 RETVAL = Mix_VolumeChunk (self, volume);
2392 OUTPUT: 2596 OUTPUT:
2393 RETVAL 2597 RETVAL
2394 2598
2395CFPlus::Channel 2599DC::Channel
2396play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) 2600play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1)
2397 CODE: 2601 CODE:
2398{ 2602{
2399 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); 2603 RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks);
2400 2604
2401 if (RETVAL < 0) 2605 if (RETVAL < 0)
2408 } 2612 }
2409} 2613}
2410 OUTPUT: 2614 OUTPUT:
2411 RETVAL 2615 RETVAL
2412 2616
2413MODULE = CFPlus PACKAGE = CFPlus::MixMusic 2617MODULE = Deliantra::Client PACKAGE = DC::MixMusic
2414 2618
2415int 2619int
2416volume (int volume = -1) 2620volume (int volume = -1)
2417 PROTOTYPE: ;$ 2621 PROTOTYPE: ;$
2418 CODE: 2622 CODE:
2430void 2634void
2431halt () 2635halt ()
2432 CODE: 2636 CODE:
2433 Mix_HaltMusic (); 2637 Mix_HaltMusic ();
2434 2638
2435CFPlus::MixMusic 2639DC::MixMusic
2436new (SV *class, CFPlus::RW rwops) 2640new (SV *class, DC::RW rwops)
2437 CODE: 2641 CODE:
2438 RETVAL = Mix_LoadMUS_RW (rwops); 2642 RETVAL = Mix_LoadMUS_RW (rwops);
2439 OUTPUT: 2643 OUTPUT:
2440 RETVAL 2644 RETVAL
2441 2645
2442void 2646void
2443DESTROY (CFPlus::MixMusic self) 2647DESTROY (DC::MixMusic self)
2444 CODE: 2648 CODE:
2445 Mix_FreeMusic (self); 2649 Mix_FreeMusic (self);
2446 2650
2447int 2651int
2448play (CFPlus::MixMusic self, int loops = -1) 2652play (DC::MixMusic self, int loops = -1)
2449 CODE: 2653 CODE:
2450 RETVAL = Mix_PlayMusic (self, loops); 2654 RETVAL = Mix_PlayMusic (self, loops);
2451 OUTPUT: 2655 OUTPUT:
2452 RETVAL 2656 RETVAL
2453 2657
2454void 2658void
2455fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) 2659fade_in_pos (DC::MixMusic self, int loops, int ms, double position)
2456 CODE: 2660 CODE:
2457 Mix_FadeInMusicPos (self, loops, ms, position); 2661 Mix_FadeInMusicPos (self, loops, ms, position);
2458 2662
2459MODULE = CFPlus PACKAGE = CFPlus::OpenGL 2663MODULE = Deliantra::Client PACKAGE = DC::OpenGL
2460 2664
2461PROTOTYPES: ENABLE 2665PROTOTYPES: ENABLE
2462 2666
2463BOOT: 2667BOOT:
2464{ 2668{
2465 HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); 2669 HV *stash = gv_stashpv ("DC::OpenGL", 1);
2466 static const struct { 2670 static const struct {
2467 const char *name; 2671 const char *name;
2468 IV iv; 2672 IV iv;
2469 } *civ, const_iv[] = { 2673 } *civ, const_iv[] = {
2470# define const_iv(name) { # name, (IV)name } 2674# define const_iv(name) { # name, (IV)name }
2505 const_iv (GL_INTENSITY), 2709 const_iv (GL_INTENSITY),
2506 const_iv (GL_LUMINANCE), 2710 const_iv (GL_LUMINANCE),
2507 const_iv (GL_LUMINANCE_ALPHA), 2711 const_iv (GL_LUMINANCE_ALPHA),
2508 const_iv (GL_FLOAT), 2712 const_iv (GL_FLOAT),
2509 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 2713 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
2714 const_iv (GL_COMPRESSED_ALPHA_ARB),
2715 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
2716 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
2717 const_iv (GL_COMPRESSED_INTENSITY_ARB),
2718 const_iv (GL_COMPRESSED_RGB_ARB),
2719 const_iv (GL_COMPRESSED_RGBA_ARB),
2510 const_iv (GL_COMPILE), 2720 const_iv (GL_COMPILE),
2511 const_iv (GL_PROXY_TEXTURE_1D), 2721 const_iv (GL_PROXY_TEXTURE_1D),
2512 const_iv (GL_PROXY_TEXTURE_2D), 2722 const_iv (GL_PROXY_TEXTURE_2D),
2513 const_iv (GL_TEXTURE_1D), 2723 const_iv (GL_TEXTURE_1D),
2514 const_iv (GL_TEXTURE_2D), 2724 const_iv (GL_TEXTURE_2D),
2553 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2763 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2554 const_iv (GL_POINT_SMOOTH_HINT), 2764 const_iv (GL_POINT_SMOOTH_HINT),
2555 const_iv (GL_LINE_SMOOTH_HINT), 2765 const_iv (GL_LINE_SMOOTH_HINT),
2556 const_iv (GL_POLYGON_SMOOTH_HINT), 2766 const_iv (GL_POLYGON_SMOOTH_HINT),
2557 const_iv (GL_GENERATE_MIPMAP_HINT), 2767 const_iv (GL_GENERATE_MIPMAP_HINT),
2768 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2558 const_iv (GL_FASTEST), 2769 const_iv (GL_FASTEST),
2559 const_iv (GL_DONT_CARE), 2770 const_iv (GL_DONT_CARE),
2560 const_iv (GL_NICEST), 2771 const_iv (GL_NICEST),
2561 const_iv (GL_V2F), 2772 const_iv (GL_V2F),
2562 const_iv (GL_V3F), 2773 const_iv (GL_V3F),
2570 2781
2571 texture_av = newAV (); 2782 texture_av = newAV ();
2572 AvREAL_off (texture_av); 2783 AvREAL_off (texture_av);
2573} 2784}
2574 2785
2786void
2787disable_GL_EXT_blend_func_separate ()
2788 CODE:
2789 gl.BlendFuncSeparate = 0;
2790 gl.BlendFuncSeparateEXT = 0;
2791
2575char * 2792char *
2576gl_vendor () 2793gl_vendor ()
2577 CODE: 2794 CODE:
2578 RETVAL = (char *)glGetString (GL_VENDOR); 2795 RETVAL = (char *)glGetString (GL_VENDOR);
2579 OUTPUT: 2796 OUTPUT:
2700 2917
2701void glRect (float x1, float y1, float x2, float y2) 2918void glRect (float x1, float y1, float x2, float y2)
2702 CODE: 2919 CODE:
2703 glRectf (x1, y1, x2, y2); 2920 glRectf (x1, y1, x2, y2);
2704 2921
2922void glRect_lineloop (float x1, float y1, float x2, float y2)
2923 CODE:
2924 glBegin (GL_LINE_LOOP);
2925 glVertex2f (x1, y1);
2926 glVertex2f (x2, y1);
2927 glVertex2f (x2, y2);
2928 glVertex2f (x1, y2);
2929 glEnd ();
2930
2705PROTOTYPES: ENABLE 2931PROTOTYPES: ENABLE
2706 2932
2707void glBegin (int mode) 2933void glBegin (int mode)
2708 2934
2709void glEnd () 2935void glEnd ()
2741void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) 2967void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column)
2742 CODE: 2968 CODE:
2743 if (gl.SeparableFilter2D) 2969 if (gl.SeparableFilter2D)
2744 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); 2970 gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column);
2745 2971
2746void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) 2972void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0)
2747 2973
2748void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) 2974void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border)
2749 2975
2750void glDrawPixels (int width, int height, int format, int type, char *pixels) 2976void glDrawPixels (int width, int height, int format, int type, char *pixels)
2751 2977
2777 3003
2778void glEndList () 3004void glEndList ()
2779 3005
2780void glCallList (int list) 3006void glCallList (int list)
2781 3007
2782MODULE = CFPlus PACKAGE = CFPlus::UI::Base 3008MODULE = Deliantra::Client PACKAGE = DC::UI::Base
2783 3009
2784PROTOTYPES: DISABLE 3010PROTOTYPES: DISABLE
2785 3011
2786void 3012void
2787find_widget (SV *self, NV x, NV y) 3013find_widget (SV *self, NV x, NV y)
2791 XPUSHs (self); 3017 XPUSHs (self);
2792} 3018}
2793 3019
2794BOOT: 3020BOOT:
2795{ 3021{
2796 hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); 3022 hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV);
2797 3023
2798 draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); 3024 draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV);
2799 draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); 3025 draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV);
2800 draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); 3026 draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV);
2801 draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); 3027 draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV);
2802} 3028}
2803 3029
2804void 3030void
2805draw (SV *self) 3031draw (SV *self)
2806 CODE: 3032 CODE:
2810 NV x, y, w, h; 3036 NV x, y, w, h;
2811 SV *draw_x_sv = GvSV (draw_x_gv); 3037 SV *draw_x_sv = GvSV (draw_x_gv);
2812 SV *draw_y_sv = GvSV (draw_y_gv); 3038 SV *draw_y_sv = GvSV (draw_y_gv);
2813 SV *draw_w_sv = GvSV (draw_w_gv); 3039 SV *draw_w_sv = GvSV (draw_w_gv);
2814 SV *draw_h_sv = GvSV (draw_h_gv); 3040 SV *draw_h_sv = GvSV (draw_h_gv);
2815 SV *hover;
2816 double draw_x, draw_y, draw_w, draw_h; 3041 double draw_x, draw_y;
2817 3042
2818 if (!SvROK (self)) 3043 if (!SvROK (self))
2819 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 3044 croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self));
2820 3045
2821 hv = (HV *)SvRV (self); 3046 hv = (HV *)SvRV (self);
2822 3047
2823 if (SvTYPE (hv) != SVt_PVHV) 3048 if (SvTYPE (hv) != SVt_PVHV)
2824 croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); 3049 croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self));
2825 3050
2826 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; 3051 svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.;
2827 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; 3052 svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.;
2828 3053
2829 if (!h || !w) 3054 if (!h || !w)
2849 { 3074 {
2850 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 3075 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2851 3076
2852 if (svp && SvTRUE (*svp)) 3077 if (svp && SvTRUE (*svp))
2853 { 3078 {
2854 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 3079 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2855 glEnable (GL_BLEND); 3080 glEnable (GL_BLEND);
2856 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 3081 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2857 glBegin (GL_QUADS); 3082 glBegin (GL_QUADS);
2858 glVertex2f (0, 0); 3083 glVertex2f (0, 0);
2859 glVertex2f (w, 0); 3084 glVertex2f (w, 0);
2862 glEnd (); 3087 glEnd ();
2863 glDisable (GL_BLEND); 3088 glDisable (GL_BLEND);
2864 } 3089 }
2865 } 3090 }
2866#if 0 3091#if 0
2867 if ($ENV{CFPLUS_DEBUG} & 1) { 3092 // draw borders, for debugging
2868 glPushMatrix; 3093 glPushMatrix ();
2869 glColor 1, 1, 0, 1; 3094 glColor4f (1., 1., 0., 1.);
2870 glTranslate 0.375, 0.375; 3095 glTranslatef (.5, .5, 0.);
2871 glBegin GL_LINE_LOOP; 3096 glBegin (GL_LINE_LOOP);
2872 glVertex 0 , 0; 3097 glVertex2f (0 , 0);
2873 glVertex $self->{w} - 1, 0; 3098 glVertex2f (w - 1, 0);
2874 glVertex $self->{w} - 1, $self->{h} - 1; 3099 glVertex2f (w - 1, h - 1);
2875 glVertex 0 , $self->{h} - 1; 3100 glVertex2f (0 , h - 1);
2876 glEnd; 3101 glEnd ();
2877 glPopMatrix; 3102 glPopMatrix ();
2878 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2879 }
2880#endif 3103#endif
2881 PUSHMARK (SP); 3104 PUSHMARK (SP);
2882 XPUSHs (self); 3105 XPUSHs (self);
2883 PUTBACK; 3106 PUTBACK;
2884 call_method ("_draw", G_VOID | G_DISCARD); 3107 call_method ("_draw", G_VOID | G_DISCARD);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines