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.14 by root, Tue Nov 7 15:04:44 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
89 85
90 if ($type eq "map") { 86 if ($type eq "map") {
91 if (my $map = cf::map::has_been_loaded $path) { 87 if (my $map = cf::map::has_been_loaded $path) {
92 $cb->(), next if $map->in_memory == cf::MAP_IN_MEMORY; 88 $cb->(), next if $map->in_memory == cf::MAP_IN_MEMORY;
93 89
94 prefetch file => $map->tmppath 90 prefetch file => $map->tmpname
95 if $map->in_memory == cf::MAP_SWAPPED; 91 if $map->in_memory == cf::MAP_SWAPPED;
96 } 92 }
97 } 93 }
98 94
99 load_file $path, $cb; 95 load_file $path, $cb;
103 $PREFETCHING = 0; 99 $PREFETCHING = 0;
104} 100}
105 101
106my %MAP_EXITS; 102my %MAP_EXITS;
107 103
108sub prefetch_map { 104sub prefetch_map($) {
109 my ($map) = @_; 105 my ($map) = @_;
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
119if (0) { #test#
121# prefetch a few players/second 120# prefetch a few players/second
122{ 121{
123 my @players; 122 my @players;
124 123
125 Event->timer (interval => 0.2, cb => sub { 124 Event->timer (interval => 0.2, cb => sub {
126 @players = map $_->ob->name, cf::player::list unless @players; 125 @players = map $_->ob->name, cf::player::list unless @players;
127 my $player = cf::player::find pop @players 126 my $player = cf::player::find pop @players
128 or return; 127 or return;
129 128
129 if (my $map = $player->ob->map) {
130 prefetch_map $player->ob->map; 130 prefetch_map $map;
131 }
132
131 prefetch map => +($player->get_savebed)[0]; 133 prefetch map => +($player->get_savebed)[0];
132 }); 134 });
133} 135}
134 136
135# 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)
146 }; 148 };
147 149
148 $prefetch->(); $prefetch->(); 150 $prefetch->(); $prefetch->();
149 }; 151 };
150}); 152});
153}
151 154
152 155
153 156

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines