ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cfmaps/cfmap2png
(Generate patch)

Comparing cfmaps/cfmap2png (file contents):
Revision 1.10 by root, Sun Nov 20 01:31:21 2005 UTC vs.
Revision 1.16 by root, Mon Dec 12 01:37:11 2005 UTC

17# along with gvpe; if not, write to the Free Software 17# along with gvpe; if not, write to the Free Software
18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 19
20# tower of stars: missing craters? 20# tower of stars: missing craters?
21 21
22our $VERSION = '1.1'; 22our $VERSION = '1.2';
23 23
24use strict; 24use strict;
25 25
26use Storable; 26use Storable;
27use List::Util qw(max); 27use List::Util qw(max);
74 74
75 $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; 75 $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/;
76 } 76 }
77 77
78 Storable::nstore \%smooth, "$path.pst"; 78 Storable::nstore \%smooth, "$path.pst";
79 utime +(stat $path)[8,9], "$path.pst";
79 80
80 \%smooth 81 \%smooth
81 } 82 }
82} 83}
83 84
151 } 152 }
152 } 153 }
153 154
154 undef $parse_block; # work around bug in perl not freeing $fh etc. 155 undef $parse_block; # work around bug in perl not freeing $fh etc.
155 156
157 if ($cache) {
156 Storable::nstore \%arc, "$path.pst" 158 Storable::nstore \%arc, "$path.pst";
157 if $cache; 159 utime +(stat $path)[8,9], "$path.pst";
160 }
158 161
159 \%arc 162 \%arc
160 } 163 }
161} 164}
162 165
222 # first pass, gather face stacking order, border and corner info 225 # first pass, gather face stacking order, border and corner info
223 for my $x (0 .. $mapx - 1) { 226 for my $x (0 .. $mapx - 1) {
224 my $col = $map->[$x]; 227 my $col = $map->[$x];
225 for my $y (0 .. $mapy - 1) { 228 for my $y (0 .. $mapy - 1) {
226 my $as = $col->[$y] || []; 229 my $as = $col->[$y] || [];
227 230
231 my $minsmooth = 0;
232
228 for my $layer (0 .. $#$as) { 233 for my $layer (0 .. $#$as) {
229 my $a = $as->[$layer]; 234 my $a = $as->[$layer];
230 235
231 my $o = $arch->{$a->{_name}} 236 my $o = $arch->{$a->{_name}}
232 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 237 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
233 238
234 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; 239 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel};
240
241 # hack to ensure somewhat correct ordering in case of conflicting
242 # smoothlevel/stacking order
243 $smoothlevel = $minsmooth + 0.01 if $minsmooth >= $smoothlevel;
244 $minsmooth = $smoothlevel;
245
235 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; 246 #my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor};
236 my $level = $smoothlevel ? $smoothlevel 247 my $level = $smoothlevel + $layer * 256;
237 : $is_floor ? 0 248
238 : 256 + $layer; 249 $level -= 100 * 256 if $o->{_name} eq "blocked";
239 250
240 while ($o) { 251 while ($o) {
241 my $face = $a->{face} || $o->{face}; 252 my $face = $a->{face} || $o->{face};
242 253
243 my $pb = tile $face 254 my $pb = tile $face
277 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; 288 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
278 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; 289 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
279 } 290 }
280 291
281 $o = $o->{more}; 292 $o = $o->{more};
293 $level = ($layer + 1000) * 2; # put "big things" on top, no matter what
282 } 294 }
283 } 295 }
284 } 296 }
285 } 297 }
286 298
299 my ($x, $y) = split $;, $xy; 311 my ($x, $y) = split $;, $xy;
300 312
301 next if $x < 0 || $x >= $mapx 313 next if $x < 0 || $x >= $mapx
302 || $y < 0 || $y >= $mapy; 314 || $y < 0 || $y >= $mapy;
303 315
304 # bits is 00XX XXXX YYYY YYFX cccc CCCC BBBB 316 # bits is xxxx xxxx yyyy yyyy __fn cccc CCCC bbbb
305 # X don't draw
306 # F full tile draw with x|y bigface displacement 317 # f full tile draw with x|y bigface displacement
307 # c maybe draw these corners
308 # C do not draw these corners 318 # n do not draw borders&corners
319 # c draw these corners, but...
320 # C ... not these
309 # b draw these borders 321 # b draw these borders
310 322
311 if ($bits & 0x2000) { 323 if ($bits & 0x2000) {
312 my $dx = (($bits >> 24) & 0xff) - 128; 324 my $dx = (($bits >> 24) & 0xff) - 128;
313 my $dy = (($bits >> 16) & 0xff) - 128; 325 my $dy = (($bits >> 16) & 0xff) - 128;
363} 375}
364 376
365for my $file (@ARGV) { 377for my $file (@ARGV) {
366 my $mapa = read_arch $file; 378 my $mapa = read_arch $file;
367 my ($pb, $meta) = cfmap_render $mapa, $file; 379 my ($pb, $meta) = cfmap_render $mapa, $file;
368 $pb->save ("$file.png~", "png"); 380 $pb->save ("$file.png~~", "png");
369 system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; 381 system "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg";
370 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency 382 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency
371 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png"; 383 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~";
384# system "pngnq <\Q$file.png~\E >\Q$file.png\E";
372 unlink "$file.png~"; 385 unlink "$file.png~~";
373 Storable::nstore $meta, "$file.pst"; 386 Storable::nstore $meta, "$file.pst";
387 utime +(stat $file)[8,9], "$file.pst";
388 utime +(stat $file)[8,9], "$file.png~";
389 rename "$file.png~", "$file.png";
374} 390}
375 391
376 392
377 393
378 394

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines