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

Comparing cfmaps/cfmap2png (file contents):
Revision 1.8 by root, Sun Nov 20 00:58:57 2005 UTC vs.
Revision 1.12 by root, Tue Nov 22 06:46:43 2005 UTC

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# tower of stars: missing craters?
21# world_108_123 (8|18), hole below grass but shouldn't?
22
23our $VERSION = '1.11';
21 24
22use strict; 25use strict;
23 26
24use Storable; 27use Storable;
25use List::Util qw(max); 28use List::Util qw(max);
26 29
27use Gtk2; 30use Gtk2;
28
29our $VERSION = '1.0';
30 31
31#init Gtk2::Gdk; 32#init Gtk2::Gdk;
32 33
33my $LIB = $ENV{CROSSFIRE_LIBDIR} 34my $LIB = $ENV{CROSSFIRE_LIBDIR}
34 or die "\$CROSSFIRE_LIBDIR must be set\n"; 35 or die "\$CROSSFIRE_LIBDIR must be set\n";
190 191
191 my %meta; 192 my %meta;
192 193
193 my ($mapx, $mapy); 194 my ($mapx, $mapy);
194 195
195 my $map = $meta{map} = []; 196 my $map;
196 197
197 for (@{ $mapa->{arch} }) { 198 for (@{ $mapa->{arch} }) {
199 my ($x, $y) = ($_->{x}, $_->{y});
200
198 if ($_->{_name} eq "map") { 201 if ($_->{_name} eq "map") {
199 $meta{info} = $_; 202 $meta{info} = $_;
200 203
201 $mapx = $_->{width} || $_->{x}; 204 $mapx = $_->{width} || $x;
202 $mapy = $_->{height} || $_->{y}; 205 $mapy = $_->{height} || $y;
203 } else { 206 } else {
204 push @{ $map->[$_->{x}][$_->{y}] }, $_; 207 push @{ $map->[$x][$y] }, $_;
205 208
206 # arch map is unreliable w.r.t. width and height 209 # arch map is unreliable w.r.t. width and height
207 $mapx = $_->{x} + 1 if $mapx <= $_->{x}; 210 $mapx = $x + 1 if $mapx <= $x;
208 $mapy = $_->{y} + 1 if $mapy <= $_->{y}; 211 $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}; 212 #$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}; 213 #$mapy = $a->{y} + 1, warn "$mapname: arch '$a->{_name}' outside map height at ($a->{x}|$a->{y})\n" if $mapy <= $a->{y};
211 } 214 }
212 } 215 }
213 216
214 $meta{width} = $mapx; 217 $meta{width} = $mapx;
215 $meta{height} = $mapy; 218 $meta{height} = $mapy;
216 219
217 my %draw_info; 220 my %draw_info;
221 my %map_info;
218 222
219 # first pass, gather face stacking order, border and corner info 223 # first pass, gather face stacking order, border and corner info
220 for my $x (0 .. $mapx - 1) { 224 for my $x (0 .. $mapx - 1) {
221 my $col = $map->[$x]; 225 my $col = $map->[$x];
222 for my $y (0 .. $mapy - 1) { 226 for my $y (0 .. $mapy - 1) {
229 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 233 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
230 234
231 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; 235 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel};
232 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; 236 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor};
233 my $level = $smoothlevel ? $smoothlevel 237 my $level = $smoothlevel ? $smoothlevel
234 : $is_floor ? 0 238 : $is_floor ? $layer - 1000
235 : 256 + $layer; 239 : $layer + 1000;
236 240
237 while ($o) { 241 while ($o) {
238 my $face = $a->{face} || $o->{face}; 242 my $face = $a->{face} || $o->{face};
239 243
240 my $pb = tile $face 244 my $pb = tile $face
246 last if 0 > $mx || $mx >= $mapx 250 last if 0 > $mx || $mx >= $mapx
247 || 0 > $my || $my >= $mapy; 251 || 0 > $my || $my >= $mapy;
248 252
249 # this is very ugly (some tiles are 32x33 or worse) 253 # this is very ugly (some tiles are 32x33 or worse)
250 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; 254 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2;
255
256 my $dx = $bigface ? $o->{x} : 0;
257 my $dy = $bigface ? $o->{y} : 0;
258
259 push @{ $map_info{$level}{$mx, $my} }, $a;
260
261 $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16);
251 262
252 if (my $sface = $smooth->{$face}) { 263 if (my $sface = $smooth->{$face}) {
253 $bigface and die "can't handle bigfaces with smoothing ($face)\n"; 264 $bigface and die "can't handle bigfaces with smoothing ($face)\n";
254 265
255 # full tile 266 # full tile
266 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200; 277 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200;
267 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; 278 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
268 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; 279 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
269 } 280 }
270 281
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}; 282 $o = $o->{more};
277 } 283 }
278 } 284 }
279 } 285 }
280 } 286 }
281 287
282 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T 288 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T
283 or die; 289 or die;
284 $map_pb->fill (0xffffff00); 290 $map_pb->fill (0xffffff00);
285 291
286 # second pass, render all the stuff 292 # second pass, render the map
287 for my $level (sort { $a <=> $b } keys %draw_info) { 293 for my $level (sort { $a <=> $b } keys %draw_info) {
288 my $v = $draw_info{$level}; 294 my $v = $draw_info{$level};
289 while (my ($sface, $info) = each %$v) { 295 while (my ($sface, $info) = each %$v) {
290 my $pb = tile $sface 296 my $pb = tile $sface
291 or die "no smooth face $sface\n"; 297 or die "no smooth face $sface\n";
336 255 342 255
337 ) if $corner; 343 ) if $corner;
338 } 344 }
339 } 345 }
340 } 346 }
347 }
348
349 # third pass, gather meta info
350 for my $level (sort { $a <=> $b } keys %map_info) {
351 my $info = $map_info{$level};
352
353 while (my ($xy, $as) = each %$info) {
354 my ($x, $y) = split $;, $xy;
355
356 next if $x < 0 || $x >= $mapx
357 || $y < 0 || $y >= $mapy;
358
359 push @{ $meta{map}[$x][$y] }, $_ for @$as;
360 }
341 } 361 }
342 362
343 ($map_pb, \%meta) 363 ($map_pb, \%meta)
344} 364}
345 365

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines