… | |
… | |
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# |
|
|
8 | use Errno (); |
7 | use Errno (); |
9 | use Time::HiRes; |
8 | use Time::HiRes; |
10 | use Fcntl; |
9 | use Fcntl; |
11 | use IO::AIO; |
10 | use IO::AIO; |
12 | |
11 | |
… | |
… | |
111 | |
110 | |
112 | my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; |
111 | my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; |
113 | prefetch map => $_ for @$exit; |
112 | prefetch map => $_ for @$exit; |
114 | } |
113 | } |
115 | |
114 | |
116 | sub on_mapenter { |
115 | cf::attach_to_players prio => -900, |
117 | my ($ob) = @_; |
116 | on_map_change => sub { |
|
|
117 | my ($pl, $old, $new) = @_; |
118 | |
118 | |
119 | prefetch_map $ob->map; |
119 | prefetch_map $new; |
120 | } |
120 | }, |
|
|
121 | ; |
121 | |
122 | |
|
|
123 | if (0) { #test# |
122 | # prefetch a few players/second |
124 | # prefetch a few players/second |
123 | { |
125 | { |
124 | my @players; |
126 | my @players; |
125 | |
127 | |
126 | Event->timer (interval => 0.2, cb => sub { |
128 | Event->timer (interval => 0.2, cb => sub { |