--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/07/27 18:04:42 1.136 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2007/08/06 05:06:33 1.146 @@ -50,16 +50,16 @@ } sort { $a->{par} <=> $b->{par} } CFPlus::Pod::find command => "*"; - $self->connect_ext (music => sub { - my ($ev) = @_; - - &::audio_music_set ($self->{songs} = $ev->{play}) - if $ev->{play}; + $self->connect_ext (ambient_music => sub { + my ($songs) = @_; + &::audio_music_set_ambient ($songs); }); $self->connect_ext (capabilities => sub { my (%cap) = @_; + #$self->send ("setup sound 0"); # we use a different protocol + $self->send_exti_msg (fx_want => { 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 5 => !!$::CFG->{audio_enable}, # FT_SOUND @@ -228,23 +228,7 @@ sub logprint { my ($self, @a) = @_; - $self->{log_fh} ||= do { - my $path = "$Crossfire::VARDIR/log.$self->{host}"; - - open my $fh, ">>:utf8", $path - or die "Couldn't open logfile $path: $!"; - - $fh->autoflush (1); - - $fh; - }; - - my ($sec, $min, $hour, $mday, $mon, $year) = localtime time; - - my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", - $year + 1900, $mon + 1, $mday, $hour, $min, $sec; - - print {$self->{log_fh}} "$ts ", @a, "\n"; + CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; } sub _stat_numdiff { @@ -562,13 +546,13 @@ or return; } while $self->{texture}[$id]; - CFPlus::DB::get tilecache => $id, sub { - my ($data) = @_; + CFPlus::DB::exists tilecache => $id, sub { + my ($exists) = @_; return unless $self->{map}; # stop when destroyed - $self->set_texture ($id => $data) - if defined $data; + $self->have_tile ($id) + if $exists; $self->bg_fetch; }; @@ -735,7 +719,7 @@ } elsif ($face->{type} & 1) { # with metadata #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); - CFPlus::DB::get "res-metadata" => $face->{name}, $cb; + CFPlus::DB::get res_meta => $face->{name}, $cb; } } @@ -746,7 +730,7 @@ CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } if $changed; - $self->set_texture ($face->{id} => delete $face->{data}); + $self->have_tile ($face->{id}); } elsif ($face->{type} & 1) { # split metadata my $cb = sub { }; @@ -758,24 +742,32 @@ ::message ({ markup => "downloaded song #$facenum" }) if $changed; - &::audio_music_set ($self->{songs}); + &::audio_music_push ($facenum); + }; + } elsif ($face->{type} == 5) { # FT_SOUND + $cb = sub { + $self->{sound_meta}{$facenum} = $face; + + ::message ({ markup => "downloaded sound #$facenum" }) + if $changed; + + &::audio_sound_push ($facenum); }; } if ($changed) { # new data my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; - my $path = CFPlus::DB::path_of_res $face->{name}; - CFPlus::DB::write_file $path, $data, sub { - CFPlus::DB::put "res-metadata" => $face->{name} => $meta_json, sub { - $face->{meta} = $self->{json_coder}->decode ($meta_json); - $face->{path} = $path; - - $cb->(); - }; + CFPlus::DB::put res_data => $face->{name} => $data, sub { }; + CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { + $face->{meta} = $self->{json_coder}->decode ($meta_json); + ::add_license ($face); + $cb->(); }; + } else { $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); + ::add_license ($face); $cb->(); } } @@ -787,19 +779,16 @@ $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); } -sub set_texture { - my ($self, $id, $data) = @_; +sub have_tile { + my ($self, $tile) = @_; return unless $self->{map}; - $self->{texture}[$id] = my $tex = - new_from_image CFPlus::Texture - $data, minify => 1, mipmap => 1; + $self->{texture}[$tile] ||= my $tex = + new CFPlus::Texture + tile => $tile, minify => 1, mipmap => 1, delay => 1; - $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); - $self->{map_widget}->update; - - $_->() for @{(delete $self->{face_cb}{$id}) || []}; + $_->() for @{(delete $self->{face_cb}{$tile}) || []}; } sub connect_face_update { @@ -815,9 +804,10 @@ } sub sound_play { - my ($self, $x, $y, $soundnum, $type) = @_; + my ($self, $type, $face, $dx, $dy, $vol) = @_; - $self->{sound_play}->($x, $y, $soundnum, $type); + &::audio_sound_play ($face, $dx, $dy, $vol) + unless $type & 1; # odd types are silent for future expansion } my $LAST_QUERY; # server is stupid, stupid, stupid @@ -892,7 +882,7 @@ $self->logprint ("msg: ", $text); return if $color < 0; # negative color == ignore if not understood - my $fg = $CF_COLOR[$color % @CF_COLOR]; + my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; ## try to create single paragraphs of multiple lines sent by the server # no longer neecssary with TRT servers @@ -965,40 +955,6 @@ ::stop_game (); } -sub image_info { - my ($self, $numfaces) = @_; - - $self->{num_faces} = $numfaces; - $self->{face_prefetch} = [1 .. $numfaces]; - $self->face_prefetch; -} - -sub face_prefetch { - my ($self) = @_; - - return unless $::CFG->{face_prefetch}; - - if ($self->{num_faces}) { - return if @{ $self->{send_queue} || [] }; - my $todo = @{ $self->{face_prefetch} } - or return; - - my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); - - $self->send ("requestinfo image_sums $face $face"); - - $self->{statusbox}->add (CFPlus::asxml "prefetching $todo", - group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); - } elsif (!exists $self->{num_faces}) { - $self->send ("requestinfo image_info"); - - $self->{num_faces} = 0; - - $self->{statusbox}->add (CFPlus::asxml "starting to prefetch", - group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); - } -} - sub update_floorbox { $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { return unless $::CONN;