--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/04/06 07:45:35 1.96 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2007/04/12 07:53:31 1.101 @@ -17,9 +17,14 @@ use base 'Crossfire::Protocol::Base'; sub new { - my $class = shift; + my ($class, %arg) = @_; - my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); + my $self = $class->SUPER::new (%arg, + setup_req => { + extmap => 1, + %{$arg{setup_req} || {}}, + }, + ); $self->{map_widget}->clr_commands; @@ -404,24 +409,45 @@ delete $self->{map_widget}{magicmap}; } +sub bg_fetch { + my ($self) = @_; + + my $id; + + do { + $id = pop @{$self->{bg_fetch}} + or return; + } while $self->{texture}[$id]; + + CFPlus::DB::get tilecache => $id, sub { + my ($data) = @_; + + return unless $self->{map}; # stop when destroyed + + $self->set_texture ($id => $data) + if defined $data; + + $self->bg_fetch; + }; +} sub load_map($$$) { my ($self, $hash, $x, $y) = @_; + my $gen = $self->{map_change_gen}; + CFPlus::DB::get $self->{mapcache} => $hash, 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# - for my $id ($self->{map}->set_rect ($x, $y, $data)) { - CFPlus::DB::get tilecache => $id, sub { - my ($data) = @_; - - $self->set_texture ($id => $data) - if defined $data; - }; - } + + my $inprogress = @{ $self->{bg_fetch} || [] }; + unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); + $self->bg_fetch unless $inprogress; } }; } @@ -497,7 +523,10 @@ if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; } else { + my $gen = $self->{map_change_gen}; $self->send_mapinfo ("spatial $path$tile", sub { + return unless $gen == $self->{map_change_gen}; + my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; return if $mode ne "spatial"; @@ -522,6 +551,8 @@ $self->flush_map; + ++$self->{map_change_gen}; + my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); my $mapmapw = $self->{mapmap}->{w}; @@ -570,19 +601,21 @@ $self->set_texture ($face->{id} => delete $face->{image}); } +sub smooth_update { + my ($self, $facenum, $face) = @_; + + $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); +} + sub set_texture { my ($self, $id, $data) = @_; - $self->{texture}[$id] ||= do { - my $tex = - new_from_image CFPlus::Texture - $data, minify => 1, mipmap => 1; - - $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); - $self->{map_widget}->update; + $self->{texture}[$id] = my $tex = + new_from_image CFPlus::Texture + $data, minify => 1, mipmap => 1; - $tex - }; + $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); + $self->{map_widget}->update; } sub sound_play {