Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
bitarray.c
Go to the documentation of this file.
1 //this class allows for creation and manipulation of arrays which hold unique IDs, and allow for bitwise-like operation over these IDs
2 //essentially, this extends single INT to any legth when it comes to holding and manipulating individual bits
3 
4 const int BIT_INT_SIZE = 32;
5 class BitArray
6 {
7  static int IDToIndex(int id)
8  {
9  int m_NumOfItems = BitArray.IDToNumOfItems(id);
10  int index = (id - (m_NumOfItems * BIT_INT_SIZE)) - 1;
11  return index;
12  }
13 
14  static int IDToMask(int id)
15  {
16  int index = BitArray.IDToIndex(id);
17  int bit = 1 << index;
18  return bit;
19  }
21  static array<int> CreateMaskArray(int size)
22  {
23  int m_NumOfItems = BitArray.IDToNumOfItems(size);
24  array<int> bit_array = new array<int>;
25 
26  for(int i = 0;i <= m_NumOfItems;i++)
27  {
28  bit_array.Insert(0);
29  }
30 
31  return bit_array;
32  }
34  static int GetBitCount( array<int> bit_array )
35  {
36  return ( (bit_array.Count() ) * BIT_INT_SIZE );
37  }
38 
40  static int IDToNumOfItems(int id)
41  {
42  int m_NumOfItems = id / BIT_INT_SIZE;
43  if( id % BIT_INT_SIZE == 0 ) m_NumOfItems--;
44  return m_NumOfItems;
45  }
46 
47  static array<int> CreateArrayWithID(int id)
48  {
49  int m_NumOfItems = BitArray.IDToNumOfItems(id);//TODO: check for too big id
50  int bit = BitArray.IDToMask(id);
51 
52  array<int> bit_array = new array<int>;
53 
54  for(int i = 0;i <= m_NumOfItems;i++)
55  {
56  bit_array.Insert(0);
57  }
58  bit_array.Set(m_NumOfItems, bit);
59  return bit_array;
60  }
61 
62  static bool IsMaskContainID(array<int> bit_array, int id)
63  {
64  if( BitArray.IDToNumOfItems( id ) > bit_array.Count() )
65  {
66  return false;
67  }
68  else
69  {
70  int index_mask = BitArray.IDToMask(id);
71  int num_of_items = BitArray.IDToNumOfItems(id);
72  int array_mask = bit_array.Get( num_of_items );
73 
74  if ( index_mask & array_mask )
75  {
76  return true;
77  }
78  else
79  {
80  return false;
81  }
82  }
83  }
84 
85  static bool AddIDToMask(array<int> bit_array, int id)
86  {
87  if( BitArray.IDToNumOfItems(id) > bit_array.Count() )
88  {
89  return false;
90  }
91  else
92  {
93  int num_of_items = BitArray.IDToNumOfItems(id);
94  int bit = BitArray.IDToMask(id);
95  int new_mask = bit_array.Get(num_of_items) | bit;
96  bit_array.Set(num_of_items, new_mask);
97  return true;
98  }
99  }
100 };
BitArray
Definition: bitarray.c:5
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
BIT_INT_SIZE
const int BIT_INT_SIZE
Definition: bitarray.c:4