--- deliantra/Deliantra-Client/bin/pclient 2006/04/18 01:36:13 1.130 +++ deliantra/Deliantra-Client/bin/pclient 2006/04/18 21:37:48 1.138 @@ -10,6 +10,11 @@ use SDL::App; use SDL::Event; use SDL::Surface; + +use SDL::Mixer; +use SDL::Sound; +use SDL::Music; + use SDL::OpenGL; use Crossfire; @@ -57,6 +62,10 @@ our $SDL_EV; our %SDL_CB; +our $SDL_MIXER; +our @SOUNDS; # event => file mapping +our %AUDIO_CHUNKS; # audio files + our $ALT_ENTER_MESSAGE; our $STATUS_LINE; our $DEBUG_STATUS; @@ -148,6 +157,7 @@ $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { my ($self, $value) = @_; $CFG->{fow_smooth} = $value; + status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; }); $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); @@ -157,8 +167,23 @@ }); $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { - destroy_screen (); - init_screen (); + video_shutdown (); + video_init (); + }); + + $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); + $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub { + my ($self, $value) = @_; + $CFG->{sound} = $value; + }); + $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music"); + $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub { + my ($self, $value) = @_; + $CFG->{bg_music_enable} = $value; + }); + $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { + audio_shutdown (); + audio_init (); }); $dialog @@ -351,12 +376,12 @@ } sub sdl_init { - SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE - #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO + #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE + SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO and die "SDL::Init failed!\n"; } -sub init_screen { +sub video_init { sdl_init; ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; @@ -452,11 +477,49 @@ $CFClient::UI::ROOT->add ($tgw); } -sub destroy_screen { +sub video_shutdown { $CFClient::UI::ROOT->{children} = []; undef $SDL_ACTIVE; undef $SDL_EV; - SDL::Quit; +} + +my $bgmusic;#TODO#hack#d# + +sub audio_init { + if ($CFG->{sound} || 1) { + if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { + $SDL_MIXER = new SDL::Mixer; + $SDL_MIXER->allocate_channels (8); + + if ($CFG->{bg_music_enable}) { + $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; + $SDL_MIXER->play_music ($bgmusic, -1); + } + + while (<$fh>) { + next if /^\s*#/; + next if /^\s*$/; + + my ($file, $volume, $event) = split /\s+/, $_, 3; + + push @SOUNDS, "$volume,$file"; + + $AUDIO_CHUNKS{"$volume,$file"} ||= do { + my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; + $chunk->volume ($volume * 128 / 100); + $chunk + }; + } + } else { + status "unable to open sound config: $!"; + } + } +} + +sub audio_shutdown { + undef $SDL_MIXER; + @SOUNDS = (); + %AUDIO_CHUNKS = (); } my %animate_object; @@ -637,8 +700,6 @@ my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); - warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# - my $mapmapw = 250; my $mapmaph = 250; @@ -711,6 +772,16 @@ }; } +sub conn::sound_play { + my ($self, $x, $y, $soundnum, $type) = @_; + + my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} + or return; + + $SDL_MIXER->play_channel (-1, $chunk); + warn "sound $x,$y,$soundnum,$type\n";#d# +} + sub conn::query { my ($self, $flags, $prompt) = @_; @@ -752,9 +823,9 @@ SDL_KEYDOWN() => sub { if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { # alt-enter - destroy_screen; + video_shutdown; $CFG->{fullscreen} = !$CFG->{fullscreen}; - init_screen; + video_init; } else { CFClient::UI::feed_sdl_key_down_event ($SDL_EV); } @@ -778,6 +849,8 @@ ############################################################################# +$SIG{INT} = $SIG{TERM} = sub { exit }; + $TILECACHE = CFClient::db_table "tilecache"; $FACEMAP = CFClient::db_table "facemap"; @@ -796,6 +869,8 @@ mapsize => 100, host => "crossfire.schmorp.de", say_command => 'say', + sound => 1, + bg_music_enable => 1, ); while (my ($k, $v) = each %DEF_CFG) { @@ -820,8 +895,11 @@ CFClient::set_font $fonts[0]; } -init_screen; +video_init; +audio_init; Event::loop; +END { SDL::Quit } +