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.284 by elmex, Thu Dec 11 00:17:47 2008 UTC vs.
Revision 1.292 by root, Fri Dec 4 15:04:56 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 16 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{
2005 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2009 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) 2010 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
2007 smooth_key skey; 2011 smooth_key skey;
2008 int pl_x, pl_y; 2012 int pl_x, pl_y;
2009 maptex pl_tex; 2013 maptex pl_tex;
2010 rc_t *rc = rc_alloc (); 2014 rc_t *rc = rc_alloc ();
2015 rc_t *rc_ov = rc_alloc ();
2011 rc_key_t key; 2016 rc_key_t key;
2012 rc_array_t *arr; 2017 rc_array_t *arr, *arr_hidden;
2013 2018
2014 pl_tex.name = 0; 2019 pl_tex.name = 0;
2015 2020
2016 // thats current max. sorry. 2021 // that's current max. sorry.
2017 if (sw > 255) sw = 255; 2022 if (sw > 255) sw = 255;
2018 if (sh > 255) sh = 255; 2023 if (sh > 255) sh = 255;
2019 2024
2020 // clear key, in case of extra padding 2025 // clear key, in case of extra padding
2021 memset (&skey, 0, sizeof (skey)); 2026 memset (&skey, 0, sizeof (skey));
2054 } 2059 }
2055 2060
2056 glEnable (GL_BLEND); 2061 glEnable (GL_BLEND);
2057 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2062 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2058 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2063 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2064
2065 key.texname = self->tex [TEXID_HIDDEN].name;
2066 arr_hidden = rc_array (rc_ov, &key);
2059 2067
2060 for (z = 0; z <= 2; z++) 2068 for (z = 0; z <= 2; z++)
2061 { 2069 {
2062 memset (smooth_level, 0, sizeof (smooth_level)); 2070 memset (smooth_level, 0, sizeof (smooth_level));
2063 key.texname = -1; 2071 key.texname = -1;
2074 tileid tile = cell->tile [z]; 2082 tileid tile = cell->tile [z];
2075 2083
2076 if (tile) 2084 if (tile)
2077 { 2085 {
2078 maptex tex = self->tex [tile]; 2086 maptex tex = self->tex [tile];
2079 int px = (x + 1) * T - tex.w; 2087 int px, py;
2080 int py = (y + 1) * T - tex.h;
2081 2088
2082 if (key.texname != tex.name) 2089 if (key.texname != tex.name)
2083 { 2090 {
2084 self->tex [tile].unused = 0; 2091 self->tex [tile].unused = 0;
2085 2092
2086 if (!tex.name) 2093 if (!tex.name)
2087 tex = self->tex [2]; /* missing, replace by noface */ 2094 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2088 2095
2089 key.texname = tex.name; 2096 key.texname = tex.name;
2090 arr = rc_array (rc, &key); 2097 arr = rc_array (rc, &key);
2091 } 2098 }
2099
2100 px = (x + 1) * T - tex.w;
2101 py = (y + 1) * T - tex.h;
2092 2102
2093 if (expect_false (cell->player == player) && expect_false (z == 2)) 2103 if (expect_false (cell->player == player) && expect_false (z == 2))
2094 { 2104 {
2095 pl_x = px; 2105 pl_x = px;
2096 pl_y = py; 2106 pl_y = py;
2101 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2111 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2102 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2112 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); 2113 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); 2114 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2105 2115
2106 if (expect_false (cell->flags) && expect_false (z == 2))
2107 {
2108 /* this is a workaround to make speech bubbles drawn
2109 * for example above walls, work. */
2110 rc_draw (rc);
2111 rc_clear (rc);
2112 key.texname = -1;
2113
2114 // overlays such as the speech bubble, probably more to come
2115 if (cell->flags & 1)
2116 {
2117 maptex tex = self->tex [1];
2118 int px = x * T + T * 2 / 32;
2119 int py = y * T - T * 6 / 32;
2120
2121 if (tex.name)
2122 {
2123 if (key.texname != tex.name)
2124 {
2125 key.texname = tex.name;
2126 arr = rc_array (rc, &key);
2127 }
2128
2129 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2130 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2131 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2132 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2133 }
2134 }
2135 }
2136
2137 // update smooth hash 2116 // update smooth hash
2138 if (tex.smoothtile) 2117 if (tex.smoothtile)
2139 { 2118 {
2140 skey.tile = tex.smoothtile; 2119 skey.tile = tex.smoothtile;
2141 skey.level = tex.smoothlevel; 2120 skey.level = tex.smoothlevel;
2169 // corners 2148 // corners
2170 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2149 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100);
2171 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2150 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200);
2172 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2151 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400);
2173 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2152 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800);
2153 }
2154 }
2155
2156 if (expect_false (z == 2))
2157 {
2158 /* draw question marks on top of hidden spaces */
2159 if (!cell->darkness)
2160 {
2161 maptex tex = self->tex [TEXID_HIDDEN];
2162 int px = (x + 1) * T - tex.w;
2163 int py = (y + 1) * T - tex.h;
2164
2165 rc_t2f_v3f (arr_hidden, 0 , 0 , px , py , 0);
2166 rc_t2f_v3f (arr_hidden, 0 , tex.t, px , py + tex.h, 0);
2167 rc_t2f_v3f (arr_hidden, tex.s, tex.t, px + tex.w, py + tex.h, 0);
2168 rc_t2f_v3f (arr_hidden, tex.s, 0 , px + tex.w, py , 0);
2169 }
2170
2171 if (expect_false (cell->flags))
2172 {
2173 // overlays such as the speech bubble, probably more to come
2174 if (cell->flags & 1)
2175 {
2176 rc_key_t key_ov = key;
2177 maptex tex = self->tex [TEXID_SPEECH];
2178 rc_array_t *arr;
2179 int px = x * T + T * 2 / 32;
2180 int py = y * T - T * 6 / 32;
2181
2182 key_ov.texname = tex.name;
2183 arr = rc_array (rc_ov, &key_ov);
2184
2185 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2186 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2187 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2188 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2189 }
2174 } 2190 }
2175 } 2191 }
2176 } 2192 }
2177 } 2193 }
2178 2194
2275 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2291 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
2276 2292
2277 rc_draw (rc); 2293 rc_draw (rc);
2278 } 2294 }
2279 2295
2296 rc_draw (rc_ov);
2297 rc_clear (rc_ov);
2298
2280 glDisable (GL_BLEND); 2299 glDisable (GL_BLEND);
2281 rc_free (rc); 2300 rc_free (rc);
2301 rc_free (rc_ov);
2282 2302
2283 // top layer: overlays such as the health bar 2303 // top layer: overlays such as the health bar
2284 for (y = 0; y < sh; y++) 2304 for (y = 0; y < sh; y++)
2285 if (0 <= y + my && y + my < self->rows) 2305 if (0 <= y + my && y + my < self->rows)
2286 { 2306 {
2346 }; 2366 };
2347 2367
2348 int x, y; 2368 int x, y;
2349 2369
2350 glEnable (GL_TEXTURE_2D); 2370 glEnable (GL_TEXTURE_2D);
2371 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2372 * but the nvidia driver (185.18.14) mishandles alpha textures
2373 * ansd takes the colour from god knows where instead of using
2374 * Cp. MODULATE results in the same colour, but slightly different
2375 * alpha, but atcually gives us the correct colour with nvidia.
2376 */
2351 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2377 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2352 glEnable (GL_BLEND); 2378 glEnable (GL_BLEND);
2353 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2379 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2354 glBegin (GL_QUADS); 2380 glBegin (GL_QUADS);
2355 2381
2356 for (y = 0; y < h; y++) 2382 for (y = 0; y < h; y++)
2363 float *c = color [m & 15]; 2389 float *c = color [m & 15];
2364 2390
2365 float tx1 = m & 0x40 ? 0.5 : 0.; 2391 float tx1 = m & 0x40 ? 0.5 : 0.;
2366 float tx2 = tx1 + 0.5; 2392 float tx2 = tx1 + 0.5;
2367 2393
2368 glColor4f (c[0], c[1], c[2], 0.75); 2394 glColor4f (c[0], c[1], c[2], 1);
2369 glTexCoord2f (tx1, 0.); glVertex2i (x , y ); 2395 glTexCoord2f (tx1, 0.); glVertex2i (x , y );
2370 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); 2396 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1);
2371 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); 2397 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1);
2372 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); 2398 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y );
2373 } 2399 }
2930 const_iv (GL_NICEST), 2956 const_iv (GL_NICEST),
2931 const_iv (GL_V2F), 2957 const_iv (GL_V2F),
2932 const_iv (GL_V3F), 2958 const_iv (GL_V3F),
2933 const_iv (GL_T2F_V3F), 2959 const_iv (GL_T2F_V3F),
2934 const_iv (GL_T2F_N3F_V3F), 2960 const_iv (GL_T2F_N3F_V3F),
2961 const_iv (GL_FUNC_ADD),
2962 const_iv (GL_FUNC_SUBTRACT),
2963 const_iv (GL_FUNC_REVERSE_SUBTRACT),
2935# undef const_iv 2964# undef const_iv
2936 }; 2965 };
2937 2966
2938 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 2967 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
2939 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 2968 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
2946disable_GL_EXT_blend_func_separate () 2975disable_GL_EXT_blend_func_separate ()
2947 CODE: 2976 CODE:
2948 gl.BlendFuncSeparate = 0; 2977 gl.BlendFuncSeparate = 0;
2949 gl.BlendFuncSeparateEXT = 0; 2978 gl.BlendFuncSeparateEXT = 0;
2950 2979
2980void
2981apple_nvidia_bug (int enable)
2982
2951char * 2983char *
2952gl_vendor () 2984gl_vendor ()
2953 CODE: 2985 CODE:
2954 RETVAL = (char *)glGetString (GL_VENDOR); 2986 RETVAL = (char *)glGetString (GL_VENDOR);
2955 OUTPUT: 2987 OUTPUT:
3003void glBlendFunc (int sfactor, int dfactor) 3035void glBlendFunc (int sfactor, int dfactor)
3004 3036
3005void glBlendFuncSeparate (int sa, int da, int saa, int daa) 3037void glBlendFuncSeparate (int sa, int da, int saa, int daa)
3006 CODE: 3038 CODE:
3007 gl_BlendFuncSeparate (sa, da, saa, daa); 3039 gl_BlendFuncSeparate (sa, da, saa, daa);
3040
3041# void glBlendEquation (int se)
3008 3042
3009void glDepthMask (int flag) 3043void glDepthMask (int flag)
3010 3044
3011void glLogicOp (int opcode) 3045void glLogicOp (int opcode)
3012 3046

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines