fix it again

This commit is contained in:
Josh Deprez 2021-09-16 11:18:24 +10:00
parent 97c5939483
commit 4a7deaca47
3 changed files with 38 additions and 34 deletions

View file

@ -2,6 +2,8 @@ package engine
import "github.com/hajimehoshi/ebiten/v2"
const commonDrawerComparisons = false
var _ Drawer = tombstone{}
type tombstone struct{}
@ -26,6 +28,7 @@ func (d drawList) Less(i, j int) bool {
return true
}
if commonDrawerComparisons {
// Common logic for known interfaces (BoundingBoxer, ZPositioner), to
// simplify Draw{Before,After} implementations.
switch x := d.list[i].(type) {
@ -58,6 +61,7 @@ func (d drawList) Less(i, j int) bool {
return x.ZPos() < y.ZPos()
}
}
}
// Fallback case: ask the components themselves
return d.list[i].DrawBefore(d.list[j]) || d.list[j].DrawAfter(d.list[i])

View file

@ -158,7 +158,7 @@ func (p *Prism) DrawAfter(x Drawer) bool {
case BoundingBoxer:
xb := x.BoundingBox()
if false {
if !commonDrawerComparisons {
if pb.Max.Z <= xb.Min.Z { // p is behind x
return false
}
@ -185,8 +185,8 @@ func (p *Prism) DrawAfter(x Drawer) bool {
return true
}
//case ZPositioner:
// return pb.Min.Z > x.ZPos() // p is after x
case ZPositioner:
return pb.Min.Z > x.ZPos() // p is after x
}
return false
}
@ -204,7 +204,7 @@ func (p *Prism) DrawBefore(x Drawer) bool {
case BoundingBoxer:
xb := x.BoundingBox()
if false {
if !commonDrawerComparisons {
if pb.Min.Z >= xb.Max.Z { // p is in front of x
return false
}
@ -231,8 +231,8 @@ func (p *Prism) DrawBefore(x Drawer) bool {
return true
}
//case ZPositioner:
// return pb.Max.Z < x.ZPos() // p is before x
case ZPositioner:
return pb.Max.Z < x.ZPos() // p is before x
}
return false
}

View file

@ -41,7 +41,7 @@ func (s *Sprite) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
// DrawAfter reports if the sprite should be drawn after x.
func (s *Sprite) DrawAfter(x Drawer) bool {
if false {
if !commonDrawerComparisons {
sb := s.BoundingBox()
switch x := x.(type) {
case BoundingBoxer:
@ -67,7 +67,7 @@ func (s *Sprite) DrawAfter(x Drawer) bool {
// DrawBefore reports if the sprite should be drawn before x.
func (s *Sprite) DrawBefore(x Drawer) bool {
if false {
if !commonDrawerComparisons {
sb := s.BoundingBox()
switch x := x.(type) {
case BoundingBoxer: