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.79 by root, Sun Nov 15 18:04:00 2009 UTC vs.
Revision 1.89 by root, Tue Oct 5 23:26:56 2010 UTC

20# <http://www.gnu.org/licenses/>. 20# <http://www.gnu.org/licenses/>.
21# 21#
22# The authors can be reached via e-mail to <support@deliantra.net> 22# The authors can be reached via e-mail to <support@deliantra.net>
23# 23#
24 24
25use strict; 25use common::sense;
26 26
27my $prefix = "@prefix@"; 27my $prefix = "@prefix@";
28my $exec_prefix = "@exec_prefix@"; 28my $exec_prefix = "@exec_prefix@";
29my $datarootdir = "@datarootdir@"; 29my $datarootdir = "@datarootdir@";
30my $DATADIR = "@datadir@/@PACKAGE@"; 30my $DATADIR = "@datadir@/@PACKAGE@";
74my $VERBOSE = 1; 74my $VERBOSE = 1;
75my $CACHE = 0; 75my $CACHE = 0;
76my $FORCE; 76my $FORCE;
77my $TMPDIR = "/tmp/cfutil$$~"; 77my $TMPDIR = "/tmp/cfutil$$~";
78my $TMPFILE = "aaaa0"; 78my $TMPFILE = "aaaa0";
79my @COMMIT;
79 80
80our %COLOR = ( 81our %COLOR = (
81 black => 0, 82 black => 0,
82 white => 1, 83 white => 1,
83 navy => 2, 84 navy => 2,
155 and die "map installation failed.\n"; 156 and die "map installation failed.\n";
156 157
157 print "maps installed successfully.\n"; 158 print "maps installed successfully.\n";
158} 159}
159 160
161sub autoglyph {
162 my ($stem, $face) = @_;
163
164 if ($stem =~ /^wall\/|Nimwall/) {
165# warn $stem;
166 "+"
167 } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) {
168 "."
169 } elsif ($stem =~ /^player\//) {
170 "\@"
171 } else {
172 substr $stem, 0, 1
173 }
174}
175
160{ 176{
161 our %ANIMINFO; 177 our %ANIMINFO;
162 our %FACEINFO; 178 our %FACEINFO;
163 our %RESOURCE; 179 our %RESOURCE;
164 our @ARC; 180 our @ARC;
173 our $c_trs = new Coro::Channel; 189 our $c_trs = new Coro::Channel;
174 our $c_res = new Coro::Channel; 190 our $c_res = new Coro::Channel;
175 191
176 our @c_png; 192 our @c_png;
177 193
178 sub commit_png($$$) { 194 sub commit_png($$$$) {
179 my ($name, $data, $T) = @_; 195 my ($stem, $name, $data, $T) = @_;
180 196
197 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH;
181 $FACEINFO{$name}{"data$T"} = $data; 198 $FACEINFO{$name}{"data$T"} = $data;
182 } 199 }
183 200
184 sub process_png { 201 sub process_png {
185 while (@c_png) { 202 while (@c_png) {
403 420
404 if (0 > aio_load $file, $tile) { 421 if (0 > aio_load $file, $tile) {
405 die "$path: unable to read tile +$x+$y, aborting.\n"; 422 die "$path: unable to read tile +$x+$y, aborting.\n";
406 } 423 }
407 IO::AIO::aio_unlink $file unless $CACHE; 424 IO::AIO::aio_unlink $file unless $CACHE;
408 commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; 425 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T;
409 } 426 }
410 } else { 427 } else {
411 # use as-is (either small, use smooth) 428 # use as-is (either small, use smooth)
412 commit_png $face, $png, $T; 429 commit_png $stem, $face, $png, $T;
413 } 430 }
414 431
415 aio_unlink $path if $delete; 432 aio_unlink $path if $delete;
416 } 433 }
417 } 434 }
432 449
433 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge 450 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge
434 451
435 my $visibility = delete $o->{visibility}; 452 my $visibility = delete $o->{visibility};
436 my $magicmap = delete $o->{magicmap}; 453 my $magicmap = delete $o->{magicmap};
454 my $glyph = delete $o->{glyph};
437 455
438 # find upper left corner :/ 456 # find upper left corner :/
439 # omg, this is sooo broken 457 # omg, this is sooo broken
440 my ($dx, $dy); 458 my ($dx, $dy);
441 for (my $o = $o; $o; $o = $o->{more}) { 459 for (my $o = $o; $o; $o = $o->{more}) {
451 469
452 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; 470 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
453 471
454 $visibility = delete $o->{visibility} if exists $o->{visibility}; 472 $visibility = delete $o->{visibility} if exists $o->{visibility};
455 $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 473 $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
474 $glyph = delete $o->{glyph} if exists $o->{glyph};
456 475
457 my $anim = delete $o->{anim}; 476 my $anim = delete $o->{anim};
458 477
459 if ($anim) { 478 if ($anim) {
460 # possibly add $ext to the animation name to avoid 479 # possibly add $ext to the animation name to avoid
491 510
492 next if $face =~ /^blank.x11$|^empty.x11$/; 511 next if $face =~ /^blank.x11$|^empty.x11$/;
493 512
494 $info->{visibility} = $visibility if defined $visibility; 513 $info->{visibility} = $visibility if defined $visibility;
495 $info->{magicmap} = $magicmap if defined $magicmap; 514 $info->{magicmap} = $magicmap if defined $magicmap;
515 $info->{glyph} = $glyph if defined $glyph;
496 } 516 }
497 517
498 if (my $smooth = delete $o->{smoothface}) { 518 if (my $smooth = delete $o->{smoothface}) {
499 my %kv = split /\s+/, $smooth; 519 my %kv = split /\s+/, $smooth;
500 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 520 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
569 if ($meta->{license} =~ s/^#//) { 589 if ($meta->{license} =~ s/^#//) {
570 $meta->{license} = ({ 590 $meta->{license} = ({
571 "pd" => "Public Domain", 591 "pd" => "Public Domain",
572 "gpl" => "GNU General Public License, version 3.0 or any later", 592 "gpl" => "GNU General Public License, version 3.0 or any later",
573 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", 593 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
594 "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/",
574 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", 595 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/",
575 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", 596 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
576 })->{$meta->{license}} 597 })->{$meta->{license}}
577 || warn "$dir/$file: license tag '$meta->{license}' not found."; 598 || warn "$dir/$file: license tag '$meta->{license}' not found.";
599 }
600
601 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
602 ($meta->{author} = $1) =~ s/_/ /g;
578 } 603 }
579 604
580 $file =~ s/\.res$//; 605 $file =~ s/\.res$//;
581 $file =~ s/\.(ogg|wav|jpg|png)$//; 606 $file =~ s/\.(ogg|wav|jpg|png)$//;
582 607
610 IO::AIO::aioreq_pri 4; 635 IO::AIO::aioreq_pri 4;
611 IO::AIO::aio_scandir $path, 4, sub { 636 IO::AIO::aio_scandir $path, 4, sub {
612 my ($dirs, $nondirs) = @_; 637 my ($dirs, $nondirs) = @_;
613 638
614 find_files "$path/$_" 639 find_files "$path/$_"
615 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; 640 for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs;
616 641
617 my $dir = $path; 642 my $dir = $path;
618 substr $dir, 0, 1 + length $PATH, ""; 643 substr $dir, 0, 1 + length $PATH, "";
619 644
620 for my $file (@$nondirs) { 645 for my $file (@$nondirs) {
733 while () { 758 while () {
734 my $progress; 759 my $progress;
735 my $loop; 760 my $loop;
736 761
737 for my $o (values %ARC) { 762 for my $o (values %ARC) {
738 if (my $other = $o->{inherit}) { 763 for my $other (split /,/, $o->{inherit}) {
739 if (my $s = $ARC{$other}) { 764 if (my $s = $ARC{$other}) {
740 if ($s->{inherit}) { 765 if ($s->{inherit}) {
741 $loop = $s; 766 $loop = $s;
742 } else { 767 } else {
743 delete $o->{inherit}; 768 delete $o->{inherit};
790 make_hash $k, $v->{data64}, $v->{hash64}; 815 make_hash $k, $v->{data64}, $v->{hash64};
791 816
792 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 817 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
793 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; 818 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
794 819
820 my $stem = delete $v->{stem};
821 $v->{glyph} //= autoglyph $stem, $v;
822
795 if (my $magicmap = $v->{magicmap}) { 823 if (my $magicmap = $v->{magicmap}) {
796 $magicmap =~ y/A-Z_\-/a-z/d; 824 $magicmap =~ y/A-Z_\-/a-z/d;
797 $v->{magicmap} = $COLOR{$magicmap}; 825 $v->{magicmap} = $COLOR{$magicmap};
798 } 826 }
799 827
802 830
803 print "processing resources...\n" if $VERBOSE; 831 print "processing resources...\n" if $VERBOSE;
804 my $enc = JSON::XS->new->utf8->canonical->relaxed; 832 my $enc = JSON::XS->new->utf8->canonical->relaxed;
805 while (my ($k, $v) = each %RESOURCE) { 833 while (my ($k, $v) = each %RESOURCE) {
806 834
835 if ($v->{meta} && $v->{meta}{datadir}) {
836 delete $RESOURCE{$k};
837
838 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
839
840 printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE;
841 open my $fh, ">:raw", "$DATADIR/$k~"
842 or die "$DATADIR/$k~: $!";
843 syswrite $fh, $v->{data};
844 push @COMMIT, $k;
845
846 } else {
807 if ($v->{type} & 1) { 847 if ($v->{type} & 1) {
808 # prepend meta info 848 # prepend meta info
809 849
810 my $meta = $enc->encode ({ 850 my $meta = $enc->encode ({
811 name => $k, 851 name => $k,
812 %{ $v->{meta} || {} }, 852 %{ $v->{meta} || {} },
813 }); 853 });
814 854
815 $v->{data} = pack "(w/a*)*", $meta, $v->{data}; 855 $v->{data} = pack "(w/a*)*", $meta, $v->{data};
816 } 856 }
817 857
818 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 858 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
859 }
819 } 860 }
820 861
821 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 862 printf "writing facedata (%d faces, %d anims, %d resources)...\n",
822 scalar keys %FACEINFO, 863 scalar keys %FACEINFO,
823 scalar keys %ANIMINFO, 864 scalar keys %ANIMINFO,
825 if $VERBOSE; 866 if $VERBOSE;
826 867
827 open my $fh, ">:perlio", "$DATADIR/facedata~" 868 open my $fh, ">:perlio", "$DATADIR/facedata~"
828 or die "$DATADIR/facedata~: $!"; 869 or die "$DATADIR/facedata~: $!";
829 870
830 print $fh freeze { 871 print $fh nfreeze {
831 version => 2, 872 version => 2,
832 faceinfo => \%FACEINFO, 873 faceinfo => \%FACEINFO,
833 animinfo => \%ANIMINFO, 874 animinfo => \%ANIMINFO,
834 resource => \%RESOURCE, 875 resource => \%RESOURCE,
835 }; 876 };
836 877
837 } 878 }
838 879
839 print "committing files...\n" if $VERBOSE; 880 print "committing files...\n" if $VERBOSE;
840 881
841 for (qw(archetypes facedata treasures)) { 882 for (qw(archetypes facedata treasures), @COMMIT) {
842 chmod 0644, "$DATADIR/$_~"; 883 chmod 0644, "$DATADIR/$_~";
843 rename "$DATADIR/$_~", "$DATADIR/$_" 884 rename "$DATADIR/$_~", "$DATADIR/$_"
844 or die "$DATADIR/$_: $!"; 885 or die "$DATADIR/$_: $!";
845 } 886 }
846 887

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines