-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashset_arbiter.go
More file actions
60 lines (46 loc) · 1.63 KB
/
hashset_arbiter.go
File metadata and controls
60 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cm
import "slices"
// SpaceArbiterSetFilter throws away old arbiters.
func SpaceArbiterSetFilter(arb *Arbiter, space *Space) bool {
// TODO: should make an arbiter state for this so it doesn't require filtering arbiters for dangling body pointers on body removal.
// Preserve arbiters on sensors and rejected arbiters for sleeping objects.
// This prevents errant separate callbacks from happening.
a := arb.bodyA
b := arb.bodyB
if (a.Type() == Static || a.IsSleeping()) && (b.Type() == Static || b.IsSleeping()) {
return true
}
ticks := space.stamp - arb.stamp
if ticks >= 1 && arb.state != ArbiterStateCached {
arb.state = ArbiterStateCached
handler := arb.handler
handler.SeparateFunc(arb, space, handler.UserData)
}
if ticks >= space.CollisionPersistence {
arb.Contacts = nil
arb.count = 0
space.pooledArbiters.Put(arb)
return false
}
return true
}
func CachedArbitersFilter(arb *Arbiter, space *Space, shape *Shape, body *Body) bool {
// Match on the filter shape, or if it's nil the filter body
if (body == arb.bodyA && (shape == arb.shapeA || shape == nil)) ||
(body == arb.bodyB && (shape == arb.shapeB || shape == nil)) {
// Call separate when removing shapes.
if shape != nil && arb.state != ArbiterStateCached {
// Invalidate the arbiter since one of the shapes was removed
arb.state = ArbiterStateInvalidated
handler := arb.handler
handler.SeparateFunc(arb, space, handler.UserData)
}
arb.Unthread()
space.Arbiters = slices.DeleteFunc(space.Arbiters, func(arbiter *Arbiter) bool {
return arb == arbiter
})
space.pooledArbiters.Put(arb)
return false
}
return true
}