--- deliantra/Deliantra-Client/Client.xs 2008/01/06 18:25:59 1.255 +++ deliantra/Deliantra-Client/Client.xs 2008/07/16 20:12:27 1.262 @@ -67,6 +67,15 @@ # include #endif +#if __GNUC__ >= 4 +# define expect(expr,value) __builtin_expect ((expr),(value)) +#else +# define expect(expr,value) (expr) +#endif + +#define expect_false(expr) expect ((expr) != 0, 0) +#define expect_true(expr) expect ((expr) != 0, 1) + #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ #define FOW_DARKNESS 32 @@ -79,7 +88,7 @@ /* mask out modifiers we are not interested in */ #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) -#if 0 +#if 1 # define PARACHUTE SDL_INIT_NOPARACHUTE #else # define PARACHUTE 0 @@ -187,7 +196,7 @@ layout_update_font (DC__Layout self) { /* use a random scale factor to account for unknown descenders, 0.8 works - * reasonably well with bitstream vera + * reasonably well with dejavu/bistream fonts */ PangoFontDescription *font = self->font ? self->font : default_font; @@ -675,6 +684,7 @@ opengl_fontmap = pango_opengl_font_map_new (); pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); + /*pango_context_set_font_description (opengl_context, default_font);*/ #if PANGO_VERSION_CHECK (1, 15, 2) pango_context_set_language (opengl_context, pango_language_from_string ("en")); /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ @@ -772,6 +782,9 @@ int SDL_GetAppState () +int +SDL_GetModState () + void poll_events () PPCODE: @@ -914,10 +927,12 @@ #endif } -void +int add_font (char *file) CODE: - FcConfigAppFontAddFile (0, (const FcChar8 *)file); + RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); + OUTPUT: + RETVAL void load_image_inline (SV *image_) @@ -1683,7 +1698,7 @@ do { ext = *data++; - cmd = ext & 0x3f; + cmd = ext & 0x7f; if (cmd < 4) cell->darkness = 255 - ext * 64 + 1; @@ -1696,8 +1711,10 @@ cell->stat_width = *data++ + 1; else if (cmd == 0x47) { - if (*data == 4) - ; // decode player count + if (*data == 1) cell->player = data [1]; + else if (*data == 2) cell->player = data [2] + (data [1] << 8); + else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); + else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); data += *data + 1; } @@ -1799,7 +1816,7 @@ RETVAL void -draw (DC::Map self, int mx, int my, int sw, int sh, int T) +draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int pdx = 0, int pdy = 0) CODE: { int x, y, z; @@ -1808,11 +1825,14 @@ uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) smooth_key skey; - + int pl_x, pl_y; + maptex pl_tex; rc_t *rc = rc_alloc (); rc_key_t key; rc_array_t *arr; + pl_tex.name = 0; + // thats current max. sorry. if (sw > 255) sw = 255; if (sh > 255) sh = 255; @@ -1876,7 +1896,8 @@ if (tile) { maptex tex = self->tex [tile]; - int px, py; + int px = (x + 1) * T - tex.w; + int py = (y + 1) * T - tex.h; if (key.texname != tex.name) { @@ -1887,15 +1908,20 @@ 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; + pl_y = py; + pl_tex = tex; + continue; + } rc_t2f_v3f (arr, 0 , 0 , px , py , 0); rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 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 (cell->flags && z == 2) + if (expect_false (cell->flags) && expect_false (z == 2)) { // overlays such as the speech bubble, probably more to come if (cell->flags & 1) @@ -2044,6 +2070,23 @@ hv_clear (smooth); } + if (pl_tex.name) + { + maptex tex = pl_tex; + int px = pl_x + pdx; + int py = pl_y + pdy; + + 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 + tex.h, 0); + 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); + + rc_draw (rc); + } + glDisable (GL_BLEND); rc_free (rc); @@ -2288,20 +2331,35 @@ } } - SvPOK_only (data_sv); - SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); - RETVAL = data_sv; + /* if size is w*h + 5 then no data has been found */ + if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) + { + SvPOK_only (data_sv); + SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); + } + + RETVAL = data_sv; } OUTPUT: RETVAL void -set_rect (DC::Map self, int x0, int y0, uint8_t *data) +set_rect (DC::Map self, int x0, int y0, SV *data_sv) PPCODE: { int x, y, z; int w, h; int x1, y1; + STRLEN len; + uint8_t *data, *end; + + len = SvLEN (data_sv); + SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more + data = SvPVbyte_nolen (data_sv); + end = data + len + 8; + + if (len < 5) + XSRETURN_EMPTY; if (*data++ != 0) XSRETURN_EMPTY; /* version mismatch */ @@ -2326,7 +2384,12 @@ for (x = x0; x < x1; x++) { - uint8_t flags = *data++; + uint8_t flags; + + if (data + 7 >= end) + XSRETURN_EMPTY; + + flags = *data++; if (flags) { @@ -2339,7 +2402,8 @@ if (cell->darkness == 0) { - cell->darkness = 0; + /*cell->darkness = 0;*/ + EXTEND (SP, 3); for (z = 0; z <= 2; z++) { @@ -2347,7 +2411,7 @@ if (t >= self->texs || (t && !self->tex [t].name)) { - XPUSHs (sv_2mortal (newSViv (t))); + PUSHs (sv_2mortal (newSViv (t))); need_texid (self, t); }