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.21 by root, Thu Apr 5 12:34:31 2007 UTC vs.
Revision 1.29 by root, Wed Apr 18 09:38:58 2007 UTC

20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5; 24use Digest::MD5;
25use Storable; $Storable::canonical = 1; 25use Coro::Storable; $Storable::canonical = 1;
26 26
27sub usage { 27sub usage {
28 warn <<EOF; 28 warn <<EOF;
29Usage: cfutil [-v] [-q] [--force] [--cache] 29Usage: cfutil [-v] [-q] [--force] [--cache]
30 [--install-arch path] 30 [--install-arch path]
68} 68}
69 69
70sub inst_maps($) { 70sub inst_maps($) {
71 my (undef, $path) = @_; 71 my (undef, $path) = @_;
72 72
73 print "installing '$path' to '$DATADIR/maps'\n"; 73 print "\nInstalling '$path' to '$DATADIR/maps'\n\n";
74 74
75 if (!-f "$path/regions") { 75 if (!-f "$path/regions") {
76 warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; 76 warn "'$path' does not look like a maps directory ('regions' file is missing).\n";
77 exit 1 unless $FORCE; 77 exit 1 unless $FORCE;
78 } 78 }
82 82
83 print "maps installed successfully.\n"; 83 print "maps installed successfully.\n";
84} 84}
85 85
86{ 86{
87 our %ANIMINFO;
87 our %FACEINFO; 88 our %FACEINFO;
88 our @ARC; 89 our %ARC;
89 our $TRS; 90 our $TRS;
90 our $NFILE; 91 our $NFILE;
91 our %ANIM;
92 92
93 our $QUANTIZE = "+dither -colorspace RGB -colors 256"; 93 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
94 94
95 our (@png, @trs, @arc); # files we are interested in 95 our (@png, @trs, @arc); # files we are interested in
96 96
147 # possibly enlarge 147 # possibly enlarge
148 if (0 > aio_stat "$stem.64x64.png") { 148 if (0 > aio_stat "$stem.64x64.png") {
149 my $other = "$stem.64x64.png~"; 149 my $other = "$stem.64x64.png~";
150 150
151 if (0 > aio_lstat $other or (-M _) > (-M $path)) { 151 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
152 warn "rescale $other\n";#d#
153 my $wrap = 0; # for the time being 152 my $wrap = 0; # for the time being
154 fork_sub { 153 fork_sub {
155 system "convert png:\Q$path\E -depth 8 rgba:-" 154 system "convert png:\Q$path\E -depth 8 rgba:-"
156 . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" 155 . "| $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~" 156 . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~"
183 } 182 }
184 } 183 }
185 184
186 (my $face = $stem) =~ s/^.*\///; 185 (my $face = $stem) =~ s/^.*\///;
187 186
187 # split all bigfaces, but avoid smoothfaces (*_S)
188 if (($w > $T || $h > $T) && $face !~ /_S\./) { 188 if (($w > $T || $h > $T) && $face !~ /_S\./) {
189 # split 189 # split
190 my @tile; 190 my @tile;
191 for my $x (0 .. (int $w / $T) - 1) { 191 for my $x (0 .. (int $w / $T) - 1) {
192 for my $y (0 .. (int $h / $T) - 1) { 192 for my $y (0 .. (int $h / $T) - 1) {
255 my $arc; 255 my $arc;
256 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 256 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
257 257
258 my $arc = read_arch "$dir/$file"; 258 my $arc = read_arch "$dir/$file";
259 for my $o (values %$arc) { 259 for my $o (values %$arc) {
260 push @ARC, $o; 260 $ARC{$o->{_name}} = $o;
261 261
262 $o->{editor_folder} = $dir; 262 $o->{editor_folder} = $dir;
263 263
264 my $visibility = delete $o->{visibility}; 264 my $visibility = delete $o->{visibility};
265 my $magicmap = delete $o->{magicmap}; 265 my $magicmap = delete $o->{magicmap};
276 my $x = $o->{x} - $dx; 276 my $x = $o->{x} - $dx;
277 my $y = $o->{y} - $dy; 277 my $y = $o->{y} - $dy;
278 278
279 my $ext = $x|$y ? "+$x+$y" : ""; 279 my $ext = $x|$y ? "+$x+$y" : "";
280 280
281 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; 281 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
282 282
283 my $visibility = delete $o->{visibility} if exists $o->{visibility}; 283 my $visibility = delete $o->{visibility} if exists $o->{visibility};
284 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 284 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
285 285
286 my $anim = delete $o->{anim}; 286 my $anim = delete $o->{anim};
287 287
288 if ($anim) { 288 if ($anim) {
289 # possibly add $ext to the animation name to avoid
290 # the need to specify archnames for all parts
291 # of a multipart archetype.
289 $o->{animation} = "$o->{_name}"; 292 $o->{animation} = "$o->{_name}";
293 my $facings = 1;
294 my @frames;
290 295
291 for (@$anim) { 296 for (@$anim) {
292 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; 297 if (/^facings\s+(\d+)/) {
298 $facings = $1*1;
299 } elsif (/^blank.x11$|^empty.x11$/) {
300 push @frames, $_;
301 } else {
302 push @frames, "$_$ext";
303 }
293 } 304 }
294 305
295 $ANIM{"$o->{_name}$ext"} = 306 $ANIMINFO{$o->{animation}} = {
296 join "", map "$_\n", 307 facings => $facings,
297 "anim $o->{_name}", 308 frames => \@frames,
298 @$anim, 309 };
299 "mina";
300 } 310 }
301 311
302 for my $face ($o->{face} || (), @{$anim || []}) { 312 for my $face ($o->{face} || (), @{$anim || []}) {
303 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; 313 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
304 314
307 $info->{visibility} = $visibility if defined $visibility; 317 $info->{visibility} = $visibility if defined $visibility;
308 $info->{magicmap} = $magicmap if defined $magicmap; 318 $info->{magicmap} = $magicmap if defined $magicmap;
309 } 319 }
310 320
311 if (my $smooth = delete $o->{smoothface}) { 321 if (my $smooth = delete $o->{smoothface}) {
312 my ($face, $smooth) = split /\s+/, $smooth; 322 my %kv =split /\s+/, $smooth;
313 # skip empty_S.x11, it seems to server no purpose whatsoever 323 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
314 # but increases bandwidth demands and worse. 324 while (my ($face, $smooth) = each %kv) {
315 unless ($smooth eq "empty_S.x11") {
316 $FACEINFO{$face}{smooth} = $smooth; 325 $FACEINFO{$face}{smooth} = $smooth;
326 $FACEINFO{$face}{smoothlevel} = $level;
317 } 327 }
318 } 328 }
319 } 329 }
320 } 330 }
321 } 331 }
362 } 372 }
363 373
364 sub inst_arch($) { 374 sub inst_arch($) {
365 my (undef, $path) = @_; 375 my (undef, $path) = @_;
366 376
377 print "\n",
367 print "installing '$path' to '$DATADIR'\n", 378 "Installing '$path' to '$DATADIR'\n",
379 "\n",
368 "(this can take a long time if you run this\n", 380 "This can take a long time if you run this\n",
369 "for the first time or do not use --cache).\n"; 381 "for the first time or do not use --cache.\n",
382 "\n",
383 "Unless you run verbosely, all following warning\n",
384 "or error messages indicate serious problems.\n",
385 "\n";
370 386
371 if (!-d "$path/treasures") { 387 if (!-d "$path/treasures") {
372 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 388 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n";
373 exit 1 unless $FORCE; 389 exit 1 unless $FORCE;
374 } 390 }
382 (async \&process_trs), (async \&process_trs), 398 (async \&process_trs), (async \&process_trs),
383 (async \&process_arc), (async \&process_arc), 399 (async \&process_arc), (async \&process_arc),
384 ); 400 );
385 401
386 { 402 {
387 open my $fh, ">:utf8", "$DATADIR/animations~" 403 # remove path prefix from editor_folder
388 or die "$DATADIR/animations~: $!"; 404 substr $_->{editor_folder}, 0, 1 + length $path, ""
389 print $fh join "", map $ANIM{$_}, sort keys %ANIM 405 for values %ARC;
406
407 # resolve inherit
408 while () {
409 my $progress;
410 my $loop;
411
412 for my $o (values %ARC) {
413 if (my $other = $o->{inherit}) {
414 if (my $s = $ARC{$other}) {
415 if ($s->{inherit}) {
416 $loop = $s;
417 } else {
418 delete $o->{inherit};
419 %$o = ( %$s, %$o );
420 ++$progress;
421 }
422 } else {
423 warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n";
424 delete $ARC{$o->{_name}};
425 }
426 }
427 }
428
429 unless ($progress) {
430 die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n"
431 if $loop;
432
433 last;
434 }
390 } 435 }
391 436
392 {
393 open my $fh, ">:utf8", "$DATADIR/archetypes~" 437 open my $fh, ">:utf8", "$DATADIR/archetypes~"
394 or die "$DATADIR/archetypes~: $!"; 438 or die "$DATADIR/archetypes~: $!";
395 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; 439 print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } values %ARC];
396 print $fh Crossfire::archlist_to_string \@ARC;
397 } 440 }
398 441
399 { 442 {
400 open my $fh, ">:utf8", "$DATADIR/treasures~" 443 open my $fh, ">:utf8", "$DATADIR/treasures~"
401 or die "$DATADIR/treasures~: $!"; 444 or die "$DATADIR/treasures~: $!";
415 } 458 }
416 459
417 open my $fh, ">:perlio", "$DATADIR/facedata~" 460 open my $fh, ">:perlio", "$DATADIR/facedata~"
418 or die "$DATADIR/facedata~: $!"; 461 or die "$DATADIR/facedata~: $!";
419 462
420 $FACEINFO{""} = { version => 1}; 463 print $fh freeze {
421 print $fh Storable::nfreeze \%FACEINFO; 464 version => 2,
465 faceinfo => \%FACEINFO,
466 animinfo => \%ANIMINFO,
422 } 467 };
468 }
423 469
424 for (qw(archetypes facedata animations treasures)) { 470 for (qw(archetypes facedata treasures)) {
425 chmod 0644, "$DATADIR/$_~"; 471 chmod 0644, "$DATADIR/$_~";
426 rename "$DATADIR/$_~", "$DATADIR/$_" 472 rename "$DATADIR/$_~", "$DATADIR/$_"
427 or die "$DATADIR/$_: $!"; 473 or die "$DATADIR/$_: $!";
428 } 474 }
429 475

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines