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.22 by root, Sun Nov 4 02:13:53 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
31use AnyEvent::Socket (); 33use AnyEvent::Socket ();
32use AnyEvent::DNS (); 34use AnyEvent::DNS ();
33 35
34use Compress::LZF; 36use Compress::LZF;
35use JSON::XS; 37use JSON::XS;
38use Urlader;
36 39
37use DC; 40use DC;
38 41
39sub crash($;$) { 42sub crash($;$) {
40 # nop at compiletime 43 # nop at compiletime
41} 44}
42 45
43BEGIN { 46BEGIN {
44 $SIG{__DIE__} = sub { 47 $SIG{__DIE__} = sub {
45 return if $^S; 48 return if $^S; # quick reject
49
50 # return if there are any eval contexts in the call 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
46 crash "CRASH/DIE: $_[0]" => 1; 57 crash "CRASH/DIE: $_[0]" => 1;
47 DC::fatal Carp::longmess "$_[0]"; 58 DC::fatal Carp::longmess "$_[0]";
48 } 59 }
49} 60}
50 61
51use DC::OpenGL (); 62use DC::OpenGL ();
63use DC::Audio ();
52use DC::Protocol; 64use DC::Protocol;
53use DC::DB; 65use DC::DB;
54use DC::UI; 66use DC::UI;
55use DC::UI::Canvas; 67use DC::UI::Canvas;
56use DC::UI::Inventory; 68use DC::UI::Inventory;
133our $PL_NOTEBOOK; 145our $PL_NOTEBOOK;
134our $PL_WINDOW; 146our $PL_WINDOW;
135 147
136our $MUSIC_PLAYING_WIDGET; 148our $MUSIC_PLAYING_WIDGET;
137our $LICENSE_WIDGET; 149our $LICENSE_WIDGET;
150our $DOWNLOADS_WIDGET;
138 151
139our $PICKUP_PAGE; 152our $PICKUP_PAGE;
140our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
141our $STATS_PAGE; 154our $STATS_PAGE;
142our $SKILL_PAGE; 155our $SKILL_PAGE;
185 AnyEvent::Util::fh_nonblocking $fh, 1; 198 AnyEvent::Util::fh_nonblocking $fh, 1;
186 199
187 $msg =~ s/\s+$//; 200 $msg =~ s/\s+$//;
188 201
189 # backtrace as second step, in case it crashes, too 202 # backtrace as second step, in case it crashes, too
190 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"
191 if $backtrace; 204 if $backtrace;
192}; 205};
193 206
194sub clienterror($;$) { 207sub clienterror($;$) {
195 my ($msg, $backtrace) = @_; 208 my ($msg, $backtrace) = @_;
197 warn $msg; 210 warn $msg;
198 211
199 return unless $CONN; 212 return unless $CONN;
200 213
201 $CONN->send_exti_msg (clientlog => $msg); 214 $CONN->send_exti_msg (clientlog => $msg);
202 $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;
203} 216}
204 217
205############################################################################# 218#############################################################################
206 219
207sub status { 220sub status {
462 audio_music_push; 475 audio_music_push;
463} 476}
464 477
465sub audio_init { 478sub audio_init {
466 if ($CFG->{audio_enable}) { 479 if ($CFG->{audio_enable}) {
467 if (length $CFG->{audio_driver}) { 480 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 481
483 if ($SDL_MIXER) { 482 if ($SDL_MIXER) {
484 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
485
486 audio_music_finished; 483 audio_music_finished;
487 } else { 484 } else {
488 status "Unable to open sound device: there will be no sound"; 485 status "Unable to open sound device: there will be no sound";
489 } 486 }
490 } else { 487 } else {
512 509
513 DC::Mix_CloseAudio if $SDL_MIXER; 510 DC::Mix_CloseAudio if $SDL_MIXER;
514 undef $SDL_MIXER; 511 undef $SDL_MIXER;
515 512
516 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 });
517} 697}
518 698
519############################################################################# 699#############################################################################
520 700
521sub destroy_query_dialog { 701sub destroy_query_dialog {
764 mapw => $mapw, 944 mapw => $mapw,
765 maph => $maph, 945 maph => $maph,
766 946
767 c_version => { 947 c_version => {
768 client => "deliantra", 948 client => "deliantra",
769 clientver => $DC::VERSION, 949 clientver => "$DC::VERSION$Urlader::EXE_VER",
770 gl_vendor => DC::OpenGL::gl_vendor, 950 gl_vendor => DC::OpenGL::gl_vendor,
771 gl_version => DC::OpenGL::gl_version, 951 gl_version => DC::OpenGL::gl_version,
772 }, 952 },
773 953
774 map_widget => $MAPWIDGET, 954 map_widget => $MAPWIDGET,
782 }, 962 },
783 963
784 on_connect => sub { 964 on_connect => sub {
785 if ($_[0]) { 965 if ($_[0]) {
786 DC::lowdelay fileno $CONN->{fh}; 966 DC::lowdelay fileno $CONN->{fh};
967
968 ota_update_check;
787 969
788 status "successfully connected to the server"; 970 status "successfully connected to the server";
789 } else { 971 } else {
790 undef $CONN; 972 undef $CONN;
791 status "unable to connect: $!"; 973 status "unable to connect: $!";
1131 text => $CFG->{audio_driver}, 1313 text => $CFG->{audio_driver},
1132 template => "dsound1234", 1314 template => "dsound1234",
1133 tooltip => "You can override the audio driver to use here. Leaving it empty will result " 1315 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 " 1316 . "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> " 1317 . "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" 1318 . "or other system-specific drivers. Selecting the wrong driver here will simply result "
1137 . "in no sound.", 1319 . "in no sound.",
1138 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 } 1320 on_changed => sub { my ($self, $value) = @_; $CFG->{audio_driver} = $value; 1 }
1139 ); 1321 );
1140 1322
1141 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects"); 1323 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Sound Effects");
1826 $table->add_at (2, $row++, new DC::UI::Button 2008 $table->add_at (2, $row++, new DC::UI::Button
1827 text => "Save Now", 2009 text => "Save Now",
1828 tooltip => "Use this to manually save configuration and UI layout when " 2010 tooltip => "Use this to manually save configuration and UI layout when "
1829 . "autosave is disabled.", 2011 . "autosave is disabled.",
1830 on_activate => sub { 2012 on_activate => sub {
1831 DC::write_cfg; 2013 DC::save_cfg;
1832 0 2014 0
1833 } 2015 }
1834 ); 2016 );
1835 } 2017 }
1836 2018
1841 2023
1842 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); 2024 $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 => ""); 2025 $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"); 2026 $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 => ""); 2027 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2028 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2029 $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)"); 2030 $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 => ""); 2031 $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)"); 2032 $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 => ""); 2033 $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 } 2034 }
1853 2035
1854 $vbox 2036 $vbox
1855} 2037}
1856 2038
2030 2212
2031sub media_window { 2213sub media_window {
2032 my $vb = new DC::UI::VBox; 2214 my $vb = new DC::UI::VBox;
2033 2215
2034 $vb->add (new DC::UI::FancyFrame 2216 $vb->add (new DC::UI::FancyFrame
2035 label => "Currently playing music", 2217 label => "Current background music",
2036 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2218 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), 2219 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2038 ); 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 });
2039 2256
2040 $vb->add (new DC::UI::FancyFrame 2257 $vb->add (new DC::UI::FancyFrame
2041 label => "Other media used in this session", 2258 label => "Other media used in this session",
2042 expand => 1, 2259 expand => 1,
2043 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2260 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2044 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2261 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2045 ); 2262 );
2046 2263
2047 $vb 2264 $vb
2048} 2265}
2049 2266
2234sub open_quit_dialog { 2451sub open_quit_dialog {
2235 unless ($QUIT_DIALOG) { 2452 unless ($QUIT_DIALOG) {
2236 $QUIT_DIALOG = new DC::UI::Toplevel 2453 $QUIT_DIALOG = new DC::UI::Toplevel
2237 x => "center", 2454 x => "center",
2238 y => "center", 2455 y => "center",
2239 z => 50, 2456 z => 60,
2240 title => "Really Quit?", 2457 title => "Really Quit?",
2241 on_key_down => sub { 2458 on_key_down => sub {
2242 my ($dialog, $ev) = @_; 2459 my ($dialog, $ev) = @_;
2243 $ev->{sym} == 27 and $dialog->hide; 2460 $ev->{sym} == 27 and $dialog->hide;
2244 } 2461 }
2437 DC::set_theme $CFG->{uitheme}; 2654 DC::set_theme $CFG->{uitheme};
2438 2655
2439 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2656 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2440 $SDL_REINIT = 0; 2657 $SDL_REINIT = 0;
2441 2658
2442 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2659 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2443 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2660 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2444 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2661 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2445 @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)";
2446 2663
2447 @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;
2460 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2677 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2461 2678
2462 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2679 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2463 $FULLSCREEN = $CFG->{fullscreen}; 2680 $FULLSCREEN = $CFG->{fullscreen};
2464 $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
2465 2684
2466 # 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
2467 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2686 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2468 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2687 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2469 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2688 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2727 EV::unloop; 2946 EV::unloop;
2728 #d# TODO calling exit here hangs the process in some futex 2947 #d# TODO calling exit here hangs the process in some futex
2729}; 2948};
2730 2949
2731# 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
2732sub DC::Main::main { 2951sub DC::Main::run {
2733 { 2952 DC::SDL_main_hack {
2953 {
2734 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 2954 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2735 2955
2736 if (-e "$Deliantra::VARDIR/client.cf") { 2956 DC::load_cfg;
2737 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 2957 DC::upgrade_cfg;
2738 } else {
2739 #TODO: compatibility cruft
2740 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2741 print STDERR "INFO: used old configuration file\n";
2742 }
2743 2958
2959 DC::Audio::probe;
2960
2744 DC::DB::Server::run; 2961 DC::DB::Server::run;
2745 2962
2746 if ($CFG->{db_schema} < 1) { 2963 if ($CFG->{db_schema} < 1) {
2747 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";
2748 DC::DB::nuke_db; 2965 DC::DB::nuke_db;
2749 $CFG->{db_schema} = 1; 2966 $CFG->{db_schema} = 1;
2750 DC::write_cfg; 2967 DC::save_cfg;
2751 }
2752
2753 DC::DB::open_db;
2754
2755 DC::UI::set_layout ($::CFG->{layout});
2756
2757 my %DEF_CFG = (
2758 config_autosave => 1,
2759 sdl_mode => undef,
2760 fullscreen => 1,
2761 fast => 0,
2762 force_opengl11 => undef,
2763 disable_alpha => 0,
2764 smooth_movement => 1,
2765 smooth_transitions => 1,
2766 texture_compression => 1,
2767 map_scale => 1,
2768 fow_enable => 1,
2769 fow_intensity => 0,
2770 fow_texture => 0,
2771 map_smoothing => 1,
2772 gui_fontsize => 1,
2773 log_fontsize => 0.7,
2774 gauge_fontsize => 1,
2775 gauge_size => 0.35,
2776 stat_fontsize => 0.7,
2777 mapsize => 100,
2778 audio_enable => 1,
2779 audio_hw_channels => 0,
2780 audio_hw_frequency => 0,
2781 audio_hw_chunksize => 0,
2782 audio_mix_channels => 8,
2783 effects_enable => 1,
2784 effects_volume => 1,
2785 bgm_enable => 1,
2786 bgm_volume => 0.5,
2787 output_rate => "",
2788 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
2789 inv_sort => "mtime",
2790 default => "profile", # default profile
2791 show_tips => 1,
2792 logview_max_par => 1000,
2793 shift_fire_stop => 0,
2794 uitheme => "wood",
2795 map_shift_x => -24, # arbitrary
2796 map_shift_y => +24, # arbitrary
2797 );
2798
2799 while (my ($k, $v) = each %DEF_CFG) {
2800 $CFG->{$k} = $v unless exists $CFG->{$k};
2801 }
2802
2803 my @args = @ARGV;
2804
2805 # OS X passes some process serial number of other shit. they
2806 # could have used an env var or any other sane mechanism. but
2807 # would it be os x then? no...
2808 shift @args if $args[0] =~ /^-psn_/;
2809
2810 my $profile = 'default';
2811
2812 for (my $i = 0; $i < @args; $i++) {
2813 if ($args[$i] =~ /^--?profile$/) {
2814 $profile = $args[$i + 1];
2815 splice @args, $i, 2, ();
2816 $i = 0;
2817 } elsif ($args[$i] =~ /^--?h/) {
2818 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2819 exit 0;
2820 } 2968 }
2821 }
2822 2969
2823 $CFG->{profile}{$profile} ||= {}; 2970 DC::DB::open_db;
2824 $PROFILE = $CFG->{profile}{$profile};
2825 $PROFILE->{host} ||= "gameserver.deliantra.net";
2826 2971
2827 $PROFILE->{host} = $args[0] if @args > 0; 2972 DC::UI::set_layout ($::CFG->{layout});
2828 $PROFILE->{user} = $args[1] if @args > 1;
2829 $PROFILE->{password} = $args[2] if @args > 2;
2830 2973
2831 # convert old bindings (only default profile matters) 2974 my @args = @ARGV;
2832 if (my $bindings = delete $PROFILE->{bindings}) { 2975
2833 while (my ($mod, $syms) = each %$bindings) { 2976 # OS X passes some process serial number of other shit. they
2834 while (my ($sym, $cmds) = each %$syms) { 2977 # could have used an env var or any other sane mechanism. but
2835 push @{ $PROFILE->{macro} }, { 2978 # would it be os x then? no...
2836 accelkey => [$mod*1, $sym*1], 2979 shift @args if $args[0] =~ /^-psn_/;
2837 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, ();
2838 }; 2987 $i = 0;
2988 } elsif ($args[$i] =~ /^--?h/) {
2989 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
2990 exit 0;
2839 } 2991 }
2840 } 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 }
2841 } 3012 }
2842 3013
3014 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed
3015 # these are ignored under windows, for some reason, and thus set in the loader
2843 $ENV{FONTCONFIG_FILE} = DC::find_rcfile "fonts/fonts.conf"; 3016 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2844 $ENV{FONTCONFIG_DIR} = DC::find_rcfile "fonts"; 3017 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3018 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2845 3019
2846 { 3020 {
2847 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3021 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2848 DejaVuSans.ttf 3022 DejaVuSans.ttf
2849 DejaVuSansMono.ttf 3023 DejaVuSansMono.ttf
2850 DejaVuSans-Bold.ttf 3024 DejaVuSans-Bold.ttf
2851 DejaVuSansMono-Bold.ttf 3025 DejaVuSansMono-Bold.ttf
2852 DejaVuSans-Oblique.ttf 3026 DejaVuSans-Oblique.ttf
2853 DejaVuSansMono-Oblique.ttf 3027 DejaVuSansMono-Oblique.ttf
2854 DejaVuSans-BoldOblique.ttf 3028 DejaVuSans-BoldOblique.ttf
2855 DejaVuSansMono-BoldOblique.ttf 3029 DejaVuSansMono-BoldOblique.ttf
2856 mona.ttf 3030 mona.ttf
2857 ); 3031 );
2858 3032
2859 DC::add_font $_ for @fonts; 3033 DC::add_font $_ for @fonts;
2860 3034
2861 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3035 $FONT_PROP = new_from_file DC::Font $fonts[0];
2862 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3036 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2863 3037
2864 $FONT_PROP->make_default; 3038 $FONT_PROP->make_default;
2865 3039
2866 DC::pango_init; 3040 DC::pango_init;
2867 } 3041 }
2868 3042
2869# compare mono (ft) vs. rgba (cairo) 3043# compare mono (ft) vs. rgba (cairo)
2870# ft - 1.8s, cairo 3s, even in alpha-only mode 3044# ft - 1.8s, cairo 3s, even in alpha-only mode
2871# for my $rgba (0..1) { 3045# for my $rgba (0..1) {
2872# my $t1 = Time::HiRes::time; 3046# my $t1 = Time::HiRes::time;
2877# } 3051# }
2878# my $t2 = Time::HiRes::time; 3052# my $t2 = Time::HiRes::time;
2879# warn $t2-$t1; 3053# warn $t2-$t1;
2880# } 3054# }
2881 3055
3056 }
3057
3058 DC::SDL_Init 0;
2882 DC::IMG_Init; video_init; 3059 DC::IMG_Init; video_init;
2883 DC::Mix_Init; audio_init; 3060 DC::Mix_Init; audio_init;
2884 }
2885 3061
2886 show_tip_of_the_day if $CFG->{show_tips}; 3062 show_tip_of_the_day if $CFG->{show_tips};
2887 3063
2888 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3064 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
2889 undef $STARTUP_CANCEL; 3065 undef $STARTUP_CANCEL;
2890 (pop @::STARTUP_DONE)->() 3066 (pop @::STARTUP_DONE)->()
2891 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;
2892 }; 3083 };
2893
2894 debug_toggle 0;
2895
2896 delete $SIG{__DIE__};
2897 EV::loop;
2898
2899 DC::write_cfg if $CFG->{config_autosave};
2900
2901 #video_shutdown;
2902 #audio_shutdown;
2903
2904 DC::OpenGL::quit;
2905 DC::SDL_Quit;
2906 DC::DB::Server::stop;
2907} 3084}
2908
2909*DC::Main::run = \&DC::SDL_braino; # see sub above
2910 3085
29111 30861

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines