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.6 by root, Mon Dec 3 22:37:10 2007 UTC vs.
Revision 1.15 by root, Wed Dec 26 18:20:46 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
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
2218 $BUTTONBAR->add (new CFPlus::UI::Button 2227 $BUTTONBAR->add (new CFPlus::UI::Button
2219 text => "Save Config", 2228 text => "Save Config",
2220 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.",
2221 on_activate => sub { 2230 on_activate => sub {
2222 $::CFG->{layout} = CFPlus::UI::get_layout; 2231 $::CFG->{layout} = CFPlus::UI::get_layout;
2223 CFPlus::write_cfg "$Crossfire::VARDIR/cfplusrc"; 2232 CFPlus::write_cfg "$Deliantra::VARDIR/client.cf";
2224 status "Configuration Saved"; 2233 status "Configuration Saved";
2225 0 2234 0
2226 }, 2235 },
2227 ); 2236 );
2228 2237
2261my $animate_timer; 2270my $animate_timer;
2262 2271
2263my $fps = 9; 2272my $fps = 9;
2264 2273
2265sub force_refresh { 2274sub force_refresh {
2266 $WANT_REFRESH->stop;
2267
2268 if ($ENV{CFPLUS_DEBUG} & 4) { 2275 if ($ENV{CFPLUS_DEBUG} & 4) {
2269 $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;
2270 debug sprintf "%3.2f", $fps; 2277 debug sprintf "%3.2f", $fps;
2271 } 2278 }
2272 2279
2280 $WANT_REFRESH->stop;
2281
2273 $CFPlus::UI::ROOT->draw; 2282 $CFPlus::UI::ROOT->draw;
2274 CFPlus::SDL_GL_SwapBuffers; 2283 CFPlus::SDL_GL_SwapBuffers;
2275 $LAST_REFRESH = $NOW; 2284 $LAST_REFRESH = $NOW;
2276} 2285}
2277 2286
2278$WANT_REFRESH = EV::idle_ns \&force_refresh; 2287$WANT_REFRESH = EV::idle_ns \&force_refresh;
2279 2288
2280my $input = EV::timer 0, 1/60, sub { 2289# 0.015 is server tick time / 8 ~~ 66.6...hz
2290my $input = EV::periodic 0, 0.015, undef, sub {
2281 $NOW = time; 2291 $NOW = time;
2282 2292
2283 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2293 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2284 for CFPlus::poll_events; 2294 for CFPlus::poll_events;
2285 2295
2307 }, 2317 },
2308 CFPlus::SDL_VIDEOEXPOSE => sub { 2318 CFPlus::SDL_VIDEOEXPOSE => sub {
2309 CFPlus::UI::full_refresh; 2319 CFPlus::UI::full_refresh;
2310 }, 2320 },
2311 CFPlus::SDL_ACTIVEEVENT => sub { 2321 CFPlus::SDL_ACTIVEEVENT => sub {
2312# not useful, as APPACTIVE include sonly iconified state, not unmapped 2322# not useful, as APPACTIVE includes only iconified state, not unmapped
2313# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, CFPlus::SDL_GetAppState;#d# 2323# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, CFPlus::SDL_GetAppState;#d#
2314# printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d# 2324# printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d#
2315# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; 2325# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE;
2316# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; 2326# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS;
2317# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; 2327# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS;
2339 }, 2349 },
2340); 2350);
2341 2351
2342############################################################################# 2352#############################################################################
2343 2353
2344$SIG{INT} = $SIG{TERM} = sub { exit }; 2354$SIG{INT} = $SIG{TERM} = sub {
2355 EV::unloop;
2356 #d# TODO calling exit here hangs the process in some futex
2357};
2345 2358
2346{ 2359{
2360 if (-e "$Deliantra::VARDIR/client.cf") {
2361 CFPlus::read_cfg "$Deliantra::VARDIR/client.cf";
2362 } else {
2363 #TODO: compatibility cruft
2347 CFPlus::read_cfg "$Crossfire::VARDIR/cfplusrc"; 2364 CFPlus::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2365 print STDERR "INFO: used old configuratrion file\n";
2366 }
2367
2348 CFPlus::DB::Server::run; 2368 CFPlus::DB::Server::run;
2349 2369
2350 CFPlus::UI::set_layout ($::CFG->{layout}); 2370 CFPlus::UI::set_layout ($::CFG->{layout});
2351 2371
2352 my %DEF_CFG = ( 2372 my %DEF_CFG = (

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines