… | |
… | |
20 | # The authors can be reached via e-mail to <support@deliantra.net> |
20 | # The authors can be reached via e-mail to <support@deliantra.net> |
21 | # |
21 | # |
22 | |
22 | |
23 | package cf; |
23 | package cf; |
24 | |
24 | |
25 | use 5.10.0; |
25 | use common::sense; |
26 | use utf8; |
|
|
27 | use strict qw(vars subs); |
|
|
28 | |
26 | |
29 | use Symbol; |
27 | use Symbol; |
30 | use List::Util; |
28 | use List::Util; |
31 | use Socket; |
29 | use Socket; |
32 | use EV; |
30 | use EV; |
… | |
… | |
78 | # strictly for debugging |
76 | # strictly for debugging |
79 | $SIG{QUIT} = sub { Carp::cluck "SIGQUIT" }; |
77 | $SIG{QUIT} = sub { Carp::cluck "SIGQUIT" }; |
80 | |
78 | |
81 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
79 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
82 | |
80 | |
|
|
81 | our @ORIG_INC; |
|
|
82 | |
83 | our %COMMAND = (); |
83 | our %COMMAND = (); |
84 | our %COMMAND_TIME = (); |
84 | our %COMMAND_TIME = (); |
85 | |
85 | |
86 | our @EXTS = (); # list of extension package names |
86 | our @EXTS = (); # list of extension package names |
87 | our %EXTCMD = (); |
87 | our %EXTCMD = (); |
… | |
… | |
124 | our $BDB_DEADLOCK_WATCHER; |
124 | our $BDB_DEADLOCK_WATCHER; |
125 | our $BDB_CHECKPOINT_WATCHER; |
125 | our $BDB_CHECKPOINT_WATCHER; |
126 | our $BDB_TRICKLE_WATCHER; |
126 | our $BDB_TRICKLE_WATCHER; |
127 | our $DB_ENV; |
127 | our $DB_ENV; |
128 | |
128 | |
129 | our @EXTRA_MODULES = qw(pod match mapscript); |
129 | our @EXTRA_MODULES = qw(pod match mapscript incloader); |
130 | |
130 | |
131 | our %CFG; |
131 | our %CFG; |
132 | |
132 | |
133 | our $UPTIME; $UPTIME ||= time; |
133 | our $UPTIME; $UPTIME ||= time; |
134 | our $RUNTIME; |
134 | our $RUNTIME; |
… | |
… | |
1451 | |
1451 | |
1452 | my $active = eval $v->{source}; |
1452 | my $active = eval $v->{source}; |
1453 | |
1453 | |
1454 | if (length $@) { |
1454 | if (length $@) { |
1455 | error "$v->{path}: $@\n"; |
1455 | error "$v->{path}: $@\n"; |
1456 | undef $@; # work around perl 5.10.0 utf-8 caching bug |
|
|
1457 | |
1456 | |
1458 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1457 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1459 | if exists $v->{meta}{mandatory}; |
1458 | if exists $v->{meta}{mandatory}; |
1460 | |
1459 | |
1461 | warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; |
1460 | warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; |
… | |
… | |
1849 | |
1848 | |
1850 | sub register { |
1849 | sub register { |
1851 | my (undef, $regex, $prio) = @_; |
1850 | my (undef, $regex, $prio) = @_; |
1852 | my $pkg = caller; |
1851 | my $pkg = caller; |
1853 | |
1852 | |
1854 | no strict; |
|
|
1855 | push @{"$pkg\::ISA"}, __PACKAGE__; |
1853 | push @{"$pkg\::ISA"}, __PACKAGE__; |
1856 | |
1854 | |
1857 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1855 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1858 | } |
1856 | } |
1859 | |
1857 | |
… | |
… | |
1871 | } |
1869 | } |
1872 | |
1870 | |
1873 | sub normalise { |
1871 | sub normalise { |
1874 | my ($path, $base) = @_; |
1872 | my ($path, $base) = @_; |
1875 | |
1873 | |
1876 | $path = "$path"; # make sure its a string |
1874 | $path = "$path"; # make sure it's a string |
1877 | |
1875 | |
1878 | $path =~ s/\.map$//; |
1876 | $path =~ s/\.map$//; |
1879 | |
1877 | |
1880 | # map plan: |
1878 | # map plan: |
1881 | # |
1879 | # |
… | |
… | |
1920 | $self->init; # pass $1 etc. |
1918 | $self->init; # pass $1 etc. |
1921 | return $self; |
1919 | return $self; |
1922 | } |
1920 | } |
1923 | } |
1921 | } |
1924 | |
1922 | |
1925 | Carp::cluck "unable to resolve path '$path' (base '$base')."; |
1923 | Carp::cluck "unable to resolve path '$path' (base '$base')"; |
1926 | () |
1924 | () |
1927 | } |
1925 | } |
1928 | |
1926 | |
1929 | sub init { |
1927 | sub init { |
1930 | my ($self) = @_; |
1928 | my ($self) = @_; |
… | |
… | |
2052 | } |
2050 | } |
2053 | |
2051 | |
2054 | sub find; |
2052 | sub find; |
2055 | sub find { |
2053 | sub find { |
2056 | my ($path, $origin) = @_; |
2054 | my ($path, $origin) = @_; |
|
|
2055 | |
|
|
2056 | cf::cede_to_tick; |
2057 | |
2057 | |
2058 | $path = normalise $path, $origin && $origin->path; |
2058 | $path = normalise $path, $origin && $origin->path; |
2059 | |
2059 | |
2060 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2060 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2061 | my $guard2 = cf::lock_acquire "map_find:$path"; |
2061 | my $guard2 = cf::lock_acquire "map_find:$path"; |
… | |
… | |
3274 | decrease split destroy change_exp value msg lore send_msg)], |
3274 | decrease split destroy change_exp value msg lore send_msg)], |
3275 | ["cf::object::player" => qw(player)], |
3275 | ["cf::object::player" => qw(player)], |
3276 | ["cf::player" => qw(peaceful send_msg)], |
3276 | ["cf::player" => qw(peaceful send_msg)], |
3277 | ["cf::map" => qw(trigger)], |
3277 | ["cf::map" => qw(trigger)], |
3278 | ) { |
3278 | ) { |
3279 | no strict 'refs'; |
|
|
3280 | my ($pkg, @funs) = @$_; |
3279 | my ($pkg, @funs) = @$_; |
3281 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
3280 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
3282 | for @funs; |
3281 | for @funs; |
3283 | } |
3282 | } |
3284 | |
3283 | |
… | |
… | |
3500 | sub reload_treasures { |
3499 | sub reload_treasures { |
3501 | load_resource_file "$DATADIR/treasures" |
3500 | load_resource_file "$DATADIR/treasures" |
3502 | or die "unable to load treasurelists\n"; |
3501 | or die "unable to load treasurelists\n"; |
3503 | } |
3502 | } |
3504 | |
3503 | |
|
|
3504 | sub reload_exp { |
|
|
3505 | cf::init_experience; |
|
|
3506 | } |
|
|
3507 | |
3505 | sub reload_sound { |
3508 | sub reload_sound { |
3506 | trace "loading sound config from $DATADIR/sound\n"; |
3509 | trace "loading sound config from $DATADIR/sound\n"; |
3507 | |
3510 | |
3508 | 0 < Coro::AIO::aio_load "$DATADIR/sound", my $data |
3511 | 0 < Coro::AIO::aio_load "$DATADIR/sound", my $data |
3509 | or die "$DATADIR/sound $!"; |
3512 | or die "$DATADIR/sound $!"; |
… | |
… | |
3526 | } |
3529 | } |
3527 | |
3530 | |
3528 | sub reload_resources { |
3531 | sub reload_resources { |
3529 | trace "reloading resource files...\n"; |
3532 | trace "reloading resource files...\n"; |
3530 | |
3533 | |
|
|
3534 | reload_exp; |
3531 | reload_facedata; |
3535 | reload_facedata; |
3532 | reload_sound; |
3536 | reload_sound; |
3533 | reload_archetypes; |
3537 | reload_archetypes; |
3534 | reload_regions; |
3538 | reload_regions; |
3535 | reload_treasures; |
3539 | reload_treasures; |
… | |
… | |
3592 | |
3596 | |
3593 | sub main { |
3597 | sub main { |
3594 | cf::init_globals; # initialise logging |
3598 | cf::init_globals; # initialise logging |
3595 | |
3599 | |
3596 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3600 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3597 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3601 | LOG llevInfo, "Copyright (C) 2005-2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3598 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3602 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3599 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3603 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3600 | |
3604 | |
3601 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3605 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3602 | |
3606 | |
… | |
… | |
3610 | }; |
3614 | }; |
3611 | |
3615 | |
3612 | evthread_start IO::AIO::poll_fileno; |
3616 | evthread_start IO::AIO::poll_fileno; |
3613 | |
3617 | |
3614 | cf::sync_job { |
3618 | cf::sync_job { |
3615 | cf::init_experience; |
3619 | cf::incloader::init (); |
|
|
3620 | |
3616 | cf::init_anim; |
3621 | cf::init_anim; |
3617 | cf::init_attackmess; |
3622 | cf::init_attackmess; |
3618 | cf::init_dynamic; |
3623 | cf::init_dynamic; |
3619 | |
3624 | |
3620 | cf::load_settings; |
3625 | cf::load_settings; |
… | |
… | |
3644 | }; |
3649 | }; |
3645 | |
3650 | |
3646 | cf::object::thawer::errors_are_fatal 0; |
3651 | cf::object::thawer::errors_are_fatal 0; |
3647 | info "parse errors in files are no longer fatal from this point on.\n"; |
3652 | info "parse errors in files are no longer fatal from this point on.\n"; |
3648 | |
3653 | |
|
|
3654 | my $free_main; $free_main = EV::idle sub { |
|
|
3655 | undef $free_main; |
|
|
3656 | undef &main; # free gobs of memory :) |
|
|
3657 | }; |
|
|
3658 | |
3649 | main_loop; |
3659 | goto &main_loop; |
3650 | } |
3660 | } |
3651 | |
3661 | |
3652 | ############################################################################# |
3662 | ############################################################################# |
3653 | # initialisation and cleanup |
3663 | # initialisation and cleanup |
3654 | |
3664 | |
… | |
… | |
3855 | } |
3865 | } |
3856 | } |
3866 | } |
3857 | |
3867 | |
3858 | sub do_reload_perl() { |
3868 | sub do_reload_perl() { |
3859 | # can/must only be called in main |
3869 | # can/must only be called in main |
3860 | if (in_main) { |
3870 | unless (in_main) { |
3861 | error "can only reload from main coroutine"; |
3871 | error "can only reload from main coroutine"; |
3862 | return; |
3872 | return; |
3863 | } |
3873 | } |
3864 | |
3874 | |
3865 | return if $RELOAD++; |
3875 | return if $RELOAD++; |
3866 | |
3876 | |
3867 | my $t1 = AE::time; |
3877 | my $t1 = AE::time; |
3868 | |
3878 | |
3869 | while ($RELOAD) { |
3879 | while ($RELOAD) { |
|
|
3880 | cf::get_slot 0.1, -1, "reload_perl"; |
3870 | info "reloading..."; |
3881 | info "reloading..."; |
3871 | |
3882 | |
3872 | trace "entering sync_job"; |
3883 | trace "entering sync_job"; |
3873 | |
3884 | |
3874 | cf::sync_job { |
3885 | cf::sync_job { |
3875 | cf::emergency_save; |
3886 | #cf::emergency_save; |
3876 | |
3887 | |
3877 | trace "cancelling all extension coros"; |
3888 | trace "cancelling all extension coros"; |
3878 | $_->cancel for values %EXT_CORO; |
3889 | $_->cancel for values %EXT_CORO; |
3879 | %EXT_CORO = (); |
3890 | %EXT_CORO = (); |
3880 | |
3891 | |
… | |
… | |
3995 | reload_perl; |
4006 | reload_perl; |
3996 | }; |
4007 | }; |
3997 | } |
4008 | } |
3998 | }; |
4009 | }; |
3999 | |
4010 | |
4000 | unshift @INC, $LIBDIR; |
4011 | ############################################################################# |
4001 | |
4012 | |
4002 | my $bug_warning = 0; |
4013 | my $bug_warning = 0; |
4003 | |
4014 | |
4004 | our @WAIT_FOR_TICK; |
4015 | our @WAIT_FOR_TICK; |
4005 | our @WAIT_FOR_TICK_BEGIN; |
4016 | our @WAIT_FOR_TICK_BEGIN; |