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.3 by root, Sat Nov 3 12:08:44 2007 UTC vs.
Revision 1.4 by root, Mon Nov 12 23:25:37 2007 UTC

71# need to do it again because that pile of garbage called PAR nukes it before main 71# need to do it again because that pile of garbage called PAR nukes it before main
72unshift @INC, $ENV{PAR_TEMP} 72unshift @INC, $ENV{PAR_TEMP}
73 if %PAR::LibCache; 73 if %PAR::LibCache;
74 74
75use Time::HiRes 'time'; 75use Time::HiRes 'time';
76use Event; 76use EV;
77use List::Util qw(max min); 77use List::Util qw(max min);
78 78
79use Crossfire; 79use Crossfire;
80use Crossfire::Protocol::Constants; 80use Crossfire::Protocol::Constants;
81 81
97use CFPlus::Macro; 97use CFPlus::Macro;
98 98
99$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 99$SIG{QUIT} = sub { Carp::cluck "QUIT" };
100$SIG{PIPE} = 'IGNORE'; 100$SIG{PIPE} = 'IGNORE';
101 101
102$Event::Eval = 1;
103$Event::DIED = sub { 102$EV::DIED = sub {
104 CFPlus::fatal Carp::longmess $_[1] 103 CFPlus::fatal Carp::longmess $@;
105}; 104};
106 105
107my $MAX_FPS = 60; 106my $MAX_FPS = 60;
108my $MIN_FPS = 5; # unused as of yet 107my $MIN_FPS = 5; # unused as of yet
109 108
223 222
224 $AUDIO_PLAY{$face} 223 $AUDIO_PLAY{$face}
225 or return; 224 or return;
226 225
227 if (my $chunk = $AUDIO_CHUNK{$face}) { 226 if (my $chunk = $AUDIO_CHUNK{$face}) {
228 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { 227 for (grep $_->[0] >= EV::now, @{(delete $AUDIO_PLAY{$face}) || []}) {
229 my (undef, $dx, $dy, $vol) = @$_; 228 my (undef, $dx, $dy, $vol) = @$_;
230 229
231 my $channel = CFPlus::Channel::find; 230 my $channel = CFPlus::Channel::find;
232 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); 231 $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
233 $channel->set_position_r ($dx, $dy, 20); 232 $channel->set_position_r ($dx, $dy, 20);
269 or return; 268 or return;
270 $CFG->{effects_enable} 269 $CFG->{effects_enable}
271 or return; 270 or return;
272 271
273 my $queue = $AUDIO_PLAY{$face} ||= []; 272 my $queue = $AUDIO_PLAY{$face} ||= [];
274 push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events 273 push @$queue, [EV::now + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
275 audio_sound_push $face 274 audio_sound_push $face
276 unless @$queue > 1; 275 unless @$queue > 1;
277} 276}
278 277
279sub audio_music_set_meta { 278sub audio_music_set_meta {
462 461
463 # FIXME: a very ugly hack to wait for stat update #d# 462 # FIXME: a very ugly hack to wait for stat update #d#
464 if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) { 463 if ($prompt =~ /roll new stats/ and not $conn->{stat_change_with}) {
465 unless ($QUERY_TIMER) { 464 unless ($QUERY_TIMER) {
466 $QUERY_TIMER = 465 $QUERY_TIMER =
467 Event->timer ( 466 EV::timer 1, 0, sub {
468 after => 1,
469 cb => sub {
470 server_query ($conn, $flags, $prompt, 1); 467 server_query ($conn, $flags, $prompt, 1);
471 $QUERY_TIMER = undef 468 $QUERY_TIMER = undef
472 }
473 ); 469 };
474 return; 470 return;
475 } 471 }
476 } 472 }
477 473
478 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel 474 $conn->{query_dialog} = my $dialog = new CFPlus::UI::Toplevel
2013 on_activate => sub { $QUIT_DIALOG->hide; 0 }, 2009 on_activate => sub { $QUIT_DIALOG->hide; 0 },
2014 ); 2010 );
2015 $hb->add (new CFPlus::UI::Button 2011 $hb->add (new CFPlus::UI::Button
2016 text => "Quit anyway", 2012 text => "Quit anyway",
2017 expand => 1, 2013 expand => 1,
2018 on_activate => sub { Event::unloop_all }, 2014 on_activate => sub { EV::unloop EV::UNLOOP_ALL },
2019 ); 2015 );
2020 } 2016 }
2021 2017
2022 $QUIT_DIALOG->show; 2018 $QUIT_DIALOG->show;
2023 $QUIT_DIALOG->grab_focus; 2019 $QUIT_DIALOG->grab_focus;
2237 tooltip => "Terminates the program", 2233 tooltip => "Terminates the program",
2238 on_activate => sub { 2234 on_activate => sub {
2239 if ($CONN) { 2235 if ($CONN) {
2240 open_quit_dialog; 2236 open_quit_dialog;
2241 } else { 2237 } else {
2242 Event::unloop_all; 2238 EV::unloop EV::UNLOOP_ALL;
2243 } 2239 }
2244 0 2240 0
2245 }, 2241 },
2246 ); 2242 );
2247 2243
2263my $animate_timer; 2259my $animate_timer;
2264 2260
2265my $fps = 9; 2261my $fps = 9;
2266 2262
2267sub force_refresh { 2263sub force_refresh {
2264 $WANT_REFRESH->stop;
2265
2268 if ($ENV{CFPLUS_DEBUG} & 4) { 2266 if ($ENV{CFPLUS_DEBUG} & 4) {
2269 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; 2267 $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
2270 debug sprintf "%3.2f", $fps; 2268 debug sprintf "%3.2f", $fps;
2271 } 2269 }
2272 2270
2273 $CFPlus::UI::ROOT->draw; 2271 $CFPlus::UI::ROOT->draw;
2274 CFPlus::SDL_GL_SwapBuffers; 2272 CFPlus::SDL_GL_SwapBuffers;
2275 $LAST_REFRESH = $NOW; 2273 $LAST_REFRESH = $NOW;
2276 $WANT_REFRESH->stop;
2277} 2274}
2278 2275
2279$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); 2276$WANT_REFRESH = EV::idle_ns \&force_refresh;
2280 2277
2281my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { 2278my $input = EV::timer 0, 1/60, sub {
2282 $NOW = time; 2279 $NOW = time;
2283 2280
2284 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2281 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2285 for CFPlus::poll_events; 2282 for CFPlus::poll_events;
2286 2283
2287 if (%animate_object) { 2284 if (%animate_object) {
2288 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2285 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2289 $WANT_REFRESH->start; 2286 $WANT_REFRESH->start;
2290 } 2287 }
2291}); 2288};
2292 2289
2293sub animation_start { 2290sub animation_start {
2294 my ($widget) = @_; 2291 my ($widget) = @_;
2295 $animate_object{$widget} = $widget; 2292 $animate_object{$widget} = $widget;
2296} 2293}
2300 delete $animate_object{$widget}; 2297 delete $animate_object{$widget};
2301} 2298}
2302 2299
2303%SDL_CB = ( 2300%SDL_CB = (
2304 CFPlus::SDL_QUIT => sub { 2301 CFPlus::SDL_QUIT => sub {
2305 Event::unloop_all; 2302 EV::unloop EV::UNLOOP_ALL;
2306 }, 2303 },
2307 CFPlus::SDL_VIDEORESIZE => sub { 2304 CFPlus::SDL_VIDEORESIZE => sub {
2308 }, 2305 },
2309 CFPlus::SDL_VIDEOEXPOSE => sub { 2306 CFPlus::SDL_VIDEOEXPOSE => sub {
2310 CFPlus::UI::full_refresh; 2307 CFPlus::UI::full_refresh;
2451 audio_init; 2448 audio_init;
2452} 2449}
2453 2450
2454show_tip_of_the_day if $CFG->{show_tips}; 2451show_tip_of_the_day if $CFG->{show_tips};
2455 2452
2456Event->idle (cb => sub { 2453our $STARTUP_CANCEL = EV::idle sub {
2457 $_[0]->w->cancel; 2454 undef $::STARTUP_CANCEL;
2458 $startup_done->(); 2455 $startup_done->();
2459}); 2456};
2460 2457
2461Event::loop; 2458EV::loop;
2462 2459
2463#video_shutdown; 2460#video_shutdown;
2464#audio_shutdown; 2461#audio_shutdown;
2465CFPlus::SDL_Quit; 2462CFPlus::SDL_Quit;
2466CFPlus::DB::Server::stop; 2463CFPlus::DB::Server::stop;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines