Made tile renderer resetable to reduce the memory for render more than one tile.

This commit is contained in:
Sascha L. Teichmann 2014-09-14 14:57:49 +02:00
parent 3a0b922a9e
commit f762154b05
2 changed files with 24 additions and 13 deletions

View File

@ -70,7 +70,8 @@ func main() {
q1x, q1y, q1z := int16(x), int16(y), int16(z)
q2x, q2y, q2z := q1x+int16(width)-1, q1y+int16(depth)-1, q1z+int16(height)-1
renderer := common.NewRenderer(q1x, q1z, width, height)
renderer := common.NewRenderer(width, height)
renderer.SetPos(q1x, q1z)
yOrder := common.NewYOrder(renderer, 512)
numBlocks := 0

View File

@ -40,6 +40,10 @@ func NewYOrder(renderer *Renderer, capacity int) *YOrder {
capacity: capacity}
}
func (yo *YOrder) Reset() {
yo.blocks = yo.blocks[0:0]
}
func max(a, b int) int {
if a > b {
return a
@ -116,33 +120,39 @@ func (yo *YOrder) Pop() (x interface{}) {
return x
}
func NewRenderer(xOfs, zOfs int16, width, height int) (renderer *Renderer) {
func NewRenderer(width, height int) (renderer *Renderer) {
dim := width * height
pixSize := dim * 16 * 16
yBuffer := make([]int32, pixSize)
cBuffer := make([]int32, pixSize)
yMin := make([]int32, dim)
for i := 0; i < pixSize; i++ {
yBuffer[i] = math.MinInt32
cBuffer[i] = -1
}
for i := 0; i < dim; i++ {
yMin[i] = math.MinInt32
}
renderer = &Renderer{
width: width,
height: height,
xOfs: xOfs,
zOfs: zOfs,
yBuffer: yBuffer,
cBuffer: cBuffer,
yMin: yMin}
renderer.Reset()
return
}
func (r *Renderer) SetPos(xOfs, zOfs int16) {
r.xOfs = xOfs
r.zOfs = zOfs
}
func (r *Renderer) Reset() {
for i, n := 0, len(r.yBuffer); i < n; i++ {
r.yBuffer[i] = math.MinInt32
r.cBuffer[i] = -1
}
for i, n := 0, len(r.yMin); i < n; i++ {
r.yMin[i] = math.MinInt32
}
}
func (r *Renderer) IsFilled() bool {
for _, y := range r.yMin {
if y == math.MinInt32 {