… | |
… | |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
14 | my $PNGNQ = "@PNGNQ@"; |
15 | |
15 | |
16 | use Getopt::Long; |
16 | use Getopt::Long; |
|
|
17 | use File::Temp; |
|
|
18 | use POSIX (); |
|
|
19 | use Carp; |
|
|
20 | |
17 | use Coro::Event; |
21 | use Coro::EV; |
18 | use AnyEvent; |
22 | use AnyEvent; |
|
|
23 | use YAML::XS (); |
|
|
24 | use JSON::XS (); |
19 | use IO::AIO (); |
25 | use IO::AIO (); |
20 | use File::Temp; |
26 | |
21 | use Crossfire; |
|
|
22 | use Coro; |
27 | use Coro 5.12; |
23 | use Coro::AIO; |
28 | use Coro::AIO; |
24 | use Coro::Util; |
29 | use Coro::Util; |
25 | use POSIX (); |
|
|
26 | use Carp; |
|
|
27 | use Coro::Channel; |
30 | use Coro::Channel; |
28 | use Coro::Storable; $Storable::canonical = 1; |
31 | use Coro::Storable; $Storable::canonical = 1; |
|
|
32 | |
|
|
33 | use Deliantra; |
29 | |
34 | |
30 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
35 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
31 | |
36 | |
32 | sub usage { |
37 | sub usage { |
33 | warn <<EOF; |
38 | warn <<EOF; |
… | |
… | |
65 | tan => 12, |
70 | tan => 12, |
66 | ); |
71 | ); |
67 | |
72 | |
68 | END { system "rm", "-rf", $TMPDIR } |
73 | END { system "rm", "-rf", $TMPDIR } |
69 | |
74 | |
70 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
75 | my $s_INT = EV::signal INT => sub { exit 1 }; |
71 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
76 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
72 | |
77 | |
73 | mkdir $TMPDIR, 0700 |
78 | mkdir $TMPDIR, 0700 |
74 | or die "$TMPDIR: $!"; |
79 | or die "$TMPDIR: $!"; |
75 | |
80 | |
76 | sub fork_sub(&) { |
81 | sub fork_sub(&) { |
… | |
… | |
96 | if (!-f "$path/regions") { |
101 | if (!-f "$path/regions") { |
97 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
102 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
98 | exit 1 unless $FORCE; |
103 | exit 1 unless $FORCE; |
99 | } |
104 | } |
100 | |
105 | |
101 | system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
106 | system $RSYNC, "-av", "--chmod=u=rwX,go=rX", |
|
|
107 | "$path/.", "$DATADIR/maps/.", |
|
|
108 | "--exclude", "CVS", "--exclude", "/world-precomposed", |
|
|
109 | "--delete", "--delete-excluded" |
102 | and die "map installation failed.\n"; |
110 | and die "map installation failed.\n"; |
103 | |
111 | |
104 | print "maps installed successfully.\n"; |
112 | print "maps installed successfully.\n"; |
105 | } |
113 | } |
106 | |
114 | |
… | |
… | |
268 | fork_sub { |
276 | fork_sub { |
269 | 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~"; |
270 | system $OPTIPNG, "-i0", "-q", "$other~"; |
278 | system $OPTIPNG, "-i0", "-q", "$other~"; |
271 | |
279 | |
272 | # reduce smoothfaces >10000 bytes |
280 | # reduce smoothfaces >10000 bytes |
|
|
281 | # obsolete, no longer required |
273 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
282 | if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { |
274 | my $ncolor = 256; |
283 | my $ncolor = 256; |
275 | while () { |
284 | while () { |
276 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
285 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
277 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
286 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
278 | last if 10000 > -s "$other~~"; |
287 | last if 10000 > -s "$other~~"; |
… | |
… | |
494 | my ($dir, $file, $type) = @$job; |
503 | my ($dir, $file, $type) = @$job; |
495 | |
504 | |
496 | my $data; |
505 | my $data; |
497 | aio_load "$dir/$file", $data; |
506 | aio_load "$dir/$file", $data; |
498 | |
507 | |
499 | |
|
|
500 | 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) }; |
501 | |
509 | |
502 | utf8::decode $dir; |
510 | utf8::decode $dir; |
503 | utf8::decode $file; |
511 | utf8::decode $file; |
504 | |
512 | |
… | |
… | |
527 | $file =~ s/\.res$//; |
535 | $file =~ s/\.res$//; |
528 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
536 | $file =~ s/\.(ogg|wav|jpg|png)$//; |
529 | |
537 | |
530 | substr $dir, 0, 1 + length $PATH, ""; |
538 | substr $dir, 0, 1 + length $PATH, ""; |
531 | |
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 | |
532 | $RESOURCE{"$dir/$file"} = { |
553 | $RESOURCE{"$dir/$file"} = { |
533 | type => (delete $meta->{type}) || $type, |
554 | type => (exists $meta->{type} ? delete $meta->{type} : $type), |
534 | data => $data, |
555 | data => $data, |
535 | %$meta ? (meta => $meta) : (), |
556 | %$meta ? (meta => $meta) : (), |
536 | }; |
557 | }; |
537 | } |
558 | } |
538 | } |
559 | } |
… | |
… | |
559 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
580 | } elsif ($dir =~ /^sound(?:\/|$)/) { |
560 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
581 | $c_res->put ([$path, $file, 5]) # FT_SOUND |
561 | if $file =~ /\.(wav|ogg)$/; |
582 | if $file =~ /\.(wav|ogg)$/; |
562 | |
583 | |
563 | } elsif ($dir =~ /^res(?:\/|$)/) { |
584 | } elsif ($dir =~ /^res(?:\/|$)/) { |
|
|
585 | if ($file =~ /\.(jpg|png)$/) { |
564 | $c_res->put ([$path, $file, 0]) # FT_FACE |
586 | $c_res->put ([$path, $file, 0]) # FT_FACE |
565 | if $file =~ /\.(jpg|png)$/; |
587 | } elsif ($file =~ /\.(res)$/) { |
566 | $c_res->put ([$path, $file, 7]) # FT_RSRC |
588 | $c_res->put ([$path, $file, 6]) # FT_RSRC |
567 | if $file =~ /\.(res)$/; |
589 | } else { |
|
|
590 | $c_res->put ([$path, $file, undef]); |
|
|
591 | } |
568 | |
592 | |
569 | } elsif ($file =~ /\.png$/) { |
593 | } elsif ($file =~ /\.png$/) { |
570 | push @c_png, ["$path/$file", 0]; |
594 | push @c_png, ["$path/$file", 0]; |
571 | |
595 | |
572 | } elsif ($file =~ /\.trs$/) { |
596 | } elsif ($file =~ /\.trs$/) { |
… | |
… | |
578 | } else { |
602 | } else { |
579 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
603 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
580 | } |
604 | } |
581 | } |
605 | } |
582 | }; |
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 | # } |
583 | } |
632 | } |
584 | |
633 | |
585 | sub inst_arch($) { |
634 | sub inst_arch($) { |
586 | my (undef, $path) = @_; |
635 | my (undef, $path) = @_; |
587 | |
636 | |
… | |
… | |
610 | my @a_res = map +(async \&process_res), 1..2; |
659 | my @a_res = map +(async \&process_res), 1..2; |
611 | my @a_trs = map +(async \&process_trs), 1..2; |
660 | my @a_trs = map +(async \&process_trs), 1..2; |
612 | |
661 | |
613 | IO::AIO::flush; |
662 | IO::AIO::flush; |
614 | |
663 | |
615 | $c_res->put (undef) for @a_res; |
664 | $c_res->shutdown; |
616 | $c_arc->put (undef) for @a_arc; |
665 | $c_arc->shutdown; |
617 | $c_trs->put (undef) for @a_trs; |
666 | $c_trs->shutdown; |
618 | |
667 | |
619 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
668 | print "start file scan, arc, res processing...\n" if $VERBOSE; |
620 | |
669 | |
621 | $_->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 |
622 | |
671 | |
623 | print "end arc, start png processing...\n" if $VERBOSE; |
672 | print "end arc, start png processing...\n" if $VERBOSE; |
624 | |
673 | |
625 | # four png crunchers work fine for my 2x smp machine |
674 | # eight png crunchers work fine for my 4x smp machine |
626 | my @a_png = map +(async \&process_png), 1..4; |
675 | my @a_png = map +(async \&process_png), 1..8; |
627 | |
676 | |
628 | $_->join for (@a_trs, @a_res, @a_png); |
677 | $_->join for (@a_trs, @a_res, @a_png); |
629 | |
678 | |
630 | print "scanning done, processing results...\n" if $VERBOSE; |
679 | print "scanning done, processing results...\n" if $VERBOSE; |
631 | { |
680 | { |
… | |
… | |
667 | } |
716 | } |
668 | |
717 | |
669 | # 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 |
670 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
719 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
671 | |
720 | |
|
|
721 | print "generating plurals...\n" if $VERBOSE; |
|
|
722 | generate_plurals; |
|
|
723 | |
672 | print "writing archetypes...\n" if $VERBOSE; |
724 | print "writing archetypes...\n" if $VERBOSE; |
673 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
725 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
674 | or die "$DATADIR/archetypes~: $!"; |
726 | or die "$DATADIR/archetypes~: $!"; |
675 | 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]; |
676 | } |
728 | } |
677 | |
729 | |
678 | { |
730 | { |
679 | print "writing treasures...\n" if $VERBOSE; |
731 | print "writing treasures...\n" if $VERBOSE; |
680 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
732 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
… | |
… | |
686 | print "processing facedata...\n" if $VERBOSE; |
738 | print "processing facedata...\n" if $VERBOSE; |
687 | while (my ($k, $v) = each %FACEINFO) { |
739 | while (my ($k, $v) = each %FACEINFO) { |
688 | 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"; |
689 | 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"; |
690 | |
742 | |
691 | 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"; |
692 | #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"; |
693 | |
745 | |
694 | if (my $magicmap = $v->{magicmap}) { |
746 | if (my $magicmap = $v->{magicmap}) { |
695 | $magicmap =~ y/A-Z_\-/a-z/d; |
747 | $magicmap =~ y/A-Z_\-/a-z/d; |
696 | $v->{magicmap} = $COLOR{$magicmap}; |
748 | $v->{magicmap} = $COLOR{$magicmap}; |