#! perl # OPTIONAL # optional plug-in to speed up worldmap rendering by dynamically # generating it out of a image # - saves loading time (less data to read) # - saves temporary space (only overlay stuff needs to be saved) our $WORLD = Storable::retrieve cf::datadir . "/world.pst" or die "unable to load world.pst"; $WORLD->{version} == 1 or die "world.pst version mismatch, expected version 1, got $WORLD->{version}"; cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); sub init { my ($self) = @_; 1 } sub wxwy { $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} ? ($1, $2) : (0, 0) } sub load_header_orig { my ($self) = @_; $self->width ($WORLD->{tilew}); $self->height ($WORLD->{tileh}); my ($x, $y) = $self->wxwy; $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); $self->name ("'The World' at +$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}; 1 } sub load { my ($self) = @_; if ($self->{load_path}) { $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); } } sub post_load { my ($self) = @_; my ($x, $y) = $self->wxwy; return unless $x >= $WORLD->{minx} && $x <= $WORLD->{maxx} && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy}; 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); } } } 1