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