ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/deliantra
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/deliantra (file contents):
Revision 1.43 by root, Wed May 21 23:35:55 2008 UTC vs.
Revision 1.53 by root, Fri Jul 18 22:32:55 2008 UTC

97use List::Util qw(max min); 97use List::Util qw(max min);
98 98
99use Deliantra; 99use Deliantra;
100use Deliantra::Protocol::Constants; 100use Deliantra::Protocol::Constants;
101 101
102use AnyEvent::DNS;
103use AnyEvent::Socket ();
104
102use Compress::LZF; 105use Compress::LZF;
103 106
107use DC;
104use DC; BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$@" unless $^S } } 108BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } }
105use DC::OpenGL (); 109use DC::OpenGL ();
106use DC::Protocol; 110use DC::Protocol;
107use DC::DB; 111use DC::DB;
108use DC::UI; 112use DC::UI;
109use DC::UI::Canvas; 113use DC::UI::Canvas;
137our $PROFILE; # current profile 141our $PROFILE; # current profile
138our $FAST; # fast, low-quality mode, possibly useful for software-rendering 142our $FAST; # fast, low-quality mode, possibly useful for software-rendering
139 143
140our $WANT_REFRESH; 144our $WANT_REFRESH;
141 145
146our $MODE_SLIDER;
147our $CAVEAT_LABEL;
148
142our @SDL_MODES; 149our @SDL_MODES;
150our $SDL_REINIT = 1;
143our $WIDTH; 151our $WIDTH;
144our $HEIGHT; 152our $HEIGHT;
145our $FULLSCREEN; 153our $FULLSCREEN;
146our $FONTSIZE; 154our $FONTSIZE;
147 155
725 733
726 $vbox->add (@dialog); 734 $vbox->add (@dialog);
727 $dialog->show; 735 $dialog->show;
728} 736}
729 737
730sub start_game { 738sub dc_connect {
731 status "logging in..."; 739 my ($host, $port) = @_;
732
733 $LOGIN_BUTTON->set_text ("Logout");
734 $SETUP_DIALOG->hide;
735 740
736 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 741 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
737 742
738 my ($host, $port) = split /:/, $PROFILE->{host};
739
740 $MAP = new DC::Map;
741
742 $CONN = eval { 743 $CONN =
743 local $SIG{__DIE__};
744
745 new DC::Protocol 744 new DC::Protocol
746 host => $host, 745 host => $host,
747 port => $port || 13327, 746 port => $port,
748 user => $PROFILE->{user}, 747 user => $PROFILE->{user},
749 pass => $PROFILE->{password}, 748 pass => $PROFILE->{password},
750 mapw => $mapsize, 749 mapw => $mapsize,
751 maph => $mapsize, 750 maph => $mapsize,
752 751
759 query => \&server_query, 758 query => \&server_query,
760 759
761 setup_req => { 760 setup_req => {
762 smoothing => $CFG->{map_smoothing}*1, 761 smoothing => $CFG->{map_smoothing}*1,
763 }, 762 },
764 };
765 763
766 if ($CONN) { 764 on_connect => sub {
765 if ($_[0]) {
767 DC::lowdelay fileno $CONN->{fh}; 766 DC::lowdelay fileno $CONN->{fh};
768 767
769 status "login successful"; 768 status "login successful";
769 } else {
770 undef $CONN;
771 status "unable to connect: $!";
772 stop_game();
773 }
774 },
775 ;
776}
777
778sub start_game {
779 status "logging in...";
780
781 $LOGIN_BUTTON->set_text ("Logout");
782 $SETUP_DIALOG->hide;
783
784 my ($host, $port) = AnyEvent::Socket::parse_hostport $PROFILE->{host}, "deliantra=13327";
785
786 $MAP = new DC::Map;
787
788 # hack to make SURE we find the IP address all right
789 # can be removed once AnyEvent::DNS is proven stable.
790 if ($host eq "gameserver.deliantra.net") {
791 AnyEvent::DNS::a "dnstest.deliantra.net", sub {
792 if ($_[0] ne "80.101.114.108") { # Perl
793 status "dns failure, using hardcoded address";
794 $host = "129.13.162.95";
795 }
796
797 dc_connect $host, $port;
798 };
770 } else { 799 } else {
771 warn $@; 800 dc_connect $host, $port;
772 status "unable to connect";
773 stop_game();
774 } 801 }
775} 802}
776 803
777sub stop_game { 804sub stop_game {
778 $LOGIN_BUTTON->set_text ("Login / Register"); 805 $LOGIN_BUTTON->set_text ("Login / Register");
805 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "OpenGL Info"); 832 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "OpenGL Info");
806 $table->add_at (1, $row++, new DC::UI::Label fontsize => 0.8, text => DC::OpenGL::gl_vendor . ", " . DC::OpenGL::gl_version, 833 $table->add_at (1, $row++, new DC::UI::Label fontsize => 0.8, text => DC::OpenGL::gl_vendor . ", " . DC::OpenGL::gl_version,
807 can_events => 1, 834 can_events => 1,
808 tooltip => "<tt><span size='8192'>" . (DC::OpenGL::gl_extensions) . "</span></tt>"); 835 tooltip => "<tt><span size='8192'>" . (DC::OpenGL::gl_extensions) . "</span></tt>");
809 836
837 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Caveats");
838 $table->add_at (1, $row++, $CAVEAT_LABEL = new DC::UI::Label fontsize => 0.8,
839 can_events => 1,
840 tooltip => "This field shows any known issues with your config or driver, such as "
841 . "a non-accelerated display format. You can try to work around these issues "
842 . "by selecting a different video mode, changing the settings below or "
843 . "by installing the right driver for your graphics card.");
844
810 my $vidmode_tooltip = 845 my $vidmode_tooltip =
811 "<b>Video Mode.</b> The video mode to use for fullscreen (and the window size for windowed operation). " 846 "<b>Video Mode.</b> The video mode to use for fullscreen (and the window size for windowed operation). "
812 . "The format is <i>width</i> x <i>height</i> \@ <i>depth-per-channel</i> + <i>alpha-channel</i>."; 847 . "The format is <i>width</i> x <i>height</i> \@ <i>depth-per-channel</i> + <i>alpha-channel</i>.";
813 848
814 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Video Mode"); 849 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Video Mode");
815 $table->add_at (1, $row++, my $hbox = new DC::UI::HBox); 850 $table->add_at (1, $row++, my $hbox = new DC::UI::HBox);
816 851
817 $hbox->add (my $mode_slider = new DC::UI::Slider 852 $hbox->add ($MODE_SLIDER = new DC::UI::Slider
818 force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1], 853 force_w => $WIDTH * 0.1, expand => 1,
819 tooltip => $vidmode_tooltip); 854 tooltip => $vidmode_tooltip);
820 $hbox->add (my $mode_label = new DC::UI::Label 855 $hbox->add (my $mode_label = new DC::UI::Label
821 height => 0.8, template => "9999x9999@9+9", 856 height => 0.8, template => "9999x9999@9+9",
822 can_events => 1, tooltip => $vidmode_tooltip); 857 can_events => 1, tooltip => $vidmode_tooltip);
823 858
824 $mode_slider->connect (changed => sub { 859 $MODE_SLIDER->connect (changed => sub {
825 my ($self, $value) = @_; 860 my ($self, $value) = @_;
826 861
827 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 862 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
828 $mode_label->set_text (sprintf '%dx%d@%d+%d', @{$SDL_MODES[$value]}); 863 $mode_label->set_text (sprintf '%dx%d@%d+%d', @{$SDL_MODES[$value]});
829 }); 864 });
830 $mode_slider->emit (changed => $mode_slider->{range}[0]); 865 $MODE_SLIDER->emit (changed => $MODE_SLIDER->{range}[0]);
831 866
832 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fullscreen"); 867 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fullscreen");
833 $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new DC::UI::CheckBox 868 $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new DC::UI::CheckBox
834 state => $CFG->{fullscreen}, 869 state => $CFG->{fullscreen},
835 tooltip => "Bring the client into fullscreen mode.", 870 tooltip => "Bring the client into fullscreen mode.",
841 state => $CFG->{force_opengl11}, 876 state => $CFG->{force_opengl11},
842 tooltip => "Limit Deliantra to use OpenGL 1.1 features only. This will normally result in " 877 tooltip => "Limit Deliantra to use OpenGL 1.1 features only. This will normally result in "
843 . "higher memory usage and slower performance. It will, however, help tremendously on " 878 . "higher memory usage and slower performance. It will, however, help tremendously on "
844 . "cards that claim to support a feature but fall back to software rendering. " 879 . "cards that claim to support a feature but fall back to software rendering. "
845 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " 880 . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
846 . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " 881 . "but cards and drivers from other vendors (ATI) are often just as bad. "
847 . "experience extremely low framerates and your card should do better, try this option.</b>", 882 . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>",
848 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } 883 on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
884 );
885
886 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Forbid Alpha");
887 $table->add_at (1, $row++, new DC::UI::CheckBox
888 state => $CFG->{disable_alpha},
889 tooltip => "Forbid off the use of the alpha channel. This makes Deliantra look a lot worse "
890 . "by disabling a number of textures and transparency effects. Normally, these "
891 . "effects do not cost a lot of resources, but some graphics cards might fall "
892 . "back to etxremely slow rendering if this is enabled. If disabling this option "
893 . "noticably improves the framerate of the client please report this! "
894 . "<b>If you experience extremely low framerates and your card should do better, try this option.</b>",
895 on_changed => sub {
896 my ($self, $value) = @_;
897 $CFG->{disable_alpha} = $value;
898 $SDL_REINIT = 1; # SDL_SetVideoMode ignores GL attr changes
899 0
900 }
849 ); 901 );
850 902
851 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); 903 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
852 $table->add_at (1, $row++, new DC::UI::CheckBox 904 $table->add_at (1, $row++, new DC::UI::CheckBox
853 state => $CFG->{texture_compression}, 905 state => $CFG->{texture_compression},
2124 $dialog->show; 2176 $dialog->show;
2125 }; 2177 };
2126} 2178}
2127 2179
2128sub sdl_init { 2180sub sdl_init {
2129 DC::SDL_Init 2181 DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE
2130 and die "SDL::Init failed!\n"; 2182 and die "SDL::Init failed!\n";
2131} 2183}
2132 2184
2133sub video_init { 2185sub video_init {
2186 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2187 $SDL_REINIT = 0;
2188
2189 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8;
2190 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2191 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2192 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2193
2194 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2195
2134 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; 2196 if (!exists $CFG->{sdl_mode} or $CFG->{sdl_mode} >= @SDL_MODES) {
2197 $CFG->{sdl_mode} = 0;
2198 for (reverse 0 .. $#SDL_MODES) {
2199 $CFG->{sdl_mode} = $_ if $SDL_MODES[$_][0] * $SDL_MODES[$_][1] >= 800 * 600;
2200 }
2201 }
2135 2202
2136 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2203 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2137 2204
2138 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 2205 ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
2139 $FULLSCREEN = $CFG->{fullscreen}; 2206 $FULLSCREEN = $CFG->{fullscreen};
2323 $BUTTONBAR->show; 2390 $BUTTONBAR->show;
2324 $SETUP_DIALOG->show; 2391 $SETUP_DIALOG->show;
2325 $MESSAGE_WINDOW->show; 2392 $MESSAGE_WINDOW->show;
2326 } 2393 }
2327 2394
2395 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, $#SDL_MODES, 1, 1]);
2396 $MODE_SLIDER->emit (changed => $CFG->{sdl_mode});
2397
2398 $CAVEAT_LABEL->set_text ("None :)");
2399 $CAVEAT_LABEL->set_text ("Non-accelerated video mode")
2400 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL;
2401
2328 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 2402 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
2329} 2403}
2330 2404
2331sub video_shutdown { 2405sub video_shutdown {
2332 DC::OpenGL::shutdown; 2406 DC::OpenGL::shutdown;
2407 DC::SDL_QuitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2333 2408
2334 undef $SDL_ACTIVE; 2409 undef $SDL_ACTIVE;
2335} 2410}
2336 2411
2337my %animate_object; 2412my %animate_object;
2398# printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS; 2473# printf "M\n" if $_[0]{state} & DC::SDL_APPMOUSEFOCUS;
2399 }, 2474 },
2400 DC::SDL_KEYDOWN => sub { 2475 DC::SDL_KEYDOWN => sub {
2401 if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) { 2476 if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) {
2402 # alt-enter 2477 # alt-enter
2478 video_shutdown;
2403 $FULLSCREEN_ENABLE->toggle; 2479 $FULLSCREEN_ENABLE->toggle;
2404 video_shutdown;
2405 video_init; 2480 video_init;
2406 } else { 2481 } else {
2407 &DC::UI::feed_sdl_key_down_event; 2482 &DC::UI::feed_sdl_key_down_event;
2408 } 2483 }
2409 update_modbox; 2484 update_modbox;
2458 my %DEF_CFG = ( 2533 my %DEF_CFG = (
2459 sdl_mode => 0, 2534 sdl_mode => 0,
2460 fullscreen => 1, 2535 fullscreen => 1,
2461 fast => 0, 2536 fast => 0,
2462 force_opengl11 => undef, 2537 force_opengl11 => undef,
2538 disable_alpha => 0,
2463 texture_compression => 1, 2539 texture_compression => 1,
2464 map_scale => 1, 2540 map_scale => 1,
2465 fow_enable => 1, 2541 fow_enable => 1,
2466 fow_intensity => 0, 2542 fow_intensity => 0,
2467 map_smoothing => 1, 2543 map_smoothing => 1,
2508 } 2584 }
2509 } 2585 }
2510 2586
2511 sdl_init; 2587 sdl_init;
2512 2588
2513 @SDL_MODES = DC::SDL_ListModes 8, 8;
2514 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2515 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2516
2517 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2518
2519 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
2520
2521 { 2589 {
2522 my @fonts = map DC::find_rcfile "fonts/$_", qw( 2590 my @fonts = map DC::find_rcfile "fonts/$_", qw(
2523 DejaVuSans.ttf 2591 DejaVuSans.ttf
2524 DejaVuSansMono.ttf 2592 DejaVuSansMono.ttf
2525 DejaVuSans-Bold.ttf 2593 DejaVuSans-Bold.ttf

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines