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.123 by root, Sun Nov 11 04:29:11 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
711 $meta->{license} = ({ 775 $meta->{license} = ({
712 "pd" => "Public Domain", 776 "pd" => "Public Domain",
713 "gpl" => "GNU General Public License, version 3.0 or any later", 777 "gpl" => "GNU General Public License, version 3.0 or any later",
714 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", 778 "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/", 779 "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/", 780 "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/", 781 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
718 })->{$meta->{license}} 782 })->{$meta->{license}}
719 || warn "$dir/$file: license tag '$meta->{license}' not found."; 783 || warn "ERROR: $dir/$file: license tag '$meta->{license}' not found.";
720 } 784 }
721 785
722 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) { 786 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
723 ($meta->{author} = $1) =~ s/_/ /g; 787 ($meta->{author} = $1) =~ s/_/ /g;
724 } 788 }
726 $file =~ s/\.res$//; 790 $file =~ s/\.res$//;
727 $file =~ s/\.(ogg|wav|jpg|png)$//; 791 $file =~ s/\.(ogg|wav|jpg|png)$//;
728 792
729 if ($file =~ s/\.plt$//) { 793 if ($file =~ s/\.plt$//) {
730 $data = process_plt "$dir/$file", $data; 794 $data = process_plt "$dir/$file", $data;
731 } elsif (my $filter = $meta->{cfutil_filter}) { 795 } elsif (my $filter = delete $meta->{cfutil_filter}) {
732 if ($filter eq "yaml2json") { 796 if ($filter eq "yaml2json") {
733 $data = JSON::XS::encode_json YAML::XS::Load $data; 797 $data = JSON::XS::encode_json YAML::XS::Load $data;
734 } elsif ($filter eq "json2json") { 798 } elsif ($filter eq "json2json") {
735 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); 799 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data);
736 } elsif ($filter eq "perl2json") { 800 } elsif ($filter eq "perl2json") {
737 $data = eval $data; die if $@; 801 $data = eval $data; die if $@;
738 $data = JSON::XS::encode_json $data; 802 $data = JSON::XS::encode_json $data;
739 } else { 803 } else {
740 warn "$dir/$file: unknown filter $filter, skipping\n"; 804 warn "ERROR: $dir/$file: unknown filter $filter, skipping\n";
741 } 805 }
742 } 806 }
743 807
744 substr $dir, 0, 1 + length $PATH, ""; 808 substr $dir, 0, 1 + length $PATH, "";
745 809
746 $RESOURCE{"$dir/$file"} = { 810 my %info = (
747 type => (exists $meta->{type} ? delete $meta->{type} : $type), 811 type => (exists $meta->{type} ? delete $meta->{type} : $type),
748 data => $data, 812 data => $data,
749 %$meta ? (meta => $meta) : (), 813 %$meta ? (meta => $meta) : (),
750 }; 814 );
815
816 $RESOURCE{"$dir/$file"} = \%info;
751 } 817 }
752 818
753 sub process_any { 819 sub process_any {
754 while (my ($func, @args) = @{ $c_any->get }) { 820 while (my ($func, @args) = @{ $c_any->get }) {
755 $func->(@args); 821 $func->(@args);
788 if ($file =~ /\.(jpg|png)$/) { 854 if ($file =~ /\.(jpg|png)$/) {
789 $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE 855 $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE
790 } elsif ($file =~ /\.(res)$/) { 856 } elsif ($file =~ /\.(res)$/) {
791 $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC 857 $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC
792 } else { 858 } else {
793 $c_any->put ([\&process_res, $path, $file, undef]); 859 $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 } 860 }
795 861
796 } elsif ($file =~ /\.png$/) { 862 } elsif ($file =~ /\.png$/) {
797 push @c_png, ["$path/$file", 0]; 863 $PNG{$file} = $path;
798 864
799 } elsif ($file =~ /\.faceinfo$/) { 865 } elsif ($file =~ /\.faceinfo$/) {
800 $c_any->put ([\&process_faceinfo, $path, $file]); 866 $c_any->put ([\&process_faceinfo, $path, $file]);
801 867
802 } elsif ($file =~ /\.trs$/) { 868 } elsif ($file =~ /\.trs$/) {
855 "Unless you run verbosely, all following warning\n", 921 "Unless you run verbosely, all following warning\n",
856 "or error messages indicate serious problems.\n", 922 "or error messages indicate serious problems.\n",
857 "\n"; 923 "\n";
858 924
859 if (!-d "$path/treasures") { 925 if (!-d "$path/treasures") {
860 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 926 warn "FATAL: '$path' does not look like an arch directory ('treasures' directory is missing).\n";
861 exit 1 unless $FORCE; 927 exit 1 unless $FORCE;
862 } 928 }
863 929
864 print "starting file scan, arc, any processing...\n" if $VERBOSE; 930 print "starting file scan, arc, any processing...\n" if $VERBOSE;
865 931
870 936
871 $c_arc->shutdown; 937 $c_arc->shutdown;
872 $c_any->shutdown; 938 $c_any->shutdown;
873 939
874 $_->join for @a_arc; # need to parse all archetypes before png processing 940 $_->join for @a_arc; # need to parse all archetypes before png processing
875 print "ended arc processing...\n" if $VERBOSE; 941 print "finished arc processing...\n" if $VERBOSE;
942
943 # fill png queue
944 for (keys %FACEINFO) {
945 # we only expect source pngs to exist for non-derived
946 # faces, i.e. no split tiles (+x+x) and no face derivates
947 # (xxx:)
948 /^[^:]+\....$/
949 or next;
950
951 my $seen;
952
953 if (exists $PNG{"$_.32x32.png"}) {
954 push @c_png, ["$PNG{\"$_.32x32.png\"}/$_.32x32.png"];
955 $seen = 1;
956 }
957 if (exists $PNG{"$_.64x64.png"}) {
958 push @c_png, ["$PNG{\"$_.64x64.png\"}/$_.64x64.png"];
959 $seen = 1;
960 }
961
962 warn "ERROR: $_: face not found, expect problems.\n"
963 unless $seen;
964 }
876 965
877 print "starting png processing...\n" if $VERBOSE; 966 print "starting png processing...\n" if $VERBOSE;
878 967
879 # eight png crunchers work fine for my 4x smp machine 968 # eight png crunchers work fine for my 4x smp machine
880 my @a_png = map +(async \&process_png), 1..8; 969 my @a_png = map +(async \&process_png), 1..8;
881 970
882 $_->join for @a_any; 971 $_->join for @a_any;
883 print "ended any processing...\n" if $VERBOSE; 972 print "finished any processing...\n" if $VERBOSE;
884 973
885 $_->join for @a_png; 974 $_->join for @a_png;
886 print "ended png processing...\n" if $VERBOSE; 975 print "finished png processing...\n" if $VERBOSE;
887 976
888 print "scanning done, processing results...\n" if $VERBOSE; 977 print "scanning done, processing results...\n" if $VERBOSE;
889 { 978 {
890 # remove path prefix from editor_folder 979 # remove path prefix from editor_folder
891 $_->{editor_folder} =~ /^\x00/ 980 $_->{editor_folder} =~ /^\x00/
909 delete @s{qw(_name more name name_pl)}; 998 delete @s{qw(_name more name name_pl)};
910 %$o = ( %s, %$o ); 999 %$o = ( %s, %$o );
911 ++$progress; 1000 ++$progress;
912 } 1001 }
913 } else { 1002 } else {
914 warn "WARNING: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n"; 1003 warn "ERROR: archetype '$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n";
915 delete $ARC{$o->{_name}}; 1004 delete $ARC{$o->{_name}};
916 } 1005 }
917 } 1006 }
918 } 1007 }
919 1008
955 print $fh $TRS; 1044 print $fh $TRS;
956 } 1045 }
957 1046
958 { 1047 {
959 print "processing facedata...\n" if $VERBOSE; 1048 print "processing facedata...\n" if $VERBOSE;
960 while (my ($k, $v) = each %FACEINFO) { 1049
1050 for my $k (sort keys %FACEINFO) {
1051 my $v = $FACEINFO{$k};
1052
961 length $v->{data32} or warn "WARNING: face '$k' has no png32. this will not work (shoddy gcfclient will crash of course).\n"; 1053 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"; 1054 length $v->{data64} or warn "ERROR: face '$k' has no png64 - this will not work.\n";
963 1055
964 make_hash $k, $v->{data32}, $v->{hash32}; 1056 make_hash $k, $v->{data32}, $v->{hash32};
965 make_hash $k, $v->{data64}, $v->{hash64}; 1057 make_hash $k, $v->{data64}, $v->{hash64};
966 1058
967 #length $v->{data32} <= 10000 or warn "WARNING: face '$k' has face32 larger than 10000 bytes, will not work with crossfire client.\n"; 1059 #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"; 1060 #length $v->{data64} <= 10000 or warn "WARNING: face '$k' has face64 larger than 10000 bytes.\n";
969 1061
970 $v->{glyph} // warn "WARNING: face '$k' has glyph."; 1062 $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"; 1063 $v->{visibility} // warn "ERROR: face '$k' has no visibility info - missing faceinfo entry?\n";
972 $v->{magicmap} // warn "WARNING: face '$k' has foreground colour."; 1064 $v->{magicmap} // warn "ERROR: face '$k' has no foreground colour - missing faceinfo entry?\n";
973 1065
1066 if (0 && $v->{w} == 1 && $v->{h} == 1) { # texture catalogs
1067 my $id = @TC;
1068 my $n = @{ $TC[-1] };
1069 my $x = $n % TC_W;
1070 my $y = int $n / TC_W;
1071
1072 push @{ $TC[-1] }, [$v, $x, $y];
1073
1074 $v->{tc} = [$id, $x, $y];
1075
1076 push @TC, [] if $n == TC_W * TC_H - 1; # start new texture if full
1077 }
1078
974 delete @$v{qw(arc stem)}; # not used by the server 1079 delete @$v{qw(w h arc stem derive)}; # not used by the server
1080 }
1081
1082if (0) { #d# texture catalogs
1083 print "creating texture catalogs...\n" if $VERBOSE;
1084
1085 for my $id (0 .. $#TC) {
1086 my $tc = $TC[$id];
1087
1088 my $cmd = "$CONVERT -depth 8 -size " . (TC_W * 64) . "x" . (TC_H * 64) . " xc:transparent";
1089 my $idx = "a";
1090
1091 for (@$tc) {
1092 my $path = "$TMPDIR/tc" . $idx++;
1093
1094 open my $fh, ">:perlio", $path
1095 or die "$path: $!";
1096 syswrite $fh, $_->[0]{data64};
1097
1098 my $x = $_->[1] * 64;
1099 my $y = $_->[2] * 64;
1100
1101 $cmd .= " png:\Q$path\E -geometry +$x+$y -composite";
975 } 1102 }
1103
1104 system "$cmd png:\Q$TMPDIR/tc$id\E";
1105 optipng "$TMPDIR/tc$id";
1106 }
1107}
976 1108
977 print "processing resources...\n" if $VERBOSE; 1109 print "processing resources...\n" if $VERBOSE;
978 my $enc = JSON::XS->new->utf8->canonical->relaxed; 1110 my $enc = JSON::XS->new->utf8->canonical->relaxed;
979 while (my ($k, $v) = each %RESOURCE) { 1111 while (my ($k, $v) = each %RESOURCE) {
980
981 if ($v->{meta} && $v->{meta}{datadir}) { 1112 if ($v->{meta} && $v->{meta}{datadir}) {
982 delete $RESOURCE{$k}; 1113 delete $RESOURCE{$k};
983 1114
984 $k =~ s/^res\/// or die "$k: datadir files must be in res/"; 1115 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
985 1116
1003 1134
1004 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 1135 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
1005 } 1136 }
1006 } 1137 }
1007 1138
1139 printf "writing facedata...\n" if $VERBOSE;
1140
1141 {
1142 open my $fh, ">:perlio", "$DATADIR/facedata~"
1143 or die "$DATADIR/facedata~: $!";
1144
1145 print $fh "FACEDATA";
1146 my $fofs = 8;
1147
1148 my $put = sub {
1149 my $len = length $_[0];
1150 my $ofs = $fofs;
1151
1152 print $fh $_[0];
1153 $fofs += $len;
1154
1155 ($len, $ofs)
1156 };
1157
1158 for (values %FACEINFO) {
1159 ($_->{size32}, $_->{fofs32}) = $put->(delete $_->{data32});
1160 ($_->{size64}, $_->{fofs64}) = $put->(delete $_->{data64});
1161 }
1162
1163 for (values %RESOURCE) {
1164 ($_->{size}, $_->{fofs}) = $put->(delete $_->{data});
1165 }
1166
1167 close $fh;
1168 }
1169
1008 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 1170 printf "writing faceinfo (%d faces, %d anims, %d resources)...\n",
1009 scalar keys %FACEINFO, 1171 scalar keys %FACEINFO,
1010 scalar keys %ANIMINFO, 1172 scalar keys %ANIMINFO,
1011 scalar keys %RESOURCE 1173 scalar keys %RESOURCE
1012 if $VERBOSE; 1174 if $VERBOSE;
1013 1175
1014 open my $fh, ">:perlio", "$DATADIR/facedata~" 1176 open my $fh, ">:perlio", "$DATADIR/faceinfo~"
1015 or die "$DATADIR/facedata~: $!"; 1177 or die "$DATADIR/faceinfo~: $!";
1016 1178
1017 print $fh nfreeze { 1179 print $fh nfreeze {
1018 version => 2, 1180 version => 2,
1019 faceinfo => \%FACEINFO, 1181 faceinfo => \%FACEINFO,
1020 animinfo => \%ANIMINFO, 1182 animinfo => \%ANIMINFO,
1022 }; 1184 };
1023 } 1185 }
1024 1186
1025 print "committing files...\n" if $VERBOSE; 1187 print "committing files...\n" if $VERBOSE;
1026 1188
1027 for (qw(archetypes facedata treasures), @COMMIT) { 1189 for (qw(archetypes faceinfo facedata treasures), @COMMIT) {
1028 chmod 0644, "$DATADIR/$_~"; 1190 chmod 0644, "$DATADIR/$_~";
1029 rename "$DATADIR/$_~", "$DATADIR/$_" 1191 rename "$DATADIR/$_~", "$DATADIR/$_"
1030 or die "$DATADIR/$_: $!"; 1192 or die "$DATADIR/$_: $!";
1031 } 1193 }
1032 1194

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines