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.195 by root, Thu May 8 20:19:49 2008 UTC vs.
Revision 1.198 by root, Tue May 20 02:49:56 2008 UTC

64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
65 for my $ws (values %{delete $self->{widgetset} || {}}) { 65 for my $ws (values %{delete $self->{widgetset} || {}}) {
66 $_->destroy 66 $_->destroy
67 for values %{delete $ws->{w} || {}}; 67 for values %{delete $ws->{w} || {}};
68 } 68 }
69
70 delete $self->{items};
71 $::INV->clear;
72 $::INVR_HB->clear;
73 $::FLOORBOX->clear;
69 }); 74 });
70 75
71 $self->{map_widget}->add_command (@$_) 76 $self->{map_widget}->add_command (@$_)
72 for @cmd_help; 77 for @cmd_help;
73 78
679} 684}
680 685
681sub flush_map { 686sub flush_map {
682 my ($self) = @_; 687 my ($self) = @_;
683 688
684 my $map_info = delete $self->{map_info} 689 return unless $self->{map_info};
685 or return;
686 690
691 for my $map_info (values %{ $self->{map_cache} || {} }) {
687 my ($hash, $x, $y, $w, $h) = @$map_info; 692 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
688 693
689 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 694 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
690 $self->{map_cache_new}{$hash} = \$data; 695
696 if ($data ne $$rdata) {
697 $map_info->[1] = \$data;
698 my $cdata = Compress::LZF::compress $data;
691 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 699 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
700 }
701 }
692} 702}
693 703
694sub map_clear { 704sub map_clear {
695 my ($self) = @_; 705 my ($self) = @_;
696 706
697 $self->flush_map; 707 $self->flush_map;
708 delete $self->{map_info};
698 delete $self->{neigh_map}; 709 delete $self->{neigh_map};
699 710
700 $self->{map}->clear; 711 $self->{map}->clear;
701 delete $self->{map_widget}{magicmap}; 712 delete $self->{map_widget}{magicmap};
702} 713}
723 734
724 $self->bg_fetch; 735 $self->bg_fetch;
725 }; 736 };
726} 737}
727 738
728sub load_map($$$) { 739sub load_map($$$$$$) {
729 my ($self, $hash, $x, $y) = @_; 740 my ($self, $hash, $x, $y, $w, $h) = @_;
730 741
731 my $gen = $self->{map_change_gen}; 742 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
732 743
733 my $cb = sub { 744 my $cb = sub {
734 return unless $gen == $self->{map_change_gen}; 745 $map_info->[1] = \$_[0];
735 746
736 my ($data) = @_;
737
738 if (defined $data) {
739 $self->{map_cache_new}{$hash} = \$data;
740
741 my $data = Compress::LZF::decompress $data;
742
743 my $inprogress = @{ $self->{bg_fetch} || [] }; 747 my $inprogress = @{ $self->{bg_fetch} || [] };
744 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 748 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
745 $self->bg_fetch unless $inprogress; 749 $self->bg_fetch unless $inprogress;
746 }
747 }; 750 };
748 751
749 if (my $rdata = $self->{map_cache_old}{$hash}) { 752 if (my $map_info = $self->{map_cache_old}{$hash}) {
750 $cb->($$rdata); 753 $cb->(${ $map_info->[1] });
751 } else { 754 } else {
755 my $gen = $self->{map_change_gen};
756
752 DC::DB::get $self->{mapcache} => $hash, $cb; 757 DC::DB::get $self->{mapcache} => $hash, sub {
758 return unless $gen == $self->{map_change_gen};
759 return unless defined $_[0];
760 $cb->(Compress::LZF::decompress $_[0]);
761 };
753 } 762 }
754} 763}
755 764
756# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 765# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
757# (server resource,s latency, bandwidth), so this hack is warranted. 766# (server resources, latency, bandwidth), so this hack is warranted.
758# the right fix is to make real tiled maps with an overview file 767# the right fix is to make real tiled maps with an overview file
759sub send_mapinfo { 768sub send_mapinfo {
760 my ($self, $data, $cb) = @_; 769 my ($self, $data, $cb) = @_;
761 770
762 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 771 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
787} 796}
788 797
789# this method does a "flood fill" into every tile direction 798# this method does a "flood fill" into every tile direction
790# it assumes that tiles are arranged in a rectangular grid, 799# it assumes that tiles are arranged in a rectangular grid,
791# i.e. a map is the same as the left of the right map etc. 800# i.e. a map is the same as the left of the right map etc.
792# failure to comply are harmless and result in display errors 801# failure to comply is harmless and results in display errors
793# at worst. 802# at worst.
794sub flood_fill { 803sub flood_fill {
795 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 804 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
796 805
797 # the server does not allow map paths > 6 806 # the server does not allow map paths > 6
833 return if $mode ne "spatial"; 842 return if $mode ne "spatial";
834 843
835 $x += $self->{map}->ox; 844 $x += $self->{map}->ox;
836 $y += $self->{map}->oy; 845 $y += $self->{map}->oy;
837 846
838 $self->load_map ($hash, $x, $y) 847 $self->load_map ($hash, $x, $y, $w, $h)
839 unless $self->{neigh_map}{$hash}[5]++;#d# 848 unless $self->{neigh_map}{$hash}[5]++;#d#
840 849
841 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 850 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
842 851
843 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 852 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
851 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 860 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
852 861
853 $self->flush_map; 862 $self->flush_map;
854 863
855 ++$self->{map_change_gen}; 864 ++$self->{map_change_gen};
856 $self->{map_cache_old} = delete $self->{map_cache_new}; 865 $self->{map_cache_old} = delete $self->{map_cache};
857 866
858 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 867 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
859 868
860 my $mapmapw = $self->{mapmap}->{w}; 869 my $mapmapw = $self->{mapmap}->{w};
861 my $mapmaph = $self->{mapmap}->{h}; 870 my $mapmaph = $self->{mapmap}->{h};
873 $self->{map_info} = [$hash, $x, $y, $w, $h]; 882 $self->{map_info} = [$hash, $x, $y, $w, $h];
874 883
875 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 884 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
876 $::STATWIDS->{map}->set_text ("Map: " . $map); 885 $::STATWIDS->{map}->set_text ("Map: " . $map);
877 886
878 $self->load_map ($hash, $x, $y); 887 $self->load_map ($hash, $x, $y, $w, $h);
879 $self->flood_fill (0, 0, 0, "", $hash, $flags); 888 $self->flood_fill (0, 0, 0, "", $hash, $flags);
880} 889}
881 890
882sub face_find { 891sub face_find {
883 my ($self, $facenum, $face, $cb) = @_; 892 my ($self, $facenum, $face, $cb) = @_;
1210sub set_opencont { 1219sub set_opencont {
1211 my ($conn, $tag, $name) = @_; 1220 my ($conn, $tag, $name) = @_;
1212 $conn->{open_container} = $tag; 1221 $conn->{open_container} = $tag;
1213 update_floorbox; 1222 update_floorbox;
1214 1223
1215 $::INVR_HB->clear (); 1224 $::INVR_HB->clear;
1216 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); 1225 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1217 1226
1218 if ($tag != 0) { # Floor isn't closable, is it? 1227 if ($tag != 0) { # Floor isn't closable, is it?
1219 $::INVR_HB->add (new DC::UI::Button 1228 $::INVR_HB->add (new DC::UI::Button
1220 text => "Close container", 1229 text => "Close container",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines