mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Made tile renderer resetable to reduce the memory for render more than one tile.
This commit is contained in:
parent
3a0b922a9e
commit
f762154b05
@ -70,7 +70,8 @@ func main() {
|
|||||||
q1x, q1y, q1z := int16(x), int16(y), int16(z)
|
q1x, q1y, q1z := int16(x), int16(y), int16(z)
|
||||||
q2x, q2y, q2z := q1x+int16(width)-1, q1y+int16(depth)-1, q1z+int16(height)-1
|
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)
|
yOrder := common.NewYOrder(renderer, 512)
|
||||||
|
|
||||||
numBlocks := 0
|
numBlocks := 0
|
||||||
|
@ -40,6 +40,10 @@ func NewYOrder(renderer *Renderer, capacity int) *YOrder {
|
|||||||
capacity: capacity}
|
capacity: capacity}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (yo *YOrder) Reset() {
|
||||||
|
yo.blocks = yo.blocks[0:0]
|
||||||
|
}
|
||||||
|
|
||||||
func max(a, b int) int {
|
func max(a, b int) int {
|
||||||
if a > b {
|
if a > b {
|
||||||
return a
|
return a
|
||||||
@ -116,33 +120,39 @@ func (yo *YOrder) Pop() (x interface{}) {
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRenderer(xOfs, zOfs int16, width, height int) (renderer *Renderer) {
|
func NewRenderer(width, height int) (renderer *Renderer) {
|
||||||
dim := width * height
|
dim := width * height
|
||||||
pixSize := dim * 16 * 16
|
pixSize := dim * 16 * 16
|
||||||
yBuffer := make([]int32, pixSize)
|
yBuffer := make([]int32, pixSize)
|
||||||
cBuffer := make([]int32, pixSize)
|
cBuffer := make([]int32, pixSize)
|
||||||
yMin := make([]int32, dim)
|
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{
|
renderer = &Renderer{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
xOfs: xOfs,
|
|
||||||
zOfs: zOfs,
|
|
||||||
yBuffer: yBuffer,
|
yBuffer: yBuffer,
|
||||||
cBuffer: cBuffer,
|
cBuffer: cBuffer,
|
||||||
yMin: yMin}
|
yMin: yMin}
|
||||||
|
|
||||||
|
renderer.Reset()
|
||||||
return
|
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 {
|
func (r *Renderer) IsFilled() bool {
|
||||||
for _, y := range r.yMin {
|
for _, y := range r.yMin {
|
||||||
if y == math.MinInt32 {
|
if y == math.MinInt32 {
|
||||||
|
Loading…
Reference in New Issue
Block a user