… | |
… | |
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}) { |
… | |
… | |
1831 | |
1842 | |
1832 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1843 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1833 | } |
1844 | } |
1834 | |
1845 | |
1835 | # also paths starting with '/' |
1846 | # also paths starting with '/' |
1836 | $EXT_MAP{"cf::map"} = [0, qr{^(?=/)}]; |
1847 | $EXT_MAP{"cf::map::wrap"} = [0, qr{^(?=/)}]; |
1837 | |
1848 | |
1838 | sub thawer_merge { |
1849 | sub thawer_merge { |
1839 | my ($self, $merge) = @_; |
1850 | my ($self, $merge) = @_; |
1840 | |
1851 | |
1841 | # we have to keep some variables in memory intact |
1852 | # we have to keep some variables in memory intact |
… | |
… | |
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 | |
|
|
2277 | # first deactivate the map and "unlink" it from the core |
|
|
2278 | $self->deactivate; |
|
|
2279 | $_->clear_links_to ($self) for values %cf::MAP; |
2262 | $self->in_memory (cf::MAP_SWAPPED); |
2280 | $self->in_memory (cf::MAP_SWAPPED); |
|
|
2281 | |
|
|
2282 | # then atomically save |
|
|
2283 | $self->_save; |
|
|
2284 | |
|
|
2285 | # then free the map |
|
|
2286 | $self->clear; |
|
|
2287 | } |
|
|
2288 | |
|
|
2289 | sub reset_at { |
|
|
2290 | my ($self) = @_; |
|
|
2291 | |
|
|
2292 | # TODO: safety, remove and allow resettable per-player maps |
|
|
2293 | return 1e99 if $self->{deny_reset}; |
|
|
2294 | |
|
|
2295 | my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; |
|
|
2296 | my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET; |
|
|
2297 | |
|
|
2298 | $time + $to |
|
|
2299 | } |
|
|
2300 | |
|
|
2301 | sub should_reset { |
|
|
2302 | my ($self) = @_; |
|
|
2303 | |
|
|
2304 | $self->reset_at <= $cf::RUNTIME |
|
|
2305 | } |
|
|
2306 | |
|
|
2307 | sub reset { |
|
|
2308 | my ($self) = @_; |
|
|
2309 | |
|
|
2310 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2311 | |
|
|
2312 | return if $self->players; |
|
|
2313 | |
|
|
2314 | warn "resetting map ", $self->path, "\n"; |
|
|
2315 | |
|
|
2316 | $self->in_memory (cf::MAP_SWAPPED); |
|
|
2317 | |
|
|
2318 | # need to save uniques path |
|
|
2319 | unless ($self->{deny_save}) { |
|
|
2320 | my $uniq = $self->uniq_path; utf8::encode $uniq; |
|
|
2321 | |
|
|
2322 | $self->_save_objects ($uniq, cf::IO_UNIQUES) |
|
|
2323 | if $uniq; |
|
|
2324 | } |
|
|
2325 | |
|
|
2326 | delete $cf::MAP{$self->path}; |
2263 | |
2327 | |
2264 | $self->deactivate; |
2328 | $self->deactivate; |
2265 | $_->clear_links_to ($self) for values %cf::MAP; |
2329 | $_->clear_links_to ($self) for values %cf::MAP; |
2266 | $self->clear; |
2330 | $self->clear; |
2267 | } |
|
|
2268 | |
|
|
2269 | sub reset_at { |
|
|
2270 | my ($self) = @_; |
|
|
2271 | |
|
|
2272 | # TODO: safety, remove and allow resettable per-player maps |
|
|
2273 | return 1e99 if $self->{deny_reset}; |
|
|
2274 | |
|
|
2275 | my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; |
|
|
2276 | my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET; |
|
|
2277 | |
|
|
2278 | $time + $to |
|
|
2279 | } |
|
|
2280 | |
|
|
2281 | sub should_reset { |
|
|
2282 | my ($self) = @_; |
|
|
2283 | |
|
|
2284 | $self->reset_at <= $cf::RUNTIME |
|
|
2285 | } |
|
|
2286 | |
|
|
2287 | sub reset { |
|
|
2288 | my ($self) = @_; |
|
|
2289 | |
|
|
2290 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2291 | |
|
|
2292 | return if $self->players; |
|
|
2293 | |
|
|
2294 | warn "resetting map ", $self->path, "\n"; |
|
|
2295 | |
|
|
2296 | $self->in_memory (cf::MAP_SWAPPED); |
|
|
2297 | |
|
|
2298 | # need to save uniques path |
|
|
2299 | unless ($self->{deny_save}) { |
|
|
2300 | my $uniq = $self->uniq_path; utf8::encode $uniq; |
|
|
2301 | |
|
|
2302 | $self->_save_objects ($uniq, cf::IO_UNIQUES) |
|
|
2303 | if $uniq; |
|
|
2304 | } |
|
|
2305 | |
|
|
2306 | delete $cf::MAP{$self->path}; |
|
|
2307 | |
|
|
2308 | $self->deactivate; |
|
|
2309 | $_->clear_links_to ($self) for values %cf::MAP; |
|
|
2310 | $self->clear; |
|
|
2311 | |
2331 | |
2312 | $self->unlink_save; |
2332 | $self->unlink_save; |
2313 | $self->destroy; |
2333 | $self->destroy; |
2314 | } |
2334 | } |
2315 | |
2335 | |
… | |
… | |
2323 | |
2343 | |
2324 | delete $cf::MAP{$self->path}; |
2344 | delete $cf::MAP{$self->path}; |
2325 | |
2345 | |
2326 | $self->unlink_save; |
2346 | $self->unlink_save; |
2327 | |
2347 | |
2328 | bless $self, "cf::map"; |
2348 | bless $self, "cf::map::wrap"; |
2329 | delete $self->{deny_reset}; |
2349 | delete $self->{deny_reset}; |
2330 | $self->{deny_save} = 1; |
2350 | $self->{deny_save} = 1; |
2331 | $self->reset_timeout (1); |
2351 | $self->reset_timeout (1); |
2332 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
2352 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
2333 | |
2353 | |
… | |
… | |
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 | |
… | |
… | |
2637 | |
2657 | |
2638 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2658 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2639 | $self->enter_map ($map, $x, $y); |
2659 | $self->enter_map ($map, $x, $y); |
2640 | |
2660 | |
2641 | # only activate afterwards, to support waiting in hooks |
2661 | # only activate afterwards, to support waiting in hooks |
2642 | $self->activate_recursive; |
2662 | $self->activate_recursive |
|
|
2663 | unless exists $self->{_link_pos}; # maybe we re in-flight again |
2643 | } |
2664 | } |
2644 | |
2665 | |
2645 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2666 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2646 | |
2667 | |
2647 | Moves the player to the given map-path and coordinates by first freezing |
2668 | Moves the player to the given map-path and coordinates by first freezing |
… | |
… | |
3543 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3564 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3544 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3565 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3545 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3566 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3546 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3567 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3547 | |
3568 | |
3548 | cf::init_experience; |
|
|
3549 | cf::init_anim; |
|
|
3550 | cf::init_attackmess; |
|
|
3551 | cf::init_dynamic; |
|
|
3552 | |
|
|
3553 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3569 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3554 | |
3570 | |
3555 | # we must not ever block the main coroutine |
3571 | # we must not ever block the main coroutine |
3556 | local $Coro::idle = sub { |
3572 | local $Coro::idle = sub { |
3557 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3573 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
… | |
… | |
3562 | }; |
3578 | }; |
3563 | |
3579 | |
3564 | evthread_start IO::AIO::poll_fileno; |
3580 | evthread_start IO::AIO::poll_fileno; |
3565 | |
3581 | |
3566 | cf::sync_job { |
3582 | cf::sync_job { |
|
|
3583 | cf::init_experience; |
|
|
3584 | cf::init_anim; |
|
|
3585 | cf::init_attackmess; |
|
|
3586 | cf::init_dynamic; |
|
|
3587 | |
3567 | cf::load_settings; |
3588 | cf::load_settings; |
3568 | cf::load_materials; |
3589 | cf::load_materials; |
3569 | |
3590 | |
3570 | reload_resources; |
3591 | reload_resources; |
3571 | reload_config; |
3592 | reload_config; |
… | |
… | |
3587 | use POSIX (); |
3608 | use POSIX (); |
3588 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3609 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3589 | |
3610 | |
3590 | (pop @POST_INIT)->(0) while @POST_INIT; |
3611 | (pop @POST_INIT)->(0) while @POST_INIT; |
3591 | }; |
3612 | }; |
|
|
3613 | |
|
|
3614 | cf::object::thawer::errors_are_fatal 0; |
|
|
3615 | warn "parse errors in files are no longer fatal from this point on.\n"; |
3592 | |
3616 | |
3593 | main_loop; |
3617 | main_loop; |
3594 | } |
3618 | } |
3595 | |
3619 | |
3596 | ############################################################################# |
3620 | ############################################################################# |
… | |
… | |
3773 | my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; |
3797 | my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; |
3774 | for my $name (keys %$leaf_symtab) { |
3798 | for my $name (keys %$leaf_symtab) { |
3775 | _gv_clear *{"$pkg$name"}; |
3799 | _gv_clear *{"$pkg$name"}; |
3776 | # use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; |
3800 | # use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; |
3777 | } |
3801 | } |
3778 | warn "cleared package $pkg\n";#d# |
|
|
3779 | } |
3802 | } |
3780 | |
3803 | |
3781 | sub do_reload_perl() { |
3804 | sub do_reload_perl() { |
3782 | # can/must only be called in main |
3805 | # can/must only be called in main |
3783 | if ($Coro::current != $Coro::main) { |
3806 | if (in_main) { |
3784 | warn "can only reload from main coroutine"; |
3807 | warn "can only reload from main coroutine"; |
3785 | return; |
3808 | return; |
3786 | } |
3809 | } |
3787 | |
3810 | |
3788 | return if $RELOAD++; |
3811 | return if $RELOAD++; |