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

Comparing deliantra/server/ext/map-random.ext (file contents):
Revision 1.37 by root, Mon Nov 9 03:08:55 2009 UTC vs.
Revision 1.38 by root, Fri Mar 26 00:26:48 2010 UTC

52 52
53 $self->generate_random_map ($self->{random}); 53 $self->generate_random_map ($self->{random});
54 $self->activate; 54 $self->activate;
55 55
56 1 56 1
57}
58
59sub clean_random_maps {
60 my $files = Coro::AIO::aio_readdirx $cf::RANDOMDIR, IO::AIO::READDIR_STAT_ORDER
61 or return;
62
63 my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7;
64
65 for my $file (@$files) {
66 next unless $file =~ /\.meta$/;
67
68 Coro::AIO::aio_stat "$cf::RANDOMDIR/$file"
69 and next;
70
71 my $age = $cf::NOW - (stat _)[8];
72
73 if ($age > $META_TIMEOUT) {
74 warn "resetting random meta data for $file";
75 IO::AIO::aio_unlink "$cf::RANDOMDIR/$file";
76 }
77 }
78} 57}
79 58
80# called by the random map generator 59# called by the random map generator
81sub find_style_; 60sub find_style_;
82sub find_style_($$) { 61sub find_style_($$) {
138 117
139 #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d# 118 #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d#
140 $map 119 $map
141} 120}
142 121
143# clean up old temp maps regularly 122cf::async_ext {
144our $CLEAN_RANDOM_MAPS = cf::periodic 3600, Coro::unblock_sub { 123 $Coro::current->{desc} = "random map meta file cleaner";
145 clean_random_maps; 124 $Coro::current->nice (1);
125
126 while () {
127 my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7;
128
129 Coro::AnyEvent::idle_upto $META_TIMEOUT / 10 * 2;
130
131 my ($files) = Coro::AIO::aio_readdirx $cf::RANDOMDIR, IO::AIO::READDIR_STAT_ORDER
132 or return;
133
134 for my $file (@$files) {
135 next unless $file =~ /\.meta$/;
136
137 Coro::AIO::aio_stat "$cf::RANDOMDIR/$file"
138 and next;
139
140 my $age = $cf::NOW - (stat _)[8];
141
142 if ($age > $META_TIMEOUT) {
143 warn "resetting random meta data for $file";
144 IO::AIO::aio_unlink "$cf::RANDOMDIR/$file";
145 }
146 }
147
148 Coro::AnyEvent::sleep $META_TIMEOUT / 10;
149 }
146}; 150};
147 151
148# map generator stresstest, NEVER enable under normal circumstances 152# map generator stresstest, NEVER enable under normal circumstances
149if ($ENV{STRESSTEST}) { 153if ($ENV{STRESSTEST}) {
150 cf::async { 154 cf::async {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines