… | |
… | |
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 | |
98 | static AV *texture_av; |
102 | static AV *texture_av; |
99 | |
103 | |
100 | static struct |
104 | static struct |
101 | { |
105 | { |
… | |
… | |
1780 | if (tex->name) |
1784 | if (tex->name) |
1781 | { |
1785 | { |
1782 | if (tex->unused) |
1786 | if (tex->unused) |
1783 | { |
1787 | { |
1784 | tex->name = 0; |
1788 | tex->name = 0; |
1785 | tex->unused = 0, |
1789 | tex->unused = 0; |
1786 | XPUSHs (sv_2mortal (newSViv (texid))); |
1790 | XPUSHs (sv_2mortal (newSViv (texid))); |
1787 | } |
1791 | } |
1788 | else |
1792 | else |
1789 | tex->unused = 1; |
1793 | tex->unused = 1; |
1790 | } |
1794 | } |
… | |
… | |
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)); |
… | |
… | |
2025 | key.g = 255; |
2030 | key.g = 255; |
2026 | key.b = 255; |
2031 | key.b = 255; |
2027 | key.a = 255; |
2032 | key.a = 255; |
2028 | key.mode = GL_QUADS; |
2033 | key.mode = GL_QUADS; |
2029 | key.format = GL_T2F_V3F; |
2034 | key.format = GL_T2F_V3F; |
2030 | key.texname = -1; |
|
|
2031 | |
2035 | |
2032 | mx += self->x; |
2036 | mx += self->x; |
2033 | my += self->y; |
2037 | my += self->y; |
2034 | |
2038 | |
2035 | // first pass: determine smooth_max |
2039 | // first pass: determine smooth_max |
… | |
… | |
2056 | |
2060 | |
2057 | glEnable (GL_BLEND); |
2061 | glEnable (GL_BLEND); |
2058 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2062 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2059 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2063 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2060 | |
2064 | |
|
|
2065 | key.texname = self->tex [TEXID_HIDDEN].name; |
|
|
2066 | arr_hidden = rc_array (rc_ov, &key); |
|
|
2067 | |
2061 | for (z = 0; z <= 2; z++) |
2068 | for (z = 0; z <= 2; z++) |
2062 | { |
2069 | { |
2063 | memset (smooth_level, 0, sizeof (smooth_level)); |
2070 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
2071 | key.texname = -1; |
2064 | |
2072 | |
2065 | for (y = 0; y < sh; y++) |
2073 | for (y = 0; y < sh; y++) |
2066 | if (0 <= y + my && y + my < self->rows) |
2074 | if (0 <= y + my && y + my < self->rows) |
2067 | { |
2075 | { |
2068 | maprow *row = self->row + (y + my); |
2076 | maprow *row = self->row + (y + my); |
… | |
… | |
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 | // 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 |
2116 | // update smooth hash |
2132 | if (tex.smoothtile) |
2117 | if (tex.smoothtile) |
2133 | { |
2118 | { |
2134 | skey.tile = tex.smoothtile; |
2119 | skey.tile = tex.smoothtile; |
2135 | skey.level = tex.smoothlevel; |
2120 | skey.level = tex.smoothlevel; |
… | |
… | |
2163 | // corners |
2148 | // corners |
2164 | 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); |
2165 | 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); |
2166 | 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); |
2167 | 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 | } |
2168 | } |
2190 | } |
2169 | } |
2191 | } |
2170 | } |
2192 | } |
2171 | } |
2193 | } |
2172 | |
2194 | |
… | |
… | |
2269 | 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); |
2270 | |
2292 | |
2271 | rc_draw (rc); |
2293 | rc_draw (rc); |
2272 | } |
2294 | } |
2273 | |
2295 | |
|
|
2296 | rc_draw (rc_ov); |
|
|
2297 | rc_clear (rc_ov); |
|
|
2298 | |
2274 | glDisable (GL_BLEND); |
2299 | glDisable (GL_BLEND); |
2275 | rc_free (rc); |
2300 | rc_free (rc); |
|
|
2301 | rc_free (rc_ov); |
2276 | |
2302 | |
2277 | // top layer: overlays such as the health bar |
2303 | // top layer: overlays such as the health bar |
2278 | for (y = 0; y < sh; y++) |
2304 | for (y = 0; y < sh; y++) |
2279 | if (0 <= y + my && y + my < self->rows) |
2305 | if (0 <= y + my && y + my < self->rows) |
2280 | { |
2306 | { |
… | |
… | |
2340 | }; |
2366 | }; |
2341 | |
2367 | |
2342 | int x, y; |
2368 | int x, y; |
2343 | |
2369 | |
2344 | 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 | */ |
2345 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2377 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
2346 | glEnable (GL_BLEND); |
2378 | glEnable (GL_BLEND); |
2347 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2379 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2348 | glBegin (GL_QUADS); |
2380 | glBegin (GL_QUADS); |
2349 | |
2381 | |
2350 | for (y = 0; y < h; y++) |
2382 | for (y = 0; y < h; y++) |
… | |
… | |
2357 | float *c = color [m & 15]; |
2389 | float *c = color [m & 15]; |
2358 | |
2390 | |
2359 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2391 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2360 | float tx2 = tx1 + 0.5; |
2392 | float tx2 = tx1 + 0.5; |
2361 | |
2393 | |
2362 | glColor4f (c[0], c[1], c[2], 0.75); |
2394 | glColor4f (c[0], c[1], c[2], 1); |
2363 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2395 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2364 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2396 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2365 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2397 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2366 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2398 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2367 | } |
2399 | } |