… | |
… | |
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 | |
|
|
13 | Event->io (fd => IO::AIO::poll_fileno, |
|
|
14 | poll => 'r', |
|
|
15 | cb => \&IO::AIO::poll_cb); |
|
|
16 | |
11 | |
17 | # find all potential exit paths, this is slow, so this info is cached |
12 | # find all potential exit paths, this is slow, so this info is cached |
18 | sub find_exits { |
13 | sub find_exits { |
19 | my ($map) = @_; |
14 | my ($map) = @_; |
20 | |
15 | |
… | |
… | |
111 | |
106 | |
112 | my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; |
107 | my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; |
113 | prefetch map => $_ for @$exit; |
108 | prefetch map => $_ for @$exit; |
114 | } |
109 | } |
115 | |
110 | |
116 | sub on_mapenter { |
111 | cf::attach_to_players prio => -900, |
117 | my ($ob) = @_; |
112 | on_map_change => sub { |
|
|
113 | my ($pl, $new, $x, $x) = @_; |
118 | |
114 | |
119 | prefetch_map $ob->map; |
115 | prefetch_map $new; |
120 | } |
116 | }, |
|
|
117 | ; |
121 | |
118 | |
|
|
119 | if (0) { #test# |
122 | # prefetch a few players/second |
120 | # prefetch a few players/second |
123 | { |
121 | { |
124 | my @players; |
122 | my @players; |
125 | |
123 | |
126 | Event->timer (interval => 0.2, cb => sub { |
124 | Event->timer (interval => 0.2, data => cf::WF_AUTOCANCEL, cb => sub { |
127 | @players = map $_->ob->name, cf::player::list unless @players; |
125 | @players = map $_->ob->name, cf::player::list unless @players; |
128 | my $player = cf::player::find pop @players |
126 | my $player = cf::player::find pop @players |
129 | or return; |
127 | or return; |
130 | |
128 | |
131 | if (my $map = $player->ob->map) { |
129 | if (my $map = $player->ob->map) { |
… | |
… | |
135 | prefetch map => +($player->get_savebed)[0]; |
133 | prefetch map => +($player->get_savebed)[0]; |
136 | }); |
134 | }); |
137 | } |
135 | } |
138 | |
136 | |
139 | # prefetch all .pl files every few minutes (thats only a "few" megabytes) |
137 | # prefetch all .pl files every few minutes (thats only a "few" megabytes) |
140 | Event->timer (after => 1, interval => 600, cb => sub { |
138 | Event->timer (after => 1, interval => 600, data => cf::WF_AUTOCANCEL, cb => sub { |
141 | my $playerdir = cf::localdir . "/" . cf::playerdir; |
139 | my $playerdir = cf::localdir . "/" . cf::playerdir; |
142 | |
140 | |
143 | aio_readdir $playerdir, sub { |
141 | aio_readdir $playerdir, sub { |
144 | my ($players) = @_; |
142 | my ($players) = @_; |
145 | my $prefetch; $prefetch = sub { |
143 | my $prefetch; $prefetch = sub { |