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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines