ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.538 by root, Tue May 4 21:45:43 2010 UTC vs.
Revision 1.544 by root, Thu May 6 21:58:07 2010 UTC

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
23package cf; 23package cf;
24 24
25use 5.10.0; 25use common::sense;
26use utf8;
27use strict qw(vars subs);
28 26
29use Symbol; 27use Symbol;
30use List::Util; 28use List::Util;
31use Socket; 29use Socket;
32use EV; 30use 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
81sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload 79sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
82 80
81our @ORIG_INC;
82
83our %COMMAND = (); 83our %COMMAND = ();
84our %COMMAND_TIME = (); 84our %COMMAND_TIME = ();
85 85
86our @EXTS = (); # list of extension package names 86our @EXTS = (); # list of extension package names
87our %EXTCMD = (); 87our %EXTCMD = ();
124our $BDB_DEADLOCK_WATCHER; 124our $BDB_DEADLOCK_WATCHER;
125our $BDB_CHECKPOINT_WATCHER; 125our $BDB_CHECKPOINT_WATCHER;
126our $BDB_TRICKLE_WATCHER; 126our $BDB_TRICKLE_WATCHER;
127our $DB_ENV; 127our $DB_ENV;
128 128
129our @EXTRA_MODULES = qw(pod match mapscript); 129our @EXTRA_MODULES = qw(pod match mapscript incloader);
130 130
131our %CFG; 131our %CFG;
132 132
133our $UPTIME; $UPTIME ||= time; 133our $UPTIME; $UPTIME ||= time;
134our $RUNTIME; 134our $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
1850sub register { 1849sub 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
1873sub normalise { 1871sub 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
1929sub init { 1927sub init {
1930 my ($self) = @_; 1928 my ($self) = @_;
2052} 2050}
2053 2051
2054sub find; 2052sub find;
2055sub find { 2053sub 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
3500sub reload_treasures { 3499sub 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
3504sub reload_exp {
3505 cf::init_experience;
3506}
3507
3505sub reload_sound { 3508sub 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
3528sub reload_resources { 3531sub 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
3593sub main { 3597sub 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
3858sub do_reload_perl() { 3868sub 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
4000unshift @INC, $LIBDIR; 4011#############################################################################
4001 4012
4002my $bug_warning = 0; 4013my $bug_warning = 0;
4003 4014
4004our @WAIT_FOR_TICK; 4015our @WAIT_FOR_TICK;
4005our @WAIT_FOR_TICK_BEGIN; 4016our @WAIT_FOR_TICK_BEGIN;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines