--- deliantra/Deliantra-Client/Client.xs 2006/06/05 03:33:09 1.105 +++ deliantra/Deliantra-Client/Client.xs 2006/06/17 15:07:52 1.119 @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -87,9 +88,15 @@ static void substitute_func (FcPattern *pattern, gpointer data) { - FcPatternAddBool (pattern, FC_HINTING , 1); - //FcPatternAddBool (pattern, FC_AUTOHINT, 1); + FcPatternAddBool (pattern, FC_HINTING, 1); +#ifdef FC_HINT_STYLE + FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); +#endif +#ifdef _WIN32 + FcPatternAddBool (pattern, FC_AUTOHINT, 1); +#else FcPatternAddBool (pattern, FC_AUTOHINT, 0); +#endif } static void @@ -297,6 +304,23 @@ SDL_PushEvent ((SDL_Event *)&ev); } +static unsigned int +minpot (unsigned int n) +{ + if (!n) + return 0; + + --n; + + n |= n >> 1; + n |= n >> 2; + n |= n >> 4; + n |= n >> 8; + n |= n >> 16; + + return n + 1; +} + MODULE = CFClient PACKAGE = CFClient PROTOTYPES: ENABLE @@ -414,6 +438,10 @@ newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); } +NV floor (NV x) + +NV ceil (NV x) + void pango_init () CODE: @@ -424,12 +452,16 @@ pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); } - { cairo_font_options_t *fopt = cairo_font_options_create (); cairo_fontmap = pango_cairo_font_map_get_default (); cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); +#ifdef _WIN32 + // cairo looks like shit eaten twice on windows + cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); +#else cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); +#endif cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); pango_cairo_context_set_font_options (cairo_context, fopt); @@ -455,7 +487,7 @@ SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 1); SDL_GL_SetAttribute (SDL_GL_BUFFER_SIZE, 15); - SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); @@ -695,7 +727,12 @@ #ifdef _WIN32 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); #endif - exit (1); + _exit (1); + +void +_exit (int retval) + CODE: + _exit (retval); MODULE = CFClient PACKAGE = CFClient::Font @@ -726,10 +763,6 @@ CFClient::Layout new (SV *class, int rgba = 0) CODE: -#if _WIN32 - //rgba = 0;//D makes text nicer, breaks TextView -#endif - rgba=1;//D New (0, RETVAL, 1, struct cf_layout); RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); @@ -783,7 +816,7 @@ get_text (CFClient::Layout self) CODE: RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); - SvUTF8_on (RETVAL); + sv_utf8_decode (RETVAL); OUTPUT: RETVAL @@ -974,7 +1007,44 @@ MODULE = CFClient PACKAGE = CFClient::Texture void -draw_quad (SV *self, float x, float y, float w = 0, float h = 0) +pad2pot (SV *data_, SV *w_, SV *h_) + CODE: +{ + int ow = SvIV (w_); + int oh = SvIV (h_); + + if (ow && oh) + { + int nw = minpot (ow); + int nh = minpot (oh); + + if (nw != ow || nh != oh) + { + if (SvOK (data_)) + { + STRLEN datalen; + char *data = SvPVbyte (data_, datalen); + int bpp = datalen / (ow * oh); + SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); + + SvPOK_only (result_); + SvCUR_set (result_, nw * nh * bpp); + + memset (SvPVX (result_), 0, nw * nh * bpp); + while (oh--) + memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); + + sv_setsv (data_, result_); + } + + sv_setiv (w_, nw); + sv_setiv (h_, nh); + } + } +} + +void +draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) PROTOTYPE: $$$;$$ ALIAS: draw_quad_alpha = 1 @@ -1049,6 +1119,7 @@ { map_clear (self); Safefree (self->face); + Safefree (self->tex); Safefree (self); } @@ -1265,22 +1336,15 @@ void draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) - PPCODE: + CODE: { int vx, vy; int x, y, z; int last_name; mapface face; - int sw4 = (sw + 3) & ~3; - SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); - uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); - memset (darkness, 255, sw4 * sh); - SvPOK_only (darkness_sv); - SvCUR_set (darkness_sv, sw4 * sh); - - vx = self->x + (self->w - sw) / 2 - shift_x; - vy = self->y + (self->h - sh) / 2 - shift_y; + vx = self->x + (self->w - sw + 1) / 2 - shift_x; + vy = self->y + (self->h - sh + 1) / 2 - shift_y; /* int vx = self->vx = self->w >= sw @@ -1294,8 +1358,8 @@ glColor4ub (255, 255, 255, 255); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_TEXTURE_2D); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); @@ -1314,10 +1378,6 @@ { mapcell *cell = row->col + (x + vx - row->c0); - darkness[y * sw4 + x] = cell->darkness < 0 - ? 255 - FOW_DARKNESS - : 255 - cell->darkness; - face = cell->face [z]; if (face) @@ -1347,6 +1407,100 @@ glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); +} + +void +draw_magicmap (CFClient::Map self, int dx, int dy, int w, int h, unsigned char *data) + CODE: +{ + static float color[16][3] = { + { 0.00, 0.00, 0.00 }, + { 1.00, 1.00, 1.00 }, + { 0.00, 0.00, 0.55 }, + { 1.00, 0.00, 0.00 }, + + { 1.00, 0.54, 0.00 }, + { 0.11, 0.56, 1.00 }, + { 0.93, 0.46, 0.00 }, + { 0.18, 0.54, 0.34 }, + + { 0.56, 0.73, 0.56 }, + { 0.80, 0.80, 0.80 }, + { 0.55, 0.41, 0.13 }, + { 0.99, 0.77, 0.26 }, + + { 0.74, 0.65, 0.41 }, + + { 0.00, 1.00, 1.00 }, + { 1.00, 0.00, 1.00 }, + { 1.00, 1.00, 0.00 }, + }; + + int x, y; + + glEnable (GL_TEXTURE_2D); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin (GL_QUADS); + + for (y = 0; y < h; y++) + for (x = 0; x < w; x++) + { + unsigned char m = data [x + y * w]; + + if (m) + { + float *c = color [m & 15]; + + float tx1 = m & 0x40 ? 0.5 : 0.; + float tx2 = tx1 + 0.5; + + glColor4f (c[0], c[1], c[2], 0.75); + glTexCoord2f (tx1, 0.); glVertex2i (x , y ); + glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); + glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); + glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); + } + } + + glEnd (); + glDisable (GL_BLEND); + glDisable (GL_TEXTURE_2D); +} + +void +fow_texture (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) + PPCODE: +{ + int vx, vy; + int x, y; + int sw4 = (sw + 3) & ~3; + SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); + uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); + + memset (darkness, 255, sw4 * sh); + SvPOK_only (darkness_sv); + SvCUR_set (darkness_sv, sw4 * sh); + + vx = self->x + (self->w - sw + 1) / 2 - shift_x; + vy = self->y + (self->h - sh + 1) / 2 - shift_y; + + for (y = 0; y < sh; y++) + if (0 <= y + vy && y + vy < self->rows) + { + maprow *row = self->row + (y + vy); + + for (x = 0; x < sw; x++) + if (row->c0 <= x + vx && x + vx < row->c1) + { + mapcell *cell = row->col + (x + vx - row->c0); + + darkness[y * sw4 + x] = cell->darkness < 0 + ? 255 - FOW_DARKNESS + : 255 - cell->darkness; + } + } EXTEND (SP, 3); PUSHs (sv_2mortal (newSViv (sw4))); @@ -1563,6 +1717,8 @@ const_iv (GL_ALPHA_TEST), const_iv (GL_NORMALIZE), const_iv (GL_RESCALE_NORMAL), + const_iv (GL_FRONT), + const_iv (GL_BACK), const_iv (GL_AND), const_iv (GL_ONE), const_iv (GL_ZERO), @@ -1573,6 +1729,9 @@ const_iv (GL_SRC_ALPHA_SATURATE), const_iv (GL_RGB), const_iv (GL_RGBA), + const_iv (GL_RGBA4), + const_iv (GL_RGBA8), + const_iv (GL_RGB5_A1), const_iv (GL_UNSIGNED_BYTE), const_iv (GL_UNSIGNED_SHORT), const_iv (GL_UNSIGNED_INT), @@ -1656,6 +1815,8 @@ int glGetError () +void glFinish () + void glClear (int mask) void glClearColor (float r, float g, float b, float a = 1.0) @@ -1689,6 +1850,10 @@ void glLoadIdentity () +void glDrawBuffer (int buffer) + +void glReadBuffer (int buffer) + # near_ and far_ are due to microsofts buggy "c" compiler void glFrustum (double left, double right, double bottom, double top, double near_, double far_)