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.138 by root, Sat Jul 28 16:48:45 2007 UTC vs.
Revision 1.146 by root, Mon Aug 6 05:06:33 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
65 $self->send_exti_msg (fx_want => { 63 $self->send_exti_msg (fx_want => {
66 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 64 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
67 #5 => !!$::CFG->{audio_enable}, # FT_SOUND 65 5 => !!$::CFG->{audio_enable}, # FT_SOUND
68 }); 66 });
69 67
70 if (my $ts = $cap{tileset}) { 68 if (my $ts = $cap{tileset}) {
71 if (my ($default) = grep $_->[2] & 1, @$ts) { 69 if (my ($default) = grep $_->[2] & 1, @$ts) {
72 $self->{tileset} = $default; 70 $self->{tileset} = $default;
228} 226}
229 227
230sub logprint { 228sub logprint {
231 my ($self, @a) = @_; 229 my ($self, @a) = @_;
232 230
233 $self->{log_fh} ||= do { 231 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} 232}
251 233
252sub _stat_numdiff { 234sub _stat_numdiff {
253 my ($self, $name, $old, $new) = @_; 235 my ($self, $name, $old, $new) = @_;
254 236
562 do { 544 do {
563 $id = pop @{$self->{bg_fetch}} 545 $id = pop @{$self->{bg_fetch}}
564 or return; 546 or return;
565 } while $self->{texture}[$id]; 547 } while $self->{texture}[$id];
566 548
567 CFPlus::DB::get tilecache => $id, sub { 549 CFPlus::DB::exists tilecache => $id, sub {
568 my ($data) = @_; 550 my ($exists) = @_;
569 551
570 return unless $self->{map}; # stop when destroyed 552 return unless $self->{map}; # stop when destroyed
571 553
572 $self->set_texture ($id => $data) 554 $self->have_tile ($id)
573 if defined $data; 555 if $exists;
574 556
575 $self->bg_fetch; 557 $self->bg_fetch;
576 }; 558 };
577} 559}
578 560
735 717
736 CFPlus::DB::get tilecache => $id, $cb; 718 CFPlus::DB::get tilecache => $id, $cb;
737 719
738 } elsif ($face->{type} & 1) { # with metadata 720 } elsif ($face->{type} & 1) { # with metadata
739 #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); 721 #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
740 CFPlus::DB::get "res-metadata" => $face->{name}, $cb; 722 CFPlus::DB::get res_meta => $face->{name}, $cb;
741 } 723 }
742} 724}
743 725
744sub face_update { 726sub face_update {
745 my ($self, $facenum, $face, $changed) = @_; 727 my ($self, $facenum, $face, $changed) = @_;
746 728
747 if ($face->{type} == 0) { # FT_FACE 729 if ($face->{type} == 0) { # FT_FACE
748 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 730 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { }
749 if $changed; 731 if $changed;
750 732
751 $self->set_texture ($face->{id} => delete $face->{data}); 733 $self->have_tile ($face->{id});
752 734
753 } elsif ($face->{type} & 1) { # split metadata 735 } elsif ($face->{type} & 1) { # split metadata
754 my $cb = sub { }; 736 my $cb = sub { };
755 737
756 if ($face->{type} == 3) { # FT_MUSIC 738 if ($face->{type} == 3) { # FT_MUSIC
758 $self->{music_meta}{$facenum} = $face; 740 $self->{music_meta}{$facenum} = $face;
759 741
760 ::message ({ markup => "downloaded song #$facenum" }) 742 ::message ({ markup => "downloaded song #$facenum" })
761 if $changed; 743 if $changed;
762 744
763 &::audio_music_set ($self->{songs}); 745 &::audio_music_push ($facenum);
764 }; 746 };
747 } elsif ($face->{type} == 5) { # FT_SOUND
748 $cb = sub {
749 $self->{sound_meta}{$facenum} = $face;
750
751 ::message ({ markup => "downloaded sound #$facenum" })
752 if $changed;
753
754 &::audio_sound_push ($facenum);
765 } 755 };
766 756 }
767 my $path = CFPlus::DB::path_of_res $face->{name};
768 757
769 if ($changed) { # new data 758 if ($changed) { # new data
770 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; 759 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data};
771 760
772 CFPlus::DB::write_file $path, $data, sub { 761 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
773 CFPlus::DB::put "res-metadata" => $face->{name} => $meta_json, sub { 762 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub {
774 $face->{meta} = $self->{json_coder}->decode ($meta_json); 763 $face->{meta} = $self->{json_coder}->decode ($meta_json);
775 $face->{path} = $path; 764 ::add_license ($face);
776
777 $cb->(); 765 $cb->();
778 };
779 }; 766 };
767
780 } else { 768 } else {
781 $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); 769 $face->{meta} = $self->{json_coder}->decode (delete $face->{data});
782 $face->{path} = $path; 770 ::add_license ($face);
783 $cb->(); 771 $cb->();
784 } 772 }
785 } 773 }
786} 774}
787 775
789 my ($self, $facenum, $face) = @_; 777 my ($self, $facenum, $face) = @_;
790 778
791 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); 779 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
792} 780}
793 781
794sub set_texture { 782sub have_tile {
795 my ($self, $id, $data) = @_; 783 my ($self, $tile) = @_;
796 784
797 return unless $self->{map}; 785 return unless $self->{map};
798 786
799 $self->{texture}[$id] = my $tex = 787 $self->{texture}[$tile] ||= my $tex =
800 new_from_image CFPlus::Texture 788 new CFPlus::Texture
801 $data, minify => 1, mipmap => 1; 789 tile => $tile, minify => 1, mipmap => 1, delay => 1;
802 790
803 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
804 $self->{map_widget}->update;
805
806 $_->() for @{(delete $self->{face_cb}{$id}) || []}; 791 $_->() for @{(delete $self->{face_cb}{$tile}) || []};
807} 792}
808 793
809sub connect_face_update { 794sub connect_face_update {
810 my ($self, $id, $cb) = @_; 795 my ($self, $id, $cb) = @_;
811 796
817 @{$self->{face_cb}{$id}}; 802 @{$self->{face_cb}{$id}};
818 } 803 }
819} 804}
820 805
821sub sound_play { 806sub sound_play {
822 my ($self, $x, $y, $soundnum, $type) = @_; 807 my ($self, $type, $face, $dx, $dy, $vol) = @_;
823 warn "sound play <@_>\n";#d#
824 808
825 #$self->{sound_play}->($x, $y, $soundnum, $type); 809 &::audio_sound_play ($face, $dx, $dy, $vol)
810 unless $type & 1; # odd types are silent for future expansion
826} 811}
827 812
828my $LAST_QUERY; # server is stupid, stupid, stupid 813my $LAST_QUERY; # server is stupid, stupid, stupid
829 814
830sub query { 815sub query {
968 $self->{map_widget}->clr_commands; 953 $self->{map_widget}->clr_commands;
969 954
970 ::stop_game (); 955 ::stop_game ();
971} 956}
972 957
973sub image_info {
974 my ($self, $numfaces) = @_;
975
976 $self->{num_faces} = $numfaces;
977 $self->{face_prefetch} = [1 .. $numfaces];
978 $self->face_prefetch;
979}
980
981sub face_prefetch {
982 my ($self) = @_;
983
984 return unless $::CFG->{face_prefetch};
985
986 if ($self->{num_faces}) {
987 return if @{ $self->{send_queue} || [] };
988 my $todo = @{ $self->{face_prefetch} }
989 or return;
990
991 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
992
993 $self->send ("requestinfo image_sums $face $face");
994
995 $self->{statusbox}->add (CFPlus::asxml "prefetching $todo",
996 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
997 } elsif (!exists $self->{num_faces}) {
998 $self->send ("requestinfo image_info");
999
1000 $self->{num_faces} = 0;
1001
1002 $self->{statusbox}->add (CFPlus::asxml "starting to prefetch",
1003 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
1004 }
1005}
1006
1007sub update_floorbox { 958sub update_floorbox {
1008 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 959 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub {
1009 return unless $::CONN; 960 return unless $::CONN;
1010 961
1011 $::FLOORBOX->clear; 962 $::FLOORBOX->clear;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines