ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/utils/cfutil.in
(Generate patch)

Comparing deliantra/server/utils/cfutil.in (file contents):
Revision 1.5 by root, Thu Mar 8 15:19:08 2007 UTC vs.
Revision 1.11 by root, Mon Mar 12 14:55:43 2007 UTC

19use File::Temp; 19use File::Temp;
20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5;
24 25
25sub usage { 26sub usage {
26 warn <<EOF; 27 warn <<EOF;
27Usage: cfutil [-v] [-q] [--force] [--cache] 28Usage: cfutil [-v] [-q] [--force] [--cache]
28 [--install-arch path] 29 [--install-arch path]
77 78
78 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; 79 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded";
79} 80}
80 81
81{ 82{
82 our @PNG; 83 our %PNG32;
84 our %FACEINFO;
83 our @ARC; 85 our @ARC;
84 our $NFILE; 86 our $NFILE;
85 our @FACE;
86 our $ANIM; 87 our %ANIM;
87 88
88 our (@png, @trs, @arc); # files we are interested in 89 our (@png, @trs, @arc); # files we are interested in
89 90
90 sub commit_png { 91 sub commit_png {
91 my ($name, $data) = @_; 92 my ($name, $data) = @_;
92 93
93 push @PNG, [$name => $data]; 94 $PNG32{$name} = $data;
95 $FACEINFO{$name} ||= {};
94 } 96 }
95 97
96 sub process_png { 98 sub process_png {
97 while (@png) { 99 while (@png) {
98 my $path = pop @png; 100 my $path = pop @png;
104 if (0 > aio_load $path, $png) { 106 if (0 > aio_load $path, $png) {
105 warn "$path: $!, skipping.\n"; 107 warn "$path: $!, skipping.\n";
106 next; 108 next;
107 } 109 }
108 110
109 # quickly extratc width and height of the (necessarily PNG) image 111 # quickly extract width and height of the (necessarily PNG) image
110 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 112 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
111 warn "$path: not a recongized png file, skipping.\n"; 113 warn "$path: not a recongized png file, skipping.\n";
112 next; 114 next;
113 } 115 }
114 116
147 my @todo = grep { $_->[3] <= $mtime } @tile; 149 my @todo = grep { $_->[3] <= $mtime } @tile;
148 if (@todo) { 150 if (@todo) {
149 fork_sub { 151 fork_sub {
150 open my $convert, "|-", $CONVERT, 152 open my $convert, "|-", $CONVERT,
151 "png:-", 153 "png:-",
152 -negate,#d#
153 (map { 154 (map {
154 ( 155 (
155 "(", 156 "(",
156 "+clone", 157 "+clone",
157 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 158 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
159 "+repage",
158 -write => "png:$_->[2]~", 160 -write => "png:$_->[2]~",
159 "+delete", 161 "+delete",
160 ")", 162 ")",
161 ) 163 )
162 } @todo), 164 } @todo),
199 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 201 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
200 202
201 my $arc = read_arch "$dir/$file"; 203 my $arc = read_arch "$dir/$file";
202 for my $o (values %$arc) { 204 for my $o (values %$arc) {
203 push @ARC, $o; 205 push @ARC, $o;
206
207 $o->{editor_folder} = $dir;
208
209 my $visibility = delete $o->{visibility};
210 my $magicmap = delete $o->{magicmap};
211
212 # find upper left corner :/
213 # omg, this is sooo broken
204 my ($dx, $dy); 214 my ($dx, $dy);
205 # omg, this is sooo broken
206 for (my $o = $o; $o; $o = $o->{more}) { 215 for (my $o = $o; $o; $o = $o->{more}) {
207 $dx = $o->{x} if $o->{x} < $dx; 216 $dx = $o->{x} if $o->{x} < $dx;
208 $dy = $o->{y} if $o->{y} < $dy; 217 $dy = $o->{y} if $o->{y} < $dy;
209 } 218 }
219
210 for (my $o = $o; $o; $o = $o->{more}) { 220 for (my $o = $o; $o; $o = $o->{more}) {
211 my $x = $o->{x} - $dx; 221 my $x = $o->{x} - $dx;
212 my $y = $o->{y} - $dy; 222 my $y = $o->{y} - $dy;
223
224 my $ext = $x|$y ? "+$x+$y" : "";
225
226 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/;
227
228 my $visibility = delete $o->{visibility} if exists $o->{visibility};
229 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
230
231 my $anim = delete $o->{anim};
232
213 if ($x|$y) { 233 if ($anim) {
214 $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; 234 $o->{animation} = "$o->{_name}";
235
236 for (@$anim) {
237 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/;
238 }
239
240 $ANIM{"$o->{_name}$ext"} =
241 join "", map "$_\n",
242 "anim $o->{_name}",
243 @$anim,
244 "mina";
215 } 245 }
246
247 for my $face ($o->{face} || (), @{$anim || []}) {
248 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
249
250 my $info = $FACEINFO{$face} ||= {};
251
252 $info->{visibility} = $visibility if defined $visibility;
253 $info->{magicmap} = $magicmap if defined $magicmap;
216 } 254 }
217 if (my $anim = delete $o->{anim}) {
218 $o->{animation} = $o->{_name};
219 $ANIM .= join "", map "$_\n",
220 "anim $o->{_name}",
221 @$anim,
222 "mina";
223 } 255 }
224 } 256 }
225 } 257 }
226 } 258 }
227 259
276 ); 308 );
277 309
278 { 310 {
279 open my $fh, ">:utf8", "$DATADIR/animations~" 311 open my $fh, ">:utf8", "$DATADIR/animations~"
280 or die "$DATADIR/animations~: $!"; 312 or die "$DATADIR/animations~: $!";
281 print $fh $ANIM; 313 print $fh join "", map $ANIM{$_}, sort keys %ANIM
282 } 314 }
283 315
284 { 316 {
285 open my $fh, ">:utf8", "$DATADIR/archetypes~" 317 open my $fh, ">:utf8", "$DATADIR/archetypes~"
286 or die "$DATADIR/archetypes~: $!"; 318 or die "$DATADIR/archetypes~: $!";
319 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC;
287 print $fh Crossfire::archlist_to_string \@ARC; 320 print $fh Crossfire::archlist_to_string \@ARC;
288 } 321 }
289 322
290 @PNG = sort { $a->[0] cmp $b->[0] } @PNG;
291
292 { 323 {
324 while (my ($k, $v) = each %FACEINFO) {
325 $v->{data32} ||= delete $PNG32{$k};
326 }
327
328 while (my ($k, $v) = each %FACEINFO) {
329 length $v->{data32} or warn "$k: face has no png32. this will crash the server.\n";
330
331 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
332 }
333
293 open my $fh, ">:perlio", "$DATADIR/crossfire.0~" 334 open my $fh, ">:perlio", "$DATADIR/faces~"
294 or die "$DATADIR/crossfire.0~: $!"; 335 or die "$DATADIR/faces~: $!";
295 printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1]
296 for 0.. $#PNG;
297 }
298 336
299 rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; 337 print $fh Storable::nfreeze \%FACEINFO;
300 rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; 338
301 rename "$DATADIR/animations~" , "$DATADIR/animations"; 339 #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO;
340 }
341
342 for (qw(archetypes faces animations)) {
343 chmod 0644, "$DATADIR/$_~";
344 rename "$DATADIR/$_~", "$DATADIR/$_";
345 }
302 346
303 die "--install-arch not fully implemented\n"; 347 die "--install-arch not fully implemented\n";
304 } 348 }
305} 349}
306 350

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines