optimize Drawer.Dirty (defer the hard part until drawing)
This commit is contained in:
parent
ec4f5e3663
commit
a9d735dafe
12
drawer.go
12
drawer.go
|
@ -27,6 +27,7 @@ type Drawer struct {
|
|||
tris map[Target]TargetTriangles
|
||||
clean map[Target]bool
|
||||
pics map[targetPicturePair]TargetPicture
|
||||
dirty bool
|
||||
inited bool
|
||||
}
|
||||
|
||||
|
@ -49,9 +50,7 @@ func (d *Drawer) lazyInit() {
|
|||
func (d *Drawer) Dirty() {
|
||||
d.lazyInit()
|
||||
|
||||
for t := range d.clean {
|
||||
d.clean[t] = false
|
||||
}
|
||||
d.dirty = true
|
||||
}
|
||||
|
||||
// Draw efficiently draws Triangles with Picture onto the provided Target.
|
||||
|
@ -61,6 +60,13 @@ func (d *Drawer) Dirty() {
|
|||
func (d *Drawer) Draw(t Target) {
|
||||
d.lazyInit()
|
||||
|
||||
if d.dirty {
|
||||
for t := range d.clean {
|
||||
d.clean[t] = false
|
||||
}
|
||||
d.dirty = false
|
||||
}
|
||||
|
||||
if d.Triangles == nil {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue