… | |
… | |
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 | |
|
|
110 | use AnyEvent::Util (); |
109 | use AnyEvent::DNS; |
111 | use AnyEvent::DNS; |
110 | use AnyEvent::Socket (); |
112 | use AnyEvent::Socket (); |
111 | |
113 | |
112 | use Compress::LZF; |
114 | use Compress::LZF; |
|
|
115 | use JSON::XS; |
113 | |
116 | |
114 | use DC; |
117 | use DC; |
115 | BEGIN { $SIG{__DIE__} = sub { DC::fatal Carp::longmess "$_[0]" unless $^S } } |
118 | |
|
|
119 | sub crash($;$) { |
|
|
120 | # nop during compiletime |
|
|
121 | } |
|
|
122 | |
|
|
123 | BEGIN { |
|
|
124 | $SIG{__DIE__} = sub { |
|
|
125 | return if $^S; |
|
|
126 | crash "CRASH/DIE: $_[0]" => 1; |
|
|
127 | DC::fatal Carp::longmess "$_[0]"; |
|
|
128 | } |
|
|
129 | } |
|
|
130 | |
116 | use DC::OpenGL (); |
131 | use DC::OpenGL (); |
117 | use DC::Protocol; |
132 | use DC::Protocol; |
118 | use DC::DB; |
133 | use DC::DB; |
119 | use DC::UI; |
134 | use DC::UI; |
120 | use DC::UI::Canvas; |
135 | use DC::UI::Canvas; |
121 | use DC::UI::Inventory; |
136 | use DC::UI::Inventory; |
122 | use DC::UI::SpellList; |
137 | use DC::UI::SpellList; |
123 | use DC::UI::Dockable; |
138 | use DC::UI::Dockable; |
124 | use DC::UI::Dockbar; |
139 | use DC::UI::Dockbar; |
125 | use DC::UI::MessageWindow; |
|
|
126 | use DC::UI::ChatView; |
140 | use DC::UI::ChatView; |
127 | use DC::MessageDistributor; |
141 | use DC::MessageDistributor; |
128 | use DC::Pod; |
142 | use DC::Pod; |
129 | use DC::MapWidget; |
143 | use DC::MapWidget; |
130 | use DC::Macro; |
144 | use 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 | |
139 | my $MAX_FPS = 60; |
154 | my $MAX_FPS = 60; |
140 | |
155 | |
… | |
… | |
142 | |
157 | |
143 | our $LAST_REFRESH; |
158 | our $LAST_REFRESH; |
144 | our $NOW; |
159 | our $NOW; |
145 | |
160 | |
146 | our $CFG; |
161 | our $CFG; |
147 | our $CONN; |
|
|
148 | our $PROFILE; # current profile |
162 | our $PROFILE; # current profile |
149 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
163 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
150 | |
164 | |
151 | our $WANT_REFRESH; |
165 | our $WANT_REFRESH; |
152 | |
166 | |
… | |
… | |
160 | our $FULLSCREEN; |
174 | our $FULLSCREEN; |
161 | our $FONTSIZE; |
175 | our $FONTSIZE; |
162 | |
176 | |
163 | our $FONT_PROP; |
177 | our $FONT_PROP; |
164 | our $FONT_FIXED; |
178 | our $FONT_FIXED; |
|
|
179 | |
|
|
180 | our $CONN; |
165 | |
181 | |
166 | our $MAP; |
182 | our $MAP; |
167 | our $MAPMAP; |
183 | our $MAPMAP; |
168 | our $MAPWIDGET; |
184 | our $MAPWIDGET; |
169 | our $COMPLETER; |
185 | our $COMPLETER; |
… | |
… | |
211 | our $DEBUG_STATUS; |
227 | our $DEBUG_STATUS; |
212 | |
228 | |
213 | our $INV; |
229 | our $INV; |
214 | our $INVR; |
230 | our $INVR; |
215 | 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 | }; |
216 | |
259 | |
217 | ############################################################################# |
260 | ############################################################################# |
218 | |
261 | |
219 | sub status { |
262 | sub 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 | |
811 | sub stop_game { |
854 | sub 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 (dark)"], |
|
|
904 | [metal => "Metal (light)"], |
|
|
905 | ], |
|
|
906 | tooltip => "Choose the User Interface theme that you like most :)", |
|
|
907 | on_changed => sub { my ($self, $value) = @_; $CFG->{uitheme} = $value; 0 } |
|
|
908 | ); |
851 | |
909 | |
852 | my $vidmode_tooltip = |
910 | my $vidmode_tooltip = |
853 | "<b>Video Mode.</b> The video mode to use for fullscreen (and the window size for windowed operation). " |
911 | "<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>."; |
912 | . "The format is <i>width</i> x <i>height</i> \@ <i>depth-per-channel</i> + <i>alpha-channel</i>."; |
855 | |
913 | |
… | |
… | |
910 | |
968 | |
911 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); |
969 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Compress Textures"); |
912 | $table->add_at (1, $row++, new DC::UI::CheckBox |
970 | $table->add_at (1, $row++, new DC::UI::CheckBox |
913 | state => $CFG->{texture_compression}, |
971 | state => $CFG->{texture_compression}, |
914 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
972 | 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 " |
973 | . "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 " |
974 | . "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.", |
975 | . "forced OpenGL 1.1 mode and when using the Apple renderer.", |
918 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
976 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
919 | ); |
977 | ); |
920 | |
978 | |
921 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); |
979 | $table->add_at (0, $row, new DC::UI::Label align => 1, text => "Fast & Ugly"); |
922 | $table->add_at (1, $row++, new DC::UI::CheckBox |
980 | $table->add_at (1, $row++, new DC::UI::CheckBox |
… | |
… | |
1596 | 1 |
1654 | 1 |
1597 | }, |
1655 | }, |
1598 | ); |
1656 | ); |
1599 | |
1657 | |
1600 | $vbox->add (new DC::UI::FancyFrame |
1658 | $vbox->add (new DC::UI::FancyFrame |
1601 | label => "Registering", |
1659 | label => "How to Play", |
1602 | min_h => 200, |
1660 | min_h => 240, |
1603 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1661 | child => (new DC::UI::Label valign => 0, ellipsise => 0, |
1604 | markup => |
1662 | markup => |
|
|
1663 | "First select a suitable video resolution in the <b>Graphics</b> tab, above.\n\n" |
|
|
1664 | . "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 " |
1665 | . "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.", |
1666 | . "try to log-in. Follow the instructions in the Log tab in the message window.", |
1607 | ), |
1667 | ), |
1608 | ); |
1668 | ); |
1609 | |
1669 | |
1610 | $vbox |
1670 | $vbox |
… | |
… | |
2131 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
2191 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
2132 | ); |
2192 | ); |
2133 | $hb->add (new DC::UI::Button |
2193 | $hb->add (new DC::UI::Button |
2134 | text => "Quit anyway", |
2194 | text => "Quit anyway", |
2135 | expand => 1, |
2195 | expand => 1, |
2136 | on_activate => sub { EV::unloop EV::UNLOOP_ALL }, |
2196 | on_activate => sub { |
|
|
2197 | crash "Quit anyway"; |
|
|
2198 | EV::unloop EV::UNLOOP_ALL; |
|
|
2199 | }, |
2137 | ); |
2200 | ); |
2138 | } |
2201 | } |
2139 | |
2202 | |
2140 | $QUIT_DIALOG->show; |
2203 | $QUIT_DIALOG->show; |
2141 | $QUIT_DIALOG->grab_focus; |
2204 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
2199 | DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE |
2262 | DC::SDL_Init DC::SDL_INIT_AUDIO #| DC::SDL_NOPARACHUTE |
2200 | and die "SDL::Init failed!\n"; |
2263 | and die "SDL::Init failed!\n"; |
2201 | } |
2264 | } |
2202 | |
2265 | |
2203 | sub video_init { |
2266 | sub video_init { |
|
|
2267 | DC::set_theme $CFG->{uitheme}; |
|
|
2268 | |
2204 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2269 | DC::SDL_InitSubSystem DC::SDL_INIT_VIDEO if $SDL_REINIT; |
2205 | $SDL_REINIT = 0; |
2270 | $SDL_REINIT = 0; |
2206 | |
2271 | |
2207 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2272 | @SDL_MODES = DC::SDL_ListModes 8, $CFG->{disable_alpha} ? 0 : 8; |
2208 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2273 | @SDL_MODES = DC::SDL_ListModes 8, 8 unless @SDL_MODES; |
2209 | @SDL_MODES = DC::SDL_ListModes 5, 0 unless @SDL_MODES; |
2274 | @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)"; |
2275 | @SDL_MODES or DC::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
2211 | |
2276 | |
2212 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
2277 | @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES; |
2213 | |
2278 | |
2214 | if (!exists $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) { |
2279 | if (!defined $CFG->{sdl_mode} or $CFG->{sdl_mode} > $#SDL_MODES) { |
2215 | $CFG->{sdl_mode} = 0; |
2280 | $CFG->{sdl_mode} = 0; # lowest resolution by default |
|
|
2281 | |
|
|
2282 | # now choose biggest mode <= 1024x768 |
2216 | for (reverse 0 .. $#SDL_MODES) { |
2283 | for (0 .. $#SDL_MODES) { |
2217 | $CFG->{sdl_mode} = $_ if $SDL_MODES[$_][0] * $SDL_MODES[$_][1] >= 800 * 600; |
2284 | if ($SDL_MODES[$_][0] * $SDL_MODES[$_][1] <= 1024 * 768) { |
|
|
2285 | $CFG->{sdl_mode} = $_; |
|
|
2286 | } |
2218 | } |
2287 | } |
2219 | } |
2288 | } |
2220 | |
2289 | |
2221 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2290 | my ($old_w, $old_h) = ($WIDTH, $HEIGHT); |
2222 | |
2291 | |
… | |
… | |
2301 | x => 0, |
2370 | x => 0, |
2302 | y => $FONTSIZE + 8, |
2371 | y => $FONTSIZE + 8, |
2303 | border_bg => [1, 1, 1, 192/255], |
2372 | border_bg => [1, 1, 1, 192/255], |
2304 | bg => [1, 1, 1, 0], |
2373 | bg => [1, 1, 1, 0], |
2305 | child => ($MAPMAP = new DC::MapWidget::MapMap |
2374 | 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.", |
2375 | tooltip => "<b>Minimap</b>. This will display an overview of the surrounding areas.", |
2307 | ), |
2376 | ), |
2308 | )->show; |
2377 | )->show; |
2309 | |
2378 | |
2310 | $MAPWIDGET = new DC::MapWidget; |
2379 | $MAPWIDGET = new DC::MapWidget; |
2311 | $MAPWIDGET->connect (activate_console => sub { |
2380 | $MAPWIDGET->connect (activate_console => sub { |
… | |
… | |
2410 | $BUTTONBAR->show; |
2479 | $BUTTONBAR->show; |
2411 | $SETUP_DIALOG->show; |
2480 | $SETUP_DIALOG->show; |
2412 | $MESSAGE_WINDOW->show; |
2481 | $MESSAGE_WINDOW->show; |
2413 | } |
2482 | } |
2414 | |
2483 | |
2415 | $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, $#SDL_MODES, 1, 1]); |
2484 | $MODE_SLIDER->set_range ([$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1, 1]); |
2416 | $MODE_SLIDER->emit (changed => $CFG->{sdl_mode}); |
2485 | $MODE_SLIDER->emit (changed => $CFG->{sdl_mode}); |
2417 | |
2486 | |
2418 | $CAVEAT_LABEL->set_text ("None :)"); |
2487 | $CAVEAT_LABEL->set_text ("None :)"); |
2419 | $CAVEAT_LABEL->set_text ("Software Rendering (very slow)") |
2488 | $CAVEAT_LABEL->set_text ("Software Rendering (very slow)") |
2420 | unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL; |
2489 | unless DC::SDL_GL_GetAttribute DC::SDL_GL_ACCELERATED_VISUAL; |
… | |
… | |
2475 | delete $animate_object{$widget}; |
2544 | delete $animate_object{$widget}; |
2476 | } |
2545 | } |
2477 | |
2546 | |
2478 | %SDL_CB = ( |
2547 | %SDL_CB = ( |
2479 | DC::SDL_QUIT => sub { |
2548 | DC::SDL_QUIT => sub { |
|
|
2549 | crash "SDL_QUIT"; |
2480 | EV::unloop EV::UNLOOP_ALL; |
2550 | EV::unloop EV::UNLOOP_ALL; |
2481 | }, |
2551 | }, |
2482 | DC::SDL_VIDEORESIZE => sub { |
2552 | DC::SDL_VIDEORESIZE => sub { |
2483 | }, |
2553 | }, |
2484 | DC::SDL_VIDEOEXPOSE => sub { |
2554 | DC::SDL_VIDEOEXPOSE => sub { |
… | |
… | |
2551 | DC::DB::open_db; |
2621 | DC::DB::open_db; |
2552 | |
2622 | |
2553 | DC::UI::set_layout ($::CFG->{layout}); |
2623 | DC::UI::set_layout ($::CFG->{layout}); |
2554 | |
2624 | |
2555 | my %DEF_CFG = ( |
2625 | my %DEF_CFG = ( |
2556 | sdl_mode => 0, |
2626 | sdl_mode => undef, |
2557 | fullscreen => 1, |
2627 | fullscreen => 1, |
2558 | fast => 0, |
2628 | fast => 0, |
2559 | force_opengl11 => undef, |
2629 | force_opengl11 => undef, |
2560 | disable_alpha => 0, |
2630 | disable_alpha => 0, |
2561 | smooth_movement => 1, |
2631 | smooth_movement => 1, |
… | |
… | |
2584 | inv_sort => "mtime", |
2654 | inv_sort => "mtime", |
2585 | default => "profile", # default profile |
2655 | default => "profile", # default profile |
2586 | show_tips => 1, |
2656 | show_tips => 1, |
2587 | logview_max_par => 1000, |
2657 | logview_max_par => 1000, |
2588 | shift_fire_stop => 0, |
2658 | shift_fire_stop => 0, |
|
|
2659 | uitheme => "wood", |
2589 | ); |
2660 | ); |
2590 | |
2661 | |
2591 | while (my ($k, $v) = each %DEF_CFG) { |
2662 | while (my ($k, $v) = each %DEF_CFG) { |
2592 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2663 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2593 | } |
2664 | } |