Created
September 1, 2014 20:54
-
-
Save iqualfragile/b661626795a7482c69d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# adapt these to local environment | |
PARALLEL=/home/minetest/building/parallel-20140822/src/parallel | |
MAPPER=/home/minetest/minetest/util/minetestmapper | |
WORLDPATH=/home/minetest/minetest/worlds/newworld/ | |
TILEPATH=/var/www/mineguild.de/mt/leafletmap/tiles | |
PNGCRUSH="/home/minetest/local/bin/pngcrush -q -w 512 -brute" | |
#MAPSIZE*TILESIZE= max/min xy reached | |
MAPSIZE=8 | |
TILESIZE=256 | |
LEVELS=5 | |
export MAPPER | |
export PNGCRUSH | |
export WORLDPATH | |
export TILEPATH | |
export LEVELS | |
export TILESIZE | |
#xpos ypos | |
rendertile (){ | |
geomstring=$(($1 * $TILESIZE))":"$(($2 * $TILESIZE))"+$TILESIZE+$TILESIZE" | |
succ=1 | |
while [[ $succ == 1 ]]; do | |
$MAPPER \ | |
--drawalpha \ | |
--geometry $geomstring \ | |
-i $WORLDPATH \ | |
-o $TILEPATH/$LEVELS/$1_$2.png.uncrush \ | |
> /dev/zero 2> /dev/zero | |
succ=$? | |
# database locked, better wait | |
if [[ $succ == 1 ]]; then | |
sleep 0.1 | |
fi | |
done | |
$PNGCRUSH $TILEPATH/$LEVELS/$1"_"$2.png.uncrush $TILEPATH/$LEVELS/$1"_"$2.png | |
} | |
export -f rendertile | |
#prelevel basex basey | |
combine_resize(){ | |
basex=$2 | |
basey=$3 | |
if [[ $basex == -0 ]]; then basex=0; fi | |
if [[ $basey == -0 ]]; then basey=0; fi | |
x=$(($basex * 2)) | |
y=$(($basey * 2)) | |
drueber=$TILEPATH/$1/$x"_"$(($y + 1)).png | |
diagonal=$TILEPATH/$1/$(($x + 1))_$(($y + 1)).png | |
selbst=$TILEPATH/$1/$x"_"$y.png | |
rechts=$TILEPATH/$1/$(($x + 1))_$y.png | |
if [[ ! -f $drueber ]]; then drueber=$TILEPATH/blank.png ; fi | |
if [[ ! -f $diagonal ]]; then diagonal=$TILEPATH/blank.png ; fi | |
if [[ ! -f $selbst ]]; then selbst=$TILEPATH/blank.png ; fi | |
if [[ ! -f $rechts ]]; then rechts=$TILEPATH/blank.png ; fi | |
montage $drueber $diagonal $selbst $rechts \ | |
-geometry $(($TILESIZE / 2))x$(($TILESIZE / 2))+0+0 \ | |
$TILEPATH/$(($1 - 1))/$basex"_"$basey.png.uncrush | |
$PNGCRUSH $TILEPATH/$(($1 - 1))/$basex"_"$basey.png.uncrush $TILEPATH/$(($1 - 1))/$basex"_"$basey.png | |
} | |
export -f combine_resize | |
rendertiles(){ | |
$PARALLEL --eta \ | |
-j$1 \ | |
rendertile \ | |
::: $(seq -$MAPSIZE $MAPSIZE) \ | |
::: $(seq -$MAPSIZE $MAPSIZE) | |
} | |
make_zoomlevels(){ | |
div=2 | |
for zoom in $(seq $LEVELS -1 1); do | |
$PARALLEL --eta \ | |
-j$1 \ | |
combine_resize $zoom\ | |
::: $(seq -$(($(($MAPSIZE / $div)) + 1)) $(($(($MAPSIZE / $div)) + 1))) \ | |
::: $(seq -$(($(($MAPSIZE / $div)) + 1)) $(($(($MAPSIZE / $div)) + 1))) | |
div=$(($div * 2)) | |
wait | |
done | |
} | |
dostuf(){ | |
echo RENDERING TILES | |
rendertiles $1 | |
echo COMBINING TILES | |
make_zoomlevels $1 | |
echo WAITING FOR COMPRESSION TO FINISH | |
rm $TILEPATH/[0-5]/*uncrush | |
} | |
#invoke ./filename numworkers | |
dostuf $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Give some feedback please