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.1 by root, Tue Dec 27 07:23:33 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");
1773 1957
1774 $vbox 1958 $vbox
1775} 1959}
1776 1960
1777sub client_setup { 1961sub client_setup {
1962 my $vbox = new DC::UI::VBox;
1963
1964 $vbox->add (my $top = new DC::UI::FancyFrame expand => 1, label => "Client Settings");
1965 $vbox->add (my $bot = new DC::UI::FancyFrame expand => 1, label => "Client Info");
1966
1967 {
1778 my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]; 1968 $top->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
1779 1969
1780 my $row = 0; 1970 my $row = 0;
1781 1971
1782 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day"); 1972 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day");
1783 $table->add_at (1, $row++, new DC::UI::CheckBox 1973 $table->add_at (1, $row++, new DC::UI::CheckBox
1784 c_colspan => 2, 1974 c_colspan => 2,
1785 state => $CFG->{show_tips}, 1975 state => $CFG->{show_tips},
1786 tooltip => "Show the <b>Tip of the day</b> window at startup?", 1976 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1787 on_changed => sub { 1977 on_changed => sub {
1788 my ($self, $value) = @_; 1978 my ($self, $value) = @_;
1789 $CFG->{show_tips} = $value; 1979 $CFG->{show_tips} = $value;
1980 0
1790 0 1981 }
1791 } 1982 );
1792 );
1793 1983
1794 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); 1984 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size");
1795 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry 1985 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1796 c_colspan => 2, 1986 c_colspan => 2,
1797 text => $CFG->{logview_max_par}, 1987 text => $CFG->{logview_max_par},
1798 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server " 1988 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server "
1799 . "sends more messages than this number, older messages get removed to save memory and " 1989 . "sends more messages than this number, older messages get removed to save memory and "
1800 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.", 1990 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1801 on_changed => sub { 1991 on_changed => sub {
1802 my ($self, $value) = @_; 1992 my ($self, $value) = @_;
1803 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); 1993 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1804 0 1994 0
1805 }, 1995 },
1806 ); 1996 );
1807 1997
1808 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave"); 1998 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave");
1809 $table->add_at (1, $row, new DC::UI::CheckBox 1999 $table->add_at (1, $row, new DC::UI::CheckBox
1810 state => $CFG->{config_autosave}, 2000 state => $CFG->{config_autosave},
1811 tooltip => "Normally, configuration settings and the user interface layout " 2001 tooltip => "Normally, configuration settings and the user interface layout "
1812 . "are saved on client exit. You can disable this behaviour by " 2002 . "are saved on client exit. You can disable this behaviour by "
1813 . "unchecking this checkbox.", 2003 . "unchecking this checkbox.",
1814 on_changed => sub { 2004 on_changed => sub {
1815 my ($self, $value) = @_; 2005 my ($self, $value) = @_;
1816 $CFG->{config_autosave} = $value; 2006 $CFG->{config_autosave} = $value;
2007 0
1817 0 2008 }
1818 } 2009 );
1819 );
1820 $table->add_at (2, $row++, new DC::UI::Button 2010 $table->add_at (2, $row++, new DC::UI::Button
1821 text => "Save Now", 2011 text => "Save Now",
1822 tooltip => "Use this to manually save configuration and UI layout when " 2012 tooltip => "Use this to manually save configuration and UI layout when "
1823 . "autosave is disabled.", 2013 . "autosave is disabled.",
1824 on_activate => sub { 2014 on_activate => sub {
1825 DC::write_cfg; 2015 DC::write_cfg;
2016 0
1826 0 2017 }
1827 } 2018 );
1828 ); 2019 }
1829 2020
1830 $table 2021 {
2022 $bot->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
2023
2024 my $row = 0;
2025
2026 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
2027 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
2028 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
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 => "");
2032 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
2034 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
2035 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
2036 }
2037
2038 $vbox
1831} 2039}
1832 2040
1833sub autopickup_setup { 2041sub autopickup_setup {
1834 my $r = new DC::UI::ScrolledWindow ( 2042 my $r = new DC::UI::ScrolledWindow (
1835 expand => 1, 2043 expand => 1,
2006 2214
2007sub media_window { 2215sub media_window {
2008 my $vb = new DC::UI::VBox; 2216 my $vb = new DC::UI::VBox;
2009 2217
2010 $vb->add (new DC::UI::FancyFrame 2218 $vb->add (new DC::UI::FancyFrame
2011 label => "Currently playing music", 2219 label => "Current background music",
2012 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2220 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2013 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),
2014 ); 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 });
2015 2258
2016 $vb->add (new DC::UI::FancyFrame 2259 $vb->add (new DC::UI::FancyFrame
2017 label => "Other media used in this session", 2260 label => "Other media used in this session",
2018 expand => 1, 2261 expand => 1,
2019 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2262 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2020 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2263 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2021 ); 2264 );
2022 2265
2023 $vb 2266 $vb
2024} 2267}
2025 2268
2632 2875
2633our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub { 2876our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub {
2634 $NOW = EV::now; 2877 $NOW = EV::now;
2635 2878
2636 ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_) 2879 ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_)
2637 for DC::poll_events; 2880 for DC::peep_events;
2638 2881
2639 if (%animate_object) { 2882 if (%animate_object) {
2640 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2883 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2641 $WANT_REFRESH = 1; 2884 $WANT_REFRESH = 1;
2642 } 2885 }
2814 }; 3057 };
2815 } 3058 }
2816 } 3059 }
2817 } 3060 }
2818 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
2819 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; 3064 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2820 $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
2821 3067
2822 { 3068 {
2823 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3069 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2824 DejaVuSans.ttf 3070 DejaVuSans.ttf
2825 DejaVuSansMono.ttf 3071 DejaVuSansMono.ttf

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines