ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/deliantra (file contents):
Revision 1.4 by root, Mon Nov 12 23:25:37 2007 UTC vs.
Revision 1.12 by root, Wed Dec 26 13:35:06 2007 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
3if ($ENV{DELIANTRA_CORO_DEBUG}) {
4 eval '
5 use Coro;
6 use Coro::EV;
7 use Coro::Debug;
8 our $debug = new_unix_server Coro::Debug "/tmp/dc";
9 ';
10}
2 11
3# do splash-screen thingy on win32 12# do splash-screen thingy on win32
4my $startup_done = sub { }; 13my $startup_done = sub { };
5BEGIN { 14BEGIN {
6 if (%PAR::LibCache && $^O eq "MSWin32") { 15 if (%PAR::LibCache && $^O eq "MSWin32") {
249 } else { 258 } else {
250 # fetch from database 259 # fetch from database
251 CFPlus::DB::get res_data => $meta->{name}, sub { 260 CFPlus::DB::get res_data => $meta->{name}, sub {
252 my $rwops = new CFPlus::RW $_[0]; 261 my $rwops = new CFPlus::RW $_[0];
253 my $chunk = new CFPlus::MixChunk $rwops 262 my $chunk = new CFPlus::MixChunk $rwops
254 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; 263 or Carp::confess "sound face " . (JSON::XS::encode_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
255 $chunk->volume (($meta->{data}{volume} || 1) * 128); 264 $chunk->volume (($meta->{data}{volume} || 1) * 128);
256 $AUDIO_CHUNK{$face} = $chunk; 265 $AUDIO_CHUNK{$face} = $chunk;
257 266
258 audio_sound_push ($face); 267 audio_sound_push ($face);
259 }; 268 };
335 return unless $SDL_MIXER; 344 return unless $SDL_MIXER;
336 345
337 my $fade_out; 346 my $fade_out;
338 347
339 if (@MUSIC_JINGLE) { 348 if (@MUSIC_JINGLE) {
349 $fade_out = 333;
340 @MUSIC_HAVE = $MUSIC_JINGLE[0]; 350 @MUSIC_HAVE = $MUSIC_JINGLE[0];
341 $fade_out = 333; 351
342 } else { 352 } else {
343 return unless $CFG->{bgm_enable}; 353 return unless $CFG->{bgm_enable};
344 354
345 my @have = 355 $fade_out = 700;
356
357 @MUSIC_HAVE =
346 grep $_ && $_->{data}, 358 grep $_ && $_->{data},
347 map $CONN->{face}[$_], 359 map $CONN->{face}[$_],
348 @$MUSIC_WANT; 360 @$MUSIC_WANT;
349 361
350 # randomize music a bit so that the order is not always the same 362 # randomize music a bit so that the order is not always the same
351 $_->{stop_time} ||= rand for @have; 363 $_->{stop_time} ||= rand for @MUSIC_HAVE;
352
353 @MUSIC_HAVE = @have
354 if @have;
355 364
356 # default MUSIC_HAVE == MUSIC_DEFAULT 365 # default MUSIC_HAVE == MUSIC_DEFAULT
357 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 366 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" }
358 $fade_out = 700; 367 unless @MUSIC_HAVE;
359 } 368 }
360 369
361 # if the currently playing song is acceptable, let it continue 370 # if the currently playing song is acceptable, let it continue
362 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 371 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
363 372
460 my ($conn, $flags, $prompt) = @_; 469 my ($conn, $flags, $prompt) = @_;
461 470
462 # FIXME: a very ugly hack to wait for stat update #d# 471 # FIXME: a very ugly hack to wait for stat update #d#
463 if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) { 472 if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) {
464 unless ($QUERY_TIMER) { 473 unless ($QUERY_TIMER) {
465 $QUERY_TIMER =
466 EV::timer 1, 0, sub { 474 $QUERY_TIMER = EV::timer 1, 0, sub {
467 server_query ($conn, $flags, $prompt, 1); 475 server_query ($conn, $flags, $prompt, 1);
468 $QUERY_TIMER = undef 476 $QUERY_TIMER = undef
469 }; 477 };
478
470 return; 479 return;
471 } 480 }
472 } 481 }
473 482
474 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel 483 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel
990 c_colspan => 2, expand => 1, 999 c_colspan => 2, expand => 1,
991 value => $CFG->{audio_hw_channels}, 1000 value => $CFG->{audio_hw_channels},
992 options => [ 1001 options => [
993 [0, "default" , "Use System Default"], 1002 [0, "default" , "Use System Default"],
994 [1, "Mono" , "Mono (single channel, low quality)"], 1003 [1, "Mono" , "Mono (single channel, low quality)"],
995 [2, "Stereo" , "Stereo (dual channe, standard quality)"], 1004 [2, "Stereo" , "Stereo (dual channel, standard quality)"],
996 [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"], 1005 [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"],
997 [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"], 1006 [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"],
998 ], 1007 ],
999 tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", 1008 tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.",
1000 on_changed => sub { 1009 on_changed => sub {
1341 my $ok = 0; 1350 my $ok = 0;
1342 1351
1343 CFPlus::background { 1352 CFPlus::background {
1344 my $ua = CFPlus::lwp_useragent; 1353 my $ua = CFPlus::lwp_useragent;
1345 1354
1346 CFPlus::background_msg CFPlus::from_json +(CFPlus::lwp_check $ua->get ($META_SERVER))->decoded_content; 1355 CFPlus::background_msg CFPlus::decode_json +(CFPlus::lwp_check $ua->get ($META_SERVER))->decoded_content;
1347 } sub { 1356 } sub {
1348 my ($msg) = @_; 1357 my ($msg) = @_;
1349 if ($msg) { 1358 if ($msg) {
1350 $table->clear; 1359 $table->clear;
1351 1360
1517 $CFG->{profile}{default}{host} = $value; 1526 $CFG->{profile}{default}{host} = $value;
1518 1 1527 1
1519 } 1528 }
1520 ); 1529 );
1521 1530
1531 if (0) { #d# disabled
1522 $vbox->add (new CFPlus::UI::Button 1532 $vbox->add (new CFPlus::UI::Button
1523 expand => 1, 1533 expand => 1,
1524 text => "Server List", 1534 text => "Server List",
1525 other => $METASERVER, 1535 other => $METASERVER,
1526 tooltip => "Show a list of available crossfire servers", 1536 tooltip => "Show a list of available crossfire servers",
1527 on_activate => sub { $METASERVER->toggle_visibility; 0 }, 1537 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1528 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 }, 1538 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1529 ); 1539 );
1540 }#d#
1530 } 1541 }
1531 1542
1532 $table->add_at (0, ++$row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); 1543 $table->add_at (0, ++$row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
1533 $table->add_at (1, $row, new CFPlus::UI::Slider 1544 $table->add_at (1, $row, new CFPlus::UI::Slider
1534 force_w => 100, 1545 force_w => 100,
2259my $animate_timer; 2270my $animate_timer;
2260 2271
2261my $fps = 9; 2272my $fps = 9;
2262 2273
2263sub force_refresh { 2274sub force_refresh {
2264 $WANT_REFRESH->stop;
2265
2266 if ($ENV{CFPLUS_DEBUG} & 4) { 2275 if ($ENV{CFPLUS_DEBUG} & 4) {
2267 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; 2276 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2268 debug sprintf "%3.2f", $fps; 2277 debug sprintf "%3.2f", $fps;
2269 } 2278 }
2279
2280 $WANT_REFRESH->stop;
2270 2281
2271 $CFPlus::UI::ROOT->draw; 2282 $CFPlus::UI::ROOT->draw;
2272 CFPlus::SDL_GL_SwapBuffers; 2283 CFPlus::SDL_GL_SwapBuffers;
2273 $LAST_REFRESH = $NOW; 2284 $LAST_REFRESH = $NOW;
2274} 2285}
2305 }, 2316 },
2306 CFPlus::SDL_VIDEOEXPOSE => sub { 2317 CFPlus::SDL_VIDEOEXPOSE => sub {
2307 CFPlus::UI::full_refresh; 2318 CFPlus::UI::full_refresh;
2308 }, 2319 },
2309 CFPlus::SDL_ACTIVEEVENT => sub { 2320 CFPlus::SDL_ACTIVEEVENT => sub {
2310# not useful, as APPACTIVE include sonly iconified state, not unmapped 2321# not useful, as APPACTIVE includes only iconified state, not unmapped
2311# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, CFPlus::SDL_GetAppState;#d# 2322# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, CFPlus::SDL_GetAppState;#d#
2312# printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d# 2323# printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d#
2313# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; 2324# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE;
2314# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; 2325# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS;
2315# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; 2326# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS;
2337 }, 2348 },
2338); 2349);
2339 2350
2340############################################################################# 2351#############################################################################
2341 2352
2342$SIG{INT} = $SIG{TERM} = sub { exit }; 2353$SIG{INT} = $SIG{TERM} = sub {
2354 EV::unloop;
2355 #d# TODO calling exit here hangs the process in some futex
2356};
2343 2357
2344{ 2358{
2345 CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc"; 2359 CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc";
2346 CFPlus::DB::Server::run; 2360 CFPlus::DB::Server::run;
2347 2361

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines