ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-scheduler.ext
(Generate patch)

Comparing deliantra/server/ext/map-scheduler.ext (file contents):
Revision 1.34 by root, Fri May 11 07:59:59 2007 UTC vs.
Revision 1.37 by root, Mon Jun 11 21:38:13 2007 UTC

1#! perl # MANDATORY 1#! perl # mandatory
2 2
3# this extension swaps out maps and resets them, in essence managing 3# this extension swaps out maps and resets them, in essence managing
4# the reset/swap policy of the server. 4# the reset/swap policy of the server.
5# it also contains the map prefetching logic 5# it also contains the map prefetching logic
6 6
11our $SWAP_LOAD1 = $cf::CFG{swap_load1} || .1; # start aggressively swapping at this load 11our $SWAP_LOAD1 = $cf::CFG{swap_load1} || .1; # start aggressively swapping at this load
12our $SWAP_LOAD2 = $cf::CFG{swap_load2} || .4; # swap as fast as possible at this load 12our $SWAP_LOAD2 = $cf::CFG{swap_load2} || .4; # swap as fast as possible at this load
13 13
14cf::async_ext { 14cf::async_ext {
15 $Coro::current->prio (Coro::PRIO_MIN); 15 $Coro::current->prio (Coro::PRIO_MIN);
16
16 # load the header of swapped-out maps. 17 # load the header of swapped-out maps.
17 # this is not a correctness issue, it simply saves diskspace 18 # this is not a correctness issue, it simply saves diskspace
18 # because old files will get cleaned up on reset time 19 # because old files will get cleaned up on reset time
19 Coro::Timer::sleep 1; 20 Coro::Timer::sleep 0.25;
20 21
21 my $files = Coro::AIO::aio_readdir $cf::TMPDIR; 22 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) {
22
23 for my $map (@$files) {
24 utf8::decode $map;
25 next if $map =~ /\.(?:pst|meta)$/;
26 cf::map::find $map; 23 cf::map::find $path;
27 cf::wait_for_tick; 24 cf::wait_for_tick; Coro::cede;
28 } 25 }
29 26
30 #TODO: should also preload random maps... 27 # now hunt for resettable per-player maps
28 for my $login (@{ cf::player::list_logins or [] }) {
29 for my $path (@{ cf::player::maps $login or [] }) {
30 Coro::cede;
31
32 $path =~ /^~[^\/]+(\/.*)$/
33 or next; # doh
34
35 my $base = cf::map::find $1;
36
37 # skip maps without base maps on the assumption
38 # that those are old, unresettable maps
39 next unless $base;
40
41 # skip unresettable maps, for speed
42 next if $base->{deny_reset};
43
44 my $map = cf::map::find $path;
45 cf::wait_for_tick;
46
47 if ($map->{deny_reset}) {
48 warn "found noreset map with resettable base map, resetting: $path\n";
49 delete $map->{deny_reset};
50 }
51 }
52 }
31}; 53};
32 54
33our $SCHEDULER = cf::async_ext { 55our $SCHEDULER = cf::async_ext {
34 while () { 56 while () {
35 Coro::Event::do_timer (after => $SCHEDULE_INTERVAL) 57 Coro::Event::do_timer (after => $SCHEDULE_INTERVAL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines