ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/cfplus
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/cfplus (file contents):
Revision 1.167 by root, Fri Jul 13 05:31:32 2007 UTC vs.
Revision 1.171 by root, Sun Jul 15 21:42:02 2007 UTC

161our %SDL_CB; 161our %SDL_CB;
162 162
163our $SDL_MIXER; 163our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT; 165our @MUSIC_WANT;
166our $MUSIC_START;
166our $MUSIC_PLAYING; 167our $MUSIC_PLAYING;
167our $MUSIC_PLAYER; 168our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
168our @SOUNDS; # event => file mapping 170our @SOUNDS; # event => file mapping
169our %AUDIO_CHUNKS; # audio files 171our %AUDIO_CHUNKS; # audio files
170 172
171our $ALT_ENTER_MESSAGE; 173our $ALT_ENTER_MESSAGE;
172our $STATUSBOX; 174our $STATUSBOX;
1278 1280
1279 $window 1281 $window
1280} 1282}
1281 1283
1282sub autopickup_setup { 1284sub autopickup_setup {
1285 my $r = new CFPlus::UI::ScrolledWindow (
1286 expand => 1,
1287 scroll_y => 1
1288 );
1283 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 );
1284 1293
1285 for ( 1294 for (
1286 ["General", 0, 0, 1295 ["General", 0, 0,
1287 ["Enable autopickup" => PICKUP_NEWMODE, \$PICKUP_ENABLE], 1296 ["Enable autopickup" => PICKUP_NEWMODE, \$PICKUP_ENABLE],
1288 ["Inhibit autopickup" => PICKUP_INHIBIT], 1297 ["Inhibit autopickup" => PICKUP_INHIBIT],
1372 $::CONN->send_command ("pickup $::CFG->{pickup}") 1381 $::CONN->send_command ("pickup $::CFG->{pickup}")
1373 if defined $::CONN; 1382 if defined $::CONN;
1374 0 1383 0
1375 }); 1384 });
1376 1385
1377 $table 1386 $r
1378} 1387}
1379 1388
1380my %SORT_ORDER = ( 1389my %SORT_ORDER = (
1381 type => undef, 1390 type => undef,
1382 mtime => sub { 1391 mtime => sub {
2017} 2026}
2018 2027
2019sub audio_music_set { 2028sub audio_music_set {
2020 my ($songs) = @_; 2029 my ($songs) = @_;
2021 2030
2022 my $count = @$songs; 2031 my @want =
2023 my @meta; 2032 grep $_,
2033 map $CONN->{music_meta}{$_},
2034 @$songs;
2024 2035
2025 for my $name (@$songs) { 2036 if (@want) {
2026 CFPlus::DB::get "res-metadata" => $name, sub {
2027 my ($data) = @_;
2028
2029 if ($data) {
2030 $data = JSON::XS->new->utf8->decode ($data);
2031 $data->{path} = CFPlus::DB::path_of $name;
2032 push @meta, $data;
2033 }
2034
2035 unless (--$count) {
2036 if (@meta) {
2037 @MUSIC_WANT = @meta; 2037 @MUSIC_WANT = @want;
2038 &audio_music_changed (); 2038 &audio_music_changed ();
2039 } 2039 }
2040 } 2040}
2041
2042sub 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;
2041 }; 2062 }
2063
2064 delete $MUSIC_PLAYING->{stop_time};
2065 delete $MUSIC_PLAYING->{stop_pos};
2042 } 2066 }
2043} 2067}
2044 2068
2045sub audio_music_changed { 2069sub audio_music_changed {
2046 return unless $CFG->{bgm_enable}; 2070 return unless $CFG->{bgm_enable};
2050 2074
2051 # if the currently playing song is acceptable, let it continue 2075 # if the currently playing song is acceptable, let it continue
2052 return if $MUSIC_PLAYING 2076 return if $MUSIC_PLAYING
2053 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; 2077 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT;
2054 2078
2079 my $NOW = time;
2080
2055 if ($MUSIC_PLAYING) { 2081 if ($MUSIC_PLAYING) {
2082 $MUSIC_PLAYING->{stop_time} = $NOW;
2083 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START;
2056 CFPlus::MixMusic::fade_out 1000; 2084 CFPlus::MixMusic::fade_out 1000;
2057 } else { 2085 } else {
2058 my $music = $MUSIC_WANT [rand @MUSIC_WANT]; 2086 # sort by stop time, oldest first
2087 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
2059 2088
2089 # if the most recently-played piece played very recently,
2090 # resume it, else choose the oldest piece for rotation.
2060 $MUSIC_PLAYING = $music; 2091 $MUSIC_PLAYING =
2092 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
2093 ? $MUSIC_WANT[-1]
2094 : $MUSIC_WANT[0];
2061 2095
2062 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $music->{path}; 2096 audio_music_start;
2063 $MUSIC_PLAYER->play (0);
2064 } 2097 }
2065} 2098}
2066 2099
2067sub audio_music_finished { 2100sub audio_music_finished {
2068 $MUSIC_PLAYING = undef; 2101 $MUSIC_PLAYING = undef;
2136 2169
2137my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { 2170my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub {
2138 $NOW = time; 2171 $NOW = time;
2139 2172
2140 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 2173 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
2141 for CFPlus::SDL_PollEvent; 2174 for CFPlus::poll_events;
2142 2175
2143 if (%animate_object) { 2176 if (%animate_object) {
2144 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 2177 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
2145 $WANT_REFRESH++; 2178 $WANT_REFRESH++;
2146 } 2179 }
2180 CFPlus::SDL_VIDEOEXPOSE => sub { 2213 CFPlus::SDL_VIDEOEXPOSE => sub {
2181 CFPlus::UI::full_refresh; 2214 CFPlus::UI::full_refresh;
2182 }, 2215 },
2183 CFPlus::SDL_ACTIVEEVENT => sub { 2216 CFPlus::SDL_ACTIVEEVENT => sub {
2184# not useful, as APPACTIVE include sonly iconified state, not unmapped 2217# not useful, as APPACTIVE include sonly iconified state, not unmapped
2185# 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#
2186# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE; 2220# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE;
2187# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS; 2221# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS;
2188# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS; 2222# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS;
2189 }, 2223 },
2190 CFPlus::SDL_KEYDOWN => sub { 2224 CFPlus::SDL_KEYDOWN => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines