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.260 by root, Tue May 20 20:29:47 2008 UTC vs.
Revision 1.273 by root, Wed Aug 20 13:30:02 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
65# include <netinet/in.h> 70# include <netinet/in.h>
66# include <netinet/tcp.h> 71# include <netinet/tcp.h>
67# include <inttypes.h> 72# include <inttypes.h>
68#endif 73#endif
69 74
75#if __GNUC__ >= 4
76# define expect(expr,value) __builtin_expect ((expr),(value))
77#else
78# define expect(expr,value) (expr)
79#endif
80
81#define expect_false(expr) expect ((expr) != 0, 0)
82#define expect_true(expr) expect ((expr) != 0, 1)
83
70#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
71 85
72#define FOW_DARKNESS 32 86#define FOW_DARKNESS 32
73 87
74#define MAP_EXTEND_X 32 88#define MAP_EXTEND_X 32
76 90
77#define MIN_FONT_HEIGHT 10 91#define MIN_FONT_HEIGHT 10
78 92
79/* mask out modifiers we are not interested in */ 93/* mask out modifiers we are not interested in */
80#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) 94#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
81
82#if 0
83# define PARACHUTE SDL_INIT_NOPARACHUTE
84#else
85# define PARACHUTE 0
86#endif
87 95
88static AV *texture_av; 96static AV *texture_av;
89 97
90static struct 98static struct
91{ 99{
364 self->oy = 0; 372 self->oy = 0;
365 self->row = 0; 373 self->row = 0;
366 self->rows = 0; 374 self->rows = 0;
367} 375}
368 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
369static void 387static void
370map_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)
371{ 389{
372 int x, y; 390 int x, y;
373 maprow *row; 391 maprow *row;
387 if (x >= row->c1) 405 if (x >= row->c1)
388 break; 406 break;
389 407
390 cell = row->col + x - row->c0; 408 cell = row->col + x - row->c0;
391 409
392 cell->darkness = 0; 410 CELL_CLEAR (cell);
393 cell->stat_hp = 0;
394 cell->flags = 0;
395 cell->player = 0;
396 } 411 }
397 } 412 }
398} 413}
399 414
400typedef struct { 415typedef struct {
511 if (!svp || !SvTRUE (*svp)) 526 if (!svp || !SvTRUE (*svp))
512 return 0; 527 return 0;
513 528
514 return 1; 529 return 1;
515} 530}
531
532static void
533deliantra_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
516 570
517MODULE = Deliantra::Client PACKAGE = DC 571MODULE = Deliantra::Client PACKAGE = DC
518 572
519PROTOTYPES: ENABLE 573PROTOTYPES: ENABLE
520 574
635 const_iv (KMOD_NUM), 689 const_iv (KMOD_NUM),
636 const_iv (KMOD_CAPS), 690 const_iv (KMOD_CAPS),
637 const_iv (KMOD_MODE), 691 const_iv (KMOD_MODE),
638 692
639 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)
640# undef const_iv 723# undef const_iv
641 }; 724 };
642 725
643 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; )
644 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 727 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
680 pango_context_set_language (opengl_context, pango_language_from_string ("en")); 763 pango_context_set_language (opengl_context, pango_language_from_string ("en"));
681 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ 764 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
682#endif 765#endif
683} 766}
684 767
685char *
686SDL_GetError () 768char *SDL_GetError ()
687 769
688int 770void SDL_braino ()
689SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE)
690 771
691void 772int SDL_Init (U32 flags)
773
774int SDL_InitSubSystem (U32 flags)
775
776void SDL_QuitSubSystem (U32 flags)
777
692SDL_Quit () 778void SDL_Quit ()
779
780int SDL_GL_SetAttribute (int attr, int value)
781
782int SDL_GL_GetAttribute (int attr)
783 CODE:
784 if (SDL_GL_GetAttribute (attr, &RETVAL))
785 XSRETURN_UNDEF;
786 OUTPUT:
787 RETVAL
693 788
694void 789void
695SDL_ListModes (int rgb, int alpha) 790SDL_ListModes (int rgb, int alpha)
696 PPCODE: 791 PPCODE:
697{ 792{
709 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); 804 SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
710 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); 805 SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0);
711 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); 806 SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
712 807
713 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 808 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
714#if SDL_VERSION_ATLEAST(1,2,10)
715 SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1);
716 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); 809 SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
717#endif
718 810
719 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 811 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
720 812
721 if (m && m != (SDL_Rect **)-1) 813 if (m && m != (SDL_Rect **)-1)
722 while (*m) 814 while (*m)
723 { 815 {
724 if ((*m)->w >= 800 && (*m)->h >= 480) 816 if ((*m)->w >= 400 && (*m)->h >= 300)
725 { 817 {
726 AV *av = newAV (); 818 AV *av = newAV ();
727 av_push (av, newSViv ((*m)->w)); 819 av_push (av, newSViv ((*m)->w));
728 av_push (av, newSViv ((*m)->h)); 820 av_push (av, newSViv ((*m)->h));
729 av_push (av, newSViv (rgb)); 821 av_push (av, newSViv (rgb));
1687 uint8_t ext, cmd; 1779 uint8_t ext, cmd;
1688 1780
1689 do 1781 do
1690 { 1782 {
1691 ext = *data++; 1783 ext = *data++;
1692 cmd = ext & 0x3f; 1784 cmd = ext & 0x7f;
1693 1785
1694 if (cmd < 4) 1786 if (cmd < 4)
1695 cell->darkness = 255 - ext * 64 + 1; 1787 cell->darkness = 255 - ext * 64 + 1;
1696 else if (cmd == 5) // health 1788 else if (cmd == 5) // health
1697 { 1789 {
1700 } 1792 }
1701 else if (cmd == 6) // monster width 1793 else if (cmd == 6) // monster width
1702 cell->stat_width = *data++ + 1; 1794 cell->stat_width = *data++ + 1;
1703 else if (cmd == 0x47) 1795 else if (cmd == 0x47)
1704 { 1796 {
1705 if (*data == 4) 1797 if (*data == 1) cell->player = data [1];
1706 ; // decode player count 1798 else if (*data == 2) cell->player = data [2] + (data [1] << 8);
1799 else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16);
1800 else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24);
1707 1801
1708 data += *data + 1; 1802 data += *data + 1;
1709 } 1803 }
1710 else if (cmd == 8) // cell flags 1804 else if (cmd == 8) // cell flags
1711 cell->flags = *data++; 1805 cell->flags = *data++;
1741 } 1835 }
1742 } 1836 }
1743 } 1837 }
1744 } 1838 }
1745 else 1839 else
1746 cell->darkness = 0; 1840 CELL_CLEAR (cell);
1747 } 1841 }
1748} 1842}
1749 OUTPUT: 1843 OUTPUT:
1750 RETVAL 1844 RETVAL
1751 1845
1803} 1897}
1804 OUTPUT: 1898 OUTPUT:
1805 RETVAL 1899 RETVAL
1806 1900
1807void 1901void
1808draw (DC::Map self, int mx, int my, int sw, int sh, int T) 1902draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
1809 CODE: 1903 CODE:
1810{ 1904{
1811 int x, y, z; 1905 int x, y, z;
1812 1906
1813 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1907 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1814 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1908 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1815 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 1909 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1816 smooth_key skey; 1910 smooth_key skey;
1817 1911 int pl_x, pl_y;
1912 maptex pl_tex;
1818 rc_t *rc = rc_alloc (); 1913 rc_t *rc = rc_alloc ();
1819 rc_key_t key; 1914 rc_key_t key;
1820 rc_array_t *arr; 1915 rc_array_t *arr;
1916
1917 pl_tex.name = 0;
1821 1918
1822 // thats current max. sorry. 1919 // thats current max. sorry.
1823 if (sw > 255) sw = 255; 1920 if (sw > 255) sw = 255;
1824 if (sh > 255) sh = 255; 1921 if (sh > 255) sh = 255;
1825 1922
1880 tileid tile = cell->tile [z]; 1977 tileid tile = cell->tile [z];
1881 1978
1882 if (tile) 1979 if (tile)
1883 { 1980 {
1884 maptex tex = self->tex [tile]; 1981 maptex tex = self->tex [tile];
1885 int px, py; 1982 int px = (x + 1) * T - tex.w;
1983 int py = (y + 1) * T - tex.h;
1886 1984
1887 if (key.texname != tex.name) 1985 if (key.texname != tex.name)
1888 { 1986 {
1889 if (!tex.name) 1987 if (!tex.name)
1890 tex = self->tex [2]; /* missing, replace by noface */ 1988 tex = self->tex [2]; /* missing, replace by noface */
1891 1989
1892 key.texname = tex.name; 1990 key.texname = tex.name;
1893 arr = rc_array (rc, &key); 1991 arr = rc_array (rc, &key);
1894 } 1992 }
1895 1993
1896 px = (x + 1) * T - tex.w; 1994 if (expect_false (cell->player == player) && expect_false (z == 2))
1897 py = (y + 1) * T - tex.h; 1995 {
1996 pl_x = px;
1997 pl_y = py;
1998 pl_tex = tex;
1999 continue;
2000 }
1898 2001
1899 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2002 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1900 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2003 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1901 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2004 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1902 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2005 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1903 2006
1904 if (cell->flags && z == 2) 2007 if (expect_false (cell->flags) && expect_false (z == 2))
1905 { 2008 {
1906 // overlays such as the speech bubble, probably more to come 2009 // overlays such as the speech bubble, probably more to come
1907 if (cell->flags & 1) 2010 if (cell->flags & 1)
1908 { 2011 {
1909 maptex tex = self->tex [1]; 2012 maptex tex = self->tex [1];
2048 } 2151 }
2049 2152
2050 hv_clear (smooth); 2153 hv_clear (smooth);
2051 } 2154 }
2052 2155
2156 if (pl_tex.name)
2157 {
2158 maptex tex = pl_tex;
2159 int px = pl_x + sdx;
2160 int py = pl_y + sdy;
2161
2162 key.texname = tex.name;
2163 arr = rc_array (rc, &key);
2164
2165 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2166 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2167 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2168 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2169
2170 rc_draw (rc);
2171 }
2172
2053 glDisable (GL_BLEND); 2173 glDisable (GL_BLEND);
2054 rc_free (rc); 2174 rc_free (rc);
2055 2175
2056 // top layer: overlays such as the health bar 2176 // top layer: overlays such as the health bar
2057 for (y = 0; y < sh; y++) 2177 for (y = 0; y < sh; y++)
2162 SvCUR_set (darkness3_sv, sw34 * sh3); 2282 SvCUR_set (darkness3_sv, sw34 * sh3);
2163 2283
2164 mx += self->x - 1; 2284 mx += self->x - 1;
2165 my += self->y - 1; 2285 my += self->y - 1;
2166 2286
2167 memset (darkness1, 255, sw1 * sh1); 2287 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2168 2288
2169 for (y = 0; y < sh1; y++) 2289 for (y = 0; y < sh1; y++)
2170 if (0 <= y + my && y + my < self->rows) 2290 if (0 <= y + my && y + my < self->rows)
2171 { 2291 {
2172 maprow *row = self->row + (y + my); 2292 maprow *row = self->row + (y + my);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines