… | |
… | |
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 | |
|
|
59 | sub clean_random_maps { |
|
|
60 | return;#d# |
|
|
61 | my $files = Coro::AIO::aio_readdir $cf::RANDOMDIR |
|
|
62 | or return; |
|
|
63 | |
|
|
64 | my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7; |
|
|
65 | |
|
|
66 | for my $file (@$files) { |
|
|
67 | next unless $file =~ /\.meta$/; |
|
|
68 | |
|
|
69 | Coro::AIO::aio_stat "$cf::RANDOMDIR/$file" |
|
|
70 | and next; |
|
|
71 | |
|
|
72 | my $age = $cf::NOW - (stat _)[8]; |
|
|
73 | |
|
|
74 | if ($age > $META_TIMEOUT) { |
|
|
75 | warn "resetting random meta data for $file"; |
|
|
76 | IO::AIO::aio_unlink "$cf::RANDOMDIR/$file"; |
|
|
77 | } |
|
|
78 | } |
|
|
79 | } |
57 | } |
80 | |
58 | |
81 | # called by the random map generator |
59 | # called by the random map generator |
82 | sub find_style_; |
60 | sub find_style_; |
83 | sub find_style_($$) { |
61 | sub find_style_($$) { |
… | |
… | |
139 | |
117 | |
140 | #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d# |
118 | #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d# |
141 | $map |
119 | $map |
142 | } |
120 | } |
143 | |
121 | |
144 | # clean up old temp maps regularly |
122 | cf::async_ext { |
145 | our $CLEAN_RANDOM_MAPS = cf::periodic 3600, Coro::unblock_sub { |
123 | $Coro::current->{desc} = "random map meta file cleaner"; |
146 | 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 | } |
147 | }; |
150 | }; |
148 | |
151 | |
149 | # map generator stresstest, NEVER enable under normal circumstances |
152 | # map generator stresstest, NEVER enable under normal circumstances |
150 | if ($ENV{STRESSTEST}) { |
153 | if ($ENV{STRESSTEST}) { |
151 | cf::async { |
154 | cf::async { |
… | |
… | |
175 | } |
178 | } |
176 | } |
179 | } |
177 | }; |
180 | }; |
178 | } |
181 | } |
179 | |
182 | |
|
|
183 | # save test |
|
|
184 | if (0) { |
|
|
185 | cf::async { |
|
|
186 | # 0.080 |
|
|
187 | Coro::Timer::sleep 2; |
|
|
188 | my $map = cf::map::find "/mlab/citydeclouds2"; |
|
|
189 | $map->load_header; |
|
|
190 | $map->load; |
|
|
191 | $map->post_load_original; |
|
|
192 | my $m=100; |
|
|
193 | for (1..50) { |
|
|
194 | my $t=EV::time; |
|
|
195 | $map->_save_objects ("/tmp/x", cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); |
|
|
196 | $t = EV::time-$t; |
|
|
197 | $m=$t if $m>$t; |
|
|
198 | warn $m; |
|
|
199 | } |
|
|
200 | }; |
|
|
201 | } |
|
|
202 | |
180 | 1 |
203 | 1 |
181 | |
204 | |