--- deliantra/Deliantra-Client/bin/deliantra 2008/03/25 19:28:56 1.32 +++ deliantra/Deliantra-Client/bin/deliantra 2008/07/18 21:18:42 1.52 @@ -99,9 +99,13 @@ use Deliantra; use Deliantra::Protocol::Constants; +use AnyEvent::DNS; +use AnyEvent::Socket (); + use Compress::LZF; use DC; +BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } } use DC::OpenGL (); use DC::Protocol; use DC::DB; @@ -140,6 +144,7 @@ our $WANT_REFRESH; our @SDL_MODES; +our $SDL_REINIT = 1; our $WIDTH; our $HEIGHT; our $FULLSCREEN; @@ -666,7 +671,6 @@ text => "Accept", on_activate => sub { $conn->send ("reply n"); - $STATS_PAGE->hide; destroy_query_dialog $conn; 0 }, @@ -728,22 +732,15 @@ $dialog->show; } -sub start_game { - status "logging in..."; - - $LOGIN_BUTTON->set_text ("Logout"); - $SETUP_DIALOG->hide; +sub dc_connect { + my ($host, $port) = @_; my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; - my ($host, $port) = split /:/, $PROFILE->{host}; - - $MAP = new DC::Map; - - $CONN = eval { + $CONN = new DC::Protocol host => $host, - port => $port || 13327, + port => $port, user => $PROFILE->{user}, pass => $PROFILE->{password}, mapw => $mapsize, @@ -760,16 +757,44 @@ setup_req => { smoothing => $CFG->{map_smoothing}*1, }, - }; - if ($CONN) { - DC::lowdelay fileno $CONN->{fh}; + on_connect => sub { + if ($_[0]) { + DC::lowdelay fileno $CONN->{fh}; + + status "login successful"; + } else { + undef $CONN; + status "unable to connect: $!"; + stop_game(); + } + }, + ; +} + +sub start_game { + status "logging in..."; + + $LOGIN_BUTTON->set_text ("Logout"); + $SETUP_DIALOG->hide; + + my ($host, $port) = AnyEvent::Socket::parse_hostport $PROFILE->{host}, "deliantra=13327"; - status "login successful"; + $MAP = new DC::Map; + + # hack to make SURE we find the IP address all right + # can be removed once AnyEvent::DNS is proven stable. + if ($host eq "gameserver.deliantra.net") { + AnyEvent::DNS::a "dnstest.deliantra.net", sub { + if ($_[0] ne "80.101.114.108") { # Perl + status "dns failure, using hardcoded address"; + $host = "129.13.162.95"; + } + + dc_connect $host, $port; + }; } else { - warn $@; - status "unable to connect"; - stop_game(); + dc_connect $host, $port; } } @@ -842,11 +867,28 @@ . "higher memory usage and slower performance. It will, however, help tremendously on " . "cards that claim to support a feature but fall back to software rendering. " . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " - . "but cards and drivers from other vendors (ATI) are often just as bad. If you " - . "experience extremely low framerates and your card should do better, try this option.", + . "but cards and drivers from other vendors (ATI) are often just as bad. " + . "If you experience extremely low framerates and your card should do better, try this option.", on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } ); + $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Forbid Alpha"); + $table->add_at (1, $row++, new DC::UI::CheckBox + state => $CFG->{disable_alpha}, + tooltip => "Forbid off the use of the alpha channel. This makes Deliantra look a lot worse " + . "by disabling a number of textures and transparency effects. Normally, these " + . "effects do not cost a lot of resources, but some graphics cards might fall " + . "back to etxremely slow rendering if this is enabled. If disabling this option " + . "noticably improves the framerate of the client please report this! " + . "If you experience extremely low framerates and your card should do better, try this option.", + on_changed => sub { + my ($self, $value) = @_; + $CFG->{disable_alpha} = $value; + $SDL_REINIT = 1; # SDL_SetVideoMode ignores GL attr changes + 0 + } + ); + $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); $table->add_at (1, $row++, new DC::UI::CheckBox state => $CFG->{texture_compression}, @@ -1623,10 +1665,10 @@ } ); - $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Messages Window Size"); + $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Message Window Size"); $table->add_at (1, $row++, my $saycmd = new DC::UI::Entry text => $CFG->{logview_max_par}, - tooltip => "This is maximum number of messages remembered in the Messages window. If the server " + tooltip => "This is maximum number of messages remembered in the Message window. If the server " . "sends more messages than this number, older messages get removed to save memory and " . "computing time. A value of 0 disables this feature, but that is not recommended.", on_changed => sub { @@ -1745,7 +1787,9 @@ } my %SORT_ORDER = ( - type => undef, + type => sub { + sort { $a->{type} <=> $b->{type} or $a->{name} cmp $b->{name} } @_ + }, mtime => sub { my $NOW = time; sort { @@ -2123,12 +2167,27 @@ } sub sdl_init { - DC::SDL_Init + DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE and die "SDL::Init failed!\n"; } sub video_init { - $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES; + DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; + $SDL_REINIT = 0; + + @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; + @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; + @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; + @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; + + @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; + + if (!exists $CFG->{sdl_mode} or $CFG->{sdl_mode} >= @SDL_MODES) { + $CFG->{sdl_mode} = 0; + for (reverse 0 .. $#SDL_MODES) { + $CFG->{sdl_mode} = $_ if $SDL_MODES[$_][0] * $SDL_MODES[$_][1] >= 800 * 600; + } + } my ($old_w, $old_h) = ($WIDTH, $HEIGHT); @@ -2244,10 +2303,17 @@ ; $METASERVER = metaserver_dialog; - $MESSAGE_WINDOW = new DC::UI::Dockbar (name => 'message_window', title => 'Messages'); + # the name is changed to not conflict with the older name as users could have hidden it + $MESSAGE_WINDOW = new DC::UI::Dockbar + name => "message_window2", + title => 'Messages', + force_w => $::WIDTH * 0.6, + force_h => $::HEIGHT * 0.25, + ; + $MESSAGE_DIST = new DC::MessageDistributor dockbar => $MESSAGE_WINDOW; - $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, debug => 1, + $SETUP_DIALOG->add ($SETUP_NOTEBOOK = new DC::UI::Notebook expand => 1, filter => new DC::UI::ScrolledWindow expand => 1, scroll_y => 1); $SETUP_NOTEBOOK->add_tab (Login => $SETUP_LOGIN = login_setup, @@ -2275,8 +2341,8 @@ $BUTTONBAR->add (new DC::UI::Flopper text => "Setup", other => $SETUP_DIALOG, tooltip => "Toggles a dialog where you can configure all aspects of this client."); - $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, - tooltip => "Toggles the server message log, where the client collects all messages from the server."); +# $BUTTONBAR->add (new DC::UI::Flopper text => "Message Window", other => $MESSAGE_WINDOW, +# tooltip => "Toggles the server message log, where the client collects all messages from the server."); make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D @@ -2288,7 +2354,7 @@ tooltip => "Saves the options chosen in the client setting, server settings and the window layout to be restored on later runs.", on_activate => sub { $::CFG->{layout} = DC::UI::get_layout; - DC::write_cfg "$Deliantra::VARDIR/client.cf"; + DC::write_cfg; status "Configuration Saved"; 0 }, @@ -2297,7 +2363,6 @@ $BUTTONBAR->add (new DC::UI::Flopper text => "Help!", other => $HELP_WINDOW = help_window, tooltip => "View Documentation"); - $BUTTONBAR->add (new DC::UI::Button text => "Quit", tooltip => "Terminates the program", @@ -2321,6 +2386,7 @@ sub video_shutdown { DC::OpenGL::shutdown; + DC::SDL_QuitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; undef $SDL_ACTIVE; } @@ -2391,8 +2457,8 @@ DC::SDL_KEYDOWN => sub { if ($_[0]{mod} & DC::KMOD_ALT && $_[0]{sym} == 13) { # alt-enter - $FULLSCREEN_ENABLE->toggle; video_shutdown; + $FULLSCREEN_ENABLE->toggle; video_init; } else { &DC::UI::feed_sdl_key_down_event; @@ -2423,6 +2489,8 @@ }; { + DC::Pod::load_docwiki DC::find_rcfile "docwiki.pst"; + if (-e "$Deliantra::VARDIR/client.cf") { DC::read_cfg "$Deliantra::VARDIR/client.cf"; } else { @@ -2433,6 +2501,15 @@ DC::DB::Server::run; + if ($CFG->{db_schema} < 1) { + warn "INFO: upgrading database schema from 0 to 1, mapcache and tilecache will be lost\n"; + DC::DB::nuke_db; + $CFG->{db_schema} = 1; + DC::write_cfg; + } + + DC::DB::open_db; + DC::UI::set_layout ($::CFG->{layout}); my %DEF_CFG = ( @@ -2440,6 +2517,7 @@ fullscreen => 1, fast => 0, force_opengl11 => undef, + disable_alpha => 0, texture_compression => 1, map_scale => 1, fow_enable => 1, @@ -2466,6 +2544,7 @@ default => "profile", # default profile show_tips => 1, logview_max_par => 1000, + shift_fire_stop => 0, ); while (my ($k, $v) = each %DEF_CFG) { @@ -2489,14 +2568,6 @@ sdl_init; - @SDL_MODES = DC::SDL_ListModes 8, 8; - @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; - @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; - - @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; - - $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; - { my @fonts = map DC::find_rcfile "fonts/$_", qw( DejaVuSans.ttf @@ -2543,6 +2614,7 @@ $startup_done->(); }; +delete $SIG{__DIE__}; EV::loop; #video_shutdown;