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.53 by root, Sun Aug 19 09:27:08 2007 UTC vs.
Revision 1.61 by root, Thu Aug 30 07:13:17 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" };
170 if ($w % $T || $h % $T) { 169 if ($w % $T || $h % $T) {
171 warn "$path: weird png size ($w $h), skipping.\n"; 170 warn "$path: weird png size ($w $h), skipping.\n";
172 next; 171 next;
173 } 172 }
174 173
174 (my $base = $stem) =~ s/^.*\///;
175
176 my $fi = $FACEINFO{$base};
177 unless ($fi) {
178 #warn "$path: <$base> not referenced by any archetype, skipping.\n";
179 #next;
180 }
181
182 my $arc = $fi->{arc} || { };
183
175 unless ($path =~ /~$/) { 184 unless ($path =~ /~$/) {
176 # possibly enlarge 185 # possibly enlarge
177 if (0 > aio_stat "$stem.64x64.png") { 186 if (0 > aio_stat "$stem.64x64.png") {
178 my $other = "$stem.64x64.png~"; 187 my $other = "$stem.64x64.png~";
179 188
180 if (0 > aio_lstat $other or (-M _) > (-M $path)) { 189 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
181 fork_sub { 190 fork_sub {
182 my $CROP; 191 my $CROP;
183 my $SRC = "png:\Q$path\E"; 192 my $SRC = "png:\Q$path\E";
184 193
185 # check if this is a wall. ultra-ugly. ultra-ultra-ugly. 194 my $is_floor = $arc->{is_floor};
195 my $is_wall = 0;
196
197 my ($wall_pfx, $wall_dir, $wall_sfx);
198
199 if (
200 !$is_floor
201 && !$arc->{alive}
202 && $arc->{move_block} eq "all"
186 if ($path =~ /^(.*\/wall\/.*_)([0-9A-F])(\.x11.*\.png)$/) { 203 && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/
204 ) {
187 my ($pfx, $dir, $sfx) = ($1, hex $2, $3); 205 ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3);
188 #check for 0..F images to be sure(?) this is a wall 206
189 unless (grep { !-e sprintf "%s%X%s", $pfx, $_, $sfx } 0..15) { 207 unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) {
208 $is_wall = 1;
209 }
210 }
211
212 if ($is_wall || $is_floor) {
190 # add a 4px border and add other images around it 213 # add a 4px border and add other images around it
191 $CROP = "-shave 8x8 +repage"; 214 $CROP = "-shave 8x8 +repage";
192 215
193 $w += 8; 216 $w += 8;
194 $h += 8; 217 $h += 8;
195 218
196 $SRC = "-size ${w}x${h} xc:transparent"; 219 $SRC = "-size ${w}x${h} xc:transparent";
197 $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; 220 $SRC .= " png:\Q$path\E -geometry +4+4 -composite";
198 221
199 # 8 surrounding images 222 # 8 surrounding images
200 for ( 223 for (
201 # x y b r0 r1 224 # x y b r0 r1
202 [-1, -1, 0, 6], 225 [-1, -1, 0, 6],
203 [ 0, -1, 1, 10, 14], 226 [ 0, -1, 1, 10, 14],
204 [+1, -1, 0, 12], 227 [+1, -1, 0, 12],
205 228
206 [-1, 0, 8, 5, 7], 229 [-1, 0, 8, 5, 7],
207 # 230 #
208 [+1, 0, 2, 5, 13], 231 [+1, 0, 2, 5, 13],
209 232
210 [-1, +1, 0, 3], 233 [-1, +1, 0, 3],
211 [ 0, +1, 4, 10, 11], 234 [ 0, +1, 4, 10, 11],
212 [+1, +1, 0, 9], 235 [+1, +1, 0, 9],
213 ) { 236 ) {
214 my ($x, $y, $d, $r0, $r1) = @$_; 237 my ($x, $y, $d, $r0, $r1) = @$_;
238
239 my $tile = $is_floor ? $path
240 : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx
241 : die;
242
215 $SRC .= sprintf " png:%s%X%s -geometry %+d%+d -composite", 243 $SRC .= sprintf " png:%s -geometry %+d%+d -composite",
216 "\Q$pfx", 244 "\Q$tile",
217 ($dir & $d) ? $r1 : $r0,
218 "\Q$sfx",
219 $x * ($w - 8) + 4, 245 $x * ($w - 8) + 4,
220 $y * ($h - 8) + 4; 246 $y * ($h - 8) + 4;
221 }
222 } 247 }
223 } 248 }
224 249
225 system "convert -depth 8 $SRC rgba:-" 250 system "convert -depth 8 $SRC rgba:-"
226 . "| $exec_prefix/bin/cfhq2xa $w $h 0" 251 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
399 facings => $facings, 424 facings => $facings,
400 frames => \@frames, 425 frames => \@frames,
401 }; 426 };
402 } 427 }
403 428
404 for my $face ($o->{face} || (), @{$anim || []}) { 429 for ($o->{face} || (), @{$anim || []}) {
405 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; 430 next if /^facings\s/;
406 431
432 my $face = $_;
433 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates
434
407 my $info = $FACEINFO{$face} ||= {}; 435 my $info = $FACEINFO{$face} ||= { };
408
409 $info->{arc} = $o; 436 $info->{arc} = $o;
437
438 next if $face =~ /^blank.x11$|^empty.x11$/;
439
410 $info->{visibility} = $visibility if defined $visibility; 440 $info->{visibility} = $visibility if defined $visibility;
411 $info->{magicmap} = $magicmap if defined $magicmap; 441 $info->{magicmap} = $magicmap if defined $magicmap;
412 } 442 }
413 443
414 if (my $smooth = delete $o->{smoothface}) { 444 if (my $smooth = delete $o->{smoothface}) {
415 my %kv =split /\s+/, $smooth; 445 my %kv = split /\s+/, $smooth;
416 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 446 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
417 while (my ($face, $smooth) = each %kv) { 447 while (my ($face, $smooth) = each %kv) {
448 $FACEINFO{$smooth}{arc} = $o;
449
418 $FACEINFO{$face}{smooth} = $smooth; 450 $FACEINFO{$face}{smooth} = $smooth;
419 $FACEINFO{$face}{smoothlevel} = $level; 451 $FACEINFO{$face}{smoothlevel} = $level;
420 } 452 }
421 } 453 }
422 } 454 }
462 my ($dir, $file, $type) = @$job; 494 my ($dir, $file, $type) = @$job;
463 495
464 my $data; 496 my $data;
465 aio_load "$dir/$file", $data; 497 aio_load "$dir/$file", $data;
466 498
499
467 my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; 500 my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) };
468 501
469 next if $meta && !exists $meta->{$file}; 502 utf8::decode $dir;
503 utf8::decode $file;
504
505 # a meta file for resources is now mandatory
506 unless (exists $meta->{$file}) {
507 warn "skipping $dir/$file\n" if $VERBOSE >= 3;
508 next;
509 }
470 510
471 $meta = { 511 $meta = {
472 %{ $meta->{"" } || {} }, 512 %{ $meta->{"" } || {} },
473 %{ $meta->{$file} || {} }, 513 %{ $meta->{$file} || {} },
474 }; 514 };
490 substr $dir, 0, 1 + length $PATH, ""; 530 substr $dir, 0, 1 + length $PATH, "";
491 531
492 $RESOURCE{"$dir/$file"} = { 532 $RESOURCE{"$dir/$file"} = {
493 type => (delete $meta->{type}) || $type, 533 type => (delete $meta->{type}) || $type,
494 data => $data, 534 data => $data,
495 chksum => (Digest::MD5::md5 $data),
496 %$meta ? (meta => $meta) : (), 535 %$meta ? (meta => $meta) : (),
497 }; 536 };
498 } 537 }
499 } 538 }
500 539
650 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; 689 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
651 690
652 length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 691 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"; 692 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
654 693
655 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
656 $v->{chksum64} = Digest::MD5::md5 $v->{data64};
657
658 if (my $magicmap = $v->{magicmap}) { 694 if (my $magicmap = $v->{magicmap}) {
659 $magicmap =~ y/A-Z_\-/a-z/d; 695 $magicmap =~ y/A-Z_\-/a-z/d;
660 $v->{magicmap} = $COLOR{$magicmap}; 696 $v->{magicmap} = $COLOR{$magicmap};
661 } 697 }
662 698

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines