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,36 +28,38 @@ func (d drawList) Less(i, j int) bool {
return true
}
// Common logic for known interfaces (BoundingBoxer, ZPositioner), to
// simplify Draw{Before,After} implementations.
switch x := d.list[i].(type) {
case BoundingBoxer:
xb := x.BoundingBox()
switch y := d.list[j].(type) {
if commonDrawerComparisons {
// Common logic for known interfaces (BoundingBoxer, ZPositioner), to
// simplify Draw{Before,After} implementations.
switch x := d.list[i].(type) {
case BoundingBoxer:
yb := y.BoundingBox()
if xb.Min.Z >= yb.Max.Z { // x is in front of y
return false
xb := x.BoundingBox()
switch y := d.list[j].(type) {
case BoundingBoxer:
yb := y.BoundingBox()
if xb.Min.Z >= yb.Max.Z { // x is in front of y
return false
}
if xb.Max.Z <= yb.Min.Z { // x is behind y
return true
}
if xb.Max.Y <= yb.Min.Y { // x is above y
return false
}
if xb.Min.Y >= yb.Max.Y { // x is below y
return true
}
case ZPositioner:
return xb.Max.Z < y.ZPos() // x is before y
}
if xb.Max.Z <= yb.Min.Z { // x is behind y
return true
}
if xb.Max.Y <= yb.Min.Y { // x is above y
return false
}
if xb.Min.Y >= yb.Max.Y { // x is below y
return true
}
case ZPositioner:
return xb.Max.Z < y.ZPos() // x is before y
}
case ZPositioner:
switch y := d.list[j].(type) {
case BoundingBoxer:
return x.ZPos() < y.BoundingBox().Min.Z
case ZPositioner:
return x.ZPos() < y.ZPos()
switch y := d.list[j].(type) {
case BoundingBoxer:
return x.ZPos() < y.BoundingBox().Min.Z
case ZPositioner:
return x.ZPos() < y.ZPos()
}
}
}

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: