… | |
… | |
99 | |
99 | |
100 | #define KMOD_LRAM 0x10000 // our extension |
100 | #define KMOD_LRAM 0x10000 // our extension |
101 | |
101 | |
102 | #define TEXID_SPEECH 1 |
102 | #define TEXID_SPEECH 1 |
103 | #define TEXID_NOFACE 2 |
103 | #define TEXID_NOFACE 2 |
|
|
104 | |
|
|
105 | static char * |
|
|
106 | fast_sv_grow (SV *sv, STRLEN need) |
|
|
107 | { |
|
|
108 | STRLEN len = SvLEN (sv); |
|
|
109 | STRLEN want = SvCUR (sv) + need; |
|
|
110 | |
|
|
111 | if (expect_false (len < want)) |
|
|
112 | { |
|
|
113 | do |
|
|
114 | len *= 2; |
|
|
115 | while (len < want); |
|
|
116 | |
|
|
117 | sv_grow (sv, len); |
|
|
118 | } |
|
|
119 | |
|
|
120 | SvCUR_set (sv, want); |
|
|
121 | return SvEND (sv) - need; |
|
|
122 | } |
104 | |
123 | |
105 | static AV *texture_av; |
124 | static AV *texture_av; |
106 | |
125 | |
107 | static struct |
126 | static struct |
108 | { |
127 | { |
… | |
… | |
460 | ev.code = 1; |
479 | ev.code = 1; |
461 | ev.data1 = (void *)(long)channel; |
480 | ev.data1 = (void *)(long)channel; |
462 | ev.data2 = 0; |
481 | ev.data2 = 0; |
463 | |
482 | |
464 | SDL_PushEvent ((SDL_Event *)&ev); |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
|
|
484 | } |
|
|
485 | |
|
|
486 | static unsigned int |
|
|
487 | div255 (unsigned int n) |
|
|
488 | { |
|
|
489 | return (n + (n >> 8)) >> 8; |
465 | } |
490 | } |
466 | |
491 | |
467 | static unsigned int |
492 | static unsigned int |
468 | minpot (unsigned int n) |
493 | minpot (unsigned int n) |
469 | { |
494 | { |
… | |
… | |
796 | |
821 | |
797 | const_iv (FOW_DARKNESS) |
822 | const_iv (FOW_DARKNESS) |
798 | # undef const_iv |
823 | # undef const_iv |
799 | }; |
824 | }; |
800 | |
825 | |
801 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
826 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
802 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
827 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
803 | |
828 | |
804 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
829 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
805 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
830 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
806 | } |
831 | } |
807 | |
832 | |
… | |
… | |
2115 | ? self->row + y |
2140 | ? self->row + y |
2116 | : 0; |
2141 | : 0; |
2117 | |
2142 | |
2118 | for (x = x0; x < x1; x++) |
2143 | for (x = x0; x < x1; x++) |
2119 | { |
2144 | { |
2120 | int r = 32, g = 32, b = 32, a = 192; |
2145 | unsigned int r = 32, g = 32, b = 32, a = 192; |
2121 | |
2146 | |
2122 | if (row && row->c0 <= x && x < row->c1) |
2147 | if (row && row->c0 <= x && x < row->c1) |
2123 | { |
2148 | { |
2124 | mapcell *cell = row->col + (x - row->c0); |
2149 | mapcell *cell = row->col + (x - row->c0); |
2125 | |
2150 | |
… | |
… | |
2127 | { |
2152 | { |
2128 | maptex tex = self->tex [cell->tile [z]]; |
2153 | maptex tex = self->tex [cell->tile [z]]; |
2129 | int a0 = 255 - tex.a; |
2154 | int a0 = 255 - tex.a; |
2130 | int a1 = tex.a; |
2155 | int a1 = tex.a; |
2131 | |
2156 | |
2132 | r = (r * a0 + tex.r * a1) / 255; |
2157 | r = div255 (r * a0 + tex.r * a1); |
2133 | g = (g * a0 + tex.g * a1) / 255; |
2158 | g = div255 (g * a0 + tex.g * a1); |
2134 | b = (b * a0 + tex.b * a1) / 255; |
2159 | b = div255 (b * a0 + tex.b * a1); |
2135 | a = (a * a0 + tex.a * a1) / 255; |
2160 | a = div255 (a * a0 + tex.a * a1); |
2136 | } |
2161 | } |
2137 | } |
2162 | } |
2138 | |
2163 | |
2139 | *map++ = (r ) |
2164 | *map++ = (r ) |
2140 | | (g << 8) |
2165 | | (g << 8) |
… | |
… | |
2147 | } |
2172 | } |
2148 | OUTPUT: |
2173 | OUTPUT: |
2149 | RETVAL |
2174 | RETVAL |
2150 | |
2175 | |
2151 | void |
2176 | void |
2152 | draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2177 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2153 | CODE: |
2178 | CODE: |
2154 | { |
2179 | { |
2155 | int x, y, z; |
2180 | int x, y, z; |
2156 | |
2181 | |
2157 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
2182 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
… | |
… | |
2241 | |
2266 | |
2242 | key.texname = tex.name; |
2267 | key.texname = tex.name; |
2243 | arr = rc_array (rc, &key); |
2268 | arr = rc_array (rc, &key); |
2244 | } |
2269 | } |
2245 | |
2270 | |
2246 | px = (x + 1) * T - tex.w; |
2271 | px = (x + 1) * Th - tex.w; |
2247 | py = (y + 1) * T - tex.h; |
2272 | py = (y + 1) * Tw - tex.h; |
2248 | |
2273 | |
2249 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2274 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2250 | { |
2275 | { |
2251 | pl_x = px; |
2276 | pl_x = px; |
2252 | pl_y = py; |
2277 | pl_y = py; |
… | |
… | |
2305 | if (cell->flags & 1) |
2330 | if (cell->flags & 1) |
2306 | { |
2331 | { |
2307 | rc_key_t key_ov = key; |
2332 | rc_key_t key_ov = key; |
2308 | maptex tex = self->tex [TEXID_SPEECH]; |
2333 | maptex tex = self->tex [TEXID_SPEECH]; |
2309 | rc_array_t *arr; |
2334 | rc_array_t *arr; |
2310 | int px = x * T + T * 2 / 32; |
2335 | int px = x * Tw + Tw * 2 / 32; |
2311 | int py = y * T - T * 6 / 32; |
2336 | int py = y * Th - Th * 6 / 32; |
2312 | |
2337 | |
2313 | key_ov.texname = tex.name; |
2338 | key_ov.texname = tex.name; |
2314 | arr = rc_array (rc_ov, &key_ov); |
2339 | arr = rc_array (rc_ov, &key_ov); |
2315 | |
2340 | |
2316 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2341 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2317 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
2342 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
2318 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
2343 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
2319 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
2344 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
2320 | } |
2345 | } |
2321 | } |
2346 | } |
2322 | } |
2347 | } |
2323 | } |
2348 | } |
2324 | |
2349 | |
… | |
… | |
2351 | if (!(bits & 0x1000) |
2376 | if (!(bits & 0x1000) |
2352 | && skey->level == level |
2377 | && skey->level == level |
2353 | && level > smooth_max [skey->x][skey->y]) |
2378 | && level > smooth_max [skey->x][skey->y]) |
2354 | { |
2379 | { |
2355 | maptex tex = self->tex [skey->tile]; |
2380 | maptex tex = self->tex [skey->tile]; |
2356 | int px = (((int)skey->x) - 1) * T; |
2381 | int px = (((int)skey->x) - 1) * Tw; |
2357 | int py = (((int)skey->y) - 1) * T; |
2382 | int py = (((int)skey->y) - 1) * Th; |
2358 | int border = bits & 15; |
2383 | int border = bits & 15; |
2359 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2384 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2360 | float dx = tex.s * .0625f; // 16 images/row |
2385 | float dx = tex.s * .0625f; // 16 images/row |
2361 | float dy = tex.t * .5f ; // 2 images/column |
2386 | float dy = tex.t * .5f ; // 2 images/column |
2362 | |
2387 | |
… | |
… | |
2375 | |
2400 | |
2376 | if (border) |
2401 | if (border) |
2377 | { |
2402 | { |
2378 | float ox = border * dx; |
2403 | float ox = border * dx; |
2379 | |
2404 | |
2380 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2405 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2381 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
2406 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2382 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
2407 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2383 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
2408 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2384 | } |
2409 | } |
2385 | |
2410 | |
2386 | if (corner) |
2411 | if (corner) |
2387 | { |
2412 | { |
2388 | float ox = corner * dx; |
2413 | float ox = corner * dx; |
2389 | |
2414 | |
2390 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2415 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2391 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
2416 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2392 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
2417 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2393 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
2418 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2394 | } |
2419 | } |
2395 | } |
2420 | } |
2396 | } |
2421 | } |
2397 | } |
2422 | } |
2398 | } |
2423 | } |
… | |
… | |
2439 | for (x = 0; x < sw; x++) |
2464 | for (x = 0; x < sw; x++) |
2440 | if (row->c0 <= x + mx && x + mx < row->c1) |
2465 | if (row->c0 <= x + mx && x + mx < row->c1) |
2441 | { |
2466 | { |
2442 | mapcell *cell = row->col + (x + mx - row->c0); |
2467 | mapcell *cell = row->col + (x + mx - row->c0); |
2443 | |
2468 | |
2444 | int px = x * T; |
2469 | int px = x * Tw; |
2445 | int py = y * T; |
2470 | int py = y * Th; |
2446 | |
2471 | |
2447 | if (expect_false (cell->player == player)) |
2472 | if (expect_false (cell->player == player)) |
2448 | { |
2473 | { |
2449 | px += sdx; |
2474 | px += sdx; |
2450 | py += sdy; |
2475 | py += sdy; |
2451 | } |
2476 | } |
2452 | |
2477 | |
2453 | if (cell->stat_hp) |
2478 | if (cell->stat_hp) |
2454 | { |
2479 | { |
2455 | int width = cell->stat_width * T; |
2480 | int width = cell->stat_width * Tw; |
2456 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2481 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
2457 | |
2482 | |
2458 | glColor3ub (0, 0, 0); |
2483 | glColor3ub (0, 0, 0); |
2459 | glRectf (px + 1, py - thick - 2, |
2484 | glRectf (px + 1, py - thick - 2, |
2460 | px + width - 1, py); |
2485 | px + width - 1, py); |
2461 | |
2486 | |
… | |
… | |
2541 | int x, y; |
2566 | int x, y; |
2542 | int sw1 = sw + 2; |
2567 | int sw1 = sw + 2; |
2543 | int sh1 = sh + 2; |
2568 | int sh1 = sh + 2; |
2544 | int sh3 = sh * 3; |
2569 | int sh3 = sh * 3; |
2545 | int sw3 = sw * 3; |
2570 | int sw3 = sw * 3; |
2546 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
|
|
2547 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
2571 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
2548 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
2572 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
2573 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
|
|
2574 | memset (darkness1, 0, sw1*sh1); |
2549 | |
2575 | |
2550 | SvPOK_only (darkness3_sv); |
2576 | SvPOK_only (darkness3_sv); |
2551 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2577 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2552 | |
2578 | |
2553 | mx += self->x - 1; |
2579 | mx += self->x - 1; |
… | |
… | |
3132 | const_iv (GL_FUNC_SUBTRACT), |
3158 | const_iv (GL_FUNC_SUBTRACT), |
3133 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
3159 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
3134 | # undef const_iv |
3160 | # undef const_iv |
3135 | }; |
3161 | }; |
3136 | |
3162 | |
3137 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3163 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
3138 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3164 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
3139 | |
3165 | |
3140 | texture_av = newAV (); |
3166 | texture_av = newAV (); |
3141 | AvREAL_off (texture_av); |
3167 | AvREAL_off (texture_av); |
3142 | } |
3168 | } |
3143 | |
3169 | |