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.111 by root, Fri Apr 22 02:03:12 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 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($\$\$;$) {
119 my ($id, $dataref, $hashref, $clen) = @_; 119 my ($id, $dataref, $hashref, $clen) = @_;
120 120
121 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; 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\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 }
132 $hash{$hash} = [$id, $dataref, $hashref]; 132 $hash{$hash} = [$id, $dataref, $hashref];
133 133
134 $$hashref = $hash; 134 $$hashref = $hash;
135}
136
137sub optipng($) {
138 system $OPTIPNG, "-o5", "-i0", "-q", $_[0];
139 die "$_[0] has zero size, aborting." unless -s $_[0];
135} 140}
136 141
137mkdir $TMPDIR, 0700 142mkdir $TMPDIR, 0700
138 or die "$TMPDIR: $!"; 143 or die "$TMPDIR: $!";
139 144
185 my (undef, $path) = @_; 190 my (undef, $path) = @_;
186 191
187 print "\nInstalling '$path' to '$DATADIR/maps'\n\n"; 192 print "\nInstalling '$path' to '$DATADIR/maps'\n\n";
188 193
189 if (!-f "$path/regions") { 194 if (!-f "$path/regions") {
190 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";
191 exit 1 unless $FORCE; 196 exit 1 unless $FORCE;
192 } 197 }
193 198
194 system $RSYNC, "-av", "--chmod=u=rwX,go=rX", 199 system $RSYNC, "-av", "--chmod=u=rwX,go=rX",
195 "$path/.", "$DATADIR/maps/.", 200 "$path/.", "$DATADIR/maps/.",
205 our %FACEINFO; 210 our %FACEINFO;
206 our %RESOURCE; 211 our %RESOURCE;
207 our @ARC; 212 our @ARC;
208 our %ARC; 213 our %ARC;
209 our $TRS; 214 our $TRS;
215 our %PNG;
210 our $NFILE; 216 our $NFILE;
211 our $PATH; 217 our $PATH;
212 218
213 our $QUANTIZE = "+dither -colorspace RGB -colors 256"; 219 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
214 220
215 our $c_arc = new Coro::Channel; 221 our $c_arc = new Coro::Channel;
216 our $c_any = new Coro::Channel; 222 our $c_any = new Coro::Channel;
217 223
218 our @c_png; 224 our @c_png;
219 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
220 sub commit_png($$$$) { 232 sub commit_png($$$$$$) {
221 my ($stem, $name, $data, $T) = @_; 233 my ($stem, $name, $data, $T, $w, $h) = @_;
222 234
223 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH; 235 $FACEINFO{$name}{stem} = substr $stem, 1 + length $PATH;
224 $FACEINFO{$name}{"data$T"} = $data; 236 $FACEINFO{$name}{"data$T"} = $data;
237 $FACEINFO{$name}{w} = $w;
238 $FACEINFO{$name}{h} = $h;
225 } 239 }
226 240
227 sub process_png { 241 sub process_png {
228 while (@c_png) { 242 while (@c_png) {
229 my ($path, $delete) = @{pop @c_png}; 243 my ($path, $delete) = @{pop @c_png};
231 my $png; 245 my $png;
232 aio_lstat $path; 246 aio_lstat $path;
233 my ($size, $mtime) = (stat _)[7,9]; 247 my ($size, $mtime) = (stat _)[7,9];
234 248
235 if (0 > aio_load $path, $png) { 249 if (0 > aio_load $path, $png) {
236 warn "$path: $!, skipping.\n"; 250 warn "ERROR: $path: $!, skipping.\n";
237 next; 251 next;
238 } 252 }
239 253
240 my $stem = $path; 254 my $stem = $path;
241 my $T; 255 my $T;
243 if ($stem =~ s/\.32x32\.png~?$//) { 257 if ($stem =~ s/\.32x32\.png~?$//) {
244 $T = 32; 258 $T = 32;
245 } elsif ($stem =~ s/\.64x64\.png~?$//) { 259 } elsif ($stem =~ s/\.64x64\.png~?$//) {
246 $T = 64; 260 $T = 64;
247 } else { 261 } else {
248 warn "$path: weird filename, skipping.\n"; 262 warn "ERROR: $path: weird filename, skipping.\n";
249 next; 263 next;
250 } 264 }
251 265
252 # quickly extract width and height of the (necessarily PNG) image 266 # quickly extract width and height of the (necessarily PNG) image
253 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 267 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
254 warn "$path: not a recognized png file, skipping.\n"; 268 warn "ERROR: $path: not a recognized png file, skipping.\n";
255 next; 269 next;
256 } 270 }
257 271
258 my ($w, $h) = unpack "NN", $1; 272 my ($w, $h) = unpack "NN", $1;
259 273
260 if ($w < $T || $h < $T) { 274 if ($w < $T || $h < $T) {
261 warn "$path: too small ($w $h), skipping.\n"; 275 warn "ERROR: $path: too small ($w $h), skipping.\n";
262 next; 276 next;
263 } 277 }
264 278
265 if ($w % $T || $h % $T) { 279 if ($w % $T || $h % $T) {
266 warn "$path: weird png size ($w $h), skipping.\n"; 280 warn "ERROR: $path: weird png size ($w $h), skipping.\n";
267 next; 281 next;
268 } 282 }
269 283
270 (my $base = $stem) =~ s/^.*\///; 284 (my $base = $stem) =~ s/^.*\///;
271 285
341 $x * ($w - 8) + 4, 355 $x * ($w - 8) + 4,
342 $y * ($h - 8) + 4; 356 $y * ($h - 8) + 4;
343 } 357 }
344 } 358 }
345 359
346 system "convert -depth 8 $SRC rgba:-" 360 system "$CONVERT -depth 8 $SRC rgba:-"
347 . "| $exec_prefix/bin/cfhq2xa $w $h 0" 361 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
348 . "| 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~"
349 and die "convert/cfhq2xa pipeline error: status $? ($!)"; 363 and die "convert/cfhq2xa pipeline error: status $? ($!)";
350 system $OPTIPNG, "-i0", "-q", "$other~"; 364 optipng "$other~";
351 die "$other~ has zero size, aborting." unless -s "$other~";
352 rename "$other~", $other; 365 rename "$other~", $other;
353 }; 366 };
354 }; 367 };
355 368
356 push @c_png, [$other, !$CACHE]; 369 push @c_png, [$other, !$CACHE];
360 if (0 > aio_stat "$stem.32x32.png") { 373 if (0 > aio_stat "$stem.32x32.png") {
361 my $other = "$stem.32x32.png~"; 374 my $other = "$stem.32x32.png~";
362 375
363 make_file $path, $other, sub { 376 make_file $path, $other, sub {
364 fork_exec { 377 fork_exec {
365 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~";
366 system $OPTIPNG, "-i0", "-q", "$other~"; 379 optipng "$other~";
367 380
368 # reduce smoothfaces >10000 bytes 381 # reduce smoothfaces >10000 bytes
369 # obsolete, no longer required 382 # obsolete, no longer required
370 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) { 383 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) {
371 my $ncolor = 256; 384 my $ncolor = 256;
372 while () { 385 while () {
373 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; 386 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E";
374 system $OPTIPNG, "-i0", "-q", "$other~~"; 387 optipng "$other~~";
375 last if 10000 > -s "$other~~"; 388 last if 10000 > -s "$other~~";
376 $ncolor = int $ncolor * 0.9; 389 $ncolor = int $ncolor * 0.9;
377 $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; 390 $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes";
378 } 391 }
379 392
392 push @c_png, [$other, !$CACHE]; 405 push @c_png, [$other, !$CACHE];
393 } 406 }
394 } 407 }
395 408
396 (my $face = $stem) =~ s/^.*\///; 409 (my $face = $stem) =~ s/^.*\///;
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 }
397 460
398 # split all bigfaces, but avoid smoothfaces (*_S) 461 # split all bigfaces, but avoid smoothfaces (*_S)
399 if (($w > $T || $h > $T) && $face !~ /_S\./) { 462 if (($w > $T || $h > $T) && $face !~ /_S\./) {
400 # split 463 # split
401 my @tile; 464 my @tile;
406 push @tile, [$x, $y, $file, (stat _)[9]]; 469 push @tile, [$x, $y, $file, (stat _)[9]];
407 } 470 }
408 } 471 }
409 472
410 my $mtime = (lstat $path)[9]; 473 my $mtime = (lstat $path)[9];
411 my @todo = grep { $_->[3] <= $mtime } @tile; 474 my @todo = grep { $_->[3] < $mtime } @tile;
412 if (@todo) { 475 if (@todo) {
413 fork_exec { 476 fork_exec {
414 open my $convert, "|-", $CONVERT, 477 open my $convert, "|-", $CONVERT,
415 "png:-", 478 "png:-",
416 (map { 479 (map {
431 print $convert $png; 494 print $convert $png;
432 close $convert; 495 close $convert;
433 496
434 # pass 2, optimise, and rename 497 # pass 2, optimise, and rename
435 for (@todo) { 498 for (@todo) {
436 system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; 499 optipng "$_->[2]~";
437 die "$_->[2]~ has zero size, aborting." unless -s "$_->[2]~";
438 rename "$_->[2]~", $_->[2]; 500 rename "$_->[2]~", $_->[2];
439 } 501 }
440 }; 502 };
441 } 503 }
442 504
446 508
447 if (0 > aio_load $file, $tile) { 509 if (0 > aio_load $file, $tile) {
448 die "$path: unable to read tile +$x+$y, aborting.\n"; 510 die "$path: unable to read tile +$x+$y, aborting.\n";
449 } 511 }
450 IO::AIO::aio_unlink $file unless $CACHE; 512 IO::AIO::aio_unlink $file unless $CACHE;
451 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;
452 } 514 }
453 } else { 515 } else {
454 # use as-is (either small, use smooth) 516 # use as-is (either small, use smooth)
455 commit_png $stem, $face, $png, $T; 517 commit_png $stem, $face, $png, $T, $w / $T, $h / $T;
456 } 518 }
457 519
458 aio_unlink $path if $delete; 520 IO::AIO::aio_unlink $path if $delete;
459 } 521 }
460 } 522 }
461 523
462 sub process_faceinfo { 524 sub process_faceinfo {
463 my ($dir, $file) = @_; 525 my ($dir, $file) = @_;
464 my $path = "$dir/$file"; 526 my $path = "$dir/$file";
465 527
466 my $data; 528 my $data;
467 if (0 > aio_load $path, $data) { 529 if (0 > aio_load $path, $data) {
468 warn "$path: $!, skipping.\n"; 530 warn "ERROR: $path: $!, skipping.\n";
469 return; 531 return;
470 } 532 }
471 533
472 for (split /\n/, $data) { 534 for (split /\n/, $data) {
473 chomp; 535 chomp;
479 $glyph =~ s/^"(.+)"$/$1/; # allow for ""-style quoting 541 $glyph =~ s/^"(.+)"$/$1/; # allow for ""-style quoting
480 542
481 $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
482 544
483 (my $fgi = $COLOR{$fg}) 545 (my $fgi = $COLOR{$fg})
484 // warn "WARNING: $path: $face specifies unknown foreground colour '$fg'.\n"; 546 // warn "ERROR: $path: $face specifies unknown foreground colour '$fg'.\n";
485 (my $bgi = $COLOR{$bg}) 547 (my $bgi = $COLOR{$bg})
486 // warn "WARNING: $path: $face specifies unknown background colour '$bg'.\n"; 548 // warn "ERROR: $path: $face specifies unknown background colour '$bg'.\n";
487 549
488 my $fi = $FACEINFO{$face} ||= { }; 550 my $fi = $FACEINFO{$face} ||= { };
489 $fi->{visibility} = $visibility * 1; 551 $fi->{visibility} = $visibility * 1;
490 $fi->{magicmap} = $fgi; # foreground colour becomes magicmap 552 $fi->{magicmap} = $fgi; # foreground colour becomes magicmap
491 553
560 next if /^facings\s/; 622 next if /^facings\s/;
561 623
562 my $face = $_; 624 my $face = $_;
563 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates 625 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates
564 626
565 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
566 $info->{arc} = $o; 633 $FACEINFO{$face}{arc} = $o;
567 634
568 next if $face =~ /^blank.x11$|^empty.x11$/; 635 next if $face =~ /^blank.x11$|^empty.x11$/;
569 } 636 }
570 637
571 if (my $smooth = delete $o->{smoothface}) { 638 if (my $smooth = delete $o->{smoothface}) {
587 my ($dir, $file) = @_; 654 my ($dir, $file) = @_;
588 my $path = "$dir/$file"; 655 my $path = "$dir/$file";
589 656
590 my $trs; 657 my $trs;
591 if (0 > aio_load $path, $trs) { 658 if (0 > aio_load $path, $trs) {
592 warn "$path: $!, skipping.\n"; 659 warn "ERROR: $path: $!, skipping.\n";
593 return; 660 return;
594 } 661 }
595 662
596 $TRS .= $trs; 663 $TRS .= $trs;
597 } 664 }
602 unless (exists $FILECACHE{$_[0]}) { 669 unless (exists $FILECACHE{$_[0]}) {
603 my $data; 670 my $data;
604 if (0 < aio_load $_[0], $data) { 671 if (0 < aio_load $_[0], $data) {
605 if ($_[1]) { 672 if ($_[1]) {
606 $data = eval { $_[1]->($data) }; 673 $data = eval { $_[1]->($data) };
607 warn "$_[0]: $@" if $@; 674 warn "ERROR: $_[0]: $@" if $@;
608 } 675 }
609 } 676 }
610 677
611 $FILECACHE{$_[0]} = $data; 678 $FILECACHE{$_[0]} = $data;
612 } 679 }
626 my @plt; 693 my @plt;
627 my %map; 694 my %map;
628 695
629 for (split /\n/, $plt) { 696 for (split /\n/, $plt) {
630 next unless /\S/; 697 next unless /\S/;
698 next if /^\s*#/;
631 699
632 /^([0-9a-fA-F]{3,6})\s*(.*?)\s*$/ 700 /^([0-9a-fA-F]{3,6})\s*(.*?)\s*$/
633 or die "unparseable palette entry for $base.plt: $_"; 701 or die "unparseable palette entry for $base.plt: $_";
634 702
635 my ($rgb, $name) = ($1, $2); 703 my ($rgb, $name) = ($1, $2);
701 $meta = { 769 $meta = {
702 %{ $meta->{"" } || {} }, 770 %{ $meta->{"" } || {} },
703 %{ $meta->{$file} || {} }, 771 %{ $meta->{$file} || {} },
704 }; 772 };
705 773
706 if ($meta->{license} =~ s/^#//) { 774 if (exists $meta->{license} && $meta->{license} =~ s/^#//) { # exists == avoid autovivification
707 $meta->{license} = ({ 775 $meta->{license} = ({
708 "pd" => "Public Domain", 776 "pd" => "Public Domain",
709 "gpl" => "GNU General Public License, version 3.0 or any later", 777 "gpl" => "GNU General Public License, version 3.0 or any later",
710 "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/",
711 "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/",
712 "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/",
713 "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/",
714 })->{$meta->{license}} 782 })->{$meta->{license}}
715 || warn "$dir/$file: license tag '$meta->{license}' not found."; 783 || warn "ERROR: $dir/$file: license tag '$meta->{license}' not found.";
716 } 784 }
717 785
718 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/(.*)$%) {
719 ($meta->{author} = $1) =~ s/_/ /g; 787 ($meta->{author} = $1) =~ s/_/ /g;
720 } 788 }
722 $file =~ s/\.res$//; 790 $file =~ s/\.res$//;
723 $file =~ s/\.(ogg|wav|jpg|png)$//; 791 $file =~ s/\.(ogg|wav|jpg|png)$//;
724 792
725 if ($file =~ s/\.plt$//) { 793 if ($file =~ s/\.plt$//) {
726 $data = process_plt "$dir/$file", $data; 794 $data = process_plt "$dir/$file", $data;
727 } elsif (my $filter = $meta->{cfutil_filter}) { 795 } elsif (my $filter = delete $meta->{cfutil_filter}) {
728 if ($filter eq "yaml2json") { 796 if ($filter eq "yaml2json") {
729 $data = JSON::XS::encode_json YAML::XS::Load $data; 797 $data = JSON::XS::encode_json YAML::XS::Load $data;
730 } elsif ($filter eq "json2json") { 798 } elsif ($filter eq "json2json") {
731 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data); 799 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data);
732 } elsif ($filter eq "perl2json") { 800 } elsif ($filter eq "perl2json") {
733 $data = eval $data; die if $@; 801 $data = eval $data; die if $@;
734 $data = JSON::XS::encode_json $data; 802 $data = JSON::XS::encode_json $data;
735 } else { 803 } else {
736 warn "$dir/$file: unknown filter $filter, skipping\n"; 804 warn "ERROR: $dir/$file: unknown filter $filter, skipping\n";
737 } 805 }
738 } 806 }
739 807
740 substr $dir, 0, 1 + length $PATH, ""; 808 substr $dir, 0, 1 + length $PATH, "";
741 809
742 $RESOURCE{"$dir/$file"} = { 810 my %info = (
743 type => (exists $meta->{type} ? delete $meta->{type} : $type), 811 type => (exists $meta->{type} ? delete $meta->{type} : $type),
744 data => $data, 812 data => $data,
745 %$meta ? (meta => $meta) : (), 813 %$meta ? (meta => $meta) : (),
746 }; 814 );
815
816 $RESOURCE{"$dir/$file"} = \%info;
747 } 817 }
748 818
749 sub process_any { 819 sub process_any {
750 while (my ($func, @args) = @{ $c_any->get }) { 820 while (my ($func, @args) = @{ $c_any->get }) {
751 $func->(@args); 821 $func->(@args);
784 if ($file =~ /\.(jpg|png)$/) { 854 if ($file =~ /\.(jpg|png)$/) {
785 $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE 855 $c_any->put ([\&process_res, $path, $file, 0]) # FT_FACE
786 } elsif ($file =~ /\.(res)$/) { 856 } elsif ($file =~ /\.(res)$/) {
787 $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC 857 $c_any->put ([\&process_res, $path, $file, 6]) # FT_RSRC
788 } else { 858 } else {
789 $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
790 } 860 }
791 861
792 } elsif ($file =~ /\.png$/) { 862 } elsif ($file =~ /\.png$/) {
793 push @c_png, ["$path/$file", 0]; 863 $PNG{$file} = $path;
794 864
795 } elsif ($file =~ /\.faceinfo$/) { 865 } elsif ($file =~ /\.faceinfo$/) {
796 $c_any->put ([\&process_faceinfo, $path, $file]); 866 $c_any->put ([\&process_faceinfo, $path, $file]);
797 867
798 } elsif ($file =~ /\.trs$/) { 868 } elsif ($file =~ /\.trs$/) {
851 "Unless you run verbosely, all following warning\n", 921 "Unless you run verbosely, all following warning\n",
852 "or error messages indicate serious problems.\n", 922 "or error messages indicate serious problems.\n",
853 "\n"; 923 "\n";
854 924
855 if (!-d "$path/treasures") { 925 if (!-d "$path/treasures") {
856 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";
857 exit 1 unless $FORCE; 927 exit 1 unless $FORCE;
858 } 928 }
859 929
860 print "start file scan, arc, any processing...\n" if $VERBOSE; 930 print "starting file scan, arc, any processing...\n" if $VERBOSE;
861 931
862 my @a_arc = map +(async \&process_arc), 1..2; 932 my @a_arc = map +(async \&process_arc), 1..2;
863 my @a_any = map +(async \&process_any), 1..4; 933 my @a_any = map +(async \&process_any), 1..4;
864 934
865 find_files $path; 935 find_files $path;
866 936
867 $c_arc->shutdown; 937 $c_arc->shutdown;
868 $c_any->shutdown; 938 $c_any->shutdown;
869 939
870 $_->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
941 print "finished arc processing...\n" if $VERBOSE;
871 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 }
965
872 print "end arc, start png processing...\n" if $VERBOSE; 966 print "starting png processing...\n" if $VERBOSE;
873 967
874 # eight png crunchers work fine for my 4x smp machine 968 # eight png crunchers work fine for my 4x smp machine
875 my @a_png = map +(async \&process_png), 1..8; 969 my @a_png = map +(async \&process_png), 1..8;
876 970
877 print "end any processing...\n" if $VERBOSE;
878 $_->join for @a_any; 971 $_->join for @a_any;
879
880 print "end png processing...\n" if $VERBOSE; 972 print "finished any processing...\n" if $VERBOSE;
973
881 $_->join for @a_png; 974 $_->join for @a_png;
975 print "finished png processing...\n" if $VERBOSE;
882 976
883 print "scanning done, processing results...\n" if $VERBOSE; 977 print "scanning done, processing results...\n" if $VERBOSE;
884 { 978 {
885 # remove path prefix from editor_folder 979 # remove path prefix from editor_folder
886 $_->{editor_folder} =~ /^\x00/ 980 $_->{editor_folder} =~ /^\x00/
904 delete @s{qw(_name more name name_pl)}; 998 delete @s{qw(_name more name name_pl)};
905 %$o = ( %s, %$o ); 999 %$o = ( %s, %$o );
906 ++$progress; 1000 ++$progress;
907 } 1001 }
908 } else { 1002 } else {
909 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";
910 delete $ARC{$o->{_name}}; 1004 delete $ARC{$o->{_name}};
911 } 1005 }
912 } 1006 }
913 } 1007 }
914 1008
950 print $fh $TRS; 1044 print $fh $TRS;
951 } 1045 }
952 1046
953 { 1047 {
954 print "processing facedata...\n" if $VERBOSE; 1048 print "processing facedata...\n" if $VERBOSE;
955 while (my ($k, $v) = each %FACEINFO) { 1049
1050 for my $k (sort keys %FACEINFO) {
1051 my $v = $FACEINFO{$k};
1052
956 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";
957 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";
958 1055
959 make_hash $k, $v->{data32}, $v->{hash32}; 1056 make_hash $k, $v->{data32}, $v->{hash32};
960 make_hash $k, $v->{data64}, $v->{hash64}; 1057 make_hash $k, $v->{data64}, $v->{hash64};
961 1058
962 #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";
963 #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";
964 1061
965 $v->{glyph} // warn "WARNING: face '$k' has glyph."; 1062 $v->{glyph} // warn "ERROR: face '$k' has no glyph - missing faceinfo entry?\n";
966 $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";
967 $v->{magicmap} // warn "WARNING: face '$k' has foreground colour."; 1064 $v->{magicmap} // warn "ERROR: face '$k' has no foreground colour - missing faceinfo entry?\n";
968 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
969 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";
970 } 1102 }
1103
1104 system "$cmd png:\Q$TMPDIR/tc$id\E";
1105 optipng "$TMPDIR/tc$id";
1106 }
1107}
971 1108
972 print "processing resources...\n" if $VERBOSE; 1109 print "processing resources...\n" if $VERBOSE;
973 my $enc = JSON::XS->new->utf8->canonical->relaxed; 1110 my $enc = JSON::XS->new->utf8->canonical->relaxed;
974 while (my ($k, $v) = each %RESOURCE) { 1111 while (my ($k, $v) = each %RESOURCE) {
975
976 if ($v->{meta} && $v->{meta}{datadir}) { 1112 if ($v->{meta} && $v->{meta}{datadir}) {
977 delete $RESOURCE{$k}; 1113 delete $RESOURCE{$k};
978 1114
979 $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/";
980 1116
998 1134
999 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
1000 } 1136 }
1001 } 1137 }
1002 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
1003 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 1170 printf "writing faceinfo (%d faces, %d anims, %d resources)...\n",
1004 scalar keys %FACEINFO, 1171 scalar keys %FACEINFO,
1005 scalar keys %ANIMINFO, 1172 scalar keys %ANIMINFO,
1006 scalar keys %RESOURCE 1173 scalar keys %RESOURCE
1007 if $VERBOSE; 1174 if $VERBOSE;
1008 1175
1009 open my $fh, ">:perlio", "$DATADIR/facedata~" 1176 open my $fh, ">:perlio", "$DATADIR/faceinfo~"
1010 or die "$DATADIR/facedata~: $!"; 1177 or die "$DATADIR/faceinfo~: $!";
1011 1178
1012 print $fh nfreeze { 1179 print $fh nfreeze {
1013 version => 2, 1180 version => 2,
1014 faceinfo => \%FACEINFO, 1181 faceinfo => \%FACEINFO,
1015 animinfo => \%ANIMINFO, 1182 animinfo => \%ANIMINFO,
1017 }; 1184 };
1018 } 1185 }
1019 1186
1020 print "committing files...\n" if $VERBOSE; 1187 print "committing files...\n" if $VERBOSE;
1021 1188
1022 for (qw(archetypes facedata treasures), @COMMIT) { 1189 for (qw(archetypes faceinfo facedata treasures), @COMMIT) {
1023 chmod 0644, "$DATADIR/$_~"; 1190 chmod 0644, "$DATADIR/$_~";
1024 rename "$DATADIR/$_~", "$DATADIR/$_" 1191 rename "$DATADIR/$_~", "$DATADIR/$_"
1025 or die "$DATADIR/$_: $!"; 1192 or die "$DATADIR/$_: $!";
1026 } 1193 }
1027 1194

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines