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.261 by root, Sun Jul 13 12:17:00 2008 UTC vs.
Revision 1.274 by root, Wed Aug 20 17:50:47 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
644 const_iv (KMOD_NUM), 688 const_iv (KMOD_NUM),
645 const_iv (KMOD_CAPS), 689 const_iv (KMOD_CAPS),
646 const_iv (KMOD_MODE), 690 const_iv (KMOD_MODE),
647 691
648 const_iv (MIX_DEFAULT_FORMAT), 692 const_iv (MIX_DEFAULT_FORMAT),
693
694 const_iv (SDL_INIT_TIMER),
695 const_iv (SDL_INIT_AUDIO),
696 const_iv (SDL_INIT_VIDEO),
697 const_iv (SDL_INIT_CDROM),
698 const_iv (SDL_INIT_JOYSTICK),
699 const_iv (SDL_INIT_EVERYTHING),
700 const_iv (SDL_INIT_NOPARACHUTE),
701 const_iv (SDL_INIT_EVENTTHREAD),
702
703 const_iv (SDL_GL_RED_SIZE),
704 const_iv (SDL_GL_GREEN_SIZE),
705 const_iv (SDL_GL_BLUE_SIZE),
706 const_iv (SDL_GL_ALPHA_SIZE),
707 const_iv (SDL_GL_DOUBLEBUFFER),
708 const_iv (SDL_GL_BUFFER_SIZE),
709 const_iv (SDL_GL_DEPTH_SIZE),
710 const_iv (SDL_GL_STENCIL_SIZE),
711 const_iv (SDL_GL_ACCUM_RED_SIZE),
712 const_iv (SDL_GL_ACCUM_GREEN_SIZE),
713 const_iv (SDL_GL_ACCUM_BLUE_SIZE),
714 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
715 const_iv (SDL_GL_STEREO),
716 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
717 const_iv (SDL_GL_MULTISAMPLESAMPLES),
718 const_iv (SDL_GL_ACCELERATED_VISUAL),
719 const_iv (SDL_GL_SWAP_CONTROL),
720
721 const_iv (FOW_DARKNESS)
649# undef const_iv 722# undef const_iv
650 }; 723 };
651 724
652 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 725 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
653 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 726 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
689 pango_context_set_language (opengl_context, pango_language_from_string ("en")); 762 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
690 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ 763 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
691#endif 764#endif
692} 765}
693 766
694char *
695SDL_GetError () 767char *SDL_GetError ()
696 768
697int 769void SDL_braino ()
698SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
699 770
700void 771int SDL_Init (U32 flags)
772
773int SDL_InitSubSystem (U32 flags)
774
775void SDL_QuitSubSystem (U32 flags)
776
701SDL_Quit () 777void SDL_Quit ()
778
779int SDL_GL_SetAttribute (int attr, int value)
780
781int SDL_GL_GetAttribute (int attr)
782 CODE:
783 if (SDL_GL_GetAttribute (attr, &RETVAL))
784 XSRETURN_UNDEF;
785 OUTPUT:
786 RETVAL
702 787
703void 788void
704SDL_ListModes (int rgb, int alpha) 789SDL_ListModes (int rgb, int alpha)
705 PPCODE: 790 PPCODE:
706{ 791{
718 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 803 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
719 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 804 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
720 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 805 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
721 806
722 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 807 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); 808 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
726#endif
727 809
728 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 810 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
729 811
730 if (m && m != (SDL_Rect **)-1) 812 if (m && m != (SDL_Rect **)-1)
731 while (*m) 813 while (*m)
732 { 814 {
733 if ((*m)->w >= 800 && (*m)->h >= 480) 815 if ((*m)->w >= 400 && (*m)->h >= 300)
734 { 816 {
735 AV *av = newAV (); 817 AV *av = newAV ();
736 av_push (av, newSViv ((*m)->w)); 818 av_push (av, newSViv ((*m)->w));
737 av_push (av, newSViv ((*m)->h)); 819 av_push (av, newSViv ((*m)->h));
738 av_push (av, newSViv (rgb)); 820 av_push (av, newSViv (rgb));
1752 } 1834 }
1753 } 1835 }
1754 } 1836 }
1755 } 1837 }
1756 else 1838 else
1757 cell->darkness = 0; 1839 CELL_CLEAR (cell);
1758 } 1840 }
1759} 1841}
1760 OUTPUT: 1842 OUTPUT:
1761 RETVAL 1843 RETVAL
1762 1844
1814} 1896}
1815 OUTPUT: 1897 OUTPUT:
1816 RETVAL 1898 RETVAL
1817 1899
1818void 1900void
1819draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int pdx = 0, int pdy = 0) 1901draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1820 CODE: 1902 CODE:
1821{ 1903{
1822 int x, y, z; 1904 int x, y, z;
1823 1905
1824 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1906 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1825 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1907 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1826 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 1908 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1827 smooth_key skey; 1909 smooth_key skey;
1828 int pl_x, pl_y; 1910 int pl_x, pl_y;
1829 maptex pl_tex; 1911 maptex pl_tex;
1830
1831 pl_tex.name = 0;
1832
1833 rc_t *rc = rc_alloc (); 1912 rc_t *rc = rc_alloc ();
1834 rc_key_t key; 1913 rc_key_t key;
1835 rc_array_t *arr; 1914 rc_array_t *arr;
1915
1916 pl_tex.name = 0;
1836 1917
1837 // thats current max. sorry. 1918 // thats current max. sorry.
1838 if (sw > 255) sw = 255; 1919 if (sw > 255) sw = 255;
1839 if (sh > 255) sh = 255; 1920 if (sh > 255) sh = 255;
1840 1921
2072 } 2153 }
2073 2154
2074 if (pl_tex.name) 2155 if (pl_tex.name)
2075 { 2156 {
2076 maptex tex = pl_tex; 2157 maptex tex = pl_tex;
2077 int px = pl_x + pdx; 2158 int px = pl_x + sdx;
2078 int py = pl_y + pdy; 2159 int py = pl_y + sdy;
2079 2160
2080 key.texname = tex.name; 2161 key.texname = tex.name;
2081 arr = rc_array (rc, &key); 2162 arr = rc_array (rc, &key);
2082 2163
2083 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2164 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2200 SvCUR_set (darkness3_sv, sw34 * sh3); 2281 SvCUR_set (darkness3_sv, sw34 * sh3);
2201 2282
2202 mx += self->x - 1; 2283 mx += self->x - 1;
2203 my += self->y - 1; 2284 my += self->y - 1;
2204 2285
2205 memset (darkness1, 255, sw1 * sh1); 2286 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2206 2287
2207 for (y = 0; y < sh1; y++) 2288 for (y = 0; y < sh1; y++)
2208 if (0 <= y + my && y + my < self->rows) 2289 if (0 <= y + my && y + my < self->rows)
2209 { 2290 {
2210 maprow *row = self->row + (y + my); 2291 maprow *row = self->row + (y + my);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines