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.262 by root, Wed Jul 16 20:12:27 2008 UTC vs.
Revision 1.276 by root, Sat Aug 30 08:04:01 2008 UTC

39#include <SDL_endian.h> 39#include <SDL_endian.h>
40#include <SDL_image.h> 40#include <SDL_image.h>
41#include <SDL_mixer.h> 41#include <SDL_mixer.h>
42#include <SDL_opengl.h> 42#include <SDL_opengl.h>
43 43
44/* work around os x broken headers */
45#ifdef __MACOSX__
46typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
47#endif
48
44#define PANGO_ENABLE_BACKEND 49#define PANGO_ENABLE_BACKEND
45#define G_DISABLE_CAST_CHECKS 50#define G_DISABLE_CAST_CHECKS
46 51
47#include <glib/gmacros.h> 52#include <glib/gmacros.h>
48 53
86#define MIN_FONT_HEIGHT 10 91#define MIN_FONT_HEIGHT 10
87 92
88/* mask out modifiers we are not interested in */ 93/* mask out modifiers we are not interested in */
89#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) 94#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
90 95
91#if 1 96#define KMOD_LRAM 0x10000 // our extension
92# define PARACHUTE SDL_INIT_NOPARACHUTE
93#else
94# define PARACHUTE 0
95#endif
96 97
97static AV *texture_av; 98static AV *texture_av;
98 99
99static struct 100static struct
100{ 101{
373 self->oy = 0; 374 self->oy = 0;
374 self->row = 0; 375 self->row = 0;
375 self->rows = 0; 376 self->rows = 0;
376} 377}
377 378
379#define CELL_CLEAR(cell) \
380 do { \
381 if ((cell)->player) \
382 (cell)->tile [2] = 0; \
383 (cell)->darkness = 0; \
384 (cell)->stat_hp = 0; \
385 (cell)->flags = 0; \
386 (cell)->player = 0; \
387 } while (0)
388
378static void 389static void
379map_blank (DC__Map self, int x0, int y0, int w, int h) 390map_blank (DC__Map self, int x0, int y0, int w, int h)
380{ 391{
381 int x, y; 392 int x, y;
382 maprow *row; 393 maprow *row;
396 if (x >= row->c1) 407 if (x >= row->c1)
397 break; 408 break;
398 409
399 cell = row->col + x - row->c0; 410 cell = row->col + x - row->c0;
400 411
401 cell->darkness = 0; 412 CELL_CLEAR (cell);
402 cell->stat_hp = 0;
403 cell->flags = 0;
404 cell->player = 0;
405 } 413 }
406 } 414 }
407} 415}
408 416
409typedef struct { 417typedef struct {
520 if (!svp || !SvTRUE (*svp)) 528 if (!svp || !SvTRUE (*svp))
521 return 0; 529 return 0;
522 530
523 return 1; 531 return 1;
524} 532}
533
534/* process keyboard modifiers */
535static int
536mod_munge (int mod)
537{
538 mod &= MOD_MASK;
539
540 if (mod & (KMOD_META | KMOD_ALT))
541 mod |= KMOD_LRAM;
542
543 return mod;
544}
545
546static void
547deliantra_main ()
548{
549 char *argv[] = { 0 };
550 call_argv ("::main", G_DISCARD | G_VOID, argv);
551}
552
553#ifdef __MACOSX__
554 /* to due surprising braindamage on the side of SDL design, we
555 * do some mind-boggling hack here: SDL requires a custom main()
556 * on OS X, so... we provide one and call the original main(), which,
557 * due to share dlibrary magic, calls -lSDLmain's main, not perl's main,
558 * and which calls our main (== SDL_main) back.
559 */
560 extern C_LINKAGE int
561 main (int argc, char *argv[])
562 {
563 deliantra_main ();
564 }
565
566 #undef main
567
568 extern C_LINKAGE int main (int argc, char *argv[]);
569
570 static void
571 SDL_braino (void)
572 {
573 char *argv[] = { "deliantra client", 0 };
574 (main) (1, argv);
575 }
576#else
577 static void
578 SDL_braino (void)
579 {
580 deliantra_main ();
581 }
582#endif
525 583
526MODULE = Deliantra::Client PACKAGE = DC 584MODULE = Deliantra::Client PACKAGE = DC
527 585
528PROTOTYPES: ENABLE 586PROTOTYPES: ENABLE
529 587
558 const_iv (SDL_USEREVENT), 616 const_iv (SDL_USEREVENT),
559 617
560 const_iv (SDL_APPINPUTFOCUS), 618 const_iv (SDL_APPINPUTFOCUS),
561 const_iv (SDL_APPMOUSEFOCUS), 619 const_iv (SDL_APPMOUSEFOCUS),
562 const_iv (SDL_APPACTIVE), 620 const_iv (SDL_APPACTIVE),
621
622
623 const_iv (SDLK_UNKNOWN),
624 const_iv (SDLK_FIRST),
625 const_iv (SDLK_BACKSPACE),
626 const_iv (SDLK_TAB),
627 const_iv (SDLK_CLEAR),
628 const_iv (SDLK_RETURN),
629 const_iv (SDLK_PAUSE),
630 const_iv (SDLK_ESCAPE),
631 const_iv (SDLK_SPACE),
632 const_iv (SDLK_EXCLAIM),
633 const_iv (SDLK_QUOTEDBL),
634 const_iv (SDLK_HASH),
635 const_iv (SDLK_DOLLAR),
636 const_iv (SDLK_AMPERSAND),
637 const_iv (SDLK_QUOTE),
638 const_iv (SDLK_LEFTPAREN),
639 const_iv (SDLK_RIGHTPAREN),
640 const_iv (SDLK_ASTERISK),
641 const_iv (SDLK_PLUS),
642 const_iv (SDLK_COMMA),
643 const_iv (SDLK_MINUS),
644 const_iv (SDLK_PERIOD),
645 const_iv (SDLK_SLASH),
646 const_iv (SDLK_0),
647 const_iv (SDLK_1),
648 const_iv (SDLK_2),
649 const_iv (SDLK_3),
650 const_iv (SDLK_4),
651 const_iv (SDLK_5),
652 const_iv (SDLK_6),
653 const_iv (SDLK_7),
654 const_iv (SDLK_8),
655 const_iv (SDLK_9),
656 const_iv (SDLK_COLON),
657 const_iv (SDLK_SEMICOLON),
658 const_iv (SDLK_LESS),
659 const_iv (SDLK_EQUALS),
660 const_iv (SDLK_GREATER),
661 const_iv (SDLK_QUESTION),
662 const_iv (SDLK_AT),
663
664 const_iv (SDLK_LEFTBRACKET),
665 const_iv (SDLK_BACKSLASH),
666 const_iv (SDLK_RIGHTBRACKET),
667 const_iv (SDLK_CARET),
668 const_iv (SDLK_UNDERSCORE),
669 const_iv (SDLK_BACKQUOTE),
670 const_iv (SDLK_DELETE),
563 671
564 const_iv (SDLK_FIRST), 672 const_iv (SDLK_FIRST),
565 const_iv (SDLK_LAST), 673 const_iv (SDLK_LAST),
566 const_iv (SDLK_KP0), 674 const_iv (SDLK_KP0),
567 const_iv (SDLK_KP1), 675 const_iv (SDLK_KP1),
643 const_iv (KMOD_RMETA), 751 const_iv (KMOD_RMETA),
644 const_iv (KMOD_NUM), 752 const_iv (KMOD_NUM),
645 const_iv (KMOD_CAPS), 753 const_iv (KMOD_CAPS),
646 const_iv (KMOD_MODE), 754 const_iv (KMOD_MODE),
647 755
756 const_iv (KMOD_LRAM),
757
648 const_iv (MIX_DEFAULT_FORMAT), 758 const_iv (MIX_DEFAULT_FORMAT),
759
760 const_iv (SDL_INIT_TIMER),
761 const_iv (SDL_INIT_AUDIO),
762 const_iv (SDL_INIT_VIDEO),
763 const_iv (SDL_INIT_CDROM),
764 const_iv (SDL_INIT_JOYSTICK),
765 const_iv (SDL_INIT_EVERYTHING),
766 const_iv (SDL_INIT_NOPARACHUTE),
767 const_iv (SDL_INIT_EVENTTHREAD),
768
769 const_iv (SDL_GL_RED_SIZE),
770 const_iv (SDL_GL_GREEN_SIZE),
771 const_iv (SDL_GL_BLUE_SIZE),
772 const_iv (SDL_GL_ALPHA_SIZE),
773 const_iv (SDL_GL_DOUBLEBUFFER),
774 const_iv (SDL_GL_BUFFER_SIZE),
775 const_iv (SDL_GL_DEPTH_SIZE),
776 const_iv (SDL_GL_STENCIL_SIZE),
777 const_iv (SDL_GL_ACCUM_RED_SIZE),
778 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
779 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
780 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
781 const_iv (SDL_GL_STEREO),
782 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
783 const_iv (SDL_GL_MULTISAMPLESAMPLES),
784 const_iv (SDL_GL_ACCELERATED_VISUAL),
785 const_iv (SDL_GL_SWAP_CONTROL),
786
787 const_iv (FOW_DARKNESS)
649# undef const_iv 788# undef const_iv
650 }; 789 };
651 790
652 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 791 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
653 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 792 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
689 pango_context_set_language (opengl_context, pango_language_from_string ("en")); 828 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
690 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ 829 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
691#endif 830#endif
692} 831}
693 832
694char *
695SDL_GetError () 833char *SDL_GetError ()
696 834
697int 835void SDL_braino ()
698SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
699 836
700void 837int SDL_Init (U32 flags)
838
839int SDL_InitSubSystem (U32 flags)
840
841void SDL_QuitSubSystem (U32 flags)
842
701SDL_Quit () 843void SDL_Quit ()
844
845int SDL_GL_SetAttribute (int attr, int value)
846
847int SDL_GL_GetAttribute (int attr)
848 CODE:
849 if (SDL_GL_GetAttribute (attr, &RETVAL))
850 XSRETURN_UNDEF;
851 OUTPUT:
852 RETVAL
702 853
703void 854void
704SDL_ListModes (int rgb, int alpha) 855SDL_ListModes (int rgb, int alpha)
705 PPCODE: 856 PPCODE:
706{ 857{
718 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 869 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
719 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 870 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
720 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 871 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
721 872
722 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 873 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
723#if SDL_VERSION_ATLEAST(1,2,10)
724 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
725 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 874 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
726#endif
727 875
728 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 876 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
729 877
730 if (m && m != (SDL_Rect **)-1) 878 if (m && m != (SDL_Rect **)-1)
731 while (*m) 879 while (*m)
732 { 880 {
733 if ((*m)->w >= 800 && (*m)->h >= 480) 881 if ((*m)->w >= 400 && (*m)->h >= 300)
734 { 882 {
735 AV *av = newAV (); 883 AV *av = newAV ();
736 av_push (av, newSViv ((*m)->w)); 884 av_push (av, newSViv ((*m)->w));
737 av_push (av, newSViv ((*m)->h)); 885 av_push (av, newSViv ((*m)->h));
738 av_push (av, newSViv (rgb)); 886 av_push (av, newSViv (rgb));
801 { 949 {
802 case SDL_KEYDOWN: 950 case SDL_KEYDOWN:
803 case SDL_KEYUP: 951 case SDL_KEYUP:
804 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 952 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
805 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 953 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
806 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); 954 hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0);
807 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ 955 hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */
808 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 956 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
809 break; 957 break;
810 958
811 case SDL_ACTIVEEVENT: 959 case SDL_ACTIVEEVENT:
812 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 960 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
830 x = ev.motion.x; 978 x = ev.motion.x;
831 y = ev.motion.y; 979 y = ev.motion.y;
832 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 980 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
833 } 981 }
834 982
835 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); 983 hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0);
836 hv_store (hv, "state", 5, newSViv (state), 0); 984 hv_store (hv, "state", 5, newSViv (state), 0);
837 hv_store (hv, "x", 1, newSViv (x), 0); 985 hv_store (hv, "x", 1, newSViv (x), 0);
838 hv_store (hv, "y", 1, newSViv (y), 0); 986 hv_store (hv, "y", 1, newSViv (y), 0);
839 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 987 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
840 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 988 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
1752 } 1900 }
1753 } 1901 }
1754 } 1902 }
1755 } 1903 }
1756 else 1904 else
1757 cell->darkness = 0; 1905 CELL_CLEAR (cell);
1758 } 1906 }
1759} 1907}
1760 OUTPUT: 1908 OUTPUT:
1761 RETVAL 1909 RETVAL
1762 1910
1814} 1962}
1815 OUTPUT: 1963 OUTPUT:
1816 RETVAL 1964 RETVAL
1817 1965
1818void 1966void
1819draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int pdx = 0, int pdy = 0) 1967draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1820 CODE: 1968 CODE:
1821{ 1969{
1822 int x, y, z; 1970 int x, y, z;
1823 1971
1824 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1972 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2071 } 2219 }
2072 2220
2073 if (pl_tex.name) 2221 if (pl_tex.name)
2074 { 2222 {
2075 maptex tex = pl_tex; 2223 maptex tex = pl_tex;
2076 int px = pl_x + pdx; 2224 int px = pl_x + sdx;
2077 int py = pl_y + pdy; 2225 int py = pl_y + sdy;
2078 2226
2079 key.texname = tex.name; 2227 key.texname = tex.name;
2080 arr = rc_array (rc, &key); 2228 arr = rc_array (rc, &key);
2081 2229
2082 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2230 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2199 SvCUR_set (darkness3_sv, sw34 * sh3); 2347 SvCUR_set (darkness3_sv, sw34 * sh3);
2200 2348
2201 mx += self->x - 1; 2349 mx += self->x - 1;
2202 my += self->y - 1; 2350 my += self->y - 1;
2203 2351
2204 memset (darkness1, 255, sw1 * sh1); 2352 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2205 2353
2206 for (y = 0; y < sh1; y++) 2354 for (y = 0; y < sh1; y++)
2207 if (0 <= y + my && y + my < self->rows) 2355 if (0 <= y + my && y + my < self->rows)
2208 { 2356 {
2209 maprow *row = self->row + (y + my); 2357 maprow *row = self->row + (y + my);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines