Deliantra-Client
view release on metacpan or search on metacpan
DC/Protocol.pm view on Meta::CPAN
$self->flush_map;
++$self->{map_change_gen};
$self->{map_cache_old} = delete $self->{map_cache};
my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
my $mapmapw = $self->{mapmap}->{w};
my $mapmaph = $self->{mapmap}->{h};
$self->{neigh_rect} = [
$ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
$ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
];
delete $self->{neigh_grid};
$x += $ox;
$y += $oy;
$self->{map_info} = [$hash, $x, $y, $w, $h];
(my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
$::STATWIDS->{map}->set_text ("Map: " . $map);
$self->load_map ($hash, $x, $y, $w, $h);
$self->flood_fill (0, 0, 0, "", $hash, $flags);
}
sub face_find {
my ($self, $facenum, $face, $cb) = @_;
if ($face->{type} == 0) { # FT_FACE
my $id = DC::DB::get_tile_id_sync $face->{name};
$face->{id} = $id;
$self->{map}->set_tileid ($facenum => $id);
DC::DB::get tilecache => $id, $cb;
} elsif ($face->{type} & 1) { # with metadata
DC::DB::get res_meta => $face->{name}, $cb;
} else { # no metadata
DC::DB::get res_data => $face->{name}, $cb;
}
}
sub face_update {
my ($self, $facenum, $face, $changed) = @_;
if ($face->{type} == 0) {
# image, FT_FACE
DC::DB::put tilecache => $face->{id} => $face->{data}, sub { }
if $changed;
$self->have_tile ($face->{id}, delete $face->{data});
} elsif ($face->{type} & 1) {
# split metadata case, FT_MUSIC, FT_SOUND
if ($changed) { # new data
my ($meta, $data) = unpack "(w/a*)*", $face->{data};
$face->{data} = $meta;
# rely on strict ordering here and also on later fetch
DC::DB::put res_data => $face->{name} => $data, sub { };
DC::DB::put res_meta => $face->{name} => $meta, sub { };
}
$face->{data} = $self->{json_coder}->decode ($face->{data});
::add_license ($face);
::message ({ markup => DC::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." })
if $changed;
if ($face->{type} == 3) { # FT_MUSIC
&::audio_music_push ($facenum);
} elsif ($face->{type} == 5) { # FT_SOUND
&::audio_sound_push ($facenum);
}
} else {
# flat resource case, FT_RSRC
DC::DB::put res_data => $face->{name} => $face->{data}, sub { }
if $changed;
}
if (my $cbs = $self->{face_cb}{$facenum}) {
$_->($face, $changed) for @$cbs;
}
}
sub smooth_update {
my ($self, $facenum, $face) = @_;
$self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
}
sub have_tile {
my ($self, $tile, $data) = @_;
return unless $self->{map};
my $tex = $self->{texture}[$tile] ||=
new DC::Texture
tile => $tile,
image => $data, delete_image => 1,
minify => 1;
if (my $cbs = delete $self->{tile_cb}{$tile}) {
$_->($tex) for @$cbs;
}
}
# call in non-void context registers a temporary
# hook with handle, otherwise its permanent
sub on_face_change {
my ($self, $num, $cb) = @_;
push @{$self->{face_cb}{$num}}, $cb;
( run in 0.556 second using v1.01-cache-2.11-cpan-71847e10f99 )