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.86 by root, Thu Dec 14 05:09:32 2006 UTC vs.
Revision 1.90 by root, Sat Dec 16 04:22:13 2006 UTC

16# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode? 16# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode?
17$YAML::Syck::ImplicitUnicode = 1; 17$YAML::Syck::ImplicitUnicode = 1;
18 18
19use strict; 19use strict;
20 20
21sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
22
21our %COMMAND = (); 23our %COMMAND = ();
22our %COMMAND_TIME = (); 24our %COMMAND_TIME = ();
23our %EXTCMD = (); 25our %EXTCMD = ();
24 26
25_init_vars; 27_init_vars;
26 28
27our @EVENT; 29our @EVENT;
28our $LIBDIR = maps_directory "perl"; 30our $LIBDIR = datadir . "/ext";
29 31
30our $TICK = MAX_TIME * 1e-6; 32our $TICK = MAX_TIME * 1e-6;
31our $TICK_WATCHER; 33our $TICK_WATCHER;
32our $NEXT_TICK; 34our $NEXT_TICK;
33 35
78 80
79# we bless all objects into (empty) derived classes to force a method lookup 81# we bless all objects into (empty) derived classes to force a method lookup
80# within the Safe compartment. 82# within the Safe compartment.
81for my $pkg (qw( 83for my $pkg (qw(
82 cf::object cf::object::player 84 cf::object cf::object::player
83 cf::client_socket cf::player 85 cf::client cf::player
84 cf::arch cf::living 86 cf::arch cf::living
85 cf::map cf::party cf::region 87 cf::map cf::party cf::region
86)) { 88)) {
87 no strict 'refs'; 89 no strict 'refs';
88 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 90 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
718 720
719 Symbol::delete_package $pkg; 721 Symbol::delete_package $pkg;
720} 722}
721 723
722sub load_extensions { 724sub load_extensions {
723 my $LIBDIR = maps_directory "perl";
724
725 for my $ext (<$LIBDIR/*.ext>) { 725 for my $ext (<$LIBDIR/*.ext>) {
726 next unless -r $ext; 726 next unless -r $ext;
727 eval { 727 eval {
728 load_extension $ext; 728 load_extension $ext;
729 1 729 1
1023 sub db_sync() { 1023 sub db_sync() {
1024 db_save if $dirty; 1024 db_save if $dirty;
1025 undef $dirty; 1025 undef $dirty;
1026 } 1026 }
1027 1027
1028 my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, cb => sub { 1028 my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, data => WF_AUTOCANCEL, cb => sub {
1029 db_sync; 1029 db_sync;
1030 }); 1030 });
1031 1031
1032 sub db_dirty() { 1032 sub db_dirty() {
1033 $dirty = 1; 1033 $dirty = 1;
1083 1083
1084 $msg->("reloading..."); 1084 $msg->("reloading...");
1085 1085
1086 eval { 1086 eval {
1087 # cancel all watchers 1087 # cancel all watchers
1088 $_->cancel for Event::all_watchers; 1088 for (Event::all_watchers) {
1089 $_->cancel if $_->data & WF_AUTOCANCEL;
1090 }
1089 1091
1090 # unload all extensions 1092 # unload all extensions
1091 for (@exts) { 1093 for (@exts) {
1092 $msg->("unloading <$_>"); 1094 $msg->("unloading <$_>");
1093 unload_extension $_; 1095 unload_extension $_;
1169}; 1171};
1170 1172
1171unshift @INC, $LIBDIR; 1173unshift @INC, $LIBDIR;
1172 1174
1173$TICK_WATCHER = Event->timer ( 1175$TICK_WATCHER = Event->timer (
1174 prio => 1, 1176 prio => 0,
1175 async => 1,
1176 at => $NEXT_TICK || 1, 1177 at => $NEXT_TICK || 1,
1178 data => WF_AUTOCANCEL,
1177 cb => sub { 1179 cb => sub {
1178 cf::server_tick; # one server iteration 1180 cf::server_tick; # one server iteration
1179 1181
1180 my $NOW = Event::time; 1182 my $NOW = Event::time;
1181 $NEXT_TICK += $TICK; 1183 $NEXT_TICK += $TICK;
1191IO::AIO::max_poll_time $TICK * 0.2; 1193IO::AIO::max_poll_time $TICK * 0.2;
1192 1194
1193Event->io (fd => IO::AIO::poll_fileno, 1195Event->io (fd => IO::AIO::poll_fileno,
1194 poll => 'r', 1196 poll => 'r',
1195 prio => 5, 1197 prio => 5,
1198 data => WF_AUTOCANCEL,
1196 cb => \&IO::AIO::poll_cb); 1199 cb => \&IO::AIO::poll_cb);
1197 1200
11981 12011
1199 1202

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines