Better early stopping when the tile is filled.

This commit is contained in:
Sascha L. Teichmann 2014-09-11 02:28:09 +02:00
parent e2070c8b94
commit 072eba3e5a
2 changed files with 29 additions and 22 deletions

View File

@ -72,8 +72,8 @@ func main() {
c1 := common.Coord{X: q1x, Z: q1z}
c2 := common.Coord{X: q2x, Z: q2z}
for c2.Y = q2y; c2.Y > q1y; c2.Y -= 16 {
c1.Y = c2.Y - 15
for c2.Y = q2y; c2.Y > q1y; c2.Y -= 8 {
c1.Y = c2.Y - 7
if c1.Y < q1y {
c1.Y = q1y
}
@ -81,6 +81,9 @@ func main() {
if err = client.QueryCuboid(cuboid, drawBlock); err != nil {
log.Fatalf("query failed: %s", err)
}
if renderer.IsFilled() {
break
}
}
image := renderer.CreateImage(
@ -90,6 +93,6 @@ func main() {
log.Fatalf("writing image failed: %s", err)
}
fmt.Printf("Rejected blocks: %d\n", renderer.RejectedBlocks)
fmt.Printf("num blocks: %d\n", numBlocks)
fmt.Printf("rejected blocks: %d\n", renderer.Rejected)
}

View File

@ -19,9 +19,8 @@ type Renderer struct {
zOfs int16
yBuffer []int32
cBuffer []int32
filled []uint16
minYs []int16
RejectedBlocks int
filled int
Rejected int
}
func NewRenderer(xOfs, zOfs int16, width, height int) (renderer *Renderer) {
@ -45,11 +44,10 @@ func NewRenderer(xOfs, zOfs int16, width, height int) (renderer *Renderer) {
return
}
func (r *Renderer) minY(x, z int16) (minY int32) {
x -= r.xOfs
z -= r.zOfs
w := r.width << 4
ofs := int(z)*w<<4 + int(x)<<4
//func (r *Renderer) minY(x, z int16) (minY int32) {
func (r *Renderer) minY(ofs, w int) (minY int32) {
//w := r.width << 4
//ofs := int(z)*w<<4 + int(x)<<4
minY = int32(math.MaxInt32)
for yEnd := ofs + w<<4; ofs < yEnd; {
for xEnd := ofs + 16; ofs < xEnd; ofs++ {
@ -63,15 +61,21 @@ func (r *Renderer) minY(x, z int16) (minY int32) {
return
}
func (r *Renderer) IsFilled() bool {
return r.filled == r.width<<4*r.height<<4
}
func (r *Renderer) RenderBlock(block *common.Block, nameIndex map[string]int32) (err error) {
bx := block.Coord.X - r.xOfs
bz := block.Coord.Z - r.zOfs
// We do not need to render the block if the whole 16x16 area
// is already filled and the block is strictly below.
w := r.width << 4
ofs := int(bz)*w<<4 + int(bx)<<4
blockY := int32(block.Coord.Y) << 4
if blockY < r.minY(block.Coord.X, block.Coord.Z) {
r.RejectedBlocks++
if blockY < r.minY(ofs, w) {
r.Rejected++
return
}
@ -81,14 +85,14 @@ func (r *Renderer) RenderBlock(block *common.Block, nameIndex map[string]int32)
return
}
w := r.width << 4
ofs := int(bz)*w<<4 + int(bx)<<4
for z := 0; z < 16; z++ {
for x := 0; x < 16; x++ {
if currentY := r.yBuffer[ofs]; currentY < blockY {
for y := 15; y >= 0; y-- {
if c, ok := db.Content(x, y, z); ok {
if r.cBuffer[ofs] == -1 {
r.filled++
}
r.cBuffer[ofs] = c
r.yBuffer[ofs] = blockY + int32(y)
break