--- deliantra/server/utils/cfutil.in 2007/04/18 09:38:58 1.29 +++ deliantra/server/utils/cfutil.in 2007/07/12 08:40:14 1.38 @@ -8,9 +8,10 @@ my $DATADIR = "@datadir@/@PACKAGE@"; my $CONVERT = "@CONVERT@"; -my $IDENTIFY = "@IDENTIFY@"; +#my $IDENTIFY = "@IDENTIFY@"; my $OPTIPNG = "@OPTIPNG@"; my $RSYNC = "@RSYNC@"; +my $PNGNQ = "@PNGNQ@"; use Getopt::Long; use Coro::Event; @@ -44,6 +45,22 @@ my $TMPDIR = "/tmp/cfutil$$~"; my $TMPFILE = "aaaa0"; +our %COLOR = ( + black => 0, + white => 1, + navy => 2, + red => 3, + orange => 4, + blue => 5, + darkorange => 6, + green => 7, + lightgreen => 8, + grey => 9, + brown => 10, + gold => 11, + tan => 12, +); + END { system "rm", "-rf", $TMPDIR } Event->signal (signal => "INT", cb => sub { exit 1 }); @@ -86,13 +103,16 @@ { our %ANIMINFO; our %FACEINFO; + our %RESOURCE; + our @ARC; our %ARC; our $TRS; our $NFILE; + our $PATH; our $QUANTIZE = "+dither -colorspace RGB -colors 256"; - our (@png, @trs, @arc); # files we are interested in + our (@png, @trs, @arc, @res); # files we are interested in sub commit_png($$$) { my ($name, $data, $T) = @_; @@ -155,7 +175,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 +191,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 +295,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; @@ -280,8 +321,8 @@ $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; - my $visibility = delete $o->{visibility} if exists $o->{visibility}; - my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; + $visibility = delete $o->{visibility} if exists $o->{visibility}; + $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; my $anim = delete $o->{anim}; @@ -346,6 +387,33 @@ } } + sub process_res { + while (@res) { + my ($dir, $file) = @{pop @res}; + + my $data; + aio_load "$dir/$file", $data; + + my $copyright; + aio_load "$dir/copyright", $copyright; + + $file =~ s/\.res$//; + $file =~ /\.([^.]+)$/ + or next; + + my $type = $1; + + substr $dir, 0, 1 + length $PATH, ""; + + $RESOURCE{"$dir/$file"} = { + type => $1, + copyright => $copyright, + data => $data, + chksum => Digest::MD5::md5 $data, + }; + } + } + sub find_files; sub find_files { my ($path) = @_; @@ -364,8 +432,10 @@ push @trs, [$path, $file]; } elsif ($file =~ /\.arc$/) { push @arc, [$path, $file]; + } elsif ($file =~ /\.(ogg|res)$/) { + push @res, [$path, $file]; } else { - warn "ignoring $path/$file\n" if $VERBOSE >= 2; + warn "ignoring $path/$file\n" if $VERBOSE >= 3; } } }; @@ -374,6 +444,8 @@ sub inst_arch($) { my (undef, $path) = @_; + $PATH = $path; + print "\n", "Installing '$path' to '$DATADIR'\n", "\n", @@ -397,6 +469,7 @@ (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_trs), (async \&process_trs), (async \&process_arc), (async \&process_arc), + (async \&process_res), (async \&process_res), ); { @@ -416,7 +489,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 { @@ -434,9 +509,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]; } { @@ -455,6 +533,11 @@ $v->{chksum32} = Digest::MD5::md5 $v->{data32}; $v->{chksum64} = Digest::MD5::md5 $v->{data64}; + + if (my $magicmap = $v->{magicmap}) { + $magicmap =~ y/A-Z_\-/a-z/d; + $v->{magicmap} = $COLOR{$magicmap}; + } } open my $fh, ">:perlio", "$DATADIR/facedata~" @@ -464,6 +547,7 @@ version => 2, faceinfo => \%FACEINFO, animinfo => \%ANIMINFO, + resource => \%RESOURCE, }; }