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.280 by root, Wed Nov 26 23:08:34 2008 UTC vs.
Revision 1.293 by root, Thu Dec 17 02:49:38 2009 UTC

81#define expect_false(expr) expect ((expr) != 0, 0) 81#define expect_false(expr) expect ((expr) != 0, 0)
82#define expect_true(expr) expect ((expr) != 0, 1) 82#define expect_true(expr) expect ((expr) != 0, 1)
83 83
84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
85 85
86#define FOW_DARKNESS 32 86#define FOW_DARKNESS 64
87 87
88#define MAP_EXTEND_X 32 88#define MAP_EXTEND_X 32
89#define MAP_EXTEND_Y 512 89#define MAP_EXTEND_Y 512
90 90
91#define MIN_FONT_HEIGHT 10 91#define MIN_FONT_HEIGHT 10
92 92
93/* mask out modifiers we are not interested in */ 93/* mask out modifiers we are not interested in */
94#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) 94#define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META)
95 95
96#define KMOD_LRAM 0x10000 // our extension 96#define KMOD_LRAM 0x10000 // our extension
97
98#define TEXID_SPEECH 1
99#define TEXID_NOFACE 2
100#define TEXID_HIDDEN 3
97 101
98static AV *texture_av; 102static AV *texture_av;
99 103
100static struct 104static struct
101{ 105{
1654 glDisable (GL_ALPHA_TEST); 1658 glDisable (GL_ALPHA_TEST);
1655 glDisable (GL_BLEND); 1659 glDisable (GL_BLEND);
1656 } 1660 }
1657} 1661}
1658 1662
1663void
1664draw_fow_texture (float intensity, int name1, float s1, float t1, float w1, float h1)
1665 PROTOTYPE: @
1666 CODE:
1667{
1668 glEnable (GL_TEXTURE_2D);
1669 glEnable (GL_BLEND);
1670 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1671 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1672
1673 glColor4f (intensity, intensity, intensity, 0.9);
1674 glPushMatrix ();
1675 glScalef (1./3, 1./3, 1.);
1676
1677 glBindTexture (GL_TEXTURE_2D, name1);
1678
1679 glBegin (GL_QUADS);
1680 glTexCoord2f ( 0, 0); glVertex2f ( 0, 0);
1681 glTexCoord2f ( 0, t1); glVertex2f ( 0, h1);
1682 glTexCoord2f (s1, t1); glVertex2f (w1, h1);
1683 glTexCoord2f (s1, 0); glVertex2f (w1, 0);
1684 glEnd ();
1685
1686 glPopMatrix ();
1687
1688 glDisable (GL_TEXTURE_2D);
1689 glDisable (GL_BLEND);
1690}
1691
1659IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) 1692IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type)
1660 CODE: 1693 CODE:
1661{ 1694{
1662 GLint width; 1695 GLint width;
1663 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); 1696 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0);
1780 if (tex->name) 1813 if (tex->name)
1781 { 1814 {
1782 if (tex->unused) 1815 if (tex->unused)
1783 { 1816 {
1784 tex->name = 0; 1817 tex->name = 0;
1785 tex->unused = 0, 1818 tex->unused = 0;
1786 XPUSHs (sv_2mortal (newSViv (texid))); 1819 XPUSHs (sv_2mortal (newSViv (texid)));
1787 } 1820 }
1788 else 1821 else
1789 tex->unused = 1; 1822 tex->unused = 1;
1790 } 1823 }
2005 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2038 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2006 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2039 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
2007 smooth_key skey; 2040 smooth_key skey;
2008 int pl_x, pl_y; 2041 int pl_x, pl_y;
2009 maptex pl_tex; 2042 maptex pl_tex;
2010 rc_t *rc = rc_alloc (); 2043 rc_t *rc = rc_alloc ();
2044 rc_t *rc_ov = rc_alloc ();
2011 rc_key_t key; 2045 rc_key_t key;
2012 rc_array_t *arr; 2046 rc_array_t *arr, *arr_hidden;
2013 2047
2014 pl_tex.name = 0; 2048 pl_tex.name = 0;
2015 2049
2016 // thats current max. sorry. 2050 // that's current max. sorry.
2017 if (sw > 255) sw = 255; 2051 if (sw > 255) sw = 255;
2018 if (sh > 255) sh = 255; 2052 if (sh > 255) sh = 255;
2019 2053
2020 // clear key, in case of extra padding 2054 // clear key, in case of extra padding
2021 memset (&skey, 0, sizeof (skey)); 2055 memset (&skey, 0, sizeof (skey));
2025 key.g = 255; 2059 key.g = 255;
2026 key.b = 255; 2060 key.b = 255;
2027 key.a = 255; 2061 key.a = 255;
2028 key.mode = GL_QUADS; 2062 key.mode = GL_QUADS;
2029 key.format = GL_T2F_V3F; 2063 key.format = GL_T2F_V3F;
2030 key.texname = -1;
2031 2064
2032 mx += self->x; 2065 mx += self->x;
2033 my += self->y; 2066 my += self->y;
2034 2067
2035 // first pass: determine smooth_max 2068 // first pass: determine smooth_max
2056 2089
2057 glEnable (GL_BLEND); 2090 glEnable (GL_BLEND);
2058 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2091 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2059 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2092 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2060 2093
2094 key.texname = self->tex [TEXID_HIDDEN].name;
2095 arr_hidden = rc_array (rc_ov, &key);
2096
2061 for (z = 0; z <= 2; z++) 2097 for (z = 0; z <= 2; z++)
2062 { 2098 {
2063 memset (smooth_level, 0, sizeof (smooth_level)); 2099 memset (smooth_level, 0, sizeof (smooth_level));
2100 key.texname = -1;
2064 2101
2065 for (y = 0; y < sh; y++) 2102 for (y = 0; y < sh; y++)
2066 if (0 <= y + my && y + my < self->rows) 2103 if (0 <= y + my && y + my < self->rows)
2067 { 2104 {
2068 maprow *row = self->row + (y + my); 2105 maprow *row = self->row + (y + my);
2074 tileid tile = cell->tile [z]; 2111 tileid tile = cell->tile [z];
2075 2112
2076 if (tile) 2113 if (tile)
2077 { 2114 {
2078 maptex tex = self->tex [tile]; 2115 maptex tex = self->tex [tile];
2079 int px = (x + 1) * T - tex.w; 2116 int px, py;
2080 int py = (y + 1) * T - tex.h;
2081 2117
2082 if (key.texname != tex.name) 2118 if (key.texname != tex.name)
2083 { 2119 {
2084 self->tex [tile].unused = 0; 2120 self->tex [tile].unused = 0;
2085 2121
2086 if (!tex.name) 2122 if (!tex.name)
2087 tex = self->tex [2]; /* missing, replace by noface */ 2123 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2088 2124
2089 key.texname = tex.name; 2125 key.texname = tex.name;
2090 arr = rc_array (rc, &key); 2126 arr = rc_array (rc, &key);
2091 } 2127 }
2128
2129 px = (x + 1) * T - tex.w;
2130 py = (y + 1) * T - tex.h;
2092 2131
2093 if (expect_false (cell->player == player) && expect_false (z == 2)) 2132 if (expect_false (cell->player == player) && expect_false (z == 2))
2094 { 2133 {
2095 pl_x = px; 2134 pl_x = px;
2096 pl_y = py; 2135 pl_y = py;
2101 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2140 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2102 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2141 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
2103 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2142 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2104 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2143 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2105 2144
2106 if (expect_false (cell->flags) && expect_false (z == 2))
2107 {
2108 // overlays such as the speech bubble, probably more to come
2109 if (cell->flags & 1)
2110 {
2111 maptex tex = self->tex [1];
2112 int px = x * T + T * 2 / 32;
2113 int py = y * T - T * 6 / 32;
2114
2115 if (tex.name)
2116 {
2117 if (key.texname != tex.name)
2118 {
2119 key.texname = tex.name;
2120 arr = rc_array (rc, &key);
2121 }
2122
2123 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2124 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2125 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2126 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2127 }
2128 }
2129 }
2130
2131 // update smooth hash 2145 // update smooth hash
2132 if (tex.smoothtile) 2146 if (tex.smoothtile)
2133 { 2147 {
2134 skey.tile = tex.smoothtile; 2148 skey.tile = tex.smoothtile;
2135 skey.level = tex.smoothlevel; 2149 skey.level = tex.smoothlevel;
2163 // corners 2177 // corners
2164 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2178 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100);
2165 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2179 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200);
2166 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2180 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400);
2167 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2181 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800);
2182 }
2183 }
2184
2185 if (expect_false (z == 2))
2186 {
2187 /* draw question marks on top of hidden spaces */
2188 if (!cell->darkness)
2189 {
2190 maptex tex = self->tex [TEXID_HIDDEN];
2191 int px = (x + 1) * T - tex.w;
2192 int py = (y + 1) * T - tex.h;
2193
2194 rc_t2f_v3f (arr_hidden, 0 , 0 , px , py , 0);
2195 rc_t2f_v3f (arr_hidden, 0 , tex.t, px , py + tex.h, 0);
2196 rc_t2f_v3f (arr_hidden, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2197 rc_t2f_v3f (arr_hidden, tex.s, 0 , px + tex.w, py , 0);
2198 }
2199
2200 if (expect_false (cell->flags))
2201 {
2202 // overlays such as the speech bubble, probably more to come
2203 if (cell->flags & 1)
2204 {
2205 rc_key_t key_ov = key;
2206 maptex tex = self->tex [TEXID_SPEECH];
2207 rc_array_t *arr;
2208 int px = x * T + T * 2 / 32;
2209 int py = y * T - T * 6 / 32;
2210
2211 key_ov.texname = tex.name;
2212 arr = rc_array (rc_ov, &key_ov);
2213
2214 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2215 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2216 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2217 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2218 }
2168 } 2219 }
2169 } 2220 }
2170 } 2221 }
2171 } 2222 }
2172 2223
2269 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2320 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2270 2321
2271 rc_draw (rc); 2322 rc_draw (rc);
2272 } 2323 }
2273 2324
2325 rc_draw (rc_ov);
2326 rc_clear (rc_ov);
2327
2274 glDisable (GL_BLEND); 2328 glDisable (GL_BLEND);
2275 rc_free (rc); 2329 rc_free (rc);
2330 rc_free (rc_ov);
2276 2331
2277 // top layer: overlays such as the health bar 2332 // top layer: overlays such as the health bar
2278 for (y = 0; y < sh; y++) 2333 for (y = 0; y < sh; y++)
2279 if (0 <= y + my && y + my < self->rows) 2334 if (0 <= y + my && y + my < self->rows)
2280 { 2335 {
2340 }; 2395 };
2341 2396
2342 int x, y; 2397 int x, y;
2343 2398
2344 glEnable (GL_TEXTURE_2D); 2399 glEnable (GL_TEXTURE_2D);
2400 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2401 * but the nvidia driver (185.18.14) mishandles alpha textures
2402 * ansd takes the colour from god knows where instead of using
2403 * Cp. MODULATE results in the same colour, but slightly different
2404 * alpha, but atcually gives us the correct colour with nvidia.
2405 */
2345 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2406 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2346 glEnable (GL_BLEND); 2407 glEnable (GL_BLEND);
2347 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2408 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2348 glBegin (GL_QUADS); 2409 glBegin (GL_QUADS);
2349 2410
2350 for (y = 0; y < h; y++) 2411 for (y = 0; y < h; y++)
2357 float *c = color [m & 15]; 2418 float *c = color [m & 15];
2358 2419
2359 float tx1 = m & 0x40 ? 0.5 : 0.; 2420 float tx1 = m & 0x40 ? 0.5 : 0.;
2360 float tx2 = tx1 + 0.5; 2421 float tx2 = tx1 + 0.5;
2361 2422
2362 glColor4f (c[0], c[1], c[2], 0.75); 2423 glColor4f (c[0], c[1], c[2], 1);
2363 glTexCoord2f (tx1, 0.); glVertex2i (x , y ); 2424 glTexCoord2f (tx1, 0.); glVertex2i (x , y );
2364 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); 2425 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1);
2365 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); 2426 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1);
2366 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); 2427 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y );
2367 } 2428 }
2826 } *civ, const_iv[] = { 2887 } *civ, const_iv[] = {
2827# define const_iv(name) { # name, (IV)name } 2888# define const_iv(name) { # name, (IV)name }
2828 const_iv (GL_VENDOR), 2889 const_iv (GL_VENDOR),
2829 const_iv (GL_VERSION), 2890 const_iv (GL_VERSION),
2830 const_iv (GL_EXTENSIONS), 2891 const_iv (GL_EXTENSIONS),
2892 const_iv (GL_MAX_TEXTURE_UNITS),
2831 const_iv (GL_COLOR_MATERIAL), 2893 const_iv (GL_COLOR_MATERIAL),
2832 const_iv (GL_SMOOTH), 2894 const_iv (GL_SMOOTH),
2833 const_iv (GL_FLAT), 2895 const_iv (GL_FLAT),
2834 const_iv (GL_DITHER), 2896 const_iv (GL_DITHER),
2835 const_iv (GL_BLEND), 2897 const_iv (GL_BLEND),
2847 const_iv (GL_ZERO), 2909 const_iv (GL_ZERO),
2848 const_iv (GL_SRC_ALPHA), 2910 const_iv (GL_SRC_ALPHA),
2849 const_iv (GL_DST_ALPHA), 2911 const_iv (GL_DST_ALPHA),
2850 const_iv (GL_ONE_MINUS_SRC_ALPHA), 2912 const_iv (GL_ONE_MINUS_SRC_ALPHA),
2851 const_iv (GL_ONE_MINUS_DST_ALPHA), 2913 const_iv (GL_ONE_MINUS_DST_ALPHA),
2914 const_iv (GL_SRC_COLOR),
2915 const_iv (GL_DST_COLOR),
2916 const_iv (GL_ONE_MINUS_SRC_COLOR),
2917 const_iv (GL_ONE_MINUS_DST_COLOR),
2852 const_iv (GL_SRC_ALPHA_SATURATE), 2918 const_iv (GL_SRC_ALPHA_SATURATE),
2853 const_iv (GL_RGB), 2919 const_iv (GL_RGB),
2854 const_iv (GL_RGBA), 2920 const_iv (GL_RGBA),
2855 const_iv (GL_RGBA4), 2921 const_iv (GL_RGBA4),
2856 const_iv (GL_RGBA8), 2922 const_iv (GL_RGBA8),
2924 const_iv (GL_NICEST), 2990 const_iv (GL_NICEST),
2925 const_iv (GL_V2F), 2991 const_iv (GL_V2F),
2926 const_iv (GL_V3F), 2992 const_iv (GL_V3F),
2927 const_iv (GL_T2F_V3F), 2993 const_iv (GL_T2F_V3F),
2928 const_iv (GL_T2F_N3F_V3F), 2994 const_iv (GL_T2F_N3F_V3F),
2995 const_iv (GL_FUNC_ADD),
2996 const_iv (GL_FUNC_SUBTRACT),
2997 const_iv (GL_FUNC_REVERSE_SUBTRACT),
2929# undef const_iv 2998# undef const_iv
2930 }; 2999 };
2931 3000
2932 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 3001 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
2933 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 3002 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
2940disable_GL_EXT_blend_func_separate () 3009disable_GL_EXT_blend_func_separate ()
2941 CODE: 3010 CODE:
2942 gl.BlendFuncSeparate = 0; 3011 gl.BlendFuncSeparate = 0;
2943 gl.BlendFuncSeparateEXT = 0; 3012 gl.BlendFuncSeparateEXT = 0;
2944 3013
3014void
3015apple_nvidia_bug (int enable)
3016
2945char * 3017char *
2946gl_vendor () 3018gl_vendor ()
2947 CODE: 3019 CODE:
2948 RETVAL = (char *)glGetString (GL_VENDOR); 3020 RETVAL = (char *)glGetString (GL_VENDOR);
2949 OUTPUT: 3021 OUTPUT:
2997void glBlendFunc (int sfactor, int dfactor) 3069void glBlendFunc (int sfactor, int dfactor)
2998 3070
2999void glBlendFuncSeparate (int sa, int da, int saa, int daa) 3071void glBlendFuncSeparate (int sa, int da, int saa, int daa)
3000 CODE: 3072 CODE:
3001 gl_BlendFuncSeparate (sa, da, saa, daa); 3073 gl_BlendFuncSeparate (sa, da, saa, daa);
3074
3075# void glBlendEquation (int se)
3002 3076
3003void glDepthMask (int flag) 3077void glDepthMask (int flag)
3004 3078
3005void glLogicOp (int opcode) 3079void glLogicOp (int opcode)
3006 3080

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines