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.64 by root, Mon Dec 17 08:50:15 2007 UTC vs.
Revision 1.74 by root, Wed Oct 28 04:10:46 2009 UTC

12my $OPTIPNG = "@OPTIPNG@"; 12my $OPTIPNG = "@OPTIPNG@";
13my $RSYNC = "@RSYNC@"; 13my $RSYNC = "@RSYNC@";
14my $PNGNQ = "@PNGNQ@"; 14my $PNGNQ = "@PNGNQ@";
15 15
16use Getopt::Long; 16use Getopt::Long;
17use File::Temp;
18use POSIX ();
19use Carp;
20
17use Coro::Event; 21use Coro::EV;
18use AnyEvent; 22use AnyEvent;
19use YAML::Syck (); 23use YAML::XS ();
20use JSON::XS (); 24use JSON::XS ();
21use IO::AIO (); 25use IO::AIO ();
22use File::Temp; 26
23use Crossfire;
24use Coro; 27use Coro 5.12;
25use Coro::AIO; 28use Coro::AIO;
26use Coro::Util; 29use Coro::Util;
27use POSIX ();
28use Carp;
29use Coro::Channel; 30use Coro::Channel;
30use Coro::Storable; $Storable::canonical = 1; 31use Coro::Storable; $Storable::canonical = 1;
32
33use Deliantra;
31 34
32$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 35$SIG{QUIT} = sub { Carp::cluck "QUIT" };
33 36
34sub usage { 37sub usage {
35 warn <<EOF; 38 warn <<EOF;
67 tan => 12, 70 tan => 12,
68); 71);
69 72
70END { system "rm", "-rf", $TMPDIR } 73END { system "rm", "-rf", $TMPDIR }
71 74
72Event->signal (signal => "INT", cb => sub { exit 1 }); 75my $s_INT = EV::signal INT => sub { exit 1 };
73Event->signal (signal => "TERM", cb => sub { exit 1 }); 76my $s_TERM = EV::signal TERM => sub { exit 1 };
74 77
75mkdir $TMPDIR, 0700 78mkdir $TMPDIR, 0700
76 or die "$TMPDIR: $!"; 79 or die "$TMPDIR: $!";
77 80
78sub fork_sub(&) { 81sub fork_sub(&) {
273 fork_sub { 276 fork_sub {
274 system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; 277 system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~";
275 system $OPTIPNG, "-i0", "-q", "$other~"; 278 system $OPTIPNG, "-i0", "-q", "$other~";
276 279
277 # reduce smoothfaces >10000 bytes 280 # reduce smoothfaces >10000 bytes
281 # obsolete, no longer required
278 if ($stem =~ /_S\./ && (-s "$other~") > 10000) { 282 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) {
279 my $ncolor = 256; 283 my $ncolor = 256;
280 while () { 284 while () {
281 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; 285 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E";
282 system $OPTIPNG, "-i0", "-q", "$other~~"; 286 system $OPTIPNG, "-i0", "-q", "$other~~";
283 last if 10000 > -s "$other~~"; 287 last if 10000 > -s "$other~~";
533 537
534 substr $dir, 0, 1 + length $PATH, ""; 538 substr $dir, 0, 1 + length $PATH, "";
535 539
536 if (my $filter = $meta->{cfutil_filter}) { 540 if (my $filter = $meta->{cfutil_filter}) {
537 if ($filter eq "yaml2json") { 541 if ($filter eq "yaml2json") {
538 $data = JSON::XS::encode_json YAML::Syck::Load $data; 542 $data = JSON::XS::encode_json YAML::XS::Load $data;
543 } elsif ($filter eq "json2json") {
544 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data);
545 } elsif ($filter eq "perl2json") {
546 $data = eval $data; die if $@;
547 $data = JSON::XS::encode_json $data;
539 } else { 548 } else {
540 warn "$dir/$file: unknown filter $filter, skipping\n"; 549 warn "$dir/$file: unknown filter $filter, skipping\n";
541 } 550 }
542 } 551 }
543 552
574 583
575 } elsif ($dir =~ /^res(?:\/|$)/) { 584 } elsif ($dir =~ /^res(?:\/|$)/) {
576 if ($file =~ /\.(jpg|png)$/) { 585 if ($file =~ /\.(jpg|png)$/) {
577 $c_res->put ([$path, $file, 0]) # FT_FACE 586 $c_res->put ([$path, $file, 0]) # FT_FACE
578 } elsif ($file =~ /\.(res)$/) { 587 } elsif ($file =~ /\.(res)$/) {
579 $c_res->put ([$path, $file, 7]) # FT_RSRC 588 $c_res->put ([$path, $file, 6]) # FT_RSRC
580 } else { 589 } else {
581 $c_res->put ([$path, $file, undef]); 590 $c_res->put ([$path, $file, undef]);
582 } 591 }
583 592
584 } elsif ($file =~ /\.png$/) { 593 } elsif ($file =~ /\.png$/) {
593 } else { 602 } else {
594 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 603 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
595 } 604 }
596 } 605 }
597 }; 606 };
607 }
608
609 sub generate_plurals {
610# use Lingua::EN::Inflect ();
611# Lingua::EN::Inflect::classical;
612# Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy
613# Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack
614#
615# for my $a (@ARC) {
616# my $name = $a->{name} || $a->{_name};
617#
618# next unless $a->{name_pl};
619# next if $a->{invisible};
620# next if $a->{is_floor};
621# next if $a->{no_pick};
622#
623# my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name;
624# my $pl = $test =~ /^(?:eq|p:.)$/
625# ? $name
626# : Lingua::EN::Inflect::PL $name;
627#
628# if ($pl ne $a->{name_pl}) {
629# warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n";
630# }
631# }
598 } 632 }
599 633
600 sub inst_arch($) { 634 sub inst_arch($) {
601 my (undef, $path) = @_; 635 my (undef, $path) = @_;
602 636
625 my @a_res = map +(async \&process_res), 1..2; 659 my @a_res = map +(async \&process_res), 1..2;
626 my @a_trs = map +(async \&process_trs), 1..2; 660 my @a_trs = map +(async \&process_trs), 1..2;
627 661
628 IO::AIO::flush; 662 IO::AIO::flush;
629 663
630 $c_res->put (undef) for @a_res; 664 $c_res->shutdown;
631 $c_arc->put (undef) for @a_arc; 665 $c_arc->shutdown;
632 $c_trs->put (undef) for @a_trs; 666 $c_trs->shutdown;
633 667
634 print "start file scan, arc, res processing...\n" if $VERBOSE; 668 print "start file scan, arc, res processing...\n" if $VERBOSE;
635 669
636 $_->join for @a_arc; # need to parse all archetypes before png processing 670 $_->join for @a_arc; # need to parse all archetypes before png processing
637 671
638 print "end arc, start png processing...\n" if $VERBOSE; 672 print "end arc, start png processing...\n" if $VERBOSE;
639 673
640 # four png crunchers work fine for my 2x smp machine 674 # eight png crunchers work fine for my 4x smp machine
641 my @a_png = map +(async \&process_png), 1..4; 675 my @a_png = map +(async \&process_png), 1..8;
642 676
643 $_->join for (@a_trs, @a_res, @a_png); 677 $_->join for (@a_trs, @a_res, @a_png);
644 678
645 print "scanning done, processing results...\n" if $VERBOSE; 679 print "scanning done, processing results...\n" if $VERBOSE;
646 { 680 {
682 } 716 }
683 717
684 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit 718 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit
685 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; 719 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC;
686 720
721 print "generating plurals...\n" if $VERBOSE;
722 generate_plurals;
723
687 print "writing archetypes...\n" if $VERBOSE; 724 print "writing archetypes...\n" if $VERBOSE;
688 open my $fh, ">:utf8", "$DATADIR/archetypes~" 725 open my $fh, ">:utf8", "$DATADIR/archetypes~"
689 or die "$DATADIR/archetypes~: $!"; 726 or die "$DATADIR/archetypes~: $!";
690 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; 727 print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC];
691 } 728 }
692 729
693 { 730 {
694 print "writing treasures...\n" if $VERBOSE; 731 print "writing treasures...\n" if $VERBOSE;
695 open my $fh, ">:utf8", "$DATADIR/treasures~" 732 open my $fh, ">:utf8", "$DATADIR/treasures~"
701 print "processing facedata...\n" if $VERBOSE; 738 print "processing facedata...\n" if $VERBOSE;
702 while (my ($k, $v) = each %FACEINFO) { 739 while (my ($k, $v) = each %FACEINFO) {
703 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; 740 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
704 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; 741 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
705 742
706 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 743 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
707 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; 744 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
708 745
709 if (my $magicmap = $v->{magicmap}) { 746 if (my $magicmap = $v->{magicmap}) {
710 $magicmap =~ y/A-Z_\-/a-z/d; 747 $magicmap =~ y/A-Z_\-/a-z/d;
711 $v->{magicmap} = $COLOR{$magicmap}; 748 $v->{magicmap} = $COLOR{$magicmap};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines