… | |
… | |
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__ |
|
|
46 | typedef 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 | |
97 | static AV *texture_av; |
98 | static AV *texture_av; |
98 | |
99 | |
99 | static struct |
100 | static 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 | |
378 | static void |
389 | static void |
379 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
390 | map_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 | |
409 | typedef struct { |
417 | typedef 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 | /******************************************************************************/ |
|
|
535 | |
|
|
536 | /* process keyboard modifiers */ |
|
|
537 | static int |
|
|
538 | mod_munge (int mod) |
|
|
539 | { |
|
|
540 | mod &= MOD_MASK; |
|
|
541 | |
|
|
542 | if (mod & (KMOD_META | KMOD_ALT)) |
|
|
543 | mod |= KMOD_LRAM; |
|
|
544 | |
|
|
545 | return mod; |
|
|
546 | } |
|
|
547 | |
|
|
548 | static void |
|
|
549 | deliantra_main () |
|
|
550 | { |
|
|
551 | char *argv[] = { 0 }; |
|
|
552 | call_argv ("::main", G_DISCARD | G_VOID, argv); |
|
|
553 | } |
|
|
554 | |
|
|
555 | #ifdef __MACOSX__ |
|
|
556 | /* to due surprising braindamage on the side of SDL design, we |
|
|
557 | * do some mind-boggling hack here: SDL requires a custom main() |
|
|
558 | * on OS X, so... we provide one and call the original main(), which, |
|
|
559 | * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, |
|
|
560 | * and which calls our main (== SDL_main) back. |
|
|
561 | */ |
|
|
562 | extern C_LINKAGE int |
|
|
563 | main (int argc, char *argv[]) |
|
|
564 | { |
|
|
565 | deliantra_main (); |
|
|
566 | } |
|
|
567 | |
|
|
568 | #undef main |
|
|
569 | |
|
|
570 | extern C_LINKAGE int main (int argc, char *argv[]); |
|
|
571 | |
|
|
572 | static void |
|
|
573 | SDL_braino (void) |
|
|
574 | { |
|
|
575 | char *argv[] = { "deliantra client", 0 }; |
|
|
576 | (main) (1, argv); |
|
|
577 | } |
|
|
578 | #else |
|
|
579 | static void |
|
|
580 | SDL_braino (void) |
|
|
581 | { |
|
|
582 | deliantra_main (); |
|
|
583 | } |
|
|
584 | #endif |
525 | |
585 | |
526 | MODULE = Deliantra::Client PACKAGE = DC |
586 | MODULE = Deliantra::Client PACKAGE = DC |
527 | |
587 | |
528 | PROTOTYPES: ENABLE |
588 | PROTOTYPES: ENABLE |
529 | |
589 | |
… | |
… | |
558 | const_iv (SDL_USEREVENT), |
618 | const_iv (SDL_USEREVENT), |
559 | |
619 | |
560 | const_iv (SDL_APPINPUTFOCUS), |
620 | const_iv (SDL_APPINPUTFOCUS), |
561 | const_iv (SDL_APPMOUSEFOCUS), |
621 | const_iv (SDL_APPMOUSEFOCUS), |
562 | const_iv (SDL_APPACTIVE), |
622 | const_iv (SDL_APPACTIVE), |
|
|
623 | |
|
|
624 | |
|
|
625 | const_iv (SDLK_UNKNOWN), |
|
|
626 | const_iv (SDLK_FIRST), |
|
|
627 | const_iv (SDLK_BACKSPACE), |
|
|
628 | const_iv (SDLK_TAB), |
|
|
629 | const_iv (SDLK_CLEAR), |
|
|
630 | const_iv (SDLK_RETURN), |
|
|
631 | const_iv (SDLK_PAUSE), |
|
|
632 | const_iv (SDLK_ESCAPE), |
|
|
633 | const_iv (SDLK_SPACE), |
|
|
634 | const_iv (SDLK_EXCLAIM), |
|
|
635 | const_iv (SDLK_QUOTEDBL), |
|
|
636 | const_iv (SDLK_HASH), |
|
|
637 | const_iv (SDLK_DOLLAR), |
|
|
638 | const_iv (SDLK_AMPERSAND), |
|
|
639 | const_iv (SDLK_QUOTE), |
|
|
640 | const_iv (SDLK_LEFTPAREN), |
|
|
641 | const_iv (SDLK_RIGHTPAREN), |
|
|
642 | const_iv (SDLK_ASTERISK), |
|
|
643 | const_iv (SDLK_PLUS), |
|
|
644 | const_iv (SDLK_COMMA), |
|
|
645 | const_iv (SDLK_MINUS), |
|
|
646 | const_iv (SDLK_PERIOD), |
|
|
647 | const_iv (SDLK_SLASH), |
|
|
648 | const_iv (SDLK_0), |
|
|
649 | const_iv (SDLK_1), |
|
|
650 | const_iv (SDLK_2), |
|
|
651 | const_iv (SDLK_3), |
|
|
652 | const_iv (SDLK_4), |
|
|
653 | const_iv (SDLK_5), |
|
|
654 | const_iv (SDLK_6), |
|
|
655 | const_iv (SDLK_7), |
|
|
656 | const_iv (SDLK_8), |
|
|
657 | const_iv (SDLK_9), |
|
|
658 | const_iv (SDLK_COLON), |
|
|
659 | const_iv (SDLK_SEMICOLON), |
|
|
660 | const_iv (SDLK_LESS), |
|
|
661 | const_iv (SDLK_EQUALS), |
|
|
662 | const_iv (SDLK_GREATER), |
|
|
663 | const_iv (SDLK_QUESTION), |
|
|
664 | const_iv (SDLK_AT), |
|
|
665 | |
|
|
666 | const_iv (SDLK_LEFTBRACKET), |
|
|
667 | const_iv (SDLK_BACKSLASH), |
|
|
668 | const_iv (SDLK_RIGHTBRACKET), |
|
|
669 | const_iv (SDLK_CARET), |
|
|
670 | const_iv (SDLK_UNDERSCORE), |
|
|
671 | const_iv (SDLK_BACKQUOTE), |
|
|
672 | const_iv (SDLK_DELETE), |
563 | |
673 | |
564 | const_iv (SDLK_FIRST), |
674 | const_iv (SDLK_FIRST), |
565 | const_iv (SDLK_LAST), |
675 | const_iv (SDLK_LAST), |
566 | const_iv (SDLK_KP0), |
676 | const_iv (SDLK_KP0), |
567 | const_iv (SDLK_KP1), |
677 | const_iv (SDLK_KP1), |
… | |
… | |
643 | const_iv (KMOD_RMETA), |
753 | const_iv (KMOD_RMETA), |
644 | const_iv (KMOD_NUM), |
754 | const_iv (KMOD_NUM), |
645 | const_iv (KMOD_CAPS), |
755 | const_iv (KMOD_CAPS), |
646 | const_iv (KMOD_MODE), |
756 | const_iv (KMOD_MODE), |
647 | |
757 | |
|
|
758 | const_iv (KMOD_LRAM), |
|
|
759 | |
648 | const_iv (MIX_DEFAULT_FORMAT), |
760 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
761 | |
|
|
762 | const_iv (SDL_INIT_TIMER), |
|
|
763 | const_iv (SDL_INIT_AUDIO), |
|
|
764 | const_iv (SDL_INIT_VIDEO), |
|
|
765 | const_iv (SDL_INIT_CDROM), |
|
|
766 | const_iv (SDL_INIT_JOYSTICK), |
|
|
767 | const_iv (SDL_INIT_EVERYTHING), |
|
|
768 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
769 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
770 | |
|
|
771 | const_iv (SDL_GL_RED_SIZE), |
|
|
772 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
773 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
774 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
775 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
776 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
777 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
778 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
779 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
780 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
781 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
782 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
783 | const_iv (SDL_GL_STEREO), |
|
|
784 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
785 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
786 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
787 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
788 | |
|
|
789 | const_iv (FOW_DARKNESS) |
649 | # undef const_iv |
790 | # undef const_iv |
650 | }; |
791 | }; |
651 | |
792 | |
652 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
793 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
653 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
794 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
689 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
830 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
690 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
831 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
691 | #endif |
832 | #endif |
692 | } |
833 | } |
693 | |
834 | |
694 | char * |
|
|
695 | SDL_GetError () |
835 | char *SDL_GetError () |
696 | |
836 | |
697 | int |
837 | void SDL_braino () |
698 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
|
|
699 | |
838 | |
700 | void |
839 | int SDL_Init (U32 flags) |
|
|
840 | |
|
|
841 | int SDL_InitSubSystem (U32 flags) |
|
|
842 | |
|
|
843 | void SDL_QuitSubSystem (U32 flags) |
|
|
844 | |
701 | SDL_Quit () |
845 | void SDL_Quit () |
|
|
846 | |
|
|
847 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
848 | |
|
|
849 | int SDL_GL_GetAttribute (int attr) |
|
|
850 | CODE: |
|
|
851 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
|
|
852 | XSRETURN_UNDEF; |
|
|
853 | OUTPUT: |
|
|
854 | RETVAL |
702 | |
855 | |
703 | void |
856 | void |
704 | SDL_ListModes (int rgb, int alpha) |
857 | SDL_ListModes (int rgb, int alpha) |
705 | PPCODE: |
858 | PPCODE: |
706 | { |
859 | { |
… | |
… | |
718 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
871 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
719 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
872 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
720 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
873 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
721 | |
874 | |
722 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
875 | 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); |
876 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
726 | #endif |
|
|
727 | |
877 | |
728 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
878 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
729 | |
879 | |
730 | if (m && m != (SDL_Rect **)-1) |
880 | if (m && m != (SDL_Rect **)-1) |
731 | while (*m) |
881 | while (*m) |
732 | { |
882 | { |
733 | if ((*m)->w >= 800 && (*m)->h >= 480) |
883 | if ((*m)->w >= 400 && (*m)->h >= 300) |
734 | { |
884 | { |
735 | AV *av = newAV (); |
885 | AV *av = newAV (); |
736 | av_push (av, newSViv ((*m)->w)); |
886 | av_push (av, newSViv ((*m)->w)); |
737 | av_push (av, newSViv ((*m)->h)); |
887 | av_push (av, newSViv ((*m)->h)); |
738 | av_push (av, newSViv (rgb)); |
888 | av_push (av, newSViv (rgb)); |
… | |
… | |
801 | { |
951 | { |
802 | case SDL_KEYDOWN: |
952 | case SDL_KEYDOWN: |
803 | case SDL_KEYUP: |
953 | case SDL_KEYUP: |
804 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
954 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
805 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
955 | 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); |
956 | 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 */ |
957 | 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); |
958 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
809 | break; |
959 | break; |
810 | |
960 | |
811 | case SDL_ACTIVEEVENT: |
961 | case SDL_ACTIVEEVENT: |
812 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
962 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
830 | x = ev.motion.x; |
980 | x = ev.motion.x; |
831 | y = ev.motion.y; |
981 | y = ev.motion.y; |
832 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
982 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
833 | } |
983 | } |
834 | |
984 | |
835 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
985 | hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); |
836 | hv_store (hv, "state", 5, newSViv (state), 0); |
986 | hv_store (hv, "state", 5, newSViv (state), 0); |
837 | hv_store (hv, "x", 1, newSViv (x), 0); |
987 | hv_store (hv, "x", 1, newSViv (x), 0); |
838 | hv_store (hv, "y", 1, newSViv (y), 0); |
988 | hv_store (hv, "y", 1, newSViv (y), 0); |
839 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
989 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
840 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
990 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
… | |
… | |
1752 | } |
1902 | } |
1753 | } |
1903 | } |
1754 | } |
1904 | } |
1755 | } |
1905 | } |
1756 | else |
1906 | else |
1757 | cell->darkness = 0; |
1907 | CELL_CLEAR (cell); |
1758 | } |
1908 | } |
1759 | } |
1909 | } |
1760 | OUTPUT: |
1910 | OUTPUT: |
1761 | RETVAL |
1911 | RETVAL |
1762 | |
1912 | |
… | |
… | |
1814 | } |
1964 | } |
1815 | OUTPUT: |
1965 | OUTPUT: |
1816 | RETVAL |
1966 | RETVAL |
1817 | |
1967 | |
1818 | void |
1968 | void |
1819 | draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int pdx = 0, int pdy = 0) |
1969 | draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
1820 | CODE: |
1970 | CODE: |
1821 | { |
1971 | { |
1822 | int x, y, z; |
1972 | int x, y, z; |
1823 | |
1973 | |
1824 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1974 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
… | |
… | |
2071 | } |
2221 | } |
2072 | |
2222 | |
2073 | if (pl_tex.name) |
2223 | if (pl_tex.name) |
2074 | { |
2224 | { |
2075 | maptex tex = pl_tex; |
2225 | maptex tex = pl_tex; |
2076 | int px = pl_x + pdx; |
2226 | int px = pl_x + sdx; |
2077 | int py = pl_y + pdy; |
2227 | int py = pl_y + sdy; |
2078 | |
2228 | |
2079 | key.texname = tex.name; |
2229 | key.texname = tex.name; |
2080 | arr = rc_array (rc, &key); |
2230 | arr = rc_array (rc, &key); |
2081 | |
2231 | |
2082 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2232 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
… | |
… | |
2199 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2349 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2200 | |
2350 | |
2201 | mx += self->x - 1; |
2351 | mx += self->x - 1; |
2202 | my += self->y - 1; |
2352 | my += self->y - 1; |
2203 | |
2353 | |
2204 | memset (darkness1, 255, sw1 * sh1); |
2354 | memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); |
2205 | |
2355 | |
2206 | for (y = 0; y < sh1; y++) |
2356 | for (y = 0; y < sh1; y++) |
2207 | if (0 <= y + my && y + my < self->rows) |
2357 | if (0 <= y + my && y + my < self->rows) |
2208 | { |
2358 | { |
2209 | maprow *row = self->row + (y + my); |
2359 | maprow *row = self->row + (y + my); |
… | |
… | |
2851 | void glRotate (float angle, float x, float y, float z) |
3001 | void glRotate (float angle, float x, float y, float z) |
2852 | CODE: |
3002 | CODE: |
2853 | glRotatef (angle, x, y, z); |
3003 | glRotatef (angle, x, y, z); |
2854 | |
3004 | |
2855 | void glColor (float r, float g, float b, float a = 1.0) |
3005 | void glColor (float r, float g, float b, float a = 1.0) |
|
|
3006 | PROTOTYPE: @ |
2856 | ALIAS: |
3007 | ALIAS: |
2857 | glColor_premultiply = 1 |
3008 | glColor_premultiply = 1 |
2858 | CODE: |
3009 | CODE: |
2859 | if (ix) |
3010 | if (ix) |
2860 | { |
3011 | { |