… | |
… | |
159 | |
159 | |
160 | our $SDL_ACTIVE; |
160 | our $SDL_ACTIVE; |
161 | our %SDL_CB; |
161 | our %SDL_CB; |
162 | |
162 | |
163 | our $SDL_MIXER; |
163 | our $SDL_MIXER; |
|
|
164 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
|
|
165 | our @MUSIC_WANT; |
|
|
166 | our $MUSIC_START; |
|
|
167 | our $MUSIC_PLAYING; |
|
|
168 | our $MUSIC_PLAYER; |
|
|
169 | our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before |
164 | our @SOUNDS; # event => file mapping |
170 | our @SOUNDS; # event => file mapping |
165 | our %AUDIO_CHUNKS; # audio files |
171 | our %AUDIO_CHUNKS; # audio files |
166 | |
172 | |
167 | our $ALT_ENTER_MESSAGE; |
173 | our $ALT_ENTER_MESSAGE; |
168 | our $STATUSBOX; |
174 | our $STATUSBOX; |
… | |
… | |
445 | |
451 | |
446 | my ($host, $port) = split /:/, $PROFILE->{host}; |
452 | my ($host, $port) = split /:/, $PROFILE->{host}; |
447 | |
453 | |
448 | $MAP = new CFPlus::Map; |
454 | $MAP = new CFPlus::Map; |
449 | |
455 | |
450 | warn "connecting...\n";#d# |
|
|
451 | $CONN = eval { |
456 | $CONN = eval { |
452 | new CFPlus::Protocol |
457 | new CFPlus::Protocol |
453 | host => $host, |
458 | host => $host, |
454 | port => $port || 13327, |
459 | port => $port || 13327, |
455 | user => $PROFILE->{user}, |
460 | user => $PROFILE->{user}, |
… | |
… | |
480 | or return; |
485 | or return; |
481 | |
486 | |
482 | $chunk->play; |
487 | $chunk->play; |
483 | }, |
488 | }, |
484 | }; |
489 | }; |
485 | warn "connected<$CONN>\n";#d# |
|
|
486 | |
490 | |
487 | if ($CONN) { |
491 | if ($CONN) { |
488 | CFPlus::lowdelay fileno $CONN->{fh}; |
492 | CFPlus::lowdelay fileno $CONN->{fh}; |
489 | |
493 | |
490 | status "login successful"; |
494 | status "login successful"; |
… | |
… | |
499 | $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); |
503 | $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); |
500 | $SETUP_DIALOG->show; |
504 | $SETUP_DIALOG->show; |
501 | $PL_WINDOW->hide; |
505 | $PL_WINDOW->hide; |
502 | $SPELL_LIST->clear_spells; |
506 | $SPELL_LIST->clear_spells; |
503 | $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); |
507 | $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); |
|
|
508 | |
|
|
509 | &audio_music_set ([]); |
504 | |
510 | |
505 | return unless $CONN; |
511 | return unless $CONN; |
506 | |
512 | |
507 | status "connection closed"; |
513 | status "connection closed"; |
508 | |
514 | |
… | |
… | |
1274 | |
1280 | |
1275 | $window |
1281 | $window |
1276 | } |
1282 | } |
1277 | |
1283 | |
1278 | sub autopickup_setup { |
1284 | sub autopickup_setup { |
|
|
1285 | my $r = new CFPlus::UI::ScrolledWindow ( |
|
|
1286 | expand => 1, |
|
|
1287 | scroll_y => 1 |
|
|
1288 | ); |
1279 | my $table = new CFPlus::UI::Table; |
1289 | $r->add (my $table = new CFPlus::UI::Table |
|
|
1290 | row_expand => [0], |
|
|
1291 | col_expand => [0, 1, 0, 1], |
|
|
1292 | ); |
1280 | |
1293 | |
1281 | for ( |
1294 | for ( |
1282 | ["General", 0, 0, |
1295 | ["General", 0, 0, |
1283 | ["Enable autopickup" => PICKUP_NEWMODE, \$PICKUP_ENABLE], |
1296 | ["Enable autopickup" => PICKUP_NEWMODE, \$PICKUP_ENABLE], |
1284 | ["Inhibit autopickup" => PICKUP_INHIBIT], |
1297 | ["Inhibit autopickup" => PICKUP_INHIBIT], |
… | |
… | |
1368 | $::CONN->send_command ("pickup $::CFG->{pickup}") |
1381 | $::CONN->send_command ("pickup $::CFG->{pickup}") |
1369 | if defined $::CONN; |
1382 | if defined $::CONN; |
1370 | 0 |
1383 | 0 |
1371 | }); |
1384 | }); |
1372 | |
1385 | |
1373 | $table |
1386 | $r |
1374 | } |
1387 | } |
1375 | |
1388 | |
1376 | my %SORT_ORDER = ( |
1389 | my %SORT_ORDER = ( |
1377 | type => undef, |
1390 | type => undef, |
1378 | mtime => sub { |
1391 | mtime => sub { |
… | |
… | |
2004 | CFPlus::OpenGL::shutdown; |
2017 | CFPlus::OpenGL::shutdown; |
2005 | |
2018 | |
2006 | undef $SDL_ACTIVE; |
2019 | undef $SDL_ACTIVE; |
2007 | } |
2020 | } |
2008 | |
2021 | |
2009 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
|
|
2010 | my $bgmusic;#TODO#hack#d# |
|
|
2011 | |
|
|
2012 | sub audio_channel_finished { |
2022 | sub audio_channel_finished { |
2013 | my ($channel) = @_; |
2023 | my ($channel) = @_; |
2014 | |
2024 | |
2015 | #warn "channel $channel finished\n";#d# |
2025 | #warn "channel $channel finished\n";#d# |
2016 | } |
2026 | } |
2017 | |
2027 | |
|
|
2028 | sub audio_music_set { |
|
|
2029 | my ($songs) = @_; |
|
|
2030 | |
|
|
2031 | my @want = |
|
|
2032 | grep $_, |
|
|
2033 | map $CONN->{music_meta}{$_}, |
|
|
2034 | @$songs; |
|
|
2035 | |
|
|
2036 | if (@want) { |
|
|
2037 | @MUSIC_WANT = @want; |
|
|
2038 | &audio_music_changed (); |
|
|
2039 | } |
|
|
2040 | } |
|
|
2041 | |
|
|
2042 | sub audio_music_start { |
|
|
2043 | my $path = $MUSIC_PLAYING->{path} |
|
|
2044 | or return; |
|
|
2045 | |
|
|
2046 | CFPlus::DB::prefetch_file $path, 1024_000, sub { |
|
|
2047 | # music might have changed... |
|
|
2048 | $path eq $MUSIC_PLAYING->{path} |
|
|
2049 | or return &audio_music_start (); |
|
|
2050 | |
|
|
2051 | $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path; |
|
|
2052 | |
|
|
2053 | my $NOW = time; |
|
|
2054 | |
|
|
2055 | if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { |
|
|
2056 | my $pos = $MUSIC_PLAYING->{stop_pos}; |
|
|
2057 | $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); |
|
|
2058 | $MUSIC_START = time - $pos; |
|
|
2059 | } else { |
|
|
2060 | $MUSIC_PLAYER->play (0); |
|
|
2061 | $MUSIC_START = time; |
|
|
2062 | } |
|
|
2063 | |
|
|
2064 | delete $MUSIC_PLAYING->{stop_time}; |
|
|
2065 | delete $MUSIC_PLAYING->{stop_pos}; |
|
|
2066 | } |
|
|
2067 | } |
|
|
2068 | |
|
|
2069 | sub audio_music_changed { |
|
|
2070 | return unless $CFG->{bgm_enable}; |
|
|
2071 | |
|
|
2072 | # default MUSIC_WANT == MUSIC_DEFAULT |
|
|
2073 | @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; |
|
|
2074 | |
|
|
2075 | # if the currently playing song is acceptable, let it continue |
|
|
2076 | return if $MUSIC_PLAYING |
|
|
2077 | && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; |
|
|
2078 | |
|
|
2079 | my $NOW = time; |
|
|
2080 | |
|
|
2081 | if ($MUSIC_PLAYING) { |
|
|
2082 | $MUSIC_PLAYING->{stop_time} = $NOW; |
|
|
2083 | $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; |
|
|
2084 | CFPlus::MixMusic::fade_out 1000; |
|
|
2085 | } else { |
|
|
2086 | # sort by stop time, oldest first |
|
|
2087 | @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; |
|
|
2088 | |
|
|
2089 | # if the most recently-played piece played very recently, |
|
|
2090 | # resume it, else choose the oldest piece for rotation. |
|
|
2091 | $MUSIC_PLAYING = |
|
|
2092 | $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME |
|
|
2093 | ? $MUSIC_WANT[-1] |
|
|
2094 | : $MUSIC_WANT[0]; |
|
|
2095 | |
|
|
2096 | audio_music_start; |
|
|
2097 | } |
|
|
2098 | } |
|
|
2099 | |
2018 | sub audio_music_finished { |
2100 | sub audio_music_finished { |
2019 | return unless $CFG->{bgm_enable}; |
2101 | $MUSIC_PLAYING = undef; |
|
|
2102 | undef $MUSIC_PLAYER; |
2020 | |
2103 | |
2021 | # TODO: hack, do play loop and mood music |
2104 | audio_music_changed; |
2022 | $bgmusic = new_from_file CFPlus::MixMusic CFPlus::find_rcfile "music/$bgmusic[0]"; |
|
|
2023 | $bgmusic->play (0); |
|
|
2024 | |
|
|
2025 | push @bgmusic, shift @bgmusic; |
|
|
2026 | } |
2105 | } |
2027 | |
2106 | |
2028 | sub audio_init { |
2107 | sub audio_init { |
2029 | if ($CFG->{audio_enable}) { |
2108 | if ($CFG->{audio_enable}) { |
2030 | if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { |
2109 | if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { |
… | |
… | |
2090 | |
2169 | |
2091 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2170 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2092 | $NOW = time; |
2171 | $NOW = time; |
2093 | |
2172 | |
2094 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2173 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2095 | for CFPlus::SDL_PollEvent; |
2174 | for CFPlus::poll_events; |
2096 | |
2175 | |
2097 | if (%animate_object) { |
2176 | if (%animate_object) { |
2098 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2177 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2099 | $WANT_REFRESH++; |
2178 | $WANT_REFRESH++; |
2100 | } |
2179 | } |
… | |
… | |
2134 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2213 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2135 | CFPlus::UI::full_refresh; |
2214 | CFPlus::UI::full_refresh; |
2136 | }, |
2215 | }, |
2137 | CFPlus::SDL_ACTIVEEVENT => sub { |
2216 | CFPlus::SDL_ACTIVEEVENT => sub { |
2138 | # not useful, as APPACTIVE include sonly iconified state, not unmapped |
2217 | # not useful, as APPACTIVE include sonly iconified state, not unmapped |
2139 | # printf "active %x %x\n", $_[0]{gain}, $_[0]{state};#d# |
2218 | # printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, CFPlus::SDL_GetAppState;#d# |
|
|
2219 | # printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d# |
2140 | # printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; |
2220 | # printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; |
2141 | # printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; |
2221 | # printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; |
2142 | # printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; |
2222 | # printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; |
2143 | }, |
2223 | }, |
2144 | CFPlus::SDL_KEYDOWN => sub { |
2224 | CFPlus::SDL_KEYDOWN => sub { |