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.3 by root, Wed Mar 7 18:04:44 2007 UTC vs.
Revision 1.11 by root, Mon Mar 12 14:55:43 2007 UTC

19use File::Temp; 19use File::Temp;
20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5;
24 25
25sub usage { 26sub usage {
26 warn <<EOF; 27 warn <<EOF;
27Usage: cfutil [-v] [-q] [--force] [--cache] 28Usage: cfutil [-v] [-q] [--force] [--cache]
28 [--install-arch path] 29 [--install-arch path]
77 78
78 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; 79 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded";
79} 80}
80 81
81{ 82{
82 our @PNG; 83 our %PNG32;
84 our %FACEINFO;
83 our @ARC; 85 our @ARC;
84 our $NFILE; 86 our $NFILE;
87 our %ANIM;
85 88
86 our (@png, @trs, @arc); # files we are interested in 89 our (@png, @trs, @arc); # files we are interested in
87 90
88 sub commit_png { 91 sub commit_png {
89 my ($name, $data) = @_; 92 my ($name, $data) = @_;
90 #warn "$name: commited\n"; 93
94 $PNG32{$name} = $data;
95 $FACEINFO{$name} ||= {};
91 } 96 }
92 97
93 sub process_png { 98 sub process_png {
94 while (@png) { 99 while (@png) {
95 my $path = pop @png; 100 my $path = pop @png;
98 aio_lstat $path; 103 aio_lstat $path;
99 my ($size, $mtime) = (stat _)[7,9]; 104 my ($size, $mtime) = (stat _)[7,9];
100 105
101 if (0 > aio_load $path, $png) { 106 if (0 > aio_load $path, $png) {
102 warn "$path: $!, skipping.\n"; 107 warn "$path: $!, skipping.\n";
103 return; 108 next;
104 } 109 }
105 110
106 # quickly extratc width and height of the (necessarily PNG) image 111 # quickly extract width and height of the (necessarily PNG) image
107 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 112 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
108 warn "$path: not a recongized png file, skipping.\n"; 113 warn "$path: not a recongized png file, skipping.\n";
109 return; 114 next;
110 } 115 }
111 116
112 my ($w, $h) = unpack "NN", $1; 117 my ($w, $h) = unpack "NN", $1;
113 118
114 (my $face = $path) =~ s/^.*\///; 119 (my $face = $path) =~ s/^.*\///;
115 my $T = 32; 120 my $T = 32;
116 121
117 unless ($face =~ s/\.base\.(...)\.png$/.$1/) { 122 unless ($face =~ s/\.base\.(...)\.png$/.$1/) {
118 warn "$path: weird filename, skipping.\n"; 123 warn "$path: weird filename, skipping.\n";
119 return; 124 next;
120 } 125 }
121 126
122 if ($w < $T || $h < $T) { 127 if ($w < $T || $h < $T) {
123 warn "$path: too small ($w $h), skipping.\n"; 128 warn "$path: too small ($w $h), skipping.\n";
124 return; 129 next;
125 } 130 }
126 131
127 if ($w % $T || $h % $T) { 132 if ($w % $T || $h % $T) {
128 warn "$path: weird png size ($w $h), skipping.\n"; 133 warn "$path: weird png size ($w $h), skipping.\n";
129 return; 134 next;
130 } 135 }
131 136
132 if (($w > $T || $h > $T) && $face !~ /_S\./) { 137 if (($w > $T || $h > $T) && $face !~ /_S\./) {
133 # split 138 # split
134 my @tile; 139 my @tile;
149 (map { 154 (map {
150 ( 155 (
151 "(", 156 "(",
152 "+clone", 157 "+clone",
153 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 158 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
159 "+repage",
154 -write => "png:$_->[2]~", 160 -write => "png:$_->[2]~",
155 "+delete", 161 "+delete",
156 ")", 162 ")",
157 ) 163 )
158 } @todo), 164 } @todo),
191 while (@arc) { 197 while (@arc) {
192 my ($dir, $file) = @{pop @arc}; 198 my ($dir, $file) = @{pop @arc};
193 199
194 my $arc; 200 my $arc;
195 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 201 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
202
196 my $arc = read_arch "$dir/$file"; 203 my $arc = read_arch "$dir/$file";
204 for my $o (values %$arc) {
205 push @ARC, $o;
206
207 $o->{editor_folder} = $dir;
208
209 my $visibility = delete $o->{visibility};
210 my $magicmap = delete $o->{magicmap};
211
212 # find upper left corner :/
213 # omg, this is sooo broken
214 my ($dx, $dy);
215 for (my $o = $o; $o; $o = $o->{more}) {
216 $dx = $o->{x} if $o->{x} < $dx;
217 $dy = $o->{y} if $o->{y} < $dy;
218 }
219
220 for (my $o = $o; $o; $o = $o->{more}) {
221 my $x = $o->{x} - $dx;
222 my $y = $o->{y} - $dy;
223
224 my $ext = $x|$y ? "+$x+$y" : "";
225
226 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/;
227
228 my $visibility = delete $o->{visibility} if exists $o->{visibility};
229 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
230
231 my $anim = delete $o->{anim};
232
233 if ($anim) {
234 $o->{animation} = "$o->{_name}";
235
236 for (@$anim) {
237 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/;
238 }
239
240 $ANIM{"$o->{_name}$ext"} =
241 join "", map "$_\n",
242 "anim $o->{_name}",
243 @$anim,
244 "mina";
245 }
246
247 for my $face ($o->{face} || (), @{$anim || []}) {
248 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
249
250 my $info = $FACEINFO{$face} ||= {};
251
252 $info->{visibility} = $visibility if defined $visibility;
253 $info->{magicmap} = $magicmap if defined $magicmap;
254 }
255 }
256 }
197 } 257 }
198 } 258 }
199 259
200 sub process_trs { 260 sub process_trs {
201 while (@trs) { 261 while (@trs) {
245 (async \&process_png), (async \&process_png), 305 (async \&process_png), (async \&process_png),
246 (async \&process_trs), (async \&process_trs), 306 (async \&process_trs), (async \&process_trs),
247 (async \&process_arc), (async \&process_arc), 307 (async \&process_arc), (async \&process_arc),
248 ); 308 );
249 309
310 {
311 open my $fh, ">:utf8", "$DATADIR/animations~"
312 or die "$DATADIR/animations~: $!";
313 print $fh join "", map $ANIM{$_}, sort keys %ANIM
314 }
315
316 {
317 open my $fh, ">:utf8", "$DATADIR/archetypes~"
318 or die "$DATADIR/archetypes~: $!";
319 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC;
320 print $fh Crossfire::archlist_to_string \@ARC;
321 }
322
323 {
324 while (my ($k, $v) = each %FACEINFO) {
325 $v->{data32} ||= delete $PNG32{$k};
326 }
327
328 while (my ($k, $v) = each %FACEINFO) {
329 length $v->{data32} or warn "$k: face has no png32. this will crash the server.\n";
330
331 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
332 }
333
334 open my $fh, ">:perlio", "$DATADIR/faces~"
335 or die "$DATADIR/faces~: $!";
336
337 print $fh Storable::nfreeze \%FACEINFO;
338
339 #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO;
340 }
341
342 for (qw(archetypes faces animations)) {
343 chmod 0644, "$DATADIR/$_~";
344 rename "$DATADIR/$_~", "$DATADIR/$_";
345 }
346
250 die "--install-arch not yet implemented\n"; 347 die "--install-arch not fully implemented\n";
251 } 348 }
252} 349}
253 350
254Getopt::Long::Configure ("bundling", "no_ignore_case"); 351Getopt::Long::Configure ("bundling", "no_ignore_case");
255GetOptions ( 352GetOptions (

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines