… | |
… | |
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 | |
… | |
… | |
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 | |
97 | static AV *texture_av; |
96 | static AV *texture_av; |
98 | |
97 | |
99 | static struct |
98 | static 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 | |
378 | static void |
387 | static void |
379 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
388 | map_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 | |
409 | typedef struct { |
415 | typedef 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 | |
|
|
532 | static void |
|
|
533 | deliantra_main () |
|
|
534 | { |
|
|
535 | char *argv[] = { 0 }; |
|
|
536 | call_argv ("::main", G_DISCARD | G_VOID, argv); |
|
|
537 | dSP; |
|
|
538 | } |
|
|
539 | |
|
|
540 | #ifdef __MACOSX__ |
|
|
541 | /* to due surprising braindamage on the side of SDL design, we |
|
|
542 | * do some mind-boggling hack here: SDL requires a custom main() |
|
|
543 | * on OS X, so... we provide one and call the original main(), which, |
|
|
544 | * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, |
|
|
545 | * and which calls our main (== SDL_main) back. |
|
|
546 | */ |
|
|
547 | extern C_LINKAGE int |
|
|
548 | main (int argc, char *argv[]) |
|
|
549 | { |
|
|
550 | deliantra_main (); |
|
|
551 | } |
|
|
552 | |
|
|
553 | #undef main |
|
|
554 | |
|
|
555 | extern C_LINKAGE int main (int argc, char *argv[]); |
|
|
556 | |
|
|
557 | static void |
|
|
558 | SDL_braino (void) |
|
|
559 | { |
|
|
560 | char *argv[] = { "deliantra client", 0 }; |
|
|
561 | (main) (1, argv); |
|
|
562 | } |
|
|
563 | #else |
|
|
564 | static void |
|
|
565 | SDL_braino (void) |
|
|
566 | { |
|
|
567 | deliantra_main (); |
|
|
568 | } |
|
|
569 | #endif |
525 | |
570 | |
526 | MODULE = Deliantra::Client PACKAGE = DC |
571 | MODULE = Deliantra::Client PACKAGE = DC |
527 | |
572 | |
528 | PROTOTYPES: ENABLE |
573 | PROTOTYPES: ENABLE |
529 | |
574 | |
… | |
… | |
644 | const_iv (KMOD_NUM), |
689 | const_iv (KMOD_NUM), |
645 | const_iv (KMOD_CAPS), |
690 | const_iv (KMOD_CAPS), |
646 | const_iv (KMOD_MODE), |
691 | const_iv (KMOD_MODE), |
647 | |
692 | |
648 | const_iv (MIX_DEFAULT_FORMAT), |
693 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
694 | |
|
|
695 | const_iv (SDL_INIT_TIMER), |
|
|
696 | const_iv (SDL_INIT_AUDIO), |
|
|
697 | const_iv (SDL_INIT_VIDEO), |
|
|
698 | const_iv (SDL_INIT_CDROM), |
|
|
699 | const_iv (SDL_INIT_JOYSTICK), |
|
|
700 | const_iv (SDL_INIT_EVERYTHING), |
|
|
701 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
702 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
703 | |
|
|
704 | const_iv (SDL_GL_RED_SIZE), |
|
|
705 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
706 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
707 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
708 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
709 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
710 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
711 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
712 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
713 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
714 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
715 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
716 | const_iv (SDL_GL_STEREO), |
|
|
717 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
718 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
719 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
720 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
721 | |
|
|
722 | const_iv (FOW_DARKNESS) |
649 | # undef const_iv |
723 | # undef const_iv |
650 | }; |
724 | }; |
651 | |
725 | |
652 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
726 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
653 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
727 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
689 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
763 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
690 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
764 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
691 | #endif |
765 | #endif |
692 | } |
766 | } |
693 | |
767 | |
694 | char * |
|
|
695 | SDL_GetError () |
768 | char *SDL_GetError () |
696 | |
769 | |
697 | int |
770 | void SDL_braino () |
698 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
|
|
699 | |
771 | |
700 | void |
772 | int SDL_Init (U32 flags) |
|
|
773 | |
|
|
774 | int SDL_InitSubSystem (U32 flags) |
|
|
775 | |
|
|
776 | void SDL_QuitSubSystem (U32 flags) |
|
|
777 | |
701 | SDL_Quit () |
778 | void SDL_Quit () |
|
|
779 | |
|
|
780 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
781 | |
|
|
782 | int SDL_GL_GetAttribute (int attr) |
|
|
783 | CODE: |
|
|
784 | if (SDL_GL_GetAttribute (attr, &RETVAL)) |
|
|
785 | XSRETURN_UNDEF; |
|
|
786 | OUTPUT: |
|
|
787 | RETVAL |
702 | |
788 | |
703 | void |
789 | void |
704 | SDL_ListModes (int rgb, int alpha) |
790 | SDL_ListModes (int rgb, int alpha) |
705 | PPCODE: |
791 | PPCODE: |
706 | { |
792 | { |
… | |
… | |
718 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
804 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
719 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
805 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
720 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
806 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
721 | |
807 | |
722 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
808 | 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); |
809 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
726 | #endif |
|
|
727 | |
810 | |
728 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
811 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
729 | |
812 | |
730 | if (m && m != (SDL_Rect **)-1) |
813 | if (m && m != (SDL_Rect **)-1) |
731 | while (*m) |
814 | while (*m) |
732 | { |
815 | { |
733 | if ((*m)->w >= 800 && (*m)->h >= 480) |
816 | if ((*m)->w >= 400 && (*m)->h >= 300) |
734 | { |
817 | { |
735 | AV *av = newAV (); |
818 | AV *av = newAV (); |
736 | av_push (av, newSViv ((*m)->w)); |
819 | av_push (av, newSViv ((*m)->w)); |
737 | av_push (av, newSViv ((*m)->h)); |
820 | av_push (av, newSViv ((*m)->h)); |
738 | av_push (av, newSViv (rgb)); |
821 | av_push (av, newSViv (rgb)); |
… | |
… | |
1752 | } |
1835 | } |
1753 | } |
1836 | } |
1754 | } |
1837 | } |
1755 | } |
1838 | } |
1756 | else |
1839 | else |
1757 | cell->darkness = 0; |
1840 | CELL_CLEAR (cell); |
1758 | } |
1841 | } |
1759 | } |
1842 | } |
1760 | OUTPUT: |
1843 | OUTPUT: |
1761 | RETVAL |
1844 | RETVAL |
1762 | |
1845 | |
… | |
… | |
1814 | } |
1897 | } |
1815 | OUTPUT: |
1898 | OUTPUT: |
1816 | RETVAL |
1899 | RETVAL |
1817 | |
1900 | |
1818 | void |
1901 | 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) |
1902 | 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: |
1903 | CODE: |
1821 | { |
1904 | { |
1822 | int x, y, z; |
1905 | int x, y, z; |
1823 | |
1906 | |
1824 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1907 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
… | |
… | |
2071 | } |
2154 | } |
2072 | |
2155 | |
2073 | if (pl_tex.name) |
2156 | if (pl_tex.name) |
2074 | { |
2157 | { |
2075 | maptex tex = pl_tex; |
2158 | maptex tex = pl_tex; |
2076 | int px = pl_x + pdx; |
2159 | int px = pl_x + sdx; |
2077 | int py = pl_y + pdy; |
2160 | int py = pl_y + sdy; |
2078 | |
2161 | |
2079 | key.texname = tex.name; |
2162 | key.texname = tex.name; |
2080 | arr = rc_array (rc, &key); |
2163 | arr = rc_array (rc, &key); |
2081 | |
2164 | |
2082 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2165 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
… | |
… | |
2199 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2282 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2200 | |
2283 | |
2201 | mx += self->x - 1; |
2284 | mx += self->x - 1; |
2202 | my += self->y - 1; |
2285 | my += self->y - 1; |
2203 | |
2286 | |
2204 | memset (darkness1, 255, sw1 * sh1); |
2287 | memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); |
2205 | |
2288 | |
2206 | for (y = 0; y < sh1; y++) |
2289 | for (y = 0; y < sh1; y++) |
2207 | if (0 <= y + my && y + my < self->rows) |
2290 | if (0 <= y + my && y + my < self->rows) |
2208 | { |
2291 | { |
2209 | maprow *row = self->row + (y + my); |
2292 | maprow *row = self->row + (y + my); |