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

Comparing deliantra/Deliantra-Client/DC/Main.pm (file contents):
Revision 1.8 by root, Wed Jan 4 11:23:23 2012 UTC vs.
Revision 1.21 by root, Thu Jun 7 15:40:03 2012 UTC

18} 18}
19 19
20use common::sense; 20use common::sense;
21use Carp 'verbose'; 21use Carp 'verbose';
22use Cwd (); 22use Cwd ();
23use Digest::MD5 ();
23use EV; 24use EV;
24BEGIN { *time = \&EV::time } 25BEGIN { *time = \&EV::time }
25 26
26use List::Util qw(max min); 27use List::Util qw(max min);
27 28
32use AnyEvent::Socket (); 33use AnyEvent::Socket ();
33use AnyEvent::DNS (); 34use AnyEvent::DNS ();
34 35
35use Compress::LZF; 36use Compress::LZF;
36use JSON::XS; 37use JSON::XS;
38use Urlader;
37 39
38use DC; 40use DC;
39 41
40sub crash($;$) { 42sub crash($;$) {
41 # nop at compiletime 43 # nop at compiletime
43 45
44BEGIN { 46BEGIN {
45 $SIG{__DIE__} = sub { 47 $SIG{__DIE__} = sub {
46 return if $^S; # quick reject 48 return if $^S; # quick reject
47 49
48 # return if there are any eval contexts in the csall stack 50 # return if there are any eval contexts in the call stack
49 for my $i (0..999) { 51 for my $i (0..999) {
50 my ($sub, $is_require) = (caller $i)[3, 7] 52 my ($sub, $is_require) = (caller $i)[3, 7]
51 or last; 53 or last;
52 return if $sub eq "(eval)" && !$is_require; 54 return if $sub eq "(eval)" && !$is_require;
53 } 55 }
56 DC::fatal Carp::longmess "$_[0]"; 58 DC::fatal Carp::longmess "$_[0]";
57 } 59 }
58} 60}
59 61
60use DC::OpenGL (); 62use DC::OpenGL ();
63use DC::Audio ();
61use DC::Protocol; 64use DC::Protocol;
62use DC::DB; 65use DC::DB;
63use DC::UI; 66use DC::UI;
64use DC::UI::Canvas; 67use DC::UI::Canvas;
65use DC::UI::Inventory; 68use DC::UI::Inventory;
195 AnyEvent::Util::fh_nonblocking $fh, 1; 198 AnyEvent::Util::fh_nonblocking $fh, 1;
196 199
197 $msg =~ s/\s+$//; 200 $msg =~ s/\s+$//;
198 201
199 # backtrace as second step, in case it crashes, too 202 # backtrace as second step, in case it crashes, too
200 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" 203 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated"
201 if $backtrace; 204 if $backtrace;
202}; 205};
203 206
204sub clienterror($;$) { 207sub clienterror($;$) {
205 my ($msg, $backtrace) = @_; 208 my ($msg, $backtrace) = @_;
207 warn $msg; 210 warn $msg;
208 211
209 return unless $CONN; 212 return unless $CONN;
210 213
211 $CONN->send_exti_msg (clientlog => $msg); 214 $CONN->send_exti_msg (clientlog => $msg);
212 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; 215 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace;
213} 216}
214 217
215############################################################################# 218#############################################################################
216 219
217sub status { 220sub status {
472 audio_music_push; 475 audio_music_push;
473} 476}
474 477
475sub audio_init { 478sub audio_init {
476 if ($CFG->{audio_enable}) { 479 if ($CFG->{audio_enable}) {
477 if (length $CFG->{audio_driver}) { 480 DC::Audio::init $CFG->{audio_driver};
478 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
479 DC::SDL_Init DC::SDL_INIT_AUDIO
480 and die "SDL::Init failed!\n";
481 } else {
482 DC::SDL_Init DC::SDL_INIT_AUDIO
483 and die "SDL::Init failed!\n";
484 }
485
486 $ENV{MIX_EFFECTSMAXSPEED} = 1;
487 $SDL_MIXER = !DC::Mix_OpenAudio
488 $CFG->{audio_hw_frequency},
489 DC::MIX_DEFAULT_FORMAT,
490 $CFG->{audio_hw_channels},
491 $CFG->{audio_hw_chunksize};
492 481
493 if ($SDL_MIXER) { 482 if ($SDL_MIXER) {
494 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
495
496 audio_music_finished; 483 audio_music_finished;
497 } else { 484 } else {
498 status "Unable to open sound device: there will be no sound"; 485 status "Unable to open sound device: there will be no sound";
499 } 486 }
500 } else { 487 } else {
527} 514}
528 515
529############################################################################# 516#############################################################################
530# Over-the-air updates 517# Over-the-air updates
531 518
532sub ota_update_finish {
533 $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] });
534}
535
536sub ota_update_status {
537}
538
539sub ota_update { 519sub ota_update {
540 my ($face, $size) = @_; 520 my ($face, $size, $md5) = @_;
541 521
542 my $coro = Coro::async_pool { 522 my $coro = Coro::async_pool {
543 my $override = "$Urlader::EXE_DIR/override"; 523 my $override = "$Urlader::EXE_DIR/override";
544 524
545 $MESSAGE_DIST->add_channel ({ 525 $MESSAGE_DIST->add_channel ({
551 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); 531 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
552 532
553 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; 533 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
554 534
555 unless ($fh) { 535 unless ($fh) {
556 ota_update_finish "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!"; 536 $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") });
557 return; 537 return;
558 } 538 }
559 539
560 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); 540 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
561 541
562 my $cv = AE::cv; 542 my $cv = AE::cv;
563 my $error; 543 my $error;
564 544
565 $cv->begin (Coro::rouse_cb); 545 $cv->begin (Coro::rouse_cb);
566
567 $CONN->ask_face ( 546 $CONN->ask_face (
568 $face, 547 $face,
569 -1000, 548 -1000,
570 sub { 549 sub {
571 $STATUSBOX->add ( 550 $STATUSBOX->add (
596 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); 575 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
597 Coro::AIO::aio_unlink "$override.tmp"; 576 Coro::AIO::aio_unlink "$override.tmp";
598 return; 577 return;
599 } 578 }
600 579
580 {
581 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verifying update file..." });
582
583 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
584
585 if ($fh) {
586 $error ||= Coro::AIO::aio_stat "$override.tmp";
587 $error ||= -s _ != $size;
588 Coro::AIO::aio_readahead $fh, 0, $size;
589
590 my $f_md5 = new Digest::MD5;
591 binmode $fh; # ugh :(
592 $f_md5->addfile ($fh);
593 $f_md5 = $f_md5->hexdigest;
594 $error ||= $md5 ne $f_md5;
595 }
596 }
597
598 if ($error) {
599 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." });
600 Coro::AIO::aio_unlink "$override.tmp";
601 return;
602 }
603
601 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); 604 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
602 605
603 if (Coro::AIO::aio_rename "$override.tmp", $override) { 606 if (Coro::AIO::aio_rename "$override.tmp", $override) {
604 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); 607 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
605 Coro::AIO::aio_unlink "$override.tmp"; 608 Coro::AIO::aio_unlink "$override.tmp";
606 } 609 }
607 610
608 $MESSAGE_DIST->message ({ type => "ota_update", markup => "update successfull, changes become active at next start." }); 611 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
609 }; 612 };
610 613
611 $CONN->{ota_update} = Guard::guard { 614 $CONN->{ota_update} = Guard::guard {
612 $coro->cancel; 615 $coro->cancel;
613 }; 616 };
614} 617}
615 618
616sub ota_update_ask { 619sub ota_update_ask {
617 my ($ok, $face, $ver, $size, $changes) = @_; 620 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
618 621
619 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel 622 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
620 x => "center", 623 x => "center",
621 y => "center", 624 y => "center",
625 z => 55,
622 max_w => $::WIDTH * 0.7, 626 force_w => $::WIDTH * 0.7,
623 max_h => $::WIDTH * 0.7, 627 force_h => $::HEIGHT * 0.7,
624 title => "Software update available", 628 title => "Software update available",
625 child => my $vbox = new DC::UI::VBox, 629 child => my $vbox = new DC::UI::VBox,
626 ; 630 ;
627 631
628 $vbox->add (new DC::UI::Label 632 $vbox->add (new DC::UI::Label
629 ellipsise => 0, 633 ellipsise => 0,
630 text => "The server offers a software update, " 634 text => "The server offers a software update, "
631 . "do you want to start downloading this update in the background?", 635 . "do you want to start downloading this update in the background?",
632 ); 636 );
633 637
634 $vbox->add (new DC::UI::FancyFrame 638 $vbox->add (new DC::UI::FancyFrame
635 expand => 1, 639 expand => 1,
636 label => "Changes", 640 label => "Details",
637 child => (new DC::UI::TextScroller 641 child => (new DC::UI::TextScroller
638 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, 642 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
639 par => [{ 643 par => [{
640 markup => "<tt>Old revision: $Urlader::EXE_VER\n" 644 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
641 . "New revision: $ver\n" 645 . "New revision: $ver\n"
642 . "Download size: $size bytes</tt>\n\n" 646 . "Download size: $size bytes</tt>\n\n"
647 . "Changes:\n\n"
643 . DC::asxml $changes 648 . DC::asxml $changes
644 }], 649 }],
645 ), 650 ),
646 ); 651 );
647 652
658 $hbox->add (new DC::UI::Button 663 $hbox->add (new DC::UI::Button
659 expand => 1, 664 expand => 1,
660 text => "Yes, start downloading", 665 text => "Yes, start downloading",
661 on_activate => sub { 666 on_activate => sub {
662 $dialog->destroy; 667 $dialog->destroy;
663 ota_update $face, $size; 668 ota_update $face, $size, $md5;
664 0 669 0
665 }, 670 },
666 ); 671 );
667 672
668 $dialog->show; 673 $dialog->show;
672 return unless defined $Urlader::EXE_ID; 677 return unless defined $Urlader::EXE_ID;
673 678
674 ::message { markup => "Checking for software update..." }; 679 ::message { markup => "Checking for software update..." };
675 680
676 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { 681 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
677 my ($ok, $face, $ver, $size, $changes) = @_; 682 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
678 683
679 if ($ok) { 684 if ($ok) {
680 if (defined $ver) { 685 if (defined $ver) {
681 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; 686 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
682 &ota_update_ask; 687 &ota_update_ask;
946 mapw => $mapw, 951 mapw => $mapw,
947 maph => $maph, 952 maph => $maph,
948 953
949 c_version => { 954 c_version => {
950 client => "deliantra", 955 client => "deliantra",
951 clientver => $DC::VERSION, 956 clientver => "$DC::VERSION$Urlader::EXE_VER",
952 gl_vendor => DC::OpenGL::gl_vendor, 957 gl_vendor => DC::OpenGL::gl_vendor,
953 gl_version => DC::OpenGL::gl_version, 958 gl_version => DC::OpenGL::gl_version,
954 }, 959 },
955 960
956 map_widget => $MAPWIDGET, 961 map_widget => $MAPWIDGET,
2010 $table->add_at (2, $row++, new DC::UI::Button 2015 $table->add_at (2, $row++, new DC::UI::Button
2011 text => "Save Now", 2016 text => "Save Now",
2012 tooltip => "Use this to manually save configuration and UI layout when " 2017 tooltip => "Use this to manually save configuration and UI layout when "
2013 . "autosave is disabled.", 2018 . "autosave is disabled.",
2014 on_activate => sub { 2019 on_activate => sub {
2015 DC::write_cfg; 2020 DC::save_cfg;
2016 0 2021 0
2017 } 2022 }
2018 ); 2023 );
2019 } 2024 }
2020 2025
2453sub open_quit_dialog { 2458sub open_quit_dialog {
2454 unless ($QUIT_DIALOG) { 2459 unless ($QUIT_DIALOG) {
2455 $QUIT_DIALOG = new DC::UI::Toplevel 2460 $QUIT_DIALOG = new DC::UI::Toplevel
2456 x => "center", 2461 x => "center",
2457 y => "center", 2462 y => "center",
2458 z => 50, 2463 z => 60,
2459 title => "Really Quit?", 2464 title => "Really Quit?",
2460 on_key_down => sub { 2465 on_key_down => sub {
2461 my ($dialog, $ev) = @_; 2466 my ($dialog, $ev) = @_;
2462 $ev->{sym} == 27 and $dialog->hide; 2467 $ev->{sym} == 27 and $dialog->hide;
2463 } 2468 }
2656 DC::set_theme $CFG->{uitheme}; 2661 DC::set_theme $CFG->{uitheme};
2657 2662
2658 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2663 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2659 $SDL_REINIT = 0; 2664 $SDL_REINIT = 0;
2660 2665
2661 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2666 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2662 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2667 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2663 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2668 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2664 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 2669 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2665 2670
2666 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2671 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2679 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2684 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2680 2685
2681 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2686 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2682 $FULLSCREEN = $CFG->{fullscreen}; 2687 $FULLSCREEN = $CFG->{fullscreen};
2683 $FAST = $CFG->{fast}; 2688 $FAST = $CFG->{fast};
2689
2690 DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init
2684 2691
2685 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error 2692 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error
2686 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2693 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2687 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2694 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2688 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2695 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2946 EV::unloop; 2953 EV::unloop;
2947 #d# TODO calling exit here hangs the process in some futex 2954 #d# TODO calling exit here hangs the process in some futex
2948}; 2955};
2949 2956
2950# due to mac os x + sdl combined braindamage, we need this contortion 2957# due to mac os x + sdl combined braindamage, we need this contortion
2951sub DC::Main::main { 2958sub DC::Main::run {
2952 { 2959 DC::SDL_main_hack {
2960 {
2953 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2961 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2954 2962
2955 if (-e "$Deliantra::VARDIR/client.cf") { 2963 DC::load_cfg;
2956 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2964 DC::upgrade_cfg;
2957 } else {
2958 #TODO: compatibility cruft
2959 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2960 print STDERR "INFO: used old configuration file\n";
2961 }
2962 2965
2966 DC::Audio::probe;
2967
2963 DC::DB::Server::run; 2968 DC::DB::Server::run;
2964 2969
2965 if ($CFG->{db_schema} < 1) { 2970 if ($CFG->{db_schema} < 1) {
2966 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2971 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2967 DC::DB::nuke_db; 2972 DC::DB::nuke_db;
2968 $CFG->{db_schema} = 1; 2973 $CFG->{db_schema} = 1;
2969 DC::write_cfg; 2974 DC::save_cfg;
2970 }
2971
2972 DC::DB::open_db;
2973
2974 DC::UI::set_layout ($::CFG->{layout});
2975
2976 my %DEF_CFG = (
2977 config_autosave => 1,
2978 sdl_mode => undef,
2979 fullscreen => 1,
2980 fast => 0,
2981 force_opengl11 => undef,
2982 disable_alpha => 0,
2983 smooth_movement => 1,
2984 smooth_transitions => 1,
2985 texture_compression => 1,
2986 map_scale => 1,
2987 fow_enable => 1,
2988 fow_intensity => 0,
2989 fow_texture => 0,
2990 map_smoothing => 1,
2991 gui_fontsize => 1,
2992 log_fontsize => 0.7,
2993 gauge_fontsize => 1,
2994 gauge_size => 0.35,
2995 stat_fontsize => 0.7,
2996 mapsize => 100,
2997 audio_enable => 1,
2998 audio_hw_channels => 0,
2999 audio_hw_frequency => 0,
3000 audio_hw_chunksize => 0,
3001 audio_mix_channels => 8,
3002 effects_enable => 1,
3003 effects_volume => 1,
3004 bgm_enable => 1,
3005 bgm_volume => 0.5,
3006 output_rate => "",
3007 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3008 inv_sort => "mtime",
3009 default => "profile", # default profile
3010 show_tips => 1,
3011 logview_max_par => 1000,
3012 shift_fire_stop => 0,
3013 uitheme => "wood",
3014 map_shift_x => -24, # arbitrary
3015 map_shift_y => +24, # arbitrary
3016 );
3017
3018 while (my ($k, $v) = each %DEF_CFG) {
3019 $CFG->{$k} = $v unless exists $CFG->{$k};
3020 }
3021
3022 my @args = @ARGV;
3023
3024 # OS X passes some process serial number of other shit. they
3025 # could have used an env var or any other sane mechanism. but
3026 # would it be os x then? no...
3027 shift @args if $args[0] =~ /^-psn_/;
3028
3029 my $profile = 'default';
3030
3031 for (my $i = 0; $i < @args; $i++) {
3032 if ($args[$i] =~ /^--?profile$/) {
3033 $profile = $args[$i + 1];
3034 splice @args, $i, 2, ();
3035 $i = 0;
3036 } elsif ($args[$i] =~ /^--?h/) {
3037 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3038 exit 0;
3039 } 2975 }
3040 }
3041 2976
3042 $CFG->{profile}{$profile} ||= {}; 2977 DC::DB::open_db;
3043 $PROFILE = $CFG->{profile}{$profile};
3044 $PROFILE->{host} ||= "gameserver.deliantra.net";
3045 2978
3046 $PROFILE->{host} = $args[0] if @args > 0; 2979 DC::UI::set_layout ($::CFG->{layout});
3047 $PROFILE->{user} = $args[1] if @args > 1;
3048 $PROFILE->{password} = $args[2] if @args > 2;
3049 2980
3050 # convert old bindings (only default profile matters) 2981 my @args = @ARGV;
3051 if (my $bindings = delete $PROFILE->{bindings}) { 2982
3052 while (my ($mod, $syms) = each %$bindings) { 2983 # OS X passes some process serial number of other shit. they
3053 while (my ($sym, $cmds) = each %$syms) { 2984 # could have used an env var or any other sane mechanism. but
3054 push @{ $PROFILE->{macro} }, { 2985 # would it be os x then? no...
3055 accelkey => [$mod*1, $sym*1], 2986 shift @args if $args[0] =~ /^-psn_/;
3056 action => $cmds, 2987
2988 my $profile = 'default';
2989
2990 for (my $i = 0; $i < @args; $i++) {
2991 if ($args[$i] =~ /^--?profile$/) {
2992 $profile = $args[$i + 1];
2993 splice @args, $i, 2, ();
3057 }; 2994 $i = 0;
2995 } elsif ($args[$i] =~ /^--?h/) {
2996 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2997 exit 0;
3058 } 2998 }
3059 } 2999 }
3000
3001 $CFG->{profile}{$profile} ||= {};
3002 $PROFILE = $CFG->{profile}{$profile};
3003 $PROFILE->{host} ||= "gameserver.deliantra.net";
3004
3005 $PROFILE->{host} = $args[0] if @args > 0;
3006 $PROFILE->{user} = $args[1] if @args > 1;
3007 $PROFILE->{password} = $args[2] if @args > 2;
3008
3009 # convert old bindings (only default profile matters)
3010 if (my $bindings = delete $PROFILE->{bindings}) {
3011 while (my ($mod, $syms) = each %$bindings) {
3012 while (my ($sym, $cmds) = each %$syms) {
3013 push @{ $PROFILE->{macro} }, {
3014 accelkey => [$mod*1, $sym*1],
3015 action => $cmds,
3016 };
3017 }
3018 }
3060 } 3019 }
3061 3020
3062 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3021 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3063 # these are ignored under windows, for some reason, and thus set in the loader 3022 # these are ignored under windows, for some reason, and thus set in the loader
3064 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3023 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3065 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3024 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3066 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3025 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3067 3026
3068 { 3027 {
3069 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3028 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3070 DejaVuSans.ttf 3029 DejaVuSans.ttf
3071 DejaVuSansMono.ttf 3030 DejaVuSansMono.ttf
3072 DejaVuSans-Bold.ttf 3031 DejaVuSans-Bold.ttf
3073 DejaVuSansMono-Bold.ttf 3032 DejaVuSansMono-Bold.ttf
3074 DejaVuSans-Oblique.ttf 3033 DejaVuSans-Oblique.ttf
3075 DejaVuSansMono-Oblique.ttf 3034 DejaVuSansMono-Oblique.ttf
3076 DejaVuSans-BoldOblique.ttf 3035 DejaVuSans-BoldOblique.ttf
3077 DejaVuSansMono-BoldOblique.ttf 3036 DejaVuSansMono-BoldOblique.ttf
3078 mona.ttf 3037 mona.ttf
3079 ); 3038 );
3080 3039
3081 DC::add_font $_ for @fonts; 3040 DC::add_font $_ for @fonts;
3082 3041
3083 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3042 $FONT_PROP = new_from_file DC::Font $fonts[0];
3084 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3043 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3085 3044
3086 $FONT_PROP->make_default; 3045 $FONT_PROP->make_default;
3087 3046
3088 DC::pango_init; 3047 DC::pango_init;
3089 } 3048 }
3090 3049
3091# compare mono (ft) vs. rgba (cairo) 3050# compare mono (ft) vs. rgba (cairo)
3092# ft - 1.8s, cairo 3s, even in alpha-only mode 3051# ft - 1.8s, cairo 3s, even in alpha-only mode
3093# for my $rgba (0..1) { 3052# for my $rgba (0..1) {
3094# my $t1 = Time::HiRes::time; 3053# my $t1 = Time::HiRes::time;
3099# } 3058# }
3100# my $t2 = Time::HiRes::time; 3059# my $t2 = Time::HiRes::time;
3101# warn $t2-$t1; 3060# warn $t2-$t1;
3102# } 3061# }
3103 3062
3063 }
3064
3065 DC::SDL_Init 0;
3104 DC::IMG_Init; video_init; 3066 DC::IMG_Init; video_init;
3105 DC::Mix_Init; audio_init; 3067 DC::Mix_Init; audio_init;
3106 }
3107 3068
3108 show_tip_of_the_day if $CFG->{show_tips}; 3069 show_tip_of_the_day if $CFG->{show_tips};
3109 3070
3110 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3071 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3111 undef $STARTUP_CANCEL; 3072 undef $STARTUP_CANCEL;
3112 (pop @::STARTUP_DONE)->() 3073 (pop @::STARTUP_DONE)->()
3113 while @::STARTUP_DONE; 3074 while @::STARTUP_DONE;
3075 };
3076
3077 debug_toggle 0;
3078
3079 delete $SIG{__DIE__};
3080 EV::loop;
3081
3082 DC::save_cfg if $CFG->{config_autosave};
3083
3084 #video_shutdown;
3085 #audio_shutdown;
3086
3087 DC::OpenGL::quit;
3088 DC::SDL_Quit;
3089 DC::DB::Server::stop;
3114 }; 3090 };
3115
3116 debug_toggle 0;
3117
3118 delete $SIG{__DIE__};
3119 EV::loop;
3120
3121 DC::write_cfg if $CFG->{config_autosave};
3122
3123 #video_shutdown;
3124 #audio_shutdown;
3125
3126 DC::OpenGL::quit;
3127 DC::SDL_Quit;
3128 DC::DB::Server::stop;
3129} 3091}
3130
3131*DC::Main::run = \&DC::SDL_braino; # see sub above
3132 3092
31331 30931

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines