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 | |
|
|
9 | cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); |
8 | |
10 | |
9 | use Coro::Handle; |
11 | use Coro::Handle; |
10 | use Coro::AIO; |
12 | use Coro::AIO; |
11 | |
13 | |
12 | our $WORLD; |
14 | our $WORLD; |
… | |
… | |
86 | |
88 | |
87 | # this is contorted, but likely the correct way to acquire the lock :) |
89 | # this is contorted, but likely the correct way to acquire the lock :) |
88 | cf::sync_job { |
90 | cf::sync_job { |
89 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
91 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
90 | cf::async_ext { |
92 | cf::async_ext { |
|
|
93 | $Coro::current->{desc} = "worldmap loader"; |
91 | reload; |
94 | reload; |
92 | undef $guard; |
95 | undef $guard; |
93 | }; |
96 | }; |
94 | }; |
97 | }; |
95 | |
|
|
96 | cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); |
|
|
97 | |
98 | |
98 | sub wxwy { |
99 | sub wxwy { |
99 | $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} |
100 | $_[0]->path =~ m{/world/world_(\d\d\d)_(\d\d\d)$} |
100 | ? ($1, $2) |
101 | ? ($1, $2) |
101 | : (0, 0) |
102 | : (0, 0) |
… | |
… | |
119 | $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; |
120 | $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; |
121 | $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; |
122 | $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; |
123 | $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; |
123 | |
124 | |
124 | $self->{load_path} = sprintf "%s/world-overlay/world_%03d_%03d.map", $cf::MAPDIR, $x, $y |
125 | my $overlay = sprintf "%s/world/world_%03d_%03d.map", $cf::MAPDIR, $x, $y; |
125 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
126 | |
|
|
127 | $self->{load_path} = $overlay |
|
|
128 | unless Coro::AIO::aio_stat $overlay; |
126 | |
129 | |
127 | $self->{need_create_treasure} = 1; |
130 | $self->{need_create_treasure} = 1; |
128 | |
131 | |
129 | 1 |
132 | 1 |
130 | } |
133 | } |
… | |
… | |
143 | $self->SUPER::load; |
146 | $self->SUPER::load; |
144 | } else { |
147 | } else { |
145 | $self->alloc; |
148 | $self->alloc; |
146 | $self->fill; |
149 | $self->fill; |
147 | $self->in_memory (cf::MAP_IN_MEMORY); |
150 | $self->in_memory (cf::MAP_IN_MEMORY); |
|
|
151 | $self->activate; |
148 | } |
152 | } |
149 | } |
153 | } |
150 | |
154 | |
151 | sub post_load { |
155 | sub post_load { |
152 | my ($self) = @_; |
156 | my ($self) = @_; |
153 | |
157 | |
|
|
158 | { |
154 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
159 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
155 | |
160 | |
156 | my ($x, $y) = $self->wxwy; |
161 | my ($x, $y) = $self->wxwy; |
157 | |
162 | |
158 | if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { |
163 | if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { |
159 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
164 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
160 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
165 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
161 | + ($x - 100) * $WORLD->{tile_w}; |
166 | + ($x - 100) * $WORLD->{tile_w}; |
162 | |
167 | |
163 | $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); |
168 | $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); |
164 | $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); |
169 | $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); |
165 | |
170 | |
166 | } else { |
171 | } else { |
167 | $self->fill; |
172 | $self->fill; |
|
|
173 | } |
168 | } |
174 | } |
169 | |
175 | |
170 | $self->create_region_treasure |
176 | $self->create_region_treasure |
171 | if delete $self->{need_create_treasure}; |
177 | if delete $self->{need_create_treasure}; |
172 | } |
178 | } |