--- deliantra/server/ext/map-world.ext 2007/04/19 16:23:46 1.24 +++ deliantra/server/ext/map-world.ext 2008/12/28 06:59:26 1.36 @@ -1,4 +1,4 @@ -#! perl # OPTIONAL +#! perl # optional # optional plug-in to speed up worldmap rendering by dynamically # generating it out of an image @@ -6,6 +6,8 @@ # - saves temporary space (only overlay stuff needs to be saved) # - might get reused as a generic tiled map +cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); + use Coro::Handle; use Coro::AIO; @@ -65,7 +67,7 @@ 1 => sub { my ($src) = @_; - my $map = cf::from_json $src->[0]; + 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?"; @@ -84,16 +86,17 @@ 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 { - reload; - undef $guard; - }; -}; -cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); + cf::post_init { + cf::async_ext { + $Coro::current->{desc} = "worldmap loader"; + reload; + undef $guard; + }; + }; +} sub wxwy { $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} @@ -121,8 +124,10 @@ $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/world-overlay/world_%03d_%03d.map", $cf::MAPDIR, $x, $y - if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; + my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y; + + $self->{load_path} = $overlay + unless Coro::AIO::aio_stat $overlay; $self->{need_create_treasure} = 1; @@ -132,7 +137,7 @@ sub fill { my ($self) = @_; - $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt}); + $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]); } @@ -144,27 +149,30 @@ } else { $self->alloc; $self->fill; - $self->in_memory (cf::MAP_IN_MEMORY); + $self->in_memory (cf::MAP_ACTIVE); + $self->activate; } } sub post_load { my ($self) = @_; - my $guard = cf::lock_acquire "ext::world_gridmap"; + { + my $guard = cf::lock_acquire "ext::world_gridmap"; - my ($x, $y) = $self->wxwy; + 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}; + 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}; - $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 ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); + $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); - } else { - $self->fill; + } else { + $self->fill; + } } $self->create_region_treasure