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.305 by root, Sun May 2 21:22:20 2010 UTC vs.
Revision 1.310 by root, Tue Dec 27 07:23:33 2011 UTC

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
105static char *
106fast_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
105static AV *texture_av; 124static AV *texture_av;
106 125
107static struct 126static struct
108{ 127{
463 482
464 SDL_PushEvent ((SDL_Event *)&ev); 483 SDL_PushEvent ((SDL_Event *)&ev);
465} 484}
466 485
467static unsigned int 486static unsigned int
487div255 (unsigned int n)
488{
489 return (n + (n >> 8)) >> 8;
490}
491
492static unsigned int
468minpot (unsigned int n) 493minpot (unsigned int n)
469{ 494{
470 if (!n) 495 if (!n)
471 return 0; 496 return 0;
472 497
555 580
556static void 581static void
557deliantra_main () 582deliantra_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
1114 OUTPUT: 1139 OUTPUT:
1115 RETVAL 1140 RETVAL
1116 1141
1117void 1142void
1118IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) 1143IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG)
1144
1145void
1146Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG)
1119 1147
1120void 1148void
1121load_image_inline (SV *image_) 1149load_image_inline (SV *image_)
1122 ALIAS: 1150 ALIAS:
1123 load_image_file = 1 1151 load_image_file = 1
2115 ? self->row + y 2143 ? self->row + y
2116 : 0; 2144 : 0;
2117 2145
2118 for (x = x0; x < x1; x++) 2146 for (x = x0; x < x1; x++)
2119 { 2147 {
2120 int r = 32, g = 32, b = 32, a = 192; 2148 unsigned int r = 32, g = 32, b = 32, a = 192;
2121 2149
2122 if (row && row->c0 <= x && x < row->c1) 2150 if (row && row->c0 <= x && x < row->c1)
2123 { 2151 {
2124 mapcell *cell = row->col + (x - row->c0); 2152 mapcell *cell = row->col + (x - row->c0);
2125 2153
2127 { 2155 {
2128 maptex tex = self->tex [cell->tile [z]]; 2156 maptex tex = self->tex [cell->tile [z]];
2129 int a0 = 255 - tex.a; 2157 int a0 = 255 - tex.a;
2130 int a1 = tex.a; 2158 int a1 = tex.a;
2131 2159
2132 r = (r * a0 + tex.r * a1) / 255; 2160 r = div255 (r * a0 + tex.r * a1);
2133 g = (g * a0 + tex.g * a1) / 255; 2161 g = div255 (g * a0 + tex.g * a1);
2134 b = (b * a0 + tex.b * a1) / 255; 2162 b = div255 (b * a0 + tex.b * a1);
2135 a = (a * a0 + tex.a * a1) / 255; 2163 a = div255 (a * a0 + tex.a * a1);
2136 } 2164 }
2137 } 2165 }
2138 2166
2139 *map++ = (r ) 2167 *map++ = (r )
2140 | (g << 8) 2168 | (g << 8)
2147} 2175}
2148 OUTPUT: 2176 OUTPUT:
2149 RETVAL 2177 RETVAL
2150 2178
2151void 2179void
2152draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2180draw (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: 2181 CODE:
2154{ 2182{
2155 int x, y, z; 2183 int x, y, z;
2156 2184
2157 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 2185 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2241 2269
2242 key.texname = tex.name; 2270 key.texname = tex.name;
2243 arr = rc_array (rc, &key); 2271 arr = rc_array (rc, &key);
2244 } 2272 }
2245 2273
2246 px = (x + 1) * T - tex.w; 2274 px = (x + 1) * Th - tex.w;
2247 py = (y + 1) * T - tex.h; 2275 py = (y + 1) * Tw - tex.h;
2248 2276
2249 if (expect_false (cell->player == player) && expect_false (z == 2)) 2277 if (expect_false (cell->player == player) && expect_false (z == 2))
2250 { 2278 {
2251 pl_x = px; 2279 pl_x = px;
2252 pl_y = py; 2280 pl_y = py;
2305 if (cell->flags & 1) 2333 if (cell->flags & 1)
2306 { 2334 {
2307 rc_key_t key_ov = key; 2335 rc_key_t key_ov = key;
2308 maptex tex = self->tex [TEXID_SPEECH]; 2336 maptex tex = self->tex [TEXID_SPEECH];
2309 rc_array_t *arr; 2337 rc_array_t *arr;
2310 int px = x * T + T * 2 / 32; 2338 int px = x * Tw + Tw * 2 / 32;
2311 int py = y * T - T * 6 / 32; 2339 int py = y * Th - Th * 6 / 32;
2312 2340
2313 key_ov.texname = tex.name; 2341 key_ov.texname = tex.name;
2314 arr = rc_array (rc_ov, &key_ov); 2342 arr = rc_array (rc_ov, &key_ov);
2315 2343
2316 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2344 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2317 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); 2345 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); 2346 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); 2347 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0);
2320 } 2348 }
2321 } 2349 }
2322 } 2350 }
2323 } 2351 }
2324 2352
2351 if (!(bits & 0x1000) 2379 if (!(bits & 0x1000)
2352 && skey->level == level 2380 && skey->level == level
2353 && level > smooth_max [skey->x][skey->y]) 2381 && level > smooth_max [skey->x][skey->y])
2354 { 2382 {
2355 maptex tex = self->tex [skey->tile]; 2383 maptex tex = self->tex [skey->tile];
2356 int px = (((int)skey->x) - 1) * T; 2384 int px = (((int)skey->x) - 1) * Tw;
2357 int py = (((int)skey->y) - 1) * T; 2385 int py = (((int)skey->y) - 1) * Th;
2358 int border = bits & 15; 2386 int border = bits & 15;
2359 int corner = (bits >> 8) & ~(bits >> 4) & 15; 2387 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2360 float dx = tex.s * .0625f; // 16 images/row 2388 float dx = tex.s * .0625f; // 16 images/row
2361 float dy = tex.t * .5f ; // 2 images/column 2389 float dy = tex.t * .5f ; // 2 images/column
2362 2390
2375 2403
2376 if (border) 2404 if (border)
2377 { 2405 {
2378 float ox = border * dx; 2406 float ox = border * dx;
2379 2407
2380 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2408 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2381 glTexCoord2f (ox , dy ); glVertex2i (px , py + T); 2409 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2382 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); 2410 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2383 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); 2411 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2384 } 2412 }
2385 2413
2386 if (corner) 2414 if (corner)
2387 { 2415 {
2388 float ox = corner * dx; 2416 float ox = corner * dx;
2389 2417
2390 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2418 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2391 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); 2419 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2392 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); 2420 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2393 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); 2421 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2394 } 2422 }
2395 } 2423 }
2396 } 2424 }
2397 } 2425 }
2398 } 2426 }
2439 for (x = 0; x < sw; x++) 2467 for (x = 0; x < sw; x++)
2440 if (row->c0 <= x + mx && x + mx < row->c1) 2468 if (row->c0 <= x + mx && x + mx < row->c1)
2441 { 2469 {
2442 mapcell *cell = row->col + (x + mx - row->c0); 2470 mapcell *cell = row->col + (x + mx - row->c0);
2443 2471
2444 int px = x * T; 2472 int px = x * Tw;
2445 int py = y * T; 2473 int py = y * Th;
2446 2474
2447 if (expect_false (cell->player == player)) 2475 if (expect_false (cell->player == player))
2448 { 2476 {
2449 px += sdx; 2477 px += sdx;
2450 py += sdy; 2478 py += sdy;
2451 } 2479 }
2452 2480
2453 if (cell->stat_hp) 2481 if (cell->stat_hp)
2454 { 2482 {
2455 int width = cell->stat_width * T; 2483 int width = cell->stat_width * Tw;
2456 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; 2484 int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width;
2457 2485
2458 glColor3ub (0, 0, 0); 2486 glColor3ub (0, 0, 0);
2459 glRectf (px + 1, py - thick - 2, 2487 glRectf (px + 1, py - thick - 2,
2460 px + width - 1, py); 2488 px + width - 1, py);
2461 2489
2541 int x, y; 2569 int x, y;
2542 int sw1 = sw + 2; 2570 int sw1 = sw + 2;
2543 int sh1 = sh + 2; 2571 int sh1 = sh + 2;
2544 int sh3 = sh * 3; 2572 int sh3 = sh * 3;
2545 int sw3 = sw * 3; 2573 int sw3 = sw * 3;
2546 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
2547 SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); 2574 SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3));
2548 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); 2575 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
2576 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
2577 memset (darkness1, 0, sw1*sh1);
2549 2578
2550 SvPOK_only (darkness3_sv); 2579 SvPOK_only (darkness3_sv);
2551 SvCUR_set (darkness3_sv, sw3 * sh3); 2580 SvCUR_set (darkness3_sv, sw3 * sh3);
2552 2581
2553 mx += self->x - 1; 2582 mx += self->x - 1;
3132 const_iv (GL_FUNC_SUBTRACT), 3161 const_iv (GL_FUNC_SUBTRACT),
3133 const_iv (GL_FUNC_REVERSE_SUBTRACT), 3162 const_iv (GL_FUNC_REVERSE_SUBTRACT),
3134# undef const_iv 3163# undef const_iv
3135 }; 3164 };
3136 3165
3137 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 3166 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
3138 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 3167 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
3139 3168
3140 texture_av = newAV (); 3169 texture_av = newAV ();
3141 AvREAL_off (texture_av); 3170 AvREAL_off (texture_av);
3142} 3171}
3143 3172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines