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.8 by root, Sun Mar 11 21:26:06 2007 UTC vs.
Revision 1.77 by root, Tue Nov 3 23:44:21 2009 UTC

1#!@PERL@ 1#!@PERL@
2
3#
4# This file is part of Deliantra, the Roguelike Realtime MMORPG.
5#
6# Copyright (©) 2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
7#
8# Deliantra is free software: you can redistribute it and/or modify it under
9# the terms of the Affero GNU General Public License as published by the
10# Free Software Foundation, either version 3 of the License, or (at your
11# option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the Affero GNU General Public License
19# and the GNU General Public License along with this program. If not, see
20# <http://www.gnu.org/licenses/>.
21#
22# The authors can be reached via e-mail to <support@deliantra.net>
23#
2 24
3use strict; 25use strict;
4 26
5my $prefix = "@prefix@"; 27my $prefix = "@prefix@";
6my $exec_prefix = "@exec_prefix@"; 28my $exec_prefix = "@exec_prefix@";
7my $datarootdir = "@datarootdir@"; 29my $datarootdir = "@datarootdir@";
8my $DATADIR = "@datadir@/@PACKAGE@"; 30my $DATADIR = "@datadir@/@PACKAGE@";
9 31
10my $CONVERT = "@CONVERT@"; 32my $CONVERT = "@CONVERT@";
11my $IDENTIFY = "@IDENTIFY@"; 33#my $IDENTIFY = "@IDENTIFY@";
12my $OPTIPNG = "@OPTIPNG@"; 34my $OPTIPNG = "@OPTIPNG@";
13my $RSYNC = "@RSYNC@"; 35my $RSYNC = "@RSYNC@";
36my $PNGNQ = "@PNGNQ@";
14 37
15use Getopt::Long; 38use Getopt::Long;
39use File::Temp;
40use POSIX ();
41use Carp;
42
16use Coro::Event; 43use Coro::EV;
17use AnyEvent; 44use AnyEvent;
45use YAML::XS ();
46use JSON::XS ();
18use IO::AIO (); 47use IO::AIO ();
19use File::Temp; 48
20use Crossfire;
21use Coro; 49use Coro 5.12;
22use Coro::AIO; 50use Coro::AIO;
23use POSIX (); 51use Coro::Util;
24use Digest::MD5; 52use Coro::Channel;
53use Coro::Storable; $Storable::canonical = 1;
54
55use Deliantra;
56
57$SIG{QUIT} = sub { Carp::cluck "QUIT" };
25 58
26sub usage { 59sub usage {
27 warn <<EOF; 60 warn <<EOF;
28Usage: cfutil [-v] [-q] [--force] [--cache] 61Usage: cfutil [-v] [-q] [--force] [--cache]
29 [--install-arch path] 62 [--install-arch path]
41my $CACHE = 0; 74my $CACHE = 0;
42my $FORCE; 75my $FORCE;
43my $TMPDIR = "/tmp/cfutil$$~"; 76my $TMPDIR = "/tmp/cfutil$$~";
44my $TMPFILE = "aaaa0"; 77my $TMPFILE = "aaaa0";
45 78
79our %COLOR = (
80 black => 0,
81 white => 1,
82 navy => 2,
83 red => 3,
84 orange => 4,
85 blue => 5,
86 darkorange => 6,
87 green => 7,
88 lightgreen => 8,
89 grey => 9,
90 brown => 10,
91 gold => 11,
92 tan => 12,
93);
94
46END { system "rm", "-rf", $TMPDIR } 95END { system "rm", "-rf", $TMPDIR }
47 96
48Event->signal (signal => "INT", cb => sub { exit 1 }); 97my $s_INT = EV::signal INT => sub { exit 1 };
49Event->signal (signal => "TERM", cb => sub { exit 1 }); 98my $s_TERM = EV::signal TERM => sub { exit 1 };
50 99
51mkdir $TMPDIR, 0700 100mkdir $TMPDIR, 0700
52 or die "$TMPDIR: $!"; 101 or die "$TMPDIR: $!";
53 102
54sub fork_sub(&) { 103sub fork_sub(&) {
67} 116}
68 117
69sub inst_maps($) { 118sub inst_maps($) {
70 my (undef, $path) = @_; 119 my (undef, $path) = @_;
71 120
72 print "installing '$path' to '$DATADIR/maps'\n\n"; 121 print "\nInstalling '$path' to '$DATADIR/maps'\n\n";
73 122
74 if (!-f "$path/regions") { 123 if (!-f "$path/regions") {
75 warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; 124 warn "'$path' does not look like a maps directory ('regions' file is missing).\n";
76 exit 1 unless $FORCE; 125 exit 1 unless $FORCE;
77 } 126 }
78 127
79 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; 128 system $RSYNC, "-av", "--chmod=u=rwX,go=rX",
129 "$path/.", "$DATADIR/maps/.",
130 "--exclude", "CVS", "--exclude", "/world-precomposed",
131 "--delete", "--delete-excluded"
132 and die "map installation failed.\n";
133
134 print "maps installed successfully.\n";
80} 135}
81 136
82{ 137{
83 our %PNG32; 138 our %ANIMINFO;
84 our %FACEINFO; 139 our %FACEINFO;
140 our %RESOURCE;
85 our @ARC; 141 our @ARC;
142 our %ARC;
143 our $TRS;
86 our $NFILE; 144 our $NFILE;
87 our %ANIM; 145 our $PATH;
88 146
89 our (@png, @trs, @arc); # files we are interested in 147 our $QUANTIZE = "+dither -colorspace RGB -colors 256";
90 148
149 our $c_arc = new Coro::Channel;
150 our $c_trs = new Coro::Channel;
151 our $c_res = new Coro::Channel;
152
153 our @c_png;
154
91 sub commit_png { 155 sub commit_png($$$) {
92 my ($name, $data) = @_; 156 my ($name, $data, $T) = @_;
93 157
94 $PNG32{$name} = $data; 158 $FACEINFO{$name}{"data$T"} = $data;
95 $FACEINFO{$name} ||= {};
96 } 159 }
97 160
98 sub process_png { 161 sub process_png {
99 while (@png) { 162 while (@c_png) {
100 my $path = pop @png; 163 my ($path, $delete) = @{pop @c_png};
101 164
102 my $png; 165 my $png;
103 aio_lstat $path; 166 aio_lstat $path;
104 my ($size, $mtime) = (stat _)[7,9]; 167 my ($size, $mtime) = (stat _)[7,9];
105 168
106 if (0 > aio_load $path, $png) { 169 if (0 > aio_load $path, $png) {
107 warn "$path: $!, skipping.\n"; 170 warn "$path: $!, skipping.\n";
108 next; 171 next;
109 } 172 }
110 173
174 my $stem = $path;
175 my $T;
176
177 if ($stem =~ s/\.32x32\.png~?$//) {
178 $T = 32;
179 } elsif ($stem =~ s/\.64x64\.png~?$//) {
180 $T = 64;
181 } else {
182 warn "$path: weird filename, skipping.\n";
183 next;
184 }
185
111 # quickly extract width and height of the (necessarily PNG) image 186 # quickly extract width and height of the (necessarily PNG) image
112 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 187 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
113 warn "$path: not a recongized png file, skipping.\n"; 188 warn "$path: not a recognized png file, skipping.\n";
114 next; 189 next;
115 } 190 }
116 191
117 my ($w, $h) = unpack "NN", $1; 192 my ($w, $h) = unpack "NN", $1;
118
119 (my $face = $path) =~ s/^.*\///;
120 my $T = 32;
121
122 unless ($face =~ s/\.base\.(...)\.png$/.$1/) {
123 warn "$path: weird filename, skipping.\n";
124 next;
125 }
126 193
127 if ($w < $T || $h < $T) { 194 if ($w < $T || $h < $T) {
128 warn "$path: too small ($w $h), skipping.\n"; 195 warn "$path: too small ($w $h), skipping.\n";
129 next; 196 next;
130 } 197 }
132 if ($w % $T || $h % $T) { 199 if ($w % $T || $h % $T) {
133 warn "$path: weird png size ($w $h), skipping.\n"; 200 warn "$path: weird png size ($w $h), skipping.\n";
134 next; 201 next;
135 } 202 }
136 203
204 (my $base = $stem) =~ s/^.*\///;
205
206 my $fi = $FACEINFO{$base};
207 unless ($fi) {
208 #warn "$path: <$base> not referenced by any archetype, skipping.\n";
209 #next;
210 }
211
212 my $arc = $fi->{arc} || { };
213
214 unless ($path =~ /~$/) {
215 # possibly enlarge
216 if (0 > aio_stat "$stem.64x64.png") {
217 my $other = "$stem.64x64.png~";
218
219 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
220 fork_sub {
221 my $CROP;
222 my $SRC = "png:\Q$path\E";
223
224 my $is_floor = $arc->{is_floor};
225 my $is_wall = 0;
226
227 my ($wall_pfx, $wall_dir, $wall_sfx);
228
229 if (
230 !$is_floor
231 && !$arc->{alive}
232 && $arc->{move_block} eq "all"
233 && $path =~ /^(.*_)([0-9A-F])(\.x11.*\.png)$/
234 ) {
235 ($wall_pfx, $wall_dir, $wall_sfx) = ($1, hex $2, $3);
236
237 unless (grep { !-e sprintf "%s%X%s", $wall_pfx, $_, $wall_sfx } 0..15) {
238 $is_wall = 1;
239 }
240 }
241
242 if ($is_wall || $is_floor) {
243 # add a 4px border and add other images around it
244 $CROP = "-shave 8x8 +repage";
245
246 $w += 8;
247 $h += 8;
248
249 $SRC = "-size ${w}x${h} xc:transparent";
250 $SRC .= " png:\Q$path\E -geometry +4+4 -composite";
251
252 # 8 surrounding images
253 for (
254 # x y b r0 r1
255 [-1, -1, 0, 6],
256 [ 0, -1, 1, 10, 14],
257 [+1, -1, 0, 12],
258
259 [-1, 0, 8, 5, 7],
260 #
261 [+1, 0, 2, 5, 13],
262
263 [-1, +1, 0, 3],
264 [ 0, +1, 4, 10, 11],
265 [+1, +1, 0, 9],
266 ) {
267 my ($x, $y, $d, $r0, $r1) = @$_;
268
269 my $tile = $is_floor ? $path
270 : $is_wall ? sprintf "%s%X%s", $wall_pfx, ($wall_dir & $d) ? $r1 : $r0, $wall_sfx
271 : die;
272
273 $SRC .= sprintf " png:%s -geometry %+d%+d -composite",
274 "\Q$tile",
275 $x * ($w - 8) + 4,
276 $y * ($h - 8) + 4;
277 }
278 }
279
280 system "convert -depth 8 $SRC rgba:-"
281 . "| $exec_prefix/bin/cfhq2xa $w $h 0"
282 . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~"
283 and die "convert/cfhq2xa pipeline error: status $? ($!)";
284 system $OPTIPNG, "-i0", "-q", "$other~";
285 die "$other~ has zero size, aborting." unless -s "$other~";
286 rename "$other~", $other;
287 };
288 }
289
290 push @c_png, [$other, !$CACHE];
291 }
292
293 # possibly scale down
294 if (0 > aio_stat "$stem.32x32.png") {
295 my $other = "$stem.32x32.png~";
296
297 if (0 > aio_lstat $other or (-M _) > (-M $path)) {
298 fork_sub {
299 system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~";
300 system $OPTIPNG, "-i0", "-q", "$other~";
301
302 # reduce smoothfaces >10000 bytes
303 # obsolete, no longer required
304 if (0 && $stem =~ /_S\./ && (-s "$other~") > 10000) {
305 my $ncolor = 256;
306 while () {
307 system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E";
308 system $OPTIPNG, "-i0", "-q", "$other~~";
309 last if 10000 > -s "$other~~";
310 $ncolor = int $ncolor * 0.9;
311 $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes";
312 }
313
314 printf "reduced %s from %d to %d bytes using %d colours.\n",
315 $other, -s "$other~", -s "$other~~", $ncolor
316 if $VERBOSE >= 2;
317 rename "$other~~", "$other~";
318 }
319
320 die "$other~ has zero size, aborting." unless -s "$other~";
321 rename "$other~", $other;
322 };
323 }
324
325 #warn "scaled down $path to $other\n";#d#
326 push @c_png, [$other, !$CACHE];
327 }
328 }
329
330 (my $face = $stem) =~ s/^.*\///;
331
332 # split all bigfaces, but avoid smoothfaces (*_S)
137 if (($w > $T || $h > $T) && $face !~ /_S\./) { 333 if (($w > $T || $h > $T) && $face !~ /_S\./) {
138 # split 334 # split
139 my @tile; 335 my @tile;
140 for my $x (0 .. (int $w / $T) - 1) { 336 for my $x (0 .. (int $w / $T) - 1) {
141 for my $y (0 .. (int $h / $T) - 1) { 337 for my $y (0 .. (int $h / $T) - 1) {
155 ( 351 (
156 "(", 352 "(",
157 "+clone", 353 "+clone",
158 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 354 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
159 "+repage", 355 "+repage",
356 -quality => "00",
160 -write => "png:$_->[2]~", 357 -write => "png32:$_->[2]~",
161 "+delete", 358 "+delete",
162 ")", 359 ")",
163 ) 360 )
164 } @todo), 361 } @todo),
165 "null:"; 362 "null:";
169 close $convert; 366 close $convert;
170 367
171 # pass 2, optimise, and rename 368 # pass 2, optimise, and rename
172 for (@todo) { 369 for (@todo) {
173 system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~"; 370 system $OPTIPNG, "-o5", "-i0", "-q", "$_->[2]~";
371 die "$_->[2]~ has zero size, aborting." unless -s "$_->[2]~";
174 rename "$_->[2]~", $_->[2]; 372 rename "$_->[2]~", $_->[2];
175 } 373 }
176 }; 374 };
177 } 375 }
178 376
182 380
183 if (0 > aio_load $file, $tile) { 381 if (0 > aio_load $file, $tile) {
184 die "$path: unable to read tile +$x+$y, aborting.\n"; 382 die "$path: unable to read tile +$x+$y, aborting.\n";
185 } 383 }
186 IO::AIO::aio_unlink $file unless $CACHE; 384 IO::AIO::aio_unlink $file unless $CACHE;
187 commit_png $x|$y ? "$face+$x+$y" : $face, $tile; 385 commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T;
188 } 386 }
189 } else { 387 } else {
190 # use as-is (either small, use smooth) 388 # use as-is (either small, use smooth)
191 commit_png $face, $png; 389 commit_png $face, $png, $T;
192 } 390 }
391
392 aio_unlink $path if $delete;
193 } 393 }
194 } 394 }
195 395
196 sub process_arc { 396 sub process_arc {
197 while (@arc) { 397 while (my $job = $c_arc->get) {
198 my ($dir, $file) = @{pop @arc}; 398 my ($dir, $file) = @$job;
199 399
200 my $arc; 400 my $arc;
201 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 401 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
202 402
203 my $arc = read_arch "$dir/$file"; 403 my $arc = read_arch "$dir/$file";
204 for my $o (values %$arc) { 404 for my $o (values %$arc) {
205 push @ARC, $o; 405 push @ARC, $o;
406 for (my $m = $o; $m; $m = $m->{more}) {
407 $ARC{$m->{_name}} = $m;
408 }
409
410 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge
206 411
207 my $visibility = delete $o->{visibility}; 412 my $visibility = delete $o->{visibility};
208 my $magicmap = delete $o->{magicmap}; 413 my $magicmap = delete $o->{magicmap};
209 414
210 # find upper left corner :/ 415 # find upper left corner :/
219 my $x = $o->{x} - $dx; 424 my $x = $o->{x} - $dx;
220 my $y = $o->{y} - $dy; 425 my $y = $o->{y} - $dy;
221 426
222 my $ext = $x|$y ? "+$x+$y" : ""; 427 my $ext = $x|$y ? "+$x+$y" : "";
223 428
224 $o->{face} .= $ext; 429 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
225 430
226 my $visibility = delete $o->{visibility} if exists $o->{visibility}; 431 $visibility = delete $o->{visibility} if exists $o->{visibility};
227 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 432 $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
228 433
229 my $anim = delete $o->{anim}; 434 my $anim = delete $o->{anim};
230 435
231 if ($anim) { 436 if ($anim) {
437 # possibly add $ext to the animation name to avoid
438 # the need to specify archnames for all parts
439 # of a multipart archetype.
232 $o->{animation} = "$o->{_name}"; 440 $o->{animation} = "$o->{_name}";
441 my $facings = 1;
442 my @frames;
233 443
234 for (@$anim) { 444 for (@$anim) {
235 $_ .= $ext unless /^facings\s/; 445 if (/^facings\s+(\d+)/) {
446 $facings = $1*1;
447 } elsif (/^blank.x11$|^empty.x11$/) {
448 push @frames, $_;
449 } else {
450 push @frames, "$_$ext";
451 }
236 } 452 }
237 453
238 $ANIM{"$o->{_name}$ext"} = 454 $ANIMINFO{$o->{animation}} = {
239 join "", map "$_\n", 455 facings => $facings,
240 "anim $o->{_name}", 456 frames => \@frames,
241 @$anim, 457 };
242 "mina";
243 } 458 }
244 459
245 for my $face ($o->{face} || (), @{$anim || []}) { 460 for ($o->{face} || (), @{$anim || []}) {
246 next if /^facings\s/; 461 next if /^facings\s/;
247 462
463 my $face = $_;
464 $face =~ s/\+\d+\+\d+$//; # remove tile offset coordinates
465
248 my $info = $FACEINFO{$face} ||= {}; 466 my $info = $FACEINFO{$face} ||= { };
467 $info->{arc} = $o;
468
469 next if $face =~ /^blank.x11$|^empty.x11$/;
249 470
250 $info->{visibility} = $visibility if defined $visibility; 471 $info->{visibility} = $visibility if defined $visibility;
251 $info->{magicmap} = $magicmap if defined $magicmap; 472 $info->{magicmap} = $magicmap if defined $magicmap;
252 } 473 }
474
475 if (my $smooth = delete $o->{smoothface}) {
476 my %kv = split /\s+/, $smooth;
477 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
478 while (my ($face, $smooth) = each %kv) {
479 $FACEINFO{$smooth}{arc} = $o;
480
481 $FACEINFO{$face}{smooth} = $smooth;
482 $FACEINFO{$face}{smoothlevel} = $level;
483 }
484 }
253 } 485 }
254 } 486 }
255 } 487 }
256 } 488 }
257 489
258 sub process_trs { 490 sub process_trs {
259 while (@trs) { 491 while (my $job = $c_trs->get) {
260 my ($dir, $file) = @{pop @trs}; 492 my ($dir, $file) = @$job;
493 my $path = "$dir/$file";
494
495 my $trs;
496 if (0 > aio_load $path, $trs) {
497 warn "$path: $!, skipping.\n";
498 next;
499 }
500
501 $TRS .= $trs;
502 }
503 }
504
505 my %FILECACHE;
506
507 sub load_cached($;$) {
508 unless (exists $FILECACHE{$_[0]}) {
509 my $data;
510 if (0 < aio_load $_[0], $data) {
511 if ($_[1]) {
512 $data = eval { $_[1]->($data) };
513 warn "$_[0]: $@" if $@;
514 }
515 }
516
517 $FILECACHE{$_[0]} = $data;
518 }
519
520 $FILECACHE{$_[0]}
521 }
522
523 sub process_res {
524 while (my $job = $c_res->get) {
525 my ($dir, $file, $type) = @$job;
526
527 my $data;
528 aio_load "$dir/$file", $data;
529
530 my $meta = load_cached "$dir/meta", sub { JSON::XS->new->utf8->relaxed->decode (shift) };
531
532 utf8::decode $dir;
533 utf8::decode $file;
534
535 # a meta file for resources is now mandatory
536 unless (exists $meta->{$file}) {
537 warn "skipping $dir/$file\n" if $VERBOSE >= 3;
538 next;
539 }
540
541 $meta = {
542 %{ $meta->{"" } || {} },
543 %{ $meta->{$file} || {} },
544 };
545
546 if ($meta->{license} =~ s/^#//) {
547 $meta->{license} = ({
548 "pd" => "Public Domain",
549 "gpl" => "GNU General Public License, version 3.0 or any later",
550 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
551 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/",
552 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
553 })->{$meta->{license}}
554 || warn "$dir/$file: license tag '$meta->{license}' not found.";
555 }
556
557 $file =~ s/\.res$//;
558 $file =~ s/\.(ogg|wav|jpg|png)$//;
559
560 substr $dir, 0, 1 + length $PATH, "";
561
562 if (my $filter = $meta->{cfutil_filter}) {
563 if ($filter eq "yaml2json") {
564 $data = JSON::XS::encode_json YAML::XS::Load $data;
565 } elsif ($filter eq "json2json") {
566 $data = JSON::XS::encode_json JSON::XS->relaxed->utf8->decode ($data);
567 } elsif ($filter eq "perl2json") {
568 $data = eval $data; die if $@;
569 $data = JSON::XS::encode_json $data;
570 } else {
571 warn "$dir/$file: unknown filter $filter, skipping\n";
572 }
573 }
574
575 $RESOURCE{"$dir/$file"} = {
576 type => (exists $meta->{type} ? delete $meta->{type} : $type),
577 data => $data,
578 %$meta ? (meta => $meta) : (),
579 };
261 } 580 }
262 } 581 }
263 582
264 sub find_files; 583 sub find_files;
265 sub find_files { 584 sub find_files {
270 my ($dirs, $nondirs) = @_; 589 my ($dirs, $nondirs) = @_;
271 590
272 find_files "$path/$_" 591 find_files "$path/$_"
273 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; 592 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs;
274 593
594 my $dir = $path;
595 substr $dir, 0, 1 + length $PATH, "";
596
275 for my $file (@$nondirs) { 597 for my $file (@$nondirs) {
598 if ($dir =~ /^music(?:\/|$)/) {
599 $c_res->put ([$path, $file, 3]) # FT_MUSIC
600 if $file =~ /\.(ogg)$/;
601
602 } elsif ($dir =~ /^sound(?:\/|$)/) {
603 $c_res->put ([$path, $file, 5]) # FT_SOUND
604 if $file =~ /\.(wav|ogg)$/;
605
606 } elsif ($dir =~ /^res(?:\/|$)/) {
607 if ($file =~ /\.(jpg|png)$/) {
608 $c_res->put ([$path, $file, 0]) # FT_FACE
609 } elsif ($file =~ /\.(res)$/) {
610 $c_res->put ([$path, $file, 6]) # FT_RSRC
611 } else {
612 $c_res->put ([$path, $file, undef]);
613 }
614
276 if ($file =~ /\.png$/) { 615 } elsif ($file =~ /\.png$/) {
277 push @png, "$path/$file"; 616 push @c_png, ["$path/$file", 0];
617
278 } elsif ($file =~ /\.trs$/) { 618 } elsif ($file =~ /\.trs$/) {
279 push @trs, [$path, $file]; 619 $c_trs->put ([$path, $file]);
620
280 } elsif ($file =~ /\.arc$/) { 621 } elsif ($file =~ /\.arc$/) {
281 push @arc, [$path, $file]; 622 $c_arc->put ([$path, $file]);
623
282 } else { 624 } else {
283 warn "ignoring $path/$file\n" if $VERBOSE >= 2; 625 warn "ignoring $path/$file\n" if $VERBOSE >= 3;
284 } 626 }
285 } 627 }
286 }; 628 };
629 }
630
631 sub generate_plurals {
632# use Lingua::EN::Inflect ();
633# Lingua::EN::Inflect::classical;
634# Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy
635# Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack
636#
637# for my $a (@ARC) {
638# my $name = $a->{name} || $a->{_name};
639#
640# next unless $a->{name_pl};
641# next if $a->{invisible};
642# next if $a->{is_floor};
643# next if $a->{no_pick};
644#
645# my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name;
646# my $pl = $test =~ /^(?:eq|p:.)$/
647# ? $name
648# : Lingua::EN::Inflect::PL $name;
649#
650# if ($pl ne $a->{name_pl}) {
651# warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n";
652# }
653# }
287 } 654 }
288 655
289 sub inst_arch($) { 656 sub inst_arch($) {
290 my (undef, $path) = @_; 657 my (undef, $path) = @_;
291 658
659 $PATH = $path;
660
661 print "\n",
292 print "installing '$path' to '$DATADIR'\n\n"; 662 "Installing '$path' to '$DATADIR'\n",
663 "\n",
664 "This can take a long time if you run this\n",
665 "for the first time or do not use --cache.\n",
666 "\n",
667 "Unless you run verbosely, all following warning\n",
668 "or error messages indicate serious problems.\n",
669 "\n";
293 670
294 if (!-d "$path/treasures") { 671 if (!-d "$path/treasures") {
295 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 672 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n";
296 exit 1 unless $FORCE; 673 exit 1 unless $FORCE;
297 } 674 }
298 675
676 print "scanning files...\n" if $VERBOSE;
677
299 find_files $path; 678 find_files $path;
679
680 my @a_arc = map +(async \&process_arc), 1..2;
681 my @a_res = map +(async \&process_res), 1..2;
682 my @a_trs = map +(async \&process_trs), 1..2;
683
300 IO::AIO::flush; 684 IO::AIO::flush;
301 685
302 $_->join for ( 686 $c_res->shutdown;
303 (async \&process_png), (async \&process_png), 687 $c_arc->shutdown;
304 (async \&process_trs), (async \&process_trs), 688 $c_trs->shutdown;
305 (async \&process_arc), (async \&process_arc),
306 );
307 689
690 print "start file scan, arc, res processing...\n" if $VERBOSE;
691
692 $_->join for @a_arc; # need to parse all archetypes before png processing
693
694 print "end arc, start png processing...\n" if $VERBOSE;
695
696 # eight png crunchers work fine for my 4x smp machine
697 my @a_png = map +(async \&process_png), 1..8;
698
699 $_->join for (@a_trs, @a_res, @a_png);
700
701 print "scanning done, processing results...\n" if $VERBOSE;
308 { 702 {
309 open my $fh, ">:utf8", "$DATADIR/animations~" 703 # remove path prefix from editor_folder
310 or die "$DATADIR/animations~: $!"; 704 $_->{editor_folder} =~ /^\x00/
311 print $fh join "", map $ANIM{$_}, sort keys %ANIM 705 and substr $_->{editor_folder}, 0, 2 + length $path, ""
706 for values %ARC;
707
708 print "resolving inheritance tree...\n" if $VERBOSE;
709 # resolve inherit
710 while () {
711 my $progress;
712 my $loop;
713
714 for my $o (values %ARC) {
715 if (my $other = $o->{inherit}) {
716 if (my $s = $ARC{$other}) {
717 if ($s->{inherit}) {
718 $loop = $s;
719 } else {
720 delete $o->{inherit};
721 my %s = %$s;
722 delete @s{qw(_name more name name_pl)};
723 %$o = ( %s, %$o );
724 ++$progress;
725 }
726 } else {
727 warn "'$o->{_name}' tries to inherit from undefined archetype '$other', skipping.\n";
728 delete $ARC{$o->{_name}};
729 }
730 }
731 }
732
733 unless ($progress) {
734 die "inheritance loop detected starting at archetype '$loop->{_name}', aborting.\n"
735 if $loop;
736
737 last;
738 }
312 } 739 }
313 740
314 { 741 # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit
742 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC;
743
744 print "generating plurals...\n" if $VERBOSE;
745 generate_plurals;
746
747 print "writing archetypes...\n" if $VERBOSE;
315 open my $fh, ">:utf8", "$DATADIR/archetypes~" 748 open my $fh, ">:utf8", "$DATADIR/archetypes~"
316 or die "$DATADIR/archetypes~: $!"; 749 or die "$DATADIR/archetypes~: $!";
317 print $fh Crossfire::archlist_to_string \@ARC; 750 print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC];
318 } 751 }
319 752
320 { 753 {
754 print "writing treasures...\n" if $VERBOSE;
755 open my $fh, ">:utf8", "$DATADIR/treasures~"
756 or die "$DATADIR/treasures~: $!";
757 print $fh $TRS;
758 }
759
760 {
761 print "processing facedata...\n" if $VERBOSE;
321 while (my ($k, $v) = each %FACEINFO) { 762 while (my ($k, $v) = each %FACEINFO) {
322 $v->{data32} ||= delete $PNG32{$k}; 763 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
764 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
765
766 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
767 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
768
769 if (my $magicmap = $v->{magicmap}) {
770 $magicmap =~ y/A-Z_\-/a-z/d;
771 $v->{magicmap} = $COLOR{$magicmap};
323 } 772 }
324 773
325 while (my ($k, $v) = each %FACEINFO) { 774 delete $v->{arc};
326 exists $v->{data32} or warn "$k: face has no png32. this will crash the server.\n";
327
328 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
329 } 775 }
330 776
777 print "writing facedata...\n" if $VERBOSE;
331 open my $fh, ">:perlio", "$DATADIR/faces~" 778 open my $fh, ">:perlio", "$DATADIR/facedata~"
332 or die "$DATADIR/faces~: $!"; 779 or die "$DATADIR/facedata~: $!";
333 780
334 print $fh Storable::nfreeze \%FACEINFO; 781 print $fh freeze {
335 782 version => 2,
336 #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO; 783 faceinfo => \%FACEINFO,
784 animinfo => \%ANIMINFO,
785 resource => \%RESOURCE,
337 } 786 };
787 }
338 788
789 print "committing files...\n" if $VERBOSE;
790
339 for (qw(archetypes faces animations)) { 791 for (qw(archetypes facedata treasures)) {
340 chmod 0644, "$DATADIR/$_~"; 792 chmod 0644, "$DATADIR/$_~";
341 rename "$DATADIR/$_~", "$DATADIR/$_"; 793 rename "$DATADIR/$_~", "$DATADIR/$_"
794 or die "$DATADIR/$_: $!";
342 } 795 }
343 796
344 die "--install-arch not fully implemented\n"; 797 print "archetype data installed successfully.\n";
345 } 798 }
346} 799}
347 800
348Getopt::Long::Configure ("bundling", "no_ignore_case"); 801Getopt::Long::Configure ("bundling", "no_ignore_case");
349GetOptions ( 802GetOptions (

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines