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

View File

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