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.62 by root, Mon Sep 10 18:30:30 2007 UTC vs.
Revision 1.73 by root, Mon Oct 26 11:31:39 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;
23use YAML::XS ();
24use JSON::XS ();
19use IO::AIO (); 25use IO::AIO ();
20use File::Temp; 26
21use Crossfire;
22use Coro; 27use Coro 5.12;
23use Coro::AIO; 28use Coro::AIO;
24use Coro::Util; 29use Coro::Util;
25use POSIX ();
26use Carp;
27use Coro::Channel; 30use Coro::Channel;
28use Coro::Storable; $Storable::canonical = 1; 31use Coro::Storable; $Storable::canonical = 1;
32
33use Deliantra;
29 34
30$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 35$SIG{QUIT} = sub { Carp::cluck "QUIT" };
31 36
32sub usage { 37sub usage {
33 warn <<EOF; 38 warn <<EOF;
65 tan => 12, 70 tan => 12,
66); 71);
67 72
68END { system "rm", "-rf", $TMPDIR } 73END { system "rm", "-rf", $TMPDIR }
69 74
70Event->signal (signal => "INT", cb => sub { exit 1 }); 75my $s_INT = EV::signal INT => sub { exit 1 };
71Event->signal (signal => "TERM", cb => sub { exit 1 }); 76my $s_TERM = EV::signal TERM => sub { exit 1 };
72 77
73mkdir $TMPDIR, 0700 78mkdir $TMPDIR, 0700
74 or die "$TMPDIR: $!"; 79 or die "$TMPDIR: $!";
75 80
76sub fork_sub(&) { 81sub fork_sub(&) {
271 fork_sub { 276 fork_sub {
272 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~";
273 system $OPTIPNG, "-i0", "-q", "$other~"; 278 system $OPTIPNG, "-i0", "-q", "$other~";
274 279
275 # reduce smoothfaces >10000 bytes 280 # reduce smoothfaces >10000 bytes
281 # obsolete, no longer required
276 if ($stem =~ /_S\./ && (-s "$other~") > 10000) { 282 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) {
277 my $ncolor = 256; 283 my $ncolor = 256;
278 while () { 284 while () {
279 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; 285 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E";
280 system $OPTIPNG, "-i0", "-q", "$other~~"; 286 system $OPTIPNG, "-i0", "-q", "$other~~";
281 last if 10000 > -s "$other~~"; 287 last if 10000 > -s "$other~~";
497 my ($dir, $file, $type) = @$job; 503 my ($dir, $file, $type) = @$job;
498 504
499 my $data; 505 my $data;
500 aio_load "$dir/$file", $data; 506 aio_load "$dir/$file", $data;
501 507
502
503 my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) }; 508 my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) };
504 509
505 utf8::decode $dir; 510 utf8::decode $dir;
506 utf8::decode $file; 511 utf8::decode $file;
507 512
530 $file =~ s/\.res$//; 535 $file =~ s/\.res$//;
531 $file =~ s/\.(ogg|wav|jpg|png)$//; 536 $file =~ s/\.(ogg|wav|jpg|png)$//;
532 537
533 substr $dir, 0, 1 + length $PATH, ""; 538 substr $dir, 0, 1 + length $PATH, "";
534 539
540 if (my $filter = $meta->{cfutil_filter}) {
541 if ($filter eq "yaml2json") {
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;
548 } else {
549 warn "$dir/$file: unknown filter $filter, skipping\n";
550 }
551 }
552
535 $RESOURCE{"$dir/$file"} = { 553 $RESOURCE{"$dir/$file"} = {
536 type => (delete $meta->{type}) || $type, 554 type => (exists $meta->{type} ? delete $meta->{type} : $type),
537 data => $data, 555 data => $data,
538 %$meta ? (meta => $meta) : (), 556 %$meta ? (meta => $meta) : (),
539 }; 557 };
540 } 558 }
541 } 559 }
562 } elsif ($dir =~ /^sound(?:\/|$)/) { 580 } elsif ($dir =~ /^sound(?:\/|$)/) {
563 $c_res->put ([$path, $file, 5]) # FT_SOUND 581 $c_res->put ([$path, $file, 5]) # FT_SOUND
564 if $file =~ /\.(wav|ogg)$/; 582 if $file =~ /\.(wav|ogg)$/;
565 583
566 } elsif ($dir =~ /^res(?:\/|$)/) { 584 } elsif ($dir =~ /^res(?:\/|$)/) {
585 if ($file =~ /\.(jpg|png)$/) {
567 $c_res->put ([$path, $file, 0]) # FT_FACE 586 $c_res->put ([$path, $file, 0]) # FT_FACE
568 if $file =~ /\.(jpg|png)$/; 587 } elsif ($file =~ /\.(res)$/) {
569 $c_res->put ([$path, $file, 7]) # FT_RSRC 588 $c_res->put ([$path, $file, 6]) # FT_RSRC
570 if $file =~ /\.(res)$/; 589 } else {
590 $c_res->put ([$path, $file, undef]);
591 }
571 592
572 } elsif ($file =~ /\.png$/) { 593 } elsif ($file =~ /\.png$/) {
573 push @c_png, ["$path/$file", 0]; 594 push @c_png, ["$path/$file", 0];
574 595
575 } elsif ($file =~ /\.trs$/) { 596 } elsif ($file =~ /\.trs$/) {
581 } else { 602 } else {
582 warn "ignoring $path/$file\n" if $VERBOSE >= 3; 603 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
583 } 604 }
584 } 605 }
585 }; 606 };
607 }
608
609 sub generate_plurals {
610# use Lingua::EN::Inflect ();
611# Lingua::EN::Inflect::classical;
612# Lingua::EN::Inflect::def_noun 'talisman' => 'talismans';
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#
620#
621# my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name;
622# my $pl = $test =~ /^(?:eq|p:.)$/
623# ? $name
624# : Lingua::EN::Inflect::PL $name;
625# die "$test $pl" if $pl =~ /bootss/;#d#
626#
627# if ($pl ne $a->{name_pl}) {
628# warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n";
629# }
630# }
586 } 631 }
587 632
588 sub inst_arch($) { 633 sub inst_arch($) {
589 my (undef, $path) = @_; 634 my (undef, $path) = @_;
590 635
613 my @a_res = map +(async \&process_res), 1..2; 658 my @a_res = map +(async \&process_res), 1..2;
614 my @a_trs = map +(async \&process_trs), 1..2; 659 my @a_trs = map +(async \&process_trs), 1..2;
615 660
616 IO::AIO::flush; 661 IO::AIO::flush;
617 662
618 $c_res->put (undef) for @a_res; 663 $c_res->shutdown;
619 $c_arc->put (undef) for @a_arc; 664 $c_arc->shutdown;
620 $c_trs->put (undef) for @a_trs; 665 $c_trs->shutdown;
621 666
622 print "start file scan, arc, res processing...\n" if $VERBOSE; 667 print "start file scan, arc, res processing...\n" if $VERBOSE;
623 668
624 $_->join for @a_arc; # need to parse all archetypes before png processing 669 $_->join for @a_arc; # need to parse all archetypes before png processing
625 670
626 print "end arc, start png processing...\n" if $VERBOSE; 671 print "end arc, start png processing...\n" if $VERBOSE;
627 672
628 # four png crunchers work fine for my 2x smp machine 673 # eight png crunchers work fine for my 4x smp machine
629 my @a_png = map +(async \&process_png), 1..4; 674 my @a_png = map +(async \&process_png), 1..8;
630 675
631 $_->join for (@a_trs, @a_res, @a_png); 676 $_->join for (@a_trs, @a_res, @a_png);
632 677
633 print "scanning done, processing results...\n" if $VERBOSE; 678 print "scanning done, processing results...\n" if $VERBOSE;
634 { 679 {
670 } 715 }
671 716
672 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit 717 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit
673 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; 718 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC;
674 719
720 print "generating plurals...\n" if $VERBOSE;
721 generate_plurals;
722
675 print "writing archetypes...\n" if $VERBOSE; 723 print "writing archetypes...\n" if $VERBOSE;
676 open my $fh, ">:utf8", "$DATADIR/archetypes~" 724 open my $fh, ">:utf8", "$DATADIR/archetypes~"
677 or die "$DATADIR/archetypes~: $!"; 725 or die "$DATADIR/archetypes~: $!";
678 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; 726 print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC];
679 } 727 }
680 728
681 { 729 {
682 print "writing treasures...\n" if $VERBOSE; 730 print "writing treasures...\n" if $VERBOSE;
683 open my $fh, ">:utf8", "$DATADIR/treasures~" 731 open my $fh, ">:utf8", "$DATADIR/treasures~"
689 print "processing facedata...\n" if $VERBOSE; 737 print "processing facedata...\n" if $VERBOSE;
690 while (my ($k, $v) = each %FACEINFO) { 738 while (my ($k, $v) = each %FACEINFO) {
691 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; 739 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
692 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; 740 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
693 741
694 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 742 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
695 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; 743 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
696 744
697 if (my $magicmap = $v->{magicmap}) { 745 if (my $magicmap = $v->{magicmap}) {
698 $magicmap =~ y/A-Z_\-/a-z/d; 746 $magicmap =~ y/A-Z_\-/a-z/d;
699 $v->{magicmap} = $COLOR{$magicmap}; 747 $v->{magicmap} = $COLOR{$magicmap};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines