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.16 by root, Wed Dec 26 19:11:13 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") {
74 83
75use Time::HiRes 'time'; 84use Time::HiRes 'time';
76use EV; 85use EV;
77use List::Util qw(max min); 86use List::Util qw(max min);
78 87
79use Crossfire; 88use Deliantra;
80use Crossfire::Protocol::Constants; 89use Deliantra::Protocol::Constants;
81 90
82use Compress::LZF; 91use Compress::LZF;
83 92
84use CFPlus; 93use CFPlus;
85use CFPlus::OpenGL (); 94use CFPlus::OpenGL ();
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,
2216 $BUTTONBAR->add (new CFPlus::UI::Button 2227 $BUTTONBAR->add (new CFPlus::UI::Button
2217 text => "Save Config", 2228 text => "Save Config",
2218 tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.", 2229 tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.",
2219 on_activate => sub { 2230 on_activate => sub {
2220 $::CFG->{layout} = CFPlus::UI::get_layout; 2231 $::CFG->{layout} = CFPlus::UI::get_layout;
2221 CFPlus::write_cfg "$Crossfire::VARDIR/cfplusrc"; 2232 CFPlus::write_cfg "$Deliantra::VARDIR/client.cf";
2222 status "Configuration Saved"; 2233 status "Configuration Saved";
2223 0 2234 0
2224 }, 2235 },
2225 ); 2236 );
2226 2237
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 }
2270 2279
2280 undef $WANT_REFRESH;
2281 $_[0]->stop;
2282
2271 $CFPlus::UI::ROOT->draw; 2283 $CFPlus::UI::ROOT->draw;
2272 CFPlus::SDL_GL_SwapBuffers; 2284 CFPlus::SDL_GL_SwapBuffers;
2273 $LAST_REFRESH = $NOW; 2285 $LAST_REFRESH = $NOW;
2274} 2286}
2275 2287
2276$WANT_REFRESH = EV::idle_ns \&force_refresh; 2288my $want_refresh = EV::idle_ns \&force_refresh;
2277 2289
2278my $input = EV::timer 0, 1/60, sub { 2290my $input = EV::periodic 0, 1/60, undef, sub {
2279 $NOW = time; 2291 $NOW = time;
2280 2292
2281 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2293 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2282 for CFPlus::poll_events; 2294 for CFPlus::poll_events;
2283 2295
2284 if (%animate_object) { 2296 if (%animate_object) {
2285 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2297 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2286 $WANT_REFRESH->start; 2298 $WANT_REFRESH = 1;
2287 } 2299 }
2300
2301 $want_refresh->start
2302 if $WANT_REFRESH;
2288}; 2303};
2289 2304
2290sub animation_start { 2305sub animation_start {
2291 my ($widget) = @_; 2306 my ($widget) = @_;
2292 $animate_object{$widget} = $widget; 2307 $animate_object{$widget} = $widget;
2305 }, 2320 },
2306 CFPlus::SDL_VIDEOEXPOSE => sub { 2321 CFPlus::SDL_VIDEOEXPOSE => sub {
2307 CFPlus::UI::full_refresh; 2322 CFPlus::UI::full_refresh;
2308 }, 2323 },
2309 CFPlus::SDL_ACTIVEEVENT => sub { 2324 CFPlus::SDL_ACTIVEEVENT => sub {
2310# not useful, as APPACTIVE include sonly iconified state, not unmapped 2325# 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# 2326# 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# 2327# printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d#
2313# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; 2328# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE;
2314# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; 2329# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS;
2315# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; 2330# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS;
2337 }, 2352 },
2338); 2353);
2339 2354
2340############################################################################# 2355#############################################################################
2341 2356
2342$SIG{INT} = $SIG{TERM} = sub { exit }; 2357$SIG{INT} = $SIG{TERM} = sub {
2358 EV::unloop;
2359 #d# TODO calling exit here hangs the process in some futex
2360};
2343 2361
2344{ 2362{
2363 if (-e "$Deliantra::VARDIR/client.cf") {
2364 CFPlus::read_cfg "$Deliantra::VARDIR/client.cf";
2365 } else {
2366 #TODO: compatibility cruft
2345 CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc"; 2367 CFPlus::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2368 print STDERR "INFO: used old configuratrion file\n";
2369 }
2370
2346 CFPlus::DB::Server::run; 2371 CFPlus::DB::Server::run;
2347 2372
2348 CFPlus::UI::set_layout ($::CFG->{layout}); 2373 CFPlus::UI::set_layout ($::CFG->{layout});
2349 2374
2350 my %DEF_CFG = ( 2375 my %DEF_CFG = (
2457 2482
2458EV::loop; 2483EV::loop;
2459 2484
2460#video_shutdown; 2485#video_shutdown;
2461#audio_shutdown; 2486#audio_shutdown;
2487CFPlus::OpenGL::quit;
2462CFPlus::SDL_Quit; 2488CFPlus::SDL_Quit;
2463CFPlus::DB::Server::stop; 2489CFPlus::DB::Server::stop;
2464 2490
2465=head1 NAME 2491=head1 NAME
2466 2492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines