--- deliantra/server/ext/map-scheduler.ext 2010/05/04 21:45:42 1.53 +++ deliantra/server/ext/map-scheduler.ext 2011/08/13 20:20:30 1.57 @@ -11,47 +11,45 @@ our $SWAP_LOAD1 = $cf::CFG{swap_load1} || .1; # start aggressively swapping at this load our $SWAP_LOAD2 = $cf::CFG{swap_load2} || .6; # swap as fast as possible at this load -cf::post_init { - cf::async_ext { - $Coro::current->{desc} = "startup map scanner"; - $Coro::current->prio (Coro::PRIO_MIN); - - # load the header of swapped-out maps. - # this is not a correctness issue, it simply saves diskspace - # because old files will get cleaned up on reset time - Coro::Timer::sleep 0.25; - - for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { - cf::cede_to_tick; - cf::map::find $path; - } - - # now hunt for resettable per-player maps - for my $login (@{ cf::player::list_logins or [] }) { - for my $path (@{ cf::player::maps $login or [] }) { - cf::cede_to_tick; - - $path =~ /^~[^\/]+(\/.*)$/ - or next; # doh - - my $base = cf::map::find $1; - - # skip maps without base maps on the assumption - # that those are old, unresettable maps - next unless $base; - - # skip unresettable maps, for speed - next if $base->{deny_reset}; - - my $map = cf::map::find $path; - - if ($map->{deny_reset}) { - warn "found noreset map with resettable base map, resetting: $path\n"; - delete $map->{deny_reset}; - } +sub reload { + local $Coro::current->{desc} = "startup map scanner"; + $Coro::current->prio (Coro::PRIO_MIN); + + # load the header of swapped-out maps. + # this is not a correctness issue, it simply saves diskspace + # because old files will get cleaned up on reset time + + for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { + cf::map::find $path; + } + + # now hunt for resettable per-player maps + for my $login (@{ cf::player::list_logins or [] }) { + for my $path (@{ cf::player::maps $login or [] }) { + $path =~ /^~[^\/]+(\/.*)$/ + or next; # doh + + my $base = cf::map::find $1; + + # skip maps without base maps on the assumption + # that those are old, unresettable maps + next unless $base; + + # skip unresettable maps, for speed + next if $base->{deny_reset}; + + my $map = cf::map::find $path; + + if ($map->{deny_reset}) { + warn "found noreset map with resettable base map, resetting: $path\n"; + delete $map->{deny_reset}; } } - }; + } +} + +cf::post_init { + cf::async { reload }; our $SCHEDULER = cf::async_ext { $Coro::current->{desc} = "map scheduler"; @@ -61,7 +59,7 @@ if ($cf::LOADAVG > $SWAP_LOAD2) { cf::wait_for_tick; } else { - Coro::EV::timer_once $SCHEDULE_INTERVAL; + Coro::AnyEvent::sleep $SCHEDULE_INTERVAL; } # this weird form of iteration over values is used because @@ -83,7 +81,7 @@ # } if ($map->should_reset) { $map->reset; - } elsif ($map->in_memory == cf::MAP_ACTIVE) { + } elsif ($map->linkable) { my $max_idle = cf::clamp +(cf::lerp $cf::LOADAVG, $SWAP_LOAD1, $SWAP_LOAD2, $SWAP_TIMEOUT, $cf::TICK * 1.5), $cf::TICK * 1.5, $SWAP_TIMEOUT;