Implement renderer reset cheaper ... and this time correctly.

This commit is contained in:
Sascha L. Teichmann 2017-02-27 23:50:15 +01:00
parent eed91e7148
commit d6411f3f6d

View File

@ -137,7 +137,7 @@ func NewRenderer(width, height int, transparent bool) (renderer *Renderer) {
tBuffer: tBuffer, tBuffer: tBuffer,
spans: spans} spans: spans}
renderer.Reset() renderer.initBuffers()
return return
} }
@ -146,16 +146,7 @@ func (r *Renderer) SetPos(xOfs, zOfs int16) {
r.zOfs = zOfs r.zOfs = zOfs
} }
func (r *Renderer) Reset() { func (r *Renderer) initBuffers() {
/* TODO: Figure out why this early stop results
in broken renderings.
if r.IsEmpty() {
return
}
*/
yb := r.yBuffer yb := r.yBuffer
yb = yb[:len(yb)] yb = yb[:len(yb)]
for i := range yb { for i := range yb {
@ -173,9 +164,20 @@ func (r *Renderer) Reset() {
for i := range ym { for i := range ym {
ym[i] = math.MinInt32 ym[i] = math.MinInt32
} }
}
func (r *Renderer) Reset() {
r.RejectedBlocks = 0
if r.SolidBlocks > 0 || r.TransparentBlocks > 0 {
r.SolidBlocks = 0
r.initBuffers()
}
if r.TransparentBlocks > 0 { if r.TransparentBlocks > 0 {
r.TransparentBlocks = 0 r.TransparentBlocks = 0
tb := r.tBuffer tb := r.tBuffer
for i, t := range tb { for i, t := range tb {
if t != nil { if t != nil {
@ -184,8 +186,6 @@ func (r *Renderer) Reset() {
} }
} }
} }
r.SolidBlocks = 0
r.RejectedBlocks = 0
} }
func (r *Renderer) IsFilled() bool { func (r *Renderer) IsFilled() bool {