mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-07-03 08:30:45 +02:00
Better early stopping when the tile is filled.
This commit is contained in:
@ -13,15 +13,14 @@ import (
|
||||
)
|
||||
|
||||
type Renderer struct {
|
||||
width int
|
||||
height int
|
||||
xOfs int16
|
||||
zOfs int16
|
||||
yBuffer []int32
|
||||
cBuffer []int32
|
||||
filled []uint16
|
||||
minYs []int16
|
||||
RejectedBlocks int
|
||||
width int
|
||||
height int
|
||||
xOfs int16
|
||||
zOfs int16
|
||||
yBuffer []int32
|
||||
cBuffer []int32
|
||||
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
|
||||
|
Reference in New Issue
Block a user