… | |
… | |
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 |
72 | unshift @INC, $ENV{PAR_TEMP} |
72 | unshift @INC, $ENV{PAR_TEMP} |
73 | if %PAR::LibCache; |
73 | if %PAR::LibCache; |
74 | |
74 | |
75 | use Time::HiRes 'time'; |
75 | use Time::HiRes 'time'; |
76 | use Event; |
76 | use EV; |
77 | use List::Util qw(max min); |
77 | use List::Util qw(max min); |
78 | |
78 | |
79 | use Crossfire; |
79 | use Crossfire; |
80 | use Crossfire::Protocol::Constants; |
80 | use Crossfire::Protocol::Constants; |
81 | |
81 | |
… | |
… | |
97 | use CFPlus::Macro; |
97 | use 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 | |
107 | my $MAX_FPS = 60; |
106 | my $MAX_FPS = 60; |
108 | my $MIN_FPS = 5; # unused as of yet |
107 | my $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 | |
279 | sub audio_music_set_meta { |
278 | sub 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 |
… | |
… | |
994 | c_colspan => 2, expand => 1, |
990 | c_colspan => 2, expand => 1, |
995 | value => $CFG->{audio_hw_channels}, |
991 | value => $CFG->{audio_hw_channels}, |
996 | options => [ |
992 | options => [ |
997 | [0, "default" , "Use System Default"], |
993 | [0, "default" , "Use System Default"], |
998 | [1, "Mono" , "Mono (single channel, low quality)"], |
994 | [1, "Mono" , "Mono (single channel, low quality)"], |
999 | [2, "Stereo" , "Stereo (dual channe, standard quality)"], |
995 | [2, "Stereo" , "Stereo (dual channel, standard quality)"], |
1000 | [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"], |
996 | [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"], |
1001 | [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"], |
997 | [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"], |
1002 | ], |
998 | ], |
1003 | tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", |
999 | tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", |
1004 | on_changed => sub { |
1000 | on_changed => sub { |
… | |
… | |
1521 | $CFG->{profile}{default}{host} = $value; |
1517 | $CFG->{profile}{default}{host} = $value; |
1522 | 1 |
1518 | 1 |
1523 | } |
1519 | } |
1524 | ); |
1520 | ); |
1525 | |
1521 | |
|
|
1522 | if (0) { #d# disabled |
1526 | $vbox->add (new CFPlus::UI::Button |
1523 | $vbox->add (new CFPlus::UI::Button |
1527 | expand => 1, |
1524 | expand => 1, |
1528 | text => "Server List", |
1525 | text => "Server List", |
1529 | other => $METASERVER, |
1526 | other => $METASERVER, |
1530 | tooltip => "Show a list of available crossfire servers", |
1527 | tooltip => "Show a list of available crossfire servers", |
1531 | on_activate => sub { $METASERVER->toggle_visibility; 0 }, |
1528 | on_activate => sub { $METASERVER->toggle_visibility; 0 }, |
1532 | on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 }, |
1529 | on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 }, |
1533 | ); |
1530 | ); |
|
|
1531 | }#d# |
1534 | } |
1532 | } |
1535 | |
1533 | |
1536 | $table->add_at (0, ++$row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); |
1534 | $table->add_at (0, ++$row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); |
1537 | $table->add_at (1, $row, new CFPlus::UI::Slider |
1535 | $table->add_at (1, $row, new CFPlus::UI::Slider |
1538 | force_w => 100, |
1536 | force_w => 100, |
… | |
… | |
2013 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
2011 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
2014 | ); |
2012 | ); |
2015 | $hb->add (new CFPlus::UI::Button |
2013 | $hb->add (new CFPlus::UI::Button |
2016 | text => "Quit anyway", |
2014 | text => "Quit anyway", |
2017 | expand => 1, |
2015 | expand => 1, |
2018 | on_activate => sub { Event::unloop_all }, |
2016 | on_activate => sub { EV::unloop EV::UNLOOP_ALL }, |
2019 | ); |
2017 | ); |
2020 | } |
2018 | } |
2021 | |
2019 | |
2022 | $QUIT_DIALOG->show; |
2020 | $QUIT_DIALOG->show; |
2023 | $QUIT_DIALOG->grab_focus; |
2021 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
2237 | tooltip => "Terminates the program", |
2235 | tooltip => "Terminates the program", |
2238 | on_activate => sub { |
2236 | on_activate => sub { |
2239 | if ($CONN) { |
2237 | if ($CONN) { |
2240 | open_quit_dialog; |
2238 | open_quit_dialog; |
2241 | } else { |
2239 | } else { |
2242 | Event::unloop_all; |
2240 | EV::unloop EV::UNLOOP_ALL; |
2243 | } |
2241 | } |
2244 | 0 |
2242 | 0 |
2245 | }, |
2243 | }, |
2246 | ); |
2244 | ); |
2247 | |
2245 | |
… | |
… | |
2263 | my $animate_timer; |
2261 | my $animate_timer; |
2264 | |
2262 | |
2265 | my $fps = 9; |
2263 | my $fps = 9; |
2266 | |
2264 | |
2267 | sub force_refresh { |
2265 | sub force_refresh { |
|
|
2266 | $WANT_REFRESH->stop; |
|
|
2267 | |
2268 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2268 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2269 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2269 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2270 | debug sprintf "%3.2f", $fps; |
2270 | debug sprintf "%3.2f", $fps; |
2271 | } |
2271 | } |
2272 | |
2272 | |
2273 | $CFPlus::UI::ROOT->draw; |
2273 | $CFPlus::UI::ROOT->draw; |
2274 | CFPlus::SDL_GL_SwapBuffers; |
2274 | CFPlus::SDL_GL_SwapBuffers; |
2275 | $LAST_REFRESH = $NOW; |
2275 | $LAST_REFRESH = $NOW; |
2276 | $WANT_REFRESH->stop; |
|
|
2277 | } |
2276 | } |
2278 | |
2277 | |
2279 | $WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); |
2278 | $WANT_REFRESH = EV::idle_ns \&force_refresh; |
2280 | |
2279 | |
2281 | my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { |
2280 | my $input = EV::timer 0, 1/60, sub { |
2282 | $NOW = time; |
2281 | $NOW = time; |
2283 | |
2282 | |
2284 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2283 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2285 | for CFPlus::poll_events; |
2284 | for CFPlus::poll_events; |
2286 | |
2285 | |
2287 | if (%animate_object) { |
2286 | if (%animate_object) { |
2288 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2287 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2289 | $WANT_REFRESH->start; |
2288 | $WANT_REFRESH->start; |
2290 | } |
2289 | } |
2291 | }); |
2290 | }; |
2292 | |
2291 | |
2293 | sub animation_start { |
2292 | sub animation_start { |
2294 | my ($widget) = @_; |
2293 | my ($widget) = @_; |
2295 | $animate_object{$widget} = $widget; |
2294 | $animate_object{$widget} = $widget; |
2296 | } |
2295 | } |
… | |
… | |
2300 | delete $animate_object{$widget}; |
2299 | delete $animate_object{$widget}; |
2301 | } |
2300 | } |
2302 | |
2301 | |
2303 | %SDL_CB = ( |
2302 | %SDL_CB = ( |
2304 | CFPlus::SDL_QUIT => sub { |
2303 | CFPlus::SDL_QUIT => sub { |
2305 | Event::unloop_all; |
2304 | EV::unloop EV::UNLOOP_ALL; |
2306 | }, |
2305 | }, |
2307 | CFPlus::SDL_VIDEORESIZE => sub { |
2306 | CFPlus::SDL_VIDEORESIZE => sub { |
2308 | }, |
2307 | }, |
2309 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2308 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2310 | CFPlus::UI::full_refresh; |
2309 | CFPlus::UI::full_refresh; |
… | |
… | |
2451 | audio_init; |
2450 | audio_init; |
2452 | } |
2451 | } |
2453 | |
2452 | |
2454 | show_tip_of_the_day if $CFG->{show_tips}; |
2453 | show_tip_of_the_day if $CFG->{show_tips}; |
2455 | |
2454 | |
2456 | Event->idle (cb => sub { |
2455 | our $STARTUP_CANCEL = EV::idle sub { |
2457 | $_[0]->w->cancel; |
2456 | undef $::STARTUP_CANCEL; |
2458 | $startup_done->(); |
2457 | $startup_done->(); |
2459 | }); |
2458 | }; |
2460 | |
2459 | |
2461 | Event::loop; |
2460 | EV::loop; |
2462 | |
2461 | |
2463 | #video_shutdown; |
2462 | #video_shutdown; |
2464 | #audio_shutdown; |
2463 | #audio_shutdown; |
2465 | CFPlus::SDL_Quit; |
2464 | CFPlus::SDL_Quit; |
2466 | CFPlus::DB::Server::stop; |
2465 | CFPlus::DB::Server::stop; |