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.145 by root, Mon Aug 6 02:11:45 2007 UTC vs.
Revision 1.153 by root, Mon Aug 13 14:24:17 2007 UTC

21 21
22 my $self = $class->SUPER::new (%arg, 22 my $self = $class->SUPER::new (%arg,
23 setup_req => { 23 setup_req => {
24 extmap => 1, 24 extmap => 1,
25 excmd => 1, 25 excmd => 1,
26 xwidget => 1,#d# 26 ywidget => 1,#d#
27 %{$arg{setup_req} || {}}, 27 %{$arg{setup_req} || {}},
28 }, 28 },
29 ); 29 );
30 30
31 $self->{map_widget}->clr_commands; 31 $self->{map_widget}->clr_commands;
57 57
58 $self->connect_ext (capabilities => sub { 58 $self->connect_ext (capabilities => sub {
59 my (%cap) = @_; 59 my (%cap) = @_;
60 60
61 #$self->send ("setup sound 0"); # we use a different protocol 61 #$self->send ("setup sound 0"); # we use a different protocol
62 62 $self->update_fx_want;
63 $self->send_exti_msg (fx_want => {
64 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
65 5 => !!$::CFG->{audio_enable}, # FT_SOUND
66 });
67 63
68 if (my $ts = $cap{tileset}) { 64 if (my $ts = $cap{tileset}) {
69 if (my ($default) = grep $_->[2] & 1, @$ts) { 65 if (my ($default) = grep $_->[2] & 1, @$ts) {
70 $self->{tileset} = $default; 66 $self->{tileset} = $default;
71 $self->{tilesize} = $default->[3]; 67 $self->{tilesize} = $default->[3];
221 217
222 # per server 218 # per server
223 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 219 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
224 220
225 $self 221 $self
222}
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 });
226} 231}
227 232
228sub logprint { 233sub logprint {
229 my ($self, @a) = @_; 234 my ($self, @a) = @_;
230 235
501} 506}
502 507
503sub feed_map1a { 508sub feed_map1a {
504 my ($self, $data) = @_; 509 my ($self, $data) = @_;
505 510
506 $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 511 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap});
512 my $delay;
513
514 for my $tile (@$missing) {
515 next if $self->{delay}{$tile};
516
517 $delay = 1;
518
519 if (my $tex = $::CONN->{texture}[$tile]) {
520 $tex->upload;
521 } else {
522 $self->{delay}{$tile} = 1;
523
524 # we assume the face is in-flight and will eventually come
525 push @{$self->{face_cb}{$tile}}, sub {
526 delete $self->{delay}{$tile};
527 $_[0]->upload;
528 };
529 }
530 }
531
532 if ($delay) {
533 # delay the map drawing a tiny bit in the hope of getting the missing fetched
534 Event->timer (after => 0.03, cb => sub {
535 $_[0]->w->cancel;
536 $self->{map_widget}->update;
537 });
538 } else {
507 $self->{map_widget}->update; 539 $self->{map_widget}->update;
540 }
508} 541}
509 542
510sub magicmap { 543sub magicmap {
511 my ($self, $w, $h, $x, $y, $data) = @_; 544 my ($self, $w, $h, $x, $y, $data) = @_;
512 545
519 my $map_info = delete $self->{map_info} 552 my $map_info = delete $self->{map_info}
520 or return; 553 or return;
521 554
522 my ($hash, $x, $y, $w, $h) = @$map_info; 555 my ($hash, $x, $y, $w, $h) = @$map_info;
523 556
524 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 557 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h);
558 $self->{map_cache_new}{$hash} = \$data;
525 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; 559 CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { };
526 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
527} 560}
528 561
529sub map_clear { 562sub map_clear {
530 my ($self) = @_; 563 my ($self) = @_;
531 564
544 do { 577 do {
545 $id = pop @{$self->{bg_fetch}} 578 $id = pop @{$self->{bg_fetch}}
546 or return; 579 or return;
547 } while $self->{texture}[$id]; 580 } while $self->{texture}[$id];
548 581
549 CFPlus::DB::get tilecache => $id, sub { 582 CFPlus::DB::exists tilecache => $id, sub {
550 my ($data) = @_; 583 my ($exists) = @_;
551 584
552 return unless $self->{map}; # stop when destroyed 585 return unless $self->{map}; # stop when destroyed
553 586
554 $self->set_texture ($id => $data) 587 if ($exists) {
555 if defined $data; 588 $self->have_tile ($id);
589 $self->{texture}[$id]->upload;
590 }
556 591
557 $self->bg_fetch; 592 $self->bg_fetch;
558 }; 593 };
559} 594}
560 595
561sub load_map($$$) { 596sub load_map($$$) {
562 my ($self, $hash, $x, $y) = @_; 597 my ($self, $hash, $x, $y) = @_;
563 598
564 my $gen = $self->{map_change_gen}; 599 my $gen = $self->{map_change_gen};
565 600
566 CFPlus::DB::get $self->{mapcache} => $hash, sub { 601 my $cb = sub {
567 return unless $gen == $self->{map_change_gen}; 602 return unless $gen == $self->{map_change_gen};
568 603
569 my ($data) = @_; 604 my ($data) = @_;
570 605
571 if (defined $data) { 606 if (defined $data) {
607 $self->{map_cache_new}{$hash} = \$data;
608
572 $data = Compress::LZF::decompress $data; 609 my $data = Compress::LZF::decompress $data;
573 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
574 610
575 my $inprogress = @{ $self->{bg_fetch} || [] }; 611 my $inprogress = @{ $self->{bg_fetch} || [] };
576 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 612 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
577 $self->bg_fetch unless $inprogress; 613 $self->bg_fetch unless $inprogress;
578 } 614 }
579 }; 615 };
616
617 if (my $rdata = $self->{map_cache_old}{$hash}) {
618 $cb->($$rdata);
619 } else {
620 CFPlus::DB::get $self->{mapcache} => $hash, $cb;
621 }
580} 622}
581 623
582# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 624# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
583# (server resource,s latency, bandwidth), so this hack is warranted. 625# (server resource,s latency, bandwidth), so this hack is warranted.
584# the right fix is to make real tiled maps with an overview file 626# the right fix is to make real tiled maps with an overview file
677 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 719 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
678 720
679 $self->flush_map; 721 $self->flush_map;
680 722
681 ++$self->{map_change_gen}; 723 ++$self->{map_change_gen};
724 $self->{map_cache_old} = delete $self->{map_cache_new};
682 725
683 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 726 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
684 727
685 my $mapmapw = $self->{mapmap}->{w}; 728 my $mapmapw = $self->{mapmap}->{w};
686 my $mapmaph = $self->{mapmap}->{h}; 729 my $mapmaph = $self->{mapmap}->{h};
716 $self->{map}->set_tileid ($facenum => $id); 759 $self->{map}->set_tileid ($facenum => $id);
717 760
718 CFPlus::DB::get tilecache => $id, $cb; 761 CFPlus::DB::get tilecache => $id, $cb;
719 762
720 } elsif ($face->{type} & 1) { # with metadata 763 } elsif ($face->{type} & 1) { # with metadata
721 #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
722 CFPlus::DB::get res_meta => $face->{name}, $cb; 764 CFPlus::DB::get res_meta => $face->{name}, $cb;
723 } 765 }
724} 766}
725 767
726sub face_update { 768sub face_update {
728 770
729 if ($face->{type} == 0) { # FT_FACE 771 if ($face->{type} == 0) { # FT_FACE
730 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 772 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { }
731 if $changed; 773 if $changed;
732 774
733 $self->set_texture ($face->{id} => delete $face->{data}); 775 $self->have_tile ($face->{id});
734 776
735 } elsif ($face->{type} & 1) { # split metadata 777 } elsif ($face->{type} & 1) { # split metadata
736 my $cb = sub { };
737
738 if ($face->{type} == 3) { # FT_MUSIC
739 $cb = sub {
740 $self->{music_meta}{$facenum} = $face;
741
742 ::message ({ markup => "downloaded song #$facenum" })
743 if $changed;
744
745 &::audio_music_push ($facenum);
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);
755 };
756 }
757
758 if ($changed) { # new data 778 if ($changed) { # new data
759 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; 779 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data};
780 $face->{meta} = $self->{json_coder}->decode ($meta_json);
760 781
761 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 782 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
762 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { 783 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { };
763 $face->{meta} = $self->{json_coder}->decode ($meta_json);
764 ::add_license ($face);
765 $cb->();
766 };
767
768 } else { 784 } else {
769 $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); 785 $face->{meta} = $self->{json_coder}->decode (delete $face->{data});
786 }
787
770 ::add_license ($face); 788 ::add_license ($face);
771 $cb->(); 789
790 if ($face->{type} == 3) { # FT_MUSIC
791 $self->{music_meta}{$facenum} = $face;
792
793 ::message ({ markup => "downloaded song #$facenum" })
794 if $changed;
795
796 &::audio_music_push ($facenum);
797 } elsif ($face->{type} == 5) { # FT_SOUND
798 $self->{sound_meta}{$facenum} = $face;
799
800 ::message ({ markup => "downloaded sound #$facenum" })
801 if $changed;
802
803 &::audio_sound_push ($facenum);
772 } 804 }
805
773 } 806 }
774} 807}
775 808
776sub smooth_update { 809sub smooth_update {
777 my ($self, $facenum, $face) = @_; 810 my ($self, $facenum, $face) = @_;
778 811
779 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); 812 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
780} 813}
781 814
782sub set_texture { 815sub have_tile {
783 my ($self, $id, $data) = @_; 816 my ($self, $tile) = @_;
784 817
785 return unless $self->{map}; 818 return unless $self->{map};
786 819
787 $self->{texture}[$id] = my $tex = 820 my $tex = $self->{texture}[$tile] ||=
788 new_from_image CFPlus::Texture 821 new CFPlus::Texture
789 $data, minify => 1, mipmap => 1; 822 tile => $tile, minify => 1, mipmap => 1, delay => 1;
790 823
791 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
792 $self->{map_widget}->update;
793
794 $_->() for @{(delete $self->{face_cb}{$id}) || []}; 824 $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []};
795} 825}
796 826
797sub connect_face_update { 827sub connect_face_update {
798 my ($self, $id, $cb) = @_; 828 my ($self, $id, $cb) = @_;
799 829
994 } 1024 }
995 1025
996 $::FLOORBOX->add_at (@add); 1026 $::FLOORBOX->add_at (@add);
997 }); 1027 });
998 1028
999 $::WANT_REFRESH++; 1029 $::WANT_REFRESH->start;
1000} 1030}
1001 1031
1002sub set_opencont { 1032sub set_opencont {
1003 my ($conn, $tag, $name) = @_; 1033 my ($conn, $tag, $name) = @_;
1004 $conn->{open_container} = $tag; 1034 $conn->{open_container} = $tag;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines