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.2 by root, Tue Dec 27 09:17:27 2011 UTC vs.
Revision 1.8 by root, Wed Jan 4 11:23:23 2012 UTC

17 die if $@; 17 die if $@;
18} 18}
19 19
20use common::sense; 20use common::sense;
21use Carp 'verbose'; 21use Carp 'verbose';
22use Cwd ();
22use EV; 23use EV;
23BEGIN { *time = \&EV::time } 24BEGIN { *time = \&EV::time }
24 25
25use List::Util qw(max min); 26use List::Util qw(max min);
26 27
40 # nop at compiletime 41 # nop at compiletime
41} 42}
42 43
43BEGIN { 44BEGIN {
44 $SIG{__DIE__} = sub { 45 $SIG{__DIE__} = sub {
45 return if $^S; 46 return if $^S; # quick reject
47
48 # return if there are any eval contexts in the csall stack
49 for my $i (0..999) {
50 my ($sub, $is_require) = (caller $i)[3, 7]
51 or last;
52 return if $sub eq "(eval)" && !$is_require;
53 }
54
46 crash "CRASH/DIE: $_[0]" => 1; 55 crash "CRASH/DIE: $_[0]" => 1;
47 DC::fatal Carp::longmess "$_[0]"; 56 DC::fatal Carp::longmess "$_[0]";
48 } 57 }
49} 58}
50 59
133our $PL_NOTEBOOK; 142our $PL_NOTEBOOK;
134our $PL_WINDOW; 143our $PL_WINDOW;
135 144
136our $MUSIC_PLAYING_WIDGET; 145our $MUSIC_PLAYING_WIDGET;
137our $LICENSE_WIDGET; 146our $LICENSE_WIDGET;
147our $DOWNLOADS_WIDGET;
138 148
139our $PICKUP_PAGE; 149our $PICKUP_PAGE;
140our $INVENTORY_PAGE; 150our $INVENTORY_PAGE;
141our $STATS_PAGE; 151our $STATS_PAGE;
142our $SKILL_PAGE; 152our $SKILL_PAGE;
512 522
513 DC::Mix_CloseAudio if $SDL_MIXER; 523 DC::Mix_CloseAudio if $SDL_MIXER;
514 undef $SDL_MIXER; 524 undef $SDL_MIXER;
515 525
516 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 526 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
527}
528
529#############################################################################
530# Over-the-air updates
531
532sub ota_update_finish {
533 $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] });
534}
535
536sub ota_update_status {
537}
538
539sub ota_update {
540 my ($face, $size) = @_;
541
542 my $coro = Coro::async_pool {
543 my $override = "$Urlader::EXE_DIR/override";
544
545 $MESSAGE_DIST->add_channel ({
546 id => "ota_update",
547 title => "Update",
548 tooltip => "<b>Software Update Log</b>",
549 });
550
551 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
552
553 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
554
555 unless ($fh) {
556 ota_update_finish "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!";
557 return;
558 }
559
560 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
561
562 my $cv = AE::cv;
563 my $error;
564
565 $cv->begin (Coro::rouse_cb);
566
567 $CONN->ask_face (
568 $face,
569 -1000,
570 sub {
571 $STATUSBOX->add (
572 (sprintf "update download: %d/%d", $size - $_[1], $size),
573 pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1]
574 );
575
576 $cv->begin;
577 my $len = length $_[2];
578 IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub {
579 $error ||= $_[0] != $len;
580 $cv->end;
581 };
582 },
583 sub {
584 $cv->end;
585 },
586 );
587
588 Coro::rouse_wait;
589
590 $STATUSBOX->clr_group ("ota_update");
591
592 $error ||= Coro::AIO::aio_fsync $fh;
593 $error ||= Coro::AIO::aio_close $fh;
594
595 if ($error) {
596 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
597 Coro::AIO::aio_unlink "$override.tmp";
598 return;
599 }
600
601 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
602
603 if (Coro::AIO::aio_rename "$override.tmp", $override) {
604 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
605 Coro::AIO::aio_unlink "$override.tmp";
606 }
607
608 $MESSAGE_DIST->message ({ type => "ota_update", markup => "update successfull, changes become active at next start." });
609 };
610
611 $CONN->{ota_update} = Guard::guard {
612 $coro->cancel;
613 };
614}
615
616sub ota_update_ask {
617 my ($ok, $face, $ver, $size, $changes) = @_;
618
619 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
620 x => "center",
621 y => "center",
622 max_w => $::WIDTH * 0.7,
623 max_h => $::WIDTH * 0.7,
624 title => "Software update available",
625 child => my $vbox = new DC::UI::VBox,
626 ;
627
628 $vbox->add (new DC::UI::Label
629 ellipsise => 0,
630 text => "The server offers a software update, "
631 . "do you want to start downloading this update in the background?",
632 );
633
634 $vbox->add (new DC::UI::FancyFrame
635 expand => 1,
636 label => "Changes",
637 child => (new DC::UI::TextScroller
638 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
639 par => [{
640 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
641 . "New revision: $ver\n"
642 . "Download size: $size bytes</tt>\n\n"
643 . DC::asxml $changes
644 }],
645 ),
646 );
647
648 $vbox->add (my $hbox = new DC::UI::HBox);
649
650 $hbox->add (new DC::UI::Button
651 expand => 1,
652 text => "Not now",
653 on_activate => sub {
654 $dialog->destroy;
655 0
656 }
657 );
658 $hbox->add (new DC::UI::Button
659 expand => 1,
660 text => "Yes, start downloading",
661 on_activate => sub {
662 $dialog->destroy;
663 ota_update $face, $size;
664 0
665 },
666 );
667
668 $dialog->show;
669}
670
671sub ota_update_check {
672 return unless defined $Urlader::EXE_ID;
673
674 ::message { markup => "Checking for software update..." };
675
676 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
677 my ($ok, $face, $ver, $size, $changes) = @_;
678
679 if ($ok) {
680 if (defined $ver) {
681 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
682 &ota_update_ask;
683 } else {
684 ::message { markup => "Server has no newer version." };
685 }
686 } else {
687 ::message { markup => "Server does not support software update." };
688 }
689
690# $self->register_face_handler ($exp_table, sub {
691# my ($face) = @_;
692
693# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
694# $_->() for values %{ $self->{on_exp_update} || {} };
695# });
696
697 ()
698 });
517} 699}
518 700
519############################################################################# 701#############################################################################
520 702
521sub destroy_query_dialog { 703sub destroy_query_dialog {
783 965
784 on_connect => sub { 966 on_connect => sub {
785 if ($_[0]) { 967 if ($_[0]) {
786 DC::lowdelay fileno $CONN->{fh}; 968 DC::lowdelay fileno $CONN->{fh};
787 969
970 ota_update_check;
971
788 status "successfully connected to the server"; 972 status "successfully connected to the server";
789 } else { 973 } else {
790 undef $CONN; 974 undef $CONN;
791 status "unable to connect: $!"; 975 status "unable to connect: $!";
792 stop_game(); 976 stop_game();
1131 text => $CFG->{audio_driver}, 1315 text => $CFG->{audio_driver},
1132 template => "dsound1234", 1316 template => "dsound1234",
1133 tooltip => "You can override the audio driver to use here. Leaving it empty will result " 1317 tooltip => "You can override the audio driver to use here. Leaving it empty will result "
1134 . "in Deliantra picking one automatically. GNU/Linux users often prefer specific " 1318 . "in Deliantra picking one automatically. GNU/Linux users often prefer specific "
1135 . "drivers though, and can experiment with <b>alsa</b>, <b>dsp</b>, <b>esd</b>, <b>pulse</b>, <b>arts</b>, <b>nas</b> " 1319 . "drivers though, and can experiment with <b>alsa</b>, <b>dsp</b>, <b>esd</b>, <b>pulse</b>, <b>arts</b>, <b>nas</b> "
1136 . "or other system-specific drivers. Selecting the wrong driver here will simply result" 1320 . "or other system-specific drivers. Selecting the wrong driver here will simply result "
1137 . "in no sound.", 1321 . "in no sound.",
1138 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } 1322 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 }
1139 ); 1323 );
1140 1324
1141 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); 1325 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1841 2025
1842 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); 2026 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
1843 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); 2027 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
1844 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); 2028 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
1845 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2029 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2030 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2031 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1846 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); 2032 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
1847 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_ID, tooltip => ""); 2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1848 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); 2034 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
1849 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_VER, tooltip => ""); 2035 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1850 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Update (Prebuilt)");
1851 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::UPDPAR, tooltip => "");
1852 } 2036 }
1853 2037
1854 $vbox 2038 $vbox
1855} 2039}
1856 2040
2030 2214
2031sub media_window { 2215sub media_window {
2032 my $vb = new DC::UI::VBox; 2216 my $vb = new DC::UI::VBox;
2033 2217
2034 $vb->add (new DC::UI::FancyFrame 2218 $vb->add (new DC::UI::FancyFrame
2035 label => "Currently playing music", 2219 label => "Current background music",
2036 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2220 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2037 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), 2221 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2038 ); 2222 );
2223
2224 $vb->add (new DC::UI::FancyFrame
2225 label => "Current downloads",
2226 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2227 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2228 );
2229
2230 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2231 my ($self) = @_;
2232
2233 delete $self->{updater};
2234 return unless $_[1];
2235
2236 $self->{updater} = AE::timer 0, 0.7, sub {
2237 $self->clear;
2238
2239 return unless $CONN;
2240
2241 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2242 return unless @nums;
2243
2244 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2245 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2246
2247 for my $row (0 .. $#nums) {
2248 my $num = $nums[$row];
2249
2250 my $total = length $CONN->{ix_recv_buf}{$num};
2251 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2252
2253 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2254 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2255 }
2256 };
2257 });
2039 2258
2040 $vb->add (new DC::UI::FancyFrame 2259 $vb->add (new DC::UI::FancyFrame
2041 label => "Other media used in this session", 2260 label => "Other media used in this session",
2042 expand => 1, 2261 expand => 1,
2043 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2262 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2044 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2263 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2045 ); 2264 );
2046 2265
2047 $vb 2266 $vb
2048} 2267}
2049 2268
2838 }; 3057 };
2839 } 3058 }
2840 } 3059 }
2841 } 3060 }
2842 3061
3062 # 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
2843 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; 3064 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2844 $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts"; 3065 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3066 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2845 3067
2846 { 3068 {
2847 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3069 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2848 DejaVuSans.ttf 3070 DejaVuSans.ttf
2849 DejaVuSansMono.ttf 3071 DejaVuSansMono.ttf

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines