Fixes #14. mtseeder and mtwebmapper now have command line flags -ymin=block and -ymax=block to limit the y range of mapping. Defaults to full range.

This commit is contained in:
Sascha L. Teichmann 2015-07-27 19:03:47 +02:00
parent 464ccbf670
commit e606e2700f
6 changed files with 66 additions and 28 deletions

View File

@ -35,16 +35,9 @@ func createTiles(
}
}
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,
xMin, yMin, zMin, xMax, yMax, zMax int,
transparent bool, transparentDim float32,
colorsFile, outDir string,
numWorkers int) (err error) {
@ -71,11 +64,14 @@ func createBaseLevel(
return
}
done.Add(1)
btc := common.NewBaseTileCreator(client, colors, transparent, baseDir, false)
btc := common.NewBaseTileCreator(
client, colors,
int16(yMin), int16(yMax),
transparent, baseDir, false)
go createTiles(btc, jobs, &done)
}
zMin, zMax = order(zMin, zMax)
zMin, zMax = common.Order(zMin, zMax)
for x, i := int16(xMin), 0; x <= int16(xMax); x += 16 {
xDir := filepath.Join(baseDir, strconv.Itoa(i))

View File

@ -14,18 +14,18 @@ import (
func main() {
var (
port int
host string
xMin, zMin int
xMax, zMax int
colorsFile string
outDir string
numWorkers int
skipBaseLevel bool
skipPyramid bool
transparent bool
transparentDim float64
version bool
port int
host string
xMin, yMin, zMin int
xMax, yMax, zMax int
colorsFile string
outDir string
numWorkers int
skipBaseLevel bool
skipPyramid bool
transparent bool
transparentDim float64
version bool
)
flag.IntVar(&port, "port", 6379, "port to of mtredisalize server")
@ -33,6 +33,8 @@ func main() {
flag.StringVar(&host, "host", "localhost", "host to mtredisalize server")
flag.IntVar(&xMin, "xmin", -1933, "x min of the area to tile")
flag.IntVar(&xMax, "xmax", 1932, "x max of the area to tile")
flag.IntVar(&yMin, "ymin", common.MinHeight, "Minimum y in blocks.")
flag.IntVar(&yMax, "ymax", common.MaxHeight, "Maximum y in blocks.")
flag.IntVar(&zMin, "zmin", -1933, "z min of the area to tile")
flag.IntVar(&zMax, "zmax", 1932, "z max of the area to tile")
flag.StringVar(&colorsFile, "colors", "colors.txt", "definition of colors")
@ -65,7 +67,7 @@ func main() {
address := fmt.Sprintf("%s:%d", host, port)
if err := createBaseLevel(
address,
xMin, zMin, xMax, zMax,
xMin, yMin, zMin, xMax, yMax, zMax,
transparent, td,
colorsFile,
outDir,

View File

@ -32,6 +32,8 @@ func main() {
websockets bool
playersFIFO string
version bool
yMin int
yMax int
)
flag.IntVar(&webPort, "web-port", 8808, "port of the web server")
flag.IntVar(&webPort, "p", 8808, "port of the web server (shorthand)")
@ -64,6 +66,8 @@ func main() {
flag.BoolVar(&websockets, "ws", false, "Forward tile changes to clients via websockets (shorthand).")
flag.StringVar(&playersFIFO, "players", "", "Path to FIFO file to read active players from.")
flag.StringVar(&playersFIFO, "ps", "", "Path to FIFO file to read active players from (shorthand).")
flag.IntVar(&yMin, "ymin", common.MinHeight, "Minimum y in blocks.")
flag.IntVar(&yMax, "ymax", common.MaxHeight, "Maximum y in blocks.")
flag.BoolVar(&version, "version", false, "Print version and exit.")
flag.Parse()
@ -113,6 +117,7 @@ func main() {
redisAddress,
allowedUpdateIps,
colors,
yMin, yMax,
transparent,
workers,
btu)

View File

@ -35,6 +35,7 @@ type tileUpdater struct {
redisAddress string
ips []net.IP
colors *common.Colors
yMin, yMax int16
workers int
transparent bool
cond *sync.Cond
@ -71,6 +72,7 @@ func newTileUpdater(
mapDir, redisAddress string,
ips []net.IP,
colors *common.Colors,
yMin, yMax int,
transparent bool,
workers int,
btu baseTilesUpdates) *tileUpdater {
@ -82,6 +84,8 @@ func newTileUpdater(
ips: ips,
changes: map[xz]bool{},
colors: colors,
yMin: int16(yMin),
yMax: int16(yMax),
transparent: transparent,
workers: workers}
tu.cond = sync.NewCond(&tu.mu)
@ -166,7 +170,10 @@ func (tu *tileUpdater) doUpdates() {
log.Printf("WARN: Cannot connect to redis server: %s\n", err)
continue
}
btc := common.NewBaseTileCreator(client, tu.colors, tu.transparent, baseDir, true)
btc := common.NewBaseTileCreator(
client, tu.colors,
tu.yMin, tu.yMax,
tu.transparent, baseDir, true)
done.Add(1)
go updateBaseTiles(jobs, btc, &done)
}

View File

@ -18,10 +18,15 @@ const (
yOrderCapacity = 512
)
const (
MaxHeight = 1934
MinHeight = -1934
)
// To scan the whole height in terms of the y coordinate
// the database is queried in height units defined in the tileDepths table.
var tileDepths = [...][2]int16{
{1024, 1934},
{1024, MaxHeight},
{256, 1023},
{128, 255},
{64, 127},
@ -40,7 +45,7 @@ var tileDepths = [...][2]int16{
{-128, -65},
{-256, -129},
{-1024, -257},
{-1934, -1025}}
{MinHeight, -1025}}
var BackgroundColor = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
@ -49,6 +54,8 @@ type BaseTileCreator struct {
colors *Colors
renderer *Renderer
yOrder *YOrder
yMin int16
yMax int16
baseDir string
update bool
emptyImage []byte
@ -57,15 +64,19 @@ type BaseTileCreator struct {
func NewBaseTileCreator(
client *RedisClient,
colors *Colors,
yMin, yMax int16,
transparent bool,
baseDir string,
update bool) *BaseTileCreator {
renderer := NewRenderer(tileWidth, tileHeight, transparent)
yMin, yMax = Order16(yMin, yMax)
return &BaseTileCreator{
client: client,
colors: colors,
renderer: renderer,
yOrder: NewYOrder(renderer, yOrderCapacity),
yMin: yMin,
yMax: yMax,
baseDir: baseDir,
update: update}
}
@ -95,8 +106,11 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
X2: int16(tileWidth) - 1, Z2: int16(tileHeight) - 1}
for _, yRange := range tileDepths {
c1.Y = yRange[0]
c2.Y = yRange[1]
if yRange[0] > btc.yMax || yRange[1] < btc.yMin {
continue
}
c1.Y = max16(yRange[0], btc.yMin)
c2.Y = min16(yRange[1], btc.yMax)
nareas = btc.renderer.UncoveredAreas(nareas, oareas)

View File

@ -63,6 +63,20 @@ func Clamp32f(x, a, b float32) float32 {
return x
}
func Order(a, b int) (int, int) {
if a < b {
return a, b
}
return b, a
}
func Order16(a, b int16) (int16, int16) {
if a < b {
return a, b
}
return b, a
}
func Order64(a, b int64) (int64, int64) {
if a < b {
return a, b