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.4 by root, Wed Mar 7 20:30:18 2007 UTC vs.
Revision 1.5 by root, Thu Mar 8 15:19:08 2007 UTC

80 80
81{ 81{
82 our @PNG; 82 our @PNG;
83 our @ARC; 83 our @ARC;
84 our $NFILE; 84 our $NFILE;
85 our @FACE;
86 our $ANIM;
85 87
86 our (@png, @trs, @arc); # files we are interested in 88 our (@png, @trs, @arc); # files we are interested in
87 89
88 sub commit_png { 90 sub commit_png {
89 my ($name, $data) = @_; 91 my ($name, $data) = @_;
90 #warn "$name: commited\n"; 92
93 push @PNG, [$name => $data];
91 } 94 }
92 95
93 sub process_png { 96 sub process_png {
94 while (@png) { 97 while (@png) {
95 my $path = pop @png; 98 my $path = pop @png;
98 aio_lstat $path; 101 aio_lstat $path;
99 my ($size, $mtime) = (stat _)[7,9]; 102 my ($size, $mtime) = (stat _)[7,9];
100 103
101 if (0 > aio_load $path, $png) { 104 if (0 > aio_load $path, $png) {
102 warn "$path: $!, skipping.\n"; 105 warn "$path: $!, skipping.\n";
103 return; 106 next;
104 } 107 }
105 108
106 # quickly extratc width and height of the (necessarily PNG) image 109 # quickly extratc width and height of the (necessarily PNG) image
107 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 110 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
108 warn "$path: not a recongized png file, skipping.\n"; 111 warn "$path: not a recongized png file, skipping.\n";
109 return; 112 next;
110 } 113 }
111 114
112 my ($w, $h) = unpack "NN", $1; 115 my ($w, $h) = unpack "NN", $1;
113 116
114 (my $face = $path) =~ s/^.*\///; 117 (my $face = $path) =~ s/^.*\///;
115 my $T = 32; 118 my $T = 32;
116 119
117 unless ($face =~ s/\.base\.(...)\.png$/.$1/) { 120 unless ($face =~ s/\.base\.(...)\.png$/.$1/) {
118 warn "$path: weird filename, skipping.\n"; 121 warn "$path: weird filename, skipping.\n";
119 return; 122 next;
120 } 123 }
121 124
122 if ($w < $T || $h < $T) { 125 if ($w < $T || $h < $T) {
123 warn "$path: too small ($w $h), skipping.\n"; 126 warn "$path: too small ($w $h), skipping.\n";
124 return; 127 next;
125 } 128 }
126 129
127 if ($w % $T || $h % $T) { 130 if ($w % $T || $h % $T) {
128 warn "$path: weird png size ($w $h), skipping.\n"; 131 warn "$path: weird png size ($w $h), skipping.\n";
129 return; 132 next;
130 } 133 }
131 134
132 if (($w > $T || $h > $T) && $face !~ /_S\./) { 135 if (($w > $T || $h > $T) && $face !~ /_S\./) {
133 # split 136 # split
134 my @tile; 137 my @tile;
144 my @todo = grep { $_->[3] <= $mtime } @tile; 147 my @todo = grep { $_->[3] <= $mtime } @tile;
145 if (@todo) { 148 if (@todo) {
146 fork_sub { 149 fork_sub {
147 open my $convert, "|-", $CONVERT, 150 open my $convert, "|-", $CONVERT,
148 "png:-", 151 "png:-",
152 -negate,#d#
149 (map { 153 (map {
150 ( 154 (
151 "(", 155 "(",
152 "+clone", 156 "+clone",
153 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 157 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
208 my $y = $o->{y} - $dy; 212 my $y = $o->{y} - $dy;
209 if ($x|$y) { 213 if ($x|$y) {
210 $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; 214 $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []};
211 } 215 }
212 } 216 }
217 if (my $anim = delete $o->{anim}) {
218 $o->{animation} = $o->{_name};
219 $ANIM .= join "", map "$_\n",
220 "anim $o->{_name}",
221 @$anim,
222 "mina";
223 }
213 } 224 }
214 } 225 }
215 } 226 }
216 227
217 sub process_trs { 228 sub process_trs {
262 (async \&process_png), (async \&process_png), 273 (async \&process_png), (async \&process_png),
263 (async \&process_trs), (async \&process_trs), 274 (async \&process_trs), (async \&process_trs),
264 (async \&process_arc), (async \&process_arc), 275 (async \&process_arc), (async \&process_arc),
265 ); 276 );
266 277
278 {
279 open my $fh, ">:utf8", "$DATADIR/animations~"
280 or die "$DATADIR/animations~: $!";
281 print $fh $ANIM;
282 }
283
284 {
267 open my $archetypes, ">:utf8", "$DATADIR/archetypes~" 285 open my $fh, ">:utf8", "$DATADIR/archetypes~"
268 or die "$DATADIR/archetypes~: $!"; 286 or die "$DATADIR/archetypes~: $!";
269 print $archetypes Crossfire::archlist_to_string \@ARC; 287 print $fh Crossfire::archlist_to_string \@ARC;
270 close $archetypes; 288 }
289
290 @PNG = sort { $a->[0] cmp $b->[0] } @PNG;
291
292 {
293 open my $fh, ">:perlio", "$DATADIR/crossfire.0~"
294 or die "$DATADIR/crossfire.0~: $!";
295 printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1]
296 for 0.. $#PNG;
297 }
298
271 rename "$DATADIR/archetypes~", "$DATADIR/archetypes"; 299 rename "$DATADIR/archetypes~" , "$DATADIR/archetypes";
300 rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0";
301 rename "$DATADIR/animations~" , "$DATADIR/animations";
272 302
273 die "--install-arch not fully implemented\n"; 303 die "--install-arch not fully implemented\n";
274 } 304 }
275} 305}
276 306

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines