… | |
… | |
2 | |
2 | |
3 | # this plug-in prefetches maps. everytime a player enters a map, |
3 | # this plug-in prefetches maps. everytime a player enters a map, |
4 | # it will asynchronously prefetch files from disk (it will not load them |
4 | # it will asynchronously prefetch files from disk (it will not load them |
5 | # into the server, but into the OS cache only). |
5 | # into the server, but into the OS cache only). |
6 | |
6 | |
|
|
7 | if (0) { #test# |
7 | use Errno (); |
8 | use Errno (); |
8 | use Time::HiRes; |
9 | use Time::HiRes; |
9 | use Fcntl; |
10 | use Fcntl; |
10 | use IO::AIO; |
11 | use IO::AIO; |
11 | |
12 | |
… | |
… | |
89 | |
90 | |
90 | if ($type eq "map") { |
91 | if ($type eq "map") { |
91 | if (my $map = cf::map::has_been_loaded $path) { |
92 | if (my $map = cf::map::has_been_loaded $path) { |
92 | $cb->(), next if $map->in_memory == cf::MAP_IN_MEMORY; |
93 | $cb->(), next if $map->in_memory == cf::MAP_IN_MEMORY; |
93 | |
94 | |
94 | prefetch file => $map->tmppath |
95 | prefetch file => $map->tmpname |
95 | if $map->in_memory == cf::MAP_SWAPPED; |
96 | if $map->in_memory == cf::MAP_SWAPPED; |
96 | } |
97 | } |
97 | } |
98 | } |
98 | |
99 | |
99 | load_file $path, $cb; |
100 | load_file $path, $cb; |
… | |
… | |
103 | $PREFETCHING = 0; |
104 | $PREFETCHING = 0; |
104 | } |
105 | } |
105 | |
106 | |
106 | my %MAP_EXITS; |
107 | my %MAP_EXITS; |
107 | |
108 | |
108 | sub prefetch_map { |
109 | sub prefetch_map($) { |
109 | my ($map) = @_; |
110 | my ($map) = @_; |
110 | |
111 | |
111 | my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; |
112 | my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; |
112 | prefetch map => $_ for @$exit; |
113 | prefetch map => $_ for @$exit; |
113 | } |
114 | } |
… | |
… | |
125 | Event->timer (interval => 0.2, cb => sub { |
126 | Event->timer (interval => 0.2, cb => sub { |
126 | @players = map $_->ob->name, cf::player::list unless @players; |
127 | @players = map $_->ob->name, cf::player::list unless @players; |
127 | my $player = cf::player::find pop @players |
128 | my $player = cf::player::find pop @players |
128 | or return; |
129 | or return; |
129 | |
130 | |
|
|
131 | if (my $map = $player->ob->map) { |
130 | prefetch_map $player->ob->map; |
132 | prefetch_map $map; |
|
|
133 | } |
|
|
134 | |
131 | prefetch map => +($player->get_savebed)[0]; |
135 | prefetch map => +($player->get_savebed)[0]; |
132 | }); |
136 | }); |
133 | } |
137 | } |
134 | |
138 | |
135 | # prefetch all .pl files every few minutes (thats only a "few" megabytes) |
139 | # prefetch all .pl files every few minutes (thats only a "few" megabytes) |
… | |
… | |
146 | }; |
150 | }; |
147 | |
151 | |
148 | $prefetch->(); $prefetch->(); |
152 | $prefetch->(); $prefetch->(); |
149 | }; |
153 | }; |
150 | }); |
154 | }); |
|
|
155 | } |
151 | |
156 | |
152 | |
157 | |
153 | |
158 | |