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

Comparing deliantra/maps/perl/map-prefetch.ext (file contents):
Revision 1.9 by root, Wed Aug 2 11:17:08 2006 UTC vs.
Revision 1.15 by root, Fri Dec 15 19:06:29 2006 UTC

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
7if (0) { #test#
8use Errno (); 7use Errno ();
9use Time::HiRes; 8use Time::HiRes;
10use Fcntl; 9use Fcntl;
11use IO::AIO; 10use IO::AIO;
12
13Event->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
18sub find_exits { 13sub 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
116sub on_mapenter { 111cf::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
119if (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)
140Event->timer (after => 1, interval => 600, cb => sub { 138Event->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 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines