ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/server/utils/cfutil.in
(Generate patch)

Comparing cf.schmorp.de/server/utils/cfutil.in (file contents):
Revision 1.53 by root, Sun Aug 19 09:27:08 2007 UTC vs.
Revision 1.62 by root, Mon Sep 10 18:30:30 2007 UTC

21use Crossfire; 21use Crossfire;
22use Coro; 22use Coro;
23use Coro::AIO; 23use Coro::AIO;
24use Coro::Util; 24use Coro::Util;
25use POSIX (); 25use POSIX ();
26use Digest::MD5;
27use Carp; 26use Carp;
28use Coro::Channel; 27use Coro::Channel;
29use Coro::Storable; $Storable::canonical = 1; 28use Coro::Storable; $Storable::canonical = 1;
30 29
31$SIG{QUIT} = sub { Carp::cluck "QUIT" }; 30$SIG{QUIT} = sub { Carp::cluck "QUIT" };
97 if (!-f "$path/regions") { 96 if (!-f "$path/regions") {
98 warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; 97 warn "'$path' does not look like a maps directory ('regions' file is missing).\n";
99 exit 1 unless $FORCE; 98 exit 1 unless $FORCE;
100 } 99 }
101 100
102 system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" 101 system $RSYNC, "-av", "--chmod=u=rwX,go=rX",
102 "$path/.", "$DATADIR/maps/.",
103 "--exclude", "CVS", "--exclude", "/world-precomposed",
104 "--delete", "--delete-excluded"
103 and die "map installation failed.\n"; 105 and die "map installation failed.\n";
104 106
105 print "maps installed successfully.\n"; 107 print "maps installed successfully.\n";
106} 108}
107 109
170 if ($w % $T || $h % $T) { 172 if ($w % $T || $h % $T) {
171 warn "$path: weird png size ($w $h), skipping.\n"; 173 warn "$path: weird png size ($w $h), skipping.\n";
172 next; 174 next;
173 } 175 }
174 176
177 (my $base = $stem) =~ s/^.*\///;
178
179 my $fi = $FACEINFO{$base};
180 unless ($fi) {
181 #warn "$path: <$base> not referenced by any archetype, skipping.\n";
182 #next;
183 }
184
185 my $arc = $fi->{arc} || { };
186
175 unless ($path =~ /~$/) { 187 unless ($path =~ /~$/) {
176 # possibly enlarge 188 # possibly enlarge
177 if (0 > aio_stat "$stem.64x64.png") { 189 if (0 > aio_stat "$stem.64x64.png") {
178 my $other = "$stem.64x64.png~"; 190 my $other = "$stem.64x64.png~";
179 191
180 if (0 > aio_lstat $other or (-M _) > (-M $path)) { 192 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
181 fork_sub { 193 fork_sub {
182 my $CROP; 194 my $CROP;
183 my $SRC = "png:\Q$path\E"; 195 my $SRC = "png:\Q$path\E";
184 196
185 # check if this is a wall. ultra-ugly. ultra-ultra-ugly. 197 my $is_floor = $arc->{is_floor};
198 my $is_wall = 0;
199
200 my ($wall_pfx, $wall_dir, $wall_sfx);
201
202 if (
203 !$is_floor
204 && !$arc->{alive}
205 && $arc->{move_block} eq "all"
186 if ($path =~ /^(.*\/wall\/.*_)([0-9A-F])(\.x11.*\.png)$/) { 206 && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/
207 ) {
187 my ($pfx, $dir, $sfx) = ($1, hex $2, $3); 208 ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3);
188 #check for 0..F images to be sure(?) this is a wall 209
189 unless (grep { !-e sprintf "%s%X%s", $pfx, $_, $sfx } 0..15) { 210 unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) {
211 $is_wall = 1;
212 }
213 }
214
215 if ($is_wall || $is_floor) {
190 # add a 4px border and add other images around it 216 # add a 4px border and add other images around it
191 $CROP = "-shave 8x8 +repage"; 217 $CROP = "-shave 8x8 +repage";
192 218
193 $w += 8; 219 $w += 8;
194 $h += 8; 220 $h += 8;
195 221
196 $SRC = "-size ${w}x${h} xc:transparent"; 222 $SRC = "-size ${w}x${h} xc:transparent";
197 $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; 223 $SRC .= " png:\Q$path\E -geometry +4+4 -composite";
198 224
199 # 8 surrounding images 225 # 8 surrounding images
200 for ( 226 for (
201 # x y b r0 r1 227 # x y b r0 r1
202 [-1, -1, 0, 6], 228 [-1, -1, 0, 6],
203 [ 0, -1, 1, 10, 14], 229 [ 0, -1, 1, 10, 14],
204 [+1, -1, 0, 12], 230 [+1, -1, 0, 12],
205 231
206 [-1, 0, 8, 5, 7], 232 [-1, 0, 8, 5, 7],
207 # 233 #
208 [+1, 0, 2, 5, 13], 234 [+1, 0, 2, 5, 13],
209 235
210 [-1, +1, 0, 3], 236 [-1, +1, 0, 3],
211 [ 0, +1, 4, 10, 11], 237 [ 0, +1, 4, 10, 11],
212 [+1, +1, 0, 9], 238 [+1, +1, 0, 9],
213 ) { 239 ) {
214 my ($x, $y, $d, $r0, $r1) = @$_; 240 my ($x, $y, $d, $r0, $r1) = @$_;
241
242 my $tile = $is_floor ? $path
243 : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx
244 : die;
245
215 $SRC .= sprintf " png:%s%X%s -geometry %+d%+d -composite", 246 $SRC .= sprintf " png:%s -geometry %+d%+d -composite",
216 "\Q$pfx", 247 "\Q$tile",
217 ($dir & $d) ? $r1 : $r0,
218 "\Q$sfx",
219 $x * ($w - 8) + 4, 248 $x * ($w - 8) + 4,
220 $y * ($h - 8) + 4; 249 $y * ($h - 8) + 4;
221 }
222 } 250 }
223 } 251 }
224 252
225 system "convert -depth 8 $SRC rgba:-" 253 system "convert -depth 8 $SRC rgba:-"
226 . "| $exec_prefix/bin/cfhq2xa $w $h 0" 254 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
399 facings => $facings, 427 facings => $facings,
400 frames => \@frames, 428 frames => \@frames,
401 }; 429 };
402 } 430 }
403 431
404 for my $face ($o->{face} || (), @{$anim || []}) { 432 for ($o->{face} || (), @{$anim || []}) {
405 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; 433 next if /^facings\s/;
406 434
435 my $face = $_;
436 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates
437
407 my $info = $FACEINFO{$face} ||= {}; 438 my $info = $FACEINFO{$face} ||= { };
408
409 $info->{arc} = $o; 439 $info->{arc} = $o;
440
441 next if $face =~ /^blank.x11$|^empty.x11$/;
442
410 $info->{visibility} = $visibility if defined $visibility; 443 $info->{visibility} = $visibility if defined $visibility;
411 $info->{magicmap} = $magicmap if defined $magicmap; 444 $info->{magicmap} = $magicmap if defined $magicmap;
412 } 445 }
413 446
414 if (my $smooth = delete $o->{smoothface}) { 447 if (my $smooth = delete $o->{smoothface}) {
415 my %kv =split /\s+/, $smooth; 448 my %kv = split /\s+/, $smooth;
416 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 449 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
417 while (my ($face, $smooth) = each %kv) { 450 while (my ($face, $smooth) = each %kv) {
451 $FACEINFO{$smooth}{arc} = $o;
452
418 $FACEINFO{$face}{smooth} = $smooth; 453 $FACEINFO{$face}{smooth} = $smooth;
419 $FACEINFO{$face}{smoothlevel} = $level; 454 $FACEINFO{$face}{smoothlevel} = $level;
420 } 455 }
421 } 456 }
422 } 457 }
462 my ($dir, $file, $type) = @$job; 497 my ($dir, $file, $type) = @$job;
463 498
464 my $data; 499 my $data;
465 aio_load "$dir/$file", $data; 500 aio_load "$dir/$file", $data;
466 501
502
467 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; 503 my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) };
468 504
469 next if $meta && !exists $meta->{$file}; 505 utf8::decode $dir;
506 utf8::decode $file;
507
508 # a meta file for resources is now mandatory
509 unless (exists $meta->{$file}) {
510 warn "skipping $dir/$file\n" if $VERBOSE >= 3;
511 next;
512 }
470 513
471 $meta = { 514 $meta = {
472 %{ $meta->{"" } || {} }, 515 %{ $meta->{"" } || {} },
473 %{ $meta->{$file} || {} }, 516 %{ $meta->{$file} || {} },
474 }; 517 };
490 substr $dir, 0, 1 + length $PATH, ""; 533 substr $dir, 0, 1 + length $PATH, "";
491 534
492 $RESOURCE{"$dir/$file"} = { 535 $RESOURCE{"$dir/$file"} = {
493 type => (delete $meta->{type}) || $type, 536 type => (delete $meta->{type}) || $type,
494 data => $data, 537 data => $data,
495 chksum => (Digest::MD5::md5 $data),
496 %$meta ? (meta => $meta) : (), 538 %$meta ? (meta => $meta) : (),
497 }; 539 };
498 } 540 }
499 } 541 }
500 542
650 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; 692 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
651 693
652 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 694 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
653 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; 695 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
654 696
655 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
656 $v->{chksum64} = Digest::MD5::md5 $v->{data64};
657
658 if (my $magicmap = $v->{magicmap}) { 697 if (my $magicmap = $v->{magicmap}) {
659 $magicmap =~ y/A-Z_\-/a-z/d; 698 $magicmap =~ y/A-Z_\-/a-z/d;
660 $v->{magicmap} = $COLOR{$magicmap}; 699 $v->{magicmap} = $COLOR{$magicmap};
661 } 700 }
662 701

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines