--- deliantra/Deliantra-Client/Client.xs 2006/04/13 23:07:56 1.30 +++ deliantra/Deliantra-Client/Client.xs 2006/04/15 00:04:58 1.39 @@ -39,7 +39,7 @@ substitute_func (FcPattern *pattern, gpointer data) { FcPatternAddBool (pattern, FC_HINTING , 1); - FcPatternAddBool (pattern, FC_AUTOHINT, 1); + FcPatternAddBool (pattern, FC_AUTOHINT, 0); } static void @@ -68,6 +68,7 @@ GLint name; int w, h; float s, t; + uint8_t r, g, b, a; } mapface; typedef struct { @@ -152,9 +153,7 @@ if (x >= row->c1) break; - mapcell *cell = row->col + (x - row->c0); - cell->darkness = -1; - cell->face [2] = 0; + row->col[x - row->c0].darkness = -1; } } } @@ -246,6 +245,8 @@ surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); + assert (surface2->pitch == surface2->w * 4); + EXTEND (SP, 5); PUSHs (sv_2mortal (newSViv (surface2->w))); PUSHs (sv_2mortal (newSViv (surface2->h))); @@ -261,6 +262,34 @@ } void +average (int x, int y, uint32_t *data) + PPCODE: +{ + // only good for x * y < 32768 + uint32_t r = 0, g = 0, b = 0, a = 0; + + x = y = x * y; + + assert (x < 32768); + + while (x--) + { + uint32_t p = *data++; + + r += (p ) & 255; + g += (p >> 8) & 255; + b += (p >> 16) & 255; + a += (p >> 24) & 255; + } + + EXTEND (SP, 4); + PUSHs (sv_2mortal (newSViv (r * 255 / y))); + PUSHs (sv_2mortal (newSViv (g * 255 / y))); + PUSHs (sv_2mortal (newSViv (b * 255 / y))); + PUSHs (sv_2mortal (newSViv (a * 255 / y))); +} + +void fatal (char *message) CODE: #ifdef WIN32 @@ -289,6 +318,16 @@ Safefree (self); void +set_text (CFClient::Layout self, SV *text_) + CODE: +{ + STRLEN textlen; + char *text = SvPVutf8 (text_, textlen); + + pango_layout_set_text (self->pl, text, textlen); +} + +void set_markup (CFClient::Layout self, SV *text_) CODE: { @@ -385,14 +424,15 @@ MODULE = CFClient PACKAGE = CFClient::Texture void -draw_quad (SV *self, double x, double y, double w = 0, double h = 0) +draw_quad (SV *self, float x, float y, float w = 0, float h = 0) PROTOTYPE: $$$;$$ CODE: { HV *hv = (HV *)SvRV (self); - double s = SvNV (*hv_fetch (hv, "s", 1, 1)); - double t = SvNV (*hv_fetch (hv, "t", 1, 1)); + float s = SvNV (*hv_fetch (hv, "s", 1, 1)); + float t = SvNV (*hv_fetch (hv, "t", 1, 1)); int name = SvIV (*hv_fetch (hv, "name", 4, 1)); + int wrap_mode = SvIV (*hv_fetch (hv, "wrap_mode", 9, 1)); if (items < 5) { @@ -401,11 +441,15 @@ } glBindTexture (GL_TEXTURE_2D, name); + if (wrap_mode) { + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } glBegin (GL_QUADS); - glTexCoord2d (0, 0); glVertex2d (x , y ); - glTexCoord2d (0, t); glVertex2d (x , y + h); - glTexCoord2d (s, t); glVertex2d (x + w, y + h); - glTexCoord2d (s, 0); glVertex2d (x + w, y ); + glTexCoord2f (0, 0); glVertex2f (x , y ); + glTexCoord2f (0, t); glVertex2f (x , y + h); + glTexCoord2f (s, t); glVertex2f (x + w, y + h); + glTexCoord2f (s, 0); glVertex2f (x + w, y ); glEnd (); } @@ -443,7 +487,7 @@ map_clear (self); void -set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t) +set_texture (CFClient::Map self, int face, int name, int w, int h, float s, float t, int r, int g, int b, int a) CODE: { while (self->faces < face) @@ -452,11 +496,17 @@ self->faces *= 2; } - self->face [face].name = name; - self->face [face].w = w; - self->face [face].h = h; - self->face [face].s = s; - self->face [face].t = t; + mapface *f = self->face + face; + + f->name = name; + f->w = w; + f->h = h; + f->s = s; + f->t = t; + f->r = r; + f->g = g; + f->b = b; + f->a = a; } void @@ -562,24 +612,34 @@ } } else - { - cell->darkness = -1; - cell->face [2] = 0; - } + cell->darkness = -1; } } void -draw (CFClient::Map self, int x0, int y0, int sw, int sh) - CODE: +draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) + PPCODE: { - int vx = self->vx = self->w >= sw - ? self->x + (self->w - sw) / 2 - : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); + int sw4 = (sw + 3) & ~3; + SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); + uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); - int vy = self->vy = self->h >= sh - ? self->y + (self->h - sh) / 2 - : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); + SvPOK_only (darkness_sv); + SvCUR_set (darkness_sv, sw4 * sh); + + int vx = self->x + (self->w - sw) / 2 - shift_x; + int vy = self->y + (self->h - sh) / 2 - shift_y; + + if (0) + { + int vx = self->vx = self->w >= sw + ? self->x + (self->w - sw) / 2 + : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); + + int vy = self->vy = self->h >= sh + ? self->y + (self->h - sh) / 2 + : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); + } glColor4ub (255, 255, 255, 255); @@ -604,6 +664,11 @@ 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; + uint16_t face = cell->face [z]; if (face) @@ -630,5 +695,13 @@ } glEnd (); + + glDisable (GL_TEXTURE_2D); + glDisable (GL_BLEND); + + EXTEND (SP, 3); + PUSHs (sv_2mortal (newSViv (sw4))); + PUSHs (sv_2mortal (newSViv (sh))); + PUSHs (darkness_sv); }