-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathhashset_arbiter.go
59 lines (48 loc) · 1.68 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 cp
// 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.body_a
b := arb.body_b
if (a.GetType() == BODY_STATIC || a.IsSleeping()) && (b.GetType() == BODY_STATIC || b.IsSleeping()) {
return true
}
ticks := space.stamp - arb.stamp
if ticks >= 1 && arb.state != CP_ARBITER_STATE_CACHED {
arb.state = CP_ARBITER_STATE_CACHED
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 NULL the filter body
if (body == arb.body_a && (shape == arb.a || shape == nil)) ||
(body == arb.body_b && (shape == arb.b || shape == nil)) {
// Call separate when removing shapes.
if shape != nil && arb.state != CP_ARBITER_STATE_CACHED {
// Invalidate the arbiter since one of the shapes was removed
arb.state = CP_ARBITER_STATE_INVALIDATED
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
}