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.52 by root, Sat Aug 18 22:25:35 2007 UTC vs.
Revision 1.53 by root, Sun Aug 19 09:27:08 2007 UTC

23use Coro::AIO; 23use Coro::AIO;
24use Coro::Util; 24use Coro::Util;
25use POSIX (); 25use POSIX ();
26use Digest::MD5; 26use Digest::MD5;
27use Carp; 27use Carp;
28use Coro::Channel;
28use Coro::Storable; $Storable::canonical = 1; 29use Coro::Storable; $Storable::canonical = 1;
29 30
30$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 31$SIG{QUIT} = sub { Carp::cluck "QUIT" };
31 32
32sub usage { 33sub usage {
114 our $NFILE; 115 our $NFILE;
115 our $PATH; 116 our $PATH;
116 117
117 our $QUANTIZE = "+dither -colorspace RGB -colors 256"; 118 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
118 119
119 our (@png, @trs, @arc, @res); # files we are interested in 120 our $c_arc = new Coro::Channel;
121 our $c_trs = new Coro::Channel;
122 our $c_res = new Coro::Channel;
123
124 our @c_png;
120 125
121 sub commit_png($$$) { 126 sub commit_png($$$) {
122 my ($name, $data, $T) = @_; 127 my ($name, $data, $T) = @_;
123 128
124 $FACEINFO{$name}{"data$T"} = $data; 129 $FACEINFO{$name}{"data$T"} = $data;
125 } 130 }
126 131
127 sub process_png { 132 sub process_png {
128 while (@png) { 133 while (@c_png) {
129 my ($path, $delete) = @{pop @png}; 134 my ($path, $delete) = @{pop @c_png};
130 135
131 my $png; 136 my $png;
132 aio_lstat $path; 137 aio_lstat $path;
133 my ($size, $mtime) = (stat _)[7,9]; 138 my ($size, $mtime) = (stat _)[7,9];
134 139
225 die "$other~ has zero size, aborting." unless -s "$other~"; 230 die "$other~ has zero size, aborting." unless -s "$other~";
226 rename "$other~", $other; 231 rename "$other~", $other;
227 }; 232 };
228 } 233 }
229 234
230 push @png, [$other, !$CACHE]; 235 push @c_png, [$other, !$CACHE];
231 } 236 }
232 237
233 # possibly scale down 238 # possibly scale down
234 if (0 > aio_stat "$stem.32x32.png") { 239 if (0 > aio_stat "$stem.32x32.png") {
235 my $other = "$stem.32x32.png~"; 240 my $other = "$stem.32x32.png~";
260 rename "$other~", $other; 265 rename "$other~", $other;
261 }; 266 };
262 } 267 }
263 268
264 #warn "scaled down $path to $other\n";#d# 269 #warn "scaled down $path to $other\n";#d#
265 push @png, [$other, !$CACHE]; 270 push @c_png, [$other, !$CACHE];
266 } 271 }
267 } 272 }
268 273
269 (my $face = $stem) =~ s/^.*\///; 274 (my $face = $stem) =~ s/^.*\///;
270 275
331 aio_unlink $path if $delete; 336 aio_unlink $path if $delete;
332 } 337 }
333 } 338 }
334 339
335 sub process_arc { 340 sub process_arc {
336 while (@arc) { 341 while (my $job = $c_arc->get) {
337 my ($dir, $file) = @{pop @arc}; 342 my ($dir, $file) = @$job;
338 343
339 my $arc; 344 my $arc;
340 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 345 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
341 346
342 my $arc = read_arch "$dir/$file"; 347 my $arc = read_arch "$dir/$file";
399 for my $face ($o->{face} || (), @{$anim || []}) { 404 for my $face ($o->{face} || (), @{$anim || []}) {
400 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; 405 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
401 406
402 my $info = $FACEINFO{$face} ||= {}; 407 my $info = $FACEINFO{$face} ||= {};
403 408
409 $info->{arc} = $o;
404 $info->{visibility} = $visibility if defined $visibility; 410 $info->{visibility} = $visibility if defined $visibility;
405 $info->{magicmap} = $magicmap if defined $magicmap; 411 $info->{magicmap} = $magicmap if defined $magicmap;
406 } 412 }
407 413
408 if (my $smooth = delete $o->{smoothface}) { 414 if (my $smooth = delete $o->{smoothface}) {
417 } 423 }
418 } 424 }
419 } 425 }
420 426
421 sub process_trs { 427 sub process_trs {
422 while (@trs) { 428 while (my $job = $c_trs->get) {
423 my ($dir, $file) = @{pop @trs}; 429 my ($dir, $file) = @$job;
424 my $path = "$dir/$file"; 430 my $path = "$dir/$file";
425 431
426 my $trs; 432 my $trs;
427 if (0 > aio_load $path, $trs) { 433 if (0 > aio_load $path, $trs) {
428 warn "$path: $!, skipping.\n"; 434 warn "$path: $!, skipping.\n";
450 456
451 $FILECACHE{$_[0]} 457 $FILECACHE{$_[0]}
452 } 458 }
453 459
454 sub process_res { 460 sub process_res {
455 while (@res) { 461 while (my $job = $c_res->get) {
456 my ($dir, $file, $type) = @{pop @res}; 462 my ($dir, $file, $type) = @$job;
457 463
458 my $data; 464 my $data;
459 aio_load "$dir/$file", $data; 465 aio_load "$dir/$file", $data;
460 466
461 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; 467 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift };
470 if ($meta->{license} =~ s/^#//) { 476 if ($meta->{license} =~ s/^#//) {
471 $meta->{license} = ({ 477 $meta->{license} = ({
472 "pd" => "Public Domain", 478 "pd" => "Public Domain",
473 "gpl" => "GNU General Public License, version 3.0 or any later", 479 "gpl" => "GNU General Public License, version 3.0 or any later",
474 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", 480 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
475 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.5/", 481 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/",
476 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", 482 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
477 })->{$meta->{license}} 483 })->{$meta->{license}}
478 || warn "$dir/$file: license tag '$meta->{license}' not found."; 484 || warn "$dir/$file: license tag '$meta->{license}' not found.";
479 } 485 }
480 486
506 my $dir = $path; 512 my $dir = $path;
507 substr $dir, 0, 1 + length $PATH, ""; 513 substr $dir, 0, 1 + length $PATH, "";
508 514
509 for my $file (@$nondirs) { 515 for my $file (@$nondirs) {
510 if ($dir =~ /^music(?:\/|$)/) { 516 if ($dir =~ /^music(?:\/|$)/) {
511 push @res, [$path, $file, 3] # FT_MUSIC 517 $c_res->put ([$path, $file, 3]) # FT_MUSIC
512 if $file =~ /\.(ogg)$/; 518 if $file =~ /\.(ogg)$/;
513 519
514 } elsif ($dir =~ /^sound(?:\/|$)/) { 520 } elsif ($dir =~ /^sound(?:\/|$)/) {
515 push @res, [$path, $file, 5] # FT_SOUND 521 $c_res->put ([$path, $file, 5]) # FT_SOUND
516 if $file =~ /\.(wav|ogg)$/; 522 if $file =~ /\.(wav|ogg)$/;
517 523
518 } elsif ($dir =~ /^res(?:\/|$)/) { 524 } elsif ($dir =~ /^res(?:\/|$)/) {
519 push @res, [$path, $file, 0] # FT_FACE 525 $c_res->put ([$path, $file, 0]) # FT_FACE
520 if $file =~ /\.(jpg|png)$/; 526 if $file =~ /\.(jpg|png)$/;
521 push @res, [$path, $file, 7] # FT_RSRC 527 $c_res->put ([$path, $file, 7]) # FT_RSRC
522 if $file =~ /\.(res)$/; 528 if $file =~ /\.(res)$/;
523 529
524 } elsif ($file =~ /\.png$/) { 530 } elsif ($file =~ /\.png$/) {
525 push @png, ["$path/$file", 0]; 531 push @c_png, ["$path/$file", 0];
526 532
527 } elsif ($file =~ /\.trs$/) { 533 } elsif ($file =~ /\.trs$/) {
528 push @trs, [$path, $file]; 534 $c_trs->put ([$path, $file]);
529 535
530 } elsif ($file =~ /\.arc$/) { 536 } elsif ($file =~ /\.arc$/) {
531 push @arc, [$path, $file]; 537 $c_arc->put ([$path, $file]);
532 538
533 } else { 539 } else {
534 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 540 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
535 } 541 }
536 } 542 }
555 if (!-d "$path/treasures") { 561 if (!-d "$path/treasures") {
556 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 562 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n";
557 exit 1 unless $FORCE; 563 exit 1 unless $FORCE;
558 } 564 }
559 565
566 print "scanning files...\n" if $VERBOSE;
567
560 find_files $path; 568 find_files $path;
569
570 my @a_arc = map +(async \&process_arc), 1..2;
571 my @a_res = map +(async \&process_res), 1..2;
572 my @a_trs = map +(async \&process_trs), 1..2;
573
561 IO::AIO::flush; 574 IO::AIO::flush;
562 575
563 $_->join for ( 576 $c_res->put (undef) for @a_res;
577 $c_arc->put (undef) for @a_arc;
578 $c_trs->put (undef) for @a_trs;
579
580 print "start file scan, arc, res processing...\n" if $VERBOSE;
581
582 $_->join for @a_arc; # need to parse all archetypes before png processing
583
584 print "end arc, start png processing...\n" if $VERBOSE;
585
564 # four png crunchers work fine for my 2x smp machine 586 # four png crunchers work fine for my 2x smp machine
565 (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), 587 my @a_png = map +(async \&process_png), 1..4;
566 (async \&process_trs), (async \&process_trs),
567 (async \&process_arc), (async \&process_arc),
568 (async \&process_res), (async \&process_res),
569 );
570 588
589 $_->join for (@a_trs, @a_res, @a_png);
590
591 print "scanning done, processing results...\n" if $VERBOSE;
571 { 592 {
572 # remove path prefix from editor_folder 593 # remove path prefix from editor_folder
573 substr $_->{editor_folder}, 0, 1 + length $path, "" 594 substr $_->{editor_folder}, 0, 1 + length $path, ""
574 for values %ARC; 595 for values %ARC;
575 596
597 print "resolving inheritance tree...\n" if $VERBOSE;
576 # resolve inherit 598 # resolve inherit
577 while () { 599 while () {
578 my $progress; 600 my $progress;
579 my $loop; 601 my $loop;
580 602
606 } 628 }
607 629
608 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit 630 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit
609 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; 631 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC;
610 632
633 print "writing archetypes...\n" if $VERBOSE;
611 open my $fh, ">:utf8", "$DATADIR/archetypes~" 634 open my $fh, ">:utf8", "$DATADIR/archetypes~"
612 or die "$DATADIR/archetypes~: $!"; 635 or die "$DATADIR/archetypes~: $!";
613 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; 636 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC];
614 } 637 }
615 638
616 { 639 {
640 print "writing treasures...\n" if $VERBOSE;
617 open my $fh, ">:utf8", "$DATADIR/treasures~" 641 open my $fh, ">:utf8", "$DATADIR/treasures~"
618 or die "$DATADIR/treasures~: $!"; 642 or die "$DATADIR/treasures~: $!";
619 print $fh $TRS; 643 print $fh $TRS;
620 } 644 }
621 645
622 { 646 {
647 print "processing facedata...\n" if $VERBOSE;
623 while (my ($k, $v) = each %FACEINFO) { 648 while (my ($k, $v) = each %FACEINFO) {
624 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; 649 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
625 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; 650 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
626 651
627 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 652 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
632 657
633 if (my $magicmap = $v->{magicmap}) { 658 if (my $magicmap = $v->{magicmap}) {
634 $magicmap =~ y/A-Z_\-/a-z/d; 659 $magicmap =~ y/A-Z_\-/a-z/d;
635 $v->{magicmap} = $COLOR{$magicmap}; 660 $v->{magicmap} = $COLOR{$magicmap};
636 } 661 }
637 }
638 662
663 delete $v->{arc};
664 }
665
666 print "writing facedata...\n" if $VERBOSE;
639 open my $fh, ">:perlio", "$DATADIR/facedata~" 667 open my $fh, ">:perlio", "$DATADIR/facedata~"
640 or die "$DATADIR/facedata~: $!"; 668 or die "$DATADIR/facedata~: $!";
641 669
642 print $fh freeze { 670 print $fh freeze {
643 version => 2, 671 version => 2,
644 faceinfo => \%FACEINFO, 672 faceinfo => \%FACEINFO,
645 animinfo => \%ANIMINFO, 673 animinfo => \%ANIMINFO,
646 resource => \%RESOURCE, 674 resource => \%RESOURCE,
647 }; 675 };
648 } 676 }
677
678 print "committing files...\n" if $VERBOSE;
649 679
650 for (qw(archetypes facedata treasures)) { 680 for (qw(archetypes facedata treasures)) {
651 chmod 0644, "$DATADIR/$_~"; 681 chmod 0644, "$DATADIR/$_~";
652 rename "$DATADIR/$_~", "$DATADIR/$_" 682 rename "$DATADIR/$_~", "$DATADIR/$_"
653 or die "$DATADIR/$_: $!"; 683 or die "$DATADIR/$_: $!";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines