drawlist -> own file
This commit is contained in:
parent
0981350993
commit
e6afa2de50
2 changed files with 34 additions and 31 deletions
34
engine/drawlist.go
Normal file
34
engine/drawlist.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package engine
|
||||||
|
|
||||||
|
import "github.com/hajimehoshi/ebiten/v2"
|
||||||
|
|
||||||
|
var _ Drawer = tombstone{}
|
||||||
|
|
||||||
|
type tombstone struct{}
|
||||||
|
|
||||||
|
func (tombstone) Draw(*ebiten.Image, *ebiten.DrawImageOptions) {}
|
||||||
|
|
||||||
|
func (tombstone) DrawAfter(x Drawer) bool { return x != tombstone{} }
|
||||||
|
func (tombstone) DrawBefore(Drawer) bool { return false }
|
||||||
|
|
||||||
|
type drawList struct {
|
||||||
|
list []Drawer
|
||||||
|
rev map[Drawer]int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d drawList) Less(i, j int) bool {
|
||||||
|
if d.list[i] == (tombstone{}) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if d.list[j] == (tombstone{}) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return d.list[i].DrawBefore(d.list[j]) || d.list[j].DrawAfter(d.list[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d drawList) Len() int { return len(d.list) }
|
||||||
|
|
||||||
|
func (d drawList) Swap(i, j int) {
|
||||||
|
d.rev[d.list[i]], d.rev[d.list[j]] = j, i
|
||||||
|
d.list[i], d.list[j] = d.list[j], d.list[i]
|
||||||
|
}
|
|
@ -433,37 +433,6 @@ type abKey struct {
|
||||||
behaviour reflect.Type
|
behaviour reflect.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Drawer = tombstone{}
|
|
||||||
|
|
||||||
type tombstone struct{}
|
|
||||||
|
|
||||||
func (tombstone) Draw(*ebiten.Image, *ebiten.DrawImageOptions) {}
|
|
||||||
|
|
||||||
func (tombstone) DrawAfter(x Drawer) bool { return x != tombstone{} }
|
|
||||||
func (tombstone) DrawBefore(Drawer) bool { return false }
|
|
||||||
|
|
||||||
type drawList struct {
|
|
||||||
list []Drawer
|
|
||||||
rev map[Drawer]int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d drawList) Less(i, j int) bool {
|
|
||||||
if d.list[i] == (tombstone{}) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if d.list[j] == (tombstone{}) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return d.list[i].DrawBefore(d.list[j]) || d.list[j].DrawAfter(d.list[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d drawList) Len() int { return len(d.list) }
|
|
||||||
|
|
||||||
func (d drawList) Swap(i, j int) {
|
|
||||||
d.rev[d.list[i]], d.rev[d.list[j]] = j, i
|
|
||||||
d.list[i], d.list[j] = d.list[j], d.list[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
// concatOpts returns the combined options (as though a was applied and then b).
|
// concatOpts returns the combined options (as though a was applied and then b).
|
||||||
func concatOpts(a, b ebiten.DrawImageOptions) ebiten.DrawImageOptions {
|
func concatOpts(a, b ebiten.DrawImageOptions) ebiten.DrawImageOptions {
|
||||||
a.ColorM.Concat(b.ColorM)
|
a.ColorM.Concat(b.ColorM)
|
||||||
|
|
Loading…
Reference in a new issue