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

Comparing cfmaps/cfmap2png (file contents):
Revision 1.9 by root, Sun Nov 20 01:05:34 2005 UTC vs.
Revision 1.10 by root, Sun Nov 20 01:31:21 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.01'; 22our $VERSION = '1.1';
23 23
24use strict; 24use strict;
25 25
26use Storable; 26use Storable;
27use List::Util qw(max); 27use List::Util qw(max);
190 190
191 my %meta; 191 my %meta;
192 192
193 my ($mapx, $mapy); 193 my ($mapx, $mapy);
194 194
195 my $map = $meta{map} = []; 195 my $map;
196 196
197 for (@{ $mapa->{arch} }) { 197 for (@{ $mapa->{arch} }) {
198 my ($x, $y) = ($_->{x}, $_->{y});
199
198 if ($_->{_name} eq "map") { 200 if ($_->{_name} eq "map") {
199 $meta{info} = $_; 201 $meta{info} = $_;
200 202
201 $mapx = $_->{width} || $_->{x}; 203 $mapx = $_->{width} || $x;
202 $mapy = $_->{height} || $_->{y}; 204 $mapy = $_->{height} || $y;
203 } else { 205 } else {
204 push @{ $map->[$_->{x}][$_->{y}] }, $_; 206 push @{ $map->[$x][$y] }, $_;
205 207
206 # arch map is unreliable w.r.t. width and height 208 # arch map is unreliable w.r.t. width and height
207 $mapx = $_->{x} + 1 if $mapx <= $_->{x}; 209 $mapx = $x + 1 if $mapx <= $x;
208 $mapy = $_->{y} + 1 if $mapy <= $_->{y}; 210 $mapy = $y + 1 if $mapy <= $y;
209 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x}; 211 #$mapx = $a->{x} + 1, warn "$mapname: arch '$a->{_name}' outside map width at ($a->{x}|$a->{y})\n" if $mapx <= $a->{x};
210 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y}; 212 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
211 } 213 }
212 } 214 }
213 215
214 $meta{width} = $mapx; 216 $meta{width} = $mapx;
215 $meta{height} = $mapy; 217 $meta{height} = $mapy;
216 218
217 my %draw_info; 219 my %draw_info;
220 my %map_info;
218 221
219 # first pass, gather face stacking order, border and corner info 222 # first pass, gather face stacking order, border and corner info
220 for my $x (0 .. $mapx - 1) { 223 for my $x (0 .. $mapx - 1) {
221 my $col = $map->[$x]; 224 my $col = $map->[$x];
222 for my $y (0 .. $mapy - 1) { 225 for my $y (0 .. $mapy - 1) {
247 || 0 > $my || $my >= $mapy; 250 || 0 > $my || $my >= $mapy;
248 251
249 # this is very ugly (some tiles are 32x33 or worse) 252 # this is very ugly (some tiles are 32x33 or worse)
250 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; 253 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2;
251 254
255 my $dx = $bigface ? $o->{x} : 0;
256 my $dy = $bigface ? $o->{y} : 0;
257
258 push @{ $map_info{$level}{$mx, $my} }, $a;
259
260 $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16);
261
252 if (my $sface = $smooth->{$face}) { 262 if (my $sface = $smooth->{$face}) {
253 $bigface and die "can't handle bigfaces with smoothing ($face)\n"; 263 $bigface and die "can't handle bigfaces with smoothing ($face)\n";
254 264
255 # full tile 265 # full tile
256 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000; 266 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000;
266 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200; 276 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200;
267 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; 277 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
268 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; 278 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
269 } 279 }
270 280
271 my $dx = $bigface ? $o->{x} : 0;
272 my $dy = $bigface ? $o->{y} : 0;
273
274 $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16);
275
276 $o = $o->{more}; 281 $o = $o->{more};
277 } 282 }
278 } 283 }
279 } 284 }
280 } 285 }
281 286
282 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T 287 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T
283 or die; 288 or die;
284 $map_pb->fill (0xffffff00); 289 $map_pb->fill (0xffffff00);
285 290
286 # second pass, render all the stuff 291 # second pass, render the map
287 for my $level (sort { $a <=> $b } keys %draw_info) { 292 for my $level (sort { $a <=> $b } keys %draw_info) {
288 my $v = $draw_info{$level}; 293 my $v = $draw_info{$level};
289 while (my ($sface, $info) = each %$v) { 294 while (my ($sface, $info) = each %$v) {
290 my $pb = tile $sface 295 my $pb = tile $sface
291 or die "no smooth face $sface\n"; 296 or die "no smooth face $sface\n";
336 255 341 255
337 ) if $corner; 342 ) if $corner;
338 } 343 }
339 } 344 }
340 } 345 }
346 }
347
348 # third pass, gather meta info
349 for my $level (sort { $a <=> $b } keys %map_info) {
350 my $info = $map_info{$level};
351
352 while (my ($xy, $as) = each %$info) {
353 my ($x, $y) = split $;, $xy;
354
355 next if $x < 0 || $x >= $mapx
356 || $y < 0 || $y >= $mapy;
357
358 push @{ $meta{map}[$x][$y] }, $_ for @$as;
359 }
341 } 360 }
342 361
343 ($map_pb, \%meta) 362 ($map_pb, \%meta)
344} 363}
345 364

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines