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.9 by root, Thu Jan 5 05:37:02 2012 UTC vs.
Revision 1.31 by root, Mon Nov 19 00:56:08 2018 UTC

25BEGIN { *time = \&EV::time } 25BEGIN { *time = \&EV::time }
26 26
27use List::Util qw(max min); 27use List::Util qw(max min);
28 28
29use Deliantra; 29use Deliantra;
30use Deliantra::Util;
30use Deliantra::Protocol::Constants; 31use Deliantra::Protocol::Constants;
31 32
32use AnyEvent::Util (); 33use AnyEvent::Util ();
33use AnyEvent::Socket (); 34use AnyEvent::Socket ();
34use AnyEvent::DNS (); 35use AnyEvent::DNS ();
35 36
36use Compress::LZF; 37use Compress::LZF;
37use JSON::XS; 38use JSON::XS;
39use Urlader;
38 40
39use DC; 41use DC;
40 42
41sub crash($;$) { 43sub crash($;$) {
42 # nop at compiletime 44 # nop at compiletime
44 46
45BEGIN { 47BEGIN {
46 $SIG{__DIE__} = sub { 48 $SIG{__DIE__} = sub {
47 return if $^S; # quick reject 49 return if $^S; # quick reject
48 50
49 # return if there are any eval contexts in the csall stack 51 # return if there are any eval contexts in the call stack
50 for my $i (0..999) { 52 for my $i (0..999) {
51 my ($sub, $is_require) = (caller $i)[3, 7] 53 my ($sub, $is_require) = (caller $i)[3, 7]
52 or last; 54 or last;
53 return if $sub eq "(eval)" && !$is_require; 55 return if $sub eq "(eval)" && !$is_require;
54 } 56 }
57 DC::fatal Carp::longmess "$_[0]"; 59 DC::fatal Carp::longmess "$_[0]";
58 } 60 }
59} 61}
60 62
61use DC::OpenGL (); 63use DC::OpenGL ();
64use DC::Audio ();
62use DC::Protocol; 65use DC::Protocol;
63use DC::DB; 66use DC::DB;
64use DC::UI; 67use DC::UI;
65use DC::UI::Canvas; 68use DC::UI::Canvas;
66use DC::UI::Inventory; 69use DC::UI::Inventory;
71use DC::MessageDistributor; 74use DC::MessageDistributor;
72use DC::Pod; 75use DC::Pod;
73use DC::MapWidget; 76use DC::MapWidget;
74use DC::Macro; 77use DC::Macro;
75 78
79# printf "%5d %5d %5d %5d\n", $_, DC::minpot $_, DC::ld32 $_, 2 << ((DC::ld32 $_ - 1));
80
76$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 81$SIG{QUIT} = sub { Carp::cluck "QUIT" };
77$SIG{PIPE} = 'IGNORE'; 82$SIG{PIPE} = 'IGNORE';
78 83
79$EV::DIED = sub { 84$EV::DIED = sub {
80 crash "CRASH/EV::DIED: $@" => 0; 85 crash "CRASH/EV::DIED: $@" => 0;
126our $MENUBAR; # the hbox at the top 131our $MENUBAR; # the hbox at the top
127our $MENUPOPUP; 132our $MENUPOPUP;
128our $BUTTONBAR; # the menu buttons 133our $BUTTONBAR; # the menu buttons
129our $METASERVER; 134our $METASERVER;
130our $LOGIN_BUTTON; 135our $LOGIN_BUTTON;
136our $LOGIN_ERROR;
131our $QUIT_DIALOG; 137our $QUIT_DIALOG;
132our $HOST_ENTRY; 138our $HOST_ENTRY;
133our $FULLSCREEN_ENABLE; 139our $FULLSCREEN_ENABLE;
134our $PICKUP_ENABLE; 140our $PICKUP_ENABLE;
135our $SERVER_INFO; 141our $SERVER_INFO;
196 AnyEvent::Util::fh_nonblocking $fh, 1; 202 AnyEvent::Util::fh_nonblocking $fh, 1;
197 203
198 $msg =~ s/\s+$//; 204 $msg =~ s/\s+$//;
199 205
200 # backtrace as second step, in case it crashes, too 206 # backtrace as second step, in case it crashes, too
201 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"
202 if $backtrace; 208 if $backtrace;
203}; 209};
204 210
205sub clienterror($;$) { 211sub clienterror($;$) {
206 my ($msg, $backtrace) = @_; 212 my ($msg, $backtrace) = @_;
208 warn $msg; 214 warn $msg;
209 215
210 return unless $CONN; 216 return unless $CONN;
211 217
212 $CONN->send_exti_msg (clientlog => $msg); 218 $CONN->send_exti_msg (clientlog => $msg);
213 $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;
214} 220}
215 221
216############################################################################# 222#############################################################################
217 223
218sub status { 224sub status {
249 : "[<span foreground='#888'>num</span>]"; 255 : "[<span foreground='#888'>num</span>]";
250 256
251 # <tt> around next statement works around some bug that keeps the 257 # <tt> around next statement works around some bug that keeps the
252 # "font =>" from being used on windows 258 # "font =>" from being used on windows
253 $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;
254} 294}
255 295
256############################################################################# 296#############################################################################
257#TODO: maybe move into own audio module... 297#TODO: maybe move into own audio module...
258 298
473 audio_music_push; 513 audio_music_push;
474} 514}
475 515
476sub audio_init { 516sub audio_init {
477 if ($CFG->{audio_enable}) { 517 if ($CFG->{audio_enable}) {
478 if (length $CFG->{audio_driver}) { 518 DC::Audio::init;
479 local $ENV{SDL_AUDIODRIVER} = $CFG->{audio_driver};
480 DC::SDL_Init DC::SDL_INIT_AUDIO
481 and die "SDL::Init failed!\n";
482 } else {
483 DC::SDL_Init DC::SDL_INIT_AUDIO
484 and die "SDL::Init failed!\n";
485 }
486
487 $ENV{MIX_EFFECTSMAXSPEED} = 1;
488 $SDL_MIXER = !DC::Mix_OpenAudio
489 $CFG->{audio_hw_frequency},
490 DC::MIX_DEFAULT_FORMAT,
491 $CFG->{audio_hw_channels},
492 $CFG->{audio_hw_chunksize};
493 519
494 if ($SDL_MIXER) { 520 if ($SDL_MIXER) {
495 DC::Mix_AllocateChannels $CFG->{audio_mix_channels};
496
497 audio_music_finished; 521 audio_music_finished;
498 } else { 522 } else {
499 status "Unable to open sound device: there will be no sound"; 523 status "Unable to open sound device: there will be no sound";
500 } 524 }
501 } else { 525 } else {
597 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; 621 my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0;
598 622
599 if ($fh) { 623 if ($fh) {
600 $error ||= Coro::AIO::aio_stat "$override.tmp"; 624 $error ||= Coro::AIO::aio_stat "$override.tmp";
601 $error ||= -s _ != $size; 625 $error ||= -s _ != $size;
602 $error ||= Coro::AIO::aio_readahead $fh, 0, $size; 626 Coro::AIO::aio_readahead $fh, 0, $size;
603 627
604 my $f_md5 = new Digest::MD5; 628 my $f_md5 = new Digest::MD5;
629 binmode $fh; # ugh :(
605 $f_md5->addfile ($fh); 630 $f_md5->addfile ($fh);
606 $f_md5 = $f_md5->hexdigest; 631 $f_md5 = $f_md5->hexdigest;
607 $error ||= $md5 ne $f_md5; 632 $error ||= $md5 ne $f_md5;
608 } 633 }
609 } 634 }
702 ::message { markup => "Server has no newer version." }; 727 ::message { markup => "Server has no newer version." };
703 } 728 }
704 } else { 729 } else {
705 ::message { markup => "Server does not support software update." }; 730 ::message { markup => "Server does not support software update." };
706 } 731 }
707
708# $self->register_face_handler ($exp_table, sub {
709# my ($face) = @_;
710
711# $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
712# $_->() for values %{ $self->{on_exp_update} || {} };
713# });
714 732
715 () 733 ()
716 }); 734 });
717} 735}
718 736
948 $vbox->add (@dialog); 966 $vbox->add (@dialog);
949 $dialog->show; 967 $dialog->show;
950} 968}
951 969
952sub dc_connect { 970sub dc_connect {
953 my ($host, $port) = @_; 971 my ($host, $port, $create) = @_;
954 972
955 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;
956 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;
957 975
958 $CONN = 976 $CONN =
959 new DC::Protocol 977 new DC::Protocol
960 host => $host, 978 host => $host,
961 port => $port, 979 port => $port,
980 create_login => $create,
962 user => $PROFILE->{user}, 981 user => $PROFILE->{user},
963 pass => $PROFILE->{password}, 982 pass => (pack "H*", $PROFILE->{password}),
964 mapw => $mapw, 983 mapw => $mapw,
965 maph => $maph, 984 maph => $maph,
966 985
967 c_version => { 986 c_version => {
968 client => "deliantra", 987 client => "deliantra",
969 clientver => $DC::VERSION, 988 clientver => "$DC::VERSION$Urlader::EXE_VER",
970 gl_vendor => DC::OpenGL::gl_vendor, 989 gl_vendor => DC::OpenGL::gl_vendor,
971 gl_version => DC::OpenGL::gl_version, 990 gl_version => DC::OpenGL::gl_version,
972 }, 991 },
973 992
974 map_widget => $MAPWIDGET, 993 map_widget => $MAPWIDGET,
988 ota_update_check; 1007 ota_update_check;
989 1008
990 status "successfully connected to the server"; 1009 status "successfully connected to the server";
991 } else { 1010 } else {
992 undef $CONN; 1011 undef $CONN;
993 status "unable to connect: $!"; 1012 $LOGIN_ERROR->{fg} = [1, 0, 0];
1013 $LOGIN_ERROR->set_text ("Unable to connect to server: $!");
994 stop_game(); 1014 stop_game();
995 } 1015 }
996 }, 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 },
997 ; 1024 ;
998} 1025}
999 1026
1000sub start_game { 1027sub start_game($) {
1028 my ($create) = @_;
1029
1001 status "logging in..."; 1030 status "logging in...";
1002 1031
1003 my $server = $PROFILE->{host} || $DEFAULT_SERVER; 1032 my $server = $PROFILE->{host} || $DEFAULT_SERVER;
1004 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" 1033 my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327"
1005 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.";
1020 status "dns failure, using hardcoded address"; 1049 status "dns failure, using hardcoded address";
1021 $host = "194.126.175.154"; 1050 $host = "194.126.175.154";
1022 } 1051 }
1023 } 1052 }
1024 1053
1025 dc_connect $host, $port; 1054 dc_connect $host, $port, $create;
1026 }; 1055 };
1027 } else { 1056 } else {
1028 dc_connect $host, $port; 1057 dc_connect $host, $port, $create;
1029 } 1058 }
1030} 1059}
1031 1060
1032sub stop_game { 1061sub stop_game {
1033 crash "stop_game"; 1062 crash "stop_game";
1151 $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");
1152 $table->add_at (1, $row++, new DC::UI::CheckBox 1181 $table->add_at (1, $row++, new DC::UI::CheckBox
1153 state => $CFG->{texture_compression}, 1182 state => $CFG->{texture_compression},
1154 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 "
1155 . "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). "
1156 . "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 "
1157 . "forced OpenGL 1.1 mode and when using the Apple renderer.", 1186 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
1158 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 1187 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
1159 ); 1188 );
1160 1189
1161 $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");
1513 $DELIANTRA_DEBUG ^= $_[0]; 1542 $DELIANTRA_DEBUG ^= $_[0];
1514 1543
1515 if ($DELIANTRA_DEBUG & 16) { 1544 if ($DELIANTRA_DEBUG & 16) {
1516 $BW_WATCHER = EV::periodic 0, 1, 0, sub { 1545 $BW_WATCHER = EV::periodic 0, 1, 0, sub {
1517 return unless $CONN; 1546 return unless $CONN;
1518 debug sprintf "%8.2gKB/s", $CONN->{octets_in} / 1e3; 1547 debug sprintf "%8.2gkB/s", $CONN->{octets_in} / 1e3;
1519 $CONN->{octets_in} = 0; 1548 $CONN->{octets_in} = 0;
1520 }; 1549 };
1521 } else { 1550 } else {
1522 undef $BW_WATCHER; 1551 undef $BW_WATCHER;
1523 } 1552 }
1866 $vbox->add (new DC::UI::FancyFrame 1895 $vbox->add (new DC::UI::FancyFrame
1867 label => "Login Settings", 1896 label => "Login Settings",
1868 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]),
1869 ); 1898 );
1870 1899
1900 my $nullpw = "\x00" x 16;
1901
1871 $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");
1872 $table->add_at (1, 4, new DC::UI::Entry 1903 $table->add_at (1, 0, new DC::UI::Entry
1873 text => $PROFILE->{user}, 1904 text => $PROFILE->{user},
1874 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!",
1875 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } 1906 on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 }
1876 ); 1907 );
1877 1908
1878 $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");
1879 $table->add_at (1, 5, new DC::UI::Entry 1910 $table->add_at (1, 1, my $pw1 = new DC::UI::Entry
1880 text => $PROFILE->{password}, 1911 text => $PROFILE->{password} ? $nullpw : "",
1881 hidden => 1, 1912 hidden => 1,
1882 tooltip => "The password for your character.", 1913 tooltip => "The password for your character.",
1883 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 },
1884 ); 1926 );
1885 1927
1886 $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button 1928 $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button
1887 expand => 1, 1929 expand => 1,
1888 text => "Login / Register", 1930 text => "Login to Existing Account",
1889 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.",
1890 on_activate => sub { 1932 on_activate => sub {
1891 $CONN ? stop_game 1933 $CONN ? stop_game
1892 : start_game; 1934 : start_game 0;
1893 1 1935 1
1894 }, 1936 },
1895 ); 1937 );
1896 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
1897 $vbox->add (new DC::UI::FancyFrame 1966 $vbox->add (new DC::UI::FancyFrame
1898 label => "How to Play", 1967 label => "How to Play",
1899 min_h => 240, 1968 min_h => 240,#d# should not be necessary - widget bug
1900 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1969 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1901 markup => 1970 markup =>
1902 "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"
1903 . "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"
1904 . "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 "
1905 . "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>.",
1906 ), 1975 ),
1907 ); 1976 );
1908 1977
1909 $vbox 1978 $vbox
1910} 1979}
1961 $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");
1962 $table->add_at (1, $row, new DC::UI::Entry 2031 $table->add_at (1, $row, new DC::UI::Entry
1963 text => $CFG->{output_rate}, 2032 text => $CFG->{output_rate},
1964 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 "
1965 . "when sending data. When 0 or unset, the server " 2034 . "when sending data. When 0 or unset, the server "
1966 . "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 "
1967 . "dynamically find an optimal rate, so adjust this only when necessary.", 2036 . "dynamically find an optimal rate, so adjust this only when necessary.",
1968 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 }, 2037 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1969 ); 2038 );
1970 2039
1971 $vbox->add (new DC::UI::FancyFrame 2040 $vbox->add (new DC::UI::FancyFrame
2028 $table->add_at (2, $row++, new DC::UI::Button 2097 $table->add_at (2, $row++, new DC::UI::Button
2029 text => "Save Now", 2098 text => "Save Now",
2030 tooltip => "Use this to manually save configuration and UI layout when " 2099 tooltip => "Use this to manually save configuration and UI layout when "
2031 . "autosave is disabled.", 2100 . "autosave is disabled.",
2032 on_activate => sub { 2101 on_activate => sub {
2033 DC::write_cfg; 2102 DC::save_cfg;
2034 0 2103 0
2035 } 2104 }
2036 ); 2105 );
2037 } 2106 }
2038 2107
2528 make_playerbook; 2597 make_playerbook;
2529 2598
2530 $MENUPOPUP = DC::UI::Menu->new (items => [ 2599 $MENUPOPUP = DC::UI::Menu->new (items => [
2531 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }], 2600 ["Setup…\tF9" , sub { $SETUP_DIALOG->toggle_visibility }],
2532 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }], 2601 ["Playerbook…\tTab" , sub { $PL_WINDOW ->toggle_visibility }],
2533 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }], 2602 ["…Statistics\tF2" , sub { toggle_player_page ($::STATS_PAGE) }],
2534 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }], 2603 ["…Skills\tF3" , sub { toggle_player_page ($::SKILL_PAGE) }],
2535 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }], 2604 ["…Spells\tF4" , sub { toggle_player_page ($::SPELL_PAGE) }],
2536 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }], 2605 ["…Inventory\tF5" , sub { toggle_player_page ($::INVENTORY_PAGE) }],
2537 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }], 2606 ["Help Browser…\tF1" , sub { $HELP_WINDOW ->toggle_visibility }],
2538 ["Quit…" , sub { 2607 ["Quit…" , sub {
2539 if ($CONN) { 2608 if ($CONN) {
2540 open_quit_dialog; 2609 open_quit_dialog;
2541 } else { 2610 } else {
2542 EV::unloop EV::UNLOOP_ALL; 2611 EV::break EV::BREAK_ALL;
2543 } 2612 }
2544 }], 2613 }],
2545 ]); 2614 ]);
2546 2615
2547 $BUTTONBAR->add (new DC::UI::Button text => "Menu…", 2616 $BUTTONBAR->add (new DC::UI::Button text => "Menu…",
2674 DC::set_theme $CFG->{uitheme}; 2743 DC::set_theme $CFG->{uitheme};
2675 2744
2676 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2745 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2677 $SDL_REINIT = 0; 2746 $SDL_REINIT = 0;
2678 2747
2679 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2748 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2;
2680 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2749 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2681 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2750 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2682 @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)";
2683 2752
2684 @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;
2697 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2766 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2698 2767
2699 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2768 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2700 $FULLSCREEN = $CFG->{fullscreen}; 2769 $FULLSCREEN = $CFG->{fullscreen};
2701 $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
2702 2773
2703 # 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
2704 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN 2775 DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
2705 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN 2776 or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN
2706 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; 2777 or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n";
2916 delete $animate_object{$widget}; 2987 delete $animate_object{$widget};
2917} 2988}
2918 2989
2919$SDL_CB[DC::SDL_QUIT] = sub { 2990$SDL_CB[DC::SDL_QUIT] = sub {
2920 crash "SDL_QUIT"; 2991 crash "SDL_QUIT";
2921 EV::unloop EV::UNLOOP_ALL; 2992 EV::break EV::BREAK_ALL;
2922}; 2993};
2923$SDL_CB[DC::SDL_VIDEORESIZE] = sub { }; 2994$SDL_CB[DC::SDL_VIDEORESIZE] = sub { };
2924$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub { 2995$SDL_CB[DC::SDL_VIDEOEXPOSE] = sub {
2925 DC::UI::full_refresh; 2996 DC::UI::full_refresh;
2926}; 2997};
2959}; 3030};
2960 3031
2961############################################################################# 3032#############################################################################
2962 3033
2963$SIG{INT} = $SIG{TERM} = sub { 3034$SIG{INT} = $SIG{TERM} = sub {
2964 EV::unloop; 3035 EV::break;
2965 #d# TODO calling exit here hangs the process in some futex 3036 #d# TODO calling exit here hangs the process in some futex
2966}; 3037};
2967 3038
2968# 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
2969sub DC::Main::main { 3040sub DC::Main::run {
2970 { 3041 DC::SDL_main_hack {
3042 {
2971 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; 3043 DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst";
2972 3044
2973 if (-e "$Deliantra::VARDIR/client.cf") { 3045 DC::load_cfg;
2974 DC::read_cfg "$Deliantra::VARDIR/client.cf"; 3046 DC::upgrade_cfg;
2975 } else {
2976 #TODO: compatibility cruft
2977 DC::read_cfg "$Deliantra::OLDDIR/cfplusrc";
2978 print STDERR "INFO: used old configuration file\n";
2979 }
2980 3047
3048 DC::Audio::probe;
3049
2981 DC::DB::Server::run; 3050 DC::DB::Server::run;
2982 3051
2983 if ($CFG->{db_schema} < 1) { 3052 if ($CFG->{db_schema} < 1) {
2984 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";
2985 DC::DB::nuke_db; 3054 DC::DB::nuke_db;
2986 $CFG->{db_schema} = 1; 3055 $CFG->{db_schema} = 1;
2987 DC::write_cfg; 3056 DC::save_cfg;
2988 }
2989
2990 DC::DB::open_db;
2991
2992 DC::UI::set_layout ($::CFG->{layout});
2993
2994 my %DEF_CFG = (
2995 config_autosave => 1,
2996 sdl_mode => undef,
2997 fullscreen => 1,
2998 fast => 0,
2999 force_opengl11 => undef,
3000 disable_alpha => 0,
3001 smooth_movement => 1,
3002 smooth_transitions => 1,
3003 texture_compression => 1,
3004 map_scale => 1,
3005 fow_enable => 1,
3006 fow_intensity => 0,
3007 fow_texture => 0,
3008 map_smoothing => 1,
3009 gui_fontsize => 1,
3010 log_fontsize => 0.7,
3011 gauge_fontsize => 1,
3012 gauge_size => 0.35,
3013 stat_fontsize => 0.7,
3014 mapsize => 100,
3015 audio_enable => 1,
3016 audio_hw_channels => 0,
3017 audio_hw_frequency => 0,
3018 audio_hw_chunksize => 0,
3019 audio_mix_channels => 8,
3020 effects_enable => 1,
3021 effects_volume => 1,
3022 bgm_enable => 1,
3023 bgm_volume => 0.5,
3024 output_rate => "",
3025 pickup => PICKUP_SPELLBOOK | PICKUP_SKILLSCROLL | PICKUP_VALUABLES,
3026 inv_sort => "mtime",
3027 default => "profile", # default profile
3028 show_tips => 1,
3029 logview_max_par => 1000,
3030 shift_fire_stop => 0,
3031 uitheme => "wood",
3032 map_shift_x => -24, # arbitrary
3033 map_shift_y => +24, # arbitrary
3034 );
3035
3036 while (my ($k, $v) = each %DEF_CFG) {
3037 $CFG->{$k} = $v unless exists $CFG->{$k};
3038 }
3039
3040 my @args = @ARGV;
3041
3042 # OS X passes some process serial number of other shit. they
3043 # could have used an env var or any other sane mechanism. but
3044 # would it be os x then? no...
3045 shift @args if $args[0] =~ /^-psn_/;
3046
3047 my $profile = 'default';
3048
3049 for (my $i = 0; $i < @args; $i++) {
3050 if ($args[$i] =~ /^--?profile$/) {
3051 $profile = $args[$i + 1];
3052 splice @args, $i, 2, ();
3053 $i = 0;
3054 } elsif ($args[$i] =~ /^--?h/) {
3055 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3056 exit 0;
3057 } 3057 }
3058 }
3059 3058
3060 $CFG->{profile}{$profile} ||= {}; 3059 DC::DB::open_db;
3061 $PROFILE = $CFG->{profile}{$profile};
3062 $PROFILE->{host} ||= "gameserver.deliantra.net";
3063 3060
3064 $PROFILE->{host} = $args[0] if @args > 0; 3061 DC::UI::set_layout ($::CFG->{layout});
3065 $PROFILE->{user} = $args[1] if @args > 1;
3066 $PROFILE->{password} = $args[2] if @args > 2;
3067 3062
3068 # convert old bindings (only default profile matters) 3063 my @args = @ARGV;
3069 if (my $bindings = delete $PROFILE->{bindings}) { 3064
3070 while (my ($mod, $syms) = each %$bindings) { 3065 # OS X passes some process serial number of other shit. they
3071 while (my ($sym, $cmds) = each %$syms) { 3066 # could have used an env var or any other sane mechanism. but
3072 push @{ $PROFILE->{macro} }, { 3067 # would it be os x then? no...
3073 accelkey => [$mod*1, $sym*1], 3068 shift @args if $args[0] =~ /^-psn_/;
3074 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, ();
3075 }; 3076 $i = 0;
3077 } elsif ($args[$i] =~ /^--?h/) {
3078 print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n";
3079 exit 0;
3076 } 3080 }
3077 } 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 }
3078 } 3101 }
3079 3102
3080 # 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
3081 # 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
3082 $ENV{FONTCONFIG_FILE} = "fonts.conf"; 3105 $ENV{FONTCONFIG_FILE} = "fonts.conf";
3083 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; 3106 $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts";
3084 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions 3107 $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions
3085 3108
3086 { 3109 {
3087 my @fonts = map DC::find_rcfile "fonts/$_", qw( 3110 my @fonts = map DC::find_rcfile "fonts/$_", qw(
3088 DejaVuSans.ttf 3111 DejaVuSans.ttf
3089 DejaVuSansMono.ttf 3112 DejaVuSansMono.ttf
3090 DejaVuSans-Bold.ttf 3113 DejaVuSans-Bold.ttf
3091 DejaVuSansMono-Bold.ttf 3114 DejaVuSansMono-Bold.ttf
3092 DejaVuSans-Oblique.ttf 3115 DejaVuSans-Oblique.ttf
3093 DejaVuSansMono-Oblique.ttf 3116 DejaVuSansMono-Oblique.ttf
3094 DejaVuSans-BoldOblique.ttf 3117 DejaVuSans-BoldOblique.ttf
3095 DejaVuSansMono-BoldOblique.ttf 3118 DejaVuSansMono-BoldOblique.ttf
3096 mona.ttf 3119 mona.ttf
3097 ); 3120 );
3098 3121
3099 DC::add_font $_ for @fonts; 3122 DC::add_font $_ for @fonts;
3100 3123
3101 $FONT_PROP = new_from_file DC::Font $fonts[0]; 3124 $FONT_PROP = new_from_file DC::Font $fonts[0];
3102 $FONT_FIXED = new_from_file DC::Font $fonts[1]; 3125 $FONT_FIXED = new_from_file DC::Font $fonts[1];
3103 3126
3104 $FONT_PROP->make_default; 3127 $FONT_PROP->make_default;
3105 3128
3106 DC::pango_init; 3129 DC::pango_init;
3107 } 3130 }
3108 3131
3109# compare mono (ft) vs. rgba (cairo) 3132# compare mono (ft) vs. rgba (cairo)
3110# ft - 1.8s, cairo 3s, even in alpha-only mode 3133# ft - 1.8s, cairo 3s, even in alpha-only mode
3111# for my $rgba (0..1) { 3134# for my $rgba (0..1) {
3112# my $t1 = Time::HiRes::time; 3135# my $t1 = Time::HiRes::time;
3117# } 3140# }
3118# my $t2 = Time::HiRes::time; 3141# my $t2 = Time::HiRes::time;
3119# warn $t2-$t1; 3142# warn $t2-$t1;
3120# } 3143# }
3121 3144
3145 }
3146
3147 DC::SDL_Init 0;
3122 DC::IMG_Init; video_init; 3148 DC::IMG_Init; video_init;
3123 DC::Mix_Init; audio_init; 3149 DC::Mix_Init; audio_init;
3124 }
3125 3150
3126 show_tip_of_the_day if $CFG->{show_tips}; 3151 show_tip_of_the_day if $CFG->{show_tips};
3127 3152
3128 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { 3153 my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub {
3129 undef $STARTUP_CANCEL; 3154 undef $STARTUP_CANCEL;
3130 (pop @::STARTUP_DONE)->() 3155 (pop @::STARTUP_DONE)->()
3131 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;
3132 }; 3172 };
3133
3134 debug_toggle 0;
3135
3136 delete $SIG{__DIE__};
3137 EV::loop;
3138
3139 DC::write_cfg if $CFG->{config_autosave};
3140
3141 #video_shutdown;
3142 #audio_shutdown;
3143
3144 DC::OpenGL::quit;
3145 DC::SDL_Quit;
3146 DC::DB::Server::stop;
3147} 3173}
3148
3149*DC::Main::run = \&DC::SDL_braino; # see sub above
3150 3174
31511 31751

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines