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.80 by root, Fri Mar 19 14:36:39 2010 UTC vs.
Revision 1.94 by root, Wed Oct 6 00:18:14 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,
105 my ($id, $dataref, $hashref, $clen) = @_; 106 my ($id, $dataref, $hashref, $clen) = @_;
106 107
107 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; 108 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4;
108 109
109 if (exists $hash{$hash}) { 110 if (exists $hash{$hash}) {
110 # hahs collinion, but some files are simply identical 111 # hash collision, but some files are simply identical
111 if (${$hash{$hash}[1]} ne $$dataref) { 112 if (${$hash{$hash}[1]} ne $$dataref) {
112 warn "hash collision $hash{$hash}[0] vs. $id\n"; 113 warn "hash collision $hash{$hash}[0] vs. $id\n";
113 exit 1; 114 exit 1;
114 } else { 115 } else {
115 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; 116 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3;
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
161our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋);
162
163sub autoglyph {
164 my ($stem, $face) = @_;
165
166 if ($stem =~ /^wall\/|Nimwall/) {
167 return $WALL_SUFFIX[hex $1]
168 if $stem =~ $stem =~ /(_[0-9A-F]).x11/;
169
170 "+"
171
172 } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) {
173 "."
174
175 } elsif ($stem =~ /^player\//) {
176 "\@"
177
178 } else {
179 substr $stem, 0, 1
180 }
181}
182
160{ 183{
161 our %ANIMINFO; 184 our %ANIMINFO;
162 our %FACEINFO; 185 our %FACEINFO;
163 our %RESOURCE; 186 our %RESOURCE;
164 our @ARC; 187 our @ARC;
173 our $c_trs = new Coro::Channel; 196 our $c_trs = new Coro::Channel;
174 our $c_res = new Coro::Channel; 197 our $c_res = new Coro::Channel;
175 198
176 our @c_png; 199 our @c_png;
177 200
178 sub commit_png($$$) { 201 sub commit_png($$$$) {
179 my ($name, $data, $T) = @_; 202 my ($stem, $name, $data, $T) = @_;
180 203
204 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH;
181 $FACEINFO{$name}{"data$T"} = $data; 205 $FACEINFO{$name}{"data$T"} = $data;
182 } 206 }
183 207
184 sub process_png { 208 sub process_png {
185 while (@c_png) { 209 while (@c_png) {
403 427
404 if (0 > aio_load $file, $tile) { 428 if (0 > aio_load $file, $tile) {
405 die "$path: unable to read tile +$x+$y, aborting.\n"; 429 die "$path: unable to read tile +$x+$y, aborting.\n";
406 } 430 }
407 IO::AIO::aio_unlink $file unless $CACHE; 431 IO::AIO::aio_unlink $file unless $CACHE;
408 commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; 432 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T;
409 } 433 }
410 } else { 434 } else {
411 # use as-is (either small, use smooth) 435 # use as-is (either small, use smooth)
412 commit_png $face, $png, $T; 436 commit_png $stem, $face, $png, $T;
413 } 437 }
414 438
415 aio_unlink $path if $delete; 439 aio_unlink $path if $delete;
416 } 440 }
417 } 441 }
432 456
433 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge 457 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge
434 458
435 my $visibility = delete $o->{visibility}; 459 my $visibility = delete $o->{visibility};
436 my $magicmap = delete $o->{magicmap}; 460 my $magicmap = delete $o->{magicmap};
461 my $glyph = delete $o->{glyph};
437 462
438 # find upper left corner :/ 463 # find upper left corner :/
439 # omg, this is sooo broken 464 # omg, this is sooo broken
440 my ($dx, $dy); 465 my ($dx, $dy);
441 for (my $o = $o; $o; $o = $o->{more}) { 466 for (my $o = $o; $o; $o = $o->{more}) {
451 476
452 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; 477 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
453 478
454 $visibility = delete $o->{visibility} if exists $o->{visibility}; 479 $visibility = delete $o->{visibility} if exists $o->{visibility};
455 $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 480 $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
481 $glyph = delete $o->{glyph} if exists $o->{glyph};
456 482
457 my $anim = delete $o->{anim}; 483 my $anim = delete $o->{anim};
458 484
459 if ($anim) { 485 if ($anim) {
460 # possibly add $ext to the animation name to avoid 486 # possibly add $ext to the animation name to avoid
491 517
492 next if $face =~ /^blank.x11$|^empty.x11$/; 518 next if $face =~ /^blank.x11$|^empty.x11$/;
493 519
494 $info->{visibility} = $visibility if defined $visibility; 520 $info->{visibility} = $visibility if defined $visibility;
495 $info->{magicmap} = $magicmap if defined $magicmap; 521 $info->{magicmap} = $magicmap if defined $magicmap;
522 $info->{glyph} = $glyph if defined $glyph;
496 } 523 }
497 524
498 if (my $smooth = delete $o->{smoothface}) { 525 if (my $smooth = delete $o->{smoothface}) {
499 my %kv = split /\s+/, $smooth; 526 my %kv = split /\s+/, $smooth;
500 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 527 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
569 if ($meta->{license} =~ s/^#//) { 596 if ($meta->{license} =~ s/^#//) {
570 $meta->{license} = ({ 597 $meta->{license} = ({
571 "pd" => "Public Domain", 598 "pd" => "Public Domain",
572 "gpl" => "GNU General Public License, version 3.0 or any later", 599 "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/", 600 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
601 "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/", 602 "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/", 603 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
576 })->{$meta->{license}} 604 })->{$meta->{license}}
577 || warn "$dir/$file: license tag '$meta->{license}' not found."; 605 || warn "$dir/$file: license tag '$meta->{license}' not found.";
606 }
607
608 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
609 ($meta->{author} = $1) =~ s/_/ /g;
578 } 610 }
579 611
580 $file =~ s/\.res$//; 612 $file =~ s/\.res$//;
581 $file =~ s/\.(ogg|wav|jpg|png)$//; 613 $file =~ s/\.(ogg|wav|jpg|png)$//;
582 614
733 while () { 765 while () {
734 my $progress; 766 my $progress;
735 my $loop; 767 my $loop;
736 768
737 for my $o (values %ARC) { 769 for my $o (values %ARC) {
738 if (my $other = $o->{inherit}) { 770 for my $other (split /,/, $o->{inherit}) {
739 if (my $s = $ARC{$other}) { 771 if (my $s = $ARC{$other}) {
740 if ($s->{inherit}) { 772 if ($s->{inherit}) {
741 $loop = $s; 773 $loop = $s;
742 } else { 774 } else {
743 delete $o->{inherit}; 775 delete $o->{inherit};
795 if (my $magicmap = $v->{magicmap}) { 827 if (my $magicmap = $v->{magicmap}) {
796 $magicmap =~ y/A-Z_\-/a-z/d; 828 $magicmap =~ y/A-Z_\-/a-z/d;
797 $v->{magicmap} = $COLOR{$magicmap}; 829 $v->{magicmap} = $COLOR{$magicmap};
798 } 830 }
799 831
832 my $stem = delete $v->{stem};
833 $v->{glyph} //= autoglyph $stem, $v;
834 utf8::encode $v->{glyph};
835 $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph};
836
800 delete $v->{arc}; 837 delete $v->{arc};
801 } 838 }
802 839
803 print "processing resources...\n" if $VERBOSE; 840 print "processing resources...\n" if $VERBOSE;
804 my $enc = JSON::XS->new->utf8->canonical->relaxed; 841 my $enc = JSON::XS->new->utf8->canonical->relaxed;
805 while (my ($k, $v) = each %RESOURCE) { 842 while (my ($k, $v) = each %RESOURCE) {
806 843
844 if ($v->{meta} && $v->{meta}{datadir}) {
845 delete $RESOURCE{$k};
846
847 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
848
849 printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE;
850 open my $fh, ">:raw", "$DATADIR/$k~"
851 or die "$DATADIR/$k~: $!";
852 syswrite $fh, $v->{data};
853 push @COMMIT, $k;
854
855 } else {
807 if ($v->{type} & 1) { 856 if ($v->{type} & 1) {
808 # prepend meta info 857 # prepend meta info
809 858
810 my $meta = $enc->encode ({ 859 my $meta = $enc->encode ({
811 name => $k, 860 name => $k,
812 %{ $v->{meta} || {} }, 861 %{ $v->{meta} || {} },
813 }); 862 });
814 863
815 $v->{data} = pack "(w/a*)*", $meta, $v->{data}; 864 $v->{data} = pack "(w/a*)*", $meta, $v->{data};
816 } 865 }
817 866
818 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 867 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
868 }
819 } 869 }
820 870
821 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 871 printf "writing facedata (%d faces, %d anims, %d resources)...\n",
822 scalar keys %FACEINFO, 872 scalar keys %FACEINFO,
823 scalar keys %ANIMINFO, 873 scalar keys %ANIMINFO,
825 if $VERBOSE; 875 if $VERBOSE;
826 876
827 open my $fh, ">:perlio", "$DATADIR/facedata~" 877 open my $fh, ">:perlio", "$DATADIR/facedata~"
828 or die "$DATADIR/facedata~: $!"; 878 or die "$DATADIR/facedata~: $!";
829 879
830 print $fh freeze { 880 print $fh nfreeze {
831 version => 2, 881 version => 2,
832 faceinfo => \%FACEINFO, 882 faceinfo => \%FACEINFO,
833 animinfo => \%ANIMINFO, 883 animinfo => \%ANIMINFO,
834 resource => \%RESOURCE, 884 resource => \%RESOURCE,
835 }; 885 };
836 886
837 } 887 }
838 888
839 print "committing files...\n" if $VERBOSE; 889 print "committing files...\n" if $VERBOSE;
840 890
841 for (qw(archetypes facedata treasures)) { 891 for (qw(archetypes facedata treasures), @COMMIT) {
842 chmod 0644, "$DATADIR/$_~"; 892 chmod 0644, "$DATADIR/$_~";
843 rename "$DATADIR/$_~", "$DATADIR/$_" 893 rename "$DATADIR/$_~", "$DATADIR/$_"
844 or die "$DATADIR/$_: $!"; 894 or die "$DATADIR/$_: $!";
845 } 895 }
846 896

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines