-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashset_arbiter.go
59 lines (48 loc) · 1.65 KB
/
hashset_arbiter.go
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
package cm
// 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()
for i, arbiter := range space.Arbiters {
if arb == arbiter {
space.Arbiters = append(space.Arbiters[:i], space.Arbiters[i+1:]...)
break
}
}
space.pooledArbiters.Put(arb)
return false
}
return true
}