… | |
… | |
25 | BEGIN { *time = \&EV::time } |
25 | BEGIN { *time = \&EV::time } |
26 | |
26 | |
27 | use List::Util qw(max min); |
27 | use List::Util qw(max min); |
28 | |
28 | |
29 | use Deliantra; |
29 | use Deliantra; |
|
|
30 | use Deliantra::Util; |
30 | use Deliantra::Protocol::Constants; |
31 | use Deliantra::Protocol::Constants; |
31 | |
32 | |
32 | use AnyEvent::Util (); |
33 | use AnyEvent::Util (); |
33 | use AnyEvent::Socket (); |
34 | use AnyEvent::Socket (); |
34 | use AnyEvent::DNS (); |
35 | use AnyEvent::DNS (); |
35 | |
36 | |
36 | use Compress::LZF; |
37 | use Compress::LZF; |
37 | use JSON::XS; |
38 | use JSON::XS; |
|
|
39 | use Urlader; |
38 | |
40 | |
39 | use DC; |
41 | use DC; |
40 | |
42 | |
41 | sub crash($;$) { |
43 | sub crash($;$) { |
42 | # nop at compiletime |
44 | # nop at compiletime |
… | |
… | |
44 | |
46 | |
45 | BEGIN { |
47 | BEGIN { |
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 | |
61 | use DC::OpenGL (); |
63 | use DC::OpenGL (); |
|
|
64 | use DC::Audio (); |
62 | use DC::Protocol; |
65 | use DC::Protocol; |
63 | use DC::DB; |
66 | use DC::DB; |
64 | use DC::UI; |
67 | use DC::UI; |
65 | use DC::UI::Canvas; |
68 | use DC::UI::Canvas; |
66 | use DC::UI::Inventory; |
69 | use DC::UI::Inventory; |
… | |
… | |
126 | our $MENUBAR; # the hbox at the top |
129 | our $MENUBAR; # the hbox at the top |
127 | our $MENUPOPUP; |
130 | our $MENUPOPUP; |
128 | our $BUTTONBAR; # the menu buttons |
131 | our $BUTTONBAR; # the menu buttons |
129 | our $METASERVER; |
132 | our $METASERVER; |
130 | our $LOGIN_BUTTON; |
133 | our $LOGIN_BUTTON; |
|
|
134 | our $LOGIN_ERROR; |
131 | our $QUIT_DIALOG; |
135 | our $QUIT_DIALOG; |
132 | our $HOST_ENTRY; |
136 | our $HOST_ENTRY; |
133 | our $FULLSCREEN_ENABLE; |
137 | our $FULLSCREEN_ENABLE; |
134 | our $PICKUP_ENABLE; |
138 | our $PICKUP_ENABLE; |
135 | our $SERVER_INFO; |
139 | our $SERVER_INFO; |
… | |
… | |
196 | AnyEvent::Util::fh_nonblocking $fh, 1; |
200 | AnyEvent::Util::fh_nonblocking $fh, 1; |
197 | |
201 | |
198 | $msg =~ s/\s+$//; |
202 | $msg =~ s/\s+$//; |
199 | |
203 | |
200 | # backtrace as second step, in case it crashes, too |
204 | # backtrace as second step, in case it crashes, too |
201 | crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated" |
205 | crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated" |
202 | if $backtrace; |
206 | if $backtrace; |
203 | }; |
207 | }; |
204 | |
208 | |
205 | sub clienterror($;$) { |
209 | sub clienterror($;$) { |
206 | my ($msg, $backtrace) = @_; |
210 | my ($msg, $backtrace) = @_; |
… | |
… | |
208 | warn $msg; |
212 | warn $msg; |
209 | |
213 | |
210 | return unless $CONN; |
214 | return unless $CONN; |
211 | |
215 | |
212 | $CONN->send_exti_msg (clientlog => $msg); |
216 | $CONN->send_exti_msg (clientlog => $msg); |
213 | $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") if $backtrace; |
217 | $CONN->send_exti_msg (clientlog => Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION$Urlader::EXE_VER, generated") if $backtrace; |
214 | } |
218 | } |
215 | |
219 | |
216 | ############################################################################# |
220 | ############################################################################# |
217 | |
221 | |
218 | sub status { |
222 | sub status { |
… | |
… | |
249 | : "[<span foreground='#888'>num</span>]"; |
253 | : "[<span foreground='#888'>num</span>]"; |
250 | |
254 | |
251 | # <tt> around next statement works around some bug that keeps the |
255 | # <tt> around next statement works around some bug that keeps the |
252 | # "font =>" from being used on windows |
256 | # "font =>" from being used on windows |
253 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
257 | $MODBOX->set_markup ("<tt>$markup</tt>"); |
|
|
258 | } |
|
|
259 | |
|
|
260 | sub errorbox { |
|
|
261 | my ($msg) = @_; |
|
|
262 | |
|
|
263 | status $msg; |
|
|
264 | |
|
|
265 | my $dialog = new DC::UI::Toplevel |
|
|
266 | x => "center", |
|
|
267 | y => "center", |
|
|
268 | z => 200, |
|
|
269 | title => "Error", |
|
|
270 | child => my $vbox = new DC::UI::VBox, |
|
|
271 | has_close_button => 1, |
|
|
272 | on_delete => sub { |
|
|
273 | $_[0]->destroy; |
|
|
274 | }, |
|
|
275 | ; |
|
|
276 | |
|
|
277 | add $vbox new DC::UI::Label |
|
|
278 | align => 0.5, |
|
|
279 | ellipsise => 0, |
|
|
280 | text => $msg; |
|
|
281 | |
|
|
282 | add $vbox new DC::UI::Button |
|
|
283 | expand => 1, |
|
|
284 | text => "OK", |
|
|
285 | on_activate => sub { |
|
|
286 | $dialog->destroy; |
|
|
287 | 0 |
|
|
288 | } |
|
|
289 | ; |
|
|
290 | |
|
|
291 | $dialog->show; |
254 | } |
292 | } |
255 | |
293 | |
256 | ############################################################################# |
294 | ############################################################################# |
257 | #TODO: maybe move into own audio module... |
295 | #TODO: maybe move into own audio module... |
258 | |
296 | |
… | |
… | |
473 | audio_music_push; |
511 | audio_music_push; |
474 | } |
512 | } |
475 | |
513 | |
476 | sub audio_init { |
514 | sub audio_init { |
477 | if ($CFG->{audio_enable}) { |
515 | if ($CFG->{audio_enable}) { |
478 | if (length $CFG->{audio_driver}) { |
516 | DC::Audio::init $CFG->{audio_driver}; |
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 | |
517 | |
494 | if ($SDL_MIXER) { |
518 | if ($SDL_MIXER) { |
495 | DC::Mix_AllocateChannels $CFG->{audio_mix_channels}; |
|
|
496 | |
|
|
497 | audio_music_finished; |
519 | audio_music_finished; |
498 | } else { |
520 | } else { |
499 | status "Unable to open sound device: there will be no sound"; |
521 | status "Unable to open sound device: there will be no sound"; |
500 | } |
522 | } |
501 | } else { |
523 | } else { |
… | |
… | |
597 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; |
619 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_RDONLY, 0; |
598 | |
620 | |
599 | if ($fh) { |
621 | if ($fh) { |
600 | $error ||= Coro::AIO::aio_stat "$override.tmp"; |
622 | $error ||= Coro::AIO::aio_stat "$override.tmp"; |
601 | $error ||= -s _ != $size; |
623 | $error ||= -s _ != $size; |
602 | $error ||= Coro::AIO::aio_readahead $fh, 0, $size; |
624 | Coro::AIO::aio_readahead $fh, 0, $size; |
603 | |
625 | |
604 | my $f_md5 = new Digest::MD5; |
626 | my $f_md5 = new Digest::MD5; |
|
|
627 | binmode $fh; # ugh :( |
605 | $f_md5->addfile ($fh); |
628 | $f_md5->addfile ($fh); |
606 | $f_md5 = $f_md5->hexdigest; |
629 | $f_md5 = $f_md5->hexdigest; |
607 | $error ||= $md5 ne $f_md5; |
630 | $error ||= $md5 ne $f_md5; |
608 | } |
631 | } |
609 | } |
632 | } |
… | |
… | |
702 | ::message { markup => "Server has no newer version." }; |
725 | ::message { markup => "Server has no newer version." }; |
703 | } |
726 | } |
704 | } else { |
727 | } else { |
705 | ::message { markup => "Server does not support software update." }; |
728 | ::message { markup => "Server does not support software update." }; |
706 | } |
729 | } |
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 | |
730 | |
715 | () |
731 | () |
716 | }); |
732 | }); |
717 | } |
733 | } |
718 | |
734 | |
… | |
… | |
948 | $vbox->add (@dialog); |
964 | $vbox->add (@dialog); |
949 | $dialog->show; |
965 | $dialog->show; |
950 | } |
966 | } |
951 | |
967 | |
952 | sub dc_connect { |
968 | sub dc_connect { |
953 | my ($host, $port) = @_; |
969 | my ($host, $port, $create) = @_; |
954 | |
970 | |
955 | my $mapw = List::Util::min 48, List::Util::max 11, int 1.5 + $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
971 | 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; |
972 | my $maph = List::Util::min 48, List::Util::max 11, int 1.5 + $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
957 | |
973 | |
958 | $CONN = |
974 | $CONN = |
959 | new DC::Protocol |
975 | new DC::Protocol |
960 | host => $host, |
976 | host => $host, |
961 | port => $port, |
977 | port => $port, |
|
|
978 | create_login => $create, |
962 | user => $PROFILE->{user}, |
979 | user => $PROFILE->{user}, |
963 | pass => $PROFILE->{password}, |
980 | pass => (pack "H*", $PROFILE->{password}), |
964 | mapw => $mapw, |
981 | mapw => $mapw, |
965 | maph => $maph, |
982 | maph => $maph, |
966 | |
983 | |
967 | c_version => { |
984 | c_version => { |
968 | client => "deliantra", |
985 | client => "deliantra", |
969 | clientver => $DC::VERSION, |
986 | clientver => "$DC::VERSION$Urlader::EXE_VER", |
970 | gl_vendor => DC::OpenGL::gl_vendor, |
987 | gl_vendor => DC::OpenGL::gl_vendor, |
971 | gl_version => DC::OpenGL::gl_version, |
988 | gl_version => DC::OpenGL::gl_version, |
972 | }, |
989 | }, |
973 | |
990 | |
974 | map_widget => $MAPWIDGET, |
991 | map_widget => $MAPWIDGET, |
… | |
… | |
988 | ota_update_check; |
1005 | ota_update_check; |
989 | |
1006 | |
990 | status "successfully connected to the server"; |
1007 | status "successfully connected to the server"; |
991 | } else { |
1008 | } else { |
992 | undef $CONN; |
1009 | undef $CONN; |
993 | status "unable to connect: $!"; |
1010 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1011 | $LOGIN_ERROR->set_text ("Unable to connect to server: $!"); |
994 | stop_game(); |
1012 | stop_game(); |
995 | } |
1013 | } |
996 | }, |
1014 | }, |
|
|
1015 | |
|
|
1016 | on_addme => sub { |
|
|
1017 | my ($ok, $msg) = @_; |
|
|
1018 | |
|
|
1019 | $LOGIN_ERROR->{fg} = $ok ? [0, 1, 0] : [1, 0, 0]; |
|
|
1020 | $LOGIN_ERROR->set_text ($msg); |
|
|
1021 | }, |
997 | ; |
1022 | ; |
998 | } |
1023 | } |
999 | |
1024 | |
1000 | sub start_game { |
1025 | sub start_game($) { |
|
|
1026 | my ($create) = @_; |
|
|
1027 | |
1001 | status "logging in..."; |
1028 | status "logging in..."; |
1002 | |
1029 | |
1003 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
1030 | my $server = $PROFILE->{host} || $DEFAULT_SERVER; |
1004 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
1031 | my ($host, $port) = AnyEvent::Socket::parse_hostport $server, "deliantra=13327" |
1005 | or return status "$server: unable to parse server address, try an empty field."; |
1032 | or return status "$server: unable to parse server address, try an empty field."; |
… | |
… | |
1020 | status "dns failure, using hardcoded address"; |
1047 | status "dns failure, using hardcoded address"; |
1021 | $host = "194.126.175.154"; |
1048 | $host = "194.126.175.154"; |
1022 | } |
1049 | } |
1023 | } |
1050 | } |
1024 | |
1051 | |
1025 | dc_connect $host, $port; |
1052 | dc_connect $host, $port, $create; |
1026 | }; |
1053 | }; |
1027 | } else { |
1054 | } else { |
1028 | dc_connect $host, $port; |
1055 | dc_connect $host, $port, $create; |
1029 | } |
1056 | } |
1030 | } |
1057 | } |
1031 | |
1058 | |
1032 | sub stop_game { |
1059 | sub stop_game { |
1033 | crash "stop_game"; |
1060 | crash "stop_game"; |
… | |
… | |
1866 | $vbox->add (new DC::UI::FancyFrame |
1893 | $vbox->add (new DC::UI::FancyFrame |
1867 | label => "Login Settings", |
1894 | label => "Login Settings", |
1868 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1895 | child => (my $table = new DC::UI::Table expand => 1, col_expand => [0, 1]), |
1869 | ); |
1896 | ); |
1870 | |
1897 | |
|
|
1898 | my $nullpw = "\x00" x 16; |
|
|
1899 | |
1871 | $table->add_at (0, 4, new DC::UI::Label align => 1, text => "Username"); |
1900 | $table->add_at (0, 0, new DC::UI::Label align => 1, text => "Username"); |
1872 | $table->add_at (1, 4, new DC::UI::Entry |
1901 | $table->add_at (1, 0, new DC::UI::Entry |
1873 | text => $PROFILE->{user}, |
1902 | text => $PROFILE->{user}, |
1874 | tooltip => "The name of your character on the server. The name is case-sensitive!", |
1903 | 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 } |
1904 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{user} = $value; 1 } |
1876 | ); |
1905 | ); |
1877 | |
1906 | |
1878 | $table->add_at (0, 5, new DC::UI::Label align => 1, text => "Password"); |
1907 | $table->add_at (0, 1, new DC::UI::Label align => 1, text => "Password"); |
1879 | $table->add_at (1, 5, new DC::UI::Entry |
1908 | $table->add_at (1, 1, my $pw1 = new DC::UI::Entry |
1880 | text => $PROFILE->{password}, |
1909 | text => $PROFILE->{password} ? $nullpw : "", |
1881 | hidden => 1, |
1910 | hidden => 1, |
1882 | tooltip => "The password for your character.", |
1911 | tooltip => "The password for your character.", |
1883 | on_changed => sub { my ($self, $value) = @_; $PROFILE->{password} = $value; 1 } |
1912 | on_focus_in => sub { |
|
|
1913 | my ($self) = @_; |
|
|
1914 | $self->set_text ("") |
|
|
1915 | if $self->{text} eq $nullpw; |
|
|
1916 | 0 |
|
|
1917 | }, |
|
|
1918 | on_changed => sub { |
|
|
1919 | my ($self, $value) = @_; |
|
|
1920 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $value |
|
|
1921 | if length $value && $value ne $nullpw; |
|
|
1922 | 1 |
|
|
1923 | }, |
1884 | ); |
1924 | ); |
1885 | |
1925 | |
1886 | $table->add_at (1, 11, $LOGIN_BUTTON = new DC::UI::Button |
1926 | $table->add_at (1, 2, $LOGIN_BUTTON = new DC::UI::Button |
1887 | expand => 1, |
1927 | expand => 1, |
1888 | text => "Login / Register", |
1928 | text => "Login to Existing Account", |
1889 | tooltip => "This button will either login to the account configured above or register a new account.", |
1929 | tooltip => "This button will login to the account given by the <b>Username</b> and <b>Password</b> fields above.", |
1890 | on_activate => sub { |
1930 | on_activate => sub { |
1891 | $CONN ? stop_game |
1931 | $CONN ? stop_game |
1892 | : start_game; |
1932 | : start_game 0; |
1893 | 1 |
1933 | 1 |
1894 | }, |
1934 | }, |
1895 | ); |
1935 | ); |
1896 | |
1936 | |
|
|
1937 | $table->add_at (0, 3, new DC::UI::Label align => 1, text => "Password"); |
|
|
1938 | $table->add_at (1, 3, my $pw2 = new DC::UI::Entry |
|
|
1939 | hidden => 1, |
|
|
1940 | tooltip => "The new password for your character", |
|
|
1941 | ); |
|
|
1942 | |
|
|
1943 | $table->add_at (1, 4, new DC::UI::Button |
|
|
1944 | expand => 1, |
|
|
1945 | text => "Create New Account", |
|
|
1946 | 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.", |
|
|
1947 | on_activate => sub { |
|
|
1948 | if ($pw1->{text} ne $pw2->{text}) { |
|
|
1949 | $LOGIN_ERROR->{fg} = [1, 0, 0]; |
|
|
1950 | $LOGIN_ERROR->set_text ("The passwords do not match - try to enter them again."); |
|
|
1951 | } else { |
|
|
1952 | $CONN or start_game 1; |
|
|
1953 | } |
|
|
1954 | 1 |
|
|
1955 | }, |
|
|
1956 | ); |
|
|
1957 | |
|
|
1958 | $vbox->add (new DC::UI::FancyFrame |
|
|
1959 | label => "Server Message", |
|
|
1960 | tooltip => "The last message, or error, form the server.", |
|
|
1961 | child => ($LOGIN_ERROR = new DC::UI::Label valign => 0, ellipsise => 0), |
|
|
1962 | ); |
|
|
1963 | |
1897 | $vbox->add (new DC::UI::FancyFrame |
1964 | $vbox->add (new DC::UI::FancyFrame |
1898 | label => "How to Play", |
1965 | label => "How to Play", |
1899 | min_h => 240, |
1966 | min_h => 240,#d# should not be necessary - widget bug |
1900 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1967 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1901 | markup => |
1968 | markup => |
1902 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
1969 | "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). " |
1970 | . "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 " |
1971 | . "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.", |
1972 | . "fill out the top two <b>Password</b> fields using the same password, then press <b>Create New Account</b>.", |
1906 | ), |
1973 | ), |
1907 | ); |
1974 | ); |
1908 | |
1975 | |
1909 | $vbox |
1976 | $vbox |
1910 | } |
1977 | } |
… | |
… | |
2028 | $table->add_at (2, $row++, new DC::UI::Button |
2095 | $table->add_at (2, $row++, new DC::UI::Button |
2029 | text => "Save Now", |
2096 | text => "Save Now", |
2030 | tooltip => "Use this to manually save configuration and UI layout when " |
2097 | tooltip => "Use this to manually save configuration and UI layout when " |
2031 | . "autosave is disabled.", |
2098 | . "autosave is disabled.", |
2032 | on_activate => sub { |
2099 | on_activate => sub { |
2033 | DC::write_cfg; |
2100 | DC::save_cfg; |
2034 | 0 |
2101 | 0 |
2035 | } |
2102 | } |
2036 | ); |
2103 | ); |
2037 | } |
2104 | } |
2038 | |
2105 | |
… | |
… | |
2674 | DC::set_theme $CFG->{uitheme}; |
2741 | DC::set_theme $CFG->{uitheme}; |
2675 | |
2742 | |
2676 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2743 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2677 | $SDL_REINIT = 0; |
2744 | $SDL_REINIT = 0; |
2678 | |
2745 | |
2679 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2746 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 2; |
2680 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2747 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2681 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2748 | @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)"; |
2749 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2683 | |
2750 | |
2684 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
2751 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
… | |
… | |
2697 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2764 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2698 | |
2765 | |
2699 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2766 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2700 | $FULLSCREEN = $CFG->{fullscreen}; |
2767 | $FULLSCREEN = $CFG->{fullscreen}; |
2701 | $FAST = $CFG->{fast}; |
2768 | $FAST = $CFG->{fast}; |
|
|
2769 | |
|
|
2770 | DC::SDL_WM_SetCaption "Deliantra MORPG Client $DC::VERSION$Urlader::EXE_VER", "Deliantra"; # must be after SDL_Init |
2702 | |
2771 | |
2703 | # due to mac os x braindamage, we simply retry with !fullscreen in case of an error |
2772 | # 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 |
2773 | DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN |
2705 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2774 | or DC::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, !$FULLSCREEN |
2706 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
2775 | or die "SDL_SetVideoMode failed: " . (DC::SDL_GetError) . "\n"; |
… | |
… | |
2964 | EV::unloop; |
3033 | EV::unloop; |
2965 | #d# TODO calling exit here hangs the process in some futex |
3034 | #d# TODO calling exit here hangs the process in some futex |
2966 | }; |
3035 | }; |
2967 | |
3036 | |
2968 | # due to mac os x + sdl combined braindamage, we need this contortion |
3037 | # due to mac os x + sdl combined braindamage, we need this contortion |
2969 | sub DC::Main::main { |
3038 | sub DC::Main::run { |
2970 | { |
3039 | DC::SDL_main_hack { |
|
|
3040 | { |
2971 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
3041 | DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; |
2972 | |
3042 | |
2973 | if (-e "$Deliantra::VARDIR/client.cf") { |
3043 | DC::load_cfg; |
2974 | DC::read_cfg "$Deliantra::VARDIR/client.cf"; |
3044 | 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 | |
3045 | |
|
|
3046 | DC::Audio::probe; |
|
|
3047 | |
2981 | DC::DB::Server::run; |
3048 | DC::DB::Server::run; |
2982 | |
3049 | |
2983 | if ($CFG->{db_schema} < 1) { |
3050 | if ($CFG->{db_schema} < 1) { |
2984 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
3051 | warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; |
2985 | DC::DB::nuke_db; |
3052 | DC::DB::nuke_db; |
2986 | $CFG->{db_schema} = 1; |
3053 | $CFG->{db_schema} = 1; |
2987 | DC::write_cfg; |
3054 | 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 | } |
3055 | } |
3058 | } |
|
|
3059 | |
3056 | |
3060 | $CFG->{profile}{$profile} ||= {}; |
3057 | DC::DB::open_db; |
3061 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
3062 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
3063 | |
3058 | |
3064 | $PROFILE->{host} = $args[0] if @args > 0; |
3059 | DC::UI::set_layout ($::CFG->{layout}); |
3065 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
3066 | $PROFILE->{password} = $args[2] if @args > 2; |
|
|
3067 | |
3060 | |
3068 | # convert old bindings (only default profile matters) |
3061 | my @args = @ARGV; |
3069 | if (my $bindings = delete $PROFILE->{bindings}) { |
3062 | |
3070 | while (my ($mod, $syms) = each %$bindings) { |
3063 | # OS X passes some process serial number of other shit. they |
3071 | while (my ($sym, $cmds) = each %$syms) { |
3064 | # could have used an env var or any other sane mechanism. but |
3072 | push @{ $PROFILE->{macro} }, { |
3065 | # would it be os x then? no... |
3073 | accelkey => [$mod*1, $sym*1], |
3066 | shift @args if $args[0] =~ /^-psn_/; |
3074 | action => $cmds, |
3067 | |
|
|
3068 | my $profile = 'default'; |
|
|
3069 | |
|
|
3070 | for (my $i = 0; $i < @args; $i++) { |
|
|
3071 | if ($args[$i] =~ /^--?profile$/) { |
|
|
3072 | $profile = $args[$i + 1]; |
|
|
3073 | splice @args, $i, 2, (); |
3075 | }; |
3074 | $i = 0; |
|
|
3075 | } elsif ($args[$i] =~ /^--?h/) { |
|
|
3076 | print STDERR "Usage: $0 [--profile name] [host [user [password]]]\n"; |
|
|
3077 | exit 0; |
3076 | } |
3078 | } |
3077 | } |
3079 | } |
|
|
3080 | |
|
|
3081 | $CFG->{profile}{$profile} ||= {}; |
|
|
3082 | $PROFILE = $CFG->{profile}{$profile}; |
|
|
3083 | $PROFILE->{host} ||= "gameserver.deliantra.net"; |
|
|
3084 | |
|
|
3085 | $PROFILE->{host} = $args[0] if @args > 0; |
|
|
3086 | $PROFILE->{user} = $args[1] if @args > 1; |
|
|
3087 | $PROFILE->{password} = unpack "H*", Deliantra::Util::hash_pw $args[2] if @args > 2; |
|
|
3088 | |
|
|
3089 | # convert old bindings (only default profile matters) |
|
|
3090 | if (my $bindings = delete $PROFILE->{bindings}) { |
|
|
3091 | while (my ($mod, $syms) = each %$bindings) { |
|
|
3092 | while (my ($sym, $cmds) = each %$syms) { |
|
|
3093 | push @{ $PROFILE->{macro} }, { |
|
|
3094 | accelkey => [$mod*1, $sym*1], |
|
|
3095 | action => $cmds, |
|
|
3096 | }; |
|
|
3097 | } |
|
|
3098 | } |
3078 | } |
3099 | } |
3079 | |
3100 | |
3080 | # fontconfig doesn't support relative paths anymore, so use abs_path and keep fingers crossed |
3101 | # 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 |
3102 | # these are ignored under windows, for some reason, and thus set in the loader |
3082 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
3103 | $ENV{FONTCONFIG_FILE} = "fonts.conf"; |
3083 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
3104 | $ENV{FONTCONFIG_PATH} = Cwd::abs_path DC::find_rcfile "fonts"; |
3084 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions |
3105 | $ENV{FONTCONFIG_DIR} = $ENV{FONTCONFIG_PATH}; # helps with older versions |
3085 | |
3106 | |
3086 | { |
3107 | { |
3087 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
3108 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
3088 | DejaVuSans.ttf |
3109 | DejaVuSans.ttf |
3089 | DejaVuSansMono.ttf |
3110 | DejaVuSansMono.ttf |
3090 | DejaVuSans-Bold.ttf |
3111 | DejaVuSans-Bold.ttf |
3091 | DejaVuSansMono-Bold.ttf |
3112 | DejaVuSansMono-Bold.ttf |
3092 | DejaVuSans-Oblique.ttf |
3113 | DejaVuSans-Oblique.ttf |
3093 | DejaVuSansMono-Oblique.ttf |
3114 | DejaVuSansMono-Oblique.ttf |
3094 | DejaVuSans-BoldOblique.ttf |
3115 | DejaVuSans-BoldOblique.ttf |
3095 | DejaVuSansMono-BoldOblique.ttf |
3116 | DejaVuSansMono-BoldOblique.ttf |
3096 | mona.ttf |
3117 | mona.ttf |
3097 | ); |
3118 | ); |
3098 | |
3119 | |
3099 | DC::add_font $_ for @fonts; |
3120 | DC::add_font $_ for @fonts; |
3100 | |
3121 | |
3101 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
3122 | $FONT_PROP = new_from_file DC::Font $fonts[0]; |
3102 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
3123 | $FONT_FIXED = new_from_file DC::Font $fonts[1]; |
3103 | |
3124 | |
3104 | $FONT_PROP->make_default; |
3125 | $FONT_PROP->make_default; |
3105 | |
3126 | |
3106 | DC::pango_init; |
3127 | DC::pango_init; |
3107 | } |
3128 | } |
3108 | |
3129 | |
3109 | # compare mono (ft) vs. rgba (cairo) |
3130 | # compare mono (ft) vs. rgba (cairo) |
3110 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
3131 | # ft - 1.8s, cairo 3s, even in alpha-only mode |
3111 | # for my $rgba (0..1) { |
3132 | # for my $rgba (0..1) { |
3112 | # my $t1 = Time::HiRes::time; |
3133 | # my $t1 = Time::HiRes::time; |
… | |
… | |
3117 | # } |
3138 | # } |
3118 | # my $t2 = Time::HiRes::time; |
3139 | # my $t2 = Time::HiRes::time; |
3119 | # warn $t2-$t1; |
3140 | # warn $t2-$t1; |
3120 | # } |
3141 | # } |
3121 | |
3142 | |
|
|
3143 | } |
|
|
3144 | |
|
|
3145 | DC::SDL_Init 0; |
3122 | DC::IMG_Init; video_init; |
3146 | DC::IMG_Init; video_init; |
3123 | DC::Mix_Init; audio_init; |
3147 | DC::Mix_Init; audio_init; |
3124 | } |
|
|
3125 | |
3148 | |
3126 | show_tip_of_the_day if $CFG->{show_tips}; |
3149 | show_tip_of_the_day if $CFG->{show_tips}; |
3127 | |
3150 | |
3128 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
3151 | my $STARTUP_CANCEL; $STARTUP_CANCEL = EV::idle sub { |
3129 | undef $STARTUP_CANCEL; |
3152 | undef $STARTUP_CANCEL; |
3130 | (pop @::STARTUP_DONE)->() |
3153 | (pop @::STARTUP_DONE)->() |
3131 | while @::STARTUP_DONE; |
3154 | while @::STARTUP_DONE; |
|
|
3155 | }; |
|
|
3156 | |
|
|
3157 | debug_toggle 0; |
|
|
3158 | |
|
|
3159 | delete $SIG{__DIE__}; |
|
|
3160 | EV::loop; |
|
|
3161 | |
|
|
3162 | DC::save_cfg if $CFG->{config_autosave}; |
|
|
3163 | |
|
|
3164 | #video_shutdown; |
|
|
3165 | #audio_shutdown; |
|
|
3166 | |
|
|
3167 | DC::OpenGL::quit; |
|
|
3168 | DC::SDL_Quit; |
|
|
3169 | DC::DB::Server::stop; |
3132 | }; |
3170 | }; |
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 | } |
3171 | } |
3148 | |
|
|
3149 | *DC::Main::run = \&DC::SDL_braino; # see sub above |
|
|
3150 | |
3172 | |
3151 | 1 |
3173 | 1 |