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.5 by root, Thu Mar 8 15:19:08 2007 UTC vs.
Revision 1.6 by root, Sun Mar 11 02:12:45 2007 UTC

19use File::Temp; 19use File::Temp;
20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5;
24 25
25sub usage { 26sub usage {
26 warn <<EOF; 27 warn <<EOF;
27Usage: cfutil [-v] [-q] [--force] [--cache] 28Usage: cfutil [-v] [-q] [--force] [--cache]
28 [--install-arch path] 29 [--install-arch path]
77 78
78 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; 79 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded";
79} 80}
80 81
81{ 82{
82 our @PNG; 83 our %PNG32;
84 our %FACEINFO;
83 our @ARC; 85 our @ARC;
84 our $NFILE; 86 our $NFILE;
85 our @FACE;
86 our $ANIM; 87 our %ANIM;
87 88
88 our (@png, @trs, @arc); # files we are interested in 89 our (@png, @trs, @arc); # files we are interested in
89 90
90 sub commit_png { 91 sub commit_png {
91 my ($name, $data) = @_; 92 my ($name, $data) = @_;
92 93
93 push @PNG, [$name => $data]; 94 $PNG32{$name} = $data;
95 $FACEINFO{$name} ||= {};
94 } 96 }
95 97
96 sub process_png { 98 sub process_png {
97 while (@png) { 99 while (@png) {
98 my $path = pop @png; 100 my $path = pop @png;
104 if (0 > aio_load $path, $png) { 106 if (0 > aio_load $path, $png) {
105 warn "$path: $!, skipping.\n"; 107 warn "$path: $!, skipping.\n";
106 next; 108 next;
107 } 109 }
108 110
109 # quickly extratc width and height of the (necessarily PNG) image 111 # quickly extract width and height of the (necessarily PNG) image
110 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 112 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
111 warn "$path: not a recongized png file, skipping.\n"; 113 warn "$path: not a recongized png file, skipping.\n";
112 next; 114 next;
113 } 115 }
114 116
147 my @todo = grep { $_->[3] <= $mtime } @tile; 149 my @todo = grep { $_->[3] <= $mtime } @tile;
148 if (@todo) { 150 if (@todo) {
149 fork_sub { 151 fork_sub {
150 open my $convert, "|-", $CONVERT, 152 open my $convert, "|-", $CONVERT,
151 "png:-", 153 "png:-",
152 -negate,#d#
153 (map { 154 (map {
154 ( 155 (
155 "(", 156 "(",
156 "+clone", 157 "+clone",
157 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 158 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
199 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 200 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
200 201
201 my $arc = read_arch "$dir/$file"; 202 my $arc = read_arch "$dir/$file";
202 for my $o (values %$arc) { 203 for my $o (values %$arc) {
203 push @ARC, $o; 204 push @ARC, $o;
205
206 my $visibility = delete $o->{visibility};
207 my $magicmap = delete $o->{magicmap};
208
209 # find upper left corner :/
210 # omg, this is sooo broken
204 my ($dx, $dy); 211 my ($dx, $dy);
205 # omg, this is sooo broken
206 for (my $o = $o; $o; $o = $o->{more}) { 212 for (my $o = $o; $o; $o = $o->{more}) {
207 $dx = $o->{x} if $o->{x} < $dx; 213 $dx = $o->{x} if $o->{x} < $dx;
208 $dy = $o->{y} if $o->{y} < $dy; 214 $dy = $o->{y} if $o->{y} < $dy;
209 } 215 }
216
210 for (my $o = $o; $o; $o = $o->{more}) { 217 for (my $o = $o; $o; $o = $o->{more}) {
211 my $x = $o->{x} - $dx; 218 my $x = $o->{x} - $dx;
212 my $y = $o->{y} - $dy; 219 my $y = $o->{y} - $dy;
220
221 my $ext = $x|$y ? "+$x+$y" : "";
222
223 $o->{face} .= $ext;
224
225 my $visibility = delete $o->{visibility} if exists $o->{visibility};
226 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
227
228 my $anim = delete $o->{anim};
229
213 if ($x|$y) { 230 if ($anim) {
214 $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; 231 $o->{animation} = "$o->{_name}$ext";
232
233 for (@$anim) {
234 $_ .= $ext unless /^facings\s/;
235 }
236
237 $ANIM{"$o->{_name}$ext"} =
238 join "", map "$_\n",
239 "anim $o->{_name}$ext",
240 @$anim,
241 "mina";
215 } 242 }
243
244 for my $face ($o->{face} || (), @{$anim || []}) {
245 next if /^facings\s/;
246
247 my $info = $FACEINFO{$face} ||= {};
248
249 $info->{visibility} = $visibility if defined $visibility;
250 $info->{magicmap} = $magicmap if defined $magicmap;
216 } 251 }
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 } 252 }
224 } 253 }
225 } 254 }
226 } 255 }
227 256
276 ); 305 );
277 306
278 { 307 {
279 open my $fh, ">:utf8", "$DATADIR/animations~" 308 open my $fh, ">:utf8", "$DATADIR/animations~"
280 or die "$DATADIR/animations~: $!"; 309 or die "$DATADIR/animations~: $!";
281 print $fh $ANIM; 310 print $fh join "", map $ANIM{$_}, sort keys %ANIM
282 } 311 }
283 312
284 { 313 {
285 open my $fh, ">:utf8", "$DATADIR/archetypes~" 314 open my $fh, ">:utf8", "$DATADIR/archetypes~"
286 or die "$DATADIR/archetypes~: $!"; 315 or die "$DATADIR/archetypes~: $!";
287 print $fh Crossfire::archlist_to_string \@ARC; 316 print $fh Crossfire::archlist_to_string \@ARC;
288 } 317 }
289 318
290 @PNG = sort { $a->[0] cmp $b->[0] } @PNG;
291
292 { 319 {
320 while (my ($k, $v) = each %FACEINFO) {
321 $v->{data32} ||= delete $PNG32{$k};
322 }
323
324 while (my ($k, $v) = each %FACEINFO) {
325 exists $v->{data32} or warn "$k: face has no png32. this will crash the server.\n";
326
327 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
328 }
329
293 open my $fh, ">:perlio", "$DATADIR/crossfire.0~" 330 open my $fh, ">:perlio", "$DATADIR/faces~"
294 or die "$DATADIR/crossfire.0~: $!"; 331 or die "$DATADIR/faces~: $!";
295 printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1]
296 for 0.. $#PNG;
297 }
298 332
299 rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; 333 print $fh Storable::nfreeze \%FACEINFO;
300 rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; 334
301 rename "$DATADIR/animations~" , "$DATADIR/animations"; 335 #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO;
336 }
337
338 for (qw(archetypes faces animations)) {
339 chmod 0644, "$DATADIR/$_~";
340 rename "$DATADIR/$_~", "$DATADIR/$_";
341 }
302 342
303 die "--install-arch not fully implemented\n"; 343 die "--install-arch not fully implemented\n";
304 } 344 }
305} 345}
306 346

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines