diff --git a/cmd/mtseeder/baselevel.go b/cmd/mtseeder/baselevel.go index f65e889..2f7fba6 100644 --- a/cmd/mtseeder/baselevel.go +++ b/cmd/mtseeder/baselevel.go @@ -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)) diff --git a/cmd/mtseeder/main.go b/cmd/mtseeder/main.go index dd85fee..acb9a24 100644 --- a/cmd/mtseeder/main.go +++ b/cmd/mtseeder/main.go @@ -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, diff --git a/cmd/mtwebmapper/main.go b/cmd/mtwebmapper/main.go index 3f70e03..7d4b420 100644 --- a/cmd/mtwebmapper/main.go +++ b/cmd/mtwebmapper/main.go @@ -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) diff --git a/cmd/mtwebmapper/tilesupdater.go b/cmd/mtwebmapper/tilesupdater.go index 4df0fd3..5023fe0 100644 --- a/cmd/mtwebmapper/tilesupdater.go +++ b/cmd/mtwebmapper/tilesupdater.go @@ -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) } diff --git a/common/basetilecreator.go b/common/basetilecreator.go index 5517580..e26050b 100644 --- a/common/basetilecreator.go +++ b/common/basetilecreator.go @@ -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) diff --git a/common/math.go b/common/math.go index 321346e..7b0f5dd 100644 --- a/common/math.go +++ b/common/math.go @@ -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