1 |
#!/usr/bin/perl |
2 |
# This script takes a bunch of world image files and combines them |
3 |
# into one large image. This should be run from the directory |
4 |
# where all the images are. |
5 |
# Note that this takes a while to run. Probably pretty proportional |
6 |
# to the the size of the target image. |
7 |
# This is somewhat hacked for my usage - it presumes you run this |
8 |
# from the top level of the maps directory (eg, contains world, scorn, |
9 |
# etc directories). This is smart enough to regen the image files |
10 |
# that may be missing/out of date. |
11 |
|
12 |
$DEST_WIDTH=3000; |
13 |
$DEST_HEIGHT=3000; |
14 |
|
15 |
$NUM_X=30; |
16 |
$NUM_Y=30; |
17 |
|
18 |
$START_X=100; |
19 |
$START_Y=100; |
20 |
|
21 |
$TILE_WIDTH = $DEST_WIDTH/$NUM_X; |
22 |
$TILE_HEIGHT = $DEST_HEIGHT/$NUM_Y; |
23 |
# This is the command to run the editor. Really, it can be anything that |
24 |
# outputs a .png file. The %I and %O are substituted with actul |
25 |
# path names. |
26 |
$CFEDITOR="cd /export/home/crossfire/CFJavaEditor; java -Xmx128mb -classpath class/:lib/png.jar:lib/visualtek.jar cfeditor.CFJavaEditor -infile %I -outfile %O > /dev/null"; |
27 |
|
28 |
die ("No images directory - exiting\n") if (! -d "./images"); |
29 |
use Cwd; |
30 |
$cwd = cwd(); |
31 |
|
32 |
|
33 |
# If we already have a combined image, then we only need to paste |
34 |
# the new bits onto it, saving a bunch of time |
35 |
if (! -f "images/combine.ppm") { |
36 |
system("ppmmake \\#000 $DEST_WIDTH $DEST_HEIGHT > /tmp/tmp.ppm"); |
37 |
$first_run=1; |
38 |
print "Creating images for the first time.\n"; |
39 |
} else { |
40 |
system("cp images/combine.ppm /tmp/tmp.ppm"); |
41 |
$first_run=0; |
42 |
} |
43 |
|
44 |
print "Processing."; |
45 |
for ($x=0; $x<$NUM_X; $x++) { |
46 |
for ($y=0; $y<$NUM_Y; $y++) { |
47 |
print "."; |
48 |
$dx = $x + $START_X; |
49 |
$dy = $y + $START_Y; |
50 |
|
51 |
# These time values are the reverse in how you'd normally think about them - they |
52 |
# are the time (in days) since the fiel was last modified. Thus, a file that hasn't |
53 |
# been modified in a long time has a high value, a file modified recently has |
54 |
# a low level. |
55 |
$time1 = -M "images\/world_$dx\_$dy.png"; |
56 |
$time2 = -M "world\/world_$dx\_$dy"; |
57 |
if ($time1 > $time2) { |
58 |
$cmd = $CFEDITOR; |
59 |
$cmd =~ s#%I#$cwd/world/world_$dx\_$dy#; |
60 |
$cmd =~ s#%O#$cwd/images/world_$dx\_$dy.png#; |
61 |
system($cmd); |
62 |
system("pngtopnm images/world_$dx\_$dy.png | pnmscale -xysize $TILE_WIDTH $TILE_HEIGHT > /tmp/ppm.tmp"); |
63 |
$sx = $x * $TILE_WIDTH; |
64 |
$sy = $y * $TILE_HEIGHT; |
65 |
system("pnmpaste /tmp/ppm.tmp $sx $sy /tmp/tmp.ppm > /tmp/tmp.ppm1"); |
66 |
unlink("/tmp/tmp.ppm"); |
67 |
rename("/tmp/tmp.ppm1", "/tmp/tmp.ppm"); |
68 |
} |
69 |
} |
70 |
} |
71 |
system("mv /tmp/tmp.ppm images/combine.ppm"); |
72 |
print "\n"; |