--- deliantra/server/ext/map-world.ext 2007/01/21 13:40:42 1.4 +++ deliantra/server/ext/map-world.ext 2011/04/22 02:03:11 1.40 @@ -1,22 +1,42 @@ -#! perl # OPTIONAL +#! perl # optional # optional plug-in to speed up worldmap rendering by dynamically -# generating it out of a image +# generating it out of an image # - saves loading time (less data to read) # - saves temporary space (only overlay stuff needs to be saved) +# - might get reused as a generic tiled map -our $WORLD = Storable::retrieve cf::datadir . "/world.pst" - or die "unable to load world.pst"; +cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); -$WORLD->{version} == 1 - or die "world.pst version mismatch, expected version 1, got $WORLD->{version}"; +use Coro::Handle; +use Coro::AIO; -cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); +my $TILE_W = 50; +my $TILE_H = 50; -sub init { - my ($self) = @_; +my $GRID_W = 30; +my $GRID_H = 30; - 1 +our $ARCH; +our $REGN; + +sub reload() { + 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"; +} + +{ + my $guard = cf::lock_acquire "ext::world_gridmap"; + + cf::post_init { + cf::async_ext { + $Coro::current->{desc} = "worldmap loader"; + reload; + undef $guard; + }; + }; } sub wxwy { @@ -28,30 +48,40 @@ sub load_header_orig { my ($self) = @_; - $self->width ($WORLD->{tilew}); - $self->height ($WORLD->{tileh}); - my ($x, $y) = $self->wxwy; + my $guard = cf::lock_acquire "ext::world_gridmap"; + + $self->width ($TILE_W); + $self->height ($TILE_H); + + $self->name ("'The World' at +$x+$y"); + $self->msg ("worldmap dynamically created by map-world extension"); + $self->outdoor (1); + $self->default_region (cf::region::find "wilderness"); + $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->outdoor (1); + my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y; - $self->msg ("worldmap dynamically created by map-world extension"); - - #TODO: region - - $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y - if $x >= $WORLD->{minx} && $x <= $WORLD->{maxx} - && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy}; + $self->{load_path} = $overlay + unless Coro::AIO::aio_stat $overlay; + $self->{need_create_treasure} = 1; 1 } +sub fill { + my ($self) = @_; + + $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 { my ($self) = @_; @@ -59,40 +89,34 @@ $self->SUPER::load; } else { $self->alloc; - - for my $X (0 .. $WORLD->{tilew} - 1) { - Coro::cede; - for my $Y (0 .. $WORLD->{tileh} - 1) { - my $ob = cf::object::new "deep_sea"; - $self->insert ($ob, $X, $Y); - } - } - $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1); - - $self->in_memory (cf::MAP_IN_MEMORY); + $self->fill; + $self->in_memory (cf::MAP_ACTIVE); + $self->activate; } } sub post_load { my ($self) = @_; - my ($x, $y) = $self->wxwy; + { + my $guard = cf::lock_acquire "ext::world_gridmap"; + + my ($x, $y) = $self->wxwy; + + if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { + my $stride = $GRID_W * $TILE_W; + my $top = ($y - 100) * $TILE_H * $stride + + ($x - 100) * $TILE_W; - my $stride = ($WORLD->{maxx} - $WORLD->{minx} + 1) * $WORLD->{tilew}; - my $top = ($y - $WORLD->{miny}) * $WORLD->{tileh} * $stride - + ($x - $WORLD->{minx}) * $WORLD->{tilew}; - - for my $Y (0 .. $WORLD->{tileh} - 1) { - Coro::cede; - my $row = substr $WORLD->{data}, $top + $Y * $stride, $WORLD->{tilew}; - for my $X (0 .. $WORLD->{tilew} - 1) { - next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); - my $ob = cf::object::new $WORLD->{arch}[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 ($ARCH->{tbl}, $top, $stride, $ARCH->{plt}); + $self->set_regiondata ($REGN->{tbl}, $top, $stride, $REGN->{plt}); + + } else { + $self->fill; } } -} -1 + $self->create_region_treasure + if delete $self->{need_create_treasure}; +}