… | |
… | |
165 | |
165 | |
166 | our $EMERGENCY_POSITION; |
166 | our $EMERGENCY_POSITION; |
167 | |
167 | |
168 | sub cf::map::normalise; |
168 | sub cf::map::normalise; |
169 | |
169 | |
|
|
170 | sub in_main() { |
|
|
171 | $Coro::current == $Coro::main |
|
|
172 | } |
|
|
173 | |
170 | ############################################################################# |
174 | ############################################################################# |
171 | |
175 | |
172 | %REFLECT = (); |
176 | %REFLECT = (); |
173 | for (@REFLECT) { |
177 | for (@REFLECT) { |
174 | my $reflect = JSON::XS::decode_json $_; |
178 | my $reflect = JSON::XS::decode_json $_; |
… | |
… | |
261 | $Coro::State::DIEHOOK = sub { |
265 | $Coro::State::DIEHOOK = sub { |
262 | return unless $^S eq 0; # "eq", not "==" |
266 | return unless $^S eq 0; # "eq", not "==" |
263 | |
267 | |
264 | warn Carp::longmess $_[0]; |
268 | warn Carp::longmess $_[0]; |
265 | |
269 | |
266 | if ($Coro::current == $Coro::main) {#d# |
270 | if (in_main) {#d# |
267 | warn "DIEHOOK called in main context, Coro bug?\n";#d# |
271 | warn "DIEHOOK called in main context, Coro bug?\n";#d# |
268 | return;#d# |
272 | return;#d# |
269 | }#d# |
273 | }#d# |
270 | |
274 | |
271 | # kill coroutine otherwise |
275 | # kill coroutine otherwise |
… | |
… | |
1436 | if (length $@) { |
1440 | if (length $@) { |
1437 | warn "$v->{path}: $@\n"; |
1441 | warn "$v->{path}: $@\n"; |
1438 | |
1442 | |
1439 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1443 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1440 | if exists $v->{meta}{mandatory}; |
1444 | if exists $v->{meta}{mandatory}; |
|
|
1445 | |
|
|
1446 | warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; |
|
|
1447 | delete $todo{$k}; |
1441 | } else { |
1448 | } else { |
1442 | $done{$k} = delete $todo{$k}; |
1449 | $done{$k} = delete $todo{$k}; |
1443 | push @EXTS, $v->{pkg}; |
1450 | push @EXTS, $v->{pkg}; |
1444 | $progress = 1; |
1451 | $progress = 1; |
1445 | |
1452 | |
… | |
… | |
1688 | \@logins |
1695 | \@logins |
1689 | } |
1696 | } |
1690 | |
1697 | |
1691 | =item $player->maps |
1698 | =item $player->maps |
1692 | |
1699 | |
|
|
1700 | =item cf::player::maps $login |
|
|
1701 | |
1693 | Returns an arrayref of map paths that are private for this |
1702 | Returns an arrayref of map paths that are private for this |
1694 | player. May block. |
1703 | player. May block. |
1695 | |
1704 | |
1696 | =cut |
1705 | =cut |
1697 | |
1706 | |
… | |
… | |
1758 | |
1767 | |
1759 | =cut |
1768 | =cut |
1760 | |
1769 | |
1761 | sub find_by_path($) { |
1770 | sub find_by_path($) { |
1762 | my ($path) = @_; |
1771 | my ($path) = @_; |
|
|
1772 | |
|
|
1773 | $path =~ s/^~[^\/]*//; # skip ~login |
1763 | |
1774 | |
1764 | my ($match, $specificity); |
1775 | my ($match, $specificity); |
1765 | |
1776 | |
1766 | for my $region (list) { |
1777 | for my $region (list) { |
1767 | if ($region->{match} && $path =~ $region->{match}) { |
1778 | if ($region->{match} && $path =~ $region->{match}) { |
… | |
… | |
2212 | $MAP_PREFETCHER->prio (6); |
2223 | $MAP_PREFETCHER->prio (6); |
2213 | |
2224 | |
2214 | () |
2225 | () |
2215 | } |
2226 | } |
2216 | |
2227 | |
|
|
2228 | # common code, used by both ->save and ->swapout |
2217 | sub save { |
2229 | sub _save { |
2218 | my ($self) = @_; |
2230 | my ($self) = @_; |
2219 | |
|
|
2220 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2221 | |
2231 | |
2222 | $self->{last_save} = $cf::RUNTIME; |
2232 | $self->{last_save} = $cf::RUNTIME; |
2223 | |
2233 | |
2224 | return unless $self->dirty; |
2234 | return unless $self->dirty; |
2225 | |
2235 | |
… | |
… | |
2245 | } else { |
2255 | } else { |
2246 | $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); |
2256 | $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); |
2247 | } |
2257 | } |
2248 | } |
2258 | } |
2249 | |
2259 | |
|
|
2260 | sub save { |
|
|
2261 | my ($self) = @_; |
|
|
2262 | |
|
|
2263 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2264 | |
|
|
2265 | $self->_save; |
|
|
2266 | } |
|
|
2267 | |
2250 | sub swap_out { |
2268 | sub swap_out { |
2251 | my ($self) = @_; |
2269 | my ($self) = @_; |
2252 | |
2270 | |
2253 | # save first because save cedes |
|
|
2254 | $self->save; |
|
|
2255 | |
|
|
2256 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2271 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2257 | |
2272 | |
2258 | return if $self->players; |
|
|
2259 | return if $self->in_memory != cf::MAP_ACTIVE; |
2273 | return if $self->in_memory != cf::MAP_ACTIVE; |
2260 | return if $self->{deny_save}; |
2274 | return if $self->{deny_save}; |
|
|
2275 | return if $self->players; |
2261 | |
2276 | |
2262 | $self->in_memory (cf::MAP_SWAPPED); |
2277 | # first deactivate the map and "unlink" it from the core |
2263 | |
|
|
2264 | $self->deactivate; |
2278 | $self->deactivate; |
2265 | $_->clear_links_to ($self) for values %cf::MAP; |
2279 | $_->clear_links_to ($self) for values %cf::MAP; |
|
|
2280 | $self->in_memory (cf::MAP_SWAPPED); |
|
|
2281 | |
|
|
2282 | # then atomically save |
|
|
2283 | $self->_save; |
|
|
2284 | |
|
|
2285 | # then free the map |
2266 | $self->clear; |
2286 | $self->clear; |
2267 | } |
2287 | } |
2268 | |
2288 | |
2269 | sub reset_at { |
2289 | sub reset_at { |
2270 | my ($self) = @_; |
2290 | my ($self) = @_; |
… | |
… | |
2599 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
2619 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
2600 | |
2620 | |
2601 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
2621 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
2602 | if $self->map && $self->map->{path} ne "{link}"; |
2622 | if $self->map && $self->map->{path} ne "{link}"; |
2603 | |
2623 | |
2604 | $self->enter_map ($LINK_MAP || link_map, 10, 10); |
2624 | $self->enter_map ($LINK_MAP || link_map, 3, 3); |
2605 | } |
2625 | } |
2606 | |
2626 | |
2607 | sub cf::object::player::leave_link { |
2627 | sub cf::object::player::leave_link { |
2608 | my ($self, $map, $x, $y) = @_; |
2628 | my ($self, $map, $x, $y) = @_; |
2609 | |
2629 | |
… | |
… | |
3589 | |
3609 | |
3590 | (pop @POST_INIT)->(0) while @POST_INIT; |
3610 | (pop @POST_INIT)->(0) while @POST_INIT; |
3591 | }; |
3611 | }; |
3592 | |
3612 | |
3593 | cf::object::thawer::errors_are_fatal 0; |
3613 | cf::object::thawer::errors_are_fatal 0; |
|
|
3614 | warn "parse errors in files are no longer fatal from this point on.\n"; |
3594 | |
3615 | |
3595 | main_loop; |
3616 | main_loop; |
3596 | } |
3617 | } |
3597 | |
3618 | |
3598 | ############################################################################# |
3619 | ############################################################################# |
… | |
… | |
3775 | my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; |
3796 | my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; |
3776 | for my $name (keys %$leaf_symtab) { |
3797 | for my $name (keys %$leaf_symtab) { |
3777 | _gv_clear *{"$pkg$name"}; |
3798 | _gv_clear *{"$pkg$name"}; |
3778 | # use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; |
3799 | # use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; |
3779 | } |
3800 | } |
3780 | warn "cleared package $pkg\n";#d# |
|
|
3781 | } |
3801 | } |
3782 | |
3802 | |
3783 | sub do_reload_perl() { |
3803 | sub do_reload_perl() { |
3784 | # can/must only be called in main |
3804 | # can/must only be called in main |
3785 | if ($Coro::current != $Coro::main) { |
3805 | if (in_main) { |
3786 | warn "can only reload from main coroutine"; |
3806 | warn "can only reload from main coroutine"; |
3787 | return; |
3807 | return; |
3788 | } |
3808 | } |
3789 | |
3809 | |
3790 | return if $RELOAD++; |
3810 | return if $RELOAD++; |