From 458fc5d1da6122e0ebf6db309487561a93ec4f65 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Thu, 11 Sep 2014 11:03:35 +0200 Subject: [PATCH] Do some early stopping when scanning for min y of a 16x16 region. --- tilemapper/renderer.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tilemapper/renderer.go b/tilemapper/renderer.go index fd3a80f..bcccab6 100644 --- a/tilemapper/renderer.go +++ b/tilemapper/renderer.go @@ -44,17 +44,21 @@ func NewRenderer(xOfs, zOfs int16, width, height int) (renderer *Renderer) { return } -func (r *Renderer) minY(ofs, w int) (minY int32) { +func (r *Renderer) minY(ofs, w int) (minY int32, filled bool) { minY = int32(math.MaxInt32) for yEnd := ofs + w<<4; ofs < yEnd; { for xEnd := ofs + 16; ofs < xEnd; ofs++ { y := r.yBuffer[ofs] - if y < minY { + switch { + case y == math.MaxInt32: + return + case y < minY: minY = y } } ofs += w - 16 } + filled = true return } @@ -71,7 +75,7 @@ func (r *Renderer) RenderBlock(block *common.Block, nameIndex map[string]int32) w := r.width << 4 ofs := int(bz)*w<<4 + int(bx)<<4 blockY := int32(block.Coord.Y) << 4 - if blockY < r.minY(ofs, w) { + if minY, filled := r.minY(ofs, w); filled && blockY < minY { r.Rejected++ return }