--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/04/06 08:09:43 1.97 +++ 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; @@ -417,6 +422,8 @@ CFPlus::DB::get tilecache => $id, sub { my ($data) = @_; + return unless $self->{map}; # stop when destroyed + $self->set_texture ($id => $data) if defined $data; @@ -427,7 +434,11 @@ 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) { @@ -435,7 +446,7 @@ #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# my $inprogress = @{ $self->{bg_fetch} || [] }; - push @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); + unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); $self->bg_fetch unless $inprogress; } }; @@ -512,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"; @@ -537,6 +551,8 @@ $self->flush_map; + ++$self->{map_change_gen}; + my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); my $mapmapw = $self->{mapmap}->{w}; @@ -585,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 {