ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.140 by root, Sun Jul 29 18:56:02 2007 UTC vs.
Revision 1.147 by root, Thu Aug 9 03:40:01 2007 UTC

48 sort { (length $a) <=> (length $b) } 48 sort { (length $a) <=> (length $b) }
49 @args 49 @args
50 } sort { $a->{par} <=> $b->{par} } 50 } sort { $a->{par} <=> $b->{par} }
51 CFPlus::Pod::find command => "*"; 51 CFPlus::Pod::find command => "*";
52 52
53 $self->connect_ext (music => sub { 53 $self->connect_ext (ambient_music => sub {
54 my ($ev) = @_; 54 my ($songs) = @_;
55 55 &::audio_music_set_ambient ($songs);
56 &::audio_music_set ($self->{songs} = $ev->{play})
57 if $ev->{play};
58 }); 56 });
59 57
60 $self->connect_ext (capabilities => sub { 58 $self->connect_ext (capabilities => sub {
61 my (%cap) = @_; 59 my (%cap) = @_;
62 60
63 #$self->send ("setup sound 0"); # we use a different protocol 61 #$self->send ("setup sound 0"); # we use a different protocol
64 62 $self->update_fx_want;
65 $self->send_exti_msg (fx_want => {
66 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
67 5 => !!$::CFG->{audio_enable}, # FT_SOUND
68 });
69 63
70 if (my $ts = $cap{tileset}) { 64 if (my $ts = $cap{tileset}) {
71 if (my ($default) = grep $_->[2] & 1, @$ts) { 65 if (my ($default) = grep $_->[2] & 1, @$ts) {
72 $self->{tileset} = $default; 66 $self->{tileset} = $default;
73 $self->{tilesize} = $default->[3]; 67 $self->{tilesize} = $default->[3];
225 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 219 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
226 220
227 $self 221 $self
228} 222}
229 223
224sub update_fx_want {
225 my ($self) = @_;
226
227 $self->send_exti_msg (fx_want => {
228 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
229 5 => !!$::CFG->{audio_enable}, # FT_SOUND
230 });
231}
232
230sub logprint { 233sub logprint {
231 my ($self, @a) = @_; 234 my ($self, @a) = @_;
232 235
233 $self->{log_fh} ||= do { 236 CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { };
234 my $path = "$Crossfire::VARDIR/log.$self->{host}";
235
236 open my $fh, ">>:utf8", $path
237 or die "Couldn't open logfile $path: $!";
238
239 $fh->autoflush (1);
240
241 $fh;
242 };
243
244 my ($sec, $min, $hour, $mday, $mon, $year) = localtime time;
245
246 my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d",
247 $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
248
249 print {$self->{log_fh}} "$ts ", @a, "\n";
250} 237}
251 238
252sub _stat_numdiff { 239sub _stat_numdiff {
253 my ($self, $name, $old, $new) = @_; 240 my ($self, $name, $old, $new) = @_;
254 241
562 do { 549 do {
563 $id = pop @{$self->{bg_fetch}} 550 $id = pop @{$self->{bg_fetch}}
564 or return; 551 or return;
565 } while $self->{texture}[$id]; 552 } while $self->{texture}[$id];
566 553
567 CFPlus::DB::get tilecache => $id, sub { 554 CFPlus::DB::exists tilecache => $id, sub {
568 my ($data) = @_; 555 my ($exists) = @_;
569 556
570 return unless $self->{map}; # stop when destroyed 557 return unless $self->{map}; # stop when destroyed
571 558
572 $self->set_texture ($id => $data) 559 $self->have_tile ($id)
573 if defined $data; 560 if $exists;
574 561
575 $self->bg_fetch; 562 $self->bg_fetch;
576 }; 563 };
577} 564}
578 565
746 733
747 if ($face->{type} == 0) { # FT_FACE 734 if ($face->{type} == 0) { # FT_FACE
748 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 735 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { }
749 if $changed; 736 if $changed;
750 737
751 $self->set_texture ($face->{id} => delete $face->{data}); 738 $self->have_tile ($face->{id});
752 739
753 } elsif ($face->{type} & 1) { # split metadata 740 } elsif ($face->{type} & 1) { # split metadata
754 my $cb = sub { };
755
756 if ($face->{type} == 3) { # FT_MUSIC
757 $cb = sub {
758 $self->{music_meta}{$facenum} = $face;
759
760 ::message ({ markup => "downloaded song #$facenum" })
761 if $changed;
762
763 &::audio_music_set ($self->{songs});
764 };
765 } elsif ($face->{type} == 5) { # FT_SOUND
766 $cb = sub {
767 $self->{sound_meta}{$facenum} = $face;
768
769 use Data::Dumper; warn Dumper $face;#d#
770 ::message ({ markup => "downloaded sound #$facenum" })
771 if $changed;
772 };
773 }
774
775
776 if ($changed) { # new data 741 if ($changed) { # new data
777 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; 742 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data};
743 $face->{meta} = $self->{json_coder}->decode ($meta_json);
778 744
779 CFPlus::DB::put res_data => $face->{name} => $data, sub { 745 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
780 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { 746 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { };
781 $face->{meta} = $self->{json_coder}->decode ($meta_json);
782
783 $cb->();
784 };
785 };
786
787 } else { 747 } else {
788 $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); 748 $face->{meta} = $self->{json_coder}->decode (delete $face->{data});
789 $cb->();
790 } 749 }
750
751 ::add_license ($face);
752
753 if ($face->{type} == 3) { # FT_MUSIC
754 $self->{music_meta}{$facenum} = $face;
755
756 ::message ({ markup => "downloaded song #$facenum" })
757 if $changed;
758
759 &::audio_music_push ($facenum);
760 } elsif ($face->{type} == 5) { # FT_SOUND
761 $self->{sound_meta}{$facenum} = $face;
762
763 ::message ({ markup => "downloaded sound #$facenum" })
764 if $changed;
765
766 &::audio_sound_push ($facenum);
767 }
768
791 } 769 }
792} 770}
793 771
794sub smooth_update { 772sub smooth_update {
795 my ($self, $facenum, $face) = @_; 773 my ($self, $facenum, $face) = @_;
796 774
797 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); 775 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
798} 776}
799 777
800sub set_texture { 778sub have_tile {
801 my ($self, $id, $data) = @_; 779 my ($self, $tile) = @_;
802 780
803 return unless $self->{map}; 781 return unless $self->{map};
804 782
805 $self->{texture}[$id] = my $tex = 783 $self->{texture}[$tile] ||= my $tex =
806 new_from_image CFPlus::Texture 784 new CFPlus::Texture
807 $data, minify => 1, mipmap => 1; 785 tile => $tile, minify => 1, mipmap => 1, delay => 1;
808 786
809 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
810 $self->{map_widget}->update;
811
812 $_->() for @{(delete $self->{face_cb}{$id}) || []}; 787 $_->() for @{(delete $self->{face_cb}{$tile}) || []};
813} 788}
814 789
815sub connect_face_update { 790sub connect_face_update {
816 my ($self, $id, $cb) = @_; 791 my ($self, $id, $cb) = @_;
817 792
823 @{$self->{face_cb}{$id}}; 798 @{$self->{face_cb}{$id}};
824 } 799 }
825} 800}
826 801
827sub sound_play { 802sub sound_play {
828 my ($self, $x, $y, $soundnum, $type) = @_; 803 my ($self, $type, $face, $dx, $dy, $vol) = @_;
829 warn "sound play <@_>\n";#d#
830 804
831 #$self->{sound_play}->($x, $y, $soundnum, $type); 805 &::audio_sound_play ($face, $dx, $dy, $vol)
806 unless $type & 1; # odd types are silent for future expansion
832} 807}
833 808
834my $LAST_QUERY; # server is stupid, stupid, stupid 809my $LAST_QUERY; # server is stupid, stupid, stupid
835 810
836sub query { 811sub query {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines