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( func createBaseLevel(
address string, address string,
xMin, zMin, xMax, zMax int, xMin, yMin, zMin, xMax, yMax, zMax int,
transparent bool, transparentDim float32, transparent bool, transparentDim float32,
colorsFile, outDir string, colorsFile, outDir string,
numWorkers int) (err error) { numWorkers int) (err error) {
@ -71,11 +64,14 @@ func createBaseLevel(
return return
} }
done.Add(1) 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) 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 { for x, i := int16(xMin), 0; x <= int16(xMax); x += 16 {
xDir := filepath.Join(baseDir, strconv.Itoa(i)) xDir := filepath.Join(baseDir, strconv.Itoa(i))

View File

@ -14,18 +14,18 @@ import (
func main() { func main() {
var ( var (
port int port int
host string host string
xMin, zMin int xMin, yMin, zMin int
xMax, zMax int xMax, yMax, zMax int
colorsFile string colorsFile string
outDir string outDir string
numWorkers int numWorkers int
skipBaseLevel bool skipBaseLevel bool
skipPyramid bool skipPyramid bool
transparent bool transparent bool
transparentDim float64 transparentDim float64
version bool version bool
) )
flag.IntVar(&port, "port", 6379, "port to of mtredisalize server") 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.StringVar(&host, "host", "localhost", "host to mtredisalize server")
flag.IntVar(&xMin, "xmin", -1933, "x min of the area to tile") 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(&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(&zMin, "zmin", -1933, "z min of the area to tile")
flag.IntVar(&zMax, "zmax", 1932, "z max 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") flag.StringVar(&colorsFile, "colors", "colors.txt", "definition of colors")
@ -65,7 +67,7 @@ func main() {
address := fmt.Sprintf("%s:%d", host, port) address := fmt.Sprintf("%s:%d", host, port)
if err := createBaseLevel( if err := createBaseLevel(
address, address,
xMin, zMin, xMax, zMax, xMin, yMin, zMin, xMax, yMax, zMax,
transparent, td, transparent, td,
colorsFile, colorsFile,
outDir, outDir,

View File

@ -32,6 +32,8 @@ func main() {
websockets bool websockets bool
playersFIFO string playersFIFO string
version bool version bool
yMin int
yMax int
) )
flag.IntVar(&webPort, "web-port", 8808, "port of the web server") flag.IntVar(&webPort, "web-port", 8808, "port of the web server")
flag.IntVar(&webPort, "p", 8808, "port of the web server (shorthand)") 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.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, "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.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.BoolVar(&version, "version", false, "Print version and exit.")
flag.Parse() flag.Parse()
@ -113,6 +117,7 @@ func main() {
redisAddress, redisAddress,
allowedUpdateIps, allowedUpdateIps,
colors, colors,
yMin, yMax,
transparent, transparent,
workers, workers,
btu) btu)

View File

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

View File

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

View File

@ -63,6 +63,20 @@ func Clamp32f(x, a, b float32) float32 {
return x 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) { func Order64(a, b int64) (int64, int64) {
if a < b { if a < b {
return a, b return a, b