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" import "github.com/hajimehoshi/ebiten/v2"
const commonDrawerComparisons = false
var _ Drawer = tombstone{} var _ Drawer = tombstone{}
type tombstone struct{} type tombstone struct{}
@ -26,36 +28,38 @@ func (d drawList) Less(i, j int) bool {
return true return true
} }
// Common logic for known interfaces (BoundingBoxer, ZPositioner), to if commonDrawerComparisons {
// simplify Draw{Before,After} implementations. // Common logic for known interfaces (BoundingBoxer, ZPositioner), to
switch x := d.list[i].(type) { // simplify Draw{Before,After} implementations.
case BoundingBoxer: switch x := d.list[i].(type) {
xb := x.BoundingBox()
switch y := d.list[j].(type) {
case BoundingBoxer: case BoundingBoxer:
yb := y.BoundingBox() xb := x.BoundingBox()
if xb.Min.Z >= yb.Max.Z { // x is in front of y switch y := d.list[j].(type) {
return false 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: 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: case BoundingBoxer:
xb := x.BoundingBox() xb := x.BoundingBox()
if false { if !commonDrawerComparisons {
if pb.Max.Z <= xb.Min.Z { // p is behind x if pb.Max.Z <= xb.Min.Z { // p is behind x
return false return false
} }
@ -185,8 +185,8 @@ func (p *Prism) DrawAfter(x Drawer) bool {
return true return true
} }
//case ZPositioner: case ZPositioner:
// return pb.Min.Z > x.ZPos() // p is after x return pb.Min.Z > x.ZPos() // p is after x
} }
return false return false
} }
@ -204,7 +204,7 @@ func (p *Prism) DrawBefore(x Drawer) bool {
case BoundingBoxer: case BoundingBoxer:
xb := x.BoundingBox() xb := x.BoundingBox()
if false { if !commonDrawerComparisons {
if pb.Min.Z >= xb.Max.Z { // p is in front of x if pb.Min.Z >= xb.Max.Z { // p is in front of x
return false return false
} }
@ -231,8 +231,8 @@ func (p *Prism) DrawBefore(x Drawer) bool {
return true return true
} }
//case ZPositioner: case ZPositioner:
// return pb.Max.Z < x.ZPos() // p is before x return pb.Max.Z < x.ZPos() // p is before x
} }
return false 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. // DrawAfter reports if the sprite should be drawn after x.
func (s *Sprite) DrawAfter(x Drawer) bool { func (s *Sprite) DrawAfter(x Drawer) bool {
if false { if !commonDrawerComparisons {
sb := s.BoundingBox() sb := s.BoundingBox()
switch x := x.(type) { switch x := x.(type) {
case BoundingBoxer: case BoundingBoxer:
@ -67,7 +67,7 @@ func (s *Sprite) DrawAfter(x Drawer) bool {
// DrawBefore reports if the sprite should be drawn before x. // DrawBefore reports if the sprite should be drawn before x.
func (s *Sprite) DrawBefore(x Drawer) bool { func (s *Sprite) DrawBefore(x Drawer) bool {
if false { if !commonDrawerComparisons {
sb := s.BoundingBox() sb := s.BoundingBox()
switch x := x.(type) { switch x := x.(type) {
case BoundingBoxer: case BoundingBoxer: