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.275 by root, Thu Aug 28 00:53:53 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
85 90
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
91#if 1
92# define PARACHUTE SDL_INIT_NOPARACHUTE
93#else
94# define PARACHUTE 0
95#endif
96 95
97static AV *texture_av; 96static AV *texture_av;
98 97
99static struct 98static struct
100{ 99{
373 self->oy = 0; 372 self->oy = 0;
374 self->row = 0; 373 self->row = 0;
375 self->rows = 0; 374 self->rows = 0;
376} 375}
377 376
377#define CELL_CLEAR(cell) \
378 do { \
379 if ((cell)->player) \
380 (cell)->tile [2] = 0; \
381 (cell)->darkness = 0; \
382 (cell)->stat_hp = 0; \
383 (cell)->flags = 0; \
384 (cell)->player = 0; \
385 } while (0)
386
378static void 387static void
379map_blank (DC__Map self, int x0, int y0, int w, int h) 388map_blank (DC__Map self, int x0, int y0, int w, int h)
380{ 389{
381 int x, y; 390 int x, y;
382 maprow *row; 391 maprow *row;
396 if (x >= row->c1) 405 if (x >= row->c1)
397 break; 406 break;
398 407
399 cell = row->col + x - row->c0; 408 cell = row->col + x - row->c0;
400 409
401 cell->darkness = 0; 410 CELL_CLEAR (cell);
402 cell->stat_hp = 0;
403 cell->flags = 0;
404 cell->player = 0;
405 } 411 }
406 } 412 }
407} 413}
408 414
409typedef struct { 415typedef struct {
520 if (!svp || !SvTRUE (*svp)) 526 if (!svp || !SvTRUE (*svp))
521 return 0; 527 return 0;
522 528
523 return 1; 529 return 1;
524} 530}
531
532static void
533deliantra_main ()
534{
535 char *argv[] = { 0 };
536 call_argv ("::main", G_DISCARD | G_VOID, argv);
537}
538
539#ifdef __MACOSX__
540 /* to due surprising braindamage on the side of SDL design, we
541 * do some mind-boggling hack here: SDL requires a custom main()
542 * on OS X, so... we provide one and call the original main(), which,
543 * due to share dlibrary magic, calls -lSDLmain's main, not perl's main,
544 * and which calls our main (== SDL_main) back.
545 */
546 extern C_LINKAGE int
547 main (int argc, char *argv[])
548 {
549 deliantra_main ();
550 }
551
552 #undef main
553
554 extern C_LINKAGE int main (int argc, char *argv[]);
555
556 static void
557 SDL_braino (void)
558 {
559 char *argv[] = { "deliantra client", 0 };
560 (main) (1, argv);
561 }
562#else
563 static void
564 SDL_braino (void)
565 {
566 deliantra_main ();
567 }
568#endif
525 569
526MODULE = Deliantra::Client PACKAGE = DC 570MODULE = Deliantra::Client PACKAGE = DC
527 571
528PROTOTYPES: ENABLE 572PROTOTYPES: ENABLE
529 573
558 const_iv (SDL_USEREVENT), 602 const_iv (SDL_USEREVENT),
559 603
560 const_iv (SDL_APPINPUTFOCUS), 604 const_iv (SDL_APPINPUTFOCUS),
561 const_iv (SDL_APPMOUSEFOCUS), 605 const_iv (SDL_APPMOUSEFOCUS),
562 const_iv (SDL_APPACTIVE), 606 const_iv (SDL_APPACTIVE),
607
608
609 const_iv (SDLK_UNKNOWN),
610 const_iv (SDLK_FIRST),
611 const_iv (SDLK_BACKSPACE),
612 const_iv (SDLK_TAB),
613 const_iv (SDLK_CLEAR),
614 const_iv (SDLK_RETURN),
615 const_iv (SDLK_PAUSE),
616 const_iv (SDLK_ESCAPE),
617 const_iv (SDLK_SPACE),
618 const_iv (SDLK_EXCLAIM),
619 const_iv (SDLK_QUOTEDBL),
620 const_iv (SDLK_HASH),
621 const_iv (SDLK_DOLLAR),
622 const_iv (SDLK_AMPERSAND),
623 const_iv (SDLK_QUOTE),
624 const_iv (SDLK_LEFTPAREN),
625 const_iv (SDLK_RIGHTPAREN),
626 const_iv (SDLK_ASTERISK),
627 const_iv (SDLK_PLUS),
628 const_iv (SDLK_COMMA),
629 const_iv (SDLK_MINUS),
630 const_iv (SDLK_PERIOD),
631 const_iv (SDLK_SLASH),
632 const_iv (SDLK_0),
633 const_iv (SDLK_1),
634 const_iv (SDLK_2),
635 const_iv (SDLK_3),
636 const_iv (SDLK_4),
637 const_iv (SDLK_5),
638 const_iv (SDLK_6),
639 const_iv (SDLK_7),
640 const_iv (SDLK_8),
641 const_iv (SDLK_9),
642 const_iv (SDLK_COLON),
643 const_iv (SDLK_SEMICOLON),
644 const_iv (SDLK_LESS),
645 const_iv (SDLK_EQUALS),
646 const_iv (SDLK_GREATER),
647 const_iv (SDLK_QUESTION),
648 const_iv (SDLK_AT),
649
650 const_iv (SDLK_LEFTBRACKET),
651 const_iv (SDLK_BACKSLASH),
652 const_iv (SDLK_RIGHTBRACKET),
653 const_iv (SDLK_CARET),
654 const_iv (SDLK_UNDERSCORE),
655 const_iv (SDLK_BACKQUOTE),
656 const_iv (SDLK_DELETE),
563 657
564 const_iv (SDLK_FIRST), 658 const_iv (SDLK_FIRST),
565 const_iv (SDLK_LAST), 659 const_iv (SDLK_LAST),
566 const_iv (SDLK_KP0), 660 const_iv (SDLK_KP0),
567 const_iv (SDLK_KP1), 661 const_iv (SDLK_KP1),
644 const_iv (KMOD_NUM), 738 const_iv (KMOD_NUM),
645 const_iv (KMOD_CAPS), 739 const_iv (KMOD_CAPS),
646 const_iv (KMOD_MODE), 740 const_iv (KMOD_MODE),
647 741
648 const_iv (MIX_DEFAULT_FORMAT), 742 const_iv (MIX_DEFAULT_FORMAT),
743
744 const_iv (SDL_INIT_TIMER),
745 const_iv (SDL_INIT_AUDIO),
746 const_iv (SDL_INIT_VIDEO),
747 const_iv (SDL_INIT_CDROM),
748 const_iv (SDL_INIT_JOYSTICK),
749 const_iv (SDL_INIT_EVERYTHING),
750 const_iv (SDL_INIT_NOPARACHUTE),
751 const_iv (SDL_INIT_EVENTTHREAD),
752
753 const_iv (SDL_GL_RED_SIZE),
754 const_iv (SDL_GL_GREEN_SIZE),
755 const_iv (SDL_GL_BLUE_SIZE),
756 const_iv (SDL_GL_ALPHA_SIZE),
757 const_iv (SDL_GL_DOUBLEBUFFER),
758 const_iv (SDL_GL_BUFFER_SIZE),
759 const_iv (SDL_GL_DEPTH_SIZE),
760 const_iv (SDL_GL_STENCIL_SIZE),
761 const_iv (SDL_GL_ACCUM_RED_SIZE),
762 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
763 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
764 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
765 const_iv (SDL_GL_STEREO),
766 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
767 const_iv (SDL_GL_MULTISAMPLESAMPLES),
768 const_iv (SDL_GL_ACCELERATED_VISUAL),
769 const_iv (SDL_GL_SWAP_CONTROL),
770
771 const_iv (FOW_DARKNESS)
649# undef const_iv 772# undef const_iv
650 }; 773 };
651 774
652 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 775 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
653 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 776 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
689 pango_context_set_language (opengl_context, pango_language_from_string ("en")); 812 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
690 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ 813 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
691#endif 814#endif
692} 815}
693 816
694char *
695SDL_GetError () 817char *SDL_GetError ()
696 818
697int 819void SDL_braino ()
698SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
699 820
700void 821int SDL_Init (U32 flags)
822
823int SDL_InitSubSystem (U32 flags)
824
825void SDL_QuitSubSystem (U32 flags)
826
701SDL_Quit () 827void SDL_Quit ()
828
829int SDL_GL_SetAttribute (int attr, int value)
830
831int SDL_GL_GetAttribute (int attr)
832 CODE:
833 if (SDL_GL_GetAttribute (attr, &RETVAL))
834 XSRETURN_UNDEF;
835 OUTPUT:
836 RETVAL
702 837
703void 838void
704SDL_ListModes (int rgb, int alpha) 839SDL_ListModes (int rgb, int alpha)
705 PPCODE: 840 PPCODE:
706{ 841{
718 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 853 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
719 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 854 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
720 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 855 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
721 856
722 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 857 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); 858 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
726#endif
727 859
728 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 860 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
729 861
730 if (m && m != (SDL_Rect **)-1) 862 if (m && m != (SDL_Rect **)-1)
731 while (*m) 863 while (*m)
732 { 864 {
733 if ((*m)->w >= 800 && (*m)->h >= 480) 865 if ((*m)->w >= 400 && (*m)->h >= 300)
734 { 866 {
735 AV *av = newAV (); 867 AV *av = newAV ();
736 av_push (av, newSViv ((*m)->w)); 868 av_push (av, newSViv ((*m)->w));
737 av_push (av, newSViv ((*m)->h)); 869 av_push (av, newSViv ((*m)->h));
738 av_push (av, newSViv (rgb)); 870 av_push (av, newSViv (rgb));
1752 } 1884 }
1753 } 1885 }
1754 } 1886 }
1755 } 1887 }
1756 else 1888 else
1757 cell->darkness = 0; 1889 CELL_CLEAR (cell);
1758 } 1890 }
1759} 1891}
1760 OUTPUT: 1892 OUTPUT:
1761 RETVAL 1893 RETVAL
1762 1894
1814} 1946}
1815 OUTPUT: 1947 OUTPUT:
1816 RETVAL 1948 RETVAL
1817 1949
1818void 1950void
1819draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int pdx = 0, int pdy = 0) 1951draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1820 CODE: 1952 CODE:
1821{ 1953{
1822 int x, y, z; 1954 int x, y, z;
1823 1955
1824 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1956 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2071 } 2203 }
2072 2204
2073 if (pl_tex.name) 2205 if (pl_tex.name)
2074 { 2206 {
2075 maptex tex = pl_tex; 2207 maptex tex = pl_tex;
2076 int px = pl_x + pdx; 2208 int px = pl_x + sdx;
2077 int py = pl_y + pdy; 2209 int py = pl_y + sdy;
2078 2210
2079 key.texname = tex.name; 2211 key.texname = tex.name;
2080 arr = rc_array (rc, &key); 2212 arr = rc_array (rc, &key);
2081 2213
2082 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2214 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2199 SvCUR_set (darkness3_sv, sw34 * sh3); 2331 SvCUR_set (darkness3_sv, sw34 * sh3);
2200 2332
2201 mx += self->x - 1; 2333 mx += self->x - 1;
2202 my += self->y - 1; 2334 my += self->y - 1;
2203 2335
2204 memset (darkness1, 255, sw1 * sh1); 2336 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2205 2337
2206 for (y = 0; y < sh1; y++) 2338 for (y = 0; y < sh1; y++)
2207 if (0 <= y + my && y + my < self->rows) 2339 if (0 <= y + my && y + my < self->rows)
2208 { 2340 {
2209 maprow *row = self->row + (y + my); 2341 maprow *row = self->row + (y + my);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines