Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BitFlagsGenerator.cs
Go to the documentation of this file.
2
4
5internal sealed class BitFlagsGenerator
6{
7 private readonly int _bitCount;
8
9 private readonly CodeGenerator _ilg;
10
11 private readonly LocalBuilder[] _locals;
12
13 public BitFlagsGenerator(int bitCount, CodeGenerator ilg, string localName)
14 {
15 _ilg = ilg;
16 _bitCount = bitCount;
17 int num = (bitCount + 7) / 8;
18 _locals = new LocalBuilder[num];
19 for (int i = 0; i < _locals.Length; i++)
20 {
21 _locals[i] = ilg.DeclareLocal(typeof(byte), localName + i, (byte)0);
22 }
23 }
24
25 public static bool IsBitSet(byte[] bytes, int bitIndex)
26 {
29 return (bytes[byteIndex] & bitValue) == bitValue;
30 }
31
32 public static void SetBit(byte[] bytes, int bitIndex)
33 {
37 }
38
39 public int GetBitCount()
40 {
41 return _bitCount;
42 }
43
44 public LocalBuilder GetLocal(int i)
45 {
46 return _locals[i];
47 }
48
49 public int GetLocalCount()
50 {
51 return _locals.Length;
52 }
53
54 public void Load(int bitIndex)
55 {
58 _ilg.Load(obj);
60 _ilg.And();
62 _ilg.Ceq();
63 }
64
65 public void LoadArray()
66 {
68 _ilg.NewArray(typeof(byte), _locals.Length);
70 for (int i = 0; i < _locals.Length; i++)
71 {
73 }
75 }
76
77 public void Store(int bitIndex, bool value)
78 {
81 if (value)
82 {
85 _ilg.Or();
87 }
88 else
89 {
92 _ilg.Not();
93 _ilg.And();
95 }
96 }
97
98 private static byte GetBitValue(int bitIndex)
99 {
100 return (byte)(1 << (bitIndex & 7));
101 }
102
103 private static int GetByteIndex(int bitIndex)
104 {
105 return bitIndex >> 3;
106 }
107}
BitFlagsGenerator(int bitCount, CodeGenerator ilg, string localName)
static void SetBit(byte[] bytes, int bitIndex)
static bool IsBitSet(byte[] bytes, int bitIndex)
void NewArray(Type elementType, object len)
LocalBuilder DeclareLocal(Type type, string name, object initialValue)
void StoreArrayElement(object obj, object arrayIndex, object value)