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.189 by root, Sun Jul 29 18:22:34 2007 UTC vs.
Revision 1.190 by root, Sun Jul 29 18:56:03 2007 UTC

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_START;
167our $MUSIC_PLAYING; 167our $MUSIC_PLAYING_DATA;
168our $MUSIC_PLAYING_META;
168our $MUSIC_PLAYER; 169our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 170our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
170our @SOUNDS; # event => file mapping 171our @SOUNDS; # event => file mapping
171our %AUDIO_CHUNKS; # audio files 172our %AUDIO_CHUNKS; # audio files
172 173
1817 &audio_music_changed (); 1818 &audio_music_changed ();
1818 } 1819 }
1819} 1820}
1820 1821
1821sub audio_music_start { 1822sub audio_music_start {
1822 my $path = $MUSIC_PLAYING->{path} 1823 my $meta = $MUSIC_PLAYING_META;
1823 or return;
1824 1824
1825 CFPlus::DB::prefetch_file $path, 1024_000, sub { 1825 CFPlus::DB::get res_data => $meta->{name}, sub {
1826 return unless $SDL_MIXER; 1826 return unless $SDL_MIXER;
1827 1827
1828 # music might have changed... 1828 # music might have changed...
1829 $path eq $MUSIC_PLAYING->{path} 1829 $meta eq $MUSIC_PLAYING_META
1830 or return &audio_music_start (); 1830 or return &audio_music_start ();
1831 1831
1832 my $rwops = new_from_file CFPlus::RW $path; 1832 $MUSIC_PLAYING_DATA = \$_[0];
1833
1834 my $rwops = $meta->{path}
1835 ? new_from_file CFPlus::RW $meta->{path}
1836 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1837
1833 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops; 1838 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1839 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
1834 1840
1835 my $NOW = time; 1841 my $NOW = time;
1836 1842
1837 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { 1843 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
1838 my $pos = $MUSIC_PLAYING->{stop_pos}; 1844 my $pos = $MUSIC_PLAYING_META->{stop_pos};
1839 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 1845 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1840 $MUSIC_START = time - $pos; 1846 $MUSIC_START = time - $pos;
1841 } else { 1847 } else {
1842 $MUSIC_PLAYER->play (0); 1848 $MUSIC_PLAYER->play (0);
1843 $MUSIC_START = time; 1849 $MUSIC_START = time;
1844 } 1850 }
1845 1851
1846 delete $MUSIC_PLAYING->{stop_time}; 1852 delete $MUSIC_PLAYING_META->{stop_time};
1847 delete $MUSIC_PLAYING->{stop_pos}; 1853 delete $MUSIC_PLAYING_META->{stop_pos};
1848 } 1854 }
1849} 1855}
1850 1856
1851sub audio_music_changed { 1857sub audio_music_changed {
1852 return unless $CFG->{bgm_enable}; 1858 return unless $CFG->{bgm_enable};
1854 1860
1855 # default MUSIC_WANT == MUSIC_DEFAULT 1861 # default MUSIC_WANT == MUSIC_DEFAULT
1856 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 1862 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1857 1863
1858 # if the currently playing song is acceptable, let it continue 1864 # if the currently playing song is acceptable, let it continue
1859 return if $MUSIC_PLAYING 1865 return if $MUSIC_PLAYING_META
1860 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; 1866 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
1861 1867
1862 my $NOW = time; 1868 my $NOW = time;
1863 1869
1864 if ($MUSIC_PLAYING) { 1870 if ($MUSIC_PLAYING_META) {
1865 $MUSIC_PLAYING->{stop_time} = $NOW; 1871 $MUSIC_PLAYING_META->{stop_time} = $NOW;
1866 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; 1872 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
1867 CFPlus::MixMusic::fade_out 1000; 1873 CFPlus::MixMusic::fade_out 1000;
1868 } else { 1874 } else {
1869 # sort by stop time, oldest first 1875 # sort by stop time, oldest first
1870 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; 1876 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
1871 1877
1872 # if the most recently-played piece played very recently, 1878 # if the most recently-played piece played very recently,
1873 # resume it, else choose the oldest piece for rotation. 1879 # resume it, else choose the oldest piece for rotation.
1874 $MUSIC_PLAYING = 1880 $MUSIC_PLAYING_META =
1875 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME 1881 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
1876 ? $MUSIC_WANT[-1] 1882 ? $MUSIC_WANT[-1]
1877 : $MUSIC_WANT[0]; 1883 : $MUSIC_WANT[0];
1878 1884
1879 audio_music_start; 1885 audio_music_start;
1880 } 1886 }
1881} 1887}
1882 1888
1883sub audio_music_finished { 1889sub audio_music_finished {
1884 $MUSIC_PLAYING = undef;
1885 undef $MUSIC_PLAYER; 1890 undef $MUSIC_PLAYER;
1891 undef $MUSIC_PLAYING_META;
1892 undef $MUSIC_PLAYING_DATA;
1886 1893
1887 audio_music_changed; 1894 audio_music_changed;
1888} 1895}
1889 1896
1890sub audio_init { 1897sub audio_init {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines