--- deliantra/Deliantra-Client/Client.xs 2008/07/16 20:12:27 1.262 +++ deliantra/Deliantra-Client/Client.xs 2008/12/23 18:52:54 1.288 @@ -41,6 +41,11 @@ #include #include +/* work around os x broken headers */ +#ifdef __MACOSX__ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + #define PANGO_ENABLE_BACKEND #define G_DISABLE_CAST_CHECKS @@ -78,7 +83,7 @@ #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ -#define FOW_DARKNESS 32 +#define FOW_DARKNESS 64 #define MAP_EXTEND_X 32 #define MAP_EXTEND_Y 512 @@ -88,11 +93,11 @@ /* mask out modifiers we are not interested in */ #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) -#if 1 -# define PARACHUTE SDL_INIT_NOPARACHUTE -#else -# define PARACHUTE 0 -#endif +#define KMOD_LRAM 0x10000 // our extension + +#define TEXID_SPEECH 1 +#define TEXID_NOFACE 2 +#define TEXID_HIDDEN 3 static AV *texture_av; @@ -234,6 +239,7 @@ uint8_t r, g, b, a; tileid smoothtile; uint8_t smoothlevel; + uint8_t unused; /* set to zero on use */ } maptex; typedef struct { @@ -375,6 +381,16 @@ self->rows = 0; } +#define CELL_CLEAR(cell) \ + do { \ + if ((cell)->player) \ + (cell)->tile [2] = 0; \ + (cell)->darkness = 0; \ + (cell)->stat_hp = 0; \ + (cell)->flags = 0; \ + (cell)->player = 0; \ + } while (0) + static void map_blank (DC__Map self, int x0, int y0, int w, int h) { @@ -398,10 +414,7 @@ cell = row->col + x - row->c0; - cell->darkness = 0; - cell->stat_hp = 0; - cell->flags = 0; - cell->player = 0; + CELL_CLEAR (cell); } } } @@ -523,6 +536,58 @@ return 1; } +/******************************************************************************/ + +/* process keyboard modifiers */ +static int +mod_munge (int mod) +{ + mod &= MOD_MASK; + + if (mod & (KMOD_META | KMOD_ALT)) + mod |= KMOD_LRAM; + + return mod; +} + +static void +deliantra_main () +{ + char *argv[] = { 0 }; + call_argv ("::main", G_DISCARD | G_VOID, argv); +} + +#ifdef __MACOSX__ + /* to due surprising braindamage on the side of SDL design, we + * do some mind-boggling hack here: SDL requires a custom main() + * on OS X, so... we provide one and call the original main(), which, + * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, + * and which calls our main (== SDL_main) back. + */ + extern C_LINKAGE int + main (int argc, char *argv[]) + { + deliantra_main (); + } + + #undef main + + extern C_LINKAGE int main (int argc, char *argv[]); + + static void + SDL_braino (void) + { + char *argv[] = { "deliantra client", 0 }; + (main) (1, argv); + } +#else + static void + SDL_braino (void) + { + deliantra_main (); + } +#endif + MODULE = Deliantra::Client PACKAGE = DC PROTOTYPES: ENABLE @@ -561,6 +626,56 @@ const_iv (SDL_APPMOUSEFOCUS), const_iv (SDL_APPACTIVE), + + const_iv (SDLK_UNKNOWN), + const_iv (SDLK_FIRST), + const_iv (SDLK_BACKSPACE), + const_iv (SDLK_TAB), + const_iv (SDLK_CLEAR), + const_iv (SDLK_RETURN), + const_iv (SDLK_PAUSE), + const_iv (SDLK_ESCAPE), + const_iv (SDLK_SPACE), + const_iv (SDLK_EXCLAIM), + const_iv (SDLK_QUOTEDBL), + const_iv (SDLK_HASH), + const_iv (SDLK_DOLLAR), + const_iv (SDLK_AMPERSAND), + const_iv (SDLK_QUOTE), + const_iv (SDLK_LEFTPAREN), + const_iv (SDLK_RIGHTPAREN), + const_iv (SDLK_ASTERISK), + const_iv (SDLK_PLUS), + const_iv (SDLK_COMMA), + const_iv (SDLK_MINUS), + const_iv (SDLK_PERIOD), + const_iv (SDLK_SLASH), + const_iv (SDLK_0), + const_iv (SDLK_1), + const_iv (SDLK_2), + const_iv (SDLK_3), + const_iv (SDLK_4), + const_iv (SDLK_5), + const_iv (SDLK_6), + const_iv (SDLK_7), + const_iv (SDLK_8), + const_iv (SDLK_9), + const_iv (SDLK_COLON), + const_iv (SDLK_SEMICOLON), + const_iv (SDLK_LESS), + const_iv (SDLK_EQUALS), + const_iv (SDLK_GREATER), + const_iv (SDLK_QUESTION), + const_iv (SDLK_AT), + + const_iv (SDLK_LEFTBRACKET), + const_iv (SDLK_BACKSLASH), + const_iv (SDLK_RIGHTBRACKET), + const_iv (SDLK_CARET), + const_iv (SDLK_UNDERSCORE), + const_iv (SDLK_BACKQUOTE), + const_iv (SDLK_DELETE), + const_iv (SDLK_FIRST), const_iv (SDLK_LAST), const_iv (SDLK_KP0), @@ -645,7 +760,38 @@ const_iv (KMOD_CAPS), const_iv (KMOD_MODE), + const_iv (KMOD_LRAM), + const_iv (MIX_DEFAULT_FORMAT), + + const_iv (SDL_INIT_TIMER), + const_iv (SDL_INIT_AUDIO), + const_iv (SDL_INIT_VIDEO), + const_iv (SDL_INIT_CDROM), + const_iv (SDL_INIT_JOYSTICK), + const_iv (SDL_INIT_EVERYTHING), + const_iv (SDL_INIT_NOPARACHUTE), + const_iv (SDL_INIT_EVENTTHREAD), + + const_iv (SDL_GL_RED_SIZE), + const_iv (SDL_GL_GREEN_SIZE), + const_iv (SDL_GL_BLUE_SIZE), + const_iv (SDL_GL_ALPHA_SIZE), + const_iv (SDL_GL_DOUBLEBUFFER), + const_iv (SDL_GL_BUFFER_SIZE), + const_iv (SDL_GL_DEPTH_SIZE), + const_iv (SDL_GL_STENCIL_SIZE), + const_iv (SDL_GL_ACCUM_RED_SIZE), + const_iv (SDL_GL_ACCUM_GREEN_SIZE), + const_iv (SDL_GL_ACCUM_BLUE_SIZE), + const_iv (SDL_GL_ACCUM_ALPHA_SIZE), + const_iv (SDL_GL_STEREO), + const_iv (SDL_GL_MULTISAMPLEBUFFERS), + const_iv (SDL_GL_MULTISAMPLESAMPLES), + const_iv (SDL_GL_ACCELERATED_VISUAL), + const_iv (SDL_GL_SWAP_CONTROL), + + const_iv (FOW_DARKNESS) # undef const_iv }; @@ -691,14 +837,26 @@ #endif } -char * -SDL_GetError () +char *SDL_GetError () -int -SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) +void SDL_braino () -void -SDL_Quit () +int SDL_Init (U32 flags) + +int SDL_InitSubSystem (U32 flags) + +void SDL_QuitSubSystem (U32 flags) + +void SDL_Quit () + +int SDL_GL_SetAttribute (int attr, int value) + +int SDL_GL_GetAttribute (int attr) + CODE: + if (SDL_GL_GetAttribute (attr, &RETVAL)) + XSRETURN_UNDEF; + OUTPUT: + RETVAL void SDL_ListModes (int rgb, int alpha) @@ -720,17 +878,14 @@ SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); -#if SDL_VERSION_ATLEAST(1,2,10) - SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); -#endif m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); if (m && m != (SDL_Rect **)-1) while (*m) { - if ((*m)->w >= 800 && (*m)->h >= 480) + if ((*m)->w >= 400 && (*m)->h >= 300) { AV *av = newAV (); av_push (av, newSViv ((*m)->w)); @@ -803,8 +958,8 @@ case SDL_KEYUP: hv_store (hv, "state", 5, newSViv (ev.key.state), 0); hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); - hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod & MOD_MASK), 0); - hv_store (hv, "cmod", 4, newSViv (SDL_GetModState () & MOD_MASK), 0); /* current mode */ + hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0); + hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */ hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); break; @@ -832,7 +987,7 @@ SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); } - hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); + hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); hv_store (hv, "state", 5, newSViv (state), 0); hv_store (hv, "x", 1, newSViv (x), 0); hv_store (hv, "y", 1, newSViv (y), 0); @@ -1058,6 +1213,13 @@ #endif } +int +SvREFCNT (SV *sv) + CODE: + RETVAL = SvREFCNT (sv); + OUTPUT: + RETVAL + MODULE = Deliantra::Client PACKAGE = DC::Font PROTOTYPES: DISABLE @@ -1612,6 +1774,26 @@ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } +void +expire_textures (DC::Map self, int texid, int count) + PPCODE: + for (; texid < self->texs && count; ++texid, --count) + { + maptex *tex = self->tex + texid; + + if (tex->name) + { + if (tex->unused) + { + tex->name = 0; + tex->unused = 0; + XPUSHs (sv_2mortal (newSViv (texid))); + } + else + tex->unused = 1; + } + } + int ox (DC::Map self) ALIAS: @@ -1741,12 +1923,14 @@ if (cell->tile [z]) { maptex *tex = self->tex + cell->tile [z]; + tex->unused = 0; if (!tex->name) av_push (missing, newSViv (cell->tile [z])); if (tex->smoothtile) { maptex *smooth = self->tex + tex->smoothtile; + smooth->unused = 0; if (!smooth->name) av_push (missing, newSViv (tex->smoothtile)); } @@ -1754,7 +1938,7 @@ } } else - cell->darkness = 0; + CELL_CLEAR (cell); } } OUTPUT: @@ -1816,7 +2000,7 @@ RETVAL void -draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int pdx = 0, int pdy = 0) +draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) CODE: { int x, y, z; @@ -1827,13 +2011,14 @@ smooth_key skey; int pl_x, pl_y; maptex pl_tex; - rc_t *rc = rc_alloc (); + rc_t *rc = rc_alloc (); + rc_t *rc_ov = rc_alloc (); rc_key_t key; - rc_array_t *arr; + rc_array_t *arr, *arr_hidden; pl_tex.name = 0; - // thats current max. sorry. + // that's current max. sorry. if (sw > 255) sw = 255; if (sh > 255) sh = 255; @@ -1847,7 +2032,6 @@ key.a = 255; key.mode = GL_QUADS; key.format = GL_T2F_V3F; - key.texname = -1; mx += self->x; my += self->y; @@ -1878,9 +2062,13 @@ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + key.texname = self->tex [TEXID_HIDDEN].name; + arr_hidden = rc_array (rc_ov, &key); + for (z = 0; z <= 2; z++) { memset (smooth_level, 0, sizeof (smooth_level)); + key.texname = -1; for (y = 0; y < sh; y++) if (0 <= y + my && y + my < self->rows) @@ -1896,18 +2084,22 @@ if (tile) { maptex tex = self->tex [tile]; - int px = (x + 1) * T - tex.w; - int py = (y + 1) * T - tex.h; + int px, py; if (key.texname != tex.name) { + self->tex [tile].unused = 0; + if (!tex.name) - tex = self->tex [2]; /* missing, replace by noface */ + tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ key.texname = tex.name; arr = rc_array (rc, &key); } + px = (x + 1) * T - tex.w; + py = (y + 1) * T - tex.h; + if (expect_false (cell->player == player) && expect_false (z == 2)) { pl_x = px; @@ -1921,31 +2113,6 @@ rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); - if (expect_false (cell->flags) && expect_false (z == 2)) - { - // overlays such as the speech bubble, probably more to come - if (cell->flags & 1) - { - maptex tex = self->tex [1]; - int px = x * T + T * 2 / 32; - int py = y * T - T * 6 / 32; - - if (tex.name) - { - if (key.texname != tex.name) - { - key.texname = tex.name; - arr = rc_array (rc, &key); - } - - rc_t2f_v3f (arr, 0 , 0 , px , py , 0); - rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); - rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); - rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); - } - } - } - // update smooth hash if (tex.smoothtile) { @@ -1985,6 +2152,44 @@ skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); } } + + if (expect_false (z == 2)) + { + /* draw question marks on top of hidden spaces */ + if (!cell->darkness) + { + maptex tex = self->tex [TEXID_HIDDEN]; + int px = (x + 1) * T - tex.w; + int py = (y + 1) * T - tex.h; + + rc_t2f_v3f (arr_hidden, 0 , 0 , px , py , 0); + rc_t2f_v3f (arr_hidden, 0 , tex.t, px , py + tex.h, 0); + rc_t2f_v3f (arr_hidden, tex.s, tex.t, px + tex.w, py + tex.h, 0); + rc_t2f_v3f (arr_hidden, tex.s, 0 , px + tex.w, py , 0); + } + + if (expect_false (cell->flags)) + { + // overlays such as the speech bubble, probably more to come + if (cell->flags & 1) + { + rc_key_t key_ov = key; + maptex tex = self->tex [TEXID_SPEECH]; + rc_array_t *arr; + + key_ov.texname = tex.name; + arr = rc_array (rc_ov, &key_ov); + + int px = x * T + T * 2 / 32; + int py = y * T - T * 6 / 32; + + rc_t2f_v3f (arr, 0 , 0 , px , py , 0); + rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); + rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); + rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); + } + } + } } } @@ -2032,6 +2237,8 @@ // save gobs of state changes. if (key.texname != tex.name) { + self->tex [skey->tile].unused = 0; + glEnd (); glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); glBegin (GL_QUADS); @@ -2073,8 +2280,8 @@ if (pl_tex.name) { maptex tex = pl_tex; - int px = pl_x + pdx; - int py = pl_y + pdy; + int px = pl_x + sdx; + int py = pl_y + sdy; key.texname = tex.name; arr = rc_array (rc, &key); @@ -2087,8 +2294,12 @@ rc_draw (rc); } + rc_draw (rc_ov); + rc_clear (rc_ov); + glDisable (GL_BLEND); rc_free (rc); + rc_free (rc_ov); // top layer: overlays such as the health bar for (y = 0; y < sh; y++) @@ -2104,6 +2315,12 @@ int px = x * T; int py = y * T; + if (expect_false (cell->player == player)) + { + px += sdx; + py += sdy; + } + if (cell->stat_hp) { int width = cell->stat_width * T; @@ -2201,7 +2418,7 @@ mx += self->x - 1; my += self->y - 1; - memset (darkness1, 255, sw1 * sh1); + memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); for (y = 0; y < sh1; y++) if (0 <= y + my && y + my < self->rows) @@ -2853,6 +3070,7 @@ glRotatef (angle, x, y, z); void glColor (float r, float g, float b, float a = 1.0) + PROTOTYPE: @ ALIAS: glColor_premultiply = 1 CODE: