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.10 by root, Thu Aug 3 11:23:58 2006 UTC vs.
Revision 1.15 by root, Fri Dec 15 19:06:29 2006 UTC

6 6
7use Errno (); 7use Errno ();
8use Time::HiRes; 8use Time::HiRes;
9use Fcntl; 9use Fcntl;
10use IO::AIO; 10use IO::AIO;
11
12Event->io (fd => IO::AIO::poll_fileno,
13 poll => 'r',
14 cb => \&IO::AIO::poll_cb);
15 11
16# 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
17sub find_exits { 13sub find_exits {
18 my ($map) = @_; 14 my ($map) = @_;
19 15
110 106
111 my $exit = $MAP_EXITS{$map->path} ||= find_exits $map; 107 my $exit = $MAP_EXITS{$map->path} ||= find_exits $map;
112 prefetch map => $_ for @$exit; 108 prefetch map => $_ for @$exit;
113} 109}
114 110
115sub on_mapenter { 111cf::attach_to_players prio => -900,
116 my ($ob) = @_; 112 on_map_change => sub {
113 my ($pl, $new, $x, $x) = @_;
117 114
118 prefetch_map $ob->map; 115 prefetch_map $new;
119} 116 },
117;
120 118
121if (0) { #test# 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