2015-07-26 16:33:29 +02:00
|
|
|
// Copyright 2014, 2015 by Sascha L. Teichmann
|
2014-09-14 17:12:28 +02:00
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2014-09-20 15:50:07 +02:00
|
|
|
"strconv"
|
2014-09-14 17:12:28 +02:00
|
|
|
"sync"
|
|
|
|
|
2014-10-03 12:07:53 +02:00
|
|
|
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
2014-09-14 17:12:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-05-01 14:04:23 +02:00
|
|
|
baseLevelDir = "8"
|
2014-09-14 17:12:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type blockPos struct {
|
|
|
|
x, z int16
|
|
|
|
j, i int
|
|
|
|
}
|
|
|
|
|
2014-09-20 15:50:07 +02:00
|
|
|
func createTiles(
|
|
|
|
btc *common.BaseTileCreator,
|
|
|
|
jobs chan blockPos,
|
|
|
|
done *sync.WaitGroup) {
|
2014-09-14 17:12:28 +02:00
|
|
|
|
|
|
|
defer done.Done()
|
2014-09-20 15:50:07 +02:00
|
|
|
defer btc.Close()
|
2014-09-14 17:12:28 +02:00
|
|
|
for job := range jobs {
|
2014-09-20 15:50:07 +02:00
|
|
|
btc.CreateTile(job.x-1, job.z-1, job.i, job.j)
|
2014-09-14 17:12:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func order(a, b int) (int, int) {
|
|
|
|
if a < b {
|
|
|
|
return a, b
|
|
|
|
}
|
|
|
|
return b, a
|
|
|
|
}
|
|
|
|
|
|
|
|
func createBaseLevel(
|
|
|
|
address string,
|
|
|
|
xMin, zMin, xMax, zMax int,
|
2015-07-26 11:55:38 +02:00
|
|
|
transparent bool, transparentDim float32,
|
2014-09-14 17:12:28 +02:00
|
|
|
colorsFile, outDir string,
|
|
|
|
numWorkers int) (err error) {
|
|
|
|
|
|
|
|
var colors *common.Colors
|
|
|
|
|
|
|
|
if colors, err = common.ParseColors(colorsFile); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-26 11:55:38 +02:00
|
|
|
colors.TransparentDim = transparentDim
|
|
|
|
|
2014-09-14 17:12:28 +02:00
|
|
|
baseDir := filepath.Join(outDir, baseLevelDir)
|
|
|
|
if err = os.MkdirAll(baseDir, os.ModePerm); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
jobs := make(chan blockPos)
|
|
|
|
var done sync.WaitGroup
|
|
|
|
|
|
|
|
for i := 0; i < numWorkers; i++ {
|
|
|
|
var client *common.RedisClient
|
|
|
|
if client, err = common.NewRedisClient("tcp", address); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
done.Add(1)
|
2014-10-26 18:36:47 +01:00
|
|
|
btc := common.NewBaseTileCreator(client, colors, transparent, baseDir, false)
|
2014-09-20 15:50:07 +02:00
|
|
|
go createTiles(btc, jobs, &done)
|
2014-09-14 17:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zMin, zMax = order(zMin, zMax)
|
|
|
|
|
|
|
|
for x, i := int16(xMin), 0; x <= int16(xMax); x += 16 {
|
2014-09-20 15:50:07 +02:00
|
|
|
xDir := filepath.Join(baseDir, strconv.Itoa(i))
|
2015-07-20 14:19:41 +02:00
|
|
|
log.Printf("creating dir: %s\n", xDir)
|
2014-09-14 17:12:28 +02:00
|
|
|
if err = os.MkdirAll(xDir, os.ModePerm); err != nil {
|
2015-07-20 14:19:41 +02:00
|
|
|
log.Fatalf("Cannot create directory '%s': %s\n", xDir, err)
|
2014-09-14 17:12:28 +02:00
|
|
|
}
|
|
|
|
for z, j := int16(zMin), 0; z <= int16(zMax); z += 16 {
|
|
|
|
jobs <- blockPos{x: x, z: z, i: i, j: j}
|
|
|
|
j++
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
close(jobs)
|
|
|
|
|
|
|
|
done.Wait()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|