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.115 by root, Sat May 14 17:41:57 2011 UTC vs.
Revision 1.125 by root, Mon Nov 19 00:40:55 2012 UTC

1#!@PERL@ 1#!@PERL@
2 2
3# 3#
4# This file is part of Deliantra, the Roguelike Realtime MMORPG. 4# This file is part of Deliantra, the Roguelike Realtime MMORPG.
5# 5#
6# Copyright (©) 2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 6# Copyright (©) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
7# 7#
8# Deliantra is free software: you can redistribute it and/or modify it under 8# Deliantra is free software: you can redistribute it and/or modify it under
9# the terms of the Affero GNU General Public License as published by the 9# the terms of the Affero GNU General Public License as published by the
10# Free Software Foundation, either version 3 of the License, or (at your 10# Free Software Foundation, either version 3 of the License, or (at your
11# option) any later version. 11# option) any later version.
12# 12#
13# This program is distributed in the hope that it will be useful, 13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details. 16# GNU General Public License for more details.
17# 17#
18# You should have received a copy of the Affero GNU General Public License 18# You should have received a copy of the Affero GNU General Public License
19# and the GNU General Public License along with this program. If not, see 19# and the GNU General Public License along with this program. If not, see
20# <http://www.gnu.org/licenses/>. 20# <http://www.gnu.org/licenses/>.
21# 21#
22# The authors can be reached via e-mail to <support@deliantra.net> 22# The authors can be reached via e-mail to <support@deliantra.net>
23# 23#
24 24
25use common::sense; 25use common::sense;
26 26
107 khaki => 12, 107 khaki => 12,
108); 108);
109 109
110END { system "rm", "-rf", $TMPDIR } 110END { system "rm", "-rf", $TMPDIR }
111 111
112my $s_INT = EV::signal INT => sub { exit 1 }; 112my $s_INT = AE::signal INT => sub { exit 1 };
113my $s_TERM = EV::signal TERM => sub { exit 1 }; 113my $s_TERM = AE::signal TERM => sub { exit 1 };
114 114
115our %hash; 115our %hash;
116 116
117# here we could try to avoid collisions and reduce chksum size further 117# here we could try to avoid collisions and reduce chksum size further
118sub make_hash($\$\$;$) { 118sub make_hash($\$\$;$) {
121 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 5; 121 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 5;
122 122
123 if (exists $hash{$hash}) { 123 if (exists $hash{$hash}) {
124 # hash collision, but some files are simply identical 124 # hash collision, but some files are simply identical
125 if (${$hash{$hash}[1]} ne $$dataref) { 125 if (${$hash{$hash}[1]} ne $$dataref) {
126 warn "hash collision $hash{$hash}[0] vs. $id (increase the default \$clen in make_hash?)\n"; 126 warn "ERROR: hash collision $hash{$hash}[0] vs. $id (increase the default \$clen in make_hash?)\n";
127 exit 1; 127 exit 1;
128 } else { 128 } else {
129 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; 129 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3;
130 } 130 }
131 } 131 }
190 my (undef, $path) = @_; 190 my (undef, $path) = @_;
191 191
192 print "\nInstalling '$path' to '$DATADIR/maps'\n\n"; 192 print "\nInstalling '$path' to '$DATADIR/maps'\n\n";
193 193
194 if (!-f "$path/regions") { 194 if (!-f "$path/regions") {
195 warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; 195 warn "ERROR: '$path' does not look like a maps directory ('regions' file is missing).\n";
196 exit 1 unless $FORCE; 196 exit 1 unless $FORCE;
197 } 197 }
198 198
199 system $RSYNC, "-av", "--chmod=u=rwX,go=rX", 199 system $RSYNC, "-av", "--chmod=u=rwX,go=rX",
200 "$path/.", "$DATADIR/maps/.", 200 "$path/.", "$DATADIR/maps/.",
210 our %FACEINFO; 210 our %FACEINFO;
211 our %RESOURCE; 211 our %RESOURCE;
212 our @ARC; 212 our @ARC;
213 our %ARC; 213 our %ARC;
214 our $TRS; 214 our $TRS;
215 our %PNG;
215 our $NFILE; 216 our $NFILE;
216 our $PATH; 217 our $PATH;
217 218
218 our $QUANTIZE = "+dither -colorspace RGB -colors 256"; 219 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
219 220
220 our $c_arc = new Coro::Channel; 221 our $c_arc = new Coro::Channel;
221 our $c_any = new Coro::Channel; 222 our $c_any = new Coro::Channel;
222 223
223 our @c_png; 224 our @c_png;
224 225
226 # texture catalog size, in 64x64 tiles
227 sub TC_W() { 1024 / 64 }
228 sub TC_H() { 1024 / 64 }
229
230 our @TC = ([]); # texture catalogs
231
225 sub commit_png($$$$) { 232 sub commit_png($$$$$$) {
226 my ($stem, $name, $data, $T) = @_; 233 my ($stem, $name, $data, $T, $w, $h) = @_;
227 234
228 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; 235 $FACEINFO{$name}{stem} = substr $stem, 1 + length $PATH;
229 $FACEINFO{$name}{"data$T"} = $data; 236 $FACEINFO{$name}{"data$T"} = $data;
237 $FACEINFO{$name}{w} = $w;
238 $FACEINFO{$name}{h} = $h;
230 } 239 }
231 240
232 sub process_png { 241 sub process_png {
233 while (@c_png) { 242 while (@c_png) {
234 my ($path, $delete) = @{pop @c_png}; 243 my ($path, $delete) = @{pop @c_png};
236 my $png; 245 my $png;
237 aio_lstat $path; 246 aio_lstat $path;
238 my ($size, $mtime) = (stat _)[7,9]; 247 my ($size, $mtime) = (stat _)[7,9];
239 248
240 if (0 > aio_load $path, $png) { 249 if (0 > aio_load $path, $png) {
241 warn "$path: $!, skipping.\n"; 250 warn "ERROR: $path: $!, skipping.\n";
242 next; 251 next;
243 } 252 }
244 253
245 my $stem = $path; 254 my $stem = $path;
246 my $T; 255 my $T;
248 if ($stem =~ s/\.32x32\.png~?$//) { 257 if ($stem =~ s/\.32x32\.png~?$//) {
249 $T = 32; 258 $T = 32;
250 } elsif ($stem =~ s/\.64x64\.png~?$//) { 259 } elsif ($stem =~ s/\.64x64\.png~?$//) {
251 $T = 64; 260 $T = 64;
252 } else { 261 } else {
253 warn "$path: weird filename, skipping.\n"; 262 warn "ERROR: $path: weird filename, skipping.\n";
254 next; 263 next;
255 } 264 }
256 265
257 # quickly extract width and height of the (necessarily PNG) image 266 # quickly extract width and height of the (necessarily PNG) image
258 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 267 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
259 warn "$path: not a recognized png file, skipping.\n"; 268 warn "ERROR: $path: not a recognized png file, skipping.\n";
260 next; 269 next;
261 } 270 }
262 271
263 my ($w, $h) = unpack "NN", $1; 272 my ($w, $h) = unpack "NN", $1;
264 273
265 if ($w < $T || $h < $T) { 274 if ($w < $T || $h < $T) {
266 warn "$path: too small ($w $h), skipping.\n"; 275 warn "ERROR: $path: too small ($w $h), skipping.\n";
267 next; 276 next;
268 } 277 }
269 278
270 if ($w % $T || $h % $T) { 279 if ($w % $T || $h % $T) {
271 warn "$path: weird png size ($w $h), skipping.\n"; 280 warn "ERROR: $path: weird png size ($w $h), skipping.\n";
272 next; 281 next;
273 } 282 }
274 283
275 (my $base = $stem) =~ s/^.*\///; 284 (my $base = $stem) =~ s/^.*\///;
276 285
346 $x * ($w - 8) + 4, 355 $x * ($w - 8) + 4,
347 $y * ($h - 8) + 4; 356 $y * ($h - 8) + 4;
348 } 357 }
349 } 358 }
350 359
351 system "convert -depth 8 $SRC rgba:-" 360 system "$CONVERT -depth 8 $SRC rgba:-"
352 . "| $exec_prefix/bin/cfhq2xa $w $h 0" 361 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
353 . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~" 362 . "| $CONVERT -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~"
354 and die "convert/cfhq2xa pipeline error: status $? ($!)"; 363 and die "convert/cfhq2xa pipeline error: status $? ($!)";
355 optipng "$other~"; 364 optipng "$other~";
356 rename "$other~", $other; 365 rename "$other~", $other;
357 }; 366 };
358 }; 367 };
364 if (0 > aio_stat "$stem.32x32.png") { 373 if (0 > aio_stat "$stem.32x32.png") {
365 my $other = "$stem.32x32.png~"; 374 my $other = "$stem.32x32.png~";
366 375
367 make_file $path, $other, sub { 376 make_file $path, $other, sub {
368 fork_exec { 377 fork_exec {
369 system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; 378 system "$CONVERT png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~";
370 optipng "$other~"; 379 optipng "$other~";
371 380
372 # reduce smoothfaces >10000 bytes 381 # reduce smoothfaces >10000 bytes
373 # obsolete, no longer required 382 # obsolete, no longer required
374 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { 383 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) {
397 } 406 }
398 } 407 }
399 408
400 (my $face = $stem) =~ s/^.*\///; 409 (my $face = $stem) =~ s/^.*\///;
401 410
411 for (@{ $fi->{derive} }) {
412 my ($dir, $type) = @$_;
413
414 my $geom = "${T}x${T}";
415 my $dpath = "$dir/$type:$face.$geom.png~";
416
417 if ($type eq "buildmaterial") {
418 my $ov = "$PATH/mapbuilding/buildmaterial.png";
419 make_file [$path, $ov], $dpath, sub {
420 fork_exec {
421 system "$CONVERT -size 64x64 xc:transparent \\( \Q$path\E -geometry 52x52+6+6 \\) -composite \Q$ov\E -composite -geometry $geom png:\Q$dpath\E~";
422 optipng "$dpath~";
423 rename "$dpath~", $dpath;
424 };
425 };
426 } elsif ($type eq "buildmaterial-box") {
427 my $ov = "$PATH/mapbuilding/buildmaterial-box.png";
428 make_file [$path, $ov], $dpath, sub {
429 fork_exec {
430 system "$CONVERT \Q$ov\E "
431 . "\\( \Q$path\E -trim -geometry 34x31\\> "
432 . "-gravity center -background transparent -extent 37x34 +gravity "
433 . "-geometry +22+6 \\) -composite "
434 . "-geometry $geom png:\Q$dpath\E~";
435 optipng "$dpath~";
436 rename "$dpath~", $dpath;
437 };
438 };
439 } elsif ($type eq "buildmaterial-sbox") {
440 my $ov = "$PATH/mapbuilding/buildmaterial-sbox.png";
441 make_file [$path, $ov], $dpath, sub {
442 fork_exec {
443 system "$CONVERT \Q$ov\E "
444 . "\\( \Q$path\E -trim -geometry 16x24\\> "
445 . "-gravity center -background transparent -extent 18x26 +gravity "
446 . "-geometry +26+16 \\) -composite "
447 . "-geometry $geom png:\Q$dpath\E~";
448 optipng "$dpath~";
449 rename "$dpath~", $dpath;
450 };
451 };
452 } else {
453 warn "ERROR: facename $type:$face contains unsupported derivation type.\n";
454 }
455
456 aio_load $dpath, my $png;
457 IO::AIO::aio_unlink $dpath unless $CACHE;
458 commit_png "$dir/$type:$face", "$type:$face", $png, $T, 1, 1;
459 }
460
402 # split all bigfaces, but avoid smoothfaces (*_S) 461 # split all bigfaces, but avoid smoothfaces (*_S)
403 if (($w > $T || $h > $T) && $face !~ /_S\./) { 462 if (($w > $T || $h > $T) && $face !~ /_S\./) {
404 # split 463 # split
405 my @tile; 464 my @tile;
406 for my $x (0 .. (int $w / $T) - 1) { 465 for my $x (0 .. (int $w / $T) - 1) {
410 push @tile, [$x, $y, $file, (stat _)[9]]; 469 push @tile, [$x, $y, $file, (stat _)[9]];
411 } 470 }
412 } 471 }
413 472
414 my $mtime = (lstat $path)[9]; 473 my $mtime = (lstat $path)[9];
415 my @todo = grep { $_->[3] <= $mtime } @tile; 474 my @todo = grep { $_->[3] < $mtime } @tile;
416 if (@todo) { 475 if (@todo) {
417 fork_exec { 476 fork_exec {
418 open my $convert, "|-", $CONVERT, 477 open my $convert, "|-", $CONVERT,
419 "png:-", 478 "png:-",
420 (map { 479 (map {
449 508
450 if (0 > aio_load $file, $tile) { 509 if (0 > aio_load $file, $tile) {
451 die "$path: unable to read tile +$x+$y, aborting.\n"; 510 die "$path: unable to read tile +$x+$y, aborting.\n";
452 } 511 }
453 IO::AIO::aio_unlink $file unless $CACHE; 512 IO::AIO::aio_unlink $file unless $CACHE;
454 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T; 513 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T, 1, 1;
455 } 514 }
456 } else { 515 } else {
457 # use as-is (either small, use smooth) 516 # use as-is (either small, use smooth)
458 commit_png $stem, $face, $png, $T; 517 commit_png $stem, $face, $png, $T, $w / $T, $h / $T;
459 } 518 }
460 519
461 aio_unlink $path if $delete; 520 IO::AIO::aio_unlink $path if $delete;
462 } 521 }
463 } 522 }
464 523
465 sub process_faceinfo { 524 sub process_faceinfo {
466 my ($dir, $file) = @_; 525 my ($dir, $file) = @_;
467 my $path = "$dir/$file"; 526 my $path = "$dir/$file";
468 527
469 my $data; 528 my $data;
470 if (0 > aio_load $path, $data) { 529 if (0 > aio_load $path, $data) {
471 warn "$path: $!, skipping.\n"; 530 warn "ERROR: $path: $!, skipping.\n";
472 return; 531 return;
473 } 532 }
474 533
475 for (split /\n/, $data) { 534 for (split /\n/, $data) {
476 chomp; 535 chomp;
482 $glyph =~ s/^"(.+)"$/$1/; # allow for ""-style quoting 541 $glyph =~ s/^"(.+)"$/$1/; # allow for ""-style quoting
483 542
484 $fg = "white" if $fg eq "none"; # lots of faces have no fg colour yet 543 $fg = "white" if $fg eq "none"; # lots of faces have no fg colour yet
485 544
486 (my $fgi = $COLOR{$fg}) 545 (my $fgi = $COLOR{$fg})
487 // warn "WARNING: $path: $face specifies unknown foreground colour '$fg'.\n"; 546 // warn "ERROR: $path: $face specifies unknown foreground colour '$fg'.\n";
488 (my $bgi = $COLOR{$bg}) 547 (my $bgi = $COLOR{$bg})
489 // warn "WARNING: $path: $face specifies unknown background colour '$bg'.\n"; 548 // warn "ERROR: $path: $face specifies unknown background colour '$bg'.\n";
490 549
491 my $fi = $FACEINFO{$face} ||= { }; 550 my $fi = $FACEINFO{$face} ||= { };
492 $fi->{visibility} = $visibility * 1; 551 $fi->{visibility} = $visibility * 1;
493 $fi->{magicmap} = $fgi; # foreground colour becomes magicmap 552 $fi->{magicmap} = $fgi; # foreground colour becomes magicmap
494 553
563 next if /^facings\s/; 622 next if /^facings\s/;
564 623
565 my $face = $_; 624 my $face = $_;
566 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates 625 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates
567 626
568 my $info = $FACEINFO{$face} ||= { }; 627 # handle derived faces
628 if ($face =~ /^([^:]+):(.*)/) {
629 my ($type, $base) = ($1, $2);
630 push @{ $FACEINFO{$base}{derive} }, [$dir, $type];
631 }
632
569 $info->{arc} = $o; 633 $FACEINFO{$face}{arc} = $o;
570 634
571 next if $face =~ /^blank.x11$|^empty.x11$/; 635 next if $face =~ /^blank.x11$|^empty.x11$/;
572 } 636 }
573 637
574 if (my $smooth = delete $o->{smoothface}) { 638 if (my $smooth = delete $o->{smoothface}) {
590 my ($dir, $file) = @_; 654 my ($dir, $file) = @_;
591 my $path = "$dir/$file"; 655 my $path = "$dir/$file";
592 656
593 my $trs; 657 my $trs;
594 if (0 > aio_load $path, $trs) { 658 if (0 > aio_load $path, $trs) {
595 warn "$path: $!, skipping.\n"; 659 warn "ERROR: $path: $!, skipping.\n";
596 return; 660 return;
597 } 661 }
598 662
599 $TRS .= $trs; 663 $TRS .= $trs;
600 } 664 }
605 unless (exists $FILECACHE{$_[0]}) { 669 unless (exists $FILECACHE{$_[0]}) {
606 my $data; 670 my $data;
607 if (0 < aio_load $_[0], $data) { 671 if (0 < aio_load $_[0], $data) {
608 if ($_[1]) { 672 if ($_[1]) {
609 $data = eval { $_[1]->($data) }; 673 $data = eval { $_[1]->($data) };
610 warn "$_[0]: $@" if $@; 674 warn "ERROR: $_[0]: $@" if $@;
611 } 675 }
612 } 676 }
613 677
614 $FILECACHE{$_[0]} = $data; 678 $FILECACHE{$_[0]} = $data;
615 } 679 }
705 $meta = { 769 $meta = {
706 %{ $meta->{"" } || {} }, 770 %{ $meta->{"" } || {} },
707 %{ $meta->{$file} || {} }, 771 %{ $meta->{$file} || {} },
708 }; 772 };
709 773
710 if ($meta->{license} =~ s/^#//) { 774 if (exists $meta->{license} && $meta->{license} =~ s/^#//) { # exists == avoid autovivification
775 # all these are acceptable for deliantra - if not specified, agpl 3+ is the default.
711 $meta->{license} = ({ 776 $meta->{license} = ({
712 "pd" => "Public Domain", 777 "pd" => "Public Domain",
713 "gpl" => "GNU General Public License, version 3.0 or any later", 778 "gpl" => "GNU General Public License, version 3.0 or any later",
779 "2bsd" => "2-clause BSD/MIT style license",
780 "3bsd" => "3-clause BSD style license",
714 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", 781 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
715 "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/", 782 "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/",
716 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", 783 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/",
717 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", 784 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
718 })->{$meta->{license}} 785 })->{$meta->{license}}
719 || warn "$dir/$file: license tag '$meta->{license}' not found."; 786 || warn "ERROR: $dir/$file: license tag '$meta->{license}' not found.";
720 } 787 }
721 788
722 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { 789 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
723 ($meta->{author} = $1) =~ s/_/ /g; 790 ($meta->{author} = $1) =~ s/_/ /g;
724 } 791 }
726 $file =~ s/\.res$//; 793 $file =~ s/\.res$//;
727 $file =~ s/\.(ogg|wav|jpg|png)$//; 794 $file =~ s/\.(ogg|wav|jpg|png)$//;
728 795
729 if ($file =~ s/\.plt$//) { 796 if ($file =~ s/\.plt$//) {
730 $data = process_plt "$dir/$file", $data; 797 $data = process_plt "$dir/$file", $data;
731 } elsif (my $filter = $meta->{cfutil_filter}) { 798 } elsif (my $filter = delete $meta->{cfutil_filter}) {
732 if ($filter eq "yaml2json") { 799 if ($filter eq "yaml2json") {
733 $data = JSON::XS::encode_json YAML::XS::Load $data; 800 $data = JSON::XS::encode_json YAML::XS::Load $data;
734 } elsif ($filter eq "json2json") { 801 } elsif ($filter eq "json2json") {
735 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); 802 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data);
736 } elsif ($filter eq "perl2json") { 803 } elsif ($filter eq "perl2json") {
737 $data = eval $data; die if $@; 804 $data = eval $data; die if $@;
738 $data = JSON::XS::encode_json $data; 805 $data = JSON::XS::encode_json $data;
739 } else { 806 } else {
740 warn "$dir/$file: unknown filter $filter, skipping\n"; 807 warn "ERROR: $dir/$file: unknown filter $filter, skipping\n";
741 } 808 }
742 } 809 }
743 810
744 substr $dir, 0, 1 + length $PATH, ""; 811 substr $dir, 0, 1 + length $PATH, "";
745 812
746 $RESOURCE{"$dir/$file"} = { 813 my %info = (
747 type => (exists $meta->{type} ? delete $meta->{type} : $type), 814 type => (exists $meta->{type} ? delete $meta->{type} : $type),
748 data => $data, 815 data => $data,
749 %$meta ? (meta => $meta) : (), 816 %$meta ? (meta => $meta) : (),
750 }; 817 );
818
819 $RESOURCE{"$dir/$file"} = \%info;
751 } 820 }
752 821
753 sub process_any { 822 sub process_any {
754 while (my ($func, @args) = @{ $c_any->get }) { 823 while (my ($func, @args) = @{ $c_any->get }) {
755 $func->(@args); 824 $func->(@args);
788 if ($file =~ /\.(jpg|png)$/) { 857 if ($file =~ /\.(jpg|png)$/) {
789 $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE 858 $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE
790 } elsif ($file =~ /\.(res)$/) { 859 } elsif ($file =~ /\.(res)$/) {
791 $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC 860 $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC
792 } else { 861 } else {
793 $c_any->put ([\&process_res, $path, $file, undef]); 862 $c_any->put ([\&process_res, $path, $file, 6]); # was type undef, but now meta files are mandatory, so any mentioned file surely has a purpose
794 } 863 }
795 864
796 } elsif ($file =~ /\.png$/) { 865 } elsif ($file =~ /\.png$/) {
797 push @c_png, ["$path/$file", 0]; 866 $PNG{$file} = $path;
798 867
799 } elsif ($file =~ /\.faceinfo$/) { 868 } elsif ($file =~ /\.faceinfo$/) {
800 $c_any->put ([\&process_faceinfo, $path, $file]); 869 $c_any->put ([\&process_faceinfo, $path, $file]);
801 870
802 } elsif ($file =~ /\.trs$/) { 871 } elsif ($file =~ /\.trs$/) {
855 "Unless you run verbosely, all following warning\n", 924 "Unless you run verbosely, all following warning\n",
856 "or error messages indicate serious problems.\n", 925 "or error messages indicate serious problems.\n",
857 "\n"; 926 "\n";
858 927
859 if (!-d "$path/treasures") { 928 if (!-d "$path/treasures") {
860 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 929 warn "FATAL: '$path' does not look like an arch directory ('treasures' directory is missing).\n";
861 exit 1 unless $FORCE; 930 exit 1 unless $FORCE;
862 } 931 }
863 932
864 print "starting file scan, arc, any processing...\n" if $VERBOSE; 933 print "starting file scan, arc, any processing...\n" if $VERBOSE;
865 934
870 939
871 $c_arc->shutdown; 940 $c_arc->shutdown;
872 $c_any->shutdown; 941 $c_any->shutdown;
873 942
874 $_->join for @a_arc; # need to parse all archetypes before png processing 943 $_->join for @a_arc; # need to parse all archetypes before png processing
875 print "ended arc processing...\n" if $VERBOSE; 944 print "finished arc processing...\n" if $VERBOSE;
945
946 # fill png queue
947 for (keys %FACEINFO) {
948 # we only expect source pngs to exist for non-derived
949 # faces, i.e. no split tiles (+x+x) and no face derivates
950 # (xxx:)
951 /^[^:]+\....$/
952 or next;
953
954 my $seen;
955
956 if (exists $PNG{"$_.32x32.png"}) {
957 push @c_png, ["$PNG{\"$_.32x32.png\"}/$_.32x32.png"];
958 $seen = 1;
959 }
960 if (exists $PNG{"$_.64x64.png"}) {
961 push @c_png, ["$PNG{\"$_.64x64.png\"}/$_.64x64.png"];
962 $seen = 1;
963 }
964
965 warn "ERROR: $_: face not found, expect problems.\n"
966 unless $seen;
967 }
876 968
877 print "starting png processing...\n" if $VERBOSE; 969 print "starting png processing...\n" if $VERBOSE;
878 970
879 # eight png crunchers work fine for my 4x smp machine 971 # eight png crunchers work fine for my 4x smp machine
880 my @a_png = map +(async \&process_png), 1..8; 972 my @a_png = map +(async \&process_png), 1..8;
881 973
882 $_->join for @a_any; 974 $_->join for @a_any;
883 print "ended any processing...\n" if $VERBOSE; 975 print "finished any processing...\n" if $VERBOSE;
884 976
885 $_->join for @a_png; 977 $_->join for @a_png;
886 print "ended png processing...\n" if $VERBOSE; 978 print "finished png processing...\n" if $VERBOSE;
887 979
888 print "scanning done, processing results...\n" if $VERBOSE; 980 print "scanning done, processing results...\n" if $VERBOSE;
889 { 981 {
890 # remove path prefix from editor_folder 982 # remove path prefix from editor_folder
891 $_->{editor_folder} =~ /^\x00/ 983 $_->{editor_folder} =~ /^\x00/
909 delete @s{qw(_name more name name_pl)}; 1001 delete @s{qw(_name more name name_pl)};
910 %$o = ( %s, %$o ); 1002 %$o = ( %s, %$o );
911 ++$progress; 1003 ++$progress;
912 } 1004 }
913 } else { 1005 } else {
914 warn "WARNING: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; 1006 warn "ERROR: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n";
915 delete $ARC{$o->{_name}}; 1007 delete $ARC{$o->{_name}};
916 } 1008 }
917 } 1009 }
918 } 1010 }
919 1011
955 print $fh $TRS; 1047 print $fh $TRS;
956 } 1048 }
957 1049
958 { 1050 {
959 print "processing facedata...\n" if $VERBOSE; 1051 print "processing facedata...\n" if $VERBOSE;
960 while (my ($k, $v) = each %FACEINFO) { 1052
1053 for my $k (sort keys %FACEINFO) {
1054 my $v = $FACEINFO{$k};
1055
961 length $v->{data32} or warn "WARNING: face '$k' has no png32. this will not work (shoddy gcfclient will crash of course).\n"; 1056 length $v->{data32} or warn "ERROR: face '$k' has no png32 - this will not work.\n";
962 length $v->{data64} or warn "WARNING: face '$k' has no png64. this will not work very well.\n"; 1057 length $v->{data64} or warn "ERROR: face '$k' has no png64 - this will not work.\n";
963 1058
964 make_hash $k, $v->{data32}, $v->{hash32}; 1059 make_hash $k, $v->{data32}, $v->{hash32};
965 make_hash $k, $v->{data64}, $v->{hash64}; 1060 make_hash $k, $v->{data64}, $v->{hash64};
966 1061
967 #length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n"; 1062 #length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n";
968 #length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n"; 1063 #length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n";
969 1064
970 $v->{glyph} // warn "WARNING: face '$k' has glyph."; 1065 $v->{glyph} // warn "ERROR: face '$k' has no glyph - missing faceinfo entry?\n";
971 $v->{visibility} // warn "WARNING: face '$k' has no visibility info, missing faceinfo entry?\n"; 1066 $v->{visibility} // warn "ERROR: face '$k' has no visibility info - missing faceinfo entry?\n";
972 $v->{magicmap} // warn "WARNING: face '$k' has foreground colour."; 1067 $v->{magicmap} // warn "ERROR: face '$k' has no foreground colour - missing faceinfo entry?\n";
973 1068
1069 if (0 && $v->{w} == 1 && $v->{h} == 1) { # texture catalogs
1070 my $id = @TC;
1071 my $n = @{ $TC[-1] };
1072 my $x = $n % TC_W;
1073 my $y = int $n / TC_W;
1074
1075 push @{ $TC[-1] }, [$v, $x, $y];
1076
1077 $v->{tc} = [$id, $x, $y];
1078
1079 push @TC, [] if $n == TC_W * TC_H - 1; # start new texture if full
1080 }
1081
974 delete @$v{qw(arc stem)}; # not used by the server 1082 delete @$v{qw(w h arc stem derive)}; # not used by the server
1083 }
1084
1085if (0) { #d# texture catalogs
1086 print "creating texture catalogs...\n" if $VERBOSE;
1087
1088 for my $id (0 .. $#TC) {
1089 my $tc = $TC[$id];
1090
1091 my $cmd = "$CONVERT -depth 8 -size " . (TC_W * 64) . "x" . (TC_H * 64) . " xc:transparent";
1092 my $idx = "a";
1093
1094 for (@$tc) {
1095 my $path = "$TMPDIR/tc" . $idx++;
1096
1097 open my $fh, ">:perlio", $path
1098 or die "$path: $!";
1099 syswrite $fh, $_->[0]{data64};
1100
1101 my $x = $_->[1] * 64;
1102 my $y = $_->[2] * 64;
1103
1104 $cmd .= " png:\Q$path\E -geometry +$x+$y -composite";
975 } 1105 }
1106
1107 system "$cmd png:\Q$TMPDIR/tc$id\E";
1108 optipng "$TMPDIR/tc$id";
1109 }
1110}
976 1111
977 print "processing resources...\n" if $VERBOSE; 1112 print "processing resources...\n" if $VERBOSE;
978 my $enc = JSON::XS->new->utf8->canonical->relaxed; 1113 my $enc = JSON::XS->new->utf8->canonical->relaxed;
979 while (my ($k, $v) = each %RESOURCE) { 1114 for my $k (sort keys %RESOURCE) {
1115 my $v = $RESOURCE{$k};
980 1116
981 if ($v->{meta} && $v->{meta}{datadir}) { 1117 if ($v->{meta} && $v->{meta}{datadir}) {
982 delete $RESOURCE{$k}; 1118 delete $RESOURCE{$k};
983 1119
984 $k =~ s/^res\/// or die "$k: datadir files must be in res/"; 1120 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
1003 1139
1004 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 1140 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
1005 } 1141 }
1006 } 1142 }
1007 1143
1144 printf "writing facedata...\n" if $VERBOSE;
1145
1146 {
1147 open my $fh, ">:perlio", "$DATADIR/facedata~"
1148 or die "$DATADIR/facedata~: $!";
1149
1150 print $fh "FACEDATA";
1151 my $fofs = 8;
1152
1153 my $put = sub {
1154 my $len = length $_[0];
1155 my $ofs = $fofs;
1156
1157 print $fh $_[0];
1158 $fofs += $len;
1159
1160 ($len, $ofs)
1161 };
1162
1163 for (values %FACEINFO) {
1164 ($_->{size32}, $_->{fofs32}) = $put->(delete $_->{data32});
1165 ($_->{size64}, $_->{fofs64}) = $put->(delete $_->{data64});
1166 }
1167
1168 for (values %RESOURCE) {
1169 ($_->{size}, $_->{fofs}) = $put->(delete $_->{data});
1170 }
1171
1172 close $fh;
1173 }
1174
1008 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 1175 printf "writing faceinfo (%d faces, %d anims, %d resources)...\n",
1009 scalar keys %FACEINFO, 1176 scalar keys %FACEINFO,
1010 scalar keys %ANIMINFO, 1177 scalar keys %ANIMINFO,
1011 scalar keys %RESOURCE 1178 scalar keys %RESOURCE
1012 if $VERBOSE; 1179 if $VERBOSE;
1013 1180
1014 open my $fh, ">:perlio", "$DATADIR/facedata~" 1181 open my $fh, ">:perlio", "$DATADIR/faceinfo~"
1015 or die "$DATADIR/facedata~: $!"; 1182 or die "$DATADIR/faceinfo~: $!";
1016 1183
1017 print $fh nfreeze { 1184 print $fh nfreeze {
1018 version => 2, 1185 version => 2,
1019 faceinfo => \%FACEINFO, 1186 faceinfo => \%FACEINFO,
1020 animinfo => \%ANIMINFO, 1187 animinfo => \%ANIMINFO,
1022 }; 1189 };
1023 } 1190 }
1024 1191
1025 print "committing files...\n" if $VERBOSE; 1192 print "committing files...\n" if $VERBOSE;
1026 1193
1027 for (qw(archetypes facedata treasures), @COMMIT) { 1194 for (qw(archetypes faceinfo facedata treasures), @COMMIT) {
1028 chmod 0644, "$DATADIR/$_~"; 1195 chmod 0644, "$DATADIR/$_~";
1029 rename "$DATADIR/$_~", "$DATADIR/$_" 1196 rename "$DATADIR/$_~", "$DATADIR/$_"
1030 or die "$DATADIR/$_: $!"; 1197 or die "$DATADIR/$_: $!";
1031 } 1198 }
1032 1199

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines