Formalized use of frame data logging.

This commit is contained in:
genxium
2022-12-27 10:09:53 +08:00
parent 335e11e925
commit c017aaa7ed
13 changed files with 123 additions and 83 deletions

View File

@@ -1,3 +1,4 @@
//go:build !noasm
// +build !noasm
package resolv

View File

@@ -1,3 +1,4 @@
//go:build !amd64 || noasm
// +build !amd64 noasm
package resolv
@@ -21,4 +22,3 @@ func scalUnitaryTo(dst []float64, alpha float64, x []float64) {
dst[i] *= alpha
}
}

View File

@@ -2,7 +2,7 @@ package resolv
import (
"math"
"sort"
//"sort"
)
// Object represents an object that can be spread across one or more Cells in a Space. An Object is essentially an AABB (Axis-Aligned Bounding Box) Rectangle.
@@ -284,26 +284,29 @@ func (obj *Object) Check(dx, dy float64, tags ...string) *Collision {
return nil
}
ox, oy := cc.checkingObject.Center()
oc := Vector{ox, oy}
/*
// In my use case, order of objects within a collision instance is not needed, and this also favors both runtime performance & size reduction of `jsexport.js`.
sort.Slice(cc.Objects, func(i, j int) bool {
ox, oy := cc.checkingObject.Center()
oc := Vector{ox, oy}
sort.Slice(cc.Objects, func(i, j int) bool {
ix, iy := cc.Objects[i].Center()
jx, jy := cc.Objects[j].Center()
return Vector{ix, iy}.Sub(oc).Magnitude2() < Vector{jx, jy}.Sub(oc).Magnitude2()
ix, iy := cc.Objects[i].Center()
jx, jy := cc.Objects[j].Center()
return Vector{ix, iy}.Sub(oc).Magnitude2() < Vector{jx, jy}.Sub(oc).Magnitude2()
})
})
cw := cc.checkingObject.Space.CellWidth
ch := cc.checkingObject.Space.CellHeight
cw := cc.checkingObject.Space.CellWidth
ch := cc.checkingObject.Space.CellHeight
sort.Slice(cc.Cells, func(i, j int) bool {
sort.Slice(cc.Cells, func(i, j int) bool {
return Vector{float64(cc.Cells[i].X*cw + (cw / 2)), float64(cc.Cells[i].Y*ch + (ch / 2))}.Sub(oc).Magnitude2() <
Vector{float64(cc.Cells[j].X*cw + (cw / 2)), float64(cc.Cells[j].Y*ch + (ch / 2))}.Sub(oc).Magnitude2()
return Vector{float64(cc.Cells[i].X*cw + (cw / 2)), float64(cc.Cells[i].Y*ch + (ch / 2))}.Sub(oc).Magnitude2() <
Vector{float64(cc.Cells[j].X*cw + (cw / 2)), float64(cc.Cells[j].Y*ch + (ch / 2))}.Sub(oc).Magnitude2()
})
})
*/
return cc

View File

@@ -2,7 +2,6 @@ package resolv
import (
"math"
"sort"
)
type Shape interface {
@@ -518,18 +517,7 @@ func (cp *ConvexPolygon) calculateMTV(contactSet *ContactSet, otherShape Shape)
}
}
case *Circle:
verts := append([]Vector{}, cp.Transformed()...)
// The center point of a contact could also be closer than the verts, particularly if we're testing from a Circle to another Shape.
verts = append(verts, contactSet.Center)
center := Vector{other.X, other.Y}
sort.Slice(verts, func(i, j int) bool { return verts[i].Sub(center).Magnitude() < verts[j].Sub(center).Magnitude() })
smallest = Vector{center[0] - verts[0][0], center[1] - verts[0][1]}
smallest = smallest.Unit().Scale(smallest.Magnitude() - other.Radius)
// Removed support of "Circle" to remove dependency of "sort" module
}
delta[0] = smallest[0]