… | |
… | |
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 | { |
… | |
… | |
463 | |
482 | |
464 | SDL_PushEvent ((SDL_Event *)&ev); |
483 | SDL_PushEvent ((SDL_Event *)&ev); |
465 | } |
484 | } |
466 | |
485 | |
467 | static unsigned int |
486 | static unsigned int |
|
|
487 | div255 (unsigned int n) |
|
|
488 | { |
|
|
489 | return (n + (n >> 8)) >> 8; |
|
|
490 | } |
|
|
491 | |
|
|
492 | static unsigned int |
468 | minpot (unsigned int n) |
493 | minpot (unsigned int n) |
469 | { |
494 | { |
470 | if (!n) |
495 | if (!n) |
471 | return 0; |
496 | return 0; |
472 | |
497 | |
… | |
… | |
555 | |
580 | |
556 | static void |
581 | static void |
557 | deliantra_main () |
582 | deliantra_main () |
558 | { |
583 | { |
559 | char *argv[] = { 0 }; |
584 | char *argv[] = { 0 }; |
560 | call_argv ("::main", G_DISCARD | G_VOID, argv); |
585 | call_argv ("DC::Main::main", G_DISCARD | G_VOID, argv); |
561 | } |
586 | } |
562 | |
587 | |
563 | #ifdef __MACOSX__ |
588 | #ifdef __MACOSX__ |
564 | /* to due surprising braindamage on the side of SDL design, we |
589 | /* to due surprising braindamage on the side of SDL design, we |
565 | * do some mind-boggling hack here: SDL requires a custom main() |
590 | * do some mind-boggling hack here: SDL requires a custom main() |
566 | * on OS X, so... we provide one and call the original main(), which, |
591 | * on OS X, so... we provide one and call the original main(), which, |
567 | * due to share dlibrary magic, calls -lSDLmain's main, not perl's main, |
592 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
568 | * and which calls our main (== SDL_main) back. |
593 | * and which calls our main (== SDL_main) back. |
569 | */ |
594 | */ |
570 | extern C_LINKAGE int |
595 | extern C_LINKAGE int |
571 | main (int argc, char *argv[]) |
596 | main (int argc, char *argv[]) |
572 | { |
597 | { |
… | |
… | |
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 | |
… | |
… | |
950 | SDL_GetAppState () |
975 | SDL_GetAppState () |
951 | |
976 | |
952 | int |
977 | int |
953 | SDL_GetModState () |
978 | SDL_GetModState () |
954 | |
979 | |
|
|
980 | int |
|
|
981 | SDL_WaitEvent () |
|
|
982 | C_ARGS: 0 |
|
|
983 | |
955 | void |
984 | void |
|
|
985 | SDL_PumpEvents () |
|
|
986 | |
|
|
987 | void |
956 | poll_events () |
988 | peep_events () |
957 | PPCODE: |
989 | PPCODE: |
958 | { |
990 | { |
959 | SDL_Event ev; |
991 | SDL_Event ev; |
960 | |
992 | |
961 | SDL_PumpEvents (); |
993 | SDL_PumpEvents (); |
… | |
… | |
1027 | |
1059 | |
1028 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
1060 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
1029 | } |
1061 | } |
1030 | } |
1062 | } |
1031 | |
1063 | |
|
|
1064 | char * |
|
|
1065 | SDL_AudioDriverName () |
|
|
1066 | CODE: |
|
|
1067 | { |
|
|
1068 | char buf [256]; |
|
|
1069 | if (!SDL_AudioDriverName (buf, sizeof (buf))) |
|
|
1070 | XSRETURN_UNDEF; |
|
|
1071 | |
|
|
1072 | RETVAL = buf; |
|
|
1073 | } |
|
|
1074 | OUTPUT: |
|
|
1075 | RETVAL |
|
|
1076 | |
1032 | int |
1077 | int |
1033 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1078 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
1034 | POSTCALL: |
1079 | POSTCALL: |
1035 | Mix_HookMusicFinished (music_finished); |
1080 | Mix_HookMusicFinished (music_finished); |
1036 | Mix_ChannelFinished (channel_finished); |
1081 | Mix_ChannelFinished (channel_finished); |
… | |
… | |
1098 | add_font (char *file) |
1143 | add_font (char *file) |
1099 | CODE: |
1144 | CODE: |
1100 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1145 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1101 | OUTPUT: |
1146 | OUTPUT: |
1102 | RETVAL |
1147 | RETVAL |
|
|
1148 | |
|
|
1149 | void |
|
|
1150 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
|
|
1151 | |
|
|
1152 | void |
|
|
1153 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG) |
1103 | |
1154 | |
1104 | void |
1155 | void |
1105 | load_image_inline (SV *image_) |
1156 | load_image_inline (SV *image_) |
1106 | ALIAS: |
1157 | ALIAS: |
1107 | load_image_file = 1 |
1158 | load_image_file = 1 |
… | |
… | |
2099 | ? self->row + y |
2150 | ? self->row + y |
2100 | : 0; |
2151 | : 0; |
2101 | |
2152 | |
2102 | for (x = x0; x < x1; x++) |
2153 | for (x = x0; x < x1; x++) |
2103 | { |
2154 | { |
2104 | int r = 32, g = 32, b = 32, a = 192; |
2155 | unsigned int r = 32, g = 32, b = 32, a = 192; |
2105 | |
2156 | |
2106 | if (row && row->c0 <= x && x < row->c1) |
2157 | if (row && row->c0 <= x && x < row->c1) |
2107 | { |
2158 | { |
2108 | mapcell *cell = row->col + (x - row->c0); |
2159 | mapcell *cell = row->col + (x - row->c0); |
2109 | |
2160 | |
… | |
… | |
2111 | { |
2162 | { |
2112 | maptex tex = self->tex [cell->tile [z]]; |
2163 | maptex tex = self->tex [cell->tile [z]]; |
2113 | int a0 = 255 - tex.a; |
2164 | int a0 = 255 - tex.a; |
2114 | int a1 = tex.a; |
2165 | int a1 = tex.a; |
2115 | |
2166 | |
2116 | r = (r * a0 + tex.r * a1) / 255; |
2167 | r = div255 (r * a0 + tex.r * a1); |
2117 | g = (g * a0 + tex.g * a1) / 255; |
2168 | g = div255 (g * a0 + tex.g * a1); |
2118 | b = (b * a0 + tex.b * a1) / 255; |
2169 | b = div255 (b * a0 + tex.b * a1); |
2119 | a = (a * a0 + tex.a * a1) / 255; |
2170 | a = div255 (a * a0 + tex.a * a1); |
2120 | } |
2171 | } |
2121 | } |
2172 | } |
2122 | |
2173 | |
2123 | *map++ = (r ) |
2174 | *map++ = (r ) |
2124 | | (g << 8) |
2175 | | (g << 8) |
… | |
… | |
2131 | } |
2182 | } |
2132 | OUTPUT: |
2183 | OUTPUT: |
2133 | RETVAL |
2184 | RETVAL |
2134 | |
2185 | |
2135 | void |
2186 | void |
2136 | draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
2187 | 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) |
2137 | CODE: |
2188 | CODE: |
2138 | { |
2189 | { |
2139 | int x, y, z; |
2190 | int x, y, z; |
2140 | |
2191 | |
2141 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
2192 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
… | |
… | |
2225 | |
2276 | |
2226 | key.texname = tex.name; |
2277 | key.texname = tex.name; |
2227 | arr = rc_array (rc, &key); |
2278 | arr = rc_array (rc, &key); |
2228 | } |
2279 | } |
2229 | |
2280 | |
2230 | px = (x + 1) * T - tex.w; |
2281 | px = (x + 1) * Th - tex.w; |
2231 | py = (y + 1) * T - tex.h; |
2282 | py = (y + 1) * Tw - tex.h; |
2232 | |
2283 | |
2233 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2284 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2234 | { |
2285 | { |
2235 | pl_x = px; |
2286 | pl_x = px; |
2236 | pl_y = py; |
2287 | pl_y = py; |
… | |
… | |
2289 | if (cell->flags & 1) |
2340 | if (cell->flags & 1) |
2290 | { |
2341 | { |
2291 | rc_key_t key_ov = key; |
2342 | rc_key_t key_ov = key; |
2292 | maptex tex = self->tex [TEXID_SPEECH]; |
2343 | maptex tex = self->tex [TEXID_SPEECH]; |
2293 | rc_array_t *arr; |
2344 | rc_array_t *arr; |
2294 | int px = x * T + T * 2 / 32; |
2345 | int px = x * Tw + Tw * 2 / 32; |
2295 | int py = y * T - T * 6 / 32; |
2346 | int py = y * Th - Th * 6 / 32; |
2296 | |
2347 | |
2297 | key_ov.texname = tex.name; |
2348 | key_ov.texname = tex.name; |
2298 | arr = rc_array (rc_ov, &key_ov); |
2349 | arr = rc_array (rc_ov, &key_ov); |
2299 | |
2350 | |
2300 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2351 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2301 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
2352 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
2302 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
2353 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
2303 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
2354 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
2304 | } |
2355 | } |
2305 | } |
2356 | } |
2306 | } |
2357 | } |
2307 | } |
2358 | } |
2308 | |
2359 | |
… | |
… | |
2335 | if (!(bits & 0x1000) |
2386 | if (!(bits & 0x1000) |
2336 | && skey->level == level |
2387 | && skey->level == level |
2337 | && level > smooth_max [skey->x][skey->y]) |
2388 | && level > smooth_max [skey->x][skey->y]) |
2338 | { |
2389 | { |
2339 | maptex tex = self->tex [skey->tile]; |
2390 | maptex tex = self->tex [skey->tile]; |
2340 | int px = (((int)skey->x) - 1) * T; |
2391 | int px = (((int)skey->x) - 1) * Tw; |
2341 | int py = (((int)skey->y) - 1) * T; |
2392 | int py = (((int)skey->y) - 1) * Th; |
2342 | int border = bits & 15; |
2393 | int border = bits & 15; |
2343 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2394 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
2344 | float dx = tex.s * .0625f; // 16 images/row |
2395 | float dx = tex.s * .0625f; // 16 images/row |
2345 | float dy = tex.t * .5f ; // 2 images/column |
2396 | float dy = tex.t * .5f ; // 2 images/column |
2346 | |
2397 | |
… | |
… | |
2359 | |
2410 | |
2360 | if (border) |
2411 | if (border) |
2361 | { |
2412 | { |
2362 | float ox = border * dx; |
2413 | float ox = border * dx; |
2363 | |
2414 | |
2364 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2415 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2365 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
2416 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2366 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
2417 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2367 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
2418 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2368 | } |
2419 | } |
2369 | |
2420 | |
2370 | if (corner) |
2421 | if (corner) |
2371 | { |
2422 | { |
2372 | float ox = corner * dx; |
2423 | float ox = corner * dx; |
2373 | |
2424 | |
2374 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2425 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2375 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
2426 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2376 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
2427 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2377 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
2428 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2378 | } |
2429 | } |
2379 | } |
2430 | } |
2380 | } |
2431 | } |
2381 | } |
2432 | } |
2382 | } |
2433 | } |
… | |
… | |
2423 | for (x = 0; x < sw; x++) |
2474 | for (x = 0; x < sw; x++) |
2424 | if (row->c0 <= x + mx && x + mx < row->c1) |
2475 | if (row->c0 <= x + mx && x + mx < row->c1) |
2425 | { |
2476 | { |
2426 | mapcell *cell = row->col + (x + mx - row->c0); |
2477 | mapcell *cell = row->col + (x + mx - row->c0); |
2427 | |
2478 | |
2428 | int px = x * T; |
2479 | int px = x * Tw; |
2429 | int py = y * T; |
2480 | int py = y * Th; |
2430 | |
2481 | |
2431 | if (expect_false (cell->player == player)) |
2482 | if (expect_false (cell->player == player)) |
2432 | { |
2483 | { |
2433 | px += sdx; |
2484 | px += sdx; |
2434 | py += sdy; |
2485 | py += sdy; |
2435 | } |
2486 | } |
2436 | |
2487 | |
2437 | if (cell->stat_hp) |
2488 | if (cell->stat_hp) |
2438 | { |
2489 | { |
2439 | int width = cell->stat_width * T; |
2490 | int width = cell->stat_width * Tw; |
2440 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2491 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
2441 | |
2492 | |
2442 | glColor3ub (0, 0, 0); |
2493 | glColor3ub (0, 0, 0); |
2443 | glRectf (px + 1, py - thick - 2, |
2494 | glRectf (px + 1, py - thick - 2, |
2444 | px + width - 1, py); |
2495 | px + width - 1, py); |
2445 | |
2496 | |
… | |
… | |
2525 | int x, y; |
2576 | int x, y; |
2526 | int sw1 = sw + 2; |
2577 | int sw1 = sw + 2; |
2527 | int sh1 = sh + 2; |
2578 | int sh1 = sh + 2; |
2528 | int sh3 = sh * 3; |
2579 | int sh3 = sh * 3; |
2529 | int sw3 = sw * 3; |
2580 | int sw3 = sw * 3; |
2530 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
|
|
2531 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
2581 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
2532 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
2582 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
2583 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
|
|
2584 | memset (darkness1, 0, sw1*sh1); |
2533 | |
2585 | |
2534 | SvPOK_only (darkness3_sv); |
2586 | SvPOK_only (darkness3_sv); |
2535 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2587 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2536 | |
2588 | |
2537 | mx += self->x - 1; |
2589 | mx += self->x - 1; |
… | |
… | |
2798 | if (RETVAL < 0) |
2850 | if (RETVAL < 0) |
2799 | { |
2851 | { |
2800 | RETVAL = Mix_GroupOldest (-1); |
2852 | RETVAL = Mix_GroupOldest (-1); |
2801 | |
2853 | |
2802 | if (RETVAL < 0) |
2854 | if (RETVAL < 0) |
|
|
2855 | { |
|
|
2856 | // happens sometimes, maybe it just stopped playing(?) |
|
|
2857 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2858 | |
|
|
2859 | if (RETVAL < 0) |
2803 | XSRETURN_UNDEF; |
2860 | XSRETURN_UNDEF; |
2804 | |
2861 | } |
|
|
2862 | else |
2805 | Mix_HaltChannel (RETVAL); |
2863 | Mix_HaltChannel (RETVAL); |
2806 | } |
2864 | } |
2807 | |
2865 | |
2808 | Mix_UnregisterAllEffects (RETVAL); |
2866 | Mix_UnregisterAllEffects (RETVAL); |
2809 | Mix_Volume (RETVAL, 128); |
2867 | Mix_Volume (RETVAL, 128); |
2810 | } |
2868 | } |
… | |
… | |
3110 | const_iv (GL_FUNC_SUBTRACT), |
3168 | const_iv (GL_FUNC_SUBTRACT), |
3111 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
3169 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
3112 | # undef const_iv |
3170 | # undef const_iv |
3113 | }; |
3171 | }; |
3114 | |
3172 | |
3115 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3173 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
3116 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3174 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
3117 | |
3175 | |
3118 | texture_av = newAV (); |
3176 | texture_av = newAV (); |
3119 | AvREAL_off (texture_av); |
3177 | AvREAL_off (texture_av); |
3120 | } |
3178 | } |
3121 | |
3179 | |
… | |
… | |
3164 | RETVAL |
3222 | RETVAL |
3165 | |
3223 | |
3166 | int glGetError () |
3224 | int glGetError () |
3167 | |
3225 | |
3168 | void glFinish () |
3226 | void glFinish () |
|
|
3227 | |
|
|
3228 | void glFlush () |
3169 | |
3229 | |
3170 | void glClear (int mask) |
3230 | void glClear (int mask) |
3171 | |
3231 | |
3172 | void glClearColor (float r, float g, float b, float a = 1.0) |
3232 | void glClearColor (float r, float g, float b, float a = 1.0) |
3173 | PROTOTYPE: @ |
3233 | PROTOTYPE: @ |