--- deliantra/server/utils/cfutil.in 2007/04/18 07:59:03 1.27 +++ deliantra/server/utils/cfutil.in 2007/05/07 06:01:48 1.34 @@ -11,6 +11,7 @@ my $IDENTIFY = "@IDENTIFY@"; my $OPTIPNG = "@OPTIPNG@"; my $RSYNC = "@RSYNC@"; +my $PNGNQ = "@PNGNQ@"; use Getopt::Long; use Coro::Event; @@ -70,7 +71,7 @@ sub inst_maps($) { my (undef, $path) = @_; - print "installing '$path' to '$DATADIR/maps'\n"; + print "\nInstalling '$path' to '$DATADIR/maps'\n\n"; if (!-f "$path/regions") { warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; @@ -86,6 +87,7 @@ { our %ANIMINFO; our %FACEINFO; + our @ARC; our %ARC; our $TRS; our $NFILE; @@ -155,7 +157,7 @@ . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" and die "convert/hq2xa pipeline error: status $? ($!)"; - system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; + system $OPTIPNG, "-i0", "-q", "$other~"; die "$other~ has zero size, aborting." unless -s "$other~"; rename "$other~", $other; }; @@ -171,7 +173,25 @@ if (0 > aio_lstat $other or (-M _) > (-M $path)) { fork_sub { system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; - system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; + system $OPTIPNG, "-i0", "-q", "$other~"; + + # reduce smoothfaces >10000 bytes + if ($stem =~ /_S\./ && (-s "$other~") > 10000) { + my $ncolor = 256; + while () { + system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; + system $OPTIPNG, "-i0", "-q", "$other~~"; + last if 10000 > -s "$other~~"; + $ncolor = int $ncolor * 0.9; + $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; + } + + printf "reduced %s from %d to %d bytes using %d colours.\n", + $other, -s "$other~", -s "$other~~", $ncolor + if $VERBOSE >= 2; + rename "$other~~", "$other~"; + } + die "$other~ has zero size, aborting." unless -s "$other~"; rename "$other~", $other; }; @@ -257,7 +277,10 @@ my $arc = read_arch "$dir/$file"; for my $o (values %$arc) { - $ARC{$o->{_name}} = $o; + push @ARC, $o; + for (my $m = $o; $m; $m = $m->{more}) { + $ARC{$m->{_name}} = $m; + } $o->{editor_folder} = $dir; @@ -365,7 +388,7 @@ } elsif ($file =~ /\.arc$/) { push @arc, [$path, $file]; } else { - warn "ignoring $path/$file\n" if $VERBOSE >= 2; + warn "ignoring $path/$file\n" if $VERBOSE >= 3; } } }; @@ -374,7 +397,9 @@ sub inst_arch($) { my (undef, $path) = @_; - print "Installing '$path' to '$DATADIR'\n", + print "\n", + "Installing '$path' to '$DATADIR'\n", + "\n", "This can take a long time if you run this\n", "for the first time or do not use --cache.\n", "\n", @@ -414,7 +439,9 @@ $loop = $s; } else { delete $o->{inherit}; - %$o = ( %$s, %$o ); + my %s = %$s; + delete @s{qw(_name more name name_pl)}; + %$o = ( %s, %$o ); ++$progress; } } else { @@ -432,9 +459,12 @@ } } + # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit + @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; + open my $fh, ">:utf8", "$DATADIR/archetypes~" or die "$DATADIR/archetypes~: $!"; - print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } values %ARC]; + print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; } {