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.62 by root, Fri Aug 22 21:53:07 2008 UTC vs.
Revision 1.72 by root, Tue Sep 2 17:15:39 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 "
910 955
911 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); 956 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures");
912 $table->add_at (1, $row++, new DC::UI::CheckBox 957 $table->add_at (1, $row++, new DC::UI::CheckBox
913 state => $CFG->{texture_compression}, 958 state => $CFG->{texture_compression},
914 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " 959 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 " 960 . "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 " 961 . "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.", 962 . "forced OpenGL 1.1 mode and when using the Apple renderer.",
918 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 963 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
919 ); 964 );
920 965
921 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); 966 $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly");
922 $table->add_at (1, $row++, new DC::UI::CheckBox 967 $table->add_at (1, $row++, new DC::UI::CheckBox
1597 }, 1642 },
1598 ); 1643 );
1599 1644
1600 $vbox->add (new DC::UI::FancyFrame 1645 $vbox->add (new DC::UI::FancyFrame
1601 label => "How to Play", 1646 label => "How to Play",
1602 min_h => 200, 1647 min_h => 240,
1603 child => (new DC::UI::Label valign => 0, ellipsise => 0, 1648 child => (new DC::UI::Label valign => 0, ellipsise => 0,
1604 markup => 1649 markup =>
1605 "First select a suitable video resolution in the Graphics tab, above.\n\n" 1650 "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n"
1606 . "Then register a new account (or use an existing one if you have one). " 1651 . "Then register a new account (or use an existing one if you have one). "
1607 . "To register an account, choose a username that hasn't been taken yet (just guess) and " 1652 . "To register an account, choose a username that hasn't been taken yet (just guess) and "
1608 . "try to log-in. Follow the instructions in the Log tab in the message window.", 1653 . "try to log-in. Follow the instructions in the Log tab in the message window.",
1609 ), 1654 ),
1610 ); 1655 );
2133 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 2178 on_activate => sub { $QUIT_DIALOG->hide; 0 },
2134 ); 2179 );
2135 $hb->add (new DC::UI::Button 2180 $hb->add (new DC::UI::Button
2136 text => "Quit anyway", 2181 text => "Quit anyway",
2137 expand => 1, 2182 expand => 1,
2138 on_activate => sub { EV::unloop EV::UNLOOP_ALL }, 2183 on_activate => sub {
2184 crash "Quit anyway";
2185 EV::unloop EV::UNLOOP_ALL;
2186 },
2139 ); 2187 );
2140 } 2188 }
2141 2189
2142 $QUIT_DIALOG->show; 2190 $QUIT_DIALOG->show;
2143 $QUIT_DIALOG->grab_focus; 2191 $QUIT_DIALOG->grab_focus;
2214 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; 2262 @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
2215 2263
2216 if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) { 2264 if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) {
2217 $CFG->{sdl_mode} = 0; # lowest resolution by default 2265 $CFG->{sdl_mode} = 0; # lowest resolution by default
2218 2266
2219 # now choose biggets mode <= 1024x768 2267 # now choose biggest mode <= 1024x768
2220 for (0 .. $#SDL_MODES) { 2268 for (0 .. $#SDL_MODES) {
2221 if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) { 2269 if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) {
2222 $CFG->{sdl_mode} = $_; 2270 $CFG->{sdl_mode} = $_;
2223 } 2271 }
2224 } 2272 }
2416 $BUTTONBAR->show; 2464 $BUTTONBAR->show;
2417 $SETUP_DIALOG->show; 2465 $SETUP_DIALOG->show;
2418 $MESSAGE_WINDOW->show; 2466 $MESSAGE_WINDOW->show;
2419 } 2467 }
2420 2468
2421 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, $#SDL_MODES, 1, 1]); 2469 $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1, 1]);
2422 $MODE_SLIDER->emit (changed => $CFG->{sdl_mode}); 2470 $MODE_SLIDER->emit (changed => $CFG->{sdl_mode});
2423 2471
2424 $CAVEAT_LABEL->set_text ("None :)"); 2472 $CAVEAT_LABEL->set_text ("None :)");
2425 $CAVEAT_LABEL->set_text ("Software Rendering (very slow)") 2473 $CAVEAT_LABEL->set_text ("Software Rendering (very slow)")
2426 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL; 2474 unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL;
2481 delete $animate_object{$widget}; 2529 delete $animate_object{$widget};
2482} 2530}
2483 2531
2484%SDL_CB = ( 2532%SDL_CB = (
2485 DC::SDL_QUIT => sub { 2533 DC::SDL_QUIT => sub {
2534 crash "SDL_QUIT";
2486 EV::unloop EV::UNLOOP_ALL; 2535 EV::unloop EV::UNLOOP_ALL;
2487 }, 2536 },
2488 DC::SDL_VIDEORESIZE => sub { 2537 DC::SDL_VIDEORESIZE => sub {
2489 }, 2538 },
2490 DC::SDL_VIDEOEXPOSE => sub { 2539 DC::SDL_VIDEOEXPOSE => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines