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.5 by root, Fri Dec 30 10:59:00 2011 UTC vs.
Revision 1.18 by root, Wed Jan 18 15:31:51 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
56 DC::fatal Carp::longmess "$_[0]"; 57 DC::fatal Carp::longmess "$_[0]";
57 } 58 }
58} 59}
59 60
60use DC::OpenGL (); 61use DC::OpenGL ();
62use DC::Audio ();
61use DC::Protocol; 63use DC::Protocol;
62use DC::DB; 64use DC::DB;
63use DC::UI; 65use DC::UI;
64use DC::UI::Canvas; 66use DC::UI::Canvas;
65use DC::UI::Inventory; 67use DC::UI::Inventory;
142our $PL_NOTEBOOK; 144our $PL_NOTEBOOK;
143our $PL_WINDOW; 145our $PL_WINDOW;
144 146
145our $MUSIC_PLAYING_WIDGET; 147our $MUSIC_PLAYING_WIDGET;
146our $LICENSE_WIDGET; 148our $LICENSE_WIDGET;
149our $DOWNLOADS_WIDGET;
147 150
148our $PICKUP_PAGE; 151our $PICKUP_PAGE;
149our $INVENTORY_PAGE; 152our $INVENTORY_PAGE;
150our $STATS_PAGE; 153our $STATS_PAGE;
151our $SKILL_PAGE; 154our $SKILL_PAGE;
194 AnyEvent::Util::fh_nonblocking $fh, 1; 197 AnyEvent::Util::fh_nonblocking $fh, 1;
195 198
196 $msg =~ s/\s+$//; 199 $msg =~ s/\s+$//;
197 200
198 # backtrace as second step, in case it crashes, too 201 # backtrace as second step, in case it crashes, too
199 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" 202 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated"
200 if $backtrace; 203 if $backtrace;
201}; 204};
202 205
203sub clienterror($;$) { 206sub clienterror($;$) {
204 my ($msg, $backtrace) = @_; 207 my ($msg, $backtrace) = @_;
206 warn $msg; 209 warn $msg;
207 210
208 return unless $CONN; 211 return unless $CONN;
209 212
210 $CONN->send_exti_msg (clientlog => $msg); 213 $CONN->send_exti_msg (clientlog => $msg);
211 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; 214 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace;
212} 215}
213 216
214############################################################################# 217#############################################################################
215 218
216sub status { 219sub status {
471 audio_music_push; 474 audio_music_push;
472} 475}
473 476
474sub audio_init { 477sub audio_init {
475 if ($CFG->{audio_enable}) { 478 if ($CFG->{audio_enable}) {
476 if (length $CFG->{audio_driver}) { 479 DC::Audio::init $CFG->{audio_driver};
477 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
478 DC::SDL_Init DC::SDL_INIT_AUDIO
479 and die "SDL::Init failed!\n";
480 } else {
481 DC::SDL_Init DC::SDL_INIT_AUDIO
482 and die "SDL::Init failed!\n";
483 }
484
485 $ENV{MIX_EFFECTSMAXSPEED} = 1;
486 $SDL_MIXER = !DC::Mix_OpenAudio
487 $CFG->{audio_hw_frequency},
488 DC::MIX_DEFAULT_FORMAT,
489 $CFG->{audio_hw_channels},
490 $CFG->{audio_hw_chunksize};
491 480
492 if ($SDL_MIXER) { 481 if ($SDL_MIXER) {
493 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
494
495 audio_music_finished; 482 audio_music_finished;
496 } else { 483 } else {
497 status "Unable to open sound device: there will be no sound"; 484 status "Unable to open sound device: there will be no sound";
498 } 485 }
499 } else { 486 } else {
521 508
522 DC::Mix_CloseAudio if $SDL_MIXER; 509 DC::Mix_CloseAudio if $SDL_MIXER;
523 undef $SDL_MIXER; 510 undef $SDL_MIXER;
524 511
525 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 512 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
513}
514
515#############################################################################
516# Over-the-air updates
517
518sub ota_update {
519 my ($face, $size, $md5) = @_;
520
521 my $coro = Coro::async_pool {
522 my $override = "$Urlader::EXE_DIR/override";
523
524 $MESSAGE_DIST->add_channel ({
525 id => "ota_update",
526 title => "Update",
527 tooltip => "<b>Software Update Log</b>",
528 });
529
530 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
531
532 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
533
534 unless ($fh) {
535 $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") });
536 return;
537 }
538
539 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
540
541 my $cv = AE::cv;
542 my $error;
543
544 $cv->begin (Coro::rouse_cb);
545 $CONN->ask_face (
546 $face,
547 -1000,
548 sub {
549 $STATUSBOX->add (
550 (sprintf "update download: %d/%d", $size - $_[1], $size),
551 pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1]
552 );
553
554 $cv->begin;
555 my $len = length $_[2];
556 IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub {
557 $error ||= $_[0] != $len;
558 $cv->end;
559 };
560 },
561 sub {
562 $cv->end;
563 },
564 );
565
566 Coro::rouse_wait;
567
568 $STATUSBOX->clr_group ("ota_update");
569
570 $error ||= Coro::AIO::aio_fsync $fh;
571 $error ||= Coro::AIO::aio_close $fh;
572
573 if ($error) {
574 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
575 Coro::AIO::aio_unlink "$override.tmp";
576 return;
577 }
578
579 {
580 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verifying update file..." });
581
582 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
583
584 if ($fh) {
585 $error ||= Coro::AIO::aio_stat "$override.tmp";
586 $error ||= -s _ != $size;
587 Coro::AIO::aio_readahead $fh, 0, $size;
588
589 my $f_md5 = new Digest::MD5;
590 binmode $fh; # ugh :(
591 $f_md5->addfile ($fh);
592 $f_md5 = $f_md5->hexdigest;
593 $error ||= $md5 ne $f_md5;
594 }
595 }
596
597 if ($error) {
598 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." });
599 Coro::AIO::aio_unlink "$override.tmp";
600 return;
601 }
602
603 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
604
605 if (Coro::AIO::aio_rename "$override.tmp", $override) {
606 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
607 Coro::AIO::aio_unlink "$override.tmp";
608 }
609
610 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
611 };
612
613 $CONN->{ota_update} = Guard::guard {
614 $coro->cancel;
615 };
616}
617
618sub ota_update_ask {
619 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
620
621 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
622 x => "center",
623 y => "center",
624 z => 55,
625 force_w => $::WIDTH * 0.7,
626 force_h => $::HEIGHT * 0.7,
627 title => "Software update available",
628 child => my $vbox = new DC::UI::VBox,
629 ;
630
631 $vbox->add (new DC::UI::Label
632 ellipsise => 0,
633 text => "The server offers a software update, "
634 . "do you want to start downloading this update in the background?",
635 );
636
637 $vbox->add (new DC::UI::FancyFrame
638 expand => 1,
639 label => "Details",
640 child => (new DC::UI::TextScroller
641 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
642 par => [{
643 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
644 . "New revision: $ver\n"
645 . "Download size: $size bytes</tt>\n\n"
646 . "Changes:\n\n"
647 . DC::asxml $changes
648 }],
649 ),
650 );
651
652 $vbox->add (my $hbox = new DC::UI::HBox);
653
654 $hbox->add (new DC::UI::Button
655 expand => 1,
656 text => "Not now",
657 on_activate => sub {
658 $dialog->destroy;
659 0
660 }
661 );
662 $hbox->add (new DC::UI::Button
663 expand => 1,
664 text => "Yes, start downloading",
665 on_activate => sub {
666 $dialog->destroy;
667 ota_update $face, $size, $md5;
668 0
669 },
670 );
671
672 $dialog->show;
673}
674
675sub ota_update_check {
676 return unless defined $Urlader::EXE_ID;
677
678 ::message { markup => "Checking for software update..." };
679
680 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
681 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
682
683 if ($ok) {
684 if (defined $ver) {
685 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
686 &ota_update_ask;
687 } else {
688 ::message { markup => "Server has no newer version." };
689 }
690 } else {
691 ::message { markup => "Server does not support software update." };
692 }
693
694# $self->register_face_handler ($exp_table, sub {
695# my ($face) = @_;
696
697# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
698# $_->() for values %{ $self->{on_exp_update} || {} };
699# });
700
701 ()
702 });
526} 703}
527 704
528############################################################################# 705#############################################################################
529 706
530sub destroy_query_dialog { 707sub destroy_query_dialog {
773 mapw => $mapw, 950 mapw => $mapw,
774 maph => $maph, 951 maph => $maph,
775 952
776 c_version => { 953 c_version => {
777 client => "deliantra", 954 client => "deliantra",
778 clientver => $DC::VERSION, 955 clientver => "$DC::VERSION$Urlader::EXE_VER",
779 gl_vendor => DC::OpenGL::gl_vendor, 956 gl_vendor => DC::OpenGL::gl_vendor,
780 gl_version => DC::OpenGL::gl_version, 957 gl_version => DC::OpenGL::gl_version,
781 }, 958 },
782 959
783 map_widget => $MAPWIDGET, 960 map_widget => $MAPWIDGET,
791 }, 968 },
792 969
793 on_connect => sub { 970 on_connect => sub {
794 if ($_[0]) { 971 if ($_[0]) {
795 DC::lowdelay fileno $CONN->{fh}; 972 DC::lowdelay fileno $CONN->{fh};
973
974 ota_update_check;
796 975
797 status "successfully connected to the server"; 976 status "successfully connected to the server";
798 } else { 977 } else {
799 undef $CONN; 978 undef $CONN;
800 status "unable to connect: $!"; 979 status "unable to connect: $!";
1835 $table->add_at (2, $row++, new DC::UI::Button 2014 $table->add_at (2, $row++, new DC::UI::Button
1836 text => "Save Now", 2015 text => "Save Now",
1837 tooltip => "Use this to manually save configuration and UI layout when " 2016 tooltip => "Use this to manually save configuration and UI layout when "
1838 . "autosave is disabled.", 2017 . "autosave is disabled.",
1839 on_activate => sub { 2018 on_activate => sub {
1840 DC::write_cfg; 2019 DC::save_cfg;
1841 0 2020 0
1842 } 2021 }
1843 ); 2022 );
1844 } 2023 }
1845 2024
1854 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
1855 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)"); 2034 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
1856 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => ""); 2035 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1857 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); 2036 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
1858 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => ""); 2037 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1859 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); 2038 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
1860 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => ""); 2039 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1861 } 2040 }
1862 2041
1863 $vbox 2042 $vbox
1864} 2043}
2039 2218
2040sub media_window { 2219sub media_window {
2041 my $vb = new DC::UI::VBox; 2220 my $vb = new DC::UI::VBox;
2042 2221
2043 $vb->add (new DC::UI::FancyFrame 2222 $vb->add (new DC::UI::FancyFrame
2044 label => "Currently playing music", 2223 label => "Current background music",
2045 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2224 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2046 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), 2225 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2047 ); 2226 );
2227
2228 $vb->add (new DC::UI::FancyFrame
2229 label => "Current downloads",
2230 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2231 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2232 );
2233
2234 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2235 my ($self) = @_;
2236
2237 delete $self->{updater};
2238 return unless $_[1];
2239
2240 $self->{updater} = AE::timer 0, 0.7, sub {
2241 $self->clear;
2242
2243 return unless $CONN;
2244
2245 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2246 return unless @nums;
2247
2248 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2249 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2250
2251 for my $row (0 .. $#nums) {
2252 my $num = $nums[$row];
2253
2254 my $total = length $CONN->{ix_recv_buf}{$num};
2255 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2256
2257 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2258 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2259 }
2260 };
2261 });
2048 2262
2049 $vb->add (new DC::UI::FancyFrame 2263 $vb->add (new DC::UI::FancyFrame
2050 label => "Other media used in this session", 2264 label => "Other media used in this session",
2051 expand => 1, 2265 expand => 1,
2052 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2266 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2053 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2267 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2054 ); 2268 );
2055 2269
2056 $vb 2270 $vb
2057} 2271}
2058 2272
2243sub open_quit_dialog { 2457sub open_quit_dialog {
2244 unless ($QUIT_DIALOG) { 2458 unless ($QUIT_DIALOG) {
2245 $QUIT_DIALOG = new DC::UI::Toplevel 2459 $QUIT_DIALOG = new DC::UI::Toplevel
2246 x => "center", 2460 x => "center",
2247 y => "center", 2461 y => "center",
2248 z => 50, 2462 z => 60,
2249 title => "Really Quit?", 2463 title => "Really Quit?",
2250 on_key_down => sub { 2464 on_key_down => sub {
2251 my ($dialog, $ev) = @_; 2465 my ($dialog, $ev) = @_;
2252 $ev->{sym} == 27 and $dialog->hide; 2466 $ev->{sym} == 27 and $dialog->hide;
2253 } 2467 }
2469 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2683 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2470 2684
2471 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2685 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2472 $FULLSCREEN = $CFG->{fullscreen}; 2686 $FULLSCREEN = $CFG->{fullscreen};
2473 $FAST = $CFG->{fast}; 2687 $FAST = $CFG->{fast};
2688
2689 DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init
2474 2690
2475 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error 2691 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error
2476 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2692 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2477 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2693 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2478 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2694 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2736 EV::unloop; 2952 EV::unloop;
2737 #d# TODO calling exit here hangs the process in some futex 2953 #d# TODO calling exit here hangs the process in some futex
2738}; 2954};
2739 2955
2740# due to mac os x + sdl combined braindamage, we need this contortion 2956# due to mac os x + sdl combined braindamage, we need this contortion
2741sub DC::Main::main { 2957sub DC::Main::run {
2742 { 2958 DC::SDL_main_hack {
2959 {
2743 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2960 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2744 2961
2745 if (-e "$Deliantra::VARDIR/client.cf") { 2962 DC::load_cfg;
2746 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2963 DC::upgrade_cfg;
2747 } else {
2748 #TODO: compatibility cruft
2749 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2750 print STDERR "INFO: used old configuration file\n";
2751 }
2752 2964
2965 DC::Audio::probe;
2966
2753 DC::DB::Server::run; 2967 DC::DB::Server::run;
2754 2968
2755 if ($CFG->{db_schema} < 1) { 2969 if ($CFG->{db_schema} < 1) {
2756 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2970 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2757 DC::DB::nuke_db; 2971 DC::DB::nuke_db;
2758 $CFG->{db_schema} = 1; 2972 $CFG->{db_schema} = 1;
2759 DC::write_cfg; 2973 DC::save_cfg;
2760 }
2761
2762 DC::DB::open_db;
2763
2764 DC::UI::set_layout ($::CFG->{layout});
2765
2766 my %DEF_CFG = (
2767 config_autosave => 1,
2768 sdl_mode => undef,
2769 fullscreen => 1,
2770 fast => 0,
2771 force_opengl11 => undef,
2772 disable_alpha => 0,
2773 smooth_movement => 1,
2774 smooth_transitions => 1,
2775 texture_compression => 1,
2776 map_scale => 1,
2777 fow_enable => 1,
2778 fow_intensity => 0,
2779 fow_texture => 0,
2780 map_smoothing => 1,
2781 gui_fontsize => 1,
2782 log_fontsize => 0.7,
2783 gauge_fontsize => 1,
2784 gauge_size => 0.35,
2785 stat_fontsize => 0.7,
2786 mapsize => 100,
2787 audio_enable => 1,
2788 audio_hw_channels => 0,
2789 audio_hw_frequency => 0,
2790 audio_hw_chunksize => 0,
2791 audio_mix_channels => 8,
2792 effects_enable => 1,
2793 effects_volume => 1,
2794 bgm_enable => 1,
2795 bgm_volume => 0.5,
2796 output_rate => "",
2797 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
2798 inv_sort => "mtime",
2799 default => "profile", # default profile
2800 show_tips => 1,
2801 logview_max_par => 1000,
2802 shift_fire_stop => 0,
2803 uitheme => "wood",
2804 map_shift_x => -24, # arbitrary
2805 map_shift_y => +24, # arbitrary
2806 );
2807
2808 while (my ($k, $v) = each %DEF_CFG) {
2809 $CFG->{$k} = $v unless exists $CFG->{$k};
2810 }
2811
2812 my @args = @ARGV;
2813
2814 # OS X passes some process serial number of other shit. they
2815 # could have used an env var or any other sane mechanism. but
2816 # would it be os x then? no...
2817 shift @args if $args[0] =~ /^-psn_/;
2818
2819 my $profile = 'default';
2820
2821 for (my $i = 0; $i < @args; $i++) {
2822 if ($args[$i] =~ /^--?profile$/) {
2823 $profile = $args[$i + 1];
2824 splice @args, $i, 2, ();
2825 $i = 0;
2826 } elsif ($args[$i] =~ /^--?h/) {
2827 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2828 exit 0;
2829 } 2974 }
2830 }
2831 2975
2832 $CFG->{profile}{$profile} ||= {}; 2976 DC::DB::open_db;
2833 $PROFILE = $CFG->{profile}{$profile};
2834 $PROFILE->{host} ||= "gameserver.deliantra.net";
2835 2977
2836 $PROFILE->{host} = $args[0] if @args > 0; 2978 DC::UI::set_layout ($::CFG->{layout});
2837 $PROFILE->{user} = $args[1] if @args > 1;
2838 $PROFILE->{password} = $args[2] if @args > 2;
2839 2979
2840 # convert old bindings (only default profile matters) 2980 my @args = @ARGV;
2841 if (my $bindings = delete $PROFILE->{bindings}) { 2981
2842 while (my ($mod, $syms) = each %$bindings) { 2982 # OS X passes some process serial number of other shit. they
2843 while (my ($sym, $cmds) = each %$syms) { 2983 # could have used an env var or any other sane mechanism. but
2844 push @{ $PROFILE->{macro} }, { 2984 # would it be os x then? no...
2845 accelkey => [$mod*1, $sym*1], 2985 shift @args if $args[0] =~ /^-psn_/;
2846 action => $cmds, 2986
2987 my $profile = 'default';
2988
2989 for (my $i = 0; $i < @args; $i++) {
2990 if ($args[$i] =~ /^--?profile$/) {
2991 $profile = $args[$i + 1];
2992 splice @args, $i, 2, ();
2847 }; 2993 $i = 0;
2994 } elsif ($args[$i] =~ /^--?h/) {
2995 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2996 exit 0;
2848 } 2997 }
2849 } 2998 }
2999
3000 $CFG->{profile}{$profile} ||= {};
3001 $PROFILE = $CFG->{profile}{$profile};
3002 $PROFILE->{host} ||= "gameserver.deliantra.net";
3003
3004 $PROFILE->{host} = $args[0] if @args > 0;
3005 $PROFILE->{user} = $args[1] if @args > 1;
3006 $PROFILE->{password} = $args[2] if @args > 2;
3007
3008 # convert old bindings (only default profile matters)
3009 if (my $bindings = delete $PROFILE->{bindings}) {
3010 while (my ($mod, $syms) = each %$bindings) {
3011 while (my ($sym, $cmds) = each %$syms) {
3012 push @{ $PROFILE->{macro} }, {
3013 accelkey => [$mod*1, $sym*1],
3014 action => $cmds,
3015 };
3016 }
3017 }
2850 } 3018 }
2851 3019
2852 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3020 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
2853 # these are ignored under windows, for some reason, and thus set in the loader 3021 # these are ignored under windows, for some reason, and thus set in the loader
2854 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3022 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2855 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3023 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
2856 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3024 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2857 3025
2858 { 3026 {
2859 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3027 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2860 DejaVuSans.ttf 3028 DejaVuSans.ttf
2861 DejaVuSansMono.ttf 3029 DejaVuSansMono.ttf
2862 DejaVuSans-Bold.ttf 3030 DejaVuSans-Bold.ttf
2863 DejaVuSansMono-Bold.ttf 3031 DejaVuSansMono-Bold.ttf
2864 DejaVuSans-Oblique.ttf 3032 DejaVuSans-Oblique.ttf
2865 DejaVuSansMono-Oblique.ttf 3033 DejaVuSansMono-Oblique.ttf
2866 DejaVuSans-BoldOblique.ttf 3034 DejaVuSans-BoldOblique.ttf
2867 DejaVuSansMono-BoldOblique.ttf 3035 DejaVuSansMono-BoldOblique.ttf
2868 mona.ttf 3036 mona.ttf
2869 ); 3037 );
2870 3038
2871 DC::add_font $_ for @fonts; 3039 DC::add_font $_ for @fonts;
2872 3040
2873 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3041 $FONT_PROP = new_from_file DC::Font $fonts[0];
2874 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3042 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2875 3043
2876 $FONT_PROP->make_default; 3044 $FONT_PROP->make_default;
2877 3045
2878 DC::pango_init; 3046 DC::pango_init;
2879 } 3047 }
2880 3048
2881# compare mono (ft) vs. rgba (cairo) 3049# compare mono (ft) vs. rgba (cairo)
2882# ft - 1.8s, cairo 3s, even in alpha-only mode 3050# ft - 1.8s, cairo 3s, even in alpha-only mode
2883# for my $rgba (0..1) { 3051# for my $rgba (0..1) {
2884# my $t1 = Time::HiRes::time; 3052# my $t1 = Time::HiRes::time;
2889# } 3057# }
2890# my $t2 = Time::HiRes::time; 3058# my $t2 = Time::HiRes::time;
2891# warn $t2-$t1; 3059# warn $t2-$t1;
2892# } 3060# }
2893 3061
3062 }
3063
3064 DC::SDL_Init 0;
2894 DC::IMG_Init; video_init; 3065 DC::IMG_Init; video_init;
2895 DC::Mix_Init; audio_init; 3066 DC::Mix_Init; audio_init;
2896 }
2897 3067
2898 show_tip_of_the_day if $CFG->{show_tips}; 3068 show_tip_of_the_day if $CFG->{show_tips};
2899 3069
2900 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3070 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
2901 undef $STARTUP_CANCEL; 3071 undef $STARTUP_CANCEL;
2902 (pop @::STARTUP_DONE)->() 3072 (pop @::STARTUP_DONE)->()
2903 while @::STARTUP_DONE; 3073 while @::STARTUP_DONE;
3074 };
3075
3076 debug_toggle 0;
3077
3078 delete $SIG{__DIE__};
3079 EV::loop;
3080
3081 DC::save_cfg if $CFG->{config_autosave};
3082
3083 #video_shutdown;
3084 #audio_shutdown;
3085
3086 DC::OpenGL::quit;
3087 DC::SDL_Quit;
3088 DC::DB::Server::stop;
2904 }; 3089 };
2905
2906 debug_toggle 0;
2907
2908 delete $SIG{__DIE__};
2909 EV::loop;
2910
2911 DC::write_cfg if $CFG->{config_autosave};
2912
2913 #video_shutdown;
2914 #audio_shutdown;
2915
2916 DC::OpenGL::quit;
2917 DC::SDL_Quit;
2918 DC::DB::Server::stop;
2919} 3090}
2920
2921*DC::Main::run = \&DC::SDL_braino; # see sub above
2922 3091
29231 30921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines