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.85 by root, Mon Dec 11 22:56:57 2006 UTC vs.
Revision 1.89 by root, Fri Dec 15 19:59:20 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
76 78
77@safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; 79@safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object';
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(cf::object cf::object::player cf::player cf::map cf::party cf::region cf::arch cf::living)) { 83for my $pkg (qw(
84 cf::object cf::object::player
85 cf::client cf::player
86 cf::arch cf::living
87 cf::map cf::party cf::region
88)) {
82 no strict 'refs'; 89 no strict 'refs';
83 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 90 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
84} 91}
85 92
86$Event::DIED = sub { 93$Event::DIED = sub {
713 720
714 Symbol::delete_package $pkg; 721 Symbol::delete_package $pkg;
715} 722}
716 723
717sub load_extensions { 724sub load_extensions {
718 my $LIBDIR = maps_directory "perl";
719
720 for my $ext (<$LIBDIR/*.ext>) { 725 for my $ext (<$LIBDIR/*.ext>) {
721 next unless -r $ext; 726 next unless -r $ext;
722 eval { 727 eval {
723 load_extension $ext; 728 load_extension $ext;
724 1 729 1
1018 sub db_sync() { 1023 sub db_sync() {
1019 db_save if $dirty; 1024 db_save if $dirty;
1020 undef $dirty; 1025 undef $dirty;
1021 } 1026 }
1022 1027
1023 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 {
1024 db_sync; 1029 db_sync;
1025 }); 1030 });
1026 1031
1027 sub db_dirty() { 1032 sub db_dirty() {
1028 $dirty = 1; 1033 $dirty = 1;
1078 1083
1079 $msg->("reloading..."); 1084 $msg->("reloading...");
1080 1085
1081 eval { 1086 eval {
1082 # cancel all watchers 1087 # cancel all watchers
1083 $_->cancel for Event::all_watchers; 1088 for (Event::all_watchers) {
1089 $_->cancel if $_->data & WF_AUTOCANCEL;
1090 }
1084 1091
1085 # unload all extensions 1092 # unload all extensions
1086 for (@exts) { 1093 for (@exts) {
1087 $msg->("unloading <$_>"); 1094 $msg->("unloading <$_>");
1088 unload_extension $_; 1095 unload_extension $_;
1167 1174
1168$TICK_WATCHER = Event->timer ( 1175$TICK_WATCHER = Event->timer (
1169 prio => 1, 1176 prio => 1,
1170 async => 1, 1177 async => 1,
1171 at => $NEXT_TICK || 1, 1178 at => $NEXT_TICK || 1,
1179 data => WF_AUTOCANCEL,
1172 cb => sub { 1180 cb => sub {
1173 cf::server_tick; # one server iteration 1181 cf::server_tick; # one server iteration
1174 1182
1175 my $NOW = Event::time; 1183 my $NOW = Event::time;
1176 $NEXT_TICK += $TICK; 1184 $NEXT_TICK += $TICK;
1186IO::AIO::max_poll_time $TICK * 0.2; 1194IO::AIO::max_poll_time $TICK * 0.2;
1187 1195
1188Event->io (fd => IO::AIO::poll_fileno, 1196Event->io (fd => IO::AIO::poll_fileno,
1189 poll => 'r', 1197 poll => 'r',
1190 prio => 5, 1198 prio => 5,
1199 data => WF_AUTOCANCEL,
1191 cb => \&IO::AIO::poll_cb); 1200 cb => \&IO::AIO::poll_cb);
1192 1201
11931 12021
1194 1203

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines