--- deliantra/server/ext/map-world.ext 2007/04/17 20:41:15 1.21 +++ deliantra/server/ext/map-world.ext 2007/04/18 14:24:09 1.22 @@ -32,32 +32,20 @@ } } - my $pid = open my $pipe, "-|"; + my $data = cf::fork_call { + open my $fh, "convert \Q$path.png\E -depth 8 rgb:- |" + or die "convert: $!"; + binmode $fh; - defined $pid - or cf::cleanup "fork: $!"; + $size * 3 == read $fh, my $data, $size * 3 + or die "$path.png, expected $size rgb triplets: $!"; - unless ($pid) { - eval { - open my $fh, "convert \Q$path.png\E -depth 8 rgb:- |" - or die "convert: $!"; - binmode $fh; + cf::_quantise $data, [map "$_$plt{$_}", keys %plt]; - $size * 3 == read $fh, my $data, $size * 3 - or die "$path.png, expected $size rgb triplets: $!"; + $data + }; - cf::_quantise $data, [map "$_$plt{$_}", keys %plt]; - - binmode STDOUT; - syswrite STDOUT, $data; - }; - warn $@ if $@; - cf::_exit; - } - - $pipe = Coro::Handle::unblock $pipe; - binmode $pipe; - $size == read $pipe, my $data, $size + $size == length $data or cf::cleanup "$path.png, expected $size index octets ($!)"; ($data, \@plt) @@ -66,32 +54,41 @@ sub load_gridmap($) { my ($path) = @_; -# if (! -e "/tmp/xxxx.gridmap") { - 0 < aio_load "$path/gridmap.meta", my $map - or cf::cleanup "$path/gridmap.meta: $!\n"; + my $map = cf::cache "ext::map-world/gridmap" => + [ + "$path/gridmap.meta", + "$path/gridmap.arch.plt", + "$path/gridmap.arch.png", + "$path/gridmap.regn.plt", + "$path/gridmap.regn.png", + ], + 1 => sub { + my ($src) = @_; + + my $map = cf::from_json $src->[0]; - $map = cf::from_json $map; + my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h} + or cf::cleanup "$path/gridmap.meta: empty gridmap?"; - my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h} - or cf::cleanup "$path/gridmap.meta: empty gridmap?"; + ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size; + ($map->{reg_data}, $map->{reg_plt}) = load_indexed "$path/gridmap.regn", $size; - ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size; - ($map->{reg_data}, $map->{reg_plt}) = load_indexed "$path/gridmap.regn", $size; + Coro::Storable::freeze $map + }; -# Storable::nstore $map, "/tmp/xxxx.gridmap" if 0;#d# + Coro::Storable::thaw $map +} - $map -# } else { -# Storable::retrieve "/tmp/xxxx.gridmap"; -# } +sub reload() { + $WORLD = load_gridmap sprintf "%s/%s/%s", cf::datadir, cf::mapdir, "world"; + warn "worldmap gridmap loaded."; } # this is contorted, but likely the correct way to acquire the lock :) cf::sync_job { my $guard = cf::lock_acquire "ext::world_gridmap"; cf::async_ext { - $WORLD = load_gridmap sprintf "%s/%s/%s", cf::datadir, cf::mapdir, "world"; - warn "worldmap gridmap loaded."; + reload; undef $guard; } };