… | |
… | |
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 " |
… | |
… | |
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 { |