--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/08/09 03:40:01 1.147 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2007/08/13 14:15:09 1.152 @@ -508,8 +508,36 @@ sub feed_map1a { my ($self, $data) = @_; - $self->{map}->map1a_update ($data, $self->{setup}{extmap}); - $self->{map_widget}->update; + my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); + my $delay; + + for my $tile (@$missing) { + next if $self->{delay}{$tile}; + + $delay = 1; + + if (my $tex = $::CONN->{texture}[$tile]) { + $tex->upload; + } else { + $self->{delay}{$tile} = 1; + + # we assume the face is in-flight and will eventually come + push @{$self->{face_cb}{$tile}}, sub { + delete $self->{delay}{$tile}; + $_[0]->upload; + }; + } + } + + if ($delay) { + # delay the map drawing a tiny bit in the hope of getting the missing fetched + Event->timer (after => 0.03, cb => sub { + $_[0]->w->cancel; + $self->{map_widget}->update; + }); + } else { + $self->{map_widget}->update; + } } sub magicmap { @@ -556,8 +584,10 @@ return unless $self->{map}; # stop when destroyed - $self->have_tile ($id) - if $exists; + if ($exists) { + $self->have_tile ($id); + $self->{texture}[$id]->upload; + } $self->bg_fetch; }; @@ -568,20 +598,27 @@ my $gen = $self->{map_change_gen}; - CFPlus::DB::get $self->{mapcache} => $hash, sub { + my $cb = sub { return unless $gen == $self->{map_change_gen}; my ($data) = @_; if (defined $data) { - $data = Compress::LZF::decompress $data; - #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# + $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; } }; + + if (my $rdata = $self->{map_cache_old}{$hash}) { + $cb->($$rdata); + } else { + CFPlus::DB::get $self->{mapcache} => $hash, $cb; + } } # hardcode /world/world_xxx_xxx map names, the savings are enourmous, @@ -684,6 +721,7 @@ $self->flush_map; ++$self->{map_change_gen}; + $self->{map_cache_old} = delete $self->{map_cache_new}; my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); @@ -723,7 +761,6 @@ CFPlus::DB::get tilecache => $id, $cb; } elsif ($face->{type} & 1) { # with metadata - #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); CFPlus::DB::get res_meta => $face->{name}, $cb; } } @@ -780,11 +817,11 @@ return unless $self->{map}; - $self->{texture}[$tile] ||= my $tex = + my $tex = $self->{texture}[$tile] ||= new CFPlus::Texture tile => $tile, minify => 1, mipmap => 1, delay => 1; - $_->() for @{(delete $self->{face_cb}{$tile}) || []}; + $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []}; } sub connect_face_update { @@ -989,7 +1026,7 @@ $::FLOORBOX->add_at (@add); }); - $::WANT_REFRESH++; + $::WANT_REFRESH->start; } sub set_opencont {