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.297 by root, Tue Dec 22 00:08:11 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
95 97
96#define KMOD_LRAM 0x10000 // our extension 98#define KMOD_LRAM 0x10000 // our extension
97 99
98#define TEXID_SPEECH 1 100#define TEXID_SPEECH 1
99#define TEXID_NOFACE 2 101#define TEXID_NOFACE 2
100#define TEXID_HIDDEN 3
101 102
102static AV *texture_av; 103static AV *texture_av;
103 104
104static struct 105static struct
105{ 106{
1665 glDisable (GL_BLEND); 1666 glDisable (GL_BLEND);
1666 } 1667 }
1667} 1668}
1668 1669
1669void 1670void
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) 1671draw_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: @ 1672 PROTOTYPE: @
1672 CODE: 1673 CODE:
1673{ 1674{
1674 glEnable (GL_TEXTURE_2D); 1675 glEnable (GL_TEXTURE_2D);
1675 glEnable (GL_BLEND); 1676 glEnable (GL_BLEND);
1680 glPushMatrix (); 1681 glPushMatrix ();
1681 glScalef (1./3, 1./3, 1.); 1682 glScalef (1./3, 1./3, 1.);
1682 1683
1683 if (blend > 0.f) 1684 if (blend > 0.f)
1684 { 1685 {
1685 float S2, T2; /* 0. 0. for texture 2 */ 1686 float dx3 = dx * -3.f / w;
1686 float w = w1 > w2 ? w1 : w2; 1687 float dy3 = dy * -3.f / h;
1687 float h = h1 > h2 ? h1 : h2;
1688 GLfloat env_color[4] = { 0., 0., 0., blend }; 1688 GLfloat env_color[4] = { 0., 0., 0., blend };
1689 1689
1690 /* interpolate the two shadow textures */ 1690 /* interpolate the two shadow textures */
1691 /* stage 0 == rgb(glcolor) + alpha(t0) */ 1691 /* stage 0 == rgb(glcolor) + alpha(t0) */
1692 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1692 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1713 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); 1713 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1714 1714
1715 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); 1715 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT);
1716 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); 1716 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
1717 1717
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); 1718 glBegin (GL_QUADS);
1730 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy ); glVertex2f ( 0, 0); 1719 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); 1720 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); 1721 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); 1722 gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0);
1734 glEnd (); 1723 glEnd ();
1735 1724
1736 glDisable (GL_TEXTURE_2D); 1725 glDisable (GL_TEXTURE_2D);
1737 gl.ActiveTexture (GL_TEXTURE0); 1726 gl.ActiveTexture (GL_TEXTURE0);
1738 } 1727 }
1740 { 1729 {
1741 /* simple blending of one texture, also opengl <1.3 path */ 1730 /* simple blending of one texture, also opengl <1.3 path */
1742 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1731 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1743 1732
1744 glBegin (GL_QUADS); 1733 glBegin (GL_QUADS);
1745 glTexCoord2f ( 0, 0); glVertex2f ( 0, 0); 1734 glTexCoord2f (0, 0); glVertex2f (0, 0);
1746 glTexCoord2f ( 0, t1); glVertex2f ( 0, h1); 1735 glTexCoord2f (0, t); glVertex2f (0, h);
1747 glTexCoord2f (s1, t1); glVertex2f (w1, h1); 1736 glTexCoord2f (s, t); glVertex2f (w, h);
1748 glTexCoord2f (s1, 0); glVertex2f (w1, 0); 1737 glTexCoord2f (s, 0); glVertex2f (w, 0);
1749 glEnd (); 1738 glEnd ();
1750 } 1739 }
1740
1741 /* draw ?-marks or equivalent, this is very clumsy code :/ */
1742 {
1743 int x, y;
1744 int dx3 = dx * 3;
1745 int dy3 = dy * 3;
1746
1747 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1748 glBindTexture (GL_TEXTURE_2D, hidden_tex);
1749 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1750 glTranslatef (-1., -1., 0);
1751 glBegin (GL_QUADS);
1752
1753 for (y = 1; y < h; y += 3)
1754 {
1755 int y1 = y - dy3;
1756 int y1valid = y1 >= 0 && y1 < h;
1757
1758 for (x = 1; x < w; x += 3)
1759 {
1760 int x1 = x - dx3;
1761 uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1762 uint8_t h2;
1763
1764 if (y1valid && x1 >= 0 && x1 < w)
1765 h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS);
1766 else
1767 h2 = 1; /* out of range == invisible */
1768
1769 if (h1 || h2)
1770 {
1771 float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend;
1772 glColor4f (1., 1., 1., alpha);
1773
1774 glTexCoord2f (0, 0.); glVertex2i (x , y );
1775 glTexCoord2f (0, 1.); glVertex2i (x , y + 3);
1776 glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3);
1777 glTexCoord2f (1, 0.); glVertex2i (x + 3, y );
1778 }
1779 }
1780 }
1781 }
1782
1783 glEnd ();
1751 1784
1752 glPopMatrix (); 1785 glPopMatrix ();
1753 1786
1754 glDisable (GL_TEXTURE_2D); 1787 glDisable (GL_TEXTURE_2D);
1755 glDisable (GL_BLEND); 1788 glDisable (GL_BLEND);
1976 { 2009 {
1977 ext = *data++; 2010 ext = *data++;
1978 cmd = ext & 0x7f; 2011 cmd = ext & 0x7f;
1979 2012
1980 if (cmd < 4) 2013 if (cmd < 4)
1981 cell->darkness = 255 - ext * 64 + 1; 2014 cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */
1982 else if (cmd == 5) // health 2015 else if (cmd == 5) // health
1983 { 2016 {
1984 cell->stat_width = 1; 2017 cell->stat_width = 1;
1985 cell->stat_hp = *data++; 2018 cell->stat_hp = *data++;
1986 } 2019 }
2107 int pl_x, pl_y; 2140 int pl_x, pl_y;
2108 maptex pl_tex; 2141 maptex pl_tex;
2109 rc_t *rc = rc_alloc (); 2142 rc_t *rc = rc_alloc ();
2110 rc_t *rc_ov = rc_alloc (); 2143 rc_t *rc_ov = rc_alloc ();
2111 rc_key_t key; 2144 rc_key_t key;
2112 rc_array_t *arr, *arr_hidden; 2145 rc_array_t *arr;
2113 2146
2114 pl_tex.name = 0; 2147 pl_tex.name = 0;
2115 2148
2116 // that's current max. sorry. 2149 // that's current max. sorry.
2117 if (sw > 255) sw = 255; 2150 if (sw > 255) sw = 255;
2154 } 2187 }
2155 2188
2156 glEnable (GL_BLEND); 2189 glEnable (GL_BLEND);
2157 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2190 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2158 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2191 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2159
2160 key.texname = self->tex [TEXID_HIDDEN].name;
2161 arr_hidden = rc_array (rc_ov, &key);
2162 2192
2163 for (z = 0; z <= 2; z++) 2193 for (z = 0; z <= 2; z++)
2164 { 2194 {
2165 memset (smooth_level, 0, sizeof (smooth_level)); 2195 memset (smooth_level, 0, sizeof (smooth_level));
2166 key.texname = -1; 2196 key.texname = -1;
2246 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2276 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); 2277 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800);
2248 } 2278 }
2249 } 2279 }
2250 2280
2251 if (expect_false (z == 2)) 2281 if (expect_false (z == 2) && expect_false (cell->flags))
2252 { 2282 {
2253 /* draw question marks on top of hidden spaces */ 2283 // overlays such as the speech bubble, probably more to come
2254 if (!cell->darkness) 2284 if (cell->flags & 1)
2255 { 2285 {
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; 2286 rc_key_t key_ov = key;
2272 maptex tex = self->tex [TEXID_SPEECH]; 2287 maptex tex = self->tex [TEXID_SPEECH];
2273 rc_array_t *arr; 2288 rc_array_t *arr;
2274 int px = x * T + T * 2 / 32; 2289 int px = x * T + T * 2 / 32;
2275 int py = y * T - T * 6 / 32; 2290 int py = y * T - T * 6 / 32;
2276 2291
2277 key_ov.texname = tex.name; 2292 key_ov.texname = tex.name;
2278 arr = rc_array (rc_ov, &key_ov); 2293 arr = rc_array (rc_ov, &key_ov);
2279 2294
2280 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2295 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2281 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); 2296 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); 2297 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); 2298 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2284 }
2285 } 2299 }
2286 } 2300 }
2287 } 2301 }
2288 } 2302 }
2289 2303
2463 int x, y; 2477 int x, y;
2464 2478
2465 glEnable (GL_TEXTURE_2D); 2479 glEnable (GL_TEXTURE_2D);
2466 /* GL_REPLACE would be correct, as we don't need to modulate alpha, 2480 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2467 * but the nvidia driver (185.18.14) mishandles alpha textures 2481 * but the nvidia driver (185.18.14) mishandles alpha textures
2468 * ansd takes the colour from god knows where instead of using 2482 * and takes the colour from god knows where instead of using
2469 * Cp. MODULATE results in the same colour, but slightly different 2483 * Cp. MODULATE results in the same colour, but slightly different
2470 * alpha, but atcually gives us the correct colour with nvidia. 2484 * alpha, but atcually gives us the correct colour with nvidia.
2471 */ 2485 */
2472 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 2486 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2473 glEnable (GL_BLEND); 2487 glEnable (GL_BLEND);
2502void 2516void
2503fow_texture (DC::Map self, int mx, int my, int sw, int sh) 2517fow_texture (DC::Map self, int mx, int my, int sw, int sh)
2504 PPCODE: 2518 PPCODE:
2505{ 2519{
2506 int x, y; 2520 int x, y;
2507 int sw1 = sw + 2; 2521 int sw1 = sw + 2;
2508 int sh1 = sh + 2; 2522 int sh1 = sh + 2;
2509 int sh3 = sh * 3; 2523 int sh3 = sh * 3;
2510 int sw34 = (sw * 3 + 3) & ~3; 2524 int sw3 = sw * 3;
2511 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); 2525 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
2512 SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); 2526 SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3));
2513 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); 2527 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2514 2528
2515 SvPOK_only (darkness3_sv); 2529 SvPOK_only (darkness3_sv);
2516 SvCUR_set (darkness3_sv, sw34 * sh3); 2530 SvCUR_set (darkness3_sv, sw3 * sh3);
2517 2531
2518 mx += self->x - 1; 2532 mx += self->x - 1;
2519 my += self->y - 1; 2533 my += self->y - 1;
2520
2521 memset (darkness1, DARKNESS_ADJUST (255 - FOW_DARKNESS), sw1 * sh1);
2522 2534
2523 for (y = 0; y < sh1; y++) 2535 for (y = 0; y < sh1; y++)
2524 if (0 <= y + my && y + my < self->rows) 2536 if (0 <= y + my && y + my < self->rows)
2525 { 2537 {
2526 maprow *row = self->row + (y + my); 2538 maprow *row = self->row + (y + my);
2559 2571
2560 uint8_t r13 = (d13 + d23 + d12) / 3; 2572 uint8_t r13 = (d13 + d23 + d12) / 3;
2561 uint8_t r23 = d23; 2573 uint8_t r23 = d23;
2562 uint8_t r33 = (d23 + d33 + d32) / 3; 2574 uint8_t r33 = (d23 + d33 + d32) / 3;
2563 2575
2564 darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); 2576 darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11);
2565 darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); 2577 darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21);
2566 darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); 2578 darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31);
2567 darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); 2579 darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12);
2568 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); 2580 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); 2581 darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32);
2570 darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); 2582 darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13);
2571 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); 2583 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23);
2572 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); 2584 darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33);
2573 } 2585 }
2574 2586
2575 free (darkness1); 2587 free (darkness1);
2576 2588
2577 EXTEND (SP, 3); 2589 EXTEND (SP, 3);
2578 PUSHs (sv_2mortal (newSViv (sw34))); 2590 PUSHs (sv_2mortal (newSViv (sw3)));
2579 PUSHs (sv_2mortal (newSViv (sh3))); 2591 PUSHs (sv_2mortal (newSViv (sh3)));
2580 PUSHs (darkness3_sv); 2592 PUSHs (darkness3_sv);
2581} 2593}
2582 2594
2583SV * 2595SV *
3297 3309
3298void glEndList () 3310void glEndList ()
3299 3311
3300void glCallList (int list) 3312void glCallList (int list)
3301 3313
3314void c_init ()
3315 CODE:
3316 glPixelStorei (GL_PACK_ALIGNMENT , 1);
3317 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
3318
3302MODULE = Deliantra::Client PACKAGE = DC::UI::Base 3319MODULE = Deliantra::Client PACKAGE = DC::UI::Base
3303 3320
3304PROTOTYPES: DISABLE 3321PROTOTYPES: DISABLE
3305 3322
3306void 3323void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines