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.6 by root, Tue Jul 11 15:37:31 2006 UTC vs.
Revision 1.9 by root, Wed Aug 2 11:17:08 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#
7use Errno (); 8use Errno ();
8use Time::HiRes; 9use Time::HiRes;
9use Fcntl; 10use Fcntl;
10use IO::AIO; 11use 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
106my %MAP_EXITS; 107my %MAP_EXITS;
107 108
108sub prefetch_map { 109sub 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines