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.60 by root, Tue Aug 19 21:48:28 2008 UTC vs.
Revision 1.75 by root, Wed Sep 3 10:08:18 2008 UTC

97 97
98# need to do it again because that pile of garbage called PAR nukes it before main 98# need to do it again because that pile of garbage called PAR nukes it before main
99unshift @INC, $ENV{PAR_TEMP} 99unshift @INC, $ENV{PAR_TEMP}
100 if %PAR::LibCache; 100 if %PAR::LibCache;
101 101
102use Time::HiRes 'time';
103use EV; 102use EV;
103BEGIN { *time = \&EV::time }
104
104use List::Util qw(max min); 105use List::Util qw(max min);
105 106
106use Deliantra; 107use Deliantra;
107use Deliantra::Protocol::Constants; 108use Deliantra::Protocol::Constants;
108 109
110use AnyEvent::Util ();
109use AnyEvent::DNS; 111use AnyEvent::DNS;
110use AnyEvent::Socket (); 112use AnyEvent::Socket ();
111 113
112use Compress::LZF; 114use Compress::LZF;
115use JSON::XS;
113 116
114use DC; 117use DC;
115BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } } 118
119sub crash($;$) {
120 # nop during compiletime
121}
122
123BEGIN {
124 $SIG{__DIE__} = sub {
125 return if $^S;
126 crash "CRASH/DIE: $_[0]" => 1;
127 DC::fatal Carp::longmess "$_[0]";
128 }
129}
130
116use DC::OpenGL (); 131use DC::OpenGL ();
117use DC::Protocol; 132use DC::Protocol;
118use DC::DB; 133use DC::DB;
119use DC::UI; 134use DC::UI;
120use DC::UI::Canvas; 135use DC::UI::Canvas;
121use DC::UI::Inventory; 136use DC::UI::Inventory;
122use DC::UI::SpellList; 137use DC::UI::SpellList;
123use DC::UI::Dockable; 138use DC::UI::Dockable;
124use DC::UI::Dockbar; 139use DC::UI::Dockbar;
125use DC::UI::MessageWindow;
126use DC::UI::ChatView; 140use DC::UI::ChatView;
127use DC::MessageDistributor; 141use DC::MessageDistributor;
128use DC::Pod; 142use DC::Pod;
129use DC::MapWidget; 143use DC::MapWidget;
130use DC::Macro; 144use DC::Macro;
131 145
132$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 146$SIG{QUIT} = sub { Carp::cluck "QUIT" };
133$SIG{PIPE} = 'IGNORE'; 147$SIG{PIPE} = 'IGNORE';
134 148
135$EV::DIED = sub { 149$EV::DIED = sub {
150 crash "CRASH/EV::DIED: $@" => 1;
136 DC::fatal Carp::longmess $@; 151 DC::fatal Carp::longmess $@;
137}; 152};
138 153
139my $MAX_FPS = 60; 154my $MAX_FPS = 60;
140 155
142 157
143our $LAST_REFRESH; 158our $LAST_REFRESH;
144our $NOW; 159our $NOW;
145 160
146our $CFG; 161our $CFG;
147our $CONN;
148our $PROFILE; # current profile 162our $PROFILE; # current profile
149our $FAST; # fast, low-quality mode, possibly useful for software-rendering 163our $FAST; # fast, low-quality mode, possibly useful for software-rendering
150 164
151our $WANT_REFRESH; 165our $WANT_REFRESH;
152 166
160our $FULLSCREEN; 174our $FULLSCREEN;
161our $FONTSIZE; 175our $FONTSIZE;
162 176
163our $FONT_PROP; 177our $FONT_PROP;
164our $FONT_FIXED; 178our $FONT_FIXED;
179
180our $CONN;
165 181
166our $MAP; 182our $MAP;
167our $MAPMAP; 183our $MAPMAP;
168our $MAPWIDGET; 184our $MAPWIDGET;
169our $COMPLETER; 185our $COMPLETER;
211our $DEBUG_STATUS; 227our $DEBUG_STATUS;
212 228
213our $INV; 229our $INV;
214our $INVR; 230our $INVR;
215our $INVR_HB; 231our $INVR_HB;
232
233#############################################################################
234
235# write a crash message blockingly to the socket, if possible
236# this is a bit too complicated for my tastes, but it was easy.
237*crash = sub($;$) {
238 my ($msg, $backtrace) = @_;
239
240 return unless $CONN;
241
242 my $fh = $CONN->{fh}
243 or return;
244
245 my $buf = delete $CONN->{wbuf};
246
247 $buf .= pack "n/a*", "exti " . JSON::XS::encode_json [clientlog => undef, substr $msg, 0, 8000];
248
249 AnyEvent::Util::fh_nonblocking $fh, 0;
250 syswrite $fh, $buf;
251 AnyEvent::Util::fh_nonblocking $fh, 1;
252
253 $msg =~ s/\s+$//;
254
255 # backtrace as second step, in case it crashes, too
256 crash Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated"
257 if $backtrace;
258};
216 259
217############################################################################# 260#############################################################################
218 261
219sub status { 262sub status {
220 $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 263 $STATUSBOX->add (DC::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
807 dc_connect $host, $port; 850 dc_connect $host, $port;
808 } 851 }
809} 852}
810 853
811sub stop_game { 854sub stop_game {
855 crash "stop_game";
856
812 $LOGIN_BUTTON->set_text ("Login / Register"); 857 $LOGIN_BUTTON->set_text ("Login / Register");
813 $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN); 858 $SETUP_NOTEBOOK->set_current_page ($SETUP_LOGIN);
814 $SETUP_DIALOG->show; 859 $SETUP_DIALOG->show;
815 $PL_WINDOW->hide; 860 $PL_WINDOW->hide;
816 $SPELL_LIST->clear_spells; 861 $SPELL_LIST->clear_spells;
836 881
837 my $row = 0; 882 my $row = 0;
838 883
839 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "OpenGL Info"); 884 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "OpenGL Info");
840 $table->add_at (1, $row++, new DC::UI::Label fontsize => 0.8, text => DC::OpenGL::gl_vendor . ", " . DC::OpenGL::gl_version, 885 $table->add_at (1, $row++, new DC::UI::Label fontsize => 0.8, text => DC::OpenGL::gl_vendor . ", " . DC::OpenGL::gl_version,
841 can_events => 1, 886 can_events => 1,
842 tooltip => "<tt><span size='8192'>" . (DC::OpenGL::gl_extensions) . "</span></tt>"); 887 tooltip => "<tt><span size='8192'>" . (DC::OpenGL::gl_extensions) . "</span></tt>");
843 888
844 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Caveats"); 889 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Caveats");
845 $table->add_at (1, $row++, $CAVEAT_LABEL = new DC::UI::Label fontsize => 0.8, 890 $table->add_at (1, $row++, $CAVEAT_LABEL = new DC::UI::Label fontsize => 0.8,
846 can_events => 1, 891 can_events => 1,
847 tooltip => "This field shows any known issues with your config or driver, such as " 892 tooltip => "This field shows any known issues with your config or driver, such as "
848 . "a non-accelerated display format. You can try to work around these issues " 893 . "a non-accelerated display format. You can try to work around these issues "
849 . "by selecting a different video mode, changing the settings below or " 894 . "by selecting a different video mode, changing the settings below or "
850 . "by installing the right driver for your graphics card."); 895 . "by installing the right driver for your graphics card.");
896
897 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "UI Theme");
898 $table->add_at (1, $row++, $FULLSCREEN_ENABLE = new DC::UI::Selector
899 value => $CFG->{uitheme},
900 options => [
901 [wood => "Wood (the default)"],
902 [plain => "Plain (very)"],
903 [blue => "Blue"],
904 ],
905 tooltip => "Choose the User Interface theme that you like most :)",
906 on_changed => sub { my ($self, $value) = @_; $CFG->{uitheme} = $value; 0 }
907 );
851 908
852 my $vidmode_tooltip = 909 my $vidmode_tooltip =
853 "<b>Video Mode.</b> The video mode to use for fullscreen (and the window size for windowed operation). " 910 "<b>Video Mode.</b> The video mode to use for fullscreen (and the window size for windowed operation). "
854 . "The format is <i>width</i> x <i>height</i> \@ <i>depth-per-channel</i> + <i>alpha-channel</i>."; 911 . "The format is <i>width</i> x <i>height</i> \@ <i>depth-per-channel</i> + <i>alpha-channel</i>.";
855 912
910 967
911 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); 968 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
912 $table->add_at (1, $row++, new DC::UI::CheckBox 969 $table->add_at (1, $row++, new DC::UI::CheckBox
913 state => $CFG->{texture_compression}, 970 state => $CFG->{texture_compression},
914 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " 971 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
915 . "will save a lot of memory and increase performance. The compression algorithm " 972 . "will save a lot of memory and increase performance (and also fall prey to the ever-buggy Mac OS X software renderer). "
916 . "can differ form card to card, so your mileage may vary. This setting is ignored in " 973 . "The compression algorithm can differ form card to card, so your mileage may vary. This setting is ignored in "
917 . "forced OpenGL 1.1 mode.", 974 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
918 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 975 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
919 ); 976 );
920 977
921 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); 978 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly");
922 $table->add_at (1, $row++, new DC::UI::CheckBox 979 $table->add_at (1, $row++, new DC::UI::CheckBox
1596 1 1653 1
1597 }, 1654 },
1598 ); 1655 );
1599 1656
1600 $vbox->add (new DC::UI::FancyFrame 1657 $vbox->add (new DC::UI::FancyFrame
1601 label => "Registering", 1658 label => "How to Play",
1602 min_h => 200, 1659 min_h => 240,
1603 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1660 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1604 markup => 1661 markup =>
1662 "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n"
1663 . "Then register a new account (or use an existing one if you have one). "
1605 "To register a new account, choose a username that hasn't been taken yet and " 1664 . "To register an account, choose a username that hasn't been taken yet (just guess) and "
1606 . "try to log-in. Follow the instructions in the Log tab in the message window.", 1665 . "try to log-in. Follow the instructions in the Log tab in the message window.",
1607 ), 1666 ),
1608 ); 1667 );
1609 1668
1610 $vbox 1669 $vbox
2131 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 2190 on_activate => sub { $QUIT_DIALOG->hide; 0 },
2132 ); 2191 );
2133 $hb->add (new DC::UI::Button 2192 $hb->add (new DC::UI::Button
2134 text => "Quit anyway", 2193 text => "Quit anyway",
2135 expand => 1, 2194 expand => 1,
2136 on_activate => sub { EV::unloop EV::UNLOOP_ALL }, 2195 on_activate => sub {
2196 crash "Quit anyway";
2197 EV::unloop EV::UNLOOP_ALL;
2198 },
2137 ); 2199 );
2138 } 2200 }
2139 2201
2140 $QUIT_DIALOG->show; 2202 $QUIT_DIALOG->show;
2141 $QUIT_DIALOG->grab_focus; 2203 $QUIT_DIALOG->grab_focus;
2199 DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE 2261 DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE
2200 and die "SDL::Init failed!\n"; 2262 and die "SDL::Init failed!\n";
2201} 2263}
2202 2264
2203sub video_init { 2265sub video_init {
2266 DC::set_theme $CFG->{uitheme};
2267
2204 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; 2268 DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT;
2205 $SDL_REINIT = 0; 2269 $SDL_REINIT = 0;
2206 2270
2207 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; 2271 @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8;
2208 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; 2272 @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES;
2209 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; 2273 @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES;
2210 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 2274 @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
2211 2275
2212 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2276 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2213 2277
2214 if (!exists $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) { 2278 if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) {
2215 $CFG->{sdl_mode} = 0; 2279 $CFG->{sdl_mode} = 0; # lowest resolution by default
2280
2281 # now choose biggest mode <= 1024x768
2216 for (reverse 0 .. $#SDL_MODES) { 2282 for (0 .. $#SDL_MODES) {
2217 $CFG->{sdl_mode} = $_ if $SDL_MODES[$_][0] * $SDL_MODES[$_][1] >= 800 * 600; 2283 if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) {
2284 $CFG->{sdl_mode} = $_;
2285 }
2218 } 2286 }
2219 } 2287 }
2220 2288
2221 my ($old_w, $old_h) = ($WIDTH, $HEIGHT); 2289 my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
2222 2290
2301 x => 0, 2369 x => 0,
2302 y => $FONTSIZE + 8, 2370 y => $FONTSIZE + 8,
2303 border_bg => [1, 1, 1, 192/255], 2371 border_bg => [1, 1, 1, 192/255],
2304 bg => [1, 1, 1, 0], 2372 bg => [1, 1, 1, 0],
2305 child => ($MAPMAP = new DC::MapWidget::MapMap 2373 child => ($MAPMAP = new DC::MapWidget::MapMap
2306 tooltip => "<b>Map</b>. On servers that support this feature, this will display an overview of the surrounding areas.", 2374 tooltip => "<b>Minimap</b>. This will display an overview of the surrounding areas.",
2307 ), 2375 ),
2308 )->show; 2376 )->show;
2309 2377
2310 $MAPWIDGET = new DC::MapWidget; 2378 $MAPWIDGET = new DC::MapWidget;
2311 $MAPWIDGET->connect (activate_console => sub { 2379 $MAPWIDGET->connect (activate_console => sub {
2410 $BUTTONBAR->show; 2478 $BUTTONBAR->show;
2411 $SETUP_DIALOG->show; 2479 $SETUP_DIALOG->show;
2412 $MESSAGE_WINDOW->show; 2480 $MESSAGE_WINDOW->show;
2413 } 2481 }
2414 2482
2415 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, $#SDL_MODES, 1, 1]); 2483 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1, 1]);
2416 $MODE_SLIDER->emit (changed => $CFG->{sdl_mode}); 2484 $MODE_SLIDER->emit (changed => $CFG->{sdl_mode});
2417 2485
2418 $CAVEAT_LABEL->set_text ("None :)"); 2486 $CAVEAT_LABEL->set_text ("None :)");
2419 $CAVEAT_LABEL->set_text ("Software Rendering (very slow)") 2487 $CAVEAT_LABEL->set_text ("Software Rendering (very slow)")
2420 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL; 2488 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL;
2475 delete $animate_object{$widget}; 2543 delete $animate_object{$widget};
2476} 2544}
2477 2545
2478%SDL_CB = ( 2546%SDL_CB = (
2479 DC::SDL_QUIT => sub { 2547 DC::SDL_QUIT => sub {
2548 crash "SDL_QUIT";
2480 EV::unloop EV::UNLOOP_ALL; 2549 EV::unloop EV::UNLOOP_ALL;
2481 }, 2550 },
2482 DC::SDL_VIDEORESIZE => sub { 2551 DC::SDL_VIDEORESIZE => sub {
2483 }, 2552 },
2484 DC::SDL_VIDEOEXPOSE => sub { 2553 DC::SDL_VIDEOEXPOSE => sub {
2551 DC::DB::open_db; 2620 DC::DB::open_db;
2552 2621
2553 DC::UI::set_layout ($::CFG->{layout}); 2622 DC::UI::set_layout ($::CFG->{layout});
2554 2623
2555 my %DEF_CFG = ( 2624 my %DEF_CFG = (
2556 sdl_mode => 0, 2625 sdl_mode => undef,
2557 fullscreen => 1, 2626 fullscreen => 1,
2558 fast => 0, 2627 fast => 0,
2559 force_opengl11 => undef, 2628 force_opengl11 => undef,
2560 disable_alpha => 0, 2629 disable_alpha => 0,
2561 smooth_movement => 1, 2630 smooth_movement => 1,
2584 inv_sort => "mtime", 2653 inv_sort => "mtime",
2585 default => "profile", # default profile 2654 default => "profile", # default profile
2586 show_tips => 1, 2655 show_tips => 1,
2587 logview_max_par => 1000, 2656 logview_max_par => 1000,
2588 shift_fire_stop => 0, 2657 shift_fire_stop => 0,
2658 uitheme => "wood",
2589 ); 2659 );
2590 2660
2591 while (my ($k, $v) = each %DEF_CFG) { 2661 while (my ($k, $v) = each %DEF_CFG) {
2592 $CFG->{$k} = $v unless exists $CFG->{$k}; 2662 $CFG->{$k} = $v unless exists $CFG->{$k};
2593 } 2663 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines