… | |
… | |
6 | my $exec_prefix = "@exec_prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
7 | my $datarootdir = "@datarootdir@"; |
7 | my $datarootdir = "@datarootdir@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
8 | my $DATADIR = "@datadir@/@PACKAGE@"; |
9 | |
9 | |
10 | my $CONVERT = "@CONVERT@"; |
10 | my $CONVERT = "@CONVERT@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
11 | #my $IDENTIFY = "@IDENTIFY@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
|
|
14 | my $PNGNQ = "@PNGNQ@"; |
14 | |
15 | |
15 | use Getopt::Long; |
16 | use Getopt::Long; |
16 | use Coro::Event; |
17 | use Coro::Event; |
17 | use AnyEvent; |
18 | use AnyEvent; |
18 | use IO::AIO (); |
19 | use IO::AIO (); |
… | |
… | |
42 | my $CACHE = 0; |
43 | my $CACHE = 0; |
43 | my $FORCE; |
44 | my $FORCE; |
44 | my $TMPDIR = "/tmp/cfutil$$~"; |
45 | my $TMPDIR = "/tmp/cfutil$$~"; |
45 | my $TMPFILE = "aaaa0"; |
46 | my $TMPFILE = "aaaa0"; |
46 | |
47 | |
|
|
48 | our %COLOR = ( |
|
|
49 | black => 0, |
|
|
50 | white => 1, |
|
|
51 | navy => 2, |
|
|
52 | red => 3, |
|
|
53 | orange => 4, |
|
|
54 | blue => 5, |
|
|
55 | darkorange => 6, |
|
|
56 | green => 7, |
|
|
57 | lightgreen => 8, |
|
|
58 | grey => 9, |
|
|
59 | brown => 10, |
|
|
60 | gold => 11, |
|
|
61 | tan => 12, |
|
|
62 | ); |
|
|
63 | |
47 | END { system "rm", "-rf", $TMPDIR } |
64 | END { system "rm", "-rf", $TMPDIR } |
48 | |
65 | |
49 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
66 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
50 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
67 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
51 | |
68 | |
… | |
… | |
75 | if (!-f "$path/regions") { |
92 | if (!-f "$path/regions") { |
76 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
93 | warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; |
77 | exit 1 unless $FORCE; |
94 | exit 1 unless $FORCE; |
78 | } |
95 | } |
79 | |
96 | |
80 | system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
97 | system $RSYNC, "-av", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" |
81 | and die "map installation failed.\n"; |
98 | and die "map installation failed.\n"; |
82 | |
99 | |
83 | print "maps installed successfully.\n"; |
100 | print "maps installed successfully.\n"; |
84 | } |
101 | } |
85 | |
102 | |
86 | { |
103 | { |
87 | our %ANIMINFO; |
104 | our %ANIMINFO; |
88 | our %FACEINFO; |
105 | our %FACEINFO; |
|
|
106 | our %RESOURCE; |
89 | our @ARC; |
107 | our @ARC; |
90 | our %ARC; |
108 | our %ARC; |
91 | our $TRS; |
109 | our $TRS; |
92 | our $NFILE; |
110 | our $NFILE; |
|
|
111 | our $PATH; |
93 | |
112 | |
94 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
113 | our $QUANTIZE = "+dither -colorspace RGB -colors 256"; |
95 | |
114 | |
96 | our (@png, @trs, @arc); # files we are interested in |
115 | our (@png, @trs, @arc, @res); # files we are interested in |
97 | |
116 | |
98 | sub commit_png($$$) { |
117 | sub commit_png($$$) { |
99 | my ($name, $data, $T) = @_; |
118 | my ($name, $data, $T) = @_; |
100 | |
119 | |
101 | $FACEINFO{$name}{"data$T"} = $data; |
120 | $FACEINFO{$name}{"data$T"} = $data; |
… | |
… | |
154 | fork_sub { |
173 | fork_sub { |
155 | system "convert png:\Q$path\E -depth 8 rgba:-" |
174 | system "convert png:\Q$path\E -depth 8 rgba:-" |
156 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
175 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
157 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
176 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
158 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
177 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
159 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
178 | system $OPTIPNG, "-i0", "-q", "$other~"; |
160 | die "$other~ has zero size, aborting." unless -s "$other~"; |
179 | die "$other~ has zero size, aborting." unless -s "$other~"; |
161 | rename "$other~", $other; |
180 | rename "$other~", $other; |
162 | }; |
181 | }; |
163 | } |
182 | } |
164 | |
183 | |
… | |
… | |
170 | my $other = "$stem.32x32.png~"; |
189 | my $other = "$stem.32x32.png~"; |
171 | |
190 | |
172 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
191 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
173 | fork_sub { |
192 | fork_sub { |
174 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
193 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
175 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
194 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
195 | |
|
|
196 | # reduce smoothfaces >10000 bytes |
|
|
197 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
|
|
198 | my $ncolor = 256; |
|
|
199 | while () { |
|
|
200 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
|
|
201 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
|
|
202 | last if 10000 > -s "$other~~"; |
|
|
203 | $ncolor = int $ncolor * 0.9; |
|
|
204 | $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; |
|
|
205 | } |
|
|
206 | |
|
|
207 | printf "reduced %s from %d to %d bytes using %d colours.\n", |
|
|
208 | $other, -s "$other~", -s "$other~~", $ncolor |
|
|
209 | if $VERBOSE >= 2; |
|
|
210 | rename "$other~~", "$other~"; |
|
|
211 | } |
|
|
212 | |
176 | die "$other~ has zero size, aborting." unless -s "$other~"; |
213 | die "$other~ has zero size, aborting." unless -s "$other~"; |
177 | rename "$other~", $other; |
214 | rename "$other~", $other; |
178 | }; |
215 | }; |
179 | } |
216 | } |
180 | |
217 | |
… | |
… | |
282 | |
319 | |
283 | my $ext = $x|$y ? "+$x+$y" : ""; |
320 | my $ext = $x|$y ? "+$x+$y" : ""; |
284 | |
321 | |
285 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
322 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
286 | |
323 | |
287 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
324 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
288 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
325 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
289 | |
326 | |
290 | my $anim = delete $o->{anim}; |
327 | my $anim = delete $o->{anim}; |
291 | |
328 | |
292 | if ($anim) { |
329 | if ($anim) { |
293 | # possibly add $ext to the animation name to avoid |
330 | # possibly add $ext to the animation name to avoid |
… | |
… | |
348 | |
385 | |
349 | $TRS .= $trs; |
386 | $TRS .= $trs; |
350 | } |
387 | } |
351 | } |
388 | } |
352 | |
389 | |
|
|
390 | sub process_res { |
|
|
391 | while (@res) { |
|
|
392 | my ($dir, $file) = @{pop @res}; |
|
|
393 | |
|
|
394 | my $data; |
|
|
395 | aio_load "$dir/$file", $data; |
|
|
396 | |
|
|
397 | my $copyright; |
|
|
398 | aio_load "$dir/copyright", $copyright; |
|
|
399 | |
|
|
400 | $file =~ s/\.res$//; |
|
|
401 | $file =~ /\.([^.]+)$/ |
|
|
402 | or next; |
|
|
403 | |
|
|
404 | my $type = $1; |
|
|
405 | |
|
|
406 | substr $dir, 0, 1 + length $PATH, ""; |
|
|
407 | |
|
|
408 | $RESOURCE{"$dir/$file"} = { |
|
|
409 | type => $1, |
|
|
410 | copyright => $copyright, |
|
|
411 | data => $data, |
|
|
412 | chksum => Digest::MD5::md5 $data, |
|
|
413 | }; |
|
|
414 | } |
|
|
415 | } |
|
|
416 | |
353 | sub find_files; |
417 | sub find_files; |
354 | sub find_files { |
418 | sub find_files { |
355 | my ($path) = @_; |
419 | my ($path) = @_; |
356 | |
420 | |
357 | IO::AIO::aioreq_pri 4; |
421 | IO::AIO::aioreq_pri 4; |
… | |
… | |
366 | push @png, ["$path/$file", 0]; |
430 | push @png, ["$path/$file", 0]; |
367 | } elsif ($file =~ /\.trs$/) { |
431 | } elsif ($file =~ /\.trs$/) { |
368 | push @trs, [$path, $file]; |
432 | push @trs, [$path, $file]; |
369 | } elsif ($file =~ /\.arc$/) { |
433 | } elsif ($file =~ /\.arc$/) { |
370 | push @arc, [$path, $file]; |
434 | push @arc, [$path, $file]; |
|
|
435 | } elsif ($file =~ /\.(ogg|jpg|res)$/) { |
|
|
436 | push @res, [$path, $file]; |
371 | } else { |
437 | } else { |
372 | warn "ignoring $path/$file\n" if $VERBOSE >= 2; |
438 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
373 | } |
439 | } |
374 | } |
440 | } |
375 | }; |
441 | }; |
376 | } |
442 | } |
377 | |
443 | |
378 | sub inst_arch($) { |
444 | sub inst_arch($) { |
379 | my (undef, $path) = @_; |
445 | my (undef, $path) = @_; |
|
|
446 | |
|
|
447 | $PATH = $path; |
380 | |
448 | |
381 | print "\n", |
449 | print "\n", |
382 | "Installing '$path' to '$DATADIR'\n", |
450 | "Installing '$path' to '$DATADIR'\n", |
383 | "\n", |
451 | "\n", |
384 | "This can take a long time if you run this\n", |
452 | "This can take a long time if you run this\n", |
… | |
… | |
399 | $_->join for ( |
467 | $_->join for ( |
400 | # four png crunchers work fine for my 2x smp machine |
468 | # four png crunchers work fine for my 2x smp machine |
401 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
469 | (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), |
402 | (async \&process_trs), (async \&process_trs), |
470 | (async \&process_trs), (async \&process_trs), |
403 | (async \&process_arc), (async \&process_arc), |
471 | (async \&process_arc), (async \&process_arc), |
|
|
472 | (async \&process_res), (async \&process_res), |
404 | ); |
473 | ); |
405 | |
474 | |
406 | { |
475 | { |
407 | # remove path prefix from editor_folder |
476 | # remove path prefix from editor_folder |
408 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
477 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
… | |
… | |
438 | |
507 | |
439 | last; |
508 | last; |
440 | } |
509 | } |
441 | } |
510 | } |
442 | |
511 | |
|
|
512 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
|
|
513 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
|
|
514 | |
443 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
515 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
444 | or die "$DATADIR/archetypes~: $!"; |
516 | or die "$DATADIR/archetypes~: $!"; |
445 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
517 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
446 | } |
518 | } |
447 | |
519 | |
… | |
… | |
459 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
531 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
460 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
532 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
461 | |
533 | |
462 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
534 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
463 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
535 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
|
|
536 | |
|
|
537 | if (my $magicmap = $v->{magicmap}) { |
|
|
538 | $magicmap =~ y/A-Z_\-/a-z/d; |
|
|
539 | $v->{magicmap} = $COLOR{$magicmap}; |
|
|
540 | } |
464 | } |
541 | } |
465 | |
542 | |
466 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
543 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
467 | or die "$DATADIR/facedata~: $!"; |
544 | or die "$DATADIR/facedata~: $!"; |
468 | |
545 | |
469 | print $fh freeze { |
546 | print $fh freeze { |
470 | version => 2, |
547 | version => 2, |
471 | faceinfo => \%FACEINFO, |
548 | faceinfo => \%FACEINFO, |
472 | animinfo => \%ANIMINFO, |
549 | animinfo => \%ANIMINFO, |
|
|
550 | resource => \%RESOURCE, |
473 | }; |
551 | }; |
474 | } |
552 | } |
475 | |
553 | |
476 | for (qw(archetypes facedata treasures)) { |
554 | for (qw(archetypes facedata treasures)) { |
477 | chmod 0644, "$DATADIR/$_~"; |
555 | chmod 0644, "$DATADIR/$_~"; |