ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.295 by root, Mon Dec 21 03:30:22 2009 UTC vs.
Revision 1.296 by root, Mon Dec 21 23:52:34 2009 UTC

80#define expect_false(expr) expect ((expr) != 0, 0) 80#define expect_false(expr) expect ((expr) != 0, 0)
81#define expect_true(expr) expect ((expr) != 0, 1) 81#define expect_true(expr) expect ((expr) != 0, 1)
82 82
83#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 83#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
84 84
85/* this is used as fow flag as well, so has to have a different value */
86/* then anything that is computed by incoming darkness */
85#define FOW_DARKNESS 64 87#define FOW_DARKNESS 50
86#define DARKNESS_ADJUST(n) ((29 * (int)(n)) >> 5) /* times 0.9 */ 88#define DARKNESS_ADJUST(n) (n)
87 89
88#define MAP_EXTEND_X 32 90#define MAP_EXTEND_X 32
89#define MAP_EXTEND_Y 512 91#define MAP_EXTEND_Y 512
90 92
91#define MIN_FONT_HEIGHT 10 93#define MIN_FONT_HEIGHT 10
1665 glDisable (GL_BLEND); 1667 glDisable (GL_BLEND);
1666 } 1668 }
1667} 1669}
1668 1670
1669void 1671void
1670draw_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) 1672draw_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)
1671 PROTOTYPE: @ 1673 PROTOTYPE: @
1672 CODE: 1674 CODE:
1673{ 1675{
1674 glEnable (GL_TEXTURE_2D); 1676 glEnable (GL_TEXTURE_2D);
1675 glEnable (GL_BLEND); 1677 glEnable (GL_BLEND);
1680 glPushMatrix (); 1682 glPushMatrix ();
1681 glScalef (1./3, 1./3, 1.); 1683 glScalef (1./3, 1./3, 1.);
1682 1684
1683 if (blend > 0.f) 1685 if (blend > 0.f)
1684 { 1686 {
1685 float S2, T2; /* 0. 0. for texture 2 */ 1687 float dx3 = dx * -3.f / w;
1686 float w = w1 > w2 ? w1 : w2; 1688 float dy3 = dy * -3.f / h;
1687 float h = h1 > h2 ? h1 : h2;
1688 GLfloat env_color[4] = { 0., 0., 0., blend }; 1689 GLfloat env_color[4] = { 0., 0., 0., blend };
1689 1690
1690 /* interpolate the two shadow textures */ 1691 /* interpolate the two shadow textures */
1691 /* stage 0 == rgb(glcolor) + alpha(t0) */ 1692 /* stage 0 == rgb(glcolor) + alpha(t0) */
1692 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1693 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1713 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); 1714 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1714 1715
1715 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); 1716 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT);
1716 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); 1717 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
1717 1718
1718 s1 *= w / w1;
1719 t1 *= h / h1;
1720
1721 dx *= -3.f / w2;
1722 dy *= -3.f / h2;
1723 dx *= w / w2;
1724 dy *= h / h2;
1725
1726 s2 *= w / w2;
1727 t2 *= h / h2;
1728
1729 glBegin (GL_QUADS); 1719 glBegin (GL_QUADS);
1730 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy ); glVertex2f ( 0, 0); 1720 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0);
1731 gl.MultiTexCoord2f (GL_TEXTURE0, 0, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy + t2); glVertex2f ( 0, h1); 1721 gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h);
1732 gl.MultiTexCoord2f (GL_TEXTURE0, s1, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy + t2); glVertex2f (w1, h1); 1722 gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h);
1733 gl.MultiTexCoord2f (GL_TEXTURE0, s1, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy ); glVertex2f (w1, 0); 1723 gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0);
1734 glEnd (); 1724 glEnd ();
1735 1725
1736 glDisable (GL_TEXTURE_2D); 1726 glDisable (GL_TEXTURE_2D);
1737 gl.ActiveTexture (GL_TEXTURE0); 1727 gl.ActiveTexture (GL_TEXTURE0);
1738 } 1728 }
1740 { 1730 {
1741 /* simple blending of one texture, also opengl <1.3 path */ 1731 /* simple blending of one texture, also opengl <1.3 path */
1742 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1732 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1743 1733
1744 glBegin (GL_QUADS); 1734 glBegin (GL_QUADS);
1745 glTexCoord2f ( 0, 0); glVertex2f ( 0, 0); 1735 glTexCoord2f (0, 0); glVertex2f (0, 0);
1746 glTexCoord2f ( 0, t1); glVertex2f ( 0, h1); 1736 glTexCoord2f (0, t); glVertex2f (0, h);
1747 glTexCoord2f (s1, t1); glVertex2f (w1, h1); 1737 glTexCoord2f (s, t); glVertex2f (w, h);
1748 glTexCoord2f (s1, 0); glVertex2f (w1, 0); 1738 glTexCoord2f (s, 0); glVertex2f (w, 0);
1749 glEnd (); 1739 glEnd ();
1750 } 1740 }
1741
1742 /* draw ?-marks or equivalent, this is very clumsy code :/ */
1743 {
1744 int x, y;
1745 int dx3 = dx * 3;
1746 int dy3 = dy * 3;
1747
1748 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1749 glBindTexture (GL_TEXTURE_2D, hidden_tex);
1750 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1751 glTranslatef (-1., -1., 0);
1752 glBegin (GL_QUADS);
1753
1754 for (y = 1; y < h; y += 3)
1755 {
1756 int y1 = y - dy3;
1757 int y1valid = y1 >= 0 && y1 < h;
1758
1759 for (x = 1; x < w; x += 3)
1760 {
1761 int x1 = x - dx3;
1762 uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1763 uint8_t h2;
1764
1765 if (y1valid && x1 >= 0 && x1 < w)
1766 h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1767 else
1768 h2 = 1; /* out of range == invisible */
1769
1770 if (h1 || h2)
1771 {
1772 float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend;
1773 glColor4f (1., 1., 1., alpha);
1774
1775 glTexCoord2f (0, 0.); glVertex2i (x , y );
1776 glTexCoord2f (0, 1.); glVertex2i (x , y + 3);
1777 glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3);
1778 glTexCoord2f (1, 0.); glVertex2i (x + 3, y );
1779 }
1780 }
1781 }
1782 }
1783
1784 glEnd ();
1751 1785
1752 glPopMatrix (); 1786 glPopMatrix ();
1753 1787
1754 glDisable (GL_TEXTURE_2D); 1788 glDisable (GL_TEXTURE_2D);
1755 glDisable (GL_BLEND); 1789 glDisable (GL_BLEND);
1976 { 2010 {
1977 ext = *data++; 2011 ext = *data++;
1978 cmd = ext & 0x7f; 2012 cmd = ext & 0x7f;
1979 2013
1980 if (cmd < 4) 2014 if (cmd < 4)
1981 cell->darkness = 255 - ext * 64 + 1; 2015 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
1982 else if (cmd == 5) // health 2016 else if (cmd == 5) // health
1983 { 2017 {
1984 cell->stat_width = 1; 2018 cell->stat_width = 1;
1985 cell->stat_hp = *data++; 2019 cell->stat_hp = *data++;
1986 } 2020 }
2246 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2280 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400);
2247 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2281 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800);
2248 } 2282 }
2249 } 2283 }
2250 2284
2251 if (expect_false (z == 2)) 2285 if (expect_false (z == 2) && expect_false (cell->flags))
2252 { 2286 {
2253 /* draw question marks on top of hidden spaces */ 2287 // overlays such as the speech bubble, probably more to come
2254 if (!cell->darkness) 2288 if (cell->flags & 1)
2255 { 2289 {
2256 maptex tex = self->tex [TEXID_HIDDEN];
2257 int px = (x + 1) * T - tex.w;
2258 int py = (y + 1) * T - tex.h;
2259
2260 rc_t2f_v3f (arr_hidden, 0 , 0 , px , py , 0);
2261 rc_t2f_v3f (arr_hidden, 0 , tex.t, px , py + tex.h, 0);
2262 rc_t2f_v3f (arr_hidden, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2263 rc_t2f_v3f (arr_hidden, tex.s, 0 , px + tex.w, py , 0);
2264 }
2265
2266 if (expect_false (cell->flags))
2267 {
2268 // overlays such as the speech bubble, probably more to come
2269 if (cell->flags & 1)
2270 {
2271 rc_key_t key_ov = key; 2290 rc_key_t key_ov = key;
2272 maptex tex = self->tex [TEXID_SPEECH]; 2291 maptex tex = self->tex [TEXID_SPEECH];
2273 rc_array_t *arr; 2292 rc_array_t *arr;
2274 int px = x * T + T * 2 / 32; 2293 int px = x * T + T * 2 / 32;
2275 int py = y * T - T * 6 / 32; 2294 int py = y * T - T * 6 / 32;
2276 2295
2277 key_ov.texname = tex.name; 2296 key_ov.texname = tex.name;
2278 arr = rc_array (rc_ov, &key_ov); 2297 arr = rc_array (rc_ov, &key_ov);
2279 2298
2280 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2299 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2281 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); 2300 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2282 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); 2301 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2283 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); 2302 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2284 }
2285 } 2303 }
2286 } 2304 }
2287 } 2305 }
2288 } 2306 }
2289 2307
2463 int x, y; 2481 int x, y;
2464 2482
2465 glEnable (GL_TEXTURE_2D); 2483 glEnable (GL_TEXTURE_2D);
2466 /* GL_REPLACE would be correct, as we don't need to modulate alpha, 2484 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2467 * but the nvidia driver (185.18.14) mishandles alpha textures 2485 * but the nvidia driver (185.18.14) mishandles alpha textures
2468 * ansd takes the colour from god knows where instead of using 2486 * and takes the colour from god knows where instead of using
2469 * Cp. MODULATE results in the same colour, but slightly different 2487 * Cp. MODULATE results in the same colour, but slightly different
2470 * alpha, but atcually gives us the correct colour with nvidia. 2488 * alpha, but atcually gives us the correct colour with nvidia.
2471 */ 2489 */
2472 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 2490 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2473 glEnable (GL_BLEND); 2491 glEnable (GL_BLEND);
2502void 2520void
2503fow_texture (DC::Map self, int mx, int my, int sw, int sh) 2521fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2504 PPCODE: 2522 PPCODE:
2505{ 2523{
2506 int x, y; 2524 int x, y;
2507 int sw1 = sw + 2; 2525 int sw1 = sw + 2;
2508 int sh1 = sh + 2; 2526 int sh1 = sh + 2;
2509 int sh3 = sh * 3; 2527 int sh3 = sh * 3;
2510 int sw34 = (sw * 3 + 3) & ~3; 2528 int sw3 = sw * 3;
2511 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); 2529 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
2512 SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); 2530 SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3));
2513 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); 2531 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2514 2532
2515 SvPOK_only (darkness3_sv); 2533 SvPOK_only (darkness3_sv);
2516 SvCUR_set (darkness3_sv, sw34 * sh3); 2534 SvCUR_set (darkness3_sv, sw3 * sh3);
2517 2535
2518 mx += self->x - 1; 2536 mx += self->x - 1;
2519 my += self->y - 1; 2537 my += self->y - 1;
2520
2521 memset (darkness1, DARKNESS_ADJUST (255 - FOW_DARKNESS), sw1 * sh1);
2522 2538
2523 for (y = 0; y < sh1; y++) 2539 for (y = 0; y < sh1; y++)
2524 if (0 <= y + my && y + my < self->rows) 2540 if (0 <= y + my && y + my < self->rows)
2525 { 2541 {
2526 maprow *row = self->row + (y + my); 2542 maprow *row = self->row + (y + my);
2559 2575
2560 uint8_t r13 = (d13 + d23 + d12) / 3; 2576 uint8_t r13 = (d13 + d23 + d12) / 3;
2561 uint8_t r23 = d23; 2577 uint8_t r23 = d23;
2562 uint8_t r33 = (d23 + d33 + d32) / 3; 2578 uint8_t r33 = (d23 + d33 + d32) / 3;
2563 2579
2564 darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); 2580 darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11);
2565 darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); 2581 darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21);
2566 darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); 2582 darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31);
2567 darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); 2583 darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12);
2568 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); 2584 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */
2569 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); 2585 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32);
2570 darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); 2586 darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13);
2571 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); 2587 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23);
2572 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); 2588 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33);
2573 } 2589 }
2574 2590
2575 free (darkness1); 2591 free (darkness1);
2576 2592
2577 EXTEND (SP, 3); 2593 EXTEND (SP, 3);
2578 PUSHs (sv_2mortal (newSViv (sw34))); 2594 PUSHs (sv_2mortal (newSViv (sw3)));
2579 PUSHs (sv_2mortal (newSViv (sh3))); 2595 PUSHs (sv_2mortal (newSViv (sh3)));
2580 PUSHs (darkness3_sv); 2596 PUSHs (darkness3_sv);
2581} 2597}
2582 2598
2583SV * 2599SV *
3297 3313
3298void glEndList () 3314void glEndList ()
3299 3315
3300void glCallList (int list) 3316void glCallList (int list)
3301 3317
3318void c_init ()
3319 CODE:
3320 glPixelStorei (GL_PACK_ALIGNMENT , 1);
3321 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
3322
3302MODULE = Deliantra::Client PACKAGE = DC::UI::Base 3323MODULE = Deliantra::Client PACKAGE = DC::UI::Base
3303 3324
3304PROTOTYPES: DISABLE 3325PROTOTYPES: DISABLE
3305 3326
3306void 3327void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines