… | |
… | |
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; |
… | |
… | |
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; |
… | |
… | |
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) |