… | |
… | |
684 | } |
684 | } |
685 | |
685 | |
686 | sub flush_map { |
686 | sub flush_map { |
687 | my ($self) = @_; |
687 | my ($self) = @_; |
688 | |
688 | |
689 | my $map_info = delete $self->{map_info} |
689 | return unless $self->{map_info}; |
690 | or return; |
|
|
691 | |
690 | |
|
|
691 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
692 | my ($hash, $x, $y, $w, $h) = @$map_info; |
692 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
693 | |
693 | |
694 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
694 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
695 | $self->{map_cache_new}{$hash} = \$data; |
695 | |
|
|
696 | if ($data ne $$rdata) { |
|
|
697 | $map_info->[1] = \$data; |
|
|
698 | my $cdata = Compress::LZF::compress $data; |
696 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
699 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
700 | } |
|
|
701 | } |
697 | } |
702 | } |
698 | |
703 | |
699 | sub map_clear { |
704 | sub map_clear { |
700 | my ($self) = @_; |
705 | my ($self) = @_; |
701 | |
706 | |
702 | $self->flush_map; |
707 | $self->flush_map; |
|
|
708 | delete $self->{map_info}; |
703 | delete $self->{neigh_map}; |
709 | delete $self->{neigh_map}; |
704 | |
710 | |
705 | $self->{map}->clear; |
711 | $self->{map}->clear; |
706 | delete $self->{map_widget}{magicmap}; |
712 | delete $self->{map_widget}{magicmap}; |
707 | } |
713 | } |
… | |
… | |
728 | |
734 | |
729 | $self->bg_fetch; |
735 | $self->bg_fetch; |
730 | }; |
736 | }; |
731 | } |
737 | } |
732 | |
738 | |
733 | sub load_map($$$) { |
739 | sub load_map($$$$$$) { |
734 | my ($self, $hash, $x, $y) = @_; |
740 | my ($self, $hash, $x, $y, $w, $h) = @_; |
735 | |
741 | |
736 | my $gen = $self->{map_change_gen}; |
742 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
737 | |
743 | |
738 | my $cb = sub { |
744 | my $cb = sub { |
739 | return unless $gen == $self->{map_change_gen}; |
745 | $map_info->[1] = \$_[0]; |
740 | |
746 | |
741 | my ($data) = @_; |
|
|
742 | |
|
|
743 | if (defined $data) { |
|
|
744 | $self->{map_cache_new}{$hash} = \$data; |
|
|
745 | |
|
|
746 | my $data = Compress::LZF::decompress $data; |
|
|
747 | |
|
|
748 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
747 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
749 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
748 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
750 | $self->bg_fetch unless $inprogress; |
749 | $self->bg_fetch unless $inprogress; |
751 | } |
|
|
752 | }; |
750 | }; |
753 | |
751 | |
754 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
752 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
755 | $cb->($$rdata); |
753 | $cb->(${ $map_info->[1] }); |
756 | } else { |
754 | } else { |
|
|
755 | my $gen = $self->{map_change_gen}; |
|
|
756 | |
757 | 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 | }; |
758 | } |
762 | } |
759 | } |
763 | } |
760 | |
764 | |
761 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
765 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
762 | # (server resource,s latency, bandwidth), so this hack is warranted. |
766 | # (server resources, latency, bandwidth), so this hack is warranted. |
763 | # 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 |
764 | sub send_mapinfo { |
768 | sub send_mapinfo { |
765 | my ($self, $data, $cb) = @_; |
769 | my ($self, $data, $cb) = @_; |
766 | |
770 | |
767 | 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)$%) { |
… | |
… | |
792 | } |
796 | } |
793 | |
797 | |
794 | # this method does a "flood fill" into every tile direction |
798 | # this method does a "flood fill" into every tile direction |
795 | # it assumes that tiles are arranged in a rectangular grid, |
799 | # it assumes that tiles are arranged in a rectangular grid, |
796 | # 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. |
797 | # failure to comply are harmless and result in display errors |
801 | # failure to comply is harmless and results in display errors |
798 | # at worst. |
802 | # at worst. |
799 | sub flood_fill { |
803 | sub flood_fill { |
800 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
804 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
801 | |
805 | |
802 | # the server does not allow map paths > 6 |
806 | # the server does not allow map paths > 6 |
… | |
… | |
838 | return if $mode ne "spatial"; |
842 | return if $mode ne "spatial"; |
839 | |
843 | |
840 | $x += $self->{map}->ox; |
844 | $x += $self->{map}->ox; |
841 | $y += $self->{map}->oy; |
845 | $y += $self->{map}->oy; |
842 | |
846 | |
843 | $self->load_map ($hash, $x, $y) |
847 | $self->load_map ($hash, $x, $y, $w, $h) |
844 | unless $self->{neigh_map}{$hash}[5]++;#d# |
848 | unless $self->{neigh_map}{$hash}[5]++;#d# |
845 | |
849 | |
846 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
850 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
847 | |
851 | |
848 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
852 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
856 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
860 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
857 | |
861 | |
858 | $self->flush_map; |
862 | $self->flush_map; |
859 | |
863 | |
860 | ++$self->{map_change_gen}; |
864 | ++$self->{map_change_gen}; |
861 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
865 | $self->{map_cache_old} = delete $self->{map_cache}; |
862 | |
866 | |
863 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
867 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
864 | |
868 | |
865 | my $mapmapw = $self->{mapmap}->{w}; |
869 | my $mapmapw = $self->{mapmap}->{w}; |
866 | my $mapmaph = $self->{mapmap}->{h}; |
870 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
878 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
882 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
879 | |
883 | |
880 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
884 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
881 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
885 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
882 | |
886 | |
883 | $self->load_map ($hash, $x, $y); |
887 | $self->load_map ($hash, $x, $y, $w, $h); |
884 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
888 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
885 | } |
889 | } |
886 | |
890 | |
887 | sub face_find { |
891 | sub face_find { |
888 | my ($self, $facenum, $face, $cb) = @_; |
892 | my ($self, $facenum, $face, $cb) = @_; |