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

Comparing cf.schmorp.de/server/utils/cfutil.in (file contents):
Revision 1.22 by root, Thu Apr 5 13:50:49 2007 UTC vs.
Revision 1.27 by root, Wed Apr 18 07:59:03 2007 UTC

20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5; 24use Digest::MD5;
25use Storable; $Storable::canonical = 1; 25use Coro::Storable; $Storable::canonical = 1;
26 26
27sub usage { 27sub usage {
28 warn <<EOF; 28 warn <<EOF;
29Usage: cfutil [-v] [-q] [--force] [--cache] 29Usage: cfutil [-v] [-q] [--force] [--cache]
30 [--install-arch path] 30 [--install-arch path]
82 82
83 print "maps installed successfully.\n"; 83 print "maps installed successfully.\n";
84} 84}
85 85
86{ 86{
87 our %ANIMINFO;
87 our %FACEINFO; 88 our %FACEINFO;
88 our @ARC; 89 our %ARC;
89 our $TRS; 90 our $TRS;
90 our $NFILE; 91 our $NFILE;
91 our %ANIM;
92 92
93 our $QUANTIZE = "+dither -colorspace RGB -colors 256"; 93 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
94 94
95 our (@png, @trs, @arc); # files we are interested in 95 our (@png, @trs, @arc); # files we are interested in
96 96
182 } 182 }
183 } 183 }
184 184
185 (my $face = $stem) =~ s/^.*\///; 185 (my $face = $stem) =~ s/^.*\///;
186 186
187 # split all bigfaces, but avoid smoothfaces (*_S)
187 if (($w > $T || $h > $T) && $face !~ /_S\./) { 188 if (($w > $T || $h > $T) && $face !~ /_S\./) {
188 # split 189 # split
189 my @tile; 190 my @tile;
190 for my $x (0 .. (int $w / $T) - 1) { 191 for my $x (0 .. (int $w / $T) - 1) {
191 for my $y (0 .. (int $h / $T) - 1) { 192 for my $y (0 .. (int $h / $T) - 1) {
254 my $arc; 255 my $arc;
255 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 256 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
256 257
257 my $arc = read_arch "$dir/$file"; 258 my $arc = read_arch "$dir/$file";
258 for my $o (values %$arc) { 259 for my $o (values %$arc) {
259 push @ARC, $o; 260 $ARC{$o->{_name}} = $o;
260 261
261 $o->{editor_folder} = $dir; 262 $o->{editor_folder} = $dir;
262 263
263 my $visibility = delete $o->{visibility}; 264 my $visibility = delete $o->{visibility};
264 my $magicmap = delete $o->{magicmap}; 265 my $magicmap = delete $o->{magicmap};
275 my $x = $o->{x} - $dx; 276 my $x = $o->{x} - $dx;
276 my $y = $o->{y} - $dy; 277 my $y = $o->{y} - $dy;
277 278
278 my $ext = $x|$y ? "+$x+$y" : ""; 279 my $ext = $x|$y ? "+$x+$y" : "";
279 280
280 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; 281 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
281 282
282 my $visibility = delete $o->{visibility} if exists $o->{visibility}; 283 my $visibility = delete $o->{visibility} if exists $o->{visibility};
283 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 284 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
284 285
285 my $anim = delete $o->{anim}; 286 my $anim = delete $o->{anim};
286 287
287 if ($anim) { 288 if ($anim) {
289 # possibly add $ext to the animation name to avoid
290 # the need to specify archnames for all parts
291 # of a multipart archetype.
288 $o->{animation} = "$o->{_name}"; 292 $o->{animation} = "$o->{_name}";
293 my $facings = 1;
294 my @frames;
289 295
290 for (@$anim) { 296 for (@$anim) {
291 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; 297 if (/^facings\s+(\d+)/) {
298 $facings = $1*1;
299 } elsif (/^blank.x11$|^empty.x11$/) {
300 push @frames, $_;
301 } else {
302 push @frames, "$_$ext";
303 }
292 } 304 }
293 305
294 $ANIM{"$o->{_name}$ext"} = 306 $ANIMINFO{$o->{animation}} = {
295 join "", map "$_\n", 307 facings => $facings,
296 "anim $o->{_name}", 308 frames => \@frames,
297 @$anim, 309 };
298 "mina";
299 } 310 }
300 311
301 for my $face ($o->{face} || (), @{$anim || []}) { 312 for my $face ($o->{face} || (), @{$anim || []}) {
302 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; 313 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
303 314
306 $info->{visibility} = $visibility if defined $visibility; 317 $info->{visibility} = $visibility if defined $visibility;
307 $info->{magicmap} = $magicmap if defined $magicmap; 318 $info->{magicmap} = $magicmap if defined $magicmap;
308 } 319 }
309 320
310 if (my $smooth = delete $o->{smoothface}) { 321 if (my $smooth = delete $o->{smoothface}) {
311 my ($face, $smooth) = split /\s+/, $smooth; 322 my %kv =split /\s+/, $smooth;
312 # skip empty_S.x11, it seems to server no purpose whatsoever 323 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
313 # but increases bandwidth demands and worse. 324 while (my ($face, $smooth) = each %kv) {
314 unless ($smooth eq "empty_S.x11") {
315 $FACEINFO{$face}{smooth} = $smooth; 325 $FACEINFO{$face}{smooth} = $smooth;
326 $FACEINFO{$face}{smoothlevel} = $level;
316 } 327 }
317 } 328 }
318 } 329 }
319 } 330 }
320 } 331 }
361 } 372 }
362 373
363 sub inst_arch($) { 374 sub inst_arch($) {
364 my (undef, $path) = @_; 375 my (undef, $path) = @_;
365 376
366 print "installing '$path' to '$DATADIR'\n", 377 print "Installing '$path' to '$DATADIR'\n",
367 "(this can take a long time if you run this\n", 378 "This can take a long time if you run this\n",
368 "for the first time or do not use --cache).\n"; 379 "for the first time or do not use --cache.\n",
380 "\n",
381 "Unless you run verbosely, all following warning\n",
382 "or error messages indicate serious problems.\n",
383 "\n";
369 384
370 if (!-d "$path/treasures") { 385 if (!-d "$path/treasures") {
371 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 386 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n";
372 exit 1 unless $FORCE; 387 exit 1 unless $FORCE;
373 } 388 }
381 (async \&process_trs), (async \&process_trs), 396 (async \&process_trs), (async \&process_trs),
382 (async \&process_arc), (async \&process_arc), 397 (async \&process_arc), (async \&process_arc),
383 ); 398 );
384 399
385 { 400 {
386 open my $fh, ">:utf8", "$DATADIR/animations~" 401 # remove path prefix from editor_folder
387 or die "$DATADIR/animations~: $!"; 402 substr $_->{editor_folder}, 0, 1 + length $path, ""
388 print $fh join "", map $ANIM{$_}, sort keys %ANIM 403 for values %ARC;
404
405 # resolve inherit
406 while () {
407 my $progress;
408 my $loop;
409
410 for my $o (values %ARC) {
411 if (my $other = $o->{inherit}) {
412 if (my $s = $ARC{$other}) {
413 if ($s->{inherit}) {
414 $loop = $s;
415 } else {
416 delete $o->{inherit};
417 %$o = ( %$s, %$o );
418 ++$progress;
419 }
420 } else {
421 warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n";
422 delete $ARC{$o->{_name}};
423 }
424 }
425 }
426
427 unless ($progress) {
428 die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n"
429 if $loop;
430
431 last;
432 }
389 } 433 }
390 434
391 {
392 open my $fh, ">:utf8", "$DATADIR/archetypes~" 435 open my $fh, ">:utf8", "$DATADIR/archetypes~"
393 or die "$DATADIR/archetypes~: $!"; 436 or die "$DATADIR/archetypes~: $!";
394 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; 437 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } values %ARC];
395 print $fh Crossfire::archlist_to_string \@ARC;
396 } 438 }
397 439
398 { 440 {
399 open my $fh, ">:utf8", "$DATADIR/treasures~" 441 open my $fh, ">:utf8", "$DATADIR/treasures~"
400 or die "$DATADIR/treasures~: $!"; 442 or die "$DATADIR/treasures~: $!";
414 } 456 }
415 457
416 open my $fh, ">:perlio", "$DATADIR/facedata~" 458 open my $fh, ">:perlio", "$DATADIR/facedata~"
417 or die "$DATADIR/facedata~: $!"; 459 or die "$DATADIR/facedata~: $!";
418 460
419 $FACEINFO{""} = { version => 1}; 461 print $fh freeze {
420 print $fh Storable::nfreeze \%FACEINFO; 462 version => 2,
463 faceinfo => \%FACEINFO,
464 animinfo => \%ANIMINFO,
421 } 465 };
466 }
422 467
423 for (qw(archetypes facedata animations treasures)) { 468 for (qw(archetypes facedata treasures)) {
424 chmod 0644, "$DATADIR/$_~"; 469 chmod 0644, "$DATADIR/$_~";
425 rename "$DATADIR/$_~", "$DATADIR/$_" 470 rename "$DATADIR/$_~", "$DATADIR/$_"
426 or die "$DATADIR/$_: $!"; 471 or die "$DATADIR/$_: $!";
427 } 472 }
428 473

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines