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.4 by root, Fri Dec 30 04:15:32 2011 UTC vs.
Revision 1.31 by root, Mon Nov 19 00:56:08 2018 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
28use Deliantra; 29use Deliantra;
30use Deliantra::Util;
29use Deliantra::Protocol::Constants; 31use Deliantra::Protocol::Constants;
30 32
31use AnyEvent::Util (); 33use AnyEvent::Util ();
32use AnyEvent::Socket (); 34use AnyEvent::Socket ();
33use AnyEvent::DNS (); 35use AnyEvent::DNS ();
34 36
35use Compress::LZF; 37use Compress::LZF;
36use JSON::XS; 38use JSON::XS;
39use Urlader;
37 40
38use DC; 41use DC;
39 42
40sub crash($;$) { 43sub crash($;$) {
41 # nop at compiletime 44 # nop at compiletime
43 46
44BEGIN { 47BEGIN {
45 $SIG{__DIE__} = sub { 48 $SIG{__DIE__} = sub {
46 return if $^S; # quick reject 49 return if $^S; # quick reject
47 50
48 # return if there are any eval contexts in the csall stack 51 # return if there are any eval contexts in the call stack
49 for my $i (0..999) { 52 for my $i (0..999) {
50 my ($sub, $is_require) = (caller $i)[3, 7] 53 my ($sub, $is_require) = (caller $i)[3, 7]
51 or last; 54 or last;
52 return if $sub eq "(eval)" && !$is_require; 55 return if $sub eq "(eval)" && !$is_require;
53 } 56 }
56 DC::fatal Carp::longmess "$_[0]"; 59 DC::fatal Carp::longmess "$_[0]";
57 } 60 }
58} 61}
59 62
60use DC::OpenGL (); 63use DC::OpenGL ();
64use DC::Audio ();
61use DC::Protocol; 65use DC::Protocol;
62use DC::DB; 66use DC::DB;
63use DC::UI; 67use DC::UI;
64use DC::UI::Canvas; 68use DC::UI::Canvas;
65use DC::UI::Inventory; 69use DC::UI::Inventory;
70use DC::MessageDistributor; 74use DC::MessageDistributor;
71use DC::Pod; 75use DC::Pod;
72use DC::MapWidget; 76use DC::MapWidget;
73use DC::Macro; 77use DC::Macro;
74 78
79# printf "%5d %5d %5d %5d\n", $_, DC::minpot $_, DC::ld32 $_, 2 << ((DC::ld32 $_ - 1));
80
75$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 81$SIG{QUIT} = sub { Carp::cluck "QUIT" };
76$SIG{PIPE} = 'IGNORE'; 82$SIG{PIPE} = 'IGNORE';
77 83
78$EV::DIED = sub { 84$EV::DIED = sub {
79 crash "CRASH/EV::DIED: $@" => 0; 85 crash "CRASH/EV::DIED: $@" => 0;
125our $MENUBAR; # the hbox at the top 131our $MENUBAR; # the hbox at the top
126our $MENUPOPUP; 132our $MENUPOPUP;
127our $BUTTONBAR; # the menu buttons 133our $BUTTONBAR; # the menu buttons
128our $METASERVER; 134our $METASERVER;
129our $LOGIN_BUTTON; 135our $LOGIN_BUTTON;
136our $LOGIN_ERROR;
130our $QUIT_DIALOG; 137our $QUIT_DIALOG;
131our $HOST_ENTRY; 138our $HOST_ENTRY;
132our $FULLSCREEN_ENABLE; 139our $FULLSCREEN_ENABLE;
133our $PICKUP_ENABLE; 140our $PICKUP_ENABLE;
134our $SERVER_INFO; 141our $SERVER_INFO;
142our $PL_NOTEBOOK; 149our $PL_NOTEBOOK;
143our $PL_WINDOW; 150our $PL_WINDOW;
144 151
145our $MUSIC_PLAYING_WIDGET; 152our $MUSIC_PLAYING_WIDGET;
146our $LICENSE_WIDGET; 153our $LICENSE_WIDGET;
154our $DOWNLOADS_WIDGET;
147 155
148our $PICKUP_PAGE; 156our $PICKUP_PAGE;
149our $INVENTORY_PAGE; 157our $INVENTORY_PAGE;
150our $STATS_PAGE; 158our $STATS_PAGE;
151our $SKILL_PAGE; 159our $SKILL_PAGE;
194 AnyEvent::Util::fh_nonblocking $fh, 1; 202 AnyEvent::Util::fh_nonblocking $fh, 1;
195 203
196 $msg =~ s/\s+$//; 204 $msg =~ s/\s+$//;
197 205
198 # backtrace as second step, in case it crashes, too 206 # backtrace as second step, in case it crashes, too
199 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" 207 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated"
200 if $backtrace; 208 if $backtrace;
201}; 209};
202 210
203sub clienterror($;$) { 211sub clienterror($;$) {
204 my ($msg, $backtrace) = @_; 212 my ($msg, $backtrace) = @_;
206 warn $msg; 214 warn $msg;
207 215
208 return unless $CONN; 216 return unless $CONN;
209 217
210 $CONN->send_exti_msg (clientlog => $msg); 218 $CONN->send_exti_msg (clientlog => $msg);
211 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; 219 $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace;
212} 220}
213 221
214############################################################################# 222#############################################################################
215 223
216sub status { 224sub status {
247 : "[<span foreground='#888'>num</span>]"; 255 : "[<span foreground='#888'>num</span>]";
248 256
249 # <tt> around next statement works around some bug that keeps the 257 # <tt> around next statement works around some bug that keeps the
250 # "font =>" from being used on windows 258 # "font =>" from being used on windows
251 $MODBOX->set_markup ("<tt>$markup</tt>"); 259 $MODBOX->set_markup ("<tt>$markup</tt>");
260}
261
262sub errorbox {
263 my ($msg) = @_;
264
265 status $msg;
266
267 my $dialog = new DC::UI::Toplevel
268 x => "center",
269 y => "center",
270 z => 200,
271 title => "Error",
272 child => my $vbox = new DC::UI::VBox,
273 has_close_button => 1,
274 on_delete => sub {
275 $_[0]->destroy;
276 },
277 ;
278
279 add $vbox new DC::UI::Label
280 align => 0.5,
281 ellipsise => 0,
282 text => $msg;
283
284 add $vbox new DC::UI::Button
285 expand => 1,
286 text => "OK",
287 on_activate => sub {
288 $dialog->destroy;
289 0
290 }
291 ;
292
293 $dialog->show;
252} 294}
253 295
254############################################################################# 296#############################################################################
255#TODO: maybe move into own audio module... 297#TODO: maybe move into own audio module...
256 298
471 audio_music_push; 513 audio_music_push;
472} 514}
473 515
474sub audio_init { 516sub audio_init {
475 if ($CFG->{audio_enable}) { 517 if ($CFG->{audio_enable}) {
476 if (length $CFG->{audio_driver}) { 518 DC::Audio::init;
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 519
492 if ($SDL_MIXER) { 520 if ($SDL_MIXER) {
493 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
494
495 audio_music_finished; 521 audio_music_finished;
496 } else { 522 } else {
497 status "Unable to open sound device: there will be no sound"; 523 status "Unable to open sound device: there will be no sound";
498 } 524 }
499 } else { 525 } else {
521 547
522 DC::Mix_CloseAudio if $SDL_MIXER; 548 DC::Mix_CloseAudio if $SDL_MIXER;
523 undef $SDL_MIXER; 549 undef $SDL_MIXER;
524 550
525 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 551 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
552}
553
554#############################################################################
555# Over-the-air updates
556
557sub ota_update {
558 my ($face, $size, $md5) = @_;
559
560 my $coro = Coro::async_pool {
561 my $override = "$Urlader::EXE_DIR/override";
562
563 $MESSAGE_DIST->add_channel ({
564 id => "ota_update",
565 title => "Update",
566 tooltip => "<b>Software Update Log</b>",
567 });
568
569 $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." });
570
571 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777;
572
573 unless ($fh) {
574 $MESSAGE_DIST->message ({ type => "ota_update", markup => (DC::asxml "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!") });
575 return;
576 }
577
578 $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." });
579
580 my $cv = AE::cv;
581 my $error;
582
583 $cv->begin (Coro::rouse_cb);
584 $CONN->ask_face (
585 $face,
586 -1000,
587 sub {
588 $STATUSBOX->add (
589 (sprintf "update download: %d/%d", $size - $_[1], $size),
590 pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1]
591 );
592
593 $cv->begin;
594 my $len = length $_[2];
595 IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub {
596 $error ||= $_[0] != $len;
597 $cv->end;
598 };
599 },
600 sub {
601 $cv->end;
602 },
603 );
604
605 Coro::rouse_wait;
606
607 $STATUSBOX->clr_group ("ota_update");
608
609 $error ||= Coro::AIO::aio_fsync $fh;
610 $error ||= Coro::AIO::aio_close $fh;
611
612 if ($error) {
613 $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." });
614 Coro::AIO::aio_unlink "$override.tmp";
615 return;
616 }
617
618 {
619 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verifying update file..." });
620
621 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
622
623 if ($fh) {
624 $error ||= Coro::AIO::aio_stat "$override.tmp";
625 $error ||= -s _ != $size;
626 Coro::AIO::aio_readahead $fh, 0, $size;
627
628 my $f_md5 = new Digest::MD5;
629 binmode $fh; # ugh :(
630 $f_md5->addfile ($fh);
631 $f_md5 = $f_md5->hexdigest;
632 $error ||= $md5 ne $f_md5;
633 }
634 }
635
636 if ($error) {
637 $MESSAGE_DIST->message ({ type => "ota_update", markup => "verification failed, update aborted." });
638 Coro::AIO::aio_unlink "$override.tmp";
639 return;
640 }
641
642 $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." });
643
644 if (Coro::AIO::aio_rename "$override.tmp", $override) {
645 $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." });
646 Coro::AIO::aio_unlink "$override.tmp";
647 }
648
649 $MESSAGE_DIST->message ({ type => "ota_update", markup => "success - update becomes active after restarting." });
650 };
651
652 $CONN->{ota_update} = Guard::guard {
653 $coro->cancel;
654 };
655}
656
657sub ota_update_ask {
658 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
659
660 $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel
661 x => "center",
662 y => "center",
663 z => 55,
664 force_w => $::WIDTH * 0.7,
665 force_h => $::HEIGHT * 0.7,
666 title => "Software update available",
667 child => my $vbox = new DC::UI::VBox,
668 ;
669
670 $vbox->add (new DC::UI::Label
671 ellipsise => 0,
672 text => "The server offers a software update, "
673 . "do you want to start downloading this update in the background?",
674 );
675
676 $vbox->add (new DC::UI::FancyFrame
677 expand => 1,
678 label => "Details",
679 child => (new DC::UI::TextScroller
680 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4,
681 par => [{
682 markup => "<tt>Old revision: $Urlader::EXE_VER\n"
683 . "New revision: $ver\n"
684 . "Download size: $size bytes</tt>\n\n"
685 . "Changes:\n\n"
686 . DC::asxml $changes
687 }],
688 ),
689 );
690
691 $vbox->add (my $hbox = new DC::UI::HBox);
692
693 $hbox->add (new DC::UI::Button
694 expand => 1,
695 text => "Not now",
696 on_activate => sub {
697 $dialog->destroy;
698 0
699 }
700 );
701 $hbox->add (new DC::UI::Button
702 expand => 1,
703 text => "Yes, start downloading",
704 on_activate => sub {
705 $dialog->destroy;
706 ota_update $face, $size, $md5;
707 0
708 },
709 );
710
711 $dialog->show;
712}
713
714sub ota_update_check {
715 return unless defined $Urlader::EXE_ID;
716
717 ::message { markup => "Checking for software update..." };
718
719 $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub {
720 my ($ok, $face, $ver, $size, $md5, $changes) = @_;
721
722 if ($ok) {
723 if (defined $ver) {
724 ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." };
725 &ota_update_ask;
726 } else {
727 ::message { markup => "Server has no newer version." };
728 }
729 } else {
730 ::message { markup => "Server does not support software update." };
731 }
732
733 ()
734 });
526} 735}
527 736
528############################################################################# 737#############################################################################
529 738
530sub destroy_query_dialog { 739sub destroy_query_dialog {
757 $vbox->add (@dialog); 966 $vbox->add (@dialog);
758 $dialog->show; 967 $dialog->show;
759} 968}
760 969
761sub dc_connect { 970sub dc_connect {
762 my ($host, $port) = @_; 971 my ($host, $port, $create) = @_;
763 972
764 my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; 973 my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32;
765 my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; 974 my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
766 975
767 $CONN = 976 $CONN =
768 new DC::Protocol 977 new DC::Protocol
769 host => $host, 978 host => $host,
770 port => $port, 979 port => $port,
980 create_login => $create,
771 user => $PROFILE->{user}, 981 user => $PROFILE->{user},
772 pass => $PROFILE->{password}, 982 pass => (pack "H*", $PROFILE->{password}),
773 mapw => $mapw, 983 mapw => $mapw,
774 maph => $maph, 984 maph => $maph,
775 985
776 c_version => { 986 c_version => {
777 client => "deliantra", 987 client => "deliantra",
778 clientver => $DC::VERSION, 988 clientver => "$DC::VERSION$Urlader::EXE_VER",
779 gl_vendor => DC::OpenGL::gl_vendor, 989 gl_vendor => DC::OpenGL::gl_vendor,
780 gl_version => DC::OpenGL::gl_version, 990 gl_version => DC::OpenGL::gl_version,
781 }, 991 },
782 992
783 map_widget => $MAPWIDGET, 993 map_widget => $MAPWIDGET,
792 1002
793 on_connect => sub { 1003 on_connect => sub {
794 if ($_[0]) { 1004 if ($_[0]) {
795 DC::lowdelay fileno $CONN->{fh}; 1005 DC::lowdelay fileno $CONN->{fh};
796 1006
1007 ota_update_check;
1008
797 status "successfully connected to the server"; 1009 status "successfully connected to the server";
798 } else { 1010 } else {
799 undef $CONN; 1011 undef $CONN;
800 status "unable to connect: $!"; 1012 $LOGIN_ERROR->{fg} = [1, 0, 0];
1013 $LOGIN_ERROR->set_text ("Unable to connect to server: $!");
801 stop_game(); 1014 stop_game();
802 } 1015 }
803 }, 1016 },
1017
1018 on_addme => sub {
1019 my ($ok, $msg) = @_;
1020
1021 $LOGIN_ERROR->{fg} = $ok ? [0, 1, 0] : [1, 0, 0];
1022 $LOGIN_ERROR->set_text ($msg);
1023 },
804 ; 1024 ;
805} 1025}
806 1026
807sub start_game { 1027sub start_game($) {
1028 my ($create) = @_;
1029
808 status "logging in..."; 1030 status "logging in...";
809 1031
810 my $server = $PROFILE->{host} || $DEFAULT_SERVER; 1032 my $server = $PROFILE->{host} || $DEFAULT_SERVER;
811 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" 1033 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327"
812 or return status "$server: unable to parse server address, try an empty field."; 1034 or return status "$server: unable to parse server address, try an empty field.";
827 status "dns failure, using hardcoded address"; 1049 status "dns failure, using hardcoded address";
828 $host = "194.126.175.154"; 1050 $host = "194.126.175.154";
829 } 1051 }
830 } 1052 }
831 1053
832 dc_connect $host, $port; 1054 dc_connect $host, $port, $create;
833 }; 1055 };
834 } else { 1056 } else {
835 dc_connect $host, $port; 1057 dc_connect $host, $port, $create;
836 } 1058 }
837} 1059}
838 1060
839sub stop_game { 1061sub stop_game {
840 crash "stop_game"; 1062 crash "stop_game";
958 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); 1180 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
959 $table->add_at (1, $row++, new DC::UI::CheckBox 1181 $table->add_at (1, $row++, new DC::UI::CheckBox
960 state => $CFG->{texture_compression}, 1182 state => $CFG->{texture_compression},
961 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " 1183 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
962 . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). " 1184 . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). "
963 . "The compression algorithm can differ form card to card, so your mileage may vary. This setting is ignored in " 1185 . "The compression algorithm can differ from card to card, so your mileage may vary. This setting is ignored in "
964 . "forced OpenGL 1.1 mode and when using the Apple renderer.", 1186 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
965 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 1187 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
966 ); 1188 );
967 1189
968 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); 1190 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly");
1320 $DELIANTRA_DEBUG ^= $_[0]; 1542 $DELIANTRA_DEBUG ^= $_[0];
1321 1543
1322 if ($DELIANTRA_DEBUG & 16) { 1544 if ($DELIANTRA_DEBUG & 16) {
1323 $BW_WATCHER = EV::periodic 0, 1, 0, sub { 1545 $BW_WATCHER = EV::periodic 0, 1, 0, sub {
1324 return unless $CONN; 1546 return unless $CONN;
1325 debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3; 1547 debug sprintf "%8.2gkB/s", $CONN->{octets_in} / 1e3;
1326 $CONN->{octets_in} = 0; 1548 $CONN->{octets_in} = 0;
1327 }; 1549 };
1328 } else { 1550 } else {
1329 undef $BW_WATCHER; 1551 undef $BW_WATCHER;
1330 } 1552 }
1673 $vbox->add (new DC::UI::FancyFrame 1895 $vbox->add (new DC::UI::FancyFrame
1674 label => "Login Settings", 1896 label => "Login Settings",
1675 child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), 1897 child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]),
1676 ); 1898 );
1677 1899
1900 my $nullpw = "\x00" x 16;
1901
1678 $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username"); 1902 $table->add_at (0, 0, new DC::UI::Label align => 1, text => "Username");
1679 $table->add_at (1, 4, new DC::UI::Entry 1903 $table->add_at (1, 0, new DC::UI::Entry
1680 text => $PROFILE->{user}, 1904 text => $PROFILE->{user},
1681 tooltip => "The name of your character on the server. The name is case-sensitive!", 1905 tooltip => "The name of your character on the server. The name is case-sensitive!",
1682 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } 1906 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
1683 ); 1907 );
1684 1908
1685 $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password"); 1909 $table->add_at (0, 1, new DC::UI::Label align => 1, text => "Password");
1686 $table->add_at (1, 5, new DC::UI::Entry 1910 $table->add_at (1, 1, my $pw1 = new DC::UI::Entry
1687 text => $PROFILE->{password}, 1911 text => $PROFILE->{password} ? $nullpw : "",
1688 hidden => 1, 1912 hidden => 1,
1689 tooltip => "The password for your character.", 1913 tooltip => "The password for your character.",
1690 on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 } 1914 on_focus_in => sub {
1915 my ($self) = @_;
1916 $self->set_text ("")
1917 if $self->{text} eq $nullpw;
1918 0
1919 },
1920 on_changed => sub {
1921 my ($self, $value) = @_;
1922 $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $value
1923 if length $value && $value ne $nullpw;
1924 1
1925 },
1691 ); 1926 );
1692 1927
1693 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button 1928 $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button
1694 expand => 1, 1929 expand => 1,
1695 text => "Login / Register", 1930 text => "Login to Existing Account",
1696 tooltip => "This button will either login to the account configured above or register a new account.", 1931 tooltip => "This button will login to the account given by the <b>Username</b> and <b>Password</b> fields above.",
1697 on_activate => sub { 1932 on_activate => sub {
1698 $CONN ? stop_game 1933 $CONN ? stop_game
1699 : start_game; 1934 : start_game 0;
1700 1 1935 1
1701 }, 1936 },
1702 ); 1937 );
1703 1938
1939 $table->add_at (0, 3, new DC::UI::Label align => 1, text => "Password");
1940 $table->add_at (1, 3, my $pw2 = new DC::UI::Entry
1941 hidden => 1,
1942 tooltip => "The new password for your character",
1943 );
1944
1945 $table->add_at (1, 4, new DC::UI::Button
1946 expand => 1,
1947 text => "Create New Account",
1948 tooltip => "This button will try to create a new account - you need to fill out the <b>Username</b> and the two <b>Password</b> fields above, using the same password for both <b>Password</b> fields.",
1949 on_activate => sub {
1950 if ($pw1->{text} ne $pw2->{text}) {
1951 $LOGIN_ERROR->{fg} = [1, 0, 0];
1952 $LOGIN_ERROR->set_text ("The passwords do not match - try to enter them again.");
1953 } else {
1954 $CONN or start_game 1;
1955 }
1956 1
1957 },
1958 );
1959
1960 $vbox->add (new DC::UI::FancyFrame
1961 label => "Server Message",
1962 tooltip => "The last message, or error, from the server.",
1963 child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0),
1964 );
1965
1704 $vbox->add (new DC::UI::FancyFrame 1966 $vbox->add (new DC::UI::FancyFrame
1705 label => "How to Play", 1967 label => "How to Play",
1706 min_h => 240, 1968 min_h => 240,#d# should not be necessary - widget bug
1707 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1969 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1708 markup => 1970 markup =>
1709 "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" 1971 "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n"
1710 . "Then register a new account (or use an existing one if you have one). " 1972 . "Then create a new account (or use an existing one if you have one).\n\n"
1711 . "To register an account, choose a username that hasn't been taken yet (just guess) and " 1973 . "To create an account, choose a username that hasn't been taken yet (just guess) and "
1712 . "try to log-in. Follow the instructions in the Log tab in the message window.", 1974 . "fill out the top two <b>Password</b> fields using the same password, then press <b>Create New Account</b>.",
1713 ), 1975 ),
1714 ); 1976 );
1715 1977
1716 $vbox 1978 $vbox
1717} 1979}
1768 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate"); 2030 $table->add_at (0, ++$row, new DC::UI::Label align => 1, text => "Output-Rate");
1769 $table->add_at (1, $row, new DC::UI::Entry 2031 $table->add_at (1, $row, new DC::UI::Entry
1770 text => $CFG->{output_rate}, 2032 text => $CFG->{output_rate},
1771 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed " 2033 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1772 . "when sending data. When 0 or unset, the server " 2034 . "when sending data. When 0 or unset, the server "
1773 . "default will be used, which is usually around 100kb/s. Most servers will " 2035 . "default will be used, which is usually around 100kB/s. Most servers will "
1774 . "dynamically find an optimal rate, so adjust this only when necessary.", 2036 . "dynamically find an optimal rate, so adjust this only when necessary.",
1775 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, 2037 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1776 ); 2038 );
1777 2039
1778 $vbox->add (new DC::UI::FancyFrame 2040 $vbox->add (new DC::UI::FancyFrame
1835 $table->add_at (2, $row++, new DC::UI::Button 2097 $table->add_at (2, $row++, new DC::UI::Button
1836 text => "Save Now", 2098 text => "Save Now",
1837 tooltip => "Use this to manually save configuration and UI layout when " 2099 tooltip => "Use this to manually save configuration and UI layout when "
1838 . "autosave is disabled.", 2100 . "autosave is disabled.",
1839 on_activate => sub { 2101 on_activate => sub {
1840 DC::write_cfg; 2102 DC::save_cfg;
1841 0 2103 0
1842 } 2104 }
1843 ); 2105 );
1844 } 2106 }
1845 2107
1850 2112
1851 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); 2113 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
1852 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); 2114 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
1853 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); 2115 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
1854 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); 2116 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => "");
2117 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2118 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1855 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); 2119 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)");
1856 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_ID, tooltip => ""); 2120 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1857 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); 2121 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)");
1858 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_VER, tooltip => ""); 2122 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1859 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Update (Prebuilt)");
1860 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::UPDPAR, tooltip => "");
1861 } 2123 }
1862 2124
1863 $vbox 2125 $vbox
1864} 2126}
1865 2127
2039 2301
2040sub media_window { 2302sub media_window {
2041 my $vb = new DC::UI::VBox; 2303 my $vb = new DC::UI::VBox;
2042 2304
2043 $vb->add (new DC::UI::FancyFrame 2305 $vb->add (new DC::UI::FancyFrame
2044 label => "Currently playing music", 2306 label => "Current background music",
2045 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2307 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), 2308 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2047 ); 2309 );
2310
2311 $vb->add (new DC::UI::FancyFrame
2312 label => "Current downloads",
2313 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2314 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2315 );
2316
2317 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2318 my ($self) = @_;
2319
2320 delete $self->{updater};
2321 return unless $_[1];
2322
2323 $self->{updater} = AE::timer 0, 0.7, sub {
2324 $self->clear;
2325
2326 return unless $CONN;
2327
2328 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2329 return unless @nums;
2330
2331 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2332 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2333
2334 for my $row (0 .. $#nums) {
2335 my $num = $nums[$row];
2336
2337 my $total = length $CONN->{ix_recv_buf}{$num};
2338 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2339
2340 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2341 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2342 }
2343 };
2344 });
2048 2345
2049 $vb->add (new DC::UI::FancyFrame 2346 $vb->add (new DC::UI::FancyFrame
2050 label => "Other media used in this session", 2347 label => "Other media used in this session",
2051 expand => 1, 2348 expand => 1,
2052 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2349 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2053 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2350 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2054 ); 2351 );
2055 2352
2056 $vb 2353 $vb
2057} 2354}
2058 2355
2243sub open_quit_dialog { 2540sub open_quit_dialog {
2244 unless ($QUIT_DIALOG) { 2541 unless ($QUIT_DIALOG) {
2245 $QUIT_DIALOG = new DC::UI::Toplevel 2542 $QUIT_DIALOG = new DC::UI::Toplevel
2246 x => "center", 2543 x => "center",
2247 y => "center", 2544 y => "center",
2248 z => 50, 2545 z => 60,
2249 title => "Really Quit?", 2546 title => "Really Quit?",
2250 on_key_down => sub { 2547 on_key_down => sub {
2251 my ($dialog, $ev) = @_; 2548 my ($dialog, $ev) = @_;
2252 $ev->{sym} == 27 and $dialog->hide; 2549 $ev->{sym} == 27 and $dialog->hide;
2253 } 2550 }
2300 make_playerbook; 2597 make_playerbook;
2301 2598
2302 $MENUPOPUP = DC::UI::Menu->new (items => [ 2599 $MENUPOPUP = DC::UI::Menu->new (items => [
2303 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }], 2600 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
2304 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }], 2601 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
2305 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }], 2602 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
2306 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }], 2603 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
2307 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }], 2604 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
2308 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }], 2605 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
2309 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }], 2606 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
2310 ["Quit…" , sub { 2607 ["Quit…" , sub {
2311 if ($CONN) { 2608 if ($CONN) {
2312 open_quit_dialog; 2609 open_quit_dialog;
2313 } else { 2610 } else {
2314 EV::unloop EV::UNLOOP_ALL; 2611 EV::break EV::BREAK_ALL;
2315 } 2612 }
2316 }], 2613 }],
2317 ]); 2614 ]);
2318 2615
2319 $BUTTONBAR->add (new DC::UI::Button text => "Menu…", 2616 $BUTTONBAR->add (new DC::UI::Button text => "Menu…",
2446 DC::set_theme $CFG->{uitheme}; 2743 DC::set_theme $CFG->{uitheme};
2447 2744
2448 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2745 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2449 $SDL_REINIT = 0; 2746 $SDL_REINIT = 0;
2450 2747
2451 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2748 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2452 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2749 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2453 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2750 @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)"; 2751 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2455 2752
2456 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2753 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2469 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2766 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2470 2767
2471 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2768 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2472 $FULLSCREEN = $CFG->{fullscreen}; 2769 $FULLSCREEN = $CFG->{fullscreen};
2473 $FAST = $CFG->{fast}; 2770 $FAST = $CFG->{fast};
2771
2772 DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init
2474 2773
2475 # due to mac os x braindamage, we simply retry with !fullscreen in case of an error 2774 # 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 2775 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2477 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2776 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2478 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2777 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2688 delete $animate_object{$widget}; 2987 delete $animate_object{$widget};
2689} 2988}
2690 2989
2691$SDL_CB[DC::SDL_QUIT] = sub { 2990$SDL_CB[DC::SDL_QUIT] = sub {
2692 crash "SDL_QUIT"; 2991 crash "SDL_QUIT";
2693 EV::unloop EV::UNLOOP_ALL; 2992 EV::break EV::BREAK_ALL;
2694}; 2993};
2695$SDL_CB[DC::SDL_VIDEORESIZE] = sub { }; 2994$SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
2696$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub { 2995$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
2697 DC::UI::full_refresh; 2996 DC::UI::full_refresh;
2698}; 2997};
2731}; 3030};
2732 3031
2733############################################################################# 3032#############################################################################
2734 3033
2735$SIG{INT} = $SIG{TERM} = sub { 3034$SIG{INT} = $SIG{TERM} = sub {
2736 EV::unloop; 3035 EV::break;
2737 #d# TODO calling exit here hangs the process in some futex 3036 #d# TODO calling exit here hangs the process in some futex
2738}; 3037};
2739 3038
2740# due to mac os x + sdl combined braindamage, we need this contortion 3039# due to mac os x + sdl combined braindamage, we need this contortion
2741sub DC::Main::main { 3040sub DC::Main::run {
2742 { 3041 DC::SDL_main_hack {
3042 {
2743 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 3043 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2744 3044
2745 if (-e "$Deliantra::VARDIR/client.cf") { 3045 DC::load_cfg;
2746 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 3046 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 3047
3048 DC::Audio::probe;
3049
2753 DC::DB::Server::run; 3050 DC::DB::Server::run;
2754 3051
2755 if ($CFG->{db_schema} < 1) { 3052 if ($CFG->{db_schema} < 1) {
2756 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; 3053 warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n";
2757 DC::DB::nuke_db; 3054 DC::DB::nuke_db;
2758 $CFG->{db_schema} = 1; 3055 $CFG->{db_schema} = 1;
2759 DC::write_cfg; 3056 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 } 3057 }
2830 }
2831 3058
2832 $CFG->{profile}{$profile} ||= {}; 3059 DC::DB::open_db;
2833 $PROFILE = $CFG->{profile}{$profile};
2834 $PROFILE->{host} ||= "gameserver.deliantra.net";
2835 3060
2836 $PROFILE->{host} = $args[0] if @args > 0; 3061 DC::UI::set_layout ($::CFG->{layout});
2837 $PROFILE->{user} = $args[1] if @args > 1;
2838 $PROFILE->{password} = $args[2] if @args > 2;
2839 3062
2840 # convert old bindings (only default profile matters) 3063 my @args = @ARGV;
2841 if (my $bindings = delete $PROFILE->{bindings}) { 3064
2842 while (my ($mod, $syms) = each %$bindings) { 3065 # OS X passes some process serial number of other shit. they
2843 while (my ($sym, $cmds) = each %$syms) { 3066 # could have used an env var or any other sane mechanism. but
2844 push @{ $PROFILE->{macro} }, { 3067 # would it be os x then? no...
2845 accelkey => [$mod*1, $sym*1], 3068 shift @args if $args[0] =~ /^-psn_/;
2846 action => $cmds, 3069
3070 my $profile = 'default';
3071
3072 for (my $i = 0; $i < @args; $i++) {
3073 if ($args[$i] =~ /^--?profile$/) {
3074 $profile = $args[$i + 1];
3075 splice @args, $i, 2, ();
2847 }; 3076 $i = 0;
3077 } elsif ($args[$i] =~ /^--?h/) {
3078 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3079 exit 0;
2848 } 3080 }
2849 } 3081 }
3082
3083 $CFG->{profile}{$profile} ||= {};
3084 $PROFILE = $CFG->{profile}{$profile};
3085 $PROFILE->{host} ||= "gameserver.deliantra.net";
3086
3087 $PROFILE->{host} = $args[0] if @args > 0;
3088 $PROFILE->{user} = $args[1] if @args > 1;
3089 $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $args[2] if @args > 2;
3090
3091 # convert old bindings (only default profile matters)
3092 if (my $bindings = delete $PROFILE->{bindings}) {
3093 while (my ($mod, $syms) = each %$bindings) {
3094 while (my ($sym, $cmds) = each %$syms) {
3095 push @{ $PROFILE->{macro} }, {
3096 accelkey => [$mod*1, $sym*1],
3097 action => $cmds,
3098 };
3099 }
3100 }
2850 } 3101 }
2851 3102
2852 # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed 3103 # 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 3104 # these are ignored under windows, for some reason, and thus set in the loader
2854 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3105 $ENV{FONTCONFIG_FILE} = "fonts.conf";
2855 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3106 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
2856 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3107 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
2857 3108
2858 { 3109 {
2859 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3110 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2860 DejaVuSans.ttf 3111 DejaVuSans.ttf
2861 DejaVuSansMono.ttf 3112 DejaVuSansMono.ttf
2862 DejaVuSans-Bold.ttf 3113 DejaVuSans-Bold.ttf
2863 DejaVuSansMono-Bold.ttf 3114 DejaVuSansMono-Bold.ttf
2864 DejaVuSans-Oblique.ttf 3115 DejaVuSans-Oblique.ttf
2865 DejaVuSansMono-Oblique.ttf 3116 DejaVuSansMono-Oblique.ttf
2866 DejaVuSans-BoldOblique.ttf 3117 DejaVuSans-BoldOblique.ttf
2867 DejaVuSansMono-BoldOblique.ttf 3118 DejaVuSansMono-BoldOblique.ttf
2868 mona.ttf 3119 mona.ttf
2869 ); 3120 );
2870 3121
2871 DC::add_font $_ for @fonts; 3122 DC::add_font $_ for @fonts;
2872 3123
2873 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3124 $FONT_PROP = new_from_file DC::Font $fonts[0];
2874 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3125 $FONT_FIXED = new_from_file DC::Font $fonts[1];
2875 3126
2876 $FONT_PROP->make_default; 3127 $FONT_PROP->make_default;
2877 3128
2878 DC::pango_init; 3129 DC::pango_init;
2879 } 3130 }
2880 3131
2881# compare mono (ft) vs. rgba (cairo) 3132# compare mono (ft) vs. rgba (cairo)
2882# ft - 1.8s, cairo 3s, even in alpha-only mode 3133# ft - 1.8s, cairo 3s, even in alpha-only mode
2883# for my $rgba (0..1) { 3134# for my $rgba (0..1) {
2884# my $t1 = Time::HiRes::time; 3135# my $t1 = Time::HiRes::time;
2889# } 3140# }
2890# my $t2 = Time::HiRes::time; 3141# my $t2 = Time::HiRes::time;
2891# warn $t2-$t1; 3142# warn $t2-$t1;
2892# } 3143# }
2893 3144
3145 }
3146
3147 DC::SDL_Init 0;
2894 DC::IMG_Init; video_init; 3148 DC::IMG_Init; video_init;
2895 DC::Mix_Init; audio_init; 3149 DC::Mix_Init; audio_init;
2896 }
2897 3150
2898 show_tip_of_the_day if $CFG->{show_tips}; 3151 show_tip_of_the_day if $CFG->{show_tips};
2899 3152
2900 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3153 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
2901 undef $STARTUP_CANCEL; 3154 undef $STARTUP_CANCEL;
2902 (pop @::STARTUP_DONE)->() 3155 (pop @::STARTUP_DONE)->()
2903 while @::STARTUP_DONE; 3156 while @::STARTUP_DONE;
3157 };
3158
3159 debug_toggle 0;
3160
3161 delete $SIG{__DIE__};
3162 EV::run;
3163
3164 DC::save_cfg if $CFG->{config_autosave};
3165
3166 #video_shutdown;
3167 #audio_shutdown;
3168
3169 DC::OpenGL::quit;
3170 DC::SDL_Quit;
3171 DC::DB::Server::stop;
2904 }; 3172 };
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} 3173}
2920
2921*DC::Main::run = \&DC::SDL_braino; # see sub above
2922 3174
29231 31751

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines