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.266 by root, Sun Jul 20 02:51:40 2008 UTC vs.
Revision 1.281 by root, Thu Dec 4 23:58:20 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
76#define expect_false(expr) expect ((expr) != 0, 0) 81#define expect_false(expr) expect ((expr) != 0, 0)
77#define expect_true(expr) expect ((expr) != 0, 1) 82#define expect_true(expr) expect ((expr) != 0, 1)
78 83
79#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
80 85
81#define FOW_DARKNESS 32 86#define FOW_DARKNESS 16
82 87
83#define MAP_EXTEND_X 32 88#define MAP_EXTEND_X 32
84#define MAP_EXTEND_Y 512 89#define MAP_EXTEND_Y 512
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)
95
96#define KMOD_LRAM 0x10000 // our extension
90 97
91static AV *texture_av; 98static AV *texture_av;
92 99
93static struct 100static struct
94{ 101{
226 int w, h; 233 int w, h;
227 float s, t; 234 float s, t;
228 uint8_t r, g, b, a; 235 uint8_t r, g, b, a;
229 tileid smoothtile; 236 tileid smoothtile;
230 uint8_t smoothlevel; 237 uint8_t smoothlevel;
238 uint8_t unused; /* set to zero on use */
231} maptex; 239} maptex;
232 240
233typedef struct { 241typedef struct {
234 uint32_t player; 242 uint32_t player;
235 tileid tile[3]; 243 tileid tile[3];
367 self->oy = 0; 375 self->oy = 0;
368 self->row = 0; 376 self->row = 0;
369 self->rows = 0; 377 self->rows = 0;
370} 378}
371 379
380#define CELL_CLEAR(cell) \
381 do { \
382 if ((cell)->player) \
383 (cell)->tile [2] = 0; \
384 (cell)->darkness = 0; \
385 (cell)->stat_hp = 0; \
386 (cell)->flags = 0; \
387 (cell)->player = 0; \
388 } while (0)
389
372static void 390static void
373map_blank (DC__Map self, int x0, int y0, int w, int h) 391map_blank (DC__Map self, int x0, int y0, int w, int h)
374{ 392{
375 int x, y; 393 int x, y;
376 maprow *row; 394 maprow *row;
390 if (x >= row->c1) 408 if (x >= row->c1)
391 break; 409 break;
392 410
393 cell = row->col + x - row->c0; 411 cell = row->col + x - row->c0;
394 412
395 cell->darkness = 0; 413 CELL_CLEAR (cell);
396 cell->stat_hp = 0;
397 cell->flags = 0;
398 cell->player = 0;
399 } 414 }
400 } 415 }
401} 416}
402 417
403typedef struct { 418typedef struct {
514 if (!svp || !SvTRUE (*svp)) 529 if (!svp || !SvTRUE (*svp))
515 return 0; 530 return 0;
516 531
517 return 1; 532 return 1;
518} 533}
534
535/******************************************************************************/
536
537/* process keyboard modifiers */
538static int
539mod_munge (int mod)
540{
541 mod &= MOD_MASK;
542
543 if (mod & (KMOD_META | KMOD_ALT))
544 mod |= KMOD_LRAM;
545
546 return mod;
547}
548
549static void
550deliantra_main ()
551{
552 char *argv[] = { 0 };
553 call_argv ("::main", G_DISCARD | G_VOID, argv);
554}
555
556#ifdef __MACOSX__
557 /* to due surprising braindamage on the side of SDL design, we
558 * do some mind-boggling hack here: SDL requires a custom main()
559 * on OS X, so... we provide one and call the original main(), which,
560 * due to share dlibrary magic, calls -lSDLmain's main, not perl's main,
561 * and which calls our main (== SDL_main) back.
562 */
563 extern C_LINKAGE int
564 main (int argc, char *argv[])
565 {
566 deliantra_main ();
567 }
568
569 #undef main
570
571 extern C_LINKAGE int main (int argc, char *argv[]);
572
573 static void
574 SDL_braino (void)
575 {
576 char *argv[] = { "deliantra client", 0 };
577 (main) (1, argv);
578 }
579#else
580 static void
581 SDL_braino (void)
582 {
583 deliantra_main ();
584 }
585#endif
519 586
520MODULE = Deliantra::Client PACKAGE = DC 587MODULE = Deliantra::Client PACKAGE = DC
521 588
522PROTOTYPES: ENABLE 589PROTOTYPES: ENABLE
523 590
552 const_iv (SDL_USEREVENT), 619 const_iv (SDL_USEREVENT),
553 620
554 const_iv (SDL_APPINPUTFOCUS), 621 const_iv (SDL_APPINPUTFOCUS),
555 const_iv (SDL_APPMOUSEFOCUS), 622 const_iv (SDL_APPMOUSEFOCUS),
556 const_iv (SDL_APPACTIVE), 623 const_iv (SDL_APPACTIVE),
624
625
626 const_iv (SDLK_UNKNOWN),
627 const_iv (SDLK_FIRST),
628 const_iv (SDLK_BACKSPACE),
629 const_iv (SDLK_TAB),
630 const_iv (SDLK_CLEAR),
631 const_iv (SDLK_RETURN),
632 const_iv (SDLK_PAUSE),
633 const_iv (SDLK_ESCAPE),
634 const_iv (SDLK_SPACE),
635 const_iv (SDLK_EXCLAIM),
636 const_iv (SDLK_QUOTEDBL),
637 const_iv (SDLK_HASH),
638 const_iv (SDLK_DOLLAR),
639 const_iv (SDLK_AMPERSAND),
640 const_iv (SDLK_QUOTE),
641 const_iv (SDLK_LEFTPAREN),
642 const_iv (SDLK_RIGHTPAREN),
643 const_iv (SDLK_ASTERISK),
644 const_iv (SDLK_PLUS),
645 const_iv (SDLK_COMMA),
646 const_iv (SDLK_MINUS),
647 const_iv (SDLK_PERIOD),
648 const_iv (SDLK_SLASH),
649 const_iv (SDLK_0),
650 const_iv (SDLK_1),
651 const_iv (SDLK_2),
652 const_iv (SDLK_3),
653 const_iv (SDLK_4),
654 const_iv (SDLK_5),
655 const_iv (SDLK_6),
656 const_iv (SDLK_7),
657 const_iv (SDLK_8),
658 const_iv (SDLK_9),
659 const_iv (SDLK_COLON),
660 const_iv (SDLK_SEMICOLON),
661 const_iv (SDLK_LESS),
662 const_iv (SDLK_EQUALS),
663 const_iv (SDLK_GREATER),
664 const_iv (SDLK_QUESTION),
665 const_iv (SDLK_AT),
666
667 const_iv (SDLK_LEFTBRACKET),
668 const_iv (SDLK_BACKSLASH),
669 const_iv (SDLK_RIGHTBRACKET),
670 const_iv (SDLK_CARET),
671 const_iv (SDLK_UNDERSCORE),
672 const_iv (SDLK_BACKQUOTE),
673 const_iv (SDLK_DELETE),
557 674
558 const_iv (SDLK_FIRST), 675 const_iv (SDLK_FIRST),
559 const_iv (SDLK_LAST), 676 const_iv (SDLK_LAST),
560 const_iv (SDLK_KP0), 677 const_iv (SDLK_KP0),
561 const_iv (SDLK_KP1), 678 const_iv (SDLK_KP1),
637 const_iv (KMOD_RMETA), 754 const_iv (KMOD_RMETA),
638 const_iv (KMOD_NUM), 755 const_iv (KMOD_NUM),
639 const_iv (KMOD_CAPS), 756 const_iv (KMOD_CAPS),
640 const_iv (KMOD_MODE), 757 const_iv (KMOD_MODE),
641 758
759 const_iv (KMOD_LRAM),
760
642 const_iv (MIX_DEFAULT_FORMAT), 761 const_iv (MIX_DEFAULT_FORMAT),
643 762
644 const_iv (SDL_INIT_TIMER), 763 const_iv (SDL_INIT_TIMER),
645 const_iv (SDL_INIT_AUDIO), 764 const_iv (SDL_INIT_AUDIO),
646 const_iv (SDL_INIT_VIDEO), 765 const_iv (SDL_INIT_VIDEO),
664 const_iv (SDL_GL_ACCUM_ALPHA_SIZE), 783 const_iv (SDL_GL_ACCUM_ALPHA_SIZE),
665 const_iv (SDL_GL_STEREO), 784 const_iv (SDL_GL_STEREO),
666 const_iv (SDL_GL_MULTISAMPLEBUFFERS), 785 const_iv (SDL_GL_MULTISAMPLEBUFFERS),
667 const_iv (SDL_GL_MULTISAMPLESAMPLES), 786 const_iv (SDL_GL_MULTISAMPLESAMPLES),
668 const_iv (SDL_GL_ACCELERATED_VISUAL), 787 const_iv (SDL_GL_ACCELERATED_VISUAL),
669 const_iv (SDL_GL_SWAP_CONTROL) 788 const_iv (SDL_GL_SWAP_CONTROL),
789
790 const_iv (FOW_DARKNESS)
670# undef const_iv 791# undef const_iv
671 }; 792 };
672 793
673 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 794 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
674 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 795 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
711 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ 832 /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/
712#endif 833#endif
713} 834}
714 835
715char *SDL_GetError () 836char *SDL_GetError ()
837
838void SDL_braino ()
716 839
717int SDL_Init (U32 flags) 840int SDL_Init (U32 flags)
718 841
719int SDL_InitSubSystem (U32 flags) 842int SDL_InitSubSystem (U32 flags)
720 843
829 { 952 {
830 case SDL_KEYDOWN: 953 case SDL_KEYDOWN:
831 case SDL_KEYUP: 954 case SDL_KEYUP:
832 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 955 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
833 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 956 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
834 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); 957 hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0);
835 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ 958 hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */
836 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 959 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
837 break; 960 break;
838 961
839 case SDL_ACTIVEEVENT: 962 case SDL_ACTIVEEVENT:
840 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 963 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
858 x = ev.motion.x; 981 x = ev.motion.x;
859 y = ev.motion.y; 982 y = ev.motion.y;
860 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); 983 SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION));
861 } 984 }
862 985
863 hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); 986 hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0);
864 hv_store (hv, "state", 5, newSViv (state), 0); 987 hv_store (hv, "state", 5, newSViv (state), 0);
865 hv_store (hv, "x", 1, newSViv (x), 0); 988 hv_store (hv, "x", 1, newSViv (x), 0);
866 hv_store (hv, "y", 1, newSViv (y), 0); 989 hv_store (hv, "y", 1, newSViv (y), 0);
867 hv_store (hv, "xrel", 4, newSViv (xrel), 0); 990 hv_store (hv, "xrel", 4, newSViv (xrel), 0);
868 hv_store (hv, "yrel", 4, newSViv (yrel), 0); 991 hv_store (hv, "yrel", 4, newSViv (yrel), 0);
1084#if DEBUG 1207#if DEBUG
1085 VALGRIND_DO_LEAK_CHECK; 1208 VALGRIND_DO_LEAK_CHECK;
1086#endif 1209#endif
1087} 1210}
1088 1211
1212int
1213SvREFCNT (SV *sv)
1214 CODE:
1215 RETVAL = SvREFCNT (sv);
1216 OUTPUT:
1217 RETVAL
1218
1089MODULE = Deliantra::Client PACKAGE = DC::Font 1219MODULE = Deliantra::Client PACKAGE = DC::Font
1090 1220
1091PROTOTYPES: DISABLE 1221PROTOTYPES: DISABLE
1092 1222
1093DC::Font 1223DC::Font
1637 //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1767 //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1638 // use uglier nearest interpolation because linear suffers 1768 // use uglier nearest interpolation because linear suffers
1639 // from transparent color bleeding and ugly wrapping effects. 1769 // from transparent color bleeding and ugly wrapping effects.
1640 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1770 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1641} 1771}
1772
1773void
1774expire_textures (DC::Map self, int texid, int count)
1775 PPCODE:
1776 for (; texid < self->texs && count; ++texid, --count)
1777 {
1778 maptex *tex = self->tex + texid;
1779
1780 if (tex->name)
1781 {
1782 if (tex->unused)
1783 {
1784 tex->name = 0;
1785 tex->unused = 0,
1786 XPUSHs (sv_2mortal (newSViv (texid)));
1787 }
1788 else
1789 tex->unused = 1;
1790 }
1791 }
1642 1792
1643int 1793int
1644ox (DC::Map self) 1794ox (DC::Map self)
1645 ALIAS: 1795 ALIAS:
1646 oy = 1 1796 oy = 1
1767 cell->tile [z] = self->face2tile [face]; 1917 cell->tile [z] = self->face2tile [face];
1768 1918
1769 if (cell->tile [z]) 1919 if (cell->tile [z])
1770 { 1920 {
1771 maptex *tex = self->tex + cell->tile [z]; 1921 maptex *tex = self->tex + cell->tile [z];
1922 tex->unused = 0;
1772 if (!tex->name) 1923 if (!tex->name)
1773 av_push (missing, newSViv (cell->tile [z])); 1924 av_push (missing, newSViv (cell->tile [z]));
1774 1925
1775 if (tex->smoothtile) 1926 if (tex->smoothtile)
1776 { 1927 {
1777 maptex *smooth = self->tex + tex->smoothtile; 1928 maptex *smooth = self->tex + tex->smoothtile;
1929 smooth->unused = 0;
1778 if (!smooth->name) 1930 if (!smooth->name)
1779 av_push (missing, newSViv (tex->smoothtile)); 1931 av_push (missing, newSViv (tex->smoothtile));
1780 } 1932 }
1781 } 1933 }
1782 } 1934 }
1783 } 1935 }
1784 else 1936 else
1785 { 1937 CELL_CLEAR (cell);
1786 cell->darkness = 0;
1787 cell->stat_hp = 0;
1788 cell->flags = 0;
1789 cell->player = 0;
1790 }
1791 } 1938 }
1792} 1939}
1793 OUTPUT: 1940 OUTPUT:
1794 RETVAL 1941 RETVAL
1795 1942
1932 int px = (x + 1) * T - tex.w; 2079 int px = (x + 1) * T - tex.w;
1933 int py = (y + 1) * T - tex.h; 2080 int py = (y + 1) * T - tex.h;
1934 2081
1935 if (key.texname != tex.name) 2082 if (key.texname != tex.name)
1936 { 2083 {
2084 self->tex [tile].unused = 0;
2085
1937 if (!tex.name) 2086 if (!tex.name)
1938 tex = self->tex [2]; /* missing, replace by noface */ 2087 tex = self->tex [2]; /* missing, replace by noface */
1939 2088
1940 key.texname = tex.name; 2089 key.texname = tex.name;
1941 arr = rc_array (rc, &key); 2090 arr = rc_array (rc, &key);
2063 { 2212 {
2064 // this time avoiding texture state changes 2213 // this time avoiding texture state changes
2065 // save gobs of state changes. 2214 // save gobs of state changes.
2066 if (key.texname != tex.name) 2215 if (key.texname != tex.name)
2067 { 2216 {
2217 self->tex [skey->tile].unused = 0;
2218
2068 glEnd (); 2219 glEnd ();
2069 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2220 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2070 glBegin (GL_QUADS); 2221 glBegin (GL_QUADS);
2071 } 2222 }
2072 2223
2135 mapcell *cell = row->col + (x + mx - row->c0); 2286 mapcell *cell = row->col + (x + mx - row->c0);
2136 2287
2137 int px = x * T; 2288 int px = x * T;
2138 int py = y * T; 2289 int py = y * T;
2139 2290
2291 if (expect_false (cell->player == player))
2292 {
2293 px += sdx;
2294 py += sdy;
2295 }
2296
2140 if (cell->stat_hp) 2297 if (cell->stat_hp)
2141 { 2298 {
2142 int width = cell->stat_width * T; 2299 int width = cell->stat_width * T;
2143 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; 2300 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width;
2144 2301
2232 SvCUR_set (darkness3_sv, sw34 * sh3); 2389 SvCUR_set (darkness3_sv, sw34 * sh3);
2233 2390
2234 mx += self->x - 1; 2391 mx += self->x - 1;
2235 my += self->y - 1; 2392 my += self->y - 1;
2236 2393
2237 memset (darkness1, 255, sw1 * sh1); 2394 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1);
2238 2395
2239 for (y = 0; y < sh1; y++) 2396 for (y = 0; y < sh1; y++)
2240 if (0 <= y + my && y + my < self->rows) 2397 if (0 <= y + my && y + my < self->rows)
2241 { 2398 {
2242 maprow *row = self->row + (y + my); 2399 maprow *row = self->row + (y + my);
2884void glRotate (float angle, float x, float y, float z) 3041void glRotate (float angle, float x, float y, float z)
2885 CODE: 3042 CODE:
2886 glRotatef (angle, x, y, z); 3043 glRotatef (angle, x, y, z);
2887 3044
2888void glColor (float r, float g, float b, float a = 1.0) 3045void glColor (float r, float g, float b, float a = 1.0)
3046 PROTOTYPE: @
2889 ALIAS: 3047 ALIAS:
2890 glColor_premultiply = 1 3048 glColor_premultiply = 1
2891 CODE: 3049 CODE:
2892 if (ix) 3050 if (ix)
2893 { 3051 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines