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.161 by root, Thu Jul 5 06:57:03 2007 UTC vs.
Revision 1.168 by root, Sat Jul 14 12:05:53 2007 UTC

159 159
160our $SDL_ACTIVE; 160our $SDL_ACTIVE;
161our %SDL_CB; 161our %SDL_CB;
162 162
163our $SDL_MIXER; 163our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT;
166our $MUSIC_START;
167our $MUSIC_PLAYING;
168our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
164our @SOUNDS; # event => file mapping 170our @SOUNDS; # event => file mapping
165our %AUDIO_CHUNKS; # audio files 171our %AUDIO_CHUNKS; # audio files
166 172
167our $ALT_ENTER_MESSAGE; 173our $ALT_ENTER_MESSAGE;
168our $STATUSBOX; 174our $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
2004 CFPlus::OpenGL::shutdown; 2010 CFPlus::OpenGL::shutdown;
2005 2011
2006 undef $SDL_ACTIVE; 2012 undef $SDL_ACTIVE;
2007} 2013}
2008 2014
2009my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
2010my $bgmusic;#TODO#hack#d#
2011
2012sub audio_channel_finished { 2015sub audio_channel_finished {
2013 my ($channel) = @_; 2016 my ($channel) = @_;
2014 2017
2015 #warn "channel $channel finished\n";#d# 2018 #warn "channel $channel finished\n";#d#
2016} 2019}
2017 2020
2021sub audio_music_set {
2022 my ($songs) = @_;
2023
2024 my @want =
2025 grep $_,
2026 map $CONN->{music_meta}{$_},
2027 @$songs;
2028
2029 if (@want) {
2030 @MUSIC_WANT = @want;
2031 &audio_music_changed ();
2032 }
2033}
2034
2035sub audio_music_start {
2036 my $path = $MUSIC_PLAYING->{path}
2037 or return;
2038
2039 CFPlus::DB::prefetch_file $path, 1024_000, sub {
2040 # music might have changed...
2041 $path eq $MUSIC_PLAYING->{path}
2042 or return &audio_music_start ();
2043
2044 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path;
2045
2046 my $NOW = time;
2047
2048 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) {
2049 my $pos = $MUSIC_PLAYING->{stop_pos};
2050 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
2051 $MUSIC_START = time - $pos;
2052 } else {
2053 $MUSIC_PLAYER->play (0);
2054 $MUSIC_START = time;
2055 }
2056
2057 delete $MUSIC_PLAYING->{stop_time};
2058 delete $MUSIC_PLAYING->{stop_pos};
2059 }
2060}
2061
2062sub audio_music_changed {
2063 return unless $CFG->{bgm_enable};
2064
2065 # default MUSIC_WANT == MUSIC_DEFAULT
2066 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
2067
2068 # if the currently playing song is acceptable, let it continue
2069 return if $MUSIC_PLAYING
2070 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT;
2071
2072 my $NOW = time;
2073
2074 if ($MUSIC_PLAYING) {
2075 $MUSIC_PLAYING->{stop_time} = $NOW;
2076 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START;
2077 CFPlus::MixMusic::fade_out 1000;
2078 } else {
2079 # sort by stop time, oldest first
2080 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
2081
2082 # if the most recently-played piece played very recently,
2083 # resume it, else choose the oldest piece for rotation.
2084 $MUSIC_PLAYING =
2085 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
2086 ? $MUSIC_WANT[-1]
2087 : $MUSIC_WANT[0];
2088
2089 audio_music_start;
2090 }
2091}
2092
2018sub audio_music_finished { 2093sub audio_music_finished {
2019 return unless $CFG->{bgm_enable}; 2094 $MUSIC_PLAYING = undef;
2095 undef $MUSIC_PLAYER;
2020 2096
2021 # TODO: hack, do play loop and mood music 2097 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} 2098}
2027 2099
2028sub audio_init { 2100sub audio_init {
2029 if ($CFG->{audio_enable}) { 2101 if ($CFG->{audio_enable}) {
2030 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { 2102 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines