… | |
… | |
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 |
99 | unshift @INC, $ENV{PAR_TEMP} |
99 | unshift @INC, $ENV{PAR_TEMP} |
100 | if %PAR::LibCache; |
100 | if %PAR::LibCache; |
101 | |
101 | |
102 | use Time::HiRes 'time'; |
|
|
103 | use EV; |
102 | use EV; |
|
|
103 | BEGIN { *time = \&EV::time } |
|
|
104 | |
104 | use List::Util qw(max min); |
105 | use List::Util qw(max min); |
105 | |
106 | |
106 | use Deliantra; |
107 | use Deliantra; |
107 | use Deliantra::Protocol::Constants; |
108 | use Deliantra::Protocol::Constants; |
108 | |
109 | |
… | |
… | |
113 | use Compress::LZF; |
114 | use Compress::LZF; |
114 | use JSON::XS; |
115 | use JSON::XS; |
115 | |
116 | |
116 | use DC; |
117 | use DC; |
117 | |
118 | |
118 | ############################################################################# |
|
|
119 | |
|
|
120 | our $CONN; |
|
|
121 | |
|
|
122 | # write a crash message blockingly to the socket, if possible |
|
|
123 | # this is a bit too complicated for my tastes, but it was easy. |
|
|
124 | sub crash($;$) { |
119 | sub crash($;$) { |
125 | my ($msg, $backtrace) = @_; |
120 | # nop during compiletime |
126 | |
|
|
127 | return unless $CONN; |
|
|
128 | |
|
|
129 | my $fh = $CONN->{fh} |
|
|
130 | or return; |
|
|
131 | |
|
|
132 | my $buf = delete $CONN->{wbuf}; |
|
|
133 | |
|
|
134 | $buf .= pack "n/a*", "exti " . JSON::XS::encode_json [clientlog => undef, substr $msg, 0, 8000]; |
|
|
135 | |
|
|
136 | AnyEvent::Util::fh_nonblocking $fh, 0; |
|
|
137 | |
|
|
138 | syswrite $fh, $buf; |
|
|
139 | AnyEvent::Util::fh_nonblocking $fh, 1; |
|
|
140 | |
|
|
141 | $msg =~ s/\s+$//; |
|
|
142 | |
|
|
143 | # backtrace as second step, in case it crashes, too |
|
|
144 | crash (Carp::longmess "$msg\nbacktrace, for client version $DC::VERSION, generated") |
|
|
145 | if $backtrace; |
|
|
146 | } |
121 | } |
147 | |
|
|
148 | ############################################################################# |
|
|
149 | |
122 | |
150 | BEGIN { |
123 | BEGIN { |
151 | $SIG{__DIE__} = sub { |
124 | $SIG{__DIE__} = sub { |
152 | return if $^S; |
125 | return if $^S; |
153 | crash ("CRASH/DIE: $_[0]" => 1); |
126 | crash "CRASH/DIE: $_[0]" => 1; |
154 | DC::fatal Carp::longmess "$_[0]"; |
127 | DC::fatal Carp::longmess "$_[0]"; |
155 | } |
128 | } |
156 | } |
129 | } |
157 | |
130 | |
158 | use DC::OpenGL (); |
131 | use DC::OpenGL (); |
… | |
… | |
172 | |
145 | |
173 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
146 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
174 | $SIG{PIPE} = 'IGNORE'; |
147 | $SIG{PIPE} = 'IGNORE'; |
175 | |
148 | |
176 | $EV::DIED = sub { |
149 | $EV::DIED = sub { |
177 | crash ("CRASH/EV::DIED: $@" => 1); |
150 | crash "CRASH/EV::DIED: $@" => 1; |
178 | DC::fatal Carp::longmess $@; |
151 | DC::fatal Carp::longmess $@; |
179 | }; |
152 | }; |
180 | |
153 | |
181 | my $MAX_FPS = 60; |
154 | my $MAX_FPS = 60; |
182 | |
155 | |
… | |
… | |
201 | our $FULLSCREEN; |
174 | our $FULLSCREEN; |
202 | our $FONTSIZE; |
175 | our $FONTSIZE; |
203 | |
176 | |
204 | our $FONT_PROP; |
177 | our $FONT_PROP; |
205 | our $FONT_FIXED; |
178 | our $FONT_FIXED; |
|
|
179 | |
|
|
180 | our $CONN; |
206 | |
181 | |
207 | our $MAP; |
182 | our $MAP; |
208 | our $MAPMAP; |
183 | our $MAPMAP; |
209 | our $MAPWIDGET; |
184 | our $MAPWIDGET; |
210 | our $COMPLETER; |
185 | our $COMPLETER; |
… | |
… | |
252 | our $DEBUG_STATUS; |
227 | our $DEBUG_STATUS; |
253 | |
228 | |
254 | our $INV; |
229 | our $INV; |
255 | our $INVR; |
230 | our $INVR; |
256 | our $INVR_HB; |
231 | our $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 | }; |
257 | |
259 | |
258 | ############################################################################# |
260 | ############################################################################# |
259 | |
261 | |
260 | sub status { |
262 | sub status { |
261 | $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]); |
… | |
… | |
889 | can_events => 1, |
891 | can_events => 1, |
890 | 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 " |
891 | . "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 " |
892 | . "by selecting a different video mode, changing the settings below or " |
894 | . "by selecting a different video mode, changing the settings below or " |
893 | . "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 | ); |
894 | |
908 | |
895 | my $vidmode_tooltip = |
909 | my $vidmode_tooltip = |
896 | "<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). " |
897 | . "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>."; |
898 | |
912 | |
… | |
… | |
2247 | DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE |
2261 | DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE |
2248 | and die "SDL::Init failed!\n"; |
2262 | and die "SDL::Init failed!\n"; |
2249 | } |
2263 | } |
2250 | |
2264 | |
2251 | sub video_init { |
2265 | sub video_init { |
|
|
2266 | DC::set_theme $CFG->{uitheme}; |
|
|
2267 | |
2252 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2268 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2253 | $SDL_REINIT = 0; |
2269 | $SDL_REINIT = 0; |
2254 | |
2270 | |
2255 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2271 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2256 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2272 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
… | |
… | |
2260 | @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; |
2261 | |
2277 | |
2262 | if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) { |
2278 | if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) { |
2263 | $CFG->{sdl_mode} = 0; # lowest resolution by default |
2279 | $CFG->{sdl_mode} = 0; # lowest resolution by default |
2264 | |
2280 | |
2265 | # now choose biggets mode <= 1024x768 |
2281 | # now choose biggest mode <= 1024x768 |
2266 | for (0 .. $#SDL_MODES) { |
2282 | for (0 .. $#SDL_MODES) { |
2267 | if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) { |
2283 | if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) { |
2268 | $CFG->{sdl_mode} = $_; |
2284 | $CFG->{sdl_mode} = $_; |
2269 | } |
2285 | } |
2270 | } |
2286 | } |
… | |
… | |
2353 | x => 0, |
2369 | x => 0, |
2354 | y => $FONTSIZE + 8, |
2370 | y => $FONTSIZE + 8, |
2355 | border_bg => [1, 1, 1, 192/255], |
2371 | border_bg => [1, 1, 1, 192/255], |
2356 | bg => [1, 1, 1, 0], |
2372 | bg => [1, 1, 1, 0], |
2357 | child => ($MAPMAP = new DC::MapWidget::MapMap |
2373 | child => ($MAPMAP = new DC::MapWidget::MapMap |
2358 | 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.", |
2359 | ), |
2375 | ), |
2360 | )->show; |
2376 | )->show; |
2361 | |
2377 | |
2362 | $MAPWIDGET = new DC::MapWidget; |
2378 | $MAPWIDGET = new DC::MapWidget; |
2363 | $MAPWIDGET->connect (activate_console => sub { |
2379 | $MAPWIDGET->connect (activate_console => sub { |
… | |
… | |
2462 | $BUTTONBAR->show; |
2478 | $BUTTONBAR->show; |
2463 | $SETUP_DIALOG->show; |
2479 | $SETUP_DIALOG->show; |
2464 | $MESSAGE_WINDOW->show; |
2480 | $MESSAGE_WINDOW->show; |
2465 | } |
2481 | } |
2466 | |
2482 | |
2467 | $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]); |
2468 | $MODE_SLIDER->emit (changed => $CFG->{sdl_mode}); |
2484 | $MODE_SLIDER->emit (changed => $CFG->{sdl_mode}); |
2469 | |
2485 | |
2470 | $CAVEAT_LABEL->set_text ("None :)"); |
2486 | $CAVEAT_LABEL->set_text ("None :)"); |
2471 | $CAVEAT_LABEL->set_text ("Software Rendering (very slow)") |
2487 | $CAVEAT_LABEL->set_text ("Software Rendering (very slow)") |
2472 | unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL; |
2488 | unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL; |
… | |
… | |
2637 | inv_sort => "mtime", |
2653 | inv_sort => "mtime", |
2638 | default => "profile", # default profile |
2654 | default => "profile", # default profile |
2639 | show_tips => 1, |
2655 | show_tips => 1, |
2640 | logview_max_par => 1000, |
2656 | logview_max_par => 1000, |
2641 | shift_fire_stop => 0, |
2657 | shift_fire_stop => 0, |
|
|
2658 | uitheme => "wood", |
2642 | ); |
2659 | ); |
2643 | |
2660 | |
2644 | while (my ($k, $v) = each %DEF_CFG) { |
2661 | while (my ($k, $v) = each %DEF_CFG) { |
2645 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2662 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2646 | } |
2663 | } |