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.32 by root, Mon Sep 22 05:42:41 2008 UTC vs.
Revision 1.39 by root, Sat Mar 27 20:12:24 2010 UTC

54 $self->activate; 54 $self->activate;
55 55
56 1 56 1
57} 57}
58 58
59sub clean_random_maps { 59sub select_random_map {
60 return;#d# 60 my ($maps, $difficulty) = @_;
61 my $files = Coro::AIO::aio_readdir $cf::RANDOMDIR
62 or return;
63 61
64 my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7; 62 # because I am lazy, I ignore the weighting
65 63
66 for my $file (@$files) { 64 my @maps = keys %$maps;
67 next unless $file =~ /\.meta$/;
68 65
69 Coro::AIO::aio_stat "$cf::RANDOMDIR/$file" 66 cf::map::find "/styles/$maps[cf::rmg_rndm scalar @maps]"
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} 67}
80 68
81# called by the random map generator 69# called by the random map generator
82sub find_style_; 70sub find_style_;
83sub find_style_($$) { 71sub find_style_($$) {
84 my ($path, $difficulty) = @_; 72 my ($path, $difficulty) = @_;
85 73
86 my $map; 74 my $map;
75
76 # see if there is a metafile
77 if (0 < aio_load "$cf::MAPDIR/$path.rmg", my $meta) {
78 $meta = cf::decode_json $meta;
79
80 # only "maps" is supported
81 if ($meta->{maps}) {
82 $map = select_random_map $meta->{maps}, $difficulty;
83 }
84 }
87 85
88 $map = cf::map::find $path 86 $map = cf::map::find $path
89 unless aio_stat "$cf::MAPDIR/$path.map"; 87 unless aio_stat "$cf::MAPDIR/$path.map";
90 88
91 unless ($map) { 89 unless ($map) {
128sub find_style($$$) { 126sub find_style($$$) {
129 my ($dir, $name, $difficulty) = @_; 127 my ($dir, $name, $difficulty) = @_;
130 128
131 cf::cede_to_tick; 129 cf::cede_to_tick;
132 130
131 my $map;
132
133 if ($name) {
133 my $map = find_style_ $name ? "$dir/$name" : $dir, $difficulty; 134 $map = find_style_ "$dir/$name", $difficulty;
135 } else {
136 $map = (find_style_ "$dir/default", $difficulty)
137 || (find_style_ $dir, $difficulty);
138 }
134 139
135 if ($map) { 140 if ($map) {
136 $map->load; 141 $map->load;
137 $map->deactivate; 142 $map->deactivate;
138 } 143 }
139 144
140 #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d# 145 #warn "return $dir,$name,$difficulty => $map\n" if $difficulty >= 0;#d#
141 $map 146 $map
142} 147}
143 148
144# clean up old temp maps regularly 149cf::async_ext {
145our $CLEAN_RANDOM_MAPS = cf::periodic 3600, Coro::unblock_sub { 150 $Coro::current->{desc} = "random map meta file cleaner";
146 clean_random_maps; 151 $Coro::current->nice (1);
152
153 while () {
154 my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7;
155
156 Coro::AnyEvent::idle_upto $META_TIMEOUT / 10 * 2;
157
158 my ($files) = Coro::AIO::aio_readdirx $cf::RANDOMDIR, IO::AIO::READDIR_STAT_ORDER
159 or return;
160
161 for my $file (@$files) {
162 next unless $file =~ /\.meta$/;
163
164 Coro::AIO::aio_stat "$cf::RANDOMDIR/$file"
165 and next;
166
167 my $age = $cf::NOW - (stat _)[8];
168
169 if ($age > $META_TIMEOUT) {
170 warn "resetting random meta data for $file";
171 IO::AIO::aio_unlink "$cf::RANDOMDIR/$file";
172 }
173 }
174
175 Coro::AnyEvent::sleep $META_TIMEOUT / 10;
176 }
147}; 177};
148 178
149# map generator stresstest, NEVER enable under normal circumstances 179# map generator stresstest, NEVER enable under normal circumstances
150if ($ENV{STRESSTEST}) { 180if ($ENV{STRESSTEST}) {
151 cf::async { 181 cf::async {
175 } 205 }
176 } 206 }
177 }; 207 };
178} 208}
179 209
210# save test
211if (0) {
212 cf::async {
213 # 0.080
214 Coro::Timer::sleep 2;
215 my $map = cf::map::find "/mlab/citydeclouds2";
216 $map->load_header;
217 $map->load;
218 $map->post_load_original;
219 my $m=100;
220 for (1..50) {
221 my $t=EV::time;
222 $map->_save_objects ("/tmp/x", cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES);
223 $t = EV::time-$t;
224 $m=$t if $m>$t;
225 warn $m;
226 }
227 };
228}
229
1801 2301
181 231

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines