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

Comparing cfmaps/cfmap2png (file contents):
Revision 1.12 by root, Tue Nov 22 06:46:43 2005 UTC vs.
Revision 1.21 by root, Wed Feb 14 02:33:47 2007 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3# cfarch2png - convert crossfire maps to png+metadata 3# cfarch2png - convert crossfire maps to png+metadata
4# Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de> 4# Copyright (C) 2005,2007 Marc Lehmann <cfmaps@schmorp.de>
5# 5#
6# CFARCH2PNG is free software; you can redistribute it and/or modify 6# CFARCH2PNG is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by 7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or 8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version. 9# (at your option) any later version.
15# 15#
16# You should have received a copy of the GNU General Public License 16# You should have received a copy of the GNU General Public License
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# Quoth The master himself:
21# world_108_123 (8|18), hole below grass but shouldn't? 21#
22# Object ordering is basically like this:
23# top face: players or monsters. If none on the space, object with highest
24# visibility value - if equal, then top object in terms of object stacking on the map.
25# middle face: Object with highest visibility (of monster/player on a space). If
26# no monster/player, then object with second highest visibility, or if all equal,
27# second top object relative to map stacking.
28# Bottom object: the highest object that is a floor type object.
29#
30# ... i believe that anytime, but it still doesn't mention the smoothlevel
31# interaction :(
22 32
23our $VERSION = '1.11'; 33our $VERSION = '1.211';
24 34
25use strict; 35use strict;
26 36
27use Storable; 37use Storable;
28use List::Util qw(max); 38use List::Util qw(max);
43 -M "$path.pst" < -M $path 53 -M "$path.pst" < -M $path
44 && Storable::retrieve "$path.pst" 54 && Storable::retrieve "$path.pst"
45 } or do { 55 } or do {
46 my %pak; 56 my %pak;
47 57
48 open my $fh, "<:raw", $path 58 open my $fh, "<:raw:perlio", $path
49 or die "$_[0]: $!"; 59 or die "$_[0]: $!";
50 while (<$fh>) { 60 while (<$fh>) {
51 my ($type, $id, $len, $path) = split; 61 my ($type, $id, $len, $path) = split;
52 $path =~ s/.*\///; 62 $path =~ s/.*\///;
53 read $fh, $pak{$path}, $len; 63 read $fh, $pak{$path}, $len;
66 -M "$path.pst" < -M $path 76 -M "$path.pst" < -M $path
67 && Storable::retrieve "$path.pst" 77 && Storable::retrieve "$path.pst"
68 } or do { 78 } or do {
69 my %smooth; 79 my %smooth;
70 80
71 open my $fh, "<:raw", $path 81 open my $fh, "<:raw:perlio", $path
72 or die "$path: $!"; 82 or die "$path: $!";
73 while (<$fh>) { 83 while (<$fh>) {
74 next if /^\s*($|#)/; 84 next if /^\s*($|#)/;
75 85
76 $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; 86 $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/;
77 } 87 }
78 88
79 Storable::nstore \%smooth, "$path.pst"; 89 Storable::nstore \%smooth, "$path.pst";
90 utime +(stat $path)[8,9], "$path.pst";
80 91
81 \%smooth 92 \%smooth
82 } 93 }
83} 94}
84 95
91 && Storable::retrieve "$path.pst" 102 && Storable::retrieve "$path.pst"
92 } or do { 103 } or do {
93 my %arc; 104 my %arc;
94 my ($more, $prev); 105 my ($more, $prev);
95 106
96 open my $fh, "<:raw", $path 107 open my $fh, "<:utf8", $path
97 or die "$path: $!"; 108 or die "$path: $!";
98 109
99 my $parse_block; $parse_block = sub { 110 my $parse_block; $parse_block = sub {
100 my %arc = @_; 111 my %arc = @_;
101 112
152 } 163 }
153 } 164 }
154 165
155 undef $parse_block; # work around bug in perl not freeing $fh etc. 166 undef $parse_block; # work around bug in perl not freeing $fh etc.
156 167
168 if ($cache) {
157 Storable::nstore \%arc, "$path.pst" 169 Storable::nstore \%arc, "$path.pst";
158 if $cache; 170 utime +(stat $path)[8,9], "$path.pst";
171 }
159 172
160 \%arc 173 \%arc
161 } 174 }
162} 175}
163 176
223 # first pass, gather face stacking order, border and corner info 236 # first pass, gather face stacking order, border and corner info
224 for my $x (0 .. $mapx - 1) { 237 for my $x (0 .. $mapx - 1) {
225 my $col = $map->[$x]; 238 my $col = $map->[$x];
226 for my $y (0 .. $mapy - 1) { 239 for my $y (0 .. $mapy - 1) {
227 my $as = $col->[$y] || []; 240 my $as = $col->[$y] || [];
228 241
242 my $minsmooth = 0;
243
229 for my $layer (0 .. $#$as) { 244 for my $layer (0 .. $#$as) {
230 my $a = $as->[$layer]; 245 my $a = $as->[$layer];
231 246
232 my $o = $arch->{$a->{_name}} 247 my $o = $arch->{$a->{_name}}
233 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 248 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
234 249
235 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; 250 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel};
251
252 # hack to ensure somewhat correct ordering in case of conflicting
253 # smoothlevel/stacking order
254 $smoothlevel = $minsmooth + 0.01 if $minsmooth >= $smoothlevel;
255 $minsmooth = $smoothlevel;
256
236 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; 257 #my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor};
237 my $level = $smoothlevel ? $smoothlevel 258 my $level = $smoothlevel + $layer * 256;
238 : $is_floor ? $layer - 1000 259
239 : $layer + 1000; 260 $level -= 100 * 256 if $o->{_name} eq "blocked";
240 261
241 while ($o) { 262 while ($o) {
242 my $face = $a->{face} || $o->{face}; 263 my $face = $a->{face} || $o->{face};
243 264
244 my $pb = tile $face 265 my $pb = tile $face
278 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; 299 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
279 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; 300 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
280 } 301 }
281 302
282 $o = $o->{more}; 303 $o = $o->{more};
304 $level = ($layer + 1000) * 2; # put "big things" on top, no matter what
283 } 305 }
284 } 306 }
285 } 307 }
286 } 308 }
287 309
300 my ($x, $y) = split $;, $xy; 322 my ($x, $y) = split $;, $xy;
301 323
302 next if $x < 0 || $x >= $mapx 324 next if $x < 0 || $x >= $mapx
303 || $y < 0 || $y >= $mapy; 325 || $y < 0 || $y >= $mapy;
304 326
305 # bits is 00XX XXXX YYYY YYFX cccc CCCC BBBB 327 # bits is xxxx xxxx yyyy yyyy __fn cccc CCCC bbbb
306 # X don't draw
307 # F full tile draw with x|y bigface displacement 328 # f full tile draw with x|y bigface displacement
308 # c maybe draw these corners
309 # C do not draw these corners 329 # n do not draw borders&corners
330 # c draw these corners, but...
331 # C ... not these
310 # b draw these borders 332 # b draw these borders
311 333
312 if ($bits & 0x2000) { 334 if ($bits & 0x2000) {
313 my $dx = (($bits >> 24) & 0xff) - 128; 335 my $dx = (($bits >> 24) & 0xff) - 128;
314 my $dy = (($bits >> 16) & 0xff) - 128; 336 my $dy = (($bits >> 16) & 0xff) - 128;
363 ($map_pb, \%meta) 385 ($map_pb, \%meta)
364} 386}
365 387
366for my $file (@ARGV) { 388for my $file (@ARGV) {
367 my $mapa = read_arch $file; 389 my $mapa = read_arch $file;
390 $file =~ s/\.map$//;
368 my ($pb, $meta) = cfmap_render $mapa, $file; 391 my ($pb, $meta) = cfmap_render $mapa, $file;
369 $pb->save ("$file.png~", "png"); 392 $pb->save ("$file.png~~", "png");
370 system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; 393 system "gm", "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg";
371 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency 394 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency
372 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png"; 395 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~";
396# system "pngnq <\Q$file.png~\E >\Q$file.png\E";
373 unlink "$file.png~"; 397 unlink "$file.png~~";
374 Storable::nstore $meta, "$file.pst"; 398 Storable::nstore $meta, "$file.pst";
399 utime +(stat $file)[8,9], "$file.pst";
400 utime +(stat $file)[8,9], "$file.jpg";
401 utime +(stat $file)[8,9], "$file.png~";
402 rename "$file.png~", "$file.png";
375} 403}
376 404
377 405
378 406
379 407

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines