--- deliantra/server/ext/map-world.ext 2010/05/04 21:45:42 1.39 +++ deliantra/server/ext/map-world.ext 2011/04/22 02:03:11 1.40 @@ -11,79 +11,20 @@ use Coro::Handle; use Coro::AIO; -our $WORLD; +my $TILE_W = 50; +my $TILE_H = 50; -sub load_indexed($$) { - my ($path, $size) = @_; +my $GRID_W = 30; +my $GRID_H = 30; - use bytes; - - 0 < aio_load "$path.plt", my $plt - or cf::cleanup "$path.plt: $!"; - - my %plt; - my @plt; - - for (split /\n/, $plt) { - my ($name, $rgb) = split /\s+/; - if (/^(\S+)\s+(\S+)$/) { - my ($name, $rgb) = ($1, $2); - $rgb = join "", map chr, map $_ * 17, map hex, split //, $rgb; - $plt{$rgb} = chr @plt; - push @plt, $name; - } - } - - my $data = cf::fork_call { - open my $fh, "convert \Q$path.png\E -depth 8 rgb:- |" - or die "convert: $!"; - binmode $fh; - - $size * 3 == read $fh, my $data, $size * 3 - or die "$path.png, expected $size rgb triplets: $!"; - - cf::_quantise $data, [map "$_$plt{$_}", keys %plt]; - - $data - }; - - $size == length $data - or cf::cleanup "$path.png, expected $size index octets ($!)"; - - ($data, \@plt) -} - -sub load_gridmap($) { - my ($path) = @_; - - 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::decode_json $src->[0]; - - 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; - - Coro::Storable::freeze $map - }; - - Coro::Storable::thaw $map -} +our $ARCH; +our $REGN; sub reload() { - $WORLD = load_gridmap "$MAPDIR/world"; - cf::trace "worldmap gridmap loaded.\n"; + cf::trace "loading world+100+100 table.\n"; + $ARCH = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.arch"; + $REGN = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.regn"; + cf::trace "loaded world+100+100 table.\n"; } { @@ -111,8 +52,8 @@ my $guard = cf::lock_acquire "ext::world_gridmap"; - $self->width ($WORLD->{tile_w}); - $self->height ($WORLD->{tile_h}); + $self->width ($TILE_W); + $self->height ($TILE_H); $self->name ("'The World' at +$x+$y"); $self->msg ("worldmap dynamically created by map-world extension"); @@ -137,8 +78,8 @@ sub fill { my ($self) = @_; - $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt});#d# - $self->default_region (cf::region::find $WORLD->{reg_plt}[0]); + $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, $ARCH->{plt}); + $self->default_region (cf::region::find $REGN->{plt}[0]); } sub load { @@ -163,12 +104,12 @@ my ($x, $y) = $self->wxwy; if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { - my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; - my $top = ($y - 100) * $WORLD->{tile_h} * $stride - + ($x - 100) * $WORLD->{tile_w}; + my $stride = $GRID_W * $TILE_W; + my $top = ($y - 100) * $TILE_H * $stride + + ($x - 100) * $TILE_W; - $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); - $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); + $self->add_underlay ($ARCH->{tbl}, $top, $stride, $ARCH->{plt}); + $self->set_regiondata ($REGN->{tbl}, $top, $stride, $REGN->{plt}); } else { $self->fill;