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

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.145 by root, Wed Apr 19 20:46:45 2006 UTC vs.
Revision 1.146 by root, Wed Apr 19 21:17:16 2006 UTC

5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL::Event; 9use SDL::Event;
10
11use SDL::Mixer;
12use SDL::Sound;
13use SDL::Music;
14 10
15use SDL::OpenGL; 11use SDL::OpenGL;
16 12
17use Crossfire; 13use Crossfire;
18use Crossfire::Protocol; 14use Crossfire::Protocol;
185 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); 181 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
186 $table->add (1, 10, my $hbox = new CFClient::UI::HBox); 182 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
187 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { 183 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
188 $CFG->{bgm_enable} = $_[1]; 184 $CFG->{bgm_enable} = $_[1];
189 }); 185 });
190 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { 186 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
191 $CFG->{bgm_volume} = $_[1]; 187 $CFG->{bgm_volume} = $_[1];
192 $SDL_MIXER->music_volume ($_[1]); 188 CFClient::Mix_VolumeMusic ($_[1]);
193 }); 189 });
194 190
195 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 191 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
196 audio_shutdown (); 192 audio_shutdown ();
197 audio_init (); 193 audio_init ();
479 475
480sub audio_init { 476sub audio_init {
481 if ($CFG->{audio_enable}) { 477 if ($CFG->{audio_enable}) {
482 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 478 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
483 479
484 $SDL_MIXER = new SDL::Mixer 480 $SDL_MIXER = !CFClient::Mix_OpenAudio;
485 -rate => 22050, 481 CFClient::Mix_AllocateChannels 8;
486 -channels => 1, # mono 482 CFClient::MixMusic::volume $CFG->{bgm_volume};
487 -size => 512;
488
489 $SDL_MIXER->allocate_channels (8);
490 483
491 # TODO: hack, do play loop and mood music 484 # TODO: hack, do play loop and mood music
492 if ($CFG->{bgm_enable}) { 485 if ($CFG->{bgm_enable}) {
493 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 486 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
494 $SDL_MIXER->play_music ($bgmusic, -1); 487 $bgmusic->play;
495 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
496 } 488 }
497 489
498 while (<$fh>) { 490 while (<$fh>) {
499 next if /^\s*#/; 491 next if /^\s*#/;
500 next if /^\s*$/; 492 next if /^\s*$/;
502 my ($file, $volume, $event) = split /\s+/, $_, 3; 494 my ($file, $volume, $event) = split /\s+/, $_, 3;
503 495
504 push @SOUNDS, "$volume,$file"; 496 push @SOUNDS, "$volume,$file";
505 497
506 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 498 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
507 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 499 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
508 $chunk->volume ($volume * 128 / 100); 500 $chunk->volume ($volume * 128 / 100);
509 $chunk 501 $chunk
510 }; 502 };
511 } 503 }
512 } else { 504 } else {
514 } 506 }
515 } 507 }
516} 508}
517 509
518sub audio_shutdown { 510sub audio_shutdown {
511 CFClient::Mix_CloseAudio if $SDL_MIXER;
519 undef $SDL_MIXER; 512 undef $SDL_MIXER;
520 @SOUNDS = (); 513 @SOUNDS = ();
521 %AUDIO_CHUNKS = (); 514 %AUDIO_CHUNKS = ();
522} 515}
523 516
778 or return; 771 or return;
779 772
780 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 773 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
781 or return; 774 or return;
782 775
783 $SDL_MIXER->play_channel (-1, $chunk); 776 $chunk->play;
784# warn "sound $x,$y,$soundnum,$type\n";#d# 777# warn "sound $x,$y,$soundnum,$type\n";#d#
785} 778}
786 779
787sub conn::query { 780sub conn::query {
788 my ($self, $flags, $prompt) = @_; 781 my ($self, $flags, $prompt) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines