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.17 by root, Wed Jan 18 13:42:19 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 ();
23use Digest::MD5 ();
22use EV; 24use EV;
23BEGIN { *time = \&EV::time } 25BEGIN { *time = \&EV::time }
24 26
25use List::Util qw(max min); 27use List::Util qw(max min);
26 28
40 # nop at compiletime 42 # nop at compiletime
41} 43}
42 44
43BEGIN { 45BEGIN {
44 $SIG{__DIE__} = sub { 46 $SIG{__DIE__} = sub {
45 return if $^S; 47 return if $^S; # quick reject
48
49 # return if there are any eval contexts in the csall stack
50 for my $i (0..999) {
51 my ($sub, $is_require) = (caller $i)[3, 7]
52 or last;
53 return if $sub eq "(eval)" && !$is_require;
54 }
55
46 crash "CRASH/DIE: $_[0]" => 1; 56 crash "CRASH/DIE: $_[0]" => 1;
47 DC::fatal Carp::longmess "$_[0]"; 57 DC::fatal Carp::longmess "$_[0]";
48 } 58 }
49} 59}
50 60
51use DC::OpenGL (); 61use DC::OpenGL ();
62use DC::Audio ();
52use DC::Protocol; 63use DC::Protocol;
53use DC::DB; 64use DC::DB;
54use DC::UI; 65use DC::UI;
55use DC::UI::Canvas; 66use DC::UI::Canvas;
56use DC::UI::Inventory; 67use DC::UI::Inventory;
133our $PL_NOTEBOOK; 144our $PL_NOTEBOOK;
134our $PL_WINDOW; 145our $PL_WINDOW;
135 146
136our $MUSIC_PLAYING_WIDGET; 147our $MUSIC_PLAYING_WIDGET;
137our $LICENSE_WIDGET; 148our $LICENSE_WIDGET;
149our $DOWNLOADS_WIDGET;
138 150
139our $PICKUP_PAGE; 151our $PICKUP_PAGE;
140our $INVENTORY_PAGE; 152our $INVENTORY_PAGE;
141our $STATS_PAGE; 153our $STATS_PAGE;
142our $SKILL_PAGE; 154our $SKILL_PAGE;
185 AnyEvent::Util::fh_nonblocking $fh, 1; 197 AnyEvent::Util::fh_nonblocking $fh, 1;
186 198
187 $msg =~ s/\s+$//; 199 $msg =~ s/\s+$//;
188 200
189 # backtrace as second step, in case it crashes, too 201 # backtrace as second step, in case it crashes, too
190 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"
191 if $backtrace; 203 if $backtrace;
192}; 204};
193 205
194sub clienterror($;$) { 206sub clienterror($;$) {
195 my ($msg, $backtrace) = @_; 207 my ($msg, $backtrace) = @_;
197 warn $msg; 209 warn $msg;
198 210
199 return unless $CONN; 211 return unless $CONN;
200 212
201 $CONN->send_exti_msg (clientlog => $msg); 213 $CONN->send_exti_msg (clientlog => $msg);
202 $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;
203} 215}
204 216
205############################################################################# 217#############################################################################
206 218
207sub status { 219sub status {
462 audio_music_push; 474 audio_music_push;
463} 475}
464 476
465sub audio_init { 477sub audio_init {
466 if ($CFG->{audio_enable}) { 478 if ($CFG->{audio_enable}) {
467 if (length $CFG->{audio_driver}) { 479 DC::Audio::init $CFG->{audio_driver};
468 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
469 DC::SDL_Init DC::SDL_INIT_AUDIO
470 and die "SDL::Init failed!\n";
471 } else {
472 DC::SDL_Init DC::SDL_INIT_AUDIO
473 and die "SDL::Init failed!\n";
474 }
475
476 $ENV{MIX_EFFECTSMAXSPEED} = 1;
477 $SDL_MIXER = !DC::Mix_OpenAudio
478 $CFG->{audio_hw_frequency},
479 DC::MIX_DEFAULT_FORMAT,
480 $CFG->{audio_hw_channels},
481 $CFG->{audio_hw_chunksize};
482 480
483 if ($SDL_MIXER) { 481 if ($SDL_MIXER) {
484 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
485
486 audio_music_finished; 482 audio_music_finished;
487 } else { 483 } else {
488 status "Unable to open sound device: there will be no sound"; 484 status "Unable to open sound device: there will be no sound";
489 } 485 }
490 } else { 486 } else {
512 508
513 DC::Mix_CloseAudio if $SDL_MIXER; 509 DC::Mix_CloseAudio if $SDL_MIXER;
514 undef $SDL_MIXER; 510 undef $SDL_MIXER;
515 511
516 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 });
517} 703}
518 704
519############################################################################# 705#############################################################################
520 706
521sub destroy_query_dialog { 707sub destroy_query_dialog {
764 mapw => $mapw, 950 mapw => $mapw,
765 maph => $maph, 951 maph => $maph,
766 952
767 c_version => { 953 c_version => {
768 client => "deliantra", 954 client => "deliantra",
769 clientver => $DC::VERSION, 955 clientver => "$DC::VERSION$Urlader::EXE_VER",
770 gl_vendor => DC::OpenGL::gl_vendor, 956 gl_vendor => DC::OpenGL::gl_vendor,
771 gl_version => DC::OpenGL::gl_version, 957 gl_version => DC::OpenGL::gl_version,
772 }, 958 },
773 959
774 map_widget => $MAPWIDGET, 960 map_widget => $MAPWIDGET,
782 }, 968 },
783 969
784 on_connect => sub { 970 on_connect => sub {
785 if ($_[0]) { 971 if ($_[0]) {
786 DC::lowdelay fileno $CONN->{fh}; 972 DC::lowdelay fileno $CONN->{fh};
973
974 ota_update_check;
787 975
788 status "successfully connected to the server"; 976 status "successfully connected to the server";
789 } else { 977 } else {
790 undef $CONN; 978 undef $CONN;
791 status "unable to connect: $!"; 979 status "unable to connect: $!";
1131 text => $CFG->{audio_driver}, 1319 text => $CFG->{audio_driver},
1132 template => "dsound1234", 1320 template => "dsound1234",
1133 tooltip => "You can override the audio driver to use here. Leaving it empty will result " 1321 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 " 1322 . "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> " 1323 . "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" 1324 . "or other system-specific drivers. Selecting the wrong driver here will simply result "
1137 . "in no sound.", 1325 . "in no sound.",
1138 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } 1326 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 }
1139 ); 1327 );
1140 1328
1141 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); 1329 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1773 1961
1774 $vbox 1962 $vbox
1775} 1963}
1776 1964
1777sub client_setup { 1965sub client_setup {
1966 my $vbox = new DC::UI::VBox;
1967
1968 $vbox->add (my $top = new DC::UI::FancyFrame expand => 1, label => "Client Settings");
1969 $vbox->add (my $bot = new DC::UI::FancyFrame expand => 1, label => "Client Info");
1970
1971 {
1778 my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]; 1972 $top->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
1779 1973
1780 my $row = 0; 1974 my $row = 0;
1781 1975
1782 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Tip of the day"); 1976 $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 1977 $table->add_at (1, $row++, new DC::UI::CheckBox
1784 c_colspan => 2, 1978 c_colspan => 2,
1785 state => $CFG->{show_tips}, 1979 state => $CFG->{show_tips},
1786 tooltip => "Show the <b>Tip of the day</b> window at startup?", 1980 tooltip => "Show the <b>Tip of the day</b> window at startup?",
1787 on_changed => sub { 1981 on_changed => sub {
1788 my ($self, $value) = @_; 1982 my ($self, $value) = @_;
1789 $CFG->{show_tips} = $value; 1983 $CFG->{show_tips} = $value;
1984 0
1790 0 1985 }
1791 } 1986 );
1792 );
1793 1987
1794 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); 1988 $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 1989 $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry
1796 c_colspan => 2, 1990 c_colspan => 2,
1797 text => $CFG->{logview_max_par}, 1991 text => $CFG->{logview_max_par},
1798 tooltip => "This is maximum number of messages remembered in the <b>Message</b> window. If the server " 1992 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 " 1993 . "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.", 1994 . "computing time. A value of <b>0</b> disables this feature, but that is not recommended.",
1801 on_changed => sub { 1995 on_changed => sub {
1802 my ($self, $value) = @_; 1996 my ($self, $value) = @_;
1803 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1); 1997 $MESSAGE_DIST->set_max_par ($CFG->{logview_max_par} = $value*1);
1804 0 1998 0
1805 }, 1999 },
1806 ); 2000 );
1807 2001
1808 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave"); 2002 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Config Autosave");
1809 $table->add_at (1, $row, new DC::UI::CheckBox 2003 $table->add_at (1, $row, new DC::UI::CheckBox
1810 state => $CFG->{config_autosave}, 2004 state => $CFG->{config_autosave},
1811 tooltip => "Normally, configuration settings and the user interface layout " 2005 tooltip => "Normally, configuration settings and the user interface layout "
1812 . "are saved on client exit. You can disable this behaviour by " 2006 . "are saved on client exit. You can disable this behaviour by "
1813 . "unchecking this checkbox.", 2007 . "unchecking this checkbox.",
1814 on_changed => sub { 2008 on_changed => sub {
1815 my ($self, $value) = @_; 2009 my ($self, $value) = @_;
1816 $CFG->{config_autosave} = $value; 2010 $CFG->{config_autosave} = $value;
2011 0
1817 0 2012 }
1818 } 2013 );
1819 );
1820 $table->add_at (2, $row++, new DC::UI::Button 2014 $table->add_at (2, $row++, new DC::UI::Button
1821 text => "Save Now", 2015 text => "Save Now",
1822 tooltip => "Use this to manually save configuration and UI layout when " 2016 tooltip => "Use this to manually save configuration and UI layout when "
1823 . "autosave is disabled.", 2017 . "autosave is disabled.",
1824 on_activate => sub { 2018 on_activate => sub {
1825 DC::write_cfg; 2019 DC::save_cfg;
2020 0
1826 0 2021 }
1827 } 2022 );
1828 ); 2023 }
1829 2024
1830 $table 2025 {
2026 $bot->add (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]);
2027
2028 my $row = 0;
2029
2030 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
2031 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
2032 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2034 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2035 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
2036 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
2037 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
2038 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
2039 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
2040 }
2041
2042 $vbox
1831} 2043}
1832 2044
1833sub autopickup_setup { 2045sub autopickup_setup {
1834 my $r = new DC::UI::ScrolledWindow ( 2046 my $r = new DC::UI::ScrolledWindow (
1835 expand => 1, 2047 expand => 1,
2006 2218
2007sub media_window { 2219sub media_window {
2008 my $vb = new DC::UI::VBox; 2220 my $vb = new DC::UI::VBox;
2009 2221
2010 $vb->add (new DC::UI::FancyFrame 2222 $vb->add (new DC::UI::FancyFrame
2011 label => "Currently playing music", 2223 label => "Current background music",
2012 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2224 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), 2225 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2014 ); 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 });
2015 2262
2016 $vb->add (new DC::UI::FancyFrame 2263 $vb->add (new DC::UI::FancyFrame
2017 label => "Other media used in this session", 2264 label => "Other media used in this session",
2018 expand => 1, 2265 expand => 1,
2019 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2266 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2020 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2267 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2021 ); 2268 );
2022 2269
2023 $vb 2270 $vb
2024} 2271}
2025 2272
2210sub open_quit_dialog { 2457sub open_quit_dialog {
2211 unless ($QUIT_DIALOG) { 2458 unless ($QUIT_DIALOG) {
2212 $QUIT_DIALOG = new DC::UI::Toplevel 2459 $QUIT_DIALOG = new DC::UI::Toplevel
2213 x => "center", 2460 x => "center",
2214 y => "center", 2461 y => "center",
2215 z => 50, 2462 z => 60,
2216 title => "Really Quit?", 2463 title => "Really Quit?",
2217 on_key_down => sub { 2464 on_key_down => sub {
2218 my ($dialog, $ev) = @_; 2465 my ($dialog, $ev) = @_;
2219 $ev->{sym} == 27 and $dialog->hide; 2466 $ev->{sym} == 27 and $dialog->hide;
2220 } 2467 }
2436 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2683 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2437 2684
2438 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2685 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2439 $FULLSCREEN = $CFG->{fullscreen}; 2686 $FULLSCREEN = $CFG->{fullscreen};
2440 $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
2441 2690
2442 # 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
2443 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2692 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2444 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2693 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2445 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2694 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2632 2881
2633our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub { 2882our $INPUT_WATCHER = EV::periodic 0, 1 / $MAX_FPS, undef, sub {
2634 $NOW = EV::now; 2883 $NOW = EV::now;
2635 2884
2636 ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_) 2885 ($SDL_CB[$_->{type}] || sub { warn "unhandled event $_->{type}" })->($_)
2637 for DC::poll_events; 2886 for DC::peep_events;
2638 2887
2639 if (%animate_object) { 2888 if (%animate_object) {
2640 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2889 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2641 $WANT_REFRESH = 1; 2890 $WANT_REFRESH = 1;
2642 } 2891 }
2707# 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
2708sub DC::Main::main { 2957sub DC::Main::main {
2709 { 2958 {
2710 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2959 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2711 2960
2712 if (-e "$Deliantra::VARDIR/client.cf") { 2961 DC::load_cfg;
2713 DC::read_cfg "$Deliantra::VARDIR/client.cf";
2714 } else {
2715 #TODO: compatibility cruft
2716 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2717 print STDERR "INFO: used old configuration file\n";
2718 }
2719 2962
2720 DC::DB::Server::run; 2963 DC::DB::Server::run;
2721 2964
2722 if ($CFG->{db_schema} < 1) { 2965 if ($CFG->{db_schema} < 1) {
2723 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 2966 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2724 DC::DB::nuke_db; 2967 DC::DB::nuke_db;
2725 $CFG->{db_schema} = 1; 2968 $CFG->{db_schema} = 1;
2726 DC::write_cfg; 2969 DC::save_cfg;
2727 } 2970 }
2971
2972 DC::upgrade_cfg;
2728 2973
2729 DC::DB::open_db; 2974 DC::DB::open_db;
2730 2975
2731 DC::UI::set_layout ($::CFG->{layout}); 2976 DC::UI::set_layout ($::CFG->{layout});
2732
2733 my %DEF_CFG = (
2734 config_autosave => 1,
2735 sdl_mode => undef,
2736 fullscreen => 1,
2737 fast => 0,
2738 force_opengl11 => undef,
2739 disable_alpha => 0,
2740 smooth_movement => 1,
2741 smooth_transitions => 1,
2742 texture_compression => 1,
2743 map_scale => 1,
2744 fow_enable => 1,
2745 fow_intensity => 0,
2746 fow_texture => 0,
2747 map_smoothing => 1,
2748 gui_fontsize => 1,
2749 log_fontsize => 0.7,
2750 gauge_fontsize => 1,
2751 gauge_size => 0.35,
2752 stat_fontsize => 0.7,
2753 mapsize => 100,
2754 audio_enable => 1,
2755 audio_hw_channels => 0,
2756 audio_hw_frequency => 0,
2757 audio_hw_chunksize => 0,
2758 audio_mix_channels => 8,
2759 effects_enable => 1,
2760 effects_volume => 1,
2761 bgm_enable => 1,
2762 bgm_volume => 0.5,
2763 output_rate => "",
2764 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
2765 inv_sort => "mtime",
2766 default => "profile", # default profile
2767 show_tips => 1,
2768 logview_max_par => 1000,
2769 shift_fire_stop => 0,
2770 uitheme => "wood",
2771 map_shift_x => -24, # arbitrary
2772 map_shift_y => +24, # arbitrary
2773 );
2774
2775 while (my ($k, $v) = each %DEF_CFG) {
2776 $CFG->{$k} = $v unless exists $CFG->{$k};
2777 }
2778 2977
2779 my @args = @ARGV; 2978 my @args = @ARGV;
2780 2979
2781 # OS X passes some process serial number of other shit. they 2980 # OS X passes some process serial number of other shit. they
2782 # could have used an env var or any other sane mechanism. but 2981 # could have used an env var or any other sane mechanism. but
2814 }; 3013 };
2815 } 3014 }
2816 } 3015 }
2817 } 3016 }
2818 3017
3018 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3019 # these are ignored under windows, for some reason, and thus set in the loader
2819 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; 3020 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2820 $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts"; 3021 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3022 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2821 3023
2822 { 3024 {
2823 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3025 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2824 DejaVuSans.ttf 3026 DejaVuSans.ttf
2825 DejaVuSansMono.ttf 3027 DejaVuSansMono.ttf
2870 debug_toggle 0; 3072 debug_toggle 0;
2871 3073
2872 delete $SIG{__DIE__}; 3074 delete $SIG{__DIE__};
2873 EV::loop; 3075 EV::loop;
2874 3076
2875 DC::write_cfg if $CFG->{config_autosave}; 3077 DC::save_cfg if $CFG->{config_autosave};
2876 3078
2877 #video_shutdown; 3079 #video_shutdown;
2878 #audio_shutdown; 3080 #audio_shutdown;
2879 3081
2880 DC::OpenGL::quit; 3082 DC::OpenGL::quit;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines