--- deliantra/server/ext/map-world.ext 2007/01/27 23:59:29 1.8 +++ deliantra/server/ext/map-world.ext 2007/02/15 03:19:02 1.15 @@ -69,18 +69,24 @@ sub load_gridmap($) { my ($path) = @_; - 0 < aio_load "$path/gridmap.meta", my $map - or cf::cleanup "$path/gridmap.meta: $!\n"; + if (! -e "/tmp/xxxx.gridmap") { + 0 < aio_load "$path/gridmap.meta", my $map + or cf::cleanup "$path/gridmap.meta: $!\n"; - $map = cf::from_json $map; + $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; - $map + Storable::nstore $map, "/tmp/xxxx.gridmap";#d# + + $map + } else { + Storable::retrieve "/tmp/xxxx.gridmap"; + } } # this is contorted, but likely the correct way to acquire the lock :) @@ -116,21 +122,24 @@ $self->outdoor (1); $self->default_region (undef); -# $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; -# $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; -# $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; -# $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; - $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 100; - $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 129; - $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 129; - $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 100; + $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; + $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; + $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; + $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; - $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y + $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d.map", cf::datadir, cf::mapdir, $x, $y if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; 1 } +sub fill { + my ($self) = @_; + + $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt}); + $self->default_region (cf::region::find $WORLD->{reg_plt}[0]); +} + sub load { my ($self) = @_; @@ -138,16 +147,7 @@ $self->SUPER::load; } else { $self->alloc; - - for my $X (0 .. $WORLD->{tile_w} - 1) { - Coro::cede; - for my $Y (0 .. $WORLD->{tile_h} - 1) { - my $ob = cf::object::new "deep_sea"; - $self->insert ($ob, $X, $Y); - } - } - $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1); - + $self->fill; $self->in_memory (cf::MAP_IN_MEMORY); } } @@ -159,28 +159,17 @@ my ($x, $y) = $self->wxwy; - return - unless $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; + 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 = $WORLD->{grid_w} * $WORLD->{tile_w}; - my $top = ($y - 100) * $WORLD->{tile_h} * $stride - + ($x - 100) * $WORLD->{tile_w}; - - my $reg; - - for my $Y (0 .. $WORLD->{tile_h} - 1) { - Coro::cede; - my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w}; - $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w}; - for my $X (0 .. $WORLD->{tile_w} - 1) { - next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); - my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X]; - $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); - $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); - } - } + $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); + $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); - $self->set_regiondata ($reg, $WORLD->{reg_plt}); + } else { + $self->fill; + } } 1