--- deliantra/Deliantra-Client/Client.xs 2009/12/21 03:30:22 1.295 +++ deliantra/Deliantra-Client/Client.xs 2009/12/21 23:52:34 1.296 @@ -82,8 +82,10 @@ #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ -#define FOW_DARKNESS 64 -#define DARKNESS_ADJUST(n) ((29 * (int)(n)) >> 5) /* times 0.9 */ +/* this is used as fow flag as well, so has to have a different value */ +/* then anything that is computed by incoming darkness */ +#define FOW_DARKNESS 50 +#define DARKNESS_ADJUST(n) (n) #define MAP_EXTEND_X 32 #define MAP_EXTEND_Y 512 @@ -1667,7 +1669,7 @@ } void -draw_fow_texture (float intensity, int name1, float s1, float t1, float w1, float h1, float blend = 0.f, float dx = 0.f, float dy = 0.f, int name2 = 0, float s2 = 0.f, float t2 = 0.f, float w2 = 0.f, float h2 = 0.f) +draw_fow_texture (float intensity, int hidden_tex, int name1, uint8_t *data1, float s, float t, int w, int h, float blend = 0.f, int dx = 0, int dy = 0, int name2 = 0, uint8_t *data2 = data1) PROTOTYPE: @ CODE: { @@ -1682,9 +1684,8 @@ if (blend > 0.f) { - float S2, T2; /* 0. 0. for texture 2 */ - float w = w1 > w2 ? w1 : w2; - float h = h1 > h2 ? h1 : h2; + float dx3 = dx * -3.f / w; + float dy3 = dy * -3.f / h; GLfloat env_color[4] = { 0., 0., 0., blend }; /* interpolate the two shadow textures */ @@ -1715,22 +1716,11 @@ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); - s1 *= w / w1; - t1 *= h / h1; - - dx *= -3.f / w2; - dy *= -3.f / h2; - dx *= w / w2; - dy *= h / h2; - - s2 *= w / w2; - t2 *= h / h2; - glBegin (GL_QUADS); - gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy ); glVertex2f ( 0, 0); - gl.MultiTexCoord2f (GL_TEXTURE0, 0, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy + t2); glVertex2f ( 0, h1); - gl.MultiTexCoord2f (GL_TEXTURE0, s1, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy + t2); glVertex2f (w1, h1); - gl.MultiTexCoord2f (GL_TEXTURE0, s1, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy ); glVertex2f (w1, 0); + gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0); + gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h); + gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h); + gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0); glEnd (); glDisable (GL_TEXTURE_2D); @@ -1742,13 +1732,57 @@ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin (GL_QUADS); - glTexCoord2f ( 0, 0); glVertex2f ( 0, 0); - glTexCoord2f ( 0, t1); glVertex2f ( 0, h1); - glTexCoord2f (s1, t1); glVertex2f (w1, h1); - glTexCoord2f (s1, 0); glVertex2f (w1, 0); + glTexCoord2f (0, 0); glVertex2f (0, 0); + glTexCoord2f (0, t); glVertex2f (0, h); + glTexCoord2f (s, t); glVertex2f (w, h); + glTexCoord2f (s, 0); glVertex2f (w, 0); glEnd (); } + /* draw ?-marks or equivalent, this is very clumsy code :/ */ + { + int x, y; + int dx3 = dx * 3; + int dy3 = dy * 3; + + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glBindTexture (GL_TEXTURE_2D, hidden_tex); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glTranslatef (-1., -1., 0); + glBegin (GL_QUADS); + + for (y = 1; y < h; y += 3) + { + int y1 = y - dy3; + int y1valid = y1 >= 0 && y1 < h; + + for (x = 1; x < w; x += 3) + { + int x1 = x - dx3; + uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); + uint8_t h2; + + if (y1valid && x1 >= 0 && x1 < w) + h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); + else + h2 = 1; /* out of range == invisible */ + + if (h1 || h2) + { + float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend; + glColor4f (1., 1., 1., alpha); + + glTexCoord2f (0, 0.); glVertex2i (x , y ); + glTexCoord2f (0, 1.); glVertex2i (x , y + 3); + glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3); + glTexCoord2f (1, 0.); glVertex2i (x + 3, y ); + } + } + } + } + + glEnd (); + glPopMatrix (); glDisable (GL_TEXTURE_2D); @@ -1978,7 +2012,7 @@ cmd = ext & 0x7f; if (cmd < 4) - cell->darkness = 255 - ext * 64 + 1; + cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ else if (cmd == 5) // health { cell->stat_width = 1; @@ -2248,40 +2282,24 @@ } } - if (expect_false (z == 2)) + if (expect_false (z == 2) && expect_false (cell->flags)) { - /* draw question marks on top of hidden spaces */ - if (!cell->darkness) + // overlays such as the speech bubble, probably more to come + if (cell->flags & 1) { - 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; - int px = x * T + T * 2 / 32; - int py = y * T - T * 6 / 32; - - key_ov.texname = tex.name; - arr = rc_array (rc_ov, &key_ov); - - 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); - } + rc_key_t key_ov = key; + maptex tex = self->tex [TEXID_SPEECH]; + rc_array_t *arr; + int px = x * T + T * 2 / 32; + int py = y * T - T * 6 / 32; + + key_ov.texname = tex.name; + arr = rc_array (rc_ov, &key_ov); + + 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); } } } @@ -2465,7 +2483,7 @@ glEnable (GL_TEXTURE_2D); /* GL_REPLACE would be correct, as we don't need to modulate alpha, * but the nvidia driver (185.18.14) mishandles alpha textures - * ansd takes the colour from god knows where instead of using + * and takes the colour from god knows where instead of using * Cp. MODULATE results in the same colour, but slightly different * alpha, but atcually gives us the correct colour with nvidia. */ @@ -2504,22 +2522,20 @@ PPCODE: { int x, y; - int sw1 = sw + 2; - int sh1 = sh + 2; - int sh3 = sh * 3; - int sw34 = (sw * 3 + 3) & ~3; + int sw1 = sw + 2; + int sh1 = sh + 2; + int sh3 = sh * 3; + int sw3 = sw * 3; uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); - SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); + SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); SvPOK_only (darkness3_sv); - SvCUR_set (darkness3_sv, sw34 * sh3); + SvCUR_set (darkness3_sv, sw3 * sh3); mx += self->x - 1; my += self->y - 1; - memset (darkness1, DARKNESS_ADJUST (255 - FOW_DARKNESS), sw1 * sh1); - for (y = 0; y < sh1; y++) if (0 <= y + my && y + my < self->rows) { @@ -2561,21 +2577,21 @@ uint8_t r23 = d23; uint8_t r33 = (d23 + d33 + d32) / 3; - darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); - darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); - darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); - darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); - darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); - darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); - darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); - darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); - darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); + darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11); + darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21); + darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31); + darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12); + darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */ + darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32); + darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13); + darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23); + darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33); } free (darkness1); EXTEND (SP, 3); - PUSHs (sv_2mortal (newSViv (sw34))); + PUSHs (sv_2mortal (newSViv (sw3))); PUSHs (sv_2mortal (newSViv (sh3))); PUSHs (darkness3_sv); } @@ -3299,6 +3315,11 @@ void glCallList (int list) +void c_init () + CODE: + glPixelStorei (GL_PACK_ALIGNMENT , 1); + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + MODULE = Deliantra::Client PACKAGE = DC::UI::Base PROTOTYPES: DISABLE