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.22 by root, Wed Apr 18 14:24:09 2007 UTC vs.
Revision 1.38 by root, Thu Apr 29 07:32:34 2010 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 an 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# - might get reused as a generic tiled map 7# - might get reused as a generic tiled map
8
9cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
8 10
9use Coro::Handle; 11use Coro::Handle;
10use Coro::AIO; 12use Coro::AIO;
11 13
12our $WORLD; 14our $WORLD;
63 "$path/gridmap.regn.png", 65 "$path/gridmap.regn.png",
64 ], 66 ],
65 1 => sub { 67 1 => sub {
66 my ($src) = @_; 68 my ($src) = @_;
67 69
68 my $map = cf::from_json $src->[0]; 70 my $map = cf::decode_json $src->[0];
69 71
70 my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h} 72 my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h}
71 or cf::cleanup "$path/gridmap.meta: empty gridmap?"; 73 or cf::cleanup "$path/gridmap.meta: empty gridmap?";
72 74
73 ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size; 75 ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size;
78 80
79 Coro::Storable::thaw $map 81 Coro::Storable::thaw $map
80} 82}
81 83
82sub reload() { 84sub reload() {
83 $WORLD = load_gridmap sprintf "%s/%s/%s", cf::datadir, cf::mapdir, "world"; 85 $WORLD = load_gridmap "$MAPDIR/world";
84 warn "worldmap gridmap loaded."; 86 cf::trace "worldmap gridmap loaded.\n";
85} 87}
86 88
87# this is contorted, but likely the correct way to acquire the lock :) 89{
88cf::sync_job {
89 my $guard = cf::lock_acquire "ext::world_gridmap"; 90 my $guard = cf::lock_acquire "ext::world_gridmap";
90 cf::async_ext {
91 reload;
92 undef $guard;
93 }
94};
95 91
96cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); 92 cf::post_init {
93 cf::async_ext {
94 $Coro::current->{desc} = "worldmap loader";
95 reload;
96 undef $guard;
97 };
98 };
99}
97 100
98sub wxwy { 101sub wxwy {
99 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} 102 $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$}
100 ? ($1, $2) 103 ? ($1, $2)
101 : (0, 0) 104 : (0, 0)
119 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; 122 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0;
120 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; 123 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999;
121 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; 124 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999;
122 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; 125 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0;
123 126
124 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d.map", cf::datadir, cf::mapdir, $x, $y 127 my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y;
125 if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; 128
129 $self->{load_path} = $overlay
130 unless Coro::AIO::aio_stat $overlay;
131
132 $self->{need_create_treasure} = 1;
126 133
127 1 134 1
128} 135}
129 136
130sub fill { 137sub fill {
131 my ($self) = @_; 138 my ($self) = @_;
132 139
133 $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt}); 140 $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt});#d#
134 $self->default_region (cf::region::find $WORLD->{reg_plt}[0]); 141 $self->default_region (cf::region::find $WORLD->{reg_plt}[0]);
135} 142}
136 143
137sub load { 144sub load {
138 my ($self) = @_; 145 my ($self) = @_;
140 if ($self->{load_path}) { 147 if ($self->{load_path}) {
141 $self->SUPER::load; 148 $self->SUPER::load;
142 } else { 149 } else {
143 $self->alloc; 150 $self->alloc;
144 $self->fill; 151 $self->fill;
145 $self->in_memory (cf::MAP_IN_MEMORY); 152 $self->in_memory (cf::MAP_ACTIVE);
153 $self->activate;
146 } 154 }
147} 155}
148 156
149sub post_load { 157sub post_load {
150 my ($self) = @_; 158 my ($self) = @_;
151 159
160 {
152 my $guard = cf::lock_acquire "ext::world_gridmap"; 161 my $guard = cf::lock_acquire "ext::world_gridmap";
153 162
154 my ($x, $y) = $self->wxwy; 163 my ($x, $y) = $self->wxwy;
155 164
156 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { 165 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) {
157 my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; 166 my $stride = $WORLD->{grid_w} * $WORLD->{tile_w};
158 my $top = ($y - 100) * $WORLD->{tile_h} * $stride 167 my $top = ($y - 100) * $WORLD->{tile_h} * $stride
159 + ($x - 100) * $WORLD->{tile_w}; 168 + ($x - 100) * $WORLD->{tile_w};
160 169
161 $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); 170 $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt});
162 $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); 171 $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt});
163 172
164 } else { 173 } else {
165 $self->fill; 174 $self->fill;
175 }
166 } 176 }
177
178 $self->create_region_treasure
179 if delete $self->{need_create_treasure};
167} 180}
168 181
1691 1821
170 183

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines