--- deliantra/Deliantra-Client/DC/Protocol.pm 2008/05/08 21:30:23 1.196 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2008/05/20 02:47:21 1.197 @@ -686,20 +686,27 @@ sub flush_map { my ($self) = @_; - my $map_info = delete $self->{map_info} - or return; + return unless $self->{map_info}; - my ($hash, $x, $y, $w, $h) = @$map_info; + for my $map_info (values %{ $self->{map_cache} || {} }) { + my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; - my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); - $self->{map_cache_new}{$hash} = \$data; - DC::DB::put $self->{mapcache} => $hash => $data, sub { }; + my $data = $self->{map}->get_rect ($x, $y, $w, $h); + + if ($data ne $$rdata) { + $map_info->[1] = \$data; + my $cdata = Compress::LZF::compress $data; + warn "db_put $hash $x $y ", length $data, " > ", length $cdata; + DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; + } + } } sub map_clear { my ($self) = @_; $self->flush_map; + delete $self->{map_info}; delete $self->{neigh_map}; $self->{map}->clear; @@ -730,36 +737,37 @@ }; } -sub load_map($$$) { - my ($self, $hash, $x, $y) = @_; +sub load_map($$$$$$) { + my ($self, $hash, $x, $y, $w, $h) = @_; - my $gen = $self->{map_change_gen}; + my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; my $cb = sub { - return unless $gen == $self->{map_change_gen}; + $map_info->[1] = \$_[0]; - my ($data) = @_; + return if 2505 == length $_[0];#d# + warn "map_cache $hash $x $y $w $h ", length $_[0];#d# - if (defined $data) { - $self->{map_cache_new}{$hash} = \$data; - - my $data = Compress::LZF::decompress $data; - - my $inprogress = @{ $self->{bg_fetch} || [] }; - unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); - $self->bg_fetch unless $inprogress; - } + my $inprogress = @{ $self->{bg_fetch} || [] }; + unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); + $self->bg_fetch unless $inprogress; }; - if (my $rdata = $self->{map_cache_old}{$hash}) { - $cb->($$rdata); + if (my $map_info = $self->{map_cache_old}{$hash}) { + $cb->(${ $map_info->[1] }); } else { - DC::DB::get $self->{mapcache} => $hash, $cb; + my $gen = $self->{map_change_gen}; + + DC::DB::get $self->{mapcache} => $hash, sub { + return unless $gen == $self->{map_change_gen}; + return unless defined $_[0]; + $cb->(Compress::LZF::decompress $_[0]); + }; } } # hardcode /world/world_xxx_xxx map names, the savings are enourmous, -# (server resource,s latency, bandwidth), so this hack is warranted. +# (server resources, latency, bandwidth), so this hack is warranted. # the right fix is to make real tiled maps with an overview file sub send_mapinfo { my ($self, $data, $cb) = @_; @@ -794,7 +802,7 @@ # this method does a "flood fill" into every tile direction # it assumes that tiles are arranged in a rectangular grid, # i.e. a map is the same as the left of the right map etc. -# failure to comply are harmless and result in display errors +# failure to comply is harmless and results in display errors # at worst. sub flood_fill { my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; @@ -840,7 +848,7 @@ $x += $self->{map}->ox; $y += $self->{map}->oy; - $self->load_map ($hash, $x, $y) + $self->load_map ($hash, $x, $y, $w, $h) unless $self->{neigh_map}{$hash}[5]++;#d# $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; @@ -858,7 +866,7 @@ $self->flush_map; ++$self->{map_change_gen}; - $self->{map_cache_old} = delete $self->{map_cache_new}; + $self->{map_cache_old} = delete $self->{map_cache}; my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); @@ -880,7 +888,7 @@ (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; $::STATWIDS->{map}->set_text ("Map: " . $map); - $self->load_map ($hash, $x, $y); + $self->load_map ($hash, $x, $y, $w, $h); $self->flood_fill (0, 0, 0, "", $hash, $flags); }