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
part of flutter_sprites;
class _PhysicsCollisionGroups {
_PhysicsCollisionGroups() {
// Make sure there is a default entry in the groups
getBitmaskForKeys(["Default"]);
}
Map<Object,int> keyLookup = <Object,int>{};
List<Object> getKeysForBitmask(int bitmask) {
List<Object> keys = [];
keyLookup.forEach((Object key, int value) {
if (value & bitmask != 0) {
keys.add(key);
}
});
return keys;
}
int getBitmaskForKeys(List<Object> keys) {
if (keys == null) {
return 0xffff;
}
int bitmask = 0;
for (Object key in keys) {
int value = keyLookup[key];
if (value == null) {
assert(keyLookup.length < 16);
value = 1 << keyLookup.length;
keyLookup[key] = value;
}
bitmask |= value;
}
return bitmask;
}
}