… | |
… | |
233 | from wherever your confdir points to. |
233 | from wherever your confdir points to. |
234 | |
234 | |
235 | =item cf::wait_for_tick, cf::wait_for_tick_begin |
235 | =item cf::wait_for_tick, cf::wait_for_tick_begin |
236 | |
236 | |
237 | These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only |
237 | These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only |
238 | returns directly I<after> the tick processing (and consequently, can only wake one process |
238 | returns directly I<after> the tick processing (and consequently, can only wake one thread |
239 | per tick), while cf::wait_for_tick wakes up all waiters after tick processing. |
239 | per tick), while cf::wait_for_tick wakes up all waiters after tick processing. |
|
|
240 | |
|
|
241 | =cut |
|
|
242 | |
|
|
243 | sub wait_for_tick(); |
|
|
244 | sub wait_for_tick_begin(); |
240 | |
245 | |
241 | =item @cf::INVOKE_RESULTS |
246 | =item @cf::INVOKE_RESULTS |
242 | |
247 | |
243 | This array contains the results of the last C<invoke ()> call. When |
248 | This array contains the results of the last C<invoke ()> call. When |
244 | C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of |
249 | C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of |
… | |
… | |
3370 | |
3375 | |
3371 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
3376 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
3372 | |
3377 | |
3373 | trace "loading facedata from $path\n"; |
3378 | trace "loading facedata from $path\n"; |
3374 | |
3379 | |
3375 | my $facedata; |
|
|
3376 | 0 < aio_load $path, $facedata |
3380 | 0 < aio_load $path, my $facedata |
3377 | or die "$path: $!"; |
3381 | or die "$path: $!"; |
3378 | |
3382 | |
3379 | $facedata = Coro::Storable::thaw $facedata; |
3383 | $facedata = Coro::Storable::thaw $facedata; |
3380 | |
3384 | |
3381 | $facedata->{version} == 2 |
3385 | $facedata->{version} == 2 |
… | |
… | |
3539 | } |
3543 | } |
3540 | |
3544 | |
3541 | sub reload_config { |
3545 | sub reload_config { |
3542 | trace "reloading config file...\n"; |
3546 | trace "reloading config file...\n"; |
3543 | |
3547 | |
3544 | open my $fh, "<:utf8", "$CONFDIR/config" |
3548 | 0 < aio_load "$CONFDIR/config", my $config |
3545 | or return; |
3549 | or die "$CONFDIR/config: $!"; |
3546 | |
3550 | |
3547 | local $/; |
3551 | utf8::decode $config; |
|
|
3552 | |
|
|
3553 | cf::get_slot 0.1, 10, "reload_config"; # yaml might be slow... |
3548 | *CFG = YAML::XS::Load scalar <$fh>; |
3554 | *CFG = YAML::XS::Load $config; |
3549 | |
3555 | |
3550 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3556 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3551 | |
3557 | |
3552 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3558 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3553 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3559 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
… | |
… | |
3557 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
3563 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
3558 | and die "WARNING: m(un)lockall failed: $!\n"; |
3564 | and die "WARNING: m(un)lockall failed: $!\n"; |
3559 | }; |
3565 | }; |
3560 | warn $@ if $@; |
3566 | warn $@ if $@; |
3561 | } |
3567 | } |
3562 | |
|
|
3563 | trace "finished reloading resource files\n"; |
|
|
3564 | } |
3568 | } |
3565 | |
3569 | |
3566 | sub pidfile() { |
3570 | sub pidfile() { |
3567 | sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT |
3571 | sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT |
3568 | or die "$PIDFILE: $!"; |
3572 | or die "$PIDFILE: $!"; |
… | |
… | |
4009 | my $bug_warning = 0; |
4013 | my $bug_warning = 0; |
4010 | |
4014 | |
4011 | our @WAIT_FOR_TICK; |
4015 | our @WAIT_FOR_TICK; |
4012 | our @WAIT_FOR_TICK_BEGIN; |
4016 | our @WAIT_FOR_TICK_BEGIN; |
4013 | |
4017 | |
4014 | sub wait_for_tick { |
4018 | sub wait_for_tick() { |
4015 | return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; |
4019 | return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; |
4016 | |
4020 | |
4017 | my $signal = new Coro::Signal; |
4021 | my $signal = new Coro::Signal; |
4018 | push @WAIT_FOR_TICK, $signal; |
4022 | push @WAIT_FOR_TICK, $signal; |
4019 | $signal->wait; |
4023 | $signal->wait; |
4020 | } |
4024 | } |
4021 | |
4025 | |
4022 | sub wait_for_tick_begin { |
4026 | sub wait_for_tick_begin() { |
4023 | return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; |
4027 | return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; |
4024 | |
4028 | |
4025 | my $signal = new Coro::Signal; |
4029 | my $signal = new Coro::Signal; |
4026 | push @WAIT_FOR_TICK_BEGIN, $signal; |
4030 | push @WAIT_FOR_TICK_BEGIN, $signal; |
4027 | $signal->wait; |
4031 | $signal->wait; |