… | |
… | |
55 | |
55 | |
56 | 1 |
56 | 1 |
57 | } |
57 | } |
58 | |
58 | |
59 | sub clean_random_maps { |
59 | sub clean_random_maps { |
60 | my $files = Coro::AIO::aio_readdir $cf::RANDOMDIR |
60 | my $files = Coro::AIO::aio_readdirx $cf::RANDOMDIR, IO::AIO::READDIR_STAT_ORDER |
61 | or return; |
61 | or return; |
62 | |
62 | |
63 | my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7; |
63 | my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7; |
64 | |
64 | |
65 | for my $file (@$files) { |
65 | for my $file (@$files) { |
… | |
… | |
80 | # called by the random map generator |
80 | # called by the random map generator |
81 | sub find_style_; |
81 | sub find_style_; |
82 | sub find_style_($$) { |
82 | sub find_style_($$) { |
83 | my ($path, $difficulty) = @_; |
83 | my ($path, $difficulty) = @_; |
84 | |
84 | |
85 | my $mapdir = cf::datadir . "/" . cf::mapdir; |
|
|
86 | |
|
|
87 | my $map; |
85 | my $map; |
88 | |
86 | |
89 | $map = cf::map::find $path |
87 | $map = cf::map::find $path |
90 | unless aio_stat "$mapdir/$path.map"; |
88 | unless aio_stat "$cf::MAPDIR/$path.map"; |
91 | |
89 | |
92 | unless ($map) { |
90 | unless ($map) { |
93 | # search files and/or dirs |
91 | # search files and/or dirs |
94 | if (my ($dirs, $nondirs) = aio_scandir "$mapdir/$path/", 1) { |
92 | if (my ($dirs, $nondirs) = aio_scandir "$cf::MAPDIR/$path/", 1) { |
95 | my @entries = sort grep s/\.map$//, @$nondirs; |
93 | my @entries = sort grep s/\.map$//, @$nondirs; |
96 | |
94 | |
97 | if ($difficulty < 0) { |
95 | if ($difficulty < 0) { |
98 | # pick a fully random map, but only a map, do not recurse |
96 | # pick a fully random map, but only a map, do not recurse |
99 | $map = cf::map::find "$path/$entries[cf::rmg_rndm scalar @entries]" |
97 | $map = cf::map::find "$path/$entries[cf::rmg_rndm scalar @entries]" |
… | |
… | |
136 | if ($map) { |
134 | if ($map) { |
137 | $map->load; |
135 | $map->load; |
138 | $map->deactivate; |
136 | $map->deactivate; |
139 | } |
137 | } |
140 | |
138 | |
141 | warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d# |
139 | #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d# |
142 | $map |
140 | $map |
143 | } |
141 | } |
144 | |
142 | |
145 | # clean up old temp maps regularly |
143 | # clean up old temp maps regularly |
146 | our $CLEAN_RANDOM_MAPS = cf::periodic 3600, Coro::unblock_sub { |
144 | our $CLEAN_RANDOM_MAPS = cf::periodic 3600, Coro::unblock_sub { |
147 | clean_random_maps; |
145 | clean_random_maps; |
148 | }; |
146 | }; |
149 | |
147 | |
150 | # map generator stresstest, NEVER enable under normal circumstances |
148 | # map generator stresstest, NEVER enable under normal circumstances |
151 | if (0) { |
149 | if ($ENV{STRESSTEST}) { |
152 | cf::async { |
150 | cf::async { |
153 | my $seed = 0; |
151 | my $seed = 0; |
154 | while () { |
152 | while () { |
155 | my $map = cf::map::new; |
153 | my $map = cf::map::new; |
156 | $map->generate_random_map ({ |
154 | $map->generate_random_map ({ |
157 | region => "scorn", |
155 | region => "scorn", |
158 | random_seed => $seed++, |
156 | random_seed => $seed++, |
159 | xsize => (int rand 90) + 3, |
157 | xsize => (int rand 100) + 1, |
160 | ysize => (int rand 90) + 3, |
158 | ysize => (int rand 100) + 1, |
161 | }); |
159 | }); |
162 | # warn sprintf "%d: %d %d\n", $seed, $map->width, $map->height;#d# |
160 | warn sprintf "%d: %dx%d o# %d\n", $seed, $map->width, $map->height, &cf::object::objects_size;#d# |
163 | $map->destroy; |
161 | $map->destroy; |
164 | } |
162 | } |
165 | }; |
163 | }; |
166 | } |
164 | } |
167 | |
165 | |
… | |
… | |
176 | } |
174 | } |
177 | } |
175 | } |
178 | }; |
176 | }; |
179 | } |
177 | } |
180 | |
178 | |
|
|
179 | # save test |
|
|
180 | if (0) { |
|
|
181 | cf::async { |
|
|
182 | # 0.58 |
|
|
183 | Coro::Timer::sleep 2; |
|
|
184 | my $map = cf::map::find "/mlab/citydeclouds2"; |
|
|
185 | $map->load_header; |
|
|
186 | $map->load; |
|
|
187 | $map->post_load_original; |
|
|
188 | my $m=100; |
|
|
189 | for (1..50) { |
|
|
190 | my $t=EV::time; |
|
|
191 | $map->_save_objects ("/tmp/x", cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); |
|
|
192 | $t = EV::time-$t; |
|
|
193 | $m=$t if $m>$t; |
|
|
194 | warn $m; |
|
|
195 | } |
|
|
196 | }; |
|
|
197 | } |
|
|
198 | |
181 | 1 |
199 | 1 |
182 | |
200 | |