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