… | |
… | |
18 | # this is not a correctness issue, it simply saves diskspace |
18 | # this is not a correctness issue, it simply saves diskspace |
19 | # because old files will get cleaned up on reset time |
19 | # because old files will get cleaned up on reset time |
20 | Coro::Timer::sleep 0.25; |
20 | Coro::Timer::sleep 0.25; |
21 | |
21 | |
22 | for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { |
22 | for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { |
|
|
23 | cf::cede_to_tick; |
23 | cf::map::find $path; |
24 | cf::map::find $path; |
24 | cf::wait_for_tick; Coro::cede; |
|
|
25 | } |
25 | } |
26 | |
26 | |
27 | # now hunt for resettable per-player maps |
27 | # now hunt for resettable per-player maps |
28 | for my $login (@{ cf::player::list_logins or [] }) { |
28 | for my $login (@{ cf::player::list_logins or [] }) { |
29 | for my $path (@{ cf::player::maps $login or [] }) { |
29 | for my $path (@{ cf::player::maps $login or [] }) { |
30 | Coro::cede; |
30 | cf::cede_to_tick; |
31 | |
31 | |
32 | $path =~ /^~[^\/]+(\/.*)$/ |
32 | $path =~ /^~[^\/]+(\/.*)$/ |
33 | or next; # doh |
33 | or next; # doh |
34 | |
34 | |
35 | my $base = cf::map::find $1; |
35 | my $base = cf::map::find $1; |
… | |
… | |
40 | |
40 | |
41 | # skip unresettable maps, for speed |
41 | # skip unresettable maps, for speed |
42 | next if $base->{deny_reset}; |
42 | next if $base->{deny_reset}; |
43 | |
43 | |
44 | my $map = cf::map::find $path; |
44 | my $map = cf::map::find $path; |
45 | cf::wait_for_tick; |
|
|
46 | |
45 | |
47 | if ($map->{deny_reset}) { |
46 | if ($map->{deny_reset}) { |
48 | warn "found noreset map with resettable base map, resetting: $path\n"; |
47 | warn "found noreset map with resettable base map, resetting: $path\n"; |
49 | delete $map->{deny_reset}; |
48 | delete $map->{deny_reset}; |
50 | } |
49 | } |
51 | } |
50 | } |
52 | } |
51 | } |
53 | }; |
52 | }; |
54 | |
53 | |
55 | our $SCHEDULER = cf::async_ext { |
54 | our $SCHEDULER = cf::async_ext { |
|
|
55 | my $timer = Coro::Event->timer (after => 1); |
|
|
56 | |
56 | while () { |
57 | while () { |
57 | Coro::Event::do_timer (after => $SCHEDULE_INTERVAL) |
58 | $timer->interval ($SCHEDULE_INTERVAL); |
58 | unless $cf::LOADAVG > $SWAP_LOAD2; |
59 | $timer->next unless $cf::LOADAVG > $SWAP_LOAD2; |
59 | |
60 | |
60 | # this weird form of iteration over values is used because |
61 | # this weird form of iteration over values is used because |
61 | # the hash changes underneath us frequently, and for |
62 | # the hash changes underneath us frequently, and for |
62 | # keeps a direct reference to the value without (in 5.8 perls) |
63 | # keeps a direct reference to the value without (in 5.8 perls) |
63 | # keeping a reference, so this is prone to crashes or worse. |
64 | # keeping a reference, so this is prone to crashes or worse. |
… | |
… | |
79 | } elsif ($map->in_memory == cf::MAP_IN_MEMORY) { |
80 | } elsif ($map->in_memory == cf::MAP_IN_MEMORY) { |
80 | my $max_idle = cf::clamp +(cf::lerp $cf::LOADAVG, $SWAP_LOAD1, $SWAP_LOAD2, $SWAP_TIMEOUT, 0), 0, $SWAP_TIMEOUT; |
81 | my $max_idle = cf::clamp +(cf::lerp $cf::LOADAVG, $SWAP_LOAD1, $SWAP_LOAD2, $SWAP_TIMEOUT, 0), 0, $SWAP_TIMEOUT; |
81 | |
82 | |
82 | if ($map->last_access + $max_idle <= $cf::RUNTIME && !$map->players) { |
83 | if ($map->last_access + $max_idle <= $cf::RUNTIME && !$map->players) { |
83 | $map->swap_out; |
84 | $map->swap_out; |
84 | cf::wait_for_tick unless $cf::LOADAVG > $SWAP_LOAD2; |
|
|
85 | } elsif ($map->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
85 | } elsif ($map->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
86 | $map->save; |
86 | $map->save; |
87 | cf::wait_for_tick unless $cf::LOADAVG > $SWAP_LOAD2; |
|
|
88 | } |
87 | } |
89 | } |
88 | } |
90 | }; |
89 | }; |
91 | warn $@ if $@; |
90 | warn $@ if $@; |
92 | cf::cede_to_tick; |
91 | cf::cede_to_tick; |