Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BitsByte.cs
Go to the documentation of this file.
1using System;
3using System.IO;
4
5namespace Terraria;
6
7public struct BitsByte
8{
9 private static bool Null;
10
11 private byte value;
12
13 public bool this[int key]
14 {
15 get
16 {
17 return (value & (1 << key)) != 0;
18 }
19 set
20 {
21 if (value)
22 {
23 this.value |= (byte)(1 << key);
24 }
25 else
26 {
27 this.value &= (byte)(~(1 << key));
28 }
29 }
30 }
31
32 public BitsByte(bool b1 = false, bool b2 = false, bool b3 = false, bool b4 = false, bool b5 = false, bool b6 = false, bool b7 = false, bool b8 = false)
33 {
34 value = 0;
35 this[0] = b1;
36 this[1] = b2;
37 this[2] = b3;
38 this[3] = b4;
39 this[4] = b5;
40 this[5] = b6;
41 this[6] = b7;
42 this[7] = b8;
43 }
44
45 public void ClearAll()
46 {
47 value = 0;
48 }
49
50 public void SetAll()
51 {
52 value = byte.MaxValue;
53 }
54
55 public void Retrieve(ref bool b0)
56 {
58 }
59
60 public void Retrieve(ref bool b0, ref bool b1)
61 {
63 }
64
65 public void Retrieve(ref bool b0, ref bool b1, ref bool b2)
66 {
68 }
69
70 public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3)
71 {
73 }
74
75 public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4)
76 {
78 }
79
80 public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5)
81 {
83 }
84
85 public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5, ref bool b6)
86 {
88 }
89
90 public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5, ref bool b6, ref bool b7)
91 {
92 b0 = this[0];
93 b1 = this[1];
94 b2 = this[2];
95 b3 = this[3];
96 b4 = this[4];
97 b5 = this[5];
98 b6 = this[6];
99 b7 = this[7];
100 }
101
102 public static implicit operator byte(BitsByte bb)
103 {
104 return bb.value;
105 }
106
107 public static implicit operator BitsByte(byte b)
108 {
109 BitsByte result = default(BitsByte);
110 result.value = b;
111 return result;
112 }
113
114 public static BitsByte[] ComposeBitsBytesChain(bool optimizeLength, params bool[] flags)
115 {
116 int num = flags.Length;
117 int num2 = 0;
118 while (num > 0)
119 {
120 num2++;
121 num -= 7;
122 }
123 BitsByte[] array = new BitsByte[num2];
124 int num3 = 0;
125 int num4 = 0;
126 for (int i = 0; i < flags.Length; i++)
127 {
128 array[num4][num3] = flags[i];
129 num3++;
130 if (num3 == 7 && num4 < num2 - 1)
131 {
132 array[num4][num3] = true;
133 num3 = 0;
134 num4++;
135 }
136 }
137 if (optimizeLength)
138 {
139 int num5 = array.Length - 1;
140 while ((byte)array[num5] == 0 && num5 > 0)
141 {
142 array[num5 - 1][7] = false;
143 num5--;
144 }
145 Array.Resize(ref array, num5 + 1);
146 }
147 return array;
148 }
149
151 {
154 do
155 {
156 item = reader.ReadByte();
157 list.Add(item);
158 }
159 while (item[7]);
160 return list.ToArray();
161 }
162}
void Add(TKey key, TValue value)
virtual byte ReadByte()
void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5, ref bool b6)
Definition BitsByte.cs:85
void Retrieve(ref bool b0, ref bool b1)
Definition BitsByte.cs:60
void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4)
Definition BitsByte.cs:75
static BitsByte[] DecomposeBitsBytesChain(BinaryReader reader)
Definition BitsByte.cs:150
static BitsByte[] ComposeBitsBytesChain(bool optimizeLength, params bool[] flags)
Definition BitsByte.cs:114
void Retrieve(ref bool b0)
Definition BitsByte.cs:55
void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3)
Definition BitsByte.cs:70
BitsByte(bool b1=false, bool b2=false, bool b3=false, bool b4=false, bool b5=false, bool b6=false, bool b7=false, bool b8=false)
Definition BitsByte.cs:32
void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5)
Definition BitsByte.cs:80
static bool Null
Definition BitsByte.cs:9
void Retrieve(ref bool b0, ref bool b1, ref bool b2)
Definition BitsByte.cs:65
void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5, ref bool b6, ref bool b7)
Definition BitsByte.cs:90