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.3 by root, Thu Dec 29 07:13:44 2011 UTC vs.
Revision 1.19 by root, Thu Jan 26 20:11:14 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
42} 44}
43 45
44BEGIN { 46BEGIN {
45 $SIG{__DIE__} = sub { 47 $SIG{__DIE__} = sub {
46 return if $^S; 48 return if $^S; # quick reject
49
50 # return if there are any eval contexts in the csall stack
51 for my $i (0..999) {
52 my ($sub, $is_require) = (caller $i)[3, 7]
53 or last;
54 return if $sub eq "(eval)" && !$is_require;
55 }
56
47 crash "CRASH/DIE: $_[0]" => 1; 57 crash "CRASH/DIE: $_[0]" => 1;
48 DC::fatal Carp::longmess "$_[0]"; 58 DC::fatal Carp::longmess "$_[0]";
49 } 59 }
50} 60}
51 61
52use DC::OpenGL (); 62use DC::OpenGL ();
63use DC::Audio ();
53use DC::Protocol; 64use DC::Protocol;
54use DC::DB; 65use DC::DB;
55use DC::UI; 66use DC::UI;
56use DC::UI::Canvas; 67use DC::UI::Canvas;
57use DC::UI::Inventory; 68use DC::UI::Inventory;
134our $PL_NOTEBOOK; 145our $PL_NOTEBOOK;
135our $PL_WINDOW; 146our $PL_WINDOW;
136 147
137our $MUSIC_PLAYING_WIDGET; 148our $MUSIC_PLAYING_WIDGET;
138our $LICENSE_WIDGET; 149our $LICENSE_WIDGET;
150our $DOWNLOADS_WIDGET;
139 151
140our $PICKUP_PAGE; 152our $PICKUP_PAGE;
141our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
142our $STATS_PAGE; 154our $STATS_PAGE;
143our $SKILL_PAGE; 155our $SKILL_PAGE;
186 AnyEvent::Util::fh_nonblocking $fh, 1; 198 AnyEvent::Util::fh_nonblocking $fh, 1;
187 199
188 $msg =~ s/\s+$//; 200 $msg =~ s/\s+$//;
189 201
190 # backtrace as second step, in case it crashes, too 202 # backtrace as second step, in case it crashes, too
191 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"
192 if $backtrace; 204 if $backtrace;
193}; 205};
194 206
195sub clienterror($;$) { 207sub clienterror($;$) {
196 my ($msg, $backtrace) = @_; 208 my ($msg, $backtrace) = @_;
198 warn $msg; 210 warn $msg;
199 211
200 return unless $CONN; 212 return unless $CONN;
201 213
202 $CONN->send_exti_msg (clientlog => $msg); 214 $CONN->send_exti_msg (clientlog => $msg);
203 $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;
204} 216}
205 217
206############################################################################# 218#############################################################################
207 219
208sub status { 220sub status {
463 audio_music_push; 475 audio_music_push;
464} 476}
465 477
466sub audio_init { 478sub audio_init {
467 if ($CFG->{audio_enable}) { 479 if ($CFG->{audio_enable}) {
468 if (length $CFG->{audio_driver}) { 480 DC::Audio::init $CFG->{audio_driver};
469 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
470 DC::SDL_Init DC::SDL_INIT_AUDIO
471 and die "SDL::Init failed!\n";
472 } else {
473 DC::SDL_Init DC::SDL_INIT_AUDIO
474 and die "SDL::Init failed!\n";
475 }
476
477 $ENV{MIX_EFFECTSMAXSPEED} = 1;
478 $SDL_MIXER = !DC::Mix_OpenAudio
479 $CFG->{audio_hw_frequency},
480 DC::MIX_DEFAULT_FORMAT,
481 $CFG->{audio_hw_channels},
482 $CFG->{audio_hw_chunksize};
483 481
484 if ($SDL_MIXER) { 482 if ($SDL_MIXER) {
485 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
486
487 audio_music_finished; 483 audio_music_finished;
488 } else { 484 } else {
489 status "Unable to open sound device: there will be no sound"; 485 status "Unable to open sound device: there will be no sound";
490 } 486 }
491 } else { 487 } else {
513 509
514 DC::Mix_CloseAudio if $SDL_MIXER; 510 DC::Mix_CloseAudio if $SDL_MIXER;
515 undef $SDL_MIXER; 511 undef $SDL_MIXER;
516 512
517 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 513 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
514}
515
516#############################################################################
517# Over-the-air updates
518
519sub ota_update {
520 my ($face, $size, $md5) = @_;
521
522 my $coro = Coro::async_pool {
523 my $override = "$Urlader::EXE_DIR/override";
524
525 $MESSAGE_DIST->add_channel ({
526 id => "ota_update",
527 title => "Update",
528 tooltip => "<b>Software Update Log</b>",
529 });
530
531 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
532
533 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
534
535 unless ($fh) {
536 $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") });
537 return;
538 }
539
540 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
541
542 my $cv = AE::cv;
543 my $error;
544
545 $cv->begin (Coro::rouse_cb);
546 $CONN->ask_face (
547 $face,
548 -1000,
549 sub {
550 $STATUSBOX->add (
551 (sprintf "update download: %d/%d", $size - $_[1], $size),
552 pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1]
553 );
554
555 $cv->begin;
556 my $len = length $_[2];
557 IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub {
558 $error ||= $_[0] != $len;
559 $cv->end;
560 };
561 },
562 sub {
563 $cv->end;
564 },
565 );
566
567 Coro::rouse_wait;
568
569 $STATUSBOX->clr_group ("ota_update");
570
571 $error ||= Coro::AIO::aio_fsync $fh;
572 $error ||= Coro::AIO::aio_close $fh;
573
574 if ($error) {
575 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
576 Coro::AIO::aio_unlink "$override.tmp";
577 return;
578 }
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
604 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
605
606 if (Coro::AIO::aio_rename "$override.tmp", $override) {
607 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
608 Coro::AIO::aio_unlink "$override.tmp";
609 }
610
611 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
612 };
613
614 $CONN->{ota_update} = Guard::guard {
615 $coro->cancel;
616 };
617}
618
619sub ota_update_ask {
620 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
621
622 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
623 x => "center",
624 y => "center",
625 z => 55,
626 force_w => $::WIDTH * 0.7,
627 force_h => $::HEIGHT * 0.7,
628 title => "Software update available",
629 child => my $vbox = new DC::UI::VBox,
630 ;
631
632 $vbox->add (new DC::UI::Label
633 ellipsise => 0,
634 text => "The server offers a software update, "
635 . "do you want to start downloading this update in the background?",
636 );
637
638 $vbox->add (new DC::UI::FancyFrame
639 expand => 1,
640 label => "Details",
641 child => (new DC::UI::TextScroller
642 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
643 par => [{
644 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
645 . "New revision: $ver\n"
646 . "Download size: $size bytes</tt>\n\n"
647 . "Changes:\n\n"
648 . DC::asxml $changes
649 }],
650 ),
651 );
652
653 $vbox->add (my $hbox = new DC::UI::HBox);
654
655 $hbox->add (new DC::UI::Button
656 expand => 1,
657 text => "Not now",
658 on_activate => sub {
659 $dialog->destroy;
660 0
661 }
662 );
663 $hbox->add (new DC::UI::Button
664 expand => 1,
665 text => "Yes, start downloading",
666 on_activate => sub {
667 $dialog->destroy;
668 ota_update $face, $size, $md5;
669 0
670 },
671 );
672
673 $dialog->show;
674}
675
676sub ota_update_check {
677 return unless defined $Urlader::EXE_ID;
678
679 ::message { markup => "Checking for software update..." };
680
681 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
682 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
683
684 if ($ok) {
685 if (defined $ver) {
686 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
687 &ota_update_ask;
688 } else {
689 ::message { markup => "Server has no newer version." };
690 }
691 } else {
692 ::message { markup => "Server does not support software update." };
693 }
694
695# $self->register_face_handler ($exp_table, sub {
696# my ($face) = @_;
697
698# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
699# $_->() for values %{ $self->{on_exp_update} || {} };
700# });
701
702 ()
703 });
518} 704}
519 705
520############################################################################# 706#############################################################################
521 707
522sub destroy_query_dialog { 708sub destroy_query_dialog {
765 mapw => $mapw, 951 mapw => $mapw,
766 maph => $maph, 952 maph => $maph,
767 953
768 c_version => { 954 c_version => {
769 client => "deliantra", 955 client => "deliantra",
770 clientver => $DC::VERSION, 956 clientver => "$DC::VERSION$Urlader::EXE_VER",
771 gl_vendor => DC::OpenGL::gl_vendor, 957 gl_vendor => DC::OpenGL::gl_vendor,
772 gl_version => DC::OpenGL::gl_version, 958 gl_version => DC::OpenGL::gl_version,
773 }, 959 },
774 960
775 map_widget => $MAPWIDGET, 961 map_widget => $MAPWIDGET,
783 }, 969 },
784 970
785 on_connect => sub { 971 on_connect => sub {
786 if ($_[0]) { 972 if ($_[0]) {
787 DC::lowdelay fileno $CONN->{fh}; 973 DC::lowdelay fileno $CONN->{fh};
974
975 ota_update_check;
788 976
789 status "successfully connected to the server"; 977 status "successfully connected to the server";
790 } else { 978 } else {
791 undef $CONN; 979 undef $CONN;
792 status "unable to connect: $!"; 980 status "unable to connect: $!";
1827 $table->add_at (2, $row++, new DC::UI::Button 2015 $table->add_at (2, $row++, new DC::UI::Button
1828 text => "Save Now", 2016 text => "Save Now",
1829 tooltip => "Use this to manually save configuration and UI layout when " 2017 tooltip => "Use this to manually save configuration and UI layout when "
1830 . "autosave is disabled.", 2018 . "autosave is disabled.",
1831 on_activate => sub { 2019 on_activate => sub {
1832 DC::write_cfg; 2020 DC::save_cfg;
1833 0 2021 0
1834 } 2022 }
1835 ); 2023 );
1836 } 2024 }
1837 2025
1842 2030
1843 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); 2031 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
1844 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); 2032 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
1845 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); 2033 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
1846 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2034 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2035 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2036 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1847 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); 2037 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
1848 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_ID, tooltip => ""); 2038 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1849 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); 2039 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
1850 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_VER, tooltip => ""); 2040 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1851 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Update (Prebuilt)");
1852 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::UPDPAR, tooltip => "");
1853 } 2041 }
1854 2042
1855 $vbox 2043 $vbox
1856} 2044}
1857 2045
2031 2219
2032sub media_window { 2220sub media_window {
2033 my $vb = new DC::UI::VBox; 2221 my $vb = new DC::UI::VBox;
2034 2222
2035 $vb->add (new DC::UI::FancyFrame 2223 $vb->add (new DC::UI::FancyFrame
2036 label => "Currently playing music", 2224 label => "Current background music",
2037 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2225 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2038 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), 2226 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2039 ); 2227 );
2228
2229 $vb->add (new DC::UI::FancyFrame
2230 label => "Current downloads",
2231 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2232 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2233 );
2234
2235 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2236 my ($self) = @_;
2237
2238 delete $self->{updater};
2239 return unless $_[1];
2240
2241 $self->{updater} = AE::timer 0, 0.7, sub {
2242 $self->clear;
2243
2244 return unless $CONN;
2245
2246 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2247 return unless @nums;
2248
2249 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2250 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2251
2252 for my $row (0 .. $#nums) {
2253 my $num = $nums[$row];
2254
2255 my $total = length $CONN->{ix_recv_buf}{$num};
2256 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2257
2258 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2259 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2260 }
2261 };
2262 });
2040 2263
2041 $vb->add (new DC::UI::FancyFrame 2264 $vb->add (new DC::UI::FancyFrame
2042 label => "Other media used in this session", 2265 label => "Other media used in this session",
2043 expand => 1, 2266 expand => 1,
2044 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2267 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2045 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2268 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2046 ); 2269 );
2047 2270
2048 $vb 2271 $vb
2049} 2272}
2050 2273
2235sub open_quit_dialog { 2458sub open_quit_dialog {
2236 unless ($QUIT_DIALOG) { 2459 unless ($QUIT_DIALOG) {
2237 $QUIT_DIALOG = new DC::UI::Toplevel 2460 $QUIT_DIALOG = new DC::UI::Toplevel
2238 x => "center", 2461 x => "center",
2239 y => "center", 2462 y => "center",
2240 z => 50, 2463 z => 60,
2241 title => "Really Quit?", 2464 title => "Really Quit?",
2242 on_key_down => sub { 2465 on_key_down => sub {
2243 my ($dialog, $ev) = @_; 2466 my ($dialog, $ev) = @_;
2244 $ev->{sym} == 27 and $dialog->hide; 2467 $ev->{sym} == 27 and $dialog->hide;
2245 } 2468 }
2461 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2684 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2462 2685
2463 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2686 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2464 $FULLSCREEN = $CFG->{fullscreen}; 2687 $FULLSCREEN = $CFG->{fullscreen};
2465 $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
2466 2691
2467 # 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
2468 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2693 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2469 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2694 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2470 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2695 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2728 EV::unloop; 2953 EV::unloop;
2729 #d# TODO calling exit here hangs the process in some futex 2954 #d# TODO calling exit here hangs the process in some futex
2730}; 2955};
2731 2956
2732# 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
2733sub DC::Main::main { 2958sub DC::Main::run {
2734 { 2959 DC::SDL_main_hack {
2960 {
2735 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2961 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2736 2962
2737 if (-e "$Deliantra::VARDIR/client.cf") { 2963 DC::load_cfg;
2738 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2964 DC::upgrade_cfg;
2739 } else {
2740 #TODO: compatibility cruft
2741 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2742 print STDERR "INFO: used old configuration file\n";
2743 }
2744 2965
2966 DC::Audio::probe;
2967
2745 DC::DB::Server::run; 2968 DC::DB::Server::run;
2746 2969
2747 if ($CFG->{db_schema} < 1) { 2970 if ($CFG->{db_schema} < 1) {
2748 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";
2749 DC::DB::nuke_db; 2972 DC::DB::nuke_db;
2750 $CFG->{db_schema} = 1; 2973 $CFG->{db_schema} = 1;
2751 DC::write_cfg; 2974 DC::save_cfg;
2752 }
2753
2754 DC::DB::open_db;
2755
2756 DC::UI::set_layout ($::CFG->{layout});
2757
2758 my %DEF_CFG = (
2759 config_autosave => 1,
2760 sdl_mode => undef,
2761 fullscreen => 1,
2762 fast => 0,
2763 force_opengl11 => undef,
2764 disable_alpha => 0,
2765 smooth_movement => 1,
2766 smooth_transitions => 1,
2767 texture_compression => 1,
2768 map_scale => 1,
2769 fow_enable => 1,
2770 fow_intensity => 0,
2771 fow_texture => 0,
2772 map_smoothing => 1,
2773 gui_fontsize => 1,
2774 log_fontsize => 0.7,
2775 gauge_fontsize => 1,
2776 gauge_size => 0.35,
2777 stat_fontsize => 0.7,
2778 mapsize => 100,
2779 audio_enable => 1,
2780 audio_hw_channels => 0,
2781 audio_hw_frequency => 0,
2782 audio_hw_chunksize => 0,
2783 audio_mix_channels => 8,
2784 effects_enable => 1,
2785 effects_volume => 1,
2786 bgm_enable => 1,
2787 bgm_volume => 0.5,
2788 output_rate => "",
2789 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
2790 inv_sort => "mtime",
2791 default => "profile", # default profile
2792 show_tips => 1,
2793 logview_max_par => 1000,
2794 shift_fire_stop => 0,
2795 uitheme => "wood",
2796 map_shift_x => -24, # arbitrary
2797 map_shift_y => +24, # arbitrary
2798 );
2799
2800 while (my ($k, $v) = each %DEF_CFG) {
2801 $CFG->{$k} = $v unless exists $CFG->{$k};
2802 }
2803
2804 my @args = @ARGV;
2805
2806 # OS X passes some process serial number of other shit. they
2807 # could have used an env var or any other sane mechanism. but
2808 # would it be os x then? no...
2809 shift @args if $args[0] =~ /^-psn_/;
2810
2811 my $profile = 'default';
2812
2813 for (my $i = 0; $i < @args; $i++) {
2814 if ($args[$i] =~ /^--?profile$/) {
2815 $profile = $args[$i + 1];
2816 splice @args, $i, 2, ();
2817 $i = 0;
2818 } elsif ($args[$i] =~ /^--?h/) {
2819 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2820 exit 0;
2821 } 2975 }
2822 }
2823 2976
2824 $CFG->{profile}{$profile} ||= {}; 2977 DC::DB::open_db;
2825 $PROFILE = $CFG->{profile}{$profile};
2826 $PROFILE->{host} ||= "gameserver.deliantra.net";
2827 2978
2828 $PROFILE->{host} = $args[0] if @args > 0; 2979 DC::UI::set_layout ($::CFG->{layout});
2829 $PROFILE->{user} = $args[1] if @args > 1;
2830 $PROFILE->{password} = $args[2] if @args > 2;
2831 2980
2832 # convert old bindings (only default profile matters) 2981 my @args = @ARGV;
2833 if (my $bindings = delete $PROFILE->{bindings}) { 2982
2834 while (my ($mod, $syms) = each %$bindings) { 2983 # OS X passes some process serial number of other shit. they
2835 while (my ($sym, $cmds) = each %$syms) { 2984 # could have used an env var or any other sane mechanism. but
2836 push @{ $PROFILE->{macro} }, { 2985 # would it be os x then? no...
2837 accelkey => [$mod*1, $sym*1], 2986 shift @args if $args[0] =~ /^-psn_/;
2838 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, ();
2839 }; 2994 $i = 0;
2995 } elsif ($args[$i] =~ /^--?h/) {
2996 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2997 exit 0;
2840 } 2998 }
2841 } 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 }
2842 } 3019 }
2843 3020
2844 # 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
3022 # these are ignored under windows, for some reason, and thus set in the loader
2845 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3023 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2846 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3024 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
2847 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; 3025 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2848 3026
2849 { 3027 {
2850 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3028 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2851 DejaVuSans.ttf 3029 DejaVuSans.ttf
2852 DejaVuSansMono.ttf 3030 DejaVuSansMono.ttf
2853 DejaVuSans-Bold.ttf 3031 DejaVuSans-Bold.ttf
2854 DejaVuSansMono-Bold.ttf 3032 DejaVuSansMono-Bold.ttf
2855 DejaVuSans-Oblique.ttf 3033 DejaVuSans-Oblique.ttf
2856 DejaVuSansMono-Oblique.ttf 3034 DejaVuSansMono-Oblique.ttf
2857 DejaVuSans-BoldOblique.ttf 3035 DejaVuSans-BoldOblique.ttf
2858 DejaVuSansMono-BoldOblique.ttf 3036 DejaVuSansMono-BoldOblique.ttf
2859 mona.ttf 3037 mona.ttf
2860 ); 3038 );
2861 3039
2862 DC::add_font $_ for @fonts; 3040 DC::add_font $_ for @fonts;
2863 3041
2864 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3042 $FONT_PROP = new_from_file DC::Font $fonts[0];
2865 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3043 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2866 3044
2867 $FONT_PROP->make_default; 3045 $FONT_PROP->make_default;
2868 3046
2869 DC::pango_init; 3047 DC::pango_init;
2870 } 3048 }
2871 3049
2872# compare mono (ft) vs. rgba (cairo) 3050# compare mono (ft) vs. rgba (cairo)
2873# ft - 1.8s, cairo 3s, even in alpha-only mode 3051# ft - 1.8s, cairo 3s, even in alpha-only mode
2874# for my $rgba (0..1) { 3052# for my $rgba (0..1) {
2875# my $t1 = Time::HiRes::time; 3053# my $t1 = Time::HiRes::time;
2880# } 3058# }
2881# my $t2 = Time::HiRes::time; 3059# my $t2 = Time::HiRes::time;
2882# warn $t2-$t1; 3060# warn $t2-$t1;
2883# } 3061# }
2884 3062
3063 }
3064
3065 DC::SDL_Init 0;
2885 DC::IMG_Init; video_init; 3066 DC::IMG_Init; video_init;
2886 DC::Mix_Init; audio_init; 3067 DC::Mix_Init; audio_init;
2887 }
2888 3068
2889 show_tip_of_the_day if $CFG->{show_tips}; 3069 show_tip_of_the_day if $CFG->{show_tips};
2890 3070
2891 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3071 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
2892 undef $STARTUP_CANCEL; 3072 undef $STARTUP_CANCEL;
2893 (pop @::STARTUP_DONE)->() 3073 (pop @::STARTUP_DONE)->()
2894 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;
2895 }; 3090 };
2896
2897 debug_toggle 0;
2898
2899 delete $SIG{__DIE__};
2900 EV::loop;
2901
2902 DC::write_cfg if $CFG->{config_autosave};
2903
2904 #video_shutdown;
2905 #audio_shutdown;
2906
2907 DC::OpenGL::quit;
2908 DC::SDL_Quit;
2909 DC::DB::Server::stop;
2910} 3091}
2911
2912*DC::Main::run = \&DC::SDL_braino; # see sub above
2913 3092
29141 30931

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines