--- deliantra/Deliantra-Client/bin/cfplus 2007/07/29 18:22:34 1.189 +++ deliantra/Deliantra-Client/bin/cfplus 2007/07/29 18:56:03 1.190 @@ -164,7 +164,8 @@ our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; our @MUSIC_WANT; our $MUSIC_START; -our $MUSIC_PLAYING; +our $MUSIC_PLAYING_DATA; +our $MUSIC_PLAYING_META; our $MUSIC_PLAYER; our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before our @SOUNDS; # event => file mapping @@ -1819,23 +1820,28 @@ } sub audio_music_start { - my $path = $MUSIC_PLAYING->{path} - or return; + my $meta = $MUSIC_PLAYING_META; - CFPlus::DB::prefetch_file $path, 1024_000, sub { + CFPlus::DB::get res_data => $meta->{name}, sub { return unless $SDL_MIXER; # music might have changed... - $path eq $MUSIC_PLAYING->{path} + $meta eq $MUSIC_PLAYING_META or return &audio_music_start (); - my $rwops = new_from_file CFPlus::RW $path; - $MUSIC_PLAYER = new CFPlus::MixMusic $rwops; + $MUSIC_PLAYING_DATA = \$_[0]; + + my $rwops = $meta->{path} + ? new_from_file CFPlus::RW $meta->{path} + : new CFPlus::RW $$MUSIC_PLAYING_DATA; + + $MUSIC_PLAYER = new CFPlus::MixMusic $rwops + or ((warn CFPlus::Mix_GetError), return); # pretty fatal error my $NOW = time; - if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { - my $pos = $MUSIC_PLAYING->{stop_pos}; + if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { + my $pos = $MUSIC_PLAYING_META->{stop_pos}; $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); $MUSIC_START = time - $pos; } else { @@ -1843,8 +1849,8 @@ $MUSIC_START = time; } - delete $MUSIC_PLAYING->{stop_time}; - delete $MUSIC_PLAYING->{stop_pos}; + delete $MUSIC_PLAYING_META->{stop_time}; + delete $MUSIC_PLAYING_META->{stop_pos}; } } @@ -1856,14 +1862,14 @@ @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; # if the currently playing song is acceptable, let it continue - return if $MUSIC_PLAYING - && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; + return if $MUSIC_PLAYING_META + && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT; my $NOW = time; - if ($MUSIC_PLAYING) { - $MUSIC_PLAYING->{stop_time} = $NOW; - $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; + if ($MUSIC_PLAYING_META) { + $MUSIC_PLAYING_META->{stop_time} = $NOW; + $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START; CFPlus::MixMusic::fade_out 1000; } else { # sort by stop time, oldest first @@ -1871,7 +1877,7 @@ # if the most recently-played piece played very recently, # resume it, else choose the oldest piece for rotation. - $MUSIC_PLAYING = + $MUSIC_PLAYING_META = $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME ? $MUSIC_WANT[-1] : $MUSIC_WANT[0]; @@ -1881,8 +1887,9 @@ } sub audio_music_finished { - $MUSIC_PLAYING = undef; undef $MUSIC_PLAYER; + undef $MUSIC_PLAYING_META; + undef $MUSIC_PLAYING_DATA; audio_music_changed; }