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

Comparing cf.schmorp.de/server/lib/cf.pm (file contents):
Revision 1.167 by root, Sat Jan 13 23:32:43 2007 UTC vs.
Revision 1.170 by root, Sun Jan 14 02:00:37 2007 UTC

44our @EVENT; 44our @EVENT;
45our $LIBDIR = datadir . "/ext"; 45our $LIBDIR = datadir . "/ext";
46 46
47our $TICK = MAX_TIME * 1e-6; 47our $TICK = MAX_TIME * 1e-6;
48our $TICK_WATCHER; 48our $TICK_WATCHER;
49our $AIO_POLL_WATCHER;
50our $WRITE_RUNTIME_WATCHER;
49our $NEXT_TICK; 51our $NEXT_TICK;
50our $NOW; 52our $NOW;
51 53
52our %CFG; 54our %CFG;
53 55
257} 259}
258 260
259sub freeze_mainloop { 261sub freeze_mainloop {
260 return unless $TICK_WATCHER->is_active; 262 return unless $TICK_WATCHER->is_active;
261 263
262 my $guard = Coro::guard { $TICK_WATCHER->start }; 264 my $guard = Coro::guard {
265 $TICK_WATCHER->start;
266 $WRITE_RUNTIME_WATCHER->start;
267 };
268 $WRITE_RUNTIME_WATCHER->stop;
263 $TICK_WATCHER->stop; 269 $TICK_WATCHER->stop;
264 $guard 270 $guard
265} 271}
266 272
267=item cf::async { BLOCK } 273=item cf::async { BLOCK }
338 344
339 $coro 345 $coro
340} 346}
341 347
342sub write_runtime { 348sub write_runtime {
343 return unless $TICK_WATCHER->is_active;
344
345 my $runtime = cf::localdir . "/runtime"; 349 my $runtime = cf::localdir . "/runtime";
346 350
347 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 351 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644
348 or return; 352 or return;
349 353
499our @CB_TYPE = (); # registry for type (cf-object class) based events 503our @CB_TYPE = (); # registry for type (cf-object class) based events
500our @CB_MAP = (); 504our @CB_MAP = ();
501 505
502my %attachment; 506my %attachment;
503 507
508sub cf::attachable::thawer_merge {
509 # simply override everything except _meta
510 local $_[0]{_meta};
511 %{$_[0]} = %{$_[1]};
512}
513
504sub _attach_cb($$$$) { 514sub _attach_cb($$$$) {
505 my ($registry, $event, $prio, $cb) = @_; 515 my ($registry, $event, $prio, $cb) = @_;
506 516
507 use sort 'stable'; 517 use sort 'stable';
508 518
679# object support 689# object support
680 690
681sub reattach { 691sub reattach {
682 # basically do the same as instantiate, without calling instantiate 692 # basically do the same as instantiate, without calling instantiate
683 my ($obj) = @_; 693 my ($obj) = @_;
694
695 bless $obj, ref $obj; # re-bless in case extensions have been reloaded
684 696
685 my $registry = $obj->registry; 697 my $registry = $obj->registry;
686 698
687 @$registry = (); 699 @$registry = ();
688 700
1138} 1150}
1139 1151
1140# also paths starting with '/' 1152# also paths starting with '/'
1141$EXT_MAP{"cf::map"} = qr{^(?=/)}; 1153$EXT_MAP{"cf::map"} = qr{^(?=/)};
1142 1154
1155sub thawer_merge {
1156 # we have to keep some variables in memory intact
1157 local $_[0]{path};
1158 local $_[0]{deny_save};
1159 local $_[0]{deny_reset};
1160
1161 $_[0]->SUPER::thawer_merge ($_[1]);
1162}
1163
1143sub normalise { 1164sub normalise {
1144 my ($path, $base) = @_; 1165 my ($path, $base) = @_;
1145 1166
1146 # map plan: 1167 # map plan:
1147 # 1168 #
1243 1264
1244sub unlink_save { 1265sub unlink_save {
1245 my ($self) = @_; 1266 my ($self) = @_;
1246 1267
1247 utf8::encode (my $save = $self->save_path); 1268 utf8::encode (my $save = $self->save_path);
1248 IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink $save; 1269 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save;
1249 IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$save.pst"; 1270 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst";
1250} 1271}
1251 1272
1252sub load_header_from($) { 1273sub load_header_from($) {
1253 my ($self, $path) = @_; 1274 my ($self, $path) = @_;
1254 1275
1494 1515
1495sub reset_at { 1516sub reset_at {
1496 my ($self) = @_; 1517 my ($self) = @_;
1497 1518
1498 # TODO: safety, remove and allow resettable per-player maps 1519 # TODO: safety, remove and allow resettable per-player maps
1499 return 1e99 if $self->isa ("ext::map_per_player"); 1520 return 1e99 if $self->isa ("ext::map_per_player");#d#
1500 return 1e99 if $self->{deny_reset}; 1521 return 1e99 if $self->{deny_reset};
1501 1522
1502 my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; 1523 my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access;
1503 my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET; 1524 my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET;
1504 1525
2402 }, 2423 },
2403); 2424);
2404 2425
2405IO::AIO::max_poll_time $TICK * 0.2; 2426IO::AIO::max_poll_time $TICK * 0.2;
2406 2427
2407Event->io ( 2428$AIO_POLL_WATCHER = Event->io (
2408 fd => IO::AIO::poll_fileno, 2429 fd => IO::AIO::poll_fileno,
2409 poll => 'r', 2430 poll => 'r',
2410 prio => 5, 2431 prio => 5,
2411 data => WF_AUTOCANCEL, 2432 data => WF_AUTOCANCEL,
2412 cb => \&IO::AIO::poll_cb, 2433 cb => \&IO::AIO::poll_cb,
2413); 2434);
2414 2435
2415Event->timer ( 2436$WRITE_RUNTIME_WATCHER = Event->timer (
2416 data => WF_AUTOCANCEL, 2437 data => WF_AUTOCANCEL,
2417 after => 0, 2438 after => 0,
2418 interval => 10, 2439 interval => 10,
2419 cb => sub { 2440 cb => sub {
2420 (Coro::unblock_sub { 2441 (Coro::unblock_sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines