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.22 by root, Sun Nov 4 02:13:53 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;
142our $PL_NOTEBOOK; 145our $PL_NOTEBOOK;
143our $PL_WINDOW; 146our $PL_WINDOW;
144 147
145our $MUSIC_PLAYING_WIDGET; 148our $MUSIC_PLAYING_WIDGET;
146our $LICENSE_WIDGET; 149our $LICENSE_WIDGET;
150our $DOWNLOADS_WIDGET;
147 151
148our $PICKUP_PAGE; 152our $PICKUP_PAGE;
149our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
150our $STATS_PAGE; 154our $STATS_PAGE;
151our $SKILL_PAGE; 155our $SKILL_PAGE;
194 AnyEvent::Util::fh_nonblocking $fh, 1; 198 AnyEvent::Util::fh_nonblocking $fh, 1;
195 199
196 $msg =~ s/\s+$//; 200 $msg =~ s/\s+$//;
197 201
198 # backtrace as second step, in case it crashes, too 202 # backtrace as second step, in case it crashes, too
199 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"
200 if $backtrace; 204 if $backtrace;
201}; 205};
202 206
203sub clienterror($;$) { 207sub clienterror($;$) {
204 my ($msg, $backtrace) = @_; 208 my ($msg, $backtrace) = @_;
206 warn $msg; 210 warn $msg;
207 211
208 return unless $CONN; 212 return unless $CONN;
209 213
210 $CONN->send_exti_msg (clientlog => $msg); 214 $CONN->send_exti_msg (clientlog => $msg);
211 $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;
212} 216}
213 217
214############################################################################# 218#############################################################################
215 219
216sub status { 220sub status {
471 audio_music_push; 475 audio_music_push;
472} 476}
473 477
474sub audio_init { 478sub audio_init {
475 if ($CFG->{audio_enable}) { 479 if ($CFG->{audio_enable}) {
476 if (length $CFG->{audio_driver}) { 480 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 481
492 if ($SDL_MIXER) { 482 if ($SDL_MIXER) {
493 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
494
495 audio_music_finished; 483 audio_music_finished;
496 } else { 484 } else {
497 status "Unable to open sound device: there will be no sound"; 485 status "Unable to open sound device: there will be no sound";
498 } 486 }
499 } else { 487 } else {
521 509
522 DC::Mix_CloseAudio if $SDL_MIXER; 510 DC::Mix_CloseAudio if $SDL_MIXER;
523 undef $SDL_MIXER; 511 undef $SDL_MIXER;
524 512
525 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 ()
696 });
526} 697}
527 698
528############################################################################# 699#############################################################################
529 700
530sub destroy_query_dialog { 701sub destroy_query_dialog {
773 mapw => $mapw, 944 mapw => $mapw,
774 maph => $maph, 945 maph => $maph,
775 946
776 c_version => { 947 c_version => {
777 client => "deliantra", 948 client => "deliantra",
778 clientver => $DC::VERSION, 949 clientver => "$DC::VERSION$Urlader::EXE_VER",
779 gl_vendor => DC::OpenGL::gl_vendor, 950 gl_vendor => DC::OpenGL::gl_vendor,
780 gl_version => DC::OpenGL::gl_version, 951 gl_version => DC::OpenGL::gl_version,
781 }, 952 },
782 953
783 map_widget => $MAPWIDGET, 954 map_widget => $MAPWIDGET,
791 }, 962 },
792 963
793 on_connect => sub { 964 on_connect => sub {
794 if ($_[0]) { 965 if ($_[0]) {
795 DC::lowdelay fileno $CONN->{fh}; 966 DC::lowdelay fileno $CONN->{fh};
967
968 ota_update_check;
796 969
797 status "successfully connected to the server"; 970 status "successfully connected to the server";
798 } else { 971 } else {
799 undef $CONN; 972 undef $CONN;
800 status "unable to connect: $!"; 973 status "unable to connect: $!";
1835 $table->add_at (2, $row++, new DC::UI::Button 2008 $table->add_at (2, $row++, new DC::UI::Button
1836 text => "Save Now", 2009 text => "Save Now",
1837 tooltip => "Use this to manually save configuration and UI layout when " 2010 tooltip => "Use this to manually save configuration and UI layout when "
1838 . "autosave is disabled.", 2011 . "autosave is disabled.",
1839 on_activate => sub { 2012 on_activate => sub {
1840 DC::write_cfg; 2013 DC::save_cfg;
1841 0 2014 0
1842 } 2015 }
1843 ); 2016 );
1844 } 2017 }
1845 2018
1854 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2027 $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)"); 2028 $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 => ""); 2029 $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)"); 2030 $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 => ""); 2031 $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)"); 2032 $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 => ""); 2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1861 } 2034 }
1862 2035
1863 $vbox 2036 $vbox
1864} 2037}
2039 2212
2040sub media_window { 2213sub media_window {
2041 my $vb = new DC::UI::VBox; 2214 my $vb = new DC::UI::VBox;
2042 2215
2043 $vb->add (new DC::UI::FancyFrame 2216 $vb->add (new DC::UI::FancyFrame
2044 label => "Currently playing music", 2217 label => "Current background music",
2045 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2218 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), 2219 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2047 ); 2220 );
2221
2222 $vb->add (new DC::UI::FancyFrame
2223 label => "Current downloads",
2224 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2225 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2226 );
2227
2228 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2229 my ($self) = @_;
2230
2231 delete $self->{updater};
2232 return unless $_[1];
2233
2234 $self->{updater} = AE::timer 0, 0.7, sub {
2235 $self->clear;
2236
2237 return unless $CONN;
2238
2239 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2240 return unless @nums;
2241
2242 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2243 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2244
2245 for my $row (0 .. $#nums) {
2246 my $num = $nums[$row];
2247
2248 my $total = length $CONN->{ix_recv_buf}{$num};
2249 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2250
2251 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2252 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2253 }
2254 };
2255 });
2048 2256
2049 $vb->add (new DC::UI::FancyFrame 2257 $vb->add (new DC::UI::FancyFrame
2050 label => "Other media used in this session", 2258 label => "Other media used in this session",
2051 expand => 1, 2259 expand => 1,
2052 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2260 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2053 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2261 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2054 ); 2262 );
2055 2263
2056 $vb 2264 $vb
2057} 2265}
2058 2266
2243sub open_quit_dialog { 2451sub open_quit_dialog {
2244 unless ($QUIT_DIALOG) { 2452 unless ($QUIT_DIALOG) {
2245 $QUIT_DIALOG = new DC::UI::Toplevel 2453 $QUIT_DIALOG = new DC::UI::Toplevel
2246 x => "center", 2454 x => "center",
2247 y => "center", 2455 y => "center",
2248 z => 50, 2456 z => 60,
2249 title => "Really Quit?", 2457 title => "Really Quit?",
2250 on_key_down => sub { 2458 on_key_down => sub {
2251 my ($dialog, $ev) = @_; 2459 my ($dialog, $ev) = @_;
2252 $ev->{sym} == 27 and $dialog->hide; 2460 $ev->{sym} == 27 and $dialog->hide;
2253 } 2461 }
2446 DC::set_theme $CFG->{uitheme}; 2654 DC::set_theme $CFG->{uitheme};
2447 2655
2448 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2656 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2449 $SDL_REINIT = 0; 2657 $SDL_REINIT = 0;
2450 2658
2451 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2659 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2452 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2660 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2453 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2661 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2454 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 2662 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2455 2663
2456 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2664 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2469 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2677 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2470 2678
2471 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2679 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2472 $FULLSCREEN = $CFG->{fullscreen}; 2680 $FULLSCREEN = $CFG->{fullscreen};
2473 $FAST = $CFG->{fast}; 2681 $FAST = $CFG->{fast};
2682
2683 DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init
2474 2684
2475 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error 2685 # 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 2686 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2477 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2687 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2478 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2688 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2736 EV::unloop; 2946 EV::unloop;
2737 #d# TODO calling exit here hangs the process in some futex 2947 #d# TODO calling exit here hangs the process in some futex
2738}; 2948};
2739 2949
2740# due to mac os x + sdl combined braindamage, we need this contortion 2950# due to mac os x + sdl combined braindamage, we need this contortion
2741sub DC::Main::main { 2951sub DC::Main::run {
2742 { 2952 DC::SDL_main_hack {
2953 {
2743 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2954 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2744 2955
2745 if (-e "$Deliantra::VARDIR/client.cf") { 2956 DC::load_cfg;
2746 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2957 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 2958
2959 DC::Audio::probe;
2960
2753 DC::DB::Server::run; 2961 DC::DB::Server::run;
2754 2962
2755 if ($CFG->{db_schema} < 1) { 2963 if ($CFG->{db_schema} < 1) {
2756 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2964 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2757 DC::DB::nuke_db; 2965 DC::DB::nuke_db;
2758 $CFG->{db_schema} = 1; 2966 $CFG->{db_schema} = 1;
2759 DC::write_cfg; 2967 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 } 2968 }
2830 }
2831 2969
2832 $CFG->{profile}{$profile} ||= {}; 2970 DC::DB::open_db;
2833 $PROFILE = $CFG->{profile}{$profile};
2834 $PROFILE->{host} ||= "gameserver.deliantra.net";
2835 2971
2836 $PROFILE->{host} = $args[0] if @args > 0; 2972 DC::UI::set_layout ($::CFG->{layout});
2837 $PROFILE->{user} = $args[1] if @args > 1;
2838 $PROFILE->{password} = $args[2] if @args > 2;
2839 2973
2840 # convert old bindings (only default profile matters) 2974 my @args = @ARGV;
2841 if (my $bindings = delete $PROFILE->{bindings}) { 2975
2842 while (my ($mod, $syms) = each %$bindings) { 2976 # OS X passes some process serial number of other shit. they
2843 while (my ($sym, $cmds) = each %$syms) { 2977 # could have used an env var or any other sane mechanism. but
2844 push @{ $PROFILE->{macro} }, { 2978 # would it be os x then? no...
2845 accelkey => [$mod*1, $sym*1], 2979 shift @args if $args[0] =~ /^-psn_/;
2846 action => $cmds, 2980
2981 my $profile = 'default';
2982
2983 for (my $i = 0; $i < @args; $i++) {
2984 if ($args[$i] =~ /^--?profile$/) {
2985 $profile = $args[$i + 1];
2986 splice @args, $i, 2, ();
2847 }; 2987 $i = 0;
2988 } elsif ($args[$i] =~ /^--?h/) {
2989 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2990 exit 0;
2848 } 2991 }
2849 } 2992 }
2993
2994 $CFG->{profile}{$profile} ||= {};
2995 $PROFILE = $CFG->{profile}{$profile};
2996 $PROFILE->{host} ||= "gameserver.deliantra.net";
2997
2998 $PROFILE->{host} = $args[0] if @args > 0;
2999 $PROFILE->{user} = $args[1] if @args > 1;
3000 $PROFILE->{password} = $args[2] if @args > 2;
3001
3002 # convert old bindings (only default profile matters)
3003 if (my $bindings = delete $PROFILE->{bindings}) {
3004 while (my ($mod, $syms) = each %$bindings) {
3005 while (my ($sym, $cmds) = each %$syms) {
3006 push @{ $PROFILE->{macro} }, {
3007 accelkey => [$mod*1, $sym*1],
3008 action => $cmds,
3009 };
3010 }
3011 }
2850 } 3012 }
2851 3013
2852 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3014 # 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 3015 # these are ignored under windows, for some reason, and thus set in the loader
2854 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3016 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2855 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3017 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
2856 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3018 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2857 3019
2858 { 3020 {
2859 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3021 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2860 DejaVuSans.ttf 3022 DejaVuSans.ttf
2861 DejaVuSansMono.ttf 3023 DejaVuSansMono.ttf
2862 DejaVuSans-Bold.ttf 3024 DejaVuSans-Bold.ttf
2863 DejaVuSansMono-Bold.ttf 3025 DejaVuSansMono-Bold.ttf
2864 DejaVuSans-Oblique.ttf 3026 DejaVuSans-Oblique.ttf
2865 DejaVuSansMono-Oblique.ttf 3027 DejaVuSansMono-Oblique.ttf
2866 DejaVuSans-BoldOblique.ttf 3028 DejaVuSans-BoldOblique.ttf
2867 DejaVuSansMono-BoldOblique.ttf 3029 DejaVuSansMono-BoldOblique.ttf
2868 mona.ttf 3030 mona.ttf
2869 ); 3031 );
2870 3032
2871 DC::add_font $_ for @fonts; 3033 DC::add_font $_ for @fonts;
2872 3034
2873 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3035 $FONT_PROP = new_from_file DC::Font $fonts[0];
2874 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3036 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2875 3037
2876 $FONT_PROP->make_default; 3038 $FONT_PROP->make_default;
2877 3039
2878 DC::pango_init; 3040 DC::pango_init;
2879 } 3041 }
2880 3042
2881# compare mono (ft) vs. rgba (cairo) 3043# compare mono (ft) vs. rgba (cairo)
2882# ft - 1.8s, cairo 3s, even in alpha-only mode 3044# ft - 1.8s, cairo 3s, even in alpha-only mode
2883# for my $rgba (0..1) { 3045# for my $rgba (0..1) {
2884# my $t1 = Time::HiRes::time; 3046# my $t1 = Time::HiRes::time;
2889# } 3051# }
2890# my $t2 = Time::HiRes::time; 3052# my $t2 = Time::HiRes::time;
2891# warn $t2-$t1; 3053# warn $t2-$t1;
2892# } 3054# }
2893 3055
3056 }
3057
3058 DC::SDL_Init 0;
2894 DC::IMG_Init; video_init; 3059 DC::IMG_Init; video_init;
2895 DC::Mix_Init; audio_init; 3060 DC::Mix_Init; audio_init;
2896 }
2897 3061
2898 show_tip_of_the_day if $CFG->{show_tips}; 3062 show_tip_of_the_day if $CFG->{show_tips};
2899 3063
2900 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3064 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
2901 undef $STARTUP_CANCEL; 3065 undef $STARTUP_CANCEL;
2902 (pop @::STARTUP_DONE)->() 3066 (pop @::STARTUP_DONE)->()
2903 while @::STARTUP_DONE; 3067 while @::STARTUP_DONE;
3068 };
3069
3070 debug_toggle 0;
3071
3072 delete $SIG{__DIE__};
3073 EV::loop;
3074
3075 DC::save_cfg if $CFG->{config_autosave};
3076
3077 #video_shutdown;
3078 #audio_shutdown;
3079
3080 DC::OpenGL::quit;
3081 DC::SDL_Quit;
3082 DC::DB::Server::stop;
2904 }; 3083 };
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} 3084}
2920
2921*DC::Main::run = \&DC::SDL_braino; # see sub above
2922 3085
29231 30861

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines