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.301 by root, Thu Feb 4 20:01:08 2010 UTC vs.
Revision 1.306 by root, Thu Oct 14 00:02:39 2010 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{
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
486static unsigned int
487div255 (unsigned int n)
488{
489 return (n + (n >> 8)) >> 8;
465} 490}
466 491
467static unsigned int 492static unsigned int
468minpot (unsigned int n) 493minpot (unsigned int n)
469{ 494{
1027 1052
1028 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); 1053 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1))));
1029 } 1054 }
1030} 1055}
1031 1056
1057char *
1058SDL_AudioDriverName ()
1059 CODE:
1060{
1061 char buf [256];
1062 if (!SDL_AudioDriverName (buf, sizeof (buf)))
1063 XSRETURN_UNDEF;
1064
1065 RETVAL = buf;
1066}
1067 OUTPUT:
1068 RETVAL
1069
1032int 1070int
1033Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) 1071Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
1034 POSTCALL: 1072 POSTCALL:
1035 Mix_HookMusicFinished (music_finished); 1073 Mix_HookMusicFinished (music_finished);
1036 Mix_ChannelFinished (channel_finished); 1074 Mix_ChannelFinished (channel_finished);
1098add_font (char *file) 1136add_font (char *file)
1099 CODE: 1137 CODE:
1100 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); 1138 RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file);
1101 OUTPUT: 1139 OUTPUT:
1102 RETVAL 1140 RETVAL
1141
1142void
1143IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG)
1103 1144
1104void 1145void
1105load_image_inline (SV *image_) 1146load_image_inline (SV *image_)
1106 ALIAS: 1147 ALIAS:
1107 load_image_file = 1 1148 load_image_file = 1
2099 ? self->row + y 2140 ? self->row + y
2100 : 0; 2141 : 0;
2101 2142
2102 for (x = x0; x < x1; x++) 2143 for (x = x0; x < x1; x++)
2103 { 2144 {
2104 int r = 32, g = 32, b = 32, a = 192; 2145 unsigned int r = 32, g = 32, b = 32, a = 192;
2105 2146
2106 if (row && row->c0 <= x && x < row->c1) 2147 if (row && row->c0 <= x && x < row->c1)
2107 { 2148 {
2108 mapcell *cell = row->col + (x - row->c0); 2149 mapcell *cell = row->col + (x - row->c0);
2109 2150
2111 { 2152 {
2112 maptex tex = self->tex [cell->tile [z]]; 2153 maptex tex = self->tex [cell->tile [z]];
2113 int a0 = 255 - tex.a; 2154 int a0 = 255 - tex.a;
2114 int a1 = tex.a; 2155 int a1 = tex.a;
2115 2156
2116 r = (r * a0 + tex.r * a1) / 255; 2157 r = div255 (r * a0 + tex.r * a1);
2117 g = (g * a0 + tex.g * a1) / 255; 2158 g = div255 (g * a0 + tex.g * a1);
2118 b = (b * a0 + tex.b * a1) / 255; 2159 b = div255 (b * a0 + tex.b * a1);
2119 a = (a * a0 + tex.a * a1) / 255; 2160 a = div255 (a * a0 + tex.a * a1);
2120 } 2161 }
2121 } 2162 }
2122 2163
2123 *map++ = (r ) 2164 *map++ = (r )
2124 | (g << 8) 2165 | (g << 8)
2131} 2172}
2132 OUTPUT: 2173 OUTPUT:
2133 RETVAL 2174 RETVAL
2134 2175
2135void 2176void
2136draw (DC::Map self, int mx, int my, int sw, int sh, int T, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2177draw (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: 2178 CODE:
2138{ 2179{
2139 int x, y, z; 2180 int x, y, z;
2140 2181
2141 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 2182 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2225 2266
2226 key.texname = tex.name; 2267 key.texname = tex.name;
2227 arr = rc_array (rc, &key); 2268 arr = rc_array (rc, &key);
2228 } 2269 }
2229 2270
2230 px = (x + 1) * T - tex.w; 2271 px = (x + 1) * Th - tex.w;
2231 py = (y + 1) * T - tex.h; 2272 py = (y + 1) * Tw - tex.h;
2232 2273
2233 if (expect_false (cell->player == player) && expect_false (z == 2)) 2274 if (expect_false (cell->player == player) && expect_false (z == 2))
2234 { 2275 {
2235 pl_x = px; 2276 pl_x = px;
2236 pl_y = py; 2277 pl_y = py;
2289 if (cell->flags & 1) 2330 if (cell->flags & 1)
2290 { 2331 {
2291 rc_key_t key_ov = key; 2332 rc_key_t key_ov = key;
2292 maptex tex = self->tex [TEXID_SPEECH]; 2333 maptex tex = self->tex [TEXID_SPEECH];
2293 rc_array_t *arr; 2334 rc_array_t *arr;
2294 int px = x * T + T * 2 / 32; 2335 int px = x * Tw + Tw * 2 / 32;
2295 int py = y * T - T * 6 / 32; 2336 int py = y * Th - Th * 6 / 32;
2296 2337
2297 key_ov.texname = tex.name; 2338 key_ov.texname = tex.name;
2298 arr = rc_array (rc_ov, &key_ov); 2339 arr = rc_array (rc_ov, &key_ov);
2299 2340
2300 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2341 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2301 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); 2342 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); 2343 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); 2344 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0);
2304 } 2345 }
2305 } 2346 }
2306 } 2347 }
2307 } 2348 }
2308 2349
2335 if (!(bits & 0x1000) 2376 if (!(bits & 0x1000)
2336 && skey->level == level 2377 && skey->level == level
2337 && level > smooth_max [skey->x][skey->y]) 2378 && level > smooth_max [skey->x][skey->y])
2338 { 2379 {
2339 maptex tex = self->tex [skey->tile]; 2380 maptex tex = self->tex [skey->tile];
2340 int px = (((int)skey->x) - 1) * T; 2381 int px = (((int)skey->x) - 1) * Tw;
2341 int py = (((int)skey->y) - 1) * T; 2382 int py = (((int)skey->y) - 1) * Th;
2342 int border = bits & 15; 2383 int border = bits & 15;
2343 int corner = (bits >> 8) & ~(bits >> 4) & 15; 2384 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2344 float dx = tex.s * .0625f; // 16 images/row 2385 float dx = tex.s * .0625f; // 16 images/row
2345 float dy = tex.t * .5f ; // 2 images/column 2386 float dy = tex.t * .5f ; // 2 images/column
2346 2387
2359 2400
2360 if (border) 2401 if (border)
2361 { 2402 {
2362 float ox = border * dx; 2403 float ox = border * dx;
2363 2404
2364 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2405 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2365 glTexCoord2f (ox , dy ); glVertex2i (px , py + T); 2406 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2366 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); 2407 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2367 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); 2408 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2368 } 2409 }
2369 2410
2370 if (corner) 2411 if (corner)
2371 { 2412 {
2372 float ox = corner * dx; 2413 float ox = corner * dx;
2373 2414
2374 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2415 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2375 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); 2416 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2376 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); 2417 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2377 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); 2418 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2378 } 2419 }
2379 } 2420 }
2380 } 2421 }
2381 } 2422 }
2382 } 2423 }
2423 for (x = 0; x < sw; x++) 2464 for (x = 0; x < sw; x++)
2424 if (row->c0 <= x + mx && x + mx < row->c1) 2465 if (row->c0 <= x + mx && x + mx < row->c1)
2425 { 2466 {
2426 mapcell *cell = row->col + (x + mx - row->c0); 2467 mapcell *cell = row->col + (x + mx - row->c0);
2427 2468
2428 int px = x * T; 2469 int px = x * Tw;
2429 int py = y * T; 2470 int py = y * Th;
2430 2471
2431 if (expect_false (cell->player == player)) 2472 if (expect_false (cell->player == player))
2432 { 2473 {
2433 px += sdx; 2474 px += sdx;
2434 py += sdy; 2475 py += sdy;
2435 } 2476 }
2436 2477
2437 if (cell->stat_hp) 2478 if (cell->stat_hp)
2438 { 2479 {
2439 int width = cell->stat_width * T; 2480 int width = cell->stat_width * Tw;
2440 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; 2481 int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width;
2441 2482
2442 glColor3ub (0, 0, 0); 2483 glColor3ub (0, 0, 0);
2443 glRectf (px + 1, py - thick - 2, 2484 glRectf (px + 1, py - thick - 2,
2444 px + width - 1, py); 2485 px + width - 1, py);
2445 2486
2798 if (RETVAL < 0) 2839 if (RETVAL < 0)
2799 { 2840 {
2800 RETVAL = Mix_GroupOldest (-1); 2841 RETVAL = Mix_GroupOldest (-1);
2801 2842
2802 if (RETVAL < 0) 2843 if (RETVAL < 0)
2844 {
2845 // happens sometimes, maybe it just stopped playing(?)
2846 RETVAL = Mix_GroupAvailable (-1);
2847
2848 if (RETVAL < 0)
2803 XSRETURN_UNDEF; 2849 XSRETURN_UNDEF;
2804 2850 }
2851 else
2805 Mix_HaltChannel (RETVAL); 2852 Mix_HaltChannel (RETVAL);
2806 } 2853 }
2807 2854
2808 Mix_UnregisterAllEffects (RETVAL); 2855 Mix_UnregisterAllEffects (RETVAL);
2809 Mix_Volume (RETVAL, 128); 2856 Mix_Volume (RETVAL, 128);
2810} 2857}
3165 3212
3166int glGetError () 3213int glGetError ()
3167 3214
3168void glFinish () 3215void glFinish ()
3169 3216
3217void glFlush ()
3218
3170void glClear (int mask) 3219void glClear (int mask)
3171 3220
3172void glClearColor (float r, float g, float b, float a = 1.0) 3221void glClearColor (float r, float g, float b, float a = 1.0)
3173 PROTOTYPE: @ 3222 PROTOTYPE: @
3174 3223

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines