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.510 by root, Tue Apr 6 22:59:28 2010 UTC vs.
Revision 1.512 by root, Sun Apr 11 04:52:07 2010 UTC

503 503
504sub sync_job(&) { 504sub sync_job(&) {
505 my ($job) = @_; 505 my ($job) = @_;
506 506
507 if ($Coro::current == $Coro::main) { 507 if ($Coro::current == $Coro::main) {
508 my $time = EV::time; 508 my $time = AE::time;
509 509
510 # this is the main coro, too bad, we have to block 510 # this is the main coro, too bad, we have to block
511 # till the operation succeeds, freezing the server :/ 511 # till the operation succeeds, freezing the server :/
512 512
513 LOG llevError, Carp::longmess "sync job";#d# 513 LOG llevError, Carp::longmess "sync job";#d#
530 } else { 530 } else {
531 EV::loop EV::LOOP_ONESHOT; 531 EV::loop EV::LOOP_ONESHOT;
532 } 532 }
533 } 533 }
534 534
535 my $time = EV::time - $time; 535 my $time = AE::time - $time;
536 536
537 $TICK_START += $time; # do not account sync jobs to server load 537 $TICK_START += $time; # do not account sync jobs to server load
538 538
539 wantarray ? @res : $res[0] 539 wantarray ? @res : $res[0]
540 } else { 540 } else {
1533 $cf::PLAYER{$login} = $pl 1533 $cf::PLAYER{$login} = $pl
1534 } 1534 }
1535 } 1535 }
1536} 1536}
1537 1537
1538cf::player->attach (
1539 on_load => sub {
1540 my ($pl, $path) = @_;
1541
1542 # restore slots saved in save, below
1543 my $slots = delete $pl->{_slots};
1544
1545 $pl->ob->current_weapon ($slots->[0]);
1546 $pl->combat_ob ($slots->[1]);
1547 $pl->ranged_ob ($slots->[2]);
1548 },
1549);
1550
1538sub save($) { 1551sub save($) {
1539 my ($pl) = @_; 1552 my ($pl) = @_;
1540 1553
1541 return if $pl->{deny_save}; 1554 return if $pl->{deny_save};
1542 1555
1547 1560
1548 aio_mkdir playerdir $pl, 0770; 1561 aio_mkdir playerdir $pl, 0770;
1549 $pl->{last_save} = $cf::RUNTIME; 1562 $pl->{last_save} = $cf::RUNTIME;
1550 1563
1551 cf::get_slot 0.01; 1564 cf::get_slot 0.01;
1565
1566 # save slots, to be restored later
1567 local $pl->{_slots} = [$pl->ob->current_weapon, $pl->combat_ob, $pl->ranged_ob];
1552 1568
1553 $pl->save_pl ($path); 1569 $pl->save_pl ($path);
1554 cf::cede_to_tick; 1570 cf::cede_to_tick;
1555} 1571}
1556 1572
3568 3584
3569# install some emergency cleanup handlers 3585# install some emergency cleanup handlers
3570BEGIN { 3586BEGIN {
3571 our %SIGWATCHER = (); 3587 our %SIGWATCHER = ();
3572 for my $signal (qw(INT HUP TERM)) { 3588 for my $signal (qw(INT HUP TERM)) {
3573 $SIGWATCHER{$signal} = EV::signal $signal, sub { 3589 $SIGWATCHER{$signal} = AE::signal $signal, sub {
3574 cf::cleanup "SIG$signal"; 3590 cf::cleanup "SIG$signal";
3575 }; 3591 };
3576 } 3592 }
3577} 3593}
3578 3594
3579sub write_runtime_sync { 3595sub write_runtime_sync {
3580 my $t0 = EV::time; 3596 my $t0 = AE::time;
3581 3597
3582 # first touch the runtime file to show we are still running: 3598 # first touch the runtime file to show we are still running:
3583 # the fsync below can take a very very long time. 3599 # the fsync below can take a very very long time.
3584 3600
3585 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; 3601 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef;
3607 or return; 3623 or return;
3608 3624
3609 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE 3625 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE
3610 and return; 3626 and return;
3611 3627
3612 warn sprintf "runtime file written (%gs).\n", EV::time - $t0; 3628 warn sprintf "runtime file written (%gs).\n", AE::time - $t0;
3613 3629
3614 1 3630 1
3615} 3631}
3616 3632
3617our $uuid_lock; 3633our $uuid_lock;
3755 return; 3771 return;
3756 } 3772 }
3757 3773
3758 return if $RELOAD++; 3774 return if $RELOAD++;
3759 3775
3760 my $t1 = EV::time; 3776 my $t1 = AE::time;
3761 3777
3762 while ($RELOAD) { 3778 while ($RELOAD) {
3763 warn "reloading..."; 3779 warn "reloading...";
3764 3780
3765 warn "entering sync_job"; 3781 warn "entering sync_job";
3868 3884
3869 warn "reloaded"; 3885 warn "reloaded";
3870 --$RELOAD; 3886 --$RELOAD;
3871 } 3887 }
3872 3888
3873 $t1 = EV::time - $t1; 3889 $t1 = AE::time - $t1;
3874 warn "reload completed in ${t1}s\n"; 3890 warn "reload completed in ${t1}s\n";
3875}; 3891};
3876 3892
3877our $RELOAD_WATCHER; # used only during reload 3893our $RELOAD_WATCHER; # used only during reload
3878 3894
3881 # coro crashes during coro_state_free->destroy here. 3897 # coro crashes during coro_state_free->destroy here.
3882 3898
3883 $RELOAD_WATCHER ||= cf::async { 3899 $RELOAD_WATCHER ||= cf::async {
3884 Coro::AIO::aio_wait cache_extensions; 3900 Coro::AIO::aio_wait cache_extensions;
3885 3901
3886 $RELOAD_WATCHER = EV::timer $TICK * 1.5, 0, sub { 3902 $RELOAD_WATCHER = AE::timer $TICK * 1.5, 0, sub {
3887 do_reload_perl; 3903 do_reload_perl;
3888 undef $RELOAD_WATCHER; 3904 undef $RELOAD_WATCHER;
3889 }; 3905 };
3890 }; 3906 };
3891} 3907}
3932 return; 3948 return;
3933 } 3949 }
3934 3950
3935 cf::server_tick; # one server iteration 3951 cf::server_tick; # one server iteration
3936 3952
3937 #for(1..3e6){} EV::now_update; $NOW=EV::now; # generate load #d# 3953 #for(1..3e6){} AE::now_update; $NOW=AE::now; # generate load #d#
3938 3954
3939 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3955 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3940 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 3956 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3941 Coro::async_pool { 3957 Coro::async_pool {
3942 $Coro::current->{desc} = "runtime saver"; 3958 $Coro::current->{desc} = "runtime saver";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines