Skip to content

Commit 90def77

Browse files
committed
add helpful comment on varbit masks
1 parent 83c9a8f commit 90def77

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/main/java/com/jagex/runescape/cache/def/VarbitDefinition.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@
77
import com.jagex.runescape.util.BitUtils;
88

99
public class VarbitDefinition extends CachedNode {
10-
public static int[] varbitMasks = new int[32];
1110
public static NodeCache varbitDefinitionCache = new NodeCache(64);
1211
public static CacheArchive gameDefinitionsCacheArchive;
1312

14-
// Pre-calculate varbit masks
13+
/**
14+
* Contains information on the bit mask to use per specified bits.
15+
* Example:
16+
* We want to have a mask of 6 bits, which would look like this: 00111111 (decimal: 63)
17+
* Since this array starts from index 0, the 6th index is varbitMasks[5].
18+
* So varbitMasks[5] == 63 == 00111111
19+
* The mask can then be used together with "varPlayerValue >> LSB" to find the actual varbit value.
20+
*/
21+
public static int[] varbitMasks = new int[32];
1522
static {
16-
int i = 2;
17-
for(int i_7_ = 0; i_7_ < 32; i_7_++) {
18-
varbitMasks[i_7_] = -1 + i;
19-
i += i;
23+
int currentBit = 2;
24+
for(int index = 0; index < 32; index++) {
25+
varbitMasks[index] = currentBit - 1;
26+
currentBit += currentBit;
2027
}
2128
}
2229

0 commit comments

Comments
 (0)