ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-world.ext
(Generate patch)

Comparing deliantra/server/ext/map-world.ext (file contents):
Revision 1.6 by root, Wed Jan 24 03:13:21 2007 UTC vs.
Revision 1.40 by root, Fri Apr 22 02:03:11 2011 UTC

1#! perl # OPTIONAL 1#! perl # optional
2 2
3# optional plug-in to speed up worldmap rendering by dynamically 3# optional plug-in to speed up worldmap rendering by dynamically
4# generating it out of a image 4# generating it out of an image
5# - saves loading time (less data to read) 5# - saves loading time (less data to read)
6# - saves temporary space (only overlay stuff needs to be saved) 6# - saves temporary space (only overlay stuff needs to be saved)
7 7# - might get reused as a generic tiled map
8our $WORLD = Storable::retrieve cf::datadir . "/world.pst"
9 or die "unable to load world.pst";
10
11$WORLD->{version} == 1
12 or die "world.pst version mismatch, expected version 1, got $WORLD->{version}";
13 8
14cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); 9cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
15 10
16sub init { 11use Coro::Handle;
17 my ($self) = @_; 12use Coro::AIO;
18 13
19 1 14my $TILE_W = 50;
15my $TILE_H = 50;
16
17my $GRID_W = 30;
18my $GRID_H = 30;
19
20our $ARCH;
21our $REGN;
22
23sub reload() {
24 cf::trace "loading world+100+100 table.\n";
25 $ARCH = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.arch";
26 $REGN = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.regn";
27 cf::trace "loaded world+100+100 table.\n";
28}
29
30{
31 my $guard = cf::lock_acquire "ext::world_gridmap";
32
33 cf::post_init {
34 cf::async_ext {
35 $Coro::current->{desc} = "worldmap loader";
36 reload;
37 undef $guard;
38 };
39 };
20} 40}
21 41
22sub wxwy { 42sub wxwy {
23 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} 43 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$}
24 ? ($1, $2) 44 ? ($1, $2)
26} 46}
27 47
28sub load_header_orig { 48sub load_header_orig {
29 my ($self) = @_; 49 my ($self) = @_;
30 50
31 $self->width ($WORLD->{tilew}); 51 my ($x, $y) = $self->wxwy;
32 $self->height ($WORLD->{tileh});
33 52
34 my ($x, $y) = $self->wxwy; 53 my $guard = cf::lock_acquire "ext::world_gridmap";
54
55 $self->width ($TILE_W);
56 $self->height ($TILE_H);
57
58 $self->name ("'The World' at +$x+$y");
59 $self->msg ("worldmap dynamically created by map-world extension");
60 $self->outdoor (1);
61 $self->default_region (cf::region::find "wilderness");
35 62
36 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; 63 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0;
37 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; 64 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999;
38 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; 65 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999;
39 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; 66 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0;
40 67
41 $self->outdoor (1); 68 my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y;
42 69
43 $self->name ("'The World' at +$x+$y"); 70 $self->{load_path} = $overlay
44 $self->msg ("worldmap dynamically created by map-world extension"); 71 unless Coro::AIO::aio_stat $overlay;
45 72
46 #TODO: region 73 $self->{need_create_treasure} = 1;
47
48 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y
49 if $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
50 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
51
52 74
53 1 75 1
76}
77
78sub fill {
79 my ($self) = @_;
80
81 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, $ARCH->{plt});
82 $self->default_region (cf::region::find $REGN->{plt}[0]);
54} 83}
55 84
56sub load { 85sub load {
57 my ($self) = @_; 86 my ($self) = @_;
58 87
59 if ($self->{load_path}) { 88 if ($self->{load_path}) {
60 $self->SUPER::load; 89 $self->SUPER::load;
61 } else { 90 } else {
62 $self->alloc; 91 $self->alloc;
63 92 $self->fill;
64 for my $X (0 .. $WORLD->{tilew} - 1) {
65 Coro::cede;
66 for my $Y (0 .. $WORLD->{tileh} - 1) {
67 my $ob = cf::object::new "deep_sea";
68 $self->insert ($ob, $X, $Y);
69 }
70 }
71 $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1);
72
73 $self->in_memory (cf::MAP_IN_MEMORY); 93 $self->in_memory (cf::MAP_ACTIVE);
94 $self->activate;
74 } 95 }
75} 96}
76 97
77sub post_load { 98sub post_load {
78 my ($self) = @_; 99 my ($self) = @_;
79 100
80 my ($x, $y) = $self->wxwy; 101 {
102 my $guard = cf::lock_acquire "ext::world_gridmap";
81 103
82 return 104 my ($x, $y) = $self->wxwy;
83 unless $x >= $WORLD->{minx} && $x <= $WORLD->{maxx}
84 && $y >= $WORLD->{miny} && $y <= $WORLD->{maxy};
85 105
86 my $stride = ($WORLD->{maxx} - $WORLD->{minx} + 1) * $WORLD->{tilew}; 106 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) {
87 my $top = ($y - $WORLD->{miny}) * $WORLD->{tileh} * $stride 107 my $stride = $GRID_W * $TILE_W;
88 + ($x - $WORLD->{minx}) * $WORLD->{tilew}; 108 my $top = ($y - 100) * $TILE_H * $stride
109 + ($x - 100) * $TILE_W;
89 110
90 for my $Y (0 .. $WORLD->{tileh} - 1) { 111 $self->add_underlay ($ARCH->{tbl}, $top, $stride, $ARCH->{plt});
91 Coro::cede; 112 $self->set_regiondata ($REGN->{tbl}, $top, $stride, $REGN->{plt});
92 my $row = substr $WORLD->{data}, $top + $Y * $stride, $WORLD->{tilew}; 113
93 for my $X (0 .. $WORLD->{tilew} - 1) { 114 } else {
94 next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); 115 $self->fill;
95 my $ob = cf::object::new $WORLD->{arch}[ord substr $row, $X];
96 $ob->flag (cf::FLAG_NO_MAP_SAVE, 1);
97 $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY);
98 } 116 }
99 } 117 }
118
119 $self->create_region_treasure
120 if delete $self->{need_create_treasure};
100} 121}
101 122
1021
103

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines