… | |
… | |
97 | use List::Util qw(max min); |
97 | use List::Util qw(max min); |
98 | |
98 | |
99 | use Deliantra; |
99 | use Deliantra; |
100 | use Deliantra::Protocol::Constants; |
100 | use Deliantra::Protocol::Constants; |
101 | |
101 | |
|
|
102 | use AnyEvent::DNS; |
|
|
103 | use AnyEvent::Socket (); |
|
|
104 | |
102 | use Compress::LZF; |
105 | use Compress::LZF; |
103 | |
106 | |
104 | use DC; |
107 | use DC; |
105 | BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } |
108 | BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } } |
106 | use DC::OpenGL (); |
109 | use DC::OpenGL (); |
107 | use DC::Protocol; |
110 | use DC::Protocol; |
108 | use DC::DB; |
111 | use DC::DB; |
109 | use DC::UI; |
112 | use DC::UI; |
110 | use DC::UI::Canvas; |
113 | use DC::UI::Canvas; |
… | |
… | |
139 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
142 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
140 | |
143 | |
141 | our $WANT_REFRESH; |
144 | our $WANT_REFRESH; |
142 | |
145 | |
143 | our @SDL_MODES; |
146 | our @SDL_MODES; |
|
|
147 | our $SDL_REINIT = 1; |
144 | our $WIDTH; |
148 | our $WIDTH; |
145 | our $HEIGHT; |
149 | our $HEIGHT; |
146 | our $FULLSCREEN; |
150 | our $FULLSCREEN; |
147 | our $FONTSIZE; |
151 | our $FONTSIZE; |
148 | |
152 | |
… | |
… | |
726 | |
730 | |
727 | $vbox->add (@dialog); |
731 | $vbox->add (@dialog); |
728 | $dialog->show; |
732 | $dialog->show; |
729 | } |
733 | } |
730 | |
734 | |
731 | sub start_game { |
735 | sub dc_connect { |
732 | status "logging in..."; |
736 | my ($host, $port) = @_; |
733 | |
|
|
734 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
735 | $SETUP_DIALOG->hide; |
|
|
736 | |
737 | |
737 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
738 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
738 | |
739 | |
739 | my ($host, $port) = split /:/, $PROFILE->{host}; |
|
|
740 | |
|
|
741 | $MAP = new DC::Map; |
|
|
742 | |
|
|
743 | $CONN = |
740 | $CONN = |
744 | new DC::Protocol |
741 | new DC::Protocol |
745 | host => $host, |
742 | host => $host, |
746 | port => $port || 13327, |
743 | port => $port, |
747 | user => $PROFILE->{user}, |
744 | user => $PROFILE->{user}, |
748 | pass => $PROFILE->{password}, |
745 | pass => $PROFILE->{password}, |
749 | mapw => $mapsize, |
746 | mapw => $mapsize, |
750 | maph => $mapsize, |
747 | maph => $mapsize, |
751 | |
748 | |
… | |
… | |
773 | } |
770 | } |
774 | }, |
771 | }, |
775 | ; |
772 | ; |
776 | } |
773 | } |
777 | |
774 | |
|
|
775 | sub start_game { |
|
|
776 | status "logging in..."; |
|
|
777 | |
|
|
778 | $LOGIN_BUTTON->set_text ("Logout"); |
|
|
779 | $SETUP_DIALOG->hide; |
|
|
780 | |
|
|
781 | my ($host, $port) = AnyEvent::Socket::parse_hostport $PROFILE->{host}, "deliantra=13327"; |
|
|
782 | |
|
|
783 | $MAP = new DC::Map; |
|
|
784 | |
|
|
785 | # hack to make SURE we find the IP address all right |
|
|
786 | # can be removed once AnyEvent::DNS is proven stable. |
|
|
787 | if ($host eq "gameserver.deliantra.net") { |
|
|
788 | AnyEvent::DNS::a "dnstest.deliantra.net", sub { |
|
|
789 | if ($_[0] ne "80.101.114.108") { # Perl |
|
|
790 | status "dns failure, using hardcoded address"; |
|
|
791 | $host = "129.13.162.95"; |
|
|
792 | } |
|
|
793 | |
|
|
794 | dc_connect $host, $port; |
|
|
795 | }; |
|
|
796 | } else { |
|
|
797 | dc_connect $host, $port; |
|
|
798 | } |
|
|
799 | } |
|
|
800 | |
778 | sub stop_game { |
801 | sub stop_game { |
779 | $LOGIN_BUTTON->set_text ("Login / Register"); |
802 | $LOGIN_BUTTON->set_text ("Login / Register"); |
780 | $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN); |
803 | $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN); |
781 | $SETUP_DIALOG->show; |
804 | $SETUP_DIALOG->show; |
782 | $PL_WINDOW->hide; |
805 | $PL_WINDOW->hide; |
… | |
… | |
842 | state => $CFG->{force_opengl11}, |
865 | state => $CFG->{force_opengl11}, |
843 | tooltip => "Limit Deliantra to use OpenGL 1.1 features only. This will normally result in " |
866 | tooltip => "Limit Deliantra to use OpenGL 1.1 features only. This will normally result in " |
844 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
867 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
845 | . "cards that claim to support a feature but fall back to software rendering. " |
868 | . "cards that claim to support a feature but fall back to software rendering. " |
846 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
869 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
847 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
870 | . "but cards and drivers from other vendors (ATI) are often just as bad. " |
848 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
871 | . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>", |
849 | on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } |
872 | on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } |
|
|
873 | ); |
|
|
874 | |
|
|
875 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Forbid Alpha"); |
|
|
876 | $table->add_at (1, $row++, new DC::UI::CheckBox |
|
|
877 | state => $CFG->{disable_alpha}, |
|
|
878 | tooltip => "Forbid off the use of the alpha channel. This makes Deliantra look a lot worse " |
|
|
879 | . "by disabling a number of textures and transparency effects. Normally, these " |
|
|
880 | . "effects do not cost a lot of resources, but some graphics cards might fall " |
|
|
881 | . "back to etxremely slow rendering if this is enabled. If disabling this option " |
|
|
882 | . "noticably improves the framerate of the client please report this! " |
|
|
883 | . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>", |
|
|
884 | on_changed => sub { |
|
|
885 | my ($self, $value) = @_; |
|
|
886 | $CFG->{disable_alpha} = $value; |
|
|
887 | $SDL_REINIT = 1; # SDL_SetVideoMode ignores GL attr changes |
|
|
888 | 0 |
|
|
889 | } |
850 | ); |
890 | ); |
851 | |
891 | |
852 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); |
892 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); |
853 | $table->add_at (1, $row++, new DC::UI::CheckBox |
893 | $table->add_at (1, $row++, new DC::UI::CheckBox |
854 | state => $CFG->{texture_compression}, |
894 | state => $CFG->{texture_compression}, |
… | |
… | |
2125 | $dialog->show; |
2165 | $dialog->show; |
2126 | }; |
2166 | }; |
2127 | } |
2167 | } |
2128 | |
2168 | |
2129 | sub sdl_init { |
2169 | sub sdl_init { |
2130 | DC::SDL_Init |
2170 | DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE |
2131 | and die "SDL::Init failed!\n"; |
2171 | and die "SDL::Init failed!\n"; |
2132 | } |
2172 | } |
2133 | |
2173 | |
2134 | sub video_init { |
2174 | sub video_init { |
|
|
2175 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
|
|
2176 | $SDL_REINIT = 0; |
|
|
2177 | |
|
|
2178 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
|
|
2179 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
|
|
2180 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
|
|
2181 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
2182 | |
|
|
2183 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
|
|
2184 | |
2135 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; |
2185 | if (!exists $CFG->{sdl_mode} or $CFG->{sdl_mode} >= @SDL_MODES) { |
|
|
2186 | $CFG->{sdl_mode} = 0; |
|
|
2187 | for (reverse 0 .. $#SDL_MODES) { |
|
|
2188 | $CFG->{sdl_mode} = $_ if $SDL_MODES[$_][0] * $SDL_MODES[$_][1] >= 800 * 600; |
|
|
2189 | } |
|
|
2190 | } |
2136 | |
2191 | |
2137 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2192 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2138 | |
2193 | |
2139 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2194 | ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
2140 | $FULLSCREEN = $CFG->{fullscreen}; |
2195 | $FULLSCREEN = $CFG->{fullscreen}; |
… | |
… | |
2329 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2384 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2330 | } |
2385 | } |
2331 | |
2386 | |
2332 | sub video_shutdown { |
2387 | sub video_shutdown { |
2333 | DC::OpenGL::shutdown; |
2388 | DC::OpenGL::shutdown; |
|
|
2389 | DC::SDL_QuitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2334 | |
2390 | |
2335 | undef $SDL_ACTIVE; |
2391 | undef $SDL_ACTIVE; |
2336 | } |
2392 | } |
2337 | |
2393 | |
2338 | my %animate_object; |
2394 | my %animate_object; |
… | |
… | |
2399 | # printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS; |
2455 | # printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS; |
2400 | }, |
2456 | }, |
2401 | DC::SDL_KEYDOWN => sub { |
2457 | DC::SDL_KEYDOWN => sub { |
2402 | if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) { |
2458 | if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) { |
2403 | # alt-enter |
2459 | # alt-enter |
|
|
2460 | video_shutdown; |
2404 | $FULLSCREEN_ENABLE->toggle; |
2461 | $FULLSCREEN_ENABLE->toggle; |
2405 | video_shutdown; |
|
|
2406 | video_init; |
2462 | video_init; |
2407 | } else { |
2463 | } else { |
2408 | &DC::UI::feed_sdl_key_down_event; |
2464 | &DC::UI::feed_sdl_key_down_event; |
2409 | } |
2465 | } |
2410 | update_modbox; |
2466 | update_modbox; |
… | |
… | |
2459 | my %DEF_CFG = ( |
2515 | my %DEF_CFG = ( |
2460 | sdl_mode => 0, |
2516 | sdl_mode => 0, |
2461 | fullscreen => 1, |
2517 | fullscreen => 1, |
2462 | fast => 0, |
2518 | fast => 0, |
2463 | force_opengl11 => undef, |
2519 | force_opengl11 => undef, |
|
|
2520 | disable_alpha => 0, |
2464 | texture_compression => 1, |
2521 | texture_compression => 1, |
2465 | map_scale => 1, |
2522 | map_scale => 1, |
2466 | fow_enable => 1, |
2523 | fow_enable => 1, |
2467 | fow_intensity => 0, |
2524 | fow_intensity => 0, |
2468 | map_smoothing => 1, |
2525 | map_smoothing => 1, |
… | |
… | |
2509 | } |
2566 | } |
2510 | } |
2567 | } |
2511 | |
2568 | |
2512 | sdl_init; |
2569 | sdl_init; |
2513 | |
2570 | |
2514 | @SDL_MODES = DC::SDL_ListModes 8, 8; |
|
|
2515 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
|
|
2516 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
2517 | |
|
|
2518 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
|
|
2519 | |
|
|
2520 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
|
|
2521 | |
|
|
2522 | { |
2571 | { |
2523 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
2572 | my @fonts = map DC::find_rcfile "fonts/$_", qw( |
2524 | DejaVuSans.ttf |
2573 | DejaVuSans.ttf |
2525 | DejaVuSansMono.ttf |
2574 | DejaVuSansMono.ttf |
2526 | DejaVuSans-Bold.ttf |
2575 | DejaVuSans-Bold.ttf |